1 | /* |
---|
2 | * This routine starts the application. It includes application, |
---|
3 | * board, and monitor specific initialization and configuration. |
---|
4 | * The generic CPU dependent initialization has been performed |
---|
5 | * before this routine is invoked. |
---|
6 | * |
---|
7 | * Called by RTEMS::RTEMS constructor in startup-ctor.cc |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #include <stdio.h> |
---|
20 | #include <stdlib.h> |
---|
21 | #include <unistd.h> |
---|
22 | |
---|
23 | #include <bsp.h> |
---|
24 | #include <rtems/libcsupport.h> |
---|
25 | #include <rtems/libio.h> |
---|
26 | |
---|
27 | extern rtems_configuration_table Configuration; |
---|
28 | |
---|
29 | /* |
---|
30 | * A copy of the configuration table from the application |
---|
31 | * with some changes applied to it. |
---|
32 | */ |
---|
33 | |
---|
34 | rtems_configuration_table BSP_Configuration; |
---|
35 | rtems_multiprocessing_table BSP_Multiprocessing; |
---|
36 | rtems_cpu_table Cpu_table; |
---|
37 | rtems_unsigned32 bsp_isr_level; |
---|
38 | rtems_unsigned32 Heap_size; |
---|
39 | int rtems_argc; |
---|
40 | char **rtems_argv; |
---|
41 | |
---|
42 | /* |
---|
43 | * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE |
---|
44 | * environment variables; see below. |
---|
45 | */ |
---|
46 | |
---|
47 | #define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024)) |
---|
48 | #define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024)) |
---|
49 | |
---|
50 | /* |
---|
51 | * Amount to increment itimer by each pass |
---|
52 | * It is a variable instead of a #define to allow the 'looptest' |
---|
53 | * script to bump it without recompiling rtems |
---|
54 | */ |
---|
55 | |
---|
56 | rtems_unsigned32 CPU_CLICKS_PER_TICK; |
---|
57 | |
---|
58 | /* |
---|
59 | * Use the shared implementations of the following routines |
---|
60 | */ |
---|
61 | |
---|
62 | void bsp_postdriver_hook(void); |
---|
63 | void bsp_libc_init( void *, unsigned32, int ); |
---|
64 | |
---|
65 | /* |
---|
66 | * Function: bsp_pretasking_hook |
---|
67 | * Created: 95/03/10 |
---|
68 | * |
---|
69 | * Description: |
---|
70 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
71 | * Used to setup libc and install any BSP extensions. |
---|
72 | * |
---|
73 | * NOTES: |
---|
74 | * Must not use libc (to do io) from here, since drivers are |
---|
75 | * not yet initialized. |
---|
76 | */ |
---|
77 | |
---|
78 | void bsp_pretasking_hook(void) |
---|
79 | { |
---|
80 | void *heap_start; |
---|
81 | |
---|
82 | if (getenv("RTEMS_HEAPSPACE_SIZE")) |
---|
83 | Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0); |
---|
84 | else |
---|
85 | Heap_size = DEFAULT_HEAPSPACE_SIZE; |
---|
86 | |
---|
87 | heap_start = 0; |
---|
88 | |
---|
89 | bsp_libc_init((void *)heap_start, Heap_size, 1024 * 1024); |
---|
90 | |
---|
91 | |
---|
92 | #ifdef RTEMS_DEBUG |
---|
93 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
94 | #endif |
---|
95 | |
---|
96 | /* |
---|
97 | * Dump malloc stats on exit... |
---|
98 | */ |
---|
99 | #if defined(RTEMS_DEBUG) |
---|
100 | atexit(malloc_dump); |
---|
101 | #endif |
---|
102 | } |
---|
103 | |
---|
104 | /* |
---|
105 | * DO NOT Use the shared bsp_postdriver_hook() implementation |
---|
106 | */ |
---|
107 | |
---|
108 | void bsp_postdriver_hook(void) |
---|
109 | { |
---|
110 | return; |
---|
111 | } |
---|
112 | |
---|
113 | /* |
---|
114 | * bsp_start |
---|
115 | * |
---|
116 | * This routine does the bulk of the system initialization. |
---|
117 | */ |
---|
118 | |
---|
119 | void bsp_start(void) |
---|
120 | { |
---|
121 | unsigned32 workspace_ptr; |
---|
122 | |
---|
123 | /* |
---|
124 | * Copy the table (normally done in shared main). |
---|
125 | */ |
---|
126 | |
---|
127 | BSP_Configuration = Configuration; |
---|
128 | |
---|
129 | /* |
---|
130 | * If the node number is -1 then the application better provide |
---|
131 | * it through environment variables RTEMS_NODE. |
---|
132 | * Ditto for RTEMS_MAXIMUM_NODES |
---|
133 | */ |
---|
134 | |
---|
135 | if (BSP_Configuration.User_multiprocessing_table) { |
---|
136 | char *p; |
---|
137 | |
---|
138 | /* make a copy for possible editing */ |
---|
139 | BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table; |
---|
140 | BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing; |
---|
141 | |
---|
142 | if (BSP_Multiprocessing.node == -1) |
---|
143 | { |
---|
144 | p = getenv("RTEMS_NODE"); |
---|
145 | BSP_Multiprocessing.node = p ? atoi(p) : 1; |
---|
146 | } |
---|
147 | |
---|
148 | /* If needed provide maximum_nodes also */ |
---|
149 | if (BSP_Multiprocessing.maximum_nodes == -1) |
---|
150 | { |
---|
151 | p = getenv("RTEMS_MAXIMUM_NODES"); |
---|
152 | BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1; |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | /* |
---|
157 | * Set cpu_number to accurately reflect our cpu number |
---|
158 | */ |
---|
159 | |
---|
160 | if (BSP_Configuration.User_multiprocessing_table) |
---|
161 | cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1; |
---|
162 | else |
---|
163 | cpu_number = 0; |
---|
164 | |
---|
165 | if (getenv("RTEMS_WORKSPACE_SIZE")) |
---|
166 | BSP_Configuration.work_space_size = |
---|
167 | strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0); |
---|
168 | else |
---|
169 | BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE; |
---|
170 | |
---|
171 | /* |
---|
172 | * Allocate workspace memory, ensuring it is properly aligned |
---|
173 | */ |
---|
174 | |
---|
175 | workspace_ptr = |
---|
176 | (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT); |
---|
177 | workspace_ptr += CPU_ALIGNMENT - 1; |
---|
178 | workspace_ptr &= ~(CPU_ALIGNMENT - 1); |
---|
179 | |
---|
180 | BSP_Configuration.work_space_start = (void *) workspace_ptr; |
---|
181 | |
---|
182 | /* |
---|
183 | * Set up our hooks |
---|
184 | * Make sure libc_init is done before drivers init'd so that |
---|
185 | * they can use atexit() |
---|
186 | */ |
---|
187 | |
---|
188 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
189 | |
---|
190 | Cpu_table.predriver_hook = NULL; |
---|
191 | |
---|
192 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
193 | |
---|
194 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
195 | |
---|
196 | /* |
---|
197 | * Don't zero out the workspace since it is in the BSS under UNIX. |
---|
198 | */ |
---|
199 | |
---|
200 | Cpu_table.do_zero_of_workspace = FALSE; |
---|
201 | |
---|
202 | /* |
---|
203 | * XXX; interrupt stack not currently used, so this doesn't matter |
---|
204 | */ |
---|
205 | |
---|
206 | Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY; |
---|
207 | |
---|
208 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
209 | |
---|
210 | /* |
---|
211 | * Add 1 extension for MPCI_fatal |
---|
212 | */ |
---|
213 | |
---|
214 | if (BSP_Configuration.User_multiprocessing_table) |
---|
215 | BSP_Configuration.maximum_extensions++; |
---|
216 | |
---|
217 | CPU_CLICKS_PER_TICK = 1; |
---|
218 | |
---|
219 | /* |
---|
220 | * Start most of RTEMS |
---|
221 | * main() will start the rest |
---|
222 | */ |
---|
223 | |
---|
224 | bsp_isr_level = rtems_initialize_executive_early( |
---|
225 | &BSP_Configuration, |
---|
226 | &Cpu_table |
---|
227 | ); |
---|
228 | } |
---|