PIC remapping

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
White-spirit
Member
Member
Posts: 89
Joined: Sun Mar 23, 2008 2:23 pm
Location: [0x8:0x1000]

PIC remapping

Post by White-spirit »

Hello,

I am currently working on the hardware interrupts, so I must remap the PIC .
I've read JamesM's tutorial but he dont describe clearly ( In other words : I'm dumb :P ) how to remap the PIC... After I've searched on Google, I've found some descriptions about the PIC, but I'm still not sure if my PIC remap function is correct, here's the code :

Code: Select all

void remap_pic(){
	outb(0x20, 0x11);
	io_wait();
	outb(0xA0, 0x11);
	io_wait();
	outb(0x21, 0x20);
	io_wait();
	outb(0xA1, 0x70);
	io_wait();
	outb(0x21, 0x04);
	io_wait();
	outb(0xA1, 0x02);
	io_wait();
	outb(0x21, 0x01);
	io_wait();
	outb(0xA1, 0x01);
	io_wait();
	outb(0x21, inb(0x21) && 0xFC);
	io_wait();
	outb(0xA1, 0xFF);
}
I want to use IRQ0 ( clock ) and IRQ1 ( keyboard ), so I have to use AND like this : " inb(0x21) && 0xFC " ( 0xFC = 11111100 ), Is that correct ?

Thanks .
Working on multi-tasking support ...
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

I'll point you here which describes the format of the operational command words used by the pic as well as other details.

When remapping the pic, you are only giving it the base interrupt handlers for it to use within your IDT. Everything else is almost automatic. It is your responsibility to insure the interfaces set up and install there interrupt handlers in the IDT.

For example, the timer is always irq 0 as it is connected to the pic's ir0 line. Because of this, once you give the pic the base interrupt numbers in your IDT to use, you are done with the PIC.

Assuming that you remap the primary PIC to use int 0x20, just install the timers interrupt handler to int 0x20 and enable hardware interrupts (sti).
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
White-spirit
Member
Member
Posts: 89
Joined: Sun Mar 23, 2008 2:23 pm
Location: [0x8:0x1000]

Post by White-spirit »

Thanks neon, I understand more now and I've succesfully handled the timer and keyboard interrupts on my OS :-)

PS : thanks for the link :-)
Working on multi-tasking support ...
Post Reply