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);
}