Loading GDT in x86_64 always faults
Posted: Thu Jan 12, 2023 11:47 am
I try to implement a simple OS kernel but just can't get around a nasty bug which mostly triple faults or causes other non-wanted behaviour. In 32 bit w/GRUB it was no problems, the first attempt worked. But on x86_64 (Limine) I can't get it to work. I even simplified the code to the max by copying & pasteing code out of a functioning project but still an error. What I do have now is the following:
The call to loadGDT() doesn't triple fault as it did before but it stops the other code from working, notably not running any calls from after loadGDT(). What did I do wrong? I am near to discard long mode and to go with 32 bit for now but it sucks, I want the solution to this bug! I don't use any optimization in the compilation. Other code in my project is flawless as it's just the limine barebone.
I tried to run the code in QEmu with -d int but this doesn't seem to work on limine, it just hangs in an endless loop of output.
Many thanks in advance.
Code: Select all
.section .rodata
.align 16
GDT64: # Global Descriptor Table (64-bit).
#.equ Null, $ - $GDT64 # The null descriptor.
.short 0 # Limit (low).
.short 0 # Base (low).
.byte 0 # Base (middle)
.byte 0 # Access.
.byte 0 # Granularity.
.byte 0 # Base (high).
#.equ Code, $ - $GDT64 # The code descriptor.
.short 0xFFFF # Limit (low).
.short 0 # Base (low).
.byte 0 # Base (middle)
.byte 0b10011010 # Access (exec/read).
.byte 0b10101111 # Granularity.
.byte 0 # Base (high).
#.equ Data, $ - $GDT64 # The data descriptor.
.short 0 # Limit (low).
.short 0 # Base (low).
.byte 0 # Base (middle)
.byte 0b10010010 # Access (read/write).
.byte 0b00000000 # Granularity.
.byte 0 # Base (high).
GDTPointer: # The GDT-pointer.
.short (GDTPointer - GDT64 - 1) # Limit.
.quad GDT64 # Base.
.section .text
.code64
.global loadGDT
loadGDT:
lgdt GDTPointer
push $0x0008
push $.afterLoad
retfq
.afterLoad:
mov $0x0010, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
ret
I tried to run the code in QEmu with -d int but this doesn't seem to work on limine, it just hangs in an endless loop of output.
Many thanks in advance.