syscall.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. {$ASMMODE ATT}
  15. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  16. asm
  17. { load the registers... }
  18. movl sysnr,%eax
  19. int $0x80
  20. test %eax,%eax
  21. jae .LSysc
  22. negl %eax
  23. mov %eax,Errno
  24. mov $-1,%eax
  25. .LSysc:
  26. end;
  27. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  28. asm
  29. { load the registers... }
  30. movl sysnr,%eax
  31. movl param1,%ebx
  32. int $0x80
  33. test %eax,%eax
  34. jae .LSysc
  35. negl %eax
  36. mov %eax,Errno
  37. mov $-1,%eax
  38. .LSysc:
  39. end;
  40. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  41. asm
  42. { load the registers... }
  43. movl sysnr,%eax
  44. movl param1,%ebx
  45. movl param2,%ecx
  46. int $0x80
  47. test %eax,%eax
  48. jae .LSysc
  49. negl %eax
  50. mov %eax,Errno
  51. mov $-1,%eax
  52. .LSysc:
  53. end;
  54. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  55. asm
  56. { load the registers... }
  57. movl sysnr,%eax
  58. movl param1,%ebx
  59. movl param2,%ecx
  60. movl param3,%edx
  61. int $0x80
  62. test %eax,%eax
  63. jae .LSysc
  64. negl %eax
  65. mov %eax,Errno
  66. mov $-1,%eax
  67. .LSysc:
  68. end;
  69. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  70. asm
  71. { load the registers... }
  72. movl sysnr,%eax
  73. movl param1,%ebx
  74. movl param2,%ecx
  75. movl param3,%edx
  76. movl param4,%esi
  77. int $0x80
  78. test %eax,%eax
  79. jae .LSysc
  80. negl %eax
  81. mov %eax,Errno
  82. mov $-1,%eax
  83. .LSysc:
  84. end;
  85. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  86. asm
  87. { load the registers... }
  88. movl sysnr,%eax
  89. movl param1,%ebx
  90. movl param2,%ecx
  91. movl param3,%edx
  92. movl param4,%esi
  93. movl param5,%edi
  94. int $0x80
  95. test %eax,%eax
  96. jae .LSysc
  97. negl %eax
  98. mov %eax,Errno
  99. mov $-1,%eax
  100. .LSysc:
  101. end;
  102. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  103. asm
  104. { load the registers... }
  105. movl sysnr,%eax
  106. movl param1,%ebx
  107. movl param2,%ecx
  108. movl param3,%edx
  109. movl param4,%esi
  110. movl param5,%edi
  111. int $0x80
  112. test %eax,%eax
  113. jae .LSysc
  114. negl %eax
  115. mov %eax,Errno
  116. mov $-1,%eax
  117. .LSysc:
  118. end;
  119. {No debugging for syslinux include !}
  120. {$IFDEF SYS_LINUX}
  121. {$UNDEF SYSCALL_DEBUG}
  122. {$ENDIF SYS_LINUX}
  123. {*****************************************************************************
  124. --- Main:The System Call Self ---
  125. *****************************************************************************}
  126. Procedure FpSysCall( callnr:TSysParam;var regs : SysCallregs );assembler;
  127. {
  128. This function puts the registers in place, does the call, and then
  129. copies back the registers as they are after the SysCall.
  130. }
  131. {$ASMMODE ATT}
  132. {$define fpc_syscall_ok}
  133. asm
  134. { load the registers... }
  135. movl 12(%ebp),%eax
  136. movl 4(%eax),%ebx
  137. movl 8(%eax),%ecx
  138. movl 12(%eax),%edx
  139. movl 16(%eax),%esi
  140. movl 20(%eax),%edi
  141. { set the call number }
  142. movl 8(%ebp),%eax
  143. { Go ! }
  144. int $0x80
  145. { Put back the registers... }
  146. pushl %eax
  147. movl 12(%ebp),%eax
  148. movl %edi,20(%eax)
  149. movl %esi,16(%eax)
  150. movl %edx,12(%eax)
  151. movl %ecx,8(%eax)
  152. movl %ebx,4(%eax)
  153. popl %ebx
  154. movl %ebx,(%eax)
  155. end;
  156. {$ASMMODE DEFAULT}
  157. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  158. {
  159. This function serves as an interface to do_SysCall.
  160. If the SysCall returned a negative number, it returns -1, and puts the
  161. SysCall result in errno. Otherwise, it returns the SysCall return value
  162. }
  163. begin
  164. FpSysCall(callnr,regs);
  165. if regs.reg1<0 then
  166. begin
  167. {$IFDEF SYSCALL_DEBUG}
  168. If DoSysCallDebug then
  169. debugtxt:=' syscall error: ';
  170. {$endif}
  171. setErrNo(-regs.reg1);
  172. SysCall:=-1;
  173. end
  174. else
  175. begin
  176. {$IFDEF SYSCALL_DEBUG}
  177. if DoSysCallDebug then
  178. debugtxt:=' syscall returned: ';
  179. {$endif}
  180. SysCall:=regs.reg1;
  181. seterrno(0);
  182. end;
  183. {$IFDEF SYSCALL_DEBUG}
  184. if DoSysCallDebug then
  185. begin
  186. inc(lastcnt);
  187. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  188. begin
  189. if lastcnt>1 then
  190. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  191. lastcall:=callnr;
  192. lasteax:=regs.reg1;
  193. lastcnt:=0;
  194. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  195. end;
  196. end;
  197. {$endif}
  198. end;
  199. {
  200. $Log$
  201. Revision 1.3 2002-12-18 16:46:37 marco
  202. * Some mods.
  203. Revision 1.2 2002/11/16 15:37:47 marco
  204. * TSysParam + result moved to -h
  205. Revision 1.1 2002/11/12 13:31:32 marco
  206. * New syscall.inc
  207. }