Page 1 of 1

SOLVED: ISR problems

Posted: Mon Sep 21, 2009 11:21 am
by tharkun
Ok, so this is probably a very basic problem but I'm having trouble with the idt & isrs.
The problem is that whenever a hardware interrupt fires, say a "Divide by zero error" happens the interrupt get's called but it continually repeat's itself. But if a software interrupt fires like "int 0" then the interrupt is called and returns normally.

Here is my isrs.S: (at&t syntax)

Code: Select all

.code32

#define ISR(n) \
	.global isr##n ; \
	isr##n: \
		cli; \
		pushl $0; \
		pushl $##n; \
		jmp isr_stub

#define ISR_ERR(n) \
	.global isr##n ; \
	isr##n: \
		cli ; \
		pushl $##n ; \
		jmp isr_stub
ISR(0)
ISR(1)
ISR(2)
ISR(3)
ISR(4)
ISR(5)
ISR(6)
ISR(7)
ISR_ERR(8)
ISR(9)
ISR_ERR(10)
ISR_ERR(11)
ISR_ERR(12)
ISR_ERR(13)
ISR_ERR(14)
ISR(15)
ISR(16)
ISR(17)
ISR(18)
ISR(19)
ISR(20)
ISR(21)
ISR(22)
ISR(23)
ISR(24)
ISR(25)
ISR(26)
ISR(27)
ISR(28)
ISR(29)
ISR(30)
ISR(31)

isr_stub:
	pushal
	pushl %ds
	pushl %es
	pushl %fs
	pushl %gs
	movw $0x10, %ax
	movw %ax, %ds
	movw %ax, %es
	movw %ax, %fs
	movw %ax, %gs
	movl %esp, %eax
	pushl %eax
	movl $isrs_caller, %eax
	calll * %eax
	popl %eax
	popl %gs
	popl %fs
	popl %es
	popl %ds
	popal
	add $8, %esp
	iret
Sorry if I'm being a bit unclear about all of this, I just can't figure out what's wrong with it.

Re: ISR problems

Posted: Mon Sep 21, 2009 11:32 am
by Hangin10
Exceptions are going to repeat unless you fixed the problem caused by the code that caused the exception.

Upon return from a Divide by Zero exception, the next instruction that gets executed is going to be the one that divides by zero. This isn't generally recoverable. Similarly, after a Page Fault returns, the next instruction that executes is going to cause a page fault unless you fixed the problem (generally by putting a page wherever didn't have one. that's not the only reason for page faults though).

Re: ISR problems

Posted: Mon Sep 21, 2009 11:34 am
by tharkun
Thanks for the fast reply, but what should I do to fix the divide by zero error?

Re: ISR problems

Posted: Mon Sep 21, 2009 11:44 am
by Hangin10
Well, are you dividing by zero somewhere?

Generally one doesn't recover from divide by zero errors. The only way to do so would be to figure out the instruction that divided by zero and replace the zero with a different number; then you end up with bad math results for whatever program did the division. Usually programs are killed by the OS when a divide by zero happens (afaik).

If the interrupt is firing without you dividing anywhere, my best guess is that you haven't remapped the PIC. In protected mode, IRQs from devices overlap with exceptions, so you're probably getting Timer IRQs which will likely be interrupt zero until you remap them somewhere else (remapping the IRQs to start at INT 0x20 is common).