sparc64: Fix incorrect sigreturn stub function implementation
[uclibc-ng.git] / libc / sysdeps / linux / sparc64 / sysdep.h
blob5a4c363480833b8322349b3f47882f9ed650c171
1 /* Copyright (C) 1997-2017 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #ifndef _LINUX_SPARC64_SYSDEP_H
19 #define _LINUX_SPARC64_SYSDEP_H 1
21 #include <common/sysdep.h>
23 #undef SYS_ify
24 #define SYS_ify(syscall_name) __NR_##syscall_name
26 #ifdef __ASSEMBLER__
28 #define SPARC_PIC_THUNK(reg) \
29 .ifndef __sparc_get_pc_thunk.reg; \
30 .section .text.__sparc_get_pc_thunk.reg,"axG",@progbits,__sparc_get_pc_thunk.reg,comdat; \
31 .align 32; \
32 .weak __sparc_get_pc_thunk.reg; \
33 .hidden __sparc_get_pc_thunk.reg; \
34 .type __sparc_get_pc_thunk.reg, #function; \
35 __sparc_get_pc_thunk.reg: \
36 jmp %o7 + 8; \
37 add %o7, %reg, %##reg; \
38 .previous; \
39 .endif;
41 /* The "-4" and "+4" offsets against _GLOBAL_OFFSET_TABLE_ are
42 critical since they represent the offset from the thunk call to the
43 instruction containing the _GLOBAL_OFFSET_TABLE_ reference.
44 Therefore these instructions cannot be moved around without
45 appropriate adjustments to those offsets.
47 Furthermore, these expressions are special in another regard. When
48 the assembler sees a reference to _GLOBAL_OFFSET_TABLE_ inside of
49 a %hi() or %lo(), it emits a PC-relative relocation. This causes
50 R_SPARC_HI22 to turn into R_SPARC_PC22, and R_SPARC_LO10 to turn into
51 R_SPARC_PC10, respectively.
53 Even when v9 we use a call sequence instead of using "rd %pc" because
54 RDPC is extremely expensive and incurs a full pipeline flush. */
56 #define SPARC_PIC_THUNK_CALL(reg) \
57 sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %##reg; \
58 call __sparc_get_pc_thunk.reg; \
59 or %##reg, %lo(_GLOBAL_OFFSET_TABLE_+4), %##reg;
61 #define SETUP_PIC_REG(reg) \
62 SPARC_PIC_THUNK(reg) \
63 SPARC_PIC_THUNK_CALL(reg)
65 #define SETUP_PIC_REG_LEAF(reg, tmp) \
66 SPARC_PIC_THUNK(reg) \
67 mov %o7, %##tmp; \
68 SPARC_PIC_THUNK_CALL(reg); \
69 mov %##tmp, %o7;
72 #define LOADSYSCALL(x) mov __NR_##x, %g1
74 #define ENTRY(name) \
75 .align 4; \
76 .global C_SYMBOL_NAME(name); \
77 .type name, @function; \
78 C_LABEL(name) \
79 cfi_startproc;
81 #undef END
82 #define END(name) \
83 cfi_endproc; \
84 .size name, . - name
86 #define ENTRY_NOCFI(name) \
87 .align 4; \
88 .global C_SYMBOL_NAME(name); \
89 .type name, @function; \
90 C_LABEL(name)
92 #define END_NOCFI(name) \
93 .size name, . - name
95 #define LOC(name) .L##name
97 #undef PSEUDO
98 #define PSEUDO(name, syscall_name, args) \
99 .text; \
100 ENTRY(name); \
101 LOADSYSCALL(syscall_name); \
102 ta 0x6d; \
103 bcc,pt %xcc, 1f; \
104 nop; \
105 SYSCALL_ERROR_HANDLER \
108 #undef PSEUDO_NOERRNO
109 #define PSEUDO_NOERRNO(name, syscall_name, args)\
110 .text; \
111 ENTRY(name); \
112 LOADSYSCALL(syscall_name); \
113 ta 0x6d;
115 #undef PSEUDO_ERRVAL
116 #define PSEUDO_ERRVAL(name, syscall_name, args) \
117 .text; \
118 ENTRY(name); \
119 LOADSYSCALL(syscall_name); \
120 ta 0x6d;
122 #undef PSEUDO_END
123 #define PSEUDO_END(name) \
124 END(name)
126 #ifndef __PIC__
127 # define SYSCALL_ERROR_HANDLER \
128 mov %o7, %g1; \
129 call __syscall_error; \
130 mov %g1, %o7;
131 #else
132 # define SYSCALL_ERROR_HANDLER \
133 0: SETUP_PIC_REG_LEAF(o2,g1) \
134 sethi %gdop_hix22(errno), %g1;\
135 xor %g1, %gdop_lox10(errno), %g1;\
136 ldx [%o2 + %g1], %g1, %gdop(errno);\
137 st %o0, [%g1]; \
138 jmp %o7 + 8; \
139 mov -1, %o0;
140 #endif /* PIC */
142 #endif /* __ASSEMBLER__ */
144 /* This is the offset from the %sp to the backing store above the
145 register windows. So if you poke stack memory directly you add this. */
146 #define STACK_BIAS 2047
148 #endif