aboutsummaryrefslogtreecommitdiff
path: root/src/gdt
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-02-09 17:39:08 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-02-09 17:39:08 +0200
commitc6e0d58e177d91f01b6de80073d066bf03de2913 (patch)
treee23139d87da7967e36517fe869b3677e3a4bc9c3 /src/gdt
parentLoading GDT (diff)
downloadkernel.cpp-c6e0d58e177d91f01b6de80073d066bf03de2913.tar.xz
Add more comments to GDT code
Diffstat (limited to 'src/gdt')
-rw-r--r--src/gdt/segmentdescriptor.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/gdt/segmentdescriptor.cc b/src/gdt/segmentdescriptor.cc
new file mode 100644
index 0000000..94205c8
--- /dev/null
+++ b/src/gdt/segmentdescriptor.cc
@@ -0,0 +1,39 @@
+#include "../gdt.h"
+
+GDT::SegmentDescriptor::SegmentDescriptor(uint32_t base, uint32_t limit, GDT::SegmentDescriptor::Access a) : access(a) {
+ // store base
+ base_15_0 = base & 0xffff;
+ base_23_16 = (base >> 16) & 0xff;
+ base_31_24 = (base >> 24) & 0xff;
+
+ // store limit
+ if (limit <= 0xffffu) { // 16-bit address space
+ limit_15_0 = limit & 0xffff;
+ limit_19_16 = 0;
+ } else {
+ db = 1;
+ // limit is uint32_t, which we need to store in limit_19_16 and limit_15_0, a total of 20 bits
+ limit = limit >> 12;
+ limit_15_0 = limit & 0xffff;
+ limit_19_16 = (limit >> 16) & 0xf;
+ }
+
+ granularity = 1;
+}
+
+uint32_t GDT::SegmentDescriptor::base() const {
+ uint32_t base = base_31_24;
+ base = (base << 8) + base_23_16;
+ base = (base << 16) + base_15_0;
+ return base;
+}
+
+uint32_t GDT::SegmentDescriptor::limit() const {
+ uint32_t limit = 0;
+ if (db == 1) {
+ limit = limit_19_16;
+ limit = limit << 16;
+ }
+ limit += limit_15_0;
+ return 0;
+}