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

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 *      @(#)bspstart.c  1.13 - 95/04/25
3 *     
4 */
5
6/*  bsp_start()
7 *
8 *  This routine starts the application.  It includes application,
9 *  board, and monitor specific initialization and configuration.
10 *  The generic CPU dependent initialization has been performed
11 *  before this routine is invoked.
12 *
13 *  Called by RTEMS::RTEMS constructor in startup-ctor.cc
14 *
15 *  INPUT:  NONE
16 *
17 *  OUTPUT: NONE
18 *
19 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
20 *  On-Line Applications Research Corporation (OAR).
21 *  All rights assigned to U.S. Government, 1994.
22 *
23 *  This material may be reproduced by or for the U.S. Government pursuant
24 *  to the copyright license under the clause at DFARS 252.227-7013.  This
25 *  notice must appear in all copies of this file and its derivatives.
26 *
27 *  $Id$
28 */
29
30#include <bsp.h>
31#include <libcsupport.h>
32
33#include <string.h>
34
35#ifdef STACK_CHECKER_ON
36#include <stackchk.h>
37#endif
38
39extern rtems_configuration_table  Configuration;
40
41rtems_configuration_table BSP_Configuration;
42rtems_cpu_table           Cpu_table;
43rtems_unsigned32          bsp_isr_level;
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 == ~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->name == rtems_build_name('I', 'D', 'L', 'E'))
86        CPU_HPPA_CLICKS_PER_TICK = fast_clock;
87    else if (current_task->name == rtems_build_name('I', 'D', 'L', 'E'))
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     * Set up for the libc handling.
132     */
133
134    if (BSP_Configuration.ticks_per_timeslice > 0)
135        libc_init(1);                /* reentrant if possible */
136    else
137        libc_init(0);                /* non-reentrant */
138
139    /*
140     * on MP systems, always use the print buffer
141     *  instead of the (broken) system calls
142     */
143
144    if (BSP_Configuration.User_multiprocessing_table)
145        use_print_buffer = 1;
146
147#ifdef SIMHPPA_ROM
148    use_print_buffer = 1;
149#endif
150}
151
152
153/*
154 *  Function:   bsp_pretasking_hook
155 *  Created:    95/03/10
156 *
157 *  Description:
158 *      BSP pretasking hook.  Called just before drivers are initialized.
159 *      Used to setup libc and install any BSP extensions.
160 *
161 *  Parameters:
162 *      none
163 *
164 *  Returns:
165 *      nada
166 *
167 *  Side Effects:
168 *      installs a few extensions
169 *
170 *  Notes:
171 *      Must not use libc (to do io) from here, since drivers are
172 *      not yet initialized.
173 *
174 *  Deficiencies/ToDo:
175 *
176 *
177 */
178
179void
180bsp_pretasking_hook(void)
181{
182    bsp_libc_init();
183
184#if SIMHPPA_FAST_IDLE
185    /*
186     * Install the fast idle task switch extension
187     *
188     * on MP systems, might now want to do this; it confuses at least
189     * one test (mp06)
190     */
191
192#if 0
193    if (BSP_Configuration.User_multiprocessing_table == 0)
194#endif
195    {
196        rtems_extensions_table  fast_idle_extension;
197        rtems_id                extension_id;
198        rtems_status_code       rc;
199
200        memset(&fast_idle_extension, 0, sizeof(fast_idle_extension));
201
202        fast_idle_extension.task_switch  = fast_idle_switch_hook;
203
204        rc = rtems_extension_create(rtems_build_name('F', 'D', 'L', 'E'),
205                              &fast_idle_extension, &extension_id);
206        if (rc != RTEMS_SUCCESSFUL)
207            rtems_fatal_error_occurred(rc);
208    }
209#endif
210
211
212#ifdef STACK_CHECKER_ON
213    /*
214     *  Initialize the stack bounds checker
215     *  We can either turn it on here or from the app.
216     */
217
218    Stack_check_Initialize();
219#endif
220}
221
222/*
223 *  Function:   bsp_start
224 *  Created:    94/12/6
225 *
226 *  Description:
227 *      called by crt0 as our "main" equivalent
228 *
229 *
230 *
231 *  Parameters:
232 *
233 *
234 *  Returns:
235 *
236 *
237 *  Side Effects:
238 *
239 *
240 *  Notes:
241 *
242 *
243 *  Deficiencies/ToDo:
244 *
245 *
246 */
247
248
249void
250bsp_start(void)
251{
252    /*
253     * Set cpu_number to accurately reflect our cpu number
254     */
255
256#ifdef hppa7200
257    /*
258     * Use DR0 if supported
259     */
260    {
261        int dr0;
262        HPPA_ASM_MFCPU(DR0, dr0);
263        cpu_number = (dr0 >> 4) & 0x7;
264    }
265#else
266    if (Configuration.User_multiprocessing_table)
267        cpu_number = Configuration.User_multiprocessing_table->node - 1;
268    else
269        cpu_number = 0;
270#endif
271
272    /*
273     *  Copy the table
274     */
275
276    BSP_Configuration = Configuration;
277
278    BSP_Configuration.work_space_start = (void *)MY_WORK_SPACE;
279    if (BSP_Configuration.work_space_size)
280        BSP_Configuration.work_space_size = WORKSPACE_SIZE;
281
282    /*
283     * Set up our hooks
284     * Make sure libc_init is done before drivers init'd so that
285     * they can use atexit()
286     */
287
288    Cpu_table.pretasking_hook = bsp_pretasking_hook;    /* init libc, etc. */
289
290    Cpu_table.predriver_hook = NULL;
291
292    Cpu_table.postdriver_hook = NULL;
293
294    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
295
296    /*
297     *  Don't zero out the workspace.  The simulator did it for us.
298     */
299
300    Cpu_table.do_zero_of_workspace = FALSE;
301
302    Cpu_table.interrupt_stack_size = (12 * 1024);
303
304    Cpu_table.extra_system_initialization_stack = 0;
305
306    /*
307     * Set this artificially low for the simulator
308     */
309
310    Cpu_table.itimer_clicks_per_microsecond = 1;
311
312    /*
313     * Determine the external interrupt processing order
314     * the external interrupt handler walks thru this table, in
315     * order checking for posted interrupts.
316     */
317
318    Cpu_table.external_interrupts = 0;
319
320    Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] =
321         HPPA_INTERRUPT_EXTERNAL_INTERVAL_TIMER - HPPA_INTERRUPT_EXTERNAL_BASE;
322    Cpu_table.external_interrupts++;
323
324    if ( Configuration.User_multiprocessing_table ) {
325      Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] =
326         HPPA_INTERRUPT_EXTERNAL_10 - HPPA_INTERRUPT_EXTERNAL_BASE;
327      Cpu_table.external_interrupts++;
328    }
329
330    /*
331     * Add 1 region for RTEMS Malloc
332     */
333
334    BSP_Configuration.maximum_regions++;
335
336#ifdef RTEMS_NEWLIB
337    /*
338     * Add 1 extension for newlib libc
339     */
340
341    BSP_Configuration.maximum_extensions++;
342#endif
343
344#ifdef STACK_CHECKER_ON
345  /*
346   * Add 1 extension for stack checker
347   */
348
349    BSP_Configuration.maximum_extensions++;
350#endif
351
352#if SIMHPPA_FAST_IDLE
353  /*
354   * Add 1 extension for fast idle
355   */
356
357    BSP_Configuration.maximum_extensions++;
358#endif
359
360    /*
361     * Add 1 extension for MPCI_fatal
362     */
363
364    if (BSP_Configuration.User_multiprocessing_table)
365        BSP_Configuration.maximum_extensions++;
366
367    /*
368     * Set the "clicks per tick" for the simulator
369     *  used by libcpu/hppa/clock/clock.c to schedule interrupts
370     *
371     * Set it only if 0 to allow for simulator setting it via script
372     *   on test startup.
373     */
374
375    if (CPU_HPPA_CLICKS_PER_TICK == 0)
376        CPU_HPPA_CLICKS_PER_TICK = 0x4000;
377
378    /*
379     *  Start most of RTEMS
380     *  main() will start the rest
381     */
382
383    bsp_isr_level = rtems_initialize_executive_early(
384      &BSP_Configuration,
385      &Cpu_table
386    );
387}
Note: See TracBrowser for help on using the repository browser.