feat: Various improvements

This commit is contained in:
Daniel Hammer
2025-04-16 10:32:11 +02:00
parent 35cf3f7c80
commit fcd81be1c5
14 changed files with 135 additions and 98 deletions
+6 -27
View File
@@ -1,5 +1,6 @@
/*
* gdt.hpp
* Intel Global Descriptor Table
* Copyright (c) 2025 Daniel Hammer
*/
@@ -8,50 +9,28 @@
using namespace std;
// __attribute__((packed)) is the GCC extensions way of telling the compiler to ensure that it doesn't mess with these structures or add packing bytes
// for optimization because that would easily result in a triple fault.
namespace Hal {
class GDTEntry {
public:
// Base/Limit are obsolete in Long mode because segmentation is no longer used
// Sadly we must still build and load the GDT during kernel init
uint16_t LimitLow;
uint16_t BaseLow;
uint8_t BaseMiddle;
// Determine which processor rings this segment can be used in
uint8_t AccessByte;
// Lower 4 bits are the higher 4 bits of limit
uint8_t GranularityByte;
uint8_t BaseHigh;
// 16 + 16 + 8 + 8 = 48 bits
uint8_t BaseHigh;
}__attribute__((packed));
struct BasicGDT {
// Conventionally the first entry of the GDT has all values zeroed out.
GDTEntry Null;
// Kernel code segment descriptor
GDTEntry KernelCode;
// Kernel data segment descriptor
GDTEntry KernelData;
// UM code segment descriptor
GDTEntry UserCode;
// UM data segment descriptor
GDTEntry Null;
GDTEntry KernelCode;
GDTEntry KernelData;
GDTEntry UserCode;
GDTEntry UserData;
// Task State Segment
GDTEntry TSS;
}__attribute__((packed));
// Simple structure that tells the CPU the size of the GDT, and it's address
struct GDTPointer {
uint16_t Size;
uint64_t GDTAddress;