diff --git a/src/kernel/boot/boot.S b/src/kernel/boot/boot.S index 312a8a7..7818a45 100644 --- a/src/kernel/boot/boot.S +++ b/src/kernel/boot/boot.S @@ -43,7 +43,7 @@ _start: mov cr0, eax //; Load a new GDT - lgdt [V2P(BootGDTp)] + lgdt [V2P(GDTp)] //; and update the code selector by a long jump jmp 0x8:V2P(long_mode_start) @@ -76,7 +76,7 @@ upper_memory: mov cr3, rax //; Reload GDT - movabs rax, offset BootGDTp + movabs rax, offset GDTp lgdt [rax] mov rax, 0x0 mov ss, rax diff --git a/src/kernel/boot/boot_GDT.S b/src/kernel/boot/boot_GDT.S deleted file mode 100644 index 82f8165..0000000 --- a/src/kernel/boot/boot_GDT.S +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -.intel_syntax noprefix - -.section .rodata -.align PAGE_SIZE -.global BootGDT -.global BootGDTp -BootGDT: - .long 0, 0 - .long 0, (GDT_PRESENT | GDT_DPL(0) | GDT_CODE | GDT_LONG) -BootGDTp: - .short 2*8-1 - .quad offset BootGDT diff --git a/src/kernel/cpu/gdt.c b/src/kernel/cpu/gdt.c new file mode 100644 index 0000000..fa2b878 --- /dev/null +++ b/src/kernel/cpu/gdt.c @@ -0,0 +1,28 @@ +#include +#include + +#define GDT_CODE (3<<11) +#define GDT_DPL(lvl) ((lvl)<<13) +#define GDT_PRESENT (1<<15) +#define GDT_LONG (1<<21) + + +struct gdt +{ + uint32_t _; + uint32_t flags; +}__attribute__((packed)); + +struct gdtp +{ + uint16_t len; + struct gdt *gdt; +}__attribute__((packed)); + + +struct gdt BootGDT[] = { + {0, 0}, + {0, GDT_PRESENT | GDT_DPL(0) | GDT_CODE | GDT_LONG} +}; + +struct gdtp GDTp = {2*8-1, BootGDT}; diff --git a/src/kernel/include/gdt.h b/src/kernel/include/gdt.h deleted file mode 100644 index 73b958c..0000000 --- a/src/kernel/include/gdt.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#define GDT_CODE (3<<11) -#define GDT_DPL(lvl) ((lvl)<<13) -#define GDT_PRESENT (1<<15) -#define GDT_LONG (1<<21)