]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libpthread / linuxthreads / sysdeps / unix / sysv / linux / mips / sysdep-cancel.h
1 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Guido Guenther <agx@sigxcpu.org>, 2003.
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, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #include <sysdep.h>
20 #ifndef __ASSEMBLER__
21 # include <linuxthreads/internals.h>
22 #endif
23
24 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
25
26 #ifdef __PIC__
27 # undef PSEUDO
28 # define PSEUDO(name, syscall_name, args)                                     \
29   .align 2;                                                                   \
30   99: move a0, v0;                                                            \
31   la t9,__syscall_error;                                                      \
32   jr t9;                                                                      \
33   ENTRY (name)                                                                \
34     .set noreorder;                                                           \
35     .cpload t9;                                                               \
36     .set reorder;                                                             \
37     SINGLE_THREAD_P(t0);                                                      \
38     bne zero, t0, L(pseudo_cancel);                                           \
39     .set noreorder;                                                           \
40     li v0, SYS_ify(syscall_name);                                             \
41     syscall;                                                                  \
42     .set reorder;                                                             \
43     bne a3, zero, SYSCALL_ERROR_LABEL;                                        \
44     ret;                                                                      \
45   L(pseudo_cancel):                                                           \
46     SAVESTK_##args;                                                           \
47     sw ra, 28(sp);                                                            \
48     sw gp, 32(sp);                                                            \
49     PUSHARGS_##args;                    /* save syscall args */               \
50     CENABLE;                                                                  \
51     lw gp, 32(sp);                                                            \
52     sw v0, 44(sp);                      /* save mask */                       \
53     POPARGS_##args;                     /* restore syscall args */            \
54     .set noreorder;                                                           \
55     li v0, SYS_ify (syscall_name);                                            \
56     syscall;                                                                  \
57     .set reorder;                                                             \
58     sw v0, 36(sp);                      /* save syscall result */             \
59     sw a3, 40(sp);                      /* save syscall error flag */         \
60     lw a0, 44(sp);                      /* pass mask as arg1 */               \
61     CDISABLE;                                                                 \
62     lw gp, 32(sp);                                                            \
63     lw v0, 36(sp);                      /* restore syscall result */          \
64     lw a3, 40(sp);                      /* restore syscall error flag */      \
65     lw ra, 28(sp);                      /* restore return address */          \
66     RESTORESTK;                                                               \
67     bne a3, zero, SYSCALL_ERROR_LABEL;                                        \
68   L(pseudo_end):
69 #endif
70
71 # define PUSHARGS_0     /* nothing to do */
72 # define PUSHARGS_1     PUSHARGS_0 sw a0, 0(sp);
73 # define PUSHARGS_2     PUSHARGS_1 sw a1, 4(sp);
74 # define PUSHARGS_3     PUSHARGS_2 sw a2, 8(sp);
75 # define PUSHARGS_4     PUSHARGS_3 sw a3, 12(sp);
76 # define PUSHARGS_5     PUSHARGS_4 /* handeld by SAVESTK_## */
77 # define PUSHARGS_6     PUSHARGS_5
78 # define PUSHARGS_7     PUSHARGS_6
79
80 # define POPARGS_0      /* nothing to do */
81 # define POPARGS_1      POPARGS_0 lw a0, 0(sp);
82 # define POPARGS_2      POPARGS_1 lw a1, 4(sp);
83 # define POPARGS_3      POPARGS_2 lw a2, 8(sp);
84 # define POPARGS_4      POPARGS_3 lw a3, 12(sp);
85 # define POPARGS_5      POPARGS_4 /* args already in new stackframe */
86 # define POPARGS_6      POPARGS_5
87 # define POPARGS_7      POPARGS_6
88
89
90 # define STKSPACE       48
91 # define SAVESTK_0      subu sp, STKSPACE
92 # define SAVESTK_1      SAVESTK_0
93 # define SAVESTK_2      SAVESTK_1
94 # define SAVESTK_3      SAVESTK_2
95 # define SAVESTK_4      SAVESTK_3
96 # define SAVESTK_5      lw t0, 16(sp);          \
97                         subu sp, STKSPACE;      \
98                         sw t0, 16(sp)
99
100 # define SAVESTK_6      lw t0, 16(sp);          \
101                         lw t1, 20(sp);          \
102                         subu sp, STKSPACE;      \
103                         sw t0, 16(sp);          \
104                         sw t1, 20(sp)
105
106 # define SAVESTK_7      lw t0, 16(sp);          \
107                         lw t1, 20(sp);          \
108                         lw t2, 24(sp);          \
109                         subu sp, STKSPACE;      \
110                         sw t0, 16(sp);          \
111                         sw t1, 20(sp);          \
112                         sw t2, 24(sp)
113
114 # define RESTORESTK     addu sp, STKSPACE
115
116
117 # ifdef IS_IN_libpthread
118 #  define CENABLE       la t9, __pthread_enable_asynccancel; jalr t9;
119 #  define CDISABLE      la t9, __pthread_disable_asynccancel; jalr t9;
120 #  define __local_multiple_threads __pthread_multiple_threads
121 # elif defined IS_IN_librt
122 #  define CENABLE       la t9, __librt_enable_asynccancel; jalr t9;
123 #  define CDISABLE      la t9, __librt_disable_asynccancel; jalr t9;
124 #  define __local_multiple_threads __librt_multiple_threads
125 # else
126 #  define CENABLE       la t9, __libc_enable_asynccancel; jalr t9;
127 #  define CDISABLE      la t9, __libc_disable_asynccancel; jalr t9;
128 #  define __local_multiple_threads __libc_multiple_threads
129 # endif
130
131 # ifndef __ASSEMBLER__
132 extern int __local_multiple_threads attribute_hidden;
133 #  define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
134 # else
135 #  define SINGLE_THREAD_P(reg) lw reg, __local_multiple_threads
136 #endif
137
138 #elif !defined __ASSEMBLER__
139
140 /* This code should never be used but we define it anyhow.  */
141 # define SINGLE_THREAD_P (1)
142
143 #endif