Trouble Loading GDT

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
horizon
Posts: 3
Joined: Sat Aug 05, 2017 12:23 pm

Trouble Loading GDT

Post 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.
Last edited by horizon on Sat Aug 05, 2017 3:05 pm, edited 3 times in total.
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: Trouble Loading GDT

Post 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.
User avatar
MichaelFarthing
Member
Member
Posts: 167
Joined: Thu Mar 10, 2016 7:35 am
Location: Lancaster, England, Disunited Kingdom

Re: Trouble Loading GDT

Post by MichaelFarthing »

Well the return instruction immediately after setting ss seems a possible problem to me :shock:
Post Reply