syscall.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2004 Marco van de Voort
  5. member of the Free Pascal development team.
  6. The syscalls for the *BSD AMD64 rtl
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {
  14. Origin of this file: copied from linux/x86_64 dir, blended with the
  15. freebsd x86 changes and checked against objdump of a
  16. x86_64/freebsdprog
  17. - jge directly behind the syscall to branch on non-error
  18. - rcx is used as scratch reg (fpc/Linux-x86_64 uses edx)
  19. - More 6 and 7 param dosyscall because of the __syscall problem
  20. }
  21. {$ASMMODE GAS}
  22. function do_sysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  23. asm
  24. movq sysnr, %rax { Syscall number -> rax. }
  25. syscall { Do the system call. }
  26. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  27. movq %rax,%rcx
  28. movq FPC_THREADVAR_RELOCATE,%rax
  29. testq %rax,%rax
  30. jne .LThread
  31. movq %rcx,Errno+4
  32. jmp .LNoThread
  33. .LThread:
  34. pushq %rcx
  35. pushq Errno
  36. call *%rax
  37. popq %rcx
  38. movq %rcx,(%rax)
  39. .LNoThread:
  40. movq $-1,%rax
  41. movq rax,%rdx
  42. .LSyscOK:
  43. end;
  44. function do_sysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  45. asm
  46. movq sysnr, %rax { Syscall number -> rax. }
  47. movq param1, %rdi { shift arg1 - arg1. }
  48. syscall { Do the system call. }
  49. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  50. movq %rax,%rcx
  51. movq FPC_THREADVAR_RELOCATE,%rax
  52. testq %rax,%rax
  53. jne .LThread
  54. movq %rcx,Errno+4
  55. jmp .LNoThread
  56. .LThread:
  57. pushq %rcx
  58. pushq Errno
  59. call *%rax
  60. popq %rcx
  61. movq %rcx,(%rax)
  62. .LNoThread:
  63. movq $-1,%rax
  64. movq rax,%rdx
  65. .LSyscOK:
  66. end;
  67. function do_sysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  68. asm
  69. movq sysnr, %rax { Syscall number -> rax. }
  70. movq param1, %rdi { shift arg1 - arg2. }
  71. movq param2, %rsi
  72. mov %rcx,%r10
  73. syscall { Do the system call. }
  74. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  75. movq %rax,%rcx
  76. movq FPC_THREADVAR_RELOCATE,%rax
  77. testq %rax,%rax
  78. jne .LThread
  79. movq %rcx,Errno+4
  80. jmp .LNoThread
  81. .LThread:
  82. pushq %rcx
  83. pushq Errno
  84. call *%rax
  85. popq %rcx
  86. movq %rcx,(%rax)
  87. .LNoThread:
  88. movq $-1,%rax
  89. movq rax,%rdx
  90. .LSyscOK:
  91. end;
  92. function do_sysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  93. asm
  94. movq sysnr, %rax { Syscall number -> rax. }
  95. movq param1, %rdi { shift arg1 - arg3. }
  96. movq param2, %rsi
  97. movq param3, %rdx
  98. mov %rcx,%r10
  99. syscall { Do the system call. }
  100. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  101. movq %rax,%rcx
  102. movq FPC_THREADVAR_RELOCATE,%rax
  103. testq %rax,%rax
  104. jne .LThread
  105. movq %rcx,Errno+4
  106. jmp .LNoThread
  107. .LThread:
  108. pushq %rcx
  109. pushq Errno
  110. call *%rax
  111. popq %rcx
  112. movq %rcx,(%rax)
  113. .LNoThread:
  114. movq $-1,%rax
  115. movq rax,%rdx
  116. .LSyscOK:
  117. end;
  118. function do_sysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  119. asm
  120. movq sysnr, %rax { Syscall number -> rax. }
  121. movq param1, %rdi { shift arg1 - arg5. }
  122. movq param2, %rsi
  123. movq param3, %rdx
  124. movq param4, %r10
  125. mov %rcx,%r10
  126. syscall { Do the system call. }
  127. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  128. movq %rax,%rcx
  129. movq FPC_THREADVAR_RELOCATE,%rax
  130. testq %rax,%rax
  131. jne .LThread
  132. movq %rcx,Errno+4
  133. jmp .LNoThread
  134. .LThread:
  135. pushq %rcx
  136. pushq Errno
  137. call *%rax
  138. popq %rcx
  139. movq %rcx,(%rax)
  140. .LNoThread:
  141. movq $-1,%rax
  142. movq rax,%rdx
  143. .LSyscOK:
  144. end;
  145. function do_sysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  146. asm
  147. movq sysnr, %rax { Syscall number -> rax. }
  148. movq param1, %rdi { shift arg1 - arg5. }
  149. movq param2, %rsi
  150. movq param3, %rdx
  151. movq param4, %r10
  152. movq param5, %r8
  153. mov %rcx,%r10
  154. syscall { Do the system call. }
  155. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  156. movq %rax,%rcx
  157. movq FPC_THREADVAR_RELOCATE,%rax
  158. testq %rax,%rax
  159. jne .LThread
  160. movq %rcx,Errno+4
  161. jmp .LNoThread
  162. .LThread:
  163. pushq %rcx
  164. pushq Errno
  165. call *%rax
  166. popq %rcx
  167. movq %rcx,(%rax)
  168. .LNoThread:
  169. movq $-1,%rax
  170. movq rax,%rdx
  171. .LSyscOK:
  172. end;
  173. function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  174. asm
  175. movq sysnr, %rax { Syscall number -> rax. }
  176. movq param1, %rdi { shift arg1 - arg6. }
  177. movq param2, %rsi
  178. movq param3, %rdx
  179. movq param4, %r10
  180. movq param5, %r8
  181. movq param6, %r9
  182. mov %rcx,%r10
  183. syscall { Do the system call. }
  184. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  185. movq %rax,%rcx
  186. movq FPC_THREADVAR_RELOCATE,%rax
  187. testq %rax,%rax
  188. jne .LThread
  189. movq %rcx,Errno+4
  190. jmp .LNoThread
  191. .LThread:
  192. pushq %rcx
  193. pushq Errno
  194. call *%rax
  195. popq %rcx
  196. movq %rcx,(%rax)
  197. .LNoThread:
  198. movq $-1,%rax
  199. movq rax,%rdx
  200. .LSyscOK:
  201. end;
  202. procedure actualsyscall; assembler; {inline requires a dummy push IIRC}
  203. asm
  204. syscall
  205. jge .LSyscOK { branch to exit if ok, errorhandler otherwise}
  206. movq %rax,%rcx
  207. movq FPC_THREADVAR_RELOCATE,%rax
  208. testq %rax,%rax
  209. jne .LThread
  210. movq %rcx,Errno+4
  211. jmp .LNoThread
  212. .LThread:
  213. pushq %rcx
  214. pushq Errno
  215. call *%rax
  216. popq %rcx
  217. movq %rcx,(%rax)
  218. .LNoThread:
  219. movq $-1,%rax
  220. movq rax,%rdx
  221. .LSyscOK:
  222. end;
  223. function do__sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; {$ifndef VER1_0} oldfpccall;{$endif} external name 'FPC_DOSYS8';
  224. // Hmm, we have to do something different :)
  225. asm
  226. movq param8,%rax
  227. push %rax
  228. movq param7,%rax
  229. push %rax
  230. movq $syscall_nr__syscall, %rax
  231. mov %rcx,%r10
  232. call actualsyscall
  233. add $16,%rsp
  234. end;
  235. {
  236. $Log$
  237. Revision 1.2 2004-05-16 21:01:23 marco
  238. * syscallnr for __syscall entered
  239. Revision 1.1 2004/05/16 20:48:32 marco
  240. * Initial versions
  241. }