xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision dbad1bacba0a7adfd3c7c559f0fd0805087aeddd)
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>
3435e98e55SDan Handley#include <cm_macros.S>
354f6ad66aSAchin Gupta
364f6ad66aSAchin Gupta
374f6ad66aSAchin Gupta	.globl	bl31_entrypoint
384f6ad66aSAchin Gupta
394f6ad66aSAchin Gupta
404f6ad66aSAchin Gupta	/* -----------------------------------------------------
414f6ad66aSAchin Gupta	 * bl31_entrypoint() is the cold boot entrypoint,
424f6ad66aSAchin Gupta	 * executed only by the primary cpu.
434f6ad66aSAchin Gupta	 * -----------------------------------------------------
444f6ad66aSAchin Gupta	 */
454f6ad66aSAchin Gupta
460a30cf54SAndrew Thoelkefunc bl31_entrypoint
474112bfa0SVikram Kanigiri	/* ---------------------------------------------------------------
484112bfa0SVikram Kanigiri	 * Preceding bootloader has populated x0 with a pointer to a
494112bfa0SVikram Kanigiri	 * 'bl31_params' structure & x1 with a pointer to platform
504112bfa0SVikram Kanigiri	 * specific structure
514112bfa0SVikram Kanigiri	 * ---------------------------------------------------------------
52c10bd2ceSSandrine Bailleux	 */
53*dbad1bacSVikram Kanigiri#if !RESET_TO_BL31
5429fb905dSVikram Kanigiri	mov	x20, x0
5529fb905dSVikram Kanigiri	mov	x21, x1
56*dbad1bacSVikram Kanigiri#else
57*dbad1bacSVikram Kanigiri
58*dbad1bacSVikram Kanigiri	/* -----------------------------------------------------
59*dbad1bacSVikram Kanigiri	 * Perform any processor specific actions upon reset
60*dbad1bacSVikram Kanigiri	 * e.g. cache, tlb invalidations etc. Override the
61*dbad1bacSVikram Kanigiri	 * Boot ROM(BL0) programming sequence
62*dbad1bacSVikram Kanigiri	 * -----------------------------------------------------
63*dbad1bacSVikram Kanigiri	 */
64*dbad1bacSVikram Kanigiri	bl	cpu_reset_handler
65*dbad1bacSVikram Kanigiri#endif
66*dbad1bacSVikram Kanigiri
67*dbad1bacSVikram Kanigiri	/* ---------------------------------------------
68*dbad1bacSVikram Kanigiri	 * Enable the instruction cache.
69*dbad1bacSVikram Kanigiri	 * ---------------------------------------------
70*dbad1bacSVikram Kanigiri	 */
71*dbad1bacSVikram Kanigiri	mrs	x1, sctlr_el3
72*dbad1bacSVikram Kanigiri	orr	x1, x1, #SCTLR_I_BIT
73*dbad1bacSVikram Kanigiri	msr	sctlr_el3, x1
74*dbad1bacSVikram Kanigiri	isb
75c10bd2ceSSandrine Bailleux
76c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
77c10bd2ceSSandrine Bailleux	 * Set the exception vector to something sane.
78c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
79c10bd2ceSSandrine Bailleux	 */
80b739f22aSAchin Gupta	adr	x1, early_exceptions
81c10bd2ceSSandrine Bailleux	msr	vbar_el3, x1
82c10bd2ceSSandrine Bailleux
834f603683SHarry Liebel	/* ---------------------------------------------------------------------
844f603683SHarry Liebel	 * The initial state of the Architectural feature trap register
854f603683SHarry Liebel	 * (CPTR_EL3) is unknown and it must be set to a known state. All
864f603683SHarry Liebel	 * feature traps are disabled. Some bits in this register are marked as
874f603683SHarry Liebel	 * Reserved and should not be modified.
884f603683SHarry Liebel	 *
894f603683SHarry Liebel	 * CPTR_EL3.TCPAC: This causes a direct access to the CPACR_EL1 from EL1
904f603683SHarry Liebel	 *  or the CPTR_EL2 from EL2 to trap to EL3 unless it is trapped at EL2.
914f603683SHarry Liebel	 * CPTR_EL3.TTA: This causes access to the Trace functionality to trap
924f603683SHarry Liebel	 *  to EL3 when executed from EL0, EL1, EL2, or EL3. If system register
934f603683SHarry Liebel	 *  access to trace functionality is not supported, this bit is RES0.
944f603683SHarry Liebel	 * CPTR_EL3.TFP: This causes instructions that access the registers
954f603683SHarry Liebel	 *  associated with Floating Point and Advanced SIMD execution to trap
964f603683SHarry Liebel	 *  to EL3 when executed from any exception level, unless trapped to EL1
974f603683SHarry Liebel	 *  or EL2.
984f603683SHarry Liebel	 * ---------------------------------------------------------------------
994f603683SHarry Liebel	 */
1004f603683SHarry Liebel	mrs	x1, cptr_el3
1014f603683SHarry Liebel	bic	w1, w1, #TCPAC_BIT
1024f603683SHarry Liebel	bic	w1, w1, #TTA_BIT
1034f603683SHarry Liebel	bic	w1, w1, #TFP_BIT
1044f603683SHarry Liebel	msr	cptr_el3, x1
1054f603683SHarry Liebel
106*dbad1bacSVikram Kanigiri#if RESET_TO_BL31
107*dbad1bacSVikram Kanigiri	wait_for_entrypoint
108*dbad1bacSVikram Kanigiri	bl	platform_mem_init
109*dbad1bacSVikram Kanigiri#else
110c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
1114f6ad66aSAchin Gupta	 * This is BL31 which is expected to be executed
1124f6ad66aSAchin Gupta	 * only by the primary cpu (at least for now).
1134f6ad66aSAchin Gupta	 * So, make sure no secondary has lost its way.
1144f6ad66aSAchin Gupta	 * ---------------------------------------------
1154f6ad66aSAchin Gupta	 */
1167935d0a5SAndrew Thoelke	mrs	x0, mpidr_el1
1174f6ad66aSAchin Gupta	bl	platform_is_primary_cpu
1184f6ad66aSAchin Gupta	cbz	x0, _panic
119*dbad1bacSVikram Kanigiri#endif
1204f6ad66aSAchin Gupta
12165f546a1SSandrine Bailleux	/* ---------------------------------------------
12265f546a1SSandrine Bailleux	 * Zero out NOBITS sections. There are 2 of them:
12365f546a1SSandrine Bailleux	 *   - the .bss section;
12465f546a1SSandrine Bailleux	 *   - the coherent memory section.
12565f546a1SSandrine Bailleux	 * ---------------------------------------------
12665f546a1SSandrine Bailleux	 */
12765f546a1SSandrine Bailleux	ldr	x0, =__BSS_START__
12865f546a1SSandrine Bailleux	ldr	x1, =__BSS_SIZE__
12965f546a1SSandrine Bailleux	bl	zeromem16
13065f546a1SSandrine Bailleux
13165f546a1SSandrine Bailleux	ldr	x0, =__COHERENT_RAM_START__
13265f546a1SSandrine Bailleux	ldr	x1, =__COHERENT_RAM_UNALIGNED_SIZE__
13365f546a1SSandrine Bailleux	bl	zeromem16
13465f546a1SSandrine Bailleux
135caa84939SJeenu Viswambharan	/* ---------------------------------------------
136caa84939SJeenu Viswambharan	 * Use SP_EL0 for the C runtime stack.
137caa84939SJeenu Viswambharan	 * ---------------------------------------------
138caa84939SJeenu Viswambharan	 */
139caa84939SJeenu Viswambharan	msr	spsel, #0
140caa84939SJeenu Viswambharan
1414f6ad66aSAchin Gupta	/* --------------------------------------------
1424f6ad66aSAchin Gupta	 * Give ourselves a small coherent stack to
1434f6ad66aSAchin Gupta	 * ease the pain of initializing the MMU
1444f6ad66aSAchin Gupta	 * --------------------------------------------
1454f6ad66aSAchin Gupta	 */
1467935d0a5SAndrew Thoelke	mrs	x0, mpidr_el1
1474f6ad66aSAchin Gupta	bl	platform_set_coherent_stack
1484f6ad66aSAchin Gupta
1494f6ad66aSAchin Gupta	/* ---------------------------------------------
1504f6ad66aSAchin Gupta	 * Perform platform specific early arch. setup
1514f6ad66aSAchin Gupta	 * ---------------------------------------------
1524f6ad66aSAchin Gupta	 */
153*dbad1bacSVikram Kanigiri#if RESET_TO_BL31
154*dbad1bacSVikram Kanigiri	mov	x0, 0
155*dbad1bacSVikram Kanigiri	mov	x1, 0
156*dbad1bacSVikram Kanigiri#else
1574f6ad66aSAchin Gupta	mov	x0, x20
1584f6ad66aSAchin Gupta	mov	x1, x21
159*dbad1bacSVikram Kanigiri#endif
160*dbad1bacSVikram Kanigiri
1614f6ad66aSAchin Gupta	bl	bl31_early_platform_setup
1624f6ad66aSAchin Gupta	bl	bl31_plat_arch_setup
1634f6ad66aSAchin Gupta
1644f6ad66aSAchin Gupta	/* ---------------------------------------------
1654f6ad66aSAchin Gupta	 * Give ourselves a stack allocated in Normal
1664f6ad66aSAchin Gupta	 * -IS-WBWA memory
1674f6ad66aSAchin Gupta	 * ---------------------------------------------
1684f6ad66aSAchin Gupta	 */
1697935d0a5SAndrew Thoelke	mrs	x0, mpidr_el1
1704f6ad66aSAchin Gupta	bl	platform_set_stack
1714f6ad66aSAchin Gupta
1724f6ad66aSAchin Gupta	/* ---------------------------------------------
1734f6ad66aSAchin Gupta	 * Jump to main function.
1744f6ad66aSAchin Gupta	 * ---------------------------------------------
1754f6ad66aSAchin Gupta	 */
1764f6ad66aSAchin Gupta	bl	bl31_main
1774f6ad66aSAchin Gupta
178caa84939SJeenu Viswambharan	b	el3_exit
179caa84939SJeenu Viswambharan
1804f6ad66aSAchin Gupta_panic:
181caa84939SJeenu Viswambharan	wfi
1824f6ad66aSAchin Gupta	b	_panic
183