syscall.inc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. {$ifdef FPC_PROFILE}
  15. procedure mcount; external name 'mcount';
  16. {$endif FPC_PROFILE}
  17. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  18. asm
  19. {$ifdef FPC_PROFILE}
  20. pushq sysnr
  21. call mcount
  22. popq sysnr
  23. {$endif FPC_PROFILE}
  24. movq sysnr, %rax { Syscall number -> rax. }
  25. syscall { Do the system call. }
  26. cmpq $-4095, %rax { Check %rax for error. }
  27. jnae .LSyscOK { Jump to error handler if error. }
  28. negq %rax
  29. movq %rax,%rdx
  30. {$ifdef FPC_PIC}
  31. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  32. movq (%rax),%rax
  33. movq Errno@GOTPCREL(%rip),%r11
  34. {$else FPC_PIC}
  35. movq fpc_threadvar_relocate_proc,%rax
  36. leaq Errno,%r11
  37. {$endif FPC_PIC}
  38. testq %rax,%rax
  39. jne .LThread
  40. movl %edx,8(%r11)
  41. jmp .LNoThread
  42. .LThread:
  43. pushq %rdx
  44. movq (%r11),%rdi
  45. call *%rax
  46. popq %rdx
  47. movl %edx,(%rax)
  48. .LNoThread:
  49. movq $-1,%rax
  50. .LSyscOK:
  51. end;
  52. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  53. asm
  54. {$ifdef FPC_PROFILE}
  55. pushq sysnr
  56. pushq param1
  57. call mcount
  58. popq param1
  59. popq sysnr
  60. {$endif FPC_PROFILE}
  61. movq sysnr, %rax { Syscall number -> rax. }
  62. movq param1, %rdi { shift arg1 - arg5. }
  63. syscall { Do the system call. }
  64. cmpq $-4095, %rax { Check %rax for error. }
  65. jnae .LSyscOK { Jump to error handler if error. }
  66. negq %rax
  67. movq %rax,%rdx
  68. {$ifdef FPC_PIC}
  69. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  70. movq (%rax),%rax
  71. movq Errno@GOTPCREL(%rip),%r11
  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_SYSCALL2'];
  91. asm
  92. {$ifdef FPC_PROFILE}
  93. pushq sysnr
  94. pushq param1
  95. pushq param2
  96. call mcount
  97. popq param2
  98. popq param1
  99. popq sysnr
  100. {$endif FPC_PROFILE}
  101. movq sysnr, %rax { Syscall number -> rax. }
  102. movq param1, %rdi { shift arg1 - arg5. }
  103. movq param2, %rsi
  104. syscall { Do the system call. }
  105. cmpq $-4095, %rax { Check %rax for error. }
  106. jnae .LSyscOK { Jump to error handler if error. }
  107. negq %rax
  108. movq %rax,%rdx
  109. {$ifdef FPC_PIC}
  110. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  111. movq (%rax),%rax
  112. movq Errno@GOTPCREL(%rip),%r11
  113. {$else FPC_PIC}
  114. movq fpc_threadvar_relocate_proc,%rax
  115. leaq Errno,%r11
  116. {$endif FPC_PIC}
  117. testq %rax,%rax
  118. jne .LThread
  119. movl %edx,8(%r11)
  120. jmp .LNoThread
  121. .LThread:
  122. pushq %rdx
  123. movq (%r11),%rdi
  124. call *%rax
  125. popq %rdx
  126. movl %edx,(%rax)
  127. .LNoThread:
  128. movq $-1,%rax
  129. .LSyscOK:
  130. end;
  131. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  132. asm
  133. {$ifdef FPC_PROFILE}
  134. pushq sysnr
  135. pushq param1
  136. pushq param2
  137. pushq param3
  138. call mcount
  139. popq param3
  140. popq param2
  141. popq param1
  142. popq sysnr
  143. {$endif FPC_PROFILE}
  144. movq sysnr, %rax { Syscall number -> rax. }
  145. movq param1, %rdi { shift arg1 - arg5. }
  146. movq param2, %rsi
  147. movq param3, %rdx
  148. syscall { Do the system call. }
  149. cmpq $-4095, %rax { Check %rax for error. }
  150. jnae .LSyscOK { Jump to error handler if error. }
  151. negq %rax
  152. movq %rax,%rdx
  153. {$ifdef FPC_PIC}
  154. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  155. movq (%rax),%rax
  156. movq Errno@GOTPCREL(%rip),%r11
  157. {$else FPC_PIC}
  158. movq fpc_threadvar_relocate_proc,%rax
  159. leaq Errno,%r11
  160. {$endif FPC_PIC}
  161. testq %rax,%rax
  162. jne .LThread
  163. movl %edx,8(%r11)
  164. jmp .LNoThread
  165. .LThread:
  166. pushq %rdx
  167. movq (%r11),%rdi
  168. call *%rax
  169. popq %rdx
  170. movl %edx,(%rax)
  171. .LNoThread:
  172. movq $-1,%rax
  173. .LSyscOK:
  174. end;
  175. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  176. asm
  177. {$ifdef FPC_PROFILE}
  178. pushq sysnr
  179. pushq param1
  180. pushq param2
  181. pushq param3
  182. pushq param4
  183. call mcount
  184. popq param4
  185. popq param3
  186. popq param2
  187. popq param1
  188. popq sysnr
  189. {$endif FPC_PROFILE}
  190. movq sysnr, %rax { Syscall number -> rax. }
  191. movq param1, %rdi { shift arg1 - arg5. }
  192. movq param2, %rsi
  193. movq param3, %rdx
  194. movq param4, %r10
  195. syscall { Do the system call. }
  196. cmpq $-4095, %rax { Check %rax for error. }
  197. jnae .LSyscOK { Jump to error handler if error. }
  198. negq %rax
  199. movq %rax,%rdx
  200. {$ifdef FPC_PIC}
  201. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  202. movq (%rax),%rax
  203. movq Errno@GOTPCREL(%rip),%r11
  204. {$else FPC_PIC}
  205. movq fpc_threadvar_relocate_proc,%rax
  206. leaq Errno,%r11
  207. {$endif FPC_PIC}
  208. testq %rax,%rax
  209. jne .LThread
  210. movl %edx,8(%r11)
  211. jmp .LNoThread
  212. .LThread:
  213. pushq %rdx
  214. movq (%r11),%rdi
  215. call *%rax
  216. popq %rdx
  217. movl %edx,(%rax)
  218. .LNoThread:
  219. movq $-1,%rax
  220. .LSyscOK:
  221. end;
  222. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  223. asm
  224. {$ifdef FPC_PROFILE}
  225. pushq sysnr
  226. pushq param1
  227. pushq param2
  228. pushq param3
  229. pushq param4
  230. pushq param5
  231. call mcount
  232. popq param5
  233. popq param4
  234. popq param3
  235. popq param2
  236. popq param1
  237. popq sysnr
  238. {$endif FPC_PROFILE}
  239. movq sysnr, %rax { Syscall number -> rax. }
  240. movq param1, %rdi { shift arg1 - arg5. }
  241. movq param2, %rsi
  242. movq param3, %rdx
  243. movq param4, %r10
  244. movq param5, %r8
  245. syscall { Do the system call. }
  246. cmpq $-4095, %rax { Check %rax for error. }
  247. jnae .LSyscOK { Jump to error handler if error. }
  248. negq %rax
  249. movq %rax,%rdx
  250. {$ifdef FPC_PIC}
  251. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  252. movq (%rax),%rax
  253. movq Errno@GOTPCREL(%rip),%r11
  254. {$else FPC_PIC}
  255. movq fpc_threadvar_relocate_proc,%rax
  256. leaq Errno,%r11
  257. {$endif FPC_PIC}
  258. testq %rax,%rax
  259. jne .LThread
  260. movl %edx,8(%r11)
  261. jmp .LNoThread
  262. .LThread:
  263. pushq %rdx
  264. movq (%r11),%rdi
  265. call *%rax
  266. popq %rdx
  267. movl %edx,(%rax)
  268. .LNoThread:
  269. movq $-1,%rax
  270. .LSyscOK:
  271. end;
  272. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  273. asm
  274. {$ifdef FPC_PROFILE}
  275. pushq sysnr
  276. pushq param1
  277. pushq param2
  278. pushq param3
  279. pushq param4
  280. pushq param5
  281. pushq param6
  282. call mcount
  283. popq param6
  284. popq param5
  285. popq param4
  286. popq param3
  287. popq param2
  288. popq param1
  289. popq sysnr
  290. {$endif FPC_PROFILE}
  291. movq sysnr, %rax { Syscall number -> rax. }
  292. movq param1, %rdi { shift arg1 - arg5. }
  293. movq param2, %rsi
  294. movq param3, %rdx
  295. movq param4, %r10
  296. movq param5, %r8
  297. movq param6, %r9
  298. syscall { Do the system call. }
  299. cmpq $-4095, %rax { Check %rax for error. }
  300. jnae .LSyscOK { Jump to error handler if error. }
  301. negq %rax
  302. movq %rax,%rdx
  303. {$ifdef FPC_PIC}
  304. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  305. movq (%rax),%rax
  306. movq Errno@GOTPCREL(%rip),%r11
  307. {$else FPC_PIC}
  308. movq fpc_threadvar_relocate_proc,%rax
  309. leaq Errno,%r11
  310. {$endif FPC_PIC}
  311. testq %rax,%rax
  312. jne .LThread
  313. movl %edx,8(%r11)
  314. jmp .LNoThread
  315. .LThread:
  316. pushq %rdx
  317. movq (%r11),%rdi
  318. call *%rax
  319. popq %rdx
  320. movl %edx,(%rax)
  321. .LNoThread:
  322. movq $-1,%rax
  323. .LSyscOK:
  324. end;
  325. {No debugging for syslinux include !}
  326. {$IFDEF SYS_LINUX}
  327. {$UNDEF SYSCALL_DEBUG}
  328. {$ENDIF SYS_LINUX}