1 /* $NetBSD: elf_machdep.h,v 1.20 2017/11/06 19:17:43 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #ifndef _MIPS_ELF_MACHDEP_H_ 29 #define _MIPS_ELF_MACHDEP_H_ 30 31 #ifdef _LP64 32 #define KERN_ELFSIZE 64 33 #define ARCH_ELFSIZE 64 /* MD native binary size */ 34 #else 35 #define KERN_ELFSIZE 32 36 #define ARCH_ELFSIZE 32 /* MD native binary size */ 37 #endif 38 39 #if ELFSIZE == 32 40 #define ELF32_MACHDEP_ID_CASES \ 41 case EM_MIPS: \ 42 break; 43 44 #define ELF32_MACHDEP_ID EM_MIPS 45 #elif ELFSIZE == 64 46 #define ELF64_MACHDEP_ID_CASES \ 47 case EM_MIPS: \ 48 break; 49 50 #define ELF64_MACHDEP_ID EM_MIPS 51 #endif 52 53 /* mips relocs. */ 54 55 #define R_MIPS_NONE 0 56 #define R_MIPS_16 1 57 #define R_MIPS_32 2 58 #define R_MIPS_REL32 3 59 #define R_MIPS_REL R_MIPS_REL32 60 #define R_MIPS_26 4 61 #define R_MIPS_HI16 5 /* high 16 bits of symbol value */ 62 #define R_MIPS_LO16 6 /* low 16 bits of symbol value */ 63 #define R_MIPS_GPREL16 7 /* GP-relative reference */ 64 #define R_MIPS_LITERAL 8 /* Reference to literal section */ 65 #define R_MIPS_GOT16 9 /* Reference to global offset table */ 66 #define R_MIPS_GOT R_MIPS_GOT16 67 #define R_MIPS_PC16 10 /* 16 bit PC relative reference */ 68 #define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */ 69 #define R_MIPS_CALL R_MIPS_CALL16 70 #define R_MIPS_GPREL32 12 71 72 /* 13, 14, 15 are not defined at this point. */ 73 #define R_MIPS_UNUSED1 13 74 #define R_MIPS_UNUSED2 14 75 #define R_MIPS_UNUSED3 15 76 77 /* 78 * The remaining relocs are apparently part of the 64-bit Irix ELF ABI. 79 */ 80 #define R_MIPS_SHIFT5 16 81 #define R_MIPS_SHIFT6 17 82 83 #define R_MIPS_64 18 84 #define R_MIPS_GOT_DISP 19 85 #define R_MIPS_GOT_PAGE 20 86 #define R_MIPS_GOT_OFST 21 87 #define R_MIPS_GOT_HI16 22 88 #define R_MIPS_GOT_LO16 23 89 #define R_MIPS_SUB 24 90 #define R_MIPS_INSERT_A 25 91 #define R_MIPS_INSERT_B 26 92 #define R_MIPS_DELETE 27 93 #define R_MIPS_HIGHER 28 94 #define R_MIPS_HIGHEST 29 95 #define R_MIPS_CALL_HI16 30 96 #define R_MIPS_CALL_LO16 31 97 #define R_MIPS_SCN_DISP 32 98 #define R_MIPS_REL16 33 99 #define R_MIPS_ADD_IMMEDIATE 34 100 #define R_MIPS_PJUMP 35 101 #define R_MIPS_RELGOT 36 102 #define R_MIPS_JALR 37 103 /* TLS relocations */ 104 105 #define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ 106 #define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ 107 #define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ 108 #define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ 109 #define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ 110 #define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ 111 #define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ 112 #define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ 113 #define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ 114 #define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ 115 #define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ 116 #define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ 117 #define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ 118 119 #define R_MIPS_max 51 120 121 #define R_TYPE(name) __CONCAT(R_MIPS_,name) 122 123 #define R_MIPS16_min 100 124 #define R_MIPS16_26 100 125 #define R_MIPS16_GPREL 101 126 #define R_MIPS16_GOT16 102 127 #define R_MIPS16_CALL16 103 128 #define R_MIPS16_HI16 104 129 #define R_MIPS16_LO16 105 130 #define R_MIPS16_max 106 131 132 #define R_MIPS_COPY 126 133 #define R_MIPS_JUMP_SLOT 127 134 135 /* mips dynamic tags */ 136 137 #define DT_MIPS_RLD_VERSION 0x70000001 138 #define DT_MIPS_TIME_STAMP 0x70000002 139 #define DT_MIPS_ICHECKSUM 0x70000003 140 #define DT_MIPS_IVERSION 0x70000004 141 #define DT_MIPS_FLAGS 0x70000005 142 #define DT_MIPS_BASE_ADDRESS 0x70000006 143 #define DT_MIPS_CONFLICT 0x70000008 144 #define DT_MIPS_LIBLIST 0x70000009 145 #define DT_MIPS_CONFLICTNO 0x7000000b 146 #define DT_MIPS_LOCAL_GOTNO 0x7000000a /* number of local got ents */ 147 #define DT_MIPS_LIBLISTNO 0x70000010 148 #define DT_MIPS_SYMTABNO 0x70000011 /* number of .dynsym entries */ 149 #define DT_MIPS_UNREFEXTNO 0x70000012 150 #define DT_MIPS_GOTSYM 0x70000013 /* first dynamic sym in got */ 151 #define DT_MIPS_HIPAGENO 0x70000014 152 #define DT_MIPS_RLD_MAP 0x70000016 /* address of loader map */ 153 #define DT_MIPS_PLTGOT 0x70000032 154 #define DT_MIPS_RWPLT 0x70000034 155 156 /* 157 * ELF Flags 158 */ 159 #define EF_MIPS_PIC 0x00000002 /* Contains PIC code */ 160 #define EF_MIPS_CPIC 0x00000004 /* STD PIC calling sequence */ 161 #define EF_MIPS_ABI2 0x00000020 /* N32 */ 162 163 #define EF_MIPS_ARCH_ASE 0x0f000000 /* Architectural extensions */ 164 #define EF_MIPS_ARCH_MDMX 0x08000000 /* MDMX multimedia extension */ 165 #define EF_MIPS_ARCH_M16 0x04000000 /* MIPS-16 ISA extensions */ 166 167 #define EF_MIPS_ARCH 0xf0000000 /* Architecture field */ 168 #define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code */ 169 #define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code */ 170 #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code */ 171 #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code */ 172 #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code */ 173 #define EF_MIPS_ARCH_32 0x50000000 /* -mips32 code */ 174 #define EF_MIPS_ARCH_64 0x60000000 /* -mips64 code */ 175 #define EF_MIPS_ARCH_32R2 0x70000000 /* -mips32r2 code */ 176 #define EF_MIPS_ARCH_64R2 0x80000000 /* -mips64r2 code */ 177 178 #define EF_MIPS_ABI 0x0000f000 179 #define EF_MIPS_ABI_O32 0x00001000 180 #define EF_MIPS_ABI_O64 0x00002000 181 #define EF_MIPS_ABI_EABI32 0x00003000 182 #define EF_MIPS_ABI_EABI64 0x00004000 183 184 #if defined(__MIPSEB__) 185 #define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB 186 #define ELF64_MACHDEP_ENDIANNESS ELFDATA2MSB 187 #elif defined(__MIPSEL__) 188 #define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB 189 #define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB 190 #elif !defined(HAVE_NBTOOL_CONFIG_H) 191 #error neither __MIPSEL__ nor __MIPSEB__ are defined. 192 #endif 193 194 #ifdef _KERNEL 195 #ifdef _KERNEL_OPT 196 #include "opt_compat_netbsd.h" 197 #endif 198 #ifdef COMPAT_16 199 /* 200 * Up to 1.6, the ELF dynamic loader (ld.elf_so) was not relocatable. 201 * Tell the kernel ELF exec code not to try relocating the interpreter 202 * for dynamically-linked ELF binaries. 203 */ 204 #define ELF_INTERP_NON_RELOCATABLE 205 #endif /* COMPAT_16 */ 206 207 /* 208 * We need to be able to include the ELF header so we can pick out the 209 * ABI being used. 210 */ 211 #ifdef ELFSIZE 212 #define ELF_MD_PROBE_FUNC ELFNAME2(mips_netbsd,probe) 213 #define ELF_MD_COREDUMP_SETUP ELFNAME2(coredump,setup) 214 #endif 215 216 struct exec_package; 217 218 int mips_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *, 219 vaddr_t *); 220 void coredump_elf32_setup(struct lwp *, void *); 221 222 int mips_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *, 223 vaddr_t *); 224 void coredump_elf64_setup(struct lwp *, void *); 225 #endif /* _KERNEL */ 226 227 #endif /* _MIPS_ELF_MACHDEP_H_ */ 228