source: rtems/c/src/lib/libbsp/powerpc/gen83xx/startup/bspstart.c @ 07e9642c

4.104.114.9
Last change on this file since 07e9642c was 07e9642c, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 28, 2007 at 9:44:46 PM

2007-11-28 Joel Sherrill <joel.sherrill@…>

  • startup/bspstart.c: Eliminate PowerPC specific elements from the CPU Table. They have been replaced with variables named bsp_XXX as needed.
  • 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 *  Driver configuration parameters
66 */
67uint32_t   bsp_clicks_per_usec;
68
69/*
70 *  Use the shared implementations of the following routines.
71 *  Look in rtems/c/src/lib/libbsp/shared/bsppost.c and
72 *  rtems/c/src/lib/libbsp/shared/bsplibc.c.
73 */
74void bsp_postdriver_hook(void);
75void bsp_libc_init( void *, uint32_t, int );
76extern void initialize_exceptions(void);
77extern void cpu_init(void);
78
79void BSP_panic(char *s)
80  {
81  printk("%s PANIC %s\n",_RTEMS_version, s);
82  /*
83   * FIXME: hang/restart system
84   */
85  __asm__ __volatile ("sc");
86  }
87
88void _BSP_Fatal_error(unsigned int v)
89  {
90  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
91  /*
92   * FIXME: hang/restart system
93   */
94  __asm__ __volatile ("sc");
95  }
96
97/*
98 *  Function:   bsp_pretasking_hook
99 *  Created:    95/03/10
100 *
101 *  Description:
102 *      BSP pretasking hook.  Called just before drivers are initialized.
103 *      Used to setup libc and install any BSP extensions.
104 *
105 *  NOTES:
106 *      Must not use libc (to do io) from here, since drivers are
107 *      not yet initialized.
108 *
109 */
110
111void
112bsp_pretasking_hook(void)
113{
114
115  /*
116   * initialize libc including the heap
117   */
118  bsp_libc_init( BSP_heap_start, 
119                 BSP_heap_end - BSP_heap_start,
120                 0);
121
122
123#ifdef STACK_CHECKER_ON
124  /*
125   *  Initialize the stack bounds checker
126   *  We can either turn it on here or from the app.
127   */
128
129  Stack_check_Initialize();
130#endif
131
132#ifdef RTEMS_DEBUG
133  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
134#endif
135}
136
137
138
139void bsp_predriver_hook(void)
140{
141}
142
143void bsp_calc_mem_layout()
144{
145  /*
146   * these labels (!) are defined in the linker command file
147   * or when the linker is invoked
148   * NOTE: the information(size) is the address of the object,
149   * not the object otself
150   */
151  extern unsigned char TopRamReserved;
152  extern unsigned char _WorkspaceBase[];
153
154  /*
155   * compute the memory layout:
156   * - first unused address is Workspace start
157   * - Heap starts at end of workspace
158   * - Heap ends at end of memory - reserved memory area
159   */
160  BSP_Configuration.work_space_start = _WorkspaceBase;
161
162  BSP_heap_start = ((char *)BSP_Configuration.work_space_start +
163                    BSP_Configuration.work_space_size);
164
165#if defined(HAS_UBOOT)
166  BSP_heap_end = (uboot_bdinfo_ptr->bi_memstart
167                  + uboot_bdinfo_ptr->bi_memsize
168                  - (uint32_t)&TopRamReserved);
169#else
170  BSP_heap_end = (void *)(RAM_END - (uint32_t)&TopRamReserved);
171#endif
172
173}
174
175
176void bsp_start(void)
177{
178  ppc_cpu_id_t myCpu;
179  ppc_cpu_revision_t myCpuRevision;
180  register unsigned char* intrStack;
181
182  /*
183   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
184   * store the result in global variables so that it can be used latter...
185   */
186  myCpu             = get_ppc_cpu_type();
187  myCpuRevision = get_ppc_cpu_revision();
188  /*
189   * determine heap and workspace placement
190   */
191  bsp_calc_mem_layout();
192
193  cpu_init();
194
195  /*
196   * Initialize some SPRG registers related to irq handling
197   */
198
199  intrStack = (((unsigned char*)&intrStackPtr) - PPC_MINIMUM_STACK_FRAME_SIZE);
200
201  _write_SPRG1((unsigned int)intrStack);
202
203  /* Signal them that this BSP has fixed PR288 - eventually, this should go away */
204  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
205
206  /*
207   *  initialize the CPU table for this BSP
208   */
209
210  Cpu_table.pretasking_hook        = bsp_pretasking_hook;    /* init libc, etc. */
211  Cpu_table.predriver_hook         = bsp_predriver_hook;     /* init PCI / RTC ...   */
212  Cpu_table.postdriver_hook        = bsp_postdriver_hook;
213  Cpu_table.exceptions_in_RAM      = TRUE;
214
215  if( Cpu_table.interrupt_stack_size < 4*1024 )
216    Cpu_table.interrupt_stack_size = 4 * 1024;
217
218  bsp_clicks_per_usec        = (BSP_CSB_CLK_FRQ/1000000);
219
220  /*
221   * Install our own set of exception vectors
222   */
223
224  initialize_exceptions();
225
226  /*
227   * Enable instruction and data caches. Do not force writethrough mode.
228   */
229#if INSTRUCTION_CACHE_ENABLE
230  rtems_cache_enable_instruction();
231#endif
232#if DATA_CACHE_ENABLE
233  rtems_cache_enable_data();
234#endif
235
236  /*
237   *  Allocate the memory for the RTEMS Work Space.  This can come from
238   *  a variety of places: hard coded address, malloc'ed from outside
239   *  RTEMS world (e.g. simulator or primitive memory manager), or (as
240   *  typically done by stock BSPs) by subtracting the required amount
241   *  of work space from the last physical address on the CPU board.
242   */
243
244  /*
245   * Initalize RTEMS IRQ system
246   */
247  BSP_rtems_irq_mng_init(0);
248
249#ifdef SHOW_MORE_INIT_SETTINGS
250  printk("Exit from bspstart\n");
251#endif
252
253  }
254
255/*
256 *
257 *  _Thread_Idle_body
258 *
259 *  Replaces the one in c/src/exec/score/src/threadidlebody.c
260 *  The MSR[POW] bit is set to put the CPU into the low power mode
261 *  defined in HID0.  HID0 is set during starup in start.S.
262 *
263 */
264Thread _Thread_Idle_body(uint32_t ignored )
265  {
266
267  for(;;)
268    {
269
270    asm volatile("mfmsr 3; oris 3,3,4; sync; mtmsr 3; isync; ori 3,3,0; ori 3,3,0");
271
272    }
273
274  return 0;
275
276  }
277
Note: See TracBrowser for help on using the repository browser.