syscall.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. {Use direct assembler, dumps directly assembler code in sources}
  17. {$ASMMODE DIRECT}
  18. {*****************************************************************************
  19. --- Main:The System Call Self ---
  20. *****************************************************************************}
  21. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  22. {
  23. This function puts the registers in place, does the call, and then
  24. copies back the registers as they are after the SysCall.
  25. }
  26. asm
  27. or %i0,%g0,%g1
  28. ta 0x10
  29. bcc .LSyscOK0
  30. nop
  31. sethi %hi(FPC_THREADVAR_RELOCATE),%o0
  32. or %o0,%lo(FPC_THREADVAR_RELOCATE),%o0
  33. ld [%o0],%o7
  34. subcc %o7,%g0,%g0
  35. bne .LThread0
  36. nop
  37. sethi %hi(U_SYSTEM_ERRNO+4),%o0
  38. ba .LNoThread0
  39. or %o0,%lo(U_SYSTEM_ERRNO+4),%o0
  40. .LThread0:
  41. sethi %hi(U_SYSTEM_ERRNO),%o0
  42. ld [%o7],%o1
  43. or %o0,%lo(U_SYSTEM_ERRNO),%o0
  44. call %o1
  45. .LNoThread0:
  46. st %i0,[%o0]
  47. mov -1,%o0
  48. .LSyscOK0:
  49. mov %o0,%i0
  50. end;
  51. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  52. {
  53. This function puts the registers in place, does the call, and then
  54. copies back the registers as they are after the SysCall.
  55. }
  56. asm
  57. or %i0,%g0,%g1
  58. or %i1,%g0,%o0
  59. ta 0x10
  60. bcc .LSyscOK1
  61. nop
  62. sethi %hi(FPC_THREADVAR_RELOCATE),%o0
  63. or %o0,%lo(FPC_THREADVAR_RELOCATE),%o0
  64. ld [%o0],%o7
  65. subcc %o7,%g0,%g0
  66. bne .LThread1
  67. nop
  68. sethi %hi(U_SYSTEM_ERRNO+4),%o0
  69. ba .LNoThread1
  70. or %o0,%lo(U_SYSTEM_ERRNO+4),%o0
  71. .LThread1:
  72. sethi %hi(U_SYSTEM_ERRNO),%o0
  73. ld [%o7],%o1
  74. or %o0,%lo(U_SYSTEM_ERRNO),%o0
  75. call %o1
  76. .LNoThread1:
  77. st %i0,[%o0]
  78. mov -1,%o0
  79. .LSyscOK1:
  80. mov %o0,%i0
  81. end;
  82. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  83. {
  84. This function puts the registers in place, does the call, and then
  85. copies back the registers as they are after the SysCall.
  86. }
  87. asm
  88. or %i0,%g0,%g1
  89. or %i1,%g0,%o0
  90. or %i2,%g0,%o1
  91. ta 0x10
  92. bcc .LSyscOK2
  93. nop
  94. sethi %hi(FPC_THREADVAR_RELOCATE),%o0
  95. or %o0,%lo(FPC_THREADVAR_RELOCATE),%o0
  96. ld [%o0],%o7
  97. subcc %o7,%g0,%g0
  98. bne .LThread2
  99. nop
  100. sethi %hi(U_SYSTEM_ERRNO+4),%o0
  101. ba .LNoThread2
  102. or %o0,%lo(U_SYSTEM_ERRNO+4),%o0
  103. .LThread2:
  104. sethi %hi(U_SYSTEM_ERRNO),%o0
  105. ld [%o7],%o1
  106. or %o0,%lo(U_SYSTEM_ERRNO),%o0
  107. call %o1
  108. .LNoThread2:
  109. st %i0,[%o0]
  110. mov -1,%o0
  111. .LSyscOK2:
  112. mov %o0,%i0
  113. end;
  114. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  115. {
  116. This function puts the registers in place, does the call, and then
  117. copies back the registers as they are after the SysCall.
  118. }
  119. asm
  120. or %i0,%g0,%g1
  121. or %i1,%g0,%o0
  122. or %i2,%g0,%o1
  123. or %i3,%g0,%o2
  124. ta 0x10
  125. bcc .LSyscOK3
  126. nop
  127. sethi %hi(FPC_THREADVAR_RELOCATE),%o0
  128. or %o0,%lo(FPC_THREADVAR_RELOCATE),%o0
  129. ld [%o0],%o7
  130. subcc %o7,%g0,%g0
  131. bne .LThread3
  132. nop
  133. sethi %hi(U_SYSTEM_ERRNO+4),%o0
  134. ba .LNoThread3
  135. or %o0,%lo(U_SYSTEM_ERRNO+4),%o0
  136. .LThread3:
  137. sethi %hi(U_SYSTEM_ERRNO),%o0
  138. ld [%o7],%o1
  139. or %o0,%lo(U_SYSTEM_ERRNO),%o0
  140. call %o1
  141. .LNoThread3:
  142. st %i0,[%o0]
  143. mov -1,%o0
  144. .LSyscOK3:
  145. mov %o0,%i0
  146. end;
  147. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  148. {
  149. This function puts the registers in place, does the call, and then
  150. copies back the registers as they are after the SysCall.
  151. }
  152. asm
  153. or %i0,%g0,%g1
  154. or %i1,%g0,%o0
  155. or %i2,%g0,%o1
  156. or %i3,%g0,%o2
  157. or %i4,%g0,%o3
  158. ta 0x10
  159. bcc .LSyscOK4
  160. nop
  161. sethi %hi(FPC_THREADVAR_RELOCATE),%o0
  162. or %o0,%lo(FPC_THREADVAR_RELOCATE),%o0
  163. ld [%o0],%o7
  164. subcc %o7,%g0,%g0
  165. bne .LThread4
  166. nop
  167. sethi %hi(U_SYSTEM_ERRNO+4),%o0
  168. ba .LNoThread4
  169. or %o0,%lo(U_SYSTEM_ERRNO+4),%o0
  170. .LThread4:
  171. sethi %hi(U_SYSTEM_ERRNO),%o0
  172. ld [%o7],%o1
  173. or %o0,%lo(U_SYSTEM_ERRNO),%o0
  174. call %o1
  175. .LNoThread4:
  176. st %i0,[%o0]
  177. mov -1,%o0
  178. .LSyscOK4:
  179. mov %o0,%i0
  180. end;
  181. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  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. or %i0,%g0,%g1
  188. or %i1,%g0,%o0
  189. or %i2,%g0,%o1
  190. or %i3,%g0,%o2
  191. or %i4,%g0,%o3
  192. or %i5,%g0,%o4
  193. ta 0x10
  194. bcc .LSyscOK5
  195. nop
  196. sethi %hi(FPC_THREADVAR_RELOCATE),%o0
  197. or %o0,%lo(FPC_THREADVAR_RELOCATE),%o0
  198. ld [%o0],%o7
  199. subcc %o7,%g0,%g0
  200. bne .LThread5
  201. nop
  202. sethi %hi(U_SYSTEM_ERRNO+4),%o0
  203. ba .LNoThread5
  204. or %o0,%lo(U_SYSTEM_ERRNO+4),%o0
  205. .LThread5:
  206. sethi %hi(U_SYSTEM_ERRNO),%o0
  207. ld [%o7],%o1
  208. or %o0,%lo(U_SYSTEM_ERRNO),%o0
  209. call %o1
  210. .LNoThread5:
  211. st %i0,[%o0]
  212. mov -1,%o0
  213. .LSyscOK5:
  214. mov %o0,%i0
  215. end;
  216. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  217. {
  218. This function puts the registers in place, does the call, and then
  219. copies back the registers as they are after the SysCall.
  220. }
  221. asm
  222. or %i0,%g0,%g1
  223. or %i1,%g0,%o0
  224. or %i2,%g0,%o1
  225. or %i3,%g0,%o2
  226. or %i4,%g0,%o3
  227. ld [%i6+92],%o5
  228. or %i5,%g0,%o4
  229. ta 0x10
  230. bcc .LSyscOK6
  231. nop
  232. sethi %hi(FPC_THREADVAR_RELOCATE),%o0
  233. or %o0,%lo(FPC_THREADVAR_RELOCATE),%o0
  234. ld [%o0],%o7
  235. subcc %o7,%g0,%g0
  236. bne .LThread6
  237. nop
  238. sethi %hi(U_SYSTEM_ERRNO+4),%o0
  239. ba .LNoThread6
  240. or %o0,%lo(U_SYSTEM_ERRNO+4),%o0
  241. .LThread6:
  242. sethi %hi(U_SYSTEM_ERRNO),%o0
  243. ld [%o7],%o1
  244. or %o0,%lo(U_SYSTEM_ERRNO),%o0
  245. call %o1
  246. .LNoThread6:
  247. st %i0,[%o0]
  248. mov -1,%o0
  249. .LSyscOK6:
  250. mov %o0,%i0
  251. end;
  252. // Old style syscall:
  253. // Better use ktrace/strace/gdb for debugging.
  254. Procedure FpSysCall( callnr:longint;var regs : SysCallregs );assembler;
  255. {
  256. This function puts the registers in place, does the call, and then
  257. copies back the registers as they are after the SysCall.
  258. }
  259. asm
  260. or %i0,%g0,%g1
  261. ld [%i1],%o0
  262. ld [%i1+4],%o1
  263. ld [%i1+8],%o2
  264. ld [%i1+12],%o3
  265. ld [%i1+16],%o4
  266. { Go ! }
  267. ta 0x10
  268. { Put back the registers... }
  269. st %o0,[%i1]
  270. st %o1,[%i1+4]
  271. st %o2,[%i1+8]
  272. st %o3,[%i1+12]
  273. st %o4,[%i1+16]
  274. end;
  275. {$IFDEF SYSCALL_DEBUG}
  276. Const
  277. DoSysCallDebug : Boolean = False;
  278. var
  279. LastCnt,
  280. LastEax,
  281. LastCall : longint;
  282. DebugTxt : string[20];
  283. {$ENDIF}
  284. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  285. {
  286. This function serves as an interface to do_SysCall.
  287. If the SysCall returned a negative number, it returns -1, and puts the
  288. SysCall result in errno. Otherwise, it returns the SysCall return value
  289. }
  290. begin
  291. FpSysCall(callnr,regs);
  292. if regs.reg1<0 then
  293. begin
  294. {$IFDEF SYSCALL_DEBUG}
  295. If DoSysCallDebug then
  296. debugtxt:=' syscall error: ';
  297. {$endif}
  298. ErrNo:=-regs.reg1;
  299. SysCall:=-1;
  300. end
  301. else
  302. begin
  303. {$IFDEF SYSCALL_DEBUG}
  304. if DoSysCallDebug then
  305. debugtxt:=' syscall returned: ';
  306. {$endif}
  307. SysCall:=regs.reg1;
  308. errno:=0
  309. end;
  310. {$IFDEF SYSCALL_DEBUG}
  311. if DoSysCallDebug then
  312. begin
  313. inc(lastcnt);
  314. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  315. begin
  316. if lastcnt>1 then
  317. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  318. lastcall:=callnr;
  319. lasteax:=regs.reg1;
  320. lastcnt:=0;
  321. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  322. end;
  323. end;
  324. {$endif}
  325. end;
  326. {
  327. $Log$
  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. }