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

4.104.114.84.95
Last change on this file since 634e746 was 634e746, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 29, 1997 at 12:28:47 AM

All RTEMS system call implementation renamed to be rtems_*.

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