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