source: rtems/c/src/lib/libbsp/powerpc/mcp750/startup/bspstart.c @ 981b99f

4.104.114.84.95
Last change on this file since 981b99f was 981b99f, checked in by Joel Sherrill <joel.sherrill@…>, on 08/10/99 at 16:41:44

Patch from Eric Valette <valette@…> and Emmanuel Raguet
<raguet@…>:

  • the dec21140 driver code has been hardened (various bug fixed) Emmanuel,
  • bug in the mcp750 init code have been fixed (interrupt stack/initial stack initialization), BSS correctly cleared (Eric V)
  • remote debugging over TCP/IP is nearly complete (berakpoints, backtrace, variables,...) (Eric V),
  • exception handling code has also been improved in order to fully support RDBG requirements (Eric V),
  • Property mode set to 100644
File size: 8.5 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 *  Copyright assigned to U.S. Government, 1994.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.OARcorp.com/rtems/license.html.
14 *
15 *  Modified to support the MCP750.
16 *  Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
17 *
18 *  $Id$
19 */
20
21#include <bsp.h>
22#include <rtems/libio.h>
23#include <libcsupport.h>
24#include <string.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.h>
32#include <libcpu/bat.h>
33#include <bsp/vectors.h>
34
35extern void _return_to_ppcbug();
36extern unsigned long __rtems_end;
37extern unsigned long _end;
38extern unsigned long __bss_start;
39extern void L1_caches_enables();
40extern unsigned get_L2CR();
41extern void set_L2CR(unsigned);
42extern void bsp_cleanup(void);
43/*
44 * Copy of residuals passed by firmware
45 */
46RESIDUAL residualCopy;
47/*
48 * Copy Additional boot param passed by boot loader
49 */
50#define MAX_LOADER_ADD_PARM 80
51char loaderParam[MAX_LOADER_ADD_PARM];
52/*
53 * Vital Board data Start using DATA RESIDUAL
54 */
55/*
56 * Total memory using RESIDUAL DATA
57 */
58unsigned int BSP_mem_size;
59/*
60 * PCI Bus Frequency
61 */
62unsigned int BSP_bus_frequency;
63/*
64 * processor clock frequency
65 */
66unsigned int BSP_processor_frequency;
67/*
68 * Time base divisior (how many tick for 1 second).
69 */
70unsigned int BSP_time_base_divisor;
71/*
72 * system init stack and soft ir stack size
73 */
74#define INIT_STACK_SIZE 0x1000
75#define INTR_STACK_SIZE 0x4000
76
77void BSP_panic(char *s)
78{
79  printk("RTEMS 4.x PANIC %s\n", s);
80  _return_to_ppcbug();
81}
82
83void _BSP_Fatal_error(unsigned int v)
84{
85  printk("RTEMS 4.x PANIC ERROR %x\n", v);
86  _return_to_ppcbug();
87}
88 
89/*
90 *  The original table from the application and our copy of it with
91 *  some changes.
92 */
93
94extern rtems_configuration_table Configuration;
95
96rtems_configuration_table  BSP_Configuration;
97
98rtems_cpu_table Cpu_table;
99
100char *rtems_progname;
101
102/*
103 *  Use the shared implementations of the following routines
104 */
105 
106void bsp_postdriver_hook(void);
107void bsp_libc_init( void *, unsigned32, int );
108
109/*
110 *  Function:   bsp_pretasking_hook
111 *  Created:    95/03/10
112 *
113 *  Description:
114 *      BSP pretasking hook.  Called just before drivers are initialized.
115 *      Used to setup libc and install any BSP extensions.
116 *
117 *  NOTES:
118 *      Must not use libc (to do io) from here, since drivers are
119 *      not yet initialized.
120 *
121 */
122 
123void bsp_pretasking_hook(void)
124{
125    rtems_unsigned32        heap_start;   
126    rtems_unsigned32        heap_size;
127
128    heap_start = ((rtems_unsigned32) &__rtems_end) +INIT_STACK_SIZE + INTR_STACK_SIZE;
129    if (heap_start & (CPU_ALIGNMENT-1))
130        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
131
132    heap_size = (BSP_mem_size - heap_start) - BSP_Configuration.work_space_size;
133
134#ifdef SHOW_MORE_INIT_SETTINGS
135    printk(" HEAP start %x  size %x\n", heap_start, heap_size);
136#endif   
137    bsp_libc_init((void *) heap_start, heap_size, 0);
138
139#ifdef RTEMS_DEBUG
140    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
141#endif
142}
143
144void zero_bss()
145{
146  memset(&__bss_start, 0, ((unsigned) (&__rtems_end)) - ((unsigned) &__bss_start));
147}
148
149void save_boot_params(RESIDUAL* r3, void *r4, void* r5, char *additional_boot_options)
150{
151 
152  residualCopy = *r3;
153  strncpy(loaderParam, additional_boot_options, MAX_LOADER_ADD_PARM);
154  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
155}
156
157/*
158 *  bsp_start
159 *
160 *  This routine does the bulk of the system initialization.
161 */
162
163void bsp_start( void )
164{
165  int err;
166  unsigned char *stack;
167  unsigned l2cr;
168  register unsigned char* intrStack;
169  register unsigned int intrNestingLevel = 0;
170  unsigned char *work_space_start;
171
172  /*
173   * enables L1 Cache
174   */
175  L1_caches_enables();
176  /*
177   * Enable L2 Cache
178   */
179  l2cr = get_L2CR();
180#ifdef SHOW_LCR2_REGISTER
181  printk("Initial L2CR value = %x\n", l2cr);
182#endif 
183  if (! (l2cr & 0x80000000))
184    set_L2CR(0xb9A14000);
185  /*
186   * the initial stack  has aready been set to this value in start.S
187   * so there is no need to set it in r1 again...
188   */
189  stack = ((unsigned char*) &__rtems_end) + INIT_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
190  /*
191   * Initialize the interrupt related settings
192   * SPRG0 = interrupt nesting level count
193   * SPRG1 = software managed IRQ stack
194   *
195   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
196   * some settings below...
197   */
198  intrStack = ((unsigned char*) &__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
199  asm volatile ("mtspr  273, %0" : "=r" (intrStack) : "0" (intrStack));
200  asm volatile ("mtspr  272, %0" : "=r" (intrNestingLevel) : "0" (intrNestingLevel));
201  /*
202   * Initialize default raw exception hanlders. See vectors/vectors_init.c
203   */
204  initialize_exceptions();
205  select_console(CONSOLE_LOG);
206
207  /* We check that the keyboard is present and immediately
208   * select the serial console if not.
209   */
210  err = kbdreset();
211  if (err) select_console(CONSOLE_SERIAL);
212
213 
214  printk("-----------------------------------------\n");
215  printk("Welcome to RTEMS 4.1.1 on Motorola MCP750\n");
216  printk("-----------------------------------------\n");
217#ifdef SHOW_MORE_INIT_SETTINGS 
218  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
219  printk("Additionnal boot options are %s\n", loaderParam);
220  printk("Initial system stack at %x\n",stack);
221  printk("Software IRQ stack at %x\n",intrStack);
222  printk("-----------------------------------------\n");
223#endif
224
225#ifdef TEST_RETURN_TO_PPCBUG 
226  printk("Hit <Enter> to return to PPCBUG monitor\n");
227  printk("When Finished hit GO. It should print <Back from monitor>\n");
228  debug_getc();
229  _return_to_ppcbug();
230  printk("Back from monitor\n");
231  _return_to_ppcbug();
232#endif /* TEST_RETURN_TO_PPCBUG  */
233
234  /*
235   * Init MMU block address translation to enable hardware
236   * access
237   */
238  /*
239   * PC legacy IO space used for inb/outb and all PC
240   * compatible hardware
241   */
242  setdbat(1, 0x80000000, 0x80000000, 0x10000000, IO_PAGE);
243  /*
244   * PCI devices memory area. Needed to access OPENPIC features
245   * provided by the RAVEN
246   */
247  setdbat(2, 0xc0000000, 0xc0000000, 0x08000000, IO_PAGE);
248  /*
249   * Must have acces to open pic PCI ACK registers
250   * provided by the RAVEN
251   */
252  setdbat(3, 0xfeff0000, 0xfeff0000, 0x10000, IO_PAGE);
253
254  printk("Going to start PCI buses scanning and initialization\n");
255  InitializePCI();
256  printk("Number of PCI buses is found : %d\n", BusCountPCI());
257
258#ifdef TEST_RAW_EXCEPTION_CODE 
259  printk("Testing exception handling Part 1\n");
260  /*
261   * Cause a software exception
262   */
263  __asm__ __volatile ("sc");
264  /*
265   * Check we can still catch exceptions and returned coorectly.
266   */
267  printk("Testing exception handling Part 2\n");
268  __asm__ __volatile ("sc");
269#endif 
270
271
272  BSP_mem_size                          = residualCopy.TotalMemory;
273  BSP_bus_frequency                     = residualCopy.VitalProductData.ProcessorBusHz;
274  BSP_processor_frequency               = residualCopy.VitalProductData.ProcessorHz;
275  BSP_time_base_divisor                 = (residualCopy.VitalProductData.TimeBaseDivisor?
276                                           residualCopy.VitalProductData.TimeBaseDivisor : 4000);
277 
278  /*
279   * Set up our hooks
280   * Make sure libc_init is done before drivers initialized so that
281   * they can use atexit()
282   */
283
284  Cpu_table.pretasking_hook             = bsp_pretasking_hook;    /* init libc, etc. */
285  Cpu_table.postdriver_hook             = bsp_postdriver_hook;
286  Cpu_table.do_zero_of_workspace        = TRUE;
287  Cpu_table.interrupt_stack_size        = INTR_STACK_SIZE;
288  Cpu_table.clicks_per_usec             = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
289  Cpu_table.exceptions_in_RAM           = TRUE;
290
291#ifdef SHOW_MORE_INIT_SETTINGS
292  printk("BSP_Configuration.work_space_size = %x\n", BSP_Configuration.work_space_size);
293#endif 
294  work_space_start =
295    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
296
297  if ( work_space_start <= ((unsigned char *)&__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
298    printk( "bspstart: Not enough RAM!!!\n" );
299    bsp_cleanup();
300  }
301
302  BSP_Configuration.work_space_start = work_space_start;
303
304  /*
305   *  Account for the console's resources
306   */
307
308  console_reserve_resources( &BSP_Configuration );
309  /*
310   * Initalize RTEMS IRQ system
311   */
312  BSP_rtems_irq_mng_init(0);
313#ifdef SHOW_MORE_INIT_SETTINGS
314  printk("Exit from bspstart\n");
315#endif 
316}
Note: See TracBrowser for help on using the repository browser.