1/* @file
2 * @brief startup file for Energy Micro 'EFM32G' devices.
3 *        For use with GCC for ARM Embedded Processors
4 * @version 3.0.0
5 * Date: 08 Feb 2012
6 *
7 * Copyright (c) 2012, ARM Limited
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12    * Redistributions of source code must retain the above copyright
13      notice, this list of conditions and the following disclaimer.
14    * Redistributions in binary form must reproduce the above copyright
15      notice, this list of conditions and the following disclaimer in the
16      documentation and/or other materials provided with the distribution.
17    * Neither the name of the ARM Limited nor the
18      names of its contributors may be used to endorse or promote products
19      derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * Energy Micro release version
33 * @version 3.0.0
34 */
35    .syntax unified
36    .arch armv7-m
37
38    .section .stack
39    .align 3
40#ifdef __STACK_SIZE
41    .equ    Stack_Size, __STACK_SIZE
42#else
43    .equ    Stack_Size, 0x400
44#endif
45    .globl    __StackTop
46    .globl    __StackLimit
47__StackLimit:
48    .space    Stack_Size
49    .size __StackLimit, . - __StackLimit
50__StackTop:
51    .size __StackTop, . - __StackTop
52
53    .section .heap
54    .align 3
55#ifdef __HEAP_SIZE
56    .equ    Heap_Size, __HEAP_SIZE
57#else
58    .equ    Heap_Size, 0xC00
59#endif
60    .globl    __HeapBase
61    .globl    __HeapLimit
62__HeapBase:
63    .if    Heap_Size
64    .space    Heap_Size
65    .endif
66    .size __HeapBase, . - __HeapBase
67__HeapLimit:
68    .size __HeapLimit, . - __HeapLimit
69
70    .section .isr_vector
71    .align 8
72    .globl __isr_vector
73__isr_vector:
74    .long    __StackTop            /* Top of Stack */
75    .long    Reset_Handler         /* Reset Handler */
76    .long    NMI_Handler           /* NMI Handler */
77    .long    HardFault_Handler     /* Hard Fault Handler */
78    .long    MemManage_Handler     /* MPU Fault Handler */
79    .long    BusFault_Handler      /* Bus Fault Handler */
80    .long    UsageFault_Handler    /* Usage Fault Handler */
81    .long    Default_Handler       /* Reserved */
82    .long    Default_Handler       /* Reserved */
83    .long    Default_Handler       /* Reserved */
84    .long    Default_Handler       /* Reserved */
85    .long    SVC_Handler           /* SVCall Handler */
86    .long    DebugMon_Handler      /* Debug Monitor Handler */
87    .long    Default_Handler       /* Reserved */
88    .long    PendSV_Handler        /* PendSV Handler */
89    .long    SysTick_Handler       /* SysTick Handler */
90
91    /* External interrupts */
92    .long    DMA_IRQHandler    /* 0 - DMA */
93    .long    GPIO_EVEN_IRQHandler    /* 1 - GPIO_EVEN */
94    .long    TIMER0_IRQHandler    /* 2 - TIMER0 */
95    .long    USART0_RX_IRQHandler    /* 3 - USART0_RX */
96    .long    USART0_TX_IRQHandler    /* 4 - USART0_TX */
97    .long    ACMP0_IRQHandler    /* 5 - ACMP0 */
98    .long    ADC0_IRQHandler    /* 6 - ADC0 */
99    .long    DAC0_IRQHandler    /* 7 - DAC0 */
100    .long    I2C0_IRQHandler    /* 8 - I2C0 */
101    .long    GPIO_ODD_IRQHandler    /* 9 - GPIO_ODD */
102    .long    TIMER1_IRQHandler    /* 10 - TIMER1 */
103    .long    TIMER2_IRQHandler    /* 11 - TIMER2 */
104    .long    USART1_RX_IRQHandler    /* 12 - USART1_RX */
105    .long    USART1_TX_IRQHandler    /* 13 - USART1_TX */
106    .long    USART2_RX_IRQHandler    /* 14 - USART2_RX */
107    .long    USART2_TX_IRQHandler    /* 15 - USART2_TX */
108    .long    UART0_RX_IRQHandler    /* 16 - UART0_RX */
109    .long    UART0_TX_IRQHandler    /* 17 - UART0_TX */
110    .long    LEUART0_IRQHandler    /* 18 - LEUART0 */
111    .long    LEUART1_IRQHandler    /* 19 - LEUART1 */
112    .long    LETIMER0_IRQHandler    /* 20 - LETIMER0 */
113    .long    PCNT0_IRQHandler    /* 21 - PCNT0 */
114    .long    PCNT1_IRQHandler    /* 22 - PCNT1 */
115    .long    PCNT2_IRQHandler    /* 23 - PCNT2 */
116    .long    RTC_IRQHandler    /* 24 - RTC */
117    .long    CMU_IRQHandler    /* 25 - CMU */
118    .long    VCMP_IRQHandler    /* 26 - VCMP */
119    .long    LCD_IRQHandler    /* 27 - LCD */
120    .long    MSC_IRQHandler    /* 28 - MSC */
121    .long    AES_IRQHandler    /* 29 - AES */
122
123
124    .size    __isr_vector, . - __isr_vector
125
126    .text
127    .thumb
128    .thumb_func
129    .align 2
130    .globl    Reset_Handler
131    .type    Reset_Handler, %function
132Reset_Handler:
133/*     Loop to copy data from read only memory to RAM. The ranges
134 *      of copy from/to are specified by following symbols evaluated in
135 *      linker script.
136 *      __etext: End of code section, i.e., begin of data sections to copy from.
137 *      __data_start__/__data_end__: RAM address range that data should be
138 *      copied to. Both must be aligned to 4 bytes boundary.  */
139#ifndef __NO_SYSTEM_INIT
140    ldr    r0, =SystemInit
141    blx    r0
142#endif
143    ldr    r1, =__etext
144    ldr    r2, =__data_start__
145    ldr    r3, =__data_end__
146
147#if 1
148/* Here are two copies of loop implemenations. First one favors code size
149 * and the second one favors performance. Default uses the first one.
150 * Change to "#if 0" to use the second one */
151.flash_to_ram_loop:
152    cmp     r2, r3
153    ittt    lt
154    ldrlt   r0, [r1], #4
155    strlt   r0, [r2], #4
156    blt    .flash_to_ram_loop
157#else
158    subs    r3, r2
159    ble    .flash_to_ram_loop_end
160.flash_to_ram_loop:
161    subs    r3, #4
162    ldr    r0, [r1, r3]
163    str    r0, [r2, r3]
164    bgt    .flash_to_ram_loop
165.flash_to_ram_loop_end:
166#endif
167
168#ifndef __NO_SYSTEM_INIT
169    ldr    r0, =SystemInit
170    blx    r0
171#endif
172
173    ldr    r0, =_start
174    bx    r0
175    .pool
176    .size Reset_Handler, . - Reset_Handler
177
178/*    Macro to define default handlers. Default handler
179 *    will be weak symbol and just dead loops. They can be
180 *    overwritten by other handlers */
181    .macro    def_irq_handler    handler_name
182    .align 1
183    .thumb_func
184    .weak    \handler_name
185    .type    \handler_name, %function
186\handler_name:
187    b    .
188    .size    \handler_name, . - \handler_name
189    .endm
190
191    def_irq_handler    Default_Handler
192
193    def_irq_handler    NMI_Handler
194    def_irq_handler    HardFault_Handler
195    def_irq_handler    MemManage_Handler
196    def_irq_handler    BusFault_Handler
197    def_irq_handler    UsageFault_Handler
198    def_irq_handler    SVC_Handler
199    def_irq_handler    DebugMon_Handler
200    def_irq_handler    PendSV_Handler
201    def_irq_handler    SysTick_Handler
202
203    def_irq_handler    DMA_IRQHandler
204    def_irq_handler    GPIO_EVEN_IRQHandler
205    def_irq_handler    TIMER0_IRQHandler
206    def_irq_handler    USART0_RX_IRQHandler
207    def_irq_handler    USART0_TX_IRQHandler
208    def_irq_handler    ACMP0_IRQHandler
209    def_irq_handler    ADC0_IRQHandler
210    def_irq_handler    DAC0_IRQHandler
211    def_irq_handler    I2C0_IRQHandler
212    def_irq_handler    GPIO_ODD_IRQHandler
213    def_irq_handler    TIMER1_IRQHandler
214    def_irq_handler    TIMER2_IRQHandler
215    def_irq_handler    USART1_RX_IRQHandler
216    def_irq_handler    USART1_TX_IRQHandler
217    def_irq_handler    USART2_RX_IRQHandler
218    def_irq_handler    USART2_TX_IRQHandler
219    def_irq_handler    UART0_RX_IRQHandler
220    def_irq_handler    UART0_TX_IRQHandler
221    def_irq_handler    LEUART0_IRQHandler
222    def_irq_handler    LEUART1_IRQHandler
223    def_irq_handler    LETIMER0_IRQHandler
224    def_irq_handler    PCNT0_IRQHandler
225    def_irq_handler    PCNT1_IRQHandler
226    def_irq_handler    PCNT2_IRQHandler
227    def_irq_handler    RTC_IRQHandler
228    def_irq_handler    CMU_IRQHandler
229    def_irq_handler    VCMP_IRQHandler
230    def_irq_handler    LCD_IRQHandler
231    def_irq_handler    MSC_IRQHandler
232    def_irq_handler    AES_IRQHandler
233
234
235    .end
236