ABI question, porting ports to amd64

Marco van de Voort marcov at stack.nl
Sat May 15 16:19:56 PDT 2004


I read the ABI info on x86-64.org, and objdumped some linux and freebsd
code, and I ran into a linux<->freebsd difference something I can't figure
out:

There is a mov %rcx,%r10 instruction before each syscall on the testbox I
use (which is plain 5.2.1 afaik). The linux code doesn't have this mov
afaik. Moreover, it seems to serve no purpose.

I tried to figure out why this is done, but have failed. 
Can somebody shed some light on this?

P.s. this is for amd64 version of the fpc-devel port, a Delphi compiler,
which has the possibillity of doing syscalls besides linking to libc.

Example: sys_select:

0000000000400264 <__sys_select>:
  400264:       48 c7 c0 5d 00 00 00    mov    $0x5d,%rax
  40026b:       49 89 ca                mov    %rcx,%r10	<---- this mov
  40026e:       0f 05                   syscall
  400270:       72 01                   jb     400273 <__sys_select+0xf>
  400272:       c3                      retq
  400273:       e9 00 00 00 00          jmpq   400278 <.cerror>

0000000000400278 <.cerror>:
  400278:       50                      push   %rax
  400279:       e8 0e 03 00 00          callq  40058c <__error_unthreaded>
  40027e:       59                      pop    %rcx
  40027f:       48 89 08                mov    %rcx,(%rax)
  400282:       48 c7 c0 ff ff ff ff    mov    $0xffffffffffffffff,%rax
  400289:       48 c7 c2 ff ff ff ff    mov    $0xffffffffffffffff,%rdx
  400290:       c3                      retq

calling code:

  40023a:       48 8d 4c 24 10          lea    0x10(%rsp,1),%rcx
  40023f:       48 8d 94 24 90 00 00    lea    0x90(%rsp,1),%rdx
  400246:       00
  400247:       48 8d b4 24 10 01 00    lea    0x110(%rsp,1),%rsi
  40024e:       00
  40024f:       bf 05 00 00 00          mov    $0x5,%edi
  400254:       e8 0b 00 00 00          callq  400264 <__sys_select>


More information about the freebsd-amd64 mailing list