syscallo.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_SysCall( callnr:longint;var regs : SysCallregs );assembler;
  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 i386}
  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 i386}
  50. {$ifdef m68k}
  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 m68k}
  76. {$ifdef powerpc}
  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. nop
  90. { Put back the registers... }
  91. lwz r8, regs
  92. stw r3, 0(r8)
  93. stw r4, 4(r8)
  94. stw r5, 8(r8)
  95. stw r6, 12(r8)
  96. stw r7, 16(r8)
  97. end;
  98. {$endif powerpc}
  99. {$ifdef sparc}
  100. {$define fpc_syscall_ok}
  101. asm
  102. { we are using the callers register window }
  103. or %i0,%g0,%g1
  104. ld [%i1],%o0
  105. ld [%i1+4],%o1
  106. ld [%i1+8],%o2
  107. ld [%i1+12],%o3
  108. ld [%i1+16],%o4
  109. { Go ! }
  110. ta 0x10
  111. { Put back the registers... }
  112. st %o0,[%i1]
  113. st %o1,[%i1+4]
  114. st %o2,[%i1+8]
  115. st %o3,[%i1+12]
  116. st %o4,[%i1+16]
  117. end;
  118. {$endif powerpc}
  119. {$ifndef fpc_syscall_ok}
  120. {$error Cannot decide which processor you have!}
  121. asm
  122. end;
  123. {$endif not fpc_syscall_ok}
  124. {$IFDEF SYSCALL_DEBUG}
  125. Const
  126. DoSysCallDebug : Boolean = False;
  127. var
  128. LastCnt,
  129. LastEax,
  130. LastCall : longint;
  131. DebugTxt : string[20];
  132. {$ENDIF}
  133. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  134. {
  135. This function serves as an interface to do_SysCall.
  136. If the SysCall returned a negative number, it returns -1, and puts the
  137. SysCall result in errno. Otherwise, it returns the SysCall return value
  138. }
  139. begin
  140. do_SysCall(callnr,regs);
  141. if regs.reg1<0 then
  142. begin
  143. {$IFDEF SYSCALL_DEBUG}
  144. If DoSysCallDebug then
  145. debugtxt:=' syscall error: ';
  146. {$endif}
  147. ErrNo:=-regs.reg1;
  148. SysCall:=-1;
  149. end
  150. else
  151. begin
  152. {$IFDEF SYSCALL_DEBUG}
  153. if DoSysCallDebug then
  154. debugtxt:=' syscall returned: ';
  155. {$endif}
  156. SysCall:=regs.reg1;
  157. errno:=0
  158. end;
  159. {$IFDEF SYSCALL_DEBUG}
  160. if DoSysCallDebug then
  161. begin
  162. inc(lastcnt);
  163. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  164. begin
  165. if lastcnt>1 then
  166. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  167. lastcall:=callnr;
  168. lasteax:=regs.reg1;
  169. lastcnt:=0;
  170. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  171. end;
  172. end;
  173. {$endif}
  174. end;
  175. {
  176. $Log$
  177. Revision 1.3 2003-06-04 15:18:14 peter
  178. * compile fix for systhrds
  179. Revision 1.2 2003/04/22 17:07:55 florian
  180. * there where two SYSCALL1 procedures for the powerpc, fixed
  181. Revision 1.1 2002/11/11 21:40:26 marco
  182. * rename syscall.inc -> syscallo.inc
  183. Revision 1.1 2002/10/14 19:39:44 peter
  184. * syscall moved into seperate include
  185. }