14f6ad66aSAchin Gupta/* 2*d158d425SBoyan Karatotev * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 54f6ad66aSAchin Gupta */ 64f6ad66aSAchin Gupta 7c10bd2ceSSandrine Bailleux#include <arch.h> 80a30cf54SAndrew Thoelke#include <asm_macros.S> 909d40e0eSAntonio Nino Diaz#include <common/bl_common.h> 104f6ad66aSAchin Gupta 114f6ad66aSAchin Gupta 124f6ad66aSAchin Gupta .globl bl2_entrypoint 134f6ad66aSAchin Gupta 144f6ad66aSAchin Gupta 154f6ad66aSAchin Gupta 160a30cf54SAndrew Thoelkefunc bl2_entrypoint 174f6ad66aSAchin Gupta /*--------------------------------------------- 18a6f340feSSoby Mathew * Save arguments x0 - x3 from BL1 for future 19a6f340feSSoby Mathew * use. 204f6ad66aSAchin Gupta * --------------------------------------------- 214f6ad66aSAchin Gupta */ 22a6f340feSSoby Mathew mov x20, x0 23a6f340feSSoby Mathew mov x21, x1 24a6f340feSSoby Mathew mov x22, x2 25a6f340feSSoby Mathew mov x23, x3 264f6ad66aSAchin Gupta 274f6ad66aSAchin Gupta /* --------------------------------------------- 28c10bd2ceSSandrine Bailleux * Set the exception vector to something sane. 29c10bd2ceSSandrine Bailleux * --------------------------------------------- 30c10bd2ceSSandrine Bailleux */ 31c10bd2ceSSandrine Bailleux adr x0, early_exceptions 32c10bd2ceSSandrine Bailleux msr vbar_el1, x0 330c8d4fefSAchin Gupta isb 340c8d4fefSAchin Gupta 350c8d4fefSAchin Gupta /* --------------------------------------------- 360c8d4fefSAchin Gupta * Enable the SError interrupt now that the 370c8d4fefSAchin Gupta * exception vectors have been setup. 380c8d4fefSAchin Gupta * --------------------------------------------- 390c8d4fefSAchin Gupta */ 400c8d4fefSAchin Gupta msr daifclr, #DAIF_ABT_BIT 41c10bd2ceSSandrine Bailleux 42c10bd2ceSSandrine Bailleux /* --------------------------------------------- 43ec3c1003SAchin Gupta * Enable the instruction cache, stack pointer 4402b57943SJohn Tsichritzis * and data access alignment checks and disable 4502b57943SJohn Tsichritzis * speculative loads. 46c10bd2ceSSandrine Bailleux * --------------------------------------------- 47c10bd2ceSSandrine Bailleux */ 48ec3c1003SAchin Gupta mov x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT) 49c10bd2ceSSandrine Bailleux mrs x0, sctlr_el1 50ec3c1003SAchin Gupta orr x0, x0, x1 5110ecd580SBoyan Karatotev#if ENABLE_BTI 5210ecd580SBoyan Karatotev /* Enable PAC branch type compatibility */ 5310ecd580SBoyan Karatotev bic x0, x0, #(SCTLR_BT0_BIT | SCTLR_BT1_BIT) 5410ecd580SBoyan Karatotev#endif 5502b57943SJohn Tsichritzis bic x0, x0, #SCTLR_DSSBS_BIT 56c10bd2ceSSandrine Bailleux msr sctlr_el1, x0 57c10bd2ceSSandrine Bailleux isb 58c10bd2ceSSandrine Bailleux 5965f546a1SSandrine Bailleux /* --------------------------------------------- 6054dc71e7SAchin Gupta * Invalidate the RW memory used by the BL2 6154dc71e7SAchin Gupta * image. This includes the data and NOBITS 6254dc71e7SAchin Gupta * sections. This is done to safeguard against 6354dc71e7SAchin Gupta * possible corruption of this memory by dirty 6454dc71e7SAchin Gupta * cache lines in a system cache as a result of 6554dc71e7SAchin Gupta * use by an earlier boot loader stage. 6654dc71e7SAchin Gupta * --------------------------------------------- 6754dc71e7SAchin Gupta */ 6854dc71e7SAchin Gupta adr x0, __RW_START__ 6954dc71e7SAchin Gupta adr x1, __RW_END__ 7054dc71e7SAchin Gupta sub x1, x1, x0 7154dc71e7SAchin Gupta bl inv_dcache_range 7254dc71e7SAchin Gupta 7354dc71e7SAchin Gupta /* --------------------------------------------- 7465f546a1SSandrine Bailleux * Zero out NOBITS sections. There are 2 of them: 7565f546a1SSandrine Bailleux * - the .bss section; 7665f546a1SSandrine Bailleux * - the coherent memory section. 7765f546a1SSandrine Bailleux * --------------------------------------------- 7865f546a1SSandrine Bailleux */ 79f1722b69SSoby Mathew adrp x0, __BSS_START__ 80f1722b69SSoby Mathew add x0, x0, :lo12:__BSS_START__ 81f1722b69SSoby Mathew adrp x1, __BSS_END__ 82f1722b69SSoby Mathew add x1, x1, :lo12:__BSS_END__ 83f1722b69SSoby Mathew sub x1, x1, x0 84308d359bSDouglas Raillard bl zeromem 8565f546a1SSandrine Bailleux 86ab8707e6SSoby Mathew#if USE_COHERENT_MEM 87f1722b69SSoby Mathew adrp x0, __COHERENT_RAM_START__ 88f1722b69SSoby Mathew add x0, x0, :lo12:__COHERENT_RAM_START__ 89f1722b69SSoby Mathew adrp x1, __COHERENT_RAM_END_UNALIGNED__ 90f1722b69SSoby Mathew add x1, x1, :lo12:__COHERENT_RAM_END_UNALIGNED__ 91f1722b69SSoby Mathew sub x1, x1, x0 92308d359bSDouglas Raillard bl zeromem 93ab8707e6SSoby Mathew#endif 9465f546a1SSandrine Bailleux 954f6ad66aSAchin Gupta /* -------------------------------------------- 96754a2b7aSAchin Gupta * Allocate a stack whose memory will be marked 97754a2b7aSAchin Gupta * as Normal-IS-WBWA when the MMU is enabled. 98754a2b7aSAchin Gupta * There is no risk of reading stale stack 99754a2b7aSAchin Gupta * memory after enabling the MMU as only the 100754a2b7aSAchin Gupta * primary cpu is running at the moment. 1014f6ad66aSAchin Gupta * -------------------------------------------- 1024f6ad66aSAchin Gupta */ 10385a181ceSSoby Mathew bl plat_set_my_stack 1044f6ad66aSAchin Gupta 1054f6ad66aSAchin Gupta /* --------------------------------------------- 10651faada7SDouglas Raillard * Initialize the stack protector canary before 10751faada7SDouglas Raillard * any C code is called. 10851faada7SDouglas Raillard * --------------------------------------------- 10951faada7SDouglas Raillard */ 11051faada7SDouglas Raillard#if STACK_PROTECTOR_ENABLED 11151faada7SDouglas Raillard bl update_stack_protector_canary 11251faada7SDouglas Raillard#endif 11351faada7SDouglas Raillard 11451faada7SDouglas Raillard /* --------------------------------------------- 1159d93fc2fSAntonio Nino Diaz * Perform BL2 setup 1164f6ad66aSAchin Gupta * --------------------------------------------- 1174f6ad66aSAchin Gupta */ 1185698c5b3SYatharth Kochar mov x0, x20 119a6f340feSSoby Mathew mov x1, x21 120a6f340feSSoby Mathew mov x2, x22 121a6f340feSSoby Mathew mov x3, x23 1224f6ad66aSAchin Gupta 1234f6ad66aSAchin Gupta /* --------------------------------------------- 1244f6ad66aSAchin Gupta * Jump to main function. 1254f6ad66aSAchin Gupta * --------------------------------------------- 1264f6ad66aSAchin Gupta */ 1274f6ad66aSAchin Gupta bl bl2_main 1281c3ea103SAntonio Nino Diaz 1291c3ea103SAntonio Nino Diaz /* --------------------------------------------- 1301c3ea103SAntonio Nino Diaz * Should never reach this point. 1311c3ea103SAntonio Nino Diaz * --------------------------------------------- 1321c3ea103SAntonio Nino Diaz */ 133a806dad5SJeenu Viswambharan no_ret plat_panic_handler 1341c3ea103SAntonio Nino Diaz 1358b779620SKévin Petitendfunc bl2_entrypoint 136