1/* Copyright (C) 2011-2018 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   <http://www.gnu.org/licenses/>.  */
17
18#include_next <sysdep.h>
19
20#define _SYSDEPS_SYSDEP_H 1
21#include <bits/hwcap.h>
22
23#ifdef	__ASSEMBLER__
24
25#define SPARC_PIC_THUNK(reg)						\
26	.ifndef __sparc_get_pc_thunk.reg;				\
27	.section .text.__sparc_get_pc_thunk.reg,"axG",@progbits,__sparc_get_pc_thunk.reg,comdat; \
28	.align	 32;							\
29	.weak	 __sparc_get_pc_thunk.reg;				\
30	.hidden	 __sparc_get_pc_thunk.reg;				\
31	.type	 __sparc_get_pc_thunk.reg, #function;			\
32__sparc_get_pc_thunk.reg:		   				\
33	jmp	%o7 + 8;						\
34	 add	%o7, %reg, %##reg;					\
35	.previous;							\
36	.endif;
37
38/* The "-4" and "+4" offsets against _GLOBAL_OFFSET_TABLE_ are
39   critical since they represent the offset from the thunk call to the
40   instruction containing the _GLOBAL_OFFSET_TABLE_ reference.
41   Therefore these instructions cannot be moved around without
42   appropriate adjustments to those offsets.
43
44   Furthermore, these expressions are special in another regard.  When
45   the assembler sees a reference to _GLOBAL_OFFSET_TABLE_ inside of
46   a %hi() or %lo(), it emits a PC-relative relocation.  This causes
47   R_SPARC_HI22 to turn into R_SPARC_PC22, and R_SPARC_LO10 to turn into
48   R_SPARC_PC10, respectively.
49
50   Even when v9 we use a call sequence instead of using "rd %pc" because
51   RDPC is extremely expensive and incurs a full pipeline flush.  */
52
53#define SPARC_PIC_THUNK_CALL(reg)					\
54	sethi	%hi(_GLOBAL_OFFSET_TABLE_-4), %##reg;			\
55	call	__sparc_get_pc_thunk.reg;				\
56	 or	%##reg, %lo(_GLOBAL_OFFSET_TABLE_+4), %##reg;
57
58#define SETUP_PIC_REG(reg)						\
59	SPARC_PIC_THUNK(reg)						\
60	SPARC_PIC_THUNK_CALL(reg)
61
62#define SETUP_PIC_REG_LEAF(reg, tmp)					\
63	SPARC_PIC_THUNK(reg)						\
64	mov	%o7, %##tmp;		      				\
65	SPARC_PIC_THUNK_CALL(reg);					\
66	mov	%##tmp, %o7;
67
68#undef ENTRY
69#define ENTRY(name)			\
70	.align	4;			\
71	.global	C_SYMBOL_NAME(name);	\
72	.type	name, @function;	\
73C_LABEL(name)				\
74	cfi_startproc;
75
76#undef END
77#define END(name)			\
78	cfi_endproc;
79
80#undef LOC
81#define LOC(name)  .L##name
82
83#endif	/* __ASSEMBLER__ */
84
85/* This is the offset from the %sp to the backing store above the
86 *    register windows.  So if you poke stack memory directly you add this.  */
87#define STACK_BIAS	2047
88