1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #include <sysdeps/generic/sysdep.h>
22 # include <nptl/pthreadP.h>
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
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);
33 # define PSEUDO_CPLOAD
34 # define PSEUDO_ERRJMP j __syscall_error;
35 # define PSEUDO_SAVEGP
36 # define PSEUDO_LOADGP
40 # define PSEUDO(name, syscall_name, args) \
46 .type __##syscall_name##_nocancel, @function; \
47 .globl __##syscall_name##_nocancel; \
48 __##syscall_name##_nocancel: \
51 li v0, SYS_ify(syscall_name); \
57 .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
62 SINGLE_THREAD_P(v1); \
63 bne zero, v1, L(pseudo_cancel); \
65 li v0, SYS_ify(syscall_name); \
73 cfi_rel_offset (ra, 28); \
75 PUSHARGS_##args; /* save syscall args */ \
78 sw v0, 44(sp); /* save mask */ \
79 POPARGS_##args; /* restore syscall args */ \
81 li v0, SYS_ify (syscall_name); \
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 */ \
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 */ \
99 # define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
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
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
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); \
130 # define SAVESTK_6 lw t0, 16(sp); \
136 # define SAVESTK_7 lw t0, 16(sp); \
144 # define RESTORESTK addu sp, STKSPACE; cfi_adjust_cfa_offset(-STKSPACE)
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;
154 # define PSEUDO_JMP(sym) jal sym;
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)
164 # define CENABLE PSEUDO_JMP (__libc_enable_asynccancel)
165 # define CDISABLE PSEUDO_JMP (__libc_disable_asynccancel)
168 # ifndef __ASSEMBLER__
169 # define SINGLE_THREAD_P \
170 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
171 header.multiple_threads) \
174 # define SINGLE_THREAD_P(reg) \
175 READ_THREAD_POINTER(reg); \
176 lw reg, MULTIPLE_THREADS_OFFSET(reg)
179 #elif !defined __ASSEMBLER__
181 # define SINGLE_THREAD_P 1
182 # define NO_CANCELLATION 1
186 #ifndef __ASSEMBLER__
187 # define RTLD_SINGLE_THREAD_P \
188 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
189 header.multiple_threads) == 0, 1)