syscall.inc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. {$ifdef REGCALL}
  27. movl fpc_threadvar_relocate_proc,%ecx
  28. testl %ecx,%ecx
  29. jne .LThread
  30. movl %eax,Errno+4
  31. jmp .LNoThread
  32. .LThread:
  33. movl %eax,%ebx
  34. call *%ecx
  35. movl %ebx,(%eax)
  36. .LNoThread:
  37. {$else}
  38. movl %eax,%edx
  39. movl fpc_threadvar_relocate_proc,%eax
  40. testl %eax,%eax
  41. jne .LThread
  42. movl %edx,Errno+4
  43. jmp .LNoThread
  44. .LThread:
  45. pushl %edx
  46. pushl Errno
  47. call *%eax
  48. popl %edx
  49. movl %edx,(%eax)
  50. .LNoThread:
  51. {$endif REGCALL}
  52. {$endif ver1_0}
  53. movl $-1,%eax
  54. .LSyscOK:
  55. end;
  56. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler; {$ifndef VER1_0} oldfpccall; {$endif}[public,alias:'FPC_SYSCALL1'];
  57. asm
  58. { load the registers... }
  59. movl sysnr,%eax
  60. movl param1,%ebx
  61. int $0x80
  62. cmpl $-4095,%eax
  63. jb .LSyscOK
  64. negl %eax
  65. {$ifdef VER1_0}
  66. movl %eax,Errno
  67. {$else}
  68. {$ifdef REGCALL}
  69. movl fpc_threadvar_relocate_proc,%ecx
  70. testl %ecx,%ecx
  71. jne .LThread
  72. movl %eax,Errno+4
  73. jmp .LNoThread
  74. .LThread:
  75. movl %eax,%ebx
  76. call *%ecx
  77. movl %ebx,(%eax)
  78. .LNoThread:
  79. {$else}
  80. movl %eax,%edx
  81. movl fpc_threadvar_relocate_proc,%eax
  82. testl %eax,%eax
  83. jne .LThread
  84. movl %edx,Errno+4
  85. jmp .LNoThread
  86. .LThread:
  87. pushl %edx
  88. pushl Errno
  89. call *%eax
  90. popl %edx
  91. movl %edx,(%eax)
  92. .LNoThread:
  93. {$endif REGCALL}
  94. {$endif ver1_0}
  95. movl $-1,%eax
  96. .LSyscOK:
  97. end;
  98. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler; {$ifndef VER1_0} oldfpccall; {$endif} [public,alias:'FPC_SYSCALL2'];
  99. asm
  100. { load the registers... }
  101. movl sysnr,%eax
  102. movl param1,%ebx
  103. movl param2,%ecx
  104. int $0x80
  105. testl %eax,%eax
  106. jns .LSyscOK
  107. negl %eax
  108. {$ifdef VER1_0}
  109. movl %eax,Errno
  110. {$else}
  111. {$ifdef REGCALL}
  112. movl fpc_threadvar_relocate_proc,%ecx
  113. testl %ecx,%ecx
  114. jne .LThread
  115. movl %eax,Errno+4
  116. jmp .LNoThread
  117. .LThread:
  118. movl %eax,%ebx
  119. call *%ecx
  120. movl %ebx,(%eax)
  121. .LNoThread:
  122. {$else}
  123. movl %eax,%edx
  124. movl fpc_threadvar_relocate_proc,%eax
  125. testl %eax,%eax
  126. jne .LThread
  127. movl %edx,Errno+4
  128. jmp .LNoThread
  129. .LThread:
  130. pushl %edx
  131. pushl Errno
  132. call *%eax
  133. popl %edx
  134. movl %edx,(%eax)
  135. .LNoThread:
  136. {$endif REGCALL}
  137. {$endif ver1_0}
  138. movl $-1,%eax
  139. .LSyscOK:
  140. end;
  141. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler; {$ifndef VER1_0} oldfpccall; {$endif} [public,alias:'FPC_SYSCALL3'];
  142. asm
  143. { load the registers... }
  144. movl sysnr,%eax
  145. movl param1,%ebx
  146. movl param2,%ecx
  147. movl param3,%edx
  148. int $0x80
  149. testl %eax,%eax
  150. jns .LSyscOK
  151. negl %eax
  152. {$ifdef VER1_0}
  153. movl %eax,Errno
  154. {$else}
  155. {$ifdef REGCALL}
  156. movl fpc_threadvar_relocate_proc,%ecx
  157. testl %ecx,%ecx
  158. jne .LThread
  159. movl %eax,Errno+4
  160. jmp .LNoThread
  161. .LThread:
  162. movl %eax,%ebx
  163. call *%ecx
  164. movl %ebx,(%eax)
  165. .LNoThread:
  166. {$else}
  167. movl %eax,%edx
  168. movl fpc_threadvar_relocate_proc,%eax
  169. testl %eax,%eax
  170. jne .LThread
  171. movl %edx,Errno+4
  172. jmp .LNoThread
  173. .LThread:
  174. pushl %edx
  175. pushl Errno
  176. call *%eax
  177. popl %edx
  178. movl %edx,(%eax)
  179. .LNoThread:
  180. {$endif REGCALL}
  181. {$endif ver1_0}
  182. movl $-1,%eax
  183. .LSyscOK:
  184. end;
  185. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler; {$ifndef VER1_0} oldfpccall; {$endif} [public,alias:'FPC_SYSCALL4'];
  186. asm
  187. { load the registers... }
  188. movl sysnr,%eax
  189. movl param1,%ebx
  190. movl param2,%ecx
  191. movl param3,%edx
  192. movl param4,%esi
  193. int $0x80
  194. testl %eax,%eax
  195. jns .LSyscOK
  196. negl %eax
  197. {$ifdef VER1_0}
  198. movl %eax,Errno
  199. {$else}
  200. {$ifdef REGCALL}
  201. movl fpc_threadvar_relocate_proc,%ecx
  202. testl %ecx,%ecx
  203. jne .LThread
  204. movl %eax,Errno+4
  205. jmp .LNoThread
  206. .LThread:
  207. movl %eax,%ebx
  208. call *%ecx
  209. movl %ebx,(%eax)
  210. .LNoThread:
  211. {$else}
  212. movl %eax,%edx
  213. movl fpc_threadvar_relocate_proc,%eax
  214. testl %eax,%eax
  215. jne .LThread
  216. movl %edx,Errno+4
  217. jmp .LNoThread
  218. .LThread:
  219. pushl %edx
  220. pushl Errno
  221. call *%eax
  222. popl %edx
  223. movl %edx,(%eax)
  224. .LNoThread:
  225. {$endif REGCALL}
  226. {$endif ver1_0}
  227. movl $-1,%eax
  228. .LSyscOK:
  229. end;
  230. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler; {$ifndef VER1_0} oldfpccall; {$endif}[public,alias:'FPC_SYSCALL5'];
  231. asm
  232. { load the registers... }
  233. movl sysnr,%eax
  234. movl param1,%ebx
  235. movl param2,%ecx
  236. movl param3,%edx
  237. movl param4,%esi
  238. movl param5,%edi
  239. int $0x80
  240. testl %eax,%eax
  241. jns .LSyscOK
  242. negl %eax
  243. {$ifdef VER1_0}
  244. movl %eax,Errno
  245. {$else}
  246. {$ifdef REGCALL}
  247. movl fpc_threadvar_relocate_proc,%ecx
  248. testl %ecx,%ecx
  249. jne .LThread
  250. movl %eax,Errno+4
  251. jmp .LNoThread
  252. .LThread:
  253. movl %eax,%ebx
  254. call *%ecx
  255. movl %ebx,(%eax)
  256. .LNoThread:
  257. {$else}
  258. movl %eax,%edx
  259. movl fpc_threadvar_relocate_proc,%eax
  260. testl %eax,%eax
  261. jne .LThread
  262. movl %edx,Errno+4
  263. jmp .LNoThread
  264. .LThread:
  265. pushl %edx
  266. pushl Errno
  267. call *%eax
  268. popl %edx
  269. movl %edx,(%eax)
  270. .LNoThread:
  271. {$endif REGCALL}
  272. {$endif ver1_0}
  273. movl $-1,%eax
  274. .LSyscOK:
  275. end;
  276. {$ifdef notsupported}
  277. { Only 5 params are pushed, so it'll not work as expected (PFV) }
  278. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler; {$ifndef VER1_0} oldfpccall; {$endif}[public,alias:'FPC_SYSCALL6'];
  279. asm
  280. { load the registers... }
  281. movl sysnr,%eax
  282. movl param1,%ebx
  283. movl param2,%ecx
  284. movl param3,%edx
  285. movl param4,%esi
  286. movl param5,%edi
  287. int $0x80
  288. testl %eax,%eax
  289. jns .LSyscOK
  290. negl %eax
  291. {$ifdef VER1_0}
  292. movl %eax,Errno
  293. {$else}
  294. {$ifdef REGCALL}
  295. movl fpc_threadvar_relocate_proc,%ecx
  296. testl %ecx,%ecx
  297. jne .LThread
  298. movl %eax,Errno+4
  299. jmp .LNoThread
  300. .LThread:
  301. movl %eax,%ebx
  302. call *%ecx
  303. movl %ebx,(%eax)
  304. .LNoThread:
  305. {$else}
  306. movl %eax,%edx
  307. movl fpc_threadvar_relocate_proc,%eax
  308. testl %eax,%eax
  309. jne .LThread
  310. movl %edx,Errno+4
  311. jmp .LNoThread
  312. .LThread:
  313. pushl %edx
  314. pushl Errno
  315. call *%eax
  316. popl %edx
  317. movl %edx,(%eax)
  318. .LNoThread:
  319. {$endif REGCALL}
  320. {$endif ver1_0}
  321. movl $-1,%eax
  322. .LSyscOK:
  323. end;
  324. {$endif notsupported}
  325. {No debugging for syslinux include !}
  326. {$IFDEF SYS_LINUX}
  327. {$UNDEF SYSCALL_DEBUG}
  328. {$ENDIF SYS_LINUX}
  329. {
  330. $Log$
  331. Revision 1.14 2004-03-10 21:41:53 jonas
  332. * fixed syscall return value checking
  333. Revision 1.13 2004/03/03 22:10:48 peter
  334. * fixed previous commit
  335. Revision 1.12 2004/03/03 22:03:10 peter
  336. * regcall fix for threadvar
  337. Revision 1.11 2004/02/06 23:06:16 florian
  338. - killed tsyscallregs
  339. Revision 1.10 2004/01/06 21:32:53 peter
  340. * use relocate_proc
  341. Revision 1.9 2003/09/14 20:15:01 marco
  342. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  343. Revision 1.7 2002/12/24 19:45:59 peter
  344. * only set errno when syscall fails
  345. Revision 1.6 2002/12/23 21:17:53 peter
  346. * MT fix
  347. Revision 1.5 2002/12/23 20:56:32 peter
  348. * Reset Errno to 0 if call is successfull
  349. * Fix broken 1.0.x Errno which does not have threadvar
  350. Revision 1.4 2002/12/18 20:41:33 peter
  351. * Threadvar support for Errno
  352. * Fixed syscall error return check
  353. * Uncommented Syscall with 6 parameters, only 5 were really set
  354. Revision 1.3 2002/12/18 16:46:37 marco
  355. * Some mods.
  356. Revision 1.2 2002/11/16 15:37:47 marco
  357. * TSysParam + result moved to -h
  358. Revision 1.1 2002/11/12 13:31:32 marco
  359. * New syscall.inc
  360. }