syscall.inc 10 KB

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