Problem with PICs not firing interrupts
Posted: Tue Dec 19, 2006 8:09 pm
Hello. I've been programming for a while as a hobby, and recently I thought it would be fun to try and write a very simple PC kernel to try and learn what actually goes on when the computer boots, and how thing hardware interfaces with the OS. I started to follow this tutorial on osdever.com, but I started having some trouble with IRQs. None of them ever fired, not for the keyboard or even the timer. The Interrupt handlers are installed alright (IRQ0 fires when I run "int 0x20"), but the PIC either doesn't have the right IDT entry number, or something else is terribly wrong. I'm hoping that I've at least got this right: It has to be a problem with the PIC not firing correctly.
The only code I have that deals with the PICs is here:
where OUTPORTB is a preprocessor macro:
Is my outportb wrong? I've been staring at this for days, looking up all the info on the PIC, and all of them point to this code being right. I swear it's not anything else, or else the interrupt instruction wouldn't work, right?
I've tested this code on bochs, qemu, and on my desktop and laptop. None of them show any hint of working. I'm compiling with gcc 3.4.4 on Gentoo, and the kernel is always being booted by GRUB. That's all the relevant info I can think of right now...
On a side note, I'm trying to make sure I understand the code above. The first two lines tell the PICs that a reconfiguration is coming. The next two tell IRQ0-IRQ7 to map to interrupts 0x20-0x27, and IRQ8-IRQ15 to 0x28-0x2F. The next to tell the master PIC to communicate to the slave PIC on IRQ2 (bit 2 set), and the slave PIC to the master PIC on IRQ9 (bit 1 set). The next two tell the PICs how to communicate (or something, don't quite get this part), and the last two set the IRQ masks off.
Right?
Thanks for any help you can give me. I'm really interested in this, but I'm stumped and frustrated right now.
agrif
The only code I have that deals with the PICs is here:
Code: Select all
OUTPORTB(0x20, 0x11);
OUTPORTB(0xA0, 0x11);
OUTPORTB(0x21, 0x20);
OUTPORTB(0xA1, 0x28);
OUTPORTB(0x21, 0x04);
OUTPORTB(0xA1, 0x02);
OUTPORTB(0x21, 0x01);
OUTPORTB(0xA1, 0x01);
OUTPORTB(0x21, 0x0);
OUTPORTB(0xA1, 0x0);
Code: Select all
#define OUTPORTB(_port, _data) __asm__ __volatile__ ("outb %1, %0" : : "dN" ((unsigned short)_port), "a" ((unsigned char)_data))
I've tested this code on bochs, qemu, and on my desktop and laptop. None of them show any hint of working. I'm compiling with gcc 3.4.4 on Gentoo, and the kernel is always being booted by GRUB. That's all the relevant info I can think of right now...
On a side note, I'm trying to make sure I understand the code above. The first two lines tell the PICs that a reconfiguration is coming. The next two tell IRQ0-IRQ7 to map to interrupts 0x20-0x27, and IRQ8-IRQ15 to 0x28-0x2F. The next to tell the master PIC to communicate to the slave PIC on IRQ2 (bit 2 set), and the slave PIC to the master PIC on IRQ9 (bit 1 set). The next two tell the PICs how to communicate (or something, don't quite get this part), and the last two set the IRQ masks off.
Right?
Thanks for any help you can give me. I'm really interested in this, but I'm stumped and frustrated right now.
agrif