162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 362306a36Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 462306a36Sopenharmony_ci * for more details. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Much of this is taken from binutils and GNU libc ... 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci#ifndef _ASM_ELF_H 962306a36Sopenharmony_ci#define _ASM_ELF_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/auxvec.h> 1262306a36Sopenharmony_ci#include <linux/fs.h> 1362306a36Sopenharmony_ci#include <linux/mm_types.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <uapi/linux/elf.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include <asm/current.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* ELF header e_flags defines. */ 2062306a36Sopenharmony_ci/* MIPS architecture level. */ 2162306a36Sopenharmony_ci#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ 2262306a36Sopenharmony_ci#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ 2362306a36Sopenharmony_ci#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ 2462306a36Sopenharmony_ci#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ 2562306a36Sopenharmony_ci#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ 2662306a36Sopenharmony_ci#define EF_MIPS_ARCH_32 0x50000000 /* MIPS32 code. */ 2762306a36Sopenharmony_ci#define EF_MIPS_ARCH_64 0x60000000 /* MIPS64 code. */ 2862306a36Sopenharmony_ci#define EF_MIPS_ARCH_32R2 0x70000000 /* MIPS32 R2 code. */ 2962306a36Sopenharmony_ci#define EF_MIPS_ARCH_64R2 0x80000000 /* MIPS64 R2 code. */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci/* The ABI of a file. */ 3262306a36Sopenharmony_ci#define EF_MIPS_ABI_O32 0x00001000 /* O32 ABI. */ 3362306a36Sopenharmony_ci#define EF_MIPS_ABI_O64 0x00002000 /* O32 extended for 64 bit. */ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define PT_MIPS_REGINFO 0x70000000 3662306a36Sopenharmony_ci#define PT_MIPS_RTPROC 0x70000001 3762306a36Sopenharmony_ci#define PT_MIPS_OPTIONS 0x70000002 3862306a36Sopenharmony_ci#define PT_MIPS_ABIFLAGS 0x70000003 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* Flags in the e_flags field of the header */ 4162306a36Sopenharmony_ci#define EF_MIPS_NOREORDER 0x00000001 4262306a36Sopenharmony_ci#define EF_MIPS_PIC 0x00000002 4362306a36Sopenharmony_ci#define EF_MIPS_CPIC 0x00000004 4462306a36Sopenharmony_ci#define EF_MIPS_ABI2 0x00000020 4562306a36Sopenharmony_ci#define EF_MIPS_OPTIONS_FIRST 0x00000080 4662306a36Sopenharmony_ci#define EF_MIPS_32BITMODE 0x00000100 4762306a36Sopenharmony_ci#define EF_MIPS_FP64 0x00000200 4862306a36Sopenharmony_ci#define EF_MIPS_NAN2008 0x00000400 4962306a36Sopenharmony_ci#define EF_MIPS_ABI 0x0000f000 5062306a36Sopenharmony_ci#define EF_MIPS_ARCH 0xf0000000 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define DT_MIPS_RLD_VERSION 0x70000001 5362306a36Sopenharmony_ci#define DT_MIPS_TIME_STAMP 0x70000002 5462306a36Sopenharmony_ci#define DT_MIPS_ICHECKSUM 0x70000003 5562306a36Sopenharmony_ci#define DT_MIPS_IVERSION 0x70000004 5662306a36Sopenharmony_ci#define DT_MIPS_FLAGS 0x70000005 5762306a36Sopenharmony_ci #define RHF_NONE 0x00000000 5862306a36Sopenharmony_ci #define RHF_HARDWAY 0x00000001 5962306a36Sopenharmony_ci #define RHF_NOTPOT 0x00000002 6062306a36Sopenharmony_ci #define RHF_SGI_ONLY 0x00000010 6162306a36Sopenharmony_ci#define DT_MIPS_BASE_ADDRESS 0x70000006 6262306a36Sopenharmony_ci#define DT_MIPS_CONFLICT 0x70000008 6362306a36Sopenharmony_ci#define DT_MIPS_LIBLIST 0x70000009 6462306a36Sopenharmony_ci#define DT_MIPS_LOCAL_GOTNO 0x7000000a 6562306a36Sopenharmony_ci#define DT_MIPS_CONFLICTNO 0x7000000b 6662306a36Sopenharmony_ci#define DT_MIPS_LIBLISTNO 0x70000010 6762306a36Sopenharmony_ci#define DT_MIPS_SYMTABNO 0x70000011 6862306a36Sopenharmony_ci#define DT_MIPS_UNREFEXTNO 0x70000012 6962306a36Sopenharmony_ci#define DT_MIPS_GOTSYM 0x70000013 7062306a36Sopenharmony_ci#define DT_MIPS_HIPAGENO 0x70000014 7162306a36Sopenharmony_ci#define DT_MIPS_RLD_MAP 0x70000016 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#define R_MIPS_NONE 0 7462306a36Sopenharmony_ci#define R_MIPS_16 1 7562306a36Sopenharmony_ci#define R_MIPS_32 2 7662306a36Sopenharmony_ci#define R_MIPS_REL32 3 7762306a36Sopenharmony_ci#define R_MIPS_26 4 7862306a36Sopenharmony_ci#define R_MIPS_HI16 5 7962306a36Sopenharmony_ci#define R_MIPS_LO16 6 8062306a36Sopenharmony_ci#define R_MIPS_GPREL16 7 8162306a36Sopenharmony_ci#define R_MIPS_LITERAL 8 8262306a36Sopenharmony_ci#define R_MIPS_GOT16 9 8362306a36Sopenharmony_ci#define R_MIPS_PC16 10 8462306a36Sopenharmony_ci#define R_MIPS_CALL16 11 8562306a36Sopenharmony_ci#define R_MIPS_GPREL32 12 8662306a36Sopenharmony_ci/* The remaining relocs are defined on Irix, although they are not 8762306a36Sopenharmony_ci in the MIPS ELF ABI. */ 8862306a36Sopenharmony_ci#define R_MIPS_UNUSED1 13 8962306a36Sopenharmony_ci#define R_MIPS_UNUSED2 14 9062306a36Sopenharmony_ci#define R_MIPS_UNUSED3 15 9162306a36Sopenharmony_ci#define R_MIPS_SHIFT5 16 9262306a36Sopenharmony_ci#define R_MIPS_SHIFT6 17 9362306a36Sopenharmony_ci#define R_MIPS_64 18 9462306a36Sopenharmony_ci#define R_MIPS_GOT_DISP 19 9562306a36Sopenharmony_ci#define R_MIPS_GOT_PAGE 20 9662306a36Sopenharmony_ci#define R_MIPS_GOT_OFST 21 9762306a36Sopenharmony_ci/* 9862306a36Sopenharmony_ci * The following two relocation types are specified in the MIPS ABI 9962306a36Sopenharmony_ci * conformance guide version 1.2 but not yet in the psABI. 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_ci#define R_MIPS_GOTHI16 22 10262306a36Sopenharmony_ci#define R_MIPS_GOTLO16 23 10362306a36Sopenharmony_ci#define R_MIPS_SUB 24 10462306a36Sopenharmony_ci#define R_MIPS_INSERT_A 25 10562306a36Sopenharmony_ci#define R_MIPS_INSERT_B 26 10662306a36Sopenharmony_ci#define R_MIPS_DELETE 27 10762306a36Sopenharmony_ci#define R_MIPS_HIGHER 28 10862306a36Sopenharmony_ci#define R_MIPS_HIGHEST 29 10962306a36Sopenharmony_ci/* 11062306a36Sopenharmony_ci * The following two relocation types are specified in the MIPS ABI 11162306a36Sopenharmony_ci * conformance guide version 1.2 but not yet in the psABI. 11262306a36Sopenharmony_ci */ 11362306a36Sopenharmony_ci#define R_MIPS_CALLHI16 30 11462306a36Sopenharmony_ci#define R_MIPS_CALLLO16 31 11562306a36Sopenharmony_ci/* 11662306a36Sopenharmony_ci * Introduced for MIPSr6. 11762306a36Sopenharmony_ci */ 11862306a36Sopenharmony_ci#define R_MIPS_PC21_S2 60 11962306a36Sopenharmony_ci#define R_MIPS_PC26_S2 61 12062306a36Sopenharmony_ci/* 12162306a36Sopenharmony_ci * This range is reserved for vendor specific relocations. 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_ci#define R_MIPS_LOVENDOR 100 12462306a36Sopenharmony_ci#define R_MIPS_HIVENDOR 127 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci#define SHN_MIPS_ACCOMON 0xff00 /* Allocated common symbols */ 12762306a36Sopenharmony_ci#define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */ 12862306a36Sopenharmony_ci#define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */ 12962306a36Sopenharmony_ci#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */ 13062306a36Sopenharmony_ci#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */ 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#define SHT_MIPS_LIST 0x70000000 13362306a36Sopenharmony_ci#define SHT_MIPS_CONFLICT 0x70000002 13462306a36Sopenharmony_ci#define SHT_MIPS_GPTAB 0x70000003 13562306a36Sopenharmony_ci#define SHT_MIPS_UCODE 0x70000004 13662306a36Sopenharmony_ci#define SHT_MIPS_DEBUG 0x70000005 13762306a36Sopenharmony_ci#define SHT_MIPS_REGINFO 0x70000006 13862306a36Sopenharmony_ci#define SHT_MIPS_PACKAGE 0x70000007 13962306a36Sopenharmony_ci#define SHT_MIPS_PACKSYM 0x70000008 14062306a36Sopenharmony_ci#define SHT_MIPS_RELD 0x70000009 14162306a36Sopenharmony_ci#define SHT_MIPS_IFACE 0x7000000b 14262306a36Sopenharmony_ci#define SHT_MIPS_CONTENT 0x7000000c 14362306a36Sopenharmony_ci#define SHT_MIPS_OPTIONS 0x7000000d 14462306a36Sopenharmony_ci#define SHT_MIPS_SHDR 0x70000010 14562306a36Sopenharmony_ci#define SHT_MIPS_FDESC 0x70000011 14662306a36Sopenharmony_ci#define SHT_MIPS_EXTSYM 0x70000012 14762306a36Sopenharmony_ci#define SHT_MIPS_DENSE 0x70000013 14862306a36Sopenharmony_ci#define SHT_MIPS_PDESC 0x70000014 14962306a36Sopenharmony_ci#define SHT_MIPS_LOCSYM 0x70000015 15062306a36Sopenharmony_ci#define SHT_MIPS_AUXSYM 0x70000016 15162306a36Sopenharmony_ci#define SHT_MIPS_OPTSYM 0x70000017 15262306a36Sopenharmony_ci#define SHT_MIPS_LOCSTR 0x70000018 15362306a36Sopenharmony_ci#define SHT_MIPS_LINE 0x70000019 15462306a36Sopenharmony_ci#define SHT_MIPS_RFDESC 0x7000001a 15562306a36Sopenharmony_ci#define SHT_MIPS_DELTASYM 0x7000001b 15662306a36Sopenharmony_ci#define SHT_MIPS_DELTAINST 0x7000001c 15762306a36Sopenharmony_ci#define SHT_MIPS_DELTACLASS 0x7000001d 15862306a36Sopenharmony_ci#define SHT_MIPS_DWARF 0x7000001e 15962306a36Sopenharmony_ci#define SHT_MIPS_DELTADECL 0x7000001f 16062306a36Sopenharmony_ci#define SHT_MIPS_SYMBOL_LIB 0x70000020 16162306a36Sopenharmony_ci#define SHT_MIPS_EVENTS 0x70000021 16262306a36Sopenharmony_ci#define SHT_MIPS_TRANSLATE 0x70000022 16362306a36Sopenharmony_ci#define SHT_MIPS_PIXIE 0x70000023 16462306a36Sopenharmony_ci#define SHT_MIPS_XLATE 0x70000024 16562306a36Sopenharmony_ci#define SHT_MIPS_XLATE_DEBUG 0x70000025 16662306a36Sopenharmony_ci#define SHT_MIPS_WHIRL 0x70000026 16762306a36Sopenharmony_ci#define SHT_MIPS_EH_REGION 0x70000027 16862306a36Sopenharmony_ci#define SHT_MIPS_XLATE_OLD 0x70000028 16962306a36Sopenharmony_ci#define SHT_MIPS_PDR_EXCEPTION 0x70000029 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci#define SHF_MIPS_GPREL 0x10000000 17262306a36Sopenharmony_ci#define SHF_MIPS_MERGE 0x20000000 17362306a36Sopenharmony_ci#define SHF_MIPS_ADDR 0x40000000 17462306a36Sopenharmony_ci#define SHF_MIPS_STRING 0x80000000 17562306a36Sopenharmony_ci#define SHF_MIPS_NOSTRIP 0x08000000 17662306a36Sopenharmony_ci#define SHF_MIPS_LOCAL 0x04000000 17762306a36Sopenharmony_ci#define SHF_MIPS_NAMES 0x02000000 17862306a36Sopenharmony_ci#define SHF_MIPS_NODUPES 0x01000000 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci#define MIPS_ABI_FP_ANY 0 /* FP ABI doesn't matter */ 18162306a36Sopenharmony_ci#define MIPS_ABI_FP_DOUBLE 1 /* -mdouble-float */ 18262306a36Sopenharmony_ci#define MIPS_ABI_FP_SINGLE 2 /* -msingle-float */ 18362306a36Sopenharmony_ci#define MIPS_ABI_FP_SOFT 3 /* -msoft-float */ 18462306a36Sopenharmony_ci#define MIPS_ABI_FP_OLD_64 4 /* -mips32r2 -mfp64 */ 18562306a36Sopenharmony_ci#define MIPS_ABI_FP_XX 5 /* -mfpxx */ 18662306a36Sopenharmony_ci#define MIPS_ABI_FP_64 6 /* -mips32r2 -mfp64 */ 18762306a36Sopenharmony_ci#define MIPS_ABI_FP_64A 7 /* -mips32r2 -mfp64 -mno-odd-spreg */ 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_cistruct mips_elf_abiflags_v0 { 19062306a36Sopenharmony_ci uint16_t version; /* Version of flags structure */ 19162306a36Sopenharmony_ci uint8_t isa_level; /* The level of the ISA: 1-5, 32, 64 */ 19262306a36Sopenharmony_ci uint8_t isa_rev; /* The revision of ISA: 0 for MIPS V and below, 19362306a36Sopenharmony_ci 1-n otherwise */ 19462306a36Sopenharmony_ci uint8_t gpr_size; /* The size of general purpose registers */ 19562306a36Sopenharmony_ci uint8_t cpr1_size; /* The size of co-processor 1 registers */ 19662306a36Sopenharmony_ci uint8_t cpr2_size; /* The size of co-processor 2 registers */ 19762306a36Sopenharmony_ci uint8_t fp_abi; /* The floating-point ABI */ 19862306a36Sopenharmony_ci uint32_t isa_ext; /* Mask of processor-specific extensions */ 19962306a36Sopenharmony_ci uint32_t ases; /* Mask of ASEs used */ 20062306a36Sopenharmony_ci uint32_t flags1; /* Mask of general flags */ 20162306a36Sopenharmony_ci uint32_t flags2; 20262306a36Sopenharmony_ci}; 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci/* ELF register definitions */ 20562306a36Sopenharmony_ci#define ELF_NGREG 45 20662306a36Sopenharmony_ci#define ELF_NFPREG 33 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_citypedef unsigned long elf_greg_t; 20962306a36Sopenharmony_citypedef elf_greg_t elf_gregset_t[ELF_NGREG]; 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_citypedef double elf_fpreg_t; 21262306a36Sopenharmony_citypedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG]; 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_civoid mips_dump_regs32(u32 *uregs, const struct pt_regs *regs); 21562306a36Sopenharmony_civoid mips_dump_regs64(u64 *uregs, const struct pt_regs *regs); 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci#ifdef CONFIG_32BIT 21862306a36Sopenharmony_ci/* 21962306a36Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture. 22062306a36Sopenharmony_ci */ 22162306a36Sopenharmony_ci#define elf_check_arch elf32_check_arch 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci/* 22462306a36Sopenharmony_ci * These are used to set parameters in the core dumps. 22562306a36Sopenharmony_ci */ 22662306a36Sopenharmony_ci#define ELF_CLASS ELFCLASS32 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci#define ELF_CORE_COPY_REGS(dest, regs) \ 22962306a36Sopenharmony_ci mips_dump_regs32((u32 *)&(dest), (regs)); 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci#endif /* CONFIG_32BIT */ 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci#ifdef CONFIG_64BIT 23462306a36Sopenharmony_ci/* 23562306a36Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture. 23662306a36Sopenharmony_ci */ 23762306a36Sopenharmony_ci#define elf_check_arch elf64_check_arch 23862306a36Sopenharmony_ci#define compat_elf_check_arch elf32_check_arch 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci/* 24162306a36Sopenharmony_ci * These are used to set parameters in the core dumps. 24262306a36Sopenharmony_ci */ 24362306a36Sopenharmony_ci#define ELF_CLASS ELFCLASS64 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci#define ELF_CORE_COPY_REGS(dest, regs) \ 24662306a36Sopenharmony_ci mips_dump_regs64((u64 *)&(dest), (regs)); 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci#endif /* CONFIG_64BIT */ 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci/* 25162306a36Sopenharmony_ci * These are used to set parameters in the core dumps. 25262306a36Sopenharmony_ci */ 25362306a36Sopenharmony_ci#ifdef __MIPSEB__ 25462306a36Sopenharmony_ci#define ELF_DATA ELFDATA2MSB 25562306a36Sopenharmony_ci#elif defined(__MIPSEL__) 25662306a36Sopenharmony_ci#define ELF_DATA ELFDATA2LSB 25762306a36Sopenharmony_ci#endif 25862306a36Sopenharmony_ci#define ELF_ARCH EM_MIPS 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci/* 26162306a36Sopenharmony_ci * In order to be sure that we don't attempt to execute an O32 binary which 26262306a36Sopenharmony_ci * requires 64 bit FP (FR=1) on a system which does not support it we refuse 26362306a36Sopenharmony_ci * to execute any binary which has bits specified by the following macro set 26462306a36Sopenharmony_ci * in its ELF header flags. 26562306a36Sopenharmony_ci */ 26662306a36Sopenharmony_ci#ifdef CONFIG_MIPS_O32_FP64_SUPPORT 26762306a36Sopenharmony_ci# define __MIPS_O32_FP64_MUST_BE_ZERO 0 26862306a36Sopenharmony_ci#else 26962306a36Sopenharmony_ci# define __MIPS_O32_FP64_MUST_BE_ZERO EF_MIPS_FP64 27062306a36Sopenharmony_ci#endif 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci#define mips_elf_check_machine(x) ((x)->e_machine == EM_MIPS) 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci#define vmcore_elf32_check_arch mips_elf_check_machine 27562306a36Sopenharmony_ci#define vmcore_elf64_check_arch mips_elf_check_machine 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_ci/* 27862306a36Sopenharmony_ci * Return non-zero if HDR identifies an o32 or n32 ELF binary. 27962306a36Sopenharmony_ci */ 28062306a36Sopenharmony_ci#define elf32_check_arch(hdr) \ 28162306a36Sopenharmony_ci({ \ 28262306a36Sopenharmony_ci int __res = 1; \ 28362306a36Sopenharmony_ci struct elfhdr *__h = (hdr); \ 28462306a36Sopenharmony_ci \ 28562306a36Sopenharmony_ci if (!mips_elf_check_machine(__h)) \ 28662306a36Sopenharmony_ci __res = 0; \ 28762306a36Sopenharmony_ci if (__h->e_ident[EI_CLASS] != ELFCLASS32) \ 28862306a36Sopenharmony_ci __res = 0; \ 28962306a36Sopenharmony_ci if ((__h->e_flags & EF_MIPS_ABI2) != 0) { \ 29062306a36Sopenharmony_ci if (!IS_ENABLED(CONFIG_MIPS32_N32) || \ 29162306a36Sopenharmony_ci (__h->e_flags & EF_MIPS_ABI)) \ 29262306a36Sopenharmony_ci __res = 0; \ 29362306a36Sopenharmony_ci } else { \ 29462306a36Sopenharmony_ci if (IS_ENABLED(CONFIG_64BIT) && !IS_ENABLED(CONFIG_MIPS32_O32)) \ 29562306a36Sopenharmony_ci __res = 0; \ 29662306a36Sopenharmony_ci if (((__h->e_flags & EF_MIPS_ABI) != 0) && \ 29762306a36Sopenharmony_ci ((__h->e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32)) \ 29862306a36Sopenharmony_ci __res = 0; \ 29962306a36Sopenharmony_ci if (__h->e_flags & __MIPS_O32_FP64_MUST_BE_ZERO) \ 30062306a36Sopenharmony_ci __res = 0; \ 30162306a36Sopenharmony_ci } \ 30262306a36Sopenharmony_ci __res; \ 30362306a36Sopenharmony_ci}) 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ci/* 30662306a36Sopenharmony_ci * Return non-zero if HDR identifies an n64 ELF binary. 30762306a36Sopenharmony_ci */ 30862306a36Sopenharmony_ci#define elf64_check_arch(hdr) \ 30962306a36Sopenharmony_ci({ \ 31062306a36Sopenharmony_ci int __res = 1; \ 31162306a36Sopenharmony_ci struct elfhdr *__h = (hdr); \ 31262306a36Sopenharmony_ci \ 31362306a36Sopenharmony_ci if (!mips_elf_check_machine(__h)) \ 31462306a36Sopenharmony_ci __res = 0; \ 31562306a36Sopenharmony_ci if (__h->e_ident[EI_CLASS] != ELFCLASS64) \ 31662306a36Sopenharmony_ci __res = 0; \ 31762306a36Sopenharmony_ci \ 31862306a36Sopenharmony_ci __res; \ 31962306a36Sopenharmony_ci}) 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_cistruct mips_abi; 32262306a36Sopenharmony_ci 32362306a36Sopenharmony_ciextern struct mips_abi mips_abi; 32462306a36Sopenharmony_ciextern struct mips_abi mips_abi_32; 32562306a36Sopenharmony_ciextern struct mips_abi mips_abi_n32; 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci#ifdef CONFIG_32BIT 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci#define SET_PERSONALITY2(ex, state) \ 33062306a36Sopenharmony_cido { \ 33162306a36Sopenharmony_ci clear_thread_flag(TIF_HYBRID_FPREGS); \ 33262306a36Sopenharmony_ci set_thread_flag(TIF_32BIT_FPREGS); \ 33362306a36Sopenharmony_ci \ 33462306a36Sopenharmony_ci current->thread.abi = &mips_abi; \ 33562306a36Sopenharmony_ci \ 33662306a36Sopenharmony_ci mips_set_personality_fp(state); \ 33762306a36Sopenharmony_ci mips_set_personality_nan(state); \ 33862306a36Sopenharmony_ci \ 33962306a36Sopenharmony_ci if (personality(current->personality) != PER_LINUX) \ 34062306a36Sopenharmony_ci set_personality(PER_LINUX); \ 34162306a36Sopenharmony_ci} while (0) 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci#endif /* CONFIG_32BIT */ 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci#ifdef CONFIG_64BIT 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci#ifdef CONFIG_MIPS32_N32 34862306a36Sopenharmony_ci#define __SET_PERSONALITY32_N32() \ 34962306a36Sopenharmony_ci do { \ 35062306a36Sopenharmony_ci set_thread_flag(TIF_32BIT_ADDR); \ 35162306a36Sopenharmony_ci \ 35262306a36Sopenharmony_ci current->thread.abi = &mips_abi_n32; \ 35362306a36Sopenharmony_ci } while (0) 35462306a36Sopenharmony_ci#else 35562306a36Sopenharmony_ci#define __SET_PERSONALITY32_N32() \ 35662306a36Sopenharmony_ci do { } while (0) 35762306a36Sopenharmony_ci#endif 35862306a36Sopenharmony_ci 35962306a36Sopenharmony_ci#ifdef CONFIG_MIPS32_O32 36062306a36Sopenharmony_ci#define __SET_PERSONALITY32_O32(ex, state) \ 36162306a36Sopenharmony_ci do { \ 36262306a36Sopenharmony_ci set_thread_flag(TIF_32BIT_REGS); \ 36362306a36Sopenharmony_ci set_thread_flag(TIF_32BIT_ADDR); \ 36462306a36Sopenharmony_ci clear_thread_flag(TIF_HYBRID_FPREGS); \ 36562306a36Sopenharmony_ci set_thread_flag(TIF_32BIT_FPREGS); \ 36662306a36Sopenharmony_ci \ 36762306a36Sopenharmony_ci current->thread.abi = &mips_abi_32; \ 36862306a36Sopenharmony_ci \ 36962306a36Sopenharmony_ci mips_set_personality_fp(state); \ 37062306a36Sopenharmony_ci } while (0) 37162306a36Sopenharmony_ci#else 37262306a36Sopenharmony_ci#define __SET_PERSONALITY32_O32(ex, state) \ 37362306a36Sopenharmony_ci do { } while (0) 37462306a36Sopenharmony_ci#endif 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ci#ifdef CONFIG_MIPS32_COMPAT 37762306a36Sopenharmony_ci#define __SET_PERSONALITY32(ex, state) \ 37862306a36Sopenharmony_cido { \ 37962306a36Sopenharmony_ci if ((((ex).e_flags & EF_MIPS_ABI2) != 0) && \ 38062306a36Sopenharmony_ci ((ex).e_flags & EF_MIPS_ABI) == 0) \ 38162306a36Sopenharmony_ci __SET_PERSONALITY32_N32(); \ 38262306a36Sopenharmony_ci else \ 38362306a36Sopenharmony_ci __SET_PERSONALITY32_O32(ex, state); \ 38462306a36Sopenharmony_ci} while (0) 38562306a36Sopenharmony_ci#else 38662306a36Sopenharmony_ci#define __SET_PERSONALITY32(ex, state) do { } while (0) 38762306a36Sopenharmony_ci#endif 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci#define SET_PERSONALITY2(ex, state) \ 39062306a36Sopenharmony_cido { \ 39162306a36Sopenharmony_ci unsigned int p; \ 39262306a36Sopenharmony_ci \ 39362306a36Sopenharmony_ci clear_thread_flag(TIF_32BIT_REGS); \ 39462306a36Sopenharmony_ci clear_thread_flag(TIF_32BIT_FPREGS); \ 39562306a36Sopenharmony_ci clear_thread_flag(TIF_HYBRID_FPREGS); \ 39662306a36Sopenharmony_ci clear_thread_flag(TIF_32BIT_ADDR); \ 39762306a36Sopenharmony_ci current->personality &= ~READ_IMPLIES_EXEC; \ 39862306a36Sopenharmony_ci \ 39962306a36Sopenharmony_ci if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \ 40062306a36Sopenharmony_ci __SET_PERSONALITY32(ex, state); \ 40162306a36Sopenharmony_ci else \ 40262306a36Sopenharmony_ci current->thread.abi = &mips_abi; \ 40362306a36Sopenharmony_ci \ 40462306a36Sopenharmony_ci mips_set_personality_nan(state); \ 40562306a36Sopenharmony_ci \ 40662306a36Sopenharmony_ci p = personality(current->personality); \ 40762306a36Sopenharmony_ci if (p != PER_LINUX32 && p != PER_LINUX) \ 40862306a36Sopenharmony_ci set_personality(PER_LINUX); \ 40962306a36Sopenharmony_ci} while (0) 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci#endif /* CONFIG_64BIT */ 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci#define CORE_DUMP_USE_REGSET 41462306a36Sopenharmony_ci#define ELF_EXEC_PAGESIZE PAGE_SIZE 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_ci/* This yields a mask that user programs can use to figure out what 41762306a36Sopenharmony_ci instruction set this cpu supports. This could be done in userspace, 41862306a36Sopenharmony_ci but it's not easy, and we've already done it here. */ 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_ci#define ELF_HWCAP (elf_hwcap) 42162306a36Sopenharmony_ciextern unsigned int elf_hwcap; 42262306a36Sopenharmony_ci#include <asm/hwcap.h> 42362306a36Sopenharmony_ci 42462306a36Sopenharmony_ci/* 42562306a36Sopenharmony_ci * This yields a string that ld.so will use to load implementation 42662306a36Sopenharmony_ci * specific libraries for optimization. This is more specific in 42762306a36Sopenharmony_ci * intent than poking at uname or /proc/cpuinfo. 42862306a36Sopenharmony_ci */ 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ci#define ELF_PLATFORM __elf_platform 43162306a36Sopenharmony_ciextern const char *__elf_platform; 43262306a36Sopenharmony_ci 43362306a36Sopenharmony_ci#define ELF_BASE_PLATFORM __elf_base_platform 43462306a36Sopenharmony_ciextern const char *__elf_base_platform; 43562306a36Sopenharmony_ci 43662306a36Sopenharmony_ci/* 43762306a36Sopenharmony_ci * See comments in asm-alpha/elf.h, this is the same thing 43862306a36Sopenharmony_ci * on the MIPS. 43962306a36Sopenharmony_ci */ 44062306a36Sopenharmony_ci#define ELF_PLAT_INIT(_r, load_addr) do { \ 44162306a36Sopenharmony_ci _r->regs[1] = _r->regs[2] = _r->regs[3] = _r->regs[4] = 0; \ 44262306a36Sopenharmony_ci _r->regs[5] = _r->regs[6] = _r->regs[7] = _r->regs[8] = 0; \ 44362306a36Sopenharmony_ci _r->regs[9] = _r->regs[10] = _r->regs[11] = _r->regs[12] = 0; \ 44462306a36Sopenharmony_ci _r->regs[13] = _r->regs[14] = _r->regs[15] = _r->regs[16] = 0; \ 44562306a36Sopenharmony_ci _r->regs[17] = _r->regs[18] = _r->regs[19] = _r->regs[20] = 0; \ 44662306a36Sopenharmony_ci _r->regs[21] = _r->regs[22] = _r->regs[23] = _r->regs[24] = 0; \ 44762306a36Sopenharmony_ci _r->regs[25] = _r->regs[26] = _r->regs[27] = _r->regs[28] = 0; \ 44862306a36Sopenharmony_ci _r->regs[30] = _r->regs[31] = 0; \ 44962306a36Sopenharmony_ci} while (0) 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ci/* This is the location that an ET_DYN program is loaded if exec'ed. Typical 45262306a36Sopenharmony_ci use of this is to invoke "./ld.so someprog" to test out a new version of 45362306a36Sopenharmony_ci the loader. We need to make sure that it is out of the way of the program 45462306a36Sopenharmony_ci that it will "exec", and that there is sufficient room for the brk. */ 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_ci#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ci/* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ 45962306a36Sopenharmony_ci#define ARCH_DLINFO \ 46062306a36Sopenharmony_cido { \ 46162306a36Sopenharmony_ci NEW_AUX_ENT(AT_SYSINFO_EHDR, \ 46262306a36Sopenharmony_ci (unsigned long)current->mm->context.vdso); \ 46362306a36Sopenharmony_ci} while (0) 46462306a36Sopenharmony_ci 46562306a36Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 46662306a36Sopenharmony_cistruct linux_binprm; 46762306a36Sopenharmony_ciextern int arch_setup_additional_pages(struct linux_binprm *bprm, 46862306a36Sopenharmony_ci int uses_interp); 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci#ifdef CONFIG_MIPS_FP_SUPPORT 47162306a36Sopenharmony_ci 47262306a36Sopenharmony_cistruct arch_elf_state { 47362306a36Sopenharmony_ci int nan_2008; 47462306a36Sopenharmony_ci int fp_abi; 47562306a36Sopenharmony_ci int interp_fp_abi; 47662306a36Sopenharmony_ci int overall_fp_mode; 47762306a36Sopenharmony_ci}; 47862306a36Sopenharmony_ci 47962306a36Sopenharmony_ci#define MIPS_ABI_FP_UNKNOWN (-1) /* Unknown FP ABI (kernel internal) */ 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci#define INIT_ARCH_ELF_STATE { \ 48262306a36Sopenharmony_ci .nan_2008 = -1, \ 48362306a36Sopenharmony_ci .fp_abi = MIPS_ABI_FP_UNKNOWN, \ 48462306a36Sopenharmony_ci .interp_fp_abi = MIPS_ABI_FP_UNKNOWN, \ 48562306a36Sopenharmony_ci .overall_fp_mode = -1, \ 48662306a36Sopenharmony_ci} 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ciextern int arch_elf_pt_proc(void *ehdr, void *phdr, struct file *elf, 48962306a36Sopenharmony_ci bool is_interp, struct arch_elf_state *state); 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_ciextern int arch_check_elf(void *ehdr, bool has_interpreter, void *interp_ehdr, 49262306a36Sopenharmony_ci struct arch_elf_state *state); 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ci/* Whether to accept legacy-NaN and 2008-NaN user binaries. */ 49562306a36Sopenharmony_ciextern bool mips_use_nan_legacy; 49662306a36Sopenharmony_ciextern bool mips_use_nan_2008; 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ciextern void mips_set_personality_nan(struct arch_elf_state *state); 49962306a36Sopenharmony_ciextern void mips_set_personality_fp(struct arch_elf_state *state); 50062306a36Sopenharmony_ci 50162306a36Sopenharmony_ci#else /* !CONFIG_MIPS_FP_SUPPORT */ 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_cistruct arch_elf_state; 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_cistatic inline void mips_set_personality_nan(struct arch_elf_state *state) 50662306a36Sopenharmony_ci{ 50762306a36Sopenharmony_ci /* no-op */ 50862306a36Sopenharmony_ci} 50962306a36Sopenharmony_ci 51062306a36Sopenharmony_cistatic inline void mips_set_personality_fp(struct arch_elf_state *state) 51162306a36Sopenharmony_ci{ 51262306a36Sopenharmony_ci /* no-op */ 51362306a36Sopenharmony_ci} 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci#endif /* !CONFIG_MIPS_FP_SUPPORT */ 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ci#define elf_read_implies_exec(ex, stk) mips_elf_read_implies_exec(&(ex), stk) 51862306a36Sopenharmony_ciextern int mips_elf_read_implies_exec(void *elf_ex, int exstack); 51962306a36Sopenharmony_ci 52062306a36Sopenharmony_ci#endif /* _ASM_ELF_H */ 521