Page 1 of 1

something wrong with pic in pmode, please help!

Posted: Sun Apr 27, 2003 3:40 pm
by udarkman
I tried to reprogram pic but I think I couldnt manage to do it. What is wrong with this code??

I want to handle int8 (timer). Whenever I call int 8 softwarely, it works fine. But I want to do it with IRQ0.
Here is how I initialize pic. And full source is included.Please help:)
...
in al, (PIC8259MASTER + 1)
mov [Old82591Mask], al
in al, (PIC8259SLAVE + 1)
mov [Old82592Mask], al

mov dl, 28h
mov dh, 20h
call InitPic

mov al, 0feh ;just open int8
out (PIC8259MASTER + 1), al
mov al, 0ffh
out (PIC8259SLAVE + 1), al
...

proc InitPic
mov al, 11h
out PIC8259MASTER, al
out PIC8259SLAVE, al

mov al, dh
out PIC8259MASTER+1, al

mov al, dl
out PIC8259SLAVE+1, al

mov al, 4
out PIC8259MASTER+1, al

mov al, 2
out PIC8259SLAVE+1, al

mov al, 1
out PIC8259MASTER+1, al
out PIC8259SLAVE+1, al

ret
endp InitPic

[attachment deleted by admin]

Re:something wrong with pic in pmode, please help!

Posted: Sun Apr 27, 2003 5:32 pm
by shad
idk what all that above is.. its pretty simple..
0x20 = master, 0xA0 = slave.

outportb(0x20, 0x11);
outportb(0xA0, 0x11);

outportb(0x21, 0x20);
outportb(0xA1, 0x28);

outportb(0x21, 0x04);
outportb(0xA1, 0x02);

outportb(0x21, 0x01);
outportb(0xA1, 0x01);

That will remap to ints 32 - 48,
to mask an all ints but the clock:

outportb( 0x21, ~0x1 );
outportb( 0xA1, ~0x0 );

Make sure you send EOI at the end of ur handler (outportb(0x20,0x20); )

Re:something wrong with pic in pmode, please help!

Posted: Sun Apr 27, 2003 11:27 pm
by udarkman
if you be carefull, the code you wrote is same as mine but in C. And also Im sure that Im sending EOI at the end of int handler.. Also if there were a problem with EOI, the program would crash at the end of handler. but, 'int8 proc' dont executed even once.

Re:something wrong with pic in pmode, please help!

Posted: Mon Apr 28, 2003 12:03 am
by udarkman
I think I found the problem but couldnt solve. I forgot to set interrupts. But when I set interrupts (sti) after jumping to pmode, the program crashes and restarts computer.:)

Re:something wrong with pic in pmode, please help!

Posted: Mon Apr 28, 2003 12:55 am
by distantvoices
this is because you have mapped your hardware irq to int 0x20 - 0x27 resp. 0x28 - 0x2f.

Think about it: int 8 in asm has the cpu look in the idt at entry '0x08 and execute the code it points to. the hardware triggers int 0x20 upon receipt of a signal on the irq0-line. If you don't have setup proper entries in the idt for int #0x20 - int #0x2f, your computer will triple fault further.

stay safe

Re:something wrong with pic in pmode, please help!

Posted: Mon Apr 28, 2003 3:17 am
by Pype.Clicker
Your problem seems indeed to be in your IDT set up: in pmode, you should have the exception handlers in INT 0 .. INT 1F and *then* the ISR (irq0 => int 0x20, irq1 => int 0x21 ...)

So far your IDT looks like a real-mode interrupt table ...

Re:something wrong with pic in pmode, please help!

Posted: Mon Apr 28, 2003 8:13 am
by udarkman
oh! yes... thanks for helps....

Re:something wrong with pic in pmode, please help!

Posted: Mon Apr 28, 2003 6:36 pm
by slacker
i find it easier to do my IDT is assembly...