syscall.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. The syscalls for the new RTL, moved to platform dependant dir.
  6. Old linux calling convention is still kept.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$ASMMODE ATT}
  14. {*************************SYSENTER CODE********************************}
  15. { included by system.pp in linux rtl }
  16. const
  17. AT_NULL = 0;
  18. {* Pointer to the global system page used for system calls and other
  19. nice things. *}
  20. AT_SYSINFO = 32;
  21. AT_SYSINFO_EHDR = 33;
  22. type
  23. TAuxiliaryValue = cuInt32;
  24. TInternalUnion = record
  25. a_val: cuint32; //* Integer value */
  26. {* We use to have pointer elements added here. We cannot do that,
  27. though, since it does not work when using 32-bit definitions
  28. on 64-bit platforms and vice versa. *}
  29. end;
  30. Elf32_auxv_t = record
  31. a_type: cuint32; //* Entry type */
  32. a_un: TInternalUnion;
  33. end;
  34. TElf32AuxiliaryVector = Elf32_auxv_t;
  35. PElf32AuxiliaryVector = ^TElf32AuxiliaryVector;
  36. var
  37. psysinfo: LongWord = 0;
  38. procedure InitSyscallIntf;
  39. var
  40. ep: PPChar;
  41. auxv: PElf32AuxiliaryVector;
  42. begin
  43. psysinfo := 0;
  44. ep := envp;
  45. while ep^ <> nil do
  46. Inc(ep);
  47. Inc(ep);
  48. auxv := PElf32AuxiliaryVector(ep);
  49. repeat
  50. if auxv^.a_type = AT_SYSINFO then begin
  51. psysinfo := auxv^.a_un.a_val;
  52. if psysinfo <> 0 then
  53. sysenter_supported := 1; // descision factor in asm syscall routines
  54. Break;
  55. end;
  56. Inc(auxv);
  57. until auxv^.a_type = AT_NULL;
  58. end;
  59. {***********************SYSENTER CODE END******************************}
  60. Procedure fpc_geteipasebx;[external name 'fpc_geteipasebx'];
  61. function FpSysCall(sysnr:TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL0'];
  62. { Var sysnr located in register eax }
  63. asm
  64. // movl sysnr,%eax
  65. cmp $0, sysenter_supported
  66. jne .LSysEnter
  67. int $0x80
  68. jmp .LTail
  69. .LSysEnter:
  70. call psysinfo
  71. .LTail:
  72. cmpl $-4095,%eax
  73. jb .LSyscOK
  74. negl %eax
  75. call seterrno
  76. movl $-1,%eax
  77. .LSyscOK:
  78. end;
  79. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL1'];
  80. { Var sysnr located in register eax
  81. Var param1 located in register edx }
  82. asm
  83. movl %ebx,%ecx
  84. // movl sysnr,%eax
  85. movl %edx,%ebx
  86. cmp $0, sysenter_supported
  87. jne .LSysEnter
  88. int $0x80
  89. jmp .LTail
  90. .LSysEnter:
  91. call psysinfo
  92. .LTail:
  93. movl %ecx,%ebx
  94. cmpl $-4095,%eax
  95. jb .LSyscOK
  96. negl %eax
  97. call seterrno
  98. movl $-1,%eax
  99. .LSyscOK:
  100. end;
  101. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL2'];
  102. { Var sysnr located in register eax
  103. Var param1 located in register edx
  104. Var param2 located in register ecx }
  105. asm
  106. push %ebx
  107. // movl sysnr,%eax
  108. movl %edx,%ebx
  109. // movl param2,%ecx
  110. cmp $0, sysenter_supported
  111. jne .LSysEnter
  112. int $0x80
  113. jmp .LTail
  114. .LSysEnter:
  115. call psysinfo
  116. .LTail:
  117. pop %ebx
  118. cmpl $-4095,%eax
  119. jb .LSyscOK
  120. negl %eax
  121. call seterrno
  122. movl $-1,%eax
  123. .LSyscOK:
  124. end;
  125. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL3'];
  126. { Var sysnr located in register eax
  127. Var param1 located in register edx
  128. Var param2 located in register ecx
  129. Var param3 located at ebp+20 }
  130. asm
  131. push %ebx
  132. // movl sysnr,%eax
  133. movl %edx,%ebx
  134. // movl param2,%ecx
  135. movl param3,%edx
  136. cmp $0, sysenter_supported
  137. jne .LSysEnter
  138. int $0x80
  139. jmp .LTail
  140. .LSysEnter:
  141. call psysinfo
  142. .LTail:
  143. pop %ebx
  144. cmpl $-4095,%eax
  145. jb .LSyscOK
  146. negl %eax
  147. call seterrno
  148. movl $-1,%eax
  149. .LSyscOK:
  150. end;
  151. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL4'];
  152. { Var sysnr located in register eax
  153. Var param1 located in register edx
  154. Var param2 located in register ecx
  155. Var param3 located at ebp+20
  156. Var param4 located at ebp+16 }
  157. asm
  158. push %ebx
  159. push %esi
  160. // movl sysnr,%eax
  161. movl %edx,%ebx
  162. // movl param2,%ecx
  163. movl param3,%edx
  164. movl param4,%esi
  165. cmp $0, sysenter_supported
  166. jne .LSysEnter
  167. int $0x80
  168. jmp .LTail
  169. .LSysEnter:
  170. call psysinfo
  171. .LTail:
  172. pop %esi
  173. pop %ebx
  174. cmpl $-4095,%eax
  175. jb .LSyscOK
  176. negl %eax
  177. call seterrno
  178. movl $-1,%eax
  179. .LSyscOK:
  180. end;
  181. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL5'];
  182. { Var sysnr located in register eax
  183. Var param1 located in register edx
  184. Var param2 located in register ecx
  185. Var param3 located at ebp+20
  186. Var param4 located at ebp+16
  187. Var param5 located at ebp+12 }
  188. asm
  189. push %ebx
  190. push %esi
  191. push %edi
  192. // movl sysnr,%eax
  193. movl %edx,%ebx
  194. // movl param2,%ecx
  195. movl param3,%edx
  196. movl param4,%esi
  197. movl param5,%edi
  198. cmp $0, sysenter_supported
  199. jne .LSysEnter
  200. int $0x80
  201. jmp .LTail
  202. .LSysEnter:
  203. call psysinfo
  204. .LTail:
  205. pop %edi
  206. pop %esi
  207. pop %ebx
  208. cmpl $-4095,%eax
  209. jb .LSyscOK
  210. negl %eax
  211. call seterrno
  212. movl $-1,%eax
  213. .LSyscOK:
  214. end;
  215. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6: TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL6'];
  216. { Var sysnr located in register eax
  217. Var param1 located in register edx
  218. Var param2 located in register ecx
  219. Var param3 located at ebp+20
  220. Var param4 located at ebp+16
  221. Var param5 located at ebp+12
  222. Var param6 located at ebp+8 }
  223. asm
  224. push %ebx
  225. push %esi
  226. push %edi
  227. push %ebp
  228. // movl sysnr,%eax
  229. movl %edx,%ebx
  230. // movl param2,%ecx
  231. movl param3,%edx
  232. movl param4,%esi
  233. movl param5,%edi
  234. movl param6,%ebp
  235. cmp $0, sysenter_supported
  236. jne .LSysEnter
  237. int $0x80
  238. jmp .LTail
  239. .LSysEnter:
  240. call psysinfo
  241. .LTail:
  242. pop %ebp
  243. pop %edi
  244. pop %esi
  245. pop %ebx
  246. cmpl $-4095,%eax
  247. jb .LSyscOK
  248. negl %eax
  249. call seterrno
  250. movl $-1,%eax
  251. .LSyscOK:
  252. end;
  253. {No debugging for syslinux include !}
  254. {$IFDEF SYS_LINUX}
  255. {$UNDEF SYSCALL_DEBUG}
  256. {$ENDIF SYS_LINUX}