7 .handler_highest: resd 1
13 global set_idt_entry:function
16 ; struct idt_entry *entry, rdi
17 ; uintptr_t handler, rsi
18 ; uint16_t selector, rdx
23 mov [rdi + idt_entry.flags], cl
24 mov [rdi + idt_entry.ist], r8b
25 mov [rdi + idt_entry.selector], dx
26 mov [rdi + idt_entry.handler_low], si
28 mov [rdi + idt_entry.handler_high], si
30 mov [rdi + idt_entry.handler_highest], esi
31 mov [rdi + idt_entry.reserved], dword 0x0
33 global load_idt:function
36 ; size_t limit = sizeof(struct idt_entry) * length - 1;
49 extern interrupt_handler
58 jmp interrupt_handler_prepare
64 ; error code pushed by processor
66 jmp interrupt_handler_prepare
74 jmp interrupt_handler_prepare
77 ; create isr 0-7, which need an error code pushed
110 ; make remaining interrupts
117 interrupt_handler_prepare:
136 ; CR2 for page faults, always push for consistent frame
140 mov eax, [qword global_errno]
143 mov rdi, rsp ; context stack frame pointer
144 mov rbx, rsp ; rbx is preserved by the abi, so save it
145 and rsp, 0xFFFFFFF0 ; should be sign extended
146 call interrupt_handler
147 mov rsp, rbx ; restore the stack
149 load_interrupted_registers:
150 ; Restore the previous kernel errno.
152 mov [qword global_errno], eax
154 add rsp, 8 ; remove CR2
159 add rsp, 8 ; skip rsp
173 ; Remove int_no and err_code
177 ;.size interrupt_handler_prepare, . - interrupt_handler_prepare
179 global interrupt_handler_null:function
182 interrupt_handler_null:
184 ;.size interrupt_handler_null, . - interrupt_handler_null
186 rfprintf: db 'rflags : %llx', 10, 0
187 csprintf: db 'cs : %hx', 10, 0
188 ripprintf: db 'rip : %llx', 10, 0
189 rspprintf: db 'rsp : %llx', 10, 0
190 ssprintf: db 'ss : %hx', 10, 0
191 csvprintf: db 'gdt : %016llx', 10, 0
193 global interrupts_enabled:function
201 global enable_interrupts:function
206 global disable_interrupts:function