syscall.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 FpSysCall(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 FpSysCall(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 FpSysCall(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 FpSysCall(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 FpSysCall(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 FpSysCall(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. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; {assembler;}[public,alias:'FPC_SYSCALL5'];
  119. {
  120. This function puts the registers in place, does the call, and then
  121. copies back the registers as they are after the SysCall.
  122. }
  123. begin{asm}
  124. { mr r0,r3
  125. mr r3,r4
  126. mr r4,r5
  127. mr r5,r6
  128. mr r6,r7
  129. mr r7,r8
  130. sc
  131. bnslr
  132. neg r3, r3
  133. lis r4,Errno@ha
  134. stw r3,Errno@l(r4)
  135. li r3,-1}
  136. end;
  137. // Old style syscall:
  138. // Better use ktrace/strace/gdb for debugging.
  139. Procedure FpSysCall( callnr:longint;var regs : SysCallregs );{assembler;}
  140. {
  141. This function puts the registers in place, does the call, and then
  142. copies back the registers as they are after the SysCall.
  143. }
  144. begin{asm}
  145. { load the registers... }
  146. (* lwz r5, 12(r4)
  147. lwz r6, 16(r4)
  148. lwz r7, 20(r4)
  149. mr r0, r3
  150. lwz r3, 4(r4)
  151. stw r4, regs
  152. lwz r4, 8(r4)
  153. { Go ! }
  154. sc
  155. nop
  156. { Put back the registers... }
  157. lwz r8, regs
  158. stw r3, 0(r8)
  159. stw r4, 4(r8)
  160. stw r5, 8(r8)
  161. stw r6, 12(r8)
  162. stw r7, 16(r8)*)
  163. end;
  164. {$IFDEF SYSCALL_DEBUG}
  165. Const
  166. DoSysCallDebug : Boolean = False;
  167. var
  168. LastCnt,
  169. LastEax,
  170. LastCall : longint;
  171. DebugTxt : string[20];
  172. {$ENDIF}
  173. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  174. {
  175. This function serves as an interface to do_SysCall.
  176. If the SysCall returned a negative number, it returns -1, and puts the
  177. SysCall result in errno. Otherwise, it returns the SysCall return value
  178. }
  179. begin
  180. FpSysCall(callnr,regs);
  181. if regs.reg1<0 then
  182. begin
  183. {$IFDEF SYSCALL_DEBUG}
  184. If DoSysCallDebug then
  185. debugtxt:=' syscall error: ';
  186. {$endif}
  187. ErrNo:=-regs.reg1;
  188. SysCall:=-1;
  189. end
  190. else
  191. begin
  192. {$IFDEF SYSCALL_DEBUG}
  193. if DoSysCallDebug then
  194. debugtxt:=' syscall returned: ';
  195. {$endif}
  196. SysCall:=regs.reg1;
  197. errno:=0
  198. end;
  199. {$IFDEF SYSCALL_DEBUG}
  200. if DoSysCallDebug then
  201. begin
  202. inc(lastcnt);
  203. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  204. begin
  205. if lastcnt>1 then
  206. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  207. lastcall:=callnr;
  208. lasteax:=regs.reg1;
  209. lastcnt:=0;
  210. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  211. end;
  212. end;
  213. {$endif}
  214. end;
  215. {
  216. $Log$
  217. Revision 1.4 2003-05-23 22:36:39 florian
  218. * fixed compilation of sparc system unit
  219. Revision 1.3 2003/01/05 21:32:35 mazen
  220. * fixing several bugs compiling the RTL
  221. Revision 1.2 2002/12/24 21:30:20 mazen
  222. - some writeln(s) removed in compiler
  223. + many files added to RTL
  224. * some errors fixed in RTL
  225. Revision 1.1 2002/11/15 12:08:37 mazen
  226. + SPARC support added based on PowerPc sources
  227. Revision 1.1 2002/11/09 20:32:14 marco
  228. * powerpc version. Threadsafe errno access not yet done.
  229. Revision 1.1 2002/10/14 19:39:44 peter
  230. * syscall moved into seperate include
  231. }