Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc64 / sysdep.h
1 /* Copyright (C) 1997-2013 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
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, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _LINUX_SPARC64_SYSDEP_H
20 #define _LINUX_SPARC64_SYSDEP_H 1
21
22 #include <sysdeps/unix/sysv/linux/sparc/sysdep.h>
23
24 #ifdef IS_IN_rtld
25 # include <dl-sysdep.h>         /* Defines RTLD_PRIVATE_ERRNO.  */
26 #endif
27 #include <tls.h>
28
29 #undef SYS_ify
30 #define SYS_ify(syscall_name) __NR_##syscall_name
31
32 /* This is a kludge to make syscalls.list find these under the names
33    pread and pwrite, since some kernel headers define those names
34    and some define the *64 names for the same system calls.  */
35 #if !defined __NR_pread && defined __NR_pread64
36 # define __NR_pread __NR_pread64
37 #endif
38 #if !defined __NR_pwrite && defined __NR_pwrite64
39 # define __NR_pwrite __NR_pwrite64
40 #endif
41
42 #ifdef __ASSEMBLER__
43
44 #define LOADSYSCALL(x) mov __NR_##x, %g1
45
46 #undef PSEUDO
47 #define PSEUDO(name, syscall_name, args)        \
48         .text;                                  \
49 ENTRY(name);                                    \
50         LOADSYSCALL(syscall_name);              \
51         ta              0x6d;                   \
52         bcc,pt          %xcc, 1f;               \
53          nop;                                   \
54         SYSCALL_ERROR_HANDLER                   \
55 1:
56
57 #undef PSEUDO_NOERRNO
58 #define PSEUDO_NOERRNO(name, syscall_name, args)\
59         .text;                                  \
60 ENTRY(name);                                    \
61         LOADSYSCALL(syscall_name);              \
62         ta              0x6d;
63
64 #undef PSEUDO_ERRVAL
65 #define PSEUDO_ERRVAL(name, syscall_name, args) \
66         .text;                                  \
67 ENTRY(name);                                    \
68         LOADSYSCALL(syscall_name);              \
69         ta              0x6d;
70
71 #undef PSEUDO_END
72 #define PSEUDO_END(name)                        \
73         END(name)
74
75 #ifndef PIC
76 # define SYSCALL_ERROR_HANDLER                  \
77         mov     %o7, %g1;                       \
78         call    __syscall_error;                \
79          mov    %g1, %o7;
80 #else
81 # if RTLD_PRIVATE_ERRNO
82 #  define SYSCALL_ERROR_HANDLER                 \
83 0:      SETUP_PIC_REG_LEAF(o2,g1)               \
84         sethi   %gdop_hix22(rtld_errno), %g1;   \
85         xor     %g1, %gdop_lox10(rtld_errno), %g1;\
86         ldx     [%o2 + %g1], %g1, %gdop(rtld_errno); \
87         st      %o0, [%g1];                     \
88         jmp     %o7 + 8;                        \
89          mov    -1, %o0;
90 # elif defined _LIBC_REENTRANT
91
92 #  ifndef NOT_IN_libc
93 #   define SYSCALL_ERROR_ERRNO __libc_errno
94 #  else
95 #   define SYSCALL_ERROR_ERRNO errno
96 #  endif
97 #  define SYSCALL_ERROR_HANDLER                                 \
98 0:      SETUP_PIC_REG_LEAF(o2,g1)                               \
99         sethi   %tie_hi22(SYSCALL_ERROR_ERRNO), %g1;            \
100         add     %g1, %tie_lo10(SYSCALL_ERROR_ERRNO), %g1;       \
101         ldx     [%o2 + %g1], %g1, %tie_ldx(SYSCALL_ERROR_ERRNO);\
102         st      %o0, [%g7 + %g1];                               \
103         jmp     %o7 + 8;                                        \
104          mov    -1, %o0;
105 # else
106 #  define SYSCALL_ERROR_HANDLER         \
107 0:      SETUP_PIC_REG_LEAF(o2,g1)       \
108         sethi   %gdop_hix22(errno), %g1;\
109         xor     %g1, %gdop_lox10(errno), %g1;\
110         ldx     [%o2 + %g1], %g1, %gdop(errno);\
111         st      %o0, [%g1];             \
112         jmp     %o7 + 8;                \
113          mov    -1, %o0;
114 # endif /* _LIBC_REENTRANT */
115 #endif  /* PIC */
116
117 #else  /* __ASSEMBLER__ */
118
119 #define __SYSCALL_STRING                                                \
120         "ta     0x6d;"                                                  \
121         "bcc,pt %%xcc, 1f;"                                             \
122         " mov   0, %%g1;"                                               \
123         "sub    %%g0, %%o0, %%o0;"                                      \
124         "mov    1, %%g1;"                                               \
125         "1:"
126
127 #define __SYSCALL_CLOBBERS                                              \
128         "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",                 \
129         "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",           \
130         "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",         \
131         "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",         \
132         "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",         \
133         "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",         \
134         "cc", "memory"
135
136 #endif  /* __ASSEMBLER__ */
137
138 /* This is the offset from the %sp to the backing store above the
139    register windows.  So if you poke stack memory directly you add this.  */
140 #define STACK_BIAS      2047
141
142 /* Pointer mangling support.  */
143 #if defined NOT_IN_libc && defined IS_IN_rtld
144 /* We cannot use the thread descriptor because in ld.so we use setjmp
145    earlier than the descriptor is initialized.  */
146 #else
147 # ifdef __ASSEMBLER__
148 #  define PTR_MANGLE(dreg, reg, tmpreg) \
149   ldx   [%g7 + POINTER_GUARD], tmpreg; \
150   xor   reg, tmpreg, dreg
151 #  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
152 #  define PTR_MANGLE2(dreg, reg, tmpreg) \
153   xor   reg, tmpreg, dreg
154 #  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
155 # else
156 #  define PTR_MANGLE(var) \
157   (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
158 #  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
159 # endif
160 #endif
161
162 #endif /* linux/sparc64/sysdep.h */