source: rtems/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c @ 99e65f9c

4.104.114.9
Last change on this file since 99e65f9c was 99e65f9c, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Oct 26, 2007 at 12:12:42 PM

* empty log message *

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic MPC83xx BSP                              |
3+-----------------------------------------------------------------+
4|                    Copyright (c) 2007                           |
5|                    Embedded Brains GmbH                         |
6|                    Obere Lagerstr. 30                           |
7|                    D-82178 Puchheim                             |
8|                    Germany                                      |
9|                    rtems@embedded-brains.de                     |
10+-----------------------------------------------------------------+
11| The license and distribution terms for this file may be         |
12| found in the file LICENSE in this distribution or at            |
13|                                                                 |
14| http://www.rtems.com/license/LICENSE.                           |
15|                                                                 |
16+-----------------------------------------------------------------+
17| this file contains the BSP startup code                         |
18\*===============================================================*/
19
20/*
21 *  $Id$
22 */
23
24#include <bsp.h>
25
26#include <rtems/libio.h>
27#include <rtems/libcsupport.h>
28#include <rtems/powerpc/powerpc.h>
29#include <rtems/score/thread.h>
30
31#include <rtems/bspIo.h>
32#include <libcpu/cpuIdent.h>
33#include <libcpu/spr.h>
34#include <bsp/irq.h>
35
36#include <string.h>
37
38SPR_RW(SPRG0)
39SPR_RW(SPRG1)
40
41/*
42 *  The original table from the application (in ROM) and our copy of it with
43 *  some changes. Configuration is defined in <confdefs.h>. Make sure that
44 *  our configuration tables are uninitialized so that they get allocated in
45 *  the .bss section (RAM).
46 */
47extern rtems_configuration_table Configuration;
48extern unsigned long intrStackPtr;
49rtems_configuration_table  BSP_Configuration;
50static char *BSP_heap_start, *BSP_heap_end;
51rtems_cpu_table Cpu_table;
52char *rtems_progname;
53
54/*
55 * constants for c_clock driver:
56 * system bus frequency (for timebase etc)
57 * and
58 * Time base divisior: scaling value:
59 * BSP_time_base_divisor = TB ticks per millisecond/BSP_bus_frequency
60 */
61unsigned int BSP_bus_frequency = BSP_CSB_CLK_FRQ;
62unsigned int BSP_time_base_divisor = 4000;  /* 4 bus clicks per TB click */
63
64/*
65 *  Use the shared implementations of the following routines.
66 *  Look in rtems/c/src/lib/libbsp/shared/bsppost.c and
67 *  rtems/c/src/lib/libbsp/shared/bsplibc.c.
68 */
69void bsp_postdriver_hook(void);
70void bsp_libc_init( void *, uint32_t, int );
71extern void initialize_exceptions(void);
72extern void cpu_init(void);
73
74void BSP_panic(char *s)
75  {
76  printk("%s PANIC %s\n",_RTEMS_version, s);
77  /*
78   * FIXME: hang/restart system
79   */
80  __asm__ __volatile ("sc");
81  }
82
83void _BSP_Fatal_error(unsigned int v)
84  {
85  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
86  /*
87   * FIXME: hang/restart system
88   */
89  __asm__ __volatile ("sc");
90  }
91
92/*
93 *  Function:   bsp_pretasking_hook
94 *  Created:    95/03/10
95 *
96 *  Description:
97 *      BSP pretasking hook.  Called just before drivers are initialized.
98 *      Used to setup libc and install any BSP extensions.
99 *
100 *  NOTES:
101 *      Must not use libc (to do io) from here, since drivers are
102 *      not yet initialized.
103 *
104 */
105
106void
107bsp_pretasking_hook(void)
108{
109
110  /*
111   * initialize libc including the heap
112   */
113  bsp_libc_init( BSP_heap_start, 
114                 BSP_heap_end - BSP_heap_start,
115                 0);
116
117
118#ifdef STACK_CHECKER_ON
119  /*
120   *  Initialize the stack bounds checker
121   *  We can either turn it on here or from the app.
122   */
123
124  Stack_check_Initialize();
125#endif
126
127#ifdef RTEMS_DEBUG
128  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
129#endif
130}
131
132
133
134void bsp_predriver_hook(void)
135{
136}
137
138void bsp_calc_mem_layout()
139{
140  /*
141   * these labels (!) are defined in the linker command file
142   * or when the linker is invoked
143   * NOTE: the information(size) is the address of the object,
144   * not the object otself
145   */
146  extern unsigned char TopRamReserved;
147  extern unsigned char _WorkspaceBase[];
148
149  /*
150   * compute the memory layout:
151   * - first unused address is Workspace start
152   * - Heap starts at end of workspace
153   * - Heap ends at end of memory - reserved memory area
154   */
155  BSP_Configuration.work_space_start = _WorkspaceBase;
156
157  BSP_heap_start = ((char *)BSP_Configuration.work_space_start +
158                    BSP_Configuration.work_space_size);
159
160#if defined(HAS_UBOOT)
161  BSP_heap_end = (uboot_bdinfo_ptr->bi_memstart
162                  + uboot_bdinfo_ptr->bi_memsize
163                  - (uint32_t)&TopRamReserved);
164#else
165  BSP_heap_end = (void *)(RAM_END - (uint32_t)&TopRamReserved);
166#endif
167
168}
169
170
171void bsp_start(void)
172{
173  ppc_cpu_id_t myCpu;
174  ppc_cpu_revision_t myCpuRevision;
175  register unsigned char* intrStack;
176
177  /*
178   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
179   * store the result in global variables so that it can be used latter...
180   */
181  myCpu             = get_ppc_cpu_type();
182  myCpuRevision = get_ppc_cpu_revision();
183  /*
184   * determine heap and workspace placement
185   */
186  bsp_calc_mem_layout();
187
188  cpu_init();
189
190  /*
191   * Initialize some SPRG registers related to irq handling
192   */
193
194  intrStack = (((unsigned char*)&intrStackPtr) - PPC_MINIMUM_STACK_FRAME_SIZE);
195
196  _write_SPRG1((unsigned int)intrStack);
197
198  /* Signal them that this BSP has fixed PR288 - eventually, this should go away */
199  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
200
201  /*
202   *  initialize the CPU table for this BSP
203   */
204
205  Cpu_table.pretasking_hook        = bsp_pretasking_hook;    /* init libc, etc. */
206  Cpu_table.predriver_hook         = bsp_predriver_hook;     /* init PCI / RTC ...   */
207  Cpu_table.postdriver_hook        = bsp_postdriver_hook;
208  Cpu_table.clicks_per_usec        = (BSP_CSB_CLK_FRQ/1000000);
209  Cpu_table.exceptions_in_RAM      = TRUE;
210
211  if( Cpu_table.interrupt_stack_size < 4*1024 )
212    Cpu_table.interrupt_stack_size = 4 * 1024;
213
214 /*
215  * Install our own set of exception vectors
216  */
217
218  initialize_exceptions();
219
220  /*
221   * Enable instruction and data caches. Do not force writethrough mode.
222   */
223#if INSTRUCTION_CACHE_ENABLE
224  rtems_cache_enable_instruction();
225#endif
226#if DATA_CACHE_ENABLE
227  rtems_cache_enable_data();
228#endif
229
230  /*
231   *  Allocate the memory for the RTEMS Work Space.  This can come from
232   *  a variety of places: hard coded address, malloc'ed from outside
233   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
234   *  typically done by stock BSPs) by subtracting the required amount
235   *  of work space from the last physical address on the CPU board.
236   */
237
238  /*
239   * Initalize RTEMS IRQ system
240   */
241  BSP_rtems_irq_mng_init(0);
242
243#ifdef SHOW_MORE_INIT_SETTINGS
244  printk("Exit from bspstart\n");
245#endif
246
247  }
248
249/*
250 *
251 *  _Thread_Idle_body
252 *
253 *  Replaces the one in c/src/exec/score/src/threadidlebody.c
254 *  The MSR[POW] bit is set to put the CPU into the low power mode
255 *  defined in HID0.  HID0 is set during starup in start.S.
256 *
257 */
258Thread _Thread_Idle_body(uint32_t ignored )
259  {
260
261  for(;;)
262    {
263
264    asm volatile("mfmsr 3; oris 3,3,4; sync; mtmsr 3; isync; ori 3,3,0; ori 3,3,0");
265
266    }
267
268  return 0;
269
270  }
271
Note: See TracBrowser for help on using the repository browser.