syscall.inc 9.4 KB

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