Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / General Programming / Naked Functions Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
HRESULT

May 27, 2005, 12:04 PM

Hi!
what i'm trying to do is creating a neat interface between script and native c++ code. the VM exposes script object interfaces to c++ by creating a custom VTable. The VTable is a static table to functionpointers to a naked function written in ASM. this function reads out the this pointer and parameters according to the script function signature it retrieves from the VM and passes them to a private VM function that then marshals the parameters executes the script function.

Now the problem is: how do you write an inline-asm function that doesn't interfere with compiler optimizations and runtime checks? - meaning which registers do I have to save?
What I found out for VS 2003 (which i use) is that i have to save ESI if runtime checks are enabled, since, when the compiler calls a function it stores the previous ESP value in ESI and after returning, if these don't match anymore, throws a runtime error. Of course my code works now unter VS2003.
But what about other versions of the MS C++ compiler? which registers do i have to save?
and what about other compilers? (assuming that i port compiler-specific things such as the inline assembly)

 
Chris

May 27, 2005, 01:34 PM

For VS you've got to save everything except eax, ecx, edx. That is, you must save ebx,esi,edi,esp,ebp, and the direction flag (CLD).

This is true for versions as far back as Visual Studio 5, and includes the newest ones.

Other compilers, I don't know. gcc allows you to tell it what registers you don't preserve (clobber lists), Watcom C++ also did, but it's out of fashion nowadays. Intel is like MSVC, I'd bet.

 
tokjunior

May 27, 2005, 03:02 PM

pushad doesn't really take much time, so just use it.

 
 
HRESULT

May 28, 2005, 05:22 AM

thanks a lot for your quick and helpful responses :)

 
Chris

May 28, 2005, 08:06 AM

Thanks Roel, great document. Added it to my collection :-)

 
This thread contains 6 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.