Instant general protection fault error code 1816

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
zevvi
Posts: 5
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Instant general protection fault error code 1816

Post by zevvi »

Im was trying to implement keyboard input & interrupts but now i get infinite general protection fault errors and i cant seem to fix it.

code: https://github.com/Zeviraty/AOPOS
sebihepp
Member
Member
Posts: 223
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: Instant general protection fault error code 1816

Post by sebihepp »

In your isr_stubs.asm:

You define isr_stub_table within .text (in the code part of your executable), but only for 32 entries.
Directly afterwards you implement the code for the keyboard isr stub.

If you write data to isr_stub_table[32] you overwrite you keyboard isr stub.
sebihepp
Member
Member
Posts: 223
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: Instant general protection fault error code 1816

Post by sebihepp »

Ignore my last post. There is nothing wrong with the mentioned part. I would try to change the declaration of idt_entry *desc in your idt_set_descriptor function to volatile idt_entry *desc
Maybe the write of the values gets optimized away
Octocontrabass
Member
Member
Posts: 5805
Joined: Mon Mar 25, 2013 7:01 pm

Re: Instant general protection fault error code 1816

Post by Octocontrabass »

zevvi wrote: Wed May 28, 2025 10:04 aminfinite general protection fault errors
Your exception handler needs to halt the CPU instead of returning. You can't return from an exception handler unless you do something to handle the exception!
zevvi
Posts: 5
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: Instant general protection fault error code 1816

Post by zevvi »

Octocontrabass wrote: Wed May 28, 2025 7:48 pm
zevvi wrote: Wed May 28, 2025 10:04 aminfinite general protection fault errors
Your exception handler needs to halt the CPU instead of returning. You can't return from an exception handler unless you do something to handle the exception!
Fixed this one but even after adding volatile to the declaration it still doesnt work and it doesnt look like its getting optimized away? (i updated the code on github)
User avatar
iansjack
Member
Member
Posts: 4779
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Instant general protection fault error code 1816

Post by iansjack »

At the risk of giving the same boring answer as always, have you tried running your code under gdb with appropriate breakpoints/single-stepping? It should then be obvious exactly where the gpf is occurring and the machine state at that time. Then you just have to work out why that causes the gpf - which shouldn't be rocket science.

Debuggers are really useful tools - use them.
zevvi
Posts: 5
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: Instant general protection fault error code 1816

Post by zevvi »

I tried but i dont know what to do if someone could help me or do it for me that would be amazing :D
User avatar
iansjack
Member
Member
Posts: 4779
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Instant general protection fault error code 1816

Post by iansjack »

This wiki article: https://wiki.osdev.org/QEMU#GDB-Stub tells you how to use gdb with qemu. The gdb user manual ( https://sourceware.org/gdb/current/onlinedocs/gdb.html/ ) explains how to use gdb.

It's a very useful tool and it's a good chance to learn it on a simple example. It's far better to learn how to solve your own problems rather than asking others to solve them for you. People here will spoon-feed you the answer, but - IMO - that way you don't learn to think for yourself.
Octocontrabass
Member
Member
Posts: 5805
Joined: Mon Mar 25, 2013 7:01 pm

Re: Instant general protection fault error code 1816

Post by Octocontrabass »

zevvi wrote: Thu May 29, 2025 12:34 amFixed this one
Now that you've fixed the infinite exception loop, are you still seeing the same exception? Does it still have the same error code?
zevvi
Posts: 5
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: Instant general protection fault error code 1816

Post by zevvi »

No now its Exception 13 general protection fault (err code: 258)
Octocontrabass
Member
Member
Posts: 5805
Joined: Mon Mar 25, 2013 7:01 pm

Re: Instant general protection fault error code 1816

Post by Octocontrabass »

That error code indicates a problem with the IDT entry for interrupt 0x20. Did you perhaps leave some IRQs unmasked when you initialized the interrupt controllers? All IRQs should be masked until you're ready to handle them.
zevvi
Posts: 5
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: Instant general protection fault error code 1816

Post by zevvi »

Thanks!!! :D :D :D i fixed it!!!
Post Reply