Kernel: Move interrupt status functions to kernel/Interrupts.h
This commit is contained in:
@@ -5,9 +5,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define DISABLE_INTERRUPTS() asm volatile("cli")
|
||||
#define ENABLE_INTERRUPTS() asm volatile("sti")
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
@@ -51,11 +48,4 @@ namespace Kernel
|
||||
bool m_using_apic { false };
|
||||
};
|
||||
|
||||
inline bool interrupts_enabled()
|
||||
{
|
||||
uintptr_t flags;
|
||||
asm volatile("pushf; pop %0" : "=r"(flags) :: "memory");
|
||||
return flags & (1 << 9);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
37
kernel/include/kernel/Interrupts.h
Normal file
37
kernel/include/kernel/Interrupts.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <kernel/Arch.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
enum class InterruptState
|
||||
{
|
||||
Disabled,
|
||||
Enabled,
|
||||
};
|
||||
|
||||
#if ARCH(x86_64) || ARCH(i386)
|
||||
|
||||
inline void set_interrupt_state(InterruptState state)
|
||||
{
|
||||
if (state == InterruptState::Enabled)
|
||||
asm volatile("sti");
|
||||
else
|
||||
asm volatile("cli");
|
||||
}
|
||||
|
||||
inline InterruptState get_interrupt_state()
|
||||
{
|
||||
uintptr_t flags;
|
||||
asm volatile("pushf; pop %0" : "=rm"(flags));
|
||||
if (flags & (1 << 9))
|
||||
return InterruptState::Enabled;
|
||||
return InterruptState::Disabled;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Unknown architecure"
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -2,14 +2,13 @@
|
||||
|
||||
#include <BAN/Atomic.h>
|
||||
#include <BAN/NoCopyMove.h>
|
||||
#include <kernel/Interrupts.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
using InterruptState = bool;
|
||||
|
||||
class SpinLock
|
||||
{
|
||||
BAN_NON_COPYABLE(SpinLock);
|
||||
|
||||
Reference in New Issue
Block a user