]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/xtensa/vfork.S
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / xtensa / vfork.S
1 /* Copyright (C) 2005, 2007 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, see
16    <http://www.gnu.org/licenses/>.  */
17
18 #include "sysdep.h"
19 #include <sys/syscall.h>
20 #define _SIGNAL_H
21 #include <bits/signum.h>
22
23
24 /* Clone the calling process, but without copying the whole address space.
25    The calling process is suspended until the new process exits or is
26    replaced by a call to `execve'.  Return -1 for errors, 0 to the new process,
27    and the process ID of the new process to the old process.
28
29    Note that it is important that we don't create a new stack frame for the
30    caller.  */
31
32
33 /* The following are defined in linux/sched.h, which unfortunately
34    is not safe for inclusion in an assembly file.  */
35 #define CLONE_VM        0x00000100     /* set if VM shared between processes */
36 #define CLONE_VFORK     0x00004000     /* set if the parent wants the child to
37                                           wake it up on mm_release */
38
39 #ifndef SAVE_PID
40 #define SAVE_PID
41 #endif
42
43 #ifndef RESTORE_PID
44 #define RESTORE_PID
45 #endif
46
47
48 /* pid_t vfork(void);
49    Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */
50
51 HIDDEN_ENTRY (__vfork)
52
53         movi    a6, .Ljumptable
54         extui   a2, a0, 30, 2           /* call-size: call4/8/12 = 1/2/3 */
55         addx4   a4, a2, a6              /* find return address in jumptable */
56         l32i    a4, a4, 0
57         add     a4, a4, a6
58
59         slli    a2, a2, 30
60         xor     a3, a0, a2              /* remove call-size from return addr */
61         extui   a5, a4, 30, 2           /* get high bits of jump target */
62         slli    a5, a5, 30
63         or      a3, a3, a5              /* stuff them into the return address */
64         xor     a4, a4, a5              /* clear high bits of jump target */
65         or      a0, a4, a2              /* create temporary return address */
66         retw                            /* "return" to .L4, .L8, or .L12 */
67
68         .align  4
69 .Ljumptable:
70         .word   0
71         .word   .L4 - .Ljumptable
72         .word   .L8 - .Ljumptable
73         .word   .L12 - .Ljumptable
74
75         /* a7: return address */
76 .L4:    mov     a12, a2
77         mov     a13, a3
78
79         SAVE_PID
80
81         /* Use syscall 'clone'.  Set new stack pointer to the same address.  */
82         movi    a2, SYS_ify (clone)
83         movi    a3, 0
84         movi    a6, CLONE_VM | CLONE_VFORK | SIGCHLD
85         syscall
86
87         RESTORE_PID
88
89         movi    a5, -4096
90
91         mov     a6, a2
92         mov     a2, a12
93         mov     a3, a13
94
95         bgeu    a6, a5, 1f
96         jx      a7
97 1:      call4   .Lerr                   /* returns to original caller */
98
99
100         /* a11: return address */
101 .L8:    mov     a12, a2
102         mov     a13, a3
103         mov     a14, a6
104
105         SAVE_PID
106
107         movi    a2, SYS_ify (clone)
108         movi    a3, 0
109         movi    a6, CLONE_VM | CLONE_VFORK | SIGCHLD
110         syscall
111
112         RESTORE_PID
113
114         movi    a9, -4096
115
116         mov     a10, a2
117         mov     a2, a12
118         mov     a3, a13
119         mov     a6, a14
120
121         bgeu    a10, a9, 1f
122         jx      a11
123 1:      call8   .Lerr                   /* returns to original caller */
124
125
126         /* a15: return address */
127 .L12:   mov     a12, a2
128         mov     a13, a3
129         mov     a14, a6
130
131         SAVE_PID
132
133         movi    a2, SYS_ify (clone)
134         movi    a3, 0
135         movi    a6, CLONE_VM | CLONE_VFORK | SIGCHLD
136         syscall
137
138         RESTORE_PID
139
140         mov     a3, a13
141         movi    a13, -4096
142
143         mov     a6, a14
144         mov     a14, a2
145
146         mov     a2, a12
147
148         bgeu    a14, a13, 1f
149         jx      a15
150 1:      call12  .Lerr                   /* returns to original caller */
151
152
153         .align 4
154 .Lerr:  entry   a1, 16
155
156         /* Restore the return address.  */
157         extui   a4, a0, 30, 2           /* get the call-size bits */
158         slli    a4, a4, 30
159         slli    a3, a3, 2               /* clear high bits of target address */
160         srli    a3, a3, 2
161         or      a0, a3, a4              /* combine them */
162
163         PSEUDO_END (__vfork)
164 .Lpseudo_end:
165         retw
166
167 weak_alias (__vfork, vfork)
168 libc_hidden_def(vfork)