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

4.104.114.84.95
Last change on this file since 514cf30 was 5993d02, checked in by Joel Sherrill <joel.sherrill@…>, on 10/23/97 at 15:12:08

Added console_reserve_resources.

  • Property mode set to 100644
File size: 8.8 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-1997.
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#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
237/*
238 *  bsp_start
239 *
240 *  This routine does the bulk of the system initialization.
241 */
242
243void bsp_start( void )
244{
245  unsigned char *work_space_start;
246
247  /* Check if MEC is initialised */
248
249  if (!(ERC32_MEC.Control & 0xfe080000)) {
250
251  /*
252   *  DISABLE THE HARDWARE WATCHDOG!!!
253   */
254
255    ERC32_MEC.Watchdog_Trap_Door_Set = 0;          /* value is irrelevant */
256
257  /*
258   *  Reduce the number of wait states to 0 for all memory areas.
259   */
260
261    ERC32_MEC.Wait_State_Configuration = 0;
262
263  }
264 
265  /*
266   * Set up our hooks
267   * Make sure libc_init is done before drivers initialized so that
268   * they can use atexit()
269   */
270
271  Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
272
273  Cpu_table.predriver_hook = NULL; /* bsp_spurious_initialize;*/
274
275  Cpu_table.postdriver_hook = bsp_postdriver_hook;
276
277  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
278
279  /*
280   *  SIS does zero out memory BUT only when IT begins execution.  Thus
281   *  if we want to have a clean slate in the workspace each time we
282   *  begin execution of OUR application, then we must zero the workspace.
283   */
284
285  Cpu_table.do_zero_of_workspace = TRUE;
286
287  /*
288   *  This should be enough interrupt stack.
289   */
290
291  Cpu_table.interrupt_stack_size = (24 * 1024);
292
293  /*
294   *  SIS does not support MP configurations so there is really no way
295   *  to check this out.
296   */
297
298  Cpu_table.extra_mpci_receive_server_stack = 0;
299
300  /*
301   *  Copy the table and allocate memory for the RTEMS Workspace
302   */
303
304  BSP_Configuration = Configuration;
305
306#if defined(RTEMS_POSIX_API)
307  BSP_Configuration.work_space_size *= 3;
308#endif
309
310  work_space_start =
311    (unsigned char *)rdb_start - BSP_Configuration.work_space_size;
312
313  if ( work_space_start <= (unsigned char *)&end ) {
314    DEBUG_puts( "bspstart: Not enough RAM!!!\n" );
315    BSP_fatal_return();
316  }
317
318  BSP_Configuration.work_space_start = work_space_start;
319
320  /*
321   * Add 1 region for RTEMS Malloc
322   */
323
324  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
325
326  /*
327   *  Account for the console's resources
328   */
329
330  console_reserve_resources( &BSP_Configuration );
331
332#ifdef RTEMS_NEWLIB
333  /*
334   * Add 1 extension for newlib libc
335   */
336
337  BSP_Configuration.maximum_extensions++;
338#endif
339
340#ifdef STACK_CHECKER_ON
341  /*
342   * Add 1 extension for stack checker
343   */
344
345  BSP_Configuration.maximum_extensions++;
346#endif
347
348#if SIMSPARC_FAST_IDLE
349  /*
350   * Add 1 extension for fast idle
351   */
352
353  BSP_Configuration.maximum_extensions++;
354#endif
355
356  /*
357   * Add 1 extension for MPCI_fatal
358   */
359
360  if (BSP_Configuration.User_multiprocessing_table)
361    BSP_Configuration.maximum_extensions++;
362
363  /*
364   * Set the "clicks per tick" for the simulator
365   *  used by XXX/clock/clock.c to schedule interrupts
366   */
367
368  CPU_SPARC_CLICKS_PER_TICK = BSP_Configuration.microseconds_per_tick;
369
370  /*
371   *  Initialize RTEMS. main() will finish it up and start multitasking.
372   */
373
374  rtems_libio_config( &BSP_Configuration, BSP_LIBIO_MAX_FDS );
375 
376  bsp_isr_level = rtems_initialize_executive_early(
377     &BSP_Configuration,
378     &Cpu_table
379  );
380}
Note: See TracBrowser for help on using the repository browser.