xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision 65f546a14fbc0438c051b4243f71abd2206a7307)
14f6ad66aSAchin Gupta/*
24f6ad66aSAchin Gupta * Copyright (c) 2013, ARM Limited. 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
314f6ad66aSAchin Gupta#include <bl1.h>
324f6ad66aSAchin Gupta#include <bl_common.h>
334f6ad66aSAchin Gupta#include <platform.h>
34c10bd2ceSSandrine Bailleux#include <arch.h>
354f6ad66aSAchin Gupta
364f6ad66aSAchin Gupta
374f6ad66aSAchin Gupta	.globl	bl31_entrypoint
384f6ad66aSAchin Gupta
394f6ad66aSAchin Gupta
408d69a03fSSandrine Bailleux	.section	.text, "ax"; .align 3
414f6ad66aSAchin Gupta
424f6ad66aSAchin Gupta	/* -----------------------------------------------------
434f6ad66aSAchin Gupta	 * bl31_entrypoint() is the cold boot entrypoint,
444f6ad66aSAchin Gupta	 * executed only by the primary cpu.
454f6ad66aSAchin Gupta	 * -----------------------------------------------------
464f6ad66aSAchin Gupta	 */
474f6ad66aSAchin Gupta
484f6ad66aSAchin Guptabl31_entrypoint:; .type bl31_entrypoint, %function
494f6ad66aSAchin Gupta	/* ---------------------------------------------
504f6ad66aSAchin Gupta	 * BL2 has populated x0,x3,x4 with the opcode
514f6ad66aSAchin Gupta	 * indicating BL31 should be run, memory layout
524f6ad66aSAchin Gupta	 * of the trusted SRAM available to BL31 and
534f6ad66aSAchin Gupta	 * information about running the non-trusted
54c10bd2ceSSandrine Bailleux	 * software already loaded by BL2.
55c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
56c10bd2ceSSandrine Bailleux	 */
57c10bd2ceSSandrine Bailleux
58c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
59c10bd2ceSSandrine Bailleux	 * Set the exception vector to something sane.
60c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
61c10bd2ceSSandrine Bailleux	 */
62c10bd2ceSSandrine Bailleux	adr	x1, runtime_exceptions
63c10bd2ceSSandrine Bailleux	msr	vbar_el3, x1
64c10bd2ceSSandrine Bailleux
65c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
66c10bd2ceSSandrine Bailleux	 * Enable the instruction cache.
67c10bd2ceSSandrine Bailleux	 * ---------------------------------------------
68c10bd2ceSSandrine Bailleux	 */
69c10bd2ceSSandrine Bailleux	mrs	x1, sctlr_el3
70c10bd2ceSSandrine Bailleux	orr	x1, x1, #SCTLR_I_BIT
71c10bd2ceSSandrine Bailleux	msr	sctlr_el3, x1
72c10bd2ceSSandrine Bailleux
73c10bd2ceSSandrine Bailleux	isb
74c10bd2ceSSandrine Bailleux
75c10bd2ceSSandrine Bailleux	/* ---------------------------------------------
76c10bd2ceSSandrine Bailleux	 * Check the opcodes out of paranoia.
774f6ad66aSAchin Gupta	 * ---------------------------------------------
784f6ad66aSAchin Gupta	 */
794f6ad66aSAchin Gupta	mov	x19, #RUN_IMAGE
804f6ad66aSAchin Gupta	cmp	x0, x19
814f6ad66aSAchin Gupta	b.ne	_panic
824f6ad66aSAchin Gupta	mov	x20, x3
834f6ad66aSAchin Gupta	mov	x21, x4
844f6ad66aSAchin Gupta
854f6ad66aSAchin Gupta	/* ---------------------------------------------
864f6ad66aSAchin Gupta	 * This is BL31 which is expected to be executed
874f6ad66aSAchin Gupta	 * only by the primary cpu (at least for now).
884f6ad66aSAchin Gupta	 * So, make sure no secondary has lost its way.
894f6ad66aSAchin Gupta	 * ---------------------------------------------
904f6ad66aSAchin Gupta	 */
914f6ad66aSAchin Gupta	bl	read_mpidr
924f6ad66aSAchin Gupta	mov	x19, x0
934f6ad66aSAchin Gupta	bl	platform_is_primary_cpu
944f6ad66aSAchin Gupta	cbz	x0, _panic
954f6ad66aSAchin Gupta
96*65f546a1SSandrine Bailleux	/* ---------------------------------------------
97*65f546a1SSandrine Bailleux	 * Zero out NOBITS sections. There are 2 of them:
98*65f546a1SSandrine Bailleux	 *   - the .bss section;
99*65f546a1SSandrine Bailleux	 *   - the coherent memory section.
100*65f546a1SSandrine Bailleux	 * ---------------------------------------------
101*65f546a1SSandrine Bailleux	 */
102*65f546a1SSandrine Bailleux	ldr	x0, =__BSS_START__
103*65f546a1SSandrine Bailleux	ldr	x1, =__BSS_SIZE__
104*65f546a1SSandrine Bailleux	bl	zeromem16
105*65f546a1SSandrine Bailleux
106*65f546a1SSandrine Bailleux	ldr	x0, =__COHERENT_RAM_START__
107*65f546a1SSandrine Bailleux	ldr	x1, =__COHERENT_RAM_UNALIGNED_SIZE__
108*65f546a1SSandrine Bailleux	bl	zeromem16
109*65f546a1SSandrine Bailleux
1104f6ad66aSAchin Gupta	/* --------------------------------------------
1114f6ad66aSAchin Gupta	 * Give ourselves a small coherent stack to
1124f6ad66aSAchin Gupta	 * ease the pain of initializing the MMU
1134f6ad66aSAchin Gupta	 * --------------------------------------------
1144f6ad66aSAchin Gupta	 */
1154f6ad66aSAchin Gupta	mov	x0, x19
1164f6ad66aSAchin Gupta	bl	platform_set_coherent_stack
1174f6ad66aSAchin Gupta
1184f6ad66aSAchin Gupta	/* ---------------------------------------------
1194f6ad66aSAchin Gupta	 * Perform platform specific early arch. setup
1204f6ad66aSAchin Gupta	 * ---------------------------------------------
1214f6ad66aSAchin Gupta	 */
1224f6ad66aSAchin Gupta	mov	x0, x20
1234f6ad66aSAchin Gupta	mov	x1, x21
1244f6ad66aSAchin Gupta	mov	x2, x19
1254f6ad66aSAchin Gupta	bl	bl31_early_platform_setup
1264f6ad66aSAchin Gupta	bl	bl31_plat_arch_setup
1274f6ad66aSAchin Gupta
1284f6ad66aSAchin Gupta	/* ---------------------------------------------
1294f6ad66aSAchin Gupta	 * Give ourselves a stack allocated in Normal
1304f6ad66aSAchin Gupta	 * -IS-WBWA memory
1314f6ad66aSAchin Gupta	 * ---------------------------------------------
1324f6ad66aSAchin Gupta	 */
1334f6ad66aSAchin Gupta	mov	x0, x19
1344f6ad66aSAchin Gupta	bl	platform_set_stack
1354f6ad66aSAchin Gupta
1364f6ad66aSAchin Gupta	/* ---------------------------------------------
1374f6ad66aSAchin Gupta	 * Use SP_EL0 to initialize BL31. It allows us
1384f6ad66aSAchin Gupta	 * to jump to the next image without having to
1394f6ad66aSAchin Gupta	 * come back here to ensure all of the stack's
1404f6ad66aSAchin Gupta	 * been popped out. run_image() is not nice
1414f6ad66aSAchin Gupta	 * enough to reset the stack pointer before
1424f6ad66aSAchin Gupta	 * handing control to the next stage.
1434f6ad66aSAchin Gupta	 * ---------------------------------------------
1444f6ad66aSAchin Gupta	 */
1454f6ad66aSAchin Gupta	mov	x0, sp
1464f6ad66aSAchin Gupta	msr	sp_el0, x0
1474f6ad66aSAchin Gupta	msr	spsel, #0
1484f6ad66aSAchin Gupta	isb
1494f6ad66aSAchin Gupta
1504f6ad66aSAchin Gupta	/* ---------------------------------------------
1514f6ad66aSAchin Gupta	 * Jump to main function.
1524f6ad66aSAchin Gupta	 * ---------------------------------------------
1534f6ad66aSAchin Gupta	 */
1544f6ad66aSAchin Gupta	bl	bl31_main
1554f6ad66aSAchin Gupta
1564f6ad66aSAchin Gupta_panic:
1574f6ad66aSAchin Gupta	b	_panic
158