source: rtems/c/src/lib/libbsp/powerpc/psim/startup/bspstart.c @ c244a9ee

4.104.114.84.95
Last change on this file since c244a9ee was c244a9ee, checked in by Joel Sherrill <joel.sherrill@…>, on 04/14/98 at 21:32:12

Stack checker extension now accounted for in confdefs.h

  • Property mode set to 100644
File size: 7.9 KB
RevLine 
[8961188]1/*  bspstart.c
2 *
3 *  This set of routines starts the application.  It includes application,
4 *  board, and monitor specific initialization and configuration.
5 *  The generic CPU dependent initialization has been performed
6 *  before any of these are invoked.
7 *
8 *  Called by RTEMS::RTEMS constructor in rtems-ctor.cc
9 *
10 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994, 1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  All rights assigned to U.S. Government, 1994.
13 *
14 *  This material may be reproduced by or for the U.S. Government pursuant
15 *  to the copyright license under the clause at DFARS 252.227-7013.  This
16 *  notice must appear in all copies of this file and its derivatives.
17 *
18 *  $Id$
19 */
20
21#include <bsp.h>
22#include <rtems/libio.h>
23
24#include <libcsupport.h>
25
26#include <string.h>
27#include <fcntl.h>
28
29#ifdef STACK_CHECKER_ON
30#include <stackchk.h>
31#endif
32
33/*
34 *  The original table from the application and our copy of it with
35 *  some changes.
36 */
37 
38extern rtems_configuration_table  Configuration;
39rtems_configuration_table         BSP_Configuration;
40
41rtems_cpu_table   Cpu_table;
42rtems_unsigned32  bsp_isr_level;
43
44/*
45 *  Tells us where to put the workspace in case remote debugger is present.
46 */
47
48#if 0
49extern rtems_unsigned32  rdb_start;
50#endif
51
52/*
53 * Amount to increment itimer by each pass
54 * It is a variable instead of a #define to allow the 'looptest'
55 * script to bump it without recompiling rtems
56 *
57 *  NOTE:  This is based on the PA-RISC simulator.  I don't know if we
58 *         can actually pull this trick on the PPC simulator.
59 */
60
61rtems_unsigned32 CPU_PPC_CLICKS_PER_TICK;
62
63#if PSIM_FAST_IDLE
64
65/*
66 * Many of the tests are very slow on the simulator because they have
67 * have 5 second delays hardwired in.
68 *
69 * Try to speed those tests up by speeding up the clock when in the idle task.
70 *
71 *  NOTE:  At the current setting, 5 second delays in the tests take
72 *         approximately 5 seconds of wall time.
73 */
74
75rtems_extension
76fast_idle_switch_hook(rtems_tcb *current_task,
77                      rtems_tcb *heir_task)
78{
79    static rtems_unsigned32 normal_clock = ~0;
80    static rtems_unsigned32 fast_clock;
81
82    /* init our params on first call */
83    if (normal_clock == (rtems_unsigned32) ~0)
84    {
85        normal_clock = CPU_PPC_CLICKS_PER_TICK;
86        fast_clock = 10000;
87#if 0
88        fast_clock = CPU_PPC_CLICKS_PER_TICK / 0x10 ;
89#endif
90        if (fast_clock == 0)    /* handle pathological case */
91            fast_clock++;
92    }
93
94    /*
95     * Run the clock faster when idle is in place.
96     */
97
98    if (heir_task == _Thread_Idle)
99        CPU_PPC_CLICKS_PER_TICK = fast_clock;
100    else if (current_task == _Thread_Idle)
101        CPU_PPC_CLICKS_PER_TICK = normal_clock;
102}
103
104#endif
105
106/*
107 *  bsp_libc_init
108 *
109 *  Initialize whatever libc we are using called from bsp_postdriver_hook.
110 */
111
112void bsp_libc_init(void)
113{
114  extern int end;
115  rtems_unsigned32 heap_start;
116  rtems_unsigned32 heap_size;
117
118  heap_start = (rtems_unsigned32) &end;
119  if (heap_start & (CPU_ALIGNMENT-1))
120    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
121
122  heap_size = BSP_Configuration.work_space_start - (void *)&end;
123  heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
124
125  RTEMS_Malloc_Initialize((void *) heap_start, heap_size, 0);
126
127  /*
128   *  Init the RTEMS libio facility to provide UNIX-like system
129   *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
130   *  Uses malloc() to get area for the iops, so must be after malloc init
131   */
132 
133  rtems_libio_init();
134 
135  /*
136   * Set up for the libc handling.
137   */
138 
139  if (BSP_Configuration.ticks_per_timeslice > 0)
140    libc_init(1);                /* reentrant if possible */
141  else
142    libc_init(0);                /* non-reentrant */
143
144}
145
146
147/*
148 *  bsp_pretasking_hook
149 *
150 *  BSP pretasking hook.  Called just before drivers are initialized.
151 *  Used to setup libc and install any BSP extensions.
152 */
153
154void bsp_pretasking_hook(void)
155{
156  bsp_libc_init();
157
158#if PSIM_FAST_IDLE
159  /*
160   *  Install the fast idle task switch extension
161   *
162   *  On MP systems, might not want to do this; it confuses at least
163   *  one test (mp06) on the PA-RISC simulator
164   */
165
166#if 0
167  if (BSP_Configuration.User_multiprocessing_table == 0)
168#endif
169  {
170    rtems_extensions_table  fast_idle_extension;
171    rtems_id                extension_id;
172    rtems_status_code       rc;
173
174    memset(&fast_idle_extension, 0, sizeof(fast_idle_extension));
175
176    fast_idle_extension.thread_switch  = fast_idle_switch_hook;
177
178    rc = rtems_extension_create(
179      rtems_build_name('F', 'D', 'L', 'E'),
180      &fast_idle_extension,
181      &extension_id
182    );
183    if (rc != RTEMS_SUCCESSFUL)
184      rtems_fatal_error_occurred(rc);
185  }
186#endif
187
188
189#ifdef STACK_CHECKER_ON
190  /*
191   *  Initialize the stack bounds checker
192   *  We can either turn it on here or from the app.
193   */
194
195  Stack_check_Initialize();
196#endif
197
198#ifdef RTEMS_DEBUG
199  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
200#endif
201
202}
203
204/*
205 *  Use the shared bsp_postdriver_hook() implementation
206 */
207 
208void bsp_postdriver_hook(void);
209
210/*
211 *  bsp_start
212 *
213 *  This routine does the bulk of the system initialization.
214 */
215
216void bsp_start( void )
217{
218  unsigned char *work_space_start;
219
220#if 0
221  /*
222   * Set MSR to show vectors at 0 XXX
223   */
224  _CPU_MSR_Value( msr_value );
225  msr_value &= ~PPC_MSR_EP;
226  _CPU_MSR_SET( msr_value );
227#endif
228
229  /*
230   * Set up our hooks
231   * Make sure libc_init is done before drivers initialized so that
232   * they can use atexit()
233   */
234
235  Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
236
237  Cpu_table.predriver_hook = NULL; /* bsp_spurious_initialize;*/
238
239  Cpu_table.postdriver_hook = bsp_postdriver_hook;
240
241  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
242
243  /*
244   *  PSIM does zero out memory BUT only when IT begins execution.  Thus
245   *  if we want to have a clean slate in the workspace each time we
246   *  begin execution of OUR application, then we must zero the workspace.
247   */
248
249  Cpu_table.do_zero_of_workspace = FALSE;
250
251  /*
252   *  This should be enough interrupt stack.
253   */
254
255  Cpu_table.interrupt_stack_size = (12 * 1024);
256
257  /*
258   *  SIS does not support MP configurations so there is really no way
259   *  to check this out.
260   */
261
262  Cpu_table.extra_mpci_receive_server_stack = 0;
263
264  /*
265   *  The monitor likes the exception table to be at 0x0.
266   */
267
268  Cpu_table.exceptions_in_RAM = TRUE;
269
270  /*
271   *  Copy the table and allocate memory for the RTEMS Workspace
272   */
273
274  BSP_Configuration = Configuration;
275
276#if defined(RTEMS_POSIX_API)
277  BSP_Configuration.work_space_size *= 3;
278#endif
279
280
281#if 0
282  work_space_start =
283    (unsigned char *)rdb_start - BSP_Configuration.work_space_size;
284#endif
285
286  work_space_start =
287    (unsigned char *)&RAM_END - BSP_Configuration.work_space_size;
288
289  if ( work_space_start <= (unsigned char *)&end ) {
290    DEBUG_puts( "bspstart: Not enough RAM!!!\n" );
291    bsp_cleanup();
292  }
293
294  BSP_Configuration.work_space_start = work_space_start;
295
296#ifdef STACK_CHECKER_ON
297  /*
298   * Add 1 extension for stack checker
299   */
300
301  BSP_Configuration.maximum_extensions++;
302#endif
303
304#if PSIM_FAST_IDLE
305  /*
306   * Add 1 extension for fast idle
307   */
308
309  BSP_Configuration.maximum_extensions++;
310#endif
311
312  /*
313   * Set the "clicks per tick" for the simulator
314   *  used by XXX/clock/clock.c to schedule interrupts
315   *
316   *  NOTE: On psim, each click of the decrementer register corresponds
317   *        to 1 instruction.  By setting this to 100, we are indicating
318   *        that we are assuming it can execute 100 instructions per
319   *        microsecond.  This corresponds to sustaining 1 instruction
320   *        per cycle at 100 Mhz.  Whether this is a good guess or not
321   *        is anyone's guess.
322   */
323
324  {
325    extern int PSIM_INSTRUCTIONS_PER_MICROSECOND;
326
327    CPU_PPC_CLICKS_PER_TICK = BSP_Configuration.microseconds_per_tick *
328      (int) &PSIM_INSTRUCTIONS_PER_MICROSECOND;
329  }
330
331  /*
332   *  Initialize RTEMS. main() will finish it up and start multitasking.
333   */
334
335  rtems_libio_config( &BSP_Configuration, BSP_LIBIO_MAX_FDS );
336}
Note: See TracBrowser for help on using the repository browser.