xref: /rk3399_ARM-atf/include/arch/aarch32/el3_common_macros.S (revision fb4f511f9b454ea9e03f6391790693a834d8a830)
1f5478dedSAntonio Nino Diaz/*
2*fb4f511fSYann 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>
13f5478dedSAntonio Nino Diaz
14f5478dedSAntonio Nino Diaz	/*
15f5478dedSAntonio Nino Diaz	 * Helper macro to initialise EL3 registers we care about.
16f5478dedSAntonio Nino Diaz	 */
17f5478dedSAntonio Nino Diaz	.macro el3_arch_init_common
18f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
19f5478dedSAntonio Nino Diaz	 * SCTLR has already been initialised - read current value before
20f5478dedSAntonio Nino Diaz	 * modifying.
21f5478dedSAntonio Nino Diaz	 *
22f5478dedSAntonio Nino Diaz	 * SCTLR.I: Enable the instruction cache.
23f5478dedSAntonio Nino Diaz	 *
24f5478dedSAntonio Nino Diaz	 * SCTLR.A: Enable Alignment fault checking. All instructions that load
25f5478dedSAntonio Nino Diaz	 *  or store one or more registers have an alignment check that the
26f5478dedSAntonio Nino Diaz	 *  address being accessed is aligned to the size of the data element(s)
27f5478dedSAntonio Nino Diaz	 *  being accessed.
28f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
29f5478dedSAntonio Nino Diaz	 */
30f5478dedSAntonio Nino Diaz	ldr	r1, =(SCTLR_I_BIT | SCTLR_A_BIT)
31f5478dedSAntonio Nino Diaz	ldcopr	r0, SCTLR
32f5478dedSAntonio Nino Diaz	orr	r0, r0, r1
33f5478dedSAntonio Nino Diaz	stcopr	r0, SCTLR
34f5478dedSAntonio Nino Diaz	isb
35f5478dedSAntonio Nino Diaz
36f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
37f5478dedSAntonio Nino Diaz	 * Initialise SCR, setting all fields rather than relying on the hw.
38f5478dedSAntonio Nino Diaz	 *
39f5478dedSAntonio Nino Diaz	 * SCR.SIF: Enabled so that Secure state instruction fetches from
40f5478dedSAntonio Nino Diaz	 *  Non-secure memory are not permitted.
41f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
42f5478dedSAntonio Nino Diaz	 */
43f5478dedSAntonio Nino Diaz	ldr	r0, =(SCR_RESET_VAL | SCR_SIF_BIT)
44f5478dedSAntonio Nino Diaz	stcopr	r0, SCR
45f5478dedSAntonio Nino Diaz
46f5478dedSAntonio Nino Diaz	/* -----------------------------------------------------
47f5478dedSAntonio Nino Diaz	 * Enable the Asynchronous data abort now that the
48f5478dedSAntonio Nino Diaz	 * exception vectors have been setup.
49f5478dedSAntonio Nino Diaz	 * -----------------------------------------------------
50f5478dedSAntonio Nino Diaz	 */
51f5478dedSAntonio Nino Diaz	cpsie   a
52f5478dedSAntonio Nino Diaz	isb
53f5478dedSAntonio Nino Diaz
54f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
55f5478dedSAntonio Nino Diaz	 * Initialise NSACR, setting all the fields, except for the
56f5478dedSAntonio Nino Diaz	 * IMPLEMENTATION DEFINED field, rather than relying on the hw. Some
57f5478dedSAntonio Nino Diaz	 * fields are architecturally UNKNOWN on reset.
58f5478dedSAntonio Nino Diaz	 *
59f5478dedSAntonio Nino Diaz	 * NSACR_ENABLE_FP_ACCESS: Represents NSACR.cp11 and NSACR.cp10. The
60f5478dedSAntonio Nino Diaz	 *  cp11 field is ignored, but is set to same value as cp10. The cp10
61f5478dedSAntonio Nino Diaz	 *  field is set to allow access to Advanced SIMD and floating point
62f5478dedSAntonio Nino Diaz	 *  features from both Security states.
63f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
64f5478dedSAntonio Nino Diaz	 */
65f5478dedSAntonio Nino Diaz	ldcopr	r0, NSACR
66f5478dedSAntonio Nino Diaz	and	r0, r0, #NSACR_IMP_DEF_MASK
67f5478dedSAntonio Nino Diaz	orr	r0, r0, #(NSACR_RESET_VAL | NSACR_ENABLE_FP_ACCESS)
68f5478dedSAntonio Nino Diaz	stcopr	r0, NSACR
69f5478dedSAntonio Nino Diaz	isb
70f5478dedSAntonio Nino Diaz
71f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
72f5478dedSAntonio Nino Diaz	 * Initialise CPACR, setting all fields rather than relying on hw. Some
73f5478dedSAntonio Nino Diaz	 * fields are architecturally UNKNOWN on reset.
74f5478dedSAntonio Nino Diaz	 *
75f5478dedSAntonio Nino Diaz	 * CPACR.TRCDIS: Trap control for PL0 and PL1 System register accesses
76f5478dedSAntonio Nino Diaz	 *  to trace registers. Set to zero to allow access.
77f5478dedSAntonio Nino Diaz	 *
78f5478dedSAntonio Nino Diaz	 * CPACR_ENABLE_FP_ACCESS: Represents CPACR.cp11 and CPACR.cp10. The
79f5478dedSAntonio Nino Diaz	 *  cp11 field is ignored, but is set to same value as cp10. The cp10
80f5478dedSAntonio Nino Diaz	 *  field is set to allow full access from PL0 and PL1 to floating-point
81f5478dedSAntonio Nino Diaz	 *  and Advanced SIMD features.
82f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
83f5478dedSAntonio Nino Diaz	 */
84f5478dedSAntonio Nino Diaz	ldr	r0, =((CPACR_RESET_VAL | CPACR_ENABLE_FP_ACCESS) & ~(TRCDIS_BIT))
85f5478dedSAntonio Nino Diaz	stcopr	r0, CPACR
86f5478dedSAntonio Nino Diaz	isb
87f5478dedSAntonio Nino Diaz
88f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
89f5478dedSAntonio Nino Diaz	 * Initialise FPEXC, setting all fields rather than relying on hw. Some
90f5478dedSAntonio Nino Diaz	 * fields are architecturally UNKNOWN on reset and are set to zero
91f5478dedSAntonio Nino Diaz	 * except for field(s) listed below.
92f5478dedSAntonio Nino Diaz	 *
93f5478dedSAntonio Nino Diaz	 * FPEXC.EN: Enable access to Advanced SIMD and floating point features
94f5478dedSAntonio Nino Diaz	 *  from all exception levels.
95fbd8f6c8SManish Pandey         *
96fbd8f6c8SManish Pandey         * __SOFTFP__: Predefined macro exposed by soft-float toolchain.
97fbd8f6c8SManish Pandey         *  ARMv7 and Cortex-A32(ARMv8/aarch32) has both soft-float and
98fbd8f6c8SManish Pandey         *  hard-float variants of toolchain, avoid compiling below code with
99fbd8f6c8SManish Pandey         *  soft-float toolchain as "vmsr" instruction will not be recognized.
100f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
101f5478dedSAntonio Nino Diaz	 */
102fbd8f6c8SManish Pandey#if ((ARM_ARCH_MAJOR > 7) || defined(ARMV7_SUPPORTS_VFP)) && !(__SOFTFP__)
103f5478dedSAntonio Nino Diaz	ldr	r0, =(FPEXC_RESET_VAL | FPEXC_EN_BIT)
104f5478dedSAntonio Nino Diaz	vmsr	FPEXC, r0
105f5478dedSAntonio Nino Diaz	isb
1068f73663bSUsama Arif#endif
107f5478dedSAntonio Nino Diaz
108f5478dedSAntonio Nino Diaz#if (ARM_ARCH_MAJOR > 7)
109f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
110f5478dedSAntonio Nino Diaz	 * Initialise SDCR, setting all the fields rather than relying on hw.
111f5478dedSAntonio Nino Diaz	 *
112f5478dedSAntonio Nino Diaz	 * SDCR.SPD: Disable AArch32 privileged debug. Debug exceptions from
113f5478dedSAntonio Nino Diaz	 *  Secure EL1 are disabled.
114ed4fc6f0SAntonio Nino Diaz	 *
115c3e8b0beSAlexei Fedorov	 * SDCR.SCCD: Set to one so that cycle counting by PMCCNTR is prohibited
116c3e8b0beSAlexei Fedorov	 *  in Secure state. This bit is RES0 in versions of the architecture
117ed4fc6f0SAntonio Nino Diaz	 *  earlier than ARMv8.5, setting it to 1 doesn't have any effect on
118ed4fc6f0SAntonio Nino Diaz	 *  them.
119f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
120f5478dedSAntonio Nino Diaz	 */
121ed4fc6f0SAntonio Nino Diaz	ldr	r0, =(SDCR_RESET_VAL | SDCR_SPD(SDCR_SPD_DISABLE) | SDCR_SCCD_BIT)
122f5478dedSAntonio Nino Diaz	stcopr	r0, SDCR
123c3e8b0beSAlexei Fedorov
124c3e8b0beSAlexei Fedorov	/* ---------------------------------------------------------------------
125c3e8b0beSAlexei Fedorov	 * Initialise PMCR, setting all fields rather than relying
126c3e8b0beSAlexei Fedorov	 * on hw. Some fields are architecturally UNKNOWN on reset.
127c3e8b0beSAlexei Fedorov	 *
128c3e8b0beSAlexei Fedorov	 * PMCR.LP: Set to one so that event counter overflow, that
129c3e8b0beSAlexei Fedorov	 *  is recorded in PMOVSCLR[0-30], occurs on the increment
130c3e8b0beSAlexei Fedorov	 *  that changes PMEVCNTR<n>[63] from 1 to 0, when ARMv8.5-PMU
131c3e8b0beSAlexei Fedorov	 *  is implemented. This bit is RES0 in versions of the architecture
132c3e8b0beSAlexei Fedorov	 *  earlier than ARMv8.5, setting it to 1 doesn't have any effect
133c3e8b0beSAlexei Fedorov	 *  on them.
134c3e8b0beSAlexei Fedorov	 *  This bit is Reserved, UNK/SBZP in ARMv7.
135c3e8b0beSAlexei Fedorov	 *
136c3e8b0beSAlexei Fedorov	 * PMCR.LC: Set to one so that cycle counter overflow, that
137c3e8b0beSAlexei Fedorov	 *  is recorded in PMOVSCLR[31], occurs on the increment
138c3e8b0beSAlexei Fedorov	 *  that changes PMCCNTR[63] from 1 to 0.
139c3e8b0beSAlexei Fedorov	 *  This bit is Reserved, UNK/SBZP in ARMv7.
140c3e8b0beSAlexei Fedorov	 *
141c3e8b0beSAlexei Fedorov	 * PMCR.DP: Set to one to prohibit cycle counting whilst in Secure mode.
142c3e8b0beSAlexei Fedorov	 * ---------------------------------------------------------------------
143c3e8b0beSAlexei Fedorov	 */
144c3e8b0beSAlexei Fedorov	ldr	r0, =(PMCR_RESET_VAL | PMCR_DP_BIT | PMCR_LC_BIT | \
145c3e8b0beSAlexei Fedorov		      PMCR_LP_BIT)
146c3e8b0beSAlexei Fedorov#else
147c3e8b0beSAlexei Fedorov	ldr	r0, =(PMCR_RESET_VAL | PMCR_DP_BIT)
148f5478dedSAntonio Nino Diaz#endif
149c3e8b0beSAlexei Fedorov	stcopr	r0, PMCR
150f5478dedSAntonio Nino Diaz
151f5478dedSAntonio Nino Diaz	/*
152f5478dedSAntonio Nino Diaz	 * If Data Independent Timing (DIT) functionality is implemented,
153f5478dedSAntonio Nino Diaz	 * always enable DIT in EL3
154f5478dedSAntonio Nino Diaz	 */
155f5478dedSAntonio Nino Diaz	ldcopr	r0, ID_PFR0
156f5478dedSAntonio Nino Diaz	and	r0, r0, #(ID_PFR0_DIT_MASK << ID_PFR0_DIT_SHIFT)
157f5478dedSAntonio Nino Diaz	cmp	r0, #ID_PFR0_DIT_SUPPORTED
158f5478dedSAntonio Nino Diaz	bne	1f
159f5478dedSAntonio Nino Diaz	mrs	r0, cpsr
160f5478dedSAntonio Nino Diaz	orr	r0, r0, #CPSR_DIT_BIT
161f5478dedSAntonio Nino Diaz	msr	cpsr_cxsf, r0
162f5478dedSAntonio Nino Diaz1:
163f5478dedSAntonio Nino Diaz	.endm
164f5478dedSAntonio Nino Diaz
165f5478dedSAntonio Nino Diaz/* -----------------------------------------------------------------------------
166f5478dedSAntonio Nino Diaz * This is the super set of actions that need to be performed during a cold boot
167f5478dedSAntonio Nino Diaz * or a warm boot in EL3. This code is shared by BL1 and BL32 (SP_MIN).
168f5478dedSAntonio Nino Diaz *
169f5478dedSAntonio Nino Diaz * This macro will always perform reset handling, architectural initialisations
170f5478dedSAntonio Nino Diaz * and stack setup. The rest of the actions are optional because they might not
171f5478dedSAntonio Nino Diaz * be needed, depending on the context in which this macro is called. This is
172f5478dedSAntonio Nino Diaz * why this macro is parameterised ; each parameter allows to enable/disable
173f5478dedSAntonio Nino Diaz * some actions.
174f5478dedSAntonio Nino Diaz *
175f5478dedSAntonio Nino Diaz *  _init_sctlr:
176f5478dedSAntonio Nino Diaz *	Whether the macro needs to initialise the SCTLR register including
177f5478dedSAntonio Nino Diaz *	configuring the endianness of data accesses.
178f5478dedSAntonio Nino Diaz *
179f5478dedSAntonio Nino Diaz *  _warm_boot_mailbox:
180f5478dedSAntonio Nino Diaz *	Whether the macro needs to detect the type of boot (cold/warm). The
181f5478dedSAntonio Nino Diaz *	detection is based on the platform entrypoint address : if it is zero
182f5478dedSAntonio Nino Diaz *	then it is a cold boot, otherwise it is a warm boot. In the latter case,
183f5478dedSAntonio Nino Diaz *	this macro jumps on the platform entrypoint address.
184f5478dedSAntonio Nino Diaz *
185f5478dedSAntonio Nino Diaz *  _secondary_cold_boot:
186f5478dedSAntonio Nino Diaz *	Whether the macro needs to identify the CPU that is calling it: primary
187f5478dedSAntonio Nino Diaz *	CPU or secondary CPU. The primary CPU will be allowed to carry on with
188f5478dedSAntonio Nino Diaz *	the platform initialisations, while the secondaries will be put in a
189f5478dedSAntonio Nino Diaz *	platform-specific state in the meantime.
190f5478dedSAntonio Nino Diaz *
191f5478dedSAntonio Nino Diaz *	If the caller knows this macro will only be called by the primary CPU
192f5478dedSAntonio Nino Diaz *	then this parameter can be defined to 0 to skip this step.
193f5478dedSAntonio Nino Diaz *
194f5478dedSAntonio Nino Diaz * _init_memory:
195f5478dedSAntonio Nino Diaz *	Whether the macro needs to initialise the memory.
196f5478dedSAntonio Nino Diaz *
197f5478dedSAntonio Nino Diaz * _init_c_runtime:
198f5478dedSAntonio Nino Diaz *	Whether the macro needs to initialise the C runtime environment.
199f5478dedSAntonio Nino Diaz *
200f5478dedSAntonio Nino Diaz * _exception_vectors:
201f5478dedSAntonio Nino Diaz *	Address of the exception vectors to program in the VBAR_EL3 register.
202f5478dedSAntonio Nino Diaz * -----------------------------------------------------------------------------
203f5478dedSAntonio Nino Diaz */
204f5478dedSAntonio Nino Diaz	.macro el3_entrypoint_common					\
205f5478dedSAntonio Nino Diaz		_init_sctlr, _warm_boot_mailbox, _secondary_cold_boot,	\
206f5478dedSAntonio Nino Diaz		_init_memory, _init_c_runtime, _exception_vectors
207f5478dedSAntonio Nino Diaz
208f5478dedSAntonio Nino Diaz	/* Make sure we are in Secure Mode */
209f5478dedSAntonio Nino Diaz#if ENABLE_ASSERTIONS
210f5478dedSAntonio Nino Diaz	ldcopr	r0, SCR
211f5478dedSAntonio Nino Diaz	tst	r0, #SCR_NS_BIT
212f5478dedSAntonio Nino Diaz	ASM_ASSERT(eq)
213f5478dedSAntonio Nino Diaz#endif
214f5478dedSAntonio Nino Diaz
215f5478dedSAntonio Nino Diaz	.if \_init_sctlr
216f5478dedSAntonio Nino Diaz		/* -------------------------------------------------------------
217f5478dedSAntonio Nino Diaz		 * This is the initialisation of SCTLR and so must ensure that
218f5478dedSAntonio Nino Diaz		 * all fields are explicitly set rather than relying on hw. Some
219f5478dedSAntonio Nino Diaz		 * fields reset to an IMPLEMENTATION DEFINED value.
220f5478dedSAntonio Nino Diaz		 *
221f5478dedSAntonio Nino Diaz		 * SCTLR.TE: Set to zero so that exceptions to an Exception
222f5478dedSAntonio Nino Diaz		 *  Level executing at PL1 are taken to A32 state.
223f5478dedSAntonio Nino Diaz		 *
224f5478dedSAntonio Nino Diaz		 * SCTLR.EE: Set the CPU endianness before doing anything that
225f5478dedSAntonio Nino Diaz		 *  might involve memory reads or writes. Set to zero to select
226f5478dedSAntonio Nino Diaz		 *  Little Endian.
227f5478dedSAntonio Nino Diaz		 *
228f5478dedSAntonio Nino Diaz		 * SCTLR.V: Set to zero to select the normal exception vectors
229f5478dedSAntonio Nino Diaz		 *  with base address held in VBAR.
230f5478dedSAntonio Nino Diaz		 *
231f5478dedSAntonio Nino Diaz		 * SCTLR.DSSBS: Set to zero to disable speculation store bypass
232f5478dedSAntonio Nino Diaz		 *  safe behaviour upon exception entry to EL3.
233f5478dedSAntonio Nino Diaz		 * -------------------------------------------------------------
234f5478dedSAntonio Nino Diaz		 */
235f5478dedSAntonio Nino Diaz		ldr     r0, =(SCTLR_RESET_VAL & ~(SCTLR_TE_BIT | SCTLR_EE_BIT | \
236f5478dedSAntonio Nino Diaz				SCTLR_V_BIT | SCTLR_DSSBS_BIT))
237f5478dedSAntonio Nino Diaz		stcopr	r0, SCTLR
238f5478dedSAntonio Nino Diaz		isb
239f5478dedSAntonio Nino Diaz	.endif /* _init_sctlr */
240f5478dedSAntonio Nino Diaz
241f5478dedSAntonio Nino Diaz	/* Switch to monitor mode */
242f5478dedSAntonio Nino Diaz	cps	#MODE32_mon
243f5478dedSAntonio Nino Diaz	isb
244f5478dedSAntonio Nino Diaz
2450063dd17SJavier Almansa Sobrino#if DISABLE_MTPMU
2460063dd17SJavier Almansa Sobrino	bl	mtpmu_disable
2470063dd17SJavier Almansa Sobrino#endif
2480063dd17SJavier Almansa Sobrino
249f5478dedSAntonio Nino Diaz	.if \_warm_boot_mailbox
250f5478dedSAntonio Nino Diaz		/* -------------------------------------------------------------
251f5478dedSAntonio Nino Diaz		 * This code will be executed for both warm and cold resets.
252f5478dedSAntonio Nino Diaz		 * Now is the time to distinguish between the two.
253f5478dedSAntonio Nino Diaz		 * Query the platform entrypoint address and if it is not zero
254f5478dedSAntonio Nino Diaz		 * then it means it is a warm boot so jump to this address.
255f5478dedSAntonio Nino Diaz		 * -------------------------------------------------------------
256f5478dedSAntonio Nino Diaz		 */
257f5478dedSAntonio Nino Diaz		bl	plat_get_my_entrypoint
258f5478dedSAntonio Nino Diaz		cmp	r0, #0
259f5478dedSAntonio Nino Diaz		bxne	r0
260f5478dedSAntonio Nino Diaz	.endif /* _warm_boot_mailbox */
261f5478dedSAntonio Nino Diaz
262f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
263f5478dedSAntonio Nino Diaz	 * Set the exception vectors (VBAR/MVBAR).
264f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
265f5478dedSAntonio Nino Diaz	 */
266f5478dedSAntonio Nino Diaz	ldr	r0, =\_exception_vectors
267f5478dedSAntonio Nino Diaz	stcopr	r0, VBAR
268f5478dedSAntonio Nino Diaz	stcopr	r0, MVBAR
269f5478dedSAntonio Nino Diaz	isb
270f5478dedSAntonio Nino Diaz
271f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
272f5478dedSAntonio Nino Diaz	 * It is a cold boot.
273f5478dedSAntonio Nino Diaz	 * Perform any processor specific actions upon reset e.g. cache, TLB
274f5478dedSAntonio Nino Diaz	 * invalidations etc.
275f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
276f5478dedSAntonio Nino Diaz	 */
277f5478dedSAntonio Nino Diaz	bl	reset_handler
278f5478dedSAntonio Nino Diaz
279f5478dedSAntonio Nino Diaz	el3_arch_init_common
280f5478dedSAntonio Nino Diaz
281f5478dedSAntonio Nino Diaz	.if \_secondary_cold_boot
282f5478dedSAntonio Nino Diaz		/* -------------------------------------------------------------
283f5478dedSAntonio Nino Diaz		 * Check if this is a primary or secondary CPU cold boot.
284f5478dedSAntonio Nino Diaz		 * The primary CPU will set up the platform while the
285f5478dedSAntonio Nino Diaz		 * secondaries are placed in a platform-specific state until the
286f5478dedSAntonio Nino Diaz		 * primary CPU performs the necessary actions to bring them out
287f5478dedSAntonio Nino Diaz		 * of that state and allows entry into the OS.
288f5478dedSAntonio Nino Diaz		 * -------------------------------------------------------------
289f5478dedSAntonio Nino Diaz		 */
290f5478dedSAntonio Nino Diaz		bl	plat_is_my_cpu_primary
291f5478dedSAntonio Nino Diaz		cmp	r0, #0
292f5478dedSAntonio Nino Diaz		bne	do_primary_cold_boot
293f5478dedSAntonio Nino Diaz
294f5478dedSAntonio Nino Diaz		/* This is a cold boot on a secondary CPU */
295f5478dedSAntonio Nino Diaz		bl	plat_secondary_cold_boot_setup
296f5478dedSAntonio Nino Diaz		/* plat_secondary_cold_boot_setup() is not supposed to return */
297f5478dedSAntonio Nino Diaz		no_ret	plat_panic_handler
298f5478dedSAntonio Nino Diaz
299f5478dedSAntonio Nino Diaz	do_primary_cold_boot:
300f5478dedSAntonio Nino Diaz	.endif /* _secondary_cold_boot */
301f5478dedSAntonio Nino Diaz
302f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
303f5478dedSAntonio Nino Diaz	 * Initialize memory now. Secondary CPU initialization won't get to this
304f5478dedSAntonio Nino Diaz	 * point.
305f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
306f5478dedSAntonio Nino Diaz	 */
307f5478dedSAntonio Nino Diaz
308f5478dedSAntonio Nino Diaz	.if \_init_memory
309f5478dedSAntonio Nino Diaz		bl	platform_mem_init
310f5478dedSAntonio Nino Diaz	.endif /* _init_memory */
311f5478dedSAntonio Nino Diaz
312f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
313f5478dedSAntonio Nino Diaz	 * Init C runtime environment:
314f5478dedSAntonio Nino Diaz	 *   - Zero-initialise the NOBITS sections. There are 2 of them:
315f5478dedSAntonio Nino Diaz	 *       - the .bss section;
316f5478dedSAntonio Nino Diaz	 *       - the coherent memory section (if any).
317f5478dedSAntonio Nino Diaz	 *   - Relocate the data section from ROM to RAM, if required.
318f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
319f5478dedSAntonio Nino Diaz	 */
320f5478dedSAntonio Nino Diaz	.if \_init_c_runtime
321f5478dedSAntonio Nino Diaz#if defined(IMAGE_BL32) || (defined(IMAGE_BL2) && BL2_AT_EL3)
322f5478dedSAntonio Nino Diaz		/* -----------------------------------------------------------------
323f5478dedSAntonio Nino Diaz		 * Invalidate the RW memory used by the image. This
324f5478dedSAntonio Nino Diaz		 * includes the data and NOBITS sections. This is done to
325f5478dedSAntonio Nino Diaz		 * safeguard against possible corruption of this memory by
326f5478dedSAntonio Nino Diaz		 * dirty cache lines in a system cache as a result of use by
327f5478dedSAntonio Nino Diaz		 * an earlier boot loader stage.
328f5478dedSAntonio Nino Diaz		 * -----------------------------------------------------------------
329f5478dedSAntonio Nino Diaz		 */
330f5478dedSAntonio Nino Diaz		ldr	r0, =__RW_START__
331f5478dedSAntonio Nino Diaz		ldr	r1, =__RW_END__
332f5478dedSAntonio Nino Diaz		sub	r1, r1, r0
333f5478dedSAntonio Nino Diaz		bl	inv_dcache_range
334f5478dedSAntonio Nino Diaz#endif
335f5478dedSAntonio Nino Diaz
33630f31005SYann Gautier		/*
33730f31005SYann Gautier		 * zeromem uses r12 whereas it is used to save previous BL arg3,
33830f31005SYann Gautier		 * save it in r7
33930f31005SYann Gautier		 */
34030f31005SYann Gautier		mov	r7, r12
341f5478dedSAntonio Nino Diaz		ldr	r0, =__BSS_START__
342*fb4f511fSYann Gautier		ldr	r1, =__BSS_END__
343*fb4f511fSYann Gautier		sub 	r1, r1, r0
344f5478dedSAntonio Nino Diaz		bl	zeromem
345f5478dedSAntonio Nino Diaz
346f5478dedSAntonio Nino Diaz#if USE_COHERENT_MEM
347f5478dedSAntonio Nino Diaz		ldr	r0, =__COHERENT_RAM_START__
348*fb4f511fSYann Gautier		ldr	r1, =__COHERENT_RAM_END_UNALIGNED__
349*fb4f511fSYann Gautier		sub 	r1, r1, r0
350f5478dedSAntonio Nino Diaz		bl	zeromem
351f5478dedSAntonio Nino Diaz#endif
352f5478dedSAntonio Nino Diaz
35330f31005SYann Gautier		/* Restore r12 */
35430f31005SYann Gautier		mov	r12, r7
35530f31005SYann Gautier
3560a12302cSLionel Debieve#if defined(IMAGE_BL1) || (defined(IMAGE_BL2) && BL2_AT_EL3 && BL2_IN_XIP_MEM)
357f5478dedSAntonio Nino Diaz		/* -----------------------------------------------------
358f5478dedSAntonio Nino Diaz		 * Copy data from ROM to RAM.
359f5478dedSAntonio Nino Diaz		 * -----------------------------------------------------
360f5478dedSAntonio Nino Diaz		 */
361f5478dedSAntonio Nino Diaz		ldr	r0, =__DATA_RAM_START__
362f5478dedSAntonio Nino Diaz		ldr	r1, =__DATA_ROM_START__
363*fb4f511fSYann Gautier		ldr	r2, =__DATA_RAM_END__
364*fb4f511fSYann Gautier		sub 	r2, r2, r0
365f5478dedSAntonio Nino Diaz		bl	memcpy4
366f5478dedSAntonio Nino Diaz#endif
367f5478dedSAntonio Nino Diaz	.endif /* _init_c_runtime */
368f5478dedSAntonio Nino Diaz
369f5478dedSAntonio Nino Diaz	/* ---------------------------------------------------------------------
370f5478dedSAntonio Nino Diaz	 * Allocate a stack whose memory will be marked as Normal-IS-WBWA when
371f5478dedSAntonio Nino Diaz	 * the MMU is enabled. There is no risk of reading stale stack memory
372f5478dedSAntonio Nino Diaz	 * after enabling the MMU as only the primary CPU is running at the
373f5478dedSAntonio Nino Diaz	 * moment.
374f5478dedSAntonio Nino Diaz	 * ---------------------------------------------------------------------
375f5478dedSAntonio Nino Diaz	 */
376f5478dedSAntonio Nino Diaz	bl	plat_set_my_stack
377f5478dedSAntonio Nino Diaz
378f5478dedSAntonio Nino Diaz#if STACK_PROTECTOR_ENABLED
379f5478dedSAntonio Nino Diaz	.if \_init_c_runtime
380f5478dedSAntonio Nino Diaz	bl	update_stack_protector_canary
381f5478dedSAntonio Nino Diaz	.endif /* _init_c_runtime */
382f5478dedSAntonio Nino Diaz#endif
383f5478dedSAntonio Nino Diaz	.endm
384f5478dedSAntonio Nino Diaz
385f5478dedSAntonio Nino Diaz#endif /* EL3_COMMON_MACROS_S */
386