newbieg wrote:
I figure that lgdt might not be discerning enough to detect if my C code is incorrect, so the real problem is likely still in src/gdt.c
Hi, first of all, your gdt struct doesn't seem correct. Second, you haven't cleared interrupts before you call your C code. Third, you don't have to mess with C here, simply store your gdt as data in asm, load it before you jump to C, and forget about it! Here's how I do it:
Code:
cli
cld
lgdt [GDT_value]
jmp CODE_PROT:1f
1: mov ax, DATA_PROT
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, stack_top
call kernel_main
And my gdt table is here:
https://github.com/bztsrc/osz/blob/master/loader/mb-x86_64/bootboot.asm#L1628Here I've precalculated the entries I need, and I don't generate it with code.
I assume this gdt will just work fine for you. The selectors for it:
10h - data segment
20h - selects 16 bit code for unreal or v86 mode
30h - protected mode code segment
40h - protected mode TSS. Not used in my bootloader, but some emulators requires it anyway.
A little homework: my examples are in intel assembly, you'll have to convert them to AT&T syntax.