mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-19 00:42:06 +00:00
thermosphere: start corectx/exception stuff rewrite
This commit is contained in:
parent
d72fc3e8b9
commit
ea7d161755
4 changed files with 18 additions and 27 deletions
|
@ -16,11 +16,6 @@
|
||||||
|
|
||||||
#define EXCEP_STACK_FRAME_SIZE 0x140
|
#define EXCEP_STACK_FRAME_SIZE 0x140
|
||||||
|
|
||||||
#define CORECTX_CRASH_STACK_OFFSET 0x000
|
|
||||||
#define CORECTX_GUEST_FRAME_OFFSET 0x040
|
|
||||||
#define CORECTX_SCRATCH_OFFSET 0x048
|
|
||||||
|
|
||||||
|
|
||||||
.macro FUNCTION name
|
.macro FUNCTION name
|
||||||
.section .text.\name, "ax", %progbits
|
.section .text.\name, "ax", %progbits
|
||||||
.global \name
|
.global \name
|
||||||
|
|
|
@ -23,11 +23,9 @@ struct ExceptionStackFrame;
|
||||||
typedef struct ALIGN(64) CoreCtx {
|
typedef struct ALIGN(64) CoreCtx {
|
||||||
// Most likely only just read (assume cache line size of at most 64 bytes):
|
// Most likely only just read (assume cache line size of at most 64 bytes):
|
||||||
|
|
||||||
u8 *crashStack; // @0x00
|
|
||||||
u64 kernelArgument; // @0x08
|
u64 kernelArgument; // @0x08
|
||||||
uintptr_t kernelEntrypoint; // @0x10
|
uintptr_t kernelEntrypoint; // @0x10
|
||||||
u32 coreId; // @0x18
|
u32 coreId; // @0x18
|
||||||
u8 gicInterfaceMask; // @0x1C. Equal to BIT(coreId) anyway
|
|
||||||
bool isBootCore; // @0x1D
|
bool isBootCore; // @0x1D
|
||||||
bool warmboot; // @0x1E
|
bool warmboot; // @0x1E
|
||||||
|
|
||||||
|
@ -39,14 +37,10 @@ typedef struct ALIGN(64) CoreCtx {
|
||||||
// Most likely written to:
|
// Most likely written to:
|
||||||
|
|
||||||
ALIGN(64) struct ExceptionStackFrame *guestFrame; // @0x40
|
ALIGN(64) struct ExceptionStackFrame *guestFrame; // @0x40
|
||||||
u64 scratch; // @0x48
|
|
||||||
|
|
||||||
// Timer stuff
|
// Timer stuff
|
||||||
u64 totalTimeInHypervisor; // @0x50. cntvoff_el2 is updated to that value.
|
u64 totalTimeInHypervisor; // @0x50. cntvoff_el2 is updated to that value.
|
||||||
u64 emulPtimerCval; // @0x58. When setting cntp_cval_el0 and on interrupt
|
u64 emulPtimerCval; // @0x58. When setting cntp_cval_el0 and on interrupt
|
||||||
|
|
||||||
// Cache stuff
|
|
||||||
u32 setWayCounter; // @0x7C
|
|
||||||
} CoreCtx;
|
} CoreCtx;
|
||||||
|
|
||||||
/*static_assert(offsetof(CoreCtx, warmboot) == 0x1E, "Wrong definition for CoreCtx");
|
/*static_assert(offsetof(CoreCtx, warmboot) == 0x1E, "Wrong definition for CoreCtx");
|
||||||
|
|
|
@ -78,14 +78,16 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro PIVOT_STACK_FOR_CRASH
|
.macro PIVOT_STACK_FOR_CRASH
|
||||||
// Note: x18 assumed uncorrupted
|
// Note: replace sp_el1 with crashing sp (for convenience)
|
||||||
// Note: replace sp_el0 with crashing sp
|
// The way we do things means that exception stack ptr won't be reset on double fault
|
||||||
str x16, [x18, #CORECTX_SCRATCH_OFFSET]
|
// (sp_el2 is not accessible at el2)
|
||||||
mov x16, sp
|
msr spsel, #0
|
||||||
msr sp_el0, x16
|
str x0, [sp, #-0x10]
|
||||||
ldr x16, [x18, #CORECTX_CRASH_STACK_OFFSET]
|
msr spsel, #1
|
||||||
mov sp, x16
|
mov x0, sp
|
||||||
ldr x16, [x18, #CORECTX_SCRATCH_OFFSET]
|
msr sp_el1, x0
|
||||||
|
msr spsel, #0
|
||||||
|
ldr x0, [sp, #-0x10]
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
#define EXCEPTION_TYPE_HOST 0
|
#define EXCEPTION_TYPE_HOST 0
|
||||||
|
@ -103,10 +105,10 @@ vector_entry \name
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
|
|
||||||
.if \type == EXCEPTION_TYPE_GUEST
|
.if \type == EXCEPTION_TYPE_GUEST
|
||||||
ldp x18, xzr, [sp, #EXCEP_STACK_FRAME_SIZE]
|
ldp x18, x19, [sp, #EXCEP_STACK_FRAME_SIZE]
|
||||||
prfm pldl1keep, [x18]
|
msr sp_el0, x19
|
||||||
prfm pstl1keep, [x18, #0x40]
|
prfm pstl1keep, [x18]
|
||||||
str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
|
//todo str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
|
||||||
mov w1, #1
|
mov w1, #1
|
||||||
.else
|
.else
|
||||||
mov w1, #0
|
mov w1, #0
|
||||||
|
@ -148,7 +150,7 @@ vector_entry _synchSp0
|
||||||
check_vector_size _synchSp0
|
check_vector_size _synchSp0
|
||||||
|
|
||||||
_unknownException:
|
_unknownException:
|
||||||
pivot_stack_for_crash
|
PIVOT_STACK_FOR_CRASH
|
||||||
mov x0, x30
|
mov x0, x30
|
||||||
adr x1, g_thermosphereVectors + 4
|
adr x1, g_thermosphereVectors + 4
|
||||||
sub x0, x0, x1
|
sub x0, x0, x1
|
||||||
|
|
|
@ -94,16 +94,16 @@ _postMmuEnableReturnAddr:
|
||||||
bl initSystem
|
bl initSystem
|
||||||
|
|
||||||
// Save x18, reserve space for exception frame
|
// Save x18, reserve space for exception frame
|
||||||
|
// TODO: save exception stack too
|
||||||
stp x18, xzr, [sp, #-0x10]!
|
stp x18, xzr, [sp, #-0x10]!
|
||||||
sub sp, sp, #EXCEP_STACK_FRAME_SIZE
|
sub sp, sp, #EXCEP_STACK_FRAME_SIZE
|
||||||
|
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
mov x1, x20
|
mov x1, x20
|
||||||
str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
|
//str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
|
||||||
bl thermosphereMain
|
bl thermosphereMain
|
||||||
|
|
||||||
prfm pldl1keep, [x18]
|
prfm pstl1keep, [x18]
|
||||||
prfm pstl1keep, [x18, #0x40]
|
|
||||||
|
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
|
|
Loading…
Reference in a new issue