xref: /rk3399_ARM-atf/bl1/aarch64/bl1_entrypoint.S (revision 8b779620d3bad024b83650ecfeaafd7b3ae26ccf)
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>
334f6ad66aSAchin Gupta
349f98aa1aSJeenu Viswambharan	.globl	bl1_entrypoint
354f6ad66aSAchin Gupta
364f6ad66aSAchin Gupta
374f6ad66aSAchin Gupta	/* -----------------------------------------------------
389f98aa1aSJeenu Viswambharan	 * bl1_entrypoint() is the entry point into the trusted
394f6ad66aSAchin Gupta	 * firmware code when a cpu is released from warm or
404f6ad66aSAchin Gupta	 * cold reset.
414f6ad66aSAchin Gupta	 * -----------------------------------------------------
424f6ad66aSAchin Gupta	 */
434f6ad66aSAchin Gupta
440a30cf54SAndrew Thoelkefunc bl1_entrypoint
454f6ad66aSAchin Gupta	/* ---------------------------------------------
4640fd0725SAndrew Thoelke	 * Set the CPU endianness before doing anything
47ec3c1003SAchin Gupta	 * that might involve memory reads or writes.
4840fd0725SAndrew Thoelke	 * ---------------------------------------------
4940fd0725SAndrew Thoelke	 */
5040fd0725SAndrew Thoelke	mrs	x0, sctlr_el3
5140fd0725SAndrew Thoelke	bic	x0, x0, #SCTLR_EE_BIT
5240fd0725SAndrew Thoelke	msr	sctlr_el3, x0
5340fd0725SAndrew Thoelke	isb
5440fd0725SAndrew Thoelke
5540fd0725SAndrew Thoelke	/* ---------------------------------------------
564f6ad66aSAchin Gupta	 * Perform any processor specific actions upon
574f6ad66aSAchin Gupta	 * reset e.g. cache, tlb invalidations etc.
584f6ad66aSAchin Gupta	 * ---------------------------------------------
594f6ad66aSAchin Gupta	 */
609b476841SSoby Mathew	bl	reset_handler
614f6ad66aSAchin Gupta
62ec3c1003SAchin Gupta	/* ---------------------------------------------
63ec3c1003SAchin Gupta	 * Enable the instruction cache, stack pointer
64ec3c1003SAchin Gupta	 * and data access alignment checks
65ec3c1003SAchin Gupta	 * ---------------------------------------------
66dbad1bacSVikram Kanigiri	 */
67ec3c1003SAchin Gupta	mov	x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
68dbad1bacSVikram Kanigiri	mrs	x0, sctlr_el3
69ec3c1003SAchin Gupta	orr	x0, x0, x1
70dbad1bacSVikram Kanigiri	msr	sctlr_el3, x0
71dbad1bacSVikram Kanigiri	isb
72dbad1bacSVikram Kanigiri
73c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
74c10bd2ceSSandrine Bailleux	 * Set the exception vector to something sane.
75c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
76c10bd2ceSSandrine Bailleux	 */
776c595b3dSSandrine Bailleux	adr	x0, bl1_exceptions
78c10bd2ceSSandrine Bailleux	msr	vbar_el3, x0
790c8d4fefSAchin Gupta	isb
800c8d4fefSAchin Gupta
810c8d4fefSAchin Gupta	/* ---------------------------------------------
820c8d4fefSAchin Gupta	 * Enable the SError interrupt now that the
830c8d4fefSAchin Gupta	 * exception vectors have been setup.
840c8d4fefSAchin Gupta	 * ---------------------------------------------
850c8d4fefSAchin Gupta	 */
860c8d4fefSAchin Gupta	msr	daifclr, #DAIF_ABT_BIT
87c10bd2ceSSandrine Bailleux
884f603683SHarry Liebel	/* ---------------------------------------------------------------------
894f603683SHarry Liebel	 * The initial state of the Architectural feature trap register
904f603683SHarry Liebel	 * (CPTR_EL3) is unknown and it must be set to a known state. All
914f603683SHarry Liebel	 * feature traps are disabled. Some bits in this register are marked as
924f603683SHarry Liebel	 * Reserved and should not be modified.
934f603683SHarry Liebel	 *
944f603683SHarry Liebel	 * CPTR_EL3.TCPAC: This causes a direct access to the CPACR_EL1 from EL1
954f603683SHarry Liebel	 *  or the CPTR_EL2 from EL2 to trap to EL3 unless it is trapped at EL2.
964f603683SHarry Liebel	 * CPTR_EL3.TTA: This causes access to the Trace functionality to trap
974f603683SHarry Liebel	 *  to EL3 when executed from EL0, EL1, EL2, or EL3. If system register
984f603683SHarry Liebel	 *  access to trace functionality is not supported, this bit is RES0.
994f603683SHarry Liebel	 * CPTR_EL3.TFP: This causes instructions that access the registers
1004f603683SHarry Liebel	 *  associated with Floating Point and Advanced SIMD execution to trap
1014f603683SHarry Liebel	 *  to EL3 when executed from any exception level, unless trapped to EL1
1024f603683SHarry Liebel	 *  or EL2.
1034f603683SHarry Liebel	 * ---------------------------------------------------------------------
1044f603683SHarry Liebel	 */
1054f603683SHarry Liebel	mrs	x0, cptr_el3
1064f603683SHarry Liebel	bic	w0, w0, #TCPAC_BIT
1074f603683SHarry Liebel	bic	w0, w0, #TTA_BIT
1084f603683SHarry Liebel	bic	w0, w0, #TFP_BIT
1094f603683SHarry Liebel	msr	cptr_el3, x0
1104f603683SHarry Liebel
11103396c43SVikram Kanigiri	/* -------------------------------------------------------
11203396c43SVikram Kanigiri	 * Will not return from this macro if it is a warm boot.
11303396c43SVikram Kanigiri	 * -------------------------------------------------------
1144f6ad66aSAchin Gupta	 */
115dbad1bacSVikram Kanigiri	wait_for_entrypoint
1164f6ad66aSAchin Gupta
117dbad1bacSVikram Kanigiri	bl	platform_mem_init
1184f6ad66aSAchin Gupta
1194f6ad66aSAchin Gupta	/* ---------------------------------------------
12065f546a1SSandrine Bailleux	 * Init C runtime environment.
12165f546a1SSandrine Bailleux	 *   - Zero-initialise the NOBITS sections.
12265f546a1SSandrine Bailleux	 *     There are 2 of them:
12365f546a1SSandrine Bailleux	 *       - the .bss section;
12465f546a1SSandrine Bailleux	 *       - the coherent memory section.
12565f546a1SSandrine Bailleux	 *   - Copy the data section from BL1 image
12665f546a1SSandrine Bailleux	 *     (stored in ROM) to the correct location
12765f546a1SSandrine Bailleux	 *     in RAM.
12865f546a1SSandrine Bailleux	 * ---------------------------------------------
12965f546a1SSandrine Bailleux	 */
13065f546a1SSandrine Bailleux	ldr	x0, =__BSS_START__
13165f546a1SSandrine Bailleux	ldr	x1, =__BSS_SIZE__
13265f546a1SSandrine Bailleux	bl	zeromem16
13365f546a1SSandrine Bailleux
134ab8707e6SSoby Mathew#if USE_COHERENT_MEM
13565f546a1SSandrine Bailleux	ldr	x0, =__COHERENT_RAM_START__
13665f546a1SSandrine Bailleux	ldr	x1, =__COHERENT_RAM_UNALIGNED_SIZE__
13765f546a1SSandrine Bailleux	bl	zeromem16
138ab8707e6SSoby Mathew#endif
13965f546a1SSandrine Bailleux
14065f546a1SSandrine Bailleux	ldr	x0, =__DATA_RAM_START__
14165f546a1SSandrine Bailleux	ldr	x1, =__DATA_ROM_START__
14265f546a1SSandrine Bailleux	ldr	x2, =__DATA_SIZE__
14365f546a1SSandrine Bailleux	bl	memcpy16
14465f546a1SSandrine Bailleux
145754a2b7aSAchin Gupta	/* --------------------------------------------
146754a2b7aSAchin Gupta	 * Allocate a stack whose memory will be marked
147754a2b7aSAchin Gupta	 * as Normal-IS-WBWA when the MMU is enabled.
148754a2b7aSAchin Gupta	 * There is no risk of reading stale stack
149754a2b7aSAchin Gupta	 * memory after enabling the MMU as only the
150754a2b7aSAchin Gupta	 * primary cpu is running at the moment.
151754a2b7aSAchin Gupta	 * --------------------------------------------
1524f6ad66aSAchin Gupta	 */
153dbad1bacSVikram Kanigiri	mrs	x0, mpidr_el1
154754a2b7aSAchin Gupta	bl	platform_set_stack
1554f6ad66aSAchin Gupta
1564f6ad66aSAchin Gupta	/* ---------------------------------------------
157dbad1bacSVikram Kanigiri	 * Architectural init. can be generic e.g.
158dbad1bacSVikram Kanigiri	 * enabling stack alignment and platform spec-
159dbad1bacSVikram Kanigiri	 * ific e.g. MMU & page table setup as per the
160dbad1bacSVikram Kanigiri	 * platform memory map. Perform the latter here
161dbad1bacSVikram Kanigiri	 * and the former in bl1_main.
1624f6ad66aSAchin Gupta	 * ---------------------------------------------
1634f6ad66aSAchin Gupta	 */
164dbad1bacSVikram Kanigiri	bl	bl1_early_platform_setup
165dbad1bacSVikram Kanigiri	bl	bl1_plat_arch_setup
166dbad1bacSVikram Kanigiri
167dbad1bacSVikram Kanigiri	/* --------------------------------------------------
168dbad1bacSVikram Kanigiri	 * Initialize platform and jump to our c-entry point
169dbad1bacSVikram Kanigiri	 * for this type of reset. Panic if it returns
170dbad1bacSVikram Kanigiri	 * --------------------------------------------------
171dbad1bacSVikram Kanigiri	 */
172dbad1bacSVikram Kanigiri	bl	bl1_main
173dbad1bacSVikram Kanigiripanic:
174dbad1bacSVikram Kanigiri	b	panic
175*8b779620SKévin Petitendfunc bl1_entrypoint
176