MIPS: Consolidate nptl/ subdirectories under linux/...
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / mips / sysdep-cancel.h
1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the 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    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library.  If not, see
16    <http://www.gnu.org/licenses/>.  */
17
18 #include <sysdep.h>
19 #include <sysdeps/generic/sysdep.h>
20 #include <tls.h>
21 #ifndef __ASSEMBLER__
22 # include <nptl/pthreadP.h>
23 #endif
24
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
26
27 # ifdef __PIC__
28 #  define PSEUDO_CPLOAD .cpload t9;
29 #  define PSEUDO_ERRJMP la t9, __syscall_error; jr t9;
30 #  define PSEUDO_SAVEGP sw gp, 32(sp); cfi_rel_offset (gp, 32);
31 #  define PSEUDO_LOADGP lw gp, 32(sp);
32 # else
33 #  define PSEUDO_CPLOAD
34 #  define PSEUDO_ERRJMP j __syscall_error;
35 #  define PSEUDO_SAVEGP
36 #  define PSEUDO_LOADGP
37 # endif
38
39 # undef PSEUDO
40 # define PSEUDO(name, syscall_name, args)                                     \
41       .align 2;                                                               \
42       .set nomips16;                                                          \
43   L(pseudo_start):                                                            \
44       cfi_startproc;                                                          \
45   99: PSEUDO_ERRJMP                                                           \
46   .type __##syscall_name##_nocancel, @function;                               \
47   .globl __##syscall_name##_nocancel;                                         \
48   __##syscall_name##_nocancel:                                                \
49     .set noreorder;                                                           \
50     PSEUDO_CPLOAD                                                             \
51     li v0, SYS_ify(syscall_name);                                             \
52     syscall;                                                                  \
53     .set reorder;                                                             \
54     bne a3, zero, 99b;                                                        \
55     ret;                                                                      \
56     cfi_endproc;                                                              \
57   .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;            \
58   ENTRY (name)                                                                \
59     .set noreorder;                                                           \
60     PSEUDO_CPLOAD                                                             \
61     .set reorder;                                                             \
62     SINGLE_THREAD_P(v1);                                                      \
63     bne zero, v1, L(pseudo_cancel);                                           \
64     .set noreorder;                                                           \
65     li v0, SYS_ify(syscall_name);                                             \
66     syscall;                                                                  \
67     .set reorder;                                                             \
68     bne a3, zero, 99b;                                                        \
69     ret;                                                                      \
70   L(pseudo_cancel):                                                           \
71     SAVESTK_##args;                                                           \
72     sw ra, 28(sp);                                                            \
73     cfi_rel_offset (ra, 28);                                                  \
74     PSEUDO_SAVEGP                                                             \
75     PUSHARGS_##args;                    /* save syscall args */               \
76     CENABLE;                                                                  \
77     PSEUDO_LOADGP                                                             \
78     sw v0, 44(sp);                      /* save mask */                       \
79     POPARGS_##args;                     /* restore syscall args */            \
80     .set noreorder;                                                           \
81     li v0, SYS_ify (syscall_name);                                            \
82     syscall;                                                                  \
83     .set reorder;                                                             \
84     sw v0, 36(sp);                      /* save syscall result */             \
85     sw a3, 40(sp);                      /* save syscall error flag */         \
86     lw a0, 44(sp);                      /* pass mask as arg1 */               \
87     CDISABLE;                                                                 \
88     PSEUDO_LOADGP                                                             \
89     lw v0, 36(sp);                      /* restore syscall result */          \
90     lw a3, 40(sp);                      /* restore syscall error flag */      \
91     lw ra, 28(sp);                      /* restore return address */          \
92     .set noreorder;                                                           \
93     bne a3, zero, 99b;                                                        \
94      RESTORESTK;                                                              \
95   L(pseudo_end):                                                              \
96     .set reorder;
97
98 # undef PSEUDO_END
99 # define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
100
101 # define PUSHARGS_0     /* nothing to do */
102 # define PUSHARGS_1     PUSHARGS_0 sw a0, 0(sp); cfi_rel_offset (a0, 0);
103 # define PUSHARGS_2     PUSHARGS_1 sw a1, 4(sp); cfi_rel_offset (a1, 4);
104 # define PUSHARGS_3     PUSHARGS_2 sw a2, 8(sp); cfi_rel_offset (a2, 8);
105 # define PUSHARGS_4     PUSHARGS_3 sw a3, 12(sp); cfi_rel_offset (a3, 12);
106 # define PUSHARGS_5     PUSHARGS_4 /* handled by SAVESTK_## */
107 # define PUSHARGS_6     PUSHARGS_5
108 # define PUSHARGS_7     PUSHARGS_6
109
110 # define POPARGS_0      /* nothing to do */
111 # define POPARGS_1      POPARGS_0 lw a0, 0(sp);
112 # define POPARGS_2      POPARGS_1 lw a1, 4(sp);
113 # define POPARGS_3      POPARGS_2 lw a2, 8(sp);
114 # define POPARGS_4      POPARGS_3 lw a3, 12(sp);
115 # define POPARGS_5      POPARGS_4 /* args already in new stackframe */
116 # define POPARGS_6      POPARGS_5
117 # define POPARGS_7      POPARGS_6
118
119
120 # define STKSPACE       48
121 # define SAVESTK_0      subu sp, STKSPACE; cfi_adjust_cfa_offset(STKSPACE)
122 # define SAVESTK_1      SAVESTK_0
123 # define SAVESTK_2      SAVESTK_1
124 # define SAVESTK_3      SAVESTK_2
125 # define SAVESTK_4      SAVESTK_3
126 # define SAVESTK_5      lw t0, 16(sp);          \
127                         SAVESTK_0;              \
128                         sw t0, 16(sp)
129
130 # define SAVESTK_6      lw t0, 16(sp);          \
131                         lw t1, 20(sp);          \
132                         SAVESTK_0;              \
133                         sw t0, 16(sp);          \
134                         sw t1, 20(sp)
135
136 # define SAVESTK_7      lw t0, 16(sp);          \
137                         lw t1, 20(sp);          \
138                         lw t2, 24(sp);          \
139                         SAVESTK_0;              \
140                         sw t0, 16(sp);          \
141                         sw t1, 20(sp);          \
142                         sw t2, 24(sp)
143
144 # define RESTORESTK     addu sp, STKSPACE; cfi_adjust_cfa_offset(-STKSPACE)
145
146
147 # ifdef __PIC__
148 /* We use jalr rather than jal.  This means that the assembler will not
149    automatically restore $gp (in case libc has multiple GOTs) so we must
150    do it manually - which we have to do anyway since we don't use .cprestore.
151    It also shuts up the assembler warning about not using .cprestore.  */
152 #  define PSEUDO_JMP(sym) la t9, sym; jalr t9;
153 # else
154 #  define PSEUDO_JMP(sym) jal sym;
155 # endif
156
157 # ifdef IS_IN_libpthread
158 #  define CENABLE       PSEUDO_JMP (__pthread_enable_asynccancel)
159 #  define CDISABLE      PSEUDO_JMP (__pthread_disable_asynccancel)
160 # elif defined IS_IN_librt
161 #  define CENABLE       PSEUDO_JMP (__librt_enable_asynccancel)
162 #  define CDISABLE      PSEUDO_JMP (__librt_disable_asynccancel)
163 # else
164 #  define CENABLE       PSEUDO_JMP (__libc_enable_asynccancel)
165 #  define CDISABLE      PSEUDO_JMP (__libc_disable_asynccancel)
166 # endif
167
168 # ifndef __ASSEMBLER__
169 #  define SINGLE_THREAD_P                                               \
170         __builtin_expect (THREAD_GETMEM (THREAD_SELF,                   \
171                                          header.multiple_threads)       \
172                           == 0, 1)
173 # else
174 #  define SINGLE_THREAD_P(reg)                                          \
175         READ_THREAD_POINTER(reg);                                       \
176         lw reg, MULTIPLE_THREADS_OFFSET(reg)
177 #endif
178
179 #elif !defined __ASSEMBLER__
180
181 # define SINGLE_THREAD_P 1
182 # define NO_CANCELLATION 1
183
184 #endif
185
186 #ifndef __ASSEMBLER__
187 # define RTLD_SINGLE_THREAD_P \
188   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
189                                    header.multiple_threads) == 0, 1)
190 #endif