syscall.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. procedure InitSyscallIntf;
  37. var
  38. ep: PPChar;
  39. auxv: PElf32AuxiliaryVector;
  40. begin
  41. psysinfo := 0;
  42. ep := envp;
  43. while ep^ <> nil do
  44. Inc(ep);
  45. Inc(ep);
  46. auxv := PElf32AuxiliaryVector(ep);
  47. repeat
  48. if auxv^.a_type = AT_SYSINFO then begin
  49. psysinfo := auxv^.a_un.a_val;
  50. if psysinfo <> 0 then
  51. sysenter_supported := 1; // descision factor in asm syscall routines
  52. Break;
  53. end;
  54. Inc(auxv);
  55. until auxv^.a_type = AT_NULL;
  56. end;
  57. {***********************SYSENTER CODE END******************************}
  58. Procedure fpc_geteipasebx;[external name 'fpc_geteipasebx'];
  59. function FpSysCall(sysnr:TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL0'];
  60. { Var sysnr located in register eax }
  61. asm
  62. // movl sysnr,%eax
  63. cmp $0, sysenter_supported
  64. jne .LSysEnter
  65. int $0x80
  66. jmp .LTail
  67. .LSysEnter:
  68. call psysinfo
  69. .LTail:
  70. cmpl $-4095,%eax
  71. jb .LSyscOK
  72. negl %eax
  73. call seterrno
  74. movl $-1,%eax
  75. .LSyscOK:
  76. end;
  77. function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL1'];
  78. { Var sysnr located in register eax
  79. Var param1 located in register edx }
  80. asm
  81. movl %ebx,%ecx
  82. // movl sysnr,%eax
  83. movl %edx,%ebx
  84. cmp $0, sysenter_supported
  85. jne .LSysEnter
  86. int $0x80
  87. jmp .LTail
  88. .LSysEnter:
  89. call psysinfo
  90. .LTail:
  91. movl %ecx,%ebx
  92. cmpl $-4095,%eax
  93. jb .LSyscOK
  94. negl %eax
  95. call seterrno
  96. movl $-1,%eax
  97. .LSyscOK:
  98. end;
  99. function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL2'];
  100. { Var sysnr located in register eax
  101. Var param1 located in register edx
  102. Var param2 located in register ecx }
  103. asm
  104. push %ebx
  105. // movl sysnr,%eax
  106. movl %edx,%ebx
  107. // movl param2,%ecx
  108. cmp $0, sysenter_supported
  109. jne .LSysEnter
  110. int $0x80
  111. jmp .LTail
  112. .LSysEnter:
  113. call psysinfo
  114. .LTail:
  115. pop %ebx
  116. cmpl $-4095,%eax
  117. jb .LSyscOK
  118. negl %eax
  119. call seterrno
  120. movl $-1,%eax
  121. .LSyscOK:
  122. end;
  123. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL3'];
  124. { Var sysnr located in register eax
  125. Var param1 located in register edx
  126. Var param2 located in register ecx
  127. Var param3 located at ebp+20 }
  128. asm
  129. push %ebx
  130. // movl sysnr,%eax
  131. movl %edx,%ebx
  132. // movl param2,%ecx
  133. movl param3,%edx
  134. cmp $0, sysenter_supported
  135. jne .LSysEnter
  136. int $0x80
  137. jmp .LTail
  138. .LSysEnter:
  139. call psysinfo
  140. .LTail:
  141. pop %ebx
  142. cmpl $-4095,%eax
  143. jb .LSyscOK
  144. negl %eax
  145. call seterrno
  146. movl $-1,%eax
  147. .LSyscOK:
  148. end;
  149. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL4'];
  150. { Var sysnr located in register eax
  151. Var param1 located in register edx
  152. Var param2 located in register ecx
  153. Var param3 located at ebp+20
  154. Var param4 located at ebp+16 }
  155. asm
  156. push %ebx
  157. push %esi
  158. // movl sysnr,%eax
  159. movl %edx,%ebx
  160. // movl param2,%ecx
  161. movl param3,%edx
  162. movl param4,%esi
  163. cmp $0, sysenter_supported
  164. jne .LSysEnter
  165. int $0x80
  166. jmp .LTail
  167. .LSysEnter:
  168. call psysinfo
  169. .LTail:
  170. pop %esi
  171. pop %ebx
  172. cmpl $-4095,%eax
  173. jb .LSyscOK
  174. negl %eax
  175. call seterrno
  176. movl $-1,%eax
  177. .LSyscOK:
  178. end;
  179. function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL5'];
  180. { Var sysnr located in register eax
  181. Var param1 located in register edx
  182. Var param2 located in register ecx
  183. Var param3 located at ebp+20
  184. Var param4 located at ebp+16
  185. Var param5 located at ebp+12 }
  186. asm
  187. push %ebx
  188. push %esi
  189. push %edi
  190. // movl sysnr,%eax
  191. movl %edx,%ebx
  192. // movl param2,%ecx
  193. movl param3,%edx
  194. movl param4,%esi
  195. movl param5,%edi
  196. cmp $0, sysenter_supported
  197. jne .LSysEnter
  198. int $0x80
  199. jmp .LTail
  200. .LSysEnter:
  201. call psysinfo
  202. .LTail:
  203. pop %edi
  204. pop %esi
  205. pop %ebx
  206. cmpl $-4095,%eax
  207. jb .LSyscOK
  208. negl %eax
  209. call seterrno
  210. movl $-1,%eax
  211. .LSyscOK:
  212. end;
  213. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6: TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL6'];
  214. { Var sysnr located in register eax
  215. Var param1 located in register edx
  216. Var param2 located in register ecx
  217. Var param3 located at ebp+20
  218. Var param4 located at ebp+16
  219. Var param5 located at ebp+12
  220. Var param6 located at ebp+8 }
  221. asm
  222. push %ebx
  223. push %esi
  224. push %edi
  225. push %ebp
  226. // movl sysnr,%eax
  227. movl %edx,%ebx
  228. // movl param2,%ecx
  229. movl param3,%edx
  230. movl param4,%esi
  231. movl param5,%edi
  232. movl param6,%ebp
  233. cmp $0, sysenter_supported
  234. jne .LSysEnter
  235. int $0x80
  236. jmp .LTail
  237. .LSysEnter:
  238. call psysinfo
  239. .LTail:
  240. pop %ebp
  241. pop %edi
  242. pop %esi
  243. pop %ebx
  244. cmpl $-4095,%eax
  245. jb .LSyscOK
  246. negl %eax
  247. call seterrno
  248. movl $-1,%eax
  249. .LSyscOK:
  250. end;
  251. {No debugging for syslinux include !}
  252. {$IFDEF SYS_LINUX}
  253. {$UNDEF SYSCALL_DEBUG}
  254. {$ENDIF SYS_LINUX}