problem handling irq code
Posted: Thu Apr 20, 2006 12:41 pm
hi all,
i learned operating system development from bkerndev. i am having problem understanding this code for implementing irq in operating system.
the code is as follows :
i can understand the basic working like cascading of irq's and mapping of irq' s and all that stuff. can somebody explain me how this code is actually enabling interrupts for hardware requets bacause it is tough for me to figure out seeing the bkerndev code for irq.
i know i may be stupid asking this but i am new to operating system. also after using this code the irq's are not working.
thanks in advance for anay help
i learned operating system development from bkerndev. i am having problem understanding this code for implementing irq in operating system.
the code is as follows :
Code: Select all
static unsigned int cached_irq_mask;
#define __byte(x,y) (((unsigned char *)&(y))[[x]])
#define cached_21 (__byte(0,cached_irq_mask))
#define cached_A1 (__byte(1,cached_irq_mask))
static void irq_delay(unsigned long loops)
{
unsigned long i, j;
for (i = 0; i < loops; i++)
for (j = 0; j < loops; j++)
do {
} while (0);
}
void disable_irq(unsigned int irq)
{
unsigned int mask = 1 << irq;
cached_irq_mask |= mask;
if (irq & 8)
outb(cached_A1, 0xA1);
else
outb(cached_21, 0x21);
}
void enable_irq(unsigned int irq)
{
unsigned int mask = ~(1 << irq);
cached_irq_mask &= mask;
if (irq & 8)
outb(cached_A1, 0xA1);
else
outb(cached_21, 0x21);
}
void init_irq(void)
{
cached_irq_mask = 0xffff;
outb(0xff, 0x21); /* mask all of 8259A-1 */
outb(0xff, 0xA1); /* mask all of 8259A-2 */
outb_p(0x11, 0x20); /* ICW1: select 8259A-1 init */
outb_p(0x20 + 0, 0x21); /* ICW2: 8259A-1 IR0-7 mapped to 0x20-0x27 */
outb_p(0x04, 0x21); /* 8259A-1 (the master) has a slave on IR2 */
outb_p(0x03, 0x21); /* master does Auto EOI */
outb_p(0x11, 0xA0); /* ICW1: select 8259A-2 init */
outb_p(0x20 + 8, 0xA1); /* ICW2: 8259A-2 IR0-7 mapped to 0x28-0x2f */
outb_p(0x02, 0xA1); /* 8259A-2 is a slave on master's IR2 */
outb_p(0x01, 0xA1); /* slave doesn't Auto EOI */
irq_delay(5000); /* wait for 8259A to initialize */
outb(cached_21, 0x21); /* restore master IRQ mask */
outb(cached_A1, 0xA1); /* restore slave IRQ mask */
}
i know i may be stupid asking this but i am new to operating system. also after using this code the irq's are not working.
thanks in advance for anay help