OSDN Git Service

sparc: update ptrace.h to latest from glibc
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / sparc / clone.S
1 /* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2004, 2007
2    Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Richard Henderson (rth@tamu.edu).
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 /* clone() is even more special than fork() as it mucks with stacks
21    and invokes a function in the right context after its all over.  */
22
23 #include <asm/errno.h>
24 #include <asm/unistd.h>
25 #include <tcb-offsets.h>
26 #include <sysdep.h>
27
28 #define CLONE_VM        0x00000100
29 #define CLONE_THREAD    0x00010000
30
31 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
32              pid_t *ptid, void *tls, pid_t *ctid); */
33
34         .text
35 ENTRY (__clone)
36         save    %sp,-96,%sp
37         cfi_def_cfa_register(%fp)
38         cfi_window_save
39         cfi_register(%o7, %i7)
40
41         /* sanity check arguments */
42         orcc    %i0,%g0,%g2
43         be      .Leinval
44          orcc   %i1,%g0,%o1
45         be      .Leinval
46          mov    %i2,%o0
47
48         /* The child_stack is the top of the stack, allocate one
49            whole stack frame from that as this is what the kernel
50            expects.  */
51         sub     %o1, 96, %o1
52         mov     %i3, %g3
53         mov     %i2, %g4
54
55         /* ptid */
56         mov     %i4,%o2
57         /* tls */
58         mov     %i5,%o3
59         /* ctid */
60         ld      [%fp+92],%o4
61
62         /* Do the system call */
63         set     __NR_clone,%g1
64         ta      0x10
65         bcs     .Lerror
66          tst    %o1
67         bne     __thread_start
68          nop
69         jmpl    %i7 + 8, %g0
70          restore %o0,%g0,%o0
71
72 .Leinval:
73         mov     EINVAL, %o0
74 .Lerror:
75         call    __errno_location
76          mov    %o0, %i0
77         st      %i0,[%o0]
78         jmpl    %i7 + 8, %g0
79          restore %g0,-1,%o0
80 END(__clone)
81
82         .type   __thread_start,@function
83 __thread_start:
84 #ifdef RESET_PID
85         sethi   %hi(CLONE_THREAD), %l0
86         andcc   %g4, %l0, %g0
87         bne     1f
88          andcc  %g4, CLONE_VM, %g0
89         bne,a   2f
90          mov    -1,%o0
91         set     __NR_getpid,%g1
92         ta      0x10
93 2:
94         st      %o0,[%g7 + PID]
95         st      %o0,[%g7 + TID]
96 1:
97 #endif
98         mov     %g0, %fp        /* terminate backtrace */
99         call    %g2
100          mov    %g3,%o0
101         call    exit,0
102          nop
103
104         .size   __thread_start, .-__thread_start
105
106 weak_alias (__clone, clone)