syscall.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2003 by Florian Klaempfl,
  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. swi #0x900071
  26. cmn r0,#126
  27. bls .LDone
  28. ldr r1,.LErrno
  29. rsb r0,r0,#0
  30. str r0,[r1]
  31. mvn r0,#0
  32. b .LDone
  33. .LErrno:
  34. .word Errno
  35. .LDone:
  36. end;
  37. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  38. {
  39. This function puts the registers in place, does the call, and then
  40. copies back the registers as they are after the SysCall.
  41. }
  42. asm
  43. swi #0x900071
  44. cmn r0,#126
  45. bls .LDone
  46. ldr r1,.LErrno
  47. rsb r0,r0,#0
  48. str r0,[r1]
  49. mvn r0,#0
  50. b .LDone
  51. .LErrno:
  52. .word Errno
  53. .LDone:
  54. end;
  55. function FpSysCall(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. asm
  61. swi #0x900071
  62. cmn r0,#126
  63. bls .LDone
  64. ldr r1,.LErrno
  65. rsb r0,r0,#0
  66. str r0,[r1]
  67. mvn r0,#0
  68. b .LDone
  69. .LErrno:
  70. .word Errno
  71. .LDone:
  72. end;
  73. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  74. {
  75. This function puts the registers in place, does the call, and then
  76. copies back the registers as they are after the SysCall.
  77. }
  78. asm
  79. swi #0x900071
  80. cmn r0,#126
  81. bls .LDone
  82. ldr r1,.LErrno
  83. rsb r0,r0,#0
  84. str r0,[r1]
  85. mvn r0,#0
  86. b .LDone
  87. .LErrno:
  88. .word Errno
  89. .LDone:
  90. end;
  91. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  92. {
  93. This function puts the registers in place, does the call, and then
  94. copies back the registers as they are after the SysCall.
  95. }
  96. asm
  97. stmfd r13!,{r4}
  98. ldr r4,param4
  99. swi #0x900071
  100. cmn r0,#126
  101. bls .LDone
  102. ldr r1,.LErrno
  103. rsb r0,r0,#0
  104. str r0,[r1]
  105. mvn r0,#0
  106. b .LDone
  107. .LErrno:
  108. .word Errno
  109. .LDone:
  110. ldmfd r13!,{r4}
  111. end;
  112. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  113. {
  114. This function puts the registers in place, does the call, and then
  115. copies back the registers as they are after the SysCall.
  116. }
  117. asm
  118. stmfd r13!,{r4-r5}
  119. ldr r5,param5
  120. ldr r4,param4
  121. swi #0x900071
  122. cmn r0,#126
  123. bls .LDone
  124. ldr r1,.LErrno
  125. rsb r0,r0,#0
  126. str r0,[r1]
  127. mvn r0,#0
  128. b .LDone
  129. .LErrno:
  130. .word Errno
  131. .LDone:
  132. ldmfd r13!,{r4-r5}
  133. end;
  134. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  135. {
  136. This function puts the registers in place, does the call, and then
  137. copies back the registers as they are after the SysCall.
  138. }
  139. asm
  140. stmfd r13!,{r4-r6}
  141. ldr r6,param6
  142. ldr r5,param5
  143. ldr r4,param4
  144. swi #0x900071
  145. cmn r0,#126
  146. bls .LDone
  147. ldr r1,.LErrno
  148. rsb r0,r0,#0
  149. str r0,[r1]
  150. mvn r0,#0
  151. b .LDone
  152. .LErrno:
  153. .word Errno
  154. .LDone:
  155. ldmfd r13!,{r4-r6}
  156. end;
  157. // Old style syscall:
  158. // Better use ktrace/strace/gdb for debugging.
  159. Procedure FpSysCall(callnr:longint;var regs : SysCallregs);assembler;
  160. {
  161. This function puts the registers in place, does the call, and then
  162. copies back the registers as they are after the SysCall.
  163. }
  164. asm
  165. stmfd r13!,{r4-r6}
  166. ldr r2,[r1,#4]
  167. ldr r3,[r1,#8]
  168. ldr r4,[r1,#12]
  169. ldr r5,[r1,#16]
  170. ldr r6,[r1,#20]
  171. ldr r1,[r1]
  172. swi #0x900071
  173. cmn r0,#126
  174. bls .LDone
  175. ldr r1,.LErrno
  176. rsb r0,r0,#0
  177. str r0,[r1]
  178. mvn r0,#0
  179. b .LDone
  180. .LErrno:
  181. .word Errno
  182. .LDone:
  183. ldmfd r13!,{r4-r6}
  184. end;
  185. {$IFDEF SYSCALL_DEBUG}
  186. Const
  187. DoSysCallDebug : Boolean = False;
  188. var
  189. LastCnt,
  190. LastEax,
  191. LastCall : longint;
  192. DebugTxt : string[20];
  193. {$ENDIF}
  194. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  195. {
  196. This function serves as an interface to do_SysCall.
  197. If the SysCall returned a negative number, it returns -1, and puts the
  198. SysCall result in errno. Otherwise, it returns the SysCall return value
  199. }
  200. begin
  201. FpSysCall(callnr,regs);
  202. if regs.reg1<0 then
  203. begin
  204. {$IFDEF SYSCALL_DEBUG}
  205. If DoSysCallDebug then
  206. debugtxt:=' syscall error: ';
  207. {$endif}
  208. ErrNo:=-regs.reg1;
  209. SysCall:=-1;
  210. end
  211. else
  212. begin
  213. {$IFDEF SYSCALL_DEBUG}
  214. if DoSysCallDebug then
  215. debugtxt:=' syscall returned: ';
  216. {$endif}
  217. SysCall:=regs.reg1;
  218. errno:=0
  219. end;
  220. {$IFDEF SYSCALL_DEBUG}
  221. if DoSysCallDebug then
  222. begin
  223. inc(lastcnt);
  224. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  225. begin
  226. if lastcnt>1 then
  227. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  228. lastcall:=callnr;
  229. lasteax:=regs.reg1;
  230. lastcnt:=0;
  231. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  232. end;
  233. end;
  234. {$endif}
  235. end;
  236. {
  237. $Log$
  238. Revision 1.4 2004-01-20 21:01:57 florian
  239. * fixed setjump
  240. * fixed syscalls
  241. Revision 1.3 2003/12/29 19:24:12 florian
  242. + introduced PtrInt and PtrUInt
  243. * made strscan 64 bit safe
  244. Revision 1.2 2003/12/03 17:34:12 florian
  245. + started to implement arm syscalls
  246. Revision 1.1 2003/08/28 00:08:29 florian
  247. * syscall skeleton
  248. }