1/* Copyright (C) 1997-2025 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_SPARC64_SYSDEP_H
 19#define _LINUX_SPARC64_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;					\
 38ENTRY(name);					\
 39	LOADSYSCALL(syscall_name);		\
 40	ta		0x6d;			\
 41	bcc,pt		%xcc, 1f;		\
 42	 nop;					\
 43	SYSCALL_ERROR_HANDLER			\
 441:
 45
 46#undef PSEUDO_NOERRNO
 47#define	PSEUDO_NOERRNO(name, syscall_name, args)\
 48	.text;					\
 49ENTRY(name);					\
 50	LOADSYSCALL(syscall_name);		\
 51	ta		0x6d;
 52
 53#undef PSEUDO_ERRVAL
 54#define	PSEUDO_ERRVAL(name, syscall_name, args) \
 55	.text;					\
 56ENTRY(name);					\
 57	LOADSYSCALL(syscall_name);		\
 58	ta		0x6d;
 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			\
 720:	SETUP_PIC_REG_LEAF(o2,g1)		\
 73	sethi	%gdop_hix22(rtld_errno), %g1;	\
 74	xor	%g1, %gdop_lox10(rtld_errno), %g1;\
 75	ldx	[%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					\
 870:	SETUP_PIC_REG_LEAF(o2,g1)				\
 88	sethi	%tie_hi22(SYSCALL_ERROR_ERRNO), %g1;		\
 89	add	%g1, %tie_lo10(SYSCALL_ERROR_ERRNO), %g1;	\
 90	ldx	[%o2 + %g1], %g1, %tie_ldx(SYSCALL_ERROR_ERRNO);\
 91	st	%o0, [%g7 + %g1];				\
 92	jmp	%o7 + 8;					\
 93	 mov	-1, %o0;
 94# else
 95#  define SYSCALL_ERROR_HANDLER		\
 960:	SETUP_PIC_REG_LEAF(o2,g1)	\
 97	sethi	%gdop_hix22(errno), %g1;\
 98	xor	%g1, %gdop_lox10(errno), %g1;\
 99	ldx	[%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#else  /* __ASSEMBLER__ */
107
108#define __SYSCALL_STRING						\
109	"mov	%[scn], %%g1;"						\
110	"ta	0x6d;"							\
111	"bcc,pt	%%xcc, 1f;"						\
112	" nop;"								\
113	"sub	%%g0, %%o0, %%o0;"					\
114	"1:"
115
116#define __SYSCALL_CLOBBERS						\
117	"g1", "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	"f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",		\
122	"f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",		\
123	"cc", "memory"
124
125#endif	/* __ASSEMBLER__ */
126
127/* This is the offset from the %sp to the backing store above the
128   register windows.  So if you poke stack memory directly you add this.  */
129#define STACK_BIAS	2047
130
131#endif /* linux/sparc64/sysdep.h */