]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/alpha/clone.S
a1ef3249563b9d7477638313236a51fe092a7663
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / alpha / clone.S
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 Contributed by Richard Henderson (rth@tamu.edu)
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
18
19 /* clone() is even more special than fork() as it mucks with stacks
20 and invokes a function in the right context after its all over. */
21
22 #include <sysdep.h>
23 #include <errnos.h>
24
25 /* int clone(int (*fn)(), void *child_stack, int flags, int nargs, ...) */
26
27 .text
28 ENTRY(__clone)
29 lda sp,-16(sp)
30 .frame sp,16,$26,0
31 /* Save rest of argument registers for varargs-type work. */
32 stq a4,0(sp)
33 stq a5,8(sp)
34 .prologue 1
35
36 /* Sanity check arguments. */
37 sextl a3,a3
38 ldiq v0,EINVAL
39 beq a0,$error /* no NULL function pointers */
40 beq a1,$error /* no NULL stack pointers */
41 blt a3,$error /* no negative argument counts */
42
43 /* Allocate space on the new stack and copy args over */
44 mov a3,t0 /* save nargs for thread_start */
45 s8addq a3,sp,t1
46 1: ldq t2,-8(t1)
47 subq t1,8,t1
48 stq t2,-8(a1)
49 subq a3,1,a3
50 subq a1,8,a1
51 bne a3,1b
52
53 /* Do the system call */
54 mov a0,pv /* get fn ptr out of the way */
55 mov a2,a0
56 ldiq v0,__NR_clone
57 call_pal PAL_callsys
58
59 bne a3,$error
60 beq v0,thread_start
61
62 /* Successful return from the parent */
63 lda sp,16(sp)
64 ret
65
66 /* Something bad happened -- no child created */
67 $error:
68 br gp,1f
69 1: ldgp gp,0(gp)
70 lda sp,16(sp)
71 jmp zero,__syscall_error
72
73 END(__clone)
74
75 /* Load up the arguments to the function. Put this block of code in
76 its own function so that we can terminate the stack trace with our
77 debug info.
78
79 At this point we have $t0=nargs, $pv=fn, $sp=&arg[0]. */
80
81 .ent thread_start
82 thread_start:
83 .frame fp,0,zero,0
84 mov zero,fp
85 .prologue 0
86
87 /* Calculate address of jump into argument loading code */
88 cmple t0,6,t2 /* no more than 6 args in registers */
89 cmoveq t2,6,t0
90 br v0,1f /* find address of arg0 */
91 1: lda v0,$arg0-1b(v0)
92 s4addq t0,zero,t1
93 subq v0,t1,v0
94 jmp (v0)
95
96 /* Load the integer register arguments */
97 ldq a5,40(sp)
98 ldq a4,32(sp)
99 ldq a3,24(sp)
100 ldq a2,16(sp)
101 ldq a1,8(sp)
102 ldq a0,0(sp)
103 $arg0:
104
105 /* Adjust stack to remove the arguments we just loaded */
106 s8addq t0,sp,sp
107
108 /* Call the user's function */
109 jsr ra,(pv)
110 ldgp gp,0(ra)
111
112 /* Call _exit rather than doing it inline for breakpoint purposes */
113 mov v0,a0
114 jsr ra,_exit
115
116 .end thread_start
117
118 weak_alias(__clone, clone)