Okay, there was a bug in the code that was causing the reboots. But now when I try to remap the PICs, I always get a Divide by Zero exception.
Code:
printf( "Initializing Exceptions: " );
init_ints();
printf( "done\n" );
printf("Remapping: " );
do_it();
printf("done\n");
That's in the main body of the kernel. I'm not sure if the remapping should be before or after the exceptions are initialized... I tried it both ways with the exact same results.
Code:
void do_it()
{
asm("cli");
remap_pics(0x20, 0x28);
disable_irq(0);
enable_irq(1);
asm("sti");
}
If I comment out the asm("sti"); or the enable_irq(1); in this function, I do not get the Div/0 exception. But it also probably silently breaks it.
Code:
void enable_irq(int irq)
{
if (irq == 0xFF)
{
outb(0x00, PIC1 + 1);
outb(0x00, PIC2 + 1);
} else
{
irq = irq & (1 << irq);
if (irq < 8)
outb(irq & 0xFF, PIC1 + 1);
else
outb(irq >> 8, PIC2 + 1);
}
}
void disable_irq(int irq)
{
if (irq == 0xFF)
{
outb(0xFF, PIC1 + 1);
outb(0xFF, PIC2 + 1);
}
else
{
irq = irq | (1 << irq);
if (irq < 8)
outb(irq & 0xFF, PIC1 + 1);
else
outb(irq >> 8, PIC2 + 1);
}
}
void remap_pics(int pic1, int pic2)
{
unsigned char md, sd;
md = inb(PIC1 + 1);
sd = inb(PIC2 + 1);
outb(EOI, PIC1); /* send EOI to master */
/* send ICW1 */
outb(0x11, PIC1);
outb(0x11, PIC2);
/* send ICW2 */
outb(pic1, PIC1 + 1);
outb(pic2, PIC2 + 2);
/* send ICW3 */
outb(0x04, PIC1 + 1);
outb(0x02, PIC2 + 1);
/* send ICW4 */
outb(0x01, PIC1 + 1);
outb(0x01, PIC2 + 1);
outb(md, PIC1 + 1);
outb(sd, PIC2 + 1);
}
Does anyone see anything wrong with this? I think it's all correct, but I don't know what else could be causing it.