interrupt handler problem which doesn't relate to hardware

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
firas981

interrupt handler problem which doesn't relate to hardware

Post 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
Curufir

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

Post 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).
firas981

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

Post 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
firas981

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

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

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

Post by Candy »

bochs said the CPU triple faulted. Normally a computer would reboot.

The CPU rebooted, and thus triple faulted...
firas981

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

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