interrupts half-done
[ld45_start_nothing] / src / intr.asm
1 ; vi:filetype=nasm ts=8 sts=8 sw=8:
2         section .text
3
4 %include "intr.inc"
5
6         global init_intr
7 init_intr:
8         call init_pic
9         ret
10
11         global set_intr
12 set_intr:
13         ret
14
15 PIC1_CMD equ 20h
16 PIC1_DATA equ 21h
17 PIC2_CMD equ 0a0h
18 PIC2_DATA equ 0a1h
19
20 ; PIC initialization command word 1 bits
21 ICW1_ICW4_NEEDED        equ 01h
22 ICW1_SINGLE             equ 02h
23 ICW1_INTERVAL4          equ 04h
24 ICW1_LEVEL              equ 08h
25 ICW1_INIT               equ 10h
26 ; PIC initialization command word 4 bits
27 ICW4_8086               equ 01h
28 ICW4_AUTO_EOI           equ 02h
29 ICW4_BUF_SLAVE          equ 08h
30 ICW4_BUF_MASTER         equ 0ch
31 ICW4_SPECIAL            equ 10h
32 ; PIC operation command word 2 bits
33 OCW2_EOI                equ 20h
34
35 init_pic:
36         ; send ICW1 saying we'll follow with ICW4 later on
37         mov al, ICW1_INIT | ICW1_ICW4_NEEDED
38         out PIC1_CMD, al
39         out PIC2_CMD, al
40         ; send ICW2 with IRQ remapping
41         mov al, IRQ_OFFSET
42         out PIC1_DATA, al
43         add al, 8
44         out PIC2_DATA, al
45         ; send ICW3 to setup the master/slave relationship
46         ; ... set bit3 = 3rd interrupt input has a slave
47         mov al, 4
48         out PIC1_DATA, al
49         ; ... set slave ID to 2
50         mov al, 2
51         out PIC2_DATA, al
52         ; send ICW4 to set 8086 mode (no calls generated)
53         mov al, ICW4_8086
54         out PIC1_DATA, al
55         out PIC2_DATA, al
56         ; done, reset the data port to 0
57         xor al, al
58         out PIC1_DATA, al
59         out PIC2_DATA, al
60         ret