vfork.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
  2. Copyright (C) 2001 Hewlett-Packard Australia
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU Library General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option) any
  6. later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  10. details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. Derived in part from the Linux-8086 C library, the GNU C Library, and several
  14. other sundry sources. Files within this library are copyright by their
  15. respective copyright holders.
  16. */
  17. #include <sys/syscall.h>
  18. #define _ERRNO_H
  19. #include <bits/errno.h>
  20. /* Clone the calling process, but without copying the whole address space.
  21. The calling process is suspended until the new process exits or is
  22. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  23. and the process ID of the new process to the old process. */
  24. .text
  25. .globl __vfork
  26. .hidden __vfork
  27. .type __vfork,@function
  28. .align 4
  29. __vfork:
  30. mov.w .L2, r3
  31. trapa #__SH_SYSCALL_TRAP_BASE
  32. mov r0, r1
  33. #ifdef __sh2__
  34. /* 12 arithmetic shifts for the crappy sh2, because shad doesn't exist! */
  35. shar r1
  36. shar r1
  37. shar r1
  38. shar r1
  39. shar r1
  40. shar r1
  41. shar r1
  42. shar r1
  43. shar r1
  44. shar r1
  45. shar r1
  46. shar r1
  47. #else
  48. mov #-12, r2
  49. shad r2, r1
  50. #endif
  51. not r1, r1 /* r1=0 means r0 = -1 to -4095 */
  52. tst r1, r1 /* i.e. error in linux */
  53. bf 2f
  54. mov.w .L1, r1
  55. cmp/eq r1, r0
  56. bf/s __syscall_error
  57. mov r0, r4
  58. /* If we don't have vfork, use fork. */
  59. mov.w .L3, r3
  60. trapa #__SH_SYSCALL_TRAP_BASE
  61. mov r0, r1
  62. #ifdef __sh2__
  63. /* 12 arithmetic shifts for the crappy sh2, because shad doesn't exist! */
  64. shar r1
  65. shar r1
  66. shar r1
  67. shar r1
  68. shar r1
  69. shar r1
  70. shar r1
  71. shar r1
  72. shar r1
  73. shar r1
  74. shar r1
  75. shar r1
  76. #else
  77. mov #-12, r2
  78. shad r2, r1
  79. #endif
  80. not r1, r1 /* r1=0 means r0 = -1 to -4095 */
  81. tst r1, r1 /* i.e. error in linux */
  82. bt/s __syscall_error
  83. mov r0, r4
  84. 2:
  85. rts
  86. nop
  87. .align 2
  88. .L1:
  89. .word -ENOSYS
  90. .L2:
  91. .word __NR_vfork
  92. .L3:
  93. .word __NR_fork
  94. .size __vfork, .-__vfork
  95. weak_alias(__vfork,vfork)
  96. libc_hidden_def(vfork)
  97. #include "syscall_error.S"