syscall.inc 5.4 KB

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