syscall.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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+4)@ha
  30. stw r3,(Errno+4)@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+4)@ha
  45. stw r3,(Errno+4)@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+4)@ha
  61. stw r3,(Errno+4)@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+4)@ha
  78. stw r3,(Errno+4)@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+4)@ha
  96. stw r3,(Errno+4)@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+4)@ha
  115. stw r3,(Errno+4)@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+4)@ha
  135. stw r3,(Errno+4)@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. bns Lsyscall_ok
  157. neg r3,r3
  158. Lsyscall_ok:
  159. { Put back the registers... }
  160. lwz r8, regs
  161. stw r3, 0(r8)
  162. end;
  163. {$IFDEF SYSCALL_DEBUG}
  164. Const
  165. DoSysCallDebug : Boolean = False;
  166. var
  167. LastCnt,
  168. LastEax,
  169. LastCall : longint;
  170. DebugTxt : string[20];
  171. {$ENDIF}
  172. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  173. {
  174. This function serves as an interface to do_SysCall.
  175. If the SysCall returned a negative number, it returns -1, and puts the
  176. SysCall result in errno. Otherwise, it returns the SysCall return value
  177. }
  178. begin
  179. FpSysCall(callnr,regs);
  180. if regs.reg1<0 then
  181. begin
  182. {$IFDEF SYSCALL_DEBUG}
  183. If DoSysCallDebug then
  184. debugtxt:=' syscall error: ';
  185. {$endif}
  186. ErrNo:=-regs.reg1;
  187. SysCall:=-1;
  188. end
  189. else
  190. begin
  191. {$IFDEF SYSCALL_DEBUG}
  192. if DoSysCallDebug then
  193. debugtxt:=' syscall returned: ';
  194. {$endif}
  195. SysCall:=regs.reg1;
  196. errno:=0
  197. end;
  198. {$IFDEF SYSCALL_DEBUG}
  199. if DoSysCallDebug then
  200. begin
  201. inc(lastcnt);
  202. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  203. begin
  204. if lastcnt>1 then
  205. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  206. lastcall:=callnr;
  207. lasteax:=regs.reg1;
  208. lastcnt:=0;
  209. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  210. end;
  211. end;
  212. {$endif}
  213. end;
  214. {
  215. $Log$
  216. Revision 1.7 2003-06-17 16:39:58 jonas
  217. * fixed old syscall handling for ppc
  218. Revision 1.6 2003/05/23 21:58:30 jonas
  219. * fixed storing to errno for single threaded programs
  220. Revision 1.5 2003/05/11 16:07:55 jonas
  221. * fixed mmap for non-i386 non-m68k architectures (not sure about
  222. x86-64)
  223. Revision 1.4 2003/04/22 17:07:55 florian
  224. * there where two SYSCALL1 procedures for the powerpc, fixed
  225. Revision 1.3 2003/01/09 13:38:26 florian
  226. * syscall stuff fixed
  227. Revision 1.2 2002/12/22 16:00:28 jonas
  228. + added syscallh.inc, adapted syscall.inc
  229. Revision 1.1 2002/11/09 20:32:14 marco
  230. * powerpc version. Threadsafe errno access not yet done.
  231. Revision 1.1 2002/10/14 19:39:44 peter
  232. * syscall moved into seperate include
  233. }