1 /* Copyright (C) 1997-2022 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
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.
8 
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.
13 
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    <https://www.gnu.org/licenses/>.  */
17 
18 #ifndef _LINUX_SPARC32_SYSDEP_H
19 #define _LINUX_SPARC32_SYSDEP_H 1
20 
21 #include <sysdeps/unix/sysv/linux/sparc/sysdep.h>
22 
23 #if IS_IN (rtld)
24 # include <dl-sysdep.h>		/* Defines RTLD_PRIVATE_ERRNO.  */
25 #endif
26 #include <tls.h>
27 
28 #undef SYS_ify
29 #define SYS_ify(syscall_name) __NR_##syscall_name
30 
31 #ifdef __ASSEMBLER__
32 
33 #define LOADSYSCALL(x) mov __NR_##x, %g1
34 
35 #undef PSEUDO
36 #define PSEUDO(name, syscall_name, args)	\
37 	.text;					\
38 ENTRY(name);					\
39 	LOADSYSCALL(syscall_name);		\
40 	ta		0x10;			\
41 	bcc		1f;			\
42 	 nop;					\
43 	SYSCALL_ERROR_HANDLER			\
44 1:
45 
46 #undef PSEUDO_NOERRNO
47 #define PSEUDO_NOERRNO(name, syscall_name, args)\
48 	.text;					\
49 ENTRY(name);					\
50 	LOADSYSCALL(syscall_name);		\
51 	ta		0x10;
52 
53 #undef PSEUDO_ERRVAL
54 #define PSEUDO_ERRVAL(name, syscall_name, args)	\
55 	.text;					\
56 ENTRY(name);					\
57 	LOADSYSCALL(syscall_name);		\
58 	ta		0x10;
59 
60 #undef PSEUDO_END
61 #define PSEUDO_END(name)			\
62 	END(name)
63 
64 #ifndef PIC
65 # define SYSCALL_ERROR_HANDLER			\
66 	mov	%o7, %g1;			\
67 	call	__syscall_error;		\
68 	 mov	%g1, %o7;
69 #else
70 # if RTLD_PRIVATE_ERRNO
71 #  define SYSCALL_ERROR_HANDLER			\
72 0:	SETUP_PIC_REG_LEAF(o2,g1)		\
73 	sethi	%gdop_hix22(rtld_errno), %g1;	\
74 	xor	%g1, %gdop_lox10(rtld_errno), %g1;\
75 	ld	[%o2 + %g1], %g1, %gdop(rtld_errno); \
76 	st	%o0, [%g1];			\
77 	jmp	%o7 + 8;			\
78 	 mov	-1, %o0;
79 # elif defined _LIBC_REENTRANT
80 
81 #  if IS_IN (libc)
82 #   define SYSCALL_ERROR_ERRNO __libc_errno
83 #  else
84 #   define SYSCALL_ERROR_ERRNO errno
85 #  endif
86 #  define SYSCALL_ERROR_HANDLER					\
87 0:	SETUP_PIC_REG_LEAF(o2,g1)				\
88 	sethi	%tie_hi22(SYSCALL_ERROR_ERRNO), %g1;		\
89 	add	%g1, %tie_lo10(SYSCALL_ERROR_ERRNO), %g1;	\
90 	ld	[%o2 + %g1], %g1, %tie_ld(SYSCALL_ERROR_ERRNO);	\
91 	st	%o0, [%g7 + %g1];				\
92 	jmp	%o7 + 8;					\
93 	 mov	-1, %o0;
94 # else
95 #  define SYSCALL_ERROR_HANDLER		\
96 0:	SETUP_PIC_REG_LEAF(o2,g1)	\
97 	sethi	%gdop_hix22(errno), %g1;\
98 	xor	%g1, %gdop_lox10(errno), %g1;\
99 	ld	[%o2 + %g1], %g1, %gdop(errno);\
100 	st	%o0, [%g1];		\
101 	jmp	%o7 + 8;		\
102 	 mov	-1, %o0;
103 # endif	/* _LIBC_REENTRANT */
104 #endif	/* PIC */
105 
106 
107 #else  /* __ASSEMBLER__ */
108 
109 #define __SYSCALL_STRING						\
110 	"ta	0x10;"							\
111 	"bcc	1f;"							\
112 	" nop;"								\
113 	"sub	%%g0, %%o0, %%o0;"					\
114 	"1:"
115 
116 #define __SYSCALL_CLOBBERS						\
117 	"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",			\
118 	"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",		\
119 	"f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",		\
120 	"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",		\
121 	"cc", "memory"
122 
123 #undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
124 #define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
125 
126 #endif	/* __ASSEMBLER__ */
127 
128 /* Pointer mangling support.  */
129 #if IS_IN (rtld)
130 /* We cannot use the thread descriptor because in ld.so we use setjmp
131    earlier than the descriptor is initialized.  */
132 #else
133 # ifdef __ASSEMBLER__
134 #  define PTR_MANGLE(dreg, reg, tmpreg) \
135   ld	[%g7 + POINTER_GUARD], tmpreg; \
136   xor	reg, tmpreg, dreg
137 #  define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
138 #  define PTR_MANGLE2(dreg, reg, tmpreg) \
139   xor	reg, tmpreg, dreg
140 #  define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
141 # else
142 #  define PTR_MANGLE(var) \
143   (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
144 #  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
145 # endif
146 #endif
147 
148 #endif /* linux/sparc/sysdep.h */
149