Page 1 of 1

interrupt handler problem which doesn't relate to hardware

Posted: Sun Jul 04, 2004 11:19 am
by firas981
This is a code I wrote to test my kb interrupt handler
I invoked the kb interrupt handler by software , not by IRQs so that IDT problems are discarded
( as mega-tokyo FAQs recommend ) :



//interrupts.c

asm volatile ( "jmp KB_IRQ1_Handler_Wrapper" ) ;
BOCHSHALT ;// This is a c macro written by Brendan to breakpoint into c code
??? //, at any rate it stops execution here.


;int_wrappers.asm
GLOBAL _KB_IRQ1_Handler_Wrapper
EXTERN KB_IRQ1_Handler


ALIGN 4

KB_IRQ1_Handler_Wrapper :
pushad
call KB_IRQ1_Handler
popad
???;after debugging using bochs I found that
???;if you put "hlt" here then no exceptions occur , but
???;if you continue then exception will be raised .
iret

Re:interrupt handler problem which doesn't relate to hardwar

Posted: Sun Jul 04, 2004 11:58 am
by Curufir
IRET will pop the eflags off the stack as well as the return descriptor/address. Since you've just jumped directly to the routine eflags was never pushed onto the stack, so you're popping junk into eflags. At this point the processor is likely to keel over and die. For testing purposes either replace IRET with RET, put the EFLAGS register on the stack manually, or call using a software interrupt (Assuming you've got your IDT setup).

Re:interrupt handler problem which doesn't relate to hardwar

Posted: Wed Jul 07, 2004 11:54 am
by firas981
thank you , I've put ret instead of iret & call instead of jmp , so the test succeeded .
???
???In real world , as you know I have to put iret , and when pressing any key , the handler should be called
???however , bochs reported the following error :

???[CPU ] exception(): 3rd (13) exception with no resolution

Re:interrupt handler problem which doesn't relate to hardwar

Posted: Fri Jul 09, 2004 6:19 pm
by firas981
Another thing to say :
When I tested the os by booting my pc using it ( not using bochs ..) , it booted successfully , but rebooted when press any key

Re:interrupt handler problem which doesn't relate to hardwar

Posted: Sat Jul 10, 2004 6:15 am
by Candy
bochs said the CPU triple faulted. Normally a computer would reboot.

The CPU rebooted, and thus triple faulted...

Re:interrupt handler problem which doesn't relate to hardwar

Posted: Wed Jul 14, 2004 2:39 pm
by firas981
thanks guys , I've put call instaed of jmp and ret instead of iret , so the problem is solved .
i.e. I could call my handlers from software , but I couldn't call them by hardware ( IDT ) ..
however this is not the subject of this thread as the "Subject"
above says .

thanks a lot