xref: /rk3399_ARM-atf/bl32/tsp/aarch64/tsp_exceptions.S (revision a806dad58c4cf752238d7bbffbc9a1ce17f63cea)
157356e90SAchin Gupta/*
21c3ea103SAntonio Nino Diaz * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
357356e90SAchin Gupta *
457356e90SAchin Gupta * Redistribution and use in source and binary forms, with or without
557356e90SAchin Gupta * modification, are permitted provided that the following conditions are met:
657356e90SAchin Gupta *
757356e90SAchin Gupta * Redistributions of source code must retain the above copyright notice, this
857356e90SAchin Gupta * list of conditions and the following disclaimer.
957356e90SAchin Gupta *
1057356e90SAchin Gupta * Redistributions in binary form must reproduce the above copyright notice,
1157356e90SAchin Gupta * this list of conditions and the following disclaimer in the documentation
1257356e90SAchin Gupta * and/or other materials provided with the distribution.
1357356e90SAchin Gupta *
1457356e90SAchin Gupta * Neither the name of ARM nor the names of its contributors may be used
1557356e90SAchin Gupta * to endorse or promote products derived from this software without specific
1657356e90SAchin Gupta * prior written permission.
1757356e90SAchin Gupta *
1857356e90SAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1957356e90SAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2057356e90SAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2157356e90SAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2257356e90SAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2357356e90SAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2457356e90SAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2557356e90SAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2657356e90SAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2757356e90SAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2857356e90SAchin Gupta * POSSIBILITY OF SUCH DAMAGE.
2957356e90SAchin Gupta */
3057356e90SAchin Gupta
3157356e90SAchin Gupta#include <arch.h>
3257356e90SAchin Gupta#include <asm_macros.S>
33e0ae9fabSSandrine Bailleux#include <bl_common.h>
34e0ae9fabSSandrine Bailleux#include <tsp.h>
3557356e90SAchin Gupta
3657356e90SAchin Gupta
3757356e90SAchin Gupta	/* ----------------------------------------------------
3857356e90SAchin Gupta	 * The caller-saved registers x0-x18 and LR are saved
3957356e90SAchin Gupta	 * here.
4057356e90SAchin Gupta	 * ----------------------------------------------------
4157356e90SAchin Gupta	 */
4257356e90SAchin Gupta
4357356e90SAchin Gupta#define SCRATCH_REG_SIZE #(20 * 8)
4457356e90SAchin Gupta
4557356e90SAchin Gupta	.macro save_caller_regs_and_lr
4657356e90SAchin Gupta	sub	sp, sp, SCRATCH_REG_SIZE
4757356e90SAchin Gupta	stp	x0, x1, [sp]
4857356e90SAchin Gupta	stp	x2, x3, [sp, #0x10]
4957356e90SAchin Gupta	stp	x4, x5, [sp, #0x20]
5057356e90SAchin Gupta	stp	x6, x7, [sp, #0x30]
5157356e90SAchin Gupta	stp	x8, x9, [sp, #0x40]
5257356e90SAchin Gupta	stp	x10, x11, [sp, #0x50]
5357356e90SAchin Gupta	stp	x12, x13, [sp, #0x60]
5457356e90SAchin Gupta	stp	x14, x15, [sp, #0x70]
5557356e90SAchin Gupta	stp	x16, x17, [sp, #0x80]
5657356e90SAchin Gupta	stp	x18, x30, [sp, #0x90]
5757356e90SAchin Gupta	.endm
5857356e90SAchin Gupta
5957356e90SAchin Gupta	.macro restore_caller_regs_and_lr
6057356e90SAchin Gupta	ldp	x0, x1, [sp]
6157356e90SAchin Gupta	ldp	x2, x3, [sp, #0x10]
6257356e90SAchin Gupta	ldp	x4, x5, [sp, #0x20]
6357356e90SAchin Gupta	ldp	x6, x7, [sp, #0x30]
6457356e90SAchin Gupta	ldp	x8, x9, [sp, #0x40]
6557356e90SAchin Gupta	ldp	x10, x11, [sp, #0x50]
6657356e90SAchin Gupta	ldp	x12, x13, [sp, #0x60]
6757356e90SAchin Gupta	ldp	x14, x15, [sp, #0x70]
6857356e90SAchin Gupta	ldp	x16, x17, [sp, #0x80]
6957356e90SAchin Gupta	ldp	x18, x30, [sp, #0x90]
7057356e90SAchin Gupta	add	sp, sp, SCRATCH_REG_SIZE
7157356e90SAchin Gupta	.endm
7257356e90SAchin Gupta
7302446137SSoby Mathew	/* ----------------------------------------------------
7402446137SSoby Mathew	 * Common TSP interrupt handling routine
7502446137SSoby Mathew	 * ----------------------------------------------------
7602446137SSoby Mathew	 */
7702446137SSoby Mathew	.macro	handle_tsp_interrupt label
7802446137SSoby Mathew	/* Enable the SError interrupt */
7902446137SSoby Mathew	msr	daifclr, #DAIF_ABT_BIT
8002446137SSoby Mathew
8102446137SSoby Mathew	save_caller_regs_and_lr
8202446137SSoby Mathew	bl	tsp_common_int_handler
8302446137SSoby Mathew	cbz	x0, interrupt_exit_\label
8402446137SSoby Mathew
8502446137SSoby Mathew	/*
8602446137SSoby Mathew	 * This interrupt was not targetted to S-EL1 so send it to
8702446137SSoby Mathew	 * the monitor and wait for execution to resume.
8802446137SSoby Mathew	 */
8902446137SSoby Mathew	smc	#0
9002446137SSoby Mathewinterrupt_exit_\label:
9102446137SSoby Mathew	restore_caller_regs_and_lr
9202446137SSoby Mathew	eret
9302446137SSoby Mathew	.endm
9402446137SSoby Mathew
9557356e90SAchin Gupta	.globl	tsp_exceptions
9657356e90SAchin Gupta
9757356e90SAchin Gupta	/* -----------------------------------------------------
9857356e90SAchin Gupta	 * TSP exception handlers.
9957356e90SAchin Gupta	 * -----------------------------------------------------
10057356e90SAchin Gupta	 */
101e0ae9fabSSandrine Bailleuxvector_base tsp_exceptions
10257356e90SAchin Gupta	/* -----------------------------------------------------
103e0ae9fabSSandrine Bailleux	 * Current EL with _sp_el0 : 0x0 - 0x200. No exceptions
10457356e90SAchin Gupta	 * are expected and treated as irrecoverable errors.
10557356e90SAchin Gupta	 * -----------------------------------------------------
10657356e90SAchin Gupta	 */
107e0ae9fabSSandrine Bailleuxvector_entry sync_exception_sp_el0
108*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
10957356e90SAchin Gupta	check_vector_size sync_exception_sp_el0
11057356e90SAchin Gupta
111e0ae9fabSSandrine Bailleuxvector_entry irq_sp_el0
112*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
11357356e90SAchin Gupta	check_vector_size irq_sp_el0
11457356e90SAchin Gupta
115e0ae9fabSSandrine Bailleuxvector_entry fiq_sp_el0
116*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
11757356e90SAchin Gupta	check_vector_size fiq_sp_el0
11857356e90SAchin Gupta
119e0ae9fabSSandrine Bailleuxvector_entry serror_sp_el0
120*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
12157356e90SAchin Gupta	check_vector_size serror_sp_el0
12257356e90SAchin Gupta
12357356e90SAchin Gupta
12457356e90SAchin Gupta	/* -----------------------------------------------------
125e0ae9fabSSandrine Bailleux	 * Current EL with SPx: 0x200 - 0x400. Only IRQs/FIQs
12657356e90SAchin Gupta	 * are expected and handled
12757356e90SAchin Gupta	 * -----------------------------------------------------
12857356e90SAchin Gupta	 */
129e0ae9fabSSandrine Bailleuxvector_entry sync_exception_sp_elx
130*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
13157356e90SAchin Gupta	check_vector_size sync_exception_sp_elx
13257356e90SAchin Gupta
133e0ae9fabSSandrine Bailleuxvector_entry irq_sp_elx
13402446137SSoby Mathew	handle_tsp_interrupt irq_sp_elx
13557356e90SAchin Gupta	check_vector_size irq_sp_elx
13657356e90SAchin Gupta
137e0ae9fabSSandrine Bailleuxvector_entry fiq_sp_elx
13802446137SSoby Mathew	handle_tsp_interrupt fiq_sp_elx
13957356e90SAchin Gupta	check_vector_size fiq_sp_elx
14057356e90SAchin Gupta
141e0ae9fabSSandrine Bailleuxvector_entry serror_sp_elx
142*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
14357356e90SAchin Gupta	check_vector_size serror_sp_elx
14457356e90SAchin Gupta
14557356e90SAchin Gupta
14657356e90SAchin Gupta	/* -----------------------------------------------------
147e0ae9fabSSandrine Bailleux	 * Lower EL using AArch64 : 0x400 - 0x600. No exceptions
14857356e90SAchin Gupta	 * are handled since TSP does not implement a lower EL
14957356e90SAchin Gupta	 * -----------------------------------------------------
15057356e90SAchin Gupta	 */
151e0ae9fabSSandrine Bailleuxvector_entry sync_exception_aarch64
152*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
15357356e90SAchin Gupta	check_vector_size sync_exception_aarch64
15457356e90SAchin Gupta
155e0ae9fabSSandrine Bailleuxvector_entry irq_aarch64
156*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
15757356e90SAchin Gupta	check_vector_size irq_aarch64
15857356e90SAchin Gupta
159e0ae9fabSSandrine Bailleuxvector_entry fiq_aarch64
160*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
16157356e90SAchin Gupta	check_vector_size fiq_aarch64
16257356e90SAchin Gupta
163e0ae9fabSSandrine Bailleuxvector_entry serror_aarch64
164*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
16557356e90SAchin Gupta	check_vector_size serror_aarch64
16657356e90SAchin Gupta
16757356e90SAchin Gupta
16857356e90SAchin Gupta	/* -----------------------------------------------------
169e0ae9fabSSandrine Bailleux	 * Lower EL using AArch32 : 0x600 - 0x800. No exceptions
17057356e90SAchin Gupta	 * handled since the TSP does not implement a lower EL.
17157356e90SAchin Gupta	 * -----------------------------------------------------
17257356e90SAchin Gupta	 */
173e0ae9fabSSandrine Bailleuxvector_entry sync_exception_aarch32
174*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
17557356e90SAchin Gupta	check_vector_size sync_exception_aarch32
17657356e90SAchin Gupta
177e0ae9fabSSandrine Bailleuxvector_entry irq_aarch32
178*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
17957356e90SAchin Gupta	check_vector_size irq_aarch32
18057356e90SAchin Gupta
181e0ae9fabSSandrine Bailleuxvector_entry fiq_aarch32
182*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
18357356e90SAchin Gupta	check_vector_size fiq_aarch32
18457356e90SAchin Gupta
185e0ae9fabSSandrine Bailleuxvector_entry serror_aarch32
186*a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
18757356e90SAchin Gupta	check_vector_size serror_aarch32
188