6 %define NUM_IRQ_CALLBACKS 4
8 MM_LOCALAPIC equ 0xFFFFFD0000000000
56 ; Save to make following instructions smaller
59 ; Set an IDT entry to a callback
62 mov WORD [rdi + %1*16], ax
64 mov WORD [rdi + %1*16+6], ax
66 mov DWORD [rdi+%1*16+8], eax
68 mov ax, WORD [rdi + %1*16 + 4]
70 mov WORD [rdi + %1*16 + 4], ax
73 ; Install error handlers
99 ; int IRQ_AddHandler(int IRQ, void (*Handler)(int IRQ))
102 ; -1 on an invalid IRQ Number
103 ; -2 when no slots are avaliable
104 [global IRQ_AddHandler]
118 mov rcx, gaIRQ_Handlers
121 ; Find a free callback slot
122 %rep NUM_IRQ_CALLBACKS
128 ; None found, return -2
134 ; Assign the IRQ Callback
154 ISR_NOERRNO 0; 0: Divide By Zero Exception
155 ISR_NOERRNO 1; 1: Debug Exception
156 ISR_NOERRNO 2; 2: Non Maskable Interrupt Exception
157 ISR_NOERRNO 3; 3: Int 3 Exception
158 ISR_NOERRNO 4; 4: INTO Exception
159 ISR_NOERRNO 5; 5: Out of Bounds Exception
160 ISR_NOERRNO 6; 6: Invalid Opcode Exception
161 ISR_NOERRNO 7; 7: Coprocessor Not Available Exception
162 ISR_ERRNO 8; 8: Double Fault Exception (With Error Code!)
163 ISR_NOERRNO 9; 9: Coprocessor Segment Overrun Exception
164 ISR_ERRNO 10; 10: Bad TSS Exception (With Error Code!)
165 ISR_ERRNO 11; 11: Segment Not Present Exception (With Error Code!)
166 ISR_ERRNO 12; 12: Stack Fault Exception (With Error Code!)
167 ISR_ERRNO 13; 13: General Protection Fault Exception (With Error Code!)
168 ISR_ERRNO 14; 14: Page Fault Exception (With Error Code!)
169 ISR_NOERRNO 15; 15: Reserved Exception
170 ISR_NOERRNO 16; 16: Floating Point Exception
171 ISR_NOERRNO 17; 17: Alignment Check Exception
172 ISR_NOERRNO 18; 18: Machine Check Exception
173 ISR_NOERRNO 19; 19: Reserved
174 ISR_NOERRNO 20; 20: Reserved
175 ISR_NOERRNO 21; 21: Reserved
176 ISR_NOERRNO 22; 22: Reserved
177 ISR_NOERRNO 23; 23: Reserved
178 ISR_NOERRNO 24; 24: Reserved
179 ISR_NOERRNO 25; 25: Reserved
180 ISR_NOERRNO 26; 26: Reserved
181 ISR_NOERRNO 27; 27: Reserved
182 ISR_NOERRNO 28; 28: Reserved
183 ISR_NOERRNO 29; 29: Reserved
184 ISR_NOERRNO 30; 30: Reserved
185 ISR_NOERRNO 31; 31: Reserved
207 mov rbx, [rsp+16*8] ; Calculate address
209 mov rax, gaIRQ_Handlers
213 %rep NUM_IRQ_CALLBACKS
216 mov rdi, [rsp+16*8] ; Get IRQ number
218 call rax ; 2 Bytes (Op and Mod/RM)
224 mov rdi, [rsp+16*8] ; Get IRQ number
238 [extern Proc_Scheduler]
240 ; TODO: Find Current CPU
246 mov rdi, MM_LOCALAPIC+0x20
257 times 256 dd 0x00080000, 0x00008E00, 0, 0 ; 64-bit Interrupt Gate, CS = 0x8, IST0
263 times 16*NUM_IRQ_CALLBACKS dq 0