]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/standalone_v5_4/src/boot.S
Update BSP source files for UltraScale Cortex-A53 and Cortex-R5 and Microblaze to...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_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 A53 processor
37 * Currently the processor starts at EL3 and boot code, startup and main
38 * code will run on secure EL3.
39 *
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who     Date     Changes
45 * ----- ------- -------- ---------------------------------------------------
46 * 5.00  pkp     5/21/14 Initial version
47 *
48 * @note
49 *
50 * None.
51 *
52 ******************************************************************************/
53
54 #include "xparameters.h"
55
56 .globl MMUTableL0
57 .globl MMUTableL1
58 .globl MMUTableL2
59 .global _prestart
60 .global _boot
61
62 .global __el3_stack
63 .global __el2_stack
64 .global __el1_stack
65 .global __el0_stack
66 .global _vector_table
67
68
69 .set EL3_stack,         __el3_stack
70 .set EL2_stack,         __el2_stack
71 .set EL1_stack,         __el1_stack
72 .set EL0_stack,         __el0_stack
73
74 .set TT_S1_FAULT,       0x0
75 .set TT_S1_TABLE,       0x3
76
77 .set L0Table,   MMUTableL0
78 .set L1Table,   MMUTableL1
79 .set L2Table,   MMUTableL2
80 .set vector_base,       _vector_table
81 .set rvbar_base,        0xFD5C0040
82
83 .section .boot,"ax"
84
85
86 /* this initializes the various processor modes */
87
88 _prestart:
89 _boot:
90         mov      x0, #0
91         mov      x1, #0
92         mov      x2, #0
93         mov      x3, #0
94         mov      x4, #0
95         mov      x5, #0
96         mov      x6, #0
97         mov      x7, #0
98         mov      x8, #0
99         mov      x9, #0
100         mov      x10, #0
101         mov      x11, #0
102         mov      x12, #0
103         mov      x13, #0
104         mov      x14, #0
105         mov      x15, #0
106         mov      x16, #0
107         mov      x17, #0
108         mov      x18, #0
109         mov      x19, #0
110         mov      x20, #0
111         mov      x21, #0
112         mov      x22, #0
113         mov      x23, #0
114         mov      x24, #0
115         mov      x25, #0
116         mov      x26, #0
117         mov      x27, #0
118         mov      x28, #0
119         mov      x29, #0
120         mov      x30, #0
121 #if 0 //dont put other a53 cpus in wfi
122    //Which core am I
123    // ----------------
124         mrs      x0, MPIDR_EL1
125         and      x0, x0, #0xFF                     //Mask off to leave Aff0
126         cbz      x0, OKToRun                          //If core 0, run the primary init code
127 EndlessLoop0:
128         wfi
129         b        EndlessLoop0
130 #endif
131 OKToRun:
132
133         /*Set vector table base address*/
134         ldr     x1, =vector_base
135         msr     VBAR_EL3,x1
136
137         /* Set reset vector address */
138         /* Get the cpu ID */
139         mrs  x0, MPIDR_EL1
140         and  x0, x0, #0xFF
141         mov  w0, w0
142         ldr      w2, =rvbar_base
143         /* calculate the rvbar base address for particular CPU core */
144         mov      w3, #0x8
145         mul      w0, w0, w3
146         add      w2, w2, w0
147         /* store vector base address to RVBAR */
148         str  x1, [x2]
149
150         /*Define stack pointer for current exception level*/
151         ldr      x2,=EL3_stack
152         mov      sp,x2
153
154
155         /* Disable trapping of CPTR_EL3 accesses or use of Adv.SIMD/FPU*/
156         mov      x0, #0                 // Clear all trap bits
157         msr      CPTR_EL3, x0
158
159
160         /* Configure SCR_EL3 */
161         mov      w1, #0                 //; Initial value of register is unknown
162         orr      w1, w1, #(1 << 11)     //; Set ST bit (Secure EL1 can access CNTPS_TVAL_EL1, CNTPS_CTL_EL1 & CNTPS_CVAL_EL1)
163         orr      w1, w1, #(1 << 10)     //; Set RW bit (EL1 is AArch64, as this is the Secure world)
164         orr      w1, w1, #(1 << 3)      //; Set EA bit (SError routed to EL3)
165         orr      w1, w1, #(1 << 2)      //; Set FIQ bit (FIQs routed to EL3)
166         orr      w1, w1, #(1 << 1)      //; Set IRQ bit (IRQs routed to EL3)
167         msr      SCR_EL3, x1
168
169         /*Enable ECC protection*/
170         mrs     x0, S3_1_C11_C0_2       // register L2CTLR_EL1
171         orr     x0, x0, #(1<<22)
172         msr     S3_1_C11_C0_2, x0
173
174         /*configure cpu auxiliary control register EL1 */
175         ldr     x0,=0x80CA000           // L1 Data prefetch control - 5, Enable device split throttle, 2 independent data prefetch streams
176         msr     S3_1_C15_C2_0, x0       //CPUACTLR_EL1
177
178
179         /*Enable hardware coherency between cores*/
180         mrs      x0, S3_1_c15_c2_1      //Read EL1 CPU Extended Control Register
181         orr      x0, x0, #(1 << 6)      //Set the SMPEN bit
182         msr      S3_1_c15_c2_1, x0      //Write EL1 CPU Extended Control Register
183         isb
184
185         tlbi    ALLE3
186         ic      IALLU                   //; Invalidate I cache to PoU
187         bl      invalidate_dcaches
188         dsb      sy
189         isb
190
191         ldr      x1, =L0Table           //; Get address of level 0 for TTBR0_EL1
192         msr      TTBR0_EL3, x1          //; Set TTBR0_EL3 (NOTE: There is no TTBR1 at EL1)
193
194
195         /**********************************************
196         * Set up memory attributes
197         * This equates to:
198         * 0 = b01000100 = Normal, Inner/Outer Non-Cacheable
199         * 1 = b11111111 = Normal, Inner/Outer WB/WA/RA
200         * 2 = b00000000 = Device-nGnRnE
201         * 3 = b00000100 = Device-nGnRE
202         * 4 = b10111011 = Normal, Inner/Outer WT/WA/RA
203         **********************************************/
204         ldr      x1, =0x000000BB0400FF44
205         msr      MAIR_EL3, x1
206
207         /**********************************************
208         * Set up TCR_EL3
209         * Physical Address Size PS =  010 -> 40bits 1TB
210         * Granual Size TG0 = 00 -> 4KB
211         * size offset of the memory region T0SZ = 24 -> (region size 2^(64-24) = 2^40)
212         ***************************************************/
213         ldr     x1,=0x80823518
214         msr     TCR_EL3, x1
215         isb
216
217         /* Enable SError Exception for asynchronous abort */
218         mrs     x1,DAIF
219         bic     x1,x1,#(0x1<<8)
220         msr     DAIF,x1
221
222         /* Configure SCTLR_EL3 */
223         mov      x1, #0                //Most of the SCTLR_EL3 bits are unknown at reset
224         orr      x1, x1, #(1 << 12)     //Enable I cache
225         orr      x1, x1, #(1 << 3)      //Enable SP alignment check
226         orr      x1, x1, #(1 << 2)      //Enable caches
227         orr      x1, x1, #(1 << 0)      //Enable MMU
228         msr      SCTLR_EL3, x1
229         dsb      sy
230         isb
231
232         bl       _startup               //jump to start
233
234 loop:   b       loop
235
236
237 invalidate_dcaches:
238
239         dmb     ISH
240         mrs     x0, CLIDR_EL1          //; x0 = CLIDR
241         ubfx    w2, w0, #24, #3        //; w2 = CLIDR.LoC
242         cmp     w2, #0                 //; LoC is 0?
243         b.eq    invalidateCaches_end   //; No cleaning required and enable MMU
244         mov     w1, #0                 //; w1 = level iterator
245
246 invalidateCaches_flush_level:
247         add     w3, w1, w1, lsl #1     //; w3 = w1 * 3 (right-shift for cache type)
248         lsr     w3, w0, w3             //; w3 = w0 >> w3
249         ubfx    w3, w3, #0, #3         //; w3 = cache type of this level
250         cmp     w3, #2                 //; No cache at this level?
251         b.lt    invalidateCaches_next_level
252
253         lsl     w4, w1, #1
254         msr     CSSELR_EL1, x4         //; Select current cache level in CSSELR
255         isb                            //; ISB required to reflect new CSIDR
256         mrs     x4, CCSIDR_EL1         //; w4 = CSIDR
257
258         ubfx    w3, w4, #0, #3
259         add     w3, w3, #2             //; w3 = log2(line size)
260         ubfx    w5, w4, #13, #15
261         ubfx    w4, w4, #3, #10        //; w4 = Way number
262         clz     w6, w4                 //; w6 = 32 - log2(number of ways)
263
264 invalidateCaches_flush_set:
265         mov     w8, w4                 //; w8 = Way number
266 invalidateCaches_flush_way:
267         lsl     w7, w1, #1             //; Fill level field
268         lsl     w9, w5, w3
269         orr     w7, w7, w9             //; Fill index field
270         lsl     w9, w8, w6
271         orr     w7, w7, w9             //; Fill way field
272         dc      CISW, x7               //; Invalidate by set/way to point of coherency
273         subs    w8, w8, #1             //; Decrement way
274         b.ge    invalidateCaches_flush_way
275         subs    w5, w5, #1             //; Descrement set
276         b.ge    invalidateCaches_flush_set
277
278 invalidateCaches_next_level:
279         add     w1, w1, #1             //; Next level
280         cmp     w2, w1
281         b.gt    invalidateCaches_flush_level
282
283 invalidateCaches_end:
284         ret
285
286 .end