1 /* Copyright (C) 2003, 2004, 2005 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) \
45 .type __##syscall_name##_nocancel, @function; \
46 .globl __##syscall_name##_nocancel; \
47 __##syscall_name##_nocancel: \
50 li v0, SYS_ify(syscall_name); \
55 .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
60 SINGLE_THREAD_P(v1); \
61 bne zero, v1, L(pseudo_cancel); \
63 li v0, SYS_ify(syscall_name); \
71 cfi_rel_offset (ra, 28); \
73 PUSHARGS_##args; /* save syscall args */ \
76 sw v0, 44(sp); /* save mask */ \
77 POPARGS_##args; /* restore syscall args */ \
79 li v0, SYS_ify (syscall_name); \
82 sw v0, 36(sp); /* save syscall result */ \
83 sw a3, 40(sp); /* save syscall error flag */ \
84 lw a0, 44(sp); /* pass mask as arg1 */ \
87 lw v0, 36(sp); /* restore syscall result */ \
88 lw a3, 40(sp); /* restore syscall error flag */ \
89 lw ra, 28(sp); /* restore return address */ \
97 # define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
99 # define PUSHARGS_0 /* nothing to do */
100 # define PUSHARGS_1 PUSHARGS_0 sw a0, 0(sp); cfi_rel_offset (a0, 0);
101 # define PUSHARGS_2 PUSHARGS_1 sw a1, 4(sp); cfi_rel_offset (a1, 4);
102 # define PUSHARGS_3 PUSHARGS_2 sw a2, 8(sp); cfi_rel_offset (a2, 8);
103 # define PUSHARGS_4 PUSHARGS_3 sw a3, 12(sp); cfi_rel_offset (a3, 12);
104 # define PUSHARGS_5 PUSHARGS_4 /* handled by SAVESTK_## */
105 # define PUSHARGS_6 PUSHARGS_5
106 # define PUSHARGS_7 PUSHARGS_6
108 # define POPARGS_0 /* nothing to do */
109 # define POPARGS_1 POPARGS_0 lw a0, 0(sp);
110 # define POPARGS_2 POPARGS_1 lw a1, 4(sp);
111 # define POPARGS_3 POPARGS_2 lw a2, 8(sp);
112 # define POPARGS_4 POPARGS_3 lw a3, 12(sp);
113 # define POPARGS_5 POPARGS_4 /* args already in new stackframe */
114 # define POPARGS_6 POPARGS_5
115 # define POPARGS_7 POPARGS_6
119 # define SAVESTK_0 subu sp, STKSPACE; cfi_adjust_cfa_offset(STKSPACE)
120 # define SAVESTK_1 SAVESTK_0
121 # define SAVESTK_2 SAVESTK_1
122 # define SAVESTK_3 SAVESTK_2
123 # define SAVESTK_4 SAVESTK_3
124 # define SAVESTK_5 lw t0, 16(sp); \
128 # define SAVESTK_6 lw t0, 16(sp); \
134 # define SAVESTK_7 lw t0, 16(sp); \
142 # define RESTORESTK addu sp, STKSPACE; cfi_adjust_cfa_offset(-STKSPACE)
146 /* We use jalr rather than jal. This means that the assembler will not
147 automatically restore $gp (in case libc has multiple GOTs) so we must
148 do it manually - which we have to do anyway since we don't use .cprestore.
149 It also shuts up the assembler warning about not using .cprestore. */
150 # define PSEUDO_JMP(sym) la t9, sym; jalr t9;
152 # define PSEUDO_JMP(sym) jal sym;
155 # ifdef IS_IN_libpthread
156 # define CENABLE PSEUDO_JMP (__pthread_enable_asynccancel)
157 # define CDISABLE PSEUDO_JMP (__pthread_disable_asynccancel)
158 # elif defined IS_IN_librt
159 # define CENABLE PSEUDO_JMP (__librt_enable_asynccancel)
160 # define CDISABLE PSEUDO_JMP (__librt_disable_asynccancel)
162 # define CENABLE PSEUDO_JMP (__libc_enable_asynccancel)
163 # define CDISABLE PSEUDO_JMP (__libc_disable_asynccancel)
166 # ifndef __ASSEMBLER__
167 # define SINGLE_THREAD_P \
168 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
169 header.multiple_threads) \
172 # define SINGLE_THREAD_P(reg) \
173 READ_THREAD_POINTER(reg); \
174 lw reg, MULTIPLE_THREADS_OFFSET(reg)
177 #elif !defined __ASSEMBLER__
179 # define SINGLE_THREAD_P 1
180 # define NO_CANCELLATION 1
184 #ifndef __ASSEMBLER__
185 # define RTLD_SINGLE_THREAD_P \
186 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
187 header.multiple_threads) == 0, 1)