blob: ae6794ff9d171e06b9be6f585e444fbe88c97c57 [file] [log] [blame]
Brian Silverman2bf644d2013-12-06 16:54:59 -08001/* File: startup_ARMCM3.S
2 * Purpose: startup file for Cortex-M3 devices. Should use with
3 * GCC for ARM Embedded Processors
4 * Version: V1.4
5 * Date: 20 Dezember 2012
6 *
7 */
8/* Copyright (c) 2011 - 2012 ARM LIMITED
9
10 All rights reserved.
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 - Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 - Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 - Neither the name of ARM nor the names of its contributors may be used
19 to endorse or promote products derived from this software without
20 specific prior written permission.
21 *
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 ---------------------------------------------------------------------------*/
34
35
36 .syntax unified
37 .arch armv7-m
38
39 .section .stack
40 .align 3
41#ifdef __STACK_SIZE
42 .equ Stack_Size, __STACK_SIZE
43#else
44 .equ Stack_Size, 0x00000400
45#endif
46 .globl __StackTop
47 .globl __StackLimit
48__StackLimit:
49 .space Stack_Size
50 .size __StackLimit, . - __StackLimit
51__StackTop:
52 .size __StackTop, . - __StackTop
53
54 .section .heap
55 .align 3
56#ifdef __HEAP_SIZE
57 .equ Heap_Size, __HEAP_SIZE
58#else
59 .equ Heap_Size, 0x00000C00
60#endif
61 .globl __HeapBase
62 .globl __HeapLimit
63__HeapBase:
64 .if Heap_Size
65 .space Heap_Size
66 .endif
67 .size __HeapBase, . - __HeapBase
68__HeapLimit:
69 .size __HeapLimit, . - __HeapLimit
70
71#if 0
72 .section .isr_vector
73 .align 2
74 .globl __isr_vector
75__isr_vector:
76 .long __StackTop /* Top of Stack */
77 .long Reset_Handler /* Reset Handler */
78 .long NMI_Handler /* NMI Handler */
79 .long HardFault_Handler /* Hard Fault Handler */
80 .long MemManage_Handler /* MPU Fault Handler */
81 .long BusFault_Handler /* Bus Fault Handler */
82 .long UsageFault_Handler /* Usage Fault Handler */
83 .long 0 /* Reserved */
84 .long 0 /* Reserved */
85 .long 0 /* Reserved */
86 .long 0 /* Reserved */
87 .long SVC_Handler /* SVCall Handler */
88 .long DebugMon_Handler /* Debug Monitor Handler */
89 .long 0 /* Reserved */
90 .long PendSV_Handler /* PendSV Handler */
91 .long SysTick_Handler /* SysTick Handler */
92
93 /* External interrupts */
94 .long WDT_IRQHandler /* 0: Watchdog Timer */
95 .long RTC_IRQHandler /* 1: Real Time Clock */
96 .long TIM0_IRQHandler /* 2: Timer0 / Timer1 */
97 .long TIM2_IRQHandler /* 3: Timer2 / Timer3 */
98 .long MCIA_IRQHandler /* 4: MCIa */
99 .long MCIB_IRQHandler /* 5: MCIb */
100 .long UART0_IRQHandler /* 6: UART0 - DUT FPGA */
101 .long UART1_IRQHandler /* 7: UART1 - DUT FPGA */
102 .long UART2_IRQHandler /* 8: UART2 - DUT FPGA */
103 .long UART4_IRQHandler /* 9: UART4 - not connected */
104 .long AACI_IRQHandler /* 10: AACI / AC97 */
105 .long CLCD_IRQHandler /* 11: CLCD Combined Interrupt */
106 .long ENET_IRQHandler /* 12: Ethernet */
107 .long USBDC_IRQHandler /* 13: USB Device */
108 .long USBHC_IRQHandler /* 14: USB Host Controller */
109 .long CHLCD_IRQHandler /* 15: Character LCD */
110 .long FLEXRAY_IRQHandler /* 16: Flexray */
111 .long CAN_IRQHandler /* 17: CAN */
112 .long LIN_IRQHandler /* 18: LIN */
113 .long I2C_IRQHandler /* 19: I2C ADC/DAC */
114 .long 0 /* 20: Reserved */
115 .long 0 /* 21: Reserved */
116 .long 0 /* 22: Reserved */
117 .long 0 /* 23: Reserved */
118 .long 0 /* 24: Reserved */
119 .long 0 /* 25: Reserved */
120 .long 0 /* 26: Reserved */
121 .long 0 /* 27: Reserved */
122 .long CPU_CLCD_IRQHandler /* 28: Reserved - CPU FPGA CLCD */
123 .long 0 /* 29: Reserved - CPU FPGA */
124 .long UART3_IRQHandler /* 30: UART3 - CPU FPGA */
125 .long SPI_IRQHandler /* 31: SPI Touchscreen - CPU FPGA */
126
127 .size __isr_vector, . - __isr_vector
128#else
129.macro ISR_HANDLER name=
130 .section .vectors, "ax"
131 .word \name
132 .section .init, "ax"
133 .thumb_func
134 .weak \name
135\name:
1361: b 1b /* endless loop */
137.endm
138
139.macro ISR_RESERVED
140 .section .vectors, "ax"
141 .word 0
142.endm
143
144 .syntax unified
145 .global reset_handler
146
147 .section .vectors, "ax"
148 .code 16
149 .global _vectors
150
151_vectors:
152 .long __StackTop /* Top of Stack */
153 .long Reset_Handler /* Reset Handler */
154ISR_HANDLER NMI_Handler
155ISR_HANDLER HardFault_Handler
156ISR_HANDLER MemManage_Handler
157ISR_HANDLER BusFault_Handler
158ISR_HANDLER UsageFault_Handler
159ISR_RESERVED
160ISR_RESERVED
161ISR_RESERVED
162ISR_RESERVED
163ISR_HANDLER SVC_Handler
164ISR_HANDLER DebugMon_Handler
165ISR_RESERVED
166ISR_HANDLER PendSV_Handler
167ISR_HANDLER SysTick_Handler
168/* interrupts */
169ISR_HANDLER WWDG_IRQHandler
170ISR_HANDLER PVD_IRQHandler
171ISR_HANDLER TAMP_STAMP_IRQHandler
172ISR_HANDLER RTC_WKUP_IRQHandler
173ISR_HANDLER FLASH_IRQHandler
174ISR_HANDLER RCC_IRQHandler
175ISR_HANDLER EXTI0_IRQHandler
176ISR_HANDLER EXTI1_IRQHandler
177ISR_HANDLER EXTI2_IRQHandler
178ISR_HANDLER EXTI3_IRQHandler
179ISR_HANDLER EXTI4_IRQHandler
180ISR_HANDLER DMA1_Stream0_IRQHandler
181ISR_HANDLER DMA1_Stream1_IRQHandler
182ISR_HANDLER DMA1_Stream2_IRQHandler
183ISR_HANDLER DMA1_Stream3_IRQHandler
184ISR_HANDLER DMA1_Stream4_IRQHandler
185ISR_HANDLER DMA1_Stream5_IRQHandler
186ISR_HANDLER DMA1_Stream6_IRQHandler
187ISR_HANDLER ADC_IRQHandler
188ISR_HANDLER CAN1_TX_IRQHandler
189ISR_HANDLER CAN1_RX0_IRQHandler
190ISR_HANDLER CAN1_RX1_IRQHandler
191ISR_HANDLER CAN1_SCE_IRQHandler
192ISR_HANDLER EXTI9_5_IRQHandler
193ISR_HANDLER TIM1_BRK_TIM9_IRQHandler
194ISR_HANDLER TIM1_UP_TIM10_IRQHandler
195ISR_HANDLER TIM1_TRG_COM_TIM11_IRQHandler
196ISR_HANDLER TIM1_CC_IRQHandler
197ISR_HANDLER TIM2_IRQHandler
198ISR_HANDLER TIM3_IRQHandler
199ISR_HANDLER TIM4_IRQHandler
200ISR_HANDLER I2C1_EV_IRQHandler
201ISR_HANDLER I2C1_ER_IRQHandler
202ISR_HANDLER I2C2_EV_IRQHandler
203ISR_HANDLER I2C2_ER_IRQHandler
204ISR_HANDLER SPI1_IRQHandler
205ISR_HANDLER SPI2_IRQHandler
206ISR_HANDLER USART1_IRQHandler
207ISR_HANDLER USART2_IRQHandler
208ISR_HANDLER USART3_IRQHandler
209ISR_HANDLER EXTI15_10_IRQHandler
210ISR_HANDLER RTC_Alarm_IRQHandler
211ISR_HANDLER OTG_FS_WKUP_IRQHandler
212ISR_HANDLER TIM8_BRK_TIM12_IRQHandler
213ISR_HANDLER TIM8_UP_TIM13_IRQHandler
214ISR_HANDLER TIM8_TRG_COM_TIM14_IRQHandler
215ISR_HANDLER TIM8_CC_IRQHandler
216ISR_HANDLER DMA1_Stream7_IRQHandler
217ISR_HANDLER FSMC_IRQHandler
218ISR_HANDLER SDIO_IRQHandler
219ISR_HANDLER TIM5_IRQHandler
220ISR_HANDLER SPI3_IRQHandler
221ISR_HANDLER UART4_IRQHandler
222ISR_HANDLER UART5_IRQHandler
223ISR_HANDLER TIM6_DAC_IRQHandler
224ISR_HANDLER TIM7_IRQHandler
225ISR_HANDLER DMA2_Stream0_IRQHandler
226ISR_HANDLER DMA2_Stream1_IRQHandler
227ISR_HANDLER DMA2_Stream2_IRQHandler
228ISR_HANDLER DMA2_Stream3_IRQHandler
229ISR_HANDLER DMA2_Stream4_IRQHandler
230ISR_HANDLER ETH_IRQHandler
231ISR_HANDLER ETH_WKUP_IRQHandler
232ISR_HANDLER CAN2_TX_IRQHandler
233ISR_HANDLER CAN2_RX0_IRQHandler
234ISR_HANDLER CAN2_RX1_IRQHandler
235ISR_HANDLER CAN2_SCE_IRQHandler
236ISR_HANDLER OTG_FS_IRQHandler
237ISR_HANDLER DMA2_Stream5_IRQHandler
238ISR_HANDLER DMA2_Stream6_IRQHandler
239ISR_HANDLER DMA2_Stream7_IRQHandler
240ISR_HANDLER USART6_IRQHandler
241ISR_HANDLER I2C3_EV_IRQHandler
242ISR_HANDLER I2C3_ER_IRQHandler
243ISR_HANDLER OTG_HS_EP1_OUT_IRQHandler
244ISR_HANDLER OTG_HS_EP1_IN_IRQHandler
245ISR_HANDLER OTG_HS_WKUP_IRQHandler
246ISR_HANDLER OTG_HS_IRQHandler
247ISR_HANDLER DCMI_IRQHandler
248ISR_HANDLER CRYP_IRQHandler
249ISR_HANDLER HASH_RNG_IRQHandler
250 .section .vectors, "ax"
251_vectors_end:
252
253
254 .section .vectors_ram, "ax"
255_vectors_ram:
256 .space _vectors_end-_vectors, 0
257#endif
258
259 .text
260 .thumb
261 .thumb_func
262 .align 2
263 .globl Reset_Handler
264 .type Reset_Handler, %function
265Reset_Handler:
266/* Loop to copy data from read only memory to RAM. The ranges
267 * of copy from/to are specified by following symbols evaluated in
268 * linker script.
269 * __etext: End of code section, i.e., begin of data sections to copy from.
270 * __data_start__/__data_end__: RAM address range that data should be
271 * copied to. Both must be aligned to 4 bytes boundary. */
272
273 ldr r1, =__etext
274 ldr r2, =__data_start__
275 ldr r3, =__data_end__
276
277 subs r3, r2
278 ble .LC1
279.LC0:
280 subs r3, #4
281 ldr r0, [r1, r3]
282 str r0, [r2, r3]
283 bgt .LC0
284.LC1:
285
286/* Loop to zero out BSS section, which uses following symbols
287 * in linker script:
288 * __bss_start__: start of BSS section. Must align to 4
289 * __bss_end__: end of BSS section. Must align to 4
290 */
291 ldr r1, =__bss_start__
292 ldr r2, =__bss_end__
293
294 movs r0, 0
295.LC2:
296 cmp r1, r2
297 itt lt
298 strlt r0, [r1], #4
299 blt .LC2
300
301 bl SystemInit
302
303 ldr r0, =__vectors_load_start__
304 ldr r1, =__vectors_load_end__
305 ldr r2, =_vectors_ram
306l0:
307 cmp r0, r1
308 beq l1
309 ldr r3, [r0]
310 str r3, [r2]
311 adds r0, r0, #4
312 adds r2, r2, #4
313 b l0
314l1:
315
316 /* Configure vector table offset register */
317 ldr r0, =0xE000ED08
318 ldr r1, =_vectors_ram
319 str r1, [r0]
320
321#ifndef __START
322#define __START _start
323#endif
324 bl __START
325 .pool
326 .size Reset_Handler, . - Reset_Handler