source: rtems/c/src/lib/libbsp/powerpc/mcp750/startup/bspstart.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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