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-2011. |
---|
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 | |
---|
50 | #include <rtems.h> |
---|
51 | |
---|
52 | #include <bsp/bootcard.h> |
---|
53 | #include <rtems/bspIo.h> |
---|
54 | #include <rtems/malloc.h> |
---|
55 | |
---|
56 | #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK |
---|
57 | #include <unistd.h> /* for sbrk() */ |
---|
58 | #endif |
---|
59 | |
---|
60 | /* |
---|
61 | * At most a single pointer to the cmdline for those target |
---|
62 | * short on memory and not supporting a command line. |
---|
63 | */ |
---|
64 | const char *bsp_boot_cmdline; |
---|
65 | |
---|
66 | /* |
---|
67 | * This is the initialization framework routine that weaves together |
---|
68 | * calls to RTEMS and the BSP in the proper sequence to initialize |
---|
69 | * the system while maximizing shared code and keeping BSP code in C |
---|
70 | * as much as possible. |
---|
71 | */ |
---|
72 | uint32_t boot_card( |
---|
73 | const char *cmdline |
---|
74 | ) |
---|
75 | { |
---|
76 | rtems_interrupt_level bsp_isr_level; |
---|
77 | uint32_t status = 0; |
---|
78 | |
---|
79 | /* |
---|
80 | * Special case for PowerPC: The interrupt disable mask is stored in SPRG0. |
---|
81 | * It must be valid before we can use rtems_interrupt_disable(). |
---|
82 | */ |
---|
83 | #ifdef PPC_INTERRUPT_DISABLE_MASK_DEFAULT |
---|
84 | ppc_interrupt_set_disable_mask( PPC_INTERRUPT_DISABLE_MASK_DEFAULT ); |
---|
85 | #endif /* PPC_INTERRUPT_DISABLE_MASK_DEFAULT */ |
---|
86 | |
---|
87 | /* |
---|
88 | * Make sure interrupts are disabled. |
---|
89 | */ |
---|
90 | rtems_interrupt_disable( bsp_isr_level ); |
---|
91 | |
---|
92 | bsp_boot_cmdline = cmdline; |
---|
93 | |
---|
94 | /* |
---|
95 | * Invoke Board Support Package initialization routine written in C. |
---|
96 | */ |
---|
97 | bsp_start(); |
---|
98 | |
---|
99 | /* |
---|
100 | * Initialize the RTEMS Workspace and the C Program Heap. |
---|
101 | */ |
---|
102 | bsp_work_area_initialize(); |
---|
103 | |
---|
104 | /* |
---|
105 | * Initialize RTEMS data structures |
---|
106 | */ |
---|
107 | rtems_initialize_data_structures(); |
---|
108 | |
---|
109 | /* |
---|
110 | * Initialize the C library for those BSPs using the shared |
---|
111 | * framework. |
---|
112 | */ |
---|
113 | bsp_libc_init(); |
---|
114 | |
---|
115 | /* |
---|
116 | * Let the BSP do any required initialization now that RTEMS |
---|
117 | * data structures are initialized. In older BSPs or those |
---|
118 | * which do not use the shared framework, this is the typical |
---|
119 | * time when the C Library is initialized so malloc() |
---|
120 | * can be called by device drivers. For BSPs using the shared |
---|
121 | * framework, this routine can be empty. |
---|
122 | */ |
---|
123 | bsp_pretasking_hook(); |
---|
124 | |
---|
125 | /* |
---|
126 | * If debug is enabled, then enable all dynamic RTEMS debug |
---|
127 | * capabilities. |
---|
128 | * |
---|
129 | * NOTE: Most debug features are conditionally compiled in |
---|
130 | * or enabled via configure time plugins. |
---|
131 | */ |
---|
132 | #ifdef RTEMS_DEBUG |
---|
133 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
134 | #endif |
---|
135 | |
---|
136 | /* |
---|
137 | * Let RTEMS perform initialization it requires before drivers |
---|
138 | * are allowed to be initialized. |
---|
139 | */ |
---|
140 | rtems_initialize_before_drivers(); |
---|
141 | |
---|
142 | /* |
---|
143 | * Execute BSP specific pre-driver hook. Drivers haven't gotten |
---|
144 | * to initialize yet so this is a good chance to initialize |
---|
145 | * buses, spurious interrupt handlers, etc.. |
---|
146 | * |
---|
147 | * NOTE: Many BSPs do not require this handler and use the |
---|
148 | * shared stub. |
---|
149 | */ |
---|
150 | bsp_predriver_hook(); |
---|
151 | |
---|
152 | /* |
---|
153 | * Initialize all device drivers. |
---|
154 | */ |
---|
155 | rtems_initialize_device_drivers(); |
---|
156 | |
---|
157 | /* |
---|
158 | * Invoke the postdriver hook. This normally opens /dev/console |
---|
159 | * for use as stdin, stdout, and stderr. |
---|
160 | */ |
---|
161 | bsp_postdriver_hook(); |
---|
162 | |
---|
163 | /* |
---|
164 | * Complete initialization of RTEMS and switch to the first task. |
---|
165 | * Global C++ constructors will be executed in the context of that task. |
---|
166 | */ |
---|
167 | status = rtems_initialize_start_multitasking(); |
---|
168 | |
---|
169 | /*************************************************************** |
---|
170 | *************************************************************** |
---|
171 | * APPLICATION RUNS HERE!!! When it shuts down, we return!!! * |
---|
172 | *************************************************************** |
---|
173 | *************************************************************** |
---|
174 | */ |
---|
175 | |
---|
176 | /* |
---|
177 | * Perform any BSP specific shutdown actions which are written in C. |
---|
178 | */ |
---|
179 | bsp_cleanup( status ); |
---|
180 | |
---|
181 | /* |
---|
182 | * Now return to the start code. |
---|
183 | */ |
---|
184 | return status; |
---|
185 | } |
---|