aboutsummaryrefslogtreecommitdiff
path: root/payloads/libpayload/arch/arm64/exception.c
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2018-10-10 15:42:28 -0700
committerJulius Werner <jwerner@chromium.org>2018-10-12 20:17:28 +0000
commit5c0e72ff9952bef2dcb62881ced0d95f8ad9cf1d (patch)
treee297683091fcbea2b785c289e3f3af95bef5238f /payloads/libpayload/arch/arm64/exception.c
parentca52a258822c1c47d533684c5a4cbe5f2b7bd487 (diff)
libpayload: arm64: Make exception handling closer to arm32
This patch reworks the arm64 exception handling to be more similar to how it works on arm32. This includes a bunch of features like actually saving and restoring more exception state in the exception_state structure and supporting the same sort of partial reentrancy that is useful for GDB. Since there's no instruction to directly load into or store out of SP on arm64, we can't do quite the same thing where we use that to read an exception_state_ptr variable right after exception entry when no other register is available. But we can do something very similar by (ab-)using the "high" stack pointer (SP_EL2) as a pointer to the exception_state struct and providing a function to change it. Change-Id: Ia16a1124be1824392a309ae1f4cb031547d184c1 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/29018 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'payloads/libpayload/arch/arm64/exception.c')
-rw-r--r--payloads/libpayload/arch/arm64/exception.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/payloads/libpayload/arch/arm64/exception.c b/payloads/libpayload/arch/arm64/exception.c
index a84daf1563..a5e55163a8 100644
--- a/payloads/libpayload/arch/arm64/exception.c
+++ b/payloads/libpayload/arch/arm64/exception.c
@@ -31,6 +31,8 @@
#include <libpayload.h>
#include <stdint.h>
+u64 exception_stack[0x200] __attribute__((aligned(16)));
+u64 *exception_stack_end = exception_stack + ARRAY_SIZE(exception_stack);
extern unsigned int test_exc;
struct exception_handler_info
@@ -39,7 +41,7 @@ struct exception_handler_info
};
static exception_hook hook;
-struct exception_state *exception_state;
+struct exception_state exception_state;
static struct exception_handler_info exceptions[EXC_COUNT] = {
[EXC_SYNC_SP0] = { "_sync_sp_el0" },
@@ -88,14 +90,12 @@ static void print_regs(struct exception_state *state)
i, state->regs[i], i + 1, state->regs[i + 1]);
}
printf("X30 = 0x%016llx SP = 0x%016llx\n",
- state->regs[30], raw_read_sp_el0());
+ state->regs[30], state->sp);
}
void exception_dispatch(struct exception_state *state, int idx);
void exception_dispatch(struct exception_state *state, int idx)
{
- exception_state = state;
-
if (idx >= EXC_COUNT) {
printf("Bad exception index %d.\n", idx);
} else {
@@ -110,7 +110,7 @@ void exception_dispatch(struct exception_state *state, int idx)
}
print_regs(state);
/* Few words below SP in case we need state from a returned function. */
- dump_stack(raw_read_sp_el0() - 32, 512);
+ dump_stack(state->sp - 32, 512);
if (test_exc) {
state->elr += 4;
@@ -123,8 +123,9 @@ void exception_dispatch(struct exception_state *state, int idx)
void exception_init(void)
{
- extern void* exception_table;
- set_vbar(&exception_table);
+ extern uint64_t exception_table[];
+ raw_write_vbar_el2((uintptr_t)exception_table);
+ exception_set_state_ptr(&exception_state);
}
void exception_install_hook(exception_hook h)