syscall.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. end;
  166. {$IFDEF SYSCALL_DEBUG}
  167. Const
  168. DoSysCallDebug : Boolean = False;
  169. var
  170. LastCnt,
  171. LastEax,
  172. LastCall : longint;
  173. DebugTxt : string[20];
  174. {$ENDIF}
  175. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  176. {
  177. This function serves as an interface to do_SysCall.
  178. If the SysCall returned a negative number, it returns -1, and puts the
  179. SysCall result in errno. Otherwise, it returns the SysCall return value
  180. }
  181. begin
  182. FpSysCall(callnr,regs);
  183. if regs.reg1<0 then
  184. begin
  185. {$IFDEF SYSCALL_DEBUG}
  186. If DoSysCallDebug then
  187. debugtxt:=' syscall error: ';
  188. {$endif}
  189. ErrNo:=-regs.reg1;
  190. SysCall:=-1;
  191. end
  192. else
  193. begin
  194. {$IFDEF SYSCALL_DEBUG}
  195. if DoSysCallDebug then
  196. debugtxt:=' syscall returned: ';
  197. {$endif}
  198. SysCall:=regs.reg1;
  199. errno:=0
  200. end;
  201. {$IFDEF SYSCALL_DEBUG}
  202. if DoSysCallDebug then
  203. begin
  204. inc(lastcnt);
  205. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  206. begin
  207. if lastcnt>1 then
  208. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  209. lastcall:=callnr;
  210. lasteax:=regs.reg1;
  211. lastcnt:=0;
  212. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  213. end;
  214. end;
  215. {$endif}
  216. end;
  217. {
  218. $Log$
  219. Revision 1.3 2003-12-29 19:24:12 florian
  220. + introduced PtrInt and PtrUInt
  221. * made strscan 64 bit safe
  222. Revision 1.2 2003/12/03 17:34:12 florian
  223. + started to implement arm syscalls
  224. Revision 1.1 2003/08/28 00:08:29 florian
  225. * syscall skeleton
  226. }