From a7741c857687dfc95138cbb2664059ee42b80ce9 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Mon, 13 Jan 2020 22:46:10 +0000 Subject: [PATCH] thermosphere: add cctx->userFrame --- thermosphere/src/core_ctx.h | 39 +++++++++++++++------------- thermosphere/src/exception_vectors.s | 10 ++++--- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/thermosphere/src/core_ctx.h b/thermosphere/src/core_ctx.h index e4092a2e4..814736566 100644 --- a/thermosphere/src/core_ctx.h +++ b/thermosphere/src/core_ctx.h @@ -20,29 +20,32 @@ #include "barrier.h" #include "execute_function.h" +struct ExceptionStackFrame; typedef struct CoreCtx { - u64 kernelArgument; // @0x00 - uintptr_t kernelEntrypoint; // @0x08 - u8 *crashStack; // @0x10 - u64 scratch; // @0x18 - u32 coreId; // @0x20 - u8 gicInterfaceMask; // @0x24. Equal to BIT(coreId) anyway - bool isBootCore; // @0x25 - bool warmboot; // @0x26 - - // "Execute function" - ExecutedFunction executedFunction; // @0x28 - void *executedFunctionArgs; // @0x30 - Barrier executedFunctionBarrier; // @0x38 - bool executedFunctionSync; // @0x3C + struct ExceptionStackFrame *userFrame; // @0x00 + u64 scratch; // @0x08 + u8 *crashStack; // @0x10 + u64 kernelArgument; // @0x18 + uintptr_t kernelEntrypoint; // @0x20 + u32 coreId; // @0x28 + u8 gicInterfaceMask; // @0x2C. Equal to BIT(coreId) anyway + bool isBootCore; // @0x2D + bool warmboot; // @0x2E // Timer stuff - u64 totalTimeInHypervisor; // @0x40. cntvoff_el2 is updated to that value. - u64 emulPtimerCval; // @0x48. When setting cntp_cval_el0 and on interrupt + u64 totalTimeInHypervisor; // @0x30. cntvoff_el2 is updated to that value. + u64 emulPtimerCval; // @0x38. When setting cntp_cval_el0 and on interrupt + + // "Execute function" + ExecutedFunction executedFunction; // @0x40 + void *executedFunctionArgs; // @0x48 + Barrier executedFunctionBarrier; // @0x50 + bool executedFunctionSync; // @0x54 } CoreCtx; -static_assert(offsetof(CoreCtx, executedFunctionSync) == 0x3C, "Wrong definition for CoreCtx"); -static_assert(offsetof(CoreCtx, emulPtimerCval) == 0x48, "Wrong definition for CoreCtx"); +static_assert(offsetof(CoreCtx, warmboot) == 0x2E, "Wrong definition for CoreCtx"); +static_assert(offsetof(CoreCtx, emulPtimerCval) == 0x38, "Wrong definition for CoreCtx"); +static_assert(offsetof(CoreCtx, executedFunctionSync) == 0x54, "Wrong definition for CoreCtx"); extern CoreCtx g_coreCtxs[4]; register CoreCtx *currentCoreCtx asm("x18"); diff --git a/thermosphere/src/exception_vectors.s b/thermosphere/src/exception_vectors.s index 26ba0598d..600e6df05 100644 --- a/thermosphere/src/exception_vectors.s +++ b/thermosphere/src/exception_vectors.s @@ -65,12 +65,12 @@ .macro PIVOT_STACK_FOR_CRASH // Note: x18 assumed uncorrupted // Note: replace sp_el0 with crashing sp - str x16, [x18, #0x18] // currentCoreCtx->scratch = x16 + str x16, [x18, #8] // currentCoreCtx->scratch = x16 mov x16, sp msr sp_el0, x16 - ldr x16, [x18, #0x10] // currentCoreCtx->crashStack + ldr x16, [x18, #0x10] // currentCoreCtx->crashStack mov sp, x16 - ldr x16, [x18, #0x18] + ldr x16, [x18, #8] .endm .equ EXCEPTION_TYPE_HOST, 0 @@ -85,14 +85,16 @@ vector_entry \name SAVE_MOST_REGISTERS + mov x0, sp + .if \type == EXCEPTION_TYPE_GUEST ldp x18, xzr, [sp, #STACK_FRAME_SIZE] + str x0, [x18] // currentCoreCtx->userFrame mov w1, #1 .else mov w1, #0 .endif - mov x0, sp bl exceptionEntryPostprocess .endm