source: rtems/c/src/lib/libbsp/arm/shared/start/start.S @ 3a7f588

4.115
Last change on this file since 3a7f588 was 3a7f588, checked in by Sebastian Huber <sebastian.huber@…>, on 01/14/14 at 08:43:53

bsps/arm: Use _ARMV4_Exception_interrupt

This allows read-only vector tables in ROM. It avoids also an unsolved
problem with MMU/cache synchronization on SMP.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Boot and system start code.
5 */
6
7/*
8 * Copyright (c) 2008-2014 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 bsp_stack_irq_end
35        .extern bsp_stack_fiq_end
36        .extern bsp_stack_abt_end
37        .extern bsp_stack_und_end
38        .extern bsp_stack_svc_end
39#ifdef RTEMS_SMP
40        .extern bsp_stack_all_size
41#endif
42        .extern _ARMV4_Exception_undef_default
43        .extern _ARMV4_Exception_swi_default
44        .extern _ARMV4_Exception_data_abort_default
45        .extern _ARMV4_Exception_pref_abort_default
46        .extern _ARMV4_Exception_reserved_default
47        .extern _ARMV4_Exception_interrupt
48        .extern _ARMV4_Exception_fiq_default
49        .extern _ARMV7M_Exception_default
50
51        /* Global symbols */
52        .globl  _start
53        .globl  bsp_start_vector_table_begin
54        .globl  bsp_start_vector_table_end
55        .globl  bsp_start_vector_table_size
56        .globl  bsp_vector_table_size
57
58        .section        ".bsp_start_text", "ax"
59
60#if defined(ARM_MULTILIB_ARCH_V4)
61
62        .arm
63
64/*
65 * This is the exception vector table and the pointers to the default
66 * exceptions handlers.
67 */
68
69bsp_start_vector_table_begin:
70
71        ldr     pc, handler_addr_reset
72        ldr     pc, handler_addr_undef
73        ldr     pc, handler_addr_swi
74        ldr     pc, handler_addr_prefetch
75        ldr     pc, handler_addr_abort
76
77        /* Program signature checked by boot loader */
78        .word   0xb8a06f58
79
80        ldr     pc, handler_addr_irq
81        ldr     pc, handler_addr_fiq
82
83handler_addr_reset:
84
85#ifdef BSP_START_RESET_VECTOR
86        .word   BSP_START_RESET_VECTOR
87#else
88        .word   _start
89#endif
90
91handler_addr_undef:
92
93        .word   _ARMV4_Exception_undef_default
94
95handler_addr_swi:
96
97        .word   _ARMV4_Exception_swi_default
98
99handler_addr_prefetch:
100
101        .word   _ARMV4_Exception_pref_abort_default
102
103handler_addr_abort:
104
105        .word   _ARMV4_Exception_data_abort_default
106
107handler_addr_reserved:
108
109        .word   _ARMV4_Exception_reserved_default
110
111handler_addr_irq:
112
113        .word   _ARMV4_Exception_interrupt
114
115handler_addr_fiq:
116
117        .word   _ARMV4_Exception_fiq_default
118
119bsp_start_vector_table_end:
120
121/* Start entry */
122
123_start:
124
125        /*
126         * We do not save the context since we do not return to the boot
127         * loader.
128         */
129
130#ifdef RTEMS_SMP
131        /* Read MPIDR */
132        mrc     p15, 0, r0, c0, c0, 5
133
134        /* Calculate stack offset */
135        and     r0, #0xff
136        ldr     r1, =bsp_stack_all_size
137        mul     r1, r0
138#endif
139
140        /*
141         * Set SVC mode, disable interrupts and enable ARM instructions.
142         */
143        mov     r0, #(ARM_PSR_M_SVC | ARM_PSR_I | ARM_PSR_F)
144        msr     cpsr, r0
145
146        /* Initialize stack pointer registers for the various modes */
147
148        /* Enter IRQ mode and set up the IRQ stack pointer */
149        mov     r0, #(ARM_PSR_M_IRQ | ARM_PSR_I | ARM_PSR_F)
150        msr     cpsr, r0
151        ldr     sp, =bsp_stack_irq_end
152#ifdef RTEMS_SMP
153        add     sp, r1
154#endif
155
156        /* Enter FIQ mode and set up the FIQ stack pointer */
157        mov     r0, #(ARM_PSR_M_FIQ | ARM_PSR_I | ARM_PSR_F)
158        msr     cpsr, r0
159        ldr     sp, =bsp_stack_fiq_end
160#ifdef RTEMS_SMP
161        add     sp, r1
162#endif
163
164        /* Enter ABT mode and set up the ABT stack pointer */
165        mov     r0, #(ARM_PSR_M_ABT | ARM_PSR_I | ARM_PSR_F)
166        msr     cpsr, r0
167        ldr     sp, =bsp_stack_abt_end
168#ifdef RTEMS_SMP
169        add     sp, r1
170#endif
171
172        /* Enter UND mode and set up the UND stack pointer */
173        mov     r0, #(ARM_PSR_M_UND | ARM_PSR_I | ARM_PSR_F)
174        msr     cpsr, r0
175        ldr     sp, =bsp_stack_und_end
176#ifdef RTEMS_SMP
177        add     sp, r1
178#endif
179
180        /* Enter SVC mode and set up the SVC stack pointer */
181        mov     r0, #(ARM_PSR_M_SVC | ARM_PSR_I | ARM_PSR_F)
182        msr     cpsr, r0
183        ldr     sp, =bsp_stack_svc_end
184#ifdef RTEMS_SMP
185        add     sp, r1
186#endif
187
188        /* Stay in SVC mode */
189
190#ifdef ARM_MULTILIB_VFP_D32
191        /* Read CPACR */
192        mrc p15, 0, r0, c1, c0, 2
193
194        /* Enable CP10 and CP11 */
195        orr r0, r0, #(1 << 20)
196        orr r0, r0, #(1 << 22)
197
198        /* Clear ASEDIS and D32DIS */
199        bic r0, r0, #(3 << 30)
200
201        /* Write CPACR */
202        mcr p15, 0, r0, c1, c0, 2
203        isb
204
205        /* Enable FPU */
206        mov r0, #(1 << 30)
207        vmsr FPEXC, r0
208#endif
209
210        /*
211         * Branch to start hook 0.
212         *
213         * The previous code and parts of the start hook 0 may run with an
214         * address offset.  This implies that only branches relative to the
215         * program counter are allowed.  After the start hook 0 it is assumed
216         * that the code can run at its intended position.  Thus the link
217         * register will be loaded with the absolute address.  In THUMB mode
218         * the start hook 0 must be within a 2kByte range due to the branch
219         * instruction limitation.
220         */
221
222        ldr     lr, =bsp_start_hook_0_done
223#ifdef __thumb__
224        orr     lr, #1
225#endif
226
227        SWITCH_FROM_ARM_TO_THUMB        r0
228
229        b       bsp_start_hook_0
230
231bsp_start_hook_0_done:
232
233        SWITCH_FROM_THUMB_TO_ARM
234
235        /*
236         * Initialize the exception vectors.  This includes the exceptions
237         * vectors and the pointers to the default exception handlers.
238         */
239
240        ldr     r0, =bsp_vector_table_begin
241        adr     r1, bsp_start_vector_table_begin
242        cmp     r0, r1
243        beq     bsp_vector_table_copy_done
244        ldmia   r1!, {r2-r9}
245        stmia   r0!, {r2-r9}
246        ldmia   r1!, {r2-r9}
247        stmia   r0!, {r2-r9}
248
249bsp_vector_table_copy_done:
250
251        SWITCH_FROM_ARM_TO_THUMB        r0
252
253        /* Branch to start hook 1 */
254        bl      bsp_start_hook_1
255
256        /* Branch to boot card */
257        mov     r0, #0
258        bl      boot_card
259
260twiddle:
261
262        /* Branch to reset function */
263        bl      bsp_reset
264
265        b       twiddle
266
267#elif defined(ARM_MULTILIB_ARCH_V7M)
268
269        .syntax unified
270
271        .extern bsp_stack_main_end
272
273        .thumb
274
275bsp_start_vector_table_begin:
276
277        .word   bsp_stack_main_end
278        .word   _start /* Reset */
279        .word   _ARMV7M_Exception_default /* NMI */
280        .word   _ARMV7M_Exception_default /* Hard Fault */
281        .word   _ARMV7M_Exception_default /* MPU Fault */
282        .word   _ARMV7M_Exception_default /* Bus Fault */
283        .word   _ARMV7M_Exception_default /* Usage Fault */
284        .word   _ARMV7M_Exception_default /* Reserved */
285        .word   _ARMV7M_Exception_default /* Reserved */
286        .word   _ARMV7M_Exception_default /* Reserved */
287        .word   _ARMV7M_Exception_default /* Reserved */
288        .word   _ARMV7M_Exception_default /* SVC */
289        .word   _ARMV7M_Exception_default /* Debug Monitor */
290        .word   _ARMV7M_Exception_default /* Reserved */
291        .word   _ARMV7M_Exception_default /* PendSV */
292        .word   _ARMV7M_Exception_default /* SysTick */
293        .rept   BSP_INTERRUPT_VECTOR_MAX + 1
294        .word   _ARMV7M_Exception_default /* IRQ */
295        .endr
296
297bsp_start_vector_table_end:
298
299        .thumb_func
300
301_start:
302
303        ldr     sp, =bsp_stack_main_end
304        ldr     lr, =bsp_start_hook_0_done + 1
305        b       bsp_start_hook_0
306
307bsp_start_hook_0_done:
308
309        bl      bsp_start_hook_1
310        movs    r0, #0
311        bl      boot_card
312
313twiddle:
314
315        bl      bsp_reset
316        b       twiddle
317
318#endif /* defined(ARM_MULTILIB_ARCH_V7M) */
319
320        .set    bsp_start_vector_table_size, bsp_start_vector_table_end - bsp_start_vector_table_begin
321        .set    bsp_vector_table_size, bsp_start_vector_table_size
Note: See TracBrowser for help on using the repository browser.