aboutsummaryrefslogtreecommitdiff
path: root/src/utils/gdt.h
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-04-05 14:46:31 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-04-05 14:46:31 +0200
commitba7e57138c9e41cf944afb91c146fea23713c1d1 (patch)
tree3a57bd313ee7a7fd8535286e3364ef47bb7aa705 /src/utils/gdt.h
parentb54b87ad2d41e60e9be1e299140dbf59e76c8fc6 (diff)
Reload GDT
Diffstat (limited to 'src/utils/gdt.h')
-rw-r--r--src/utils/gdt.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/utils/gdt.h b/src/utils/gdt.h
new file mode 100644
index 0000000..85a75aa
--- /dev/null
+++ b/src/utils/gdt.h
@@ -0,0 +1,44 @@
+#ifndef GDT_H
+#define GDT_H
+
+#include "types.h"
+
+// Access byte
+#define GDT_AC 1 // Access bit
+#define GDT_RW 1 << 1 // Read/Write bit
+#define GDT_DC 1 << 2 // Direction bit/Conforming bit
+#define GDT_EXEC 1 << 3 // Executable bit
+#define GDT_S 1 << 4 // Descriptor type
+#define GDT_PRVL_0 0 // Privilege (from 0 to 3)
+#define GDT_PRVL_1 1 << 5
+#define GDT_PRVL_2 2 << 5
+#define GDT_PRVL_3 3 << 5
+#define GDT_PR 1 << 7 // Present Bit
+
+// Flags
+#define GDT_SZ 1 << 2 // Size bit
+#define GDT_GR 1 << 3 // Granularity bit
+
+typedef struct GDT_ENTRY {
+ u32 base;
+ u32 limit;
+ u8 flags;
+ u8 access;
+} GDT_ENTRY;
+
+struct GDT_REGISTER {
+ u16 limit;
+ u32 base;
+} __attribute__((packed));
+
+/**
+ * Copy GDT in memory
+ */
+void gdt_memcpy();
+
+/**
+ * Write a GDT entry at address addr
+ */
+void gdt_write_entry(GDT_ENTRY entry, u32 addr);
+
+#endif