syscall.inc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. The syscalls for the new RTL, moved to platform dependant dir.
  7. Old linux calling convention is stil kept.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. Type
  15. TSysResult = longint; // all platforms, cint=32-bit.
  16. // On platforms with off_t =64-bit, people should
  17. // use int64, and typecast all other calls to cint.
  18. // I don't think this is going to work on several platforms 64-bit machines
  19. // don't have only 64-bit params.
  20. TSysParam = Longint;
  21. {$ASMMODE ATT}
  22. function Do_SysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  23. asm
  24. { load the registers... }
  25. movl sysnr,%eax
  26. int $0x80
  27. test %eax,%eax
  28. jae .LSysc
  29. negl %eax
  30. mov %eax,Errno
  31. mov $-1,%eax
  32. .LSysc:
  33. end;
  34. function Do_SysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  35. asm
  36. { load the registers... }
  37. movl sysnr,%eax
  38. movl param1,%ebx
  39. int $0x80
  40. test %eax,%eax
  41. jae .LSysc
  42. negl %eax
  43. mov %eax,Errno
  44. mov $-1,%eax
  45. .LSysc:
  46. end;
  47. function Do_SysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  48. asm
  49. { load the registers... }
  50. movl sysnr,%eax
  51. movl param1,%ebx
  52. movl param2,%ecx
  53. int $0x80
  54. test %eax,%eax
  55. jae .LSysc
  56. negl %eax
  57. mov %eax,Errno
  58. mov $-1,%eax
  59. .LSysc:
  60. end;
  61. function Do_SysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  62. asm
  63. { load the registers... }
  64. movl sysnr,%eax
  65. movl param1,%ebx
  66. movl param2,%ecx
  67. movl param3,%edx
  68. int $0x80
  69. test %eax,%eax
  70. jae .LSysc
  71. negl %eax
  72. mov %eax,Errno
  73. mov $-1,%eax
  74. .LSysc:
  75. end;
  76. function Do_SysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  77. asm
  78. { load the registers... }
  79. movl sysnr,%eax
  80. movl param1,%ebx
  81. movl param2,%ecx
  82. movl param3,%edx
  83. movl param4,%esi
  84. int $0x80
  85. test %eax,%eax
  86. jae .LSysc
  87. negl %eax
  88. mov %eax,Errno
  89. mov $-1,%eax
  90. .LSysc:
  91. end;
  92. function Do_SysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  93. asm
  94. { load the registers... }
  95. movl sysnr,%eax
  96. movl param1,%ebx
  97. movl param2,%ecx
  98. movl param3,%edx
  99. movl param4,%esi
  100. movl param5,%edi
  101. int $0x80
  102. test %eax,%eax
  103. jae .LSysc
  104. negl %eax
  105. mov %eax,Errno
  106. mov $-1,%eax
  107. .LSysc:
  108. end;
  109. function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  110. asm
  111. { load the registers... }
  112. movl sysnr,%eax
  113. movl param1,%ebx
  114. movl param2,%ecx
  115. movl param3,%edx
  116. movl param4,%esi
  117. movl param5,%edi
  118. int $0x80
  119. test %eax,%eax
  120. jae .LSysc
  121. negl %eax
  122. mov %eax,Errno
  123. mov $-1,%eax
  124. .LSysc:
  125. end;
  126. {No debugging for syslinux include !}
  127. {$IFDEF SYS_LINUX}
  128. {$UNDEF SYSCALL_DEBUG}
  129. {$ENDIF SYS_LINUX}
  130. {*****************************************************************************
  131. --- Main:The System Call Self ---
  132. *****************************************************************************}
  133. Procedure Do_SysCall( callnr:longint;var regs : SysCallregs );assembler;
  134. {
  135. This function puts the registers in place, does the call, and then
  136. copies back the registers as they are after the SysCall.
  137. }
  138. {$ASMMODE ATT}
  139. {$define fpc_syscall_ok}
  140. asm
  141. { load the registers... }
  142. movl 12(%ebp),%eax
  143. movl 4(%eax),%ebx
  144. movl 8(%eax),%ecx
  145. movl 12(%eax),%edx
  146. movl 16(%eax),%esi
  147. movl 20(%eax),%edi
  148. { set the call number }
  149. movl 8(%ebp),%eax
  150. { Go ! }
  151. int $0x80
  152. { Put back the registers... }
  153. pushl %eax
  154. movl 12(%ebp),%eax
  155. movl %edi,20(%eax)
  156. movl %esi,16(%eax)
  157. movl %edx,12(%eax)
  158. movl %ecx,8(%eax)
  159. movl %ebx,4(%eax)
  160. popl %ebx
  161. movl %ebx,(%eax)
  162. end;
  163. {$ASMMODE DEFAULT}
  164. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  165. {
  166. This function serves as an interface to do_SysCall.
  167. If the SysCall returned a negative number, it returns -1, and puts the
  168. SysCall result in errno. Otherwise, it returns the SysCall return value
  169. }
  170. begin
  171. do_SysCall(callnr,regs);
  172. if regs.reg1<0 then
  173. begin
  174. {$IFDEF SYSCALL_DEBUG}
  175. If DoSysCallDebug then
  176. debugtxt:=' syscall error: ';
  177. {$endif}
  178. setErrNo(-regs.reg1);
  179. SysCall:=-1;
  180. end
  181. else
  182. begin
  183. {$IFDEF SYSCALL_DEBUG}
  184. if DoSysCallDebug then
  185. debugtxt:=' syscall returned: ';
  186. {$endif}
  187. SysCall:=regs.reg1;
  188. seterrno(0);
  189. end;
  190. {$IFDEF SYSCALL_DEBUG}
  191. if DoSysCallDebug then
  192. begin
  193. inc(lastcnt);
  194. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  195. begin
  196. if lastcnt>1 then
  197. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  198. lastcall:=callnr;
  199. lasteax:=regs.reg1;
  200. lastcnt:=0;
  201. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  202. end;
  203. end;
  204. {$endif}
  205. end;
  206. {
  207. $Log$
  208. Revision 1.1 2002-11-12 13:31:32 marco
  209. * New syscall.inc
  210. }