elf.h revision 325810
11539Srgrimes/* 21539Srgrimes * Copyright (c) 2013 M. Warner Losh. All Rights Reserved. 31539Srgrimes * 41539Srgrimes * Redistribution and use in source and binary forms, with or without 51539Srgrimes * modification, are permitted provided that the following conditions 61539Srgrimes * are met: 71539Srgrimes * 1. Redistributions of source code must retain the above copyright 81539Srgrimes * notice, this list of conditions and the following disclaimer. 91539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 101539Srgrimes * notice, this list of conditions and the following disclaimer in the 111539Srgrimes * documentation and/or other materials provided with the distribution. 121539Srgrimes * 131539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 141539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 151539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 161539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 171539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 181539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 191539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 201539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 211539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 221539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 231539Srgrimes * SUCH DAMAGE. 241539Srgrimes * 251539Srgrimes * $FreeBSD: stable/11/sys/mips/include/elf.h 325810 2017-11-14 16:03:07Z jhb $ 261539Srgrimes */ 271539Srgrimes 281539Srgrimes/*- 291539Srgrimes * Copyright (c) 2013 The NetBSD Foundation, Inc. 301539Srgrimes * All rights reserved. 311539Srgrimes * 321539Srgrimes * Redistribution and use in source and binary forms, with or without 3323657Speter * modification, are permitted provided that the following conditions 3455031Sbde * are met: 351539Srgrimes * 1. Redistributions of source code must retain the above copyright 361539Srgrimes * notice, this list of conditions and the following disclaimer. 371539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 387865Sbde * notice, this list of conditions and the following disclaimer in the 391539Srgrimes * documentation and/or other materials provided with the distribution. 4033861Sbde * 41102227Smike * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 4233861Sbde * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 43103728Swollman * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 44102227Smike * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 45102227Smike * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 46102227Smike * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 4715483Sbde * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 4815483Sbde * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 4915483Sbde * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50102227Smike * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 51102227Smike * POSSIBILITY OF SUCH DAMAGE. 52102227Smike * 531539Srgrimes * See below starting with the line with $NetBSD...$ for code this applies to. 541539Srgrimes */ 5599640Sobrien 56102227Smike#ifndef __MIPS_ELF_H 57102227Smike#define __MIPS_ELF_H 58102227Smike 591539Srgrimes/* FreeBSD specific bits - derived from FreeBSD specific files and changes to old elf.h */ 6099640Sobrien 611539Srgrimes/* 621539Srgrimes * Define __ELF_WORD_SIZE based on the ABI, if not defined yet. This sets 63103766Sbde * the proper defaults when we're not trying to do 32-bit on 64-bit systems. 64103766Sbde * We include both 32 and 64 bit versions so we can support multiple ABIs. 651539Srgrimes */ 661539Srgrimes#ifndef __ELF_WORD_SIZE 671539Srgrimes#if defined(__mips_n64) 68103766Sbde#define __ELF_WORD_SIZE 64 69103766Sbde#else 701539Srgrimes#define __ELF_WORD_SIZE 32 711539Srgrimes#endif 721539Srgrimes#endif 731539Srgrimes#include <sys/elf32.h> 741539Srgrimes#include <sys/elf64.h> 751539Srgrimes#include <sys/elf_generic.h> 761539Srgrimes 771539Srgrimes#define ELF_ARCH EM_MIPS 781539Srgrimes#define ELF_ARCH32 EM_MIPS 791539Srgrimes 801539Srgrimes#define ELF_MACHINE_OK(x) ((x) == ELF_ARCH) 811539Srgrimes 821539Srgrimes/* Define "machine" characteristics */ 831539Srgrimes#if __ELF_WORD_SIZE == 32 841539Srgrimes#define ELF_TARG_CLASS ELFCLASS32 8593032Simp#else 8693032Simp#define ELF_TARG_CLASS ELFCLASS64 8793032Simp#endif 8893032Simp#ifdef __MIPSEB__ 8993032Simp#define ELF_TARG_DATA ELFDATA2MSB 9093032Simp#else 9193032Simp#define ELF_TARG_DATA ELFDATA2LSB 9293032Simp#endif 9393032Simp#define ELF_TARG_MACH EM_MIPS 9493032Simp#define ELF_TARG_VER 1 9593032Simp 9693032Simp/* 9793032Simp * Auxiliary vector entries for passing information to the interpreter. 9893032Simp * 9993032Simp * The i386 supplement to the SVR4 ABI specification names this "auxv_t", 10093032Simp * but POSIX lays claim to all symbols ending with "_t". 101103728Swollman */ 102103766Sbdetypedef struct { /* Auxiliary vector entry on initial stack */ 103103728Swollman int a_type; /* Entry type. */ 10493032Simp union { 10593032Simp int a_val; /* Integer value. */ 10693032Simp void *a_ptr; /* Address. */ 10793032Simp void (*a_fcn)(void); /* Function pointer (not used). */ 10893032Simp } a_un; 109103766Sbde} Elf32_Auxinfo; 110103766Sbde 111103766Sbdetypedef struct { /* Auxiliary vector entry on initial stack */ 112103728Swollman long a_type; /* Entry type. */ 113103766Sbde union { 1141539Srgrimes long a_val; /* Integer value. */ 115103012Stjr void *a_ptr; /* Address. */ 11693032Simp void (*a_fcn)(void); /* Function pointer (not used). */ 11793032Simp } a_un; 118103012Stjr} Elf64_Auxinfo; 1191539Srgrimes 120103728Swollman__ElfType(Auxinfo); 121103728Swollman 122103728Swollman/* Values for a_type. */ 123103728Swollman#define AT_NULL 0 /* Terminates the vector. */ 124103728Swollman#define AT_IGNORE 1 /* Ignored entry. */ 125103728Swollman#define AT_EXECFD 2 /* File descriptor of program to load. */ 126103728Swollman#define AT_PHDR 3 /* Program header of program already loaded. */ 127103728Swollman#define AT_PHENT 4 /* Size of each program header entry. */ 128103728Swollman#define AT_PHNUM 5 /* Number of program header entries. */ 129103728Swollman#define AT_PAGESZ 6 /* Page size in bytes. */ 130103728Swollman#define AT_BASE 7 /* Interpreter's base address. */ 131103728Swollman#define AT_FLAGS 8 /* Flags (unused for i386). */ 132103728Swollman#define AT_ENTRY 9 /* Where interpreter should transfer control. */ 133103728Swollman#define AT_NOTELF 10 /* Program is not ELF ?? */ 134103728Swollman#define AT_UID 11 /* Real uid. */ 135103728Swollman#define AT_EUID 12 /* Effective uid. */ 136103728Swollman#define AT_GID 13 /* Real gid. */ 13769201Sphk#define AT_EGID 14 /* Effective gid. */ 138103728Swollman#define AT_EXECPATH 15 /* Path to the executable. */ 139103728Swollman#define AT_CANARY 16 /* Canary for SSP */ 140103728Swollman#define AT_CANARYLEN 17 /* Length of the canary. */ 141103728Swollman#define AT_OSRELDATE 18 /* OSRELDATE. */ 142103728Swollman#define AT_NCPUS 19 /* Number of CPUs. */ 143103728Swollman#define AT_PAGESIZES 20 /* Pagesizes. */ 144103728Swollman#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */ 145103728Swollman#define AT_TIMEKEEP 22 /* Pointer to timehands. */ 146103728Swollman#define AT_STACKPROT 23 /* Initial stack protection. */ 147103766Sbde#define AT_EHDRFLAGS 24 /* e_flags field from elf hdr */ 148103766Sbde#define AT_HWCAP 25 /* CPU feature flags. */ 149103728Swollman#define AT_HWCAP2 26 /* CPU feature flags 2. */ 150103728Swollman 151103766Sbde#define AT_COUNT 27 /* Count of defined aux entry types. */ 152103728Swollman 153103728Swollman#define ET_DYN_LOAD_ADDR 0x0120000 154103766Sbde 155103728Swollman/* 156103728Swollman * Constant to mark start of symtab/strtab saved by trampoline 157103728Swollman */ 158103728Swollman#define SYMTAB_MAGIC 0x64656267 159103728Swollman 160103728Swollman/* from NetBSD's sys/mips/include/elf_machdep.h $NetBSD: elf_machdep.h,v 1.18 2013/05/23 21:39:49 christos Exp $ */ 161103728Swollman 162103728Swollman/* mips relocs. */ 163103728Swollman 164103728Swollman#define R_MIPS_NONE 0 16593032Simp#define R_MIPS_16 1 166103728Swollman#define R_MIPS_32 2 167103728Swollman#define R_MIPS_REL32 3 1681539Srgrimes#define R_MIPS_REL R_MIPS_REL32 169103728Swollman#define R_MIPS_26 4 170103728Swollman#define R_MIPS_HI16 5 /* high 16 bits of symbol value */ 171103728Swollman#define R_MIPS_LO16 6 /* low 16 bits of symbol value */ 172103728Swollman#define R_MIPS_GPREL16 7 /* GP-relative reference */ 173103728Swollman#define R_MIPS_LITERAL 8 /* Reference to literal section */ 174103728Swollman#define R_MIPS_GOT16 9 /* Reference to global offset table */ 175103728Swollman#define R_MIPS_GOT R_MIPS_GOT16 176103728Swollman#define R_MIPS_PC16 10 /* 16 bit PC relative reference */ 177103728Swollman#define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */ 17893032Simp#define R_MIPS_CALL R_MIPS_CALL16 179103766Sbde#define R_MIPS_GPREL32 12 18093032Simp 181103766Sbde/* 13, 14, 15 are not defined at this point. */ 182103766Sbde#define R_MIPS_UNUSED1 13 183103728Swollman#define R_MIPS_UNUSED2 14 184103728Swollman#define R_MIPS_UNUSED3 15 185103728Swollman 186103728Swollman/* 187108574Sjmallett * The remaining relocs are apparently part of the 64-bit Irix ELF ABI. 188103728Swollman */ 18993032Simp#define R_MIPS_SHIFT5 16 190103728Swollman#define R_MIPS_SHIFT6 17 19193032Simp 19293032Simp#define R_MIPS_64 18 193103728Swollman#define R_MIPS_GOT_DISP 19 194103728Swollman#define R_MIPS_GOT_PAGE 20 195103728Swollman#define R_MIPS_GOT_OFST 21 196103728Swollman#define R_MIPS_GOT_HI16 22 197103728Swollman#define R_MIPS_GOT_LO16 23 198103728Swollman#define R_MIPS_SUB 24 199103766Sbde#define R_MIPS_INSERT_A 25 200103728Swollman#define R_MIPS_INSERT_B 26 20193032Simp#define R_MIPS_DELETE 27 20293032Simp#define R_MIPS_HIGHER 28 203108574Sjmallett#define R_MIPS_HIGHEST 29 204108574Sjmallett#define R_MIPS_CALL_HI16 30 205103728Swollman#define R_MIPS_CALL_LO16 31 206103728Swollman#define R_MIPS_SCN_DISP 32 207103728Swollman#define R_MIPS_REL16 33 2087865Sbde#define R_MIPS_ADD_IMMEDIATE 34 20993032Simp#define R_MIPS_PJUMP 35 210103728Swollman#define R_MIPS_RELGOT 36 211103728Swollman#define R_MIPS_JALR 37 212103728Swollman/* TLS relocations */ 213103728Swollman 214103728Swollman#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ 21593032Simp#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ 216103728Swollman#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ 217108574Sjmallett#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ 218103728Swollman#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ 2194749Sats#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ 220103728Swollman#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ 221103728Swollman#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ 222103766Sbde#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ 223103766Sbde#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ 224103728Swollman#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ 22593032Simp#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ 22641927Sdt#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ 22793032Simp 22893032Simp#define R_MIPS_max 51 22993032Simp 230108445Sobrien#define R_TYPE(name) __CONCAT(R_MIPS_,name) 231103728Swollman 23293032Simp#define R_MIPS16_min 100 23393032Simp#define R_MIPS16_26 100 23493032Simp#define R_MIPS16_GPREL 101 23593032Simp#define R_MIPS16_GOT16 102 23693032Simp#define R_MIPS16_CALL16 103 23793032Simp#define R_MIPS16_HI16 104 23893032Simp#define R_MIPS16_LO16 105 23993032Simp#define R_MIPS16_max 106 24093032Simp 24193032Simp#define R_MIPS_COPY 126 2421539Srgrimes#define R_MIPS_JUMP_SLOT 127 24393032Simp 24493032Simp/* 24593032Simp * ELF Flags 24688399Smike */ 24793032Simp 2481539Srgrimes#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code */ 24993032Simp#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code */ 25093032Simp#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code */ 251103164Swollman#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code */ 252103164Swollman#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code */ 25393032Simp#define EF_MIPS_ARCH_32 0x50000000 /* -mips32 code */ 25493032Simp#define EF_MIPS_ARCH_64 0x60000000 /* -mips64 code */ 25593032Simp#define EF_MIPS_ARCH_32R2 0x70000000 /* -mips32r2 code */ 25693032Simp#define EF_MIPS_ARCH_64R2 0x80000000 /* -mips64r2 code */ 257103164Swollman 258103164Swollman#define EF_MIPS_ABI 0x0000f000 25993032Simp#define EF_MIPS_ABI_O32 0x00001000 26093032Simp#define EF_MIPS_ABI_O64 0x00002000 261103728Swollman#define EF_MIPS_ABI_EABI32 0x00003000 262103728Swollman#define EF_MIPS_ABI_EABI64 0x00004000 263103766Sbde 264103766Sbde#endif /* __MIPS_ELF_H */ 26541927Sdt