syscall.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. {*****************************************************************************
  17. --- Main:The System Call Self ---
  18. *****************************************************************************}
  19. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  20. {
  21. This function puts the registers in place, does the call, and then
  22. copies back the registers as they are after the SysCall.
  23. }
  24. asm
  25. or %i0,%g0,%g1
  26. ta 0x10
  27. bcc .LSyscOK0
  28. nop
  29. sethi %hi(fpc_threadvar_relocate_proc),%o0
  30. or %o0,%lo(fpc_threadvar_relocate_proc),%o0
  31. ld [%o0],%o7
  32. subcc %o7,%g0,%g0
  33. bne .LThread0
  34. nop
  35. sethi %hi(Errno+4),%o0
  36. ba .LNoThread0
  37. or %o0,%lo(Errno+4),%o0
  38. .LThread0:
  39. sethi %hi(Errno),%o0
  40. ld [%o7],%o1
  41. or %o0,%lo(Errno),%o0
  42. call %o1
  43. .LNoThread0:
  44. st %i0,[%o0]
  45. mov -1,%o0
  46. .LSyscOK0:
  47. mov %o0,%i0
  48. end;
  49. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  50. {
  51. This function puts the registers in place, does the call, and then
  52. copies back the registers as they are after the SysCall.
  53. }
  54. asm
  55. or %i0,%g0,%g1
  56. or %i1,%g0,%o0
  57. ta 0x10
  58. bcc .LSyscOK1
  59. nop
  60. sethi %hi(fpc_threadvar_relocate_proc),%o0
  61. or %o0,%lo(fpc_threadvar_relocate_proc),%o0
  62. ld [%o0],%o7
  63. subcc %o7,%g0,%g0
  64. bne .LThread1
  65. nop
  66. sethi %hi(Errno+4),%o0
  67. ba .LNoThread1
  68. or %o0,%lo(Errno+4),%o0
  69. .LThread1:
  70. sethi %hi(Errno),%o0
  71. ld [%o7],%o1
  72. or %o0,%lo(Errno),%o0
  73. call %o1
  74. .LNoThread1:
  75. st %i0,[%o0]
  76. mov -1,%o0
  77. .LSyscOK1:
  78. mov %o0,%i0
  79. end;
  80. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  81. {
  82. This function puts the registers in place, does the call, and then
  83. copies back the registers as they are after the SysCall.
  84. }
  85. asm
  86. or %i0,%g0,%g1
  87. or %i1,%g0,%o0
  88. or %i2,%g0,%o1
  89. ta 0x10
  90. bcc .LSyscOK2
  91. nop
  92. sethi %hi(fpc_threadvar_relocate_proc),%o0
  93. or %o0,%lo(fpc_threadvar_relocate_proc),%o0
  94. ld [%o0],%o7
  95. subcc %o7,%g0,%g0
  96. bne .LThread2
  97. nop
  98. sethi %hi(Errno+4),%o0
  99. ba .LNoThread2
  100. or %o0,%lo(Errno+4),%o0
  101. .LThread2:
  102. sethi %hi(Errno),%o0
  103. ld [%o7],%o1
  104. or %o0,%lo(Errno),%o0
  105. call %o1
  106. .LNoThread2:
  107. st %i0,[%o0]
  108. mov -1,%o0
  109. .LSyscOK2:
  110. mov %o0,%i0
  111. end;
  112. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  113. {
  114. This function puts the registers in place, does the call, and then
  115. copies back the registers as they are after the SysCall.
  116. }
  117. asm
  118. or %i0,%g0,%g1
  119. or %i1,%g0,%o0
  120. or %i2,%g0,%o1
  121. or %i3,%g0,%o2
  122. ta 0x10
  123. bcc .LSyscOK3
  124. nop
  125. sethi %hi(fpc_threadvar_relocate_proc),%o0
  126. or %o0,%lo(fpc_threadvar_relocate_proc),%o0
  127. ld [%o0],%o7
  128. subcc %o7,%g0,%g0
  129. bne .LThread3
  130. nop
  131. sethi %hi(Errno+4),%o0
  132. ba .LNoThread3
  133. or %o0,%lo(Errno+4),%o0
  134. .LThread3:
  135. sethi %hi(Errno),%o0
  136. ld [%o7],%o1
  137. or %o0,%lo(Errno),%o0
  138. call %o1
  139. .LNoThread3:
  140. st %i0,[%o0]
  141. mov -1,%o0
  142. .LSyscOK3:
  143. mov %o0,%i0
  144. end;
  145. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  146. {
  147. This function puts the registers in place, does the call, and then
  148. copies back the registers as they are after the SysCall.
  149. }
  150. asm
  151. or %i0,%g0,%g1
  152. or %i1,%g0,%o0
  153. or %i2,%g0,%o1
  154. or %i3,%g0,%o2
  155. or %i4,%g0,%o3
  156. ta 0x10
  157. bcc .LSyscOK4
  158. nop
  159. sethi %hi(fpc_threadvar_relocate_proc),%o0
  160. or %o0,%lo(fpc_threadvar_relocate_proc),%o0
  161. ld [%o0],%o7
  162. subcc %o7,%g0,%g0
  163. bne .LThread4
  164. nop
  165. sethi %hi(Errno+4),%o0
  166. ba .LNoThread4
  167. or %o0,%lo(Errno+4),%o0
  168. .LThread4:
  169. sethi %hi(Errno),%o0
  170. ld [%o7],%o1
  171. or %o0,%lo(Errno),%o0
  172. call %o1
  173. .LNoThread4:
  174. st %i0,[%o0]
  175. mov -1,%o0
  176. .LSyscOK4:
  177. mov %o0,%i0
  178. end;
  179. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  180. {
  181. This function puts the registers in place, does the call, and then
  182. copies back the registers as they are after the SysCall.
  183. }
  184. asm
  185. or %i0,%g0,%g1
  186. or %i1,%g0,%o0
  187. or %i2,%g0,%o1
  188. or %i3,%g0,%o2
  189. or %i4,%g0,%o3
  190. or %i5,%g0,%o4
  191. ta 0x10
  192. bcc .LSyscOK5
  193. nop
  194. sethi %hi(fpc_threadvar_relocate_proc),%o0
  195. or %o0,%lo(fpc_threadvar_relocate_proc),%o0
  196. ld [%o0],%o7
  197. subcc %o7,%g0,%g0
  198. bne .LThread5
  199. nop
  200. sethi %hi(Errno+4),%o0
  201. ba .LNoThread5
  202. or %o0,%lo(Errno+4),%o0
  203. .LThread5:
  204. sethi %hi(Errno),%o0
  205. ld [%o7],%o1
  206. or %o0,%lo(Errno),%o0
  207. call %o1
  208. .LNoThread5:
  209. st %i0,[%o0]
  210. mov -1,%o0
  211. .LSyscOK5:
  212. mov %o0,%i0
  213. end;
  214. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  215. {
  216. This function puts the registers in place, does the call, and then
  217. copies back the registers as they are after the SysCall.
  218. }
  219. asm
  220. or %i0,%g0,%g1
  221. or %i1,%g0,%o0
  222. or %i2,%g0,%o1
  223. or %i3,%g0,%o2
  224. or %i4,%g0,%o3
  225. ld [%i6+92],%o5
  226. or %i5,%g0,%o4
  227. ta 0x10
  228. bcc .LSyscOK6
  229. nop
  230. sethi %hi(fpc_threadvar_relocate_proc),%o0
  231. or %o0,%lo(fpc_threadvar_relocate_proc),%o0
  232. ld [%o0],%o7
  233. subcc %o7,%g0,%g0
  234. bne .LThread6
  235. nop
  236. sethi %hi(Errno+4),%o0
  237. ba .LNoThread6
  238. or %o0,%lo(Errno+4),%o0
  239. .LThread6:
  240. sethi %hi(Errno),%o0
  241. ld [%o7],%o1
  242. or %o0,%lo(Errno),%o0
  243. call %o1
  244. .LNoThread6:
  245. st %i0,[%o0]
  246. mov -1,%o0
  247. .LSyscOK6:
  248. mov %o0,%i0
  249. end;
  250. // Old style syscall:
  251. // Better use ktrace/strace/gdb for debugging.
  252. Procedure FpSysCall( callnr:longint;var regs : SysCallregs );assembler;
  253. {
  254. This function puts the registers in place, does the call, and then
  255. copies back the registers as they are after the SysCall.
  256. }
  257. asm
  258. or %i0,%g0,%g1
  259. ld [%i1],%o0
  260. ld [%i1+4],%o1
  261. ld [%i1+8],%o2
  262. ld [%i1+12],%o3
  263. ld [%i1+16],%o4
  264. { Go ! }
  265. ta 0x10
  266. { Put back the registers... }
  267. st %o0,[%i1]
  268. st %o1,[%i1+4]
  269. st %o2,[%i1+8]
  270. st %o3,[%i1+12]
  271. st %o4,[%i1+16]
  272. end;
  273. {$IFDEF SYSCALL_DEBUG}
  274. Const
  275. DoSysCallDebug : Boolean = False;
  276. var
  277. LastCnt,
  278. LastEax,
  279. LastCall : longint;
  280. DebugTxt : string[20];
  281. {$ENDIF}
  282. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  283. {
  284. This function serves as an interface to do_SysCall.
  285. If the SysCall returned a negative number, it returns -1, and puts the
  286. SysCall result in errno. Otherwise, it returns the SysCall return value
  287. }
  288. begin
  289. FpSysCall(callnr,regs);
  290. if regs.reg1<0 then
  291. begin
  292. {$IFDEF SYSCALL_DEBUG}
  293. If DoSysCallDebug then
  294. debugtxt:=' syscall error: ';
  295. {$endif}
  296. ErrNo:=-regs.reg1;
  297. SysCall:=-1;
  298. end
  299. else
  300. begin
  301. {$IFDEF SYSCALL_DEBUG}
  302. if DoSysCallDebug then
  303. debugtxt:=' syscall returned: ';
  304. {$endif}
  305. SysCall:=regs.reg1;
  306. errno:=0
  307. end;
  308. {$IFDEF SYSCALL_DEBUG}
  309. if DoSysCallDebug then
  310. begin
  311. inc(lastcnt);
  312. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  313. begin
  314. if lastcnt>1 then
  315. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  316. lastcall:=callnr;
  317. lasteax:=regs.reg1;
  318. lastcnt:=0;
  319. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  320. end;
  321. end;
  322. {$endif}
  323. end;
  324. {
  325. $Log$
  326. Revision 1.10 2004-01-05 17:22:03 peter
  327. * removed asmmode direct
  328. Revision 1.9 2003/08/11 13:19:08 mazen
  329. + added assembler mode directive to use direct assembler reader
  330. Revision 1.8 2003/07/06 22:08:05 peter
  331. * fix setting return value
  332. Revision 1.7 2003/07/06 20:40:10 peter
  333. * wrong return reg
  334. Revision 1.6 2003/07/03 21:03:57 peter
  335. * syscalls implemented
  336. Revision 1.5 2003/06/02 22:05:03 mazen
  337. * fixing naming conflict in public clause of
  338. FPC_SYSCALL? definition
  339. Revision 1.4 2003/05/23 22:36:39 florian
  340. * fixed compilation of sparc system unit
  341. Revision 1.3 2003/01/05 21:32:35 mazen
  342. * fixing several bugs compiling the RTL
  343. Revision 1.2 2002/12/24 21:30:20 mazen
  344. - some writeln(s) removed in compiler
  345. + many files added to RTL
  346. * some errors fixed in RTL
  347. Revision 1.1 2002/11/15 12:08:37 mazen
  348. + SPARC support added based on PowerPc sources
  349. Revision 1.1 2002/11/09 20:32:14 marco
  350. * powerpc version. Threadsafe errno access not yet done.
  351. Revision 1.1 2002/10/14 19:39:44 peter
  352. * syscall moved into seperate include
  353. }