-#define HANDLER(n) .globl handler_##n ;\
+#define PUSH_REGS pushq %rax;
+#define POP_REGS popq %rax;
+
+#define HANDLER_ERRCODE(n, handler) \
+.globl handler_##n ;\
+ handler_##n: ;\
+ cli; \
+ PUSH_REGS \
+ movl 8(%rsp), %edi ;\
+ call handler ;\
+ movq $0xB0, %rdi;\
+ movq $0, %rsi;\
+ call set_APIC_reg_asm; \
+ POP_REGS \
+ sti; \
+ addq 4, %rsp;\
+ iretq
+#define HANDLER_NOERRCODE(n, handler) \
+.globl handler_##n ;\
handler_##n: ;\
- mov $n, %rdi ;\
- call handler_impl ;\
- cli ;\
-1: hlt ;\
- jmp 1b ;\
+ cli; \
+ PUSH_REGS \
+ call handler ;\
+ movq $0xB0, %rdi;\
+ movq $0, %rsi;\
+ call set_APIC_reg_asm; \
+ POP_REGS \
+ sti; \
iretq
-HANDLER(0x00)
-HANDLER(0x01)
-HANDLER(0x02)
-HANDLER(0x03)
-HANDLER(0x04)
-HANDLER(0x05)
-HANDLER(0x06)
-HANDLER(0x07)
-HANDLER(0x08)
-HANDLER(0x09)
-HANDLER(0x0a)
-HANDLER(0x0b)
-HANDLER(0x0c)
-HANDLER(0x0d)
-HANDLER(0x0e)
-HANDLER(0x0f)
-HANDLER(0x10)
-HANDLER(0x11)
-HANDLER(0x12)
-HANDLER(0x13)
-HANDLER(0x14)
-HANDLER(0x15)
-HANDLER(0x16)
-HANDLER(0x17)
-HANDLER(0x18)
-HANDLER(0x19)
-HANDLER(0x1a)
-HANDLER(0x1b)
-HANDLER(0x1c)
-HANDLER(0x1d)
-HANDLER(0x1e)
-HANDLER(0x1f)
+HANDLER_NOERRCODE(0x00, handler_impl_no_code)
+HANDLER_NOERRCODE(0x01, handler_impl_no_code)
+HANDLER_NOERRCODE(0x02, handler_impl_no_code)
+HANDLER_NOERRCODE(0x03, handler_impl_no_code)
+HANDLER_NOERRCODE(0x04, handler_impl_no_code)
+HANDLER_NOERRCODE(0x05, handler_impl_no_code)
+HANDLER_NOERRCODE(0x06, handler_impl_no_code)
+HANDLER_NOERRCODE(0x07, handler_impl_no_code)
+HANDLER_ERRCODE (0x08, handler_impl_code)
+HANDLER_NOERRCODE(0x09, handler_impl_no_code)
+HANDLER_ERRCODE (0x0a, handler_impl_code)
+HANDLER_ERRCODE (0x0b, handler_impl_code)
+HANDLER_ERRCODE (0x0c, handler_impl_code)
+HANDLER_ERRCODE (0x0d, handler_impl_code)
+HANDLER_ERRCODE (0x0e, handler_impl_code)
+HANDLER_NOERRCODE(0x0f, handler_impl_no_code)
+HANDLER_NOERRCODE(0x10, handler_impl_no_code)
+HANDLER_ERRCODE (0x11, handler_impl_code)
+HANDLER_NOERRCODE(0x12, handler_impl_no_code)
+HANDLER_NOERRCODE(0x13, handler_impl_no_code)
+HANDLER_NOERRCODE(0x14, handler_impl_no_code)
+HANDLER_ERRCODE (0x15, handler_impl_code)
+HANDLER_NOERRCODE(0x16, handler_impl_no_code)
+HANDLER_NOERRCODE(0x17, handler_impl_no_code)
+HANDLER_NOERRCODE(0x18, handler_impl_no_code)
+HANDLER_NOERRCODE(0x19, handler_impl_no_code)
+HANDLER_NOERRCODE(0x1a, handler_impl_no_code)
+HANDLER_NOERRCODE(0x1b, handler_impl_no_code)
+HANDLER_NOERRCODE(0x1c, handler_impl_no_code)
+HANDLER_ERRCODE (0x1d, handler_impl_code)
+HANDLER_ERRCODE (0x1e, handler_impl_code)
+HANDLER_NOERRCODE(0x1f, handler_impl_no_code)
os::idt<32> idt;
-extern "C" void handler_impl(std::uint8_t id) {
- os::print("Interrupt #");
- os::print(id);
- os::print(" !\n");
+extern "C" void handler_impl_code(std::uint32_t err_code) {
+ os::println("Interrupt !");
+ os::print("Err code: "); os::print(err_code); os::println(".");
+ while (true) {
+ os::hlt();
+ }
+}
+extern "C" void handler_impl_no_code() {
+ os::println("Interrupt !");
+ os::println("No error code.");
+ while (true) {
+ os::hlt();
+ }
}
extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_start> info) {