source: rtems/c/src/lib/libbsp/powerpc/score603e/startup/bspstart.c @ 40e7ae2

4.104.114.95
Last change on this file since 40e7ae2 was 40e7ae2, checked in by Joel Sherrill <joel.sherrill@…>, on 09/03/08 at 20:36:21

2008-09-03 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, README, configure.ac, console/85c30.c, console/console.c, console/consolebsp.h, include/bsp.h, include/gen2.h, irq/FPGA.c, irq/irq.c, irq/irq.h, irq/irq_init.c, start/start.S, startup/bspstart.c, startup/genpvec.c, startup/linkcmds, timer/timer.c, tod/tod.c: Initiate update and testing. Runs hello but does not run ticker yet.
  • Property mode set to 100644
File size: 9.0 KB
Line 
1/*  bspstart.c
2 *
3 *  This set of routines starts the application.  It includes application,
4 *  board, and monitor specific initialization and configuration.
5 *  The generic CPU dependent initialization has been performed
6 *  before any of these are invoked.
7 *
8 *  COPYRIGHT (c) 1989-2007.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may in
12 *  the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id:
16 */
17
18#include <string.h>
19
20#include <bsp.h>
21#include <rtems/libio.h>
22#include <rtems/libcsupport.h>
23#include <rtems/bspIo.h>
24#include <libcpu/cpuIdent.h>
25#define DEBUG 1
26
27/*
28 * Where the heap starts; is used by bsp_pretasking_hook;
29 */
30unsigned int BSP_heap_start;
31
32/*
33 * PCI Bus Frequency
34 */
35unsigned int BSP_bus_frequency;  /* XXX - Set this based upon the Score board */
36
37/*
38 * processor clock frequency
39 */
40unsigned int BSP_processor_frequency; /* XXX - Set this based upon the Score board */
41
42/*
43 * Time base divisior (how many tick for 1 second).
44 */
45unsigned int BSP_time_base_divisor = 1000;  /* XXX - Just a guess */
46
47/*
48 * system init stack
49 */
50#define INIT_STACK_SIZE 0x1000
51
52extern unsigned long __rtems_end[];
53
54
55/*
56 *  Driver configuration parameters
57 */
58uint32_t   bsp_clicks_per_usec;
59
60void BSP_panic(char *s)
61{
62  printk("%s PANIC %s\n",_RTEMS_version, s);
63  __asm__ __volatile ("sc");
64}
65
66void _BSP_Fatal_error(unsigned int v)
67{
68  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
69  __asm__ __volatile ("sc");
70}
71
72/*
73 *  Use the shared implementations of the following routines
74 */
75
76void bsp_postdriver_hook(void);
77void bsp_libc_init( void *, uint32_t, int );
78
79/*PAGE
80 *
81 *  bsp_pretasking_hook
82 *
83 *  BSP pretasking hook.  Called just before drivers are initialized.
84 *  Used to setup libc and install any BSP extensions.
85 */
86
87void bsp_pretasking_hook(void)
88{
89  extern int end;
90  uint32_t         heap_start;
91  uint32_t         heap_size;
92
93  #if DEBUG
94    printk("bsp_pretasking_hook: Set Heap\n");
95  #endif
96  heap_start = (uint32_t) &end;
97  if (heap_start & (CPU_ALIGNMENT-1))
98    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
99
100  heap_size = Configuration.work_space_start - (void *)&end;
101  heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
102
103  #if DEBUG
104    printk("bsp_pretasking_hook: bsp_libc_init\n");
105  #endif
106  bsp_libc_init((void *) heap_start, heap_size, 0);
107  #if DEBUG
108    printk("bsp_pretasking_hook: End of routine\n");
109  #endif
110}
111
112/*PAGE
113 *
114 *  bsp_predriver_hook
115 *
116 *  Before drivers are setup initialize interupt vectors.
117 */
118
119void init_RTC();
120void initialize_PMC();
121
122void bsp_predriver_hook(void)
123{
124  #if DEBUG
125    printk("bsp_predriver_hook: init_RTC\n");
126  #endif
127  init_RTC();
128  init_PCI();
129  initialize_universe();
130
131  #if DEBUG
132    printk("bsp_predriver_hook: initialize_PCI_bridge\n");
133  #endif
134  initialize_PCI_bridge ();
135
136#if (HAS_PMC_PSC8)
137  #if DEBUG
138    printk("bsp_predriver_hook: initialize_PMC\n");
139  #endif
140  initialize_PMC();
141#endif
142
143#if 0
144 /*
145  * Initialize Bsp General purpose vector table.
146  */
147  #if DEBUG
148    printk("bsp_predriver_hook: initialize_external_exception_vector\n");
149  #endif
150 initialize_external_exception_vector();
151#endif
152
153#if (0)
154  /*
155   * XXX - Modify this to write a 48000000 (loop to self) command
156   *       to each interrupt location.  This is better for debug.
157   */
158  #if DEBUG
159    printk("bsp_predriver_hook: bsp_spurious_initialize\n");
160  #endif
161 bsp_spurious_initialize();
162#endif
163
164  ShowBATS();
165
166  #if DEBUG
167    printk("bsp_predriver_hook: End of routine\n");
168  #endif
169
170}
171
172/*PAGE
173 *
174 *  initialize_PMC
175 */
176
177void initialize_PMC() {
178  volatile uint32_t         *PMC_addr;
179  uint8_t          data;
180
181#if (0) /* First Values sent */
182  /*
183   * set PMC base address.
184   */
185  PMC_addr  = BSP_PCI_DEVICE_ADDRESS( 0x14 );
186  *PMC_addr = (BSP_PCI_REGISTER_BASE >> 24) & 0x3f;
187
188  /*
189   * Clear status, enable SERR and memory space only.
190   */
191  PMC_addr = BSP_PCI_DEVICE_ADDRESS( 0x4 );
192  *PMC_addr = 0x0201ff37;
193
194  /*
195   * Bit 0 and 1 HI cause Medium Loopback to occur.
196   */
197  PMC_addr = (volatile uint32_t*)
198        BSP_PMC_SERIAL_ADDRESS( 0x100000 );
199  data = *PMC_addr;
200  /*   *PMC_addr = data | 0x3;  */
201  *PMC_addr = data & 0xfc;
202
203#endif
204
205#if (1)
206
207  /*
208   * Clear status, enable SERR and memory space only.
209   */
210  #if DEBUG
211    printk("initialize_PMC: set Device Address 0x4 \n");
212  ShowBATS();
213  #endif
214  PMC_addr = BSP_PCI_DEVICE_ADDRESS( 0x4 );
215  *PMC_addr = 0x020080cc;
216
217  /*
218   * set PMC base address.
219   */
220  #if DEBUG
221    printk("initialize_PMC: set Device Address 0x14 \n");
222  ShowBATS();
223  #endif
224  PMC_addr  = BSP_PCI_DEVICE_ADDRESS( 0x14 );
225  *PMC_addr = (BSP_PCI_REGISTER_BASE >> 24) & 0x3f;
226
227  #if DEBUG
228    printk("initialize_PMC: set PMC Serial Address 0x100000\n");
229  #endif
230   PMC_addr = (volatile uint32_t*)
231      BSP_PMC_SERIAL_ADDRESS( 0x100000 );
232  data = *PMC_addr;
233  *PMC_addr = data & 0xfc;
234
235#endif
236}
237
238/*PAGE
239 *
240 *  bsp_postdriver_hook
241 *
242 *  Standard post driver hook plus some BSP specific stuff.
243 */
244
245void bsp_postdriver_hook(void)
246{
247  extern void Init_EE_mask_init(void);
248  extern void open_dev_console(void);
249
250  #if DEBUG
251    printk("bsp_postdriver_hook: open_dev_console\n");
252  #endif
253  open_dev_console();
254  ShowBATS();
255
256  #if DEBUG
257    printk("bsp_postdriver_hook: Init_EE_mask_init\n");
258  #endif
259  Init_EE_mask_init();
260  ShowBATS();
261  #if DEBUG
262    printk("bsp_postdriver_hook: Finished procedure\n");
263  #endif
264}
265
266void bsp_set_trap_vectors( void );
267
268/*PAGE
269 *
270 *  bsp_start
271 *
272 *  This routine does the bulk of the system initialization.
273 */
274
275void bsp_start( void )
276{
277  unsigned char *work_space_start;
278  unsigned int  msr_value = 0x0000;
279  uint32_t      intrStackStart;
280  uint32_t      intrStackSize;
281  volatile uint32_t         *ptr;
282  ppc_cpu_id_t myCpu;
283  ppc_cpu_revision_t myCpuRevision;
284 
285  rtems_bsp_delay( 1000 );
286
287  /*
288   *  Zero out lots of memory
289   */
290  #if DEBUG
291    printk("bsp_start: Zero out lots of memory\n");
292    ShowBATS();
293  #endif
294
295  memset(
296    &end,
297    0,
298    (unsigned char *)&RAM_END - (unsigned char *) &end
299  );
300
301  BSP_processor_frequency = 266000000;
302  BSP_bus_frequency       =  66000000;
303
304  /*
305   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
306   * function store the result in global variables so that it can be used
307   * later...
308   */
309  myCpu         = get_ppc_cpu_type();
310  myCpuRevision = get_ppc_cpu_revision();
311
312  /*
313   * Initialize the interrupt related settings.
314   */
315  intrStackStart = (uint32_t) __rtems_end + INIT_STACK_SIZE;
316  intrStackSize = rtems_configuration_get_interrupt_stack_size();
317  BSP_heap_start = intrStackStart + intrStackSize;
318
319  /*
320   * Initialize default raw exception handlers.
321   */
322printk("ppc_exc_initialize\n");
323  ppc_exc_initialize(
324    PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
325    intrStackStart,
326    intrStackSize
327  );
328
329  /*
330   *  There are multiple ROM monitors available for this board.
331   */
332#if (SCORE603E_USE_SDS)
333  #if DEBUG
334    printk("bsp_start: USE SDS\n");
335  #endif
336
337
338  /*
339   * Write instruction for Unconditional Branch to ROM vector.
340   */
341
342   Code = 0x4bf00002;
343   for (Address = 0x100; Address <= 0xe00; Address += 0x100) {
344     A_Vector = (uint32_t*)Address;
345     Code = 0x4bf00002 + Address;
346     *A_Vector = Code;
347   }
348
349   for (Address = 0x1000; Address <= 0x1400; Address += 0x100) {
350     A_Vector = (uint32_t*)Address;
351     Code = 0x4bf00002 + Address;
352     *A_Vector = Code;
353   }
354
355  msr_value = 0x2030;
356
357#elif (SCORE603E_USE_OPEN_FIRMWARE)
358  #if DEBUG
359    printk("bsp_start: USE OPEN FIRMWARE\n");
360  #endif
361  msr_value = 0x2030;
362
363#elif (SCORE603E_USE_NONE)
364  #if DEBUG
365    printk("bsp_start: USE NONE\n");
366  #endif
367  msr_value = 0x2030;
368  _CPU_MSR_SET( msr_value );
369  bsp_set_trap_vectors();
370
371#elif (SCORE603E_USE_DINK)
372  #if DEBUG
373    printk("bsp_start: USE DINK\n");
374  #endif
375  msr_value = 0x2030;
376  _CPU_MSR_SET( msr_value );
377
378  /*
379   * Override the DINK error on a Decrementor interrupt.
380   */
381  /* org    dec_vector  - rfi */
382  ptr = (uint32_t*)0x900;
383  *ptr = 0x4c000064;
384
385#else
386  #if DEBUG
387    printk("bsp_start: ERROR unknow ROM Monitor\n");
388  #endif
389#error "SCORE603E BSPSTART.C -- what ROM monitor are you using"
390#endif
391
392  _CPU_MSR_SET( msr_value );
393
394  /*
395   *  Need to "allocate" the memory for the RTEMS Workspace and
396   *  tell the RTEMS configuration where it is.  This memory is
397   *  not malloc'ed.  It is just "pulled from the air".
398   */
399
400  #if DEBUG
401    printk("bsp_start: Calculate Wrokspace\n");
402  #endif
403  work_space_start =
404    (unsigned char *)&RAM_END - rtems_configuration_get_work_space_size();
405
406  if ( work_space_start <= (unsigned char *)&end ) {
407    printk( "bspstart: Not enough RAM!!!\n" );
408    bsp_cleanup();
409  }
410
411  Configuration.work_space_start = work_space_start;
412
413  /*
414   *  initialize the device driver parameters
415   */
416  #if DEBUG
417    printk("bsp_start: set clicks poer usec\n");
418  #endif
419  bsp_clicks_per_usec = 66 / 4;  /* XXX get from linkcmds */
420
421#if ( PPC_USE_DATA_CACHE )
422  #if DEBUG
423    printk("bsp_start: cache_enable\n");
424  #endif
425  instruction_cache_enable ();
426  data_cache_enable ();
427  #if DEBUG
428    printk("bsp_start: END PPC_USE_DATA_CACHE\n");
429  #endif
430#endif
431  #if DEBUG
432    printk("bsp_start: end BSPSTART\n");
433  ShowBATS();
434  #endif
435}
Note: See TracBrowser for help on using the repository browser.