syscall.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. function Do_SysCall(sysnr:TSysParam):TSysResult; {assembler;}[public,alias:'FPC_SYSCALL1'];
  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. begin{asm}
  25. { mr r0,r3
  26. sc
  27. bnslr
  28. neg r3, r3
  29. lis r4,Errno@ha
  30. stw r3,Errno@l(r4)
  31. li r3,-1}
  32. end;
  33. function Do_SysCall(sysnr,param1:TSysParam):TSysResult; {assembler;}[public,alias:'FPC_SYSCALL1'];
  34. {
  35. This function puts the registers in place, does the call, and then
  36. copies back the registers as they are after the SysCall.
  37. }
  38. begin{asm}
  39. { mr r0,r3
  40. mr r3,r4
  41. sc
  42. bnslr
  43. neg r3, r3
  44. lis r4,Errno@ha
  45. stw r3,Errno@l(r4)
  46. li r3,-1}
  47. end;
  48. function Do_SysCall(sysnr,param1,param2:TSysParam):TSysResult; {assembler;}[public,alias:'FPC_SYSCALL2'];
  49. {
  50. This function puts the registers in place, does the call, and then
  51. copies back the registers as they are after the SysCall.
  52. }
  53. begin{asm}
  54. { mr r0,r3
  55. mr r3,r4
  56. mr r4,r5
  57. sc
  58. bnslr
  59. neg r3, r3
  60. lis r4,Errno@ha
  61. stw r3,Errno@l(r4)
  62. li r3,-1}
  63. end;
  64. function Do_SysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; {assembler;}[public,alias:'FPC_SYSCALL3'];
  65. {
  66. This function puts the registers in place, does the call, and then
  67. copies back the registers as they are after the SysCall.
  68. }
  69. begin{asm}
  70. { mr r0,r3
  71. mr r3,r4
  72. mr r4,r5
  73. mr r5,r6
  74. sc
  75. bnslr
  76. neg r3, r3
  77. lis r4,Errno@ha
  78. stw r3,Errno@l(r4)
  79. li r3,-1}
  80. end;
  81. function Do_SysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; {assembler;}[public,alias:'FPC_SYSCALL4'];
  82. {
  83. This function puts the registers in place, does the call, and then
  84. copies back the registers as they are after the SysCall.
  85. }
  86. begin{asm}
  87. { mr r0,r3
  88. mr r3,r4
  89. mr r4,r5
  90. mr r5,r6
  91. mr r6,r7
  92. sc
  93. bnslr
  94. neg r3, r3
  95. lis r4,Errno@ha
  96. stw r3,Errno@l(r4)
  97. li r3,-1}
  98. end;
  99. function Do_SysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; {assembler;}[public,alias:'FPC_SYSCALL5'];
  100. {
  101. This function puts the registers in place, does the call, and then
  102. copies back the registers as they are after the SysCall.
  103. }
  104. begin{asm}
  105. { mr r0,r3
  106. mr r3,r4
  107. mr r4,r5
  108. mr r5,r6
  109. mr r6,r7
  110. mr r7,r8
  111. sc
  112. bnslr
  113. neg r3, r3
  114. lis r4,Errno@ha
  115. stw r3,Errno@l(r4)
  116. li r3,-1}
  117. end;
  118. // Old style syscall:
  119. // Better use ktrace/strace/gdb for debugging.
  120. Procedure Do_SysCall( callnr:longint;var regs : SysCallregs );{assembler;}
  121. {
  122. This function puts the registers in place, does the call, and then
  123. copies back the registers as they are after the SysCall.
  124. }
  125. begin{asm}
  126. { load the registers... }
  127. (* lwz r5, 12(r4)
  128. lwz r6, 16(r4)
  129. lwz r7, 20(r4)
  130. mr r0, r3
  131. lwz r3, 4(r4)
  132. stw r4, regs
  133. lwz r4, 8(r4)
  134. { Go ! }
  135. sc
  136. nop
  137. { Put back the registers... }
  138. lwz r8, regs
  139. stw r3, 0(r8)
  140. stw r4, 4(r8)
  141. stw r5, 8(r8)
  142. stw r6, 12(r8)
  143. stw r7, 16(r8)*)
  144. end;
  145. {$IFDEF SYSCALL_DEBUG}
  146. Const
  147. DoSysCallDebug : Boolean = False;
  148. var
  149. LastCnt,
  150. LastEax,
  151. LastCall : longint;
  152. DebugTxt : string[20];
  153. {$ENDIF}
  154. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  155. {
  156. This function serves as an interface to do_SysCall.
  157. If the SysCall returned a negative number, it returns -1, and puts the
  158. SysCall result in errno. Otherwise, it returns the SysCall return value
  159. }
  160. begin
  161. do_SysCall(callnr,regs);
  162. if regs.reg1<0 then
  163. begin
  164. {$IFDEF SYSCALL_DEBUG}
  165. If DoSysCallDebug then
  166. debugtxt:=' syscall error: ';
  167. {$endif}
  168. ErrNo:=-regs.reg1;
  169. SysCall:=-1;
  170. end
  171. else
  172. begin
  173. {$IFDEF SYSCALL_DEBUG}
  174. if DoSysCallDebug then
  175. debugtxt:=' syscall returned: ';
  176. {$endif}
  177. SysCall:=regs.reg1;
  178. errno:=0
  179. end;
  180. {$IFDEF SYSCALL_DEBUG}
  181. if DoSysCallDebug then
  182. begin
  183. inc(lastcnt);
  184. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  185. begin
  186. if lastcnt>1 then
  187. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  188. lastcall:=callnr;
  189. lasteax:=regs.reg1;
  190. lastcnt:=0;
  191. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  192. end;
  193. end;
  194. {$endif}
  195. end;
  196. {
  197. $Log$
  198. Revision 1.3 2003-01-05 21:32:35 mazen
  199. * fixing several bugs compiling the RTL
  200. Revision 1.2 2002/12/24 21:30:20 mazen
  201. - some writeln(s) removed in compiler
  202. + many files added to RTL
  203. * some errors fixed in RTL
  204. Revision 1.1 2002/11/15 12:08:37 mazen
  205. + SPARC support added based on PowerPc sources
  206. Revision 1.1 2002/11/09 20:32:14 marco
  207. * powerpc version. Threadsafe errno access not yet done.
  208. Revision 1.1 2002/10/14 19:39:44 peter
  209. * syscall moved into seperate include
  210. }