]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/standalone_v6_1/src/boot.S
Update BSP source files for UltraScale Cortex-A53 and Cortex-R5 and Microblaze to...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / standalone_v6_1 / 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 * 5.05 pkp   04/11/16 Enable the comparators for non-JTAG boot mode for
54 *                     lock-step to avoid putting debug logic to reset
55 * </pre>
56 *
57 * @note
58 *
59 * None.
60 *
61 ******************************************************************************/
62
63 #include "xparameters.h"
64
65
66 .global _prestart
67 .global _boot
68 .global __stack
69 .global __irq_stack
70 .global __supervisor_stack
71 .global __abort_stack
72 .global __fiq_stack
73 .global __undef_stack
74 .global _vector_table
75
76
77 /* Stack Pointer locations for boot code */
78 .set Undef_stack,       __undef_stack
79 .set FIQ_stack,         __fiq_stack
80 .set Abort_stack,       __abort_stack
81 .set SPV_stack,         __supervisor_stack
82 .set IRQ_stack,         __irq_stack
83 .set SYS_stack,         __stack
84
85 .set vector_base,       _vector_table
86
87 .set RPU_GLBL_CNTL,     0xFF9A0000
88 .set RPU_ERR_INJ,       0xFF9A0020
89 .set RST_LPD_DBG,       0xFF5E0240
90 .set BOOT_MODE_USER,    0xFF5E0200
91 .set fault_log_enable,  0x101
92
93 .section .boot,"axS"
94
95
96 /* this initializes the various processor modes */
97
98 _prestart:
99 _boot:
100
101 OKToRun:
102
103 /* Initialize processor registers to 0 */
104         mov     r0,#0
105         mov     r1,#0
106         mov     r2,#0
107         mov     r3,#0
108         mov     r4,#0
109         mov     r5,#0
110         mov     r6,#0
111         mov     r7,#0
112         mov     r8,#0
113         mov     r9,#0
114         mov     r10,#0
115         mov     r11,#0
116         mov     r12,#0
117
118 /* Initialize stack pointer and banked registers for various mode */
119         mrs     r0, cpsr                        /* get the current PSR */
120         mvn     r1, #0x1f                       /* set up the irq stack pointer */
121         and     r2, r1, r0
122         orr     r2, r2, #0x12                   /* IRQ mode */
123         msr     cpsr, r2
124         ldr     r13,=IRQ_stack                  /* IRQ stack pointer */
125         mov     r14,#0
126
127         mrs     r0, cpsr                        /* get the current PSR */
128         mvn     r1, #0x1f                       /* set up the supervisor stack pointer */
129         and     r2, r1, r0
130         orr     r2, r2, #0x13                   /* supervisor mode */
131         msr     cpsr, r2
132         ldr     r13,=SPV_stack                  /* Supervisor stack pointer */
133         mov     r14,#0
134
135         mrs     r0, cpsr                        /* get the current PSR */
136         mvn     r1, #0x1f                       /* set up the Abort  stack pointer */
137         and     r2, r1, r0
138         orr     r2, r2, #0x17                   /* Abort mode */
139         msr     cpsr, r2
140         ldr     r13,=Abort_stack                /* Abort stack pointer */
141         mov     r14,#0
142
143         mrs     r0, cpsr                        /* get the current PSR */
144         mvn     r1, #0x1f                       /* set up the FIQ stack pointer */
145         and     r2, r1, r0
146         orr     r2, r2, #0x11                   /* FIQ mode */
147         msr     cpsr, r2
148         mov     r8, #0
149         mov     r9, #0
150         mov     r10, #0
151         mov     r11, #0
152         mov     r12, #0
153         ldr     r13,=FIQ_stack                  /* FIQ stack pointer */
154         mov     r14,#0
155
156         mrs     r0, cpsr                        /* get the current PSR */
157         mvn     r1, #0x1f                       /* set up the Undefine stack pointer */
158         and     r2, r1, r0
159         orr     r2, r2, #0x1b                   /* Undefine mode */
160         msr     cpsr, r2
161         ldr     r13,=Undef_stack                /* Undefine stack pointer */
162         mov     r14,#0
163
164         mrs     r0, cpsr                        /* get the current PSR */
165         mvn     r1, #0x1f                       /* set up the system stack pointer */
166         and     r2, r1, r0
167         orr     r2, r2, #0x1F                   /* SYS mode */
168         msr     cpsr, r2
169         ldr     r13,=SYS_stack                  /* SYS stack pointer */
170         mov     r14,#0
171
172 /*
173  * Enable access to VFP by enabling access to Coprocessors 10 and 11.
174  * Enables Full Access i.e. in both privileged and non privileged modes
175  */
176         mrc     p15, 0, r0, c1, c0, 2           /* Read Coprocessor Access Control Register (CPACR) */
177         orr     r0, r0, #(0xF << 20)            /* Enable access to CP 10 & 11 */
178         mcr     p15, 0, r0, c1, c0, 2           /* Write Coprocessor Access Control Register (CPACR) */
179         isb
180
181 /* enable fpu access  */
182         vmrs    r3, FPEXC
183         orr     r1, r3, #(1<<30)
184         vmsr    FPEXC, r1
185
186 /* clear the floating point register*/
187         mov     r1,#0
188         vmov    d0,r1,r1
189         vmov    d1,r1,r1
190         vmov    d2,r1,r1
191         vmov    d3,r1,r1
192         vmov    d4,r1,r1
193         vmov    d5,r1,r1
194         vmov    d6,r1,r1
195         vmov    d7,r1,r1
196         vmov    d8,r1,r1
197         vmov    d9,r1,r1
198         vmov    d10,r1,r1
199         vmov    d11,r1,r1
200         vmov    d12,r1,r1
201         vmov    d13,r1,r1
202         vmov    d14,r1,r1
203         vmov    d15,r1,r1
204
205 /* restore previous value for fpu access */
206         vmsr    FPEXC,r3
207
208 /* Disable MPU and caches */
209         mrc     p15, 0, r0, c1, c0, 0           /* Read CP15 Control Register*/
210         bic     r0, r0, #0x05                   /* Disable MPU (M bit) and data cache (C bit) */
211         bic     r0, r0, #0x1000                 /* Disable instruction cache (I bit) */
212         dsb                                     /* Ensure all previous loads/stores have completed */
213         mcr     p15, 0, r0, c1, c0, 0           /* Write CP15 Control Register */
214         isb                                     /* Ensure subsequent insts execute wrt new MPU settings */
215
216 /* Disable Branch prediction, TCM ECC checks */
217         mrc     p15, 0, r0, c1, c0, 1           /* Read ACTLR */
218         orr     r0, r0, #(0x1 << 17)            /* Enable RSDIS bit 17 to disable the return stack */
219         orr     r0, r0, #(0x1 << 16)            /* Clear BP bit 15 and set BP bit 16:*/
220         bic     r0, r0, #(0x1 << 15)            /* Branch always not taken and history table updates disabled*/
221         bic     r0, r0, #(0x1 << 27)            /* Disable B1TCM ECC check */
222         bic     r0, r0, #(0x1 << 26)            /* Disable B0TCM ECC check */
223         bic     r0, r0, #(0x1 << 25)            /* Disable ATCM ECC check */
224         orr     r0, r0, #(0x1 << 5)             /* Enable ECC with no forced write through with [5:3]=b'101*/
225         bic     r0, r0, #(0x1 << 4)
226         orr     r0, r0, #(0x1 << 3)
227         mcr     p15, 0, r0, c1, c0, 1           /* Write ACTLR*/
228         dsb                                     /* Complete all outstanding explicit memory operations*/
229
230 /* Invalidate caches */
231         mov     r0,#0                           /* r0 = 0  */
232         dsb
233         mcr     p15, 0, r0, c7, c5, 0           /* invalidate icache */
234         mcr     p15, 0, r0, c15, c5, 0          /* Invalidate entire data cache*/
235         isb
236
237 /* enable fault log for lock step */
238         ldr     r0,=RPU_GLBL_CNTL
239         ldr     r1, [r0]
240         ands    r1, r1, #0x8
241 /* branch to initialization if split mode*/
242         bne     init
243 /* check for boot mode if in lock step, branch to init if JTAG boot mode*/
244         ldr     r0,=BOOT_MODE_USER
245         ldr     r1, [r0]
246         ands    r1, r1, #0xF
247         beq     init
248 /* reset the debug logic */
249         ldr     r0,=RST_LPD_DBG
250         ldr     r1, [r0]
251         orr     r1, r1, #(0x1 << 1)
252         orr     r1, r1, #(0x1 << 4)
253         orr     r1, r1, #(0x1 << 5)
254         str     r1, [r0]
255 /* enable fault log */
256         ldr     r0,=RPU_ERR_INJ
257         ldr     r1,=fault_log_enable
258         ldr     r2, [r0]
259         orr     r2, r2, r1
260         str     r2, [r0]
261         nop
262         nop
263
264 init:
265         bl      Init_MPU                /* Initialize MPU */
266
267 /* Enable Branch prediction */
268         mrc     p15, 0, r0, c1, c0, 1       /* Read ACTLR*/
269         bic     r0, r0, #(0x1 << 17)        /* Clear RSDIS bit 17 to enable return stack*/
270         bic     r0, r0, #(0x1 << 16)        /* Clear BP bit 15 and BP bit 16:*/
271         bic     r0, r0, #(0x1 << 15)        /* Normal operation, BP is taken from the global history table.*/
272         orr     r0, r0, #(0x1 << 14)        /* Disable DBWR for errata 780125 */
273         mcr     p15, 0, r0, c1, c0, 1       /* Write ACTLR*/
274
275 /* Enable icahce and dcache */
276         mrc     p15,0,r1,c1,c0,0
277         ldr     r0, =0x1005
278         orr     r1,r1,r0
279         dsb
280         mcr     p15,0,r1,c1,c0,0                /* Enable cache  */
281         isb                                     /* isb  flush prefetch buffer */
282
283 /* Warning message to be removed after 2016.1 */
284 /* USEAMP was introduced in 2015.4 with ZynqMP and caused confusion with USE_AMP */
285 #ifdef USEAMP
286 #warning "-DUSEAMP=1 is deprecated, use -DVEC_TABLE_IN_OCM instead to set vector table in OCM"
287 #endif
288
289 /* Set vector table in TCM/LOVEC */
290 #ifndef VEC_TABLE_IN_OCM
291         mrc     p15, 0, r0, c1, c0, 0
292         mvn     r1, #0x2000
293         and     r0, r0, r1
294         mcr     p15, 0, r0, c1, c0, 0
295 #endif
296
297 /* enable asynchronous abort exception */
298         mrs     r0, cpsr
299         bic     r0, r0, #0x100
300         msr     cpsr_xsf, r0
301
302         b       _startup                       /* jump to C startup code */
303
304
305 .Ldone: b       .Ldone                          /* Paranoia: we should never get here */
306
307
308 .end