aboutsummaryrefslogtreecommitdiff
path: root/src/gdt.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gdt.cc')
-rw-r--r--src/gdt.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/gdt.cc b/src/gdt.cc
new file mode 100644
index 0000000..202fe77
--- /dev/null
+++ b/src/gdt.cc
@@ -0,0 +1,25 @@
+#include "gdt.h"
+
+GDT::SegmentDescriptor::SegmentDescriptor(uint32_t base, uint32_t limit, uint8_t type) {
+ base_low = base & 0xffff;
+ base_high = (base >> 16) & 0xff;
+ base_vhigh = (base >> 24) & 0xff;
+}
+uint32_t GDT::SegmentDescriptor::base() const {
+ uint32_t base = base_vhigh;
+ base = (base << 8) + base_high;
+ base = (base << 8) + base_low;
+ return base;
+}
+uint32_t GDT::SegmentDescriptor::limit() const {
+ return 0;
+}
+
+GDT::GDT()
+ : segments{{0, 0, 0}, // null segment
+ {0, 64 * 1024 * 1024 /* 64MB */, 0x9a}, // code segment
+ {0, 64 * 1024 * 1024 /* 64MB */, 0x92}} // data segment
+{
+ Pointer gdtr{.limit = sizeof(segments) - 1, .base = reinterpret_cast<uint32_t>(segments)};
+ asm volatile("lgdt %0" : : "p"(gdtr));
+}