syscall.inc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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,%rdx
  27. {$ifdef FPC_PIC}
  28. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  29. movq (%rax),%rax
  30. {$ifndef FPC_STATICRIPFIXED}
  31. movq Errno@GOTPCREL(%rip),%r11
  32. {$else}
  33. leaq Errno(%rip),%r11
  34. {$endif}
  35. {$else FPC_PIC}
  36. movq fpc_threadvar_relocate_proc,%rax
  37. leaq Errno,%r11
  38. {$endif FPC_PIC}
  39. testq %rax,%rax
  40. jne .LThread
  41. movl %edx,8(%r11)
  42. jmp .LNoThread
  43. .LThread:
  44. pushq %rdx
  45. movq (%r11),%rdi
  46. call *%rax
  47. popq %rdx
  48. movl %edx,(%rax)
  49. .LNoThread:
  50. movq $-1,%rax
  51. .LSyscOK:
  52. end;
  53. function fpsysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS1'];
  54. asm
  55. movq sysnr,%rax { Syscall number -> rax. }
  56. movq param1,%rdi { shift arg1 - arg1. }
  57. syscall { Do the system call. }
  58. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  59. movq %rax,%rdx
  60. {$ifdef FPC_PIC}
  61. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  62. movq (%rax),%rax
  63. {$ifndef FPC_STATICRIPFIXED}
  64. movq Errno@GOTPCREL(%rip),%r11
  65. {$else}
  66. leaq Errno(%rip),%r11
  67. {$endif}
  68. {$else FPC_PIC}
  69. movq fpc_threadvar_relocate_proc,%rax
  70. leaq Errno,%r11
  71. {$endif FPC_PIC}
  72. testq %rax,%rax
  73. jne .LThread
  74. movl %edx,8(%r11)
  75. jmp .LNoThread
  76. .LThread:
  77. pushq %rdx
  78. movq (%r11),%rdi
  79. call *%rax
  80. popq %rdx
  81. movl %edx,(%rax)
  82. .LNoThread:
  83. movq $-1,%rax
  84. .LSyscOK:
  85. end;
  86. function fpsysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS2'];
  87. asm
  88. movq sysnr,%rax { Syscall number -> rax. }
  89. movq param1,%rdi { shift arg1 - arg2. }
  90. movq param2,%rsi
  91. syscall { Do the system call. }
  92. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  93. movq %rax,%rdx
  94. {$ifdef FPC_PIC}
  95. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  96. movq (%rax),%rax
  97. {$ifndef FPC_STATICRIPFIXED}
  98. movq Errno@GOTPCREL(%rip),%r11
  99. {$else}
  100. leaq Errno(%rip),%r11
  101. {$endif}
  102. {$else FPC_PIC}
  103. movq fpc_threadvar_relocate_proc,%rax
  104. leaq Errno,%r11
  105. {$endif FPC_PIC}
  106. testq %rax,%rax
  107. jne .LThread
  108. movl %edx,8(%r11)
  109. jmp .LNoThread
  110. .LThread:
  111. pushq %rdx
  112. movq (%r11),%rdi
  113. call *%rax
  114. popq %rdx
  115. movl %edx,(%rax)
  116. .LNoThread:
  117. movq $-1,%rax
  118. .LSyscOK:
  119. end;
  120. function fpsysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS3'];
  121. asm
  122. movq sysnr,%rax { Syscall number -> rax. }
  123. movq param1,%rdi { shift arg1 - arg3. }
  124. movq param2,%rsi
  125. movq param3,%rdx
  126. syscall { Do the system call. }
  127. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  128. movq %rax,%rdx
  129. {$ifdef FPC_PIC}
  130. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  131. movq (%rax),%rax
  132. {$ifndef FPC_STATICRIPFIXED}
  133. movq Errno@GOTPCREL(%rip),%r11
  134. {$else}
  135. leaq Errno(%rip),%r11
  136. {$endif}
  137. {$else FPC_PIC}
  138. movq fpc_threadvar_relocate_proc,%rax
  139. leaq Errno,%r11
  140. {$endif FPC_PIC}
  141. testq %rax,%rax
  142. jne .LThread
  143. movl %edx,8(%r11)
  144. jmp .LNoThread
  145. .LThread:
  146. pushq %rdx
  147. movq (%r11),%rdi
  148. call *%rax
  149. popq %rdx
  150. movl %edx,(%rax)
  151. .LNoThread:
  152. movq $-1,%rax
  153. .LSyscOK:
  154. end;
  155. function fpsysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS4'];
  156. asm
  157. movq sysnr,%rax { Syscall number -> rax. }
  158. movq param1,%rdi { shift arg1 - arg5. }
  159. movq param2,%rsi
  160. movq param3,%rdx
  161. movq param4,%r10
  162. syscall { Do the system call. }
  163. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  164. movq %rax,%rdx
  165. {$ifdef FPC_PIC}
  166. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  167. movq (%rax),%rax
  168. {$ifndef FPC_STATICRIPFIXED}
  169. movq Errno@GOTPCREL(%rip),%r11
  170. {$else}
  171. leaq Errno(%rip),%r11
  172. {$endif}
  173. {$else FPC_PIC}
  174. movq fpc_threadvar_relocate_proc,%rax
  175. leaq Errno,%r11
  176. {$endif FPC_PIC}
  177. testq %rax,%rax
  178. jne .LThread
  179. movl %edx,8(%r11)
  180. jmp .LNoThread
  181. .LThread:
  182. pushq %rdx
  183. movq (%r11),%rdi
  184. call *%rax
  185. popq %rdx
  186. movl %edx,(%rax)
  187. .LNoThread:
  188. movq $-1,%rax
  189. .LSyscOK:
  190. end;
  191. function fpsysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS5'];
  192. asm
  193. movq sysnr,%rax { Syscall number -> rax. }
  194. movq param1,%rdi { shift arg1 - arg5. }
  195. movq param2,%rsi
  196. movq param3,%rdx
  197. movq param4,%r10
  198. movq param5,%r8
  199. syscall { Do the system call. }
  200. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  201. movq %rax,%rdx
  202. {$ifdef FPC_PIC}
  203. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  204. movq (%rax),%rax
  205. {$ifndef FPC_STATICRIPFIXED}
  206. movq Errno@GOTPCREL(%rip),%r11
  207. {$else}
  208. leaq Errno(%rip),%r11
  209. {$endif}
  210. {$else FPC_PIC}
  211. movq fpc_threadvar_relocate_proc,%rax
  212. leaq Errno,%r11
  213. {$endif FPC_PIC}
  214. testq %rax,%rax
  215. jne .LThread
  216. movl %edx,8(%r11)
  217. jmp .LNoThread
  218. .LThread:
  219. pushq %rdx
  220. movq (%r11),%rdi
  221. call *%rax
  222. popq %rdx
  223. movl %edx,(%rax)
  224. .LNoThread:
  225. movq $-1,%rax
  226. .LSyscOK:
  227. end;
  228. function fpsysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS6'];
  229. asm
  230. movq sysnr,%rax { Syscall number -> rax. }
  231. movq param1,%rdi { shift arg1 - arg6. }
  232. movq param2,%rsi
  233. movq param3,%rdx
  234. movq param4,%r10
  235. movq param5,%r8
  236. movq param6,%r9
  237. syscall { Do the system call. }
  238. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  239. movq %rax,%rdx
  240. {$ifdef FPC_PIC}
  241. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  242. movq (%rax),%rax
  243. {$ifndef FPC_STATICRIPFIXED}
  244. movq Errno@GOTPCREL(%rip),%r11
  245. {$else}
  246. leaq Errno(%rip),%r11
  247. {$endif}
  248. {$else FPC_PIC}
  249. movq fpc_threadvar_relocate_proc,%rax
  250. leaq Errno,%r11
  251. {$endif FPC_PIC}
  252. testq %rax,%rax
  253. jne .LThread
  254. movl %edx,8(%r11)
  255. jmp .LNoThread
  256. .LThread:
  257. pushq %rdx
  258. movq (%r11),%rdi
  259. call *%rax
  260. popq %rdx
  261. movl %edx,(%rax)
  262. .LNoThread:
  263. movq $-1,%rax
  264. .LSyscOK:
  265. end;
  266. function fp_sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS7'];
  267. asm
  268. subq $0x10,%rsp
  269. movq sysnr,%rax { Syscall number -> rax. }
  270. movq param1,%rdi { shift arg1 - arg6. }
  271. movq param2,%rsi
  272. movq param3,%rdx
  273. movq param4,%r10
  274. movq param5,%r8
  275. movq param6,%r9
  276. movq param7,%r11
  277. movq %r11,8(%rsp)
  278. syscall { Do the system call. }
  279. jnb .LSyscOK { branch to exit if ok, errorhandler otherwise}
  280. movq %rax,%rdx
  281. {$ifdef FPC_PIC}
  282. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  283. movq (%rax),%rax
  284. {$ifndef FPC_STATICRIPFIXED}
  285. movq Errno@GOTPCREL(%rip),%r11
  286. {$else}
  287. leaq Errno(%rip),%r11
  288. {$endif}
  289. {$else FPC_PIC}
  290. movq fpc_threadvar_relocate_proc,%rax
  291. leaq Errno,%r11
  292. {$endif FPC_PIC}
  293. testq %rax,%rax
  294. jne .LThread
  295. movl %edx,8(%r11)
  296. jmp .LNoThread
  297. .LThread:
  298. pushq %rdx
  299. movq (%r11),%rdi
  300. call *%rax
  301. popq %rdx
  302. movl %edx,(%rax)
  303. .LNoThread:
  304. movq $-1,%rax
  305. .LSyscOK:
  306. addq $0x10,%rsp
  307. end;