Kernel: Move interrupt related functions to InterruptController

This commit is contained in:
Bananymous 2023-03-08 03:16:51 +02:00
parent b5673278c4
commit f7ebda3bf1
4 changed files with 30 additions and 15 deletions

View File

@ -2,6 +2,9 @@
#include <stdint.h> #include <stdint.h>
#define DISABLE_INTERRUPTS() asm volatile("cli")
#define ENABLE_INTERRUPTS() asm volatile("sti")
class InterruptController class InterruptController
{ {
public: public:
@ -13,4 +16,8 @@ public:
static void initialize(bool force_pic); static void initialize(bool force_pic);
static InterruptController& get(); static InterruptController& get();
}; };
uintptr_t disable_interrupts_and_get_flags();
void restore_flags(uintptr_t);
bool interrupts_enabled();

View File

@ -24,4 +24,23 @@ void InterruptController::initialize(bool force_pic)
return; return;
dprintln("Using PIC instead of APIC"); dprintln("Using PIC instead of APIC");
s_instance = PIC::create(); s_instance = PIC::create();
}
uintptr_t disable_interrupts_and_get_flags()
{
uintptr_t flags;
asm volatile("pushf; cli; pop %0" : "=r"(flags) :: "memory");
return flags;
}
void restore_flags(uintptr_t flags)
{
asm volatile("push %0; popf" :: "rm"(flags) : "memory", "cc");
}
bool interrupts_enabled()
{
uintptr_t flags;
asm volatile("pushf; pop %0" : "=r"(flags) :: "memory");
return flags & (1 << 9);
} }

View File

@ -5,12 +5,11 @@
#include <kernel/PCI.h> #include <kernel/PCI.h>
#define DISABLE_INTERRUPTS() asm volatile("cli")
#define ENABLE_INTERRUPTS() asm volatile("sti")
#if 1 #if 1
#define VERIFY_CLI() ASSERT(interrupts_disabled()) #define VERIFY_STI() ASSERT(interrupts_enabled())
#define VERIFY_CLI() ASSERT(!interrupts_enabled())
#else #else
#define VERIFY_STI()
#define VERIFY_CLI() #define VERIFY_CLI()
#endif #endif
@ -23,13 +22,6 @@ namespace Kernel
static Scheduler* s_instance = nullptr; static Scheduler* s_instance = nullptr;
static bool interrupts_disabled()
{
uintptr_t flags;
asm volatile("pushf; pop %0" : "=r"(flags));
return !(flags & (1 << 9));
}
BAN::ErrorOr<void> Scheduler::initialize() BAN::ErrorOr<void> Scheduler::initialize()
{ {
ASSERT(s_instance == nullptr); ASSERT(s_instance == nullptr);

View File

@ -17,9 +17,6 @@
#include <kernel/TTY.h> #include <kernel/TTY.h>
#include <kernel/VesaTerminalDriver.h> #include <kernel/VesaTerminalDriver.h>
#define DISABLE_INTERRUPTS() asm volatile("cli")
#define ENABLE_INTERRUPTS() asm volatile("sti")
extern "C" const char g_kernel_cmdline[]; extern "C" const char g_kernel_cmdline[];
struct ParsedCommandLine struct ParsedCommandLine