Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /* File: startup_armv6-m.S |
| 2 | * Purpose: startup file for armv6-m architecture devices. |
||
| 3 | * Should be used with GCC for ARM Embedded Processors |
||
| 4 | * Version: V2.00 |
||
| 5 | * Date: 16 November 2015 |
||
| 6 | * |
||
| 7 | */ |
||
| 8 | /* Copyright (c) 2011 - 2015 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 armv6-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 | .section .vectors |
||
| 72 | .align 2 |
||
| 73 | .globl __Vectors |
||
| 74 | __Vectors: |
||
| 75 | .long __StackTop /* Top of Stack */ |
||
| 76 | .long Reset_Handler /* Reset Handler */ |
||
| 77 | .long NMI_Handler /* NMI Handler */ |
||
| 78 | .long HardFault_Handler /* Hard Fault Handler */ |
||
| 79 | .long 0 /* Reserved */ |
||
| 80 | .long 0 /* Reserved */ |
||
| 81 | .long 0 /* Reserved */ |
||
| 82 | .long 0 /* Reserved */ |
||
| 83 | .long 0 /* Reserved */ |
||
| 84 | .long 0 /* Reserved */ |
||
| 85 | .long 0 /* Reserved */ |
||
| 86 | .long SVC_Handler /* SVCall Handler */ |
||
| 87 | .long 0 /* Reserved */ |
||
| 88 | .long 0 /* Reserved */ |
||
| 89 | .long PendSV_Handler /* PendSV Handler */ |
||
| 90 | .long SysTick_Handler /* SysTick Handler */ |
||
| 91 | |||
| 92 | .size __Vectors, . - __Vectors |
||
| 93 | |||
| 94 | .text |
||
| 95 | .thumb |
||
| 96 | .thumb_func |
||
| 97 | .align 1 |
||
| 98 | .globl Reset_Handler |
||
| 99 | .type Reset_Handler, %function |
||
| 100 | Reset_Handler: |
||
| 101 | /* Firstly it copies data from read only memory to RAM. There are two schemes |
||
| 102 | * to copy. One can copy more than one sections. Another can only copy |
||
| 103 | * one section. The former scheme needs more instructions and read-only |
||
| 104 | * data to implement than the latter. |
||
| 105 | * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */ |
||
| 106 | |||
| 107 | #ifdef __STARTUP_COPY_MULTIPLE |
||
| 108 | /* Multiple sections scheme. |
||
| 109 | * |
||
| 110 | * Between symbol address __copy_table_start__ and __copy_table_end__, |
||
| 111 | * there are array of triplets, each of which specify: |
||
| 112 | * offset 0: LMA of start of a section to copy from |
||
| 113 | * offset 4: VMA of start of a section to copy to |
||
| 114 | * offset 8: size of the section to copy. Must be multiply of 4 |
||
| 115 | * |
||
| 116 | * All addresses must be aligned to 4 bytes boundary. |
||
| 117 | */ |
||
| 118 | ldr r4, =__copy_table_start__ |
||
| 119 | ldr r5, =__copy_table_end__ |
||
| 120 | |||
| 121 | .L_loop0: |
||
| 122 | cmp r4, r5 |
||
| 123 | bge .L_loop0_done |
||
| 124 | ldr r1, [r4] |
||
| 125 | ldr r2, [r4, #4] |
||
| 126 | ldr r3, [r4, #8] |
||
| 127 | |||
| 128 | .L_loop0_0: |
||
| 129 | subs r3, #4 |
||
| 130 | blt .L_loop0_0_done |
||
| 131 | ldr r0, [r1, r3] |
||
| 132 | str r0, [r2, r3] |
||
| 133 | b .L_loop0_0 |
||
| 134 | |||
| 135 | .L_loop0_0_done: |
||
| 136 | adds r4, #12 |
||
| 137 | b .L_loop0 |
||
| 138 | |||
| 139 | .L_loop0_done: |
||
| 140 | #else |
||
| 141 | /* Single section scheme. |
||
| 142 | * |
||
| 143 | * The ranges of copy from/to are specified by following symbols |
||
| 144 | * __etext: LMA of start of the section to copy from. Usually end of text |
||
| 145 | * __data_start__: VMA of start of the section to copy to |
||
| 146 | * __data_end__: VMA of end of the section to copy to |
||
| 147 | * |
||
| 148 | * All addresses must be aligned to 4 bytes boundary. |
||
| 149 | */ |
||
| 150 | ldr r1, =__etext |
||
| 151 | ldr r2, =__data_start__ |
||
| 152 | ldr r3, =__data_end__ |
||
| 153 | |||
| 154 | subs r3, r2 |
||
| 155 | ble .L_loop1_done |
||
| 156 | |||
| 157 | .L_loop1: |
||
| 158 | subs r3, #4 |
||
| 159 | ldr r0, [r1,r3] |
||
| 160 | str r0, [r2,r3] |
||
| 161 | bgt .L_loop1 |
||
| 162 | |||
| 163 | .L_loop1_done: |
||
| 164 | #endif /*__STARTUP_COPY_MULTIPLE */ |
||
| 165 | |||
| 166 | /* This part of work usually is done in C library startup code. Otherwise, |
||
| 167 | * define this macro to enable it in this startup. |
||
| 168 | * |
||
| 169 | * There are two schemes too. One can clear multiple BSS sections. Another |
||
| 170 | * can only clear one section. The former is more size expensive than the |
||
| 171 | * latter. |
||
| 172 | * |
||
| 173 | * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former. |
||
| 174 | * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later. |
||
| 175 | */ |
||
| 176 | #ifdef __STARTUP_CLEAR_BSS_MULTIPLE |
||
| 177 | /* Multiple sections scheme. |
||
| 178 | * |
||
| 179 | * Between symbol address __copy_table_start__ and __copy_table_end__, |
||
| 180 | * there are array of tuples specifying: |
||
| 181 | * offset 0: Start of a BSS section |
||
| 182 | * offset 4: Size of this BSS section. Must be multiply of 4 |
||
| 183 | */ |
||
| 184 | ldr r3, =__zero_table_start__ |
||
| 185 | ldr r4, =__zero_table_end__ |
||
| 186 | |||
| 187 | .L_loop2: |
||
| 188 | cmp r3, r4 |
||
| 189 | bge .L_loop2_done |
||
| 190 | ldr r1, [r3] |
||
| 191 | ldr r2, [r3, #4] |
||
| 192 | movs r0, 0 |
||
| 193 | |||
| 194 | .L_loop2_0: |
||
| 195 | subs r2, #4 |
||
| 196 | blt .L_loop2_0_done |
||
| 197 | str r0, [r1, r2] |
||
| 198 | b .L_loop2_0 |
||
| 199 | .L_loop2_0_done: |
||
| 200 | |||
| 201 | adds r3, #8 |
||
| 202 | b .L_loop2 |
||
| 203 | .L_loop2_done: |
||
| 204 | #elif defined (__STARTUP_CLEAR_BSS) |
||
| 205 | /* Single BSS section scheme. |
||
| 206 | * |
||
| 207 | * The BSS section is specified by following symbols |
||
| 208 | * __bss_start__: start of the BSS section. |
||
| 209 | * __bss_end__: end of the BSS section. |
||
| 210 | * |
||
| 211 | * Both addresses must be aligned to 4 bytes boundary. |
||
| 212 | */ |
||
| 213 | ldr r1, =__bss_start__ |
||
| 214 | ldr r2, =__bss_end__ |
||
| 215 | |||
| 216 | movs r0, 0 |
||
| 217 | |||
| 218 | subs r2, r1 |
||
| 219 | ble .L_loop3_done |
||
| 220 | |||
| 221 | .L_loop3: |
||
| 222 | subs r2, #4 |
||
| 223 | str r0, [r1, r2] |
||
| 224 | bgt .L_loop3 |
||
| 225 | .L_loop3_done: |
||
| 226 | #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */ |
||
| 227 | |||
| 228 | #ifndef __NO_SYSTEM_INIT |
||
| 229 | bl SystemInit |
||
| 230 | #endif |
||
| 231 | |||
| 232 | #ifndef __START |
||
| 233 | #define __START _start |
||
| 234 | #endif |
||
| 235 | bl __START |
||
| 236 | |||
| 237 | .pool |
||
| 238 | .size Reset_Handler, . - Reset_Handler |
||
| 239 | |||
| 240 | .align 1 |
||
| 241 | .thumb_func |
||
| 242 | .weak Default_Handler |
||
| 243 | .type Default_Handler, %function |
||
| 244 | Default_Handler: |
||
| 245 | bkpt #0 |
||
| 246 | b . |
||
| 247 | .size Default_Handler, . - Default_Handler |
||
| 248 | |||
| 249 | /* Macro to define default handlers. Default handler |
||
| 250 | * will be weak symbol and just dead loops. They can be |
||
| 251 | * overwritten by other handlers */ |
||
| 252 | .macro def_irq_handler handler_name |
||
| 253 | .weak \handler_name |
||
| 254 | .set \handler_name, Default_Handler |
||
| 255 | .endm |
||
| 256 | |||
| 257 | def_irq_handler NMI_Handler |
||
| 258 | def_irq_handler HardFault_Handler |
||
| 259 | def_irq_handler SVC_Handler |
||
| 260 | def_irq_handler PendSV_Handler |
||
| 261 | def_irq_handler SysTick_Handler |
||
| 262 | |||
| 263 | .end |