]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libpthread / linuxthreads / sysdeps / unix / sysv / linux / mips / sysdep-cancel.h
1 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Guido Guenther <agx@sigxcpu.org>, 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 #ifndef __ASSEMBLER__
22 # include <linuxthreads/internals.h>
23 #endif
24
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
26
27 #ifdef __PIC__
28 # undef PSEUDO
29 # define PSEUDO(name, syscall_name, args)                                     \
30   .align 2;                                                                   \
31   99: move a0, v0;                                                            \
32   la t9,__syscall_error;                                                      \
33   jr t9;                                                                      \
34   ENTRY (name)                                                                \
35     .set noreorder;                                                           \
36     .cpload t9;                                                               \
37     .set reorder;                                                             \
38     SINGLE_THREAD_P(t0);                                                      \
39     bne zero, t0, L(pseudo_cancel);                                           \
40     .set noreorder;                                                           \
41     li v0, SYS_ify(syscall_name);                                             \
42     syscall;                                                                  \
43     .set reorder;                                                             \
44     bne a3, zero, SYSCALL_ERROR_LABEL;                                        \
45     ret;                                                                      \
46   L(pseudo_cancel):                                                           \
47     SAVESTK_##args;                                                           \
48     sw ra, 28(sp);                                                            \
49     sw gp, 32(sp);                                                            \
50     PUSHARGS_##args;                    /* save syscall args */               \
51     CENABLE;                                                                  \
52     lw gp, 32(sp);                                                            \
53     sw v0, 44(sp);                      /* save mask */                       \
54     POPARGS_##args;                     /* restore syscall args */            \
55     .set noreorder;                                                           \
56     li v0, SYS_ify (syscall_name);                                            \
57     syscall;                                                                  \
58     .set reorder;                                                             \
59     sw v0, 36(sp);                      /* save syscall result */             \
60     sw a3, 40(sp);                      /* save syscall error flag */         \
61     lw a0, 44(sp);                      /* pass mask as arg1 */               \
62     CDISABLE;                                                                 \
63     lw gp, 32(sp);                                                            \
64     lw v0, 36(sp);                      /* restore syscall result */          \
65     lw a3, 40(sp);                      /* restore syscall error flag */      \
66     lw ra, 28(sp);                      /* restore return address */          \
67     RESTORESTK;                                                               \
68     bne a3, zero, SYSCALL_ERROR_LABEL;                                        \
69   L(pseudo_end):
70 #endif
71
72 # define PUSHARGS_0     /* nothing to do */
73 # define PUSHARGS_1     PUSHARGS_0 sw a0, 0(sp);
74 # define PUSHARGS_2     PUSHARGS_1 sw a1, 4(sp);
75 # define PUSHARGS_3     PUSHARGS_2 sw a2, 8(sp);
76 # define PUSHARGS_4     PUSHARGS_3 sw a3, 12(sp);
77 # define PUSHARGS_5     PUSHARGS_4 /* handeld by SAVESTK_## */
78 # define PUSHARGS_6     PUSHARGS_5
79 # define PUSHARGS_7     PUSHARGS_6
80
81 # define POPARGS_0      /* nothing to do */
82 # define POPARGS_1      POPARGS_0 lw a0, 0(sp);
83 # define POPARGS_2      POPARGS_1 lw a1, 4(sp);
84 # define POPARGS_3      POPARGS_2 lw a2, 8(sp);
85 # define POPARGS_4      POPARGS_3 lw a3, 12(sp);
86 # define POPARGS_5      POPARGS_4 /* args already in new stackframe */
87 # define POPARGS_6      POPARGS_5
88 # define POPARGS_7      POPARGS_6
89
90
91 # define STKSPACE       48
92 # define SAVESTK_0      subu sp, STKSPACE
93 # define SAVESTK_1      SAVESTK_0
94 # define SAVESTK_2      SAVESTK_1
95 # define SAVESTK_3      SAVESTK_2
96 # define SAVESTK_4      SAVESTK_3
97 # define SAVESTK_5      lw t0, 16(sp);          \
98                         subu sp, STKSPACE;      \
99                         sw t0, 16(sp)
100
101 # define SAVESTK_6      lw t0, 16(sp);          \
102                         lw t1, 20(sp);          \
103                         subu sp, STKSPACE;      \
104                         sw t0, 16(sp);          \
105                         sw t1, 20(sp)
106
107 # define SAVESTK_7      lw t0, 16(sp);          \
108                         lw t1, 20(sp);          \
109                         lw t2, 24(sp);          \
110                         subu sp, STKSPACE;      \
111                         sw t0, 16(sp);          \
112                         sw t1, 20(sp);          \
113                         sw t2, 24(sp)
114
115 # define RESTORESTK     addu sp, STKSPACE
116
117
118 # ifdef IS_IN_libpthread
119 #  define CENABLE       la t9, __pthread_enable_asynccancel; jalr t9;
120 #  define CDISABLE      la t9, __pthread_disable_asynccancel; jalr t9;
121 #  define __local_multiple_threads __pthread_multiple_threads
122 # elif defined IS_IN_librt
123 #  define CENABLE       la t9, __librt_enable_asynccancel; jalr t9;
124 #  define CDISABLE      la t9, __librt_disable_asynccancel; jalr t9;
125 #  define __local_multiple_threads __librt_multiple_threads
126 # else
127 #  define CENABLE       la t9, __libc_enable_asynccancel; jalr t9;
128 #  define CDISABLE      la t9, __libc_disable_asynccancel; jalr t9;
129 #  define __local_multiple_threads __libc_multiple_threads
130 # endif
131
132 # ifndef __ASSEMBLER__
133 extern int __local_multiple_threads attribute_hidden;
134 #  define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
135 # else
136 #  define SINGLE_THREAD_P(reg) lw reg, __local_multiple_threads
137 #endif
138
139 #elif !defined __ASSEMBLER__
140
141 /* This code should never be used but we define it anyhow.  */
142 # define SINGLE_THREAD_P (1)
143
144 #endif