:: commit 848d53e1473e5917102ea402695e6ac3bbb04f97

mintsuki <mintsuki@protonmail.com> — 2021-11-25 20:51

parents: 9c6ea6b2b3

gdt: Allocate GDT on the heap on UEFI

diff --git a/stage23/entry.s3.c b/stage23/entry.s3.c
index f44e3bff..51c0aa77 100644
--- a/stage23/entry.s3.c
+++ b/stage23/entry.s3.c
@@ -8,6 +8,7 @@
 #include <sys/e820.h>
 #include <sys/a20.h>
 #include <sys/idt.h>
+#include <sys/gdt.h>
 #include <lib/print.h>
 #include <fs/file.h>
 #include <lib/elf.h>
@@ -67,6 +68,8 @@ void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
 
     init_memmap();
 
+    init_gdt();
+
     disk_create_index();
 
     boot_volume = NULL;
diff --git a/stage23/sys/gdt.h b/stage23/sys/gdt.h
index 06b1f9e7..1c93687e 100644
--- a/stage23/sys/gdt.h
+++ b/stage23/sys/gdt.h
@@ -24,4 +24,6 @@ struct gdt_desc {
 
 extern struct gdtr gdt;
 
+void init_gdt(void);
+
 #endif
diff --git a/stage23/sys/gdt.s2.c b/stage23/sys/gdt.s2.c
index e28aeece..64d8bf3e 100644
--- a/stage23/sys/gdt.s2.c
+++ b/stage23/sys/gdt.s2.c
@@ -1,5 +1,7 @@
 #include <stdint.h>
 #include <sys/gdt.h>
+#include <mm/pmm.h>
+#include <lib/libc.h>
 
 static struct gdt_desc gdt_descs[] = {
     {0},
@@ -69,3 +71,11 @@ struct gdtr gdt = {
     0
 #endif
 };
+
+#if uefi == 1
+void init_gdt(void) {
+    struct gdt_desc *gdt_copy = ext_mem_alloc(sizeof(gdt_descs));
+    memcpy(gdt_copy, gdt_descs, sizeof(gdt_descs));
+    gdt.ptr = (uintptr_t)gdt_copy;
+}
+#endif
tab: 248 wrap: offon