syscall.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2004 Marco van de Voort
  4. member of the Free Pascal development team.
  5. The syscalls for the *BSD AMD64 rtl
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. Origin of this file: copied from linux/x86_64 dir, blended with the
  14. freebsd x86 changes and checked against objdump of a
  15. x86_64/freebsdprog
  16. - jge directly behind the syscall to branch on non-error
  17. - rcx is used as scratch reg (fpc/Linux-x86_64 uses edx)
  18. - More 6 and 7 param dosyscall because of the __syscall problem
  19. }
  20. {$ASMMODE GAS}
  21. function fpsysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS0'];
  22. asm
  23. movq sysnr,%rax { Syscall number -> rax. }
  24. syscall { Do the system call. }
  25. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  26. movq %rax,%rdi
  27. call SetErrno
  28. movq $-1,%rax
  29. .LSyscOK:
  30. end;
  31. function fpsysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS1'];
  32. asm
  33. movq sysnr,%rax { Syscall number -> rax. }
  34. movq param1,%rdi { shift arg1 - arg1. }
  35. syscall { Do the system call. }
  36. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  37. movq %rax,%rdi
  38. call SetErrno
  39. movq $-1,%rax
  40. .LSyscOK:
  41. end;
  42. function fpsysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS2'];
  43. asm
  44. movq sysnr,%rax { Syscall number -> rax. }
  45. movq param1,%rdi { shift arg1 - arg2. }
  46. movq param2,%rsi
  47. syscall { Do the system call. }
  48. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  49. movq %rax,%rdi
  50. call SetErrno
  51. movq $-1,%rax
  52. .LSyscOK:
  53. end;
  54. function fpsysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS3'];
  55. asm
  56. movq sysnr,%rax { Syscall number -> rax. }
  57. movq param1,%rdi { shift arg1 - arg3. }
  58. movq param2,%rsi
  59. movq param3,%rdx
  60. syscall { Do the system call. }
  61. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  62. movq %rax,%rdi
  63. call SetErrno
  64. movq $-1,%rax
  65. .LSyscOK:
  66. end;
  67. function fpsysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS4'];
  68. asm
  69. movq sysnr,%rax { Syscall number -> rax. }
  70. movq param1,%rdi { shift arg1 - arg5. }
  71. movq param2,%rsi
  72. movq param3,%rdx
  73. movq param4,%r10
  74. syscall { Do the system call. }
  75. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  76. movq %rax,%rdi
  77. call SetErrno
  78. movq $-1,%rax
  79. .LSyscOK:
  80. end;
  81. function fpsysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS5'];
  82. asm
  83. movq sysnr,%rax { Syscall number -> rax. }
  84. movq param1,%rdi { shift arg1 - arg5. }
  85. movq param2,%rsi
  86. movq param3,%rdx
  87. movq param4,%r10
  88. movq param5,%r8
  89. syscall { Do the system call. }
  90. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  91. movq %rax,%rdi
  92. call SetErrno
  93. movq $-1,%rax
  94. .LSyscOK:
  95. end;
  96. function fpsysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS6'];
  97. asm
  98. movq sysnr,%rax { Syscall number -> rax. }
  99. movq param1,%rdi { shift arg1 - arg6. }
  100. movq param2,%rsi
  101. movq param3,%rdx
  102. movq param4,%r10
  103. movq param5,%r8
  104. movq param6,%r9
  105. syscall { Do the system call. }
  106. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  107. movq %rax,%rdi
  108. call SetErrno
  109. movq $-1,%rax
  110. .LSyscOK:
  111. end;
  112. function fp_sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS7'];
  113. asm
  114. subq $0x10,%rsp
  115. movq sysnr,%rax { Syscall number -> rax. }
  116. movq param1,%rdi { shift arg1 - arg6. }
  117. movq param2,%rsi
  118. movq param3,%rdx
  119. movq param4,%r10
  120. movq param5,%r8
  121. movq param6,%r9
  122. movq param7,%r11
  123. movq %r11,8(%rsp)
  124. syscall { Do the system call. }
  125. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  126. movq %rax,%rdi
  127. call SetErrno
  128. movq $-1,%rax
  129. .LSyscOK:
  130. addq $0x10,%rsp
  131. end;