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

4.104.114.84.95
Last change on this file since b06e68ef was b06e68ef, checked in by Joel Sherrill <joel.sherrill@…>, on 08/17/95 at 19:51:51

Numerous miscellaneous features incorporated from Tony Bennett
(tbennett@…) including the following major additions:

+ variable length messages
+ named devices
+ debug monitor
+ association tables/variables

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