1 /* Copyright (C) 1997, 2000, 2002, 2003, 2004, 2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #ifndef _LINUX_SPARC64_SYSDEP_H
22 #define _LINUX_SPARC64_SYSDEP_H 1
24 #include <sysdeps/unix/sysdep.h>
27 # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
32 #define SYS_ify(syscall_name) __NR_##syscall_name
34 /* This is a kludge to make syscalls.list find these under the names
35 pread and pwrite, since some kernel headers define those names
36 and some define the *64 names for the same system calls. */
37 #if !defined __NR_pread && defined __NR_pread64
38 # define __NR_pread __NR_pread64
40 #if !defined __NR_pwrite && defined __NR_pwrite64
41 # define __NR_pwrite __NR_pwrite64
46 #define LOADSYSCALL(x) mov __NR_##x, %g1
48 /* Linux/SPARC uses a different trap number */
55 .global C_SYMBOL_NAME(name); \
60 #ifdef LINKER_HANDLES_R_SPARC_WDISP22
61 /* Unfortunately, we cannot do this yet. Linker doesn't seem to
62 handle R_SPARC_WDISP22 against non-STB_LOCAL symbols properly . */
63 # define SYSCALL_ERROR_HANDLER_ENTRY(handler) \
64 .section .gnu.linkonce.t.handler,"ax",@progbits; \
67 .type handler,@function; \
70 # define SYSCALL_ERROR_HANDLER_ENTRY(handler) \
75 #if RTLD_PRIVATE_ERRNO
76 # define SYSCALL_ERROR_HANDLER \
77 .section .gnu.linkonce.t.__sparc64.get_pic.l7,"ax",@progbits; \
78 .globl __sparc64.get_pic.l7; \
79 .hidden __sparc64.get_pic.l7; \
80 .type __sparc64.get_pic.l7,@function; \
81 __sparc64.get_pic.l7: \
85 SYSCALL_ERROR_HANDLER_ENTRY(__syscall_error_handler) \
86 save %sp, -192, %sp; \
87 sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7; \
88 call __sparc64.get_pic.l7; \
89 add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7; \
90 sethi %hi(rtld_errno), %g1; \
91 or %g1, %lo(rtld_errno), %g1; \
92 ldx [%l7 + %g1], %l0; \
95 restore %g0, -1, %o0; \
99 # define SYSCALL_ERROR_ERRNO __libc_errno
101 # define SYSCALL_ERROR_ERRNO errno
104 # define SYSCALL_ERROR_HANDLER \
105 .section .gnu.linkonce.t.__sparc64.get_pic.l7,"ax",@progbits; \
106 .globl __sparc64.get_pic.l7; \
107 .hidden __sparc64.get_pic.l7; \
108 .type __sparc64.get_pic.l7,@function; \
109 __sparc64.get_pic.l7: \
113 SYSCALL_ERROR_HANDLER_ENTRY(__syscall_error_handler) \
115 sethi %tie_hi22(SYSCALL_ERROR_ERRNO), %l1; \
116 sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7; \
117 call __sparc64.get_pic.l7; \
118 add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7; \
119 add %l1, %tie_lo10(SYSCALL_ERROR_ERRNO), %l1; \
120 ldx [%l7 + %l1], %l1, %tie_ldx(SYSCALL_ERROR_ERRNO); \
121 st %i0, [%g7 + %l1], %tie_add(SYSCALL_ERROR_ERRNO); \
123 restore %g0, -1, %o0; \
126 # define SYSCALL_ERROR_HANDLER \
127 SYSCALL_ERROR_HANDLER_ENTRY(__syscall_error_handler) \
128 sethi %tie_hi22(SYSCALL_ERROR_ERRNO), %g1; \
129 sethi %hi(_GLOBAL_OFFSET_TABLE_), %g4; \
130 add %g1, %tie_lo10(SYSCALL_ERROR_ERRNO), %g1; \
131 add %g4, %lo(_GLOBAL_OFFSET_TABLE_), %g4; \
132 ldx [%g4 + %g1], %g1, %tie_ldx(SYSCALL_ERROR_ERRNO); \
133 st %o0, [%g7 + %g1], %tie_add(SYSCALL_ERROR_ERRNO); \
139 # define SYSCALL_ERROR_HANDLER \
140 SYSCALL_ERROR_HANDLER_ENTRY(__syscall_error_handler) \
141 .global __errno_location; \
142 .type __errno_location,@function; \
143 save %sp, -192, %sp; \
144 call __errno_location; \
148 restore %g0, -1, %o0; \
152 #define PSEUDO(name, syscall_name, args) \
155 LOADSYSCALL(syscall_name); \
157 bcs,pn %xcc, __syscall_error_handler; \
159 SYSCALL_ERROR_HANDLER
161 #define PSEUDO_NOERRNO(name, syscall_name, args) \
164 LOADSYSCALL(syscall_name); \
167 #define PSEUDO_ERRVAL(name, syscall_name, args) \
170 LOADSYSCALL(syscall_name); \
174 #define PSEUDO_END(name) \
177 #undef PSEUDO_END_NOERRNO
178 #define PSEUDO_END_NOERRNO(name) \
181 #undef PSEUDO_END_ERRVAL
182 #define PSEUDO_END_ERRVAL(name) \
189 /* Careful here! This "ret" define can interfere; use jmpl if unsure. */
190 #define ret retl; nop
191 #define ret_NOERRNO retl; nop
192 #define ret_ERRVAL retl; nop
195 #define MOVE(x,y) mov x, y
197 #else /* __ASSEMBLER__ */
199 #define __SYSCALL_STRING \
201 "bcc,pt %%xcc, 1f;" \
203 "save %%sp, -192, %%sp;" \
204 "call __errno_location;" \
207 "restore %%g0, -1, %%o0;" \
210 #define __CLONE_SYSCALL_STRING \
212 "bcc,pt %%xcc, 1f;" \
213 " sub %%o1, 1, %%o1;" \
214 "save %%sp, -192, %%sp;" \
215 "call __errno_location;" \
218 "restore %%g0, -1, %%o0;" \
220 "and %%o0, %%o1, %%o0"
222 #define __INTERNAL_SYSCALL_STRING \
224 "bcs,a,pt %%xcc, 1f;" \
225 " sub %%g0, %%o0, %%o0;" \
228 #define __SYSCALL_CLOBBERS "g2", "g3", "g4", "g5", "g6", \
229 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
230 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
231 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
232 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
233 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
234 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", \
237 #include <sysdeps/unix/sysv/linux/sparc/sysdep.h>
239 #endif /* __ASSEMBLER__ */
241 /* This is the offset from the %sp to the backing store above the
242 register windows. So if you poke stack memory directly you add this. */
243 #define STACK_BIAS 2047
245 /* Pointer mangling support. */
246 #if defined NOT_IN_libc && defined IS_IN_rtld
247 /* We cannot use the thread descriptor because in ld.so we use setjmp
248 earlier than the descriptor is initialized. */
250 # ifdef __ASSEMBLER__
251 # define PTR_MANGLE(dreg, reg, tmpreg) \
252 ldx [%g7 + POINTER_GUARD], tmpreg; \
253 xor reg, tmpreg, dreg
254 # define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
255 # define PTR_MANGLE2(dreg, reg, tmpreg) \
256 xor reg, tmpreg, dreg
257 # define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
259 # define PTR_MANGLE(var) \
260 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
261 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
265 #endif /* linux/sparc64/sysdep.h */