[Solved] Interrupt handler bug?
Posted: Wed Nov 07, 2018 4:30 am
Hi!
I'm writing a kernel for amd64 long mode. So far only doing the basic bootstrapping (interrupts, apic, page tables etc).
I've started to see a problem though - I sometimes get strange page faults and trigger "impossible" assertions in my logic, maybe every 5th time I run through my kernel code (I'm using Bochs). Most of the time, everything seems to run exactly as I'd expect. I think I've isolated it down to the following:
- I only get the errors when compiling with -O0, never with -O2.
- I only get the errors when I'm running with interrupts enabled, never with interrupts disabled.
So my main suspicion is that I have some kind of memory/register corruption going on, that depends on the timing of how my interrupt handling runs relative to the rest of my code.
The thing is, no matter how much I've stared at my interrupt code or compared it to other sources online, I can't find anything that seems wrong. So that's why I'm hoping someone here has more wisdom and can tell if I'm doing something that would cause issues.
Oh, and the only interrupt that seems to be triggered (in both the normal case and when I get my assertions) is INT32, which would be the IRQ 0 timer interrupt, so no strange stuff going on there.
Attaching the relevant parts of my isr setup, in asm and C++.
I'm writing a kernel for amd64 long mode. So far only doing the basic bootstrapping (interrupts, apic, page tables etc).
I've started to see a problem though - I sometimes get strange page faults and trigger "impossible" assertions in my logic, maybe every 5th time I run through my kernel code (I'm using Bochs). Most of the time, everything seems to run exactly as I'd expect. I think I've isolated it down to the following:
- I only get the errors when compiling with -O0, never with -O2.
- I only get the errors when I'm running with interrupts enabled, never with interrupts disabled.
So my main suspicion is that I have some kind of memory/register corruption going on, that depends on the timing of how my interrupt handling runs relative to the rest of my code.
The thing is, no matter how much I've stared at my interrupt code or compared it to other sources online, I can't find anything that seems wrong. So that's why I'm hoping someone here has more wisdom and can tell if I'm doing something that would cause issues.
Oh, and the only interrupt that seems to be triggered (in both the normal case and when I get my assertions) is INT32, which would be the IRQ 0 timer interrupt, so no strange stuff going on there.
Attaching the relevant parts of my isr setup, in asm and C++.