title: x86_64: forcing gcc to pass arguments on the stack
body: <p>I'm working on a <code>setjmp</code>/<code>longjmp</code> custom implementation for x86-64 systems which saves the whole context of the CPU (namely, all xmm, fpu stack, etc; not only callee-save registers). This is written directly in assembly.</p>
  
  <p>The code works fine in minimal examples (when calling it directly from an assembly source). The problem arises when using it with C code, due to the way parameters are passed to the homebrew <code>setjmp</code>/<code>longjmp</code> functions. In fact, SysV ABI for x64_64 systems dictates that arguments should be passed via registers (if they are at most 6). The signature of my functions are:</p>
  
  <p><code>long long set_jmp(exec_context_t *env);</code><br>
  <code>__attribute__ ((__noreturn__)) void long_jmp(exec_context_t *env, long long val);</code></p>
  
  <p>Of course, this cannot work as is. In fact, when I enter <code>set_jmp</code>, <code>rdi</code> and <code>rsi</code> have already been clobbered to keep a pointer to <code>env</code> and <code>val</code>. The same applies to <code>long_jmp</code> with respect to <code>rdi</code>.</p>
  
  <p>Is there any way to force GCC, e.g. by relying on some attribute, to force argument passing via stack? This would be much more elegant than wrapping <code>set_jmp</code> and <code>long_jmp</code> with some define which manually pushes the clobbered registers on stack, so as to retrieve them later.</p>