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.
Trouble Loading GDT
Trouble Loading GDT
Last edited by horizon on Sat Aug 05, 2017 3:05 pm, edited 3 times in total.
-
- Member
- Posts: 5586
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Trouble Loading GDT
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.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.
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.
- MichaelFarthing
- Member
- Posts: 167
- Joined: Thu Mar 10, 2016 7:35 am
- Location: Lancaster, England, Disunited Kingdom
Re: Trouble Loading GDT
Well the return instruction immediately after setting ss seems a possible problem to me