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

Last change on this file since 09b6a093 was 09b6a093, checked in by Joel Sherrill <joel.sherrill@…>, on 05/24/00 at 17:06:54

Significantly lowered the default memory requirements:

  • CONFIGURE_RTEMS_INIT_TASKS_TABLE was 10 now 0
  • CONFIGURE_POSIX_INIT_THREAD_TABLE was 10 now 0
  • CONFIGURE_ITRON_INIT_TASK_TABLE was 10 now 0
  • CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS was 20 now 3
  • added CONFIGURE_NUMBER_OF_TERMIOS_PORTS and defaulted to 1
  • added CONFIGURE_TERMIOS_DISABLED defaulted to "enabled"
  • miniIMFS is now the default

Added configuration error checks that:

+ Ensure > 0 tasks/threads are configured
+ Ensure at least one inititalization task/thread is defined

bsp.h now defines these so BSP specific requirements
are accounted for.

+ CONFIGURE_NUMBER_OF_TERMIOS_PORTS
+ CONFIGURE_INTERRUPT_STACK_MEMORY

console_reserve_resources and rtems_termios_reserve_resources
are no longer required and considered obsolete. Calls to
rtems_termios_reserve_resources have been eliminated although
the routine is still there and the body "if 0'ed".

We are very close to having NO reason to modify the
configuration tables in the BSP. Be warned that eventually
we would like to see the need for BSP_Configuration
eliminated!

  • 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 CONFIGURE_INTERRUPT_STACK_MEMORY
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, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
237  select_console(CONSOLE_LOG);
238
239  /* We check that the keyboard is present and immediately
240   * select the serial console if not.
241   */
242  err = kbdreset();
243  if (err) select_console(CONSOLE_SERIAL);
244
245  boardManufacturer   =  checkPrepBoardType(&residualCopy);
246  if (boardManufacturer != PREP_Motorola) {
247    printk("Unsupported hardware vendor\n");
248    while (1);
249  }
250  myBoard = getMotorolaBoard();
251 
252  printk("-----------------------------------------\n");
253  printk("Welcome to %s on %s\n", _RTEMS_version, motorolaBoardToString(myBoard));
254  printk("-----------------------------------------\n");
255#ifdef SHOW_MORE_INIT_SETTINGS 
256  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
257  printk("Additionnal boot options are %s\n", loaderParam);
258  printk("Initial system stack at %x\n",stack);
259  printk("Software IRQ stack at %x\n",intrStack);
260  printk("-----------------------------------------\n");
261#endif
262
263#ifdef TEST_RETURN_TO_PPCBUG 
264  printk("Hit <Enter> to return to PPCBUG monitor\n");
265  printk("When Finished hit GO. It should print <Back from monitor>\n");
266  debug_getc();
267  _return_to_ppcbug();
268  printk("Back from monitor\n");
269  _return_to_ppcbug();
270#endif /* TEST_RETURN_TO_PPCBUG  */
271
272#ifdef SHOW_MORE_INIT_SETTINGS
273  printk("Going to start PCI buses scanning and initialization\n");
274#endif 
275  InitializePCI();
276#ifdef SHOW_MORE_INIT_SETTINGS
277  printk("Number of PCI buses found is : %d\n", BusCountPCI());
278#endif
279#ifdef TEST_RAW_EXCEPTION_CODE 
280  printk("Testing exception handling Part 1\n");
281  /*
282   * Cause a software exception
283   */
284  __asm__ __volatile ("sc");
285  /*
286   * Check we can still catch exceptions and returned coorectly.
287   */
288  printk("Testing exception handling Part 2\n");
289  __asm__ __volatile ("sc");
290#endif 
291
292
293  BSP_mem_size                          = residualCopy.TotalMemory;
294  BSP_bus_frequency                     = residualCopy.VitalProductData.ProcessorBusHz;
295  BSP_processor_frequency               = residualCopy.VitalProductData.ProcessorHz;
296  BSP_time_base_divisor                 = (residualCopy.VitalProductData.TimeBaseDivisor?
297                                           residualCopy.VitalProductData.TimeBaseDivisor : 4000);
298 
299  /*
300   * Set up our hooks
301   * Make sure libc_init is done before drivers initialized so that
302   * they can use atexit()
303   */
304
305  Cpu_table.pretasking_hook      = bsp_pretasking_hook;    /* init libc, etc. */
306  Cpu_table.postdriver_hook      = bsp_postdriver_hook;
307  Cpu_table.do_zero_of_workspace = TRUE;
308  Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
309  Cpu_table.clicks_per_usec      = BSP_processor_frequency/(BSP_time_base_divisor * 1000);
310  Cpu_table.exceptions_in_RAM    = TRUE;
311
312#ifdef SHOW_MORE_INIT_SETTINGS
313  printk("BSP_Configuration.work_space_size = %x\n", BSP_Configuration.work_space_size);
314#endif 
315  work_space_start =
316    (unsigned char *)BSP_mem_size - BSP_Configuration.work_space_size;
317
318  if ( work_space_start <= ((unsigned char *)&__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
319    printk( "bspstart: Not enough RAM!!!\n" );
320    bsp_cleanup();
321  }
322
323  BSP_Configuration.work_space_start = work_space_start;
324
325  /*
326   * Initalize RTEMS IRQ system
327   */
328  BSP_rtems_irq_mng_init(0);
329#ifdef SHOW_MORE_INIT_SETTINGS
330  printk("Exit from bspstart\n");
331#endif 
332}
Note: See TracBrowser for help on using the repository browser.