8 %define NUM_IRQ_CALLBACKS 4
10 MM_LOCALAPIC equ 0xFFFFFD0000000000
54 ; Save to make following instructions smaller
57 ; Set an IDT entry to a callback
60 mov WORD [rdi + %1*16], ax
62 mov WORD [rdi + %1*16 + 6], ax
64 mov DWORD [rdi + %1*16 + 8], eax
66 mov ax, WORD [rdi + %1*16 + 4]
68 mov WORD [rdi + %1*16 + 4], ax
71 ; Install error handlers
83 SETIDT 0xF0, SchedulerIRQ
104 out dx, al ; Init Command
107 out dx, al ; Offset (Start of IDT Range)
109 out dx, al ; IRQ connected to Slave (00000100b) = IRQ2
111 out dx, al ; Set Mode
113 out dx, al ; Set Mode
117 out dx, al ; Init Command
120 out dx, al ; Offset (Start of IDT Range)
122 out dx, al ; IRQ Line connected to master
124 out dx, al ; Set Mode
126 out dx, al ; Set Mode
139 ; int IRQ_AddHandler(int IRQ, void (*Handler)(int IRQ))
142 ; -1 on an invalid IRQ Number
143 ; -2 when no slots are avaliable
144 [global IRQ_AddHandler]
158 mov rcx, gaIRQ_Handlers
161 ; Find a free callback slot
162 %rep NUM_IRQ_CALLBACKS
168 ; None found, return -2
174 ; Assign the IRQ Callback
176 ; A little bit of debug
181 mov rcx, rdi ; IRQ Number
182 mov rdx, rsi ; Callback
183 mov rsi, rax ; Pointer
184 mov rdi, csIRQ_Assigned
199 db "IRQ %p := %p (IRQ %i)",0
214 ISR_NOERRNO 0; 0: Divide By Zero Exception
215 ISR_NOERRNO 1; 1: Debug Exception
216 ISR_NOERRNO 2; 2: Non Maskable Interrupt Exception
217 ISR_NOERRNO 3; 3: Int 3 Exception
218 ISR_NOERRNO 4; 4: INTO Exception
219 ISR_NOERRNO 5; 5: Out of Bounds Exception
220 ISR_NOERRNO 6; 6: Invalid Opcode Exception
221 ISR_NOERRNO 7; 7: Coprocessor Not Available Exception
222 ISR_ERRNO 8; 8: Double Fault Exception (With Error Code!)
223 ISR_NOERRNO 9; 9: Coprocessor Segment Overrun Exception
224 ISR_ERRNO 10; 10: Bad TSS Exception (With Error Code!)
225 ISR_ERRNO 11; 11: Segment Not Present Exception (With Error Code!)
226 ISR_ERRNO 12; 12: Stack Fault Exception (With Error Code!)
227 ISR_ERRNO 13; 13: General Protection Fault Exception (With Error Code!)
228 ISR_ERRNO 14; 14: Page Fault Exception (With Error Code!)
229 ISR_NOERRNO 15; 15: Reserved Exception
230 ISR_NOERRNO 16; 16: Floating Point Exception
231 ISR_NOERRNO 17; 17: Alignment Check Exception
232 ISR_NOERRNO 18; 18: Machine Check Exception
233 ISR_NOERRNO 19; 19: Reserved
234 ISR_NOERRNO 20; 20: Reserved
235 ISR_NOERRNO 21; 21: Reserved
236 ISR_NOERRNO 22; 22: Reserved
237 ISR_NOERRNO 23; 23: Reserved
238 ISR_NOERRNO 24; 24: Reserved
239 ISR_NOERRNO 25; 25: Reserved
240 ISR_NOERRNO 26; 26: Reserved
241 ISR_NOERRNO 27; 27: Reserved
242 ISR_NOERRNO 28; 28: Reserved
243 ISR_NOERRNO 29; 29: Reserved
244 ISR_NOERRNO 30; 30: Reserved
245 ISR_NOERRNO 31; 31: Reserved
247 [extern Error_Handler]
285 mov rbx, [rsp+16*8] ; Calculate address
287 mov rax, gaIRQ_Handlers
290 ; Check all callbacks
292 %rep NUM_IRQ_CALLBACKS
293 ; Get callback address
295 test rax, rax ; Check if it exists
297 ; Set RDI to IRQ number
298 mov rdi, [rsp+16*8] ; Get IRQ number
306 mov rdi, [rsp+16*8] ; Get IRQ number
321 [extern Proc_Scheduler]
322 [global SchedulerIRQ]
328 ; Save Thread Pointer
337 ; Restore Thread Pointer
341 ; Send EOI (To either the APIC or the PIC)
348 out 0x20, al ; ACK IRQ
353 mov eax, DWORD [gpMP_LocalAPIC]
354 mov DWORD [eax+0x0B0], 0
365 ; 64-bit Interrupt Gate, CS = 0x8, IST0 (Disabled)
366 times 256 dd 0x00080000, 0x00000E00, 0, 0
372 times 16*NUM_IRQ_CALLBACKS dq 0