syscall.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. bns .LDone
  28. neg r3, r3
  29. lis r4,(Errno+4)@ha
  30. stw r3,(Errno+4)@l(r4)
  31. li r3,-1
  32. .LDone:
  33. end;
  34. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  35. {
  36. This function puts the registers in place, does the call, and then
  37. copies back the registers as they are after the SysCall.
  38. }
  39. asm
  40. mr r0,r3
  41. mr r3,r4
  42. sc
  43. bns .LDone
  44. neg r3, r3
  45. lis r4,(Errno+4)@ha
  46. stw r3,(Errno+4)@l(r4)
  47. li r3,-1
  48. .LDone:
  49. end;
  50. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  51. {
  52. This function puts the registers in place, does the call, and then
  53. copies back the registers as they are after the SysCall.
  54. }
  55. asm
  56. mr r0,r3
  57. mr r3,r4
  58. mr r4,r5
  59. sc
  60. bns .LDone
  61. neg r3, r3
  62. lis r4,(Errno+4)@ha
  63. stw r3,(Errno+4)@l(r4)
  64. li r3,-1
  65. .LDone:
  66. end;
  67. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  68. {
  69. This function puts the registers in place, does the call, and then
  70. copies back the registers as they are after the SysCall.
  71. }
  72. asm
  73. mr r0,r3
  74. mr r3,r4
  75. mr r4,r5
  76. mr r5,r6
  77. sc
  78. bns .LDone
  79. neg r3, r3
  80. lis r4,(Errno+4)@ha
  81. stw r3,(Errno+4)@l(r4)
  82. li r3,-1
  83. .LDone:
  84. end;
  85. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  86. {
  87. This function puts the registers in place, does the call, and then
  88. copies back the registers as they are after the SysCall.
  89. }
  90. asm
  91. mr r0,r3
  92. mr r3,r4
  93. mr r4,r5
  94. mr r5,r6
  95. mr r6,r7
  96. sc
  97. bns .LDone
  98. neg r3, r3
  99. lis r4,(Errno+4)@ha
  100. stw r3,(Errno+4)@l(r4)
  101. li r3,-1
  102. .LDone:
  103. end;
  104. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  105. {
  106. This function puts the registers in place, does the call, and then
  107. copies back the registers as they are after the SysCall.
  108. }
  109. asm
  110. mr r0,r3
  111. mr r3,r4
  112. mr r4,r5
  113. mr r5,r6
  114. mr r6,r7
  115. mr r7,r8
  116. sc
  117. bns .LDone
  118. neg r3, r3
  119. lis r4,(Errno+4)@ha
  120. stw r3,(Errno+4)@l(r4)
  121. li r3,-1
  122. .LDone:
  123. end;
  124. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  125. {
  126. This function puts the registers in place, does the call, and then
  127. copies back the registers as they are after the SysCall.
  128. }
  129. asm
  130. mr r0,r3
  131. mr r3,r4
  132. mr r4,r5
  133. mr r5,r6
  134. mr r6,r7
  135. mr r7,r8
  136. mr r8,r9
  137. sc
  138. bns .LDone
  139. neg r3, r3
  140. lis r4,(Errno+4)@ha
  141. stw r3,(Errno+4)@l(r4)
  142. li r3,-1
  143. .LDone:
  144. end;
  145. // Old style syscall:
  146. // Better use ktrace/strace/gdb for debugging.
  147. Procedure FpSysCall( callnr:longint;var regs : SysCallregs );assembler;
  148. {
  149. This function puts the registers in place, does the call, and then
  150. copies back the registers as they are after the SysCall.
  151. }
  152. asm
  153. { load the registers... }
  154. lwz r5, 12(r4)
  155. lwz r6, 16(r4)
  156. lwz r7, 20(r4)
  157. mr r0, r3
  158. lwz r3, 4(r4)
  159. mr r8, r4
  160. lwz r4, 8(r4)
  161. { Go ! }
  162. sc
  163. bns .Lsyscall_ok
  164. neg r3,r3
  165. .Lsyscall_ok:
  166. { Put back the registers... }
  167. stw r3, 0(r8)
  168. end;
  169. {$IFDEF SYSCALL_DEBUG}
  170. Const
  171. DoSysCallDebug : Boolean = False;
  172. var
  173. LastCnt,
  174. LastEax,
  175. LastCall : longint;
  176. DebugTxt : string[20];
  177. {$ENDIF}
  178. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  179. {
  180. This function serves as an interface to do_SysCall.
  181. If the SysCall returned a negative number, it returns -1, and puts the
  182. SysCall result in errno. Otherwise, it returns the SysCall return value
  183. }
  184. begin
  185. FpSysCall(callnr,regs);
  186. if regs.reg1<0 then
  187. begin
  188. {$IFDEF SYSCALL_DEBUG}
  189. If DoSysCallDebug then
  190. debugtxt:=' syscall error: ';
  191. {$endif}
  192. ErrNo:=-regs.reg1;
  193. SysCall:=-1;
  194. end
  195. else
  196. begin
  197. {$IFDEF SYSCALL_DEBUG}
  198. if DoSysCallDebug then
  199. debugtxt:=' syscall returned: ';
  200. {$endif}
  201. SysCall:=regs.reg1;
  202. errno:=0
  203. end;
  204. {$IFDEF SYSCALL_DEBUG}
  205. if DoSysCallDebug then
  206. begin
  207. inc(lastcnt);
  208. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  209. begin
  210. if lastcnt>1 then
  211. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  212. lastcall:=callnr;
  213. lasteax:=regs.reg1;
  214. lastcnt:=0;
  215. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  216. end;
  217. end;
  218. {$endif}
  219. end;
  220. {
  221. $Log$
  222. Revision 1.10 2003-11-29 22:54:32 jonas
  223. * more ppc fixes, hello world works again under linuxppc
  224. Revision 1.8 2003/11/15 19:01:27 florian
  225. * fixed rtl to work with the integrated fpc ppc assembler reader
  226. Revision 1.7 2003/06/17 16:39:58 jonas
  227. * fixed old syscall handling for ppc
  228. Revision 1.6 2003/05/23 21:58:30 jonas
  229. * fixed storing to errno for single threaded programs
  230. Revision 1.5 2003/05/11 16:07:55 jonas
  231. * fixed mmap for non-i386 non-m68k architectures (not sure about
  232. x86-64)
  233. Revision 1.4 2003/04/22 17:07:55 florian
  234. * there where two SYSCALL1 procedures for the powerpc, fixed
  235. Revision 1.3 2003/01/09 13:38:26 florian
  236. * syscall stuff fixed
  237. Revision 1.2 2002/12/22 16:00:28 jonas
  238. + added syscallh.inc, adapted syscall.inc
  239. Revision 1.1 2002/11/09 20:32:14 marco
  240. * powerpc version. Threadsafe errno access not yet done.
  241. Revision 1.1 2002/10/14 19:39:44 peter
  242. * syscall moved into seperate include
  243. }