Skip to content

Commit 6432f3e

Browse files
FireFox317awesomekling
authored andcommitted
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.
1 parent c1b0d25 commit 6432f3e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Kernel/Arch/Processor.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2022, Timon Kruiper <timonkruiper@gmail.com>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <Kernel/Arch/Processor.h>
8+
9+
namespace Kernel {
10+
11+
// FIXME: Move the InterruptsState related functions inside the Processor class, when we have a generic Processor base class.
12+
InterruptsState processor_interrupts_state()
13+
{
14+
return Processor::are_interrupts_enabled() ? InterruptsState::Enabled : InterruptsState::Disabled;
15+
}
16+
17+
void restore_processor_interrupts_state(InterruptsState interrupts_state)
18+
{
19+
if (interrupts_state == InterruptsState::Enabled)
20+
Processor::enable_interrupts();
21+
else
22+
Processor::disable_interrupts();
23+
}
24+
25+
}

Kernel/Arch/Processor.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
#include <AK/Function.h>
1111
#include <Kernel/Arch/DeferredCallEntry.h>
1212

13+
namespace Kernel {
14+
15+
// FIXME: Move the InterruptsState enum and related functions inside the Processor class.
16+
enum class InterruptsState {
17+
Enabled,
18+
Disabled
19+
};
20+
21+
InterruptsState processor_interrupts_state();
22+
void restore_processor_interrupts_state(InterruptsState);
23+
24+
}
25+
1326
#if ARCH(X86_64) || ARCH(I386)
1427
# include <Kernel/Arch/x86/Processor.h>
1528
#elif ARCH(AARCH64)

Kernel/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ set(KERNEL_SOURCES
329329
if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")
330330
set(KERNEL_SOURCES
331331
${KERNEL_SOURCES}
332+
Arch/Processor.cpp
333+
332334
Arch/x86/common/ScopedCritical.cpp
333335
Arch/x86/common/SmapDisabler.cpp
334336
Arch/x86/common/Spinlock.cpp
@@ -443,6 +445,8 @@ else()
443445
${AK_SOURCES}
444446
${RPI_SOURCES}
445447

448+
Arch/Processor.cpp
449+
446450
Arch/aarch64/boot.S
447451
Arch/aarch64/BootPPMParser.cpp
448452
Arch/aarch64/CrashHandler.cpp

0 commit comments

Comments
 (0)