1 /* File: startup_ARMCM4.S
2 * Purpose: startup file for Cortex-M4 devices. Should use with
3 * GCC for ARM Embedded Processors
7 /* Copyright (c) 2011 - 2013 ARM LIMITED
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 ARM nor the names of its contributors may be used
18 to endorse or promote products derived from this software without
19 specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
32 ---------------------------------------------------------------------------*/
36 .extern __SRAM_segment_end__
42 .long __SRAM_segment_end__ - 4 /* Top of Stack at top of RAM*/
43 .long Reset_Handler /* Reset Handler */
44 .long NMI_Handler /* NMI Handler */
45 .long HardFault_Handler /* Hard Fault Handler */
46 .long MemManage_Handler /* MPU Fault Handler */
47 .long BusFault_Handler /* Bus Fault Handler */
48 .long UsageFault_Handler /* Usage Fault Handler */
49 .long 0 /* Reserved */
50 .long 0 /* Reserved */
51 .long 0 /* Reserved */
52 .long 0 /* Reserved */
53 .long SVC_Handler /* SVCall Handler */
54 .long DebugMon_Handler /* Debug Monitor Handler */
55 .long 0 /* Reserved */
56 .long PendSV_Handler /* PendSV Handler */
57 .long SysTick_Handler /* SysTick Handler */
59 /* External interrupts */
121 .type Reset_Handler, %function
124 /* Firstly it copies data from read only memory to RAM. There are two schemes
125 * to copy. One can copy more than one sections. Another can only copy
126 * one section. The former scheme needs more instructions and read-only
127 * data to implement than the latter.
128 * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
130 /* Single section scheme.
132 * The ranges of copy from/to are specified by following symbols
133 * __etext: LMA of start of the section to copy from. Usually end of text
134 * __data_start__: VMA of start of the section to copy to
135 * __data_end__: VMA of end of the section to copy to
137 * All addresses must be aligned to 4 bytes boundary.
140 ldr r2, =__data_start__
141 ldr r3, =__data_end__
150 /* This part of work usually is done in C library startup code. Otherwise,
151 * define this macro to enable it in this startup.
153 * There are two schemes too. One can clear multiple BSS sections. Another
154 * can only clear one section. The former is more size expensive than the
157 * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
158 * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
161 /* Single BSS section scheme.
163 * The BSS section is specified by following symbols
164 * __bss_start__: start of the BSS section.
165 * __bss_end__: end of the BSS section.
167 * Both addresses must be aligned to 4 bytes boundary.
169 ldr r1, =__bss_start__
179 #ifndef __NO_SYSTEM_INIT
186 .size Reset_Handler, . - Reset_Handler
190 .weak Default_Handler
191 .type Default_Handler, %function
194 .size Default_Handler, . - Default_Handler
196 /* Macro to define default handlers. Default handler
197 * will be weak symbol and just dead loops. They can be
198 * overwritten by other handlers */
199 .macro def_irq_handler handler_name
201 .set \handler_name, Default_Handler
204 def_irq_handler NMI_Handler
205 def_irq_handler HardFault_Handler
206 def_irq_handler MemManage_Handler
207 def_irq_handler BusFault_Handler
208 def_irq_handler UsageFault_Handler
209 def_irq_handler SVC_Handler
210 def_irq_handler DebugMon_Handler
211 def_irq_handler PendSV_Handler
212 def_irq_handler SysTick_Handler
213 def_irq_handler DEF_IRQHandler
214 def_irq_handler DummyHandler