1253103Simp/* 2253103Simp * Copyright (c) 2013 M. Warner Losh. All Rights Reserved. 3178172Simp * 4178172Simp * Redistribution and use in source and binary forms, with or without 5178172Simp * modification, are permitted provided that the following conditions 6178172Simp * are met: 7178172Simp * 1. Redistributions of source code must retain the above copyright 8178172Simp * notice, this list of conditions and the following disclaimer. 9178172Simp * 2. Redistributions in binary form must reproduce the above copyright 10178172Simp * notice, this list of conditions and the following disclaimer in the 11178172Simp * documentation and/or other materials provided with the distribution. 12178172Simp * 13253103Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14253103Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15253103Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16253103Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17253103Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23178172Simp * SUCH DAMAGE. 24178172Simp * 25178172Simp * $FreeBSD$ 26253103Simp */ 27253103Simp 28253103Simp/*- 29253103Simp * Copyright (c) 2013 The NetBSD Foundation, Inc. 30253103Simp * All rights reserved. 31178172Simp * 32253103Simp * Redistribution and use in source and binary forms, with or without 33253103Simp * modification, are permitted provided that the following conditions 34253103Simp * are met: 35253103Simp * 1. Redistributions of source code must retain the above copyright 36253103Simp * notice, this list of conditions and the following disclaimer. 37253103Simp * 2. Redistributions in binary form must reproduce the above copyright 38253103Simp * notice, this list of conditions and the following disclaimer in the 39253103Simp * documentation and/or other materials provided with the distribution. 40253103Simp * 41253103Simp * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 42253103Simp * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 43253103Simp * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 44253103Simp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 45253103Simp * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 46253103Simp * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 47253103Simp * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 48253103Simp * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 49253103Simp * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50253103Simp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 51253103Simp * POSSIBILITY OF SUCH DAMAGE. 52253103Simp * 53253103Simp * See below starting with the line with $NetBSD...$ for code this applies to. 54178172Simp */ 55178172Simp 56253103Simp#ifndef __MIPS_ELF_H 57253103Simp#define __MIPS_ELF_H 58178172Simp 59253103Simp/* FreeBSD specific bits - derived from FreeBSD specific files and changes to old elf.h */ 60178172Simp 61253103Simp/* 62253103Simp * Define __ELF_WORD_SIZE based on the ABI, if not defined yet. This sets 63253103Simp * the proper defaults when we're not trying to do 32-bit on 64-bit systems. 64253103Simp * We include both 32 and 64 bit versions so we can support multiple ABIs. 65253103Simp */ 66186191Simp#ifndef __ELF_WORD_SIZE 67202031Simp#if defined(__mips_n64) 68253103Simp#define __ELF_WORD_SIZE 64 69202031Simp#else 70253103Simp#define __ELF_WORD_SIZE 32 71186191Simp#endif 72202031Simp#endif 73253103Simp#include <sys/elf32.h> 74253103Simp#include <sys/elf64.h> 75178172Simp#include <sys/elf_generic.h> 76178172Simp 77253103Simp#define ELF_ARCH EM_MIPS 78253103Simp#define ELF_ARCH32 EM_MIPS 79178172Simp 80178172Simp/* Define "machine" characteristics */ 81186191Simp#if __ELF_WORD_SIZE == 32 82178172Simp#define ELF_TARG_CLASS ELFCLASS32 83186191Simp#else 84186191Simp#define ELF_TARG_CLASS ELFCLASS64 85186191Simp#endif 86178172Simp#ifdef __MIPSEB__ 87178172Simp#define ELF_TARG_DATA ELFDATA2MSB 88178172Simp#else 89178172Simp#define ELF_TARG_DATA ELFDATA2LSB 90178172Simp#endif 91178172Simp#define ELF_TARG_MACH EM_MIPS 92178172Simp#define ELF_TARG_VER 1 93178172Simp 94178172Simp/* 95178172Simp * Auxiliary vector entries for passing information to the interpreter. 96178172Simp * 97178172Simp * The i386 supplement to the SVR4 ABI specification names this "auxv_t", 98178172Simp * but POSIX lays claim to all symbols ending with "_t". 99178172Simp */ 100178172Simptypedef struct { /* Auxiliary vector entry on initial stack */ 101178172Simp int a_type; /* Entry type. */ 102178172Simp union { 103186191Simp int a_val; /* Integer value. */ 104178172Simp void *a_ptr; /* Address. */ 105178172Simp void (*a_fcn)(void); /* Function pointer (not used). */ 106178172Simp } a_un; 107178172Simp} Elf32_Auxinfo; 108178172Simp 109186191Simptypedef struct { /* Auxiliary vector entry on initial stack */ 110186191Simp long a_type; /* Entry type. */ 111186191Simp union { 112186191Simp long a_val; /* Integer value. */ 113186191Simp void *a_ptr; /* Address. */ 114186191Simp void (*a_fcn)(void); /* Function pointer (not used). */ 115186191Simp } a_un; 116186191Simp} Elf64_Auxinfo; 117186191Simp 118178172Simp__ElfType(Auxinfo); 119178172Simp 120178172Simp/* Values for a_type. */ 121178172Simp#define AT_NULL 0 /* Terminates the vector. */ 122178172Simp#define AT_IGNORE 1 /* Ignored entry. */ 123178172Simp#define AT_EXECFD 2 /* File descriptor of program to load. */ 124178172Simp#define AT_PHDR 3 /* Program header of program already loaded. */ 125178172Simp#define AT_PHENT 4 /* Size of each program header entry. */ 126178172Simp#define AT_PHNUM 5 /* Number of program header entries. */ 127178172Simp#define AT_PAGESZ 6 /* Page size in bytes. */ 128178172Simp#define AT_BASE 7 /* Interpreter's base address. */ 129178172Simp#define AT_FLAGS 8 /* Flags (unused for i386). */ 130178172Simp#define AT_ENTRY 9 /* Where interpreter should transfer control. */ 131178172Simp#define AT_NOTELF 10 /* Program is not ELF ?? */ 132178172Simp#define AT_UID 11 /* Real uid. */ 133178172Simp#define AT_EUID 12 /* Effective uid. */ 134178172Simp#define AT_GID 13 /* Real gid. */ 135178172Simp#define AT_EGID 14 /* Effective gid. */ 136189926Skib#define AT_EXECPATH 15 /* Path to the executable. */ 137211412Skib#define AT_CANARY 16 /* Canary for SSP */ 138211412Skib#define AT_CANARYLEN 17 /* Length of the canary. */ 139211412Skib#define AT_OSRELDATE 18 /* OSRELDATE. */ 140211412Skib#define AT_NCPUS 19 /* Number of CPUs. */ 141211412Skib#define AT_PAGESIZES 20 /* Pagesizes. */ 142211412Skib#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */ 143237430Skib#define AT_TIMEKEEP 22 /* Pointer to timehands. */ 144217097Skib#define AT_STACKPROT 23 /* Initial stack protection. */ 145178172Simp 146217097Skib#define AT_COUNT 24 /* Count of defined aux entry types. */ 147178172Simp 148197933Skib#define ET_DYN_LOAD_ADDR 0x0120000 149197933Skib 150202908Sgonzo/* 151202908Sgonzo * Constant to mark start of symtab/strtab saved by trampoline 152202908Sgonzo */ 153202908Sgonzo#define SYMTAB_MAGIC 0x64656267 154202908Sgonzo 155253103Simp/* from NetBSD's sys/mips/include/elf_machdep.h $NetBSD: elf_machdep.h,v 1.18 2013/05/23 21:39:49 christos Exp $ */ 156253103Simp 157253103Simp/* mips relocs. */ 158253103Simp 159253103Simp#define R_MIPS_NONE 0 160253103Simp#define R_MIPS_16 1 161253103Simp#define R_MIPS_32 2 162253103Simp#define R_MIPS_REL32 3 163253103Simp#define R_MIPS_REL R_MIPS_REL32 164253103Simp#define R_MIPS_26 4 165253103Simp#define R_MIPS_HI16 5 /* high 16 bits of symbol value */ 166253103Simp#define R_MIPS_LO16 6 /* low 16 bits of symbol value */ 167253103Simp#define R_MIPS_GPREL16 7 /* GP-relative reference */ 168253103Simp#define R_MIPS_LITERAL 8 /* Reference to literal section */ 169253103Simp#define R_MIPS_GOT16 9 /* Reference to global offset table */ 170253103Simp#define R_MIPS_GOT R_MIPS_GOT16 171253103Simp#define R_MIPS_PC16 10 /* 16 bit PC relative reference */ 172253103Simp#define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */ 173253103Simp#define R_MIPS_CALL R_MIPS_CALL16 174253103Simp#define R_MIPS_GPREL32 12 175253103Simp 176253103Simp/* 13, 14, 15 are not defined at this point. */ 177253103Simp#define R_MIPS_UNUSED1 13 178253103Simp#define R_MIPS_UNUSED2 14 179253103Simp#define R_MIPS_UNUSED3 15 180253103Simp 181253103Simp/* 182253103Simp * The remaining relocs are apparently part of the 64-bit Irix ELF ABI. 183253103Simp */ 184253103Simp#define R_MIPS_SHIFT5 16 185253103Simp#define R_MIPS_SHIFT6 17 186253103Simp 187253103Simp#define R_MIPS_64 18 188253103Simp#define R_MIPS_GOT_DISP 19 189253103Simp#define R_MIPS_GOT_PAGE 20 190253103Simp#define R_MIPS_GOT_OFST 21 191253103Simp#define R_MIPS_GOT_HI16 22 192253103Simp#define R_MIPS_GOT_LO16 23 193253103Simp#define R_MIPS_SUB 24 194253103Simp#define R_MIPS_INSERT_A 25 195253103Simp#define R_MIPS_INSERT_B 26 196253103Simp#define R_MIPS_DELETE 27 197253103Simp#define R_MIPS_HIGHER 28 198253103Simp#define R_MIPS_HIGHEST 29 199253103Simp#define R_MIPS_CALL_HI16 30 200253103Simp#define R_MIPS_CALL_LO16 31 201253103Simp#define R_MIPS_SCN_DISP 32 202253103Simp#define R_MIPS_REL16 33 203253103Simp#define R_MIPS_ADD_IMMEDIATE 34 204253103Simp#define R_MIPS_PJUMP 35 205253103Simp#define R_MIPS_RELGOT 36 206253103Simp#define R_MIPS_JALR 37 207253103Simp/* TLS relocations */ 208253103Simp 209253103Simp#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ 210253103Simp#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ 211253103Simp#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ 212253103Simp#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ 213253103Simp#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ 214253103Simp#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ 215253103Simp#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ 216253103Simp#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ 217253103Simp#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ 218253103Simp#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ 219253103Simp#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ 220253103Simp#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ 221253103Simp#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ 222253103Simp 223253103Simp#define R_MIPS_max 51 224253103Simp 225253103Simp#define R_TYPE(name) __CONCAT(R_MIPS_,name) 226253103Simp 227253103Simp#define R_MIPS16_min 100 228253103Simp#define R_MIPS16_26 100 229253103Simp#define R_MIPS16_GPREL 101 230253103Simp#define R_MIPS16_GOT16 102 231253103Simp#define R_MIPS16_CALL16 103 232253103Simp#define R_MIPS16_HI16 104 233253103Simp#define R_MIPS16_LO16 105 234253103Simp#define R_MIPS16_max 106 235253103Simp 236253103Simp#define R_MIPS_COPY 126 237253103Simp#define R_MIPS_JUMP_SLOT 127 238253103Simp 239253103Simp/* mips dynamic tags */ 240253103Simp 241253103Simp#define DT_MIPS_RLD_VERSION 0x70000001 242253103Simp#define DT_MIPS_TIME_STAMP 0x70000002 243253103Simp#define DT_MIPS_ICHECKSUM 0x70000003 244253103Simp#define DT_MIPS_IVERSION 0x70000004 245253103Simp#define DT_MIPS_FLAGS 0x70000005 246253103Simp#define DT_MIPS_BASE_ADDRESS 0x70000006 247253103Simp#define DT_MIPS_CONFLICT 0x70000008 248253103Simp#define DT_MIPS_LIBLIST 0x70000009 249253103Simp#define DT_MIPS_CONFLICTNO 0x7000000b 250253103Simp#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* number of local got ents */ 251253103Simp#define DT_MIPS_LIBLISTNO 0x70000010 252253103Simp#define DT_MIPS_SYMTABNO 0x70000011 /* number of .dynsym entries */ 253253103Simp#define DT_MIPS_UNREFEXTNO 0x70000012 254253103Simp#define DT_MIPS_GOTSYM 0x70000013 /* first dynamic sym in got */ 255253103Simp#define DT_MIPS_HIPAGENO 0x70000014 256253103Simp#define DT_MIPS_RLD_MAP 0x70000016 /* address of loader map */ 257253103Simp#define DT_MIPS_PLTGOT 0x70000032 258253103Simp#define DT_MIPS_RWPLT 0x70000034 259253103Simp 260253103Simp/* 261253103Simp * ELF Flags 262253103Simp */ 263253103Simp#define EF_MIPS_PIC 0x00000002 /* Contains PIC code */ 264253103Simp#define EF_MIPS_CPIC 0x00000004 /* STD PIC calling sequence */ 265253103Simp#define EF_MIPS_ABI2 0x00000020 /* N32 */ 266253103Simp 267253103Simp#define EF_MIPS_ARCH_ASE 0x0f000000 /* Architectural extensions */ 268253103Simp#define EF_MIPS_ARCH_MDMX 0x08000000 /* MDMX multimedia extension */ 269253103Simp#define EF_MIPS_ARCH_M16 0x04000000 /* MIPS-16 ISA extensions */ 270253103Simp 271253103Simp#define EF_MIPS_ARCH 0xf0000000 /* Architecture field */ 272253103Simp#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code */ 273253103Simp#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code */ 274253103Simp#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code */ 275253103Simp#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code */ 276253103Simp#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code */ 277253103Simp#define EF_MIPS_ARCH_32 0x50000000 /* -mips32 code */ 278253103Simp#define EF_MIPS_ARCH_64 0x60000000 /* -mips64 code */ 279253103Simp#define EF_MIPS_ARCH_32R2 0x70000000 /* -mips32r2 code */ 280253103Simp#define EF_MIPS_ARCH_64R2 0x80000000 /* -mips64r2 code */ 281253103Simp 282253103Simp#define EF_MIPS_ABI 0x0000f000 283253103Simp#define EF_MIPS_ABI_O32 0x00001000 284253103Simp#define EF_MIPS_ABI_O64 0x00002000 285253103Simp#define EF_MIPS_ABI_EABI32 0x00003000 286253103Simp#define EF_MIPS_ABI_EABI64 0x00004000 287253103Simp 288253103Simp#endif /* __MIPS_ELF_H */ 289