syscalls.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  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.
  11. **********************************************************************}
  12. { Include syscall itself }
  13. {$i syscallo.inc}
  14. Function Sys_mmap(adr,len,prot,flags,fdes,off:longint):longint; // moved from sysunix.inc, used in sbrk
  15. type
  16. tmmapargs=packed record
  17. address : longint;
  18. size : longint;
  19. prot : longint;
  20. flags : longint;
  21. fd : longint;
  22. offset : longint;
  23. end;
  24. var
  25. t : syscallregs;
  26. mmapargs : tmmapargs;
  27. begin
  28. mmapargs.address:=adr;
  29. mmapargs.size:=len;
  30. mmapargs.prot:=prot;
  31. mmapargs.flags:=flags;
  32. mmapargs.fd:=fdes;
  33. mmapargs.offset:=off;
  34. t.reg2:=longint(@mmapargs);
  35. Sys_mmap:=syscall(syscall_nr_mmap,t);
  36. end;
  37. Function Sys_munmap(adr,len:longint):longint; // moved from sysunix.inc, used in sbrk
  38. var
  39. t : syscallregs;
  40. begin
  41. t.reg2:=adr;
  42. t.reg3:=len;
  43. Sys_munmap:=syscall(syscall_nr_munmap,t);
  44. end;
  45. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  46. begin
  47. if (pointer(func)=nil) or (sp=nil) then
  48. exit(-1); // give an error result
  49. {$ifdef i386}
  50. asm
  51. { Insert the argument onto the new stack. }
  52. movl sp,%ecx
  53. subl $8,%ecx
  54. movl args,%eax
  55. movl %eax,4(%ecx)
  56. { Save the function pointer as the zeroth argument.
  57. It will be popped off in the child in the ebx frobbing below. }
  58. movl func,%eax
  59. movl %eax,0(%ecx)
  60. { Do the system call }
  61. pushl %ebx
  62. movl flags,%ebx
  63. movl SysCall_nr_clone,%eax
  64. int $0x80
  65. popl %ebx
  66. test %eax,%eax
  67. jnz .Lclone_end
  68. { We're in the new thread }
  69. subl %ebp,%ebp { terminate the stack frame }
  70. call *%ebx
  71. { exit process }
  72. movl %eax,%ebx
  73. movl $1,%eax
  74. int $0x80
  75. .Lclone_end:
  76. movl %eax,__RESULT
  77. end;
  78. {$endif i386}
  79. {$ifdef m68k}
  80. { No yet translated, my m68k assembler is too weak for such things PM }
  81. (*
  82. asm
  83. { Insert the argument onto the new stack. }
  84. movl sp,%ecx
  85. subl $8,%ecx
  86. movl args,%eax
  87. movl %eax,4(%ecx)
  88. { Save the function pointer as the zeroth argument.
  89. It will be popped off in the child in the ebx frobbing below. }
  90. movl func,%eax
  91. movl %eax,0(%ecx)
  92. { Do the system call }
  93. pushl %ebx
  94. movl flags,%ebx
  95. movl SysCall_nr_clone,%eax
  96. int $0x80
  97. popl %ebx
  98. test %eax,%eax
  99. jnz .Lclone_end
  100. { We're in the new thread }
  101. subl %ebp,%ebp { terminate the stack frame }
  102. call *%ebx
  103. { exit process }
  104. movl %eax,%ebx
  105. movl $1,%eax
  106. int $0x80
  107. .Lclone_end:
  108. movl %eax,__RESULT
  109. end;
  110. *)
  111. {$endif m68k}
  112. end;
  113. {
  114. Interface to Unix ioctl call.
  115. Performs various operations on the filedescriptor Handle.
  116. Ndx describes the operation to perform.
  117. Data points to data needed for the Ndx function. The structure of this
  118. data is function-dependent.
  119. }
  120. Function Sys_IOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt; // This was missing here, instead hardcode in Do_IsDevice
  121. var
  122. sr: SysCallRegs;
  123. begin
  124. sr.reg2:=Handle;
  125. sr.reg3:=Ndx;
  126. sr.reg4:=Longint(Data);
  127. Sys_IOCtl:=SysCall(Syscall_nr_ioctl,sr);
  128. end;
  129. {
  130. $Log$
  131. Revision 1.18 2003-09-14 20:15:01 marco
  132. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  133. Revision 1.17 2002/12/18 16:43:26 marco
  134. * new unix rtl, linux part.....
  135. Revision 1.16 2002/11/11 21:40:26 marco
  136. * rename syscall.inc -> syscallo.inc
  137. Revision 1.15 2002/10/14 19:39:17 peter
  138. * threads unit added for thread support
  139. Revision 1.14 2002/09/10 21:32:14 jonas
  140. + added "nop" after sc instruction, since normally in case of success,
  141. sc returns to the second instruction after itself
  142. Revision 1.13 2002/09/07 16:01:19 peter
  143. * old logs removed and tabs fixed
  144. Revision 1.12 2002/09/07 13:14:04 florian
  145. * hopefully final fix for ppc syscall BTW: The regX numbering is somehow messy
  146. Revision 1.11 2002/09/03 21:37:54 florian
  147. * hopefully final fix for ppc syscall
  148. Revision 1.10 2002/09/02 20:42:22 florian
  149. * another ppc syscall fix
  150. Revision 1.9 2002/09/02 20:03:20 florian
  151. * ppc syscall code fixed
  152. Revision 1.8 2002/08/19 18:24:05 jonas
  153. + ppc support for do_syscall
  154. Revision 1.7 2002/07/29 21:28:17 florian
  155. * several fixes to get further with linux/ppc system unit compilation
  156. Revision 1.6 2002/07/28 20:43:48 florian
  157. * several fixes for linux/powerpc
  158. * several fixes to MT
  159. }