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