syscall.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {No debugging for syslinux include !}
  12. {$IFDEF SYS_LINUX}
  13. {$UNDEF SYSCALL_DEBUG}
  14. {$ENDIF SYS_LINUX}
  15. { This variable is needed in syscall.inc assembler code }
  16. var
  17. fpc_threadvar_relocate_proc : TRelocateThreadVarHandler; public name 'FPC_THREADVAR_RELOCATE';
  18. {$define THREADVAR_RELOCATED_ALREADY_DEFINED}
  19. function get_got : pointer;assembler;{$ifndef FPC_PIC}nostackframe;{$endif} forward;
  20. {$define FPC_SYSTEM_HAS_FPFORK}
  21. {
  22. behaviour of result of fork on sparc/linux is different than on other
  23. linux flavours
  24. }
  25. function Fpfork : pid_t; [public, alias : 'FPC_SYSC_FORK'];assembler;
  26. asm
  27. {$ifdef FPC_PIC}
  28. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  29. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  30. call get_got
  31. nop
  32. {$endif FPC_PIC}
  33. mov 2,%g1
  34. ta 0x10
  35. bcc .LSyscOK
  36. nop
  37. mov %o0,%l0
  38. sethi %hi(fpc_threadvar_relocate_proc),%o2
  39. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  40. {$ifdef FPC_PIC}
  41. ld [%o2+%l7],%o2
  42. {$endif FPC_PIC}
  43. ld [%o2],%o3
  44. cmp %o3,0
  45. bne .LThread
  46. nop
  47. {$ifndef FPC_PIC}
  48. sethi %hi(Errno+4),%o0
  49. ba .LNoThread
  50. or %o0,%lo(Errno+4),%o0
  51. {$else FPC_PIC}
  52. sethi %hi(Errno),%o0
  53. or %o0,%lo(Errno),%o0
  54. ld [%o0+%l7],%o0
  55. ba .LNoThread
  56. add %o0,4,%o0
  57. {$endif FPC_PIC}
  58. .LThread:
  59. sethi %hi(Errno),%o0
  60. or %o0,%lo(Errno),%o0
  61. {$ifdef FPC_PIC}
  62. ld [%o0+%l7],%o0
  63. {$endif FPC_PIC}
  64. call %o3
  65. ld [%o0],%o0
  66. .LNoThread:
  67. st %l0,[%o0]
  68. ba .LReturn
  69. mov -1,%i0
  70. .LSyscOK:
  71. // o1 contains 1 in the parent
  72. // and 0 in the child
  73. sub %o1, 1, %o1
  74. and %o0, %o1, %i0
  75. .LReturn:
  76. end;
  77. {*****************************************************************************
  78. --- Main:The System Call Self ---
  79. *****************************************************************************}
  80. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  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. {$ifdef FPC_PIC}
  87. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  88. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  89. call get_got
  90. nop
  91. {$endif FPC_PIC}
  92. mov %i0,%g1
  93. ta 0x10
  94. bcc .LSyscOK
  95. nop
  96. mov %o0,%l0
  97. sethi %hi(fpc_threadvar_relocate_proc),%o2
  98. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  99. {$ifdef FPC_PIC}
  100. ld [%o2+%l7],%o2
  101. {$endif FPC_PIC}
  102. ld [%o2],%o3
  103. cmp %o3,0
  104. bne .LThread
  105. nop
  106. {$ifndef FPC_PIC}
  107. sethi %hi(Errno+4),%o0
  108. ba .LNoThread
  109. or %o0,%lo(Errno+4),%o0
  110. {$else FPC_PIC}
  111. sethi %hi(Errno),%o0
  112. or %o0,%lo(Errno),%o0
  113. ld [%o0+%l7],%o0
  114. ba .LNoThread
  115. add %o0,4,%o0
  116. {$endif FPC_PIC}
  117. .LThread:
  118. sethi %hi(Errno),%o0
  119. or %o0,%lo(Errno),%o0
  120. {$ifdef FPC_PIC}
  121. ld [%o0+%l7],%o0
  122. {$endif FPC_PIC}
  123. call %o3
  124. ld [%o0],%o0
  125. .LNoThread:
  126. st %l0,[%o0]
  127. mov -1,%o0
  128. .LSyscOK:
  129. mov %o0,%i0
  130. end;
  131. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  132. {
  133. This function puts the registers in place, does the call, and then
  134. copies back the registers as they are after the SysCall.
  135. }
  136. asm
  137. {$ifdef FPC_PIC}
  138. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  139. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  140. call get_got
  141. nop
  142. {$endif FPC_PIC}
  143. mov %i0,%g1
  144. mov %i1,%o0
  145. ta 0x10
  146. bcc .LSyscOK
  147. nop
  148. mov %o0,%l0
  149. sethi %hi(fpc_threadvar_relocate_proc),%o2
  150. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  151. {$ifdef FPC_PIC}
  152. ld [%o2+%l7],%o2
  153. {$endif FPC_PIC}
  154. ld [%o2],%o3
  155. cmp %o3,0
  156. bne .LThread
  157. nop
  158. {$ifndef FPC_PIC}
  159. sethi %hi(Errno+4),%o0
  160. ba .LNoThread
  161. or %o0,%lo(Errno+4),%o0
  162. {$else FPC_PIC}
  163. sethi %hi(Errno),%o0
  164. or %o0,%lo(Errno),%o0
  165. ld [%o0+%l7],%o0
  166. ba .LNoThread
  167. add %o0,4,%o0
  168. {$endif FPC_PIC}
  169. .LThread:
  170. sethi %hi(Errno),%o0
  171. or %o0,%lo(Errno),%o0
  172. {$ifdef FPC_PIC}
  173. ld [%o0+%l7],%o0
  174. {$endif FPC_PIC}
  175. call %o3
  176. ld [%o0],%o0
  177. .LNoThread:
  178. st %l0,[%o0]
  179. mov -1,%o0
  180. .LSyscOK:
  181. mov %o0,%i0
  182. end;
  183. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  184. {
  185. This function puts the registers in place, does the call, and then
  186. copies back the registers as they are after the SysCall.
  187. }
  188. asm
  189. {$ifdef FPC_PIC}
  190. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  191. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  192. call get_got
  193. nop
  194. {$endif FPC_PIC}
  195. mov %i0,%g1
  196. mov %i1,%o0
  197. mov %i2,%o1
  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. {$ifdef FPC_PIC}
  205. ld [%o2+%l7],%o2
  206. {$endif FPC_PIC}
  207. ld [%o2],%o3
  208. cmp %o3,0
  209. bne .LThread
  210. nop
  211. {$ifndef FPC_PIC}
  212. sethi %hi(Errno+4),%o0
  213. ba .LNoThread
  214. or %o0,%lo(Errno+4),%o0
  215. {$else FPC_PIC}
  216. sethi %hi(Errno),%o0
  217. or %o0,%lo(Errno),%o0
  218. ld [%o0+%l7],%o0
  219. ba .LNoThread
  220. add %o0,4,%o0
  221. {$endif FPC_PIC}
  222. .LThread:
  223. sethi %hi(Errno),%o0
  224. or %o0,%lo(Errno),%o0
  225. {$ifdef FPC_PIC}
  226. ld [%o0+%l7],%o0
  227. {$endif FPC_PIC}
  228. call %o3
  229. ld [%o0],%o0
  230. .LNoThread:
  231. st %l0,[%o0]
  232. mov -1,%o0
  233. .LSyscOK:
  234. mov %o0,%i0
  235. end;
  236. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  237. {
  238. This function puts the registers in place, does the call, and then
  239. copies back the registers as they are after the SysCall.
  240. }
  241. asm
  242. {$ifdef FPC_PIC}
  243. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  244. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  245. call get_got
  246. nop
  247. {$endif FPC_PIC}
  248. mov %i0,%g1
  249. mov %i1,%o0
  250. mov %i2,%o1
  251. mov %i3,%o2
  252. ta 0x10
  253. bcc .LSyscOK
  254. nop
  255. mov %o0,%l0
  256. sethi %hi(fpc_threadvar_relocate_proc),%o2
  257. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  258. {$ifdef FPC_PIC}
  259. ld [%o2+%l7],%o2
  260. {$endif FPC_PIC}
  261. ld [%o2],%o3
  262. cmp %o3,0
  263. bne .LThread
  264. nop
  265. {$ifndef FPC_PIC}
  266. sethi %hi(Errno+4),%o0
  267. ba .LNoThread
  268. or %o0,%lo(Errno+4),%o0
  269. {$else FPC_PIC}
  270. sethi %hi(Errno),%o0
  271. or %o0,%lo(Errno),%o0
  272. ld [%o0+%l7],%o0
  273. ba .LNoThread
  274. add %o0,4,%o0
  275. {$endif FPC_PIC}
  276. .LThread:
  277. sethi %hi(Errno),%o0
  278. or %o0,%lo(Errno),%o0
  279. {$ifdef FPC_PIC}
  280. ld [%o0+%l7],%o0
  281. {$endif FPC_PIC}
  282. call %o3
  283. ld [%o0],%o0
  284. .LNoThread:
  285. st %l0,[%o0]
  286. mov -1,%o0
  287. .LSyscOK:
  288. mov %o0,%i0
  289. end;
  290. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  291. {
  292. This function puts the registers in place, does the call, and then
  293. copies back the registers as they are after the SysCall.
  294. }
  295. asm
  296. {$ifdef FPC_PIC}
  297. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  298. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  299. call get_got
  300. nop
  301. {$endif FPC_PIC}
  302. mov %i0,%g1
  303. mov %i1,%o0
  304. mov %i2,%o1
  305. mov %i3,%o2
  306. mov %i4,%o3
  307. ta 0x10
  308. bcc .LSyscOK
  309. nop
  310. mov %o0,%l0
  311. sethi %hi(fpc_threadvar_relocate_proc),%o2
  312. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  313. {$ifdef FPC_PIC}
  314. ld [%o2+%l7],%o2
  315. {$endif FPC_PIC}
  316. ld [%o2],%o3
  317. cmp %o3,0
  318. bne .LThread
  319. nop
  320. {$ifndef FPC_PIC}
  321. sethi %hi(Errno+4),%o0
  322. ba .LNoThread
  323. or %o0,%lo(Errno+4),%o0
  324. {$else FPC_PIC}
  325. sethi %hi(Errno),%o0
  326. or %o0,%lo(Errno),%o0
  327. ld [%o0+%l7],%o0
  328. ba .LNoThread
  329. add %o0,4,%o0
  330. {$endif FPC_PIC}
  331. .LThread:
  332. sethi %hi(Errno),%o0
  333. or %o0,%lo(Errno),%o0
  334. {$ifdef FPC_PIC}
  335. ld [%o0+%l7],%o0
  336. {$endif FPC_PIC}
  337. call %o3
  338. ld [%o0],%o0
  339. .LNoThread:
  340. st %l0,[%o0]
  341. mov -1,%o0
  342. .LSyscOK:
  343. mov %o0,%i0
  344. end;
  345. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  346. {
  347. This function puts the registers in place, does the call, and then
  348. copies back the registers as they are after the SysCall.
  349. }
  350. asm
  351. {$ifdef FPC_PIC}
  352. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  353. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  354. call get_got
  355. nop
  356. {$endif FPC_PIC}
  357. mov %i0,%g1
  358. mov %i1,%o0
  359. mov %i2,%o1
  360. mov %i3,%o2
  361. mov %i4,%o3
  362. mov %i5,%o4
  363. ta 0x10
  364. bcc .LSyscOK
  365. nop
  366. mov %o0,%l0
  367. sethi %hi(fpc_threadvar_relocate_proc),%o2
  368. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  369. {$ifdef FPC_PIC}
  370. ld [%o2+%l7],%o2
  371. {$endif FPC_PIC}
  372. ld [%o2],%o3
  373. cmp %o3,0
  374. bne .LThread
  375. nop
  376. {$ifndef FPC_PIC}
  377. sethi %hi(Errno+4),%o0
  378. ba .LNoThread
  379. or %o0,%lo(Errno+4),%o0
  380. {$else FPC_PIC}
  381. sethi %hi(Errno),%o0
  382. or %o0,%lo(Errno),%o0
  383. ld [%o0+%l7],%o0
  384. ba .LNoThread
  385. add %o0,4,%o0
  386. {$endif FPC_PIC}
  387. .LThread:
  388. sethi %hi(Errno),%o0
  389. or %o0,%lo(Errno),%o0
  390. {$ifdef FPC_PIC}
  391. ld [%o0+%l7],%o0
  392. {$endif FPC_PIC}
  393. call %o3
  394. ld [%o0],%o0
  395. .LNoThread:
  396. st %l0,[%o0]
  397. mov -1,%o0
  398. .LSyscOK:
  399. mov %o0,%i0
  400. end;
  401. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  402. {
  403. This function puts the registers in place, does the call, and then
  404. copies back the registers as they are after the SysCall.
  405. }
  406. asm
  407. {$ifdef FPC_PIC}
  408. sethi %hi(_GLOBAL_OFFSET_TABLE_ -8),%l7
  409. or %l7,%lo(_GLOBAL_OFFSET_TABLE_ -4),%l7
  410. call get_got
  411. nop
  412. {$endif FPC_PIC}
  413. mov %i0,%g1
  414. mov %i1,%o0
  415. mov %i2,%o1
  416. mov %i3,%o2
  417. mov %i4,%o3
  418. ld [%i6+92],%o5
  419. mov %i5,%o4
  420. ta 0x10
  421. bcc .LSyscOK
  422. nop
  423. mov %o0,%l0
  424. sethi %hi(fpc_threadvar_relocate_proc),%o2
  425. or %o2,%lo(fpc_threadvar_relocate_proc),%o2
  426. {$ifdef FPC_PIC}
  427. ld [%o2+%l7],%o2
  428. {$endif FPC_PIC}
  429. ld [%o2],%o3
  430. cmp %o3,0
  431. bne .LThread
  432. nop
  433. {$ifndef FPC_PIC}
  434. sethi %hi(Errno+4),%o0
  435. ba .LNoThread
  436. or %o0,%lo(Errno+4),%o0
  437. {$else FPC_PIC}
  438. sethi %hi(Errno),%o0
  439. or %o0,%lo(Errno),%o0
  440. ld [%o0+%l7],%o0
  441. ba .LNoThread
  442. add %o0,4,%o0
  443. {$endif FPC_PIC}
  444. .LThread:
  445. sethi %hi(Errno),%o0
  446. or %o0,%lo(Errno),%o0
  447. {$ifdef FPC_PIC}
  448. ld [%o0+%l7],%o0
  449. {$endif FPC_PIC}
  450. call %o3
  451. ld [%o0],%o0
  452. .LNoThread:
  453. st %l0,[%o0]
  454. mov -1,%o0
  455. .LSyscOK:
  456. mov %o0,%i0
  457. end;