1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

Kernel: Push ARCH specific ifdef's down into RegisterState functions

The non CPU specific code of the kernel shouldn't need to deal with
architecture specific registers, and should instead deal with an
abstract view of the machine. This allows us to remove a variety of
architecture specific ifdefs and helps keep the code slightly more
portable.

We do this by exposing the abstract representation of instruction
pointer, stack pointer, base pointer, return register, etc on the
RegisterState struct.
This commit is contained in:
Brian Gianforcaro 2021-07-18 16:50:08 -07:00 committed by Gunnar Beutner
parent ff8429a749
commit 1cffecbe8d
9 changed files with 119 additions and 97 deletions

View file

@ -228,13 +228,7 @@ void handle_crash(RegisterState& regs, const char* description, int signal, bool
PANIC("Crash in ring 0");
}
FlatPtr ip;
#if ARCH(I386)
ip = regs.eip;
#else
ip = regs.rip;
#endif
process->crash(signal, ip, out_of_memory);
process->crash(signal, regs.ip(), out_of_memory);
}
EH_ENTRY_NO_CODE(6, illegal_instruction);
@ -316,12 +310,7 @@ void page_fault_handler(TrapFrame* trap)
current_thread->set_handling_page_fault(false);
};
VirtualAddress userspace_sp;
#if ARCH(I386)
userspace_sp = VirtualAddress { regs.userspace_esp };
#else
userspace_sp = VirtualAddress { regs.userspace_rsp };
#endif
VirtualAddress userspace_sp = VirtualAddress { regs.userspace_sp() };
if (!faulted_in_kernel && !MM.validate_user_stack(current_thread->process(), userspace_sp)) {
dbgln("Invalid stack pointer: {}", userspace_sp);
handle_crash(regs, "Bad stack on page fault", SIGSTKFLT);