(PSEUDO): Setup backchain in pseudo_cancel. Minor code improvements.
[kopensolaris-gnu/glibc.git] / linuxthreads / sysdeps / unix / sysv / linux / s390 / s390-32 / sysdep-cancel.h
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <sysdep.h>
21 #include <tls.h>
22 #ifndef __ASSEMBLER__
23 # include <linuxthreads/internals.h>
24 #endif
25
26 #if !defined NOT_IN_libc || defined IS_IN_libpthread
27
28 # undef PSEUDO
29 # define PSEUDO(name, syscall_name, args)                                     \
30         .text;                                                                \
31 ENTRY(name)                                                                   \
32         SINGLE_THREAD_P(%r1)                                                  \
33         jne     L(pseudo_cancel);                                             \
34         DO_CALL(syscall_name, args);                                          \
35         lhi     %r4,-4095;                                                    \
36         clr     %r2,%r4;                                                      \
37         jnl     SYSCALL_ERROR_LABEL;                                          \
38         br      %r14;                                                         \
39 L(pseudo_cancel):                                                             \
40         STM_##args                                                            \
41         stm     %r12,%r15,48(%r15);                                           \
42         lr      %r14,%r15;                                                    \
43         ahi     %r15,-96;                                                     \
44         st      %r14,0(%r15);                                                 \
45         basr    %r13,0;                                                       \
46 200301: l       %r1,200302f-200301b(%r13);                                    \
47         bas     %r14,0(%r1,%r13);                                             \
48         lr      %r0,%r2;                                                      \
49         LM_##args                                                             \
50         DO_CALL(syscall_name, args);                                          \
51         l       %r1,200303f-200301b(%r13);                                    \
52         lr      %r12,%r2;                                                     \
53         lr      %r2,%r0;                                                      \
54         bas     %r14,0(%r1,%r13);                                             \
55         lr      %r2,%r12;                                                     \
56         lm      %r12,%r15,48+96(%r15);                                        \
57         lhi     %r4,-4095;                                                    \
58         clr     %r2,%r4;                                                      \
59         jnl     SYSCALL_ERROR_LABEL;                                          \
60 L(pseudo_end):
61
62 #undef PSEUDO_END
63 #define PSEUDO_END(name)                                                      \
64   SYSCALL_ERROR_HANDLER;                                                      \
65 200302: .long   CENABLE-200301b;                                              \
66 200303: .long   CDISABLE-200301b;                                             \
67     END (name)
68
69 # ifdef IS_IN_libpthread
70 #  define CENABLE       __pthread_enable_asynccancel
71 #  define CDISABLE      __pthread_disable_asynccancel
72 # else
73 #  define CENABLE       __libc_enable_asynccancel
74 #  define CDISABLE      __libc_disable_asynccancel
75 # endif
76
77 #define STM_0           /* Nothing */
78 #define STM_1           st %r2,8(%r15);
79 #define STM_2           stm %r2,%r3,8(%r15);
80 #define STM_3           stm %r2,%r4,8(%r15);
81 #define STM_4           stm %r2,%r5,8(%r15);
82 #define STM_5           stm %r2,%r5,8(%r15);
83
84 #define LM_0            /* Nothing */
85 #define LM_1            l %r2,8+96(%r15);
86 #define LM_2            lm %r2,%r3,8+96(%r15);
87 #define LM_3            lm %r2,%r4,8+96(%r15);
88 #define LM_4            lm %r2,%r5,8+96(%r15);
89 #define LM_5            lm %r2,%r5,8+96(%r15);
90
91 # ifndef __ASSEMBLER__
92 #  define SINGLE_THREAD_P \
93   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                               \
94                                    p_header.data.multiple_threads) == 0, 1)
95 # else
96 #  define SINGLE_THREAD_P(reg) \
97         ear     reg,%a0;                                                      \
98         l       reg,MULTIPLE_THREADS_OFFSET(reg);                             \
99         ltr     reg,reg;
100 # endif
101
102 #elif !defined __ASSEMBLER__
103
104 /* This code should never be used but we define it anyhow.  */
105 # define SINGLE_THREAD_P (1)
106
107 #endif