syscall.inc 4.4 KB

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