diff options
author | Timon Kruiper <timonkruiper@gmail.com> | 2022-05-16 14:42:49 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-06-02 13:14:12 +0100 |
commit | a4534678f978c7ea62b70bc8ab4bdc8f6437f90a (patch) | |
tree | 05d79a605c96f8bf8ab9afc1c87c464f78e8ca34 /Kernel/Arch | |
parent | ea9cf8b6ab6a3941ecb4727723e8e38fbd6b4bb8 (diff) | |
download | serenity-a4534678f978c7ea62b70bc8ab4bdc8f6437f90a.zip |
Kernel: Implement InterruptDisabler using generic Processor functions
Now that the code does not use architectural specific code, it is moved
to the generic Arch directory and the paths are modified accordingly.
Diffstat (limited to 'Kernel/Arch')
-rw-r--r-- | Kernel/Arch/InterruptDisabler.h | 32 | ||||
-rw-r--r-- | Kernel/Arch/x86/InterruptDisabler.h | 38 | ||||
-rw-r--r-- | Kernel/Arch/x86/common/Processor.cpp | 2 | ||||
-rw-r--r-- | Kernel/Arch/x86/common/TrapFrame.cpp | 2 |
4 files changed, 34 insertions, 40 deletions
diff --git a/Kernel/Arch/InterruptDisabler.h b/Kernel/Arch/InterruptDisabler.h new file mode 100644 index 0000000000..d4e49bb9b4 --- /dev/null +++ b/Kernel/Arch/InterruptDisabler.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022, Timon Kruiper <timonkruiper@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Types.h> +#include <Kernel/Arch/Processor.h> + +namespace Kernel { + +class InterruptDisabler { +public: + InterruptDisabler() + : m_interrupts_were_enabled(Processor::are_interrupts_enabled()) + { + Processor::disable_interrupts(); + } + + ~InterruptDisabler() + { + if (m_interrupts_were_enabled) + Processor::enable_interrupts(); + } + +private: + bool m_interrupts_were_enabled; +}; + +} diff --git a/Kernel/Arch/x86/InterruptDisabler.h b/Kernel/Arch/x86/InterruptDisabler.h deleted file mode 100644 index 941ddaab2b..0000000000 --- a/Kernel/Arch/x86/InterruptDisabler.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <AK/Types.h> - -#include <Kernel/Arch/x86/IO.h> - -#include <Kernel/Arch/x86/ASM_wrapper.h> - -#include <AK/Platform.h> -VALIDATE_IS_X86() - -namespace Kernel { - -class InterruptDisabler { -public: - InterruptDisabler() - { - m_flags = cpu_flags(); - cli(); - } - - ~InterruptDisabler() - { - if ((m_flags & 0x200) != 0) - sti(); - } - -private: - u32 m_flags; -}; - -} diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index 7e2e2800ad..632d24e2b9 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -19,12 +19,12 @@ #include <Kernel/StdLib.h> #include <Kernel/Thread.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/Interrupts.h> #include <Kernel/Arch/Processor.h> #include <Kernel/Arch/SafeMem.h> #include <Kernel/Arch/ScopedCritical.h> #include <Kernel/Arch/x86/CPUID.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/MSR.h> #include <Kernel/Arch/x86/ProcessorInfo.h> #include <Kernel/Arch/x86/TrapFrame.h> diff --git a/Kernel/Arch/x86/common/TrapFrame.cpp b/Kernel/Arch/x86/common/TrapFrame.cpp index 9e3054c678..2262840d1c 100644 --- a/Kernel/Arch/x86/common/TrapFrame.cpp +++ b/Kernel/Arch/x86/common/TrapFrame.cpp @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/Processor.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/TrapFrame.h> namespace Kernel { |