Page 1 of 1

Trouble Loading GDT

Posted: Sat Aug 05, 2017 12:30 pm
by horizon
I've been working through creating a simple kernel and I'm loading my GDT now. I used GRUB as my bootloader.

My goal is to setup a flat memory model. However, I am having quite some trouble getting it to load. I am using QEMU and it is triple faulting.


I load the GDT from my kernel by calling the gdt_init() function.

I've discovered the problem lies with instruction in load_gdt(). Everything up to that point "works." I suspect this might be due to an error in setting up my GDT, but I'm not sure where I went wrong.

RESOLVED: The issue was me failing to pass the gdt pointer correctly on the stack when loading it.

Re: Trouble Loading GDT

Posted: Sat Aug 05, 2017 12:55 pm
by Octocontrabass
horizon wrote:I suspect this might be due to an error in setting up my GDT, but I'm not sure where I went wrong.
Have you tried using a debugger? The problem you have now is most likely something simple, so it would be great practice. Popular choices include Bochs with its built-in debugger, and qemu with gdb. For this particular issue, I'd start by examining the contents of the GDT right after lgdt.

You might also be able to get some hints from the logs of your emulator or VM. In particular, look for the location and type of fault to narrow down the possibilities.

Unfortunately, I haven't spotted the bug with a quick look at your code.

Re: Trouble Loading GDT

Posted: Sat Aug 05, 2017 2:12 pm
by MichaelFarthing
Well the return instruction immediately after setting ss seems a possible problem to me :shock: