1*91f16700Schasinglulu/* 2*91f16700Schasinglulu * Copyright (c) 2016-2022, ARM Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu#include <arch.h> 8*91f16700Schasinglulu#include <asm_macros.S> 9*91f16700Schasinglulu#include <common/bl_common.h> 10*91f16700Schasinglulu 11*91f16700Schasinglulu .globl bl2_vector_table 12*91f16700Schasinglulu .globl bl2_entrypoint 13*91f16700Schasinglulu 14*91f16700Schasinglulu 15*91f16700Schasingluluvector_base bl2_vector_table 16*91f16700Schasinglulu b bl2_entrypoint 17*91f16700Schasinglulu b report_exception /* Undef */ 18*91f16700Schasinglulu b report_exception /* SVC call */ 19*91f16700Schasinglulu b report_prefetch_abort /* Prefetch abort */ 20*91f16700Schasinglulu b report_data_abort /* Data abort */ 21*91f16700Schasinglulu b report_exception /* Reserved */ 22*91f16700Schasinglulu b report_exception /* IRQ */ 23*91f16700Schasinglulu b report_exception /* FIQ */ 24*91f16700Schasinglulu 25*91f16700Schasinglulu 26*91f16700Schasinglulufunc bl2_entrypoint 27*91f16700Schasinglulu /*--------------------------------------------- 28*91f16700Schasinglulu * Save arguments x0 - x3 from BL1 for future 29*91f16700Schasinglulu * use. 30*91f16700Schasinglulu * --------------------------------------------- 31*91f16700Schasinglulu */ 32*91f16700Schasinglulu mov r9, r0 33*91f16700Schasinglulu mov r10, r1 34*91f16700Schasinglulu mov r11, r2 35*91f16700Schasinglulu mov r12, r3 36*91f16700Schasinglulu 37*91f16700Schasinglulu /* --------------------------------------------- 38*91f16700Schasinglulu * Set the exception vector to something sane. 39*91f16700Schasinglulu * --------------------------------------------- 40*91f16700Schasinglulu */ 41*91f16700Schasinglulu ldr r0, =bl2_vector_table 42*91f16700Schasinglulu stcopr r0, VBAR 43*91f16700Schasinglulu isb 44*91f16700Schasinglulu 45*91f16700Schasinglulu /* -------------------------------------------------------- 46*91f16700Schasinglulu * Enable the instruction cache - disable speculative loads 47*91f16700Schasinglulu * -------------------------------------------------------- 48*91f16700Schasinglulu */ 49*91f16700Schasinglulu ldcopr r0, SCTLR 50*91f16700Schasinglulu orr r0, r0, #SCTLR_I_BIT 51*91f16700Schasinglulu bic r0, r0, #SCTLR_DSSBS_BIT 52*91f16700Schasinglulu stcopr r0, SCTLR 53*91f16700Schasinglulu isb 54*91f16700Schasinglulu 55*91f16700Schasinglulu /* --------------------------------------------- 56*91f16700Schasinglulu * Since BL2 executes after BL1, it is assumed 57*91f16700Schasinglulu * here that BL1 has already has done the 58*91f16700Schasinglulu * necessary register initializations. 59*91f16700Schasinglulu * --------------------------------------------- 60*91f16700Schasinglulu */ 61*91f16700Schasinglulu 62*91f16700Schasinglulu /* --------------------------------------------- 63*91f16700Schasinglulu * Invalidate the RW memory used by the BL2 64*91f16700Schasinglulu * image. This includes the data and NOBITS 65*91f16700Schasinglulu * sections. This is done to safeguard against 66*91f16700Schasinglulu * possible corruption of this memory by dirty 67*91f16700Schasinglulu * cache lines in a system cache as a result of 68*91f16700Schasinglulu * use by an earlier boot loader stage. 69*91f16700Schasinglulu * --------------------------------------------- 70*91f16700Schasinglulu */ 71*91f16700Schasinglulu ldr r0, =__RW_START__ 72*91f16700Schasinglulu ldr r1, =__RW_END__ 73*91f16700Schasinglulu sub r1, r1, r0 74*91f16700Schasinglulu bl inv_dcache_range 75*91f16700Schasinglulu 76*91f16700Schasinglulu /* --------------------------------------------- 77*91f16700Schasinglulu * Zero out NOBITS sections. There are 2 of them: 78*91f16700Schasinglulu * - the .bss section; 79*91f16700Schasinglulu * - the coherent memory section. 80*91f16700Schasinglulu * --------------------------------------------- 81*91f16700Schasinglulu */ 82*91f16700Schasinglulu ldr r0, =__BSS_START__ 83*91f16700Schasinglulu ldr r1, =__BSS_END__ 84*91f16700Schasinglulu sub r1, r1, r0 85*91f16700Schasinglulu bl zeromem 86*91f16700Schasinglulu 87*91f16700Schasinglulu#if USE_COHERENT_MEM 88*91f16700Schasinglulu ldr r0, =__COHERENT_RAM_START__ 89*91f16700Schasinglulu ldr r1, =__COHERENT_RAM_END_UNALIGNED__ 90*91f16700Schasinglulu sub r1, r1, r0 91*91f16700Schasinglulu bl zeromem 92*91f16700Schasinglulu#endif 93*91f16700Schasinglulu 94*91f16700Schasinglulu /* -------------------------------------------- 95*91f16700Schasinglulu * Allocate a stack whose memory will be marked 96*91f16700Schasinglulu * as Normal-IS-WBWA when the MMU is enabled. 97*91f16700Schasinglulu * There is no risk of reading stale stack 98*91f16700Schasinglulu * memory after enabling the MMU as only the 99*91f16700Schasinglulu * primary cpu is running at the moment. 100*91f16700Schasinglulu * -------------------------------------------- 101*91f16700Schasinglulu */ 102*91f16700Schasinglulu bl plat_set_my_stack 103*91f16700Schasinglulu 104*91f16700Schasinglulu /* --------------------------------------------- 105*91f16700Schasinglulu * Initialize the stack protector canary before 106*91f16700Schasinglulu * any C code is called. 107*91f16700Schasinglulu * --------------------------------------------- 108*91f16700Schasinglulu */ 109*91f16700Schasinglulu#if STACK_PROTECTOR_ENABLED 110*91f16700Schasinglulu bl update_stack_protector_canary 111*91f16700Schasinglulu#endif 112*91f16700Schasinglulu 113*91f16700Schasinglulu /* --------------------------------------------- 114*91f16700Schasinglulu * Perform BL2 setup 115*91f16700Schasinglulu * --------------------------------------------- 116*91f16700Schasinglulu */ 117*91f16700Schasinglulu mov r0, r9 118*91f16700Schasinglulu mov r1, r10 119*91f16700Schasinglulu mov r2, r11 120*91f16700Schasinglulu mov r3, r12 121*91f16700Schasinglulu 122*91f16700Schasinglulu bl bl2_setup 123*91f16700Schasinglulu 124*91f16700Schasinglulu /* --------------------------------------------- 125*91f16700Schasinglulu * Jump to main function. 126*91f16700Schasinglulu * --------------------------------------------- 127*91f16700Schasinglulu */ 128*91f16700Schasinglulu bl bl2_main 129*91f16700Schasinglulu 130*91f16700Schasinglulu /* --------------------------------------------- 131*91f16700Schasinglulu * Should never reach this point. 132*91f16700Schasinglulu * --------------------------------------------- 133*91f16700Schasinglulu */ 134*91f16700Schasinglulu no_ret plat_panic_handler 135*91f16700Schasinglulu 136*91f16700Schasingluluendfunc bl2_entrypoint 137