blob: 2a9a2b08481bade0aba7997ae2b85f80280a534e [file] [log] [blame]
Chris Dearman645d0312014-02-05 18:51:43 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <machine/asm.h>
30#include <asm/unistd.h>
31#include <linux/errno.h>
32#include <linux/sched.h>
33
34#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
35FRAMESZ = MKFSIZ(NARGSAVE,0)
36FRAME_ARG = 0*REGSZ
37FRAME_FN = 1*REGSZ
38#else
39FRAMESZ = MKFSIZ(0,3)
40FRAME_GP = FRAMESZ-1*REGSZ
41FRAME_ARG = FRAMESZ-2*REGSZ
42FRAME_FN = FRAMESZ-3*REGSZ
43#endif
44
45// pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
46 .text
47LEAF(__bionic_clone,FRAMESZ)
48 PTR_SUBU sp, FRAMESZ # allocate stack frame
49 SETUP_GP64(FRAME_GP,__bionic_clone)
50 SAVE_GP(FRAME_GP)
51
52 # set up child stack
53 PTR_SUBU a1,FRAMESZ
54#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
55 PTR_L t0,FRAMESZ+5*REGSZ(sp) # fn
56 PRL_L t1,FRAMESZ+6*REGSZ(sp) # arg
57 PTR_S t0,FRAME_FN(a1) # fn
58 PTR_S t1,FRAME_ARG(a1) # arg
59#else
60 PTR_L t0,FRAME_GP(sp) # copy gp to child stack
61 PTR_S t0,FRAME_GP(a1)
62 PTR_S a5,FRAME_FN(a1) # fn
63 PTR_S a6,FRAME_ARG(a1) # arg
64# endif
65
66 # remainder of arguments are correct for clone system call
67 LI v0,__NR_clone
68 syscall
69
70 move a0,v0
71 bnez a3,.L__error_bc
72
73 beqz v0,.L__thread_start_bc
74
75 RESTORE_GP64
76 PTR_ADDU sp,FRAMESZ
77 j ra
78
79.L__thread_start_bc:
80 # void __bionic_clone_entry(int (*func)(void*), void *arg)
81 PTR_L a0,FRAME_FN(sp) # fn
82 PTR_L a1,FRAME_ARG(sp) # arg
83 LA t9,__bionic_clone_entry
84 RESTORE_GP64
85 /*
86 * For O32 etc the child stack must have space for a0..a3 to be stored
87 * For N64 etc, the child stack can be restored to the original value
88 */
89#if !((_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32))
90 PTR_ADDU sp,FRAMESZ
91#endif
92 j t9
93
94.L__error_bc:
95 LA t9,__set_errno
96 RESTORE_GP64
97 PTR_ADDU sp,FRAMESZ
98 j t9
99 END(__bionic_clone)