1f5478dedSAntonio Nino Diaz/* 2fb4f511fSYann Gautier * Copyright (c) 2016-2021, ARM Limited and Contributors. All rights reserved. 3f5478dedSAntonio Nino Diaz * 4f5478dedSAntonio Nino Diaz * SPDX-License-Identifier: BSD-3-Clause 5f5478dedSAntonio Nino Diaz */ 6f5478dedSAntonio Nino Diaz 7f5478dedSAntonio Nino Diaz#ifndef EL3_COMMON_MACROS_S 8f5478dedSAntonio Nino Diaz#define EL3_COMMON_MACROS_S 9f5478dedSAntonio Nino Diaz 10f5478dedSAntonio Nino Diaz#include <arch.h> 11f5478dedSAntonio Nino Diaz#include <asm_macros.S> 12f5478dedSAntonio Nino Diaz#include <assert_macros.S> 134324a14bSYann Gautier#include <lib/xlat_tables/xlat_tables_defs.h> 144324a14bSYann Gautier 154324a14bSYann Gautier#define PAGE_START_MASK ~(PAGE_SIZE_MASK) 16f5478dedSAntonio Nino Diaz 17f5478dedSAntonio Nino Diaz /* 18f5478dedSAntonio Nino Diaz * Helper macro to initialise EL3 registers we care about. 19f5478dedSAntonio Nino Diaz */ 20f5478dedSAntonio Nino Diaz .macro el3_arch_init_common 21f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 22f5478dedSAntonio Nino Diaz * SCTLR has already been initialised - read current value before 23f5478dedSAntonio Nino Diaz * modifying. 24f5478dedSAntonio Nino Diaz * 25f5478dedSAntonio Nino Diaz * SCTLR.I: Enable the instruction cache. 26f5478dedSAntonio Nino Diaz * 27f5478dedSAntonio Nino Diaz * SCTLR.A: Enable Alignment fault checking. All instructions that load 28f5478dedSAntonio Nino Diaz * or store one or more registers have an alignment check that the 29f5478dedSAntonio Nino Diaz * address being accessed is aligned to the size of the data element(s) 30f5478dedSAntonio Nino Diaz * being accessed. 31f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 32f5478dedSAntonio Nino Diaz */ 33f5478dedSAntonio Nino Diaz ldr r1, =(SCTLR_I_BIT | SCTLR_A_BIT) 34f5478dedSAntonio Nino Diaz ldcopr r0, SCTLR 35f5478dedSAntonio Nino Diaz orr r0, r0, r1 36f5478dedSAntonio Nino Diaz stcopr r0, SCTLR 37f5478dedSAntonio Nino Diaz isb 38f5478dedSAntonio Nino Diaz 39f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 40f5478dedSAntonio Nino Diaz * Initialise SCR, setting all fields rather than relying on the hw. 41f5478dedSAntonio Nino Diaz * 42f5478dedSAntonio Nino Diaz * SCR.SIF: Enabled so that Secure state instruction fetches from 43f5478dedSAntonio Nino Diaz * Non-secure memory are not permitted. 44f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 45f5478dedSAntonio Nino Diaz */ 46f5478dedSAntonio Nino Diaz ldr r0, =(SCR_RESET_VAL | SCR_SIF_BIT) 47f5478dedSAntonio Nino Diaz stcopr r0, SCR 48f5478dedSAntonio Nino Diaz 49f5478dedSAntonio Nino Diaz /* ----------------------------------------------------- 50f5478dedSAntonio Nino Diaz * Enable the Asynchronous data abort now that the 51f5478dedSAntonio Nino Diaz * exception vectors have been setup. 52f5478dedSAntonio Nino Diaz * ----------------------------------------------------- 53f5478dedSAntonio Nino Diaz */ 54f5478dedSAntonio Nino Diaz cpsie a 55f5478dedSAntonio Nino Diaz isb 56f5478dedSAntonio Nino Diaz 57f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 58f5478dedSAntonio Nino Diaz * Initialise NSACR, setting all the fields, except for the 59f5478dedSAntonio Nino Diaz * IMPLEMENTATION DEFINED field, rather than relying on the hw. Some 60f5478dedSAntonio Nino Diaz * fields are architecturally UNKNOWN on reset. 61f5478dedSAntonio Nino Diaz * 62f5478dedSAntonio Nino Diaz * NSACR_ENABLE_FP_ACCESS: Represents NSACR.cp11 and NSACR.cp10. The 63f5478dedSAntonio Nino Diaz * cp11 field is ignored, but is set to same value as cp10. The cp10 64f5478dedSAntonio Nino Diaz * field is set to allow access to Advanced SIMD and floating point 65f5478dedSAntonio Nino Diaz * features from both Security states. 66*2031d616SManish V Badarkhe * 67*2031d616SManish V Badarkhe * NSACR.NSTRCDIS: When system register trace implemented, Set to one 68*2031d616SManish V Badarkhe * so that NS System register accesses to all implemented trace 69*2031d616SManish V Badarkhe * registers are disabled. 70*2031d616SManish V Badarkhe * When system register trace is not implemented, this bit is RES0 and 71*2031d616SManish V Badarkhe * hence set to zero. 72f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 73f5478dedSAntonio Nino Diaz */ 74f5478dedSAntonio Nino Diaz ldcopr r0, NSACR 75f5478dedSAntonio Nino Diaz and r0, r0, #NSACR_IMP_DEF_MASK 76f5478dedSAntonio Nino Diaz orr r0, r0, #(NSACR_RESET_VAL | NSACR_ENABLE_FP_ACCESS) 77*2031d616SManish V Badarkhe ldcopr r1, ID_DFR0 78*2031d616SManish V Badarkhe ubfx r1, r1, #ID_DFR0_COPTRC_SHIFT, #ID_DFR0_COPTRC_LENGTH 79*2031d616SManish V Badarkhe cmp r1, #ID_DFR0_COPTRC_SUPPORTED 80*2031d616SManish V Badarkhe bne 1f 81*2031d616SManish V Badarkhe orr r0, r0, #NSTRCDIS_BIT 82*2031d616SManish V Badarkhe1: 83f5478dedSAntonio Nino Diaz stcopr r0, NSACR 84f5478dedSAntonio Nino Diaz isb 85f5478dedSAntonio Nino Diaz 86f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 87f5478dedSAntonio Nino Diaz * Initialise CPACR, setting all fields rather than relying on hw. Some 88f5478dedSAntonio Nino Diaz * fields are architecturally UNKNOWN on reset. 89f5478dedSAntonio Nino Diaz * 90f5478dedSAntonio Nino Diaz * CPACR.TRCDIS: Trap control for PL0 and PL1 System register accesses 91f5478dedSAntonio Nino Diaz * to trace registers. Set to zero to allow access. 92f5478dedSAntonio Nino Diaz * 93f5478dedSAntonio Nino Diaz * CPACR_ENABLE_FP_ACCESS: Represents CPACR.cp11 and CPACR.cp10. The 94f5478dedSAntonio Nino Diaz * cp11 field is ignored, but is set to same value as cp10. The cp10 95f5478dedSAntonio Nino Diaz * field is set to allow full access from PL0 and PL1 to floating-point 96f5478dedSAntonio Nino Diaz * and Advanced SIMD features. 97f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 98f5478dedSAntonio Nino Diaz */ 99f5478dedSAntonio Nino Diaz ldr r0, =((CPACR_RESET_VAL | CPACR_ENABLE_FP_ACCESS) & ~(TRCDIS_BIT)) 100f5478dedSAntonio Nino Diaz stcopr r0, CPACR 101f5478dedSAntonio Nino Diaz isb 102f5478dedSAntonio Nino Diaz 103f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 104f5478dedSAntonio Nino Diaz * Initialise FPEXC, setting all fields rather than relying on hw. Some 105f5478dedSAntonio Nino Diaz * fields are architecturally UNKNOWN on reset and are set to zero 106f5478dedSAntonio Nino Diaz * except for field(s) listed below. 107f5478dedSAntonio Nino Diaz * 108f5478dedSAntonio Nino Diaz * FPEXC.EN: Enable access to Advanced SIMD and floating point features 109f5478dedSAntonio Nino Diaz * from all exception levels. 110fbd8f6c8SManish Pandey * 111fbd8f6c8SManish Pandey * __SOFTFP__: Predefined macro exposed by soft-float toolchain. 112fbd8f6c8SManish Pandey * ARMv7 and Cortex-A32(ARMv8/aarch32) has both soft-float and 113fbd8f6c8SManish Pandey * hard-float variants of toolchain, avoid compiling below code with 114fbd8f6c8SManish Pandey * soft-float toolchain as "vmsr" instruction will not be recognized. 115f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 116f5478dedSAntonio Nino Diaz */ 117fbd8f6c8SManish Pandey#if ((ARM_ARCH_MAJOR > 7) || defined(ARMV7_SUPPORTS_VFP)) && !(__SOFTFP__) 118f5478dedSAntonio Nino Diaz ldr r0, =(FPEXC_RESET_VAL | FPEXC_EN_BIT) 119f5478dedSAntonio Nino Diaz vmsr FPEXC, r0 120f5478dedSAntonio Nino Diaz isb 1218f73663bSUsama Arif#endif 122f5478dedSAntonio Nino Diaz 123f5478dedSAntonio Nino Diaz#if (ARM_ARCH_MAJOR > 7) 124f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 125f5478dedSAntonio Nino Diaz * Initialise SDCR, setting all the fields rather than relying on hw. 126f5478dedSAntonio Nino Diaz * 127f5478dedSAntonio Nino Diaz * SDCR.SPD: Disable AArch32 privileged debug. Debug exceptions from 128f5478dedSAntonio Nino Diaz * Secure EL1 are disabled. 129ed4fc6f0SAntonio Nino Diaz * 130c3e8b0beSAlexei Fedorov * SDCR.SCCD: Set to one so that cycle counting by PMCCNTR is prohibited 131c3e8b0beSAlexei Fedorov * in Secure state. This bit is RES0 in versions of the architecture 132ed4fc6f0SAntonio Nino Diaz * earlier than ARMv8.5, setting it to 1 doesn't have any effect on 133ed4fc6f0SAntonio Nino Diaz * them. 134f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 135f5478dedSAntonio Nino Diaz */ 136ed4fc6f0SAntonio Nino Diaz ldr r0, =(SDCR_RESET_VAL | SDCR_SPD(SDCR_SPD_DISABLE) | SDCR_SCCD_BIT) 137f5478dedSAntonio Nino Diaz stcopr r0, SDCR 138c3e8b0beSAlexei Fedorov 139c3e8b0beSAlexei Fedorov /* --------------------------------------------------------------------- 140c3e8b0beSAlexei Fedorov * Initialise PMCR, setting all fields rather than relying 141c3e8b0beSAlexei Fedorov * on hw. Some fields are architecturally UNKNOWN on reset. 142c3e8b0beSAlexei Fedorov * 143c3e8b0beSAlexei Fedorov * PMCR.LP: Set to one so that event counter overflow, that 144c3e8b0beSAlexei Fedorov * is recorded in PMOVSCLR[0-30], occurs on the increment 145c3e8b0beSAlexei Fedorov * that changes PMEVCNTR<n>[63] from 1 to 0, when ARMv8.5-PMU 146c3e8b0beSAlexei Fedorov * is implemented. This bit is RES0 in versions of the architecture 147c3e8b0beSAlexei Fedorov * earlier than ARMv8.5, setting it to 1 doesn't have any effect 148c3e8b0beSAlexei Fedorov * on them. 149c3e8b0beSAlexei Fedorov * This bit is Reserved, UNK/SBZP in ARMv7. 150c3e8b0beSAlexei Fedorov * 151c3e8b0beSAlexei Fedorov * PMCR.LC: Set to one so that cycle counter overflow, that 152c3e8b0beSAlexei Fedorov * is recorded in PMOVSCLR[31], occurs on the increment 153c3e8b0beSAlexei Fedorov * that changes PMCCNTR[63] from 1 to 0. 154c3e8b0beSAlexei Fedorov * This bit is Reserved, UNK/SBZP in ARMv7. 155c3e8b0beSAlexei Fedorov * 156c3e8b0beSAlexei Fedorov * PMCR.DP: Set to one to prohibit cycle counting whilst in Secure mode. 157c3e8b0beSAlexei Fedorov * --------------------------------------------------------------------- 158c3e8b0beSAlexei Fedorov */ 159c3e8b0beSAlexei Fedorov ldr r0, =(PMCR_RESET_VAL | PMCR_DP_BIT | PMCR_LC_BIT | \ 160c3e8b0beSAlexei Fedorov PMCR_LP_BIT) 161c3e8b0beSAlexei Fedorov#else 162c3e8b0beSAlexei Fedorov ldr r0, =(PMCR_RESET_VAL | PMCR_DP_BIT) 163f5478dedSAntonio Nino Diaz#endif 164c3e8b0beSAlexei Fedorov stcopr r0, PMCR 165f5478dedSAntonio Nino Diaz 166f5478dedSAntonio Nino Diaz /* 167f5478dedSAntonio Nino Diaz * If Data Independent Timing (DIT) functionality is implemented, 168f5478dedSAntonio Nino Diaz * always enable DIT in EL3 169f5478dedSAntonio Nino Diaz */ 170f5478dedSAntonio Nino Diaz ldcopr r0, ID_PFR0 171f5478dedSAntonio Nino Diaz and r0, r0, #(ID_PFR0_DIT_MASK << ID_PFR0_DIT_SHIFT) 172f5478dedSAntonio Nino Diaz cmp r0, #ID_PFR0_DIT_SUPPORTED 173f5478dedSAntonio Nino Diaz bne 1f 174f5478dedSAntonio Nino Diaz mrs r0, cpsr 175f5478dedSAntonio Nino Diaz orr r0, r0, #CPSR_DIT_BIT 176f5478dedSAntonio Nino Diaz msr cpsr_cxsf, r0 177f5478dedSAntonio Nino Diaz1: 178f5478dedSAntonio Nino Diaz .endm 179f5478dedSAntonio Nino Diaz 180f5478dedSAntonio Nino Diaz/* ----------------------------------------------------------------------------- 181f5478dedSAntonio Nino Diaz * This is the super set of actions that need to be performed during a cold boot 182f5478dedSAntonio Nino Diaz * or a warm boot in EL3. This code is shared by BL1 and BL32 (SP_MIN). 183f5478dedSAntonio Nino Diaz * 184f5478dedSAntonio Nino Diaz * This macro will always perform reset handling, architectural initialisations 185f5478dedSAntonio Nino Diaz * and stack setup. The rest of the actions are optional because they might not 186f5478dedSAntonio Nino Diaz * be needed, depending on the context in which this macro is called. This is 187f5478dedSAntonio Nino Diaz * why this macro is parameterised ; each parameter allows to enable/disable 188f5478dedSAntonio Nino Diaz * some actions. 189f5478dedSAntonio Nino Diaz * 190f5478dedSAntonio Nino Diaz * _init_sctlr: 191f5478dedSAntonio Nino Diaz * Whether the macro needs to initialise the SCTLR register including 192f5478dedSAntonio Nino Diaz * configuring the endianness of data accesses. 193f5478dedSAntonio Nino Diaz * 194f5478dedSAntonio Nino Diaz * _warm_boot_mailbox: 195f5478dedSAntonio Nino Diaz * Whether the macro needs to detect the type of boot (cold/warm). The 196f5478dedSAntonio Nino Diaz * detection is based on the platform entrypoint address : if it is zero 197f5478dedSAntonio Nino Diaz * then it is a cold boot, otherwise it is a warm boot. In the latter case, 198f5478dedSAntonio Nino Diaz * this macro jumps on the platform entrypoint address. 199f5478dedSAntonio Nino Diaz * 200f5478dedSAntonio Nino Diaz * _secondary_cold_boot: 201f5478dedSAntonio Nino Diaz * Whether the macro needs to identify the CPU that is calling it: primary 202f5478dedSAntonio Nino Diaz * CPU or secondary CPU. The primary CPU will be allowed to carry on with 203f5478dedSAntonio Nino Diaz * the platform initialisations, while the secondaries will be put in a 204f5478dedSAntonio Nino Diaz * platform-specific state in the meantime. 205f5478dedSAntonio Nino Diaz * 206f5478dedSAntonio Nino Diaz * If the caller knows this macro will only be called by the primary CPU 207f5478dedSAntonio Nino Diaz * then this parameter can be defined to 0 to skip this step. 208f5478dedSAntonio Nino Diaz * 209f5478dedSAntonio Nino Diaz * _init_memory: 210f5478dedSAntonio Nino Diaz * Whether the macro needs to initialise the memory. 211f5478dedSAntonio Nino Diaz * 212f5478dedSAntonio Nino Diaz * _init_c_runtime: 213f5478dedSAntonio Nino Diaz * Whether the macro needs to initialise the C runtime environment. 214f5478dedSAntonio Nino Diaz * 215f5478dedSAntonio Nino Diaz * _exception_vectors: 216f5478dedSAntonio Nino Diaz * Address of the exception vectors to program in the VBAR_EL3 register. 2174324a14bSYann Gautier * 2184324a14bSYann Gautier * _pie_fixup_size: 2194324a14bSYann Gautier * Size of memory region to fixup Global Descriptor Table (GDT). 2204324a14bSYann Gautier * 2214324a14bSYann Gautier * A non-zero value is expected when firmware needs GDT to be fixed-up. 2224324a14bSYann Gautier * 223f5478dedSAntonio Nino Diaz * ----------------------------------------------------------------------------- 224f5478dedSAntonio Nino Diaz */ 225f5478dedSAntonio Nino Diaz .macro el3_entrypoint_common \ 226f5478dedSAntonio Nino Diaz _init_sctlr, _warm_boot_mailbox, _secondary_cold_boot, \ 2274324a14bSYann Gautier _init_memory, _init_c_runtime, _exception_vectors, \ 2284324a14bSYann Gautier _pie_fixup_size 229f5478dedSAntonio Nino Diaz 230f5478dedSAntonio Nino Diaz /* Make sure we are in Secure Mode */ 231f5478dedSAntonio Nino Diaz#if ENABLE_ASSERTIONS 232f5478dedSAntonio Nino Diaz ldcopr r0, SCR 233f5478dedSAntonio Nino Diaz tst r0, #SCR_NS_BIT 234f5478dedSAntonio Nino Diaz ASM_ASSERT(eq) 235f5478dedSAntonio Nino Diaz#endif 236f5478dedSAntonio Nino Diaz 237f5478dedSAntonio Nino Diaz .if \_init_sctlr 238f5478dedSAntonio Nino Diaz /* ------------------------------------------------------------- 239f5478dedSAntonio Nino Diaz * This is the initialisation of SCTLR and so must ensure that 240f5478dedSAntonio Nino Diaz * all fields are explicitly set rather than relying on hw. Some 241f5478dedSAntonio Nino Diaz * fields reset to an IMPLEMENTATION DEFINED value. 242f5478dedSAntonio Nino Diaz * 243f5478dedSAntonio Nino Diaz * SCTLR.TE: Set to zero so that exceptions to an Exception 244f5478dedSAntonio Nino Diaz * Level executing at PL1 are taken to A32 state. 245f5478dedSAntonio Nino Diaz * 246f5478dedSAntonio Nino Diaz * SCTLR.EE: Set the CPU endianness before doing anything that 247f5478dedSAntonio Nino Diaz * might involve memory reads or writes. Set to zero to select 248f5478dedSAntonio Nino Diaz * Little Endian. 249f5478dedSAntonio Nino Diaz * 250f5478dedSAntonio Nino Diaz * SCTLR.V: Set to zero to select the normal exception vectors 251f5478dedSAntonio Nino Diaz * with base address held in VBAR. 252f5478dedSAntonio Nino Diaz * 253f5478dedSAntonio Nino Diaz * SCTLR.DSSBS: Set to zero to disable speculation store bypass 254f5478dedSAntonio Nino Diaz * safe behaviour upon exception entry to EL3. 255f5478dedSAntonio Nino Diaz * ------------------------------------------------------------- 256f5478dedSAntonio Nino Diaz */ 257f5478dedSAntonio Nino Diaz ldr r0, =(SCTLR_RESET_VAL & ~(SCTLR_TE_BIT | SCTLR_EE_BIT | \ 258f5478dedSAntonio Nino Diaz SCTLR_V_BIT | SCTLR_DSSBS_BIT)) 259f5478dedSAntonio Nino Diaz stcopr r0, SCTLR 260f5478dedSAntonio Nino Diaz isb 261f5478dedSAntonio Nino Diaz .endif /* _init_sctlr */ 262f5478dedSAntonio Nino Diaz 263f5478dedSAntonio Nino Diaz /* Switch to monitor mode */ 264f5478dedSAntonio Nino Diaz cps #MODE32_mon 265f5478dedSAntonio Nino Diaz isb 266f5478dedSAntonio Nino Diaz 2670063dd17SJavier Almansa Sobrino#if DISABLE_MTPMU 2680063dd17SJavier Almansa Sobrino bl mtpmu_disable 2690063dd17SJavier Almansa Sobrino#endif 2700063dd17SJavier Almansa Sobrino 271f5478dedSAntonio Nino Diaz .if \_warm_boot_mailbox 272f5478dedSAntonio Nino Diaz /* ------------------------------------------------------------- 273f5478dedSAntonio Nino Diaz * This code will be executed for both warm and cold resets. 274f5478dedSAntonio Nino Diaz * Now is the time to distinguish between the two. 275f5478dedSAntonio Nino Diaz * Query the platform entrypoint address and if it is not zero 276f5478dedSAntonio Nino Diaz * then it means it is a warm boot so jump to this address. 277f5478dedSAntonio Nino Diaz * ------------------------------------------------------------- 278f5478dedSAntonio Nino Diaz */ 279f5478dedSAntonio Nino Diaz bl plat_get_my_entrypoint 280f5478dedSAntonio Nino Diaz cmp r0, #0 281f5478dedSAntonio Nino Diaz bxne r0 282f5478dedSAntonio Nino Diaz .endif /* _warm_boot_mailbox */ 283f5478dedSAntonio Nino Diaz 2844324a14bSYann Gautier .if \_pie_fixup_size 2854324a14bSYann Gautier#if ENABLE_PIE 2864324a14bSYann Gautier /* 2874324a14bSYann Gautier * ------------------------------------------------------------ 2884324a14bSYann Gautier * If PIE is enabled fixup the Global descriptor Table only 2894324a14bSYann Gautier * once during primary core cold boot path. 2904324a14bSYann Gautier * 2914324a14bSYann Gautier * Compile time base address, required for fixup, is calculated 2924324a14bSYann Gautier * using "pie_fixup" label present within first page. 2934324a14bSYann Gautier * ------------------------------------------------------------ 2944324a14bSYann Gautier */ 2954324a14bSYann Gautier pie_fixup: 2964324a14bSYann Gautier ldr r0, =pie_fixup 2974324a14bSYann Gautier ldr r1, =PAGE_START_MASK 2984324a14bSYann Gautier and r0, r0, r1 2994324a14bSYann Gautier mov_imm r1, \_pie_fixup_size 3004324a14bSYann Gautier add r1, r1, r0 3014324a14bSYann Gautier bl fixup_gdt_reloc 3024324a14bSYann Gautier#endif /* ENABLE_PIE */ 3034324a14bSYann Gautier .endif /* _pie_fixup_size */ 3044324a14bSYann Gautier 305f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 306f5478dedSAntonio Nino Diaz * Set the exception vectors (VBAR/MVBAR). 307f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 308f5478dedSAntonio Nino Diaz */ 309f5478dedSAntonio Nino Diaz ldr r0, =\_exception_vectors 310f5478dedSAntonio Nino Diaz stcopr r0, VBAR 311f5478dedSAntonio Nino Diaz stcopr r0, MVBAR 312f5478dedSAntonio Nino Diaz isb 313f5478dedSAntonio Nino Diaz 314f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 315f5478dedSAntonio Nino Diaz * It is a cold boot. 316f5478dedSAntonio Nino Diaz * Perform any processor specific actions upon reset e.g. cache, TLB 317f5478dedSAntonio Nino Diaz * invalidations etc. 318f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 319f5478dedSAntonio Nino Diaz */ 320f5478dedSAntonio Nino Diaz bl reset_handler 321f5478dedSAntonio Nino Diaz 322f5478dedSAntonio Nino Diaz el3_arch_init_common 323f5478dedSAntonio Nino Diaz 324f5478dedSAntonio Nino Diaz .if \_secondary_cold_boot 325f5478dedSAntonio Nino Diaz /* ------------------------------------------------------------- 326f5478dedSAntonio Nino Diaz * Check if this is a primary or secondary CPU cold boot. 327f5478dedSAntonio Nino Diaz * The primary CPU will set up the platform while the 328f5478dedSAntonio Nino Diaz * secondaries are placed in a platform-specific state until the 329f5478dedSAntonio Nino Diaz * primary CPU performs the necessary actions to bring them out 330f5478dedSAntonio Nino Diaz * of that state and allows entry into the OS. 331f5478dedSAntonio Nino Diaz * ------------------------------------------------------------- 332f5478dedSAntonio Nino Diaz */ 333f5478dedSAntonio Nino Diaz bl plat_is_my_cpu_primary 334f5478dedSAntonio Nino Diaz cmp r0, #0 335f5478dedSAntonio Nino Diaz bne do_primary_cold_boot 336f5478dedSAntonio Nino Diaz 337f5478dedSAntonio Nino Diaz /* This is a cold boot on a secondary CPU */ 338f5478dedSAntonio Nino Diaz bl plat_secondary_cold_boot_setup 339f5478dedSAntonio Nino Diaz /* plat_secondary_cold_boot_setup() is not supposed to return */ 340f5478dedSAntonio Nino Diaz no_ret plat_panic_handler 341f5478dedSAntonio Nino Diaz 342f5478dedSAntonio Nino Diaz do_primary_cold_boot: 343f5478dedSAntonio Nino Diaz .endif /* _secondary_cold_boot */ 344f5478dedSAntonio Nino Diaz 345f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 346f5478dedSAntonio Nino Diaz * Initialize memory now. Secondary CPU initialization won't get to this 347f5478dedSAntonio Nino Diaz * point. 348f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 349f5478dedSAntonio Nino Diaz */ 350f5478dedSAntonio Nino Diaz 351f5478dedSAntonio Nino Diaz .if \_init_memory 352f5478dedSAntonio Nino Diaz bl platform_mem_init 353f5478dedSAntonio Nino Diaz .endif /* _init_memory */ 354f5478dedSAntonio Nino Diaz 355f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 356f5478dedSAntonio Nino Diaz * Init C runtime environment: 357f5478dedSAntonio Nino Diaz * - Zero-initialise the NOBITS sections. There are 2 of them: 358f5478dedSAntonio Nino Diaz * - the .bss section; 359f5478dedSAntonio Nino Diaz * - the coherent memory section (if any). 360f5478dedSAntonio Nino Diaz * - Relocate the data section from ROM to RAM, if required. 361f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 362f5478dedSAntonio Nino Diaz */ 363f5478dedSAntonio Nino Diaz .if \_init_c_runtime 364f5478dedSAntonio Nino Diaz#if defined(IMAGE_BL32) || (defined(IMAGE_BL2) && BL2_AT_EL3) 365f5478dedSAntonio Nino Diaz /* ----------------------------------------------------------------- 366f5478dedSAntonio Nino Diaz * Invalidate the RW memory used by the image. This 367f5478dedSAntonio Nino Diaz * includes the data and NOBITS sections. This is done to 368f5478dedSAntonio Nino Diaz * safeguard against possible corruption of this memory by 369f5478dedSAntonio Nino Diaz * dirty cache lines in a system cache as a result of use by 370f5478dedSAntonio Nino Diaz * an earlier boot loader stage. 371f5478dedSAntonio Nino Diaz * ----------------------------------------------------------------- 372f5478dedSAntonio Nino Diaz */ 373f5478dedSAntonio Nino Diaz ldr r0, =__RW_START__ 374f5478dedSAntonio Nino Diaz ldr r1, =__RW_END__ 375f5478dedSAntonio Nino Diaz sub r1, r1, r0 376f5478dedSAntonio Nino Diaz bl inv_dcache_range 377f5478dedSAntonio Nino Diaz#endif 378f5478dedSAntonio Nino Diaz 37930f31005SYann Gautier /* 38030f31005SYann Gautier * zeromem uses r12 whereas it is used to save previous BL arg3, 38130f31005SYann Gautier * save it in r7 38230f31005SYann Gautier */ 38330f31005SYann Gautier mov r7, r12 384f5478dedSAntonio Nino Diaz ldr r0, =__BSS_START__ 385fb4f511fSYann Gautier ldr r1, =__BSS_END__ 386fb4f511fSYann Gautier sub r1, r1, r0 387f5478dedSAntonio Nino Diaz bl zeromem 388f5478dedSAntonio Nino Diaz 389f5478dedSAntonio Nino Diaz#if USE_COHERENT_MEM 390f5478dedSAntonio Nino Diaz ldr r0, =__COHERENT_RAM_START__ 391fb4f511fSYann Gautier ldr r1, =__COHERENT_RAM_END_UNALIGNED__ 392fb4f511fSYann Gautier sub r1, r1, r0 393f5478dedSAntonio Nino Diaz bl zeromem 394f5478dedSAntonio Nino Diaz#endif 395f5478dedSAntonio Nino Diaz 39630f31005SYann Gautier /* Restore r12 */ 39730f31005SYann Gautier mov r12, r7 39830f31005SYann Gautier 3990a12302cSLionel Debieve#if defined(IMAGE_BL1) || (defined(IMAGE_BL2) && BL2_AT_EL3 && BL2_IN_XIP_MEM) 400f5478dedSAntonio Nino Diaz /* ----------------------------------------------------- 401f5478dedSAntonio Nino Diaz * Copy data from ROM to RAM. 402f5478dedSAntonio Nino Diaz * ----------------------------------------------------- 403f5478dedSAntonio Nino Diaz */ 404f5478dedSAntonio Nino Diaz ldr r0, =__DATA_RAM_START__ 405f5478dedSAntonio Nino Diaz ldr r1, =__DATA_ROM_START__ 406fb4f511fSYann Gautier ldr r2, =__DATA_RAM_END__ 407fb4f511fSYann Gautier sub r2, r2, r0 408f5478dedSAntonio Nino Diaz bl memcpy4 409f5478dedSAntonio Nino Diaz#endif 410f5478dedSAntonio Nino Diaz .endif /* _init_c_runtime */ 411f5478dedSAntonio Nino Diaz 412f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 413f5478dedSAntonio Nino Diaz * Allocate a stack whose memory will be marked as Normal-IS-WBWA when 414f5478dedSAntonio Nino Diaz * the MMU is enabled. There is no risk of reading stale stack memory 415f5478dedSAntonio Nino Diaz * after enabling the MMU as only the primary CPU is running at the 416f5478dedSAntonio Nino Diaz * moment. 417f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 418f5478dedSAntonio Nino Diaz */ 419f5478dedSAntonio Nino Diaz bl plat_set_my_stack 420f5478dedSAntonio Nino Diaz 421f5478dedSAntonio Nino Diaz#if STACK_PROTECTOR_ENABLED 422f5478dedSAntonio Nino Diaz .if \_init_c_runtime 423f5478dedSAntonio Nino Diaz bl update_stack_protector_canary 424f5478dedSAntonio Nino Diaz .endif /* _init_c_runtime */ 425f5478dedSAntonio Nino Diaz#endif 426f5478dedSAntonio Nino Diaz .endm 427f5478dedSAntonio Nino Diaz 428f5478dedSAntonio Nino Diaz#endif /* EL3_COMMON_MACROS_S */ 429