1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +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

@ -34,7 +34,7 @@ static void drop_el3_to_el2()
saved_program_status_register_el3.D = 1;
// Indicate EL1 as exception origin mode (so we go back there)
saved_program_status_register_el3.M = Aarch64::SPSR_EL3::Mode::EL2t;
saved_program_status_register_el3.M = Aarch64::SPSR_EL3::Mode::EL2h;
// Set the register
Aarch64::SPSR_EL3::write(saved_program_status_register_el3);
@ -49,10 +49,6 @@ static void drop_el2_to_el1()
hypervisor_configuration_register_el2.RW = 1; // EL1 to use 64-bit mode
Aarch64::HCR_EL2::write(hypervisor_configuration_register_el2);
// Set up initial exception stack
// FIXME: Define in linker script
Aarch64::Asm::set_sp_el1(0x40000);
Aarch64::SPSR_EL2 saved_program_status_register_el2 = {};
// Mask (disable) all interrupts
@ -61,7 +57,7 @@ static void drop_el2_to_el1()
saved_program_status_register_el2.F = 1;
// Indicate EL1 as exception origin mode (so we go back there)
saved_program_status_register_el2.M = Aarch64::SPSR_EL2::Mode::EL1t;
saved_program_status_register_el2.M = Aarch64::SPSR_EL2::Mode::EL1h;
Aarch64::SPSR_EL2::write(saved_program_status_register_el2);
Aarch64::Asm::enter_el1_from_el2();