1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup bsp_bootcard |
---|
5 | * |
---|
6 | * @brief Standard system startup. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * This is the C entry point for ALL RTEMS BSPs. It is invoked |
---|
11 | * from the assembly language initialization file usually called |
---|
12 | * start.S. It provides the framework for the BSP initialization |
---|
13 | * sequence. The basic flow of initialization is: |
---|
14 | * |
---|
15 | * + start.S: basic CPU setup (stack, zero BSS) |
---|
16 | * + boot_card |
---|
17 | * + bspstart.c: bsp_start - more advanced initialization |
---|
18 | * + obtain information on BSP memory and allocate RTEMS Workspace |
---|
19 | * + rtems_initialize_data_structures |
---|
20 | * + allocate memory to C Program Heap |
---|
21 | * + initialize C Library and C Program Heap |
---|
22 | * + bsp_pretasking_hook |
---|
23 | * + if defined( RTEMS_DEBUG ) |
---|
24 | * - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
25 | * + rtems_initialize_before_drivers |
---|
26 | * + bsp_predriver_hook |
---|
27 | * + rtems_initialize_device_drivers |
---|
28 | * - all device drivers |
---|
29 | * + bsp_postdriver_hook |
---|
30 | * + rtems_initialize_start_multitasking |
---|
31 | * - 1st task executes C++ global constructors |
---|
32 | * .... appplication runs ... |
---|
33 | * - exit |
---|
34 | * + back to here eventually |
---|
35 | * + bspclean.c: bsp_cleanup |
---|
36 | * |
---|
37 | * This style of initialization ensures that the C++ global |
---|
38 | * constructors are executed after RTEMS is initialized. |
---|
39 | * Thanks to Chris Johns <cjohns@plessey.com.au> for the idea |
---|
40 | * to move C++ global constructors into the first task. |
---|
41 | * |
---|
42 | * COPYRIGHT (c) 1989-2008. |
---|
43 | * On-Line Applications Research Corporation (OAR). |
---|
44 | * |
---|
45 | * The license and distribution terms for this file may be |
---|
46 | * found in the file LICENSE in this distribution or at |
---|
47 | * http://www.rtems.com/license/LICENSE. |
---|
48 | * |
---|
49 | * $Id$ |
---|
50 | */ |
---|
51 | |
---|
52 | #include <rtems.h> |
---|
53 | |
---|
54 | #include <bsp/bootcard.h> |
---|
55 | #include <rtems/bspIo.h> |
---|
56 | |
---|
57 | /* |
---|
58 | * At most a single pointer to the cmdline for those target |
---|
59 | * short on memory and not supporting a command line. |
---|
60 | */ |
---|
61 | const char *bsp_boot_cmdline; |
---|
62 | |
---|
63 | /* |
---|
64 | * Are we using a single heap for the RTEMS Workspace and C Program Heap? |
---|
65 | */ |
---|
66 | extern bool rtems_unified_work_area; |
---|
67 | |
---|
68 | /* |
---|
69 | * These are the prototypes and helper routines which are used |
---|
70 | * when the BSP lets the framework handle RAM allocation between |
---|
71 | * the RTEMS Workspace and C Program Heap. |
---|
72 | */ |
---|
73 | static void bootcard_bsp_libc_helper( |
---|
74 | void *work_area_start, |
---|
75 | uintptr_t work_area_size, |
---|
76 | void *heap_start, |
---|
77 | uintptr_t heap_size |
---|
78 | ) |
---|
79 | { |
---|
80 | if ( !rtems_unified_work_area && |
---|
81 | heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA) { |
---|
82 | uintptr_t work_space_size = rtems_configuration_get_work_space_size(); |
---|
83 | |
---|
84 | heap_start = (char *) work_area_start + work_space_size; |
---|
85 | |
---|
86 | if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) { |
---|
87 | uintptr_t heap_size_default = work_area_size - work_space_size; |
---|
88 | |
---|
89 | heap_size = heap_size_default; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | bsp_libc_init(heap_start, heap_size, 0); |
---|
94 | } |
---|
95 | |
---|
96 | /* |
---|
97 | * This is the initialization framework routine that weaves together |
---|
98 | * calls to RTEMS and the BSP in the proper sequence to initialize |
---|
99 | * the system while maximizing shared code and keeping BSP code in C |
---|
100 | * as much as possible. |
---|
101 | */ |
---|
102 | int boot_card( |
---|
103 | const char *cmdline |
---|
104 | ) |
---|
105 | { |
---|
106 | rtems_interrupt_level bsp_isr_level; |
---|
107 | void *work_area_start = NULL; |
---|
108 | uintptr_t work_area_size = 0; |
---|
109 | void *heap_start = NULL; |
---|
110 | uintptr_t heap_size = 0; |
---|
111 | |
---|
112 | /* |
---|
113 | * Special case for PowerPC: The interrupt disable mask is stored in SPRG0. |
---|
114 | * It must be valid before we can use rtems_interrupt_disable(). |
---|
115 | */ |
---|
116 | #ifdef PPC_INTERRUPT_DISABLE_MASK_DEFAULT |
---|
117 | ppc_interrupt_set_disable_mask( PPC_INTERRUPT_DISABLE_MASK_DEFAULT ); |
---|
118 | #endif /* PPC_INTERRUPT_DISABLE_MASK_DEFAULT */ |
---|
119 | |
---|
120 | /* |
---|
121 | * Make sure interrupts are disabled. |
---|
122 | */ |
---|
123 | rtems_interrupt_disable( bsp_isr_level ); |
---|
124 | |
---|
125 | bsp_boot_cmdline = cmdline; |
---|
126 | |
---|
127 | /* |
---|
128 | * Invoke Board Support Package initialization routine written in C. |
---|
129 | */ |
---|
130 | bsp_start(); |
---|
131 | |
---|
132 | /* |
---|
133 | * Find out where the block of memory the BSP will use for |
---|
134 | * the RTEMS Workspace and the C Program Heap is. |
---|
135 | */ |
---|
136 | bsp_get_work_area(&work_area_start, &work_area_size, |
---|
137 | &heap_start, &heap_size); |
---|
138 | |
---|
139 | if ( work_area_size <= Configuration.work_space_size ) { |
---|
140 | printk( |
---|
141 | "bootcard: work space too big for work area: %p > %p\n", |
---|
142 | (void *) Configuration.work_space_size, |
---|
143 | (void *) work_area_size |
---|
144 | ); |
---|
145 | bsp_cleanup(); |
---|
146 | return -1; |
---|
147 | } |
---|
148 | |
---|
149 | if ( rtems_unified_work_area ) { |
---|
150 | Configuration.work_space_start = work_area_start; |
---|
151 | Configuration.work_space_size = work_area_size; |
---|
152 | } else { |
---|
153 | Configuration.work_space_start = work_area_start; |
---|
154 | } |
---|
155 | |
---|
156 | #if (BSP_DIRTY_MEMORY == 1) |
---|
157 | memset( work_area_start, 0xCF, work_area_size ); |
---|
158 | #endif |
---|
159 | |
---|
160 | /* |
---|
161 | * Initialize RTEMS data structures |
---|
162 | */ |
---|
163 | rtems_initialize_data_structures(); |
---|
164 | |
---|
165 | /* |
---|
166 | * Initialize the C library for those BSPs using the shared |
---|
167 | * framework. |
---|
168 | */ |
---|
169 | bootcard_bsp_libc_helper( |
---|
170 | work_area_start, |
---|
171 | work_area_size, |
---|
172 | heap_start, |
---|
173 | heap_size |
---|
174 | ); |
---|
175 | |
---|
176 | /* |
---|
177 | * All BSP to do any required initialization now that RTEMS |
---|
178 | * data structures are initialized. In older BSPs or those |
---|
179 | * which do not use the shared framework, this is the typical |
---|
180 | * time when the C Library is initialized so malloc() |
---|
181 | * can be called by device drivers. For BSPs using the shared |
---|
182 | * framework, this routine can be empty. |
---|
183 | */ |
---|
184 | bsp_pretasking_hook(); |
---|
185 | |
---|
186 | /* |
---|
187 | * If debug is enabled, then enable all dynamic RTEMS debug |
---|
188 | * capabilities. |
---|
189 | * |
---|
190 | * NOTE: Most debug features are conditionally compiled in |
---|
191 | * or enabled via configure time plugins. |
---|
192 | */ |
---|
193 | #ifdef RTEMS_DEBUG |
---|
194 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
195 | #endif |
---|
196 | |
---|
197 | /* |
---|
198 | * Let RTEMS perform initialization it requires before drivers |
---|
199 | * are allowed to be initialized. |
---|
200 | */ |
---|
201 | rtems_initialize_before_drivers(); |
---|
202 | |
---|
203 | /* |
---|
204 | * Execute BSP specific pre-driver hook. Drivers haven't gotten |
---|
205 | * to initialize yet so this is a good chance to initialize |
---|
206 | * buses, spurious interrupt handlers, etc.. |
---|
207 | * |
---|
208 | * NOTE: Many BSPs do not require this handler and use the |
---|
209 | * shared stub. |
---|
210 | */ |
---|
211 | bsp_predriver_hook(); |
---|
212 | |
---|
213 | /* |
---|
214 | * Initialize all device drivers. |
---|
215 | */ |
---|
216 | rtems_initialize_device_drivers(); |
---|
217 | |
---|
218 | /* |
---|
219 | * Invoke the postdriver hook. This normally opens /dev/console |
---|
220 | * for use as stdin, stdout, and stderr. |
---|
221 | */ |
---|
222 | bsp_postdriver_hook(); |
---|
223 | |
---|
224 | /* |
---|
225 | * Complete initialization of RTEMS and switch to the first task. |
---|
226 | * Global C++ constructors will be executed in the context of that task. |
---|
227 | */ |
---|
228 | rtems_initialize_start_multitasking(); |
---|
229 | |
---|
230 | /*************************************************************** |
---|
231 | *************************************************************** |
---|
232 | * APPLICATION RUNS HERE!!! When it shuts down, we return!!! * |
---|
233 | *************************************************************** |
---|
234 | *************************************************************** |
---|
235 | */ |
---|
236 | |
---|
237 | /* |
---|
238 | * Perform any BSP specific shutdown actions which are written in C. |
---|
239 | */ |
---|
240 | bsp_cleanup(); |
---|
241 | |
---|
242 | /* |
---|
243 | * Now return to the start code. |
---|
244 | */ |
---|
245 | return 0; |
---|
246 | } |
---|