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

4.104.114.84.95
Last change on this file since 69ed59f was 69ed59f, checked in by Joel Sherrill <joel.sherrill@…>, on May 14, 2002 at 5:10:17 PM

2001-05-14 Till Straumann <strauman@…>

  • bootloader/misc.c, console/Makefile.am, console/console.c, console/consoleIo.h, console/inch.c, console/polled_io.c, console/uart.c, console/uart.h, include/bsp.h, irq/Makefile.am, irq/irq.c, irq/irq.h, irq/irq_init.c, openpic/openpic.c, openpic/openpic.h, pci/Makefile.am, pci/pci.c, pci/pci.h, residual/Makefile.am, start/start.S, startup/bspstart.c, vectors/vectors.S, vectors/vectors.h, vectors/vectors_init.c: Per PR216, "libbsp/powerpc/shared" BSP has been modified considerably with the goal to make it more flexible and reusable by other BSPs. The main strategies were:
    • eliminate hardcoded base addresses; devices use offsets and a BSP defined base address.
    • separate functionality into different files (e.g. reboot from inch.c to reboot.c) which can be overridden by a 'derived' BSP.
    • separate initialization code into separate files (e.g. PCI bridge detection/initialization was separated from the more generic PCI access routines), also to make it easier for 'derived' BSPs to substitute their own initialization code.

There are also a couple of enhancements and fixes:

  • IRQ handling code now has a hook for attaching a VME bridge.
  • OpenPIC is now explicitely initialized (polarities, senses). Eliminated the implicit assumption on the presence of an ISA PIC.
  • UART and console driver now supports more than 1 port. The current maximum of 2 can easily be extended by enlarging a table (it would even be easier if the ISR API was not broken by design).
  • fixed polled_io.c so it correctly supports console on COM2
  • fixed TLB invalidation code (start.S).
  • exception handler prints a stack backtrace.
  • added BSP_pciFindDevice() to scan the pci bus for a particular vendor/device/instance.
  • Property mode set to 100644
File size: 9.6 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.OARcorp.com/rtems/license.html.
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.h>
31#include <libcpu/bat.h>
32#include <libcpu/cpuIdent.h>
33#include <bsp/vectors.h>
34#include <bsp/motorola.h>
35
36extern void _return_to_ppcbug();
37extern unsigned long __rtems_end;
38extern unsigned long _end;
39extern unsigned long __bss_start;
40extern void L1_caches_enables();
41extern unsigned get_L2CR();
42extern void set_L2CR(unsigned);
43extern void bsp_cleanup(void);
44/*
45 * Copy of residuals passed by firmware
46 */
47RESIDUAL residualCopy; 
48/*
49 * Copy Additional boot param passed by boot loader
50 */
51#define MAX_LOADER_ADD_PARM 80
52char loaderParam[MAX_LOADER_ADD_PARM];
53/*
54 * Vital Board data Start using DATA RESIDUAL
55 */
56/*
57 * Total memory using RESIDUAL DATA
58 */
59unsigned int BSP_mem_size;
60/*
61 * PCI Bus Frequency
62 */
63unsigned int BSP_bus_frequency;
64/*
65 * processor clock frequency
66 */
67unsigned int BSP_processor_frequency;
68/*
69 * Time base divisior (how many tick for 1 second).
70 */
71unsigned int BSP_time_base_divisor;
72/*
73 * system init stack and soft ir stack size
74 */
75#define INIT_STACK_SIZE 0x1000
76#define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY
77
78void BSP_panic(char *s)
79{
80  printk("%s PANIC %s\n",_RTEMS_version, s);
81  __asm__ __volatile ("sc"); 
82}
83
84void _BSP_Fatal_error(unsigned int v)
85{
86  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
87  __asm__ __volatile ("sc"); 
88}
89 
90/*
91 *  The original table from the application and our copy of it with
92 *  some changes.
93 */
94
95extern rtems_configuration_table Configuration;
96
97rtems_configuration_table  BSP_Configuration;
98
99rtems_cpu_table Cpu_table;
100
101char *rtems_progname;
102
103/*
104 *  Use the shared implementations of the following routines
105 */
106 
107void bsp_postdriver_hook(void);
108void bsp_libc_init( void *, unsigned32, int );
109
110/*
111 *  Function:   bsp_pretasking_hook
112 *  Created:    95/03/10
113 *
114 *  Description:
115 *      BSP pretasking hook.  Called just before drivers are initialized.
116 *      Used to setup libc and install any BSP extensions.
117 *
118 *  NOTES:
119 *      Must not use libc (to do io) from here, since drivers are
120 *      not yet initialized.
121 *
122 */
123 
124void bsp_pretasking_hook(void)
125{
126    rtems_unsigned32        heap_start;   
127    rtems_unsigned32        heap_size;
128
129    heap_start = ((rtems_unsigned32) &__rtems_end) +INIT_STACK_SIZE + INTR_STACK_SIZE;
130    if (heap_start & (CPU_ALIGNMENT-1))
131        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
132
133    heap_size = (BSP_mem_size - heap_start) - BSP_Configuration.work_space_size;
134
135#ifdef SHOW_MORE_INIT_SETTINGS
136    printk(" HEAP start %x  size %x\n", heap_start, heap_size);
137#endif   
138    bsp_libc_init((void *) heap_start, heap_size, 0);
139
140#ifdef RTEMS_DEBUG
141    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
142#endif
143}
144
145void zero_bss()
146{
147  memset(&__bss_start, 0, ((unsigned) (&__rtems_end)) - ((unsigned) &__bss_start));
148}
149
150void save_boot_params(RESIDUAL* r3, void *r4, void* r5, char *additional_boot_options)
151{
152 
153  residualCopy = *r3;
154  strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM);
155  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
156}
157
158/*
159 *  bsp_start
160 *
161 *  This routine does the bulk of the system initialization.
162 */
163
164void bsp_start( void )
165{
166  int err;
167  unsigned char *stack;
168  unsigned l2cr;
169  register unsigned char* intrStack;
170  register unsigned int intrNestingLevel = 0;
171  unsigned char *work_space_start;
172  ppc_cpu_id_t myCpu;
173  ppc_cpu_revision_t myCpuRevision;
174  prep_t boardManufacturer;
175  motorolaBoard myBoard;
176  /*
177   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
178   * store the result in global variables so that it can be used latter...
179   */
180  myCpu         = get_ppc_cpu_type();
181  myCpuRevision = get_ppc_cpu_revision();
182  /*
183   * enables L1 Cache. Note that the L1_caches_enables() codes checks for
184   * relevant CPU type so that the reason why there is no use of myCpu...
185   */
186  L1_caches_enables();
187  /*
188   * Enable L2 Cache. Note that the set_L2CR(L2CR) codes checks for
189   * relevant CPU type (mpc750)...
190   */
191  l2cr = get_L2CR();
192#ifdef SHOW_LCR2_REGISTER
193  printk("Initial L2CR value = %x\n", l2cr);
194#endif 
195  if ( (! (l2cr & 0x80000000)) && ((int) l2cr == -1))
196    set_L2CR(0xb9A14000);
197  /*
198   * the initial stack  has aready been set to this value in start.S
199   * so there is no need to set it in r1 again... It is just for info
200   * so that It can be printed without accessing R1.
201   */
202  stack = ((unsigned char*) &__rtems_end) + INIT_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
203
204 /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
205  *((unsigned32 *)stack) = 0;
206
207  /*
208   * Initialize the interrupt related settings
209   * SPRG0 = interrupt nesting level count
210   * SPRG1 = software managed IRQ stack
211   *
212   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
213   * some settings below...
214   */
215  intrStack = ((unsigned char*) &__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
216
217 /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
218  *((unsigned32 *)intrStack) = 0;
219
220  asm volatile ("mtspr  273, %0" : "=r" (intrStack) : "0" (intrStack));
221  asm volatile ("mtspr  272, %0" : "=r" (intrNestingLevel) : "0" (intrNestingLevel));
222  /*
223   * Initialize default raw exception hanlders. See vectors/vectors_init.c
224   */
225  initialize_exceptions();
226  /*
227   * Init MMU block address translation to enable hardware
228   * access
229   */
230  /*
231   * PC legacy IO space used for inb/outb and all PC
232   * compatible hardware
233   */
234  setdbat(1, 0x80000000, 0x80000000, 0x10000000, IO_PAGE);
235  /*
236   * PCI devices memory area. Needed to access OPENPIC features
237   * provided by the RAVEN
238   */
239  /* T. Straumann: give more PCI address space */
240  setdbat(2, 0xc0000000, 0xc0000000, 0x10000000, IO_PAGE);
241  /*
242   * Must have acces to open pic PCI ACK registers
243   * provided by the RAVEN
244   */
245  setdbat(3, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
246  select_console(CONSOLE_LOG);
247
248  /* We check that the keyboard is present and immediately
249   * select the serial console if not.
250   */
251  err = kbdreset();
252  if (err) select_console(CONSOLE_SERIAL);
253
254  boardManufacturer   =  checkPrepBoardType(&residualCopy);
255  if (boardManufacturer != PREP_Motorola) {
256    printk("Unsupported hardware vendor\n");
257    while (1);
258  }
259  myBoard = getMotorolaBoard();
260 
261  printk("-----------------------------------------\n");
262  printk("Welcome to %s on %s\n", _RTEMS_version, motorolaBoardToString(myBoard));
263  printk("-----------------------------------------\n");
264#ifdef SHOW_MORE_INIT_SETTINGS 
265  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
266  printk("Additionnal boot options are %s\n", loaderParam);
267  printk("Initial system stack at %x\n",stack);
268  printk("Software IRQ stack at %x\n",intrStack);
269  printk("-----------------------------------------\n");
270#endif
271
272#ifdef TEST_RETURN_TO_PPCBUG 
273  printk("Hit <Enter> to return to PPCBUG monitor\n");
274  printk("When Finished hit GO. It should print <Back from monitor>\n");
275  debug_getc();
276  _return_to_ppcbug();
277  printk("Back from monitor\n");
278  _return_to_ppcbug();
279#endif /* TEST_RETURN_TO_PPCBUG  */
280
281#ifdef SHOW_MORE_INIT_SETTINGS
282  printk("Going to start PCI buses scanning and initialization\n");
283#endif 
284  InitializePCI();
285#ifdef SHOW_MORE_INIT_SETTINGS
286  printk("Number of PCI buses found is : %d\n", BusCountPCI());
287#endif
288#ifdef TEST_RAW_EXCEPTION_CODE 
289  printk("Testing exception handling Part 1\n");
290  /*
291   * Cause a software exception
292   */
293  __asm__ __volatile ("sc");
294  /*
295   * Check we can still catch exceptions and returned coorectly.
296   */
297  printk("Testing exception handling Part 2\n");
298  __asm__ __volatile ("sc");
299#endif 
300
301
302  BSP_mem_size                          = residualCopy.TotalMemory;
303  BSP_bus_frequency                     = residualCopy.VitalProductData.ProcessorBusHz;
304  BSP_processor_frequency               = residualCopy.VitalProductData.ProcessorHz;
305  BSP_time_base_divisor                 = (residualCopy.VitalProductData.TimeBaseDivisor?
306                                           residualCopy.VitalProductData.TimeBaseDivisor : 4000);
307 
308  /*
309   * Set up our hooks
310   * Make sure libc_init is done before drivers initialized so that
311   * they can use atexit()
312   */
313
314  Cpu_table.pretasking_hook      = bsp_pretasking_hook;    /* init libc, etc. */
315  Cpu_table.postdriver_hook      = bsp_postdriver_hook;
316  Cpu_table.do_zero_of_workspace = TRUE;
317  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
318  Cpu_table.clicks_per_usec      = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
319  Cpu_table.exceptions_in_RAM    = TRUE;
320
321#ifdef SHOW_MORE_INIT_SETTINGS
322  printk("BSP_Configuration.work_space_size = %x\n", BSP_Configuration.work_space_size);
323#endif 
324  work_space_start = 
325    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
326
327  if ( work_space_start <= ((unsigned char *)&__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
328    printk( "bspstart: Not enough RAM!!!\n" );
329    bsp_cleanup();
330  }
331
332  BSP_Configuration.work_space_start = work_space_start;
333
334  /*
335   * Initalize RTEMS IRQ system
336   */
337  BSP_rtems_irq_mng_init(0);
338#ifdef SHOW_MORE_INIT_SETTINGS
339  printk("Exit from bspstart\n");
340#endif 
341}
Note: See TracBrowser for help on using the repository browser.