intr.asm: set_intr function
[ld45_start_nothing] / src / intr.inc
1 ; vi:filetype=nasm ts=8 sts=8 sw=8:
2
3 %define IRQ_OFFSET      32
4 %define IRQ_TO_INTR(x)  ((x) + IRQ_OFFSET)
5 %define INTR_TO_IRQ(x)  ((x) - IRQ_OFFSET)
6
7 %macro set_irq_vector 2
8         push dword IRQ_TO_INTR(%1)
9         push dword %2
10         call set_intr
11 %endmacro
12
13 %macro mask_irq 1
14 %if %1 < 8
15 %assign port PIC1_DATA
16 %assign mask (1 << %1)
17 %else
18 %assign port PIC2_DATA
19 %assign mask (1 << (%1 - 8))
20 %endif
21         in al, port
22         or al, mask
23         out port, al
24 %endmacro
25
26 %macro unmask_irq 1
27 %if %1 < 8
28 %assign port PIC1_DATA
29 %assign mask ~(1 << %1)
30 %else
31 %assign port PIC2_DATA
32 %assign mask ~(1 << (%1 - 8))
33 %endif
34         in al, port
35         and al, mask
36         out port, al
37 %endmacro
38
39 %macro end_of_irq 1
40         mov al, OCW2_EOI
41 %if %1 >= 8
42         out PIC2_CMD, al
43 %endif
44         out PIC1_CMD, al
45 %endmacro
46
47         extern idt