Ok, let me attempt to go in order of the code
First Grub is loading my Kernel (so I won't modify boot sector or stage two)
On load the kernel sets esp to the bottom of the stack, pushes eax and ebx, then calls kmain
kmain checks multiboot flags to make sure it has the information needed.
installs GDT
installs IDT
initializes 8259:
Code:
// Send Initialize Command
_8259_Command_Out(0, INIT);
_8259_Command_Out(1, INIT);
// Map IRQs (0-15) to 0x20-0x2F
_8259_Map(0, 0x20);
_8259_Map(1, 0x28);
// Tell PICs how to talk
_8259_ICW3(0);
_8259_ICW3(1);
// Tell PICs to use 80x86 mode
_8259_ICW4(0);
_8259_ICW4(1);
// Disable All IRQs
_8259_Disable_ALL_IRQ();
_8259_Enable_IRQ(2);
Which breaks down into (if I followed the code correctly):
Code:
outb(0x20, 0x11);
outb(0xA0, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x28);
outb(0x21, 2);
outb(0xA1, 4);
outb(0x21, 1);
outb(0xA1, 1);
outb(0x21, 0);
outb(0xA1, 0);
uint8_t temp = inb(0x21);
temp &= ~(1 << 2);
outb(0x21, temp);
then kmain starts the ints (sti)
from this point everything will work perfectly fine no misfired INTs unless I call outb many-many times.
For testing only at this point is the loop with outb(0xE9, 'a');
NEVER Makes it this far (while loop is in place):
cli or while(true); either way same results.
hlt
I have also tried setting up the PIT before starting interrupts, but if I send ACK to the PIC after handling what it thinks to be the PIT I then run into a Double Fault, which is captured before it hits a Triple Fault. While the actual PIT IRQ works fine, so it seems to me that the software must be triggering INT 0x20.
But again in the disassembled Binary, I don't see a reference to INT 0x20 or address 0x80010.
Also I think I have fixed the register dump code here is the new output (still BS on this INT):
Code:
UNHANDLED INTERRUPT ENCOUNTERED!
INTERRUPT # 32
FATAL ERROR:
EAX = 0x61 EBX = 0x26260 ECX = 0x1F EDX = 0xE9
EDI = 0x26455 ESI = 0x2640D EBP = 0x108FF0 ESP = 0x108FB6
GS = 0x10 FS = 0x10 ES = 0x10 DS = 0x10
EIP = 0x80010 CS = 0x0 EFLAGS = 0x0 SS = 0x0
USER-ESP = 0x610000 ERROR-CODE = 0x0
EIP RAM DUMP (EIP - 10) - (EIP + 10):
0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 [0x0] 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
ESP RAM DUMP (ESP - 10) - (ESP + 10):
0x0 0x0 0x1F 0x0 0x0 0x0 0x61 0x0 0x0 0x0 [0x20] 0x0 0x0 0x0 0x0 0x0 0xC6 0x0 0x10 0x0