0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _ASM_ELF_H
0009 #define _ASM_ELF_H
0010
0011 #include <linux/auxvec.h>
0012 #include <linux/fs.h>
0013 #include <linux/mm_types.h>
0014
0015 #include <uapi/linux/elf.h>
0016
0017 #include <asm/current.h>
0018
0019
0020
0021 #define EF_MIPS_ARCH_1 0x00000000
0022 #define EF_MIPS_ARCH_2 0x10000000
0023 #define EF_MIPS_ARCH_3 0x20000000
0024 #define EF_MIPS_ARCH_4 0x30000000
0025 #define EF_MIPS_ARCH_5 0x40000000
0026 #define EF_MIPS_ARCH_32 0x50000000
0027 #define EF_MIPS_ARCH_64 0x60000000
0028 #define EF_MIPS_ARCH_32R2 0x70000000
0029 #define EF_MIPS_ARCH_64R2 0x80000000
0030
0031
0032 #define EF_MIPS_ABI_O32 0x00001000
0033 #define EF_MIPS_ABI_O64 0x00002000
0034
0035 #define PT_MIPS_REGINFO 0x70000000
0036 #define PT_MIPS_RTPROC 0x70000001
0037 #define PT_MIPS_OPTIONS 0x70000002
0038 #define PT_MIPS_ABIFLAGS 0x70000003
0039
0040
0041 #define EF_MIPS_NOREORDER 0x00000001
0042 #define EF_MIPS_PIC 0x00000002
0043 #define EF_MIPS_CPIC 0x00000004
0044 #define EF_MIPS_ABI2 0x00000020
0045 #define EF_MIPS_OPTIONS_FIRST 0x00000080
0046 #define EF_MIPS_32BITMODE 0x00000100
0047 #define EF_MIPS_FP64 0x00000200
0048 #define EF_MIPS_NAN2008 0x00000400
0049 #define EF_MIPS_ABI 0x0000f000
0050 #define EF_MIPS_ARCH 0xf0000000
0051
0052 #define DT_MIPS_RLD_VERSION 0x70000001
0053 #define DT_MIPS_TIME_STAMP 0x70000002
0054 #define DT_MIPS_ICHECKSUM 0x70000003
0055 #define DT_MIPS_IVERSION 0x70000004
0056 #define DT_MIPS_FLAGS 0x70000005
0057 #define RHF_NONE 0x00000000
0058 #define RHF_HARDWAY 0x00000001
0059 #define RHF_NOTPOT 0x00000002
0060 #define RHF_SGI_ONLY 0x00000010
0061 #define DT_MIPS_BASE_ADDRESS 0x70000006
0062 #define DT_MIPS_CONFLICT 0x70000008
0063 #define DT_MIPS_LIBLIST 0x70000009
0064 #define DT_MIPS_LOCAL_GOTNO 0x7000000a
0065 #define DT_MIPS_CONFLICTNO 0x7000000b
0066 #define DT_MIPS_LIBLISTNO 0x70000010
0067 #define DT_MIPS_SYMTABNO 0x70000011
0068 #define DT_MIPS_UNREFEXTNO 0x70000012
0069 #define DT_MIPS_GOTSYM 0x70000013
0070 #define DT_MIPS_HIPAGENO 0x70000014
0071 #define DT_MIPS_RLD_MAP 0x70000016
0072
0073 #define R_MIPS_NONE 0
0074 #define R_MIPS_16 1
0075 #define R_MIPS_32 2
0076 #define R_MIPS_REL32 3
0077 #define R_MIPS_26 4
0078 #define R_MIPS_HI16 5
0079 #define R_MIPS_LO16 6
0080 #define R_MIPS_GPREL16 7
0081 #define R_MIPS_LITERAL 8
0082 #define R_MIPS_GOT16 9
0083 #define R_MIPS_PC16 10
0084 #define R_MIPS_CALL16 11
0085 #define R_MIPS_GPREL32 12
0086
0087
0088 #define R_MIPS_UNUSED1 13
0089 #define R_MIPS_UNUSED2 14
0090 #define R_MIPS_UNUSED3 15
0091 #define R_MIPS_SHIFT5 16
0092 #define R_MIPS_SHIFT6 17
0093 #define R_MIPS_64 18
0094 #define R_MIPS_GOT_DISP 19
0095 #define R_MIPS_GOT_PAGE 20
0096 #define R_MIPS_GOT_OFST 21
0097
0098
0099
0100
0101 #define R_MIPS_GOTHI16 22
0102 #define R_MIPS_GOTLO16 23
0103 #define R_MIPS_SUB 24
0104 #define R_MIPS_INSERT_A 25
0105 #define R_MIPS_INSERT_B 26
0106 #define R_MIPS_DELETE 27
0107 #define R_MIPS_HIGHER 28
0108 #define R_MIPS_HIGHEST 29
0109
0110
0111
0112
0113 #define R_MIPS_CALLHI16 30
0114 #define R_MIPS_CALLLO16 31
0115
0116
0117
0118 #define R_MIPS_PC21_S2 60
0119 #define R_MIPS_PC26_S2 61
0120
0121
0122
0123 #define R_MIPS_LOVENDOR 100
0124 #define R_MIPS_HIVENDOR 127
0125
0126 #define SHN_MIPS_ACCOMON 0xff00
0127 #define SHN_MIPS_TEXT 0xff01
0128 #define SHN_MIPS_DATA 0xff02
0129 #define SHN_MIPS_SCOMMON 0xff03
0130 #define SHN_MIPS_SUNDEFINED 0xff04
0131
0132 #define SHT_MIPS_LIST 0x70000000
0133 #define SHT_MIPS_CONFLICT 0x70000002
0134 #define SHT_MIPS_GPTAB 0x70000003
0135 #define SHT_MIPS_UCODE 0x70000004
0136 #define SHT_MIPS_DEBUG 0x70000005
0137 #define SHT_MIPS_REGINFO 0x70000006
0138 #define SHT_MIPS_PACKAGE 0x70000007
0139 #define SHT_MIPS_PACKSYM 0x70000008
0140 #define SHT_MIPS_RELD 0x70000009
0141 #define SHT_MIPS_IFACE 0x7000000b
0142 #define SHT_MIPS_CONTENT 0x7000000c
0143 #define SHT_MIPS_OPTIONS 0x7000000d
0144 #define SHT_MIPS_SHDR 0x70000010
0145 #define SHT_MIPS_FDESC 0x70000011
0146 #define SHT_MIPS_EXTSYM 0x70000012
0147 #define SHT_MIPS_DENSE 0x70000013
0148 #define SHT_MIPS_PDESC 0x70000014
0149 #define SHT_MIPS_LOCSYM 0x70000015
0150 #define SHT_MIPS_AUXSYM 0x70000016
0151 #define SHT_MIPS_OPTSYM 0x70000017
0152 #define SHT_MIPS_LOCSTR 0x70000018
0153 #define SHT_MIPS_LINE 0x70000019
0154 #define SHT_MIPS_RFDESC 0x7000001a
0155 #define SHT_MIPS_DELTASYM 0x7000001b
0156 #define SHT_MIPS_DELTAINST 0x7000001c
0157 #define SHT_MIPS_DELTACLASS 0x7000001d
0158 #define SHT_MIPS_DWARF 0x7000001e
0159 #define SHT_MIPS_DELTADECL 0x7000001f
0160 #define SHT_MIPS_SYMBOL_LIB 0x70000020
0161 #define SHT_MIPS_EVENTS 0x70000021
0162 #define SHT_MIPS_TRANSLATE 0x70000022
0163 #define SHT_MIPS_PIXIE 0x70000023
0164 #define SHT_MIPS_XLATE 0x70000024
0165 #define SHT_MIPS_XLATE_DEBUG 0x70000025
0166 #define SHT_MIPS_WHIRL 0x70000026
0167 #define SHT_MIPS_EH_REGION 0x70000027
0168 #define SHT_MIPS_XLATE_OLD 0x70000028
0169 #define SHT_MIPS_PDR_EXCEPTION 0x70000029
0170
0171 #define SHF_MIPS_GPREL 0x10000000
0172 #define SHF_MIPS_MERGE 0x20000000
0173 #define SHF_MIPS_ADDR 0x40000000
0174 #define SHF_MIPS_STRING 0x80000000
0175 #define SHF_MIPS_NOSTRIP 0x08000000
0176 #define SHF_MIPS_LOCAL 0x04000000
0177 #define SHF_MIPS_NAMES 0x02000000
0178 #define SHF_MIPS_NODUPES 0x01000000
0179
0180 #define MIPS_ABI_FP_ANY 0
0181 #define MIPS_ABI_FP_DOUBLE 1
0182 #define MIPS_ABI_FP_SINGLE 2
0183 #define MIPS_ABI_FP_SOFT 3
0184 #define MIPS_ABI_FP_OLD_64 4
0185 #define MIPS_ABI_FP_XX 5
0186 #define MIPS_ABI_FP_64 6
0187 #define MIPS_ABI_FP_64A 7
0188
0189 struct mips_elf_abiflags_v0 {
0190 uint16_t version;
0191 uint8_t isa_level;
0192 uint8_t isa_rev;
0193
0194 uint8_t gpr_size;
0195 uint8_t cpr1_size;
0196 uint8_t cpr2_size;
0197 uint8_t fp_abi;
0198 uint32_t isa_ext;
0199 uint32_t ases;
0200 uint32_t flags1;
0201 uint32_t flags2;
0202 };
0203
0204
0205 #define ELF_NGREG 45
0206 #define ELF_NFPREG 33
0207
0208 typedef unsigned long elf_greg_t;
0209 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
0210
0211 typedef double elf_fpreg_t;
0212 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
0213
0214 void mips_dump_regs32(u32 *uregs, const struct pt_regs *regs);
0215 void mips_dump_regs64(u64 *uregs, const struct pt_regs *regs);
0216
0217 #ifdef CONFIG_32BIT
0218
0219
0220
0221 #define elf_check_arch elf32_check_arch
0222
0223
0224
0225
0226 #define ELF_CLASS ELFCLASS32
0227
0228 #define ELF_CORE_COPY_REGS(dest, regs) \
0229 mips_dump_regs32((u32 *)&(dest), (regs));
0230
0231 #endif
0232
0233 #ifdef CONFIG_64BIT
0234
0235
0236
0237 #define elf_check_arch elf64_check_arch
0238 #define compat_elf_check_arch elf32_check_arch
0239
0240
0241
0242
0243 #define ELF_CLASS ELFCLASS64
0244
0245 #define ELF_CORE_COPY_REGS(dest, regs) \
0246 mips_dump_regs64((u64 *)&(dest), (regs));
0247
0248 #endif
0249
0250
0251
0252
0253 #ifdef __MIPSEB__
0254 #define ELF_DATA ELFDATA2MSB
0255 #elif defined(__MIPSEL__)
0256 #define ELF_DATA ELFDATA2LSB
0257 #endif
0258 #define ELF_ARCH EM_MIPS
0259
0260
0261
0262
0263
0264
0265
0266 #ifdef CONFIG_MIPS_O32_FP64_SUPPORT
0267 # define __MIPS_O32_FP64_MUST_BE_ZERO 0
0268 #else
0269 # define __MIPS_O32_FP64_MUST_BE_ZERO EF_MIPS_FP64
0270 #endif
0271
0272 #define mips_elf_check_machine(x) ((x)->e_machine == EM_MIPS)
0273
0274 #define vmcore_elf32_check_arch mips_elf_check_machine
0275 #define vmcore_elf64_check_arch mips_elf_check_machine
0276
0277
0278
0279
0280 #define elf32_check_arch(hdr) \
0281 ({ \
0282 int __res = 1; \
0283 struct elfhdr *__h = (hdr); \
0284 \
0285 if (!mips_elf_check_machine(__h)) \
0286 __res = 0; \
0287 if (__h->e_ident[EI_CLASS] != ELFCLASS32) \
0288 __res = 0; \
0289 if ((__h->e_flags & EF_MIPS_ABI2) != 0) { \
0290 if (!IS_ENABLED(CONFIG_MIPS32_N32) || \
0291 (__h->e_flags & EF_MIPS_ABI)) \
0292 __res = 0; \
0293 } else { \
0294 if (IS_ENABLED(CONFIG_64BIT) && !IS_ENABLED(CONFIG_MIPS32_O32)) \
0295 __res = 0; \
0296 if (((__h->e_flags & EF_MIPS_ABI) != 0) && \
0297 ((__h->e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32)) \
0298 __res = 0; \
0299 if (__h->e_flags & __MIPS_O32_FP64_MUST_BE_ZERO) \
0300 __res = 0; \
0301 } \
0302 __res; \
0303 })
0304
0305
0306
0307
0308 #define elf64_check_arch(hdr) \
0309 ({ \
0310 int __res = 1; \
0311 struct elfhdr *__h = (hdr); \
0312 \
0313 if (!mips_elf_check_machine(__h)) \
0314 __res = 0; \
0315 if (__h->e_ident[EI_CLASS] != ELFCLASS64) \
0316 __res = 0; \
0317 \
0318 __res; \
0319 })
0320
0321 struct mips_abi;
0322
0323 extern struct mips_abi mips_abi;
0324 extern struct mips_abi mips_abi_32;
0325 extern struct mips_abi mips_abi_n32;
0326
0327 #ifdef CONFIG_32BIT
0328
0329 #define SET_PERSONALITY2(ex, state) \
0330 do { \
0331 clear_thread_flag(TIF_HYBRID_FPREGS); \
0332 set_thread_flag(TIF_32BIT_FPREGS); \
0333 \
0334 current->thread.abi = &mips_abi; \
0335 \
0336 mips_set_personality_fp(state); \
0337 mips_set_personality_nan(state); \
0338 \
0339 if (personality(current->personality) != PER_LINUX) \
0340 set_personality(PER_LINUX); \
0341 } while (0)
0342
0343 #endif
0344
0345 #ifdef CONFIG_64BIT
0346
0347 #ifdef CONFIG_MIPS32_N32
0348 #define __SET_PERSONALITY32_N32() \
0349 do { \
0350 set_thread_flag(TIF_32BIT_ADDR); \
0351 \
0352 current->thread.abi = &mips_abi_n32; \
0353 } while (0)
0354 #else
0355 #define __SET_PERSONALITY32_N32() \
0356 do { } while (0)
0357 #endif
0358
0359 #ifdef CONFIG_MIPS32_O32
0360 #define __SET_PERSONALITY32_O32(ex, state) \
0361 do { \
0362 set_thread_flag(TIF_32BIT_REGS); \
0363 set_thread_flag(TIF_32BIT_ADDR); \
0364 clear_thread_flag(TIF_HYBRID_FPREGS); \
0365 set_thread_flag(TIF_32BIT_FPREGS); \
0366 \
0367 current->thread.abi = &mips_abi_32; \
0368 \
0369 mips_set_personality_fp(state); \
0370 } while (0)
0371 #else
0372 #define __SET_PERSONALITY32_O32(ex, state) \
0373 do { } while (0)
0374 #endif
0375
0376 #ifdef CONFIG_MIPS32_COMPAT
0377 #define __SET_PERSONALITY32(ex, state) \
0378 do { \
0379 if ((((ex).e_flags & EF_MIPS_ABI2) != 0) && \
0380 ((ex).e_flags & EF_MIPS_ABI) == 0) \
0381 __SET_PERSONALITY32_N32(); \
0382 else \
0383 __SET_PERSONALITY32_O32(ex, state); \
0384 } while (0)
0385 #else
0386 #define __SET_PERSONALITY32(ex, state) do { } while (0)
0387 #endif
0388
0389 #define SET_PERSONALITY2(ex, state) \
0390 do { \
0391 unsigned int p; \
0392 \
0393 clear_thread_flag(TIF_32BIT_REGS); \
0394 clear_thread_flag(TIF_32BIT_FPREGS); \
0395 clear_thread_flag(TIF_HYBRID_FPREGS); \
0396 clear_thread_flag(TIF_32BIT_ADDR); \
0397 current->personality &= ~READ_IMPLIES_EXEC; \
0398 \
0399 if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
0400 __SET_PERSONALITY32(ex, state); \
0401 else \
0402 current->thread.abi = &mips_abi; \
0403 \
0404 mips_set_personality_nan(state); \
0405 \
0406 p = personality(current->personality); \
0407 if (p != PER_LINUX32 && p != PER_LINUX) \
0408 set_personality(PER_LINUX); \
0409 } while (0)
0410
0411 #endif
0412
0413 #define CORE_DUMP_USE_REGSET
0414 #define ELF_EXEC_PAGESIZE PAGE_SIZE
0415
0416
0417
0418
0419
0420 #define ELF_HWCAP (elf_hwcap)
0421 extern unsigned int elf_hwcap;
0422 #include <asm/hwcap.h>
0423
0424
0425
0426
0427
0428
0429
0430 #define ELF_PLATFORM __elf_platform
0431 extern const char *__elf_platform;
0432
0433 #define ELF_BASE_PLATFORM __elf_base_platform
0434 extern const char *__elf_base_platform;
0435
0436
0437
0438
0439
0440 #define ELF_PLAT_INIT(_r, load_addr) do { \
0441 _r->regs[1] = _r->regs[2] = _r->regs[3] = _r->regs[4] = 0; \
0442 _r->regs[5] = _r->regs[6] = _r->regs[7] = _r->regs[8] = 0; \
0443 _r->regs[9] = _r->regs[10] = _r->regs[11] = _r->regs[12] = 0; \
0444 _r->regs[13] = _r->regs[14] = _r->regs[15] = _r->regs[16] = 0; \
0445 _r->regs[17] = _r->regs[18] = _r->regs[19] = _r->regs[20] = 0; \
0446 _r->regs[21] = _r->regs[22] = _r->regs[23] = _r->regs[24] = 0; \
0447 _r->regs[25] = _r->regs[26] = _r->regs[27] = _r->regs[28] = 0; \
0448 _r->regs[30] = _r->regs[31] = 0; \
0449 } while (0)
0450
0451
0452
0453
0454
0455
0456 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
0457
0458
0459 #define ARCH_DLINFO \
0460 do { \
0461 NEW_AUX_ENT(AT_SYSINFO_EHDR, \
0462 (unsigned long)current->mm->context.vdso); \
0463 } while (0)
0464
0465 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
0466 struct linux_binprm;
0467 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
0468 int uses_interp);
0469
0470 #ifdef CONFIG_MIPS_FP_SUPPORT
0471
0472 struct arch_elf_state {
0473 int nan_2008;
0474 int fp_abi;
0475 int interp_fp_abi;
0476 int overall_fp_mode;
0477 };
0478
0479 #define MIPS_ABI_FP_UNKNOWN (-1)
0480
0481 #define INIT_ARCH_ELF_STATE { \
0482 .nan_2008 = -1, \
0483 .fp_abi = MIPS_ABI_FP_UNKNOWN, \
0484 .interp_fp_abi = MIPS_ABI_FP_UNKNOWN, \
0485 .overall_fp_mode = -1, \
0486 }
0487
0488 extern int arch_elf_pt_proc(void *ehdr, void *phdr, struct file *elf,
0489 bool is_interp, struct arch_elf_state *state);
0490
0491 extern int arch_check_elf(void *ehdr, bool has_interpreter, void *interp_ehdr,
0492 struct arch_elf_state *state);
0493
0494
0495 extern bool mips_use_nan_legacy;
0496 extern bool mips_use_nan_2008;
0497
0498 extern void mips_set_personality_nan(struct arch_elf_state *state);
0499 extern void mips_set_personality_fp(struct arch_elf_state *state);
0500
0501 #else
0502
0503 struct arch_elf_state;
0504
0505 static inline void mips_set_personality_nan(struct arch_elf_state *state)
0506 {
0507
0508 }
0509
0510 static inline void mips_set_personality_fp(struct arch_elf_state *state)
0511 {
0512
0513 }
0514
0515 #endif
0516
0517 #define elf_read_implies_exec(ex, stk) mips_elf_read_implies_exec(&(ex), stk)
0518 extern int mips_elf_read_implies_exec(void *elf_ex, int exstack);
0519
0520 #endif