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

4.104.114.84.95
Last change on this file since 71f4beb was 9b64c2d5, checked in by Joel Sherrill <joel.sherrill@…>, on 04/15/98 at 00:10:03

Per suggestion from Eric Norum, went from one initial extension set
to multiple. This lets the stack check extension be installed
at system initialization time and avoids the BSP having to
even know about its existence.

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