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
95 out dx, al ; Init Command
98 out dx, al ; Offset (Start of IDT Range)
100 out dx, al ; IRQ connected to Slave (00000100b) = IRQ2
102 out dx, al ; Set Mode
104 out dx, al ; Set Mode
108 out dx, al ; Init Command
111 out dx, al ; Offset (Start of IDT Range)
113 out dx, al ; IRQ Line connected to master
115 out dx, al ; Set Mode
117 out dx, al ; Set Mode
130 ; int IRQ_AddHandler(int IRQ, void (*Handler)(int IRQ))
133 ; -1 on an invalid IRQ Number
134 ; -2 when no slots are avaliable
135 [global IRQ_AddHandler]
149 mov rcx, gaIRQ_Handlers
152 ; Find a free callback slot
153 %rep NUM_IRQ_CALLBACKS
159 ; None found, return -2
165 ; Assign the IRQ Callback
185 ISR_NOERRNO 0; 0: Divide By Zero Exception
186 ISR_NOERRNO 1; 1: Debug Exception
187 ISR_NOERRNO 2; 2: Non Maskable Interrupt Exception
188 ISR_NOERRNO 3; 3: Int 3 Exception
189 ISR_NOERRNO 4; 4: INTO Exception
190 ISR_NOERRNO 5; 5: Out of Bounds Exception
191 ISR_NOERRNO 6; 6: Invalid Opcode Exception
192 ISR_NOERRNO 7; 7: Coprocessor Not Available Exception
193 ISR_ERRNO 8; 8: Double Fault Exception (With Error Code!)
194 ISR_NOERRNO 9; 9: Coprocessor Segment Overrun Exception
195 ISR_ERRNO 10; 10: Bad TSS Exception (With Error Code!)
196 ISR_ERRNO 11; 11: Segment Not Present Exception (With Error Code!)
197 ISR_ERRNO 12; 12: Stack Fault Exception (With Error Code!)
198 ISR_ERRNO 13; 13: General Protection Fault Exception (With Error Code!)
199 ISR_ERRNO 14; 14: Page Fault Exception (With Error Code!)
200 ISR_NOERRNO 15; 15: Reserved Exception
201 ISR_NOERRNO 16; 16: Floating Point Exception
202 ISR_NOERRNO 17; 17: Alignment Check Exception
203 ISR_NOERRNO 18; 18: Machine Check Exception
204 ISR_NOERRNO 19; 19: Reserved
205 ISR_NOERRNO 20; 20: Reserved
206 ISR_NOERRNO 21; 21: Reserved
207 ISR_NOERRNO 22; 22: Reserved
208 ISR_NOERRNO 23; 23: Reserved
209 ISR_NOERRNO 24; 24: Reserved
210 ISR_NOERRNO 25; 25: Reserved
211 ISR_NOERRNO 26; 26: Reserved
212 ISR_NOERRNO 27; 27: Reserved
213 ISR_NOERRNO 28; 28: Reserved
214 ISR_NOERRNO 29; 29: Reserved
215 ISR_NOERRNO 30; 30: Reserved
216 ISR_NOERRNO 31; 31: Reserved
218 [extern Error_Handler]
254 mov rbx, [rsp+16*8] ; Calculate address
256 mov rax, gaIRQ_Handlers
260 %rep NUM_IRQ_CALLBACKS
263 mov rdi, [rsp+16*8] ; Get IRQ number
265 call rax ; 2 Bytes (Op and Mod/RM)
271 mov rdi, [rsp+16*8] ; Get IRQ number
285 [extern Proc_Scheduler]
287 ; TODO: Find Current CPU
293 mov rdi, MM_LOCALAPIC+0x20
304 times 256 dd 0x00080000, 0x00000E00, 0, 0 ; 64-bit Interrupt Gate, CS = 0x8, IST0
310 times 16*NUM_IRQ_CALLBACKS dq 0