syscall.inc 5.5 KB

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