Tutorial 15 error

OS Design, Theory, and Programming

Moderator: Moderators

Tutorial 15 error

Postby hahnski07 » Thu Oct 01, 2009 3:17 am

In Tutorial 15 you listed the default interrupt handler code as this:
Code: Select all
void int_handler_5 () {

   _asm add esp, 12
   _asm pushad

   // do whatever...

   _asm popad
   _asm iretd
}


The only way I could get it to work was for me to remove the add esp, 12 line.

Explanations?
hahnski07
 
Posts: 19
Joined: Sat Jul 18, 2009 1:50 am

Re: Tutorial 15 error

Postby Mike » Thu Oct 01, 2009 3:38 am

Hello,

Its usually recommended not changing the stack like the series does. A better workaround is either using an assembly language file for the IRQ handler and linking it in, or using __declspec (naked) (MSVC++ specific) which allows the function to be treated inline and you do not need to touch the stack
Code: Select all
__declspec (naked) void int_handler_5 () {

   // do whatever...

   _asm iretd
}
The reason for the crash is do to the _asm add esp, 12 changing the position of esp to a different value then what your current compiler configuration is set to output. add esp, 12 reverses the data pushed on the stack by the eprologue code that MSVC++ adds to the function. If it pushes a different amount of values then 12 bytes, then the instruction will, basically, make your stack (return eip) invalid causing a crash.

Using _declspec (naked) or assembly language eliminates the need to touch the stack.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Re: Tutorial 15 error

Postby hahnski07 » Fri Oct 02, 2009 2:50 am

Well that makes sense because my entire kernel is written in assembly.
hahnski07
 
Posts: 19
Joined: Sat Jul 18, 2009 1:50 am


Return to Advanced OS Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron