aboutsummaryrefslogtreecommitdiff
path: root/src/idt.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/idt.h')
-rw-r--r--src/idt.h46
1 files changed, 12 insertions, 34 deletions
diff --git a/src/idt.h b/src/idt.h
index 628eb23..bc71f05 100644
--- a/src/idt.h
+++ b/src/idt.h
@@ -11,54 +11,32 @@ public:
enum InterruptType : uint8_t {
Null = 0,
- InterruptGate = 0b110, // hardware interrupts are disabled while the handler runs
- TrapGate = 0b111, // hardware interrupts remain active while the handler runs
- TaskGate = 0b101, // selector points to TSS rather than a code segment
+ Task = 0b10000101, // 32-bit task gate selector points to TSS rather than a code segment
+ Intr = 0b10001110, // 32-bit interrupt hardware interrupts are disabled while the handler runs
+ Trap = 0b10001111, // 32-bit trap gate hardware interrupts remain active while the handler runs
};
class Entry {
public:
- constexpr Entry(uint32_t offset = 0, uint16_t select = 0, InterruptType t = Null) {
- offset_0_15 = offset & 0xffff;
- offset_16_31 = (offset & 0xffff0000) >> 16;
+ constexpr Entry() = default;
+ Entry(void (*handler)(), uint16_t select, InterruptType t) {
+ offset_0_15 = reinterpret_cast<uint32_t>(handler) & 0xffff;
+ offset_16_31 = (reinterpret_cast<uint32_t>(handler) >> 16) & 0xffff;
selector = select;
type = t;
- if (offset != 0) {
- e = true;
- }
}
private:
- uint16_t offset_0_15; // 0-15 offset in the segment
- uint16_t selector; // 16-31 selector of the code segment
+ uint16_t offset_0_15 = 0; // 0-15 offset in the segment
+ uint16_t selector = 0; // 16-31 selector of the code segment
[[maybe_unused]] uint8_t null = 0; // 32-39 unused in protected mode
- InterruptType type : 3; // 40-42 type
- [[maybe_unused]] bool d : 1 = true; // 43 true: 32-bit, false: 16-bit segment
- [[maybe_unused]] uint8_t u : 1 = 0; // 44 unused
- [[maybe_unused]] uint8_t dpl : 2 = 0; // 45-46 descriptor privilege level
- [[maybe_unused]] bool e : 1 = false; // 47 enable
- uint16_t offset_16_31; // 48-63 offset high
+ InterruptType type = Null; // 40-43 type
+ uint16_t offset_16_31 = 0; // 48-63 offset high
} __attribute__((packed));
- IDT();
+ IDT(const uint16_t selector);
private:
Entry table[256];
};
-struct interrupt_frame {
- uword_t ip;
- uword_t cs;
- uword_t flags;
- uword_t sp;
- uword_t ss;
-};
-
-/* https://wiki.osdev.org/Interrupt_Service_Routines */
-template <uint8_t irq>
-__attribute__((interrupt)) void kirq(interrupt_frame* frame);
-
-template <>
-void kirq<0x0>(interrupt_frame* frame);
-template <>
-void kirq<0x1>(interrupt_frame* frame);