about summary refs log tree commit diff
path: root/src/pOS/include/kernel/interrupts/gdt.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pOS/include/kernel/interrupts/gdt.h')
-rw-r--r--src/pOS/include/kernel/interrupts/gdt.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pOS/include/kernel/interrupts/gdt.h b/src/pOS/include/kernel/interrupts/gdt.h
new file mode 100644
index 0000000..74a6e88
--- /dev/null
+++ b/src/pOS/include/kernel/interrupts/gdt.h
@@ -0,0 +1,37 @@
+#ifndef _GDT_H_
+#define _GDT_H_
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#define GDT_NUM_DESCRIPTORS 8
+
+typedef struct gdt_entry
+{
+    uint16_t limit_low;
+    uint16_t base_low;
+    uint8_t  base_middle;
+    uint8_t  access;
+    uint8_t  granularity;
+    uint8_t  base_high;
+} __attribute__((packed)) gdt_entry_t;
+
+typedef struct gdt_ptr
+{
+    uint16_t limit;
+    uint32_t base;
+} __attribute__((packed)) gdt_ptr_t;
+
+/* ASM func */
+extern "C" void gdt_flush(uint32_t gdt_ptr);
+
+class GDT
+{
+public:
+    static int init(void);
+    static int set_entry(int index, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran);
+private:
+    static gdt_entry_t gdt_entries[GDT_NUM_DESCRIPTORS];
+};
+
+#endif