Update to LGPL v2.1.
[jlayton/glibc.git] / sysdeps / unix / sysv / linux / sh / vfork.S
1 /* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #include <sysdep.h>
20 #define _ERRNO_H        1
21 #include <bits/errno.h>
22
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
28 ENTRY (__vfork)
29
30 #ifdef __NR_vfork
31         mov.w   .L3, r3
32         trapa   #0x10
33         mov     r0, r1
34         mov     #-12, r2
35         shad    r2, r1
36         not     r1, r1                  // r1=0 means r0 = -1 to -4095
37         tst     r1, r1                  // i.e. error in linux
38         bf      1f
39         mov.w   .L1, r1
40         cmp/eq  r1, r0
41         bt      2f
42         mov.l   .L2, r1
43 #ifdef SHARED
44         mov     r0, r4
45         mov.l   r12, @-r15
46         sts.l   pr, @-r15
47         mov.l   0f, r12
48         mova    0f, r0
49         add     r0, r12
50         mova    .L2, r0
51         add     r0, r1
52         jsr     @r1
53          nop
54         lds.l   @r15+, pr
55         rts
56          mov.l  @r15+, r12
57         .align  2
58 0:
59         .long   _GLOBAL_OFFSET_TABLE_
60 #else
61         jmp     @r1
62          mov    r0, r4
63 #endif
64 .L1:
65         .word   -ENOSYS
66 .L3:    .word   __NR_vfork
67 1:
68         rts
69          nop
70 2:
71 #endif
72
73         /* If we don't have vfork, fork is close enough.  */
74         mov     #+__NR_fork, r3
75         trapa   #0x10
76         mov     r0, r1
77         mov     #-12, r2
78         shad    r2, r1
79         not     r1, r1                  // r1=0 means r0 = -1 to -4095
80         tst     r1, r1                  // i.e. error in linux
81         bf      1f
82         mov.l   .L2, r1
83 #ifdef SHARED
84         mov     r0, r4
85         mov.l   r12, @-r15
86         sts.l   pr, @-r15
87         mov.l   0f, r12
88         mova    0f, r0
89         add     r0, r12
90         mova    .L2, r0
91         add     r0, r1
92         jsr     @r1
93          nop
94         lds.l   @r15+, pr
95         rts
96          mov.l  @r15+, r12
97         .align  2
98 0:
99         .long   _GLOBAL_OFFSET_TABLE_
100 #else
101         jmp     @r1
102          mov    r0, r4
103 #endif
104         .align  2
105 .L2:
106         .long   PLTJMP(C_SYMBOL_NAME(__syscall_error))
107 1:
108         rts
109          nop
110         
111 PSEUDO_END (__vfork)
112
113 weak_alias (__vfork, vfork)