xref: /rk3399_ARM-atf/bl1/aarch64/bl1_entrypoint.S (revision 9f98aa1a7e33dd55851fd4feec0de9b40b6d9f10)
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>
324f6ad66aSAchin Gupta
33*9f98aa1aSJeenu Viswambharan	.globl	bl1_entrypoint
344f6ad66aSAchin Gupta
354f6ad66aSAchin Gupta
368d69a03fSSandrine Bailleux	.section	.text, "ax"; .align 3
374f6ad66aSAchin Gupta
384f6ad66aSAchin Gupta	/* -----------------------------------------------------
39*9f98aa1aSJeenu Viswambharan	 * bl1_entrypoint() is the entry point into the trusted
404f6ad66aSAchin Gupta	 * firmware code when a cpu is released from warm or
414f6ad66aSAchin Gupta	 * cold reset.
424f6ad66aSAchin Gupta	 * -----------------------------------------------------
434f6ad66aSAchin Gupta	 */
444f6ad66aSAchin Gupta
45*9f98aa1aSJeenu Viswambharanbl1_entrypoint: ; .type bl1_entrypoint, %function
464f6ad66aSAchin Gupta	/* ---------------------------------------------
474f6ad66aSAchin Gupta	 * Perform any processor specific actions upon
484f6ad66aSAchin Gupta	 * reset e.g. cache, tlb invalidations etc.
494f6ad66aSAchin Gupta	 * ---------------------------------------------
504f6ad66aSAchin Gupta	 */
514f6ad66aSAchin Gupta	bl	cpu_reset_handler
524f6ad66aSAchin Gupta
53c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
54c10bd2ceSSandrine Bailleux	 * Set the exception vector to something sane.
55c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
56c10bd2ceSSandrine Bailleux	 */
57c10bd2ceSSandrine Bailleux	adr	x0, early_exceptions
58c10bd2ceSSandrine Bailleux	msr	vbar_el3, x0
59c10bd2ceSSandrine Bailleux
604f603683SHarry Liebel	/* ---------------------------------------------------------------------
614f603683SHarry Liebel	 * The initial state of the Architectural feature trap register
624f603683SHarry Liebel	 * (CPTR_EL3) is unknown and it must be set to a known state. All
634f603683SHarry Liebel	 * feature traps are disabled. Some bits in this register are marked as
644f603683SHarry Liebel	 * Reserved and should not be modified.
654f603683SHarry Liebel	 *
664f603683SHarry Liebel	 * CPTR_EL3.TCPAC: This causes a direct access to the CPACR_EL1 from EL1
674f603683SHarry Liebel	 *  or the CPTR_EL2 from EL2 to trap to EL3 unless it is trapped at EL2.
684f603683SHarry Liebel	 * CPTR_EL3.TTA: This causes access to the Trace functionality to trap
694f603683SHarry Liebel	 *  to EL3 when executed from EL0, EL1, EL2, or EL3. If system register
704f603683SHarry Liebel	 *  access to trace functionality is not supported, this bit is RES0.
714f603683SHarry Liebel	 * CPTR_EL3.TFP: This causes instructions that access the registers
724f603683SHarry Liebel	 *  associated with Floating Point and Advanced SIMD execution to trap
734f603683SHarry Liebel	 *  to EL3 when executed from any exception level, unless trapped to EL1
744f603683SHarry Liebel	 *  or EL2.
754f603683SHarry Liebel	 * ---------------------------------------------------------------------
764f603683SHarry Liebel	 */
774f603683SHarry Liebel	mrs	x0, cptr_el3
784f603683SHarry Liebel	bic	w0, w0, #TCPAC_BIT
794f603683SHarry Liebel	bic	w0, w0, #TTA_BIT
804f603683SHarry Liebel	bic	w0, w0, #TFP_BIT
814f603683SHarry Liebel	msr	cptr_el3, x0
824f603683SHarry Liebel
83c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
84c10bd2ceSSandrine Bailleux	 * Enable the instruction cache.
85c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
86c10bd2ceSSandrine Bailleux	 */
87c10bd2ceSSandrine Bailleux	mrs	x0, sctlr_el3
88c10bd2ceSSandrine Bailleux	orr	x0, x0, #SCTLR_I_BIT
89c10bd2ceSSandrine Bailleux	msr	sctlr_el3, x0
90c10bd2ceSSandrine Bailleux
91c10bd2ceSSandrine Bailleux	isb
92c10bd2ceSSandrine Bailleux
934f6ad66aSAchin Gupta_wait_for_entrypoint:
944f6ad66aSAchin Gupta	/* ---------------------------------------------
954f6ad66aSAchin Gupta	 * Find the type of reset and jump to handler
964f6ad66aSAchin Gupta	 * if present. If the handler is null then it is
974f6ad66aSAchin Gupta	 * a cold boot. The primary cpu will set up the
984f6ad66aSAchin Gupta	 * platform while the secondaries wait for
994f6ad66aSAchin Gupta	 * their turn to be woken up
1004f6ad66aSAchin Gupta	 * ---------------------------------------------
1014f6ad66aSAchin Gupta	 */
1024f6ad66aSAchin Gupta	bl	read_mpidr
1034f6ad66aSAchin Gupta	bl	platform_get_entrypoint
1044f6ad66aSAchin Gupta	cbnz	x0, _do_warm_boot
1054f6ad66aSAchin Gupta	bl	read_mpidr
1064f6ad66aSAchin Gupta	bl	platform_is_primary_cpu
1074f6ad66aSAchin Gupta	cbnz	x0, _do_cold_boot
1084f6ad66aSAchin Gupta
1094f6ad66aSAchin Gupta	/* ---------------------------------------------
1104f6ad66aSAchin Gupta	 * Perform any platform specific secondary cpu
1114f6ad66aSAchin Gupta	 * actions
1124f6ad66aSAchin Gupta	 * ---------------------------------------------
1134f6ad66aSAchin Gupta	 */
1144f6ad66aSAchin Gupta	bl	plat_secondary_cold_boot_setup
1154f6ad66aSAchin Gupta	b	_wait_for_entrypoint
1164f6ad66aSAchin Gupta
1174f6ad66aSAchin Gupta_do_cold_boot:
1184f6ad66aSAchin Gupta	/* ---------------------------------------------
11965f546a1SSandrine Bailleux	 * Init C runtime environment.
12065f546a1SSandrine Bailleux	 *   - Zero-initialise the NOBITS sections.
12165f546a1SSandrine Bailleux	 *     There are 2 of them:
12265f546a1SSandrine Bailleux	 *       - the .bss section;
12365f546a1SSandrine Bailleux	 *       - the coherent memory section.
12465f546a1SSandrine Bailleux	 *   - Copy the data section from BL1 image
12565f546a1SSandrine Bailleux	 *     (stored in ROM) to the correct location
12665f546a1SSandrine Bailleux	 *     in RAM.
12765f546a1SSandrine Bailleux	 * ---------------------------------------------
12865f546a1SSandrine Bailleux	 */
12965f546a1SSandrine Bailleux	ldr	x0, =__BSS_START__
13065f546a1SSandrine Bailleux	ldr	x1, =__BSS_SIZE__
13165f546a1SSandrine Bailleux	bl	zeromem16
13265f546a1SSandrine Bailleux
13365f546a1SSandrine Bailleux	ldr	x0, =__COHERENT_RAM_START__
13465f546a1SSandrine Bailleux	ldr	x1, =__COHERENT_RAM_UNALIGNED_SIZE__
13565f546a1SSandrine Bailleux	bl	zeromem16
13665f546a1SSandrine Bailleux
13765f546a1SSandrine Bailleux	ldr	x0, =__DATA_RAM_START__
13865f546a1SSandrine Bailleux	ldr	x1, =__DATA_ROM_START__
13965f546a1SSandrine Bailleux	ldr	x2, =__DATA_SIZE__
14065f546a1SSandrine Bailleux	bl	memcpy16
14165f546a1SSandrine Bailleux
14265f546a1SSandrine Bailleux	/* ---------------------------------------------
1434f6ad66aSAchin Gupta	 * Initialize platform and jump to our c-entry
1444f6ad66aSAchin Gupta	 * point for this type of reset
1454f6ad66aSAchin Gupta	 * ---------------------------------------------
1464f6ad66aSAchin Gupta	 */
1474f6ad66aSAchin Gupta	adr	x0, bl1_main
1484f6ad66aSAchin Gupta	bl	platform_cold_boot_init
1494f6ad66aSAchin Gupta	b	_panic
1504f6ad66aSAchin Gupta
1514f6ad66aSAchin Gupta_do_warm_boot:
1524f6ad66aSAchin Gupta	/* ---------------------------------------------
1534f6ad66aSAchin Gupta	 * Jump to BL31 for all warm boot init.
1544f6ad66aSAchin Gupta	 * ---------------------------------------------
1554f6ad66aSAchin Gupta	 */
1564f6ad66aSAchin Gupta	blr	x0
1574f6ad66aSAchin Gupta_panic:
1584f6ad66aSAchin Gupta	b	_panic
159