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 <stdio.h> |
---|
26 | #include <stdlib.h> |
---|
27 | |
---|
28 | /* for sbrk prototype in linux */ |
---|
29 | #if defined(__linux__) |
---|
30 | #define __USE_MISC |
---|
31 | #endif |
---|
32 | #include <unistd.h> |
---|
33 | |
---|
34 | #include <bsp.h> |
---|
35 | #include <libcsupport.h> |
---|
36 | |
---|
37 | #include <rtems/libio.h> |
---|
38 | |
---|
39 | extern rtems_configuration_table Configuration; |
---|
40 | |
---|
41 | /* |
---|
42 | * A copy of the configuration table from the application |
---|
43 | * with some changes applied to it. |
---|
44 | */ |
---|
45 | |
---|
46 | rtems_configuration_table BSP_Configuration; |
---|
47 | rtems_multiprocessing_table BSP_Multiprocessing; |
---|
48 | rtems_cpu_table Cpu_table; |
---|
49 | rtems_unsigned32 bsp_isr_level; |
---|
50 | rtems_unsigned32 Heap_size; |
---|
51 | int rtems_argc; |
---|
52 | char **rtems_argv; |
---|
53 | |
---|
54 | /* |
---|
55 | * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE |
---|
56 | * environment variables; see below. |
---|
57 | */ |
---|
58 | |
---|
59 | #define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024)) |
---|
60 | #define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024)) |
---|
61 | |
---|
62 | /* |
---|
63 | * Amount to increment itimer by each pass |
---|
64 | * It is a variable instead of a #define to allow the 'looptest' |
---|
65 | * script to bump it without recompiling rtems |
---|
66 | */ |
---|
67 | |
---|
68 | rtems_unsigned32 CPU_CLICKS_PER_TICK; |
---|
69 | |
---|
70 | /* |
---|
71 | * Function: bsp_libc_init |
---|
72 | * Created: 94/12/6 |
---|
73 | * |
---|
74 | * Description: |
---|
75 | * Initialize whatever libc we are using |
---|
76 | * called from bsp_postdriver_hook |
---|
77 | * |
---|
78 | * |
---|
79 | * Parameters: |
---|
80 | * none |
---|
81 | * |
---|
82 | * Returns: |
---|
83 | * none. |
---|
84 | * |
---|
85 | * Side Effects: |
---|
86 | * |
---|
87 | * |
---|
88 | * Notes: |
---|
89 | * |
---|
90 | * Deficiencies/ToDo: |
---|
91 | * |
---|
92 | * |
---|
93 | */ |
---|
94 | |
---|
95 | void |
---|
96 | bsp_libc_init(void) |
---|
97 | { |
---|
98 | void *heap_start; |
---|
99 | |
---|
100 | if (getenv("RTEMS_HEAPSPACE_SIZE")) |
---|
101 | Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0); |
---|
102 | else |
---|
103 | Heap_size = DEFAULT_HEAPSPACE_SIZE; |
---|
104 | |
---|
105 | heap_start = 0; |
---|
106 | |
---|
107 | RTEMS_Malloc_Initialize((void *)heap_start, Heap_size, 1024 * 1024); |
---|
108 | |
---|
109 | /* |
---|
110 | * Init the RTEMS libio facility to provide UNIX-like system |
---|
111 | * calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc) |
---|
112 | * Uses malloc() to get area for the iops, so must be after malloc init |
---|
113 | */ |
---|
114 | |
---|
115 | rtems_libio_init(); |
---|
116 | |
---|
117 | libc_init(1); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | /* |
---|
122 | * Function: bsp_pretasking_hook |
---|
123 | * Created: 95/03/10 |
---|
124 | * |
---|
125 | * Description: |
---|
126 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
127 | * Used to setup libc and install any BSP extensions. |
---|
128 | * |
---|
129 | * Parameters: |
---|
130 | * none |
---|
131 | * |
---|
132 | * Returns: |
---|
133 | * nada |
---|
134 | * |
---|
135 | * Side Effects: |
---|
136 | * installs a few extensions |
---|
137 | * |
---|
138 | * Notes: |
---|
139 | * Must not use libc (to do io) from here, since drivers are |
---|
140 | * not yet initialized. |
---|
141 | * |
---|
142 | * Deficiencies/ToDo: |
---|
143 | * |
---|
144 | * |
---|
145 | */ |
---|
146 | |
---|
147 | void |
---|
148 | bsp_pretasking_hook(void) |
---|
149 | { |
---|
150 | bsp_libc_init(); |
---|
151 | |
---|
152 | #ifdef RTEMS_DEBUG |
---|
153 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
154 | #endif |
---|
155 | |
---|
156 | /* |
---|
157 | * Dump malloc stats on exit... |
---|
158 | */ |
---|
159 | #if defined(RTEMS_DEBUG) |
---|
160 | atexit(malloc_dump); |
---|
161 | #endif |
---|
162 | } |
---|
163 | |
---|
164 | /* |
---|
165 | * DO NOT Use the shared bsp_postdriver_hook() implementation |
---|
166 | */ |
---|
167 | |
---|
168 | void |
---|
169 | bsp_postdriver_hook(void) |
---|
170 | { |
---|
171 | return; |
---|
172 | } |
---|
173 | |
---|
174 | /* |
---|
175 | * Function: bsp_start |
---|
176 | * Created: 94/12/6 |
---|
177 | * |
---|
178 | * Description: |
---|
179 | * called by crt0 as our "main" equivalent |
---|
180 | * |
---|
181 | * |
---|
182 | * |
---|
183 | * Parameters: |
---|
184 | * |
---|
185 | * |
---|
186 | * Returns: |
---|
187 | * |
---|
188 | * |
---|
189 | * Side Effects: |
---|
190 | * |
---|
191 | * |
---|
192 | * Notes: |
---|
193 | * |
---|
194 | * |
---|
195 | * Deficiencies/ToDo: |
---|
196 | * |
---|
197 | * |
---|
198 | */ |
---|
199 | |
---|
200 | void |
---|
201 | bsp_start(void) |
---|
202 | { |
---|
203 | unsigned32 workspace_ptr; |
---|
204 | |
---|
205 | /* |
---|
206 | * Copy the table |
---|
207 | */ |
---|
208 | |
---|
209 | BSP_Configuration = Configuration; |
---|
210 | |
---|
211 | /* |
---|
212 | * If the node number is -1 then the application better provide |
---|
213 | * it through environment variables RTEMS_NODE. |
---|
214 | * Ditto for RTEMS_MAXIMUM_NODES |
---|
215 | */ |
---|
216 | |
---|
217 | if (BSP_Configuration.User_multiprocessing_table) { |
---|
218 | char *p; |
---|
219 | |
---|
220 | /* make a copy for possible editing */ |
---|
221 | BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table; |
---|
222 | BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing; |
---|
223 | |
---|
224 | if (BSP_Multiprocessing.node == -1) |
---|
225 | { |
---|
226 | p = getenv("RTEMS_NODE"); |
---|
227 | BSP_Multiprocessing.node = p ? atoi(p) : 1; |
---|
228 | } |
---|
229 | |
---|
230 | /* If needed provide maximum_nodes also */ |
---|
231 | if (BSP_Multiprocessing.maximum_nodes == -1) |
---|
232 | { |
---|
233 | p = getenv("RTEMS_MAXIMUM_NODES"); |
---|
234 | BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1; |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | /* |
---|
239 | * Set cpu_number to accurately reflect our cpu number |
---|
240 | */ |
---|
241 | |
---|
242 | if (BSP_Configuration.User_multiprocessing_table) |
---|
243 | cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1; |
---|
244 | else |
---|
245 | cpu_number = 0; |
---|
246 | |
---|
247 | if (getenv("RTEMS_WORKSPACE_SIZE")) |
---|
248 | BSP_Configuration.work_space_size = |
---|
249 | strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0); |
---|
250 | else |
---|
251 | BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE; |
---|
252 | |
---|
253 | /* |
---|
254 | * Allocate workspace memory, ensuring it is properly aligned |
---|
255 | */ |
---|
256 | |
---|
257 | workspace_ptr = |
---|
258 | (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT); |
---|
259 | workspace_ptr += CPU_ALIGNMENT - 1; |
---|
260 | workspace_ptr &= ~(CPU_ALIGNMENT - 1); |
---|
261 | |
---|
262 | BSP_Configuration.work_space_start = (void *) workspace_ptr; |
---|
263 | |
---|
264 | /* |
---|
265 | * Set up our hooks |
---|
266 | * Make sure libc_init is done before drivers init'd so that |
---|
267 | * they can use atexit() |
---|
268 | */ |
---|
269 | |
---|
270 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
271 | |
---|
272 | Cpu_table.predriver_hook = NULL; |
---|
273 | |
---|
274 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
275 | |
---|
276 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
277 | |
---|
278 | /* |
---|
279 | * Don't zero out the workspace since it is in the BSS under UNIX. |
---|
280 | */ |
---|
281 | |
---|
282 | Cpu_table.do_zero_of_workspace = FALSE; |
---|
283 | |
---|
284 | /* |
---|
285 | * XXX; interrupt stack not currently used, so this doesn't matter |
---|
286 | */ |
---|
287 | |
---|
288 | Cpu_table.interrupt_stack_size = (12 * 1024); |
---|
289 | |
---|
290 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
291 | |
---|
292 | /* |
---|
293 | * Tell libio how many fd's we want and allow it to tweak config |
---|
294 | */ |
---|
295 | |
---|
296 | rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); |
---|
297 | |
---|
298 | /* |
---|
299 | * Add 1 extension for MPCI_fatal |
---|
300 | */ |
---|
301 | |
---|
302 | if (BSP_Configuration.User_multiprocessing_table) |
---|
303 | BSP_Configuration.maximum_extensions++; |
---|
304 | |
---|
305 | CPU_CLICKS_PER_TICK = 1; |
---|
306 | |
---|
307 | /* |
---|
308 | * Start most of RTEMS |
---|
309 | * main() will start the rest |
---|
310 | */ |
---|
311 | |
---|
312 | bsp_isr_level = rtems_initialize_executive_early( |
---|
313 | &BSP_Configuration, |
---|
314 | &Cpu_table |
---|
315 | ); |
---|
316 | } |
---|