summaryrefslogtreecommitdiff
path: root/kernel/cpu/idt.h
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-30 22:12:14 +0100
committerAnton Kling <anton@kling.gg>2023-10-31 00:18:38 +0100
commit8a9208612eec8ddae4c418485d848ecfa0613699 (patch)
tree2f4b29200c2f0c19ae52f45bdb9b38a41b356e30 /kernel/cpu/idt.h
parentca76600acc8bf7a02346efa5bd8f17072210ec01 (diff)
Meta: Move kernel and userland to their own folders.
This is to allow both the kernel and the userland to share certain header files and to make the folder structure a bit more clear.
Diffstat (limited to 'kernel/cpu/idt.h')
-rw-r--r--kernel/cpu/idt.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/kernel/cpu/idt.h b/kernel/cpu/idt.h
new file mode 100644
index 0000000..025ba75
--- /dev/null
+++ b/kernel/cpu/idt.h
@@ -0,0 +1,70 @@
+typedef struct kernel_registers kernel_registers_t;
+typedef struct registers registers_t;
+#ifndef IDT_H
+#define IDT_H
+#include <cpu/gdt.h>
+#include <cpu/io.h>
+#include <log.h>
+#include <stdint.h>
+#include <stdio.h>
+
+/*
+ * the type_attribute in the IDT_Entry struct
+ * is divded like this
+ * 7 0
+ * +---+---+---+---+---+---+---+---+
+ * | P | DPL | S | GateType |
+ * +---+---+---+---+---+---+---+---+
+ * It is 8 bits(1 byte) long
+ *
+ * P
+ * Present bit. Should be zero for unused
+ * interrupts.
+ *
+ * DPL
+ * Specifices the maximum ring(0 to 3) the
+ * interrupt can be called from.
+ *
+ * S
+ * Storage segment. This should be set to
+ * zero for all interrupt and trap gates.
+ *
+ * GateType
+ * Possible IDT gate types:
+ * 0b0101 0x5 5 80386 32 bit task gate
+ * 0b0110 0x6 6 80286 16-bit interrupt gate
+ * 0b0111 0x7 7 80286 16-bit trap gate
+ * 0b1110 0xE 14 80386 32-bit interrupt gate
+ * 0b1111 0xF 15 80386 32-bit trap gate
+ */
+
+// This enables the present bit.
+#define INT_PRESENT 0x80 /* 0b10000000 */
+
+#define INT_32_TASK_GATE(min_privlege) \
+ (INT_PRESENT | 0x05 | (min_privlege << 5))
+#define INT_16_INTERRUPT_GATE(min_privlege) \
+ (INT_PRESENT | 0x06 | (min_privlege << 5))
+#define INT_16_TRAP_GATE(min_privlege) \
+ (INT_PRESENT | 0x07 | (min_privlege << 5))
+#define INT_32_INTERRUPT_GATE(min_privlege) \
+ (INT_PRESENT | 0x0E | (min_privlege << 5))
+#define INT_32_TRAP_GATE(min_privlege) \
+ (INT_PRESENT | 0x0F | (min_privlege << 5))
+
+struct interrupt_frame;
+
+struct registers {
+ uint32_t error_code;
+ uint32_t eip;
+ uint32_t cs;
+ uint32_t eflags;
+ uint32_t esp;
+ uint32_t ss;
+};
+
+void idt_init(void);
+__attribute__((no_caller_saved_registers)) void EOI(unsigned char irq);
+void install_handler(void (*handler_function)(), uint16_t type_attribute,
+ uint8_t entry);
+#endif