]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Pearl_Gecko_Simplicity_Studio/SilLabs_Source/CMSIS/efm32pg1b/startup_gcc_efm32pg1b.s
d9e8a9d3a55dc63a4b5f855ac7695f07c6f42c13
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Pearl_Gecko_Simplicity_Studio / SilLabs_Source / CMSIS / efm32pg1b / startup_gcc_efm32pg1b.s
1 /* @file startup_efm32pg1b.S\r
2  * @brief startup file for Silicon Labs EFM32PG1B devices.\r
3  *        For use with GCC for ARM Embedded Processors\r
4  * @version 4.2.1\r
5  * Date:    12 June 2014\r
6  *\r
7  */\r
8 /* Copyright (c) 2011 - 2014 ARM LIMITED\r
9 \r
10    All rights reserved.\r
11    Redistribution and use in source and binary forms, with or without\r
12    modification, are permitted provided that the following conditions are met:\r
13    - Redistributions of source code must retain the above copyright\r
14      notice, this list of conditions and the following disclaimer.\r
15    - Redistributions in binary form must reproduce the above copyright\r
16      notice, this list of conditions and the following disclaimer in the\r
17      documentation and/or other materials provided with the distribution.\r
18    - Neither the name of ARM nor the names of its contributors may be used\r
19      to endorse or promote products derived from this software without\r
20      specific prior written permission.\r
21    *\r
22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
23    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
24    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
25    ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE\r
26    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
27    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
28    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
29    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
30    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
31    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
32    POSSIBILITY OF SUCH DAMAGE.\r
33    ---------------------------------------------------------------------------*/\r
34 \r
35     .syntax     unified\r
36     .arch       armv7-m\r
37     .section    .stack\r
38     .align      3\r
39 #ifdef __STACK_SIZE\r
40     .equ        Stack_Size, __STACK_SIZE\r
41 #else\r
42     .equ        Stack_Size, 0x00000400\r
43 #endif\r
44     .globl      __StackTop\r
45     .globl      __StackLimit\r
46 __StackLimit:\r
47     .space      Stack_Size\r
48     .size       __StackLimit, . - __StackLimit\r
49 __StackTop:\r
50     .size       __StackTop, . - __StackTop\r
51 \r
52     .section    .heap\r
53     .align      3\r
54 #ifdef __HEAP_SIZE\r
55     .equ        Heap_Size, __HEAP_SIZE\r
56 #else\r
57     .equ        Heap_Size, 0x00000C00\r
58 #endif\r
59     .globl      __HeapBase\r
60     .globl      __HeapLimit\r
61 __HeapBase:\r
62     .if Heap_Size\r
63     .space      Heap_Size\r
64     .endif\r
65     .size       __HeapBase, . - __HeapBase\r
66 __HeapLimit:\r
67     .size       __HeapLimit, . - __HeapLimit\r
68 \r
69     .section    .vectors\r
70     .align      2\r
71     .globl      __Vectors\r
72 __Vectors:\r
73     .long       __StackTop            /* Top of Stack */\r
74     .long       Reset_Handler         /* Reset Handler */\r
75     .long       NMI_Handler           /* NMI Handler */\r
76     .long       HardFault_Handler     /* Hard Fault Handler */\r
77     .long       MemManage_Handler     /* MPU Fault Handler */\r
78     .long       BusFault_Handler      /* Bus Fault Handler */\r
79     .long       UsageFault_Handler    /* Usage Fault Handler */\r
80     .long       Default_Handler       /* Reserved */\r
81     .long       Default_Handler       /* Reserved */\r
82     .long       Default_Handler       /* Reserved */\r
83     .long       Default_Handler       /* Reserved */\r
84     .long       SVC_Handler           /* SVCall Handler */\r
85     .long       DebugMon_Handler      /* Debug Monitor Handler */\r
86     .long       Default_Handler       /* Reserved */\r
87     .long       PendSV_Handler        /* PendSV Handler */\r
88     .long       SysTick_Handler       /* SysTick Handler */\r
89 \r
90     /* External interrupts */\r
91     .long       EMU_IRQHandler    /* 0 - EMU */\r
92     .long       Default_Handler    /* 1 - Reserved */\r
93     .long       WDOG0_IRQHandler    /* 2 - WDOG0 */\r
94     .long       Default_Handler    /* 3 - Reserved */\r
95     .long       Default_Handler    /* 4 - Reserved */\r
96     .long       Default_Handler    /* 5 - Reserved */\r
97     .long       Default_Handler    /* 6 - Reserved */\r
98     .long       Default_Handler    /* 7 - Reserved */\r
99     .long       LDMA_IRQHandler    /* 8 - LDMA */\r
100     .long       GPIO_EVEN_IRQHandler    /* 9 - GPIO_EVEN */\r
101     .long       TIMER0_IRQHandler    /* 10 - TIMER0 */\r
102     .long       USART0_RX_IRQHandler    /* 11 - USART0_RX */\r
103     .long       USART0_TX_IRQHandler    /* 12 - USART0_TX */\r
104     .long       ACMP0_IRQHandler    /* 13 - ACMP0 */\r
105     .long       ADC0_IRQHandler    /* 14 - ADC0 */\r
106     .long       IDAC0_IRQHandler    /* 15 - IDAC0 */\r
107     .long       I2C0_IRQHandler    /* 16 - I2C0 */\r
108     .long       GPIO_ODD_IRQHandler    /* 17 - GPIO_ODD */\r
109     .long       TIMER1_IRQHandler    /* 18 - TIMER1 */\r
110     .long       USART1_RX_IRQHandler    /* 19 - USART1_RX */\r
111     .long       USART1_TX_IRQHandler    /* 20 - USART1_TX */\r
112     .long       LEUART0_IRQHandler    /* 21 - LEUART0 */\r
113     .long       PCNT0_IRQHandler    /* 22 - PCNT0 */\r
114     .long       CMU_IRQHandler    /* 23 - CMU */\r
115     .long       MSC_IRQHandler    /* 24 - MSC */\r
116     .long       CRYPTO_IRQHandler    /* 25 - CRYPTO */\r
117     .long       LETIMER0_IRQHandler    /* 26 - LETIMER0 */\r
118     .long       Default_Handler    /* 27 - Reserved */\r
119     .long       Default_Handler    /* 28 - Reserved */\r
120     .long       RTCC_IRQHandler    /* 29 - RTCC */\r
121     .long       Default_Handler    /* 30 - Reserved */\r
122     .long       CRYOTIMER_IRQHandler    /* 31 - CRYOTIMER */\r
123     .long       Default_Handler    /* 32 - Reserved */\r
124     .long       FPUEH_IRQHandler    /* 33 - FPUEH */\r
125 \r
126 \r
127     .size       __Vectors, . - __Vectors\r
128 \r
129     .text\r
130     .thumb\r
131     .thumb_func\r
132     .align      2\r
133     .globl      Reset_Handler\r
134     .type       Reset_Handler, %function\r
135 Reset_Handler:\r
136 #ifndef __NO_SYSTEM_INIT\r
137     ldr     r0, =SystemInit\r
138     blx     r0\r
139 #endif\r
140 \r
141 /*  Firstly it copies data from read only memory to RAM. There are two schemes\r
142  *  to copy. One can copy more than one sections. Another can only copy\r
143  *  one section.  The former scheme needs more instructions and read-only\r
144  *  data to implement than the latter.\r
145  *  Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes.  */\r
146 \r
147 #ifdef __STARTUP_COPY_MULTIPLE\r
148 /*  Multiple sections scheme.\r
149  *\r
150  *  Between symbol address __copy_table_start__ and __copy_table_end__,\r
151  *  there are array of triplets, each of which specify:\r
152  *    offset 0: LMA of start of a section to copy from\r
153  *    offset 4: VMA of start of a section to copy to\r
154  *    offset 8: size of the section to copy. Must be multiply of 4\r
155  *\r
156  *  All addresses must be aligned to 4 bytes boundary.\r
157  */\r
158     ldr     r4, =__copy_table_start__\r
159     ldr     r5, =__copy_table_end__\r
160 \r
161 .L_loop0:\r
162     cmp     r4, r5\r
163     bge     .L_loop0_done\r
164     ldr     r1, [r4]\r
165     ldr     r2, [r4, #4]\r
166     ldr     r3, [r4, #8]\r
167 \r
168 .L_loop0_0:\r
169     subs    r3, #4\r
170     ittt    ge\r
171     ldrge   r0, [r1, r3]\r
172     strge   r0, [r2, r3]\r
173     bge     .L_loop0_0\r
174 \r
175     adds    r4, #12\r
176     b       .L_loop0\r
177 \r
178 .L_loop0_done:\r
179 #else\r
180 /*  Single section scheme.\r
181  *\r
182  *  The ranges of copy from/to are specified by following symbols\r
183  *    __etext: LMA of start of the section to copy from. Usually end of text\r
184  *    __data_start__: VMA of start of the section to copy to\r
185  *    __data_end__: VMA of end of the section to copy to\r
186  *\r
187  *  All addresses must be aligned to 4 bytes boundary.\r
188  */\r
189     ldr     r1, =__etext\r
190     ldr     r2, =__data_start__\r
191     ldr     r3, =__data_end__\r
192 \r
193 .L_loop1:\r
194     cmp     r2, r3\r
195     ittt    lt\r
196     ldrlt   r0, [r1], #4\r
197     strlt   r0, [r2], #4\r
198     blt     .L_loop1\r
199 #endif /*__STARTUP_COPY_MULTIPLE */\r
200 \r
201 /*  This part of work usually is done in C library startup code. Otherwise,\r
202  *  define this macro to enable it in this startup.\r
203  *\r
204  *  There are two schemes too. One can clear multiple BSS sections. Another\r
205  *  can only clear one section. The former is more size expensive than the\r
206  *  latter.\r
207  *\r
208  *  Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.\r
209  *  Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.\r
210  */\r
211 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE\r
212 /*  Multiple sections scheme.\r
213  *\r
214  *  Between symbol address __copy_table_start__ and __copy_table_end__,\r
215  *  there are array of tuples specifying:\r
216  *    offset 0: Start of a BSS section\r
217  *    offset 4: Size of this BSS section. Must be multiply of 4\r
218  */\r
219     ldr     r3, =__zero_table_start__\r
220     ldr     r4, =__zero_table_end__\r
221 \r
222 .L_loop2:\r
223     cmp     r3, r4\r
224     bge     .L_loop2_done\r
225     ldr     r1, [r3]\r
226     ldr     r2, [r3, #4]\r
227     movs    r0, 0\r
228 \r
229 .L_loop2_0:\r
230     subs    r2, #4\r
231     itt     ge\r
232     strge   r0, [r1, r2]\r
233     bge     .L_loop2_0\r
234     adds    r3, #8\r
235     b       .L_loop2\r
236 .L_loop2_done:\r
237 #elif defined (__STARTUP_CLEAR_BSS)\r
238 /*  Single BSS section scheme.\r
239  *\r
240  *  The BSS section is specified by following symbols\r
241  *    __bss_start__: start of the BSS section.\r
242  *    __bss_end__: end of the BSS section.\r
243  *\r
244  *  Both addresses must be aligned to 4 bytes boundary.\r
245  */\r
246     ldr     r1, =__bss_start__\r
247     ldr     r2, =__bss_end__\r
248 \r
249     movs    r0, 0\r
250 .L_loop3:\r
251     cmp     r1, r2\r
252     itt     lt\r
253     strlt   r0, [r1], #4\r
254     blt     .L_loop3\r
255 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */\r
256 \r
257 #ifndef __START\r
258 #define __START _start\r
259 #endif\r
260     bl      __START\r
261 \r
262     .pool\r
263     .size   Reset_Handler, . - Reset_Handler\r
264 \r
265     .align  1\r
266     .thumb_func\r
267     .weak   Default_Handler\r
268     .type   Default_Handler, %function\r
269 Default_Handler:\r
270     b       .\r
271     .size   Default_Handler, . - Default_Handler\r
272 \r
273 /*    Macro to define default handlers. Default handler\r
274  *    will be weak symbol and just dead loops. They can be\r
275  *    overwritten by other handlers */\r
276     .macro  def_irq_handler     handler_name\r
277     .weak   \handler_name\r
278     .set    \handler_name, Default_Handler\r
279     .endm\r
280 \r
281     def_irq_handler     NMI_Handler\r
282     def_irq_handler     HardFault_Handler\r
283     def_irq_handler     MemManage_Handler\r
284     def_irq_handler     BusFault_Handler\r
285     def_irq_handler     UsageFault_Handler\r
286     def_irq_handler     SVC_Handler\r
287     def_irq_handler     DebugMon_Handler\r
288     def_irq_handler     PendSV_Handler\r
289     def_irq_handler     SysTick_Handler\r
290 \r
291 \r
292     def_irq_handler     EMU_IRQHandler\r
293     def_irq_handler     WDOG0_IRQHandler\r
294     def_irq_handler     LDMA_IRQHandler\r
295     def_irq_handler     GPIO_EVEN_IRQHandler\r
296     def_irq_handler     TIMER0_IRQHandler\r
297     def_irq_handler     USART0_RX_IRQHandler\r
298     def_irq_handler     USART0_TX_IRQHandler\r
299     def_irq_handler     ACMP0_IRQHandler\r
300     def_irq_handler     ADC0_IRQHandler\r
301     def_irq_handler     IDAC0_IRQHandler\r
302     def_irq_handler     I2C0_IRQHandler\r
303     def_irq_handler     GPIO_ODD_IRQHandler\r
304     def_irq_handler     TIMER1_IRQHandler\r
305     def_irq_handler     USART1_RX_IRQHandler\r
306     def_irq_handler     USART1_TX_IRQHandler\r
307     def_irq_handler     LEUART0_IRQHandler\r
308     def_irq_handler     PCNT0_IRQHandler\r
309     def_irq_handler     CMU_IRQHandler\r
310     def_irq_handler     MSC_IRQHandler\r
311     def_irq_handler     CRYPTO_IRQHandler\r
312     def_irq_handler     LETIMER0_IRQHandler\r
313     def_irq_handler     RTCC_IRQHandler\r
314     def_irq_handler     CRYOTIMER_IRQHandler\r
315     def_irq_handler     FPUEH_IRQHandler\r
316 \r
317     .end\r