fixed the interrupt gate descriptor setup
[ld45_start_nothing] / src / intr.inc
1 ; vi:filetype=nasm ts=8 sts=8 sw=8:
2
3 PIC1_CMD        equ 020h
4 PIC1_DATA       equ 021h
5 PIC2_CMD        equ 0a0h
6 PIC2_DATA       equ 0a1h
7 OCW2_EOI        equ 020h
8 OCW3_ISR        equ 00bh
9 IRQ_OFFSET      equ 32
10 %define IRQ_TO_INTR(x)  ((x) + IRQ_OFFSET)
11 %define INTR_TO_IRQ(x)  ((x) - IRQ_OFFSET)
12
13 %macro set_trap 2
14         push dword %2
15         push dword %1
16         call set_intr
17         add esp, 8
18 %endmacro
19
20 %macro set_irq_vector 2
21         push dword %2
22         push dword IRQ_TO_INTR(%1)
23         call set_intr
24         add esp, 8
25 %endmacro
26
27 %macro mask_irq 1
28 %if %1 < 8
29         in al, PIC1_DATA
30         or al, (1 << %1)
31         out PIC1_DATA, al
32 %else
33         in al, PIC2_DATA
34         or al, (1 << (%1 - 8))
35         out PIC2_DATA, al
36 %endif
37 %endmacro
38
39 %macro unmask_irq 1
40 %if %1 < 8
41         in al, PIC1_DATA
42         and al, ~(1 << %1)
43         out PIC1_DATA, al
44 %else
45         in al, PIC2_DATA
46         and al, ~(1 << (%1 - 8))
47         out PIC2_DATA, al
48 %endif
49 %endmacro
50
51 %macro end_of_irq 1
52         mov al, OCW2_EOI
53 %if %1 >= 8
54         out PIC2_CMD, al
55 %endif
56         out PIC1_CMD, al
57 %endmacro
58
59         extern idt
60
61 %ifndef INTR_ASM_
62         extern init_intr
63         extern set_intr
64 %endif