#define PIC1_ADDR	0x20 + 0xC0000000
#define PIC2_ADDR	0xA0 + 0xC0000000		
#define PIC1_COMMAND	PIC1_ADDR
#define PIC1_DATA	(PIC1_ADDR+1)
#define PIC2_COMMAND	PIC2_ADDR
#define PIC2_DATA	(PIC2_ADDR+1)
#define PIC_EOI		0x20

.code32

.global init_pic
init_pic:
    # init command
    mov $0x11, %al
    outb %al, $PIC1_COMMAND
    outb %al, $PIC2_COMMAND

    # vector offsets
    mov $0x20, %al
    outb %al, $PIC1_DATA
    mov $0x28, %al
    outb %al, $PIC2_DATA

    # cascade 
    mov $0x04, %al
    outb %al, $PIC1_DATA
    mov $0x02, %al  
    outb %al, $PIC2_DATA 

    # env
    mov $0x01, %al
    outb %al, $PIC1_DATA
    outb %al, $PIC2_DATA 

    # mask
    mov $0xF8, %al
    outb %al, $PIC1_DATA
    mov $0xFF, %al
    outb %al, $PIC2_DATA 

    ret

.global send_eoi_master
send_eoi_master:
    mov $0x20, %al
    outb %al, $PIC1_COMMAND
    ret 

.global send_eoi_slave 
send_eoi_slave:
    mov $0x20, %al
    outb %al, $PIC2_COMMAND
    call send_eoi_master
    ret 

.global read_isr_master
read_isr_master:
    xorl %eax, %eax
    mov $0x0B, %al
    outb %al, $PIC1_COMMAND
    in $PIC1_COMMAND, %al
    ret

.global read_isr_slave 
read_isr_slave:
    xorl %eax, %eax
    mov $0x0B, %al
    outb %al, $PIC2_COMMAND
    in $PIC2_COMMAND, %al
    ret