]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_LM3Sxxxx_Rowley/thumb_crt0.s
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_LM3Sxxxx_Rowley / thumb_crt0.s
1 /*****************************************************************************\r
2  * Copyright (c) 2009 Rowley Associates Limited.                             *\r
3  *                                                                           *\r
4  * This file may be distributed under the terms of the License Agreement     *\r
5  * provided with this software.                                              *\r
6  *                                                                           *\r
7  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING THE   *\r
8  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *\r
9  *****************************************************************************/\r
10 \r
11 /*****************************************************************************\r
12  *                           Preprocessor Definitions\r
13  *                           ------------------------\r
14  * APP_ENTRY_POINT\r
15  *\r
16  *   Defines the application entry point function, if undefined this setting\r
17  *   defaults to "main".\r
18  *\r
19  * USE_PROCESS_STACK\r
20  *\r
21  *   If defined, thread mode will be configured to use the process stack if\r
22  *   the size of the process stack is greater than zero bytes in length.\r
23  *\r
24  * INITIALIZE_STACK\r
25  *\r
26  *   If defined, the contents of the stack will be initialized to a the\r
27  *   value 0xCC.\r
28  *\r
29  * FULL_LIBRARY\r
30  *\r
31  *  If defined then\r
32  *    - argc, argv are setup by the debug_getargs.\r
33  *    - the exit symbol is defined and executes on return from main.\r
34  *    - the exit symbol calls destructors, atexit functions and then debug_exit.\r
35  *\r
36  *  If not defined then\r
37  *    - argc and argv are zero.\r
38  *    - no exit symbol, code loops on return from main.\r
39  *****************************************************************************/\r
40 \r
41 #ifndef APP_ENTRY_POINT\r
42 #define APP_ENTRY_POINT main\r
43 #endif\r
44 \r
45 #ifndef ARGSSPACE\r
46 #define ARGSSPACE 128\r
47 #endif\r
48 \r
49   .global _start\r
50   .syntax unified\r
51   .extern APP_ENTRY_POINT\r
52 #ifdef FULL_LIBRARY\r
53   .global exit\r
54 #endif\r
55 \r
56   .section .init, "ax"\r
57   .code 16\r
58   .align 2\r
59   .thumb_func\r
60 \r
61 _start:\r
62 #ifdef __RAM_BUILD\r
63   ldr r1, =__stack_end__\r
64   mov sp, r1\r
65 #endif\r
66 #ifdef INITIALIZE_STACK\r
67   mov r2, #0xCC\r
68   ldr r0, =__stack_start__\r
69 #ifndef __RAM_BUILD\r
70   mov r1, sp\r
71 #endif\r
72   bl memory_set\r
73 #endif\r
74 \r
75 #ifdef USE_PROCESS_STACK\r
76   /* Set up process stack if size > 0 */\r
77   ldr r1, =__stack_process_end__\r
78   ldr r0, =__stack_process_start__\r
79   subs r2, r1, r0\r
80   beq 1f\r
81   msr psp, r1\r
82   mov r2, #2\r
83   msr control, r2\r
84 #ifdef INITIALIZE_STACK\r
85   mov r2, #0xCC\r
86   bl memory_set\r
87 #endif\r
88 1:\r
89 #endif\r
90   /* Copy initialised memory sections into RAM (if necessary). */\r
91   ldr r0, =__data_load_start__\r
92   ldr r1, =__data_start__\r
93   ldr r2, =__data_end__\r
94   bl memory_copy\r
95   ldr r0, =__text_load_start__\r
96   ldr r1, =__text_start__\r
97   ldr r2, =__text_end__\r
98   bl memory_copy\r
99   ldr r0, =__fast_load_start__\r
100   ldr r1, =__fast_start__\r
101   ldr r2, =__fast_end__\r
102   bl memory_copy\r
103   ldr r0, =__ctors_load_start__\r
104   ldr r1, =__ctors_start__\r
105   ldr r2, =__ctors_end__\r
106   bl memory_copy\r
107   ldr r0, =__dtors_load_start__\r
108   ldr r1, =__dtors_start__\r
109   ldr r2, =__dtors_end__\r
110   bl memory_copy\r
111   ldr r0, =__rodata_load_start__\r
112   ldr r1, =__rodata_start__\r
113   ldr r2, =__rodata_end__\r
114   bl memory_copy\r
115 \r
116   /* Zero the bss. */\r
117   ldr r0, =__bss_start__\r
118   ldr r1, =__bss_end__\r
119   mov r2, #0\r
120   bl memory_set\r
121 \r
122   /* Initialise the heap */\r
123   ldr r0, = __heap_start__\r
124   ldr r1, = __heap_end__\r
125   sub r1, r1, r0\r
126   mov r2, #0\r
127   str r2, [r0]\r
128   add r0, r0, #4\r
129   str r1, [r0]\r
130 \r
131   /* Call constructors */\r
132   ldr r0, =__ctors_start__\r
133   ldr r1, =__ctors_end__\r
134 ctor_loop:\r
135   cmp r0, r1\r
136   beq ctor_end\r
137   ldr r2, [r0]\r
138   add r0, #4\r
139   push {r0-r1}\r
140   blx r2\r
141   pop {r0-r1}\r
142   b ctor_loop\r
143 ctor_end:\r
144 \r
145   /* Setup initial call frame */\r
146   mov r0, #0\r
147   mov lr, r0\r
148   mov r12, sp\r
149 \r
150 start:\r
151   /* Jump to application entry point */\r
152 #ifdef FULL_LIBRARY\r
153   mov r0, #ARGSSPACE\r
154   ldr r1, =args\r
155   ldr r2, =debug_getargs\r
156   blx r2\r
157   ldr r1, =args\r
158 #else\r
159   mov r0, #0\r
160   mov r1, #0\r
161 #endif\r
162   ldr r2, =APP_ENTRY_POINT\r
163   blx r2\r
164 \r
165 #ifdef FULL_LIBRARY\r
166   .thumb_func\r
167 exit:\r
168   mov r5, r0 // save the exit parameter/return result\r
169 \r
170   /* Call destructors */\r
171   ldr r0, =__dtors_start__\r
172   ldr r1, =__dtors_end__\r
173 dtor_loop:\r
174   cmp r0, r1\r
175   beq dtor_end\r
176   ldr r2, [r0]\r
177   add r0, #4\r
178   push {r0-r1}\r
179   blx r2\r
180   pop {r0-r1}\r
181   b dtor_loop\r
182 dtor_end:\r
183 \r
184   /* Call atexit functions */\r
185   ldr r2, =_execute_at_exit_fns\r
186   blx r2\r
187 \r
188   /* Call debug_exit with return result/exit parameter */\r
189   mov r0, r5\r
190   ldr r2, =debug_exit\r
191   blx r2\r
192 #endif\r
193 \r
194   /* Returned from application entry point, loop forever. */\r
195 exit_loop:\r
196   b exit_loop\r
197 \r
198 memory_copy:\r
199   cmp r0, r1\r
200   beq 2f\r
201   subs r2, r2, r1\r
202   beq 2f\r
203 1:\r
204   ldrb r3, [r0]\r
205   add r0, r0, #1\r
206   strb r3, [r1]\r
207   add r1, r1, #1\r
208   subs r2, r2, #1\r
209   bne 1b\r
210 2:\r
211   bx lr\r
212 \r
213 memory_set:\r
214   cmp r0, r1\r
215   beq 1f\r
216   strb r2, [r0]\r
217   add r0, r0, #1\r
218   b memory_set\r
219 1:\r
220   bx lr\r
221 \r
222 #ifdef FULL_LIBRARY\r
223   .bss\r
224 args:\r
225   .space ARGSSPACE\r
226 #endif\r
227 \r