diff options
| author | Emu <89668582+EmulatedSeasons@users.noreply.github.com> | 2024-05-31 23:38:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-31 23:38:46 -0400 |
| commit | 27a44e0d79d1c6e01cd832feb8ad958d5999b5e3 (patch) | |
| tree | 3759eb02fcad7a609a064080d81b7c6f9dbec4c8 /kernel/arch/x86_64/gdt.cpp | |
| parent | 639240bbf498195912d8ceb6cb396b89391a5b1b (diff) | |
| parent | fd5a1699592ce0afafc42ebf22401596abcdfc28 (diff) | |
Merge pull request #1 from EmulatedSeasons/limineswitch
Limineswitch
Diffstat (limited to 'kernel/arch/x86_64/gdt.cpp')
| -rw-r--r-- | kernel/arch/x86_64/gdt.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/kernel/arch/x86_64/gdt.cpp b/kernel/arch/x86_64/gdt.cpp new file mode 100644 index 0000000..19ec98e --- /dev/null +++ b/kernel/arch/x86_64/gdt.cpp @@ -0,0 +1,34 @@ +#include <stdint.h>
+#include "gdt.h"
+
+void gdt_entry(SegDesc* seg, uint32_t base, uint32_t limit, uint8_t access, uint8_t flags) {
+ // setting each part of the base by masking the part being set and shifting it to the right position
+ seg->base_low = base & 0xFFFF;
+ seg->base_mid = (base & 0xFF0000) >> 16;
+ seg->base_high = (base & 0xFF000000) >> 24;
+
+ seg->limit_low = limit & 0xFFFF;
+ seg->flag_limit_high = (limit & 0xF0000) >> 16;
+
+ // shifts flags to the right position and ors it with limit
+ seg->flag_limit_high |= (flags & 0xF) << 4;
+
+ seg->access = access;
+}
+
+void gdt_tss_entry(TssSegDesc* seg, uint64_t base, uint32_t limit, uint8_t access, uint8_t flags) {
+ // setting each part of the base by masking the part being set and shifting it to the right position
+ seg->base1 = base & 0xFFFF;
+ seg->base2 = (base & 0xFF0000) >> 16;
+ seg->base3 = (base & 0xFF000000) >> 24;
+ seg->base4 = (base & 0xFFFFFFFF00000000) >> 32;
+
+ seg->limit_low = limit & 0xFFFF;
+ seg->flag_limit_high = (limit & 0xF0000) >> 16;
+
+ // shifts flags to the right position and ors it with limit
+ seg->flag_limit_high |= (flags & 0xF) << 4;
+
+ seg->access = access;
+ seg->reserved = 0;
+}
\ No newline at end of file |
