syscall.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005 by Thomas Schatzl,
  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. {*****************************************************************************
  20. --- Main:The System Call Self ---
  21. *****************************************************************************}
  22. function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
  23. {
  24. This function puts the registers in place, does the call, and then
  25. copies back the registers as they are after the SysCall.
  26. }
  27. var
  28. temp : qword;
  29. retaddress: ptruint;
  30. asm
  31. mr r0, r3
  32. sc
  33. bns .LDone
  34. lis r10, (fpc_threadvar_relocate_proc)@highesta
  35. ori r10, r10, (fpc_threadvar_relocate_proc)@highera
  36. sldi r10, r10, 32
  37. oris r10, r10, (fpc_threadvar_relocate_proc)@ha
  38. ld r10, (fpc_threadvar_relocate_proc)@l(r10)
  39. cmpdi r10, 0
  40. bne .LThreaded
  41. lis r4, (Errno+8)@highesta
  42. ori r4, r4, (Errno+8)@highera
  43. sldi r4, r4, 32
  44. oris r4, r4, (Errno+8)@ha
  45. stw r3, (Errno+8)@l(r4)
  46. b .LFailed
  47. .LThreaded:
  48. std r3, temp
  49. mflr r3
  50. std r3, retaddress
  51. // load actual function entry into r9
  52. ld r9, 0(r10)
  53. // save old TOC value
  54. std r2, 40(r1)
  55. // move function entry into ctr
  56. mtctr r9
  57. // load new TOC value
  58. ld r2, 8(r10)
  59. // load environment pointer from TOC
  60. ld r11, 16(r10)
  61. // load parameters
  62. lis r4, (errno)@highesta
  63. ori r4, r4, (errno)@highera
  64. sldi r4, r4, 32
  65. oris r4, r4, (errno)@ha
  66. lwz r3, (errno)@l(r4)
  67. bctrl
  68. // restore old TOC value
  69. ld r2, 40(r1)
  70. ld r4, temp
  71. ld r5, retaddress
  72. std r4, 0(r3)
  73. mtlr r5
  74. .LFailed:
  75. li r3, -1
  76. .LDone:
  77. end;
  78. function FpSysCall(sysnr,param1:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
  79. {
  80. This function puts the registers in place, does the call, and then
  81. copies back the registers as they are after the SysCall.
  82. }
  83. var
  84. temp : qword;
  85. retaddress: ptruint;
  86. asm
  87. mr r0, r3
  88. mr r3, r4
  89. sc
  90. bns .LDone
  91. lis r10, (fpc_threadvar_relocate_proc)@highesta
  92. ori r10, r10, (fpc_threadvar_relocate_proc)@highera
  93. sldi r10, r10, 32
  94. oris r10, r10, (fpc_threadvar_relocate_proc)@ha
  95. ld r10, (fpc_threadvar_relocate_proc)@l(r10)
  96. cmpdi r10, 0
  97. bne .LThreaded
  98. lis r4, (Errno+8)@highesta
  99. ori r4, r4, (Errno+8)@highera
  100. sldi r4, r4, 32
  101. oris r4, r4, (Errno+8)@ha
  102. stw r3, (Errno+8)@l(r4)
  103. b .LFailed
  104. .LThreaded:
  105. std r3, temp
  106. mflr r3
  107. // load actual function entry into r9
  108. ld r9, 0(r10)
  109. // save old TOC value
  110. std r2, 40(r1)
  111. // move function entry into ctr
  112. mtctr r9
  113. // load new TOC value
  114. ld r2, 8(r10)
  115. // load environment pointer from TOC
  116. ld r11, 16(r10)
  117. // load parameters
  118. lis r4, (errno)@highesta
  119. ori r4, r4, (errno)@highera
  120. sldi r4, r4, 32
  121. oris r4, r4, (errno)@ha
  122. std r3, retaddress
  123. lwz r3, (errno)@l(r4)
  124. bctrl
  125. // restore old TOC value
  126. ld r2, 40(r1)
  127. ld r4, temp
  128. ld r5, retaddress
  129. std r4, 0(r3)
  130. mtlr r5
  131. .LFailed:
  132. li r3, -1
  133. .LDone:
  134. end;
  135. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
  136. {
  137. This function puts the registers in place, does the call, and then
  138. copies back the registers as they are after the SysCall.
  139. }
  140. var
  141. temp : qword;
  142. retaddress: ptruint;
  143. asm
  144. mr r0, r3
  145. mr r3, r4
  146. mr r4, r5
  147. sc
  148. bns .LDone
  149. lis r10, (fpc_threadvar_relocate_proc)@highesta
  150. ori r10, r10, (fpc_threadvar_relocate_proc)@highera
  151. sldi r10, r10, 32
  152. oris r10, r10, (fpc_threadvar_relocate_proc)@ha
  153. ld r10, (fpc_threadvar_relocate_proc)@l(r10)
  154. cmpdi r10, 0
  155. bne .LThreaded
  156. lis r4, (Errno+8)@highesta
  157. ori r4, r4, (Errno+8)@highera
  158. sldi r4, r4, 32
  159. oris r4, r4, (Errno+8)@ha
  160. stw r3, (Errno+8)@l(r4)
  161. b .LFailed
  162. .LThreaded:
  163. std r3, temp
  164. mflr r3
  165. // load actual function entry into r9
  166. ld r9, 0(r10)
  167. // save old TOC value
  168. std r2, 40(r1)
  169. // move function entry into ctr
  170. mtctr r9
  171. // load new TOC value
  172. ld r2, 8(r10)
  173. // load environment pointer from TOC
  174. ld r11, 16(r10)
  175. // load parameters
  176. lis r4, (errno)@highesta
  177. ori r4, r4, (errno)@highera
  178. sldi r4, r4, 32
  179. oris r4, r4, (errno)@ha
  180. std r3, retaddress
  181. lwz r3, (errno)@l(r4)
  182. bctrl
  183. // restore old TOC value
  184. ld r2, 40(r1)
  185. ld r4, temp
  186. ld r5, retaddress
  187. std r4, 0(r3)
  188. mtlr r5
  189. .LFailed:
  190. li r3, -1
  191. .LDone:
  192. end;
  193. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
  194. {
  195. This function puts the registers in place, does the call, and then
  196. copies back the registers as they are after the SysCall.
  197. }
  198. var
  199. temp : qword;
  200. retaddress: ptruint;
  201. asm
  202. mr r0, r3
  203. mr r3, r4
  204. mr r4, r5
  205. mr r5, r6
  206. sc
  207. bns .LDone
  208. lis r10, (fpc_threadvar_relocate_proc)@highesta
  209. ori r10, r10, (fpc_threadvar_relocate_proc)@highera
  210. sldi r10, r10, 32
  211. oris r10, r10, (fpc_threadvar_relocate_proc)@ha
  212. ld r10, (fpc_threadvar_relocate_proc)@l(r10)
  213. cmpdi r10, 0
  214. bne .LThreaded
  215. lis r4, (Errno+8)@highesta
  216. ori r4, r4, (Errno+8)@highera
  217. sldi r4, r4, 32
  218. oris r4, r4, (Errno+8)@ha
  219. stw r3, (Errno+8)@l(r4)
  220. b .LFailed
  221. .LThreaded:
  222. std r3, temp
  223. mflr r3
  224. // load actual function entry into r9
  225. ld r9, 0(r10)
  226. // save old TOC value
  227. std r2, 40(r1)
  228. // move function entry into ctr
  229. mtctr r9
  230. // load new TOC value
  231. ld r2, 8(r10)
  232. // load environment pointer from TOC
  233. ld r11, 16(r10)
  234. // load parameters
  235. lis r4, (errno)@highesta
  236. ori r4, r4, (errno)@highera
  237. sldi r4, r4, 32
  238. oris r4, r4, (errno)@ha
  239. std r3, retaddress
  240. lwz r3, (errno)@l(r4)
  241. bctrl
  242. // restore old TOC value
  243. ld r2, 40(r1)
  244. ld r4, temp
  245. ld r5, retaddress
  246. std r4, 0(r3)
  247. mtlr r5
  248. .LFailed:
  249. li r3, -1
  250. .LDone:
  251. end;
  252. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
  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. var
  258. temp : qword;
  259. retaddress: ptruint;
  260. asm
  261. mr r0, r3
  262. mr r3, r4
  263. mr r4, r5
  264. mr r5, r6
  265. mr r6, r7
  266. sc
  267. bns .LDone
  268. lis r10, (fpc_threadvar_relocate_proc)@highesta
  269. ori r10, r10, (fpc_threadvar_relocate_proc)@highera
  270. sldi r10, r10, 32
  271. oris r10, r10, (fpc_threadvar_relocate_proc)@ha
  272. ld r10, (fpc_threadvar_relocate_proc)@l(r10)
  273. cmpdi r10, 0
  274. bne .LThreaded
  275. lis r4, (Errno+8)@highesta
  276. ori r4, r4, (Errno+8)@highera
  277. sldi r4, r4, 32
  278. oris r4, r4, (Errno+8)@ha
  279. stw r3, (Errno+8)@l(r4)
  280. b .LFailed
  281. .LThreaded:
  282. std r3, temp
  283. mflr r3
  284. // load actual function entry into r9
  285. ld r9, 0(r10)
  286. // save old TOC value
  287. std r2, 40(r1)
  288. // move function entry into ctr
  289. mtctr r9
  290. // load new TOC value
  291. ld r2, 8(r10)
  292. // load environment pointer from TOC
  293. ld r11, 16(r10)
  294. // load parameters
  295. lis r4, (errno)@highesta
  296. ori r4, r4, (errno)@highera
  297. sldi r4, r4, 32
  298. oris r4, r4, (errno)@ha
  299. std r3, retaddress
  300. lwz r3, (errno)@l(r4)
  301. bctrl
  302. // restore old TOC value
  303. ld r2, 40(r1)
  304. ld r4, temp
  305. ld r5, retaddress
  306. std r4, 0(r3)
  307. mtlr r5
  308. .LFailed:
  309. li r3, -1
  310. .LDone:
  311. end;
  312. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
  313. {
  314. This function puts the registers in place, does the call, and then
  315. copies back the registers as they are after the SysCall.
  316. }
  317. var
  318. temp : qword;
  319. retaddress: ptruint;
  320. asm
  321. mr r0, r3
  322. mr r3, r4
  323. mr r4, r5
  324. mr r5, r6
  325. mr r6, r7
  326. mr r7, r8
  327. sc
  328. bns .LDone
  329. lis r10, (fpc_threadvar_relocate_proc)@highesta
  330. ori r10, r10, (fpc_threadvar_relocate_proc)@highera
  331. sldi r10, r10, 32
  332. oris r10, r10, (fpc_threadvar_relocate_proc)@ha
  333. ld r10, (fpc_threadvar_relocate_proc)@l(r10)
  334. cmpdi r10, 0
  335. bne .LThreaded
  336. lis r4, (Errno+8)@highesta
  337. ori r4, r4, (Errno+8)@highera
  338. sldi r4, r4, 32
  339. oris r4, r4, (Errno+8)@ha
  340. stw r3, (Errno+8)@l(r4)
  341. b .LFailed
  342. .LThreaded:
  343. std r3, temp
  344. mflr r3
  345. // load actual function entry into r9
  346. ld r9, 0(r10)
  347. // save old TOC value
  348. std r2, 40(r1)
  349. // move function entry into ctr
  350. mtctr r9
  351. // load new TOC value
  352. ld r2, 8(r10)
  353. // load environment pointer from TOC
  354. ld r11, 16(r10)
  355. // load parameters
  356. lis r4, (errno)@highesta
  357. ori r4, r4, (errno)@highera
  358. sldi r4, r4, 32
  359. oris r4, r4, (errno)@ha
  360. std r3, retaddress
  361. lwz r3, (errno)@l(r4)
  362. bctrl
  363. // restore old TOC value
  364. ld r2, 40(r1)
  365. ld r4, temp
  366. ld r5, retaddress
  367. std r4, 0(r3)
  368. mtlr r5
  369. .LFailed:
  370. li r3, -1
  371. .LDone:
  372. end;
  373. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
  374. {
  375. This function puts the registers in place, does the call, and then
  376. copies back the registers as they are after the SysCall.
  377. }
  378. var
  379. temp : qword;
  380. retaddress: ptruint;
  381. asm
  382. mr r0, r3
  383. mr r3, r4
  384. mr r4, r5
  385. mr r5, r6
  386. mr r6, r7
  387. mr r7, r8
  388. mr r8, r9
  389. sc
  390. bns .LDone
  391. lis r10, (fpc_threadvar_relocate_proc)@highesta
  392. ori r10, r10, (fpc_threadvar_relocate_proc)@highera
  393. sldi r10, r10, 32
  394. oris r10, r10, (fpc_threadvar_relocate_proc)@ha
  395. ld r10, (fpc_threadvar_relocate_proc)@l(r10)
  396. cmpdi r10, 0
  397. bne .LThreaded
  398. lis r4, (Errno+8)@highesta
  399. ori r4, r4, (Errno+8)@highera
  400. sldi r4, r4, 32
  401. oris r4, r4, (Errno+8)@ha
  402. stw r3, (Errno+8)@l(r4)
  403. b .LFailed
  404. .LThreaded:
  405. std r3, temp
  406. mflr r3
  407. // load actual function entry into r9
  408. ld r9, 0(r10)
  409. // save old TOC value
  410. std r2, 40(r1)
  411. // move function entry into ctr
  412. mtctr r9
  413. // load new TOC value
  414. ld r2, 8(r10)
  415. // load environment pointer from TOC
  416. ld r11, 16(r10)
  417. // load parameters
  418. lis r4, (errno)@highesta
  419. ori r4, r4, (errno)@highera
  420. sldi r4, r4, 32
  421. oris r4, r4, (errno)@ha
  422. std r3, retaddress
  423. lwz r3, (errno)@l(r4)
  424. bctrl
  425. // restore old TOC value
  426. ld r2, 40(r1)
  427. ld r4, temp
  428. ld r5, retaddress
  429. std r4, 0(r3)
  430. mtlr r5
  431. .LFailed:
  432. li r3, -1
  433. .LDone:
  434. end;