I don't like that wiki page. I suggest reading some other documents instead, for more details. Try wikipedia, or one of the pages on the OSRC website.
This is what the code means:
Code: Select all
outb(PIC1_DATA, 4); // IRQ2 is connected to the slave PIC
io_wait();
outb(PIC2_DATA, 2); // IRQ9 (which is IRQ1 on the slave) is connected to the master's IRQ2
io_wait();
brodeur235 wrote:Does this mean that any IRQ that fires on the slave PIC will also fire the 2nd IRQ on the slave PIC, which will in turn fire the 4th IRQ on the master PIC? I'm just looking for clarity here.
No, if an IRQ8-IRQ15 (slave) happens, it is sent through the master chip to the CPU. The slave uses IRQ2 to signal the master. Those two bytes are supposed to set that up.
Now, if IRQ9 happens, it is signaled to the CPU as IRQ2 (according to the wiki, which I haven't confirmed on my own).
From what I have gathered, that command byte is a bitmap of which IRQ is connected to a slave. So 0 means no slave, and 4 means IRQ2 is the slave (because 4 == bit #2 set, for IRQ2). That means a 2 should mean a slave is connected to IRQ9 (the IRQ1 of the slave PIC) because 2 == bit #1 set. But that's not exactly the case.
So it seems that there is a kind of back-and-forth relationship between the two PICs. Any IRQ on the slave is sent to the CPU via the master, but you don't receive two IRQs even though IRQ2 is used for the slave-to-master signal.
Also, just out of curiosity, what is the point of saving the bytes in the ports and restoring them afterwards if you're not going to use them anyway?
None, you don't have to save the masks if you haven't set them first. My guess is that you want all IRQs enabled, so just send a zero at that point. (Setting a bit
disables the IRQ). Save the masks only if they have already been set and you don't want to change them.
Note: if anyone saw my original post, I had made a big mistake, but I think this is correct now.