1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 14:57:34 +00:00

Prekernel: Handle synchronous EL1 exceptions in C++ on aarch64

We now have a mechanism to save the current CPU context to the stack,
and then pass that to the C++ common exception handler.
This commit is contained in:
Jesse Buhagiar 2021-10-14 22:38:59 +11:00 committed by Brian Gianforcaro
parent 547322fb95
commit 5b7682b352
2 changed files with 139 additions and 7 deletions

View file

@ -23,8 +23,17 @@ static u32 query_firmware_version();
extern "C" void wait_cycles(int n);
struct TrapFrame {
u64 x[31]; // Saved general purpose registers
u64 spsr_el1; // Save Processor Status Register, EL1
u64 elr_el1; // Exception Link Reigster, EL1
u64 tpidr_el1; // EL0 thread ID
u64 sp_el0; // EL0 stack pointer
};
extern "C" [[noreturn]] void halt();
extern "C" [[noreturn]] void init();
extern "C" void exception_common(TrapFrame const* const trap_frame);
extern "C" [[noreturn]] void init()
{
@ -50,9 +59,6 @@ extern "C" [[noreturn]] void init()
extern uintptr_t vector_table_el1;
el1_vector_table_install(&vector_table_el1);
// Set the register
asm("msr sctlr_el1, %[value]" ::[value] "r"(system_control_register_el1));
uart.print_str("Initialize MMU\r\n");
Prekernel::init_prekernel_page_tables();
@ -91,6 +97,41 @@ void __stack_chk_fail()
Prekernel::halt();
}
extern "C" void exception_common(TrapFrame const* const trap_frame)
{
static constexpr bool print_stack_frame = true;
if constexpr (print_stack_frame) {
auto& uart = Prekernel::UART::the();
uart.print_str("Exception Generated by processor!\n");
for (auto reg = 0; reg < 31; reg++) {
uart.print_str("x");
uart.print_num(reg);
uart.print_str(": ");
uart.print_hex(trap_frame->x[reg]);
uart.print_str("\r\n");
}
// Special registers
uart.print_str("spsr_el1: ");
uart.print_hex(trap_frame->spsr_el1);
uart.print_str("\r\n");
uart.print_str("elr_el1: ");
uart.print_hex(trap_frame->elr_el1);
uart.print_str("\r\n");
uart.print_str("tpidr_el1: ");
uart.print_hex(trap_frame->tpidr_el1);
uart.print_str("\r\n");
uart.print_str("sp_el0: ");
uart.print_hex(trap_frame->sp_el0);
uart.print_str("\r\n");
}
}
class QueryFirmwareVersionMboxMessage : Prekernel::Mailbox::Message {
public:
u32 version;