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

4.104.114.84.95
Last change on this file since 79aaec8 was 79aaec8, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 21, 1995 at 5:47:06 PM

Fixed problem in fast_idle_switch_hook

  • Property mode set to 100644
File size: 9.5 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/core/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   
248    if ((stdin_fd = __open("/dev/tty00", O_RDONLY, 0)) == -1)
249        rtems_fatal_error_occurred('STD0');
250
251    if ((stdout_fd = __open("/dev/tty00", O_WRONLY, 0)) == -1)
252        rtems_fatal_error_occurred('STD1');
253
254    if ((stderr_fd = __open("/dev/tty00", O_WRONLY, 0)) == -1)
255        rtems_fatal_error_occurred('STD2');
256
257    if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
258        rtems_fatal_error_occurred('STIO');
259}
260
261/*
262 *  Function:   bsp_start
263 *  Created:    94/12/6
264 *
265 *  Description:
266 *      called by crt0 as our "main" equivalent
267 *
268 *
269 *
270 *  Parameters:
271 *
272 *
273 *  Returns:
274 *
275 *
276 *  Side Effects:
277 *
278 *
279 *  Notes:
280 *
281 *
282 *  Deficiencies/ToDo:
283 *
284 *
285 */
286
287
288void
289bsp_start(void)
290{
291    /*
292     * Set cpu_number to accurately reflect our cpu number
293     */
294
295#ifdef hppa7200
296    /*
297     * Use HPPA_DR0 if supported
298     */
299    {
300        int dr0;
301        HPPA_ASM_MFCPU(HPPA_DR0, dr0);
302        cpu_number = (dr0 >> 4) & 0x7;
303    }
304#else
305    if (Configuration.User_multiprocessing_table)
306        cpu_number = Configuration.User_multiprocessing_table->node - 1;
307    else
308        cpu_number = 0;
309#endif
310
311    /*
312     *  Copy the table
313     */
314
315    BSP_Configuration = Configuration;
316
317    BSP_Configuration.work_space_start = (void *)MY_WORK_SPACE;
318    if (BSP_Configuration.work_space_size)
319        BSP_Configuration.work_space_size = WORKSPACE_SIZE;
320
321    /*
322     * Set up our hooks
323     * Make sure libc_init is done before drivers init'd so that
324     * they can use atexit()
325     */
326
327    Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
328
329    Cpu_table.predriver_hook = NULL;
330
331    Cpu_table.postdriver_hook = bsp_postdriver_hook;    /* register drivers */
332
333    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
334
335    /*
336     *  Don't zero out the workspace.  The simulator did it for us.
337     */
338
339    Cpu_table.do_zero_of_workspace = FALSE;
340
341    Cpu_table.interrupt_stack_size = (12 * 1024);
342
343    Cpu_table.extra_system_initialization_stack = 0;
344
345    /*
346     * Set this artificially low for the simulator
347     */
348
349    Cpu_table.itimer_clicks_per_microsecond = 1;
350
351    /*
352     * Determine the external interrupt processing order
353     * the external interrupt handler walks thru this table, in
354     * order checking for posted interrupts.
355     */
356
357    Cpu_table.external_interrupts = 0;
358
359    Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] =
360         HPPA_INTERRUPT_EXTERNAL_INTERVAL_TIMER - HPPA_INTERRUPT_EXTERNAL_BASE;
361    Cpu_table.external_interrupts++;
362
363    if ( Configuration.User_multiprocessing_table ) {
364      Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] =
365         HPPA_INTERRUPT_EXTERNAL_10 - HPPA_INTERRUPT_EXTERNAL_BASE;
366      Cpu_table.external_interrupts++;
367    }
368
369    /*
370     * Add 1 region for RTEMS Malloc
371     */
372
373    BSP_Configuration.maximum_regions++;
374
375#ifdef RTEMS_NEWLIB
376    /*
377     * Add 1 extension for newlib libc
378     */
379
380    BSP_Configuration.maximum_extensions++;
381#endif
382
383#ifdef STACK_CHECKER_ON
384    /*
385     * Add 1 extension for stack checker
386     */
387
388    BSP_Configuration.maximum_extensions++;
389#endif
390
391#if SIMHPPA_FAST_IDLE
392    /*
393     * Add 1 extension for fast idle
394     */
395
396    BSP_Configuration.maximum_extensions++;
397#endif
398
399    /*
400     * Tell libio how many fd's we want and allow it to tweak config
401     */
402
403    rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
404
405    /*
406     * Add 1 extension for MPCI_fatal
407     */
408
409    if (BSP_Configuration.User_multiprocessing_table)
410        BSP_Configuration.maximum_extensions++;
411
412    /*
413     * Set the "clicks per tick" for the simulator
414     *  used by libcpu/hppa/clock/clock.c to schedule interrupts
415     *
416     * Set it only if 0 to allow for simulator setting it via script
417     *   on test startup.
418     */
419
420    if (CPU_HPPA_CLICKS_PER_TICK == 0)
421        CPU_HPPA_CLICKS_PER_TICK = 0x4000;
422
423    /*
424     *  Start most of RTEMS
425     *  main() will start the rest
426     */
427
428    bsp_isr_level = rtems_initialize_executive_early(
429      &BSP_Configuration,
430      &Cpu_table
431    );
432}
Note: See TracBrowser for help on using the repository browser.