From 6432f3eee8b21979c0a455008f0a8d2124ed15a7 Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Tue, 23 Aug 2022 21:25:36 +0200 Subject: [PATCH] Kernel: Add enum InterruptsState and helper functions This commit adds the concept of an InterruptsState to the kernel. This will be used to make the Spinlock code architecture independent. A new Processor.cpp file is added such that we don't have to duplicate the code. --- Kernel/Arch/Processor.cpp | 25 +++++++++++++++++++++++++ Kernel/Arch/Processor.h | 13 +++++++++++++ Kernel/CMakeLists.txt | 4 ++++ 3 files changed, 42 insertions(+) create mode 100644 Kernel/Arch/Processor.cpp 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