xref: /rk3399_ARM-atf/bl1/aarch64/bl1_exceptions.S (revision 7baff11fb51c2739d1c0fbac894c75b3c4b242e2)
16c595b3dSSandrine Bailleux/*
2bbf8f6f9SYatharth Kochar * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
36c595b3dSSandrine Bailleux *
46c595b3dSSandrine Bailleux * Redistribution and use in source and binary forms, with or without
56c595b3dSSandrine Bailleux * modification, are permitted provided that the following conditions are met:
66c595b3dSSandrine Bailleux *
76c595b3dSSandrine Bailleux * Redistributions of source code must retain the above copyright notice, this
86c595b3dSSandrine Bailleux * list of conditions and the following disclaimer.
96c595b3dSSandrine Bailleux *
106c595b3dSSandrine Bailleux * Redistributions in binary form must reproduce the above copyright notice,
116c595b3dSSandrine Bailleux * this list of conditions and the following disclaimer in the documentation
126c595b3dSSandrine Bailleux * and/or other materials provided with the distribution.
136c595b3dSSandrine Bailleux *
146c595b3dSSandrine Bailleux * Neither the name of ARM nor the names of its contributors may be used
156c595b3dSSandrine Bailleux * to endorse or promote products derived from this software without specific
166c595b3dSSandrine Bailleux * prior written permission.
176c595b3dSSandrine Bailleux *
186c595b3dSSandrine Bailleux * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
196c595b3dSSandrine Bailleux * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206c595b3dSSandrine Bailleux * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
216c595b3dSSandrine Bailleux * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
226c595b3dSSandrine Bailleux * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
236c595b3dSSandrine Bailleux * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
246c595b3dSSandrine Bailleux * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
256c595b3dSSandrine Bailleux * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266c595b3dSSandrine Bailleux * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
276c595b3dSSandrine Bailleux * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
286c595b3dSSandrine Bailleux * POSSIBILITY OF SUCH DAMAGE.
296c595b3dSSandrine Bailleux */
306c595b3dSSandrine Bailleux
316c595b3dSSandrine Bailleux#include <arch.h>
326c595b3dSSandrine Bailleux#include <asm_macros.S>
3397043ac9SDan Handley#include <bl_common.h>
34*7baff11fSYatharth Kochar#include <context.h>
356c595b3dSSandrine Bailleux
366c595b3dSSandrine Bailleux	.globl	bl1_exceptions
376c595b3dSSandrine Bailleux
386c595b3dSSandrine Bailleux	.section	.vectors, "ax"; .align 11
396c595b3dSSandrine Bailleux
406c595b3dSSandrine Bailleux	/* -----------------------------------------------------
416c595b3dSSandrine Bailleux	 * Very simple stackless exception handlers used by BL1.
426c595b3dSSandrine Bailleux	 * -----------------------------------------------------
436c595b3dSSandrine Bailleux	 */
446c595b3dSSandrine Bailleux	.align	7
456c595b3dSSandrine Bailleuxbl1_exceptions:
466c595b3dSSandrine Bailleux	/* -----------------------------------------------------
4744804252SSandrine Bailleux	 * Current EL with SP0 : 0x0 - 0x200
486c595b3dSSandrine Bailleux	 * -----------------------------------------------------
496c595b3dSSandrine Bailleux	 */
506c595b3dSSandrine BailleuxSynchronousExceptionSP0:
516c595b3dSSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_SP_EL0
526c595b3dSSandrine Bailleux	bl	plat_report_exception
536c595b3dSSandrine Bailleux	b	SynchronousExceptionSP0
546c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionSP0
556c595b3dSSandrine Bailleux
566c595b3dSSandrine Bailleux	.align	7
576c595b3dSSandrine BailleuxIrqSP0:
586c595b3dSSandrine Bailleux	mov	x0, #IRQ_SP_EL0
596c595b3dSSandrine Bailleux	bl	plat_report_exception
606c595b3dSSandrine Bailleux	b	IrqSP0
616c595b3dSSandrine Bailleux	check_vector_size IrqSP0
626c595b3dSSandrine Bailleux
636c595b3dSSandrine Bailleux	.align	7
646c595b3dSSandrine BailleuxFiqSP0:
656c595b3dSSandrine Bailleux	mov	x0, #FIQ_SP_EL0
666c595b3dSSandrine Bailleux	bl	plat_report_exception
676c595b3dSSandrine Bailleux	b	FiqSP0
686c595b3dSSandrine Bailleux	check_vector_size FiqSP0
696c595b3dSSandrine Bailleux
706c595b3dSSandrine Bailleux	.align	7
716c595b3dSSandrine BailleuxSErrorSP0:
726c595b3dSSandrine Bailleux	mov	x0, #SERROR_SP_EL0
736c595b3dSSandrine Bailleux	bl	plat_report_exception
746c595b3dSSandrine Bailleux	b	SErrorSP0
756c595b3dSSandrine Bailleux	check_vector_size SErrorSP0
766c595b3dSSandrine Bailleux
776c595b3dSSandrine Bailleux	/* -----------------------------------------------------
7844804252SSandrine Bailleux	 * Current EL with SPx: 0x200 - 0x400
796c595b3dSSandrine Bailleux	 * -----------------------------------------------------
806c595b3dSSandrine Bailleux	 */
816c595b3dSSandrine Bailleux	.align	7
826c595b3dSSandrine BailleuxSynchronousExceptionSPx:
836c595b3dSSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_SP_ELX
846c595b3dSSandrine Bailleux	bl	plat_report_exception
856c595b3dSSandrine Bailleux	b	SynchronousExceptionSPx
866c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionSPx
876c595b3dSSandrine Bailleux
886c595b3dSSandrine Bailleux	.align	7
896c595b3dSSandrine BailleuxIrqSPx:
906c595b3dSSandrine Bailleux	mov	x0, #IRQ_SP_ELX
916c595b3dSSandrine Bailleux	bl	plat_report_exception
926c595b3dSSandrine Bailleux	b	IrqSPx
936c595b3dSSandrine Bailleux	check_vector_size IrqSPx
946c595b3dSSandrine Bailleux
956c595b3dSSandrine Bailleux	.align	7
966c595b3dSSandrine BailleuxFiqSPx:
976c595b3dSSandrine Bailleux	mov	x0, #FIQ_SP_ELX
986c595b3dSSandrine Bailleux	bl	plat_report_exception
996c595b3dSSandrine Bailleux	b	FiqSPx
1006c595b3dSSandrine Bailleux	check_vector_size FiqSPx
1016c595b3dSSandrine Bailleux
1026c595b3dSSandrine Bailleux	.align	7
1036c595b3dSSandrine BailleuxSErrorSPx:
1046c595b3dSSandrine Bailleux	mov	x0, #SERROR_SP_ELX
1056c595b3dSSandrine Bailleux	bl	plat_report_exception
1066c595b3dSSandrine Bailleux	b	SErrorSPx
1076c595b3dSSandrine Bailleux	check_vector_size SErrorSPx
1086c595b3dSSandrine Bailleux
1096c595b3dSSandrine Bailleux	/* -----------------------------------------------------
11044804252SSandrine Bailleux	 * Lower EL using AArch64 : 0x400 - 0x600
1116c595b3dSSandrine Bailleux	 * -----------------------------------------------------
1126c595b3dSSandrine Bailleux	 */
1136c595b3dSSandrine Bailleux	.align	7
1146c595b3dSSandrine BailleuxSynchronousExceptionA64:
1150c8d4fefSAchin Gupta	/* Enable the SError interrupt */
1160c8d4fefSAchin Gupta	msr	daifclr, #DAIF_ABT_BIT
1170c8d4fefSAchin Gupta
118*7baff11fSYatharth Kochar	str	x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
119*7baff11fSYatharth Kochar
1201fe4d453SSandrine Bailleux	/* Expect only SMC exceptions */
121*7baff11fSYatharth Kochar	mrs	x30, esr_el3
122*7baff11fSYatharth Kochar	ubfx	x30, x30, #ESR_EC_SHIFT, #ESR_EC_LENGTH
123*7baff11fSYatharth Kochar	cmp	x30, #EC_AARCH64_SMC
1241fe4d453SSandrine Bailleux	b.ne	unexpected_sync_exception
12529fb905dSVikram Kanigiri
1261fe4d453SSandrine Bailleux	b	smc_handler64
1276c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionA64
1286c595b3dSSandrine Bailleux
1296c595b3dSSandrine Bailleux	.align	7
1306c595b3dSSandrine BailleuxIrqA64:
1316c595b3dSSandrine Bailleux	mov	x0, #IRQ_AARCH64
1326c595b3dSSandrine Bailleux	bl	plat_report_exception
1336c595b3dSSandrine Bailleux	b	IrqA64
1346c595b3dSSandrine Bailleux	check_vector_size IrqA64
1356c595b3dSSandrine Bailleux
1366c595b3dSSandrine Bailleux	.align	7
1376c595b3dSSandrine BailleuxFiqA64:
1386c595b3dSSandrine Bailleux	mov	x0, #FIQ_AARCH64
1396c595b3dSSandrine Bailleux	bl	plat_report_exception
1406c595b3dSSandrine Bailleux	b	FiqA64
1416c595b3dSSandrine Bailleux	check_vector_size FiqA64
1426c595b3dSSandrine Bailleux
1436c595b3dSSandrine Bailleux	.align	7
1446c595b3dSSandrine BailleuxSErrorA64:
1456c595b3dSSandrine Bailleux	mov	x0, #SERROR_AARCH64
1466c595b3dSSandrine Bailleux	bl	plat_report_exception
1476c595b3dSSandrine Bailleux	b   	SErrorA64
1486c595b3dSSandrine Bailleux	check_vector_size SErrorA64
1496c595b3dSSandrine Bailleux
1506c595b3dSSandrine Bailleux	/* -----------------------------------------------------
15144804252SSandrine Bailleux	 * Lower EL using AArch32 : 0x600 - 0x800
1526c595b3dSSandrine Bailleux	 * -----------------------------------------------------
1536c595b3dSSandrine Bailleux	 */
1546c595b3dSSandrine Bailleux	.align	7
1556c595b3dSSandrine BailleuxSynchronousExceptionA32:
1566c595b3dSSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_AARCH32
1576c595b3dSSandrine Bailleux	bl	plat_report_exception
1586c595b3dSSandrine Bailleux	b	SynchronousExceptionA32
1596c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionA32
1606c595b3dSSandrine Bailleux
1616c595b3dSSandrine Bailleux	.align	7
1626c595b3dSSandrine BailleuxIrqA32:
1636c595b3dSSandrine Bailleux	mov	x0, #IRQ_AARCH32
1646c595b3dSSandrine Bailleux	bl	plat_report_exception
1656c595b3dSSandrine Bailleux	b	IrqA32
1666c595b3dSSandrine Bailleux	check_vector_size IrqA32
1676c595b3dSSandrine Bailleux
1686c595b3dSSandrine Bailleux	.align	7
1696c595b3dSSandrine BailleuxFiqA32:
1706c595b3dSSandrine Bailleux	mov	x0, #FIQ_AARCH32
1716c595b3dSSandrine Bailleux	bl	plat_report_exception
1726c595b3dSSandrine Bailleux	b	FiqA32
1736c595b3dSSandrine Bailleux	check_vector_size FiqA32
1746c595b3dSSandrine Bailleux
1756c595b3dSSandrine Bailleux	.align	7
1766c595b3dSSandrine BailleuxSErrorA32:
1776c595b3dSSandrine Bailleux	mov	x0, #SERROR_AARCH32
1786c595b3dSSandrine Bailleux	bl	plat_report_exception
1796c595b3dSSandrine Bailleux	b	SErrorA32
1806c595b3dSSandrine Bailleux	check_vector_size SErrorA32
1811fe4d453SSandrine Bailleux
1821fe4d453SSandrine Bailleux
1831fe4d453SSandrine Bailleuxfunc smc_handler64
184*7baff11fSYatharth Kochar	/* ----------------------------------------------
185*7baff11fSYatharth Kochar	 * Switch back to SP_EL0 for the C runtime stack.
186*7baff11fSYatharth Kochar	 * ----------------------------------------------
187*7baff11fSYatharth Kochar	 */
188*7baff11fSYatharth Kochar	ldr	x30, [sp, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP]
189*7baff11fSYatharth Kochar	msr	spsel, #0
190*7baff11fSYatharth Kochar	mov	sp, x30
191*7baff11fSYatharth Kochar
1921fe4d453SSandrine Bailleux	/* ---------------------------------------------------------------------
1931fe4d453SSandrine Bailleux	 * Only a single SMC exception from BL2 to ask BL1 to pass EL3 control
1941fe4d453SSandrine Bailleux	 * to BL31 is expected here. It expects:
1951fe4d453SSandrine Bailleux	 *   - X0 with RUN_IMAGE SMC function ID;
1961fe4d453SSandrine Bailleux	 *   - X1 with the address of a entry_point_info_t structure describing
1971fe4d453SSandrine Bailleux	 *     the BL31 entrypoint.
1981fe4d453SSandrine Bailleux	 * ---------------------------------------------------------------------
1991fe4d453SSandrine Bailleux	 */
2001fe4d453SSandrine Bailleux	mov	x19, x0
2011fe4d453SSandrine Bailleux	mov	x20, x1
2021fe4d453SSandrine Bailleux
2031fe4d453SSandrine Bailleux	mov	x0, #RUN_IMAGE
2041fe4d453SSandrine Bailleux	cmp	x19, x0
2051fe4d453SSandrine Bailleux	b.ne	unexpected_sync_exception
2061fe4d453SSandrine Bailleux
2071fe4d453SSandrine Bailleux	mov	x0, x20
208ee5c2b13SSandrine Bailleux	bl	bl1_print_bl31_ep_info
2091fe4d453SSandrine Bailleux
2101fe4d453SSandrine Bailleux	ldp	x0, x1, [x20, #ENTRY_POINT_INFO_PC_OFFSET]
2111fe4d453SSandrine Bailleux	msr	elr_el3, x0
2121fe4d453SSandrine Bailleux	msr	spsr_el3, x1
2131fe4d453SSandrine Bailleux	ubfx	x0, x1, #MODE_EL_SHIFT, #2
2141fe4d453SSandrine Bailleux	cmp	x0, #MODE_EL3
2151fe4d453SSandrine Bailleux	b.ne	unexpected_sync_exception
2161fe4d453SSandrine Bailleux
2171fe4d453SSandrine Bailleux	bl	disable_mmu_icache_el3
2181fe4d453SSandrine Bailleux	tlbi	alle3
2191fe4d453SSandrine Bailleux
22035e8c766SSandrine Bailleux#if SPIN_ON_BL1_EXIT
22135e8c766SSandrine Bailleux	bl	print_debug_loop_message
22235e8c766SSandrine Bailleuxdebug_loop:
22335e8c766SSandrine Bailleux	b	debug_loop
22435e8c766SSandrine Bailleux#endif
22535e8c766SSandrine Bailleux
226862b5dc2SSandrine Bailleux	mov	x0, x20
227e3f67124SJuan Castillo	bl	bl1_plat_prepare_exit
228e3f67124SJuan Castillo
2291fe4d453SSandrine Bailleux	ldp	x6, x7, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x30)]
2301fe4d453SSandrine Bailleux	ldp	x4, x5, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x20)]
2311fe4d453SSandrine Bailleux	ldp	x2, x3, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x10)]
2321fe4d453SSandrine Bailleux	ldp	x0, x1, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x0)]
2331fe4d453SSandrine Bailleux	eret
2341fe4d453SSandrine Bailleuxendfunc smc_handler64
2351fe4d453SSandrine Bailleux
2361fe4d453SSandrine Bailleuxunexpected_sync_exception:
2371fe4d453SSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_AARCH64
2381fe4d453SSandrine Bailleux	bl	plat_report_exception
2391fe4d453SSandrine Bailleux	wfi
2401fe4d453SSandrine Bailleux	b	unexpected_sync_exception
241