syscallo.inc 4.8 KB

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