source: rtems/c/src/lib/libbsp/sparc/erc32/startup/bspstart.c @ 9b64c2d5

4.104.114.84.9
Last change on this file since 9b64c2d5 was 9b64c2d5, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 15, 1998 at 12:10:03 AM

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.4 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-1998.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
19 *  Research Corporation (OAR) under contract to the European Space
20 *  Agency (ESA).
21 *
22 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
23 *  European Space Agency.
24 *
25 *  $Id$
26 */
27
28#include <bsp.h>
29#include <rtems/libio.h>
30
31#include <libcsupport.h>
32
33#include <string.h>
34
35/*
36 *  The original table from the application and our copy of it with
37 *  some changes.
38 */
39 
40extern rtems_configuration_table  Configuration;
41rtems_configuration_table         BSP_Configuration;
42
43rtems_cpu_table   Cpu_table;
44rtems_unsigned32  bsp_isr_level;
45
46/*
47 *  Tells us where to put the workspace in case remote debugger is present.
48 */
49
50extern rtems_unsigned32  rdb_start;
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 SPARC simulator.
59 */
60
61rtems_unsigned32 CPU_SPARC_CLICKS_PER_TICK;
62
63#if SIMSPARC_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 == ~0)
84    {
85        normal_clock = CPU_SPARC_CLICKS_PER_TICK;
86        fast_clock = CPU_SPARC_CLICKS_PER_TICK / 0x08;
87        if (fast_clock == 0)    /* handle pathological case */
88            fast_clock++;
89    }
90
91    /*
92     * Run the clock faster when idle is in place.
93     */
94
95    if (heir_task == _Thread_Idle)
96        CPU_SPARC_CLICKS_PER_TICK = fast_clock;
97    else if (current_task == _Thread_Idle)
98        CPU_SPARC_CLICKS_PER_TICK = normal_clock;
99}
100
101#endif
102
103/*
104 *  bsp_libc_init
105 *
106 *  Initialize whatever libc we are using called from bsp_postdriver_hook.
107 */
108
109void bsp_libc_init(void)
110{
111  extern int end;
112  rtems_unsigned32 heap_start;
113  rtems_unsigned32 heap_size;
114
115  heap_start = (rtems_unsigned32) &end;
116  if (heap_start & (CPU_ALIGNMENT-1))
117    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
118
119  heap_size = BSP_Configuration.work_space_start - (void *)&end;
120  heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
121
122  RTEMS_Malloc_Initialize((void *) heap_start, heap_size, 0);
123
124  /*
125   *  Init the RTEMS libio facility to provide UNIX-like system
126   *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
127   *  Uses malloc() to get area for the iops, so must be after malloc init
128   */
129 
130  rtems_libio_init();
131 
132  /*
133   * Set up for the libc handling.
134   */
135 
136  if (BSP_Configuration.ticks_per_timeslice > 0)
137    libc_init(1);                /* reentrant if possible */
138  else
139    libc_init(0);                /* non-reentrant */
140
141}
142
143
144/*
145 *  bsp_pretasking_hook
146 *
147 *  BSP pretasking hook.  Called just before drivers are initialized.
148 *  Used to setup libc and install any BSP extensions.
149 */
150
151void bsp_pretasking_hook(void)
152{
153  bsp_libc_init();
154
155#if SIMSPARC_FAST_IDLE
156  /*
157   *  Install the fast idle task switch extension
158   *
159   *  On MP systems, might not want to do this; it confuses at least
160   *  one test (mp06) on the PA-RISC simulator
161   */
162
163#if 0
164  if (BSP_Configuration.User_multiprocessing_table == 0)
165#endif
166  {
167    rtems_extensions_table  fast_idle_extension;
168    rtems_id                extension_id;
169    rtems_status_code       rc;
170
171    memset(&fast_idle_extension, 0, sizeof(fast_idle_extension));
172
173    fast_idle_extension.thread_switch  = fast_idle_switch_hook;
174
175    rc = rtems_extension_create(
176      rtems_build_name('F', 'D', 'L', 'E'),
177      &fast_idle_extension, 
178      &extension_id
179    );
180    if (rc != RTEMS_SUCCESSFUL)
181      rtems_fatal_error_occurred(rc);
182  }
183#endif
184
185#ifdef RTEMS_DEBUG
186  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
187#endif
188
189}
190
191/*
192 *  Use the shared bsp_postdriver_hook() implementation
193 */
194 
195void bsp_postdriver_hook(void);
196
197
198/*
199 *  bsp_start
200 *
201 *  This routine does the bulk of the system initialization.
202 */
203
204void bsp_start( void )
205{
206  unsigned char *work_space_start;
207
208  /* Check if MEC is initialised */
209
210  if (!(ERC32_MEC.Control & 0xfe080000)) {
211
212  /*
213   *  DISABLE THE HARDWARE WATCHDOG!!!
214   */
215
216    ERC32_MEC.Watchdog_Trap_Door_Set = 0;          /* value is irrelevant */
217
218  /*
219   *  Reduce the number of wait states to 0 for all memory areas.
220   */
221
222    ERC32_MEC.Wait_State_Configuration = 0; 
223
224  }
225 
226  /*
227   * Set up our hooks
228   * Make sure libc_init is done before drivers initialized so that
229   * they can use atexit()
230   */
231
232  Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
233
234  Cpu_table.predriver_hook = NULL; /* bsp_spurious_initialize;*/
235
236  Cpu_table.postdriver_hook = bsp_postdriver_hook;
237
238  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
239
240  /*
241   *  SIS does zero out memory BUT only when IT begins execution.  Thus
242   *  if we want to have a clean slate in the workspace each time we
243   *  begin execution of OUR application, then we must zero the workspace.
244   */
245
246  Cpu_table.do_zero_of_workspace = TRUE;
247
248  /*
249   *  This should be enough interrupt stack.
250   */
251
252  Cpu_table.interrupt_stack_size = (24 * 1024);
253
254  /*
255   *  SIS does not support MP configurations so there is really no way
256   *  to check this out.
257   */
258
259  Cpu_table.extra_mpci_receive_server_stack = 0;
260
261  /*
262   *  Copy the table and allocate memory for the RTEMS Workspace
263   */
264
265  BSP_Configuration = Configuration;
266
267#if defined(RTEMS_POSIX_API)
268  BSP_Configuration.work_space_size *= 3;
269#endif
270
271  work_space_start = 
272    (unsigned char *)rdb_start - BSP_Configuration.work_space_size;
273
274  if ( work_space_start <= (unsigned char *)&end ) {
275    DEBUG_puts( "bspstart: Not enough RAM!!!\n" );
276    BSP_fatal_return();
277  }
278
279  BSP_Configuration.work_space_start = work_space_start;
280
281  /*
282   *  Account for the console's resources
283   */
284
285  console_reserve_resources( &BSP_Configuration );
286
287#if SIMSPARC_FAST_IDLE
288  /*
289   * Add 1 extension for fast idle
290   */
291
292  BSP_Configuration.maximum_extensions++;
293#endif
294
295  /*
296   * Add 1 extension for MPCI_fatal
297   */
298
299  if (BSP_Configuration.User_multiprocessing_table)
300    BSP_Configuration.maximum_extensions++;
301
302  /*
303   * Set the "clicks per tick" for the simulator
304   *  used by XXX/clock/clock.c to schedule interrupts
305   */
306
307  CPU_SPARC_CLICKS_PER_TICK = BSP_Configuration.microseconds_per_tick;
308
309  /*
310   *  Initialize RTEMS. main() will finish it up and start multitasking.
311   */
312
313  rtems_libio_config( &BSP_Configuration, BSP_LIBIO_MAX_FDS );
314}
Note: See TracBrowser for help on using the repository browser.