syscall.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. {$ifndef FPC_STATICRIPFIXED}
  34. movq Errno@GOTPCREL(%rip),%r11
  35. {$else}
  36. leaq Errno(%rip),%r11
  37. {$endif}
  38. {$else FPC_PIC}
  39. movq fpc_threadvar_relocate_proc,%rax
  40. leaq Errno,%r11
  41. {$endif FPC_PIC}
  42. testq %rax,%rax
  43. jne .LThread
  44. movl %edx,8(%r11)
  45. jmp .LNoThread
  46. .LThread:
  47. pushq %rdx
  48. movq (%r11),%rdi
  49. call *%rax
  50. popq %rdx
  51. movl %edx,(%rax)
  52. .LNoThread:
  53. movq $-1,%rax
  54. .LSyscOK:
  55. end;
  56. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  57. asm
  58. {$ifdef FPC_PROFILE}
  59. pushq sysnr
  60. pushq param1
  61. call mcount
  62. popq param1
  63. popq sysnr
  64. {$endif FPC_PROFILE}
  65. movq sysnr, %rax { Syscall number -> rax. }
  66. movq param1, %rdi { shift arg1 - arg5. }
  67. syscall { Do the system call. }
  68. cmpq $-4095, %rax { Check %rax for error. }
  69. jnae .LSyscOK { Jump to error handler if error. }
  70. negq %rax
  71. movq %rax,%rdx
  72. {$ifdef FPC_PIC}
  73. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  74. movq (%rax),%rax
  75. {$ifndef FPC_STATICRIPFIXED}
  76. movq Errno@GOTPCREL(%rip),%r11
  77. {$else}
  78. leaq Errno(%rip),%r11
  79. {$endif}
  80. {$else FPC_PIC}
  81. movq fpc_threadvar_relocate_proc,%rax
  82. leaq Errno,%r11
  83. {$endif FPC_PIC}
  84. testq %rax,%rax
  85. jne .LThread
  86. movl %edx,8(%r11)
  87. jmp .LNoThread
  88. .LThread:
  89. pushq %rdx
  90. movq (%r11),%rdi
  91. call *%rax
  92. popq %rdx
  93. movl %edx,(%rax)
  94. .LNoThread:
  95. movq $-1,%rax
  96. .LSyscOK:
  97. end;
  98. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  99. asm
  100. {$ifdef FPC_PROFILE}
  101. pushq sysnr
  102. pushq param1
  103. pushq param2
  104. call mcount
  105. popq param2
  106. popq param1
  107. popq sysnr
  108. {$endif FPC_PROFILE}
  109. movq sysnr, %rax { Syscall number -> rax. }
  110. movq param1, %rdi { shift arg1 - arg5. }
  111. movq param2, %rsi
  112. syscall { Do the system call. }
  113. cmpq $-4095, %rax { Check %rax for error. }
  114. jnae .LSyscOK { Jump to error handler if error. }
  115. negq %rax
  116. movq %rax,%rdx
  117. {$ifdef FPC_PIC}
  118. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  119. movq (%rax),%rax
  120. {$ifndef FPC_STATICRIPFIXED}
  121. movq Errno@GOTPCREL(%rip),%r11
  122. {$else}
  123. leaq Errno(%rip),%r11
  124. {$endif}
  125. {$else FPC_PIC}
  126. movq fpc_threadvar_relocate_proc,%rax
  127. leaq Errno,%r11
  128. {$endif FPC_PIC}
  129. testq %rax,%rax
  130. jne .LThread
  131. movl %edx,8(%r11)
  132. jmp .LNoThread
  133. .LThread:
  134. pushq %rdx
  135. movq (%r11),%rdi
  136. call *%rax
  137. popq %rdx
  138. movl %edx,(%rax)
  139. .LNoThread:
  140. movq $-1,%rax
  141. .LSyscOK:
  142. end;
  143. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  144. asm
  145. {$ifdef FPC_PROFILE}
  146. pushq sysnr
  147. pushq param1
  148. pushq param2
  149. pushq param3
  150. call mcount
  151. popq param3
  152. popq param2
  153. popq param1
  154. popq sysnr
  155. {$endif FPC_PROFILE}
  156. movq sysnr, %rax { Syscall number -> rax. }
  157. movq param1, %rdi { shift arg1 - arg5. }
  158. movq param2, %rsi
  159. movq param3, %rdx
  160. syscall { Do the system call. }
  161. cmpq $-4095, %rax { Check %rax for error. }
  162. jnae .LSyscOK { Jump to error handler if error. }
  163. negq %rax
  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:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  192. asm
  193. {$ifdef FPC_PROFILE}
  194. pushq sysnr
  195. pushq param1
  196. pushq param2
  197. pushq param3
  198. pushq param4
  199. call mcount
  200. popq param4
  201. popq param3
  202. popq param2
  203. popq param1
  204. popq sysnr
  205. {$endif FPC_PROFILE}
  206. movq sysnr, %rax { Syscall number -> rax. }
  207. movq param1, %rdi { shift arg1 - arg5. }
  208. movq param2, %rsi
  209. movq param3, %rdx
  210. movq param4, %r10
  211. syscall { Do the system call. }
  212. cmpq $-4095, %rax { Check %rax for error. }
  213. jnae .LSyscOK { Jump to error handler if error. }
  214. negq %rax
  215. movq %rax,%rdx
  216. {$ifdef FPC_PIC}
  217. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  218. movq (%rax),%rax
  219. {$ifndef FPC_STATICRIPFIXED}
  220. movq Errno@GOTPCREL(%rip),%r11
  221. {$else}
  222. leaq Errno(%rip),%r11
  223. {$endif}
  224. {$else FPC_PIC}
  225. movq fpc_threadvar_relocate_proc,%rax
  226. leaq Errno,%r11
  227. {$endif FPC_PIC}
  228. testq %rax,%rax
  229. jne .LThread
  230. movl %edx,8(%r11)
  231. jmp .LNoThread
  232. .LThread:
  233. pushq %rdx
  234. movq (%r11),%rdi
  235. call *%rax
  236. popq %rdx
  237. movl %edx,(%rax)
  238. .LNoThread:
  239. movq $-1,%rax
  240. .LSyscOK:
  241. end;
  242. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  243. asm
  244. {$ifdef FPC_PROFILE}
  245. pushq sysnr
  246. pushq param1
  247. pushq param2
  248. pushq param3
  249. pushq param4
  250. pushq param5
  251. call mcount
  252. popq param5
  253. popq param4
  254. popq param3
  255. popq param2
  256. popq param1
  257. popq sysnr
  258. {$endif FPC_PROFILE}
  259. movq sysnr, %rax { Syscall number -> rax. }
  260. movq param1, %rdi { shift arg1 - arg5. }
  261. movq param2, %rsi
  262. movq param3, %rdx
  263. movq param4, %r10
  264. movq param5, %r8
  265. syscall { Do the system call. }
  266. cmpq $-4095, %rax { Check %rax for error. }
  267. jnae .LSyscOK { Jump to error handler if error. }
  268. negq %rax
  269. movq %rax,%rdx
  270. {$ifdef FPC_PIC}
  271. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  272. movq (%rax),%rax
  273. {$ifndef FPC_STATICRIPFIXED}
  274. movq Errno@GOTPCREL(%rip),%r11
  275. {$else}
  276. leaq Errno(%rip),%r11
  277. {$endif}
  278. {$else FPC_PIC}
  279. movq fpc_threadvar_relocate_proc,%rax
  280. leaq Errno,%r11
  281. {$endif FPC_PIC}
  282. testq %rax,%rax
  283. jne .LThread
  284. movl %edx,8(%r11)
  285. jmp .LNoThread
  286. .LThread:
  287. pushq %rdx
  288. movq (%r11),%rdi
  289. call *%rax
  290. popq %rdx
  291. movl %edx,(%rax)
  292. .LNoThread:
  293. movq $-1,%rax
  294. .LSyscOK:
  295. end;
  296. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  297. asm
  298. {$ifdef FPC_PROFILE}
  299. pushq sysnr
  300. pushq param1
  301. pushq param2
  302. pushq param3
  303. pushq param4
  304. pushq param5
  305. pushq param6
  306. call mcount
  307. popq param6
  308. popq param5
  309. popq param4
  310. popq param3
  311. popq param2
  312. popq param1
  313. popq sysnr
  314. {$endif FPC_PROFILE}
  315. movq sysnr, %rax { Syscall number -> rax. }
  316. movq param1, %rdi { shift arg1 - arg5. }
  317. movq param2, %rsi
  318. movq param3, %rdx
  319. movq param4, %r10
  320. movq param5, %r8
  321. movq param6, %r9
  322. syscall { Do the system call. }
  323. cmpq $-4095, %rax { Check %rax for error. }
  324. jnae .LSyscOK { Jump to error handler if error. }
  325. negq %rax
  326. movq %rax,%rdx
  327. {$ifdef FPC_PIC}
  328. movq fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
  329. movq (%rax),%rax
  330. {$ifndef FPC_STATICRIPFIXED}
  331. movq Errno@GOTPCREL(%rip),%r11
  332. {$else}
  333. leaq Errno(%rip),%r11
  334. {$endif}
  335. {$else FPC_PIC}
  336. movq fpc_threadvar_relocate_proc,%rax
  337. leaq Errno,%r11
  338. {$endif FPC_PIC}
  339. testq %rax,%rax
  340. jne .LThread
  341. movl %edx,8(%r11)
  342. jmp .LNoThread
  343. .LThread:
  344. pushq %rdx
  345. movq (%r11),%rdi
  346. call *%rax
  347. popq %rdx
  348. movl %edx,(%rax)
  349. .LNoThread:
  350. movq $-1,%rax
  351. .LSyscOK:
  352. end;
  353. {No debugging for syslinux include !}
  354. {$IFDEF SYS_LINUX}
  355. {$UNDEF SYSCALL_DEBUG}
  356. {$ENDIF SYS_LINUX}