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

4.115
Last change on this file since dc9aaf7 was dc9aaf7, checked in by Martin Galvan <martin.galvan@…>, on Feb 20, 2015 at 1:08:01 PM

ARM: Support VFP-D16

This patch allows the existing FPU code to support both VFP-D16 and
VFP-D32. According to ARM, writes to D32DIS are ignored for D16 so
there's no need to enclose the bic instruction with an #ifdef. We tested
it on a TMS570LS3137 using TI initialization code and it works fine.

Signed-off by: Martin Galvan <martin.galvan@…>

  • Property mode set to 100644
File size: 6.9 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.org/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
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        /*
199         * Clear ASEDIS and D32DIS.  Writes to D32DIS are ignored for VFP-D16.
200         */
201        bic r0, r0, #(3 << 30)
202
203        /* Write CPACR */
204        mcr p15, 0, r0, c1, c0, 2
205        isb
206
207        /* Enable FPU */
208        mov r0, #(1 << 30)
209        vmsr FPEXC, r0
210#endif /* ARM_MULTILIB_VFP */
211
212        /*
213         * Branch to start hook 0.
214         *
215         * The previous code and parts of the start hook 0 may run with an
216         * address offset.  This implies that only branches relative to the
217         * program counter are allowed.  After the start hook 0 it is assumed
218         * that the code can run at its intended position.  Thus the link
219         * register will be loaded with the absolute address.  In THUMB mode
220         * the start hook 0 must be within a 2kByte range due to the branch
221         * instruction limitation.
222         */
223
224        ldr     lr, =bsp_start_hook_0_done
225#ifdef __thumb__
226        orr     lr, #1
227#endif
228
229        SWITCH_FROM_ARM_TO_THUMB        r0
230
231        b       bsp_start_hook_0
232
233bsp_start_hook_0_done:
234
235        SWITCH_FROM_THUMB_TO_ARM
236
237        /*
238         * Initialize the exception vectors.  This includes the exceptions
239         * vectors and the pointers to the default exception handlers.
240         */
241
242        ldr     r0, =bsp_vector_table_begin
243        adr     r1, bsp_start_vector_table_begin
244        cmp     r0, r1
245        beq     bsp_vector_table_copy_done
246        ldmia   r1!, {r2-r9}
247        stmia   r0!, {r2-r9}
248        ldmia   r1!, {r2-r9}
249        stmia   r0!, {r2-r9}
250
251bsp_vector_table_copy_done:
252
253        SWITCH_FROM_ARM_TO_THUMB        r0
254
255        /* Branch to start hook 1 */
256        bl      bsp_start_hook_1
257
258        /* Branch to boot card */
259        mov     r0, #0
260        bl      boot_card
261
262twiddle:
263
264        /* Branch to reset function */
265        bl      bsp_reset
266
267        b       twiddle
268
269#elif defined(ARM_MULTILIB_ARCH_V7M)
270
271#include <rtems/score/armv7m.h>
272
273        .syntax unified
274
275        .extern bsp_stack_main_end
276
277        .thumb
278
279bsp_start_vector_table_begin:
280
281        .word   bsp_stack_main_end
282        .word   _start /* Reset */
283        .word   _ARMV7M_Exception_default /* NMI */
284        .word   _ARMV7M_Exception_default /* Hard Fault */
285        .word   _ARMV7M_Exception_default /* MPU Fault */
286        .word   _ARMV7M_Exception_default /* Bus Fault */
287        .word   _ARMV7M_Exception_default /* Usage Fault */
288        .word   _ARMV7M_Exception_default /* Reserved */
289        .word   _ARMV7M_Exception_default /* Reserved */
290        .word   _ARMV7M_Exception_default /* Reserved */
291        .word   _ARMV7M_Exception_default /* Reserved */
292        .word   _ARMV7M_Exception_default /* SVC */
293        .word   _ARMV7M_Exception_default /* Debug Monitor */
294        .word   _ARMV7M_Exception_default /* Reserved */
295        .word   _ARMV7M_Exception_default /* PendSV */
296        .word   _ARMV7M_Exception_default /* SysTick */
297        .rept   BSP_INTERRUPT_VECTOR_MAX + 1
298        .word   _ARMV7M_Exception_default /* IRQ */
299        .endr
300
301bsp_start_vector_table_end:
302
303        .thumb_func
304
305_start:
306
307#ifdef ARM_MULTILIB_VFP
308        /*
309         * Enable CP10 and CP11 coprocessors for privileged and user mode in
310         * CPACR (bits 20-23).  Ensure that write to register completes.
311         */
312        ldr     r0, =ARMV7M_CPACR
313        ldr     r1, [r0]
314        orr     r1, r1, #(0xf << 20)
315        str     r1, [r0]
316        dsb
317        isb
318#endif
319
320        ldr     sp, =bsp_stack_main_end
321        ldr     lr, =bsp_start_hook_0_done + 1
322        b       bsp_start_hook_0
323
324bsp_start_hook_0_done:
325
326        bl      bsp_start_hook_1
327        movs    r0, #0
328        bl      boot_card
329
330twiddle:
331
332        bl      bsp_reset
333        b       twiddle
334
335#endif /* defined(ARM_MULTILIB_ARCH_V7M) */
336
337        .set    bsp_start_vector_table_size, bsp_start_vector_table_end - bsp_start_vector_table_begin
338        .set    bsp_vector_table_size, bsp_start_vector_table_size
Note: See TracBrowser for help on using the repository browser.