os161-1.99
 All Data Structures
elf.h
00001 /*
00002  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _ELF_H_
00031 #define _ELF_H_
00032 
00033 
00034 /*
00035  * Simplified ELF definitions for OS/161 and System/161.
00036  *
00037  * Restrictions:
00038  *     32-bit only
00039  *     No support for .o files or linker structures
00040  *     Does not define all the random symbols a standard elf header would.
00041  */
00042 
00043 /* Get MD bits */
00044 #include <machine/elf.h>
00045 
00046 
00047 /*
00048  * ELF file header. This appears at the very beginning of an ELF file.
00049  */
00050 #define ELF_NIDENT      16
00051 typedef struct {
00052         unsigned char   e_ident[ELF_NIDENT];   /* magic number et al. */
00053         uint16_t        e_type;                /* type of file this is */
00054         uint16_t        e_machine;             /* processor type file is for */
00055         uint32_t        e_version;             /* ELF version */
00056         uint32_t        e_entry;           /* address of program entry point */
00057         uint32_t        e_phoff;           /* location in file of phdrs */
00058         uint32_t        e_shoff;           /* ignore */
00059         uint32_t        e_flags;           /* ignore */
00060         uint16_t        e_ehsize;          /* actual size of file header */
00061         uint16_t        e_phentsize;       /* actual size of phdr */
00062         uint16_t        e_phnum;           /* number of phdrs */
00063         uint16_t        e_shentsize;       /* ignore */
00064         uint16_t        e_shnum;           /* ignore */
00065         uint16_t        e_shstrndx;        /* ignore */
00066 } Elf32_Ehdr;
00067 
00068 /* Offsets for the 1-byte fields within e_ident[] */
00069 #define EI_MAG0         0       /* '\177' */
00070 #define EI_MAG1         1       /* 'E'    */
00071 #define EI_MAG2         2       /* 'L'    */
00072 #define EI_MAG3         3       /* 'F'    */
00073 #define EI_CLASS        4       /* File class - always ELFCLASS32 */
00074 #define EI_DATA         5       /* Data encoding - ELFDATA2LSB or ELFDATA2MSB*/
00075 #define EI_VERSION      6       /* ELF version - EV_CURRENT*/
00076 #define EI_OSABI        7       /* OS/syscall ABI identification */
00077 #define EI_ABIVERSION   8       /* syscall ABI version */
00078 #define EI_PAD          9       /* Start of padding bytes up to EI_NIDENT*/
00079 
00080 /* Values for these fields */
00081 
00082 /* For e_ident[EI_MAG0..3] */
00083 #define ELFMAG0         0x7f
00084 #define ELFMAG1         'E'
00085 #define ELFMAG2         'L'
00086 #define ELFMAG3         'F'
00087 
00088 /* For e_ident[EI_CLASS] */
00089 #define ELFCLASSNONE    0       /* Invalid class */
00090 #define ELFCLASS32      1       /* 32-bit objects */
00091 #define ELFCLASS64      2       /* 64-bit objects */
00092 
00093 /* e_ident[EI_DATA] */
00094 #define ELFDATANONE     0       /* Invalid data encoding */
00095 #define ELFDATA2LSB     1       /* 2's complement values, LSB first */
00096 #define ELFDATA2MSB     2       /* 2's complement values, MSB first */
00097 
00098 /* e_ident[EI_VERSION] */
00099 #define EV_NONE         0       /* Invalid version */
00100 #define EV_CURRENT      1       /* Current version */
00101 
00102 /* e_ident[EI_OSABI] */
00103 #define ELFOSABI_SYSV           0       /* UNIX System V ABI */
00104 #define ELFOSABI_HPUX           1       /* HP-UX operating system */
00105 #define ELFOSABI_STANDALONE     255     /* Standalone (embedded) application */
00106 
00107 
00108 /*
00109  * Values for e_type
00110  */
00111 #define ET_NONE         0       /* No file type */
00112 #define ET_REL          1       /* Relocatable file */
00113 #define ET_EXEC         2       /* Executable file */
00114 #define ET_DYN          3       /* Shared object file */
00115 #define ET_CORE         4       /* Core file */
00116 #define ET_NUM          5
00117 
00118 /*
00119  * Values for e_machine
00120  */
00121 #define EM_NONE         0       /* No machine */
00122 #define EM_M32          1       /* AT&T WE 32100 */
00123 #define EM_SPARC        2       /* SPARC */
00124 #define EM_386          3       /* Intel 80386 */
00125 #define EM_68K          4       /* Motorola 68000 */
00126 #define EM_88K          5       /* Motorola 88000 */
00127 #define EM_486          6       /* Intel 80486 */
00128 #define EM_860          7       /* Intel 80860 */
00129 #define EM_MIPS         8       /* MIPS I Architecture */
00130 #define EM_S370         9       /* Amdahl UTS on System/370 */
00131 #define EM_MIPS_RS3_LE  10      /* MIPS RS3000 Little-endian */
00132 #define EM_RS6000       11      /* IBM RS/6000 XXX reserved */
00133 #define EM_PARISC       15      /* Hewlett-Packard PA-RISC */
00134 #define EM_NCUBE        16      /* NCube XXX reserved */
00135 #define EM_VPP500       17      /* Fujitsu VPP500 */
00136 #define EM_SPARC32PLUS  18      /* Enhanced instruction set SPARC */
00137 #define EM_960          19      /* Intel 80960 */
00138 #define EM_PPC          20      /* PowerPC */
00139 #define EM_V800         36      /* NEC V800 */
00140 #define EM_FR20         37      /* Fujitsu FR20 */
00141 #define EM_RH32         38      /* TRW RH-32 */
00142 #define EM_RCE          39      /* Motorola RCE */
00143 #define EM_ARM          40      /* Advanced RISC Machines ARM */
00144 #define EM_ALPHA        41      /* DIGITAL Alpha */
00145 #define EM_SH           42      /* Hitachi Super-H */
00146 #define EM_SPARCV9      43      /* SPARC Version 9 */
00147 #define EM_TRICORE      44      /* Siemens Tricore */
00148 #define EM_ARC          45      /* Argonaut RISC Core */
00149 #define EM_H8_300       46      /* Hitachi H8/300 */
00150 #define EM_H8_300H      47      /* Hitachi H8/300H */
00151 #define EM_H8S          48      /* Hitachi H8S */
00152 #define EM_H8_500       49      /* Hitachi H8/500 */
00153 #define EM_IA_64        50      /* Intel Merced Processor */
00154 #define EM_MIPS_X       51      /* Stanford MIPS-X */
00155 #define EM_COLDFIRE     52      /* Motorola Coldfire */
00156 #define EM_68HC12       53      /* Motorola MC68HC12 */
00157 #define EM_VAX          75      /* DIGITAL VAX */
00158 #define EM_ALPHA_EXP    36902   /* used by NetBSD/alpha; obsolete */
00159 #define EM_NUM          36903
00160 
00161 
00162 /*
00163  * "Program Header" - runtime segment header.
00164  * There are Ehdr.e_phnum of these located at one position within the file.
00165  *
00166  * Note: if p_memsz > p_filesz, the leftover space should be zero-filled.
00167  */
00168 typedef struct {
00169         uint32_t        p_type;      /* Type of segment */
00170         uint32_t        p_offset;    /* Location of data within file */
00171         uint32_t        p_vaddr;     /* Virtual address */
00172         uint32_t        p_paddr;     /* Ignore */
00173         uint32_t        p_filesz;    /* Size of data within file */
00174         uint32_t        p_memsz;     /* Size of data to be loaded into memory*/
00175         uint32_t        p_flags;     /* Flags */
00176         uint32_t        p_align;     /* Required alignment - can ignore */
00177 } Elf32_Phdr;
00178 
00179 /* values for p_type */
00180 #define PT_NULL         0               /* Program header table entry unused */
00181 #define PT_LOAD         1               /* Loadable program segment */
00182 #define PT_DYNAMIC      2               /* Dynamic linking information */
00183 #define PT_INTERP       3               /* Program interpreter */
00184 #define PT_NOTE         4               /* Auxiliary information */
00185 #define PT_SHLIB        5               /* Reserved, unspecified semantics */
00186 #define PT_PHDR         6               /* Entry for header table itself */
00187 #define PT_NUM          7
00188 #define PT_MIPS_REGINFO 0x70000000
00189 
00190 /* values for p_flags */
00191 #define PF_R            0x4     /* Segment is readable */
00192 #define PF_W            0x2     /* Segment is writable */
00193 #define PF_X            0x1     /* Segment is executable */
00194 
00195 
00196 typedef Elf32_Ehdr Elf_Ehdr;
00197 typedef Elf32_Phdr Elf_Phdr;
00198 
00199 
00200 #endif /* _ELF_H_ */
 All Data Structures