writing my first isr

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
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

writing my first isr

Post 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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post 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?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post 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.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post 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 :-(
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post 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.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post 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...
Post Reply