syscall.inc 8.2 KB

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