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

4.104.114.84.95
Last change on this file since 8cbbe312 was 8cbbe312, checked in by Joel Sherrill <joel.sherrill@…>, on 02/21/96 at 14:47:03

Dispersal of internal thread handler resulted in the SYSI task being
only required in a multiprocessor system. It was replace by the MPCI
Receive Server. As a result, the CPU Table field for extra stack for
the SYSI task was changed to be extra stack for the MPCI Receive Server.

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