6 %define NUM_IRQ_CALLBACKS 4
8 MM_LOCALAPIC equ 0xFFFFFD0000000000
52 ; Save to make following instructions smaller
55 ; Set an IDT entry to a callback
58 mov WORD [rdi + %1*16], ax
60 mov WORD [rdi + %1*16 + 6], ax
62 mov DWORD [rdi + %1*16 + 8], eax
64 mov ax, WORD [rdi + %1*16 + 4]
66 mov WORD [rdi + %1*16 + 4], ax
69 ; Install error handlers
102 out dx, al ; Init Command
105 out dx, al ; Offset (Start of IDT Range)
107 out dx, al ; IRQ connected to Slave (00000100b) = IRQ2
109 out dx, al ; Set Mode
111 out dx, al ; Set Mode
115 out dx, al ; Init Command
118 out dx, al ; Offset (Start of IDT Range)
120 out dx, al ; IRQ Line connected to master
122 out dx, al ; Set Mode
124 out dx, al ; Set Mode
137 ; int IRQ_AddHandler(int IRQ, void (*Handler)(int IRQ))
140 ; -1 on an invalid IRQ Number
141 ; -2 when no slots are avaliable
142 [global IRQ_AddHandler]
156 mov rcx, gaIRQ_Handlers
159 ; Find a free callback slot
160 %rep NUM_IRQ_CALLBACKS
166 ; None found, return -2
172 ; Assign the IRQ Callback
192 ISR_NOERRNO 0; 0: Divide By Zero Exception
193 ISR_NOERRNO 1; 1: Debug Exception
194 ISR_NOERRNO 2; 2: Non Maskable Interrupt Exception
195 ISR_NOERRNO 3; 3: Int 3 Exception
196 ISR_NOERRNO 4; 4: INTO Exception
197 ISR_NOERRNO 5; 5: Out of Bounds Exception
198 ISR_NOERRNO 6; 6: Invalid Opcode Exception
199 ISR_NOERRNO 7; 7: Coprocessor Not Available Exception
200 ISR_ERRNO 8; 8: Double Fault Exception (With Error Code!)
201 ISR_NOERRNO 9; 9: Coprocessor Segment Overrun Exception
202 ISR_ERRNO 10; 10: Bad TSS Exception (With Error Code!)
203 ISR_ERRNO 11; 11: Segment Not Present Exception (With Error Code!)
204 ISR_ERRNO 12; 12: Stack Fault Exception (With Error Code!)
205 ISR_ERRNO 13; 13: General Protection Fault Exception (With Error Code!)
206 ISR_ERRNO 14; 14: Page Fault Exception (With Error Code!)
207 ISR_NOERRNO 15; 15: Reserved Exception
208 ISR_NOERRNO 16; 16: Floating Point Exception
209 ISR_NOERRNO 17; 17: Alignment Check Exception
210 ISR_NOERRNO 18; 18: Machine Check Exception
211 ISR_NOERRNO 19; 19: Reserved
212 ISR_NOERRNO 20; 20: Reserved
213 ISR_NOERRNO 21; 21: Reserved
214 ISR_NOERRNO 22; 22: Reserved
215 ISR_NOERRNO 23; 23: Reserved
216 ISR_NOERRNO 24; 24: Reserved
217 ISR_NOERRNO 25; 25: Reserved
218 ISR_NOERRNO 26; 26: Reserved
219 ISR_NOERRNO 27; 27: Reserved
220 ISR_NOERRNO 28; 28: Reserved
221 ISR_NOERRNO 29; 29: Reserved
222 ISR_NOERRNO 30; 30: Reserved
223 ISR_NOERRNO 31; 31: Reserved
225 [extern Error_Handler]
263 mov rbx, [rsp+16*8] ; Calculate address
265 mov rax, gaIRQ_Handlers
268 ; Check all callbacks
270 %rep NUM_IRQ_CALLBACKS
271 ; Get callback address
273 test rax, rax ; Check if it exists
275 ; Set RDI to IRQ number
276 mov rdi, [rsp+16*8] ; Get IRQ number
284 mov rdi, [rsp+16*8] ; Get IRQ number
299 [extern Proc_Scheduler]
300 [global SchedulerIRQ]
302 ; TODO: Find Current CPU
308 mov rdi, MM_LOCALAPIC+0x20
320 ; 64-bit Interrupt Gate, CS = 0x8, IST0 (Disabled)
321 times 256 dd 0x00080000, 0x00000E00, 0, 0
327 times 16*NUM_IRQ_CALLBACKS dq 0