PIC Remap on IRQ gives Double Fault
Posted: Sat Oct 24, 2009 11:49 pm
I dont know why this keeps on failing... I tried the sample on linux using nasm and gcc and worked fine, but most of my code uses Masm and VC++. I can handle the IDT Exceptions but when I try to set up IRQ I get an error. Here is the code..
For some reason I get a Double Fault Error when ever I uncomment __asm { sti }, If I comment it, I get no errors but also no effect .. I test it by setting up a timer
Code: Select all
; Assembly.asm-------------------------------------------------------
?Irq0@@YIXXZ proc
push 32
jmp ?IrqCaptured@@YIXXZ
?Irq0@@YIXXZ endp
extrn ?ProcessIRQ@@YIXKPAU_BL_TRAP_CONTEXT@@@Z:near
align 16
?IrqCaptured@@YIXXZ proc
pusha
push eax
push ebx
push ecx
push edx
push esi
push edi
push ebp
mov eax, esp
add eax, 48
push eax
mov eax, cr2
push eax
mov edx, esp
call ?ProcessIRQ@@YIXKPAU_IRQ_CONTEXT@@@Z
pop eax
pop ebp
pop edi
pop esi
pop edx
pop ecx
pop ebx
popa
iret
?IrqCaptured@@YIXXZ endp
// Irq.cpp --------------------------------------------------------------------------
extern void Irq0();
void *irq_routines[16] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
void InitializeIrq()
{
outportb(0x20, 0x11);
outportb(0xA0, 0x11);
outportb(0x21, 0x20);
outportb(0xA1, 0x28);
outportb(0x21, 0x04);
outportb(0xA1, 0x02);
outportb(0x21, 0x01);
outportb(0xA1, 0x01);
outportb(0x21, 0x0);
outportb(0xA1, 0x0);
SetGate(32, (unsigned)Irq0, 0x08, 0x8E);
__asm { sti }
}
void ProcessIRQ(ULONG_PTR Trap, PIRQ_CONTEXT Context)
{
void (*handler)(PIRQ_CONTEXT Context);
handler = (void(*)(PIRQ_CONTEXT))irq_routines[Context->Val-32];
if (handler)
{
handler(Context);
}
if (Context->Val >= 40)
{
outportb(0xA0, 0x20);
}
outportb(0x20, 0x20);
}