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

4.104.114.84.95
Last change on this file since 9128179 was 133fb0e5, checked in by Joel Sherrill <joel.sherrill@…>, on 03/08/97 at 03:53:37

Larger Workspace when it is a POSIX API. Actually this is just to cover
the extra stack used when GNAT tasks are in the system. This needs to be
cleaned up.

  • Property mode set to 100644
File size: 8.9 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.
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 *  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#include <fcntl.h>
35
36#ifdef STACK_CHECKER_ON
37#include <stackchk.h>
38#endif
39
40/*
41 *  The original table from the application and our copy of it with
42 *  some changes.
43 */
44 
45extern rtems_configuration_table  Configuration;
46rtems_configuration_table         BSP_Configuration;
47
48rtems_cpu_table   Cpu_table;
49rtems_unsigned32  bsp_isr_level;
50
51/*
52 *  Tells us where to put the workspace in case remote debugger is present.
53 */
54
55extern rtems_unsigned32  rdb_start;
56
57/*
58 * Amount to increment itimer by each pass
59 * It is a variable instead of a #define to allow the 'looptest'
60 * script to bump it without recompiling rtems
61 *
62 *  NOTE:  This is based on the PA-RISC simulator.  I don't know if we
63 *         can actually pull this trick on the SPARC simulator.
64 */
65
66rtems_unsigned32 CPU_SPARC_CLICKS_PER_TICK;
67
68#if SIMSPARC_FAST_IDLE
69
70/*
71 * Many of the tests are very slow on the simulator because they have
72 * have 5 second delays hardwired in.
73 *
74 * Try to speed those tests up by speeding up the clock when in the idle task.
75 *
76 *  NOTE:  At the current setting, 5 second delays in the tests take
77 *         approximately 5 seconds of wall time.
78 */
79
80rtems_extension
81fast_idle_switch_hook(rtems_tcb *current_task,
82                      rtems_tcb *heir_task)
83{
84    static rtems_unsigned32 normal_clock = ~0;
85    static rtems_unsigned32 fast_clock;
86
87    /* init our params on first call */
88    if (normal_clock == ~0)
89    {
90        normal_clock = CPU_SPARC_CLICKS_PER_TICK;
91        fast_clock = CPU_SPARC_CLICKS_PER_TICK / 0x08;
92        if (fast_clock == 0)    /* handle pathological case */
93            fast_clock++;
94    }
95
96    /*
97     * Run the clock faster when idle is in place.
98     */
99
100    if (heir_task == _Thread_Idle)
101        CPU_SPARC_CLICKS_PER_TICK = fast_clock;
102    else if (current_task == _Thread_Idle)
103        CPU_SPARC_CLICKS_PER_TICK = normal_clock;
104}
105
106#endif
107
108/*
109 *  bsp_libc_init
110 *
111 *  Initialize whatever libc we are using called from bsp_postdriver_hook.
112 */
113
114void bsp_libc_init(void)
115{
116  extern int end;
117  rtems_unsigned32 heap_start;
118  rtems_unsigned32 heap_size;
119
120  heap_start = (rtems_unsigned32) &end;
121  if (heap_start & (CPU_ALIGNMENT-1))
122    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
123
124  heap_size = BSP_Configuration.work_space_start - (void *)&end;
125  heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
126
127  RTEMS_Malloc_Initialize((void *) heap_start, heap_size, 0);
128
129  /*
130   *  Init the RTEMS libio facility to provide UNIX-like system
131   *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
132   *  Uses malloc() to get area for the iops, so must be after malloc init
133   */
134 
135  rtems_libio_init();
136 
137  /*
138   * Set up for the libc handling.
139   */
140 
141  if (BSP_Configuration.ticks_per_timeslice > 0)
142    libc_init(1);                /* reentrant if possible */
143  else
144    libc_init(0);                /* non-reentrant */
145
146}
147
148
149/*
150 *  bsp_pretasking_hook
151 *
152 *  BSP pretasking hook.  Called just before drivers are initialized.
153 *  Used to setup libc and install any BSP extensions.
154 */
155
156void bsp_pretasking_hook(void)
157{
158  bsp_libc_init();
159
160#if SIMSPARC_FAST_IDLE
161  /*
162   *  Install the fast idle task switch extension
163   *
164   *  On MP systems, might not want to do this; it confuses at least
165   *  one test (mp06) on the PA-RISC simulator
166   */
167
168#if 0
169  if (BSP_Configuration.User_multiprocessing_table == 0)
170#endif
171  {
172    rtems_extensions_table  fast_idle_extension;
173    rtems_id                extension_id;
174    rtems_status_code       rc;
175
176    memset(&fast_idle_extension, 0, sizeof(fast_idle_extension));
177
178    fast_idle_extension.thread_switch  = fast_idle_switch_hook;
179
180    rc = rtems_extension_create(
181      rtems_build_name('F', 'D', 'L', 'E'),
182      &fast_idle_extension,
183      &extension_id
184    );
185    if (rc != RTEMS_SUCCESSFUL)
186      rtems_fatal_error_occurred(rc);
187  }
188#endif
189
190
191#ifdef STACK_CHECKER_ON
192  /*
193   *  Initialize the stack bounds checker
194   *  We can either turn it on here or from the app.
195   */
196
197  Stack_check_Initialize();
198#endif
199
200#ifdef RTEMS_DEBUG
201  rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
202#endif
203
204}
205
206/*
207 *  bsp_postdriver_hook
208 *
209 *  After drivers are setup, register some "filenames"
210 *  and open stdin, stdout, stderr files
211 *
212 *  Newlib will automatically associate the files with these
213 *  (it hardcodes the numbers)
214 */
215 
216void
217bsp_postdriver_hook(void)
218{
219  int stdin_fd, stdout_fd, stderr_fd;
220  int error_code;
221 
222  error_code = 'S' << 24 | 'T' << 16;
223 
224  if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1)
225    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
226 
227  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
228    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
229 
230  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
231    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
232 
233  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
234    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
235 
236  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
237    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
238}
239
240/*
241 *  bsp_start
242 *
243 *  This routine does the bulk of the system initialization.
244 */
245
246void bsp_start( void )
247{
248  unsigned char *work_space_start;
249
250  /* Check if MEc is initialised */
251
252  if (!(ERC32_MEC.Control & 0xfe080000)) {
253
254  /*
255   *  DISABLE THE HARDWARE WATCHDOG!!!
256   */
257
258    ERC32_MEC.Watchdog_Trap_Door_Set = 0;          /* value is irrelevant */
259
260  /*
261   *  Reduce the number of wait states to 0 for all memory areas.
262   */
263
264    ERC32_MEC.Wait_State_Configuration = 0;
265
266  }
267 
268  /*
269   * Set up our hooks
270   * Make sure libc_init is done before drivers initialized so that
271   * they can use atexit()
272   */
273
274  Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
275
276  Cpu_table.predriver_hook = NULL; /* bsp_spurious_initialize;*/
277
278  Cpu_table.postdriver_hook = bsp_postdriver_hook;
279
280  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
281
282  /*
283   *  SIS does zero out memory BUT only when IT begins execution.  Thus
284   *  if we want to have a clean slate in the workspace each time we
285   *  begin execution of OUR application, then we must zero the workspace.
286   */
287
288  Cpu_table.do_zero_of_workspace = TRUE;
289
290  /*
291   *  This should be enough interrupt stack.
292   */
293
294  Cpu_table.interrupt_stack_size = (12 * 1024);
295
296  /*
297   *  SIS does not support MP configurations so there is really no way
298   *  to check this out.
299   */
300
301  Cpu_table.extra_mpci_receive_server_stack = 0;
302
303  /*
304   *  Copy the table and allocate memory for the RTEMS Workspace
305   */
306
307  BSP_Configuration = Configuration;
308
309#if defined(RTEMS_POSIX_API)
310  BSP_Configuration.work_space_size *= 3;
311#endif
312
313  work_space_start =
314    (unsigned char *)rdb_start - BSP_Configuration.work_space_size;
315
316  if ( work_space_start <= (unsigned char *)&end ) {
317    DEBUG_puts( "bspstart: Not enough RAM!!!\n" );
318    BSP_fatal_return();
319  }
320
321  BSP_Configuration.work_space_start = work_space_start;
322
323  /*
324   * Add 1 region for RTEMS Malloc
325   */
326
327  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
328
329#ifdef RTEMS_NEWLIB
330  /*
331   * Add 1 extension for newlib libc
332   */
333
334  BSP_Configuration.maximum_extensions++;
335#endif
336
337#ifdef STACK_CHECKER_ON
338  /*
339   * Add 1 extension for stack checker
340   */
341
342  BSP_Configuration.maximum_extensions++;
343#endif
344
345#if SIMSPARC_FAST_IDLE
346  /*
347   * Add 1 extension for fast idle
348   */
349
350  BSP_Configuration.maximum_extensions++;
351#endif
352
353  /*
354   * Add 1 extension for MPCI_fatal
355   */
356
357  if (BSP_Configuration.User_multiprocessing_table)
358    BSP_Configuration.maximum_extensions++;
359
360  /*
361   * Set the "clicks per tick" for the simulator
362   *  used by XXX/clock/clock.c to schedule interrupts
363   */
364
365  CPU_SPARC_CLICKS_PER_TICK = BSP_Configuration.microseconds_per_tick;
366
367  /*
368   *  Initialize RTEMS. main() will finish it up and start multitasking.
369   */
370
371  rtems_libio_config( &BSP_Configuration, BSP_LIBIO_MAX_FDS );
372 
373  bsp_isr_level = rtems_initialize_executive_early(
374     &BSP_Configuration,
375     &Cpu_table
376  );
377}
Note: See TracBrowser for help on using the repository browser.