Kernel: Move Interruptable from InterruptController.h to its own file

This commit is contained in:
Bananymous 2024-03-06 00:46:20 +02:00
parent 76b0f80169
commit f0105cb7fb
15 changed files with 63 additions and 48 deletions

View File

@ -40,6 +40,7 @@ set(KERNEL_SOURCES
kernel/Input/PS2/Keyboard.cpp kernel/Input/PS2/Keyboard.cpp
kernel/Input/PS2/Keymap.cpp kernel/Input/PS2/Keymap.cpp
kernel/Input/PS2/Mouse.cpp kernel/Input/PS2/Mouse.cpp
kernel/Interruptable.cpp
kernel/InterruptController.cpp kernel/InterruptController.cpp
kernel/kernel.cpp kernel/kernel.cpp
kernel/Memory/DMARegion.cpp kernel/Memory/DMARegion.cpp

View File

@ -2,6 +2,7 @@
#include <BAN/Array.h> #include <BAN/Array.h>
#include <BAN/NoCopyMove.h> #include <BAN/NoCopyMove.h>
#include <kernel/Interruptable.h>
#include <stdint.h> #include <stdint.h>
@ -10,8 +11,6 @@ constexpr uint8_t IRQ_VECTOR_BASE = 0x20;
namespace Kernel namespace Kernel
{ {
class Interruptable;
struct GateDescriptor struct GateDescriptor
{ {
uint16_t offset1; uint16_t offset1;

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <kernel/Input/PS2/Controller.h> #include <kernel/Input/PS2/Controller.h>
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
namespace Kernel::Input namespace Kernel::Input
{ {

View File

@ -8,23 +8,6 @@
namespace Kernel namespace Kernel
{ {
class Interruptable
{
public:
void set_irq(int irq);
void enable_interrupt();
void disable_interrupt();
virtual void handle_irq() = 0;
protected:
Interruptable() = default;
~Interruptable() {}
private:
int m_irq { -1 };
};
class InterruptController class InterruptController
{ {
public: public:

View File

@ -0,0 +1,23 @@
#pragma once
namespace Kernel
{
class Interruptable
{
public:
void set_irq(int irq);
void enable_interrupt();
void disable_interrupt();
virtual void handle_irq() = 0;
protected:
Interruptable() = default;
~Interruptable() {}
private:
int m_irq { -1 };
};
}

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <BAN/UniqPtr.h> #include <BAN/UniqPtr.h>
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
#include <kernel/Memory/DMARegion.h> #include <kernel/Memory/DMARegion.h>
#include <kernel/Networking/E1000/Definitions.h> #include <kernel/Networking/E1000/Definitions.h>
#include <kernel/Networking/NetworkInterface.h> #include <kernel/Networking/NetworkInterface.h>

View File

@ -2,7 +2,7 @@
#include <BAN/Array.h> #include <BAN/Array.h>
#include <BAN/RefPtr.h> #include <BAN/RefPtr.h>
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
#include <kernel/Memory/DMARegion.h> #include <kernel/Memory/DMARegion.h>
#include <kernel/PCI.h> #include <kernel/PCI.h>
#include <kernel/Storage/ATA/AHCI/Definitions.h> #include <kernel/Storage/ATA/AHCI/Definitions.h>

View File

@ -3,7 +3,7 @@
#include <BAN/ByteSpan.h> #include <BAN/ByteSpan.h>
#include <BAN/RefPtr.h> #include <BAN/RefPtr.h>
#include <BAN/Vector.h> #include <BAN/Vector.h>
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
#include <kernel/Lock/Mutex.h> #include <kernel/Lock/Mutex.h>
namespace Kernel namespace Kernel

View File

@ -2,7 +2,7 @@
#include <BAN/UniqPtr.h> #include <BAN/UniqPtr.h>
#include <BAN/Vector.h> #include <BAN/Vector.h>
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
#include <kernel/Lock/Mutex.h> #include <kernel/Lock/Mutex.h>
#include <kernel/Memory/DMARegion.h> #include <kernel/Memory/DMARegion.h>
#include <kernel/Semaphore.h> #include <kernel/Semaphore.h>

View File

@ -2,7 +2,7 @@
#include <BAN/CircularQueue.h> #include <BAN/CircularQueue.h>
#include <BAN/Errors.h> #include <BAN/Errors.h>
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
#include <kernel/Terminal/TTY.h> #include <kernel/Terminal/TTY.h>
namespace Kernel namespace Kernel

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
#include <kernel/Lock/SpinLock.h> #include <kernel/Lock/SpinLock.h>
#include <kernel/Timer/Timer.h> #include <kernel/Timer/Timer.h>

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <kernel/InterruptController.h> #include <kernel/Interruptable.h>
#include <kernel/Timer/Timer.h> #include <kernel/Timer/Timer.h>
namespace Kernel namespace Kernel

View File

@ -8,29 +8,8 @@
namespace Kernel namespace Kernel
{ {
namespace IDT { void register_irq_handler(uint8_t irq, Interruptable*); }
static InterruptController* s_instance = nullptr; static InterruptController* s_instance = nullptr;
void Interruptable::set_irq(int irq)
{
if (m_irq != -1)
IDT::register_irq_handler(m_irq, nullptr);
m_irq = irq;
IDT::register_irq_handler(irq, this);
}
void Interruptable::enable_interrupt()
{
ASSERT(m_irq != -1);
InterruptController::get().enable_irq(m_irq);
}
void Interruptable::disable_interrupt()
{
ASSERT_NOT_REACHED();
}
InterruptController& InterruptController::get() InterruptController& InterruptController::get()
{ {
ASSERT(s_instance); ASSERT(s_instance);

View File

@ -0,0 +1,29 @@
#include <kernel/IDT.h>
#include <kernel/Interruptable.h>
#include <kernel/InterruptController.h>
#include <kernel/Processor.h>
namespace Kernel
{
void Interruptable::set_irq(int irq)
{
auto& processor = Processor::current();
if (m_irq != -1)
processor.idt().register_irq_handler(m_irq, nullptr);
m_irq = irq;
processor.idt().register_irq_handler(irq, this);
}
void Interruptable::enable_interrupt()
{
ASSERT(m_irq != -1);
InterruptController::get().enable_irq(m_irq);
}
void Interruptable::disable_interrupt()
{
ASSERT_NOT_REACHED();
}
}

View File

@ -1,4 +1,5 @@
#include <kernel/FS/DevFS/FileSystem.h> #include <kernel/FS/DevFS/FileSystem.h>
#include <kernel/InterruptController.h>
#include <kernel/Storage/ATA/AHCI/Controller.h> #include <kernel/Storage/ATA/AHCI/Controller.h>
#include <kernel/Storage/ATA/ATABus.h> #include <kernel/Storage/ATA/ATABus.h>
#include <kernel/Storage/ATA/ATAController.h> #include <kernel/Storage/ATA/ATAController.h>