OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libpthread / nptl / sysdeps / unix / sysv / linux / sh / 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 <tls.h>
19 #include <sysdep.h>
20 #ifndef __ASSEMBLER__
21 # include <pthreadP.h>
22 #endif
23
24 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
25
26 # define _IMM12 #-12
27 # define _IMM16 #-16
28 # define _IMP16 #16
29 # undef PSEUDO
30 # define PSEUDO(name, syscall_name, args) \
31   .text; \
32   ENTRY (name); \
33   .Lpseudo_start: \
34     SINGLE_THREAD_P; \
35     bf .Lpseudo_cancel; \
36     .type __##syscall_name##_nocancel,@function; \
37     .globl __##syscall_name##_nocancel; \
38     __##syscall_name##_nocancel: \
39     DO_CALL (syscall_name, args); \
40     mov r0,r1; \
41     mov _IMM12,r2; \
42     shad r2,r1; \
43     not r1,r1; \
44     tst r1,r1; \
45     bt .Lsyscall_error; \
46     bra .Lpseudo_end; \
47      nop; \
48     .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
49  .Lpseudo_cancel: \
50     sts.l pr,@-r15; \
51     cfi_adjust_cfa_offset (4); \
52     cfi_rel_offset (pr, 0); \
53     add _IMM16,r15; \
54     cfi_adjust_cfa_offset (16); \
55     SAVE_ARGS_##args; \
56     CENABLE; \
57     LOAD_ARGS_##args; \
58     add _IMP16,r15; \
59     cfi_adjust_cfa_offset (-16); \
60     lds.l @r15+,pr; \
61     cfi_adjust_cfa_offset (-4); \
62     cfi_restore (pr); \
63     DO_CALL(syscall_name, args); \
64     SYSCALL_INST_PAD; \
65     sts.l pr,@-r15; \
66     cfi_adjust_cfa_offset (4); \
67     cfi_rel_offset (pr, 0); \
68     mov.l r0,@-r15; \
69     cfi_adjust_cfa_offset (4); \
70     cfi_rel_offset (r0, 0); \
71     CDISABLE; \
72     mov.l @r15+,r0; \
73     cfi_adjust_cfa_offset (-4); \
74     lds.l @r15+,pr; \
75     cfi_adjust_cfa_offset (-4); \
76     cfi_restore (pr); \
77     mov r0,r1; \
78     mov _IMM12,r2; \
79     shad r2,r1; \
80     not r1,r1; \
81     tst r1,r1; \
82     bf .Lpseudo_end; \
83  .Lsyscall_error: \
84     SYSCALL_ERROR_HANDLER; \
85  .Lpseudo_end:
86
87 # undef PSEUDO_END
88 # define PSEUDO_END(sym) \
89   END (sym)
90
91 # define SAVE_ARGS_0    /* Nothing.  */
92 # define SAVE_ARGS_1    SAVE_ARGS_0; mov.l r4,@(0,r15); cfi_offset (r4,-4)
93 # define SAVE_ARGS_2    SAVE_ARGS_1; mov.l r5,@(4,r15); cfi_offset (r5,-8)
94 # define SAVE_ARGS_3    SAVE_ARGS_2; mov.l r6,@(8,r15); cfi_offset (r6,-12)
95 # define SAVE_ARGS_4    SAVE_ARGS_3; mov.l r7,@(12,r15); cfi_offset (r7,-16)
96 # define SAVE_ARGS_5    SAVE_ARGS_4
97 # define SAVE_ARGS_6    SAVE_ARGS_5
98
99 # define LOAD_ARGS_0    /* Nothing.  */
100 # define LOAD_ARGS_1    LOAD_ARGS_0; mov.l @(0,r15),r4
101 # define LOAD_ARGS_2    LOAD_ARGS_1; mov.l @(4,r15),r5
102 # define LOAD_ARGS_3    LOAD_ARGS_2; mov.l @(8,r15),r6
103 # define LOAD_ARGS_4    LOAD_ARGS_3; mov.l @(12,r15),r7
104 # define LOAD_ARGS_5    LOAD_ARGS_4
105 # define LOAD_ARGS_6    LOAD_ARGS_5
106
107 # ifdef IS_IN_libpthread
108 #  define __local_enable_asynccancel    __pthread_enable_asynccancel
109 #  define __local_disable_asynccancel   __pthread_disable_asynccancel
110 # elif !defined NOT_IN_libc
111 #  define __local_enable_asynccancel    __libc_enable_asynccancel
112 #  define __local_disable_asynccancel   __libc_disable_asynccancel
113 # elif defined IS_IN_librt
114 #  define __local_enable_asynccancel    __librt_enable_asynccancel
115 #  define __local_disable_asynccancel   __librt_disable_asynccancel
116 # else
117 #  error Unsupported library
118 # endif
119
120 # define CENABLE \
121         mov.l 1f,r0; \
122         bsrf r0; \
123          nop; \
124      0: bra 2f; \
125          mov r0,r2; \
126         .align 2; \
127      1: .long __local_enable_asynccancel - 0b; \
128      2:
129
130 # define CDISABLE \
131         mov.l 1f,r0; \
132         bsrf r0; \
133          mov r2,r4; \
134      0: bra 2f; \
135          nop; \
136         .align 2; \
137      1: .long __local_disable_asynccancel - 0b; \
138      2:
139
140 # ifndef __ASSEMBLER__
141 #  define SINGLE_THREAD_P \
142   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
143                                    header.multiple_threads) == 0, 1)
144 # else
145 #  define SINGLE_THREAD_P \
146         stc gbr,r0; \
147         mov.w 0f,r1; \
148         sub r1,r0; \
149         mov.l @(MULTIPLE_THREADS_OFFSET,r0),r0; \
150         bra 1f; \
151          tst r0,r0; \
152      0: .word TLS_PRE_TCB_SIZE; \
153      1:
154
155 # endif
156
157 #elif !defined __ASSEMBLER__
158
159 # define SINGLE_THREAD_P (1)
160 # define NO_CANCELLATION 1
161
162 #endif
163
164 #ifndef __ASSEMBLER__
165 # define RTLD_SINGLE_THREAD_P \
166   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
167                                    header.multiple_threads) == 0, 1)
168 #endif