syscall.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. member of the Free Pascal development team.
  5. The syscalls for the new RTL, moved to platform dependant dir.
  6. Old linux calling convention is stil kept.
  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. {$ASMMODE GAS}
  14. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  15. asm
  16. movq sysnr, %rax { Syscall number -> rax. }
  17. syscall { Do the system call. }
  18. cmpq $-4095, %rax { Check %rax for error. }
  19. jnae .LSyscOK { Jump to error handler if error. }
  20. negq %rax
  21. movq %rax,%rdx
  22. {$ifdef FPC_PIC}
  23. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  24. movq (%rax),%rax
  25. movq Errno@GOTPCREL(%rip),%r11
  26. {$else FPC_PIC}
  27. movq fpc_threadvar_relocate_proc,%rax
  28. leaq Errno,%r11
  29. {$endif FPC_PIC}
  30. testq %rax,%rax
  31. jne .LThread
  32. movl %edx,8(%r11)
  33. jmp .LNoThread
  34. .LThread:
  35. pushq %rdx
  36. movq (%r11),%rdi
  37. call *%rax
  38. popq %rdx
  39. movl %edx,(%rax)
  40. .LNoThread:
  41. movq $-1,%rax
  42. .LSyscOK:
  43. end;
  44. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  45. asm
  46. movq sysnr, %rax { Syscall number -> rax. }
  47. movq param1, %rdi { shift arg1 - arg5. }
  48. syscall { Do the system call. }
  49. cmpq $-4095, %rax { Check %rax for error. }
  50. jnae .LSyscOK { Jump to error handler if error. }
  51. negq %rax
  52. movq %rax,%rdx
  53. {$ifdef FPC_PIC}
  54. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  55. movq (%rax),%rax
  56. movq Errno@GOTPCREL(%rip),%r11
  57. {$else FPC_PIC}
  58. movq fpc_threadvar_relocate_proc,%rax
  59. leaq Errno,%r11
  60. {$endif FPC_PIC}
  61. testq %rax,%rax
  62. jne .LThread
  63. movl %edx,8(%r11)
  64. jmp .LNoThread
  65. .LThread:
  66. pushq %rdx
  67. movq (%r11),%rdi
  68. call *%rax
  69. popq %rdx
  70. movl %edx,(%rax)
  71. .LNoThread:
  72. movq $-1,%rax
  73. .LSyscOK:
  74. end;
  75. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  76. asm
  77. movq sysnr, %rax { Syscall number -> rax. }
  78. movq param1, %rdi { shift arg1 - arg5. }
  79. movq param2, %rsi
  80. syscall { Do the system call. }
  81. cmpq $-4095, %rax { Check %rax for error. }
  82. jnae .LSyscOK { Jump to error handler if error. }
  83. negq %rax
  84. movq %rax,%rdx
  85. {$ifdef FPC_PIC}
  86. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  87. movq (%rax),%rax
  88. movq Errno@GOTPCREL(%rip),%r11
  89. {$else FPC_PIC}
  90. movq fpc_threadvar_relocate_proc,%rax
  91. leaq Errno,%r11
  92. {$endif FPC_PIC}
  93. testq %rax,%rax
  94. jne .LThread
  95. movl %edx,8(%r11)
  96. jmp .LNoThread
  97. .LThread:
  98. pushq %rdx
  99. movq (%r11),%rdi
  100. call *%rax
  101. popq %rdx
  102. movl %edx,(%rax)
  103. .LNoThread:
  104. movq $-1,%rax
  105. .LSyscOK:
  106. end;
  107. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  108. asm
  109. movq sysnr, %rax { Syscall number -> rax. }
  110. movq param1, %rdi { shift arg1 - arg5. }
  111. movq param2, %rsi
  112. movq param3, %rdx
  113. syscall { Do the system call. }
  114. cmpq $-4095, %rax { Check %rax for error. }
  115. jnae .LSyscOK { Jump to error handler if error. }
  116. negq %rax
  117. movq %rax,%rdx
  118. {$ifdef FPC_PIC}
  119. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  120. movq (%rax),%rax
  121. movq Errno@GOTPCREL(%rip),%r11
  122. {$else FPC_PIC}
  123. movq fpc_threadvar_relocate_proc,%rax
  124. leaq Errno,%r11
  125. {$endif FPC_PIC}
  126. testq %rax,%rax
  127. jne .LThread
  128. movl %edx,8(%r11)
  129. jmp .LNoThread
  130. .LThread:
  131. pushq %rdx
  132. movq (%r11),%rdi
  133. call *%rax
  134. popq %rdx
  135. movl %edx,(%rax)
  136. .LNoThread:
  137. movq $-1,%rax
  138. .LSyscOK:
  139. end;
  140. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  141. asm
  142. movq sysnr, %rax { Syscall number -> rax. }
  143. movq param1, %rdi { shift arg1 - arg5. }
  144. movq param2, %rsi
  145. movq param3, %rdx
  146. movq param4, %r10
  147. syscall { Do the system call. }
  148. cmpq $-4095, %rax { Check %rax for error. }
  149. jnae .LSyscOK { Jump to error handler if error. }
  150. negq %rax
  151. movq %rax,%rdx
  152. {$ifdef FPC_PIC}
  153. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  154. movq (%rax),%rax
  155. movq Errno@GOTPCREL(%rip),%r11
  156. {$else FPC_PIC}
  157. movq fpc_threadvar_relocate_proc,%rax
  158. leaq Errno,%r11
  159. {$endif FPC_PIC}
  160. testq %rax,%rax
  161. jne .LThread
  162. movl %edx,8(%r11)
  163. jmp .LNoThread
  164. .LThread:
  165. pushq %rdx
  166. movq (%r11),%rdi
  167. call *%rax
  168. popq %rdx
  169. movl %edx,(%rax)
  170. .LNoThread:
  171. movq $-1,%rax
  172. .LSyscOK:
  173. end;
  174. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  175. asm
  176. movq sysnr, %rax { Syscall number -> rax. }
  177. movq param1, %rdi { shift arg1 - arg5. }
  178. movq param2, %rsi
  179. movq param3, %rdx
  180. movq param4, %r10
  181. movq param5, %r8
  182. syscall { Do the system call. }
  183. cmpq $-4095, %rax { Check %rax for error. }
  184. jnae .LSyscOK { Jump to error handler if error. }
  185. negq %rax
  186. movq %rax,%rdx
  187. {$ifdef FPC_PIC}
  188. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  189. movq (%rax),%rax
  190. movq Errno@GOTPCREL(%rip),%r11
  191. {$else FPC_PIC}
  192. movq fpc_threadvar_relocate_proc,%rax
  193. leaq Errno,%r11
  194. {$endif FPC_PIC}
  195. testq %rax,%rax
  196. jne .LThread
  197. movl %edx,8(%r11)
  198. jmp .LNoThread
  199. .LThread:
  200. pushq %rdx
  201. movq (%r11),%rdi
  202. call *%rax
  203. popq %rdx
  204. movl %edx,(%rax)
  205. .LNoThread:
  206. movq $-1,%rax
  207. .LSyscOK:
  208. end;
  209. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  210. asm
  211. movq sysnr, %rax { Syscall number -> rax. }
  212. movq param1, %rdi { shift arg1 - arg5. }
  213. movq param2, %rsi
  214. movq param3, %rdx
  215. movq param4, %r10
  216. movq param5, %r8
  217. movq param6, %r9
  218. syscall { Do the system call. }
  219. cmpq $-4095, %rax { Check %rax for error. }
  220. jnae .LSyscOK { Jump to error handler if error. }
  221. negq %rax
  222. movq %rax,%rdx
  223. {$ifdef FPC_PIC}
  224. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  225. movq (%rax),%rax
  226. movq Errno@GOTPCREL(%rip),%r11
  227. {$else FPC_PIC}
  228. movq fpc_threadvar_relocate_proc,%rax
  229. leaq Errno,%r11
  230. {$endif FPC_PIC}
  231. testq %rax,%rax
  232. jne .LThread
  233. movl %edx,8(%r11)
  234. jmp .LNoThread
  235. .LThread:
  236. pushq %rdx
  237. movq (%r11),%rdi
  238. call *%rax
  239. popq %rdx
  240. movl %edx,(%rax)
  241. .LNoThread:
  242. movq $-1,%rax
  243. .LSyscOK:
  244. end;
  245. {No debugging for syslinux include !}
  246. {$IFDEF SYS_LINUX}
  247. {$UNDEF SYSCALL_DEBUG}
  248. {$ENDIF SYS_LINUX}