vfork.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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, write to the Free Software Foundation, Inc.,
  13. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Derived in part from the Linux-8086 C library, the GNU C Library, and several
  15. other sundry sources. Files within this library are copyright by their
  16. respective copyright holders.
  17. */
  18. #include <features.h>
  19. #include <sys/syscall.h>
  20. #define _ERRNO_H
  21. #include <bits/errno.h>
  22. #include <bits/sysnum.h>
  23. /* Clone the calling process, but without copying the whole address space.
  24. The calling process is suspended until the new process exits or is
  25. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  26. and the process ID of the new process to the old process. */
  27. .text
  28. .globl __vfork
  29. .hidden __vfork
  30. .type __vfork,@function
  31. .align 4
  32. __vfork:
  33. mov.w .L2, r3
  34. trapa #__SH_SYSCALL_TRAP_BASE
  35. mov r0, r1
  36. #ifdef __CONFIG_SH2__
  37. /* 12 arithmetic shifts for the crappy sh2, because shad doesn't exist! */
  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. shar r1
  48. shar r1
  49. shar r1
  50. #else
  51. mov #-12, r2
  52. shad r2, r1
  53. #endif
  54. not r1, r1 /* r1=0 means r0 = -1 to -4095 */
  55. tst r1, r1 /* i.e. error in linux */
  56. bf 2f
  57. mov.w .L1, r1
  58. cmp/eq r1, r0
  59. bf/s __syscall_error
  60. mov r0, r4
  61. /* If we don't have vfork, use fork. */
  62. mov.w .L3, r3
  63. trapa #__SH_SYSCALL_TRAP_BASE
  64. mov r0, r1
  65. #ifdef __CONFIG_SH2__
  66. /* 12 arithmetic shifts for the crappy sh2, because shad doesn't exist! */
  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. shar r1
  77. shar r1
  78. shar r1
  79. #else
  80. mov #-12, r2
  81. shad r2, r1
  82. #endif
  83. not r1, r1 /* r1=0 means r0 = -1 to -4095 */
  84. tst r1, r1 /* i.e. error in linux */
  85. bt/s __syscall_error
  86. mov r0, r4
  87. 2:
  88. rts
  89. nop
  90. .align 2
  91. .L1:
  92. .word -ENOSYS
  93. .L2:
  94. .word __NR_vfork
  95. .L3:
  96. .word __NR_fork
  97. .size __vfork, .-__vfork
  98. weak_alias(__vfork,vfork)
  99. libc_hidden_weak(vfork)
  100. #include "syscall_error.S"