xref: /rk3399_ARM-atf/bl1/aarch64/bl1_exceptions.S (revision bbf8f6f95b1ed9eeaa4e8d746a0660a7620cc415)
16c595b3dSSandrine Bailleux/*
2*bbf8f6f9SYatharth 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>
346c595b3dSSandrine Bailleux
356c595b3dSSandrine Bailleux	.globl	bl1_exceptions
366c595b3dSSandrine Bailleux
376c595b3dSSandrine Bailleux	.section	.vectors, "ax"; .align 11
386c595b3dSSandrine Bailleux
396c595b3dSSandrine Bailleux	/* -----------------------------------------------------
406c595b3dSSandrine Bailleux	 * Very simple stackless exception handlers used by BL1.
416c595b3dSSandrine Bailleux	 * -----------------------------------------------------
426c595b3dSSandrine Bailleux	 */
436c595b3dSSandrine Bailleux	.align	7
446c595b3dSSandrine Bailleuxbl1_exceptions:
456c595b3dSSandrine Bailleux	/* -----------------------------------------------------
4644804252SSandrine Bailleux	 * Current EL with SP0 : 0x0 - 0x200
476c595b3dSSandrine Bailleux	 * -----------------------------------------------------
486c595b3dSSandrine Bailleux	 */
496c595b3dSSandrine BailleuxSynchronousExceptionSP0:
506c595b3dSSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_SP_EL0
516c595b3dSSandrine Bailleux	bl	plat_report_exception
526c595b3dSSandrine Bailleux	b	SynchronousExceptionSP0
536c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionSP0
546c595b3dSSandrine Bailleux
556c595b3dSSandrine Bailleux	.align	7
566c595b3dSSandrine BailleuxIrqSP0:
576c595b3dSSandrine Bailleux	mov	x0, #IRQ_SP_EL0
586c595b3dSSandrine Bailleux	bl	plat_report_exception
596c595b3dSSandrine Bailleux	b	IrqSP0
606c595b3dSSandrine Bailleux	check_vector_size IrqSP0
616c595b3dSSandrine Bailleux
626c595b3dSSandrine Bailleux	.align	7
636c595b3dSSandrine BailleuxFiqSP0:
646c595b3dSSandrine Bailleux	mov	x0, #FIQ_SP_EL0
656c595b3dSSandrine Bailleux	bl	plat_report_exception
666c595b3dSSandrine Bailleux	b	FiqSP0
676c595b3dSSandrine Bailleux	check_vector_size FiqSP0
686c595b3dSSandrine Bailleux
696c595b3dSSandrine Bailleux	.align	7
706c595b3dSSandrine BailleuxSErrorSP0:
716c595b3dSSandrine Bailleux	mov	x0, #SERROR_SP_EL0
726c595b3dSSandrine Bailleux	bl	plat_report_exception
736c595b3dSSandrine Bailleux	b	SErrorSP0
746c595b3dSSandrine Bailleux	check_vector_size SErrorSP0
756c595b3dSSandrine Bailleux
766c595b3dSSandrine Bailleux	/* -----------------------------------------------------
7744804252SSandrine Bailleux	 * Current EL with SPx: 0x200 - 0x400
786c595b3dSSandrine Bailleux	 * -----------------------------------------------------
796c595b3dSSandrine Bailleux	 */
806c595b3dSSandrine Bailleux	.align	7
816c595b3dSSandrine BailleuxSynchronousExceptionSPx:
826c595b3dSSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_SP_ELX
836c595b3dSSandrine Bailleux	bl	plat_report_exception
846c595b3dSSandrine Bailleux	b	SynchronousExceptionSPx
856c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionSPx
866c595b3dSSandrine Bailleux
876c595b3dSSandrine Bailleux	.align	7
886c595b3dSSandrine BailleuxIrqSPx:
896c595b3dSSandrine Bailleux	mov	x0, #IRQ_SP_ELX
906c595b3dSSandrine Bailleux	bl	plat_report_exception
916c595b3dSSandrine Bailleux	b	IrqSPx
926c595b3dSSandrine Bailleux	check_vector_size IrqSPx
936c595b3dSSandrine Bailleux
946c595b3dSSandrine Bailleux	.align	7
956c595b3dSSandrine BailleuxFiqSPx:
966c595b3dSSandrine Bailleux	mov	x0, #FIQ_SP_ELX
976c595b3dSSandrine Bailleux	bl	plat_report_exception
986c595b3dSSandrine Bailleux	b	FiqSPx
996c595b3dSSandrine Bailleux	check_vector_size FiqSPx
1006c595b3dSSandrine Bailleux
1016c595b3dSSandrine Bailleux	.align	7
1026c595b3dSSandrine BailleuxSErrorSPx:
1036c595b3dSSandrine Bailleux	mov	x0, #SERROR_SP_ELX
1046c595b3dSSandrine Bailleux	bl	plat_report_exception
1056c595b3dSSandrine Bailleux	b	SErrorSPx
1066c595b3dSSandrine Bailleux	check_vector_size SErrorSPx
1076c595b3dSSandrine Bailleux
1086c595b3dSSandrine Bailleux	/* -----------------------------------------------------
10944804252SSandrine Bailleux	 * Lower EL using AArch64 : 0x400 - 0x600
1106c595b3dSSandrine Bailleux	 * -----------------------------------------------------
1116c595b3dSSandrine Bailleux	 */
1126c595b3dSSandrine Bailleux	.align	7
1136c595b3dSSandrine BailleuxSynchronousExceptionA64:
1140c8d4fefSAchin Gupta	/* Enable the SError interrupt */
1150c8d4fefSAchin Gupta	msr	daifclr, #DAIF_ABT_BIT
1160c8d4fefSAchin Gupta
1171fe4d453SSandrine Bailleux	/* Expect only SMC exceptions */
1181fe4d453SSandrine Bailleux	mrs	x19, esr_el3
1191fe4d453SSandrine Bailleux	ubfx	x20, x19, #ESR_EC_SHIFT, #ESR_EC_LENGTH
1201fe4d453SSandrine Bailleux	cmp	x20, #EC_AARCH64_SMC
1211fe4d453SSandrine Bailleux	b.ne	unexpected_sync_exception
12229fb905dSVikram Kanigiri
1231fe4d453SSandrine Bailleux	b	smc_handler64
1246c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionA64
1256c595b3dSSandrine Bailleux
1266c595b3dSSandrine Bailleux	.align	7
1276c595b3dSSandrine BailleuxIrqA64:
1286c595b3dSSandrine Bailleux	mov	x0, #IRQ_AARCH64
1296c595b3dSSandrine Bailleux	bl	plat_report_exception
1306c595b3dSSandrine Bailleux	b	IrqA64
1316c595b3dSSandrine Bailleux	check_vector_size IrqA64
1326c595b3dSSandrine Bailleux
1336c595b3dSSandrine Bailleux	.align	7
1346c595b3dSSandrine BailleuxFiqA64:
1356c595b3dSSandrine Bailleux	mov	x0, #FIQ_AARCH64
1366c595b3dSSandrine Bailleux	bl	plat_report_exception
1376c595b3dSSandrine Bailleux	b	FiqA64
1386c595b3dSSandrine Bailleux	check_vector_size FiqA64
1396c595b3dSSandrine Bailleux
1406c595b3dSSandrine Bailleux	.align	7
1416c595b3dSSandrine BailleuxSErrorA64:
1426c595b3dSSandrine Bailleux	mov	x0, #SERROR_AARCH64
1436c595b3dSSandrine Bailleux	bl	plat_report_exception
1446c595b3dSSandrine Bailleux	b   	SErrorA64
1456c595b3dSSandrine Bailleux	check_vector_size SErrorA64
1466c595b3dSSandrine Bailleux
1476c595b3dSSandrine Bailleux	/* -----------------------------------------------------
14844804252SSandrine Bailleux	 * Lower EL using AArch32 : 0x600 - 0x800
1496c595b3dSSandrine Bailleux	 * -----------------------------------------------------
1506c595b3dSSandrine Bailleux	 */
1516c595b3dSSandrine Bailleux	.align	7
1526c595b3dSSandrine BailleuxSynchronousExceptionA32:
1536c595b3dSSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_AARCH32
1546c595b3dSSandrine Bailleux	bl	plat_report_exception
1556c595b3dSSandrine Bailleux	b	SynchronousExceptionA32
1566c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionA32
1576c595b3dSSandrine Bailleux
1586c595b3dSSandrine Bailleux	.align	7
1596c595b3dSSandrine BailleuxIrqA32:
1606c595b3dSSandrine Bailleux	mov	x0, #IRQ_AARCH32
1616c595b3dSSandrine Bailleux	bl	plat_report_exception
1626c595b3dSSandrine Bailleux	b	IrqA32
1636c595b3dSSandrine Bailleux	check_vector_size IrqA32
1646c595b3dSSandrine Bailleux
1656c595b3dSSandrine Bailleux	.align	7
1666c595b3dSSandrine BailleuxFiqA32:
1676c595b3dSSandrine Bailleux	mov	x0, #FIQ_AARCH32
1686c595b3dSSandrine Bailleux	bl	plat_report_exception
1696c595b3dSSandrine Bailleux	b	FiqA32
1706c595b3dSSandrine Bailleux	check_vector_size FiqA32
1716c595b3dSSandrine Bailleux
1726c595b3dSSandrine Bailleux	.align	7
1736c595b3dSSandrine BailleuxSErrorA32:
1746c595b3dSSandrine Bailleux	mov	x0, #SERROR_AARCH32
1756c595b3dSSandrine Bailleux	bl	plat_report_exception
1766c595b3dSSandrine Bailleux	b	SErrorA32
1776c595b3dSSandrine Bailleux	check_vector_size SErrorA32
1781fe4d453SSandrine Bailleux
1791fe4d453SSandrine Bailleux
1801fe4d453SSandrine Bailleuxfunc smc_handler64
1811fe4d453SSandrine Bailleux	/* ---------------------------------------------------------------------
1821fe4d453SSandrine Bailleux	 * Only a single SMC exception from BL2 to ask BL1 to pass EL3 control
1831fe4d453SSandrine Bailleux	 * to BL31 is expected here. It expects:
1841fe4d453SSandrine Bailleux	 *   - X0 with RUN_IMAGE SMC function ID;
1851fe4d453SSandrine Bailleux	 *   - X1 with the address of a entry_point_info_t structure describing
1861fe4d453SSandrine Bailleux	 *     the BL31 entrypoint.
1871fe4d453SSandrine Bailleux	 * ---------------------------------------------------------------------
1881fe4d453SSandrine Bailleux	 */
1891fe4d453SSandrine Bailleux	mov	x19, x0
1901fe4d453SSandrine Bailleux	mov	x20, x1
1911fe4d453SSandrine Bailleux
1921fe4d453SSandrine Bailleux	mov	x0, #RUN_IMAGE
1931fe4d453SSandrine Bailleux	cmp	x19, x0
1941fe4d453SSandrine Bailleux	b.ne	unexpected_sync_exception
1951fe4d453SSandrine Bailleux
1961fe4d453SSandrine Bailleux	mov	x0, x20
197ee5c2b13SSandrine Bailleux	bl	bl1_print_bl31_ep_info
1981fe4d453SSandrine Bailleux
1991fe4d453SSandrine Bailleux	ldp	x0, x1, [x20, #ENTRY_POINT_INFO_PC_OFFSET]
2001fe4d453SSandrine Bailleux	msr	elr_el3, x0
2011fe4d453SSandrine Bailleux	msr	spsr_el3, x1
2021fe4d453SSandrine Bailleux	ubfx	x0, x1, #MODE_EL_SHIFT, #2
2031fe4d453SSandrine Bailleux	cmp	x0, #MODE_EL3
2041fe4d453SSandrine Bailleux	b.ne	unexpected_sync_exception
2051fe4d453SSandrine Bailleux
2061fe4d453SSandrine Bailleux	bl	disable_mmu_icache_el3
2071fe4d453SSandrine Bailleux	tlbi	alle3
2081fe4d453SSandrine Bailleux
20935e8c766SSandrine Bailleux#if SPIN_ON_BL1_EXIT
21035e8c766SSandrine Bailleux	bl	print_debug_loop_message
21135e8c766SSandrine Bailleuxdebug_loop:
21235e8c766SSandrine Bailleux	b	debug_loop
21335e8c766SSandrine Bailleux#endif
21435e8c766SSandrine Bailleux
215862b5dc2SSandrine Bailleux	mov	x0, x20
216e3f67124SJuan Castillo	bl	bl1_plat_prepare_exit
217e3f67124SJuan Castillo
2181fe4d453SSandrine Bailleux	ldp	x6, x7, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x30)]
2191fe4d453SSandrine Bailleux	ldp	x4, x5, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x20)]
2201fe4d453SSandrine Bailleux	ldp	x2, x3, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x10)]
2211fe4d453SSandrine Bailleux	ldp	x0, x1, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x0)]
2221fe4d453SSandrine Bailleux	eret
2231fe4d453SSandrine Bailleuxendfunc smc_handler64
2241fe4d453SSandrine Bailleux
2251fe4d453SSandrine Bailleuxunexpected_sync_exception:
2261fe4d453SSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_AARCH64
2271fe4d453SSandrine Bailleux	bl	plat_report_exception
2281fe4d453SSandrine Bailleux	wfi
2291fe4d453SSandrine Bailleux	b	unexpected_sync_exception
230