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

4.104.114.84.95
Last change on this file since acc25ee was acc25ee, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 2, 1999 at 2:31:19 PM

Merged of mcp750 and mvme2307 BSP by Eric Valette <valette@…>.
As part of this effort, the mpc750 libcpu code is now shared with the
ppc6xx.

  • Property mode set to 100644
File size: 9.4 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#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 0x4000
77
78void BSP_panic(char *s)
79{
80  printk("RTEMS 4.x PANIC %s\n", s);
81  _return_to_ppcbug();
82}
83
84void _BSP_Fatal_error(unsigned int v)
85{
86  printk("RTEMS 4.x PANIC ERROR %x\n", v);
87  _return_to_ppcbug();
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   * Initialize the interrupt related settings
205   * SPRG0 = interrupt nesting level count
206   * SPRG1 = software managed IRQ stack
207   *
208   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
209   * some settings below...
210   */
211  intrStack = ((unsigned char*) &__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
212  asm volatile ("mtspr  273, %0" : "=r" (intrStack) : "0" (intrStack));
213  asm volatile ("mtspr  272, %0" : "=r" (intrNestingLevel) : "0" (intrNestingLevel));
214  /*
215   * Initialize default raw exception hanlders. See vectors/vectors_init.c
216   */
217  initialize_exceptions();
218  /*
219   * Init MMU block address translation to enable hardware
220   * access
221   */
222  /*
223   * PC legacy IO space used for inb/outb and all PC
224   * compatible hardware
225   */
226  setdbat(1, 0x80000000, 0x80000000, 0x10000000, IO_PAGE);
227  /*
228   * PCI devices memory area. Needed to access OPENPIC features
229   * provided by the RAVEN
230   */
231  setdbat(2, 0xc0000000, 0xc0000000, 0x08000000, IO_PAGE);
232  /*
233   * Must have acces to open pic PCI ACK registers
234   * provided by the RAVEN
235   */
236  setdbat(3, 0xfeff0000, 0xfeff0000, 0x10000, IO_PAGE);
237
238  select_console(CONSOLE_LOG);
239
240  /* We check that the keyboard is present and immediately
241   * select the serial console if not.
242   */
243  err = kbdreset();
244  if (err) select_console(CONSOLE_SERIAL);
245
246  boardManufacturer   =  checkPrepBoardType(&residualCopy);
247  if (boardManufacturer != PREP_Motorola) {
248    printk("Unsupported hardware vendor\n");
249    while (1);
250  }
251  myBoard = getMotorolaBoard();
252 
253  printk("-----------------------------------------\n");
254  printk("Welcome to %s on %s\n", _RTEMS_version, motorolaBoardToString(myBoard));
255  printk("-----------------------------------------\n");
256#ifdef SHOW_MORE_INIT_SETTINGS 
257  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
258  printk("Additionnal boot options are %s\n", loaderParam);
259  printk("Initial system stack at %x\n",stack);
260  printk("Software IRQ stack at %x\n",intrStack);
261  printk("-----------------------------------------\n");
262#endif
263
264#ifdef TEST_RETURN_TO_PPCBUG 
265  printk("Hit <Enter> to return to PPCBUG monitor\n");
266  printk("When Finished hit GO. It should print <Back from monitor>\n");
267  debug_getc();
268  _return_to_ppcbug();
269  printk("Back from monitor\n");
270  _return_to_ppcbug();
271#endif /* TEST_RETURN_TO_PPCBUG  */
272
273#ifdef SHOW_MORE_INIT_SETTINGS
274  printk("Going to start PCI buses scanning and initialization\n");
275#endif 
276  InitializePCI();
277#ifdef SHOW_MORE_INIT_SETTINGS
278  printk("Number of PCI buses found is : %d\n", BusCountPCI());
279#endif
280#ifdef TEST_RAW_EXCEPTION_CODE 
281  printk("Testing exception handling Part 1\n");
282  /*
283   * Cause a software exception
284   */
285  __asm__ __volatile ("sc");
286  /*
287   * Check we can still catch exceptions and returned coorectly.
288   */
289  printk("Testing exception handling Part 2\n");
290  __asm__ __volatile ("sc");
291#endif 
292
293
294  BSP_mem_size                          = residualCopy.TotalMemory;
295  BSP_bus_frequency                     = residualCopy.VitalProductData.ProcessorBusHz;
296  BSP_processor_frequency               = residualCopy.VitalProductData.ProcessorHz;
297  BSP_time_base_divisor                 = (residualCopy.VitalProductData.TimeBaseDivisor?
298                                           residualCopy.VitalProductData.TimeBaseDivisor : 4000);
299 
300  /*
301   * Set up our hooks
302   * Make sure libc_init is done before drivers initialized so that
303   * they can use atexit()
304   */
305
306  Cpu_table.pretasking_hook             = bsp_pretasking_hook;    /* init libc, etc. */
307  Cpu_table.postdriver_hook             = bsp_postdriver_hook;
308  Cpu_table.do_zero_of_workspace        = TRUE;
309  Cpu_table.interrupt_stack_size        = INTR_STACK_SIZE;
310  Cpu_table.clicks_per_usec             = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
311  Cpu_table.exceptions_in_RAM           = TRUE;
312
313#ifdef SHOW_MORE_INIT_SETTINGS
314  printk("BSP_Configuration.work_space_size = %x\n", BSP_Configuration.work_space_size);
315#endif 
316  work_space_start = 
317    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
318
319  if ( work_space_start <= ((unsigned char *)&__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
320    printk( "bspstart: Not enough RAM!!!\n" );
321    bsp_cleanup();
322  }
323
324  BSP_Configuration.work_space_start = work_space_start;
325
326  /*
327   *  Account for the console's resources
328   */
329
330  console_reserve_resources( &BSP_Configuration );
331  /*
332   * Initalize RTEMS IRQ system
333   */
334  BSP_rtems_irq_mng_init(0);
335#ifdef SHOW_MORE_INIT_SETTINGS
336  printk("Exit from bspstart\n");
337#endif 
338}
Note: See TracBrowser for help on using the repository browser.