OSDN Git Service

9311504d22cf5a1c693f74aa43d57cf576977106
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / mips / vfork.S
1 /* Copyright (C) 2005 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 /* vfork() is just a special case of clone().  */
19
20 #include <sys/syscall.h>
21 #include <sys/asm.h>
22 #include <sysdep.h>
23
24 #ifndef SAVE_PID
25 #define SAVE_PID
26 #endif
27
28 #ifndef RESTORE_PID
29 #define RESTORE_PID
30 #endif
31
32 #ifdef __NR_fork
33
34 /* int vfork() */
35
36         .text
37         .hidden __vfork
38 LOCALSZ= 1
39 FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
40 GPOFF= FRAMESZ-(1*SZREG)
41 NESTED(__vfork,FRAMESZ,sp)
42 #ifdef __PIC__
43         SETUP_GP
44 #endif
45         PTR_SUBU sp, FRAMESZ
46         SETUP_GP64 (a5, __vfork)
47 #ifdef __PIC__
48         SAVE_GP (GPOFF)
49 #endif
50 #ifdef PROF
51 # if (_MIPS_SIM != _ABIO32)
52         PTR_S           a5, GPOFF(sp)
53 # endif
54         .set            noat
55         move            $1, ra
56 # if (_MIPS_SIM == _ABIO32)
57         subu            sp,sp,8
58 # endif
59         jal             _mcount
60         .set            at
61 # if (_MIPS_SIM != _ABIO32)
62         PTR_L           a5, GPOFF(sp)
63 # endif
64 #endif
65
66         PTR_ADDU        sp, FRAMESZ
67
68         SAVE_PID
69
70         li              a0, 0x4112      /* CLONE_VM | CLONE_VFORK | SIGCHLD */
71         move            a1, sp
72
73         /* Do the system call */
74         li              v0,__NR_clone
75         syscall
76
77         RESTORE_PID
78
79         bnez            a3,L(error)
80
81         /* Successful return from the parent or child.  */
82         RESTORE_GP64
83         j               ra
84         nop
85
86         /* Something bad happened -- no child created.  */
87 L(error):
88         move    a0, v0
89 #ifdef __PIC__
90         PTR_LA          t9, __syscall_error
91         RESTORE_GP64
92         jr              t9
93 #else
94         RESTORE_GP64
95         j               __syscall_error
96 #endif
97         END(__vfork)
98
99 weak_alias(__vfork,vfork)
100 libc_hidden_def(vfork)
101
102 #endif