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