mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:47:44 +00:00
Kernel: Factor our PreviousMode into RegisterState::previous_mode
Various places in the kernel were manually checking the cs register for x86_64, however to share this with aarch64 a function in RegisterState is added, and the call-sites are updated. While we're here the PreviousMode enum is renamed to ExecutionMode.
This commit is contained in:
parent
247109cee6
commit
fb10774862
11 changed files with 53 additions and 29 deletions
|
@ -19,7 +19,7 @@ void handle_crash(Kernel::RegisterState const& regs, char const* description, in
|
|||
if (!current_thread)
|
||||
PANIC("{} with !Thread::current()", description);
|
||||
|
||||
auto crashed_in_kernel = (regs.cs & 3) == 0;
|
||||
auto crashed_in_kernel = regs.previous_mode() == ExecutionMode::Kernel;
|
||||
if (!crashed_in_kernel && current_thread->has_signal_handler(signal) && !current_thread->should_ignore_signal(signal) && !current_thread->is_signal_masked(signal)) {
|
||||
current_thread->send_urgent_signal_to_self(signal);
|
||||
return;
|
||||
|
@ -31,7 +31,7 @@ void handle_crash(Kernel::RegisterState const& regs, char const* description, in
|
|||
// make sure we switch back to the right page tables.
|
||||
Memory::MemoryManager::enter_process_address_space(process);
|
||||
|
||||
dmesgln("CRASH: CPU #{} {} in ring {}", Processor::current_id(), description, (regs.cs & 3));
|
||||
dmesgln("CRASH: CPU #{} {} in {}", Processor::current_id(), description, regs.previous_mode() == ExecutionMode::Kernel ? "kernel"sv : "userspace"sv);
|
||||
dump_registers(regs);
|
||||
|
||||
if (crashed_in_kernel) {
|
||||
|
|
|
@ -918,10 +918,10 @@ void Processor::enter_trap(TrapFrame& trap, bool raise_irq)
|
|||
auto& current_trap = current_thread->current_trap();
|
||||
trap.next_trap = current_trap;
|
||||
current_trap = &trap;
|
||||
// The cs register of this trap tells us where we will return back to
|
||||
auto new_previous_mode = ((trap.regs->cs & 3) != 0) ? Thread::PreviousMode::UserMode : Thread::PreviousMode::KernelMode;
|
||||
|
||||
auto new_previous_mode = trap.regs->previous_mode();
|
||||
if (current_thread->set_previous_mode(new_previous_mode) && trap.prev_irq_level == 0) {
|
||||
current_thread->update_time_scheduled(TimeManagement::scheduler_current_time(), new_previous_mode == Thread::PreviousMode::KernelMode, false);
|
||||
current_thread->update_time_scheduled(TimeManagement::scheduler_current_time(), new_previous_mode == ExecutionMode::Kernel, false);
|
||||
}
|
||||
} else {
|
||||
trap.next_trap = nullptr;
|
||||
|
@ -954,17 +954,16 @@ void Processor::exit_trap(TrapFrame& trap)
|
|||
if (current_thread) {
|
||||
auto& current_trap = current_thread->current_trap();
|
||||
current_trap = trap.next_trap;
|
||||
Thread::PreviousMode new_previous_mode;
|
||||
ExecutionMode new_previous_mode;
|
||||
if (current_trap) {
|
||||
VERIFY(current_trap->regs);
|
||||
// If we have another higher level trap then we probably returned
|
||||
// from an interrupt or irq handler. The cs register of the
|
||||
// new/higher level trap tells us what the mode prior to it was
|
||||
new_previous_mode = ((current_trap->regs->cs & 3) != 0) ? Thread::PreviousMode::UserMode : Thread::PreviousMode::KernelMode;
|
||||
// from an interrupt or irq handler.
|
||||
new_previous_mode = current_trap->regs->previous_mode();
|
||||
} else {
|
||||
// If we don't have a higher level trap then we're back in user mode.
|
||||
// Which means that the previous mode prior to being back in user mode was kernel mode
|
||||
new_previous_mode = Thread::PreviousMode::KernelMode;
|
||||
new_previous_mode = ExecutionMode::Kernel;
|
||||
}
|
||||
|
||||
if (current_thread->set_previous_mode(new_previous_mode))
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <Kernel/Arch/CPU.h>
|
||||
#include <Kernel/Arch/x86_64/ASM_wrapper.h>
|
||||
#include <Kernel/ExecutionMode.h>
|
||||
|
||||
#include <AK/Platform.h>
|
||||
VALIDATE_IS_X86()
|
||||
|
@ -68,6 +69,11 @@ struct [[gnu::packed]] RegisterState {
|
|||
arg3 = rbx;
|
||||
arg4 = rsi;
|
||||
}
|
||||
|
||||
ExecutionMode previous_mode() const
|
||||
{
|
||||
return ((cs & 3) != 0) ? ExecutionMode::User : ExecutionMode::Kernel;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_STATE_SIZE (22 * 8)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue