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