1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:17:35 +00:00

Kernel/aarch64: Execute kernel with SP_EL1 instead of SP_EL0

Until now the kernel was always executing with SP_EL0, as this made the
initial dropping to EL1 a bit easier. This commit changes this behaviour
to use the corresponding SP_ELx for each exception level.

To make sure that the execution of the C++ code can continue, the
current stack pointer is copied into the corresponding SP_ELx just
before dropping an exception level.
This commit is contained in:
Timon Kruiper 2023-01-08 14:01:31 +01:00 committed by Andreas Kling
parent 05659debd1
commit 247109cee6
5 changed files with 23 additions and 20 deletions

View file

@ -6,7 +6,7 @@
.section .text.vector_table
#define TRAP_FRAME_SIZE 272
#define REGISTER_STATE_SIZE 272
#define SPSR_EL1_SLOT (31 * 8)
#define ELR_EL1_SLOT (32 * 8)
#define TPIDR_EL0_SLOT (33 * 8)
@ -34,7 +34,7 @@
//
.macro save_current_context
// Allocate stack space for Trap Frame
sub sp, sp, #TRAP_FRAME_SIZE
sub sp, sp, #REGISTER_STATE_SIZE
stp x0, x1, [sp, #(0 * 0)]
stp x2, x3, [sp, #(2 * 8)]
@ -60,10 +60,12 @@
str x0, [sp, #ELR_EL1_SLOT]
mrs x0, tpidr_el0
str x0, [sp, #TPIDR_EL0_SLOT]
mrs x0, sp_el0
str x0, [sp, #SP_EL0_SLOT]
// Set up TrapFrame struct on the stack
sub sp, sp, #16
mov x0, sp
sub sp, sp, #16
str x0, [sp, #(1 * 8)]
str xzr, [sp, #(0 * 0)]
@ -83,6 +85,8 @@
msr elr_el1, x0
ldr x0, [sp, #TPIDR_EL0_SLOT]
msr tpidr_el0, x0
ldr x0, [sp, #SP_EL0_SLOT]
msr sp_el0, x0
ldp x0, x1, [sp, #(0 * 0)]
ldp x2, x3, [sp, #(2 * 8)]
@ -101,7 +105,7 @@
ldp x28, x29, [sp, #(28 * 8)]
ldr x30, [sp, #(30 * 8)]
add sp, sp, #TRAP_FRAME_SIZE
add sp, sp, #REGISTER_STATE_SIZE
.endm
.global vector_table_el1
@ -143,7 +147,7 @@ synchronous_current_elsp_elx:
irq_current_elsp_elx:
save_current_context
bl exception_common
bl handle_interrupt
restore_previous_context
eret
@ -166,10 +170,6 @@ synchronous_current_elsp_el0:
eret
irq_current_elsp_el0:
// An IRQ will always switch the stack pointer to SP_EL1, however we want to use SP_EL0, so switch
// to SP_EL0. This means that the stack of the currently executing thread is used as the irq stack.
msr SPSel, #0
save_current_context
bl handle_interrupt
restore_previous_context