diff --git a/Kernel/Arch/Processor.cpp b/Kernel/Arch/Processor.cpp new file mode 100644 index 0000000000..f3bb93ad3a --- /dev/null +++ b/Kernel/Arch/Processor.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022, Timon Kruiper + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Kernel { + +// FIXME: Move the InterruptsState related functions inside the Processor class, when we have a generic Processor base class. +InterruptsState processor_interrupts_state() +{ + return Processor::are_interrupts_enabled() ? InterruptsState::Enabled : InterruptsState::Disabled; +} + +void restore_processor_interrupts_state(InterruptsState interrupts_state) +{ + if (interrupts_state == InterruptsState::Enabled) + Processor::enable_interrupts(); + else + Processor::disable_interrupts(); +} + +} diff --git a/Kernel/Arch/Processor.h b/Kernel/Arch/Processor.h index 2b4794e851..f634cfb603 100644 --- a/Kernel/Arch/Processor.h +++ b/Kernel/Arch/Processor.h @@ -10,6 +10,19 @@ #include #include +namespace Kernel { + +// FIXME: Move the InterruptsState enum and related functions inside the Processor class. +enum class InterruptsState { + Enabled, + Disabled +}; + +InterruptsState processor_interrupts_state(); +void restore_processor_interrupts_state(InterruptsState); + +} + #if ARCH(X86_64) || ARCH(I386) # include #elif ARCH(AARCH64) diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index b850dc3291..acdee8de2a 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -329,6 +329,8 @@ set(KERNEL_SOURCES if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64") set(KERNEL_SOURCES ${KERNEL_SOURCES} + Arch/Processor.cpp + Arch/x86/common/ScopedCritical.cpp Arch/x86/common/SmapDisabler.cpp Arch/x86/common/Spinlock.cpp @@ -443,6 +445,8 @@ else() ${AK_SOURCES} ${RPI_SOURCES} + Arch/Processor.cpp + Arch/aarch64/boot.S Arch/aarch64/BootPPMParser.cpp Arch/aarch64/CrashHandler.cpp