2
0

syscall.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {
  2. Copyright (c) 2002 by Marco van de Voort
  3. Syscall functions for i386 *BSD.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. These functions are the same over all three BSDs, except that some have a
  17. 32-bit Errno, and some a 16-bit}
  18. {$ifdef FPC_USE_SYSCALL}
  19. {$ifdef NetBSD}
  20. {$UNDEF ErrnoWord}
  21. {$endif}
  22. {$ifdef FreeBSD}
  23. {$DEFINE ErrnoWord}
  24. {$endif}
  25. Procedure fpc_geteipasebx;[external name 'fpc_geteipasebx'];
  26. procedure actualsyscall; assembler; {inline requires a dummy push IIRC}
  27. asm
  28. int $0x80
  29. jb .LErrorcode
  30. ret
  31. .LErrorcode:
  32. {$ifdef FPC_PIC}
  33. call fpc_geteipasebx
  34. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  35. movl fpc_threadvar_relocate_proc@GOT(%ebx),%ecx
  36. movl (%ecx),%ecx
  37. movl Errno@GOT(%ebx),%edi
  38. {$else FPC_PIC}
  39. leal Errno,%edi
  40. movl fpc_threadvar_relocate_proc,%ecx
  41. {$endif FPC_PIC}
  42. testl %ecx,%ecx
  43. jne .LThread
  44. {$ifdef ErrnoWord}
  45. movw %ax,4(%edi)
  46. {$else}
  47. movl %eax,4(%edi)
  48. {$endif}
  49. jmp .LNoThread
  50. .LThread:
  51. movl %eax,%ebx
  52. movl (%edi),%eax
  53. call *%ecx
  54. {$ifdef ErrnoWord}
  55. movw %bx,4(%eax)
  56. {$else}
  57. movl %ebx,4(%eax)
  58. {$endif}
  59. .LNoThread:
  60. movl $-1,%eax
  61. end;
  62. function FpSysCall(sysnr:TSysParam):TSysResult; oldfpccall; assembler; [public,alias:'FPC_DOSYS0'];
  63. asm
  64. movl sysnr,%eax
  65. call actualsyscall
  66. end;
  67. function FpSysCall(sysnr,param1:TSysParam):TSysResult; oldfpccall; assembler;[public,alias:'FPC_DOSYS1'];
  68. asm
  69. movl sysnr,%eax
  70. pushl Param1
  71. call actualsyscall
  72. addl $4,%esp
  73. end;
  74. function FpSysCall(sysnr,param1:integer):TSysResult; oldfpccall;assembler;[public,alias:'FPC_DOSYS1w'];
  75. asm
  76. movl sysnr,%eax
  77. pushw Param1
  78. call actualsyscall
  79. add $2,%esp
  80. end;
  81. function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult; oldfpccall;assembler; [public,alias:'FPC_DOSYS2'];
  82. asm
  83. movl sysnr,%eax
  84. pushl param2
  85. pushl Param1
  86. call actualsyscall
  87. addl $8,%esp
  88. end;
  89. function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; oldfpccall;assembler;[public,alias:'FPC_DOSYS3'];
  90. asm
  91. movl sysnr,%eax
  92. pushl param3
  93. pushl param2
  94. pushl Param1
  95. call actualsyscall
  96. addl $12,%esp
  97. end;
  98. function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;oldfpccall; assembler;[public,alias:'FPC_DOSYS4'];
  99. asm
  100. movl sysnr,%eax
  101. pushl param4
  102. pushl param3
  103. pushl param2
  104. pushl Param1
  105. call actualsyscall
  106. addl $16,%esp
  107. end;
  108. function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult;oldfpccall; assembler;[public,alias:'FPC_DOSYS5'];
  109. asm
  110. movl sysnr,%eax
  111. pushl param5
  112. pushl param4
  113. pushl param3
  114. pushl param2
  115. pushl Param1
  116. call actualsyscall
  117. addl $20,%esp
  118. end;
  119. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):int64; oldfpccall; assembler;[public,alias:'FPC_DOSYS6'];
  120. asm
  121. movl sysnr,%eax
  122. pushl param6
  123. pushl param5
  124. pushl param4
  125. pushl param3
  126. pushl param2
  127. pushl Param1
  128. call actualsyscall
  129. addl $24,%esp
  130. end;
  131. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:TSysParam):int64;oldfpccall; assembler; [public,alias:'FPC_DOSYS7'];
  132. asm
  133. movl sysnr,%eax
  134. pushl param7
  135. pushl param6
  136. pushl param5
  137. pushl param4
  138. pushl param3
  139. pushl param2
  140. pushl Param1
  141. call actualsyscall
  142. addl $28,%esp
  143. end;
  144. function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,param8:TSysParam):int64;oldfpccall; assembler; [public,alias:'FPC_DOSYS8'];
  145. asm
  146. movl sysnr,%eax
  147. pushl param8
  148. pushl param7
  149. pushl param6
  150. pushl param5
  151. pushl param4
  152. pushl param3
  153. pushl param2
  154. pushl Param1
  155. call actualsyscall
  156. addl $32,%esp
  157. end;
  158. {$endif}