syscall.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. 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. {$ASMMODE GAS}
  13. {$ifdef FPC_PROFILE}
  14. procedure mcount; external name 'mcount';
  15. {$endif FPC_PROFILE}
  16. function FpSysCall(sysnr:TSysParam):TSysResult; assembler; nostackframe; [public,alias:'FPC_SYSCALL0'];
  17. asm
  18. pushq %rax { keep stack aligned }
  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,%rdi
  30. call seterrno@PLT
  31. movq $-1,%rax
  32. .LSyscOK:
  33. popq %rcx { remove alignment }
  34. end;
  35. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler; nostackframe; [public,alias:'FPC_SYSCALL1'];
  36. asm
  37. pushq %rax { keep stack aligned }
  38. {$ifdef FPC_PROFILE}
  39. pushq sysnr
  40. pushq param1
  41. call mcount
  42. popq param1
  43. popq sysnr
  44. {$endif FPC_PROFILE}
  45. movq sysnr, %rax { Syscall number -> rax. }
  46. movq param1, %rdi { shift arg1 - arg5. }
  47. syscall { Do the system call. }
  48. cmpq $-4095, %rax { Check %rax for error. }
  49. jnae .LSyscOK { Jump to error handler if error. }
  50. negq %rax
  51. movq %rax,%rdi
  52. call seterrno@PLT
  53. movq $-1,%rax
  54. .LSyscOK:
  55. popq %rcx { remove alignment }
  56. end;
  57. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler; nostackframe; [public,alias:'FPC_SYSCALL2'];
  58. asm
  59. pushq %rax { keep stack aligned }
  60. {$ifdef FPC_PROFILE}
  61. pushq sysnr
  62. pushq param1
  63. pushq param2
  64. call mcount
  65. popq param2
  66. popq param1
  67. popq sysnr
  68. {$endif FPC_PROFILE}
  69. movq sysnr, %rax { Syscall number -> rax. }
  70. movq param1, %rdi { shift arg1 - arg5. }
  71. movq param2, %rsi
  72. syscall { Do the system call. }
  73. cmpq $-4095, %rax { Check %rax for error. }
  74. jnae .LSyscOK { Jump to error handler if error. }
  75. negq %rax
  76. movq %rax,%rdi
  77. call seterrno@PLT
  78. movq $-1,%rax
  79. .LSyscOK:
  80. popq %rcx { remove alignment }
  81. end;
  82. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler; nostackframe; [public,alias:'FPC_SYSCALL3'];
  83. asm
  84. pushq %rax { keep stack aligned }
  85. {$ifdef FPC_PROFILE}
  86. pushq sysnr
  87. pushq param1
  88. pushq param2
  89. pushq param3
  90. call mcount
  91. popq param3
  92. popq param2
  93. popq param1
  94. popq sysnr
  95. {$endif FPC_PROFILE}
  96. movq sysnr, %rax { Syscall number -> rax. }
  97. movq param1, %rdi { shift arg1 - arg5. }
  98. movq param2, %rsi
  99. movq param3, %rdx
  100. syscall { Do the system call. }
  101. cmpq $-4095, %rax { Check %rax for error. }
  102. jnae .LSyscOK { Jump to error handler if error. }
  103. negq %rax
  104. movq %rax,%rdi
  105. call seterrno@PLT
  106. movq $-1,%rax
  107. .LSyscOK:
  108. popq %rcx { remove alignment }
  109. end;
  110. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler; nostackframe; [public,alias:'FPC_SYSCALL4'];
  111. asm
  112. pushq %rax { keep stack aligned }
  113. {$ifdef FPC_PROFILE}
  114. pushq sysnr
  115. pushq param1
  116. pushq param2
  117. pushq param3
  118. pushq param4
  119. call mcount
  120. popq param4
  121. popq param3
  122. popq param2
  123. popq param1
  124. popq sysnr
  125. {$endif FPC_PROFILE}
  126. movq sysnr, %rax { Syscall number -> rax. }
  127. movq param1, %rdi { shift arg1 - arg5. }
  128. movq param2, %rsi
  129. movq param3, %rdx
  130. movq param4, %r10
  131. syscall { Do the system call. }
  132. cmpq $-4095, %rax { Check %rax for error. }
  133. jnae .LSyscOK { Jump to error handler if error. }
  134. negq %rax
  135. movq %rax,%rdi
  136. call seterrno@PLT
  137. movq $-1,%rax
  138. .LSyscOK:
  139. popq %rcx { remove alignment }
  140. end;
  141. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler; nostackframe; [public,alias:'FPC_SYSCALL5'];
  142. asm
  143. pushq %rax { keep stack aligned }
  144. {$ifdef FPC_PROFILE}
  145. pushq sysnr
  146. pushq param1
  147. pushq param2
  148. pushq param3
  149. pushq param4
  150. pushq param5
  151. call mcount
  152. popq param5
  153. popq param4
  154. popq param3
  155. popq param2
  156. popq param1
  157. popq sysnr
  158. {$endif FPC_PROFILE}
  159. movq sysnr, %rax { Syscall number -> rax. }
  160. movq param1, %rdi { shift arg1 - arg5. }
  161. movq param2, %rsi
  162. movq param3, %rdx
  163. movq param4, %r10
  164. movq param5, %r8
  165. syscall { Do the system call. }
  166. cmpq $-4095, %rax { Check %rax for error. }
  167. jnae .LSyscOK { Jump to error handler if error. }
  168. negq %rax
  169. movq %rax,%rdi
  170. call seterrno@PLT
  171. movq $-1,%rax
  172. .LSyscOK:
  173. popq %rcx { remove alignment }
  174. end;
  175. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  176. asm
  177. {$ifdef FPC_PROFILE}
  178. pushq sysnr
  179. pushq param1
  180. pushq param2
  181. pushq param3
  182. pushq param4
  183. pushq param5
  184. pushq param6
  185. call mcount
  186. popq param6
  187. popq param5
  188. popq param4
  189. popq param3
  190. popq param2
  191. popq param1
  192. popq sysnr
  193. {$endif FPC_PROFILE}
  194. movq sysnr, %rax { Syscall number -> rax. }
  195. movq param1, %rdi { shift arg1 - arg5. }
  196. movq param2, %rsi
  197. movq param3, %rdx
  198. movq param4, %r10
  199. movq param5, %r8
  200. movq param6, %r9
  201. syscall { Do the system call. }
  202. cmpq $-4095, %rax { Check %rax for error. }
  203. jnae .LSyscOK { Jump to error handler if error. }
  204. negq %rax
  205. movq %rax,%rdi
  206. call seterrno@PLT
  207. movq $-1,%rax
  208. .LSyscOK:
  209. end;
  210. {No debugging for syslinux include !}
  211. {$IFDEF SYS_LINUX}
  212. {$UNDEF SYSCALL_DEBUG}
  213. {$ENDIF SYS_LINUX}