Kernel: Move IDT to Processor

This commit is contained in:
2024-03-06 00:45:54 +02:00
parent f84df175ce
commit 76b0f80169
5 changed files with 89 additions and 52 deletions

View File

@@ -1,13 +1,63 @@
#pragma once
#include <BAN/Array.h>
#include <BAN/NoCopyMove.h>
#include <stdint.h>
constexpr uint8_t IRQ_VECTOR_BASE = 0x20;
namespace Kernel::IDT
namespace Kernel
{
void initialize();
[[noreturn]] void force_triple_fault();
class Interruptable;
struct GateDescriptor
{
uint16_t offset1;
uint16_t selector;
uint8_t IST;
uint8_t flags;
uint16_t offset2;
uint32_t offset3;
uint32_t reserved;
} __attribute__((packed));
struct IDTR
{
uint16_t size;
uint64_t offset;
} __attribute__((packed));
class IDT
{
BAN_NON_COPYABLE(IDT);
BAN_NON_MOVABLE(IDT);
public:
static IDT* create();
[[noreturn]] static void force_triple_fault();
void register_irq_handler(uint8_t irq, Interruptable* interruptable);
private:
IDT() = default;
void register_interrupt_handler(uint8_t index, void (*handler)());
void register_syscall_handler(uint8_t index, void (*handler)());
void flush()
{
asm volatile("lidt %0" :: "m"(m_idtr) : "memory");
}
private:
BAN::Array<GateDescriptor, 0x100> m_idt;
IDTR m_idtr {
.size = m_idt.size() * sizeof(GateDescriptor) - 1,
.offset = reinterpret_cast<uint64_t>(m_idt.data())
};
};
}

View File

@@ -4,6 +4,7 @@
#include <kernel/Arch.h>
#include <kernel/GDT.h>
#include <kernel/IDT.h>
namespace Kernel
{
@@ -60,6 +61,7 @@ namespace Kernel
void initialize();
GDT& gdt() { ASSERT(m_gdt); return *m_gdt; }
IDT& idt() { ASSERT(m_idt); return *m_idt; }
private:
Processor() = default;
@@ -70,6 +72,9 @@ namespace Kernel
m_gdt = other.m_gdt;
other.m_gdt = nullptr;
m_idt = other.m_idt;
other.m_idt = nullptr;
}
~Processor();
@@ -80,6 +85,7 @@ namespace Kernel
static constexpr size_t m_stack_size { 4096 };
GDT* m_gdt { nullptr };
IDT* m_idt { nullptr };
friend class BAN::Vector<Processor>;
};