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 | /* |
---|
36 | * The original table from the application and our copy of it with |
---|
37 | * some changes. |
---|
38 | */ |
---|
39 | |
---|
40 | extern rtems_configuration_table Configuration; |
---|
41 | |
---|
42 | rtems_configuration_table BSP_Configuration; |
---|
43 | |
---|
44 | rtems_cpu_table Cpu_table; |
---|
45 | |
---|
46 | char *rtems_progname; |
---|
47 | |
---|
48 | /* Initialize whatever libc we are using |
---|
49 | * called from postdriver hook |
---|
50 | */ |
---|
51 | |
---|
52 | void bsp_libc_init() |
---|
53 | { |
---|
54 | extern int end; |
---|
55 | rtems_unsigned32 heap_start; |
---|
56 | |
---|
57 | heap_start = (rtems_unsigned32) &end; |
---|
58 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
59 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
60 | |
---|
61 | /* |
---|
62 | * The last parameter to RTEMS_Malloc_Initialize is the "chunk" |
---|
63 | * size which a multiple of will be requested on each sbrk() |
---|
64 | * call by malloc(). A value of 0 indicates that sbrk() should |
---|
65 | * not be called to extend the heap. |
---|
66 | */ |
---|
67 | |
---|
68 | RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); |
---|
69 | |
---|
70 | /* |
---|
71 | * Init the RTEMS libio facility to provide UNIX-like system |
---|
72 | * calls for use by newlib (ie: provide __open, __close, etc) |
---|
73 | * Uses malloc() to get area for the iops, so must be after malloc init |
---|
74 | */ |
---|
75 | |
---|
76 | rtems_libio_init(); |
---|
77 | |
---|
78 | /* |
---|
79 | * Set up for the libc handling. |
---|
80 | */ |
---|
81 | |
---|
82 | if (BSP_Configuration.ticks_per_timeslice > 0) |
---|
83 | libc_init(1); /* reentrant if possible */ |
---|
84 | else |
---|
85 | libc_init(0); /* non-reentrant */ |
---|
86 | } |
---|
87 | |
---|
88 | /* |
---|
89 | * Function: bsp_pretasking_hook |
---|
90 | * Created: 95/03/10 |
---|
91 | * |
---|
92 | * Description: |
---|
93 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
94 | * Used to setup libc and install any BSP extensions. |
---|
95 | * |
---|
96 | * NOTES: |
---|
97 | * Must not use libc (to do io) from here, since drivers are |
---|
98 | * not yet initialized. |
---|
99 | * |
---|
100 | */ |
---|
101 | |
---|
102 | void |
---|
103 | bsp_pretasking_hook(void) |
---|
104 | { |
---|
105 | bsp_libc_init(); |
---|
106 | |
---|
107 | #ifdef STACK_CHECKER_ON |
---|
108 | /* |
---|
109 | * Initialize the stack bounds checker |
---|
110 | * We can either turn it on here or from the app. |
---|
111 | */ |
---|
112 | |
---|
113 | Stack_check_Initialize(); |
---|
114 | #endif |
---|
115 | |
---|
116 | #ifdef RTEMS_DEBUG |
---|
117 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
118 | #endif |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | /* |
---|
123 | * After drivers are setup, register some "filenames" |
---|
124 | * and open stdin, stdout, stderr files |
---|
125 | * |
---|
126 | * Newlib will automatically associate the files with these |
---|
127 | * (it hardcodes the numbers) |
---|
128 | */ |
---|
129 | |
---|
130 | void |
---|
131 | bsp_postdriver_hook(void) |
---|
132 | { |
---|
133 | int stdin_fd, stdout_fd, stderr_fd; |
---|
134 | int error_code; |
---|
135 | |
---|
136 | error_code = 'S' << 24 | 'T' << 16; |
---|
137 | |
---|
138 | if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1) |
---|
139 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' ); |
---|
140 | |
---|
141 | if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1) |
---|
142 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' ); |
---|
143 | |
---|
144 | if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1) |
---|
145 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' ); |
---|
146 | |
---|
147 | if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) |
---|
148 | rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' ); |
---|
149 | } |
---|
150 | |
---|
151 | int bsp_start( |
---|
152 | int argc, |
---|
153 | char **argv, |
---|
154 | char **environp |
---|
155 | ) |
---|
156 | { |
---|
157 | if ((argc > 0) && argv && argv[0]) |
---|
158 | rtems_progname = argv[0]; |
---|
159 | else |
---|
160 | rtems_progname = "RTEMS"; |
---|
161 | |
---|
162 | /* |
---|
163 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
164 | * a variety of places: hard coded address, malloc'ed from outside |
---|
165 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
166 | * typically done by stock BSPs) by subtracting the required amount |
---|
167 | * of work space from the last physical address on the CPU board. |
---|
168 | */ |
---|
169 | |
---|
170 | /* |
---|
171 | * Copy the Configuration Table .. so we can change it |
---|
172 | */ |
---|
173 | |
---|
174 | BSP_Configuration = Configuration; |
---|
175 | |
---|
176 | /* |
---|
177 | * Add 1 region for the RTEMS Malloc |
---|
178 | */ |
---|
179 | |
---|
180 | BSP_Configuration.maximum_regions++; |
---|
181 | |
---|
182 | /* |
---|
183 | * Add 1 extension for newlib libc |
---|
184 | */ |
---|
185 | |
---|
186 | #ifdef RTEMS_NEWLIB |
---|
187 | BSP_Configuration.maximum_extensions++; |
---|
188 | #endif |
---|
189 | |
---|
190 | /* |
---|
191 | * Add 1 extension for newlib libc |
---|
192 | */ |
---|
193 | |
---|
194 | #ifdef RTEMS_NEWLIB |
---|
195 | BSP_Configuration.maximum_extensions++; |
---|
196 | #endif |
---|
197 | |
---|
198 | #ifdef STACK_CHECKER_ON |
---|
199 | /* |
---|
200 | * Add 1 extension for stack checker |
---|
201 | */ |
---|
202 | |
---|
203 | BSP_Configuration.maximum_extensions++; |
---|
204 | #endif |
---|
205 | |
---|
206 | /* |
---|
207 | * Tell libio how many fd's we want and allow it to tweak config |
---|
208 | */ |
---|
209 | |
---|
210 | rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); |
---|
211 | |
---|
212 | /* |
---|
213 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
214 | * tell the RTEMS configuration where it is. This memory is |
---|
215 | * not malloc'ed. It is just "pulled from the air". |
---|
216 | */ |
---|
217 | |
---|
218 | BSP_Configuration.work_space_start = (void *) 0; |
---|
219 | |
---|
220 | /* |
---|
221 | * initialize the CPU table for this BSP |
---|
222 | */ |
---|
223 | |
---|
224 | /* |
---|
225 | * we do not use the pretasking_hook |
---|
226 | */ |
---|
227 | |
---|
228 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
229 | |
---|
230 | Cpu_table.predriver_hook = NULL; |
---|
231 | |
---|
232 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
233 | |
---|
234 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
235 | |
---|
236 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
237 | |
---|
238 | Cpu_table.interrupt_stack_size = 4096; |
---|
239 | |
---|
240 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
241 | |
---|
242 | /* |
---|
243 | * Don't forget the other CPU Table entries. |
---|
244 | */ |
---|
245 | |
---|
246 | /* |
---|
247 | * Start RTEMS |
---|
248 | */ |
---|
249 | |
---|
250 | rtems_initialize_executive( &BSP_Configuration, &Cpu_table ); |
---|
251 | |
---|
252 | bsp_cleanup(); |
---|
253 | |
---|
254 | return 0; |
---|
255 | } |
---|