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

4.104.114.84.95
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 21, 2004 at 4:01:48 PM

Remove duplicate white lines.

  • Property mode set to 100644
File size: 12.1 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#ifdef RTEMS_DEBUG
153    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
154#endif
155}
156
157void zero_bss()
158{
159  /* prevent these from being accessed in the short data areas */
160  extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[];
161  extern unsigned long __SBSS2_START__[], __SBSS2_END__[];
162  memset(__SBSS_START__, 0, ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__));
163  memset(__SBSS2_START__, 0, ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__));
164  memset(__bss_start, 0, ((unsigned) __rtems_end) - ((unsigned)__bss_start));
165}
166
167void save_boot_params(RESIDUAL* r3, void *r4, void* r5, char *additional_boot_options)
168{
169
170  residualCopy = *r3;
171  strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM);
172  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
173}
174
175/*
176 *  bsp_start
177 *
178 *  This routine does the bulk of the system initialization.
179 */
180
181void bsp_start( void )
182{
183  int err;
184  unsigned char *stack;
185  unsigned l2cr;
186  register unsigned char* intrStack;
187  unsigned char *work_space_start;
188  ppc_cpu_id_t myCpu;
189  ppc_cpu_revision_t myCpuRevision;
190  prep_t boardManufacturer;
191  motorolaBoard myBoard;
192  Triv121PgTbl  pt=0;
193  /*
194   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
195   * store the result in global variables so that it can be used latter...
196   */
197  myCpu         = get_ppc_cpu_type();
198  myCpuRevision = get_ppc_cpu_revision();
199  /*
200   * enables L1 Cache. Note that the L1_caches_enables() codes checks for
201   * relevant CPU type so that the reason why there is no use of myCpu...
202   */
203  L1_caches_enables();
204  /*
205   * Enable L2 Cache. Note that the set_L2CR(L2CR) codes checks for
206   * relevant CPU type (mpc750)...
207   */
208  l2cr = get_L2CR();
209#ifdef SHOW_LCR2_REGISTER
210  printk("Initial L2CR value = %x\n", l2cr);
211#endif
212  if ( (! (l2cr & 0x80000000)) && ((int) l2cr == -1))
213    set_L2CR(0xb9A14000);
214  /*
215   * the initial stack  has aready been set to this value in start.S
216   * so there is no need to set it in r1 again... It is just for info
217   * so that It can be printed without accessing R1.
218   */
219  stack = ((unsigned char*) __rtems_end) + INIT_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
220
221 /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
222  *((uint32_t*)stack) = 0;
223
224  /*
225   * Initialize the interrupt related settings
226   * SPRG1 = software managed IRQ stack
227   *
228   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
229   * some settings below...
230   */
231  intrStack = ((unsigned char*) __rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
232
233  /* make sure it's properly aligned */
234  (uint32_t)intrStack &= ~(CPU_STACK_ALIGNMENT-1);
235
236  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
237  *((uint32_t*)intrStack) = 0;
238
239  _write_SPRG1((unsigned int)intrStack);
240
241  /* signal them that we have fixed PR288 - eventually, this should go away */
242  _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
243
244  /*
245   * Initialize default raw exception hanlders. See vectors/vectors_init.c
246   */
247  initialize_exceptions();
248  /*
249   * Init MMU block address translation to enable hardware
250   * access
251   */
252  /*
253   * PC legacy IO space used for inb/outb and all PC
254   * compatible hardware
255   */
256  setdbat(1, _IO_BASE, _IO_BASE, 0x10000000, IO_PAGE);
257  /*
258   * PCI devices memory area. Needed to access OPENPIC features
259   * provided by the RAVEN
260   */
261  /* T. Straumann: give more PCI address space */
262  setdbat(2, PCI_MEM_BASE, PCI_MEM_BASE, 0x10000000, IO_PAGE);
263  /*
264   * Must have acces to open pic PCI ACK registers
265   * provided by the RAVEN
266   *
267   */
268  setdbat(3, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
269
270  select_console(CONSOLE_LOG);
271
272  /* We check that the keyboard is present and immediately
273   * select the serial console if not.
274   */
275  err = kbdreset();
276  if (err) select_console(CONSOLE_SERIAL);
277
278  boardManufacturer   =  checkPrepBoardType(&residualCopy);
279  if (boardManufacturer != PREP_Motorola) {
280    printk("Unsupported hardware vendor\n");
281    while (1);
282  }
283  myBoard = getMotorolaBoard();
284
285  printk("-----------------------------------------\n");
286  printk("Welcome to %s on %s\n", _RTEMS_version, motorolaBoardToString(myBoard));
287  printk("-----------------------------------------\n");
288#ifdef SHOW_MORE_INIT_SETTINGS
289  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
290  printk("Additionnal boot options are %s\n", loaderParam);
291  printk("Initial system stack at %x\n",stack);
292  printk("Software IRQ stack at %x\n",intrStack);
293  printk("-----------------------------------------\n");
294#endif
295
296#ifdef TEST_RETURN_TO_PPCBUG
297  printk("Hit <Enter> to return to PPCBUG monitor\n");
298  printk("When Finished hit GO. It should print <Back from monitor>\n");
299  debug_getc();
300  _return_to_ppcbug();
301  printk("Back from monitor\n");
302  _return_to_ppcbug();
303#endif /* TEST_RETURN_TO_PPCBUG  */
304
305#ifdef SHOW_MORE_INIT_SETTINGS
306  printk("Going to start PCI buses scanning and initialization\n");
307#endif
308  InitializePCI();
309
310 {
311    const struct _int_map     *bspmap   = motorolaIntMap(currentBoard);
312    if( bspmap )
313    {
314       printk("pci : Configuring interrupt routing for '%s'\n", motorolaBoardToString(currentBoard));
315       FixupPCI(bspmap, motorolaIntSwizzle(currentBoard) );
316    }
317    else
318       printk("pci : Interrupt routing not available for this bsp\n");
319 }
320
321#ifdef SHOW_MORE_INIT_SETTINGS
322  printk("Number of PCI buses found is : %d\n", BusCountPCI());
323#endif
324#ifdef TEST_RAW_EXCEPTION_CODE
325  printk("Testing exception handling Part 1\n");
326  /*
327   * Cause a software exception
328   */
329  __asm__ __volatile ("sc");
330  /*
331   * Check we can still catch exceptions and returned coorectly.
332   */
333  printk("Testing exception handling Part 2\n");
334  __asm__ __volatile ("sc");
335#endif
336
337  BSP_mem_size                          = residualCopy.TotalMemory;
338  BSP_bus_frequency                     = residualCopy.VitalProductData.ProcessorBusHz;
339  BSP_processor_frequency               = residualCopy.VitalProductData.ProcessorHz;
340  BSP_time_base_divisor                 = (residualCopy.VitalProductData.TimeBaseDivisor?
341                                           residualCopy.VitalProductData.TimeBaseDivisor : 4000);
342
343  /* clear hostbridge errors but leave MCP disabled -
344   * PCI config space scanning code will trip otherwise :-(
345   */
346  _BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
347
348  /* Allocate and set up the page table mappings
349   * This is only available on >604 CPUs.
350   *
351   * NOTE: This setup routine may modify the available memory
352   *       size. It is essential to call it before
353   *       calculating the workspace etc.
354   */
355  pt = BSP_pgtbl_setup(&BSP_mem_size);
356
357  if (!pt ||
358          TRIV121_MAP_SUCCESS != triv121PgTblMap(
359                                                                                pt,
360                                                                                TRIV121_121_VSID,
361                                                                                0xfeff0000,
362                                                                                1,
363                                                                                TRIV121_ATTR_IO_PAGE,
364                                                                                TRIV121_PP_RW_PAGE
365                                                                                )) {
366        printk("WARNING: unable to setup page tables VME bridge must share PCI space\n");
367  }
368
369  /*
370   * Set up our hooks
371   * Make sure libc_init is done before drivers initialized so that
372   * they can use atexit()
373   */
374
375  Cpu_table.pretasking_hook      = bsp_pretasking_hook;    /* init libc, etc. */
376  Cpu_table.postdriver_hook      = bsp_postdriver_hook;
377  Cpu_table.do_zero_of_workspace = TRUE;
378  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
379  Cpu_table.clicks_per_usec      = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
380  Cpu_table.exceptions_in_RAM    = TRUE;
381
382#ifdef SHOW_MORE_INIT_SETTINGS
383  printk("BSP_Configuration.work_space_size = %x\n", BSP_Configuration.work_space_size);
384#endif
385  work_space_start =
386    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
387
388  if ( work_space_start <= ((unsigned char *)__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
389    printk( "bspstart: Not enough RAM!!!\n" );
390    bsp_cleanup();
391  }
392
393  BSP_Configuration.work_space_start = work_space_start;
394
395  /*
396   * Initalize RTEMS IRQ system
397   */
398  BSP_rtems_irq_mng_init(0);
399
400  /* Activate the page table mappings only after
401   * initializing interrupts because the irq_mng_init()
402   * routine needs to modify the text
403   */
404  if (pt) {
405#ifdef  SHOW_MORE_INIT_SETTINGS
406    printk("Page table setup finished; will activate it NOW...\n");
407#endif
408    BSP_pgtbl_activate(pt);
409        /* finally, switch off DBAT3 */
410        setdbat(3, 0, 0, 0, 0);
411  }
412
413  /*
414   * Initialize VME bridge - needs working PCI
415   * and IRQ subsystems...
416   */
417#ifdef SHOW_MORE_INIT_SETTINGS
418  printk("Going to initialize VME bridge\n");
419#endif
420  /* VME initialization is in a separate file so apps which don't use
421   * VME or want a different configuration may link against a customized
422   * routine.
423   */
424  BSP_vme_config();
425
426#ifdef SHOW_MORE_INIT_SETTINGS
427  printk("Exit from bspstart\n");
428#endif
429}
Note: See TracBrowser for help on using the repository browser.