thermosphere: rework linkscrips, use discardable sections, better sp pivot on crash
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
// start.s
|
||||
extern uintptr_t g_initialKernelEntrypoint;
|
||||
|
||||
extern u8 __stacks_top__[], __crash_stacks_top__[];
|
||||
|
||||
// Prevents it from being put in BSS
|
||||
CoreCtx g_coreCtxs[4] = {
|
||||
{ .coreId = 0 },
|
||||
@@ -29,10 +31,12 @@ CoreCtx g_coreCtxs[4] = {
|
||||
|
||||
void coreCtxInit(u32 coreId, bool isColdbootCore, u64 argument)
|
||||
{
|
||||
size_t crashStackSize = (__crash_stacks_top__ - __stacks_top__) / 4;
|
||||
currentCoreCtx = &g_coreCtxs[coreId];
|
||||
currentCoreCtx->isColdbootCore = isColdbootCore;
|
||||
currentCoreCtx->kernelArgument = argument;
|
||||
if (isColdbootCore) {
|
||||
currentCoreCtx->crashStack = __crash_stacks_top__ - crashStackSize * coreId;
|
||||
if (isColdbootCore && currentCoreCtx->kernelEntrypoint == 0) {
|
||||
currentCoreCtx->kernelEntrypoint = g_initialKernelEntrypoint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,12 @@
|
||||
#include "utils.h"
|
||||
|
||||
typedef struct CoreCtx {
|
||||
u64 kernelArgument;
|
||||
uintptr_t kernelEntrypoint;
|
||||
u32 coreId; // @0x10
|
||||
bool isColdbootCore; // @0x14
|
||||
u64 kernelArgument; // @0x00
|
||||
uintptr_t kernelEntrypoint; // @0x08
|
||||
u8 *crashStack; // @0x10
|
||||
u64 scratch; // @0x18
|
||||
u32 coreId; // @0x20
|
||||
bool isColdbootCore; // @0x24
|
||||
} CoreCtx;
|
||||
|
||||
extern CoreCtx g_coreCtxs[4];
|
||||
|
||||
@@ -63,17 +63,14 @@
|
||||
.endm
|
||||
|
||||
.macro pivot_stack_for_crash
|
||||
// Note: reset x18 assumed uncorrupted
|
||||
// Note: x18 assumed uncorrupted
|
||||
// Note: replace sp_el0 with crashing sp
|
||||
mrs x18, esr_el2
|
||||
mov x18, sp
|
||||
msr sp_el0, x18
|
||||
bic x18, x18, #0xFF
|
||||
bic x18, x18, #0x300
|
||||
add x18, x18, #0x400
|
||||
mov sp, x18
|
||||
ldp x18, xzr, [sp, #-0x10]
|
||||
add sp, sp, #0x1000
|
||||
str x16, [x18, #0x18] // currentCoreCtx->scratch = x16
|
||||
mov x16, sp
|
||||
msr sp_el0, x16
|
||||
ldr x16, [x18, #0x10] // currentCoreCtx->crashStack
|
||||
mov sp, x16
|
||||
ldr x16, [x18, #0x18]
|
||||
.endm
|
||||
|
||||
/* Actual Vectors for Thermosphere. */
|
||||
|
||||
Reference in New Issue
Block a user