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

4.104.114.84.95
Last change on this file since bde7f268 was bde7f268, checked in by Ralf Corsepius <ralf.corsepius@…>, on Mar 31, 2004 at 3:52:40 AM

2004-03-31 Ralf Corsepius <ralf_corsepius@…>

  • bootloader/misc.c, bootloader/pci.c, console/inch.c, include/bsp.h, pci/pci.c, startup/bspstart.c, startup/sbrk.c: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 12.2 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 <rtems/libio.h>
23#include <rtems/libcsupport.h>
24#include <bsp/consoleIo.h>
25#include <libcpu/spr.h>
26#include <bsp/residual.h>
27#include <bsp/pci.h>
28#include <bsp/openpic.h>
29#include <bsp/irq.h>
30#include <bsp/VME.h>
31#include <bsp.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/*
52 * Copy of residuals passed by firmware
53 */
54RESIDUAL residualCopy; 
55/*
56 * Copy Additional boot param passed by boot loader
57 */
58#define MAX_LOADER_ADD_PARM 80
59char loaderParam[MAX_LOADER_ADD_PARM];
60/*
61 * Vital Board data Start using DATA RESIDUAL
62 */
63/*
64 * Total memory using RESIDUAL DATA
65 */
66unsigned int BSP_mem_size;
67/*
68 * PCI Bus Frequency
69 */
70unsigned int BSP_bus_frequency;
71/*
72 * processor clock frequency
73 */
74unsigned int BSP_processor_frequency;
75/*
76 * Time base divisior (how many tick for 1 second).
77 */
78unsigned int BSP_time_base_divisor;
79/*
80 * system init stack and soft ir stack size
81 */
82#define INIT_STACK_SIZE 0x1000
83#define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY
84
85void BSP_panic(char *s)
86{
87  printk("%s PANIC %s\n",_RTEMS_version, s);
88  __asm__ __volatile ("sc"); 
89}
90
91void _BSP_Fatal_error(unsigned int v)
92{
93  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
94  __asm__ __volatile ("sc"); 
95}
96 
97/*
98 *  The original table from the application and our copy of it with
99 *  some changes.
100 */
101
102extern rtems_configuration_table Configuration;
103
104rtems_configuration_table  BSP_Configuration;
105
106rtems_cpu_table Cpu_table;
107
108char *rtems_progname;
109
110/*
111 *  Use the shared implementations of the following routines
112 */
113 
114void bsp_postdriver_hook(void);
115void bsp_libc_init( void *, uint32_t, int );
116
117/*
118 *  Function:   bsp_pretasking_hook
119 *  Created:    95/03/10
120 *
121 *  Description:
122 *      BSP pretasking hook.  Called just before drivers are initialized.
123 *      Used to setup libc and install any BSP extensions.
124 *
125 *  NOTES:
126 *      Must not use libc (to do io) from here, since drivers are
127 *      not yet initialized.
128 *
129 */
130 
131void bsp_pretasking_hook(void)
132{
133    uint32_t                heap_start;   
134    uint32_t                heap_size;
135    uint32_t                heap_sbrk_spared;
136        extern uint32_t         _bsp_sbrk_init(uint32_t, uint32_t*);
137
138    heap_start = ((uint32_t) __rtems_end) +INIT_STACK_SIZE + INTR_STACK_SIZE;
139    if (heap_start & (CPU_ALIGNMENT-1))
140        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
141
142    heap_size = (BSP_mem_size - heap_start) - BSP_Configuration.work_space_size;
143
144        heap_sbrk_spared=_bsp_sbrk_init(heap_start, &heap_size);
145
146#ifdef SHOW_MORE_INIT_SETTINGS
147        printk(" HEAP start %x  size %x (%x bytes spared for sbrk)\n", heap_start, heap_size, heap_sbrk_spared);
148#endif   
149
150    bsp_libc_init((void *) 0, heap_size, heap_sbrk_spared);
151
152
153#ifdef RTEMS_DEBUG
154    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
155#endif
156}
157
158void zero_bss()
159{
160  /* prevent these from being accessed in the short data areas */
161  extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[];
162  extern unsigned long __SBSS2_START__[], __SBSS2_END__[];
163  memset(__SBSS_START__, 0, ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__));
164  memset(__SBSS2_START__, 0, ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__));
165  memset(__bss_start, 0, ((unsigned) __rtems_end) - ((unsigned)__bss_start));
166}
167
168void save_boot_params(RESIDUAL* r3, void *r4, void* r5, char *additional_boot_options)
169{
170 
171  residualCopy = *r3;
172  strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM);
173  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
174}
175
176/*
177 *  bsp_start
178 *
179 *  This routine does the bulk of the system initialization.
180 */
181
182void bsp_start( void )
183{
184  int err;
185  unsigned char *stack;
186  unsigned l2cr;
187  register unsigned char* intrStack;
188  unsigned char *work_space_start;
189  ppc_cpu_id_t myCpu;
190  ppc_cpu_revision_t myCpuRevision;
191  prep_t boardManufacturer;
192  motorolaBoard myBoard;
193  Triv121PgTbl  pt=0;
194  /*
195   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
196   * store the result in global variables so that it can be used latter...
197   */
198  myCpu         = get_ppc_cpu_type();
199  myCpuRevision = get_ppc_cpu_revision();
200  /*
201   * enables L1 Cache. Note that the L1_caches_enables() codes checks for
202   * relevant CPU type so that the reason why there is no use of myCpu...
203   */
204  L1_caches_enables();
205  /*
206   * Enable L2 Cache. Note that the set_L2CR(L2CR) codes checks for
207   * relevant CPU type (mpc750)...
208   */
209  l2cr = get_L2CR();
210#ifdef SHOW_LCR2_REGISTER
211  printk("Initial L2CR value = %x\n", l2cr);
212#endif 
213  if ( (! (l2cr & 0x80000000)) && ((int) l2cr == -1))
214    set_L2CR(0xb9A14000);
215  /*
216   * the initial stack  has aready been set to this value in start.S
217   * so there is no need to set it in r1 again... It is just for info
218   * so that It can be printed without accessing R1.
219   */
220  stack = ((unsigned char*) __rtems_end) + INIT_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
221
222 /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
223  *((uint32_t*)stack) = 0;
224
225  /*
226   * Initialize the interrupt related settings
227   * SPRG1 = software managed IRQ stack
228   *
229   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
230   * some settings below...
231   */
232  intrStack = ((unsigned char*) __rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
233
234  /* make sure it's properly aligned */
235  (uint32_t)intrStack &= ~(CPU_STACK_ALIGNMENT-1);
236
237  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
238  *((uint32_t*)intrStack) = 0;
239
240  _write_SPRG1((unsigned int)intrStack);
241
242  /* signal them that we have fixed PR288 - eventually, this should go away */
243  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
244
245  /*
246   * Initialize default raw exception hanlders. See vectors/vectors_init.c
247   */
248  initialize_exceptions();
249  /*
250   * Init MMU block address translation to enable hardware
251   * access
252   */
253  /*
254   * PC legacy IO space used for inb/outb and all PC
255   * compatible hardware
256   */
257  setdbat(1, _IO_BASE, _IO_BASE, 0x10000000, IO_PAGE);
258  /*
259   * PCI devices memory area. Needed to access OPENPIC features
260   * provided by the RAVEN
261   */
262  /* T. Straumann: give more PCI address space */
263  setdbat(2, PCI_MEM_BASE, PCI_MEM_BASE, 0x10000000, IO_PAGE);
264  /*
265   * Must have acces to open pic PCI ACK registers
266   * provided by the RAVEN
267   *
268   */
269  setdbat(3, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
270
271  select_console(CONSOLE_LOG);
272
273  /* We check that the keyboard is present and immediately
274   * select the serial console if not.
275   */
276  err = kbdreset();
277  if (err) select_console(CONSOLE_SERIAL);
278
279  boardManufacturer   =  checkPrepBoardType(&residualCopy);
280  if (boardManufacturer != PREP_Motorola) {
281    printk("Unsupported hardware vendor\n");
282    while (1);
283  }
284  myBoard = getMotorolaBoard();
285 
286  printk("-----------------------------------------\n");
287  printk("Welcome to %s on %s\n", _RTEMS_version, motorolaBoardToString(myBoard));
288  printk("-----------------------------------------\n");
289#ifdef SHOW_MORE_INIT_SETTINGS 
290  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
291  printk("Additionnal boot options are %s\n", loaderParam);
292  printk("Initial system stack at %x\n",stack);
293  printk("Software IRQ stack at %x\n",intrStack);
294  printk("-----------------------------------------\n");
295#endif
296
297#ifdef TEST_RETURN_TO_PPCBUG 
298  printk("Hit <Enter> to return to PPCBUG monitor\n");
299  printk("When Finished hit GO. It should print <Back from monitor>\n");
300  debug_getc();
301  _return_to_ppcbug();
302  printk("Back from monitor\n");
303  _return_to_ppcbug();
304#endif /* TEST_RETURN_TO_PPCBUG  */
305
306#ifdef SHOW_MORE_INIT_SETTINGS
307  printk("Going to start PCI buses scanning and initialization\n");
308#endif 
309  InitializePCI();
310
311 {
312    const struct _int_map     *bspmap   = motorolaIntMap(currentBoard);
313    if( bspmap )
314    {
315       printk("pci : Configuring interrupt routing for '%s'\n", motorolaBoardToString(currentBoard));
316       FixupPCI(bspmap, motorolaIntSwizzle(currentBoard) );
317    }
318    else
319       printk("pci : Interrupt routing not available for this bsp\n");
320 }
321
322
323#ifdef SHOW_MORE_INIT_SETTINGS
324  printk("Number of PCI buses found is : %d\n", BusCountPCI());
325#endif
326#ifdef TEST_RAW_EXCEPTION_CODE 
327  printk("Testing exception handling Part 1\n");
328  /*
329   * Cause a software exception
330   */
331  __asm__ __volatile ("sc");
332  /*
333   * Check we can still catch exceptions and returned coorectly.
334   */
335  printk("Testing exception handling Part 2\n");
336  __asm__ __volatile ("sc");
337#endif 
338
339
340  BSP_mem_size                          = residualCopy.TotalMemory;
341  BSP_bus_frequency                     = residualCopy.VitalProductData.ProcessorBusHz;
342  BSP_processor_frequency               = residualCopy.VitalProductData.ProcessorHz;
343  BSP_time_base_divisor                 = (residualCopy.VitalProductData.TimeBaseDivisor?
344                                           residualCopy.VitalProductData.TimeBaseDivisor : 4000);
345
346  /* clear hostbridge errors but leave MCP disabled -
347   * PCI config space scanning code will trip otherwise :-(
348   */
349  _BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
350
351
352  /* Allocate and set up the page table mappings
353   * This is only available on >604 CPUs.
354   *
355   * NOTE: This setup routine may modify the available memory
356   *       size. It is essential to call it before
357   *       calculating the workspace etc.
358   */
359  pt = BSP_pgtbl_setup(&BSP_mem_size);
360
361  if (!pt ||
362          TRIV121_MAP_SUCCESS != triv121PgTblMap(
363                                                                                pt,
364                                                                                TRIV121_121_VSID,
365                                                                                0xfeff0000,
366                                                                                1,
367                                                                                TRIV121_ATTR_IO_PAGE,
368                                                                                TRIV121_PP_RW_PAGE
369                                                                                )) {
370        printk("WARNING: unable to setup page tables VME bridge must share PCI space\n");
371  }
372 
373  /*
374   * Set up our hooks
375   * Make sure libc_init is done before drivers initialized so that
376   * they can use atexit()
377   */
378
379  Cpu_table.pretasking_hook      = bsp_pretasking_hook;    /* init libc, etc. */
380  Cpu_table.postdriver_hook      = bsp_postdriver_hook;
381  Cpu_table.do_zero_of_workspace = TRUE;
382  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
383  Cpu_table.clicks_per_usec      = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
384  Cpu_table.exceptions_in_RAM    = TRUE;
385
386#ifdef SHOW_MORE_INIT_SETTINGS
387  printk("BSP_Configuration.work_space_size = %x\n", BSP_Configuration.work_space_size);
388#endif 
389  work_space_start = 
390    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
391
392  if ( work_space_start <= ((unsigned char *)__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
393    printk( "bspstart: Not enough RAM!!!\n" );
394    bsp_cleanup();
395  }
396
397  BSP_Configuration.work_space_start = work_space_start;
398
399  /*
400   * Initalize RTEMS IRQ system
401   */
402  BSP_rtems_irq_mng_init(0);
403
404 
405  /* Activate the page table mappings only after
406   * initializing interrupts because the irq_mng_init()
407   * routine needs to modify the text
408   */           
409  if (pt) {
410#ifdef  SHOW_MORE_INIT_SETTINGS
411    printk("Page table setup finished; will activate it NOW...\n");
412#endif
413    BSP_pgtbl_activate(pt);
414        /* finally, switch off DBAT3 */
415        setdbat(3, 0, 0, 0, 0); 
416  }
417
418  /*
419   * Initialize VME bridge - needs working PCI
420   * and IRQ subsystems...
421   */
422#ifdef SHOW_MORE_INIT_SETTINGS
423  printk("Going to initialize VME bridge\n");
424#endif
425  /* VME initialization is in a separate file so apps which don't use
426   * VME or want a different configuration may link against a customized
427   * routine.
428   */
429  BSP_vme_config();
430
431#ifdef SHOW_MORE_INIT_SETTINGS
432  printk("Exit from bspstart\n");
433#endif 
434}
Note: See TracBrowser for help on using the repository browser.