syscall.inc 5.6 KB

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