source: rtems/c/src/lib/libbsp/arm/shared/start/start.S @ 04f399d

4.115
Last change on this file since 04f399d was 04f399d, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 7, 2013 at 9:19:23 AM

arm: Add and use _ARMV7M_Exception_default()

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Boot and system start code.
5 */
6
7/*
8 * Copyright (c) 2008-2013 embedded brains GmbH.  All rights reserved.
9 *
10 *  embedded brains GmbH
11 *  Obere Lagerstr. 30
12 *  82178 Puchheim
13 *  Germany
14 *  <rtems@embedded-brains.de>
15 *
16 * The license and distribution terms for this file may be
17 * found in the file LICENSE in this distribution or at
18 * http://www.rtems.com/license/LICENSE.
19 */
20
21#include <rtems/asm.h>
22#include <rtems/system.h>       
23#include <rtems/score/cpu.h>
24       
25#include <bspopts.h>
26#include <bsp/irq.h>
27#include <bsp/linker-symbols.h>
28
29        /* External symbols */
30        .extern bsp_reset
31        .extern boot_card
32        .extern bsp_start_hook_0
33        .extern bsp_start_hook_1
34        .extern _ARMV4_Exception_undef_default
35        .extern _ARMV4_Exception_swi_default
36        .extern _ARMV4_Exception_data_abort_default
37        .extern _ARMV4_Exception_pref_abort_default
38        .extern _ARMV4_Exception_reserved_default
39        .extern _ARMV4_Exception_irq_default
40        .extern _ARMV4_Exception_fiq_default
41        .extern _ARMV7M_Exception_default
42
43        /* Global symbols */
44        .globl  _start
45        .globl  bsp_start_vector_table_begin
46        .globl  bsp_start_vector_table_end
47        .globl  bsp_start_vector_table_size
48        .globl  bsp_vector_table_size
49
50        .section        ".bsp_start_text", "ax"
51
52#if defined(ARM_MULTILIB_ARCH_V4)
53
54        .arm
55
56/*
57 * This is the exception vector table and the pointers to the default
58 * exceptions handlers.
59 */
60
61bsp_start_vector_table_begin:
62
63        ldr     pc, handler_addr_reset
64        ldr     pc, handler_addr_undef
65        ldr     pc, handler_addr_swi
66        ldr     pc, handler_addr_prefetch
67        ldr     pc, handler_addr_abort
68
69        /* Program signature checked by boot loader */
70        .word   0xb8a06f58
71
72        ldr     pc, handler_addr_irq
73        ldr     pc, handler_addr_fiq
74
75handler_addr_reset:
76
77#ifdef BSP_START_RESET_VECTOR
78        .word   BSP_START_RESET_VECTOR
79#else
80        .word   _start
81#endif
82
83handler_addr_undef:
84
85        .word   _ARMV4_Exception_undef_default
86
87handler_addr_swi:
88
89        .word   _ARMV4_Exception_swi_default
90
91handler_addr_prefetch:
92
93        .word   _ARMV4_Exception_data_abort_default
94
95handler_addr_abort:
96
97        .word   _ARMV4_Exception_pref_abort_default
98
99handler_addr_reserved:
100
101        .word   _ARMV4_Exception_reserved_default
102
103handler_addr_irq:
104
105        .word   _ARMV4_Exception_irq_default
106
107handler_addr_fiq:
108
109        .word   _ARMV4_Exception_fiq_default
110
111bsp_start_vector_table_end:
112
113/* Start entry */
114
115_start:
116
117        /*
118         * We do not save the context since we do not return to the boot
119         * loader.
120         */
121
122        /*
123         * Set SVC mode, disable interrupts and enable ARM instructions.
124         */
125        mov     r0, #(ARM_PSR_M_SVC | ARM_PSR_I | ARM_PSR_F)
126        msr     cpsr, r0
127
128        /* Initialize stack pointer registers for the various modes */
129
130        /* Enter IRQ mode and set up the IRQ stack pointer */
131        mov     r0, #(ARM_PSR_M_IRQ | ARM_PSR_I | ARM_PSR_F)
132        msr     cpsr, r0
133        ldr     sp, =bsp_stack_irq_end
134
135        /* Enter FIQ mode and set up the FIQ stack pointer */
136        mov     r0, #(ARM_PSR_M_FIQ | ARM_PSR_I | ARM_PSR_F)
137        msr     cpsr, r0
138        ldr     sp, =bsp_stack_fiq_end
139
140        /* Enter ABT mode and set up the ABT stack pointer */
141        mov     r0, #(ARM_PSR_M_ABT | ARM_PSR_I | ARM_PSR_F)
142        msr     cpsr, r0
143        ldr     sp, =bsp_stack_abt_end
144
145        /* Enter UND mode and set up the UND stack pointer */
146        mov     r0, #(ARM_PSR_M_UND | ARM_PSR_I | ARM_PSR_F)
147        msr     cpsr, r0
148        ldr     sp, =bsp_stack_und_end
149
150        /* Enter SVC mode and set up the SVC stack pointer */
151        mov     r0, #(ARM_PSR_M_SVC | ARM_PSR_I | ARM_PSR_F)
152        msr     cpsr, r0
153        ldr     sp, =bsp_stack_svc_end
154
155        /* Stay in SVC mode */
156
157        /*
158         * Branch to start hook 0.
159         *
160         * The previous code and parts of the start hook 0 may run with an
161         * address offset.  This implies that only branches relative to the
162         * program counter are allowed.  After the start hook 0 it is assumed
163         * that the code can run at its intended position.  Thus the link
164         * register will be loaded with the absolute address.  In THUMB mode
165         * the start hook 0 must be within a 2kByte range due to the branch
166         * instruction limitation.
167         */
168
169        ldr     lr, =bsp_start_hook_0_done
170#ifdef __thumb__
171        orr     lr, #1
172#endif
173
174        SWITCH_FROM_ARM_TO_THUMB        r0
175
176        b       bsp_start_hook_0
177
178bsp_start_hook_0_done:
179
180        SWITCH_FROM_THUMB_TO_ARM
181
182        /*
183         * Initialize the exception vectors.  This includes the exceptions
184         * vectors and the pointers to the default exception handlers.
185         */
186
187        ldr     r0, =bsp_vector_table_begin
188        adr     r1, bsp_start_vector_table_begin
189        ldmia   r1!, {r2-r9}
190        stmia   r0!, {r2-r9}
191        ldmia   r1!, {r2-r9}
192        stmia   r0!, {r2-r9}
193
194        SWITCH_FROM_ARM_TO_THUMB        r0
195
196        /* Branch to start hook 1 */
197        bl      bsp_start_hook_1
198
199        /* Branch to boot card */
200        mov     r0, #0
201        bl      boot_card
202
203twiddle:
204
205        /* Branch to reset function */
206        bl      bsp_reset
207
208        b       twiddle
209
210#elif defined(ARM_MULTILIB_ARCH_V7M)
211
212        .syntax unified
213
214        .extern bsp_stack_main_end
215
216        .thumb
217
218bsp_start_vector_table_begin:
219
220        .word   bsp_stack_main_end
221        .word   _start /* Reset */
222        .word   _ARMV7M_Exception_default /* NMI */
223        .word   _ARMV7M_Exception_default /* Hard Fault */
224        .word   _ARMV7M_Exception_default /* MPU Fault */
225        .word   _ARMV7M_Exception_default /* Bus Fault */
226        .word   _ARMV7M_Exception_default /* Usage Fault */
227        .word   _ARMV7M_Exception_default /* Reserved */
228        .word   _ARMV7M_Exception_default /* Reserved */
229        .word   _ARMV7M_Exception_default /* Reserved */
230        .word   _ARMV7M_Exception_default /* Reserved */
231        .word   _ARMV7M_Exception_default /* SVC */
232        .word   _ARMV7M_Exception_default /* Debug Monitor */
233        .word   _ARMV7M_Exception_default /* Reserved */
234        .word   _ARMV7M_Exception_default /* PendSV */
235        .word   _ARMV7M_Exception_default /* SysTick */
236        .rept   BSP_INTERRUPT_VECTOR_MAX + 1
237        .word   _ARMV7M_Exception_default /* IRQ */
238        .endr
239
240bsp_start_vector_table_end:
241
242        .thumb_func
243
244_start:
245
246        ldr     sp, =bsp_stack_main_end
247        ldr     lr, =bsp_start_hook_0_done + 1
248        b       bsp_start_hook_0
249
250bsp_start_hook_0_done:
251
252        bl      bsp_start_hook_1
253        movs    r0, #0
254        bl      boot_card
255
256twiddle:
257
258        bl      bsp_reset
259        b       twiddle
260
261#endif /* defined(ARM_MULTILIB_ARCH_V7M) */
262
263        .set    bsp_start_vector_table_size, bsp_start_vector_table_end - bsp_start_vector_table_begin
264        .set    bsp_vector_table_size, bsp_start_vector_table_size
Note: See TracBrowser for help on using the repository browser.