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> 13*4324a14bSYann Gautier#include <lib/xlat_tables/xlat_tables_defs.h> 14*4324a14bSYann Gautier 15*4324a14bSYann 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. 66f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 67f5478dedSAntonio Nino Diaz */ 68f5478dedSAntonio Nino Diaz ldcopr r0, NSACR 69f5478dedSAntonio Nino Diaz and r0, r0, #NSACR_IMP_DEF_MASK 70f5478dedSAntonio Nino Diaz orr r0, r0, #(NSACR_RESET_VAL | NSACR_ENABLE_FP_ACCESS) 71f5478dedSAntonio Nino Diaz stcopr r0, NSACR 72f5478dedSAntonio Nino Diaz isb 73f5478dedSAntonio Nino Diaz 74f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 75f5478dedSAntonio Nino Diaz * Initialise CPACR, setting all fields rather than relying on hw. Some 76f5478dedSAntonio Nino Diaz * fields are architecturally UNKNOWN on reset. 77f5478dedSAntonio Nino Diaz * 78f5478dedSAntonio Nino Diaz * CPACR.TRCDIS: Trap control for PL0 and PL1 System register accesses 79f5478dedSAntonio Nino Diaz * to trace registers. Set to zero to allow access. 80f5478dedSAntonio Nino Diaz * 81f5478dedSAntonio Nino Diaz * CPACR_ENABLE_FP_ACCESS: Represents CPACR.cp11 and CPACR.cp10. The 82f5478dedSAntonio Nino Diaz * cp11 field is ignored, but is set to same value as cp10. The cp10 83f5478dedSAntonio Nino Diaz * field is set to allow full access from PL0 and PL1 to floating-point 84f5478dedSAntonio Nino Diaz * and Advanced SIMD features. 85f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 86f5478dedSAntonio Nino Diaz */ 87f5478dedSAntonio Nino Diaz ldr r0, =((CPACR_RESET_VAL | CPACR_ENABLE_FP_ACCESS) & ~(TRCDIS_BIT)) 88f5478dedSAntonio Nino Diaz stcopr r0, CPACR 89f5478dedSAntonio Nino Diaz isb 90f5478dedSAntonio Nino Diaz 91f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 92f5478dedSAntonio Nino Diaz * Initialise FPEXC, setting all fields rather than relying on hw. Some 93f5478dedSAntonio Nino Diaz * fields are architecturally UNKNOWN on reset and are set to zero 94f5478dedSAntonio Nino Diaz * except for field(s) listed below. 95f5478dedSAntonio Nino Diaz * 96f5478dedSAntonio Nino Diaz * FPEXC.EN: Enable access to Advanced SIMD and floating point features 97f5478dedSAntonio Nino Diaz * from all exception levels. 98fbd8f6c8SManish Pandey * 99fbd8f6c8SManish Pandey * __SOFTFP__: Predefined macro exposed by soft-float toolchain. 100fbd8f6c8SManish Pandey * ARMv7 and Cortex-A32(ARMv8/aarch32) has both soft-float and 101fbd8f6c8SManish Pandey * hard-float variants of toolchain, avoid compiling below code with 102fbd8f6c8SManish Pandey * soft-float toolchain as "vmsr" instruction will not be recognized. 103f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 104f5478dedSAntonio Nino Diaz */ 105fbd8f6c8SManish Pandey#if ((ARM_ARCH_MAJOR > 7) || defined(ARMV7_SUPPORTS_VFP)) && !(__SOFTFP__) 106f5478dedSAntonio Nino Diaz ldr r0, =(FPEXC_RESET_VAL | FPEXC_EN_BIT) 107f5478dedSAntonio Nino Diaz vmsr FPEXC, r0 108f5478dedSAntonio Nino Diaz isb 1098f73663bSUsama Arif#endif 110f5478dedSAntonio Nino Diaz 111f5478dedSAntonio Nino Diaz#if (ARM_ARCH_MAJOR > 7) 112f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 113f5478dedSAntonio Nino Diaz * Initialise SDCR, setting all the fields rather than relying on hw. 114f5478dedSAntonio Nino Diaz * 115f5478dedSAntonio Nino Diaz * SDCR.SPD: Disable AArch32 privileged debug. Debug exceptions from 116f5478dedSAntonio Nino Diaz * Secure EL1 are disabled. 117ed4fc6f0SAntonio Nino Diaz * 118c3e8b0beSAlexei Fedorov * SDCR.SCCD: Set to one so that cycle counting by PMCCNTR is prohibited 119c3e8b0beSAlexei Fedorov * in Secure state. This bit is RES0 in versions of the architecture 120ed4fc6f0SAntonio Nino Diaz * earlier than ARMv8.5, setting it to 1 doesn't have any effect on 121ed4fc6f0SAntonio Nino Diaz * them. 122f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 123f5478dedSAntonio Nino Diaz */ 124ed4fc6f0SAntonio Nino Diaz ldr r0, =(SDCR_RESET_VAL | SDCR_SPD(SDCR_SPD_DISABLE) | SDCR_SCCD_BIT) 125f5478dedSAntonio Nino Diaz stcopr r0, SDCR 126c3e8b0beSAlexei Fedorov 127c3e8b0beSAlexei Fedorov /* --------------------------------------------------------------------- 128c3e8b0beSAlexei Fedorov * Initialise PMCR, setting all fields rather than relying 129c3e8b0beSAlexei Fedorov * on hw. Some fields are architecturally UNKNOWN on reset. 130c3e8b0beSAlexei Fedorov * 131c3e8b0beSAlexei Fedorov * PMCR.LP: Set to one so that event counter overflow, that 132c3e8b0beSAlexei Fedorov * is recorded in PMOVSCLR[0-30], occurs on the increment 133c3e8b0beSAlexei Fedorov * that changes PMEVCNTR<n>[63] from 1 to 0, when ARMv8.5-PMU 134c3e8b0beSAlexei Fedorov * is implemented. This bit is RES0 in versions of the architecture 135c3e8b0beSAlexei Fedorov * earlier than ARMv8.5, setting it to 1 doesn't have any effect 136c3e8b0beSAlexei Fedorov * on them. 137c3e8b0beSAlexei Fedorov * This bit is Reserved, UNK/SBZP in ARMv7. 138c3e8b0beSAlexei Fedorov * 139c3e8b0beSAlexei Fedorov * PMCR.LC: Set to one so that cycle counter overflow, that 140c3e8b0beSAlexei Fedorov * is recorded in PMOVSCLR[31], occurs on the increment 141c3e8b0beSAlexei Fedorov * that changes PMCCNTR[63] from 1 to 0. 142c3e8b0beSAlexei Fedorov * This bit is Reserved, UNK/SBZP in ARMv7. 143c3e8b0beSAlexei Fedorov * 144c3e8b0beSAlexei Fedorov * PMCR.DP: Set to one to prohibit cycle counting whilst in Secure mode. 145c3e8b0beSAlexei Fedorov * --------------------------------------------------------------------- 146c3e8b0beSAlexei Fedorov */ 147c3e8b0beSAlexei Fedorov ldr r0, =(PMCR_RESET_VAL | PMCR_DP_BIT | PMCR_LC_BIT | \ 148c3e8b0beSAlexei Fedorov PMCR_LP_BIT) 149c3e8b0beSAlexei Fedorov#else 150c3e8b0beSAlexei Fedorov ldr r0, =(PMCR_RESET_VAL | PMCR_DP_BIT) 151f5478dedSAntonio Nino Diaz#endif 152c3e8b0beSAlexei Fedorov stcopr r0, PMCR 153f5478dedSAntonio Nino Diaz 154f5478dedSAntonio Nino Diaz /* 155f5478dedSAntonio Nino Diaz * If Data Independent Timing (DIT) functionality is implemented, 156f5478dedSAntonio Nino Diaz * always enable DIT in EL3 157f5478dedSAntonio Nino Diaz */ 158f5478dedSAntonio Nino Diaz ldcopr r0, ID_PFR0 159f5478dedSAntonio Nino Diaz and r0, r0, #(ID_PFR0_DIT_MASK << ID_PFR0_DIT_SHIFT) 160f5478dedSAntonio Nino Diaz cmp r0, #ID_PFR0_DIT_SUPPORTED 161f5478dedSAntonio Nino Diaz bne 1f 162f5478dedSAntonio Nino Diaz mrs r0, cpsr 163f5478dedSAntonio Nino Diaz orr r0, r0, #CPSR_DIT_BIT 164f5478dedSAntonio Nino Diaz msr cpsr_cxsf, r0 165f5478dedSAntonio Nino Diaz1: 166f5478dedSAntonio Nino Diaz .endm 167f5478dedSAntonio Nino Diaz 168f5478dedSAntonio Nino Diaz/* ----------------------------------------------------------------------------- 169f5478dedSAntonio Nino Diaz * This is the super set of actions that need to be performed during a cold boot 170f5478dedSAntonio Nino Diaz * or a warm boot in EL3. This code is shared by BL1 and BL32 (SP_MIN). 171f5478dedSAntonio Nino Diaz * 172f5478dedSAntonio Nino Diaz * This macro will always perform reset handling, architectural initialisations 173f5478dedSAntonio Nino Diaz * and stack setup. The rest of the actions are optional because they might not 174f5478dedSAntonio Nino Diaz * be needed, depending on the context in which this macro is called. This is 175f5478dedSAntonio Nino Diaz * why this macro is parameterised ; each parameter allows to enable/disable 176f5478dedSAntonio Nino Diaz * some actions. 177f5478dedSAntonio Nino Diaz * 178f5478dedSAntonio Nino Diaz * _init_sctlr: 179f5478dedSAntonio Nino Diaz * Whether the macro needs to initialise the SCTLR register including 180f5478dedSAntonio Nino Diaz * configuring the endianness of data accesses. 181f5478dedSAntonio Nino Diaz * 182f5478dedSAntonio Nino Diaz * _warm_boot_mailbox: 183f5478dedSAntonio Nino Diaz * Whether the macro needs to detect the type of boot (cold/warm). The 184f5478dedSAntonio Nino Diaz * detection is based on the platform entrypoint address : if it is zero 185f5478dedSAntonio Nino Diaz * then it is a cold boot, otherwise it is a warm boot. In the latter case, 186f5478dedSAntonio Nino Diaz * this macro jumps on the platform entrypoint address. 187f5478dedSAntonio Nino Diaz * 188f5478dedSAntonio Nino Diaz * _secondary_cold_boot: 189f5478dedSAntonio Nino Diaz * Whether the macro needs to identify the CPU that is calling it: primary 190f5478dedSAntonio Nino Diaz * CPU or secondary CPU. The primary CPU will be allowed to carry on with 191f5478dedSAntonio Nino Diaz * the platform initialisations, while the secondaries will be put in a 192f5478dedSAntonio Nino Diaz * platform-specific state in the meantime. 193f5478dedSAntonio Nino Diaz * 194f5478dedSAntonio Nino Diaz * If the caller knows this macro will only be called by the primary CPU 195f5478dedSAntonio Nino Diaz * then this parameter can be defined to 0 to skip this step. 196f5478dedSAntonio Nino Diaz * 197f5478dedSAntonio Nino Diaz * _init_memory: 198f5478dedSAntonio Nino Diaz * Whether the macro needs to initialise the memory. 199f5478dedSAntonio Nino Diaz * 200f5478dedSAntonio Nino Diaz * _init_c_runtime: 201f5478dedSAntonio Nino Diaz * Whether the macro needs to initialise the C runtime environment. 202f5478dedSAntonio Nino Diaz * 203f5478dedSAntonio Nino Diaz * _exception_vectors: 204f5478dedSAntonio Nino Diaz * Address of the exception vectors to program in the VBAR_EL3 register. 205*4324a14bSYann Gautier * 206*4324a14bSYann Gautier * _pie_fixup_size: 207*4324a14bSYann Gautier * Size of memory region to fixup Global Descriptor Table (GDT). 208*4324a14bSYann Gautier * 209*4324a14bSYann Gautier * A non-zero value is expected when firmware needs GDT to be fixed-up. 210*4324a14bSYann Gautier * 211f5478dedSAntonio Nino Diaz * ----------------------------------------------------------------------------- 212f5478dedSAntonio Nino Diaz */ 213f5478dedSAntonio Nino Diaz .macro el3_entrypoint_common \ 214f5478dedSAntonio Nino Diaz _init_sctlr, _warm_boot_mailbox, _secondary_cold_boot, \ 215*4324a14bSYann Gautier _init_memory, _init_c_runtime, _exception_vectors, \ 216*4324a14bSYann Gautier _pie_fixup_size 217f5478dedSAntonio Nino Diaz 218f5478dedSAntonio Nino Diaz /* Make sure we are in Secure Mode */ 219f5478dedSAntonio Nino Diaz#if ENABLE_ASSERTIONS 220f5478dedSAntonio Nino Diaz ldcopr r0, SCR 221f5478dedSAntonio Nino Diaz tst r0, #SCR_NS_BIT 222f5478dedSAntonio Nino Diaz ASM_ASSERT(eq) 223f5478dedSAntonio Nino Diaz#endif 224f5478dedSAntonio Nino Diaz 225f5478dedSAntonio Nino Diaz .if \_init_sctlr 226f5478dedSAntonio Nino Diaz /* ------------------------------------------------------------- 227f5478dedSAntonio Nino Diaz * This is the initialisation of SCTLR and so must ensure that 228f5478dedSAntonio Nino Diaz * all fields are explicitly set rather than relying on hw. Some 229f5478dedSAntonio Nino Diaz * fields reset to an IMPLEMENTATION DEFINED value. 230f5478dedSAntonio Nino Diaz * 231f5478dedSAntonio Nino Diaz * SCTLR.TE: Set to zero so that exceptions to an Exception 232f5478dedSAntonio Nino Diaz * Level executing at PL1 are taken to A32 state. 233f5478dedSAntonio Nino Diaz * 234f5478dedSAntonio Nino Diaz * SCTLR.EE: Set the CPU endianness before doing anything that 235f5478dedSAntonio Nino Diaz * might involve memory reads or writes. Set to zero to select 236f5478dedSAntonio Nino Diaz * Little Endian. 237f5478dedSAntonio Nino Diaz * 238f5478dedSAntonio Nino Diaz * SCTLR.V: Set to zero to select the normal exception vectors 239f5478dedSAntonio Nino Diaz * with base address held in VBAR. 240f5478dedSAntonio Nino Diaz * 241f5478dedSAntonio Nino Diaz * SCTLR.DSSBS: Set to zero to disable speculation store bypass 242f5478dedSAntonio Nino Diaz * safe behaviour upon exception entry to EL3. 243f5478dedSAntonio Nino Diaz * ------------------------------------------------------------- 244f5478dedSAntonio Nino Diaz */ 245f5478dedSAntonio Nino Diaz ldr r0, =(SCTLR_RESET_VAL & ~(SCTLR_TE_BIT | SCTLR_EE_BIT | \ 246f5478dedSAntonio Nino Diaz SCTLR_V_BIT | SCTLR_DSSBS_BIT)) 247f5478dedSAntonio Nino Diaz stcopr r0, SCTLR 248f5478dedSAntonio Nino Diaz isb 249f5478dedSAntonio Nino Diaz .endif /* _init_sctlr */ 250f5478dedSAntonio Nino Diaz 251f5478dedSAntonio Nino Diaz /* Switch to monitor mode */ 252f5478dedSAntonio Nino Diaz cps #MODE32_mon 253f5478dedSAntonio Nino Diaz isb 254f5478dedSAntonio Nino Diaz 2550063dd17SJavier Almansa Sobrino#if DISABLE_MTPMU 2560063dd17SJavier Almansa Sobrino bl mtpmu_disable 2570063dd17SJavier Almansa Sobrino#endif 2580063dd17SJavier Almansa Sobrino 259f5478dedSAntonio Nino Diaz .if \_warm_boot_mailbox 260f5478dedSAntonio Nino Diaz /* ------------------------------------------------------------- 261f5478dedSAntonio Nino Diaz * This code will be executed for both warm and cold resets. 262f5478dedSAntonio Nino Diaz * Now is the time to distinguish between the two. 263f5478dedSAntonio Nino Diaz * Query the platform entrypoint address and if it is not zero 264f5478dedSAntonio Nino Diaz * then it means it is a warm boot so jump to this address. 265f5478dedSAntonio Nino Diaz * ------------------------------------------------------------- 266f5478dedSAntonio Nino Diaz */ 267f5478dedSAntonio Nino Diaz bl plat_get_my_entrypoint 268f5478dedSAntonio Nino Diaz cmp r0, #0 269f5478dedSAntonio Nino Diaz bxne r0 270f5478dedSAntonio Nino Diaz .endif /* _warm_boot_mailbox */ 271f5478dedSAntonio Nino Diaz 272*4324a14bSYann Gautier .if \_pie_fixup_size 273*4324a14bSYann Gautier#if ENABLE_PIE 274*4324a14bSYann Gautier /* 275*4324a14bSYann Gautier * ------------------------------------------------------------ 276*4324a14bSYann Gautier * If PIE is enabled fixup the Global descriptor Table only 277*4324a14bSYann Gautier * once during primary core cold boot path. 278*4324a14bSYann Gautier * 279*4324a14bSYann Gautier * Compile time base address, required for fixup, is calculated 280*4324a14bSYann Gautier * using "pie_fixup" label present within first page. 281*4324a14bSYann Gautier * ------------------------------------------------------------ 282*4324a14bSYann Gautier */ 283*4324a14bSYann Gautier pie_fixup: 284*4324a14bSYann Gautier ldr r0, =pie_fixup 285*4324a14bSYann Gautier ldr r1, =PAGE_START_MASK 286*4324a14bSYann Gautier and r0, r0, r1 287*4324a14bSYann Gautier mov_imm r1, \_pie_fixup_size 288*4324a14bSYann Gautier add r1, r1, r0 289*4324a14bSYann Gautier bl fixup_gdt_reloc 290*4324a14bSYann Gautier#endif /* ENABLE_PIE */ 291*4324a14bSYann Gautier .endif /* _pie_fixup_size */ 292*4324a14bSYann Gautier 293f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 294f5478dedSAntonio Nino Diaz * Set the exception vectors (VBAR/MVBAR). 295f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 296f5478dedSAntonio Nino Diaz */ 297f5478dedSAntonio Nino Diaz ldr r0, =\_exception_vectors 298f5478dedSAntonio Nino Diaz stcopr r0, VBAR 299f5478dedSAntonio Nino Diaz stcopr r0, MVBAR 300f5478dedSAntonio Nino Diaz isb 301f5478dedSAntonio Nino Diaz 302f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 303f5478dedSAntonio Nino Diaz * It is a cold boot. 304f5478dedSAntonio Nino Diaz * Perform any processor specific actions upon reset e.g. cache, TLB 305f5478dedSAntonio Nino Diaz * invalidations etc. 306f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 307f5478dedSAntonio Nino Diaz */ 308f5478dedSAntonio Nino Diaz bl reset_handler 309f5478dedSAntonio Nino Diaz 310f5478dedSAntonio Nino Diaz el3_arch_init_common 311f5478dedSAntonio Nino Diaz 312f5478dedSAntonio Nino Diaz .if \_secondary_cold_boot 313f5478dedSAntonio Nino Diaz /* ------------------------------------------------------------- 314f5478dedSAntonio Nino Diaz * Check if this is a primary or secondary CPU cold boot. 315f5478dedSAntonio Nino Diaz * The primary CPU will set up the platform while the 316f5478dedSAntonio Nino Diaz * secondaries are placed in a platform-specific state until the 317f5478dedSAntonio Nino Diaz * primary CPU performs the necessary actions to bring them out 318f5478dedSAntonio Nino Diaz * of that state and allows entry into the OS. 319f5478dedSAntonio Nino Diaz * ------------------------------------------------------------- 320f5478dedSAntonio Nino Diaz */ 321f5478dedSAntonio Nino Diaz bl plat_is_my_cpu_primary 322f5478dedSAntonio Nino Diaz cmp r0, #0 323f5478dedSAntonio Nino Diaz bne do_primary_cold_boot 324f5478dedSAntonio Nino Diaz 325f5478dedSAntonio Nino Diaz /* This is a cold boot on a secondary CPU */ 326f5478dedSAntonio Nino Diaz bl plat_secondary_cold_boot_setup 327f5478dedSAntonio Nino Diaz /* plat_secondary_cold_boot_setup() is not supposed to return */ 328f5478dedSAntonio Nino Diaz no_ret plat_panic_handler 329f5478dedSAntonio Nino Diaz 330f5478dedSAntonio Nino Diaz do_primary_cold_boot: 331f5478dedSAntonio Nino Diaz .endif /* _secondary_cold_boot */ 332f5478dedSAntonio Nino Diaz 333f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 334f5478dedSAntonio Nino Diaz * Initialize memory now. Secondary CPU initialization won't get to this 335f5478dedSAntonio Nino Diaz * point. 336f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 337f5478dedSAntonio Nino Diaz */ 338f5478dedSAntonio Nino Diaz 339f5478dedSAntonio Nino Diaz .if \_init_memory 340f5478dedSAntonio Nino Diaz bl platform_mem_init 341f5478dedSAntonio Nino Diaz .endif /* _init_memory */ 342f5478dedSAntonio Nino Diaz 343f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 344f5478dedSAntonio Nino Diaz * Init C runtime environment: 345f5478dedSAntonio Nino Diaz * - Zero-initialise the NOBITS sections. There are 2 of them: 346f5478dedSAntonio Nino Diaz * - the .bss section; 347f5478dedSAntonio Nino Diaz * - the coherent memory section (if any). 348f5478dedSAntonio Nino Diaz * - Relocate the data section from ROM to RAM, if required. 349f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 350f5478dedSAntonio Nino Diaz */ 351f5478dedSAntonio Nino Diaz .if \_init_c_runtime 352f5478dedSAntonio Nino Diaz#if defined(IMAGE_BL32) || (defined(IMAGE_BL2) && BL2_AT_EL3) 353f5478dedSAntonio Nino Diaz /* ----------------------------------------------------------------- 354f5478dedSAntonio Nino Diaz * Invalidate the RW memory used by the image. This 355f5478dedSAntonio Nino Diaz * includes the data and NOBITS sections. This is done to 356f5478dedSAntonio Nino Diaz * safeguard against possible corruption of this memory by 357f5478dedSAntonio Nino Diaz * dirty cache lines in a system cache as a result of use by 358f5478dedSAntonio Nino Diaz * an earlier boot loader stage. 359f5478dedSAntonio Nino Diaz * ----------------------------------------------------------------- 360f5478dedSAntonio Nino Diaz */ 361f5478dedSAntonio Nino Diaz ldr r0, =__RW_START__ 362f5478dedSAntonio Nino Diaz ldr r1, =__RW_END__ 363f5478dedSAntonio Nino Diaz sub r1, r1, r0 364f5478dedSAntonio Nino Diaz bl inv_dcache_range 365f5478dedSAntonio Nino Diaz#endif 366f5478dedSAntonio Nino Diaz 36730f31005SYann Gautier /* 36830f31005SYann Gautier * zeromem uses r12 whereas it is used to save previous BL arg3, 36930f31005SYann Gautier * save it in r7 37030f31005SYann Gautier */ 37130f31005SYann Gautier mov r7, r12 372f5478dedSAntonio Nino Diaz ldr r0, =__BSS_START__ 373fb4f511fSYann Gautier ldr r1, =__BSS_END__ 374fb4f511fSYann Gautier sub r1, r1, r0 375f5478dedSAntonio Nino Diaz bl zeromem 376f5478dedSAntonio Nino Diaz 377f5478dedSAntonio Nino Diaz#if USE_COHERENT_MEM 378f5478dedSAntonio Nino Diaz ldr r0, =__COHERENT_RAM_START__ 379fb4f511fSYann Gautier ldr r1, =__COHERENT_RAM_END_UNALIGNED__ 380fb4f511fSYann Gautier sub r1, r1, r0 381f5478dedSAntonio Nino Diaz bl zeromem 382f5478dedSAntonio Nino Diaz#endif 383f5478dedSAntonio Nino Diaz 38430f31005SYann Gautier /* Restore r12 */ 38530f31005SYann Gautier mov r12, r7 38630f31005SYann Gautier 3870a12302cSLionel Debieve#if defined(IMAGE_BL1) || (defined(IMAGE_BL2) && BL2_AT_EL3 && BL2_IN_XIP_MEM) 388f5478dedSAntonio Nino Diaz /* ----------------------------------------------------- 389f5478dedSAntonio Nino Diaz * Copy data from ROM to RAM. 390f5478dedSAntonio Nino Diaz * ----------------------------------------------------- 391f5478dedSAntonio Nino Diaz */ 392f5478dedSAntonio Nino Diaz ldr r0, =__DATA_RAM_START__ 393f5478dedSAntonio Nino Diaz ldr r1, =__DATA_ROM_START__ 394fb4f511fSYann Gautier ldr r2, =__DATA_RAM_END__ 395fb4f511fSYann Gautier sub r2, r2, r0 396f5478dedSAntonio Nino Diaz bl memcpy4 397f5478dedSAntonio Nino Diaz#endif 398f5478dedSAntonio Nino Diaz .endif /* _init_c_runtime */ 399f5478dedSAntonio Nino Diaz 400f5478dedSAntonio Nino Diaz /* --------------------------------------------------------------------- 401f5478dedSAntonio Nino Diaz * Allocate a stack whose memory will be marked as Normal-IS-WBWA when 402f5478dedSAntonio Nino Diaz * the MMU is enabled. There is no risk of reading stale stack memory 403f5478dedSAntonio Nino Diaz * after enabling the MMU as only the primary CPU is running at the 404f5478dedSAntonio Nino Diaz * moment. 405f5478dedSAntonio Nino Diaz * --------------------------------------------------------------------- 406f5478dedSAntonio Nino Diaz */ 407f5478dedSAntonio Nino Diaz bl plat_set_my_stack 408f5478dedSAntonio Nino Diaz 409f5478dedSAntonio Nino Diaz#if STACK_PROTECTOR_ENABLED 410f5478dedSAntonio Nino Diaz .if \_init_c_runtime 411f5478dedSAntonio Nino Diaz bl update_stack_protector_canary 412f5478dedSAntonio Nino Diaz .endif /* _init_c_runtime */ 413f5478dedSAntonio Nino Diaz#endif 414f5478dedSAntonio Nino Diaz .endm 415f5478dedSAntonio Nino Diaz 416f5478dedSAntonio Nino Diaz#endif /* EL3_COMMON_MACROS_S */ 417