Move all files into ports/ subdirectory in preparation for merge with glibc
[jlayton/glibc.git] / ports / sysdeps / unix / sysv / linux / mips / mips64 / nptl / sysdep-cancel.h
1 /* Copyright (C) 2003, 2004, 2005, 2006 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 #include <sys/asm.h>
25
26 /* Gas will put the initial save of $gp into the CIE, because it appears to
27    happen before any instructions.  So we use cfi_same_value instead of
28    cfi_restore.  */
29
30 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
31
32 #ifdef __PIC__
33 # undef PSEUDO
34 # define PSEUDO(name, syscall_name, args)                                     \
35       .align 2;                                                               \
36   L(pseudo_start):                                                            \
37       cfi_startproc;                                                          \
38       cfi_adjust_cfa_offset (STKSPACE);                                       \
39       cfi_rel_offset (gp, STKOFF_GP);                                         \
40   99: PTR_LA t9,__syscall_error;                                              \
41       /* manual cpreturn */                                                   \
42       REG_L gp, STKOFF_GP(sp);                                                \
43       cfi_same_value (gp);                                                    \
44       RESTORESTK;                                                             \
45       jr t9;                                                                  \
46   .type __##syscall_name##_nocancel, @function;                               \
47   .globl __##syscall_name##_nocancel;                                         \
48   __##syscall_name##_nocancel:                                                \
49     SAVESTK;                                                                  \
50     .cpsetup t9, STKOFF_GP, name;                                             \
51     cfi_rel_offset (gp, STKOFF_GP);                                           \
52     li v0, SYS_ify(syscall_name);                                             \
53     syscall;                                                                  \
54     bne a3, zero, SYSCALL_ERROR_LABEL;                                        \
55     /* manual cpreturn */                                                     \
56     REG_L gp, STKOFF_GP(sp);                                                  \
57     cfi_same_value (gp);                                                      \
58     RESTORESTK;                                                               \
59     ret;                                                                      \
60   .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;            \
61   ENTRY (name)                                                                \
62     SAVESTK;                                                                  \
63     .cpsetup t9, STKOFF_GP, name;                                             \
64     cfi_rel_offset (gp, STKOFF_GP);                                           \
65     SINGLE_THREAD_P(v1);                                                      \
66     bne zero, v1, L(pseudo_cancel);                                           \
67     .set noreorder;                                                           \
68     li v0, SYS_ify(syscall_name);                                             \
69     syscall;                                                                  \
70     .set reorder;                                                             \
71     bne a3, zero, SYSCALL_ERROR_LABEL;                                        \
72     /* manual cpreturn */                                                     \
73     REG_L gp, STKOFF_GP(sp);                                                  \
74     cfi_same_value (gp);                                                      \
75     RESTORESTK;                                                               \
76     ret;                                                                      \
77   L(pseudo_cancel):                                                           \
78     cfi_adjust_cfa_offset (STKSPACE);                                         \
79     cfi_rel_offset (gp, STKOFF_GP);                                           \
80     REG_S ra, STKOFF_RA(sp);                                                  \
81     cfi_rel_offset (ra, STKOFF_RA);                                           \
82     PUSHARGS_##args;                    /* save syscall args */               \
83     CENABLE;                                                                  \
84     REG_S v0, STKOFF_SVMSK(sp);         /* save mask */                       \
85     POPARGS_##args;                     /* restore syscall args */            \
86     .set noreorder;                                                           \
87     li v0, SYS_ify (syscall_name);                                            \
88     syscall;                                                                  \
89     .set reorder;                                                             \
90     REG_S v0, STKOFF_SC_V0(sp);         /* save syscall result */             \
91     REG_S a3, STKOFF_SC_ERR(sp);        /* save syscall error flag */         \
92     REG_L a0, STKOFF_SVMSK(sp);         /* pass mask as arg1 */               \
93     CDISABLE;                                                                 \
94     REG_L a3, STKOFF_SC_ERR(sp);        /* restore syscall error flag */      \
95     REG_L ra, STKOFF_RA(sp);            /* restore return address */          \
96     REG_L v0, STKOFF_SC_V0(sp);         /* restore syscall result */          \
97     bne a3, zero, SYSCALL_ERROR_LABEL;                                        \
98     /* manual cpreturn */                                                     \
99     REG_L gp, STKOFF_GP(sp);                                                  \
100     cfi_same_value (gp);                                                      \
101     RESTORESTK;                                                               \
102   L(pseudo_end):
103
104
105 # undef PSEUDO_END
106 # define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
107
108 #endif
109
110 # define PUSHARGS_0     /* nothing to do */
111 # define PUSHARGS_1     PUSHARGS_0 REG_S a0, STKOFF_A0(sp); cfi_rel_offset (a0, STKOFF_A0);
112 # define PUSHARGS_2     PUSHARGS_1 REG_S a1, STKOFF_A1(sp); cfi_rel_offset (a1, STKOFF_A1);
113 # define PUSHARGS_3     PUSHARGS_2 REG_S a2, STKOFF_A2(sp); cfi_rel_offset (a2, STKOFF_A2);
114 # define PUSHARGS_4     PUSHARGS_3 REG_S a3, STKOFF_A3(sp); cfi_rel_offset (a3, STKOFF_A3);
115 # define PUSHARGS_5     PUSHARGS_4 REG_S a4, STKOFF_A4(sp); cfi_rel_offset (a3, STKOFF_A4);
116 # define PUSHARGS_6     PUSHARGS_5 REG_S a5, STKOFF_A5(sp); cfi_rel_offset (a3, STKOFF_A5);
117
118 # define POPARGS_0      /* nothing to do */
119 # define POPARGS_1      POPARGS_0 REG_L a0, STKOFF_A0(sp);
120 # define POPARGS_2      POPARGS_1 REG_L a1, STKOFF_A1(sp);
121 # define POPARGS_3      POPARGS_2 REG_L a2, STKOFF_A2(sp);
122 # define POPARGS_4      POPARGS_3 REG_L a3, STKOFF_A3(sp);
123 # define POPARGS_5      POPARGS_4 REG_L a4, STKOFF_A4(sp);
124 # define POPARGS_6      POPARGS_5 REG_L a5, STKOFF_A5(sp);
125
126 /* Save an even number of slots.  Should be 0 if an even number of slots
127    are used below, or SZREG if an odd number are used.  */
128 # define STK_PAD        SZREG
129
130 /* Place values that we are more likely to use later in this sequence, i.e.
131    closer to the SP at function entry.  If you do that, the are more
132    likely to already be in your d-cache.  */
133 # define STKOFF_A5      (STK_PAD)
134 # define STKOFF_A4      (STKOFF_A5 + SZREG)
135 # define STKOFF_A3      (STKOFF_A4 + SZREG)
136 # define STKOFF_A2      (STKOFF_A3 + SZREG)     /* MT and more args.  */
137 # define STKOFF_A1      (STKOFF_A2 + SZREG)     /* MT and 2 args.  */
138 # define STKOFF_A0      (STKOFF_A1 + SZREG)     /* MT and 1 arg.  */
139 # define STKOFF_RA      (STKOFF_A0 + SZREG)     /* Used if MT.  */
140 # define STKOFF_SC_V0   (STKOFF_RA + SZREG)     /* Used if MT.  */
141 # define STKOFF_SC_ERR  (STKOFF_SC_V0 + SZREG)  /* Used if MT.  */
142 # define STKOFF_SVMSK   (STKOFF_SC_ERR + SZREG) /* Used if MT.  */
143 # define STKOFF_GP      (STKOFF_SVMSK + SZREG)  /* Always used.  */
144
145 # define STKSPACE       (STKOFF_GP + SZREG)
146 # define SAVESTK        PTR_SUBU sp, STKSPACE; cfi_adjust_cfa_offset(STKSPACE)
147 # define RESTORESTK     PTR_ADDU sp, STKSPACE; cfi_adjust_cfa_offset(-STKSPACE)
148
149 # ifdef IS_IN_libpthread
150 #  define CENABLE       PTR_LA t9, __pthread_enable_asynccancel; jalr t9
151 #  define CDISABLE      PTR_LA t9, __pthread_disable_asynccancel; jalr t9
152 # elif defined IS_IN_librt
153 #  define CENABLE       PTR_LA t9, __librt_enable_asynccancel; jalr t9
154 #  define CDISABLE      PTR_LA t9, __librt_disable_asynccancel; jalr t9
155 # else
156 #  define CENABLE       PTR_LA t9, __libc_enable_asynccancel; jalr t9
157 #  define CDISABLE      PTR_LA t9, __libc_disable_asynccancel; jalr t9
158 # endif
159
160 # ifndef __ASSEMBLER__
161 #  define SINGLE_THREAD_P                                               \
162         __builtin_expect (THREAD_GETMEM (THREAD_SELF,                   \
163                                          header.multiple_threads)       \
164                           == 0, 1)
165 # else
166 #  define SINGLE_THREAD_P(reg)                                          \
167         READ_THREAD_POINTER(reg);                                       \
168         lw reg, MULTIPLE_THREADS_OFFSET(reg)
169 #endif
170
171 #elif !defined __ASSEMBLER__
172
173 # define SINGLE_THREAD_P 1
174 # define NO_CANCELLATION 1
175
176 #endif
177
178 #ifndef __ASSEMBLER__
179 # define RTLD_SINGLE_THREAD_P \
180   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
181                                    header.multiple_threads) == 0, 1)
182 #endif