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 01/07/13 at 09:19:23

arm: Add and use _ARMV7M_Exception_default()

  • Property mode set to 100644
File size: 5.7 KB
RevLine 
[8dcfc0a]1/**
2 * @file
3 *
4 * @brief Boot and system start code.
5 */
6
7/*
[13cf952]8 * Copyright (c) 2008-2013 embedded brains GmbH.  All rights reserved.
[8dcfc0a]9 *
[4c622e5]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.
[8dcfc0a]19 */
[091705c]20
21#include <rtems/asm.h>
[c193baad]22#include <rtems/system.h>       
[39c8fdb]23#include <rtems/score/cpu.h>
[c193baad]24       
[091705c]25#include <bspopts.h>
[4c622e5]26#include <bsp/irq.h>
[8dcfc0a]27#include <bsp/linker-symbols.h>
28
[4c622e5]29        /* External symbols */
30        .extern bsp_reset
31        .extern boot_card
32        .extern bsp_start_hook_0
33        .extern bsp_start_hook_1
[13cf952]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
[04f399d]41        .extern _ARMV7M_Exception_default
[8dcfc0a]42
[4c622e5]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
[8dcfc0a]49
[4c622e5]50        .section        ".bsp_start_text", "ax"
[8dcfc0a]51
[4c622e5]52#if defined(ARM_MULTILIB_ARCH_V4)
[091705c]53
[4c622e5]54        .arm
[9647f7fe]55
56/*
57 * This is the exception vector table and the pointers to the default
58 * exceptions handlers.
59 */
60
[4c622e5]61bsp_start_vector_table_begin:
[9647f7fe]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
[091705c]77#ifdef BSP_START_RESET_VECTOR
78        .word   BSP_START_RESET_VECTOR
79#else
[a3579d3b]80        .word   _start
[091705c]81#endif
[9647f7fe]82
83handler_addr_undef:
84
[13cf952]85        .word   _ARMV4_Exception_undef_default
[9647f7fe]86
87handler_addr_swi:
88
[13cf952]89        .word   _ARMV4_Exception_swi_default
[9647f7fe]90
91handler_addr_prefetch:
92
[13cf952]93        .word   _ARMV4_Exception_data_abort_default
[9647f7fe]94
95handler_addr_abort:
96
[13cf952]97        .word   _ARMV4_Exception_pref_abort_default
[9647f7fe]98
99handler_addr_reserved:
100
[13cf952]101        .word   _ARMV4_Exception_reserved_default
[9647f7fe]102
103handler_addr_irq:
104
[13cf952]105        .word   _ARMV4_Exception_irq_default
[9647f7fe]106
107handler_addr_fiq:
108
[13cf952]109        .word   _ARMV4_Exception_fiq_default
[9647f7fe]110
[4c622e5]111bsp_start_vector_table_end:
112
[8dcfc0a]113/* Start entry */
114
[a3579d3b]115_start:
[8dcfc0a]116
[091705c]117        /*
118         * We do not save the context since we do not return to the boot
119         * loader.
120         */
[8dcfc0a]121
[091705c]122        /*
123         * Set SVC mode, disable interrupts and enable ARM instructions.
124         */
[39c8fdb]125        mov     r0, #(ARM_PSR_M_SVC | ARM_PSR_I | ARM_PSR_F)
[8dcfc0a]126        msr     cpsr, r0
127
[091705c]128        /* Initialize stack pointer registers for the various modes */
[8dcfc0a]129
[091705c]130        /* Enter IRQ mode and set up the IRQ stack pointer */
[39c8fdb]131        mov     r0, #(ARM_PSR_M_IRQ | ARM_PSR_I | ARM_PSR_F)
[8dcfc0a]132        msr     cpsr, r0
[7ae2775]133        ldr     sp, =bsp_stack_irq_end
[8dcfc0a]134
[091705c]135        /* Enter FIQ mode and set up the FIQ stack pointer */
[39c8fdb]136        mov     r0, #(ARM_PSR_M_FIQ | ARM_PSR_I | ARM_PSR_F)
[8dcfc0a]137        msr     cpsr, r0
[7ae2775]138        ldr     sp, =bsp_stack_fiq_end
[8dcfc0a]139
[091705c]140        /* Enter ABT mode and set up the ABT stack pointer */
[39c8fdb]141        mov     r0, #(ARM_PSR_M_ABT | ARM_PSR_I | ARM_PSR_F)
[8dcfc0a]142        msr     cpsr, r0
[7ae2775]143        ldr     sp, =bsp_stack_abt_end
[8dcfc0a]144
[39c8fdb]145        /* Enter UND mode and set up the UND stack pointer */
146        mov     r0, #(ARM_PSR_M_UND | ARM_PSR_I | ARM_PSR_F)
[8dcfc0a]147        msr     cpsr, r0
[39c8fdb]148        ldr     sp, =bsp_stack_und_end
[8dcfc0a]149
[091705c]150        /* Enter SVC mode and set up the SVC stack pointer */
[39c8fdb]151        mov     r0, #(ARM_PSR_M_SVC | ARM_PSR_I | ARM_PSR_F)
[8dcfc0a]152        msr     cpsr, r0
[7ae2775]153        ldr     sp, =bsp_stack_svc_end
[8dcfc0a]154
[091705c]155        /* Stay in SVC mode */
[8dcfc0a]156
[091705c]157        /*
158         * Branch to start hook 0.
159         *
[7a6f8d0]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.
[091705c]167         */
168
169        ldr     lr, =bsp_start_hook_0_done
[7a6f8d0]170#ifdef __thumb__
171        orr     lr, #1
172#endif
173
174        SWITCH_FROM_ARM_TO_THUMB        r0
175
[091705c]176        b       bsp_start_hook_0
[8dcfc0a]177
[091705c]178bsp_start_hook_0_done:
179
[7a6f8d0]180        SWITCH_FROM_THUMB_TO_ARM
181
[091705c]182        /*
[8dcfc0a]183         * Initialize the exception vectors.  This includes the exceptions
184         * vectors and the pointers to the default exception handlers.
[091705c]185         */
[8dcfc0a]186
[c5d8d2dc]187        ldr     r0, =bsp_vector_table_begin
[4c622e5]188        adr     r1, bsp_start_vector_table_begin
[8dcfc0a]189        ldmia   r1!, {r2-r9}
190        stmia   r0!, {r2-r9}
191        ldmia   r1!, {r2-r9}
192        stmia   r0!, {r2-r9}
193
[7a6f8d0]194        SWITCH_FROM_ARM_TO_THUMB        r0
195
[091705c]196        /* Branch to start hook 1 */
[8dcfc0a]197        bl      bsp_start_hook_1
198
[091705c]199        /* Branch to boot card */
[7ae2775]200        mov     r0, #0
[8dcfc0a]201        bl      boot_card
202
[305234f7]203twiddle:
204
[091705c]205        /* Branch to reset function */
[8dcfc0a]206        bl      bsp_reset
[39c8fdb]207
[305234f7]208        b       twiddle
[8dcfc0a]209
[4c622e5]210#elif defined(ARM_MULTILIB_ARCH_V7M)
[091705c]211
[4c622e5]212        .syntax unified
[091705c]213
[4c622e5]214        .extern bsp_stack_main_end
[091705c]215
[4c622e5]216        .thumb
[091705c]217
[4c622e5]218bsp_start_vector_table_begin:
[091705c]219
[4c622e5]220        .word   bsp_stack_main_end
221        .word   _start /* Reset */
[04f399d]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 */
[4c622e5]236        .rept   BSP_INTERRUPT_VECTOR_MAX + 1
[04f399d]237        .word   _ARMV7M_Exception_default /* IRQ */
[4c622e5]238        .endr
[091705c]239
[4c622e5]240bsp_start_vector_table_end:
[091705c]241
[4c622e5]242        .thumb_func
[091705c]243
[4c622e5]244_start:
[091705c]245
[4c622e5]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.