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 | * INPUT: NONE |
---|
9 | * |
---|
10 | * OUTPUT: NONE |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * All rights assigned to U.S. Government, 1994. |
---|
15 | * |
---|
16 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
17 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
18 | * notice must appear in all copies of this file and its derivatives. |
---|
19 | * |
---|
20 | * $Id$ |
---|
21 | */ |
---|
22 | |
---|
23 | #include <bsp.h> |
---|
24 | #include <rtems/libio.h> |
---|
25 | |
---|
26 | #include <libcsupport.h> |
---|
27 | |
---|
28 | #include <string.h> |
---|
29 | #include <fcntl.h> |
---|
30 | |
---|
31 | #ifdef STACK_CHECKER_ON |
---|
32 | #include <stackchk.h> |
---|
33 | #endif |
---|
34 | |
---|
35 | #ifndef lint |
---|
36 | static char _sccsid[] = "@(#)bspstart.c 09/11/96 1.15\n"; |
---|
37 | #endif |
---|
38 | |
---|
39 | /* |
---|
40 | * The original table from the application and our copy of it with |
---|
41 | * some changes. |
---|
42 | */ |
---|
43 | |
---|
44 | extern rtems_configuration_table Configuration; |
---|
45 | |
---|
46 | rtems_configuration_table BSP_Configuration; |
---|
47 | |
---|
48 | rtems_cpu_table Cpu_table; |
---|
49 | |
---|
50 | char *rtems_progname; |
---|
51 | |
---|
52 | /* Initialize whatever libc we are using |
---|
53 | * called from postdriver hook |
---|
54 | */ |
---|
55 | |
---|
56 | #define HEAP_BLOCK_SIZE (16 * 1024) |
---|
57 | |
---|
58 | rtems_unsigned32 heap_size = 0; |
---|
59 | rtems_unsigned32 heap_start; |
---|
60 | |
---|
61 | void bsp_libc_init() |
---|
62 | { |
---|
63 | heap_size = 2 * 1024 * 1024; /* allocate a maximum of 2 megabytes for the heap */ |
---|
64 | |
---|
65 | /* allocate all remaining memory to the heap */ |
---|
66 | do { |
---|
67 | heap_size -= HEAP_BLOCK_SIZE; |
---|
68 | heap_start = _sysalloc( heap_size ); |
---|
69 | } while ( !heap_start ); |
---|
70 | |
---|
71 | if (!heap_start) |
---|
72 | rtems_fatal_error_occurred( heap_size ); |
---|
73 | |
---|
74 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
75 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
76 | |
---|
77 | /* |
---|
78 | * The last parameter to RTEMS_Malloc_Initialize is the "chunk" |
---|
79 | * size which a multiple of will be requested on each sbrk() |
---|
80 | * call by malloc(). A value of 0 indicates that sbrk() should |
---|
81 | * not be called to extend the heap. |
---|
82 | */ |
---|
83 | |
---|
84 | RTEMS_Malloc_Initialize((void *) heap_start, heap_size, 0); |
---|
85 | |
---|
86 | /* |
---|
87 | * Init the RTEMS libio facility to provide UNIX-like system |
---|
88 | * calls for use by newlib (ie: provide __open, __close, etc) |
---|
89 | * Uses malloc() to get area for the iops, so must be after malloc init |
---|
90 | */ |
---|
91 | |
---|
92 | rtems_libio_init(); |
---|
93 | |
---|
94 | /* |
---|
95 | * Set up for the libc handling. |
---|
96 | */ |
---|
97 | |
---|
98 | if (BSP_Configuration.ticks_per_timeslice > 0) |
---|
99 | libc_init(1); /* reentrant if possible */ |
---|
100 | else |
---|
101 | libc_init(0); /* non-reentrant */ |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | /* |
---|
106 | * Function: bsp_pretasking_hook |
---|
107 | * Created: 95/03/10 |
---|
108 | * |
---|
109 | * Description: |
---|
110 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
111 | * Used to setup libc and install any BSP extensions. |
---|
112 | * |
---|
113 | * NOTES: |
---|
114 | * Must not use libc (to do io) from here, since drivers are |
---|
115 | * not yet initialized. |
---|
116 | * |
---|
117 | */ |
---|
118 | |
---|
119 | void |
---|
120 | bsp_pretasking_hook(void) |
---|
121 | { |
---|
122 | bsp_libc_init(); |
---|
123 | |
---|
124 | #ifdef STACK_CHECKER_ON |
---|
125 | /* |
---|
126 | * Initialize the stack bounds checker |
---|
127 | * We can either turn it on here or from the app. |
---|
128 | */ |
---|
129 | |
---|
130 | Stack_check_Initialize(); |
---|
131 | #endif |
---|
132 | |
---|
133 | #ifdef RTEMS_DEBUG |
---|
134 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
135 | #endif |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | /* |
---|
140 | * After drivers are setup, register some "filenames" |
---|
141 | * and open stdin, stdout, stderr files |
---|
142 | * |
---|
143 | * Newlib will automatically associate the files with these |
---|
144 | * (it hardcodes the numbers) |
---|
145 | */ |
---|
146 | |
---|
147 | void |
---|
148 | bsp_postdriver_hook(void) |
---|
149 | { |
---|
150 | int stdin_fd, stdout_fd, stderr_fd; |
---|
151 | int error_code; |
---|
152 | |
---|
153 | error_code = 'S' << 24 | 'T' << 16; |
---|
154 | |
---|
155 | if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1) |
---|
156 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' ); |
---|
157 | |
---|
158 | if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1) |
---|
159 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' ); |
---|
160 | |
---|
161 | if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1) |
---|
162 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' ); |
---|
163 | |
---|
164 | if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) |
---|
165 | rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' ); |
---|
166 | |
---|
167 | printf("allocated %d heap size, %d work space size\n", |
---|
168 | heap_size, BSP_Configuration.work_space_size); |
---|
169 | printf(" work space start 0x%x\n",(unsigned int)BSP_Configuration.work_space_start); |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | int bsp_start( |
---|
174 | int argc, |
---|
175 | char **argv, |
---|
176 | char **environp |
---|
177 | ) |
---|
178 | { |
---|
179 | if ((argc > 0) && argv && argv[0]) |
---|
180 | rtems_progname = argv[0]; |
---|
181 | else |
---|
182 | rtems_progname = "RTEMS"; |
---|
183 | |
---|
184 | /* set the PIA0 register wait states */ |
---|
185 | *(volatile unsigned32 *)0x80000020 = 0x04080000; |
---|
186 | |
---|
187 | /* |
---|
188 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
189 | * a variety of places: hard coded address, malloc'ed from outside |
---|
190 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
191 | * typically done by stock BSPs) by subtracting the required amount |
---|
192 | * of work space from the last physical address on the CPU board. |
---|
193 | */ |
---|
194 | |
---|
195 | /* |
---|
196 | * Copy the Configuration Table .. so we can change it |
---|
197 | */ |
---|
198 | |
---|
199 | BSP_Configuration = Configuration; |
---|
200 | |
---|
201 | /* |
---|
202 | * Add 1 region for the RTEMS Malloc |
---|
203 | */ |
---|
204 | |
---|
205 | BSP_Configuration.RTEMS_api_configuration->maximum_regions++; |
---|
206 | |
---|
207 | /* |
---|
208 | * Add 1 extension for newlib libc |
---|
209 | */ |
---|
210 | |
---|
211 | #ifdef RTEMS_NEWLIB |
---|
212 | BSP_Configuration.maximum_extensions++; |
---|
213 | #endif |
---|
214 | |
---|
215 | /* |
---|
216 | * Add 1 extension for newlib libc |
---|
217 | */ |
---|
218 | |
---|
219 | #ifdef RTEMS_NEWLIB |
---|
220 | BSP_Configuration.maximum_extensions++; |
---|
221 | #endif |
---|
222 | |
---|
223 | #ifdef STACK_CHECKER_ON |
---|
224 | /* |
---|
225 | * Add 1 extension for stack checker |
---|
226 | */ |
---|
227 | |
---|
228 | BSP_Configuration.maximum_extensions++; |
---|
229 | #endif |
---|
230 | |
---|
231 | /* |
---|
232 | * Tell libio how many fd's we want and allow it to tweak config |
---|
233 | */ |
---|
234 | |
---|
235 | rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); |
---|
236 | |
---|
237 | /* |
---|
238 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
239 | * tell the RTEMS configuration where it is. This memory is |
---|
240 | * not malloc'ed. It is just "pulled from the air". |
---|
241 | */ |
---|
242 | |
---|
243 | BSP_Configuration.work_space_start = _sysalloc( BSP_Configuration.work_space_size + 512 ); |
---|
244 | if (!BSP_Configuration.work_space_start) |
---|
245 | rtems_fatal_error_occurred( BSP_Configuration.work_space_size ); |
---|
246 | |
---|
247 | BSP_Configuration.work_space_start = (void *) ((unsigned int)((char *)BSP_Configuration.work_space_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1)); |
---|
248 | |
---|
249 | /* |
---|
250 | * initialize the CPU table for this BSP |
---|
251 | */ |
---|
252 | |
---|
253 | /* |
---|
254 | * we do not use the pretasking_hook |
---|
255 | */ |
---|
256 | |
---|
257 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
258 | |
---|
259 | Cpu_table.predriver_hook = NULL; |
---|
260 | |
---|
261 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
262 | |
---|
263 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
264 | |
---|
265 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
266 | |
---|
267 | Cpu_table.interrupt_stack_size = 4096; |
---|
268 | |
---|
269 | Cpu_table.extra_system_initialization_stack = 0; |
---|
270 | |
---|
271 | /* |
---|
272 | * Don't forget the other CPU Table entries. |
---|
273 | */ |
---|
274 | |
---|
275 | _settrap( 109,&a29k_enable_sup); |
---|
276 | _settrap( 110,&a29k_disable_sup); |
---|
277 | _settrap( 111,&a29k_enable_all_sup); |
---|
278 | _settrap( 112,&a29k_disable_all_sup); |
---|
279 | _settrap( 106,&a29k_context_switch_sup); |
---|
280 | _settrap( 107,&a29k_context_restore_sup); |
---|
281 | _settrap( 108,&a29k_context_save_sup); |
---|
282 | _settrap( 105,&a29k_sigdfl_sup); |
---|
283 | |
---|
284 | /* |
---|
285 | * Start RTEMS |
---|
286 | */ |
---|
287 | |
---|
288 | rtems_initialize_executive( &BSP_Configuration, &Cpu_table ); |
---|
289 | |
---|
290 | bsp_cleanup(); |
---|
291 | |
---|
292 | return 0; |
---|
293 | } |
---|