2 extern exceptionHandler
3 extern interruptHandler
9 pushad ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
10 mov ax, ds ; Lower 16-bits of eax = ds.
11 push eax ; save the data segment descriptor
12 mov ax, 0x10 ; kernel data segment descriptor
17 push esp ; Push struct registers *r
18 ; 2. Clear the direction flag (eflags) & call C handler
19 cld ; C code following the sysV ABI requires DF to be clear on function entry
30 add esp, 8 ; Cleans up the pushed error code and pushed ISR number
31 iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
32 ; These irets need to be iretq's when in long mode
34 ; Common IRQ code. Identical to ISR code except for the 'call'
47 call interruptHandler ; Different than the ISR code
49 pop ebx ; Different than the ISR code
57 ; These irets need to be iretq's when in long mode
59 ; Macro expansions for isr and irq
61 %macro m_exception_err 1
71 %macro m_exception_no_err 1
90 ; We don't get information about which interrupt was called when the handler
91 ; is run, so we will need to have a different handler for every interrupt.
92 ; Furthermore, some interrupts push an error code onto the stack but others
93 ; don't, so we will push a dummy error code for those which don't, so that
94 ; we have a consistent stack for all of them.
96 ; All of the following Interrupt Service Routines are exception handlers.
97 ; As such, they push the error code along with their exception (interrupt)
98 ; number. If an exception has an error code, $0 will not be pushed as the CPU
99 ; already does that for us.
101 m_exception_err 0 ; 0: Divide By Zero Exception
102 m_exception_err 1 ; 1: Debug Exception
103 m_exception_err 2 ; 2: Non Maskable Interrupt Exception
104 m_exception_err 3 ; 3: Int 3 Exception
105 m_exception_err 4 ; 4: INTO Exception
106 m_exception_err 5 ; 5: Out of Bounds Exception
107 m_exception_err 6 ; 6: Invalid Opcode Exception
108 m_exception_err 7 ; 7: Coprocessor Not Available Exception
109 m_exception_no_err 8 ; 8: Double Fault Exception (With Error Code!)
110 m_exception_err 9 ; 9: Coprocessor Segment Overrun Exception
111 m_exception_no_err 10 ; 10: Bad TSS Exception (With Error Code!)
112 m_exception_no_err 11 ; 11: Segment Not Present Exception (With Error Code!)
113 m_exception_no_err 12 ; 12: Stack Fault Exception (With Error Code!)
114 m_exception_no_err 13 ; 13: General Protection Fault Exception (With Error Code!)
115 m_exception_no_err 14 ; 14: Page Fault Exception (With Error Code!)
116 m_exception_err 15 ; 15: Reserved Exception
117 m_exception_err 16 ; 16: Floating Point Exception
118 m_exception_no_err 17 ; 17: Alignment Check Exception (With Error Code!)
119 m_exception_err 18 ; 18: Machine Check Exception
120 m_exception_err 19 ; 19: Reserved
121 m_exception_err 20 ; 20: Reserved
122 m_exception_err 21 ; 21: Reserved
123 m_exception_err 22 ; 22: Reserved
124 m_exception_err 23 ; 23: Reserved
125 m_exception_err 24 ; 24: Reserved
126 m_exception_err 25 ; 25: Reserved
127 m_exception_err 26 ; 26: Reserved
128 m_exception_err 27 ; 27: Reserved
129 m_exception_err 28 ; 28: Reserved
130 m_exception_err 29 ; 29: Reserved
131 m_exception_no_err 30 ; 30: Reserved (With Error Code!)
132 m_exception_err 31 ; 31: Reserved
134 ; All of the following Interrupt Requests are stubs for hardware interrupts such
135 ; as device interrupts. These are not exceptions. Each Interrupt Request pushes
136 ; the IRQ value (starting at 0) along with their corresponding hardware interrupt
137 ; value (starting at 32).
139 ; Interrupt Request handlers
140 m_interrupt 0, 32 ; System timer (PIT)
141 m_interrupt 1, 33 ; PS2 Keyboard
142 m_interrupt 2, 34 ; PIC2
143 m_interrupt 3, 35 ; COM2
144 m_interrupt 4, 36 ; COM1
145 m_interrupt 5, 37 ; LPT2
146 m_interrupt 6, 38 ; Floppy Disk Drive
147 m_interrupt 7, 39 ; LPT1
148 m_interrupt 8, 40 ; CMOS Real Time Clock
149 m_interrupt 9, 41 ; Unused / Generic
150 m_interrupt 10, 42 ; Unused / Generic
151 m_interrupt 11, 43 ; Unused / Generic
152 m_interrupt 12, 44 ; PS2 Mouse
153 m_interrupt 13, 45 ; Numeric Coprocessor
154 m_interrupt 14, 46 ; IDE0 (HDD)
155 m_interrupt 15, 47 ; IDE1 (HDD)