From 6024b5ac8cc45eee211493018aea1818d458d2ca Mon Sep 17 00:00:00 2001 From: IPlayZed Date: Sun, 20 Feb 2022 16:19:57 +0100 Subject: [PATCH] Moved defines to headeer file. --- src/gdt.cpp | 19 +++++++++++-------- src/gdt.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/gdt.cpp b/src/gdt.cpp index 9c105c0..af73a17 100644 --- a/src/gdt.cpp +++ b/src/gdt.cpp @@ -1,13 +1,5 @@ #include "gdt.h" -#define _64_MEGABYTES 64*1024*1024 -#define CSS_FLAGS 0x9A -#define DSS_FLAGS 0x92 -#define EXPECTED_BYTES_NUM 2 -#define GDT_ADDRESS 0 -#define SEGMENT_INTEGER_HIGH_BYTES 1 -#define HIGH_BYTES_LSHIFT 16 - GlobalDescriptorTable::GlobalDescriptorTable() : nullSegmentSelector(0, 0, 0), unusedSegmentSelector(0, 0, 0), codeSegmentSelector(0, _64_MEGABYTES, CSS_FLAGS), @@ -30,3 +22,14 @@ uint16_t GlobalDescriptorTable::GetDataSegmentSelectorOffset(){ uint16_t GlobalDescriptorTable::GetCodeSegmentSelectorOffset() { return (uint8_t*)&codeSegmentSelector - (uint8_t*)this; } + +GlobalDescriptorTable::SegmentDescriptor::SegmentDescriptor(uint32_t base, uint32_t limit, uint8_t flags) { + uint8_t* targetSegmentDescriptor = (uint8_t*)this; + if (limit <= SMALL_LIMIT_16) { + targetSegmentDescriptor[SEGMENT_DESCRIPTOR_ACCESS] = 0x40; + } + else { + // TODO + } + +} diff --git a/src/gdt.h b/src/gdt.h index c5ebec3..27e6af3 100644 --- a/src/gdt.h +++ b/src/gdt.h @@ -1,6 +1,16 @@ #ifndef __GDT_H #define __GDT_H +#define _64_MEGABYTES 64*1024*1024 +#define CSS_FLAGS 0x9A +#define DSS_FLAGS 0x92 +#define EXPECTED_BYTES_NUM 2 +#define GDT_ADDRESS 0 +#define SEGMENT_INTEGER_HIGH_BYTES 1 +#define HIGH_BYTES_LSHIFT 16 +#define SMALL_LIMIT_16 65536 +#define SEGMENT_DESCRIPTOR_ACCESS 6 + #include "types.h" class GlobalDescriptorTable { public: