OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [tools/] [riscv-gnu-toolchain-master/] [glibc/] [sysdeps/] [unix/] [sysv/] [linux/] [riscv/] [clone.S] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
/* Copyright (C) 1996, 1997, 2000, 2003, 2005 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
3
   Contributed by Ralf Baechle , 1996.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
10
   The GNU C Library is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
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 
24
#include 
25
#define _ERRNO_H        1
26
#include 
27
#ifdef RESET_PID
28
#include 
29
#include "tcb-offsets.h"
30
#endif
31
 
32
#define CLONE_VM      0x00000100
33
#define CLONE_THREAD  0x00010000
34
 
35
/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
36
             void *parent_tidptr, void *tls, void *child_tidptr) */
37
 
38
        .text
39
LEAF(__clone)
40
 
41
        /* Sanity check arguments.  */
42
        beqz            a0,L(invalid)   /* No NULL function pointers.  */
43
        beqz            a1,L(invalid)   /* No NULL stack pointers.  */
44
 
45
        addi            a1,a1,-32       /* Reserve argument save space.  */
46
        REG_S           a0,0(a1)        /* Save function pointer.  */
47
        REG_S           a3,SZREG(a1)    /* Save argument pointer.  */
48
#ifdef RESET_PID
49
        REG_S           a2,(SZREG*2)(a1)        /* Save clone flags.  */
50
#endif
51
 
52
        /* The syscall expects the args to be in different slots.  */
53
        move            a0,a2
54
        move            a2,a4
55
        move            a3,a5
56
        move            a4,a6
57
 
58
        /* Do the system call */
59
        li              a7,__NR_clone
60
        scall
61
 
62
        bltz            a0,L(error)
63
        beqz            a0,L(thread_start)
64
 
65
        /* Successful return from the parent */
66
        ret
67
 
68
L(invalid):
69
        li              a0, 0
70
        /* Something bad happened -- no child created */
71
L(error):
72
        j               __syscall_error
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
ENTRY(__thread_start)
80
L(thread_start):
81
        /* The stackframe has been created on entry of clone().  */
82
 
83
#ifdef RESET_PID
84
        /* Check and see if we need to reset the PID.  */
85
        REG_L           a0,(SZREG*2)(sp)
86
        li              a1,CLONE_THREAD
87
        and             a1,a0,a1
88
        beqz            a1,L(restore_pid)
89
L(donepid):
90
#endif
91
 
92
        /* Restore the arg for user's function.  */
93
        REG_L           a1,0(sp)        /* Function pointer.  */
94
        REG_L           a0,SZREG(sp)    /* Argument pointer.  */
95
 
96
        /* Call the user's function.  */
97
        jalr            a1
98
 
99
        /* Call _exit with the function's return value.  */
100
        j               _exit
101
 
102
#ifdef RESET_PID
103
L(restore_pid):
104
        and             a1,a0,CLONE_VM
105
        li              a2,-1
106
        bnez            a1,L(gotpid)
107
        li              a2,__NR_getpid
108
        scall
109
L(gotpid):
110
        sw              a2,PID_OFFSET(tp)
111
        sw              a2,TID_OFFSET(tp)
112
        j               L(donepid)
113
#endif
114
 
115
        END(__thread_start)
116
 
117
weak_alias (__clone, clone)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.