syscall.inc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2009 by Michael Van Canneyt and David Zhang
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {No debugging for syslinux include !}
  11. {$IFDEF SYS_LINUX}
  12. {$UNDEF SYSCALL_DEBUG}
  13. {$ENDIF SYS_LINUX}
  14. {$define FPC_SYSTEM_HAS_FPFORK}
  15. {
  16. behaviour of result of fork on sparc/linux is different than on other
  17. linux flavours
  18. }
  19. function Fpfork : pid_t; [public, alias : 'FPC_SYSC_FORK'];assembler;
  20. var
  21. temp: longint;
  22. asm
  23. li $2,4002
  24. syscall
  25. nop
  26. beq $7,$0,.LDone
  27. nop
  28. lui $8,%hi(fpc_threadvar_relocate_proc)
  29. addiu $8,%lo(fpc_threadvar_relocate_proc)
  30. lw $8,0($8)
  31. bne $8,$0,.LThreaded
  32. nop
  33. lui $4,%hi(Errno+4)
  34. addiu $4,%lo(Errno+4)
  35. sw $2,0($4)
  36. b .LFailed
  37. nop
  38. .LThreaded:
  39. sw $2,temp
  40. lui $4,%hi(errno)
  41. addiu $4,$4,%lo(errno)
  42. jalr $8
  43. nop
  44. lw $8,temp
  45. sw $8,0($2)
  46. .LFailed:
  47. li $2,-1
  48. .LDone:
  49. end;
  50. {*****************************************************************************
  51. --- Main:The System Call Self ---
  52. *****************************************************************************}
  53. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  54. {
  55. This function puts the registers in place, does the call, and then
  56. copies back the registers as they are after the SysCall.
  57. }
  58. var
  59. temp: longint;
  60. asm
  61. move $v0,$a0
  62. syscall
  63. nop
  64. beq $7,$0,.LDone
  65. nop
  66. lui $8,%hi(fpc_threadvar_relocate_proc)
  67. addiu $8,%lo(fpc_threadvar_relocate_proc)
  68. lw $8,0($8)
  69. bne $8,$0,.LThreaded
  70. nop
  71. lui $4,%hi(Errno+4)
  72. addiu $4,%lo(Errno+4)
  73. sw $2,0($4)
  74. b .LFailed
  75. nop
  76. .LThreaded:
  77. sw $2,temp
  78. lui $4,%hi(errno)
  79. addiu $4,$4,%lo(errno)
  80. jalr $8
  81. nop
  82. lw $8,temp
  83. sw $8,0($2)
  84. .LFailed:
  85. li $2,-1
  86. .LDone:
  87. end;
  88. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  89. {
  90. This function puts the registers in place, does the call, and then
  91. copies back the registers as they are after the SysCall.
  92. }
  93. var
  94. temp: longint;
  95. asm
  96. move $v0,$a0
  97. move $a0,$a1
  98. syscall
  99. nop
  100. beq $7,$0,.LDone
  101. nop
  102. lui $8,%hi(fpc_threadvar_relocate_proc)
  103. addiu $8,%lo(fpc_threadvar_relocate_proc)
  104. lw $8,0($8)
  105. bne $8,$0,.LThreaded
  106. nop
  107. lui $4,%hi(Errno+4)
  108. addiu $4,%lo(Errno+4)
  109. sw $2,0($4)
  110. b .LFailed
  111. nop
  112. .LThreaded:
  113. sw $2,temp
  114. lui $4,%hi(errno)
  115. addiu $4,$4,%lo(errno)
  116. jalr $8
  117. nop
  118. lw $8,temp
  119. sw $8,0($2)
  120. .LFailed:
  121. li $2,-1
  122. .LDone:
  123. end;
  124. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  125. {
  126. This function puts the registers in place, does the call, and then
  127. copies back the registers as they are after the SysCall.
  128. }
  129. var
  130. temp: longint;
  131. asm
  132. move $v0,$a0
  133. move $a0,$a1
  134. move $a1,$a2
  135. syscall
  136. nop
  137. beq $7,$0,.LDone
  138. nop
  139. lui $8,%hi(fpc_threadvar_relocate_proc)
  140. addiu $8,%lo(fpc_threadvar_relocate_proc)
  141. lw $8,0($8)
  142. bne $8,$0,.LThreaded
  143. nop
  144. lui $4,%hi(Errno+4)
  145. addiu $4,%lo(Errno+4)
  146. sw $2,0($4)
  147. b .LFailed
  148. nop
  149. .LThreaded:
  150. sw $2,temp
  151. lui $4,%hi(errno)
  152. addiu $4,$4,%lo(errno)
  153. jalr $8
  154. nop
  155. lw $8,temp
  156. sw $8,0($2)
  157. .LFailed:
  158. li $2,-1
  159. .LDone:
  160. end;
  161. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  162. {
  163. This function puts the registers in place, does the call, and then
  164. copies back the registers as they are after the SysCall.
  165. }
  166. var
  167. temp: longint;
  168. asm
  169. move $v0,$a0
  170. move $a0,$a1
  171. move $a1,$a2
  172. move $a2,$a3
  173. syscall
  174. nop
  175. beq $7,$0,.LDone
  176. nop
  177. lui $8,%hi(fpc_threadvar_relocate_proc)
  178. addiu $8,%lo(fpc_threadvar_relocate_proc)
  179. lw $8,0($8)
  180. bne $8,$0,.LThreaded
  181. nop
  182. lui $4,%hi(Errno+4)
  183. addiu $4,%lo(Errno+4)
  184. sw $2,0($4)
  185. b .LFailed
  186. nop
  187. .LThreaded:
  188. sw $2,temp
  189. lui $4,%hi(errno)
  190. addiu $4,$4,%lo(errno)
  191. jalr $8
  192. nop
  193. lw $8,temp
  194. sw $8,0($2)
  195. .LFailed:
  196. li $2,-1
  197. .LDone:
  198. end;
  199. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  200. {
  201. This function puts the registers in place, does the call, and then
  202. copies back the registers as they are after the SysCall.
  203. }
  204. var
  205. temp: longint;
  206. asm
  207. move $v0,$a0
  208. move $a0,$a1
  209. move $a1,$a2
  210. move $a2,$a3
  211. lw $a3,param4
  212. syscall
  213. nop
  214. beq $7,$0,.LDone
  215. nop
  216. lui $8,%hi(fpc_threadvar_relocate_proc)
  217. addiu $8,%lo(fpc_threadvar_relocate_proc)
  218. lw $8,0($8)
  219. bne $8,$0,.LThreaded
  220. nop
  221. lui $4,%hi(Errno+4)
  222. addiu $4,%lo(Errno+4)
  223. sw $2,0($4)
  224. b .LFailed
  225. nop
  226. .LThreaded:
  227. sw $2,temp
  228. lui $4,%hi(errno)
  229. addiu $4,$4,%lo(errno)
  230. jalr $8
  231. nop
  232. lw $8,temp
  233. sw $8,0($2)
  234. .LFailed:
  235. li $2,-1
  236. .LDone:
  237. end;
  238. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  239. {
  240. This function puts the registers in place, does the call, and then
  241. copies back the registers as they are after the SysCall.
  242. }
  243. var
  244. temp: longint;
  245. asm
  246. move $v0,$a0
  247. move $a0,$a1
  248. move $a1,$a2
  249. move $a2,$a3
  250. lw $a3,param4
  251. lw $t0,param5
  252. sw $t0,16($sp)
  253. syscall
  254. nop
  255. beq $7,$0,.LDone
  256. nop
  257. lui $8,%hi(fpc_threadvar_relocate_proc)
  258. addiu $8,%lo(fpc_threadvar_relocate_proc)
  259. lw $8,0($8)
  260. bne $8,$0,.LThreaded
  261. nop
  262. lui $4,%hi(Errno+4)
  263. addiu $4,%lo(Errno+4)
  264. sw $2,0($4)
  265. b .LFailed
  266. nop
  267. .LThreaded:
  268. sw $2,temp
  269. lui $4,%hi(errno)
  270. addiu $4,$4,%lo(errno)
  271. jalr $8
  272. nop
  273. lw $8,temp
  274. sw $8,0($2)
  275. .LFailed:
  276. li $2,-1
  277. .LDone:
  278. end;
  279. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  280. {
  281. This function puts the registers in place, does the call, and then
  282. copies back the registers as they are after the SysCall.
  283. }
  284. var
  285. temp: longint;
  286. asm
  287. move $v0,$a0
  288. move $a0,$a1
  289. move $a1,$a2
  290. move $a2,$a3
  291. lw $a3,param4
  292. lw $t0,param5
  293. sw $t0,16($sp)
  294. lw $t0,param6
  295. sw $t0,20($sp)
  296. syscall
  297. nop
  298. beq $7,$0,.LDone
  299. nop
  300. lui $8,%hi(fpc_threadvar_relocate_proc)
  301. addiu $8,%lo(fpc_threadvar_relocate_proc)
  302. lw $8,0($8)
  303. bne $8,$0,.LThreaded
  304. nop
  305. lui $4,%hi(Errno+4)
  306. addiu $4,%lo(Errno+4)
  307. sw $2,0($4)
  308. b .LFailed
  309. nop
  310. .LThreaded:
  311. sw $2,temp
  312. lui $4,%hi(errno)
  313. addiu $4,$4,%lo(errno)
  314. jalr $8
  315. nop
  316. lw $8,temp
  317. sw $8,0($2)
  318. .LFailed:
  319. li $2,-1
  320. .LDone:
  321. end;