syscall.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. The syscalls for the new RTL, moved to platform dependant dir.
  7. Old linux calling convention is stil kept.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. {$ASMMODE ATT}
  15. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL0'];
  16. asm
  17. { load the registers... }
  18. movl sysnr,%eax
  19. int $0x80
  20. testl %eax,%eax
  21. jns .LSyscOK
  22. negl %eax
  23. {$ifdef VER1_0}
  24. movl %eax,Errno
  25. {$else}
  26. movl %eax,%edx
  27. movl FPC_THREADVAR_RELOCATE,%eax
  28. testl %eax,%eax
  29. jne .LThread
  30. movl %edx,Errno+4
  31. jmp .LNoThread
  32. .LThread:
  33. pushl %edx
  34. pushl Errno
  35. call *%eax
  36. popl %edx
  37. movl %edx,(%eax)
  38. .LNoThread:
  39. movl $-1,%eax
  40. {$endif}
  41. .LSyscOK:
  42. end;
  43. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL1'];
  44. asm
  45. { load the registers... }
  46. movl sysnr,%eax
  47. movl param1,%ebx
  48. int $0x80
  49. testl %eax,%eax
  50. jns .LSyscOK
  51. negl %eax
  52. {$ifdef VER1_0}
  53. movl %eax,Errno
  54. {$else}
  55. movl %eax,%edx
  56. movl FPC_THREADVAR_RELOCATE,%eax
  57. testl %eax,%eax
  58. jne .LThread
  59. movl %edx,Errno+4
  60. jmp .LNoThread
  61. .LThread:
  62. pushl %edx
  63. pushl Errno
  64. call *%eax
  65. popl %edx
  66. movl %edx,(%eax)
  67. .LNoThread:
  68. movl $-1,%eax
  69. {$endif}
  70. .LSyscOK:
  71. end;
  72. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL2'];
  73. asm
  74. { load the registers... }
  75. movl sysnr,%eax
  76. movl param1,%ebx
  77. movl param2,%ecx
  78. int $0x80
  79. testl %eax,%eax
  80. jns .LSyscOK
  81. negl %eax
  82. {$ifdef VER1_0}
  83. movl %eax,Errno
  84. {$else}
  85. movl %eax,%edx
  86. movl FPC_THREADVAR_RELOCATE,%eax
  87. testl %eax,%eax
  88. jne .LThread
  89. movl %edx,Errno+4
  90. jmp .LNoThread
  91. .LThread:
  92. pushl %edx
  93. pushl Errno
  94. call *%eax
  95. popl %edx
  96. movl %edx,(%eax)
  97. .LNoThread:
  98. movl $-1,%eax
  99. {$endif}
  100. .LSyscOK:
  101. end;
  102. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL3'];
  103. asm
  104. { load the registers... }
  105. movl sysnr,%eax
  106. movl param1,%ebx
  107. movl param2,%ecx
  108. movl param3,%edx
  109. int $0x80
  110. testl %eax,%eax
  111. jns .LSyscOK
  112. negl %eax
  113. {$ifdef VER1_0}
  114. movl %eax,Errno
  115. {$else}
  116. movl %eax,%edx
  117. movl FPC_THREADVAR_RELOCATE,%eax
  118. testl %eax,%eax
  119. jne .LThread
  120. movl %edx,Errno+4
  121. jmp .LNoThread
  122. .LThread:
  123. pushl %edx
  124. pushl Errno
  125. call *%eax
  126. popl %edx
  127. movl %edx,(%eax)
  128. .LNoThread:
  129. movl $-1,%eax
  130. {$endif}
  131. .LSyscOK:
  132. end;
  133. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL4'];
  134. asm
  135. { load the registers... }
  136. movl sysnr,%eax
  137. movl param1,%ebx
  138. movl param2,%ecx
  139. movl param3,%edx
  140. movl param4,%esi
  141. int $0x80
  142. testl %eax,%eax
  143. jns .LSyscOK
  144. negl %eax
  145. {$ifdef VER1_0}
  146. movl %eax,Errno
  147. {$else}
  148. movl %eax,%edx
  149. movl FPC_THREADVAR_RELOCATE,%eax
  150. testl %eax,%eax
  151. jne .LThread
  152. movl %edx,Errno+4
  153. jmp .LNoThread
  154. .LThread:
  155. pushl %edx
  156. pushl Errno
  157. call *%eax
  158. popl %edx
  159. movl %edx,(%eax)
  160. .LNoThread:
  161. movl $-1,%eax
  162. {$endif}
  163. .LSyscOK:
  164. end;
  165. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL5'];
  166. asm
  167. { load the registers... }
  168. movl sysnr,%eax
  169. movl param1,%ebx
  170. movl param2,%ecx
  171. movl param3,%edx
  172. movl param4,%esi
  173. movl param5,%edi
  174. int $0x80
  175. testl %eax,%eax
  176. jns .LSyscOK
  177. negl %eax
  178. {$ifdef VER1_0}
  179. movl %eax,Errno
  180. {$else}
  181. movl %eax,%edx
  182. movl FPC_THREADVAR_RELOCATE,%eax
  183. testl %eax,%eax
  184. jne .LThread
  185. movl %edx,Errno+4
  186. jmp .LNoThread
  187. .LThread:
  188. pushl %edx
  189. pushl Errno
  190. call *%eax
  191. popl %edx
  192. movl %edx,(%eax)
  193. .LNoThread:
  194. movl $-1,%eax
  195. {$endif}
  196. .LSyscOK:
  197. end;
  198. {$ifdef notsupported}
  199. { Only 5 params are pushed, so it'll not work as expected (PFV) }
  200. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL6'];
  201. asm
  202. { load the registers... }
  203. movl sysnr,%eax
  204. movl param1,%ebx
  205. movl param2,%ecx
  206. movl param3,%edx
  207. movl param4,%esi
  208. movl param5,%edi
  209. int $0x80
  210. testl %eax,%eax
  211. jns .LSyscOK
  212. negl %eax
  213. {$ifdef VER1_0}
  214. movl %eax,Errno
  215. {$else}
  216. movl %eax,%edx
  217. movl FPC_THREADVAR_RELOCATE,%eax
  218. testl %eax,%eax
  219. jne .LThread
  220. movl %edx,Errno+4
  221. jmp .LNoThread
  222. .LThread:
  223. pushl %edx
  224. pushl Errno
  225. call *%eax
  226. popl %edx
  227. movl %edx,(%eax)
  228. .LNoThread:
  229. movl $-1,%eax
  230. {$endif}
  231. .LSyscOK:
  232. end;
  233. {$endif notsupported}
  234. {No debugging for syslinux include !}
  235. {$IFDEF SYS_LINUX}
  236. {$UNDEF SYSCALL_DEBUG}
  237. {$ENDIF SYS_LINUX}
  238. {*****************************************************************************
  239. --- Main:The System Call Self ---
  240. *****************************************************************************}
  241. Procedure FpSysCall( callnr:TSysParam;var regs : SysCallregs );assembler;{$ifndef VER1_0}oldfpccall;{$endif}
  242. {
  243. This function puts the registers in place, does the call, and then
  244. copies back the registers as they are after the SysCall.
  245. }
  246. {$ASMMODE ATT}
  247. {$define fpc_syscall_ok}
  248. asm
  249. { load the registers... }
  250. movl 12(%ebp),%eax
  251. movl 4(%eax),%ebx
  252. movl 8(%eax),%ecx
  253. movl 12(%eax),%edx
  254. movl 16(%eax),%esi
  255. movl 20(%eax),%edi
  256. { set the call number }
  257. movl 8(%ebp),%eax
  258. { Go ! }
  259. int $0x80
  260. { Put back the registers... }
  261. pushl %eax
  262. movl 12(%ebp),%eax
  263. movl %edi,20(%eax)
  264. movl %esi,16(%eax)
  265. movl %edx,12(%eax)
  266. movl %ecx,8(%eax)
  267. movl %ebx,4(%eax)
  268. popl %ebx
  269. movl %ebx,(%eax)
  270. end;
  271. {$ASMMODE DEFAULT}
  272. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  273. {
  274. This function serves as an interface to do_SysCall.
  275. If the SysCall returned a negative number, it returns -1, and puts the
  276. SysCall result in errno. Otherwise, it returns the SysCall return value
  277. }
  278. begin
  279. FpSysCall(callnr,regs);
  280. if regs.reg1<0 then
  281. begin
  282. {$IFDEF SYSCALL_DEBUG}
  283. If DoSysCallDebug then
  284. debugtxt:=' syscall error: ';
  285. {$endif}
  286. setErrNo(-regs.reg1);
  287. SysCall:=-1;
  288. end
  289. else
  290. begin
  291. {$IFDEF SYSCALL_DEBUG}
  292. if DoSysCallDebug then
  293. debugtxt:=' syscall returned: ';
  294. {$endif}
  295. SysCall:=regs.reg1;
  296. seterrno(0);
  297. end;
  298. {$IFDEF SYSCALL_DEBUG}
  299. if DoSysCallDebug then
  300. begin
  301. inc(lastcnt);
  302. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  303. begin
  304. if lastcnt>1 then
  305. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  306. lastcall:=callnr;
  307. lasteax:=regs.reg1;
  308. lastcnt:=0;
  309. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  310. end;
  311. end;
  312. {$endif}
  313. end;
  314. {
  315. $Log$
  316. Revision 1.8 2003-09-14 11:34:13 peter
  317. * moved int64 asm code to int64p.inc
  318. * save ebx,esi
  319. Revision 1.7 2002/12/24 19:45:59 peter
  320. * only set errno when syscall fails
  321. Revision 1.6 2002/12/23 21:17:53 peter
  322. * MT fix
  323. Revision 1.5 2002/12/23 20:56:32 peter
  324. * Reset Errno to 0 if call is successfull
  325. * Fix broken 1.0.x Errno which does not have threadvar
  326. Revision 1.4 2002/12/18 20:41:33 peter
  327. * Threadvar support for Errno
  328. * Fixed syscall error return check
  329. * Uncommented Syscall with 6 parameters, only 5 were really set
  330. Revision 1.3 2002/12/18 16:46:37 marco
  331. * Some mods.
  332. Revision 1.2 2002/11/16 15:37:47 marco
  333. * TSysParam + result moved to -h
  334. Revision 1.1 2002/11/12 13:31:32 marco
  335. * New syscall.inc
  336. }