Hi, I'm trying to make a kernel using UEFI and I'm trying to load a GDT. However, when I call my loading function, my kernel will start, and then restart after a few seconds. All of the following happens after I call ExitBootServices in my bootloader. I do not have paging or anything like that enabled, I have only acquired the memory map so far. Can anyone help out? Im using QEMU to run the kernel.
Code:
load_gdt:
lgdt [rdi]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
pop rdi
mov rax, 0x08
push rax
push rdi
retfq
typedef struct _gdt_desc {
uint16_t limit;
uint64_t offset;
} __attribute__((packed)) GDT_DESCRIPTOR;
typedef struct _gdt_entry {
uint16_t limit0;
uint16_t base0;
uint8_t base1;
uint8_t access_byte;
uint8_t limit1_flags;
uint8_t base2;
} __attribute__((packed)) GDT_ENTRY;
typedef struct _gdt {
GDT_ENTRY null;
GDT_ENTRY kernel_code;
GDT_ENTRY kernel_data;
GDT_ENTRY user_null;
GDT_ENTRY user_code;
GDT_ENTRY user_data;
} __attribute__((packed)) __attribute__((aligned(0x1000))) GDT;
__attribute__((aligned(0x1000)))
GDT default_gdt = {
{0, 0, 0, 0x00, 0x00, 0},
{0, 0, 0, 0x9a, 0xa0, 0},
{0, 0, 0, 0x92, 0xa0, 0},
{0, 0, 0, 0x00, 0x00, 0},
{0, 0, 0, 0x9a, 0xa0, 0},
{0, 0, 0, 0x92, 0xa0, 0},
};
extern void load_gdt(GDT_DESCRIPTOR* gdt_descriptor);
And in my kernel main function:
Code:
GDT_DESCRIPTOR gdt_desc;
gdt_desc.limit = sizeof(GDT) - 1;
gdt_desc.offset = (uint64_t)&default_gdt;
load_gdt(&gdt_desc);
I have also tried to disable interrupts before calling load_gdt with
Code:
asm("cli");
but that didn't help. I paused QEMU once my kernel loaded and took a screenshot of QEMU's 'info registers' output, here is what it looks like
Can anyone help me figure this out? Thanks.