source: rtems/c/src/lib/libbsp/hppa1.1/simhppa/startup/bspstart.c @ 9700578

4.104.114.84.95
Last change on this file since 9700578 was 9700578, checked in by Joel Sherrill <joel.sherrill@…>, on 10/30/95 at 21:54:45

SPARC port passes all tests

  • Property mode set to 100644
File size: 9.7 KB
Line 
1/*
2 *      @(#)bspstart.c  1.16 - 95/06/28
3 */
4
5/*  bsp_start()
6 *
7 *  This routine starts the application.  It includes application,
8 *  board, and monitor specific initialization and configuration.
9 *  The generic CPU dependent initialization has been performed
10 *  before this routine is invoked.
11 *
12 *  Called by RTEMS::RTEMS constructor in startup-ctor.cc
13 *
14 *  INPUT:  NONE
15 *
16 *  OUTPUT: NONE
17 *
18 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
19 *  On-Line Applications Research Corporation (OAR).
20 *  All rights assigned to U.S. Government, 1994.
21 *
22 *  This material may be reproduced by or for the U.S. Government pursuant
23 *  to the copyright license under the clause at DFARS 252.227-7013.  This
24 *  notice must appear in all copies of this file and its derivatives.
25 *
26 *  $Id$
27 */
28
29#include <rtems.h>
30#include <bsp.h>
31#include <rtems/libio.h>
32#include <rtems/intthrd.h>
33
34#include <libcsupport.h>
35
36#include <string.h>
37#include <fcntl.h>
38
39#ifdef STACK_CHECKER_ON
40#include <stackchk.h>
41#endif
42
43extern rtems_configuration_table  Configuration;
44
45rtems_configuration_table BSP_Configuration;
46rtems_cpu_table           Cpu_table;
47rtems_unsigned32          bsp_isr_level;
48
49#define WORKSPACE_SIZE (1024 * 1024)
50rtems_unsigned8   MY_WORK_SPACE[ WORKSPACE_SIZE ];
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
58rtems_unsigned32 CPU_HPPA_CLICKS_PER_TICK;
59
60#if SIMHPPA_FAST_IDLE
61
62/*
63 * Many of the tests are very slow on the simulator because they have
64 * have 5 second delays hardwired in.
65 * Try to speed those tests up by speeding up the clock when in idle
66 */
67
68rtems_extension
69fast_idle_switch_hook(rtems_tcb *current_task,
70                      rtems_tcb *heir_task)
71{
72    static rtems_unsigned32 normal_clock = ~0;
73    static rtems_unsigned32 fast_clock;
74
75    /* init our params on first call */
76    if (normal_clock == ~0)
77    {
78        normal_clock = CPU_HPPA_CLICKS_PER_TICK;
79        fast_clock = CPU_HPPA_CLICKS_PER_TICK / 0x100;
80        if (fast_clock == 0)    /* who? me?  pathological?  never! */
81            fast_clock++;
82    }
83
84    /*
85     * Checking for 'name' field of 'IDLE' is not the best/safest,
86     * but its the best we could think of at the moment.
87     */
88
89    if (heir_task == _Internal_threads_Idle_thread)
90        CPU_HPPA_CLICKS_PER_TICK = fast_clock;
91    else if (current_task == _Internal_threads_Idle_thread)
92        CPU_HPPA_CLICKS_PER_TICK = normal_clock;
93}
94
95#endif
96
97/*
98 *  Function:   bsp_libc_init
99 *  Created:    94/12/6
100 *
101 *  Description:
102 *      Initialize whatever libc we are using
103 *      called from bsp_postdriver_hook
104 *
105 *
106 *  Parameters:
107 *      none
108 *
109 *  Returns:
110 *      none.
111 *
112 *  Side Effects:
113 *
114 *
115 *  Notes:
116 *
117 *  Deficiencies/ToDo:
118 *
119 *
120 */
121
122void
123bsp_libc_init(void)
124{
125    extern int end;
126    rtems_unsigned32        heap_start;
127
128    heap_start = (rtems_unsigned32) &end;
129    if (heap_start & (CPU_ALIGNMENT-1))
130        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
131
132    RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0);
133
134    /*
135     *  Init the RTEMS libio facility to provide UNIX-like system
136     *  calls for use by newlib (ie: provide __open, __close, etc)
137     *  Uses malloc() to get area for the iops, so must be after malloc init
138     */
139
140    rtems_libio_init();
141
142    /*
143     * Set up for the libc handling.
144     * XXX; this should allow for case of some other non-clock interrupts
145     */
146
147    if (BSP_Configuration.ticks_per_timeslice > 0)
148        libc_init(1);                /* reentrant if possible */
149    else
150        libc_init(0);                /* non-reentrant */
151
152    /*
153     * on MP systems, always use the print buffer
154     *  instead of the (broken) system calls
155     */
156
157    if (BSP_Configuration.User_multiprocessing_table)
158        use_print_buffer = 1;
159
160#ifdef SIMHPPA_ROM
161    use_print_buffer = 1;
162#endif
163}
164
165
166/*
167 *  Function:   bsp_pretasking_hook
168 *  Created:    95/03/10
169 *
170 *  Description:
171 *      BSP pretasking hook.  Called just before drivers are initialized.
172 *      Used to setup libc and install any BSP extensions.
173 *
174 *  Parameters:
175 *      none
176 *
177 *  Returns:
178 *      nada
179 *
180 *  Side Effects:
181 *      installs a few extensions
182 *
183 *  Notes:
184 *      Must not use libc (to do io) from here, since drivers are
185 *      not yet initialized.
186 *
187 *  Deficiencies/ToDo:
188 *
189 *
190 */
191
192void
193bsp_pretasking_hook(void)
194{
195    bsp_libc_init();
196
197#if SIMHPPA_FAST_IDLE
198    /*
199     * Install the fast idle task switch extension
200     *
201     * on MP systems, might now want to do this; it confuses at least
202     * one test (mp06)
203     */
204
205#if 0
206    if (BSP_Configuration.User_multiprocessing_table == 0)
207#endif
208    {
209        rtems_extensions_table  fast_idle_extension;
210        rtems_id                extension_id;
211        rtems_status_code       rc;
212
213        memset(&fast_idle_extension, 0, sizeof(fast_idle_extension));
214
215        fast_idle_extension.thread_switch  = fast_idle_switch_hook;
216
217        rc = rtems_extension_create(rtems_build_name('F', 'D', 'L', 'E'),
218                              &fast_idle_extension, &extension_id);
219        if (rc != RTEMS_SUCCESSFUL)
220            rtems_fatal_error_occurred(rc);
221    }
222#endif
223
224
225#ifdef STACK_CHECKER_ON
226    /*
227     *  Initialize the stack bounds checker
228     *  We can either turn it on here or from the app.
229     */
230
231    Stack_check_Initialize();
232#endif
233}
234
235/*
236 * After drivers are setup, register some "filenames"
237 * and open stdin, stdout, stderr files
238 *
239 * Newlib will automatically associate the files with these
240 * (it hardcodes the numbers)
241 */
242
243void
244bsp_postdriver_hook(void)
245{
246  int stdin_fd, stdout_fd, stderr_fd;
247  int error_code;
248 
249  error_code = 'S' << 24 | 'T' << 16;
250 
251  if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
252    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
253 
254  if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
255    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
256 
257  if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
258    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
259 
260  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
261    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
262}
263
264/*
265 *  Function:   bsp_start
266 *  Created:    94/12/6
267 *
268 *  Description:
269 *      called by crt0 as our "main" equivalent
270 *
271 *
272 *
273 *  Parameters:
274 *
275 *
276 *  Returns:
277 *
278 *
279 *  Side Effects:
280 *
281 *
282 *  Notes:
283 *
284 *
285 *  Deficiencies/ToDo:
286 *
287 *
288 */
289
290
291void
292bsp_start(void)
293{
294    /*
295     * Set cpu_number to accurately reflect our cpu number
296     */
297
298#ifdef hppa7200
299    /*
300     * Use HPPA_DR0 if supported
301     */
302    {
303        int dr0;
304        HPPA_ASM_MFCPU(HPPA_DR0, dr0);
305        cpu_number = (dr0 >> 4) & 0x7;
306    }
307#else
308    if (Configuration.User_multiprocessing_table)
309        cpu_number = Configuration.User_multiprocessing_table->node - 1;
310    else
311        cpu_number = 0;
312#endif
313
314    /*
315     *  Copy the table
316     */
317
318    BSP_Configuration = Configuration;
319
320    BSP_Configuration.work_space_start = (void *)MY_WORK_SPACE;
321    if (BSP_Configuration.work_space_size)
322        BSP_Configuration.work_space_size = WORKSPACE_SIZE;
323
324    /*
325     * Set up our hooks
326     * Make sure libc_init is done before drivers init'd so that
327     * they can use atexit()
328     */
329
330    Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
331
332    Cpu_table.predriver_hook = NULL;
333
334    Cpu_table.postdriver_hook = bsp_postdriver_hook;    /* register drivers */
335
336    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
337
338    /*
339     *  Don't zero out the workspace.  The simulator did it for us.
340     */
341
342    Cpu_table.do_zero_of_workspace = FALSE;
343
344    Cpu_table.interrupt_stack_size = (12 * 1024);
345
346    Cpu_table.extra_system_initialization_stack = 0;
347
348    /*
349     * Set this artificially low for the simulator
350     */
351
352    Cpu_table.itimer_clicks_per_microsecond = 1;
353
354    /*
355     * Determine the external interrupt processing order
356     * the external interrupt handler walks thru this table, in
357     * order checking for posted interrupts.
358     */
359
360    Cpu_table.external_interrupts = 0;
361
362    Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] =
363         HPPA_INTERRUPT_EXTERNAL_INTERVAL_TIMER - HPPA_INTERRUPT_EXTERNAL_BASE;
364    Cpu_table.external_interrupts++;
365
366    if ( Configuration.User_multiprocessing_table ) {
367      Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] =
368         HPPA_INTERRUPT_EXTERNAL_10 - HPPA_INTERRUPT_EXTERNAL_BASE;
369      Cpu_table.external_interrupts++;
370    }
371
372    /*
373     * Add 1 region for RTEMS Malloc
374     */
375
376    BSP_Configuration.maximum_regions++;
377
378#ifdef RTEMS_NEWLIB
379    /*
380     * Add 1 extension for newlib libc
381     */
382
383    BSP_Configuration.maximum_extensions++;
384#endif
385
386#ifdef STACK_CHECKER_ON
387    /*
388     * Add 1 extension for stack checker
389     */
390
391    BSP_Configuration.maximum_extensions++;
392#endif
393
394#if SIMHPPA_FAST_IDLE
395    /*
396     * Add 1 extension for fast idle
397     */
398
399    BSP_Configuration.maximum_extensions++;
400#endif
401
402    /*
403     * Tell libio how many fd's we want and allow it to tweak config
404     */
405
406    rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
407
408    /*
409     * Add 1 extension for MPCI_fatal
410     */
411
412    if (BSP_Configuration.User_multiprocessing_table)
413        BSP_Configuration.maximum_extensions++;
414
415    /*
416     * Set the "clicks per tick" for the simulator
417     *  used by libcpu/hppa/clock/clock.c to schedule interrupts
418     *
419     * Set it only if 0 to allow for simulator setting it via script
420     *   on test startup.
421     */
422
423    if (CPU_HPPA_CLICKS_PER_TICK == 0)
424        CPU_HPPA_CLICKS_PER_TICK = 0x4000;
425
426    /*
427     *  Start most of RTEMS
428     *  main() will start the rest
429     */
430
431    bsp_isr_level = rtems_initialize_executive_early(
432      &BSP_Configuration,
433      &Cpu_table
434    );
435}
Note: See TracBrowser for help on using the repository browser.