source: rtems/c/src/lib/libbsp/powerpc/shared/startup/bspstart.c @ e79a1947

4.104.114.84.95
Last change on this file since e79a1947 was e79a1947, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 10, 2004 at 11:51:17 PM

2004-11-10 Richard Campbell <richard.campbell@…>

  • Makefile.am, bootloader/misc.c, bootloader/pci.c, bootloader/pci.h, console/console.c, console/inch.c, console/reboot.c, console/uart.c, console/uart.h, irq/irq.c, irq/irq.h, irq/irq_init.c, motorola/motorola.c, motorola/motorola.h, openpic/openpic.c, openpic/openpic.h, pci/detect_raven_bridge.c, pci/pci.c, start/start.S, startup/bspstart.c, vectors/vectors_init.c, vme/vmeconfig.c: Add MVME2100 BSP and MPC8240 support. There was also a significant amount of spelling and whitespace cleanup.
  • tod/todcfg.c: New file.
  • Property mode set to 100644
File size: 14.8 KB
Line 
1/*
2 *  This routine starts the application.  It includes application,
3 *  board, and monitor specific initialization and configuration.
4 *  The generic CPU dependent initialization has been performed
5 *  before this routine is invoked.
6 *
7 *  COPYRIGHT (c) 1989-1998.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *  Modified to support the MCP750.
15 *  Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
16 *
17 *  $Id$
18 */
19
20#include <string.h>
21
22#include <bsp.h>
23#include <rtems/libio.h>
24#include <rtems/libcsupport.h>
25#include <bsp/consoleIo.h>
26#include <libcpu/spr.h>
27#include <bsp/residual.h>
28#include <bsp/pci.h>
29#include <bsp/openpic.h>
30#include <bsp/irq.h>
31#include <bsp/VME.h>
32#include <libcpu/bat.h>
33#include <libcpu/pte121.h>
34#include <libcpu/cpuIdent.h>
35#include <bsp/vectors.h>
36#include <bsp/motorola.h>
37
38extern void _return_to_ppcbug();
39extern unsigned long __rtems_end[];
40extern void L1_caches_enables();
41extern unsigned get_L2CR();
42extern void set_L2CR(unsigned);
43extern void bsp_cleanup(void);
44extern Triv121PgTbl BSP_pgtbl_setup();
45extern void                     BSP_pgtbl_activate();
46extern void                     BSP_vme_config();
47
48SPR_RW(SPRG0)
49SPR_RW(SPRG1)
50
51#if defined(DEBUG_BATS)
52void printBAT( int bat, unsigned32 upper, unsigned32 lower )
53{
54  unsigned32 lowest_addr;
55  unsigned32 size;
56
57  printk("BAT%d raw(upper=0x%08x, lower=0x%08x) ", bat, upper, lower );
58
59  lowest_addr = (upper & 0xFFFE0000);
60  size = (((upper & 0x00001FFC) >> 2) + 1) * (128 * 1024);
61  printk(" range(0x%08x, 0x%08x) %s%s %s%s%s%s %s\n",
62    lowest_addr,
63    lowest_addr + (size - 1),
64    (upper & 0x01) ? "P" : "p",
65    (upper & 0x02) ? "S" : "s",
66    (lower & 0x08) ? "G" : "g",
67    (lower & 0x10) ? "M" : "m",
68    (lower & 0x20) ? "I" : "i",
69    (lower & 0x40) ? "W" : "w",
70    (lower & 0x01) ? "Read Only" :
71      ((lower & 0x02) ? "Read/Write" : "No Access")
72  );
73}
74
75void ShowBATS(){
76  unsigned32 lower;
77  unsigned32 upper;
78
79  __MFSPR(536, upper); __MFSPR(537, lower); printBAT( 0, upper, lower );
80  __MFSPR(538, upper); __MFSPR(539, lower); printBAT( 1, upper, lower );
81  __MFSPR(540, upper); __MFSPR(541, lower); printBAT( 2, upper, lower );
82  __MFSPR(542, upper); __MFSPR(543, lower); printBAT( 3, upper, lower );
83}
84#endif
85
86/*
87 * Copy of residuals passed by firmware
88 */
89RESIDUAL residualCopy;
90/*
91 * Copy Additional boot param passed by boot loader
92 */
93#define MAX_LOADER_ADD_PARM 80
94char loaderParam[MAX_LOADER_ADD_PARM];
95/*
96 * Vital Board data Start using DATA RESIDUAL
97 */
98/*
99 * Total memory using RESIDUAL DATA
100 */
101unsigned int BSP_mem_size;
102/*
103 * PCI Bus Frequency
104 */
105unsigned int BSP_bus_frequency;
106/*
107 * processor clock frequency
108 */
109unsigned int BSP_processor_frequency;
110/*
111 * Time base divisior (how many tick for 1 second).
112 */
113unsigned int BSP_time_base_divisor;
114/*
115 * system init stack and soft ir stack size
116 */
117#define INIT_STACK_SIZE 0x1000
118#define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY
119
120void BSP_panic(char *s)
121{
122  printk("%s PANIC %s\n",_RTEMS_version, s);
123  __asm__ __volatile ("sc");
124}
125
126void _BSP_Fatal_error(unsigned int v)
127{
128  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
129  __asm__ __volatile ("sc");
130}
131
132/*
133 *  The original table from the application and our copy of it with
134 *  some changes.
135 */
136
137extern rtems_configuration_table Configuration;
138
139rtems_configuration_table  BSP_Configuration;
140
141rtems_cpu_table Cpu_table;
142
143char *rtems_progname;
144
145/*
146 *  Use the shared implementations of the following routines
147 */
148
149void bsp_postdriver_hook(void);
150void bsp_libc_init( void *, uint32_t, int );
151
152/*
153 *  Function:   bsp_pretasking_hook
154 *  Created:    95/03/10
155 *
156 *  Description:
157 *      BSP pretasking hook.  Called just before drivers are initialized.
158 *      Used to setup libc and install any BSP extensions.
159 *
160 *  NOTES:
161 *      Must not use libc (to do io) from here, since drivers are
162 *      not yet initialized.
163 *
164 */
165
166void bsp_pretasking_hook(void)
167{
168  rtems_unsigned32        heap_start;   
169  rtems_unsigned32        heap_size;
170  rtems_unsigned32        heap_sbrk_spared;
171  extern rtems_unsigned32 _bsp_sbrk_init(rtems_unsigned32, rtems_unsigned32*);
172
173  heap_start = ((rtems_unsigned32) __rtems_end) +
174                INIT_STACK_SIZE + INTR_STACK_SIZE;
175  if (heap_start & (CPU_ALIGNMENT-1))
176      heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
177
178  heap_size = (BSP_mem_size - heap_start) - BSP_Configuration.work_space_size;
179  heap_sbrk_spared=_bsp_sbrk_init(heap_start, &heap_size);
180
181#ifdef SHOW_MORE_INIT_SETTINGS
182  printk( "HEAP start %x  size %x (%x bytes spared for sbrk)\n",
183             heap_start, heap_size, heap_sbrk_spared);
184#endif   
185
186  bsp_libc_init((void *) 0, heap_size, heap_sbrk_spared);
187
188#ifdef RTEMS_DEBUG
189  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
190#endif
191}
192
193void zero_bss()
194{
195  /* prevent these from being accessed in the short data areas */
196  extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[];
197  extern unsigned long __SBSS2_START__[], __SBSS2_END__[];
198  memset(__SBSS_START__, 0, ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__));
199  memset(__SBSS2_START__, 0, ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__));
200  memset(__bss_start, 0, ((unsigned) __rtems_end) - ((unsigned)__bss_start));
201}
202
203void save_boot_params(RESIDUAL* r3, void *r4, void* r5, char *additional_boot_options)
204{
205
206  residualCopy = *r3;
207  strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM);
208  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
209}
210
211#if defined(mpc8240) || defined(mpc8245)
212unsigned int EUMBBAR;
213
214/*
215 * Return the current value of the Embedded Utilities Memory Block Base Address
216 * Register (EUMBBAR) as read from the processor configuration register using
217 * Processor Address Map B (CHRP).
218 */ 
219unsigned int get_eumbbar() {
220  register int a, e;
221
222  asm volatile( "lis %0,0xfec0; ori  %0,%0,0x0000": "=r" (a) );
223  asm volatile("sync");
224                                                               
225  asm volatile("lis %0,0x8000; ori %0,%0,0x0078": "=r"(e) ); 
226  asm volatile("stwbrx  %0,0x0,%1": "=r"(e): "r"(a)); 
227  asm volatile("sync");
228
229  asm volatile("lis %0,0xfee0; ori %0,%0,0x0000": "=r" (a) ); 
230  asm volatile("sync");
231                                                         
232  asm volatile("lwbrx %0,0x0,%1": "=r" (e): "r" (a));
233  asm volatile("isync");
234  return e;
235}
236#endif
237
238/*
239 *  bsp_start
240 *
241 *  This routine does the bulk of the system initialization.
242 */
243
244void bsp_start( void )
245{
246  unsigned char *stack;
247#if !defined(mpc8240) && !defined(mpc8245)
248  unsigned l2cr;
249#endif
250  register unsigned char* intrStack;
251  unsigned char *work_space_start;
252  ppc_cpu_id_t myCpu;
253  ppc_cpu_revision_t myCpuRevision;
254  prep_t boardManufacturer;
255  motorolaBoard myBoard;
256  Triv121PgTbl  pt=0;
257
258  /*
259   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
260   * function store the result in global variables so that it can be used
261   * later...
262   */
263  myCpu         = get_ppc_cpu_type();
264  myCpuRevision = get_ppc_cpu_revision();
265
266#if defined(mvme2100)
267  EUMBBAR = get_eumbbar(); 
268
269  Cpu_table.exceptions_in_RAM    = TRUE;
270  { unsigned v = 0x3000 ; _CPU_MSR_SET(v); }
271#endif
272
273#if !defined(mpc8240) && !defined(mpc8245)
274  /*
275   * enables L1 Cache. Note that the L1_caches_enables() codes checks for
276   * relevant CPU type so that the reason why there is no use of myCpu...
277   */
278  L1_caches_enables();
279
280  /*
281   * Enable L2 Cache. Note that the set_L2CR(L2CR) codes checks for
282   * relevant CPU type (mpc750)...
283   */
284  l2cr = get_L2CR();
285#ifdef SHOW_LCR2_REGISTER
286  printk("Initial L2CR value = %x\n", l2cr);
287#endif
288  if ( (! (l2cr & 0x80000000)) && ((int) l2cr == -1))
289    set_L2CR(0xb9A14000);
290#endif
291
292  /*
293   * the initial stack  has aready been set to this value in start.S
294   * so there is no need to set it in r1 again... It is just for info
295   * so that It can be printed without accessing R1.
296   */
297  stack = ((unsigned char*) __rtems_end) +
298               INIT_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
299
300  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
301  *((uint32_t*)stack) = 0;
302
303  /*
304   * Initialize the interrupt related settings
305   * SPRG1 = software managed IRQ stack
306   *
307   * This could be done later (e.g in IRQ_INIT) but it helps to understand
308   * some settings below...
309   */
310  intrStack = ((unsigned char*) __rtems_end) +
311    INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
312
313  /* make sure it's properly aligned */
314  (uint32_t)intrStack &= ~(CPU_STACK_ALIGNMENT-1);
315
316  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
317  *((uint32_t*)intrStack) = 0;
318
319  _write_SPRG1((unsigned int)intrStack);
320
321  /* signal them that we have fixed PR288 - eventually, this should go away */
322  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
323
324  /*
325   * Initialize default raw exception handlers. See vectors/vectors_init.c
326   */
327  initialize_exceptions();
328
329  /*
330   * Init MMU block address translation to enable hardware access
331   */
332
333#if !defined(mvme2100)
334  /*
335   * PC legacy IO space used for inb/outb and all PC compatible hardware
336   */
337  setdbat(1, _IO_BASE, _IO_BASE, 0x10000000, IO_PAGE);
338#endif
339
340  /*
341   * PCI devices memory area. Needed to access OpenPIC features
342   * provided by the Raven
343   *
344   * T. Straumann: give more PCI address space
345   */
346  setdbat(2, PCI_MEM_BASE, PCI_MEM_BASE, 0x10000000, IO_PAGE);
347
348  /*
349   * Must have acces to open pic PCI ACK registers provided by the RAVEN
350   */
351  setdbat(3, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
352
353  select_console(CONSOLE_LOG);
354
355  /*
356   * We check that the keyboard is present and immediately
357   * select the serial console if not.
358   */
359#if defined(BSP_KBD_IOBASE)
360  { int err;
361    err = kbdreset();
362    if (err) select_console(CONSOLE_SERIAL);
363  }
364#else
365  select_console(CONSOLE_SERIAL);
366#endif
367
368  boardManufacturer   =  checkPrepBoardType(&residualCopy);
369  if (boardManufacturer != PREP_Motorola) {
370    printk("Unsupported hardware vendor\n");
371    while (1);
372  }
373  myBoard = getMotorolaBoard();
374
375  printk("-----------------------------------------\n");
376  printk("Welcome to %s on %s\n", _RTEMS_version,
377                                    motorolaBoardToString(myBoard));
378  printk("-----------------------------------------\n");
379#ifdef SHOW_MORE_INIT_SETTINGS
380  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
381  printk("Additionnal boot options are %s\n", loaderParam);
382  printk("Initial system stack at %x\n",stack);
383  printk("Software IRQ stack at %x\n",intrStack);
384  printk("-----------------------------------------\n");
385#endif
386
387#ifdef TEST_RETURN_TO_PPCBUG
388  printk("Hit <Enter> to return to PPCBUG monitor\n");
389  printk("When Finished hit GO. It should print <Back from monitor>\n");
390  debug_getc();
391  _return_to_ppcbug();
392  printk("Back from monitor\n");
393  _return_to_ppcbug();
394#endif /* TEST_RETURN_TO_PPCBUG  */
395
396#ifdef SHOW_MORE_INIT_SETTINGS
397  printk("Going to start PCI buses scanning and initialization\n");
398#endif
399  InitializePCI();
400
401  {
402    const struct _int_map *bspmap  = motorolaIntMap(currentBoard);
403    if( bspmap ) {
404       printk("pci : Configuring interrupt routing for '%s'\n",
405          motorolaBoardToString(currentBoard));
406       FixupPCI(bspmap, motorolaIntSwizzle(currentBoard));
407    }
408    else
409       printk("pci : Interrupt routing not available for this bsp\n");
410 }
411
412#ifdef SHOW_MORE_INIT_SETTINGS
413  printk("Number of PCI buses found is : %d\n", BusCountPCI());
414#endif
415#ifdef TEST_RAW_EXCEPTION_CODE
416  printk("Testing exception handling Part 1\n");
417  /*
418   * Cause a software exception
419   */
420  __asm__ __volatile ("sc");
421  /*
422   * Check we can still catch exceptions and return coorectly.
423   */
424  printk("Testing exception handling Part 2\n");
425  __asm__ __volatile ("sc");
426
427  /*
428   *  Somehow doing the above seems to clobber SPRG0 on the mvme2100.  It
429   *  is probably a not so subtle hint that you do not want to use PPCBug
430   *  once RTEMS is up and running.  Anyway, we still needs to indicate
431   *  that we have fixed PR288.  Eventually, this should go away.
432   */
433  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
434#endif
435
436  BSP_mem_size            = residualCopy.TotalMemory;
437  BSP_bus_frequency       = residualCopy.VitalProductData.ProcessorBusHz;
438  BSP_processor_frequency = residualCopy.VitalProductData.ProcessorHz;
439  BSP_time_base_divisor   = (residualCopy.VitalProductData.TimeBaseDivisor?
440                    residualCopy.VitalProductData.TimeBaseDivisor : 4000);
441
442  /* clear hostbridge errors but leave MCP disabled -
443   * PCI config space scanning code will trip otherwise :-(
444   */
445  _BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
446
447  /* Allocate and set up the page table mappings
448   * This is only available on >604 CPUs.
449   *
450   * NOTE: This setup routine may modify the available memory
451   *       size. It is essential to call it before
452   *       calculating the workspace etc.
453   */
454  pt = BSP_pgtbl_setup(&BSP_mem_size);
455
456  if (!pt || TRIV121_MAP_SUCCESS != triv121PgTblMap(
457            pt, TRIV121_121_VSID, 0xfeff0000, 1,
458            TRIV121_ATTR_IO_PAGE, TRIV121_PP_RW_PAGE)) {
459        printk("WARNING: unable to setup page tables VME "
460               "bridge must share PCI space\n");
461  }
462
463  /*
464   * Set up our hooks
465   * Make sure libc_init is done before drivers initialized so that
466   * they can use atexit()
467   */
468
469  Cpu_table.pretasking_hook      = bsp_pretasking_hook;    /* init libc, etc. */
470  Cpu_table.postdriver_hook      = bsp_postdriver_hook;
471  Cpu_table.do_zero_of_workspace = TRUE;
472  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
473  Cpu_table.clicks_per_usec      = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
474  Cpu_table.exceptions_in_RAM    = TRUE;
475
476#ifdef SHOW_MORE_INIT_SETTINGS
477  printk("BSP_Configuration.work_space_size = %x\n",
478          BSP_Configuration.work_space_size);
479#endif
480
481  work_space_start =
482    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
483
484  if ( work_space_start <=
485       ((unsigned char *)__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
486    printk( "bspstart: Not enough RAM!!!\n" );
487    bsp_cleanup();
488  }
489
490  BSP_Configuration.work_space_start = work_space_start;
491
492  /*
493   * Initalize RTEMS IRQ system
494   */
495  BSP_rtems_irq_mng_init(0);
496
497  /* Activate the page table mappings only after
498   * initializing interrupts because the irq_mng_init()
499   * routine needs to modify the text
500   */
501  if (pt) {
502#ifdef  SHOW_MORE_INIT_SETTINGS
503    printk("Page table setup finished; will activate it NOW...\n");
504#endif
505    BSP_pgtbl_activate(pt);
506#if !defined(mvme2100)
507    /* finally, switch off DBAT3 */
508    setdbat(3, 0, 0, 0, 0); 
509#endif
510  }
511
512  /*
513   * Initialize VME bridge - needs working PCI and IRQ subsystems...
514   */
515#ifdef SHOW_MORE_INIT_SETTINGS
516  printk("Going to initialize VME bridge\n");
517#endif
518  /*
519   * VME initialization is in a separate file so apps which don't use VME or
520   * want a different configuration may link against a customized routine.
521   */
522  BSP_vme_config();
523
524#if defined(DEBUG_BATS)
525  ShowBATS();
526#endif
527
528#ifdef SHOW_MORE_INIT_SETTINGS
529  printk("Exit from bspstart\n");
530#endif
531}
Note: See TracBrowser for help on using the repository browser.