xref: /rk3399_ARM-atf/bl1/aarch64/bl1_exceptions.S (revision 0c8d4fef28768233f1f46b4d085f904293dffd2c)
16c595b3dSSandrine Bailleux/*
26c595b3dSSandrine Bailleux * Copyright (c) 2013-2014, 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>
3497043ac9SDan Handley#include <runtime_svc.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	/* -----------------------------------------------------
476c595b3dSSandrine Bailleux	 * Current EL with SP0 : 0x0 - 0x180
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	/* -----------------------------------------------------
786c595b3dSSandrine Bailleux	 * Current EL with SPx: 0x200 - 0x380
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	/* -----------------------------------------------------
1106c595b3dSSandrine Bailleux	 * Lower EL using AArch64 : 0x400 - 0x580
1116c595b3dSSandrine Bailleux	 * -----------------------------------------------------
1126c595b3dSSandrine Bailleux	 */
1136c595b3dSSandrine Bailleux	.align	7
1146c595b3dSSandrine BailleuxSynchronousExceptionA64:
115*0c8d4fefSAchin Gupta	/* Enable the SError interrupt */
116*0c8d4fefSAchin Gupta	msr	daifclr, #DAIF_ABT_BIT
117*0c8d4fefSAchin Gupta
11829fb905dSVikram Kanigiri	/* ------------------------------------------------
1196c595b3dSSandrine Bailleux	 * Only a single SMC exception from BL2 to ask
1206c595b3dSSandrine Bailleux	 * BL1 to pass EL3 control to BL31 is expected
1216c595b3dSSandrine Bailleux	 * here.
12229fb905dSVikram Kanigiri	 * It expects X0 with RUN_IMAGE SMC function id
1234112bfa0SVikram Kanigiri	 * X1 with address of a entry_point_info_t structure
12429fb905dSVikram Kanigiri	 * describing the BL3-1 entrypoint
12529fb905dSVikram Kanigiri	 * ------------------------------------------------
1266c595b3dSSandrine Bailleux	 */
12729fb905dSVikram Kanigiri	mov	x19, x0
12829fb905dSVikram Kanigiri	mov	x20, x1
12929fb905dSVikram Kanigiri
13029fb905dSVikram Kanigiri	mrs	x0, esr_el3
13129fb905dSVikram Kanigiri	ubfx	x1, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
13229fb905dSVikram Kanigiri	cmp	x1, #EC_AARCH64_SMC
13329fb905dSVikram Kanigiri	b.ne	panic
13429fb905dSVikram Kanigiri
13529fb905dSVikram Kanigiri	mov	x0, #RUN_IMAGE
13629fb905dSVikram Kanigiri	cmp	x19, x0
13729fb905dSVikram Kanigiri	b.ne	panic
13829fb905dSVikram Kanigiri
13929fb905dSVikram Kanigiri	mov	x0, x20
14029fb905dSVikram Kanigiri	bl	display_boot_progress
14129fb905dSVikram Kanigiri
1424112bfa0SVikram Kanigiri	ldp	x0, x1, [x20, #ENTRY_POINT_INFO_PC_OFFSET]
14329fb905dSVikram Kanigiri	msr	elr_el3, x0
14429fb905dSVikram Kanigiri	msr	spsr_el3, x1
14529fb905dSVikram Kanigiri	ubfx	x0, x1, #MODE_EL_SHIFT, #2
14629fb905dSVikram Kanigiri	cmp	x0, #MODE_EL3
14729fb905dSVikram Kanigiri	b.ne	panic
14829fb905dSVikram Kanigiri
14929fb905dSVikram Kanigiri	bl	disable_mmu_icache_el3
15029fb905dSVikram Kanigiri	tlbi	alle3
15129fb905dSVikram Kanigiri
1524112bfa0SVikram Kanigiri	ldp	x6, x7, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x30)]
1534112bfa0SVikram Kanigiri	ldp	x4, x5, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x20)]
1544112bfa0SVikram Kanigiri	ldp	x2, x3, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x10)]
1554112bfa0SVikram Kanigiri	ldp	x0, x1, [x20, #(ENTRY_POINT_INFO_ARGS_OFFSET + 0x0)]
15629fb905dSVikram Kanigiri	eret
15729fb905dSVikram Kanigiripanic:
15829fb905dSVikram Kanigiri	mov	x0, #SYNC_EXCEPTION_AARCH64
15929fb905dSVikram Kanigiri	bl	plat_report_exception
16029fb905dSVikram Kanigiri
16129fb905dSVikram Kanigiri	wfi
16229fb905dSVikram Kanigiri	b	panic
1636c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionA64
1646c595b3dSSandrine Bailleux
1656c595b3dSSandrine Bailleux	.align	7
1666c595b3dSSandrine BailleuxIrqA64:
1676c595b3dSSandrine Bailleux	mov	x0, #IRQ_AARCH64
1686c595b3dSSandrine Bailleux	bl	plat_report_exception
1696c595b3dSSandrine Bailleux	b	IrqA64
1706c595b3dSSandrine Bailleux	check_vector_size IrqA64
1716c595b3dSSandrine Bailleux
1726c595b3dSSandrine Bailleux	.align	7
1736c595b3dSSandrine BailleuxFiqA64:
1746c595b3dSSandrine Bailleux	mov	x0, #FIQ_AARCH64
1756c595b3dSSandrine Bailleux	bl	plat_report_exception
1766c595b3dSSandrine Bailleux	b	FiqA64
1776c595b3dSSandrine Bailleux	check_vector_size FiqA64
1786c595b3dSSandrine Bailleux
1796c595b3dSSandrine Bailleux	.align	7
1806c595b3dSSandrine BailleuxSErrorA64:
1816c595b3dSSandrine Bailleux	mov	x0, #SERROR_AARCH64
1826c595b3dSSandrine Bailleux	bl	plat_report_exception
1836c595b3dSSandrine Bailleux	b   	SErrorA64
1846c595b3dSSandrine Bailleux	check_vector_size SErrorA64
1856c595b3dSSandrine Bailleux
1866c595b3dSSandrine Bailleux	/* -----------------------------------------------------
1876c595b3dSSandrine Bailleux	 * Lower EL using AArch32 : 0x0 - 0x180
1886c595b3dSSandrine Bailleux	 * -----------------------------------------------------
1896c595b3dSSandrine Bailleux	 */
1906c595b3dSSandrine Bailleux	.align	7
1916c595b3dSSandrine BailleuxSynchronousExceptionA32:
1926c595b3dSSandrine Bailleux	mov	x0, #SYNC_EXCEPTION_AARCH32
1936c595b3dSSandrine Bailleux	bl	plat_report_exception
1946c595b3dSSandrine Bailleux	b	SynchronousExceptionA32
1956c595b3dSSandrine Bailleux	check_vector_size SynchronousExceptionA32
1966c595b3dSSandrine Bailleux
1976c595b3dSSandrine Bailleux	.align	7
1986c595b3dSSandrine BailleuxIrqA32:
1996c595b3dSSandrine Bailleux	mov	x0, #IRQ_AARCH32
2006c595b3dSSandrine Bailleux	bl	plat_report_exception
2016c595b3dSSandrine Bailleux	b	IrqA32
2026c595b3dSSandrine Bailleux	check_vector_size IrqA32
2036c595b3dSSandrine Bailleux
2046c595b3dSSandrine Bailleux	.align	7
2056c595b3dSSandrine BailleuxFiqA32:
2066c595b3dSSandrine Bailleux	mov	x0, #FIQ_AARCH32
2076c595b3dSSandrine Bailleux	bl	plat_report_exception
2086c595b3dSSandrine Bailleux	b	FiqA32
2096c595b3dSSandrine Bailleux	check_vector_size FiqA32
2106c595b3dSSandrine Bailleux
2116c595b3dSSandrine Bailleux	.align	7
2126c595b3dSSandrine BailleuxSErrorA32:
2136c595b3dSSandrine Bailleux	mov	x0, #SERROR_AARCH32
2146c595b3dSSandrine Bailleux	bl	plat_report_exception
2156c595b3dSSandrine Bailleux	b	SErrorA32
2166c595b3dSSandrine Bailleux	check_vector_size SErrorA32
217