1*efeebfb8Schristos /* $NetBSD: elf_machdep.h,v 1.20 2017/11/06 19:17:43 christos Exp $ */ 20e097578Scgd 33be97503Schristos /*- 43be97503Schristos * Copyright (c) 2013 The NetBSD Foundation, Inc. 53be97503Schristos * All rights reserved. 63be97503Schristos * 73be97503Schristos * Redistribution and use in source and binary forms, with or without 83be97503Schristos * modification, are permitted provided that the following conditions 93be97503Schristos * are met: 103be97503Schristos * 1. Redistributions of source code must retain the above copyright 113be97503Schristos * notice, this list of conditions and the following disclaimer. 123be97503Schristos * 2. Redistributions in binary form must reproduce the above copyright 133be97503Schristos * notice, this list of conditions and the following disclaimer in the 143be97503Schristos * documentation and/or other materials provided with the distribution. 153be97503Schristos * 163be97503Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 173be97503Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 183be97503Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 193be97503Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 203be97503Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 213be97503Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 223be97503Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 233be97503Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 243be97503Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 253be97503Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 263be97503Schristos * POSSIBILITY OF SUCH DAMAGE. 273be97503Schristos */ 28290a34a0Smatt #ifndef _MIPS_ELF_MACHDEP_H_ 29290a34a0Smatt #define _MIPS_ELF_MACHDEP_H_ 30290a34a0Smatt 31e544d504Smatt #ifdef _LP64 32*efeebfb8Schristos #define KERN_ELFSIZE 64 33e544d504Smatt #define ARCH_ELFSIZE 64 /* MD native binary size */ 34e544d504Smatt #else 35*efeebfb8Schristos #define KERN_ELFSIZE 32 36e544d504Smatt #define ARCH_ELFSIZE 32 /* MD native binary size */ 37e544d504Smatt #endif 38e544d504Smatt 39290a34a0Smatt #if ELFSIZE == 32 400e097578Scgd #define ELF32_MACHDEP_ID_CASES \ 41522cbf02Skleink case EM_MIPS: \ 420e097578Scgd break; 430e097578Scgd 4451535d4bSthorpej #define ELF32_MACHDEP_ID EM_MIPS 45e544d504Smatt #elif ELFSIZE == 64 46290a34a0Smatt #define ELF64_MACHDEP_ID_CASES \ 47290a34a0Smatt case EM_MIPS: \ 48290a34a0Smatt break; 4951535d4bSthorpej 50290a34a0Smatt #define ELF64_MACHDEP_ID EM_MIPS 51290a34a0Smatt #endif 5278b10569Sminoura 5372a7ae4eSjonathan /* mips relocs. */ 5472a7ae4eSjonathan 5572a7ae4eSjonathan #define R_MIPS_NONE 0 5672a7ae4eSjonathan #define R_MIPS_16 1 5772a7ae4eSjonathan #define R_MIPS_32 2 5872a7ae4eSjonathan #define R_MIPS_REL32 3 5972a7ae4eSjonathan #define R_MIPS_REL R_MIPS_REL32 6072a7ae4eSjonathan #define R_MIPS_26 4 6172a7ae4eSjonathan #define R_MIPS_HI16 5 /* high 16 bits of symbol value */ 6272a7ae4eSjonathan #define R_MIPS_LO16 6 /* low 16 bits of symbol value */ 6372a7ae4eSjonathan #define R_MIPS_GPREL16 7 /* GP-relative reference */ 6472a7ae4eSjonathan #define R_MIPS_LITERAL 8 /* Reference to literal section */ 6572a7ae4eSjonathan #define R_MIPS_GOT16 9 /* Reference to global offset table */ 6672a7ae4eSjonathan #define R_MIPS_GOT R_MIPS_GOT16 6772a7ae4eSjonathan #define R_MIPS_PC16 10 /* 16 bit PC relative reference */ 6872a7ae4eSjonathan #define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */ 6972a7ae4eSjonathan #define R_MIPS_CALL R_MIPS_CALL16 7072a7ae4eSjonathan #define R_MIPS_GPREL32 12 7172a7ae4eSjonathan 7272a7ae4eSjonathan /* 13, 14, 15 are not defined at this point. */ 7372a7ae4eSjonathan #define R_MIPS_UNUSED1 13 7472a7ae4eSjonathan #define R_MIPS_UNUSED2 14 7572a7ae4eSjonathan #define R_MIPS_UNUSED3 15 7672a7ae4eSjonathan 7772a7ae4eSjonathan /* 7872a7ae4eSjonathan * The remaining relocs are apparently part of the 64-bit Irix ELF ABI. 7972a7ae4eSjonathan */ 8072a7ae4eSjonathan #define R_MIPS_SHIFT5 16 8172a7ae4eSjonathan #define R_MIPS_SHIFT6 17 8272a7ae4eSjonathan 8372a7ae4eSjonathan #define R_MIPS_64 18 8472a7ae4eSjonathan #define R_MIPS_GOT_DISP 19 8572a7ae4eSjonathan #define R_MIPS_GOT_PAGE 20 8672a7ae4eSjonathan #define R_MIPS_GOT_OFST 21 8772a7ae4eSjonathan #define R_MIPS_GOT_HI16 22 8872a7ae4eSjonathan #define R_MIPS_GOT_LO16 23 8972a7ae4eSjonathan #define R_MIPS_SUB 24 9072a7ae4eSjonathan #define R_MIPS_INSERT_A 25 9172a7ae4eSjonathan #define R_MIPS_INSERT_B 26 9272a7ae4eSjonathan #define R_MIPS_DELETE 27 9372a7ae4eSjonathan #define R_MIPS_HIGHER 28 9472a7ae4eSjonathan #define R_MIPS_HIGHEST 29 9572a7ae4eSjonathan #define R_MIPS_CALL_HI16 30 9672a7ae4eSjonathan #define R_MIPS_CALL_LO16 31 9772a7ae4eSjonathan #define R_MIPS_SCN_DISP 32 9872a7ae4eSjonathan #define R_MIPS_REL16 33 9972a7ae4eSjonathan #define R_MIPS_ADD_IMMEDIATE 34 10072a7ae4eSjonathan #define R_MIPS_PJUMP 35 10172a7ae4eSjonathan #define R_MIPS_RELGOT 36 102290a34a0Smatt #define R_MIPS_JALR 37 103290a34a0Smatt /* TLS relocations */ 10472a7ae4eSjonathan 105e0397662Sskrll #define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ 106e0397662Sskrll #define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ 107e0397662Sskrll #define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ 108e0397662Sskrll #define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ 109e0397662Sskrll #define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ 110e0397662Sskrll #define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ 111e0397662Sskrll #define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ 112e0397662Sskrll #define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ 113e0397662Sskrll #define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ 114e0397662Sskrll #define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ 115e0397662Sskrll #define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ 116e0397662Sskrll #define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ 117e0397662Sskrll #define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ 11872a7ae4eSjonathan 119e0397662Sskrll #define R_MIPS_max 51 120e0397662Sskrll 121e0397662Sskrll #define R_TYPE(name) __CONCAT(R_MIPS_,name) 12272a7ae4eSjonathan 123290a34a0Smatt #define R_MIPS16_min 100 124290a34a0Smatt #define R_MIPS16_26 100 125290a34a0Smatt #define R_MIPS16_GPREL 101 126290a34a0Smatt #define R_MIPS16_GOT16 102 127290a34a0Smatt #define R_MIPS16_CALL16 103 128290a34a0Smatt #define R_MIPS16_HI16 104 129290a34a0Smatt #define R_MIPS16_LO16 105 130290a34a0Smatt #define R_MIPS16_max 106 131290a34a0Smatt 132e3604c46Smatt #define R_MIPS_COPY 126 133e3604c46Smatt #define R_MIPS_JUMP_SLOT 127 134290a34a0Smatt 1350fb478e6Smhitch /* mips dynamic tags */ 1360fb478e6Smhitch 1370fb478e6Smhitch #define DT_MIPS_RLD_VERSION 0x70000001 1380fb478e6Smhitch #define DT_MIPS_TIME_STAMP 0x70000002 1390fb478e6Smhitch #define DT_MIPS_ICHECKSUM 0x70000003 1400fb478e6Smhitch #define DT_MIPS_IVERSION 0x70000004 1410fb478e6Smhitch #define DT_MIPS_FLAGS 0x70000005 1420fb478e6Smhitch #define DT_MIPS_BASE_ADDRESS 0x70000006 1430fb478e6Smhitch #define DT_MIPS_CONFLICT 0x70000008 1440fb478e6Smhitch #define DT_MIPS_LIBLIST 0x70000009 1450fb478e6Smhitch #define DT_MIPS_CONFLICTNO 0x7000000b 1460fb478e6Smhitch #define DT_MIPS_LOCAL_GOTNO 0x7000000a /* number of local got ents */ 1470fb478e6Smhitch #define DT_MIPS_LIBLISTNO 0x70000010 1480fb478e6Smhitch #define DT_MIPS_SYMTABNO 0x70000011 /* number of .dynsym entries */ 1490fb478e6Smhitch #define DT_MIPS_UNREFEXTNO 0x70000012 1500fb478e6Smhitch #define DT_MIPS_GOTSYM 0x70000013 /* first dynamic sym in got */ 1510fb478e6Smhitch #define DT_MIPS_HIPAGENO 0x70000014 1520fb478e6Smhitch #define DT_MIPS_RLD_MAP 0x70000016 /* address of loader map */ 153e3604c46Smatt #define DT_MIPS_PLTGOT 0x70000032 154e3604c46Smatt #define DT_MIPS_RWPLT 0x70000034 1550fb478e6Smhitch 156290a34a0Smatt /* 157290a34a0Smatt * ELF Flags 158290a34a0Smatt */ 159290a34a0Smatt #define EF_MIPS_PIC 0x00000002 /* Contains PIC code */ 160290a34a0Smatt #define EF_MIPS_CPIC 0x00000004 /* STD PIC calling sequence */ 161290a34a0Smatt #define EF_MIPS_ABI2 0x00000020 /* N32 */ 162290a34a0Smatt 163290a34a0Smatt #define EF_MIPS_ARCH_ASE 0x0f000000 /* Architectural extensions */ 164290a34a0Smatt #define EF_MIPS_ARCH_MDMX 0x08000000 /* MDMX multimedia extension */ 165290a34a0Smatt #define EF_MIPS_ARCH_M16 0x04000000 /* MIPS-16 ISA extensions */ 166290a34a0Smatt 167290a34a0Smatt #define EF_MIPS_ARCH 0xf0000000 /* Architecture field */ 168290a34a0Smatt #define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code */ 169290a34a0Smatt #define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code */ 170290a34a0Smatt #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code */ 171290a34a0Smatt #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code */ 172290a34a0Smatt #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code */ 173290a34a0Smatt #define EF_MIPS_ARCH_32 0x50000000 /* -mips32 code */ 174290a34a0Smatt #define EF_MIPS_ARCH_64 0x60000000 /* -mips64 code */ 175290a34a0Smatt #define EF_MIPS_ARCH_32R2 0x70000000 /* -mips32r2 code */ 176400ff9c4Smatt #define EF_MIPS_ARCH_64R2 0x80000000 /* -mips64r2 code */ 177290a34a0Smatt 178290a34a0Smatt #define EF_MIPS_ABI 0x0000f000 179290a34a0Smatt #define EF_MIPS_ABI_O32 0x00001000 180290a34a0Smatt #define EF_MIPS_ABI_O64 0x00002000 181290a34a0Smatt #define EF_MIPS_ABI_EABI32 0x00003000 182290a34a0Smatt #define EF_MIPS_ABI_EABI64 0x00004000 183290a34a0Smatt 184290a34a0Smatt #if defined(__MIPSEB__) 185290a34a0Smatt #define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB 186290a34a0Smatt #define ELF64_MACHDEP_ENDIANNESS ELFDATA2MSB 187290a34a0Smatt #elif defined(__MIPSEL__) 188290a34a0Smatt #define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB 189290a34a0Smatt #define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB 190290a34a0Smatt #elif !defined(HAVE_NBTOOL_CONFIG_H) 191290a34a0Smatt #error neither __MIPSEL__ nor __MIPSEB__ are defined. 192290a34a0Smatt #endif 193290a34a0Smatt 194bbcd2bb1Sjonathan #ifdef _KERNEL 1950622a855Sdrochner #ifdef _KERNEL_OPT 1960622a855Sdrochner #include "opt_compat_netbsd.h" 197bbcd2bb1Sjonathan #endif 1980622a855Sdrochner #ifdef COMPAT_16 1990622a855Sdrochner /* 2000622a855Sdrochner * Up to 1.6, the ELF dynamic loader (ld.elf_so) was not relocatable. 2010622a855Sdrochner * Tell the kernel ELF exec code not to try relocating the interpreter 2020622a855Sdrochner * for dynamically-linked ELF binaries. 2030622a855Sdrochner */ 2040622a855Sdrochner #define ELF_INTERP_NON_RELOCATABLE 2050622a855Sdrochner #endif /* COMPAT_16 */ 206290a34a0Smatt 207290a34a0Smatt /* 208290a34a0Smatt * We need to be able to include the ELF header so we can pick out the 209290a34a0Smatt * ABI being used. 210290a34a0Smatt */ 211290a34a0Smatt #ifdef ELFSIZE 212290a34a0Smatt #define ELF_MD_PROBE_FUNC ELFNAME2(mips_netbsd,probe) 213290a34a0Smatt #define ELF_MD_COREDUMP_SETUP ELFNAME2(coredump,setup) 214290a34a0Smatt #endif 215290a34a0Smatt 216a06fd79fSmrg struct exec_package; 217a06fd79fSmrg 218290a34a0Smatt int mips_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *, 219290a34a0Smatt vaddr_t *); 220290a34a0Smatt void coredump_elf32_setup(struct lwp *, void *); 221290a34a0Smatt 222290a34a0Smatt int mips_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *, 223290a34a0Smatt vaddr_t *); 224290a34a0Smatt void coredump_elf64_setup(struct lwp *, void *); 2250622a855Sdrochner #endif /* _KERNEL */ 226290a34a0Smatt 227290a34a0Smatt #endif /* _MIPS_ELF_MACHDEP_H_ */ 228