+#include <ndk/asm.h>
+#include <../hal/halx86/include/halirq.h>
-#include <internal/i386/segment.h>
+_KiCommonInterrupt:
+ cld
+ pushl %ds
+ pushl %es
+ pushl %fs
+ pushl %gs
+ pushl $0xceafbeef
+ movl $KGDT_R0_DATA,%eax
+ movl %eax,%ds
+ movl %eax,%es
+ movl %eax,%gs
+ movl $KGDT_R0_PCR,%eax
+ movl %eax,%fs
+ pushl %esp
+ pushl %ebx
+ call _KiInterruptDispatch
+ addl $0xC, %esp
+ popl %gs
+ popl %fs
+ popl %es
+ popl %ds
+ popa
+ iret
-.global _irq_handler_0
-_irq_handler_0:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $0
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-.global _irq_handler_1
-_irq_handler_1:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $1
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_2
-_irq_handler_2:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $2
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_3
-_irq_handler_3:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $3
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_4
-_irq_handler_4:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $4
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_5
-_irq_handler_5:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $5
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_6
-_irq_handler_6:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $6
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_7
-_irq_handler_7:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $7
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_8
-_irq_handler_8:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $8
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
+#ifdef CONFIG_SMP
+
+#define BUILD_INTERRUPT_HANDLER(intnum) \
+ .global _KiUnexpectedInterrupt##intnum; \
+ _KiUnexpectedInterrupt##intnum:; \
+ pusha; \
+ movl $0x##intnum, %ebx; \
+ jmp _KiCommonInterrupt;
+
+/* Interrupt handlers and declarations */
+
+#define B(x,y) \
+ BUILD_INTERRUPT_HANDLER(x##y)
+
+#define B16(x) \
+ B(x,0) B(x,1) B(x,2) B(x,3) \
+ B(x,4) B(x,5) B(x,6) B(x,7) \
+ B(x,8) B(x,9) B(x,A) B(x,B) \
+ B(x,C) B(x,D) B(x,E) B(x,F)
+
+B16(3) B16(4) B16(5) B16(6)
+B16(7) B16(8) B16(9) B16(A)
+B16(B) B16(C) B16(D) B16(E)
+B16(F)
+
+#undef B
+#undef B16
+#undef BUILD_INTERRUPT_HANDLER
+
+#else /* CONFIG_SMP */
+
+#define BUILD_INTERRUPT_HANDLER(intnum) \
+ .global _irq_handler_##intnum; \
+ _irq_handler_##intnum:; \
+ pusha; \
+ movl $(##intnum + IRQ_BASE), %ebx; \
+ jmp _KiCommonInterrupt;
+
+/* Interrupt handlers and declarations */
+
+#define B(x) \
+ BUILD_INTERRUPT_HANDLER(x)
+
+B(0) B(1) B(2) B(3)
+B(4) B(5) B(6) B(7)
+B(8) B(9) B(10) B(11)
+B(12) B(13) B(14) B(15)
+
+#undef B
+#undef BUILD_INTERRUPT_HANDLER
+
+#endif /* CONFIG_SMP */
+
+.intel_syntax noprefix
+.globl _KiUnexpectedInterrupt@0
+_KiUnexpectedInterrupt@0:
+
+ /* Bugcheck with invalid interrupt code */
+ push 0x12
+ call _KeBugCheck@4
-.global _irq_handler_9
-_irq_handler_9:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $9
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_10
-_irq_handler_10:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $10
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_11
-_irq_handler_11:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $11
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_12
-_irq_handler_12:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $12
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_13
-_irq_handler_13:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $13
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_14
-_irq_handler_14:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $14
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-
-.global _irq_handler_15
-_irq_handler_15:
- pusha
- pushl %ds
- pushl %es
- pushl %fs
- movl $0xceafbeef,%eax
- pushl %eax
- movw $KERNEL_DS,%ax
- movw %ax,%ds
- movw %ax,%es
- movl $PCR_SELECTOR, %eax
- movl %eax, %fs
- pushl %esp
- pushl $15
- call _KiInterruptDispatch
- popl %eax
- popl %eax
- popl %eax
- popl %fs
- popl %es
- popl %ds
- popa
- iret
-