Page 1 of 1

irq

Posted: Mon Dec 31, 2007 4:24 pm
by packet50071
I was reading the code from the tutorial from http://osdever.net/bkerndev/Docs/irqs.htm

but i cannot understand what this code does ?
any help can be help full -- I understand y its used but i cannot understand the code itself for ex 'outb 0x20, 0x11;' why is it used ?? etc

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);
}
:?

Posted: Mon Dec 31, 2007 6:16 pm
by bewing
The code is for "remapping the PIC".
When a PC is first booted, IRQs from hardware devices end up having the same interrupt numbers as CPU exception codes. This is completely unworkable. Fortunately, the Programmable Interrupt Controller chip is programmable. So you can change (to some degree) which IRQs map into which CPU interrupt numbers, by sending some codes to the PIC chip. You don't want to use any of the first 32 CPU interrupts. But the next 16 are free for you to use for IRQs. So that is what this code does. It uses PIC-specific commands (in the form of special bytes to particular IO ports) to tell the PIC to map the 16 IRQs to CPU interrupt numbers 0x20 to 0x2f.

Posted: Mon Dec 31, 2007 6:21 pm
by packet50071
thx bewing

But what does PIC-specific commands Do ??
Or do i don't have to know that !

thx for future help

Posted: Mon Dec 31, 2007 8:16 pm
by packet50071
I have another question - i am looking at various tutorials and OS examples but they all end up looking alike - did they copy from a tutorial or do the actually think same !!

Posted: Tue Jan 01, 2008 12:42 pm
by blound
when I was wondering the same thing this really helped:

http://www.brokenthorn.com/Resources/OSDevPic.html

you should read the whole thing but if you want a quick answer look for the section:

8259A Commands

Posted: Tue Jan 01, 2008 4:32 pm
by packet50071
thx for showing me that :D

Posted: Tue Jan 01, 2008 6:43 pm
by bewing
packet50071 wrote:I have another question - i am looking at various tutorials and OS examples but they all end up looking alike - did they copy from a tutorial or do the actually think same !!
The manufacturer of a device intends for it to be used in one fairly specific way. You can change the comments a little if you want, but there is really only one possible set of commands you can send -- unless you do it wrong. There are many many ways to do it wrong.

Posted: Wed Jan 02, 2008 8:41 am
by packet50071
nah i am not talking about this - i am talking about the name of the functions used in all their code and stuff like that . any way forget about it
:wink:

Posted: Wed Jan 02, 2008 1:18 pm
by blound
packet50071 wrote:nah i am not talking about this - i am talking about the name of the functions used in all their code and stuff like that . any way forget about it
:wink:
I have noticed this alot too. It actually has advantages b/c some people are lazy with comments and others have way too many and the combination usually lets you figure out what the code is doing.

Also if you ever see hardcoded numbers used in the middle you can usually google: <the #> osdev

and find another tutorial explaining where it came from :P