syscall.inc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. 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. {$define FPC_SYSTEM_HAS_FPFORK}
  17. {
  18. behaviour of result of fork on sparc/linux is different than on other
  19. linux flavours
  20. }
  21. function Fpfork : pid_t; [public, alias : 'FPC_SYSC_FORK'];assembler;
  22. asm
  23. mov 2,%g1
  24. ta 0x10
  25. bcc .LSyscOK
  26. nop
  27. mov %o0,%l0
  28. sethi %hi(fpc_threadvar_relocate_proc),%o2
  29. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  30. ld [%o2],%o3
  31. subcc %o3,%g0,%g0
  32. bne .LThread
  33. nop
  34. sethi %hi(Errno+4),%o0
  35. ba .LNoThread
  36. or %o0,%lo(Errno+4),%o0
  37. .LThread:
  38. sethi %hi(Errno),%o0
  39. or %o0,%lo(Errno),%o0
  40. call %o3
  41. ld [%o0],%o0
  42. .LNoThread:
  43. st %l0,[%o0]
  44. ba .LReturn
  45. mov -1,%i0
  46. .LSyscOK:
  47. // o1 contains 1 in the parent
  48. // and 0 in the child
  49. sub %o1, 1, %o1
  50. and %o0, %o1, %i0
  51. .LReturn:
  52. end;
  53. {*****************************************************************************
  54. --- Main:The System Call Self ---
  55. *****************************************************************************}
  56. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  57. {
  58. This function puts the registers in place, does the call, and then
  59. copies back the registers as they are after the SysCall.
  60. }
  61. asm
  62. mov %i0,%g1
  63. ta 0x10
  64. bcc .LSyscOK
  65. nop
  66. mov %o0,%l0
  67. sethi %hi(fpc_threadvar_relocate_proc),%o2
  68. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  69. ld [%o2],%o3
  70. subcc %o3,%g0,%g0
  71. bne .LThread
  72. nop
  73. sethi %hi(Errno+4),%o0
  74. ba .LNoThread
  75. or %o0,%lo(Errno+4),%o0
  76. .LThread:
  77. sethi %hi(Errno),%o0
  78. or %o0,%lo(Errno),%o0
  79. call %o3
  80. ld [%o0],%o0
  81. .LNoThread:
  82. st %l0,[%o0]
  83. mov -1,%o0
  84. .LSyscOK:
  85. mov %o0,%i0
  86. end;
  87. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  88. {
  89. This function puts the registers in place, does the call, and then
  90. copies back the registers as they are after the SysCall.
  91. }
  92. asm
  93. mov %i0,%g1
  94. mov %i1,%o0
  95. ta 0x10
  96. bcc .LSyscOK
  97. nop
  98. mov %o0,%l0
  99. sethi %hi(fpc_threadvar_relocate_proc),%o2
  100. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  101. ld [%o2],%o3
  102. subcc %o3,%g0,%g0
  103. bne .LThread
  104. nop
  105. sethi %hi(Errno+4),%o0
  106. ba .LNoThread
  107. or %o0,%lo(Errno+4),%o0
  108. .LThread:
  109. sethi %hi(Errno),%o0
  110. or %o0,%lo(Errno),%o0
  111. call %o3
  112. ld [%o0],%o0
  113. .LNoThread:
  114. st %l0,[%o0]
  115. mov -1,%o0
  116. .LSyscOK:
  117. mov %o0,%i0
  118. end;
  119. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  120. {
  121. This function puts the registers in place, does the call, and then
  122. copies back the registers as they are after the SysCall.
  123. }
  124. asm
  125. mov %i0,%g1
  126. mov %i1,%o0
  127. mov %i2,%o1
  128. ta 0x10
  129. bcc .LSyscOK
  130. nop
  131. mov %o0,%l0
  132. sethi %hi(fpc_threadvar_relocate_proc),%o2
  133. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  134. ld [%o2],%o3
  135. subcc %o3,%g0,%g0
  136. bne .LThread
  137. nop
  138. sethi %hi(Errno+4),%o0
  139. ba .LNoThread
  140. or %o0,%lo(Errno+4),%o0
  141. .LThread:
  142. sethi %hi(Errno),%o0
  143. or %o0,%lo(Errno),%o0
  144. call %o3
  145. ld [%o0],%o0
  146. .LNoThread:
  147. st %l0,[%o0]
  148. mov -1,%o0
  149. .LSyscOK:
  150. mov %o0,%i0
  151. end;
  152. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  153. {
  154. This function puts the registers in place, does the call, and then
  155. copies back the registers as they are after the SysCall.
  156. }
  157. asm
  158. mov %i0,%g1
  159. mov %i1,%o0
  160. mov %i2,%o1
  161. mov %i3,%o2
  162. ta 0x10
  163. bcc .LSyscOK
  164. nop
  165. mov %o0,%l0
  166. sethi %hi(fpc_threadvar_relocate_proc),%o2
  167. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  168. ld [%o2],%o3
  169. subcc %o3,%g0,%g0
  170. bne .LThread
  171. nop
  172. sethi %hi(Errno+4),%o2
  173. ba .LNoThread
  174. or %o2,%lo(Errno+4),%o2
  175. .LThread:
  176. sethi %hi(Errno),%o0
  177. ld [%o3],%o1
  178. or %o0,%lo(Errno),%o0
  179. call %o1
  180. nop
  181. .LNoThread:
  182. st %o0,[%o2]
  183. mov -1,%o0
  184. .LSyscOK:
  185. mov %o0,%i0
  186. end;
  187. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  188. {
  189. This function puts the registers in place, does the call, and then
  190. copies back the registers as they are after the SysCall.
  191. }
  192. asm
  193. mov %i0,%g1
  194. mov %i1,%o0
  195. mov %i2,%o1
  196. mov %i3,%o2
  197. mov %i4,%o3
  198. ta 0x10
  199. bcc .LSyscOK
  200. nop
  201. mov %o0,%l0
  202. sethi %hi(fpc_threadvar_relocate_proc),%o2
  203. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  204. ld [%o2],%o3
  205. subcc %o3,%g0,%g0
  206. bne .LThread
  207. nop
  208. sethi %hi(Errno+4),%o0
  209. ba .LNoThread
  210. or %o0,%lo(Errno+4),%o0
  211. .LThread:
  212. sethi %hi(Errno),%o0
  213. or %o0,%lo(Errno),%o0
  214. call %o3
  215. ld [%o0],%o0
  216. .LNoThread:
  217. st %l0,[%o0]
  218. mov -1,%o0
  219. .LSyscOK:
  220. mov %o0,%i0
  221. end;
  222. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  223. {
  224. This function puts the registers in place, does the call, and then
  225. copies back the registers as they are after the SysCall.
  226. }
  227. asm
  228. mov %i0,%g1
  229. mov %i1,%o0
  230. mov %i2,%o1
  231. mov %i3,%o2
  232. mov %i4,%o3
  233. mov %i5,%o4
  234. ta 0x10
  235. bcc .LSyscOK
  236. nop
  237. mov %o0,%l0
  238. sethi %hi(fpc_threadvar_relocate_proc),%o2
  239. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  240. ld [%o2],%o3
  241. subcc %o3,%g0,%g0
  242. bne .LThread
  243. nop
  244. sethi %hi(Errno+4),%o0
  245. ba .LNoThread
  246. or %o0,%lo(Errno+4),%o0
  247. .LThread:
  248. sethi %hi(Errno),%o0
  249. or %o0,%lo(Errno),%o0
  250. call %o3
  251. ld [%o0],%o0
  252. .LNoThread:
  253. st %l0,[%o0]
  254. mov -1,%o0
  255. .LSyscOK:
  256. mov %o0,%i0
  257. end;
  258. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  259. {
  260. This function puts the registers in place, does the call, and then
  261. copies back the registers as they are after the SysCall.
  262. }
  263. asm
  264. mov %i0,%g1
  265. mov %i1,%o0
  266. mov %i2,%o1
  267. mov %i3,%o2
  268. mov %i4,%o3
  269. ld [%i6+92],%o5
  270. mov %i5,%o4
  271. ta 0x10
  272. bcc .LSyscOK
  273. nop
  274. mov %o0,%l0
  275. sethi %hi(fpc_threadvar_relocate_proc),%o2
  276. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  277. ld [%o2],%o3
  278. subcc %o3,%g0,%g0
  279. bne .LThread
  280. nop
  281. sethi %hi(Errno+4),%o0
  282. ba .LNoThread
  283. or %o0,%lo(Errno+4),%o0
  284. .LThread:
  285. sethi %hi(Errno),%o0
  286. or %o0,%lo(Errno),%o0
  287. call %o3
  288. ld [%o0],%o0
  289. .LNoThread:
  290. st %l0,[%o0]
  291. mov -1,%o0
  292. .LSyscOK:
  293. mov %o0,%i0
  294. end;
  295. {
  296. $Log$
  297. Revision 1.16 2004-11-07 00:30:17 florian
  298. * more errno setting in sparc/linux mt programs fixed
  299. Revision 1.15 2004/11/06 22:48:16 florian
  300. * fixed errno setting in mt sparc/linux mt programs
  301. Revision 1.14 2004/08/22 12:34:11 florian
  302. * fixed fork for sparc
  303. Revision 1.13 2004/07/02 19:29:19 peter
  304. * fixed errno setting
  305. Revision 1.12 2004/06/30 21:15:51 florian
  306. * first syscall fix
  307. Revision 1.11 2004/02/06 23:06:16 florian
  308. - killed tsyscallregs
  309. Revision 1.10 2004/01/05 17:22:03 peter
  310. * removed asmmode direct
  311. Revision 1.9 2003/08/11 13:19:08 mazen
  312. + added assembler mode directive to use direct assembler reader
  313. Revision 1.8 2003/07/06 22:08:05 peter
  314. * fix setting return value
  315. Revision 1.7 2003/07/06 20:40:10 peter
  316. * wrong return reg
  317. Revision 1.6 2003/07/03 21:03:57 peter
  318. * syscalls implemented
  319. Revision 1.5 2003/06/02 22:05:03 mazen
  320. * fixing naming conflict in public clause of
  321. FPC_SYSCALL? definition
  322. Revision 1.4 2003/05/23 22:36:39 florian
  323. * fixed compilation of sparc system unit
  324. Revision 1.3 2003/01/05 21:32:35 mazen
  325. * fixing several bugs compiling the RTL
  326. Revision 1.2 2002/12/24 21:30:20 mazen
  327. - some writeln(s) removed in compiler
  328. + many files added to RTL
  329. * some errors fixed in RTL
  330. Revision 1.1 2002/11/15 12:08:37 mazen
  331. + SPARC support added based on PowerPc sources
  332. Revision 1.1 2002/11/09 20:32:14 marco
  333. * powerpc version. Threadsafe errno access not yet done.
  334. Revision 1.1 2002/10/14 19:39:44 peter
  335. * syscall moved into seperate include
  336. }