2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2013-12-14 03:47:35 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2013
|
|
|
|
* David Feng <fenghua@phytium.com.cn>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm-offsets.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/macro.h>
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
|
armv8: shrink exception table code
In the moment our exception entry code needs 34 instructions, so we
can't use put it directly into the table entry, which offers "only"
32 instructions there. Right now we just put an unconditional branch
there, then use a macro to place the 34 instructions *per entry* after
that. That effectivly doubles the size of our exception table, which
is quite a waste, given that we use it mostly for debugging purposes.
Since the register saving part is actually identical, let's just convert
that macro into a function, and "bl" into it directly from the exception
slot, of course after having saved at least the original LR.
This saves us about 950 bytes of code, which is quite a relief for some
tight SPLs, in particular the 64-bit Allwinner ones.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
2017-11-27 00:47:09 +00:00
|
|
|
/*
|
2018-07-24 23:57:00 +00:00
|
|
|
* AArch64 exception vectors:
|
|
|
|
* We have four types of exceptions:
|
|
|
|
* - synchronous: traps, data aborts, undefined instructions, ...
|
|
|
|
* - IRQ: group 1 (normal) interrupts
|
|
|
|
* - FIQ: group 0 or secure interrupts
|
|
|
|
* - SError: fatal system errors
|
|
|
|
* There are entries for all four of those for different contexts:
|
|
|
|
* - from same exception level, when using the SP_EL0 stack pointer
|
|
|
|
* - from same exception level, when using the SP_ELx stack pointer
|
|
|
|
* - from lower exception level, when this is AArch64
|
|
|
|
* - from lower exception level, when this is AArch32
|
|
|
|
* Each of those 16 entries have space for 32 instructions, each entry must
|
|
|
|
* be 128 byte aligned, the whole table must be 2K aligned.
|
|
|
|
* The 32 instructions are not enough to save and restore all registers and
|
|
|
|
* to branch to the actual handler, so we split this up:
|
|
|
|
* Each entry saves the LR, branches to the save routine, then to the actual
|
|
|
|
* handler, then to the restore routine. The save and restore routines are
|
|
|
|
* each split in half and stuffed in the unused gap between the entries.
|
|
|
|
* Also as we do not run anything in a lower exception level, we just provide
|
|
|
|
* the first 8 entries for exceptions from the same EL.
|
armv8: shrink exception table code
In the moment our exception entry code needs 34 instructions, so we
can't use put it directly into the table entry, which offers "only"
32 instructions there. Right now we just put an unconditional branch
there, then use a macro to place the 34 instructions *per entry* after
that. That effectivly doubles the size of our exception table, which
is quite a waste, given that we use it mostly for debugging purposes.
Since the register saving part is actually identical, let's just convert
that macro into a function, and "bl" into it directly from the exception
slot, of course after having saved at least the original LR.
This saves us about 950 bytes of code, which is quite a relief for some
tight SPLs, in particular the 64-bit Allwinner ones.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
2017-11-27 00:47:09 +00:00
|
|
|
*/
|
|
|
|
.align 11
|
|
|
|
.globl vectors
|
|
|
|
vectors:
|
|
|
|
.align 7 /* Current EL Synchronous Thread */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_bad_sync
|
|
|
|
b exception_exit
|
|
|
|
|
2013-12-14 03:47:35 +00:00
|
|
|
/*
|
2018-07-24 23:57:00 +00:00
|
|
|
* Save (most of) the GP registers to the stack frame.
|
|
|
|
* This is the first part of the shared routine called into from all entries.
|
2013-12-14 03:47:35 +00:00
|
|
|
*/
|
armv8: shrink exception table code
In the moment our exception entry code needs 34 instructions, so we
can't use put it directly into the table entry, which offers "only"
32 instructions there. Right now we just put an unconditional branch
there, then use a macro to place the 34 instructions *per entry* after
that. That effectivly doubles the size of our exception table, which
is quite a waste, given that we use it mostly for debugging purposes.
Since the register saving part is actually identical, let's just convert
that macro into a function, and "bl" into it directly from the exception
slot, of course after having saved at least the original LR.
This saves us about 950 bytes of code, which is quite a relief for some
tight SPLs, in particular the 64-bit Allwinner ones.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
2017-11-27 00:47:09 +00:00
|
|
|
_exception_entry:
|
2013-12-14 03:47:35 +00:00
|
|
|
stp x27, x28, [sp, #-16]!
|
|
|
|
stp x25, x26, [sp, #-16]!
|
|
|
|
stp x23, x24, [sp, #-16]!
|
|
|
|
stp x21, x22, [sp, #-16]!
|
|
|
|
stp x19, x20, [sp, #-16]!
|
|
|
|
stp x17, x18, [sp, #-16]!
|
|
|
|
stp x15, x16, [sp, #-16]!
|
|
|
|
stp x13, x14, [sp, #-16]!
|
|
|
|
stp x11, x12, [sp, #-16]!
|
|
|
|
stp x9, x10, [sp, #-16]!
|
|
|
|
stp x7, x8, [sp, #-16]!
|
|
|
|
stp x5, x6, [sp, #-16]!
|
|
|
|
stp x3, x4, [sp, #-16]!
|
|
|
|
stp x1, x2, [sp, #-16]!
|
2018-07-24 23:57:00 +00:00
|
|
|
b _save_el_regs /* jump to the second part */
|
2013-12-14 03:47:35 +00:00
|
|
|
|
2018-07-24 23:57:00 +00:00
|
|
|
.align 7 /* Current EL IRQ Thread */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_bad_irq
|
|
|
|
b exception_exit
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save exception specific context: ESR and ELR, for all exception levels.
|
|
|
|
* This is the second part of the shared routine called into from all entries.
|
|
|
|
*/
|
|
|
|
_save_el_regs:
|
2013-12-14 03:47:35 +00:00
|
|
|
/* Could be running at EL3/EL2/EL1 */
|
|
|
|
switch_el x11, 3f, 2f, 1f
|
|
|
|
3: mrs x1, esr_el3
|
|
|
|
mrs x2, elr_el3
|
2022-03-22 20:59:28 +00:00
|
|
|
mrs x3, spsr_el3
|
2013-12-14 03:47:35 +00:00
|
|
|
b 0f
|
|
|
|
2: mrs x1, esr_el2
|
|
|
|
mrs x2, elr_el2
|
2022-03-22 20:59:28 +00:00
|
|
|
mrs x3, spsr_el2
|
2013-12-14 03:47:35 +00:00
|
|
|
b 0f
|
|
|
|
1: mrs x1, esr_el1
|
|
|
|
mrs x2, elr_el1
|
2022-03-22 20:59:28 +00:00
|
|
|
mrs x3, spsr_el1
|
2013-12-14 03:47:35 +00:00
|
|
|
0:
|
2022-03-22 21:17:35 +00:00
|
|
|
stp x1, x0, [sp, #-16]!
|
2022-03-22 20:59:28 +00:00
|
|
|
stp x3, x2, [sp, #-16]!
|
2013-12-14 03:47:35 +00:00
|
|
|
mov x0, sp
|
armv8: shrink exception table code
In the moment our exception entry code needs 34 instructions, so we
can't use put it directly into the table entry, which offers "only"
32 instructions there. Right now we just put an unconditional branch
there, then use a macro to place the 34 instructions *per entry* after
that. That effectivly doubles the size of our exception table, which
is quite a waste, given that we use it mostly for debugging purposes.
Since the register saving part is actually identical, let's just convert
that macro into a function, and "bl" into it directly from the exception
slot, of course after having saved at least the original LR.
This saves us about 950 bytes of code, which is quite a relief for some
tight SPLs, in particular the 64-bit Allwinner ones.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
2017-11-27 00:47:09 +00:00
|
|
|
ret
|
2013-12-14 03:47:35 +00:00
|
|
|
|
2018-07-24 23:57:00 +00:00
|
|
|
.align 7 /* Current EL FIQ Thread */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_bad_fiq
|
|
|
|
/* falling through to _exception_exit */
|
|
|
|
/*
|
|
|
|
* Restore the exception return address, for all exception levels.
|
|
|
|
* This is the first part of the shared routine called into from all entries.
|
|
|
|
*/
|
2016-03-04 00:10:05 +00:00
|
|
|
exception_exit:
|
2022-03-22 21:17:35 +00:00
|
|
|
ldp xzr, x2, [sp],#16
|
2016-03-04 00:10:05 +00:00
|
|
|
switch_el x11, 3f, 2f, 1f
|
|
|
|
3: msr elr_el3, x2
|
2018-07-24 23:57:00 +00:00
|
|
|
b _restore_regs
|
2016-03-04 00:10:05 +00:00
|
|
|
2: msr elr_el2, x2
|
2018-07-24 23:57:00 +00:00
|
|
|
b _restore_regs
|
2016-03-04 00:10:05 +00:00
|
|
|
1: msr elr_el1, x2
|
2018-07-24 23:57:00 +00:00
|
|
|
b _restore_regs /* jump to the second part */
|
|
|
|
|
|
|
|
.align 7 /* Current EL Error Thread */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_bad_error
|
|
|
|
b exception_exit
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore the general purpose registers from the exception stack, then return.
|
|
|
|
* This is the second part of the shared routine called into from all entries.
|
|
|
|
*/
|
|
|
|
_restore_regs:
|
2022-03-22 21:17:35 +00:00
|
|
|
ldp xzr, x0, [sp],#16
|
2016-03-04 00:10:05 +00:00
|
|
|
ldp x1, x2, [sp],#16
|
|
|
|
ldp x3, x4, [sp],#16
|
|
|
|
ldp x5, x6, [sp],#16
|
|
|
|
ldp x7, x8, [sp],#16
|
|
|
|
ldp x9, x10, [sp],#16
|
|
|
|
ldp x11, x12, [sp],#16
|
|
|
|
ldp x13, x14, [sp],#16
|
|
|
|
ldp x15, x16, [sp],#16
|
|
|
|
ldp x17, x18, [sp],#16
|
|
|
|
ldp x19, x20, [sp],#16
|
|
|
|
ldp x21, x22, [sp],#16
|
|
|
|
ldp x23, x24, [sp],#16
|
|
|
|
ldp x25, x26, [sp],#16
|
|
|
|
ldp x27, x28, [sp],#16
|
|
|
|
ldp x29, x30, [sp],#16
|
|
|
|
eret
|
2018-07-24 23:57:00 +00:00
|
|
|
|
|
|
|
.align 7 /* Current EL (SP_ELx) Synchronous Handler */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_sync
|
|
|
|
b exception_exit
|
|
|
|
|
|
|
|
.align 7 /* Current EL (SP_ELx) IRQ Handler */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_irq
|
|
|
|
b exception_exit
|
|
|
|
|
|
|
|
.align 7 /* Current EL (SP_ELx) FIQ Handler */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_fiq
|
|
|
|
b exception_exit
|
|
|
|
|
|
|
|
.align 7 /* Current EL (SP_ELx) Error Handler */
|
|
|
|
stp x29, x30, [sp, #-16]!
|
|
|
|
bl _exception_entry
|
|
|
|
bl do_error
|
|
|
|
b exception_exit
|