OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 8:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: problem in interrupt handler
PostPosted: Wed May 02, 2012 3:51 am 
Offline
Member
Member

Joined: Wed Apr 04, 2012 9:12 pm
Posts: 73
Hi,

I am trying to set up interrupt handlers and get interrupts working in my operating system.
But I am having some problem due to which bochs restarts.
Following is the code for interrupt handlers

Quote:
extern test_interrupt_handler

%macro isr 1
global int%1_handler

int%1_handler:
cli
pusha
push %1
call test_interrupt_handler
pop ax
popa
sti
iret
%endmacro

isr 0
isr 1
..
isr 31



I have defined handlers for all exceptions 0 through 31. Each handler pushes the interrupt number on stack and calls the function - test_interrupt_handler which is a C function that reads the interrupt number from stack and displays it.


Quote:
void test_interrupt_handler(uint16 intrnum)
{
ConsoleWriteString("\nInterrupt Number: "); //print string
ConsoleWriteAsDec(intrnum); // print in decimal format
ConsoleWriteChar('\n'); //print character
}


The problem is that when I generate any exception from main using INT instruction , the corresponding handler runs but the system restarts after that. I thought that it must be one of the exceptions but none of handler gets called after the first handler. I know that the popping value into ax is causing the problem as when I comment it the code runs fine. But I was thinking that pusha and popa instructions should restore the ax back to its original value and there shouldn't be any problem. I am unable to understand the cause of the problem.

Thanks

_________________
- Thanks
Vaibhav jain


Top
 Profile  
 
 Post subject: Re: problem in interrupt handler
PostPosted: Wed May 02, 2012 4:35 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Do you know the difference between IRET and IRETD?

(and please remove the colours in your signature if you expect me to be able to read it)

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: problem in interrupt handler
PostPosted: Wed May 02, 2012 4:47 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
pop ax may get you in trouble, are you sure you want 16bit pop? are you in real mode?


Top
 Profile  
 
 Post subject: Re: problem in interrupt handler
PostPosted: Wed May 02, 2012 6:18 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
Looks perfectly fine for 16 bit / real mode interrupt handling to me. The "iret", "pop ax" and 16 bit parameter size in "test_interrupt_handler(uint16 intrnum)" are pretty consistent.

Two questions: Did you make sure that your assembler and compiler both generate 16 bit code? Does your compiler prepend an underscore to function names?

_________________
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS


Top
 Profile  
 
 Post subject: Re: problem in interrupt handler
PostPosted: Wed May 02, 2012 11:57 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
C code and Bochs actually restarting usually means protected mode (because both are difficult to do in real mode), which in turn makes it unlikely that 16 bits is correct.

(And either way, intnum should be an uint8_t, not 16 or 32 bits because there are only 256 interrupts).

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: problem in interrupt handler
PostPosted: Wed May 02, 2012 4:23 pm 
Offline
Member
Member

Joined: Wed Apr 04, 2012 9:12 pm
Posts: 73
Thanks! I got it working. I was thinking that push would by default push 16 bit value.
I am sorry I did not mention that I am working in 32 bit mode. As far as IRET is concerned I saw tutorials
using IRET in 32 but mode so I used it too and it is working fine.

_________________
- Thanks
Vaibhav jain


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 167 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group