1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup bsp_bootcard |
---|
5 | * |
---|
6 | * @brief Standard system startup. |
---|
7 | * |
---|
8 | * This is the C entry point for ALL RTEMS BSPs. It is invoked |
---|
9 | * from the assembly language initialization file usually called |
---|
10 | * start.S. It provides the framework for the BSP initialization |
---|
11 | * sequence. The basic flow of initialization is: |
---|
12 | * |
---|
13 | * + start.S: basic CPU setup (stack, zero BSS) |
---|
14 | * + boot_card |
---|
15 | * + bspstart.c: bsp_start - more advanced initialization |
---|
16 | * + obtain information on BSP memory and allocate RTEMS Workspace |
---|
17 | * + rtems_initialize_data_structures |
---|
18 | * + allocate memory to C Program Heap |
---|
19 | * + initialize C Library and C Program Heap |
---|
20 | * + bsp_pretasking_hook |
---|
21 | * + if defined( RTEMS_DEBUG ) |
---|
22 | * - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
23 | * + rtems_initialize_before_drivers |
---|
24 | * + bsp_predriver_hook |
---|
25 | * + rtems_initialize_device_drivers |
---|
26 | * - all device drivers |
---|
27 | * + bsp_postdriver_hook |
---|
28 | * + rtems_initialize_start_multitasking |
---|
29 | * - 1st task executes C++ global constructors |
---|
30 | * .... appplication runs ... |
---|
31 | * - exit |
---|
32 | * + will not return to here |
---|
33 | * |
---|
34 | * This style of initialization ensures that the C++ global |
---|
35 | * constructors are executed after RTEMS is initialized. |
---|
36 | * Thanks to Chris Johns <cjohns@plessey.com.au> for the idea |
---|
37 | * to move C++ global constructors into the first task. |
---|
38 | */ |
---|
39 | |
---|
40 | /* |
---|
41 | * COPYRIGHT (c) 1989-2014. |
---|
42 | * On-Line Applications Research Corporation (OAR). |
---|
43 | * |
---|
44 | * The license and distribution terms for this file may be |
---|
45 | * found in the file LICENSE in this distribution or at |
---|
46 | * http://www.rtems.org/license/LICENSE. |
---|
47 | */ |
---|
48 | |
---|
49 | #include <bsp/bootcard.h> |
---|
50 | |
---|
51 | #include <rtems.h> |
---|
52 | |
---|
53 | /* |
---|
54 | * At most a single pointer to the cmdline for those target |
---|
55 | * short on memory and not supporting a command line. |
---|
56 | */ |
---|
57 | const char *bsp_boot_cmdline; |
---|
58 | |
---|
59 | /* |
---|
60 | * This is the initialization framework routine that weaves together |
---|
61 | * calls to RTEMS and the BSP in the proper sequence to initialize |
---|
62 | * the system while maximizing shared code and keeping BSP code in C |
---|
63 | * as much as possible. |
---|
64 | */ |
---|
65 | void boot_card( |
---|
66 | const char *cmdline |
---|
67 | ) |
---|
68 | { |
---|
69 | rtems_interrupt_level bsp_isr_level; |
---|
70 | |
---|
71 | /* |
---|
72 | * Make sure interrupts are disabled. |
---|
73 | */ |
---|
74 | (void) bsp_isr_level; |
---|
75 | rtems_interrupt_disable( bsp_isr_level ); |
---|
76 | |
---|
77 | bsp_boot_cmdline = cmdline; |
---|
78 | |
---|
79 | /* |
---|
80 | * Invoke Board Support Package initialization routine written in C. |
---|
81 | */ |
---|
82 | bsp_start(); |
---|
83 | |
---|
84 | /* |
---|
85 | * Initialize the RTEMS Workspace and the C Program Heap. |
---|
86 | */ |
---|
87 | bsp_work_area_initialize(); |
---|
88 | |
---|
89 | /* |
---|
90 | * Initialize RTEMS data structures |
---|
91 | */ |
---|
92 | rtems_initialize_data_structures(); |
---|
93 | |
---|
94 | /* |
---|
95 | * Initialize the C library for those BSPs using the shared |
---|
96 | * framework. |
---|
97 | */ |
---|
98 | bsp_libc_init(); |
---|
99 | |
---|
100 | /* |
---|
101 | * Let the BSP do any required initialization now that RTEMS |
---|
102 | * data structures are initialized. In older BSPs or those |
---|
103 | * which do not use the shared framework, this is the typical |
---|
104 | * time when the C Library is initialized so malloc() |
---|
105 | * can be called by device drivers. For BSPs using the shared |
---|
106 | * framework, this routine can be empty. |
---|
107 | */ |
---|
108 | bsp_pretasking_hook(); |
---|
109 | |
---|
110 | /* |
---|
111 | * If debug is enabled, then enable all dynamic RTEMS debug |
---|
112 | * capabilities. |
---|
113 | * |
---|
114 | * NOTE: Most debug features are conditionally compiled in |
---|
115 | * or enabled via configure time plugins. |
---|
116 | */ |
---|
117 | #ifdef RTEMS_DEBUG |
---|
118 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
119 | #endif |
---|
120 | |
---|
121 | /* |
---|
122 | * Let RTEMS perform initialization it requires before drivers |
---|
123 | * are allowed to be initialized. |
---|
124 | */ |
---|
125 | rtems_initialize_before_drivers(); |
---|
126 | |
---|
127 | /* |
---|
128 | * Execute BSP specific pre-driver hook. Drivers haven't gotten |
---|
129 | * to initialize yet so this is a good chance to initialize |
---|
130 | * buses, spurious interrupt handlers, etc.. |
---|
131 | * |
---|
132 | * NOTE: Many BSPs do not require this handler and use the |
---|
133 | * shared stub. |
---|
134 | */ |
---|
135 | bsp_predriver_hook(); |
---|
136 | |
---|
137 | /* |
---|
138 | * Initialize all device drivers. |
---|
139 | */ |
---|
140 | rtems_initialize_device_drivers(); |
---|
141 | |
---|
142 | /* |
---|
143 | * Invoke the postdriver hook. This normally opens /dev/console |
---|
144 | * for use as stdin, stdout, and stderr. |
---|
145 | */ |
---|
146 | bsp_postdriver_hook(); |
---|
147 | |
---|
148 | /* |
---|
149 | * Complete initialization of RTEMS and switch to the first task. |
---|
150 | * Global C++ constructors will be executed in the context of that task. |
---|
151 | */ |
---|
152 | rtems_initialize_start_multitasking(); |
---|
153 | |
---|
154 | /*************************************************************** |
---|
155 | *************************************************************** |
---|
156 | * APPLICATION RUNS NOW!!! We will not return to here!!! * |
---|
157 | *************************************************************** |
---|
158 | ***************************************************************/ |
---|
159 | } |
---|