|
| 1 | +idtr: |
| 2 | + idt_size dw 256*8 - 1 |
| 3 | + idt_offset dd _idt |
| 4 | + |
| 5 | + |
| 6 | +global _idt |
| 7 | +align 8 |
| 8 | +_idt times 256 dq 0 |
| 9 | + |
| 10 | +global load_idt |
| 11 | +load_idt: |
| 12 | + lidt [idtr] |
| 13 | + ret |
| 14 | + |
| 15 | +global _isr_0 |
| 16 | +global _isr_1 |
| 17 | +global _isr_2 |
| 18 | +global _isr_3 |
| 19 | +global _isr_4 |
| 20 | +global _isr_5 |
| 21 | +global _isr_6 |
| 22 | +global _isr_7 |
| 23 | +global _isr_8 |
| 24 | +global _isr_9 |
| 25 | +global _isr_10 |
| 26 | +global _isr_11 |
| 27 | +global _isr_12 |
| 28 | +global _isr_13 |
| 29 | +global _isr_14 |
| 30 | +global _isr_15 |
| 31 | +global _isr_16 |
| 32 | +global _isr_17 |
| 33 | +global _isr_18 |
| 34 | +global _isr_19 |
| 35 | +global _isr_20 |
| 36 | +global _isr_21 |
| 37 | +global _isr_22 |
| 38 | +global _isr_23 |
| 39 | +global _isr_24 |
| 40 | +global _isr_25 |
| 41 | +global _isr_26 |
| 42 | +global _isr_27 |
| 43 | +global _isr_28 |
| 44 | +global _isr_29 |
| 45 | +global _isr_30 |
| 46 | +global _isr_31 |
| 47 | + |
| 48 | + |
| 49 | +extern isr_0 |
| 50 | +_isr_0: ;divide error, error code: no |
| 51 | + cli |
| 52 | + push byte 0 |
| 53 | + push byte 0 |
| 54 | + jmp _isr_common |
| 55 | + |
| 56 | +_isr_1: ;debug exception, error code: no |
| 57 | + cli |
| 58 | + push byte 0 |
| 59 | + push byte 1 |
| 60 | + jmp _isr_common |
| 61 | + |
| 62 | +_isr_2: ;NMI external interrupt, error code: no |
| 63 | + cli |
| 64 | + push byte 0 |
| 65 | + push byte 2 |
| 66 | + jmp _isr_common |
| 67 | + |
| 68 | +_isr_3: ;Breakpoint, error code: no |
| 69 | + cli |
| 70 | + push byte 0 |
| 71 | + push byte 3 |
| 72 | + jmp _isr_common |
| 73 | + |
| 74 | +_isr_4: ;Overflow, error code: no |
| 75 | + cli |
| 76 | + push byte 0 |
| 77 | + push byte 4 |
| 78 | + jmp _isr_common |
| 79 | + |
| 80 | +_isr_5: ;Bound range exceeded, error code: no |
| 81 | + cli |
| 82 | + push byte 0 |
| 83 | + push byte 5 |
| 84 | + jmp _isr_common |
| 85 | + |
| 86 | +_isr_6: ;Invalid opcode, error code: no |
| 87 | + cli |
| 88 | + push byte 0 |
| 89 | + push byte 6 |
| 90 | + jmp _isr_common |
| 91 | + |
| 92 | +_isr_7: ;Device not available (no x87 coprocessor - shouldn't really happen), error code: no |
| 93 | + cli |
| 94 | + push byte 0 |
| 95 | + push byte 7 |
| 96 | + jmp _isr_common |
| 97 | + |
| 98 | +_isr_8: ;Double Fault, error code: always 0 |
| 99 | + cli |
| 100 | + push byte 8 |
| 101 | + jmp _isr_common |
| 102 | + |
| 103 | +_isr_9: ;Coprocessor segment overrun, error code: no |
| 104 | + cli |
| 105 | + push byte 0 |
| 106 | + push byte 9 |
| 107 | + jmp _isr_common |
| 108 | + |
| 109 | +_isr_10: ;Invalid TSS, error code: yes |
| 110 | + cli |
| 111 | + push byte 10 |
| 112 | + jmp _isr_common |
| 113 | + |
| 114 | +_isr_11: ;Segment not present, error code: yes |
| 115 | + cli |
| 116 | + push byte 11 |
| 117 | + jmp _isr_common |
| 118 | + |
| 119 | +_isr_12: ;Stack-Segment fault, error code: yes |
| 120 | + cli |
| 121 | + push byte 12 |
| 122 | + jmp _isr_common |
| 123 | + |
| 124 | +_isr_13: ;General Protection fault, error code: yes |
| 125 | + cli |
| 126 | + push byte 13 |
| 127 | + jmp _isr_common |
| 128 | + |
| 129 | +_isr_14: ;Page fault, error code: yes |
| 130 | + cli |
| 131 | + push byte 14 |
| 132 | + jmp _isr_common |
| 133 | + |
| 134 | +_isr_16: ;x87 floating point error (math fault), error code: no |
| 135 | + cli |
| 136 | + push byte 0 |
| 137 | + push byte 16 |
| 138 | + jmp _isr_common |
| 139 | + |
| 140 | +_isr_17: ;Alignment Check, error code: yes |
| 141 | + cli |
| 142 | + push byte 17 |
| 143 | + jmp _isr_common |
| 144 | + |
| 145 | +_isr_18: ;Machine check, error code: no |
| 146 | + cli |
| 147 | + push byte 0 |
| 148 | + push byte 18 |
| 149 | + jmp _isr_common |
| 150 | + |
| 151 | +_isr_19: ;SIMD floating point exception, error code: no |
| 152 | + cli |
| 153 | + push byte 0 |
| 154 | + push byte 19 |
| 155 | + jmp _isr_common |
| 156 | + |
| 157 | +_isr_20: ;Virtualization exception, error code: no |
| 158 | + cli |
| 159 | + push byte 0 |
| 160 | + push byte 20 |
| 161 | + jmp _isr_common |
| 162 | + |
| 163 | +_isr_15: ;reserved interrupts, error code: no |
| 164 | +_isr_21: |
| 165 | +_isr_22: |
| 166 | +_isr_23: |
| 167 | +_isr_24: |
| 168 | +_isr_25: |
| 169 | +_isr_26: |
| 170 | +_isr_27: |
| 171 | +_isr_28: |
| 172 | +_isr_29: |
| 173 | +_isr_30: |
| 174 | +_isr_31: |
| 175 | + cli |
| 176 | + push byte 0 |
| 177 | + push byte 15 ;doesn't really matter |
| 178 | + jmp _isr_common |
| 179 | + |
| 180 | +_isr_common: |
| 181 | + pusha |
| 182 | + push ds |
| 183 | + push es |
| 184 | + push fs |
| 185 | + push gs |
| 186 | + mov ax, 0x10 ;Load ring-0 DS selector |
| 187 | + mov ds, ax |
| 188 | + mov es, ax |
| 189 | + mov fs, ax |
| 190 | + mov gs, ax |
| 191 | + mov eax, esp ;Push the stack |
| 192 | + push eax |
| 193 | + extern fault_handler |
| 194 | + call fault_handler |
| 195 | + pop eax |
| 196 | + pop gs |
| 197 | + pop fs |
| 198 | + pop es |
| 199 | + pop ds |
| 200 | + popa |
| 201 | + add esp, 8 ;cleans the pushed error code and pushed isr number |
| 202 | + iret ;pops CS, EIP, EFLAGS, SS and ESP |
| 203 | + |
| 204 | + |
| 205 | + |
0 commit comments