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

4.104.114.84.95
Last change on this file since e2a2ec60 was e2a2ec60, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 21, 1998 at 3:37:18 PM

Switch to using a shared main() for all of the embedded BSPs
based on the GNU tools. This usually involved correcting the
type of bsp_start(), bsp_cleanup(), adjusting the start code to
call the right start routine (the shared boot_card()), and then
removing code from bsp_start() which was performed in the new
boot_card()/main() path.

  • Property mode set to 100644
File size: 9.5 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-1998.
15 *  On-Line Applications Research Corporation (OAR).
16 *  Copyright assigned to U.S. Government, 1994.
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.OARcorp.com/rtems/license.html.
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;
42
43int cpu_number;
44
45#define WORKSPACE_SIZE (1024 * 1024)
46rtems_unsigned8   MY_WORK_SPACE[ WORKSPACE_SIZE ];
47
48/*
49 * Amount to increment itimer by each pass
50 * It is a variable instead of a #define to allow the 'looptest'
51 * script to bump it without recompiling rtems
52 */
53
54rtems_unsigned32 CPU_HPPA_CLICKS_PER_TICK;
55
56#if SIMHPPA_FAST_IDLE
57
58/*
59 * Many of the tests are very slow on the simulator because they have
60 * have 5 second delays hardwired in.
61 * Try to speed those tests up by speeding up the clock when in idle
62 */
63
64rtems_extension
65fast_idle_switch_hook(rtems_tcb *current_task,
66                      rtems_tcb *heir_task)
67{
68    static rtems_unsigned32 normal_clock = ~0;
69    static rtems_unsigned32 fast_clock;
70
71    /* init our params on first call */
72    if (normal_clock == (rtems_unsigned32) ~0)
73    {
74        normal_clock = CPU_HPPA_CLICKS_PER_TICK;
75        fast_clock = CPU_HPPA_CLICKS_PER_TICK / 0x100;
76        if (fast_clock == 0)    /* who? me?  pathological?  never! */
77            fast_clock++;
78    }
79
80    /*
81     * Checking for 'name' field of 'IDLE' is not the best/safest,
82     * but its the best we could think of at the moment.
83     */
84
85    if (heir_task == _Thread_Idle)
86        CPU_HPPA_CLICKS_PER_TICK = fast_clock;
87    else if (current_task == _Thread_Idle)
88        CPU_HPPA_CLICKS_PER_TICK = normal_clock;
89}
90
91#endif
92
93/*
94 *  Function:   bsp_libc_init
95 *  Created:    94/12/6
96 *
97 *  Description:
98 *      Initialize whatever libc we are using
99 *      called from bsp_postdriver_hook
100 *
101 *
102 *  Parameters:
103 *      none
104 *
105 *  Returns:
106 *      none.
107 *
108 *  Side Effects:
109 *
110 *
111 *  Notes:
112 *
113 *  Deficiencies/ToDo:
114 *
115 *
116 */
117
118void
119bsp_libc_init(void)
120{
121    extern int end;
122    rtems_unsigned32        heap_start;
123
124    heap_start = (rtems_unsigned32) &end;
125    if (heap_start & (CPU_ALIGNMENT-1))
126        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
127
128    RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0);
129
130    /*
131     *  Init the RTEMS libio facility to provide UNIX-like system
132     *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
133     *  Uses malloc() to get area for the iops, so must be after malloc init
134     */
135
136    rtems_libio_init();
137
138    /*
139     * Set up for the libc handling.
140     * XXX; this should allow for case of some other non-clock interrupts
141     */
142
143    if (BSP_Configuration.ticks_per_timeslice > 0)
144        libc_init(1);                /* reentrant if possible */
145    else
146        libc_init(0);                /* non-reentrant */
147
148    /*
149     * on MP systems, always use the print buffer
150     *  instead of the (broken) system calls
151     */
152
153    if (BSP_Configuration.User_multiprocessing_table)
154        use_print_buffer = 1;
155
156#ifdef SIMHPPA_ROM
157    use_print_buffer = 1;
158#endif
159}
160
161
162/*
163 *  Function:   bsp_pretasking_hook
164 *  Created:    95/03/10
165 *
166 *  Description:
167 *      BSP pretasking hook.  Called just before drivers are initialized.
168 *      Used to setup libc and install any BSP extensions.
169 *
170 *  Parameters:
171 *      none
172 *
173 *  Returns:
174 *      nada
175 *
176 *  Side Effects:
177 *      installs a few extensions
178 *
179 *  Notes:
180 *      Must not use libc (to do io) from here, since drivers are
181 *      not yet initialized.
182 *
183 *  Deficiencies/ToDo:
184 *
185 *
186 */
187
188void
189bsp_pretasking_hook(void)
190{
191    bsp_libc_init();
192
193#if SIMHPPA_FAST_IDLE
194    /*
195     * Install the fast idle task switch extension
196     *
197     * on MP systems, might now want to do this; it confuses at least
198     * one test (mp06)
199     */
200
201#if 0
202    if (BSP_Configuration.User_multiprocessing_table == 0)
203#endif
204    {
205        rtems_extensions_table  fast_idle_extension;
206        rtems_id                extension_id;
207        rtems_status_code       rc;
208
209        memset(&fast_idle_extension, 0, sizeof(fast_idle_extension));
210
211        fast_idle_extension.thread_switch  = fast_idle_switch_hook;
212
213        rc = rtems_extension_create(rtems_build_name('F', 'D', 'L', 'E'),
214                              &fast_idle_extension, &extension_id);
215        if (rc != RTEMS_SUCCESSFUL)
216            rtems_fatal_error_occurred(rc);
217    }
218#endif
219
220
221#ifdef STACK_CHECKER_ON
222    /*
223     *  Initialize the stack bounds checker
224     *  We can either turn it on here or from the app.
225     */
226
227    Stack_check_Initialize();
228#endif
229}
230
231/*
232 * After drivers are setup, register some "filenames"
233 * and open stdin, stdout, stderr files
234 *
235 * Newlib will automatically associate the files with these
236 * (it hardcodes the numbers)
237 */
238
239void
240bsp_postdriver_hook(void)
241{
242  int stdin_fd, stdout_fd, stderr_fd;
243  int error_code;
244 
245  error_code = 'S' << 24 | 'T' << 16;
246 
247  if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1)
248    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
249 
250  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
251    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
252 
253  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
254    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
255 
256  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
257    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
258}
259
260/*
261 *  Function:   bsp_start
262 *  Created:    94/12/6
263 *
264 *  Description:
265 *      called by crt0 as our "main" equivalent
266 *
267 *
268 *
269 *  Parameters:
270 *
271 *
272 *  Returns:
273 *
274 *
275 *  Side Effects:
276 *
277 *
278 *  Notes:
279 *
280 *
281 *  Deficiencies/ToDo:
282 *
283 *
284 */
285
286void bsp_start(void)
287{
288    /*
289     * Set cpu_number to accurately reflect our cpu number
290     */
291
292#ifdef hppa7200
293    /*
294     * Use HPPA_DR0 if supported
295     */
296    {
297        int dr0;
298        HPPA_ASM_MFCPU(HPPA_DR0, dr0);
299        cpu_number = (dr0 >> 4) & 0x7;
300    }
301#else
302    if (Configuration.User_multiprocessing_table)
303        cpu_number = Configuration.User_multiprocessing_table->node - 1;
304    else
305        cpu_number = 0;
306#endif
307
308    /*
309     *  Copy the table
310     */
311
312    BSP_Configuration = Configuration;
313
314    BSP_Configuration.work_space_start = (void *)MY_WORK_SPACE;
315    if (BSP_Configuration.work_space_size)
316        BSP_Configuration.work_space_size = WORKSPACE_SIZE;
317
318    /*
319     * Set up our hooks
320     * Make sure libc_init is done before drivers init'd so that
321     * they can use atexit()
322     */
323
324    Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
325
326    Cpu_table.predriver_hook = NULL;
327
328    Cpu_table.postdriver_hook = bsp_postdriver_hook;    /* register drivers */
329
330    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
331
332    /*
333     *  Don't zero out the workspace.  The simulator did it for us.
334     */
335
336    Cpu_table.do_zero_of_workspace = FALSE;
337
338    Cpu_table.interrupt_stack_size = (12 * 1024);
339
340    Cpu_table.extra_mpci_receive_server_stack = 0;
341
342    /*
343     * Set this artificially low for the simulator
344     */
345
346    Cpu_table.itimer_clicks_per_microsecond = 1;
347
348#if 0
349    /*
350     * Commented by DIVISION INC.  External interrupt
351     * processing is now divorced from RTEMS for HPPA.
352     */
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;
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;
369      Cpu_table.external_interrupts++;
370    }
371#endif
372
373    /*
374     * Add 1 region for RTEMS Malloc
375     */
376
377    BSP_Configuration.RTEMS_api_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}
Note: See TracBrowser for help on using the repository browser.