Dont follow how to remapIRQS<Solved handy info on Pic>
Posted: Wed Jun 25, 2008 5:40 pm
Hiya still going nuts reading lots of theory tonight
, I am getting someplace with brans tutorial now but theres one piece of code I dont follow going with whats mentioned on the page in question regarding irqs
I get that the following exert from brans tutorial OK
. The master PIC's command register exists at I/O port 0x20, while the slave PIC's command register exists at I/O port 0xA0.
I think Im fine with this but I dont follow at all how in practice these irqs get remapped with the below code, have translated hex to decimal to see if I can fathom where the re-assignments are taking place or exactly whats happening in practice but can envisage it and would appreciate some input on this small exert if possible
[Cant understand]
there doesnt seem to be enough lines, 10 lines but that manages to remap 15 irqs?
outportb(0x20, 0x11); decimal of 20h = 32; decimal of 11h = 17 ,
;is this 32 referance to starting irq 32 or the command register? 0x20
so I figured
i.e irq 0 to 15 , reassigned to idt entrys 32-47
outportb(0xA0, 0x11);
A0 = 160, 11h = 32 ;at this point I figured the 32 was of some relevance but I cant find any pattern of numbers to help me understand in the following code?
outportb(0x21, 0x20);
21h = 33, 0x20
outportb(0xA1, 0x28);
A1 = 161 ; hmm is this other commands or something? outwith 20 and A0? This is where Im getting confused here
0x28 = 40
outportb(0x21, 0x04);
21h = 33 , 4
outportb(0xA1, 0x02);
A1 = 161, 2
outportb(0x21, 0x01);
21h = 33, 1
outportb(0xA1, 0x01);
A1h = 161, 1
outportb(0x21, 0x0);
33,0
outportb(0xA1, 0x0);
161,0
Im stumped as to how that remaps all the irqs mentioned but Im clearly missing something, would really appreciate some insight into how this code all works, what it is doing?
I get that the following exert from brans tutorial OK
ok soAny IBM PC/AT Compatible computer (anything with a 286 and later processor) has 2 chips that are used to manage IRQs. These 2 chips are known as the Programmable Interrupt Controllers or PICs. These PICs also go by the name '8259'. One 8259 acts as the 'Master' IRQ controller, and one is the 'Slave' IRQ controller. The slave is connected to IRQ2 on the master controller. The master IRQ controller is connected directly to the processor itself, to send signals. Each PIC can handle 8 IRQs. The master PIC handles IRQs 0 to 7, and the slave PIC handles IRQs 8 to 15. Remember that the slave controller is connected to the primary controller through IRQ2: This means that every time an IRQ from 8 to 15 occurs, IRQ2 fires at exactly the same time.
When a device signals an IRQ, remember that an interrupt is generated, and the CPU pauses whatever it's doing to call the ISR to handle the corresponding IRQ. The CPU then performs whatever necessary action (like reading from the keyboard, for example), and then it must tell the PIC that the interrupt came from that the CPU has finished executing the correct routine. The CPU tells the right PIC that the interrupt is complete by writing the command byte 0x20 in hex to the command register for that PIC. The master PIC's command register exists at I/O port 0x20, while the slave PIC's command register exists at I/O port 0xA0.
Before we get into writing our IRQ management code, we need to also know that IRQ0 to IRQ7 are originally mapped to IDT entries 8 through 15. IRQ8 to IRQ15 are mapped to IDT entries 0x70 through 0x78. If you remember the previous section of this tutorial, IDT entries 0 through 31 are reserved for exceptions. Fortunately, the Interrupt Controllers are 'programmable': You can change what IDT entries that their IRQs are mapped to. For this tutorial, we will map IRQ0 through IRQ15 to IDT entries 32 through 47. To start us off, we must add some ISRs to 'start.asm' in order to service our
. The master PIC's command register exists at I/O port 0x20, while the slave PIC's command register exists at I/O port 0xA0.
I think Im fine with this but I dont follow at all how in practice these irqs get remapped with the below code, have translated hex to decimal to see if I can fathom where the re-assignments are taking place or exactly whats happening in practice but can envisage it and would appreciate some input on this small exert if possible
[Cant understand]
Code: Select all
void irq_remap(void)
{
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);
}
outportb(0x20, 0x11); decimal of 20h = 32; decimal of 11h = 17 ,
;is this 32 referance to starting irq 32 or the command register? 0x20
so I figured
i.e irq 0 to 15 , reassigned to idt entrys 32-47
outportb(0xA0, 0x11);
A0 = 160, 11h = 32 ;at this point I figured the 32 was of some relevance but I cant find any pattern of numbers to help me understand in the following code?
outportb(0x21, 0x20);
21h = 33, 0x20
outportb(0xA1, 0x28);
A1 = 161 ; hmm is this other commands or something? outwith 20 and A0? This is where Im getting confused here
0x28 = 40
outportb(0x21, 0x04);
21h = 33 , 4
outportb(0xA1, 0x02);
A1 = 161, 2
outportb(0x21, 0x01);
21h = 33, 1
outportb(0xA1, 0x01);
A1h = 161, 1
outportb(0x21, 0x0);
33,0
outportb(0xA1, 0x0);
161,0
Im stumped as to how that remaps all the irqs mentioned but Im clearly missing something, would really appreciate some insight into how this code all works, what it is doing?