Page 1 of 1

PIC Setup

Posted: Tue Jul 28, 2009 10:49 pm
by brodeur235
This: http://wiki.osdev.org/PIC is by far the best description PIC remapping I have found, however there is a part that I don't fully understand. After you send both master and slave the initialization (0x11) and then their new vector offsets, you send information that "Tell it how it is wired to master/slaves." The code in the wiki is:

Code: Select all

	outb(PIC1_DATA, 4);                       // continue initialization sequence
	io_wait();
	outb(PIC2_DATA, 2);
	io_wait();
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.

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?

Help appreciated,

Brodeur235

Re: PIC Setup

Posted: Tue Jul 28, 2009 11:51 pm
by manonthemoon
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.

Re: PIC Setup

Posted: Wed Jul 29, 2009 12:15 am
by brodeur235
Thanks manonthemoon, that's much clearer. I wouldn't have guessed that it passed low integer arguments via the position of the set bit...

Brodeur235