General Fault when handling interrupt in long mode

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
passerby
Posts: 5
Joined: Sun Jan 08, 2023 7:22 am

General Fault when handling interrupt in long mode

Post by passerby »

Hello,
I would like some advice on my code about implementing IDT in long mode. It keeps triggering General Protection Fault when execute iretq. I know it triggers GPF because I have messed up with the stack, but I don't know where did I go wrong. Can anyone help me?
Here is my code https://github.com/NeonLightions/susOS.
The asm file when running QEMU with -d in_asm is in qemu.log. I only show the code after I execute 'sti' in there because all of the file would be very long. Need some helps.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: General Fault when handling interrupt in long mode

Post by Octocontrabass »

passerby wrote:The asm file when running QEMU with -d in_asm is in qemu.log.
The log from "-d int" is typically more useful for diagnosing this kind of problem.

My crystal ball says you didn't load your new code segment selector into CS after setting up your GDT, so the interrupt pushes the wrong CS selector on the stack. The fault occurs when IRETQ pops that bad selector.
passerby
Posts: 5
Joined: Sun Jan 08, 2023 7:22 am

Re: General Fault when handling interrupt in long mode

Post by passerby »

Octocontrabass wrote:
passerby wrote:The asm file when running QEMU with -d in_asm is in qemu.log.
The log from "-d int" is typically more useful for diagnosing this kind of problem.

My crystal ball says you didn't load your new code segment selector into CS after setting up your GDT, so the interrupt pushes the wrong CS selector on the stack. The fault occurs when IRETQ pops that bad selector.
Thank you so much, it solved my problem! This is so awkward :oops:
Post Reply