From c6e0d58e177d91f01b6de80073d066bf03de2913 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 9 Feb 2021 17:39:08 +0200 Subject: Add more comments to GDT code --- src/gdt/segmentdescriptor.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/gdt/segmentdescriptor.cc (limited to 'src/gdt') 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; +} -- cgit v1.2.1