1384740dcSRalf Baechle /*
2384740dcSRalf Baechle * This file is subject to the terms and conditions of the GNU General Public
3384740dcSRalf Baechle * License. See the file "COPYING" in the main directory of this archive
4384740dcSRalf Baechle * for more details.
5384740dcSRalf Baechle *
6384740dcSRalf Baechle * Much of this is taken from binutils and GNU libc ...
7384740dcSRalf Baechle */
8384740dcSRalf Baechle #ifndef _ASM_ELF_H
9384740dcSRalf Baechle #define _ASM_ELF_H
10384740dcSRalf Baechle
11ebb5e78cSAlex Smith #include <linux/auxvec.h>
1290cee759SPaul Burton #include <linux/fs.h>
13589ee628SIngo Molnar #include <linux/mm_types.h>
14589ee628SIngo Molnar
1590cee759SPaul Burton #include <uapi/linux/elf.h>
16384740dcSRalf Baechle
179b26616cSMaciej W. Rozycki #include <asm/current.h>
189b26616cSMaciej W. Rozycki
19384740dcSRalf Baechle /* ELF header e_flags defines. */
20384740dcSRalf Baechle /* MIPS architecture level. */
21384740dcSRalf Baechle #define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */
22384740dcSRalf Baechle #define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */
23384740dcSRalf Baechle #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
24384740dcSRalf Baechle #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */
25384740dcSRalf Baechle #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */
26384740dcSRalf Baechle #define EF_MIPS_ARCH_32 0x50000000 /* MIPS32 code. */
27384740dcSRalf Baechle #define EF_MIPS_ARCH_64 0x60000000 /* MIPS64 code. */
28384740dcSRalf Baechle #define EF_MIPS_ARCH_32R2 0x70000000 /* MIPS32 R2 code. */
29384740dcSRalf Baechle #define EF_MIPS_ARCH_64R2 0x80000000 /* MIPS64 R2 code. */
30384740dcSRalf Baechle
31384740dcSRalf Baechle /* The ABI of a file. */
32384740dcSRalf Baechle #define EF_MIPS_ABI_O32 0x00001000 /* O32 ABI. */
33384740dcSRalf Baechle #define EF_MIPS_ABI_O64 0x00002000 /* O32 extended for 64 bit. */
34384740dcSRalf Baechle
35384740dcSRalf Baechle #define PT_MIPS_REGINFO 0x70000000
36384740dcSRalf Baechle #define PT_MIPS_RTPROC 0x70000001
37384740dcSRalf Baechle #define PT_MIPS_OPTIONS 0x70000002
386cd96229SPaul Burton #define PT_MIPS_ABIFLAGS 0x70000003
39384740dcSRalf Baechle
40384740dcSRalf Baechle /* Flags in the e_flags field of the header */
41384740dcSRalf Baechle #define EF_MIPS_NOREORDER 0x00000001
42384740dcSRalf Baechle #define EF_MIPS_PIC 0x00000002
43384740dcSRalf Baechle #define EF_MIPS_CPIC 0x00000004
44384740dcSRalf Baechle #define EF_MIPS_ABI2 0x00000020
45384740dcSRalf Baechle #define EF_MIPS_OPTIONS_FIRST 0x00000080
46384740dcSRalf Baechle #define EF_MIPS_32BITMODE 0x00000100
47597ce172SPaul Burton #define EF_MIPS_FP64 0x00000200
482b5e869eSMaciej W. Rozycki #define EF_MIPS_NAN2008 0x00000400
49384740dcSRalf Baechle #define EF_MIPS_ABI 0x0000f000
50384740dcSRalf Baechle #define EF_MIPS_ARCH 0xf0000000
51384740dcSRalf Baechle
52384740dcSRalf Baechle #define DT_MIPS_RLD_VERSION 0x70000001
53384740dcSRalf Baechle #define DT_MIPS_TIME_STAMP 0x70000002
54384740dcSRalf Baechle #define DT_MIPS_ICHECKSUM 0x70000003
55384740dcSRalf Baechle #define DT_MIPS_IVERSION 0x70000004
56384740dcSRalf Baechle #define DT_MIPS_FLAGS 0x70000005
57384740dcSRalf Baechle #define RHF_NONE 0x00000000
58384740dcSRalf Baechle #define RHF_HARDWAY 0x00000001
59384740dcSRalf Baechle #define RHF_NOTPOT 0x00000002
60384740dcSRalf Baechle #define RHF_SGI_ONLY 0x00000010
61384740dcSRalf Baechle #define DT_MIPS_BASE_ADDRESS 0x70000006
62384740dcSRalf Baechle #define DT_MIPS_CONFLICT 0x70000008
63384740dcSRalf Baechle #define DT_MIPS_LIBLIST 0x70000009
64384740dcSRalf Baechle #define DT_MIPS_LOCAL_GOTNO 0x7000000a
65384740dcSRalf Baechle #define DT_MIPS_CONFLICTNO 0x7000000b
66384740dcSRalf Baechle #define DT_MIPS_LIBLISTNO 0x70000010
67384740dcSRalf Baechle #define DT_MIPS_SYMTABNO 0x70000011
68384740dcSRalf Baechle #define DT_MIPS_UNREFEXTNO 0x70000012
69384740dcSRalf Baechle #define DT_MIPS_GOTSYM 0x70000013
70384740dcSRalf Baechle #define DT_MIPS_HIPAGENO 0x70000014
71384740dcSRalf Baechle #define DT_MIPS_RLD_MAP 0x70000016
72384740dcSRalf Baechle
73384740dcSRalf Baechle #define R_MIPS_NONE 0
74384740dcSRalf Baechle #define R_MIPS_16 1
75384740dcSRalf Baechle #define R_MIPS_32 2
76384740dcSRalf Baechle #define R_MIPS_REL32 3
77384740dcSRalf Baechle #define R_MIPS_26 4
78384740dcSRalf Baechle #define R_MIPS_HI16 5
79384740dcSRalf Baechle #define R_MIPS_LO16 6
80384740dcSRalf Baechle #define R_MIPS_GPREL16 7
81384740dcSRalf Baechle #define R_MIPS_LITERAL 8
82384740dcSRalf Baechle #define R_MIPS_GOT16 9
83384740dcSRalf Baechle #define R_MIPS_PC16 10
84384740dcSRalf Baechle #define R_MIPS_CALL16 11
85384740dcSRalf Baechle #define R_MIPS_GPREL32 12
86384740dcSRalf Baechle /* The remaining relocs are defined on Irix, although they are not
87384740dcSRalf Baechle in the MIPS ELF ABI. */
88384740dcSRalf Baechle #define R_MIPS_UNUSED1 13
89384740dcSRalf Baechle #define R_MIPS_UNUSED2 14
90384740dcSRalf Baechle #define R_MIPS_UNUSED3 15
91384740dcSRalf Baechle #define R_MIPS_SHIFT5 16
92384740dcSRalf Baechle #define R_MIPS_SHIFT6 17
93384740dcSRalf Baechle #define R_MIPS_64 18
94384740dcSRalf Baechle #define R_MIPS_GOT_DISP 19
95384740dcSRalf Baechle #define R_MIPS_GOT_PAGE 20
96384740dcSRalf Baechle #define R_MIPS_GOT_OFST 21
97384740dcSRalf Baechle /*
98384740dcSRalf Baechle * The following two relocation types are specified in the MIPS ABI
99384740dcSRalf Baechle * conformance guide version 1.2 but not yet in the psABI.
100384740dcSRalf Baechle */
101384740dcSRalf Baechle #define R_MIPS_GOTHI16 22
102384740dcSRalf Baechle #define R_MIPS_GOTLO16 23
103384740dcSRalf Baechle #define R_MIPS_SUB 24
104384740dcSRalf Baechle #define R_MIPS_INSERT_A 25
105384740dcSRalf Baechle #define R_MIPS_INSERT_B 26
106384740dcSRalf Baechle #define R_MIPS_DELETE 27
107384740dcSRalf Baechle #define R_MIPS_HIGHER 28
108384740dcSRalf Baechle #define R_MIPS_HIGHEST 29
109384740dcSRalf Baechle /*
110384740dcSRalf Baechle * The following two relocation types are specified in the MIPS ABI
111384740dcSRalf Baechle * conformance guide version 1.2 but not yet in the psABI.
112384740dcSRalf Baechle */
113384740dcSRalf Baechle #define R_MIPS_CALLHI16 30
114384740dcSRalf Baechle #define R_MIPS_CALLLO16 31
115384740dcSRalf Baechle /*
116ad8319eaSPaul Burton * Introduced for MIPSr6.
117ad8319eaSPaul Burton */
118ad8319eaSPaul Burton #define R_MIPS_PC21_S2 60
119ad8319eaSPaul Burton #define R_MIPS_PC26_S2 61
120ad8319eaSPaul Burton /*
121384740dcSRalf Baechle * This range is reserved for vendor specific relocations.
122384740dcSRalf Baechle */
123384740dcSRalf Baechle #define R_MIPS_LOVENDOR 100
124384740dcSRalf Baechle #define R_MIPS_HIVENDOR 127
125384740dcSRalf Baechle
126384740dcSRalf Baechle #define SHN_MIPS_ACCOMON 0xff00 /* Allocated common symbols */
127384740dcSRalf Baechle #define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */
128384740dcSRalf Baechle #define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */
129384740dcSRalf Baechle #define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */
130384740dcSRalf Baechle #define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */
131384740dcSRalf Baechle
132384740dcSRalf Baechle #define SHT_MIPS_LIST 0x70000000
133384740dcSRalf Baechle #define SHT_MIPS_CONFLICT 0x70000002
134384740dcSRalf Baechle #define SHT_MIPS_GPTAB 0x70000003
135384740dcSRalf Baechle #define SHT_MIPS_UCODE 0x70000004
136384740dcSRalf Baechle #define SHT_MIPS_DEBUG 0x70000005
137384740dcSRalf Baechle #define SHT_MIPS_REGINFO 0x70000006
138384740dcSRalf Baechle #define SHT_MIPS_PACKAGE 0x70000007
139384740dcSRalf Baechle #define SHT_MIPS_PACKSYM 0x70000008
140384740dcSRalf Baechle #define SHT_MIPS_RELD 0x70000009
141384740dcSRalf Baechle #define SHT_MIPS_IFACE 0x7000000b
142384740dcSRalf Baechle #define SHT_MIPS_CONTENT 0x7000000c
143384740dcSRalf Baechle #define SHT_MIPS_OPTIONS 0x7000000d
144384740dcSRalf Baechle #define SHT_MIPS_SHDR 0x70000010
145384740dcSRalf Baechle #define SHT_MIPS_FDESC 0x70000011
146384740dcSRalf Baechle #define SHT_MIPS_EXTSYM 0x70000012
147384740dcSRalf Baechle #define SHT_MIPS_DENSE 0x70000013
148384740dcSRalf Baechle #define SHT_MIPS_PDESC 0x70000014
149384740dcSRalf Baechle #define SHT_MIPS_LOCSYM 0x70000015
150384740dcSRalf Baechle #define SHT_MIPS_AUXSYM 0x70000016
151384740dcSRalf Baechle #define SHT_MIPS_OPTSYM 0x70000017
152384740dcSRalf Baechle #define SHT_MIPS_LOCSTR 0x70000018
153384740dcSRalf Baechle #define SHT_MIPS_LINE 0x70000019
154384740dcSRalf Baechle #define SHT_MIPS_RFDESC 0x7000001a
155384740dcSRalf Baechle #define SHT_MIPS_DELTASYM 0x7000001b
156384740dcSRalf Baechle #define SHT_MIPS_DELTAINST 0x7000001c
157384740dcSRalf Baechle #define SHT_MIPS_DELTACLASS 0x7000001d
158384740dcSRalf Baechle #define SHT_MIPS_DWARF 0x7000001e
159384740dcSRalf Baechle #define SHT_MIPS_DELTADECL 0x7000001f
160384740dcSRalf Baechle #define SHT_MIPS_SYMBOL_LIB 0x70000020
161384740dcSRalf Baechle #define SHT_MIPS_EVENTS 0x70000021
162384740dcSRalf Baechle #define SHT_MIPS_TRANSLATE 0x70000022
163384740dcSRalf Baechle #define SHT_MIPS_PIXIE 0x70000023
164384740dcSRalf Baechle #define SHT_MIPS_XLATE 0x70000024
165384740dcSRalf Baechle #define SHT_MIPS_XLATE_DEBUG 0x70000025
166384740dcSRalf Baechle #define SHT_MIPS_WHIRL 0x70000026
167384740dcSRalf Baechle #define SHT_MIPS_EH_REGION 0x70000027
168384740dcSRalf Baechle #define SHT_MIPS_XLATE_OLD 0x70000028
169384740dcSRalf Baechle #define SHT_MIPS_PDR_EXCEPTION 0x70000029
170384740dcSRalf Baechle
171384740dcSRalf Baechle #define SHF_MIPS_GPREL 0x10000000
172384740dcSRalf Baechle #define SHF_MIPS_MERGE 0x20000000
173384740dcSRalf Baechle #define SHF_MIPS_ADDR 0x40000000
174384740dcSRalf Baechle #define SHF_MIPS_STRING 0x80000000
175384740dcSRalf Baechle #define SHF_MIPS_NOSTRIP 0x08000000
176384740dcSRalf Baechle #define SHF_MIPS_LOCAL 0x04000000
177384740dcSRalf Baechle #define SHF_MIPS_NAMES 0x02000000
178384740dcSRalf Baechle #define SHF_MIPS_NODUPES 0x01000000
179384740dcSRalf Baechle
180de704161SMaciej W. Rozycki #define MIPS_ABI_FP_ANY 0 /* FP ABI doesn't matter */
181de704161SMaciej W. Rozycki #define MIPS_ABI_FP_DOUBLE 1 /* -mdouble-float */
182de704161SMaciej W. Rozycki #define MIPS_ABI_FP_SINGLE 2 /* -msingle-float */
183de704161SMaciej W. Rozycki #define MIPS_ABI_FP_SOFT 3 /* -msoft-float */
184de704161SMaciej W. Rozycki #define MIPS_ABI_FP_OLD_64 4 /* -mips32r2 -mfp64 */
185de704161SMaciej W. Rozycki #define MIPS_ABI_FP_XX 5 /* -mfpxx */
186de704161SMaciej W. Rozycki #define MIPS_ABI_FP_64 6 /* -mips32r2 -mfp64 */
187de704161SMaciej W. Rozycki #define MIPS_ABI_FP_64A 7 /* -mips32r2 -mfp64 -mno-odd-spreg */
188384740dcSRalf Baechle
1896cd96229SPaul Burton struct mips_elf_abiflags_v0 {
1906cd96229SPaul Burton uint16_t version; /* Version of flags structure */
1916cd96229SPaul Burton uint8_t isa_level; /* The level of the ISA: 1-5, 32, 64 */
1926cd96229SPaul Burton uint8_t isa_rev; /* The revision of ISA: 0 for MIPS V and below,
1936cd96229SPaul Burton 1-n otherwise */
1946cd96229SPaul Burton uint8_t gpr_size; /* The size of general purpose registers */
1956cd96229SPaul Burton uint8_t cpr1_size; /* The size of co-processor 1 registers */
1966cd96229SPaul Burton uint8_t cpr2_size; /* The size of co-processor 2 registers */
1976cd96229SPaul Burton uint8_t fp_abi; /* The floating-point ABI */
1986cd96229SPaul Burton uint32_t isa_ext; /* Mask of processor-specific extensions */
1996cd96229SPaul Burton uint32_t ases; /* Mask of ASEs used */
2006cd96229SPaul Burton uint32_t flags1; /* Mask of general flags */
2016cd96229SPaul Burton uint32_t flags2;
2026cd96229SPaul Burton };
2036cd96229SPaul Burton
204de704161SMaciej W. Rozycki /* ELF register definitions */
205de704161SMaciej W. Rozycki #define ELF_NGREG 45
206de704161SMaciej W. Rozycki #define ELF_NFPREG 33
207de704161SMaciej W. Rozycki
208de704161SMaciej W. Rozycki typedef unsigned long elf_greg_t;
209de704161SMaciej W. Rozycki typedef elf_greg_t elf_gregset_t[ELF_NGREG];
210de704161SMaciej W. Rozycki
211de704161SMaciej W. Rozycki typedef double elf_fpreg_t;
212de704161SMaciej W. Rozycki typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2136cd96229SPaul Burton
21408c941bfSMarcin Nowakowski void mips_dump_regs32(u32 *uregs, const struct pt_regs *regs);
21508c941bfSMarcin Nowakowski void mips_dump_regs64(u64 *uregs, const struct pt_regs *regs);
21608c941bfSMarcin Nowakowski
217384740dcSRalf Baechle #ifdef CONFIG_32BIT
218597ce172SPaul Burton /*
219384740dcSRalf Baechle * This is used to ensure we don't load something for the wrong architecture.
220384740dcSRalf Baechle */
221*0bb87f05SAl Viro #define elf_check_arch elf32_check_arch
222384740dcSRalf Baechle
223384740dcSRalf Baechle /*
224384740dcSRalf Baechle * These are used to set parameters in the core dumps.
225384740dcSRalf Baechle */
226384740dcSRalf Baechle #define ELF_CLASS ELFCLASS32
227384740dcSRalf Baechle
22839a3cb27SMarcin Nowakowski #define ELF_CORE_COPY_REGS(dest, regs) \
22939a3cb27SMarcin Nowakowski mips_dump_regs32((u32 *)&(dest), (regs));
23039a3cb27SMarcin Nowakowski
231384740dcSRalf Baechle #endif /* CONFIG_32BIT */
232384740dcSRalf Baechle
233384740dcSRalf Baechle #ifdef CONFIG_64BIT
234384740dcSRalf Baechle /*
235384740dcSRalf Baechle * This is used to ensure we don't load something for the wrong architecture.
236384740dcSRalf Baechle */
237*0bb87f05SAl Viro #define elf_check_arch elf64_check_arch
238*0bb87f05SAl Viro #define compat_elf_check_arch elf32_check_arch
239384740dcSRalf Baechle
240384740dcSRalf Baechle /*
241384740dcSRalf Baechle * These are used to set parameters in the core dumps.
242384740dcSRalf Baechle */
243384740dcSRalf Baechle #define ELF_CLASS ELFCLASS64
244384740dcSRalf Baechle
24539a3cb27SMarcin Nowakowski #define ELF_CORE_COPY_REGS(dest, regs) \
24639a3cb27SMarcin Nowakowski mips_dump_regs64((u64 *)&(dest), (regs));
24739a3cb27SMarcin Nowakowski
248384740dcSRalf Baechle #endif /* CONFIG_64BIT */
249384740dcSRalf Baechle
250384740dcSRalf Baechle /*
251384740dcSRalf Baechle * These are used to set parameters in the core dumps.
252384740dcSRalf Baechle */
253384740dcSRalf Baechle #ifdef __MIPSEB__
254384740dcSRalf Baechle #define ELF_DATA ELFDATA2MSB
25508d9d1c4SDavid Daney #elif defined(__MIPSEL__)
256384740dcSRalf Baechle #define ELF_DATA ELFDATA2LSB
257384740dcSRalf Baechle #endif
258384740dcSRalf Baechle #define ELF_ARCH EM_MIPS
259384740dcSRalf Baechle
2604a60ad51SMaciej W. Rozycki /*
2614a60ad51SMaciej W. Rozycki * In order to be sure that we don't attempt to execute an O32 binary which
2624a60ad51SMaciej W. Rozycki * requires 64 bit FP (FR=1) on a system which does not support it we refuse
2634a60ad51SMaciej W. Rozycki * to execute any binary which has bits specified by the following macro set
2644a60ad51SMaciej W. Rozycki * in its ELF header flags.
2654a60ad51SMaciej W. Rozycki */
2664a60ad51SMaciej W. Rozycki #ifdef CONFIG_MIPS_O32_FP64_SUPPORT
2674a60ad51SMaciej W. Rozycki # define __MIPS_O32_FP64_MUST_BE_ZERO 0
2684a60ad51SMaciej W. Rozycki #else
2694a60ad51SMaciej W. Rozycki # define __MIPS_O32_FP64_MUST_BE_ZERO EF_MIPS_FP64
2704a60ad51SMaciej W. Rozycki #endif
2714a60ad51SMaciej W. Rozycki
272f4d3d504SDaniel Wagner #define mips_elf_check_machine(x) ((x)->e_machine == EM_MIPS)
273f4d3d504SDaniel Wagner
274f4d3d504SDaniel Wagner #define vmcore_elf32_check_arch mips_elf_check_machine
275f4d3d504SDaniel Wagner #define vmcore_elf64_check_arch mips_elf_check_machine
276f4d3d504SDaniel Wagner
277c9babb19SMaciej W. Rozycki /*
278*0bb87f05SAl Viro * Return non-zero if HDR identifies an o32 or n32 ELF binary.
279c9babb19SMaciej W. Rozycki */
280*0bb87f05SAl Viro #define elf32_check_arch(hdr) \
281c9babb19SMaciej W. Rozycki ({ \
282c9babb19SMaciej W. Rozycki int __res = 1; \
283c9babb19SMaciej W. Rozycki struct elfhdr *__h = (hdr); \
284c9babb19SMaciej W. Rozycki \
285c9babb19SMaciej W. Rozycki if (!mips_elf_check_machine(__h)) \
286c9babb19SMaciej W. Rozycki __res = 0; \
287c9babb19SMaciej W. Rozycki if (__h->e_ident[EI_CLASS] != ELFCLASS32) \
288c9babb19SMaciej W. Rozycki __res = 0; \
289*0bb87f05SAl Viro if ((__h->e_flags & EF_MIPS_ABI2) != 0) { \
290*0bb87f05SAl Viro if (!IS_ENABLED(CONFIG_MIPS32_N32) || \
291*0bb87f05SAl Viro (__h->e_flags & EF_MIPS_ABI)) \
292*0bb87f05SAl Viro __res = 0; \
293*0bb87f05SAl Viro } else { \
294*0bb87f05SAl Viro if (IS_ENABLED(CONFIG_64BIT) && !IS_ENABLED(CONFIG_MIPS32_O32)) \
295c9babb19SMaciej W. Rozycki __res = 0; \
296c9babb19SMaciej W. Rozycki if (((__h->e_flags & EF_MIPS_ABI) != 0) && \
297c9babb19SMaciej W. Rozycki ((__h->e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32)) \
298c9babb19SMaciej W. Rozycki __res = 0; \
299c9babb19SMaciej W. Rozycki if (__h->e_flags & __MIPS_O32_FP64_MUST_BE_ZERO) \
300c9babb19SMaciej W. Rozycki __res = 0; \
301*0bb87f05SAl Viro } \
302c9babb19SMaciej W. Rozycki __res; \
303c9babb19SMaciej W. Rozycki })
304c9babb19SMaciej W. Rozycki
305c9babb19SMaciej W. Rozycki /*
306c9babb19SMaciej W. Rozycki * Return non-zero if HDR identifies an n64 ELF binary.
307c9babb19SMaciej W. Rozycki */
308*0bb87f05SAl Viro #define elf64_check_arch(hdr) \
309c9babb19SMaciej W. Rozycki ({ \
310c9babb19SMaciej W. Rozycki int __res = 1; \
311c9babb19SMaciej W. Rozycki struct elfhdr *__h = (hdr); \
312c9babb19SMaciej W. Rozycki \
313c9babb19SMaciej W. Rozycki if (!mips_elf_check_machine(__h)) \
314c9babb19SMaciej W. Rozycki __res = 0; \
315c9babb19SMaciej W. Rozycki if (__h->e_ident[EI_CLASS] != ELFCLASS64) \
316c9babb19SMaciej W. Rozycki __res = 0; \
317c9babb19SMaciej W. Rozycki \
318c9babb19SMaciej W. Rozycki __res; \
319c9babb19SMaciej W. Rozycki })
320c9babb19SMaciej W. Rozycki
321384740dcSRalf Baechle struct mips_abi;
322384740dcSRalf Baechle
323384740dcSRalf Baechle extern struct mips_abi mips_abi;
324384740dcSRalf Baechle extern struct mips_abi mips_abi_32;
325384740dcSRalf Baechle extern struct mips_abi mips_abi_n32;
326384740dcSRalf Baechle
327384740dcSRalf Baechle #ifdef CONFIG_32BIT
328384740dcSRalf Baechle
32990cee759SPaul Burton #define SET_PERSONALITY2(ex, state) \
330384740dcSRalf Baechle do { \
33148f8eaeeSMarkos Chandras clear_thread_flag(TIF_HYBRID_FPREGS); \
33248f8eaeeSMarkos Chandras set_thread_flag(TIF_32BIT_FPREGS); \
33348f8eaeeSMarkos Chandras \
334384740dcSRalf Baechle current->thread.abi = &mips_abi; \
3359b26616cSMaciej W. Rozycki \
3362e5832abSMaciej W. Rozycki mips_set_personality_fp(state); \
3372b5e869eSMaciej W. Rozycki mips_set_personality_nan(state); \
3382e5832abSMaciej W. Rozycki \
3392e5832abSMaciej W. Rozycki if (personality(current->personality) != PER_LINUX) \
3402e5832abSMaciej W. Rozycki set_personality(PER_LINUX); \
341384740dcSRalf Baechle } while (0)
342384740dcSRalf Baechle
343384740dcSRalf Baechle #endif /* CONFIG_32BIT */
344384740dcSRalf Baechle
345384740dcSRalf Baechle #ifdef CONFIG_64BIT
346384740dcSRalf Baechle
347384740dcSRalf Baechle #ifdef CONFIG_MIPS32_N32
348384740dcSRalf Baechle #define __SET_PERSONALITY32_N32() \
349384740dcSRalf Baechle do { \
350384740dcSRalf Baechle set_thread_flag(TIF_32BIT_ADDR); \
3512e5832abSMaciej W. Rozycki \
352384740dcSRalf Baechle current->thread.abi = &mips_abi_n32; \
353384740dcSRalf Baechle } while (0)
354384740dcSRalf Baechle #else
355384740dcSRalf Baechle #define __SET_PERSONALITY32_N32() \
356384740dcSRalf Baechle do { } while (0)
357384740dcSRalf Baechle #endif
358384740dcSRalf Baechle
359384740dcSRalf Baechle #ifdef CONFIG_MIPS32_O32
36090cee759SPaul Burton #define __SET_PERSONALITY32_O32(ex, state) \
361384740dcSRalf Baechle do { \
362384740dcSRalf Baechle set_thread_flag(TIF_32BIT_REGS); \
363384740dcSRalf Baechle set_thread_flag(TIF_32BIT_ADDR); \
36448f8eaeeSMarkos Chandras clear_thread_flag(TIF_HYBRID_FPREGS); \
36548f8eaeeSMarkos Chandras set_thread_flag(TIF_32BIT_FPREGS); \
366597ce172SPaul Burton \
367384740dcSRalf Baechle current->thread.abi = &mips_abi_32; \
3682e5832abSMaciej W. Rozycki \
3692e5832abSMaciej W. Rozycki mips_set_personality_fp(state); \
370384740dcSRalf Baechle } while (0)
371384740dcSRalf Baechle #else
37290cee759SPaul Burton #define __SET_PERSONALITY32_O32(ex, state) \
373384740dcSRalf Baechle do { } while (0)
374384740dcSRalf Baechle #endif
375384740dcSRalf Baechle
376384740dcSRalf Baechle #ifdef CONFIG_MIPS32_COMPAT
37790cee759SPaul Burton #define __SET_PERSONALITY32(ex, state) \
378384740dcSRalf Baechle do { \
379384740dcSRalf Baechle if ((((ex).e_flags & EF_MIPS_ABI2) != 0) && \
380384740dcSRalf Baechle ((ex).e_flags & EF_MIPS_ABI) == 0) \
381384740dcSRalf Baechle __SET_PERSONALITY32_N32(); \
382384740dcSRalf Baechle else \
38390cee759SPaul Burton __SET_PERSONALITY32_O32(ex, state); \
384384740dcSRalf Baechle } while (0)
385384740dcSRalf Baechle #else
38690cee759SPaul Burton #define __SET_PERSONALITY32(ex, state) do { } while (0)
387384740dcSRalf Baechle #endif
388384740dcSRalf Baechle
38990cee759SPaul Burton #define SET_PERSONALITY2(ex, state) \
390384740dcSRalf Baechle do { \
3911c0d52b9SDavid Daney unsigned int p; \
3921c0d52b9SDavid Daney \
393384740dcSRalf Baechle clear_thread_flag(TIF_32BIT_REGS); \
394597ce172SPaul Burton clear_thread_flag(TIF_32BIT_FPREGS); \
3954227a2d4SPaul Burton clear_thread_flag(TIF_HYBRID_FPREGS); \
396384740dcSRalf Baechle clear_thread_flag(TIF_32BIT_ADDR); \
39767d0662cSTiezhu Yang current->personality &= ~READ_IMPLIES_EXEC; \
398384740dcSRalf Baechle \
399384740dcSRalf Baechle if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
40090cee759SPaul Burton __SET_PERSONALITY32(ex, state); \
401384740dcSRalf Baechle else \
402384740dcSRalf Baechle current->thread.abi = &mips_abi; \
403384740dcSRalf Baechle \
4042b5e869eSMaciej W. Rozycki mips_set_personality_nan(state); \
4059b26616cSMaciej W. Rozycki \
4061c0d52b9SDavid Daney p = personality(current->personality); \
4071c0d52b9SDavid Daney if (p != PER_LINUX32 && p != PER_LINUX) \
408384740dcSRalf Baechle set_personality(PER_LINUX); \
409384740dcSRalf Baechle } while (0)
410384740dcSRalf Baechle
411384740dcSRalf Baechle #endif /* CONFIG_64BIT */
412384740dcSRalf Baechle
4136a9c001bSRalf Baechle #define CORE_DUMP_USE_REGSET
414384740dcSRalf Baechle #define ELF_EXEC_PAGESIZE PAGE_SIZE
415384740dcSRalf Baechle
416384740dcSRalf Baechle /* This yields a mask that user programs can use to figure out what
417384740dcSRalf Baechle instruction set this cpu supports. This could be done in userspace,
418384740dcSRalf Baechle but it's not easy, and we've already done it here. */
419384740dcSRalf Baechle
420e14f1db7SPaul Burton #define ELF_HWCAP (elf_hwcap)
421e14f1db7SPaul Burton extern unsigned int elf_hwcap;
422e14f1db7SPaul Burton #include <asm/hwcap.h>
423384740dcSRalf Baechle
424874fd3b5SDavid Daney /*
425874fd3b5SDavid Daney * This yields a string that ld.so will use to load implementation
426874fd3b5SDavid Daney * specific libraries for optimization. This is more specific in
427874fd3b5SDavid Daney * intent than poking at uname or /proc/cpuinfo.
428874fd3b5SDavid Daney */
429384740dcSRalf Baechle
430874fd3b5SDavid Daney #define ELF_PLATFORM __elf_platform
431874fd3b5SDavid Daney extern const char *__elf_platform;
432384740dcSRalf Baechle
433e585b768SYunQiang Su #define ELF_BASE_PLATFORM __elf_base_platform
434e585b768SYunQiang Su extern const char *__elf_base_platform;
435e585b768SYunQiang Su
436384740dcSRalf Baechle /*
437384740dcSRalf Baechle * See comments in asm-alpha/elf.h, this is the same thing
438384740dcSRalf Baechle * on the MIPS.
439384740dcSRalf Baechle */
440384740dcSRalf Baechle #define ELF_PLAT_INIT(_r, load_addr) do { \
441384740dcSRalf Baechle _r->regs[1] = _r->regs[2] = _r->regs[3] = _r->regs[4] = 0; \
442384740dcSRalf Baechle _r->regs[5] = _r->regs[6] = _r->regs[7] = _r->regs[8] = 0; \
443384740dcSRalf Baechle _r->regs[9] = _r->regs[10] = _r->regs[11] = _r->regs[12] = 0; \
444384740dcSRalf Baechle _r->regs[13] = _r->regs[14] = _r->regs[15] = _r->regs[16] = 0; \
445384740dcSRalf Baechle _r->regs[17] = _r->regs[18] = _r->regs[19] = _r->regs[20] = 0; \
446384740dcSRalf Baechle _r->regs[21] = _r->regs[22] = _r->regs[23] = _r->regs[24] = 0; \
447384740dcSRalf Baechle _r->regs[25] = _r->regs[26] = _r->regs[27] = _r->regs[28] = 0; \
448384740dcSRalf Baechle _r->regs[30] = _r->regs[31] = 0; \
449384740dcSRalf Baechle } while (0)
450384740dcSRalf Baechle
451384740dcSRalf Baechle /* This is the location that an ET_DYN program is loaded if exec'ed. Typical
452384740dcSRalf Baechle use of this is to invoke "./ld.so someprog" to test out a new version of
453384740dcSRalf Baechle the loader. We need to make sure that it is out of the way of the program
454384740dcSRalf Baechle that it will "exec", and that there is sufficient room for the brk. */
455384740dcSRalf Baechle
456384740dcSRalf Baechle #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
457384740dcSRalf Baechle
458233b2ca1SJames Hogan /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
459ebb5e78cSAlex Smith #define ARCH_DLINFO \
460ebb5e78cSAlex Smith do { \
461ebb5e78cSAlex Smith NEW_AUX_ENT(AT_SYSINFO_EHDR, \
462ebb5e78cSAlex Smith (unsigned long)current->mm->context.vdso); \
463ebb5e78cSAlex Smith } while (0)
464ebb5e78cSAlex Smith
465c52d0d30SDavid Daney #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
466c52d0d30SDavid Daney struct linux_binprm;
467c52d0d30SDavid Daney extern int arch_setup_additional_pages(struct linux_binprm *bprm,
468c52d0d30SDavid Daney int uses_interp);
469652b14aaSDavid Daney
470ea6a3737SPaul Burton #ifdef CONFIG_MIPS_FP_SUPPORT
471ea6a3737SPaul Burton
47290cee759SPaul Burton struct arch_elf_state {
4732b5e869eSMaciej W. Rozycki int nan_2008;
47490cee759SPaul Burton int fp_abi;
47590cee759SPaul Burton int interp_fp_abi;
47646490b57SMarkos Chandras int overall_fp_mode;
47790cee759SPaul Burton };
47890cee759SPaul Burton
47946490b57SMarkos Chandras #define MIPS_ABI_FP_UNKNOWN (-1) /* Unknown FP ABI (kernel internal) */
48046490b57SMarkos Chandras
48190cee759SPaul Burton #define INIT_ARCH_ELF_STATE { \
4822b5e869eSMaciej W. Rozycki .nan_2008 = -1, \
48346490b57SMarkos Chandras .fp_abi = MIPS_ABI_FP_UNKNOWN, \
48446490b57SMarkos Chandras .interp_fp_abi = MIPS_ABI_FP_UNKNOWN, \
48546490b57SMarkos Chandras .overall_fp_mode = -1, \
48690cee759SPaul Burton }
48790cee759SPaul Burton
48890cee759SPaul Burton extern int arch_elf_pt_proc(void *ehdr, void *phdr, struct file *elf,
48990cee759SPaul Burton bool is_interp, struct arch_elf_state *state);
49090cee759SPaul Burton
491eb4bc076SMaciej W. Rozycki extern int arch_check_elf(void *ehdr, bool has_interpreter, void *interp_ehdr,
49290cee759SPaul Burton struct arch_elf_state *state);
49390cee759SPaul Burton
494ea6a3737SPaul Burton /* Whether to accept legacy-NaN and 2008-NaN user binaries. */
495ea6a3737SPaul Burton extern bool mips_use_nan_legacy;
496ea6a3737SPaul Burton extern bool mips_use_nan_2008;
497ea6a3737SPaul Burton
4982b5e869eSMaciej W. Rozycki extern void mips_set_personality_nan(struct arch_elf_state *state);
49990cee759SPaul Burton extern void mips_set_personality_fp(struct arch_elf_state *state);
50090cee759SPaul Burton
501ea6a3737SPaul Burton #else /* !CONFIG_MIPS_FP_SUPPORT */
502ea6a3737SPaul Burton
503ea6a3737SPaul Burton struct arch_elf_state;
504ea6a3737SPaul Burton
mips_set_personality_nan(struct arch_elf_state * state)505ea6a3737SPaul Burton static inline void mips_set_personality_nan(struct arch_elf_state *state)
506ea6a3737SPaul Burton {
507ea6a3737SPaul Burton /* no-op */
508ea6a3737SPaul Burton }
509ea6a3737SPaul Burton
mips_set_personality_fp(struct arch_elf_state * state)510ea6a3737SPaul Burton static inline void mips_set_personality_fp(struct arch_elf_state *state)
511ea6a3737SPaul Burton {
512ea6a3737SPaul Burton /* no-op */
513ea6a3737SPaul Burton }
514ea6a3737SPaul Burton
515ea6a3737SPaul Burton #endif /* !CONFIG_MIPS_FP_SUPPORT */
516ea6a3737SPaul Burton
5171a770b85SPaul Burton #define elf_read_implies_exec(ex, stk) mips_elf_read_implies_exec(&(ex), stk)
5181a770b85SPaul Burton extern int mips_elf_read_implies_exec(void *elf_ex, int exstack);
5191a770b85SPaul Burton
520384740dcSRalf Baechle #endif /* _ASM_ELF_H */
521