syscall.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 do_sysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  22. asm
  23. movq sysnr, %rax { Syscall number -> rax. }
  24. syscall { Do the system call. }
  25. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  26. movq %rax,%rcx
  27. movq FPC_THREADVAR_RELOCATE,%rax
  28. testq %rax,%rax
  29. jne .LThread
  30. movq %rcx,Errno+8
  31. jmp .LNoThread
  32. .LThread:
  33. pushq %rcx
  34. pushq Errno
  35. call *%rax
  36. popq %rcx
  37. movq %rcx,(%rax)
  38. .LNoThread:
  39. movq $-1,%rax
  40. movq rax,%rdx
  41. .LSyscOK:
  42. end;
  43. function do_sysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  44. asm
  45. movq sysnr, %rax { Syscall number -> rax. }
  46. movq param1, %rdi { shift arg1 - arg1. }
  47. syscall { Do the system call. }
  48. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  49. movq %rax,%rcx
  50. movq FPC_THREADVAR_RELOCATE,%rax
  51. testq %rax,%rax
  52. jne .LThread
  53. movq %rcx,Errno+8
  54. jmp .LNoThread
  55. .LThread:
  56. pushq %rcx
  57. pushq Errno
  58. call *%rax
  59. popq %rcx
  60. movq %rcx,(%rax)
  61. .LNoThread:
  62. movq $-1,%rax
  63. movq rax,%rdx
  64. .LSyscOK:
  65. end;
  66. function do_sysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  67. asm
  68. movq sysnr, %rax { Syscall number -> rax. }
  69. movq param1, %rdi { shift arg1 - arg2. }
  70. movq param2, %rsi
  71. mov %rcx,%r10
  72. syscall { Do the system call. }
  73. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  74. movq %rax,%rcx
  75. movq FPC_THREADVAR_RELOCATE,%rax
  76. testq %rax,%rax
  77. jne .LThread
  78. movq %rcx,Errno+8
  79. jmp .LNoThread
  80. .LThread:
  81. pushq %rcx
  82. pushq Errno
  83. call *%rax
  84. popq %rcx
  85. movq %rcx,(%rax)
  86. .LNoThread:
  87. movq $-1,%rax
  88. movq rax,%rdx
  89. .LSyscOK:
  90. end;
  91. function do_sysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  92. asm
  93. movq sysnr, %rax { Syscall number -> rax. }
  94. movq param1, %rdi { shift arg1 - arg3. }
  95. movq param2, %rsi
  96. movq param3, %rdx
  97. mov %rcx,%r10
  98. syscall { Do the system call. }
  99. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  100. movq %rax,%rcx
  101. movq FPC_THREADVAR_RELOCATE,%rax
  102. testq %rax,%rax
  103. jne .LThread
  104. movq %rcx,Errno+8
  105. jmp .LNoThread
  106. .LThread:
  107. pushq %rcx
  108. pushq Errno
  109. call *%rax
  110. popq %rcx
  111. movq %rcx,(%rax)
  112. .LNoThread:
  113. movq $-1,%rax
  114. movq rax,%rdx
  115. .LSyscOK:
  116. end;
  117. function do_sysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  118. asm
  119. movq sysnr, %rax { Syscall number -> rax. }
  120. movq param1, %rdi { shift arg1 - arg5. }
  121. movq param2, %rsi
  122. movq param3, %rdx
  123. movq param4, %r10
  124. mov %rcx,%r10
  125. syscall { Do the system call. }
  126. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  127. movq %rax,%rcx
  128. movq FPC_THREADVAR_RELOCATE,%rax
  129. testq %rax,%rax
  130. jne .LThread
  131. movq %rcx,Errno+8
  132. jmp .LNoThread
  133. .LThread:
  134. pushq %rcx
  135. pushq Errno
  136. call *%rax
  137. popq %rcx
  138. movq %rcx,(%rax)
  139. .LNoThread:
  140. movq $-1,%rax
  141. movq rax,%rdx
  142. .LSyscOK:
  143. end;
  144. function do_sysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  145. asm
  146. movq sysnr, %rax { Syscall number -> rax. }
  147. movq param1, %rdi { shift arg1 - arg5. }
  148. movq param2, %rsi
  149. movq param3, %rdx
  150. movq param4, %r10
  151. movq param5, %r8
  152. mov %rcx,%r10
  153. syscall { Do the system call. }
  154. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  155. movq %rax,%rcx
  156. movq FPC_THREADVAR_RELOCATE,%rax
  157. testq %rax,%rax
  158. jne .LThread
  159. movq %rcx,Errno+8
  160. jmp .LNoThread
  161. .LThread:
  162. pushq %rcx
  163. pushq Errno
  164. call *%rax
  165. popq %rcx
  166. movq %rcx,(%rax)
  167. .LNoThread:
  168. movq $-1,%rax
  169. movq rax,%rdx
  170. .LSyscOK:
  171. end;
  172. function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  173. asm
  174. movq sysnr, %rax { Syscall number -> rax. }
  175. movq param1, %rdi { shift arg1 - arg6. }
  176. movq param2, %rsi
  177. movq param3, %rdx
  178. movq param4, %r10
  179. movq param5, %r8
  180. movq param6, %r9
  181. mov %rcx,%r10
  182. syscall { Do the system call. }
  183. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  184. movq %rax,%rcx
  185. movq FPC_THREADVAR_RELOCATE,%rax
  186. testq %rax,%rax
  187. jne .LThread
  188. movq %rcx,Errno+8
  189. jmp .LNoThread
  190. .LThread:
  191. pushq %rcx
  192. pushq Errno
  193. call *%rax
  194. popq %rcx
  195. movq %rcx,(%rax)
  196. .LNoThread:
  197. movq $-1,%rax
  198. movq rax,%rdx
  199. .LSyscOK:
  200. end;
  201. procedure actualsyscall; assembler; {inline requires a dummy push IIRC}
  202. asm
  203. syscall
  204. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  205. movq %rax,%rcx
  206. movq FPC_THREADVAR_RELOCATE,%rax
  207. testq %rax,%rax
  208. jne .LThread
  209. movq %rcx,Errno+8
  210. jmp .LNoThread
  211. .LThread:
  212. pushq %rcx
  213. pushq Errno
  214. call *%rax
  215. popq %rcx
  216. movq %rcx,(%rax)
  217. .LNoThread:
  218. movq $-1,%rax
  219. movq rax,%rdx
  220. .LSyscOK:
  221. end;
  222. function do__sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; oldfpccall; external name 'FPC_DOSYS8';
  223. // Hmm, we have to do something different :)
  224. asm
  225. movq param8,%rax
  226. push %rax
  227. movq param7,%rax
  228. push %rax
  229. movq $syscall_nr__syscall, %rax
  230. mov %rcx,%r10
  231. call actualsyscall
  232. add $16,%rsp
  233. end;