xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision ec3c10039bdc2c1468a8ba95fbbe9de78628eea5)
14f6ad66aSAchin Gupta/*
2e83b0cadSDan Handley * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
44f6ad66aSAchin Gupta * Redistribution and use in source and binary forms, with or without
54f6ad66aSAchin Gupta * modification, are permitted provided that the following conditions are met:
64f6ad66aSAchin Gupta *
74f6ad66aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this
84f6ad66aSAchin Gupta * list of conditions and the following disclaimer.
94f6ad66aSAchin Gupta *
104f6ad66aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice,
114f6ad66aSAchin Gupta * this list of conditions and the following disclaimer in the documentation
124f6ad66aSAchin Gupta * and/or other materials provided with the distribution.
134f6ad66aSAchin Gupta *
144f6ad66aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used
154f6ad66aSAchin Gupta * to endorse or promote products derived from this software without specific
164f6ad66aSAchin Gupta * prior written permission.
174f6ad66aSAchin Gupta *
184f6ad66aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
194f6ad66aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
204f6ad66aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
214f6ad66aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
224f6ad66aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
234f6ad66aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
244f6ad66aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
254f6ad66aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
264f6ad66aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
274f6ad66aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284f6ad66aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE.
294f6ad66aSAchin Gupta */
304f6ad66aSAchin Gupta
31c10bd2ceSSandrine Bailleux#include <arch.h>
320a30cf54SAndrew Thoelke#include <asm_macros.S>
3397043ac9SDan Handley#include <bl_common.h>
344f6ad66aSAchin Gupta
354f6ad66aSAchin Gupta	.globl	bl31_entrypoint
364f6ad66aSAchin Gupta
374f6ad66aSAchin Gupta
384f6ad66aSAchin Gupta	/* -----------------------------------------------------
394f6ad66aSAchin Gupta	 * bl31_entrypoint() is the cold boot entrypoint,
404f6ad66aSAchin Gupta	 * executed only by the primary cpu.
414f6ad66aSAchin Gupta	 * -----------------------------------------------------
424f6ad66aSAchin Gupta	 */
434f6ad66aSAchin Gupta
440a30cf54SAndrew Thoelkefunc bl31_entrypoint
454112bfa0SVikram Kanigiri	/* ---------------------------------------------------------------
464112bfa0SVikram Kanigiri	 * Preceding bootloader has populated x0 with a pointer to a
474112bfa0SVikram Kanigiri	 * 'bl31_params' structure & x1 with a pointer to platform
484112bfa0SVikram Kanigiri	 * specific structure
494112bfa0SVikram Kanigiri	 * ---------------------------------------------------------------
50c10bd2ceSSandrine Bailleux	 */
51dbad1bacSVikram Kanigiri#if !RESET_TO_BL31
5229fb905dSVikram Kanigiri	mov	x20, x0
5329fb905dSVikram Kanigiri	mov	x21, x1
54dbad1bacSVikram Kanigiri#else
55*ec3c1003SAchin Gupta	/* ---------------------------------------------
56*ec3c1003SAchin Gupta	 * Set the CPU endianness before doing anything
57*ec3c1003SAchin Gupta	 * that might involve memory reads or writes.
58*ec3c1003SAchin Gupta	 * ---------------------------------------------
59*ec3c1003SAchin Gupta	 */
60*ec3c1003SAchin Gupta	mrs	x0, sctlr_el3
61*ec3c1003SAchin Gupta	bic	x0, x0, #SCTLR_EE_BIT
62*ec3c1003SAchin Gupta	msr	sctlr_el3, x0
63*ec3c1003SAchin Gupta	isb
64dbad1bacSVikram Kanigiri
65dbad1bacSVikram Kanigiri	/* -----------------------------------------------------
66dbad1bacSVikram Kanigiri	 * Perform any processor specific actions upon reset
67dbad1bacSVikram Kanigiri	 * e.g. cache, tlb invalidations etc. Override the
68dbad1bacSVikram Kanigiri	 * Boot ROM(BL0) programming sequence
69dbad1bacSVikram Kanigiri	 * -----------------------------------------------------
70dbad1bacSVikram Kanigiri	 */
71dbad1bacSVikram Kanigiri	bl	cpu_reset_handler
72dbad1bacSVikram Kanigiri#endif
73dbad1bacSVikram Kanigiri	/* ---------------------------------------------
74*ec3c1003SAchin Gupta	 * Enable the instruction cache, stack pointer
75*ec3c1003SAchin Gupta	 * and data access alignment checks
76dbad1bacSVikram Kanigiri	 * ---------------------------------------------
77dbad1bacSVikram Kanigiri	 */
78*ec3c1003SAchin Gupta	mov	x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
79*ec3c1003SAchin Gupta	mrs	x0, sctlr_el3
80*ec3c1003SAchin Gupta	orr	x0, x0, x1
81*ec3c1003SAchin Gupta	msr	sctlr_el3, x0
82dbad1bacSVikram Kanigiri	isb
83c10bd2ceSSandrine Bailleux
84c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
85ee94cc6fSAndrew Thoelke	 * Set the exception vector and zero tpidr_el3
86ee94cc6fSAndrew Thoelke	 * until the crash reporting is set up
87c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
88c10bd2ceSSandrine Bailleux	 */
89ee94cc6fSAndrew Thoelke	adr	x1, runtime_exceptions
90c10bd2ceSSandrine Bailleux	msr	vbar_el3, x1
91ee94cc6fSAndrew Thoelke	msr	tpidr_el3, xzr
92c10bd2ceSSandrine Bailleux
934f603683SHarry Liebel	/* ---------------------------------------------------------------------
944f603683SHarry Liebel	 * The initial state of the Architectural feature trap register
954f603683SHarry Liebel	 * (CPTR_EL3) is unknown and it must be set to a known state. All
964f603683SHarry Liebel	 * feature traps are disabled. Some bits in this register are marked as
974f603683SHarry Liebel	 * Reserved and should not be modified.
984f603683SHarry Liebel	 *
994f603683SHarry Liebel	 * CPTR_EL3.TCPAC: This causes a direct access to the CPACR_EL1 from EL1
1004f603683SHarry Liebel	 *  or the CPTR_EL2 from EL2 to trap to EL3 unless it is trapped at EL2.
1014f603683SHarry Liebel	 * CPTR_EL3.TTA: This causes access to the Trace functionality to trap
1024f603683SHarry Liebel	 *  to EL3 when executed from EL0, EL1, EL2, or EL3. If system register
1034f603683SHarry Liebel	 *  access to trace functionality is not supported, this bit is RES0.
1044f603683SHarry Liebel	 * CPTR_EL3.TFP: This causes instructions that access the registers
1054f603683SHarry Liebel	 *  associated with Floating Point and Advanced SIMD execution to trap
1064f603683SHarry Liebel	 *  to EL3 when executed from any exception level, unless trapped to EL1
1074f603683SHarry Liebel	 *  or EL2.
1084f603683SHarry Liebel	 * ---------------------------------------------------------------------
1094f603683SHarry Liebel	 */
1104f603683SHarry Liebel	mrs	x1, cptr_el3
1114f603683SHarry Liebel	bic	w1, w1, #TCPAC_BIT
1124f603683SHarry Liebel	bic	w1, w1, #TTA_BIT
1134f603683SHarry Liebel	bic	w1, w1, #TFP_BIT
1144f603683SHarry Liebel	msr	cptr_el3, x1
1154f603683SHarry Liebel
116dbad1bacSVikram Kanigiri#if RESET_TO_BL31
11703396c43SVikram Kanigiri	/* -------------------------------------------------------
11803396c43SVikram Kanigiri	 * Will not return from this macro if it is a warm boot.
11903396c43SVikram Kanigiri	 * -------------------------------------------------------
12003396c43SVikram Kanigiri	 */
121dbad1bacSVikram Kanigiri	wait_for_entrypoint
122dbad1bacSVikram Kanigiri	bl	platform_mem_init
123dbad1bacSVikram Kanigiri#else
124c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
1254f6ad66aSAchin Gupta	 * This is BL31 which is expected to be executed
1264f6ad66aSAchin Gupta	 * only by the primary cpu (at least for now).
1274f6ad66aSAchin Gupta	 * So, make sure no secondary has lost its way.
1284f6ad66aSAchin Gupta	 * ---------------------------------------------
1294f6ad66aSAchin Gupta	 */
1307935d0a5SAndrew Thoelke	mrs	x0, mpidr_el1
1314f6ad66aSAchin Gupta	bl	platform_is_primary_cpu
1324f6ad66aSAchin Gupta	cbz	x0, _panic
133dbad1bacSVikram Kanigiri#endif
1344f6ad66aSAchin Gupta
13565f546a1SSandrine Bailleux	/* ---------------------------------------------
13665f546a1SSandrine Bailleux	 * Zero out NOBITS sections. There are 2 of them:
13765f546a1SSandrine Bailleux	 *   - the .bss section;
13865f546a1SSandrine Bailleux	 *   - the coherent memory section.
13965f546a1SSandrine Bailleux	 * ---------------------------------------------
14065f546a1SSandrine Bailleux	 */
14165f546a1SSandrine Bailleux	ldr	x0, =__BSS_START__
14265f546a1SSandrine Bailleux	ldr	x1, =__BSS_SIZE__
14365f546a1SSandrine Bailleux	bl	zeromem16
14465f546a1SSandrine Bailleux
14565f546a1SSandrine Bailleux	ldr	x0, =__COHERENT_RAM_START__
14665f546a1SSandrine Bailleux	ldr	x1, =__COHERENT_RAM_UNALIGNED_SIZE__
14765f546a1SSandrine Bailleux	bl	zeromem16
14865f546a1SSandrine Bailleux
149caa84939SJeenu Viswambharan	/* ---------------------------------------------
1505e910074SAndrew Thoelke	 * Initialise cpu_data and crash reporting
1515e910074SAndrew Thoelke	 * ---------------------------------------------
1525e910074SAndrew Thoelke	 */
1535e910074SAndrew Thoelke#if CRASH_REPORTING
1545e910074SAndrew Thoelke	bl	init_crash_reporting
1555e910074SAndrew Thoelke#endif
156ee94cc6fSAndrew Thoelke	bl	init_cpu_data_ptr
1575e910074SAndrew Thoelke
1585e910074SAndrew Thoelke	/* ---------------------------------------------
159caa84939SJeenu Viswambharan	 * Use SP_EL0 for the C runtime stack.
160caa84939SJeenu Viswambharan	 * ---------------------------------------------
161caa84939SJeenu Viswambharan	 */
162caa84939SJeenu Viswambharan	msr	spsel, #0
163caa84939SJeenu Viswambharan
1644f6ad66aSAchin Gupta	/* --------------------------------------------
165754a2b7aSAchin Gupta	 * Allocate a stack whose memory will be marked
166754a2b7aSAchin Gupta	 * as Normal-IS-WBWA when the MMU is enabled.
167754a2b7aSAchin Gupta	 * There is no risk of reading stale stack
168754a2b7aSAchin Gupta	 * memory after enabling the MMU as only the
169754a2b7aSAchin Gupta	 * primary cpu is running at the moment.
1704f6ad66aSAchin Gupta	 * --------------------------------------------
1714f6ad66aSAchin Gupta	 */
1727935d0a5SAndrew Thoelke	mrs	x0, mpidr_el1
173754a2b7aSAchin Gupta	bl	platform_set_stack
1744f6ad66aSAchin Gupta
1754f6ad66aSAchin Gupta	/* ---------------------------------------------
1764f6ad66aSAchin Gupta	 * Perform platform specific early arch. setup
1774f6ad66aSAchin Gupta	 * ---------------------------------------------
1784f6ad66aSAchin Gupta	 */
179dbad1bacSVikram Kanigiri#if RESET_TO_BL31
180dbad1bacSVikram Kanigiri	mov	x0, 0
181dbad1bacSVikram Kanigiri	mov	x1, 0
182dbad1bacSVikram Kanigiri#else
1834f6ad66aSAchin Gupta	mov	x0, x20
1844f6ad66aSAchin Gupta	mov	x1, x21
185dbad1bacSVikram Kanigiri#endif
186dbad1bacSVikram Kanigiri
1874f6ad66aSAchin Gupta	bl	bl31_early_platform_setup
1884f6ad66aSAchin Gupta	bl	bl31_plat_arch_setup
1894f6ad66aSAchin Gupta
1904f6ad66aSAchin Gupta	/* ---------------------------------------------
1914f6ad66aSAchin Gupta	 * Jump to main function.
1924f6ad66aSAchin Gupta	 * ---------------------------------------------
1934f6ad66aSAchin Gupta	 */
1944f6ad66aSAchin Gupta	bl	bl31_main
1954f6ad66aSAchin Gupta
196caa84939SJeenu Viswambharan	b	el3_exit
197caa84939SJeenu Viswambharan
1984f6ad66aSAchin Gupta_panic:
199caa84939SJeenu Viswambharan	wfi
2004f6ad66aSAchin Gupta	b	_panic
201