syscall.inc 5.8 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_SYSCALL0'];
  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. 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. 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. 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. 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. 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. 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_SYSCALL6'];
  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. 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. mr r8,r9
  131. sc
  132. bnslr
  133. neg r3, r3
  134. lis r4,Errno@ha
  135. stw r3,Errno@l(r4)
  136. li r3,-1
  137. end;
  138. // Old style syscall:
  139. // Better use ktrace/strace/gdb for debugging.
  140. Procedure FpSysCall( callnr:longint;var regs : SysCallregs );assembler;
  141. {
  142. This function puts the registers in place, does the call, and then
  143. copies back the registers as they are after the SysCall.
  144. }
  145. asm
  146. { load the registers... }
  147. lwz r5, 12(r4)
  148. lwz r6, 16(r4)
  149. lwz r7, 20(r4)
  150. mr r0, r3
  151. lwz r3, 4(r4)
  152. stw r4, regs
  153. lwz r4, 8(r4)
  154. { Go ! }
  155. sc
  156. nop
  157. { Put back the registers... }
  158. lwz r8, regs
  159. stw r3, 0(r8)
  160. stw r4, 4(r8)
  161. stw r5, 8(r8)
  162. stw r6, 12(r8)
  163. stw r7, 16(r8)
  164. end;
  165. {$IFDEF SYSCALL_DEBUG}
  166. Const
  167. DoSysCallDebug : Boolean = False;
  168. var
  169. LastCnt,
  170. LastEax,
  171. LastCall : longint;
  172. DebugTxt : string[20];
  173. {$ENDIF}
  174. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  175. {
  176. This function serves as an interface to do_SysCall.
  177. If the SysCall returned a negative number, it returns -1, and puts the
  178. SysCall result in errno. Otherwise, it returns the SysCall return value
  179. }
  180. begin
  181. FpSysCall(callnr,regs);
  182. if regs.reg1<0 then
  183. begin
  184. {$IFDEF SYSCALL_DEBUG}
  185. If DoSysCallDebug then
  186. debugtxt:=' syscall error: ';
  187. {$endif}
  188. ErrNo:=-regs.reg1;
  189. SysCall:=-1;
  190. end
  191. else
  192. begin
  193. {$IFDEF SYSCALL_DEBUG}
  194. if DoSysCallDebug then
  195. debugtxt:=' syscall returned: ';
  196. {$endif}
  197. SysCall:=regs.reg1;
  198. errno:=0
  199. end;
  200. {$IFDEF SYSCALL_DEBUG}
  201. if DoSysCallDebug then
  202. begin
  203. inc(lastcnt);
  204. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  205. begin
  206. if lastcnt>1 then
  207. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  208. lastcall:=callnr;
  209. lasteax:=regs.reg1;
  210. lastcnt:=0;
  211. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  212. end;
  213. end;
  214. {$endif}
  215. end;
  216. {
  217. $Log$
  218. Revision 1.5 2003-05-11 16:07:55 jonas
  219. * fixed mmap for non-i386 non-m68k architectures (not sure about
  220. x86-64)
  221. Revision 1.4 2003/04/22 17:07:55 florian
  222. * there where two SYSCALL1 procedures for the powerpc, fixed
  223. Revision 1.3 2003/01/09 13:38:26 florian
  224. * syscall stuff fixed
  225. Revision 1.2 2002/12/22 16:00:28 jonas
  226. + added syscallh.inc, adapted syscall.inc
  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. }