2 * AcessOS Microkernel Version
8 #define MAX_CALLBACKS_PER_IRQ 4
12 typedef void (*tIRQ_Callback)(int, void *);
15 void IRQ_Handler(tRegs *Regs);
18 tIRQ_Callback gIRQ_Handlers[16][MAX_CALLBACKS_PER_IRQ];
19 void *gaIRQ_DataPointers[16][MAX_CALLBACKS_PER_IRQ];
23 * \fn void IRQ_Handler(tRegs *Regs)
24 * \brief Handle an IRQ
26 void IRQ_Handler(tRegs *Regs)
28 int irq = Regs->int_num - 0xF0;
31 //Log("IRQ_Handler: (Regs={int_num:%i})", Regs->int_num);
33 for( int i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
35 if( gIRQ_Handlers[irq][i] ) {
36 gIRQ_Handlers[irq][i](irq, gaIRQ_DataPointers[irq][i]);
39 Log("IRQ %i: Call %p", Regs->int_num, gIRQ_Handlers[Regs->int_num][i]);
46 Log_Debug("IRQ", "Unhandled IRQ %i", irq);
49 //Log(" IRQ_Handler: Resetting");
51 outb(0xA0, 0x20); // ACK IRQ (Secondary PIC)
52 outb(0x20, 0x20); // ACK IRQ
53 //Log("IRQ_Handler: RETURN");
57 * \fn int IRQ_AddHandler( int Num, void (*Callback)(int) )
59 int IRQ_AddHandler( int Num, void (*Callback)(int, void*), void *Ptr )
61 for( int i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
63 if( gIRQ_Handlers[Num][i] == NULL )
65 //Log_Log("IRQ", "Added IRQ%i Cb#%i %p", Num, i, Callback);
66 gIRQ_Handlers[Num][i] = Callback;
67 gaIRQ_DataPointers[Num][i] = Ptr;
68 return Num * MAX_CALLBACKS_PER_IRQ + i;
72 Log_Warning("IRQ", "No free callbacks on IRQ%i", Num);
76 void IRQ_RemHandler(int Handle)
78 int Num = Handle / MAX_CALLBACKS_PER_IRQ;
79 int id = Handle % MAX_CALLBACKS_PER_IRQ;
80 gIRQ_Handlers[Num][id] = NULL;