1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 Contributed by Richard Henderson (rth@tamu.edu)
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.
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.
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. */
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. */
25 /* int clone(int (*fn)(), void *child_stack, int flags, int nargs, ...) */
31 /* Save rest of argument registers for varargs-type work. */
36 /* Sanity check arguments. */
39 beq a0,$error /* no NULL function pointers */
40 beq a1,$error /* no NULL stack pointers */
41 blt a3,$error /* no negative argument counts */
43 /* Allocate space on the new stack and copy args over */
44 mov a3,t0 /* save nargs for thread_start */
53 /* Do the system call */
54 mov a0,pv /* get fn ptr out of the way */
62 /* Successful return from the parent */
66 /* Something bad happened -- no child created */
71 jmp zero,__syscall_error
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
79 At this point we have $t0=nargs, $pv=fn, $sp=&arg[0]. */
87 /* Calculate address of jump into argument loading code */
88 cmple t0,6,t2 /* no more than 6 args in registers */
90 br v0,1f /* find address of arg0 */
91 1: lda v0,$arg0-1b(v0)
96 /* Load the integer register arguments */
105 /* Adjust stack to remove the arguments we just loaded */
108 /* Call the user's function */
112 /* Call _exit rather than doing it inline for breakpoint purposes */
118 weak_alias(__clone, clone)