14f6ad66aSAchin Gupta/* 29d93fc2fSAntonio Nino Diaz * Copyright (c) 2013-2019, 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 44*02b57943SJohn Tsichritzis * and data access alignment checks and disable 45*02b57943SJohn 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 51*02b57943SJohn Tsichritzis bic x0, x0, #SCTLR_DSSBS_BIT 52c10bd2ceSSandrine Bailleux msr sctlr_el1, x0 53c10bd2ceSSandrine Bailleux isb 54c10bd2ceSSandrine Bailleux 5565f546a1SSandrine Bailleux /* --------------------------------------------- 5654dc71e7SAchin Gupta * Invalidate the RW memory used by the BL2 5754dc71e7SAchin Gupta * image. This includes the data and NOBITS 5854dc71e7SAchin Gupta * sections. This is done to safeguard against 5954dc71e7SAchin Gupta * possible corruption of this memory by dirty 6054dc71e7SAchin Gupta * cache lines in a system cache as a result of 6154dc71e7SAchin Gupta * use by an earlier boot loader stage. 6254dc71e7SAchin Gupta * --------------------------------------------- 6354dc71e7SAchin Gupta */ 6454dc71e7SAchin Gupta adr x0, __RW_START__ 6554dc71e7SAchin Gupta adr x1, __RW_END__ 6654dc71e7SAchin Gupta sub x1, x1, x0 6754dc71e7SAchin Gupta bl inv_dcache_range 6854dc71e7SAchin Gupta 6954dc71e7SAchin Gupta /* --------------------------------------------- 7065f546a1SSandrine Bailleux * Zero out NOBITS sections. There are 2 of them: 7165f546a1SSandrine Bailleux * - the .bss section; 7265f546a1SSandrine Bailleux * - the coherent memory section. 7365f546a1SSandrine Bailleux * --------------------------------------------- 7465f546a1SSandrine Bailleux */ 75f1722b69SSoby Mathew adrp x0, __BSS_START__ 76f1722b69SSoby Mathew add x0, x0, :lo12:__BSS_START__ 77f1722b69SSoby Mathew adrp x1, __BSS_END__ 78f1722b69SSoby Mathew add x1, x1, :lo12:__BSS_END__ 79f1722b69SSoby Mathew sub x1, x1, x0 80308d359bSDouglas Raillard bl zeromem 8165f546a1SSandrine Bailleux 82ab8707e6SSoby Mathew#if USE_COHERENT_MEM 83f1722b69SSoby Mathew adrp x0, __COHERENT_RAM_START__ 84f1722b69SSoby Mathew add x0, x0, :lo12:__COHERENT_RAM_START__ 85f1722b69SSoby Mathew adrp x1, __COHERENT_RAM_END_UNALIGNED__ 86f1722b69SSoby Mathew add x1, x1, :lo12:__COHERENT_RAM_END_UNALIGNED__ 87f1722b69SSoby Mathew sub x1, x1, x0 88308d359bSDouglas Raillard bl zeromem 89ab8707e6SSoby Mathew#endif 9065f546a1SSandrine Bailleux 914f6ad66aSAchin Gupta /* -------------------------------------------- 92754a2b7aSAchin Gupta * Allocate a stack whose memory will be marked 93754a2b7aSAchin Gupta * as Normal-IS-WBWA when the MMU is enabled. 94754a2b7aSAchin Gupta * There is no risk of reading stale stack 95754a2b7aSAchin Gupta * memory after enabling the MMU as only the 96754a2b7aSAchin Gupta * primary cpu is running at the moment. 974f6ad66aSAchin Gupta * -------------------------------------------- 984f6ad66aSAchin Gupta */ 9985a181ceSSoby Mathew bl plat_set_my_stack 1004f6ad66aSAchin Gupta 1014f6ad66aSAchin Gupta /* --------------------------------------------- 10251faada7SDouglas Raillard * Initialize the stack protector canary before 10351faada7SDouglas Raillard * any C code is called. 10451faada7SDouglas Raillard * --------------------------------------------- 10551faada7SDouglas Raillard */ 10651faada7SDouglas Raillard#if STACK_PROTECTOR_ENABLED 10751faada7SDouglas Raillard bl update_stack_protector_canary 10851faada7SDouglas Raillard#endif 10951faada7SDouglas Raillard 11051faada7SDouglas Raillard /* --------------------------------------------- 1119d93fc2fSAntonio Nino Diaz * Perform BL2 setup 1124f6ad66aSAchin Gupta * --------------------------------------------- 1134f6ad66aSAchin Gupta */ 1145698c5b3SYatharth Kochar mov x0, x20 115a6f340feSSoby Mathew mov x1, x21 116a6f340feSSoby Mathew mov x2, x22 117a6f340feSSoby Mathew mov x3, x23 1189d93fc2fSAntonio Nino Diaz bl bl2_setup 119a6f340feSSoby Mathew 1209d93fc2fSAntonio Nino Diaz /* --------------------------------------------- 1219d93fc2fSAntonio Nino Diaz * Enable pointer authentication 1229d93fc2fSAntonio Nino Diaz * --------------------------------------------- 1239d93fc2fSAntonio Nino Diaz */ 1249d93fc2fSAntonio Nino Diaz#if ENABLE_PAUTH 1259d93fc2fSAntonio Nino Diaz mrs x0, sctlr_el1 1269d93fc2fSAntonio Nino Diaz orr x0, x0, #SCTLR_EnIA_BIT 1279d93fc2fSAntonio Nino Diaz msr sctlr_el1, x0 1289d93fc2fSAntonio Nino Diaz isb 1299d93fc2fSAntonio Nino Diaz#endif /* ENABLE_PAUTH */ 1304f6ad66aSAchin Gupta 1314f6ad66aSAchin Gupta /* --------------------------------------------- 1324f6ad66aSAchin Gupta * Jump to main function. 1334f6ad66aSAchin Gupta * --------------------------------------------- 1344f6ad66aSAchin Gupta */ 1354f6ad66aSAchin Gupta bl bl2_main 1361c3ea103SAntonio Nino Diaz 1371c3ea103SAntonio Nino Diaz /* --------------------------------------------- 1381c3ea103SAntonio Nino Diaz * Should never reach this point. 1391c3ea103SAntonio Nino Diaz * --------------------------------------------- 1401c3ea103SAntonio Nino Diaz */ 141a806dad5SJeenu Viswambharan no_ret plat_panic_handler 1421c3ea103SAntonio Nino Diaz 1438b779620SKévin Petitendfunc bl2_entrypoint 144