syscall.inc 8.3 KB

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