1 ; vi:filetype=nasm ts=8 sts=8 sw=8:
10 GATE_PRESENT equ 8000h
15 ; install trap handlers
16 set_trap 0, trap_entry_div
17 set_trap 1, trap_entry_debug
18 set_trap 2, trap_entry_nmi
19 set_trap 3, trap_entry_bp
20 set_trap 4, trap_entry_overflow
21 set_trap 5, trap_entry_bound
22 set_trap 6, trap_entry_ill
23 set_trap 7, trap_entry_nodev
24 set_trap 8, trap_entry_dfault
25 set_trap 9, trap_entry_copseg
26 set_trap 10, trap_entry_tss
27 set_trap 11, trap_entry_segpres
28 set_trap 12, trap_entry_stack
29 set_trap 13, trap_entry_prot
30 set_trap 14, trap_entry_page
31 set_trap 15, trap_entry_reserved
32 set_trap 16, trap_entry_fpu
33 set_trap 17, trap_entry_align
34 set_trap 18, trap_entry_mce
35 set_trap 19, trap_entry_sse
37 ; install dummy interrupt handlers for all IRQ vectors
40 set_irq_vector i, dummy_intr_pic1
41 set_irq_vector i+8, dummy_intr_pic2
63 ; do exception handling
65 add esp, 8 ; remove error code and exception number from stack
72 trap_noerr 4, overflow
83 trap_noerr 15, reserved
98 cmp ebx, 32 ; determine if it's an IRQ or an exception (trap)
102 lea ebx, [ebx * 8 + idt] ; ebx <- pointer to gate descriptor
103 ; type|dpl goes to the 3rd word of the descriptor (dpl is 0)
104 or ax, (GATE_DEFAULT | GATE_PRESENT)
106 ; address low 16bits go to the first word of the descriptor
109 ; address high 16bits go to the last word of the descriptor
112 ; selector (kcode:1) goes to the second word of the descriptor
113 mov word [ebx + 2], 08h
131 ; PIC initialization command word 1 bits
132 ICW1_ICW4_NEEDED equ 01h
134 ICW1_INTERVAL4 equ 04h
137 ; PIC initialization command word 4 bits
139 ICW4_AUTO_EOI equ 02h
140 ICW4_BUF_SLAVE equ 08h
141 ICW4_BUF_MASTER equ 0ch
145 ; send ICW1 saying we'll follow with ICW4 later on
146 mov al, ICW1_INIT | ICW1_ICW4_NEEDED
149 ; send ICW2 with IRQ remapping
154 ; send ICW3 to setup the master/slave relationship
155 ; ... set bit3 = 3rd interrupt input has a slave
158 ; ... set slave ID to 2
161 ; send ICW4 to set 8086 mode (no calls generated)
165 ; done, reset the data port to 0