]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/standalone_v5_4/src/boot.S
Correct alignment issue in GCC and RVDS Cortex-A9 port that was preventing full float...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / standalone_v5_4 / src / boot.S
1 /******************************************************************************
2 *
3 * Copyright (C) 2014 - 2015 Xilinx, Inc. All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 * @file boot.S
35 *
36 * This file contains the initial startup code for the Cortex R5 processor
37 *
38 * <pre>
39 * MODIFICATION HISTORY:
40 *
41 * Ver   Who  Date     Changes
42 * ----- ---- -------- ---------------------------------------------------
43 * 5.00  pkp  02/10/14 Initial version
44 * 5.04  pkp  09/11/15 Disabled ACTLR.DBWR bit to avoid potential R5 deadlock
45 *                     for errata 780125
46 * 5.04 pkp   02/04/16 Enabled the fault log for lock-step mode
47 * 5.04 pkp   02/25/16 Initialized the banked registers for various modes,
48 *                     initialized floating point registers and enabled the
49 *                     cache ECC check before enabling the fault log for
50 *                     lock step mode
51 * 5.04 pkp   03/24/16 Reset the dbg_lpd_reset before enabling the fault log
52 *                     to avoid intervention for lock-step mode
53 * </pre>
54 *
55 * @note
56 *
57 * None.
58 *
59 ******************************************************************************/
60
61 #include "xparameters.h"
62
63
64 .global _prestart
65 .global _boot
66 .global __stack
67 .global __irq_stack
68 .global __supervisor_stack
69 .global __abort_stack
70 .global __fiq_stack
71 .global __undef_stack
72 .global _vector_table
73
74
75 /* Stack Pointer locations for boot code */
76 .set Undef_stack,       __undef_stack
77 .set FIQ_stack,         __fiq_stack
78 .set Abort_stack,       __abort_stack
79 .set SPV_stack,         __supervisor_stack
80 .set IRQ_stack,         __irq_stack
81 .set SYS_stack,         __stack
82
83 .set vector_base,       _vector_table
84
85 .set RPU_GLBL_CNTL,     0xFF9A0000
86 .set RPU_ERR_INJ,       0xFF9A0020
87 .set RST_LPD_DBG,       0xFF5E0240
88 .set fault_log_enable,  0x101
89
90 .section .boot,"axS"
91
92
93 /* this initializes the various processor modes */
94
95 _prestart:
96 _boot:
97
98 OKToRun:
99
100 /* Initialize processor registers to 0 */
101         mov     r0,#0
102         mov     r1,#0
103         mov     r2,#0
104         mov     r3,#0
105         mov     r4,#0
106         mov     r5,#0
107         mov     r6,#0
108         mov     r7,#0
109         mov     r8,#0
110         mov     r9,#0
111         mov     r10,#0
112         mov     r11,#0
113         mov     r12,#0
114
115 /* Initialize stack pointer and banked registers for various mode */
116         mrs     r0, cpsr                        /* get the current PSR */
117         mvn     r1, #0x1f                       /* set up the irq stack pointer */
118         and     r2, r1, r0
119         orr     r2, r2, #0x12                   /* IRQ mode */
120         msr     cpsr, r2
121         ldr     r13,=IRQ_stack                  /* IRQ stack pointer */
122         mov     r14,#0
123
124         mrs     r0, cpsr                        /* get the current PSR */
125         mvn     r1, #0x1f                       /* set up the supervisor stack pointer */
126         and     r2, r1, r0
127         orr     r2, r2, #0x13                   /* supervisor mode */
128         msr     cpsr, r2
129         ldr     r13,=SPV_stack                  /* Supervisor stack pointer */
130         mov     r14,#0
131
132         mrs     r0, cpsr                        /* get the current PSR */
133         mvn     r1, #0x1f                       /* set up the Abort  stack pointer */
134         and     r2, r1, r0
135         orr     r2, r2, #0x17                   /* Abort mode */
136         msr     cpsr, r2
137         ldr     r13,=Abort_stack                /* Abort stack pointer */
138         mov     r14,#0
139
140         mrs     r0, cpsr                        /* get the current PSR */
141         mvn     r1, #0x1f                       /* set up the FIQ stack pointer */
142         and     r2, r1, r0
143         orr     r2, r2, #0x11                   /* FIQ mode */
144         msr     cpsr, r2
145         mov     r8, #0
146         mov     r9, #0
147         mov     r10, #0
148         mov     r11, #0
149         mov     r12, #0
150         ldr     r13,=FIQ_stack                  /* FIQ stack pointer */
151         mov     r14,#0
152
153         mrs     r0, cpsr                        /* get the current PSR */
154         mvn     r1, #0x1f                       /* set up the Undefine stack pointer */
155         and     r2, r1, r0
156         orr     r2, r2, #0x1b                   /* Undefine mode */
157         msr     cpsr, r2
158         ldr     r13,=Undef_stack                /* Undefine stack pointer */
159         mov     r14,#0
160
161         mrs     r0, cpsr                        /* get the current PSR */
162         mvn     r1, #0x1f                       /* set up the system stack pointer */
163         and     r2, r1, r0
164         orr     r2, r2, #0x1F                   /* SYS mode */
165         msr     cpsr, r2
166         ldr     r13,=SYS_stack                  /* SYS stack pointer */
167         mov     r14,#0
168
169 /*
170  * Enable access to VFP by enabling access to Coprocessors 10 and 11.
171  * Enables Full Access i.e. in both privileged and non privileged modes
172  */
173         mrc     p15, 0, r0, c1, c0, 2           /* Read Coprocessor Access Control Register (CPACR) */
174         orr     r0, r0, #(0xF << 20)            /* Enable access to CP 10 & 11 */
175         mcr     p15, 0, r0, c1, c0, 2           /* Write Coprocessor Access Control Register (CPACR) */
176         isb
177
178 /* enable fpu access  */
179         vmrs    r3, FPEXC
180         orr     r1, r3, #(1<<30)
181         vmsr    FPEXC, r1
182
183 /* clear the floating point register*/
184         mov     r1,#0
185         vmov    d0,r1,r1
186         vmov    d1,r1,r1
187         vmov    d2,r1,r1
188         vmov    d3,r1,r1
189         vmov    d4,r1,r1
190         vmov    d5,r1,r1
191         vmov    d6,r1,r1
192         vmov    d7,r1,r1
193         vmov    d8,r1,r1
194         vmov    d9,r1,r1
195         vmov    d10,r1,r1
196         vmov    d11,r1,r1
197         vmov    d12,r1,r1
198         vmov    d13,r1,r1
199         vmov    d14,r1,r1
200         vmov    d15,r1,r1
201
202 /* restore previous value for fpu access */
203         vmsr    FPEXC,r3
204
205 /* Disable MPU and caches */
206         mrc     p15, 0, r0, c1, c0, 0           /* Read CP15 Control Register*/
207         bic     r0, r0, #0x05                   /* Disable MPU (M bit) and data cache (C bit) */
208         bic     r0, r0, #0x1000                 /* Disable instruction cache (I bit) */
209         dsb                                     /* Ensure all previous loads/stores have completed */
210         mcr     p15, 0, r0, c1, c0, 0           /* Write CP15 Control Register */
211         isb                                     /* Ensure subsequent insts execute wrt new MPU settings */
212
213 /* Disable Branch prediction, TCM ECC checks */
214         mrc     p15, 0, r0, c1, c0, 1           /* Read ACTLR */
215         orr     r0, r0, #(0x1 << 17)            /* Enable RSDIS bit 17 to disable the return stack */
216         orr     r0, r0, #(0x1 << 16)            /* Clear BP bit 15 and set BP bit 16:*/
217         bic     r0, r0, #(0x1 << 15)            /* Branch always not taken and history table updates disabled*/
218         bic     r0, r0, #(0x1 << 27)            /* Disable B1TCM ECC check */
219         bic     r0, r0, #(0x1 << 26)            /* Disable B0TCM ECC check */
220         bic     r0, r0, #(0x1 << 25)            /* Disable ATCM ECC check */
221         orr     r0, r0, #(0x1 << 5)             /* Enable ECC with no forced write through with [5:3]=b'101*/
222         bic     r0, r0, #(0x1 << 4)
223         orr     r0, r0, #(0x1 << 3)
224         mcr     p15, 0, r0, c1, c0, 1           /* Write ACTLR*/
225         dsb                                     /* Complete all outstanding explicit memory operations*/
226
227 /* Invalidate caches */
228         mov     r0,#0                           /* r0 = 0  */
229         dsb
230         mcr     p15, 0, r0, c7, c5, 0           /* invalidate icache */
231         mcr     p15, 0, r0, c15, c5, 0          /* Invalidate entire data cache*/
232         isb
233
234 /* enable fault log for lock step */
235         ldr     r0,=RPU_GLBL_CNTL
236         ldr     r1, [r0]
237         ands    r1, r1, #0x8
238 /* branch to initialization if split mode*/
239         bne     init
240 /* reset the debug logic */
241         ldr     r0,=RST_LPD_DBG
242         ldr     r1, [r0]
243         orr     r1, r1, #(0x1 << 1)
244         orr     r1, r1, #(0x1 << 4)
245         orr     r1, r1, #(0x1 << 5)
246         str     r1, [r0]
247 /* enable fault log */
248         ldr     r0,=RPU_ERR_INJ
249         ldr     r1,=fault_log_enable
250         ldr     r2, [r0]
251         orr     r2, r2, r1
252         str     r2, [r0]
253         nop
254         nop
255
256 init:
257         bl      Init_MPU                /* Initialize MPU */
258
259 /* Enable Branch prediction */
260         mrc     p15, 0, r0, c1, c0, 1       /* Read ACTLR*/
261         bic     r0, r0, #(0x1 << 17)        /* Clear RSDIS bit 17 to enable return stack*/
262         bic     r0, r0, #(0x1 << 16)        /* Clear BP bit 15 and BP bit 16:*/
263         bic     r0, r0, #(0x1 << 15)        /* Normal operation, BP is taken from the global history table.*/
264         orr     r0, r0, #(0x1 << 14)        /* Disable DBWR for errata 780125 */
265         mcr     p15, 0, r0, c1, c0, 1       /* Write ACTLR*/
266
267 /* Enable icahce and dcache */
268         mrc     p15,0,r1,c1,c0,0
269         ldr     r0, =0x1005
270         orr     r1,r1,r0
271         dsb
272         mcr     p15,0,r1,c1,c0,0                /* Enable cache  */
273         isb                                     /* isb  flush prefetch buffer */
274
275 /* Warning message to be removed after 2016.1 */
276 /* USEAMP was introduced in 2015.4 with ZynqMP and caused confusion with USE_AMP */
277 #ifdef USEAMP
278 #warning "-DUSEAMP=1 is deprecated, use -DVEC_TABLE_IN_OCM instead to set vector table in OCM"
279 #endif
280
281 /* Set vector table in TCM/LOVEC */
282 #ifndef VEC_TABLE_IN_OCM
283         mrc     p15, 0, r0, c1, c0, 0
284         mvn     r1, #0x2000
285         and     r0, r0, r1
286         mcr     p15, 0, r0, c1, c0, 0
287 #endif
288
289 /* enable asynchronous abort exception */
290         mrs     r0, cpsr
291         bic     r0, r0, #0x100
292         msr     cpsr_xsf, r0
293
294         b       _startup                       /* jump to C startup code */
295
296
297 .Ldone: b       .Ldone                          /* Paranoia: we should never get here */
298
299
300 .end