Page 1 of 1

Instant general protection fault error code 1816

Posted: Wed May 28, 2025 10:04 am
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

Re: Instant general protection fault error code 1816

Posted: Wed May 28, 2025 12:34 pm
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.

Re: Instant general protection fault error code 1816

Posted: Wed May 28, 2025 5:37 pm
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

Re: Instant general protection fault error code 1816

Posted: Wed May 28, 2025 7:48 pm
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!

Re: Instant general protection fault error code 1816

Posted: Thu May 29, 2025 12:34 am
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)

Re: Instant general protection fault error code 1816

Posted: Thu May 29, 2025 3:13 am
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.

Re: Instant general protection fault error code 1816

Posted: Thu May 29, 2025 7:04 am
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

Re: Instant general protection fault error code 1816

Posted: Thu May 29, 2025 8:55 am
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.

Re: Instant general protection fault error code 1816

Posted: Thu May 29, 2025 7:57 pm
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?

Re: Instant general protection fault error code 1816

Posted: Fri May 30, 2025 10:19 am
by zevvi
No now its Exception 13 general protection fault (err code: 258)

Re: Instant general protection fault error code 1816

Posted: Fri May 30, 2025 11:45 am
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.

Re: Instant general protection fault error code 1816

Posted: Fri May 30, 2025 2:33 pm
by zevvi
Thanks!!! :D :D :D i fixed it!!!