Kernel/armv7 - Added IRQ stack, changed IRQs to be disabled until after handling
[tpg/acess2.git] / Kernel / arch / x86 / irq.c
1 /*
2  * AcessOS Microkernel Version
3  * irq.c
4  */
5 #include <acess.h>
6
7 // === CONSTANTS ===
8 #define MAX_CALLBACKS_PER_IRQ   4
9 #define TRACE_IRQS      0
10
11 // === TYPES ===
12 typedef void (*tIRQ_Callback)(int, void *);
13
14 // === PROTOTYPES ===
15 void    IRQ_Handler(tRegs *Regs);
16
17 // === GLOBALS ===
18 tIRQ_Callback   gIRQ_Handlers[16][MAX_CALLBACKS_PER_IRQ];
19 void    *gaIRQ_DataPointers[16][MAX_CALLBACKS_PER_IRQ];
20
21 // === CODE ===
22 /**
23  * \fn void IRQ_Handler(tRegs *Regs)
24  * \brief Handle an IRQ
25  */
26 void IRQ_Handler(tRegs *Regs)
27 {
28          int    i, irq = Regs->int_num - 0xF0;
29
30         //Log("IRQ_Handler: (Regs={int_num:%i})", Regs->int_num);
31
32         for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
33         {
34                 if( gIRQ_Handlers[irq][i] ) {
35                         gIRQ_Handlers[irq][i](irq, gaIRQ_DataPointers[irq][i]);
36                         #if TRACE_IRQS
37                         if( irq != 8 )
38                                 Log("IRQ %i: Call %p", Regs->int_num, gIRQ_Handlers[Regs->int_num][i]);
39                         #endif
40                 }
41         }
42
43         //Log(" IRQ_Handler: Resetting");
44         if(irq >= 8)
45                 outb(0xA0, 0x20);       // ACK IRQ (Secondary PIC)
46         outb(0x20, 0x20);       // ACK IRQ
47         //Log("IRQ_Handler: RETURN");
48 }
49
50 /**
51  * \fn int IRQ_AddHandler( int Num, void (*Callback)(int) )
52  */
53 int IRQ_AddHandler( int Num, void (*Callback)(int, void*), void *Ptr )
54 {
55          int    i;
56         for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
57         {
58                 if( gIRQ_Handlers[Num][i] == NULL ) {
59                         Log_Log("IRQ", "Added IRQ%i Cb#%i %p", Num, i, Callback);
60                         gIRQ_Handlers[Num][i] = Callback;
61                         gaIRQ_DataPointers[Num][i] = Ptr;
62                         return 1;
63                 }
64         }
65
66         Log_Warning("IRQ", "No free callbacks on IRQ%i", Num);
67         return 0;
68 }

UCC git Repository :: git.ucc.asn.au