Page 1 of 1

writing my first isr

Posted: Mon Aug 13, 2007 3:39 pm
by sancho1980
hi

im just writing my first isr, the keyboard handler:
i first remap the PICs:

Code: Select all

procedure remap_pics(offset1: dword; offset2: dword); @nodisplay; @noalignstack;
begin remap_pics;
	push(eax);
	mov(ICW1_INIT+ICW1_ICW4,al);
	out(al,PIC1_COMMAND);
	out(al,PIC2_COMMAND);
	mov(offset1,eax);
	out(al,PIC1_DATA);
	mov(offset2,eax);
	out(al,PIC2_DATA);
	mov(%100,al);
	out(al,PIC1_DATA);
	mov(2,al);
	out(al,PIC2_DATA);
	mov(ICW4_8086,al);
	out(al,PIC1_DATA);
	out(al,PIC2_DATA);
	mov(%11111111,al); //let's mask
	out(al,PIC1_DATA); //all interrupts on master
	out(al,PIC2_DATA); //and on slave
	pop(eax);
end remap_pics;
with

Code: Select all

PIC1_COMMAND: text:="$20";
	PIC1_DATA: text:="$21";
	PIC2_COMMAND: text:="$A0";
	PIC2_DATA: text:="$A1";
	PIC_EOI: text:="$20";
	ICW1_ICW4: text:="$1";
	ICW_SINGLE: text:="$2";
	ICW1_INTERVAL4: text:="$4";
	ICW1_LEVEL: text:="$8";
	ICW1_INIT: text:="$10";
	ICW4_8086: text:="$1";
	ICW4_AUTO: text:="$2";
	ICW4_BUF_SLAVE: text:="$8";
	ICW4_BUF_MASTER: text:="$C";
	ICW4_SFNM: text:="$10";
then i hook the isr,unmask the keyboard irq, load the idt, and enable interrupts:

Code: Select all

mov(0,eax);
	mov(cseg,ax);
hook_int($21,INTERRUPT,eax,&key_int);
	mov(%11111101,al);
	out(al,$21);
	lidt(idt);
	sti;
	hlt;
the isr looks as follows:

Code: Select all

procedure key_int; @nodisplay; @noalignstack; @noframe;
begin key_int;
	putstring("HELLO");
	mov($20,al);
	out(al,PIC1_COMMAND);
	out(al,PIC2_COMMAND);
	sti;
	iret();
end key_int;
when i press a key, "HELLO" is printed to the screen only once (so no second "HELLO" for the release). when i press a key repeatedly, nothing happens..what could be the problem here??

thanks

martin

Posted: Mon Aug 13, 2007 3:49 pm
by pcmattman
I'm not sure what the problem is, but make sure you send the EOI (I think you're doing this already). Also, you don't need to enable interrupts before the iret, iret will do it for you.

Posted: Mon Aug 13, 2007 3:55 pm
by sancho1980
yeah i know, actually i think this being an interrupt not a trap gate, that interrupts are never being disabled here...i tried with putting all this stuff just to see if any of it might solve the problem..actually i think the EOI would only needed to be sent to the pic that received the request ,right?

Posted: Mon Aug 13, 2007 4:01 pm
by pcmattman
Go to the CVS link in my sig, look at syscore/fault.cc, syscore/irq.cc, and syscore/idt.cc, and compare to your code to find the problem.

Posted: Mon Aug 13, 2007 4:02 pm
by frank
For interrupts that occur on the first PIC you only have to send an EOI to it like (IRQs 0-8 IIRC). When an interrupt occurs on the slave PIC you have to send the EOI to both PICs. About interrupts being disabled, a trap gate leaves interrupts enabled and an interrupt gate disables them.

Posted: Mon Aug 13, 2007 4:15 pm
by sancho1980
pcmattman wrote:Go to the CVS link in my sig, look at syscore/fault.cc, syscore/irq.cc, and syscore/idt.cc, and compare to your code to find the problem.
I dont see the problem :-(

Posted: Mon Aug 13, 2007 4:16 pm
by jnc100
Also, in particular for the keyboard, as well as acknowledging the interrupt with the pic, you need to remove the scan code from the keyboard buffer to receive any more, even if you do nothing with it. See Keyboard Input.

Regards,
John.

Posted: Mon Aug 13, 2007 4:20 pm
by sancho1980
jnc100 wrote:Also, in particular for the keyboard, as well as acknowledging the interrupt with the pic, you need to remove the scan code from the keyboard buffer to receive any more, even if you do nothing with it. See Keyboard Input.

Regards,
John.
Ahhhh, sometimes it's the simple things that drive me crazy...