Page 1 of 1

long mode calling convention

Posted: Sat Jan 24, 2009 8:48 am
by furryfreak
Hi, is there a way to change GCC's long-mode calling convention to act more like the protected-mode calling convention?

When calling a function in protected-mode, all parameters passed to the function are pushed onto the stack before calling the function. In long-mode, the parameters are put in registers before the function call, then the function itself puts the values of those registers on the stack.

I looked around in GCC's documentation but didn't find anything... though I was only skimming through it quite quickly so I might of missed something. Hopefully theres a #pragma that'll do it, that way you could be selective and use the long-mode calling convention for assembly functions etc.

Re: long mode calling convention

Posted: Sat Jan 24, 2009 9:12 am
by 01000101
I've never heard of being able to. Why would you need that?

the x86_64 ABI specifies that integer arguments must be passed via registers (rdi,rsi,rdx...).
not sure how much help it would be for this, but have you looked at the x86_64 ABI?

You can change the method of function calls in GCC using pragmas, but I remember screwing around with enabling fast calls and such and found that they had minimal/no effect, and definitely nothing as drastic as what you want. If you *must* have that sort of inter-operability, then I'd suggest making some sort of function wrapper that checks to see what mode you're in, and if 64-bit, push the regs to the stack first, and if in 32-bit leave it alone.

Re: long mode calling convention

Posted: Sat Jan 24, 2009 12:35 pm
by furryfreak
Thanks, that ABI reference was very useful, though it'd still be nice to be able to force parameters to be passed via the stack.