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

4.115
Last change on this file since cfd8d7a was cfd8d7a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/08/13 at 07:30:31

arm: Support VFP-D32 and Neon

  • Property mode set to 100644
File size: 6.1 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
[cfd8d7a]157#ifdef ARM_MULTILIB_VFP_D32
158        /* Read CPACR */
159        mrc p15, 0, r0, c1, c0, 2
160
161        /* Enable CP10 and CP11 */
162        orr r0, r0, #(1 << 20)
163        orr r0, r0, #(1 << 22)
164
165        /* Clear ASEDIS and D32DIS */
166        bic r0, r0, #(3 << 30)
167
168        /* Write CPACR */
169        mcr p15, 0, r0, c1, c0, 2
170        isb
171
172        /* Enable FPU */
173        mov r0, #(1 << 30)
174        vmsr FPEXC, r0
175#endif
176
[091705c]177        /*
178         * Branch to start hook 0.
179         *
[7a6f8d0]180         * The previous code and parts of the start hook 0 may run with an
181         * address offset.  This implies that only branches relative to the
182         * program counter are allowed.  After the start hook 0 it is assumed
183         * that the code can run at its intended position.  Thus the link
184         * register will be loaded with the absolute address.  In THUMB mode
185         * the start hook 0 must be within a 2kByte range due to the branch
186         * instruction limitation.
[091705c]187         */
188
189        ldr     lr, =bsp_start_hook_0_done
[7a6f8d0]190#ifdef __thumb__
191        orr     lr, #1
192#endif
193
194        SWITCH_FROM_ARM_TO_THUMB        r0
195
[091705c]196        b       bsp_start_hook_0
[8dcfc0a]197
[091705c]198bsp_start_hook_0_done:
199
[7a6f8d0]200        SWITCH_FROM_THUMB_TO_ARM
201
[091705c]202        /*
[8dcfc0a]203         * Initialize the exception vectors.  This includes the exceptions
204         * vectors and the pointers to the default exception handlers.
[091705c]205         */
[8dcfc0a]206
[c5d8d2dc]207        ldr     r0, =bsp_vector_table_begin
[4c622e5]208        adr     r1, bsp_start_vector_table_begin
[9ce65803]209        cmp     r0, r1
210        beq     bsp_vector_table_copy_done
[8dcfc0a]211        ldmia   r1!, {r2-r9}
212        stmia   r0!, {r2-r9}
213        ldmia   r1!, {r2-r9}
214        stmia   r0!, {r2-r9}
215
[9ce65803]216bsp_vector_table_copy_done:
217
[7a6f8d0]218        SWITCH_FROM_ARM_TO_THUMB        r0
219
[091705c]220        /* Branch to start hook 1 */
[8dcfc0a]221        bl      bsp_start_hook_1
222
[091705c]223        /* Branch to boot card */
[7ae2775]224        mov     r0, #0
[8dcfc0a]225        bl      boot_card
226
[305234f7]227twiddle:
228
[091705c]229        /* Branch to reset function */
[8dcfc0a]230        bl      bsp_reset
[39c8fdb]231
[305234f7]232        b       twiddle
[8dcfc0a]233
[4c622e5]234#elif defined(ARM_MULTILIB_ARCH_V7M)
[091705c]235
[4c622e5]236        .syntax unified
[091705c]237
[4c622e5]238        .extern bsp_stack_main_end
[091705c]239
[4c622e5]240        .thumb
[091705c]241
[4c622e5]242bsp_start_vector_table_begin:
[091705c]243
[4c622e5]244        .word   bsp_stack_main_end
245        .word   _start /* Reset */
[04f399d]246        .word   _ARMV7M_Exception_default /* NMI */
247        .word   _ARMV7M_Exception_default /* Hard Fault */
248        .word   _ARMV7M_Exception_default /* MPU Fault */
249        .word   _ARMV7M_Exception_default /* Bus Fault */
250        .word   _ARMV7M_Exception_default /* Usage Fault */
251        .word   _ARMV7M_Exception_default /* Reserved */
252        .word   _ARMV7M_Exception_default /* Reserved */
253        .word   _ARMV7M_Exception_default /* Reserved */
254        .word   _ARMV7M_Exception_default /* Reserved */
255        .word   _ARMV7M_Exception_default /* SVC */
256        .word   _ARMV7M_Exception_default /* Debug Monitor */
257        .word   _ARMV7M_Exception_default /* Reserved */
258        .word   _ARMV7M_Exception_default /* PendSV */
259        .word   _ARMV7M_Exception_default /* SysTick */
[4c622e5]260        .rept   BSP_INTERRUPT_VECTOR_MAX + 1
[04f399d]261        .word   _ARMV7M_Exception_default /* IRQ */
[4c622e5]262        .endr
[091705c]263
[4c622e5]264bsp_start_vector_table_end:
[091705c]265
[4c622e5]266        .thumb_func
[091705c]267
[4c622e5]268_start:
[091705c]269
[4c622e5]270        ldr     sp, =bsp_stack_main_end
271        ldr     lr, =bsp_start_hook_0_done + 1
272        b       bsp_start_hook_0
273
274bsp_start_hook_0_done:
275
276        bl      bsp_start_hook_1
277        movs    r0, #0
278        bl      boot_card
279
280twiddle:
281
282        bl      bsp_reset
283        b       twiddle
284
285#endif /* defined(ARM_MULTILIB_ARCH_V7M) */
286
287        .set    bsp_start_vector_table_size, bsp_start_vector_table_end - bsp_start_vector_table_begin
288        .set    bsp_vector_table_size, bsp_start_vector_table_size
Note: See TracBrowser for help on using the repository browser.