sysc11.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. begin
  16. fpmmap(pointer(adr),size_t(len),cint(prot),cint(flags),cint(fdes),off_t(off));
  17. end;
  18. Function Sys_munmap(adr,len:longint):longint; // moved from sysunix.inc, used in sbrk
  19. begin
  20. fpmunmap(pointer(adr),cint(len));
  21. end;
  22. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  23. begin
  24. if (pointer(func)=nil) or (sp=nil) then
  25. exit(-1); // give an error result
  26. {$ifdef cpui386}
  27. {$ASMMODE ATT}
  28. asm
  29. { Insert the argument onto the new stack. }
  30. movl sp,%ecx
  31. subl $8,%ecx
  32. movl args,%eax
  33. movl %eax,4(%ecx)
  34. { Save the function pointer as the zeroth argument.
  35. It will be popped off in the child in the ebx frobbing below. }
  36. movl func,%eax
  37. movl %eax,0(%ecx)
  38. { Do the system call }
  39. pushl %ebx
  40. movl flags,%ebx
  41. movl SysCall_nr_clone,%eax
  42. int $0x80
  43. popl %ebx
  44. test %eax,%eax
  45. jnz .Lclone_end
  46. { We're in the new thread }
  47. subl %ebp,%ebp { terminate the stack frame }
  48. call *%ebx
  49. { exit process }
  50. movl %eax,%ebx
  51. movl $1,%eax
  52. int $0x80
  53. .Lclone_end:
  54. movl %eax,__RESULT
  55. end;
  56. {$endif cpui386}
  57. {$ifdef cpum68k}
  58. { No yet translated, my m68k assembler is too weak for such things PM }
  59. (*
  60. asm
  61. { Insert the argument onto the new stack. }
  62. movl sp,%ecx
  63. subl $8,%ecx
  64. movl args,%eax
  65. movl %eax,4(%ecx)
  66. { Save the function pointer as the zeroth argument.
  67. It will be popped off in the child in the ebx frobbing below. }
  68. movl func,%eax
  69. movl %eax,0(%ecx)
  70. { Do the system call }
  71. pushl %ebx
  72. movl flags,%ebx
  73. movl SysCall_nr_clone,%eax
  74. int $0x80
  75. popl %ebx
  76. test %eax,%eax
  77. jnz .Lclone_end
  78. { We're in the new thread }
  79. subl %ebp,%ebp { terminate the stack frame }
  80. call *%ebx
  81. { exit process }
  82. movl %eax,%ebx
  83. movl $1,%eax
  84. int $0x80
  85. .Lclone_end:
  86. movl %eax,__RESULT
  87. end;
  88. *)
  89. {$endif cpum68k}
  90. end;
  91. {
  92. Interface to Unix ioctl call.
  93. Performs various operations on the filedescriptor Handle.
  94. Ndx describes the operation to perform.
  95. Data points to data needed for the Ndx function. The structure of this
  96. data is function-dependent.
  97. }
  98. Function Sys_IOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt; // This was missing here, instead hardcode in Do_IsDevice
  99. begin
  100. sys_ioctl:=fpioctl(handle,ndx,data);
  101. end;
  102. {
  103. $Log$
  104. Revision 1.2 2003-10-31 08:55:11 mazen
  105. + assembler mode forced to ATT style for x86 cpu
  106. Revision 1.1 2003/10/30 16:42:25 marco
  107. * Killing off old syscall convention anywhere except for oldlinux
  108. Revision 1.19 2003/10/17 20:56:24 olle
  109. * Changed m68k to cpum68k, i386 to cpui386
  110. Revision 1.18 2003/09/14 20:15:01 marco
  111. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  112. Revision 1.17 2002/12/18 16:43:26 marco
  113. * new unix rtl, linux part.....
  114. Revision 1.16 2002/11/11 21:40:26 marco
  115. * rename syscall.inc -> syscallo.inc
  116. Revision 1.15 2002/10/14 19:39:17 peter
  117. * threads unit added for thread support
  118. Revision 1.14 2002/09/10 21:32:14 jonas
  119. + added "nop" after sc instruction, since normally in case of success,
  120. sc returns to the second instruction after itself
  121. Revision 1.13 2002/09/07 16:01:19 peter
  122. * old logs removed and tabs fixed
  123. Revision 1.12 2002/09/07 13:14:04 florian
  124. * hopefully final fix for ppc syscall BTW: The regX numbering is somehow messy
  125. Revision 1.11 2002/09/03 21:37:54 florian
  126. * hopefully final fix for ppc syscall
  127. Revision 1.10 2002/09/02 20:42:22 florian
  128. * another ppc syscall fix
  129. Revision 1.9 2002/09/02 20:03:20 florian
  130. * ppc syscall code fixed
  131. Revision 1.8 2002/08/19 18:24:05 jonas
  132. + ppc support for do_syscall
  133. Revision 1.7 2002/07/29 21:28:17 florian
  134. * several fixes to get further with linux/ppc system unit compilation
  135. Revision 1.6 2002/07/28 20:43:48 florian
  136. * several fixes for linux/powerpc
  137. * several fixes to MT
  138. }