]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/GCC_Specific/startup_ARMCM4.S
fb2af495a98742c831c9d8cc388a1b730adc8791
[freertos] / FreeRTOS / Demo / CORTEX_MPU_Simulator_Keil_GCC / GCC_Specific / startup_ARMCM4.S
1 /* File: startup_ARMCM4.S
2  * Purpose: startup file for Cortex-M4 devices. Should use with
3  *   GCC for ARM Embedded Processors
4  * Version: V2.0
5  * Date: 16 August 2013
6  *
7 /* Copyright (c) 2011 - 2013 ARM LIMITED
8
9    All rights reserved.
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.
20    *
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    ---------------------------------------------------------------------------*/
33         .syntax unified
34         .arch   armv7e-m
35
36         .extern __SRAM_segment_end__
37
38         .section .isr_vector
39         .align  4
40         .globl  __isr_vector
41 __isr_vector:
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 */
58
59         /* External interrupts */
60         .long   DummyHandler
61         .long   DummyHandler
62         .long   DummyHandler
63         .long   DummyHandler
64         .long   DummyHandler
65         .long   DummyHandler
66         .long   DummyHandler
67         .long   DummyHandler
68         .long   DummyHandler
69         .long   DummyHandler
70         .long   DummyHandler
71         .long   DummyHandler
72         .long   DummyHandler
73         .long   DummyHandler
74         .long   DummyHandler
75         .long   DummyHandler
76         .long   DummyHandler
77         .long   DummyHandler
78         .long   DummyHandler
79         .long   DummyHandler
80         .long   DummyHandler
81         .long   DummyHandler
82         .long   DummyHandler
83         .long   DummyHandler
84         .long   DummyHandler
85         .long   DummyHandler
86         .long   DummyHandler
87         .long   DummyHandler
88         .long   DummyHandler
89         .long   DummyHandler
90         .long   DummyHandler
91         .long   DummyHandler
92         .long   DummyHandler
93         .long   DummyHandler
94         .long   DummyHandler
95         .long   DummyHandler
96         .long   DummyHandler
97         .long   DummyHandler
98         .long   DummyHandler
99         .long   DummyHandler
100         .long   DummyHandler
101         .long   DummyHandler
102         .long   DummyHandler
103         .long   DummyHandler
104         .long   DummyHandler
105         .long   DummyHandler
106         .long   DummyHandler
107         .long   DummyHandler
108         .long   DummyHandler
109         .long   DummyHandler
110         .long   DummyHandler
111         .long   DummyHandler
112
113
114         .text
115         .thumb
116         .thumb_func
117         .align  2
118         .globl _start
119         .extern main
120         .globl  Reset_Handler
121         .type   Reset_Handler, %function
122 _start:
123 Reset_Handler:
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.  */
129
130 /*  Single section scheme.
131  *
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
136  *
137  *  All addresses must be aligned to 4 bytes boundary.
138  */
139         ldr     r1, =__etext
140         ldr     r2, =__data_start__
141         ldr     r3, =__data_end__
142
143 .L_loop1:
144         cmp     r2, r3
145         ittt    lt
146         ldrlt   r0, [r1], #4
147         strlt   r0, [r2], #4
148         blt     .L_loop1
149
150 /*  This part of work usually is done in C library startup code. Otherwise,
151  *  define this macro to enable it in this startup.
152  *
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
155  *  latter.
156  *
157  *  Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
158  *  Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
159  */
160
161  /*  Single BSS section scheme.
162  *
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.
166  *
167  *  Both addresses must be aligned to 4 bytes boundary.
168  */
169         ldr     r1, =__bss_start__
170         ldr     r2, =__bss_end__
171
172         movs    r0, 0
173 .L_loop3:
174         cmp     r1, r2
175         itt     lt
176         strlt   r0, [r1], #4
177         blt     .L_loop3
178
179 #ifndef __NO_SYSTEM_INIT
180 /*      bl      SystemInit */
181 #endif
182
183         bl      main
184
185         .pool
186         .size   Reset_Handler, . - Reset_Handler
187
188         .align  1
189         .thumb_func
190         .weak   Default_Handler
191         .type   Default_Handler, %function
192 Default_Handler:
193         b       .
194         .size   Default_Handler, . - Default_Handler
195
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
200         .weak   \handler_name
201         .set    \handler_name, Default_Handler
202         .endm
203
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
215
216
217         .end