syscallo.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. {$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. {$ASMMODE DEFAULT}
  51. {$endif i386}
  52. {$ifdef m68k}
  53. {$define fpc_syscall_ok}
  54. asm
  55. { load the registers... }
  56. move.l 12(a6),a0
  57. move.l 4(a0),d1
  58. move.l 8(a0),d2
  59. move.l 12(a0),d3
  60. move.l 16(a0),d4
  61. move.l 20(a0),d5
  62. { set the call number }
  63. move.l 8(a6),d0
  64. { Go ! }
  65. trap #0
  66. { Put back the registers... }
  67. move.l d0,-(sp)
  68. move.l 12(a6),a0
  69. move.l d5,20(a0)
  70. move.l d4,16(a0)
  71. move.l d3,12(a0)
  72. move.l d2,8(a0)
  73. move.l d1,4(a0)
  74. move.l (sp)+,d1
  75. move.l d1,(a0)
  76. end;
  77. {$endif m68k}
  78. {$ifdef powerpc}
  79. {$define fpc_syscall_ok}
  80. asm
  81. { load the registers... }
  82. lwz r5, 12(r4)
  83. lwz r6, 16(r4)
  84. lwz r7, 20(r4)
  85. mr r0, r3
  86. lwz r3, 4(r4)
  87. stw r4, regs
  88. lwz r4, 8(r4)
  89. { Go ! }
  90. sc
  91. nop
  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 powerpc}
  101. {$ifndef fpc_syscall_ok}
  102. {$error Cannot decide which processor you have!}
  103. asm
  104. end;
  105. {$endif not fpc_syscall_ok}
  106. {$IFDEF SYSCALL_DEBUG}
  107. Const
  108. DoSysCallDebug : Boolean = False;
  109. var
  110. LastCnt,
  111. LastEax,
  112. LastCall : longint;
  113. DebugTxt : string[20];
  114. {$ENDIF}
  115. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  116. {
  117. This function serves as an interface to do_SysCall.
  118. If the SysCall returned a negative number, it returns -1, and puts the
  119. SysCall result in errno. Otherwise, it returns the SysCall return value
  120. }
  121. begin
  122. do_SysCall(callnr,regs);
  123. if regs.reg1<0 then
  124. begin
  125. {$IFDEF SYSCALL_DEBUG}
  126. If DoSysCallDebug then
  127. debugtxt:=' syscall error: ';
  128. {$endif}
  129. ErrNo:=-regs.reg1;
  130. SysCall:=-1;
  131. end
  132. else
  133. begin
  134. {$IFDEF SYSCALL_DEBUG}
  135. if DoSysCallDebug then
  136. debugtxt:=' syscall returned: ';
  137. {$endif}
  138. SysCall:=regs.reg1;
  139. errno:=0
  140. end;
  141. {$IFDEF SYSCALL_DEBUG}
  142. if DoSysCallDebug then
  143. begin
  144. inc(lastcnt);
  145. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  146. begin
  147. if lastcnt>1 then
  148. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  149. lastcall:=callnr;
  150. lasteax:=regs.reg1;
  151. lastcnt:=0;
  152. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  153. end;
  154. end;
  155. {$endif}
  156. end;
  157. {
  158. $Log$
  159. Revision 1.1 2002-11-11 21:40:26 marco
  160. * rename syscall.inc -> syscallo.inc
  161. Revision 1.1 2002/10/14 19:39:44 peter
  162. * syscall moved into seperate include
  163. }