1/*	$NetBSD: elf_machdep.h,v 1.16 2019/12/08 21:46:03 uwe Exp $	*/
2
3#ifndef _POWERPC_ELF_MACHDEP_H_
4#define _POWERPC_ELF_MACHDEP_H_
5
6#define	ELF32_MACHDEP_ENDIANNESS	ELFDATA2MSB
7#define	ELF32_MACHDEP_ID_CASES						\
8		case EM_PPC:						\
9			break;
10
11#define	ELF64_MACHDEP_ENDIANNESS	ELFDATA2MSB
12#define	ELF64_MACHDEP_ID_CASES						\
13		case EM_PPC64:						\
14			break;
15
16#define	ELF32_MACHDEP_ID	EM_PPC
17#define	ELF64_MACHDEP_ID	EM_PPC64
18
19
20#ifdef _LP64
21#define KERN_ELFSIZE		64
22#define ARCH_ELFSIZE		64	/* MD native binary size */
23#else
24#define KERN_ELFSIZE		32
25#define ARCH_ELFSIZE		32	/* MD native binary size */
26#endif
27
28/* Specify the value of _GLOBAL_OFFSET_TABLE_ */
29#define	DT_PPC_GOT		DT_LOPROC
30#define	DT_PPC64_GLINK		(DT_LOPROC + 0)
31#define	DT_PPC64_OPD		(DT_LOPROC + 1)
32#define	DT_PPC64_OPDSZ		(DT_LOPROC + 2)
33#define	DT_PPC64_TLSOPT		(DT_LOPROC + 3)
34
35// A = the addend used to compute the value of relocatable field
36// B = the base address of the shared object
37// G = offset into the global offset table
38// L = section offset or address of the procedure link table entry for the
39//     symbol + addend
40// M = similar to G except the address which is stored may be the address of
41//     the procedure linkage table entry for the symbol
42// P = the place (section offset or address) of the storage unit being
43//     relocated (computed using r_offset)
44// R = the offset of the symbol with the section in which the symbol is defined
45// S = the value of the symbol whose index resides in the relocation entry
46//
47// @dtpmod
48//   Computes the load module index of the load module that contains the
49//   definition of sym.  The addend, if present, is ignored.
50// @dtprel
51//   Computes a dtv-relative displacement, the difference between the value of
52//   S + A and the base address of the thread-local storage block that contains
53//   the definition of the symbol, minus 0x8000.
54// @tprel
55//   Computes a tp-relative displacement, the difference between the value of
56//   S + A and the value of the thread pointer (r13).
57// @got@tlsgd
58//   Allocates two contiguous entries in the GOT to hold a tls_index structure,
59//   with values @dtpmod and @dtprel, and computes the offset to the first
60//   entry relative to the TOC base (r2).
61// @got@tlsld
62//   Allocates two contiguous entries in the GOT to hold a tls_index structure,
63//   with values @dtpmod and zero, and computes the offset to the first entry
64//   relative to the TOC base (r2).
65// @got@dtprel
66//   Allocates an entry in the GOT with value @dtprel, and computes the offset
67//   to the entry relative to the TOC base (r2).
68// @got@tprel
69//   Allocates an entry in the GOT with value @tprel, and computes the offset
70//   to the entry relative to the TOC base (r2).
71//
72// #lo(x) = (x & 0xffff)
73// #hi(x) = ((x >> 16) & 0xffff)
74// #ha(x) = (((x >> 16) + ((x & 0x8000) == 0x8000)) & 0xffff)
75// #higher(x) = ((x >> 32) & 0xffff)
76// #highera(x) =
77//    (((x >> 32) + ((x & 0xffff8000) == 0xffff8000)) & 0xffff)
78// #highest(x) = ((x >> 48) & 0xffff)
79// #highesta(x) =
80//    (((x >> 48) + ((x & 0xffffffff8000) == 0xffffffff8000)) & 0xffff)
81// .TOC. = base TOC base of TOC section for object being relocated
82
83#define	R_PPC_NONE 		0
84#define	R_PPC_ADDR32 		1	// S + A
85#define	R_PPC_ADDR24 		2	// (S + A) >> 2
86#define	R_PPC_ADDR16 		3	// S + A
87#define	R_PPC_ADDR16_LO 	4	// #lo(S + A)
88#define	R_PPC_ADDR16_HI 	5	// #hi(S + A)
89#define	R_PPC_ADDR16_HA 	6	// #ha(S + A)
90#define	R_PPC_ADDR14 		7	// (S + A) >> 2
91#define	R_PPC_ADDR14_TAKEN 	8	// (S + A) >> 2
92#define	R_PPC_ADDR14_NTAKEN 	9	// (S + A) >> 2
93#define	R_PPC_REL24 		10 	// (S + A - P) >> 2
94#define	R_PPC_REL14 		11	// (S + A - P) >> 2
95#define	R_PPC_REL14_TAKEN 	12	// (S + A - P) >> 2
96#define	R_PPC_REL14_NTAKEN 	13	// (S + A - P) >> 2
97#define	R_PPC_GOT16 		14	// G + A
98#define	R_PPC_GOT16_LO 		15	// #lo(G + A)
99#define	R_PPC_GOT16_HI 		16	// #hi(G + A)
100#define	R_PPC_GOT16_HA 		17	// #ha(G + A)
101#define	R_PPC_PLTREL24 		18	// (L + A - P) >> 2
102#define	R_PPC_COPY 		19	// none
103#define	R_PPC_GLOB_DAT 		20	// S + A
104#define	R_PPC_JMP_SLOT 		21
105#define	R_PPC_RELATIVE 		22	// B + A
106#define	R_PPC_LOCAL24PC 	23	// (see R_PPC_REL24)
107#define	R_PPC_UADDR32 		24	// S + A
108#define	R_PPC_UADDR16 		25	// S + A
109#define	R_PPC_REL32 		26	// S + A - P
110#define	R_PPC_PLT32 		27	// L
111#define	R_PPC_PLTREL 		28	// L - P
112#define	R_PPC_PLT16_LO 		29	// #lo(L)
113#define	R_PPC_PLT16_HI 		30	// #hi(L)
114#define	R_PPC_PLT16_HA 		31	// #ha(L)
115#define	R_PPC_SDAREL16 		32	// S + A - _SDA_BASE_
116#define	R_PPC_SECTOFF 		33	// R + A
117#define	R_PPC_SECTOFF_LO 	34	// #lo(R + A)
118#define	R_PPC_SECTOFF_HI	35	// #lo(R + A)
119#define	R_PPC_SECTOFF_HA	36	// #ha(R + A)
120#define	R_PPC_ADDR30 		37	// (S + A - P) >> 2
121/* PPC64 relocations */
122#define R_PPC_ADDR64		38	// S + A
123#define R_PPC_ADDR16_HIGHER	39	// #higher(S + A)
124#define R_PPC_ADDR16_HIGHERA	40	// #highera(S + A)
125#define R_PPC_ADDR16_HIGHEST	41	// #highest(S + A)
126#define R_PPC_ADDR16_HIGHESTA	42	// #highesta(S + A)
127#define R_PPC_UADDR64		43	// S + A
128#define R_PPC_REL64		44	// S + A - P
129#define R_PPC_PLT64		45	// L
130#define R_PPC_PLTREL4		46	// L - P
131#define	R_PPC_TOC16 		47	// S + A - .TOC.
132#define	R_PPC_TOC16_LO 		48	// #lo(S + A - .TOC.)
133#define	R_PPC_TOC16_HI		49	// #lo(S + A - .TOC.)
134#define	R_PPC_TOC16_HA		50	// #ha(S + A - .TOC.)
135#define R_PPC_TOC		51	// .TOC.
136#define	R_PPC_PLTGOT16 		52	// M
137#define	R_PPC_PLTGOT16_LO 	53	// #lo(M)
138#define	R_PPC_PLTGOT16_HI	54	// #lo(M)
139#define	R_PPC_PLTGOT16_HA	55	// #ha(M)
140#define	R_PPC_ADDR16_DS		56	// (S + A) >> 2
141#define	R_PPC_ADDR16_LO_DS 	57	// #lo(S + A) >> 2
142#define	R_PPC_GOT16_DS 		58	// G >> 2
143#define	R_PPC_GOT16_LO_DS 	59	// #lo(G) >> 2
144#define	R_PPC_PLT16_LO_DS 	60	// #lo(L) >> 2
145#define	R_PPC_SECTOFF16_DS	61	// (R + A) >> 2
146#define	R_PPC_SECTOFF16_LO_DS 	62	// #lo(R + A) >> 2
147#define	R_PPC_TOC16_DS		63	// (S + A - .TOC.) >> 2
148#define	R_PPC_TOC16_LO_DS 	64	// #lo(S + A - .TOC.) >> 2
149#define	R_PPC_PLTGOT16_DS	65	// M >> 2
150#define	R_PPC_PLTGOT16_LO_DS 	66	// #lo(M) >> 2
151
152/* TLS relocations */
153#define	R_PPC_TLS		67	// none
154
155#define	R_PPC_DTPMOD		68
156#define	R_PPC_TPREL16		69	// @tprel
157#define	R_PPC_TPREL16_LO	70	// #lo(@tprel)
158#define	R_PPC_TPREL16_HI	71	// #hi(@tprel)
159#define	R_PPC_TPREL16_HA	72	// #ha(@tprel)
160#define	R_PPC_TPREL		73	// @tprel
161#define	R_PPC_DTPREL16		74	// @got@dtprel
162#define	R_PPC_DTPREL16_LO	75	// #lo(@dtprel)
163#define	R_PPC_DTPREL16_HI	76	// #hi(@dtprel)
164#define	R_PPC_DTPREL16_HA	77	// #ha(@dtprel)
165#define	R_PPC_DTPREL		78	// @dtprel
166
167#define	R_PPC_GOT_TLSGD16	79	// @got@tlsgd
168#define	R_PPC_GOT_TLSGD16_LO	80	// #lo(@got@tlsgd)
169#define	R_PPC_GOT_TLSGD16_HI	81	// #hi(@got@tlsgd)
170#define	R_PPC_GOT_TLSGD16_HA	82	// #ha(@got@tlsgd)
171#define	R_PPC_GOT_TLSLD16	83	// @got@tlsld
172#define	R_PPC_GOT_TLSLD16_LO	84	// #lo(@got@tlsld)
173#define	R_PPC_GOT_TLSLD16_HI	85	// #hi(@got@tlsld)
174#define	R_PPC_GOT_TLSLD16_HA	86	// #ha(@got@tlsld)
175
176#define	R_PPC_GOT_TPREL16	87	// @got@tprel
177#define	R_PPC_GOT_TPREL16_LO	88	// #lo(@got@tprel)
178#define	R_PPC_GOT_TPREL16_HI	89	// #hi(@got@tprel)
179#define	R_PPC_GOT_TPREL16_HA	90	// #ha(@got@tprel)
180#define	R_PPC_GOT_DTPREL16	91	// @got@dtprel
181#define	R_PPC_GOT_DTPREL16_LO	92	// #lo(@got@dtprel)
182#define	R_PPC_GOT_DTPREL16_HI	93	// #hi(@got@dtprel)
183#define	R_PPC_GOT_DTPREL16_HA	94	// #ha(@got@dtprel)
184#define	R_PPC_TLSGD		95
185#define	R_PPC_TLSLD		96
186
187/* PPC64 relocations */
188#define	R_PPC_TPREL16_DS	95	// @tprel
189#define	R_PPC_TPREL16_LO_DS	96	// #lo(@tprel)
190#define	R_PPC_TPREL16_HIGHER	97	// #higher(@tprel)
191#define	R_PPC_TPREL16_HIGHERA	98	// #highera(@tprel)
192#define	R_PPC_TPREL16_HIGHEST	99	// #highest(@tprel)
193#define	R_PPC_TPREL16_HIGHESTA	100	// #highesta(@tprel)
194
195#define	R_PPC_DTPREL16_DS	101	// @dtprel
196#define	R_PPC_DTPREL16_LO_DS	102	// #lo(@dtprel)
197#define	R_PPC_DTPREL16_HIGHER	103	// #higher(@dtprel)
198#define	R_PPC_DTPREL16_HIGHERA	104	// #highera(@dtprel)
199#define	R_PPC_DTPREL16_HIGHEST	105	// #highest(@dtprel)
200#define	R_PPC_DTPREL16_HIGHESTA	106	// #highesta(@dtprel)
201
202/* Indirect-function support */
203#define	R_PPC_IRELATIVE		248
204
205/* Used for the secure-plt PIC code sequences */
206#define	R_PPC_REL16		249	// S + A - P
207#define	R_PPC_REL16_LO		250	// #lo(S + A - P)
208#define	R_PPC_REL16_HI		251	// #hi(S + A - P)
209#define	R_PPC_REL16_HA		252	// #ha(S + A - P)
210
211#define R_TYPE(name) 		__CONCAT(R_PPC_,name)
212
213#endif /* _POWERPC_ELF_MACHDEP_H_ */
214