X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=src%2Fintr.c;fp=src%2Fintr.c;h=194670875146752d75d85ca4113a26dba4aa4c97;hp=a9bd5f1f772bb760af355be90d46e1a4c530e816;hb=c1a6b9caf99005e0496f51d07b727ac73d09e3fd;hpb=3cb6f9dad7e37db865bd3cbccf0b5d6471fdd73f diff --git a/src/intr.c b/src/intr.c index a9bd5f1..1946708 100644 --- a/src/intr.c +++ b/src/intr.c @@ -54,7 +54,7 @@ along with this program. If not, see . #define OCW2_EOI (1 << 5) -static void init_pic(int offset); +void init_pic(void); static void gate_desc(desc_t *desc, uint16_t sel, uint32_t addr, int dpl, int type); /* defined in intr_asm.S */ @@ -101,7 +101,7 @@ void init_intr(void) /* initialize the programmable interrupt controller * setting up the maping of IRQs [0, 15] to interrupts [32, 47] */ - init_pic(IRQ_OFFSET); + init_pic(); eoi_pending = 0; } @@ -116,7 +116,10 @@ struct intr_frame *get_intr_frame(void) /* set an interrupt handler function for a particular interrupt */ void interrupt(int intr_num, intr_func_t func) { + int iflag = get_intr_flag(); + disable_intr(); intr_func[intr_num] = func; + set_intr_flag(iflag); } /* this function is called from all interrupt entry points @@ -146,14 +149,14 @@ void dispatch_intr(struct intr_frame frm) } } -static void init_pic(int offset) +void init_pic(void) { /* send ICW1 saying we'll follow with ICW4 later on */ outb(ICW1_INIT | ICW1_ICW4_NEEDED, PIC1_CMD); outb(ICW1_INIT | ICW1_ICW4_NEEDED, PIC2_CMD); /* send ICW2 with IRQ remapping */ - outb(offset, PIC1_DATA); - outb(offset + 8, PIC2_DATA); + outb(IRQ_OFFSET, PIC1_DATA); + outb(IRQ_OFFSET + 8, PIC2_DATA); /* send ICW3 to setup the master/slave relationship */ /* ... set bit3 = 3rd interrupt input has a slave */ outb(4, PIC1_DATA); @@ -194,6 +197,49 @@ void set_intr_entry(int num, void (*handler)(void)) gate_desc(idt + num, selector(SEGM_KCODE, 0), (uint32_t)handler, dpl, type); } +void set_pic_mask(int pic, unsigned char mask) +{ + outb(mask, pic > 0 ? PIC2_DATA : PIC1_DATA); +} + +unsigned char get_pic_mask(int pic) +{ + return inb(pic > 0 ? PIC2_DATA : PIC1_DATA); +} + +void mask_irq(int irq) +{ + int port; + unsigned char mask; + + if(irq < 8) { + port = PIC1_DATA; + } else { + port = PIC2_DATA; + irq -= 8; + } + + mask = inb(port) | (1 << irq); + outb(mask, port); +} + +void unmask_irq(int irq) +{ + int port; + unsigned char mask; + + if(irq < 8) { + port = PIC1_DATA; + } else { + port = PIC2_DATA; + irq -= 8; + } + + mask = inb(port) & ~(1 << irq); + outb(mask, port); +} + + void end_of_irq(int irq) { int intr_state = get_intr_flag();