syscallo.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. 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. {No debugging for syslinux include !}
  13. {$IFDEF SYS_LINUX}
  14. {$UNDEF SYSCALL_DEBUG}
  15. {$ENDIF SYS_LINUX}
  16. {*****************************************************************************
  17. --- Main:The System Call Self ---
  18. *****************************************************************************}
  19. Procedure Do_SysCallspec( callnr:longint;var regs : SysCallregs );assembler;{$ifndef VER1_0}oldfpccall;{$endif}
  20. {
  21. This function puts the registers in place, does the call, and then
  22. copies back the registers as they are after the SysCall.
  23. }
  24. {$ifdef cpui386}
  25. {$ASMMODE ATT}
  26. {$define fpc_syscall_ok}
  27. asm
  28. { load the registers... }
  29. movl 12(%ebp),%eax
  30. movl 4(%eax),%ebx
  31. movl 8(%eax),%ecx
  32. movl 12(%eax),%edx
  33. movl 16(%eax),%esi
  34. movl 20(%eax),%edi
  35. { set the call number }
  36. movl 8(%ebp),%eax
  37. { Go ! }
  38. int $0x80
  39. { Put back the registers... }
  40. pushl %eax
  41. movl 12(%ebp),%eax
  42. movl %edi,20(%eax)
  43. movl %esi,16(%eax)
  44. movl %edx,12(%eax)
  45. movl %ecx,8(%eax)
  46. movl %ebx,4(%eax)
  47. popl %ebx
  48. movl %ebx,(%eax)
  49. end;
  50. {$endif cpui386}
  51. {$ifdef cpum68k}
  52. {$define fpc_syscall_ok}
  53. asm
  54. { load the registers... }
  55. move.l 12(a6),a0
  56. move.l 4(a0),d1
  57. move.l 8(a0),d2
  58. move.l 12(a0),d3
  59. move.l 16(a0),d4
  60. move.l 20(a0),d5
  61. { set the call number }
  62. move.l 8(a6),d0
  63. { Go ! }
  64. trap #0
  65. { Put back the registers... }
  66. move.l d0,-(sp)
  67. move.l 12(a6),a0
  68. move.l d5,20(a0)
  69. move.l d4,16(a0)
  70. move.l d3,12(a0)
  71. move.l d2,8(a0)
  72. move.l d1,4(a0)
  73. move.l (sp)+,d1
  74. move.l d1,(a0)
  75. end;
  76. {$endif cpum68k}
  77. {$ifdef cpupowerpc}
  78. {$define fpc_syscall_ok}
  79. asm
  80. { load the registers... }
  81. lwz r5, 12(r4)
  82. lwz r6, 16(r4)
  83. lwz r7, 20(r4)
  84. mr r0, r3
  85. lwz r3, 4(r4)
  86. stw r4, regs
  87. lwz r4, 8(r4)
  88. { Go ! }
  89. sc
  90. bns Lsyscallo_ok
  91. neg r3,r3
  92. Lsyscallo_ok:
  93. { Put back the registers... }
  94. lwz r8, regs
  95. stw r3, 0(r8)
  96. stw r4, 4(r8)
  97. stw r5, 8(r8)
  98. stw r6, 12(r8)
  99. stw r7, 16(r8)
  100. end;
  101. {$endif cpupowerpc}
  102. {$ifdef cpusparc}
  103. {$define fpc_syscall_ok}
  104. asm
  105. { we are using the callers register window }
  106. or %i0,%g0,%g1
  107. ld [%i1],%o0
  108. ld [%i1+4],%o1
  109. ld [%i1+8],%o2
  110. ld [%i1+12],%o3
  111. ld [%i1+16],%o4
  112. { Go ! }
  113. ta 0x10
  114. { Put back the registers... }
  115. st %o0,[%i1]
  116. st %o1,[%i1+4]
  117. st %o2,[%i1+8]
  118. st %o3,[%i1+12]
  119. st %o4,[%i1+16]
  120. end;
  121. {$endif cpupowerpc}
  122. {$ifndef fpc_syscall_ok}
  123. {$error Cannot decide which processor you have!}
  124. asm
  125. end;
  126. {$endif not fpc_syscall_ok}
  127. {$IFDEF SYSCALL_DEBUG}
  128. Const
  129. DoSysCallDebug : Boolean = False;
  130. var
  131. LastCnt,
  132. LastEax,
  133. LastCall : longint;
  134. DebugTxt : string[20];
  135. {$ENDIF}
  136. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  137. {
  138. This function serves as an interface to do_SysCall.
  139. If the SysCall returned a negative number, it returns -1, and puts the
  140. SysCall result in errno. Otherwise, it returns the SysCall return value
  141. }
  142. begin
  143. do_SysCallspec(callnr,regs);
  144. if regs.reg1<0 then
  145. begin
  146. {$IFDEF SYSCALL_DEBUG}
  147. If DoSysCallDebug then
  148. debugtxt:=' syscall error: ';
  149. {$endif}
  150. fpseterrno(-regs.reg1);
  151. SysCall:=-1;
  152. end
  153. else
  154. begin
  155. {$IFDEF SYSCALL_DEBUG}
  156. if DoSysCallDebug then
  157. debugtxt:=' syscall returned: ';
  158. {$endif}
  159. SysCall:=regs.reg1;
  160. fpseterrno(0);
  161. end;
  162. {$IFDEF SYSCALL_DEBUG}
  163. if DoSysCallDebug then
  164. begin
  165. inc(lastcnt);
  166. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  167. begin
  168. if lastcnt>1 then
  169. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  170. lastcall:=callnr;
  171. lasteax:=regs.reg1;
  172. lastcnt:=0;
  173. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  174. end;
  175. end;
  176. {$endif}
  177. end;
  178. {
  179. $Log$
  180. Revision 1.2 2003-10-31 09:22:02 mazen
  181. + assembler mode forced to ATT style for x86 cpu
  182. Revision 1.1 2003/10/30 16:16:49 marco
  183. * moved legacy syscall to i386/
  184. Revision 1.7 2003/10/29 19:45:44 peter
  185. * use oldfpccall because all registers are destroyed
  186. Revision 1.6 2003/09/14 20:15:01 marco
  187. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  188. Revision 1.5 2003/08/21 22:24:52 olle
  189. - removed parameter from fpc_iocheck
  190. Revision 1.4 2003/06/17 16:39:58 jonas
  191. * fixed old syscall handling for ppc
  192. Revision 1.3 2003/06/04 15:18:14 peter
  193. * compile fix for systhrds
  194. Revision 1.2 2003/04/22 17:07:55 florian
  195. * there where two SYSCALL1 procedures for the powerpc, fixed
  196. Revision 1.1 2002/11/11 21:40:26 marco
  197. * rename syscall.inc -> syscallo.inc
  198. Revision 1.1 2002/10/14 19:39:44 peter
  199. * syscall moved into seperate include
  200. }