bsyscall.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005-2009 by Michael Van Canneyt and David Zhang
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {$define FPC_BASEUNIX_HAS_FPPIPE}
  11. Function fppipe(var fildes : tfildes):cint;assembler;
  12. {
  13. This function puts the registers in place, does the call, and then
  14. copies back the registers as they are after the SysCall.
  15. Extracted from linux/source/arch/mips/kernel/syscall.c:
  16. * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
  17. * convention. It returns results in registers $v0 / $v1 which means there
  18. * is no need for it to do verify the validity of a userspace pointer
  19. * argument. Historically that used to be expensive in Linux. These days
  20. * the performance advantage is negligible.
  21. }
  22. var
  23. tmp: pointer;
  24. asm
  25. sw $a0,tmp { if $a0 is preserved in syscall then this is not needed }
  26. li $v0,syscall_nr_pipe
  27. syscall
  28. nop
  29. beq $a3,$0,.L1
  30. nop
  31. move $a0,$v0
  32. jal fpseterrno
  33. nop
  34. b .L2
  35. li $v0,-1 { in delay slot }
  36. .L1:
  37. { the two files descriptors are now in v0 and v1 registers
  38. copying them back into fildes variable }
  39. lw $t1,tmp
  40. sw $v0,($t1)
  41. sw $v1,4($t1)
  42. .L2:
  43. end;