| [1] | 1 | /* This file defines standard ELF types, structures, and macros. | 
|---|
|  | 2 | Copyright (C) 1995-2003,2004,2005,2006,2007,2008,2009 | 
|---|
|  | 3 | Free Software Foundation, Inc. | 
|---|
|  | 4 | This file is part of the GNU C Library. | 
|---|
|  | 5 |  | 
|---|
|  | 6 | The GNU C Library is free software; you can redistribute it and/or | 
|---|
|  | 7 | modify it under the terms of the GNU Lesser General Public | 
|---|
|  | 8 | License as published by the Free Software Foundation; either | 
|---|
|  | 9 | version 2.1 of the License, or (at your option) any later version. | 
|---|
|  | 10 |  | 
|---|
|  | 11 | The GNU C Library is distributed in the hope that it will be useful, | 
|---|
|  | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
|  | 14 | Lesser General Public License for more details. | 
|---|
|  | 15 |  | 
|---|
|  | 16 | You should have received a copy of the GNU Lesser General Public | 
|---|
|  | 17 | License along with the GNU C Library; if not, write to the Free | 
|---|
|  | 18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 
|---|
|  | 19 | 02111-1307 USA.  */ | 
|---|
|  | 20 |  | 
|---|
|  | 21 | #ifndef _ELF_H_ | 
|---|
|  | 22 | #define _ELF_H_ 1 | 
|---|
|  | 23 |  | 
|---|
|  | 24 | #include <hal_types.h> | 
|---|
|  | 25 |  | 
|---|
| [157] | 26 | /* | 
|---|
|  | 27 | * Standard ELF types. | 
|---|
|  | 28 | */ | 
|---|
| [1] | 29 |  | 
|---|
| [157] | 30 | /* Type for a 16-bit quantity. */ | 
|---|
| [1] | 31 | typedef uint16_t Elf32_Half; | 
|---|
|  | 32 |  | 
|---|
| [157] | 33 | /* Types for signed and unsigned 32-bit quantities. */ | 
|---|
| [1] | 34 | typedef uint32_t Elf32_Word; | 
|---|
|  | 35 | typedef int32_t  Elf32_Sword; | 
|---|
|  | 36 |  | 
|---|
| [157] | 37 | /* Type of addresses. */ | 
|---|
| [1] | 38 | typedef uint32_t Elf32_Addr; | 
|---|
|  | 39 |  | 
|---|
| [157] | 40 | /* Type of file offsets. */ | 
|---|
| [1] | 41 | typedef uint32_t Elf32_Off; | 
|---|
|  | 42 |  | 
|---|
| [157] | 43 | /* Type for section indices, which are 16-bit quantities. */ | 
|---|
| [1] | 44 | typedef uint16_t Elf32_Section; | 
|---|
|  | 45 |  | 
|---|
| [157] | 46 | /* Type for version symbol information. */ | 
|---|
| [1] | 47 | typedef Elf32_Half Elf32_Versym; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | /************************************************************************************* | 
|---|
|  | 50 | * This structure defines the ELF file header (first bytes in the file) | 
|---|
|  | 51 | *************************************************************************************/ | 
|---|
|  | 52 |  | 
|---|
|  | 53 | #define EI_NIDENT (16) | 
|---|
|  | 54 |  | 
|---|
|  | 55 | typedef struct | 
|---|
|  | 56 | { | 
|---|
|  | 57 | unsigned char   e_ident[EI_NIDENT];     /* Magic number and other info */ | 
|---|
|  | 58 | Elf32_Half      e_type;             /* Object file type */ | 
|---|
|  | 59 | Elf32_Half      e_machine;          /* Architecture */ | 
|---|
|  | 60 | Elf32_Word      e_version;          /* Object file version */ | 
|---|
|  | 61 | Elf32_Addr          e_entry;            /* Entry point virtual address */ | 
|---|
|  | 62 | Elf32_Off           e_phoff;            /* Program header table file offset */ | 
|---|
|  | 63 | Elf32_Off           e_shoff;            /* Section header table file offset */ | 
|---|
|  | 64 | Elf32_Word      e_flags;            /* Processor-specific flags */ | 
|---|
|  | 65 | Elf32_Half      e_ehsize;           /* ELF header size in bytes */ | 
|---|
|  | 66 | Elf32_Half      e_phentsize;        /* Program header table entry size */ | 
|---|
|  | 67 | Elf32_Half      e_phnum;            /* Program header table entry count */ | 
|---|
|  | 68 | Elf32_Half      e_shentsize;        /* Section header table entry size */ | 
|---|
|  | 69 | Elf32_Half      e_shnum;            /* Section header table entry count */ | 
|---|
|  | 70 | Elf32_Half      e_shstrndx;         /* Section header string table index */ | 
|---|
| [156] | 71 | } | 
|---|
| [1] | 72 | Elf32_Ehdr; | 
|---|
|  | 73 |  | 
|---|
| [157] | 74 | /* | 
|---|
|  | 75 | * Fields in the e_ident array. The EI_* macros are indices into the | 
|---|
|  | 76 | * array. The macros under each EI_* macro are the values the byte | 
|---|
|  | 77 | * may have. | 
|---|
|  | 78 | */ | 
|---|
| [1] | 79 | #define EI_MAG0         0               /* File identification byte 0 index */ | 
|---|
|  | 80 | #define ELFMAG0         0x7f            /* Magic number byte 0 */ | 
|---|
|  | 81 |  | 
|---|
|  | 82 | #define EI_MAG1         1               /* File identification byte 1 index */ | 
|---|
|  | 83 | #define ELFMAG1         'E'             /* Magic number byte 1 */ | 
|---|
|  | 84 |  | 
|---|
|  | 85 | #define EI_MAG2         2               /* File identification byte 2 index */ | 
|---|
|  | 86 | #define ELFMAG2         'L'             /* Magic number byte 2 */ | 
|---|
|  | 87 |  | 
|---|
|  | 88 | #define EI_MAG3         3               /* File identification byte 3 index */ | 
|---|
|  | 89 | #define ELFMAG3         'F'             /* Magic number byte 3 */ | 
|---|
|  | 90 |  | 
|---|
|  | 91 | #define EI_CLASS        4               /* File class byte index */ | 
|---|
|  | 92 | #define ELFCLASSNONE    0               /* Invalid class */ | 
|---|
|  | 93 | #define ELFCLASS32      1               /* 32-bit objects */ | 
|---|
|  | 94 | #define ELFCLASSNUM     3 | 
|---|
|  | 95 |  | 
|---|
|  | 96 | #define EI_DATA         5               /* Data encoding byte index */ | 
|---|
|  | 97 | #define ELFDATANONE     0               /* Invalid data encoding */ | 
|---|
|  | 98 | #define ELFDATA2LSB     1               /* 2's complement, little endian */ | 
|---|
|  | 99 | #define ELFDATA2MSB     2               /* 2's complement, big endian */ | 
|---|
|  | 100 | #define ELFDATANUM      3 | 
|---|
|  | 101 |  | 
|---|
|  | 102 | #define EI_VERSION      6               /* File version byte index */ | 
|---|
|  | 103 | /* Value must be EV_CURRENT */ | 
|---|
|  | 104 |  | 
|---|
|  | 105 | #define EI_OSABI        7               /* OS ABI identification */ | 
|---|
|  | 106 | #define ELFOSABI_NONE           0       /* UNIX System V ABI */ | 
|---|
|  | 107 |  | 
|---|
|  | 108 | /* Legal values for e_type (object file type).  */ | 
|---|
|  | 109 | #define ET_NONE         0               /* No file type */ | 
|---|
|  | 110 | #define ET_REL          1               /* Relocatable file */ | 
|---|
|  | 111 | #define ET_EXEC         2               /* Executable file */ | 
|---|
|  | 112 | #define ET_DYN          3               /* Shared object file */ | 
|---|
|  | 113 | #define ET_CORE         4               /* Core file */ | 
|---|
|  | 114 | #define ET_NUM          5               /* Number of defined types */ | 
|---|
|  | 115 | #define ET_LOOS         0xfe00          /* OS-specific range start */ | 
|---|
|  | 116 | #define ET_HIOS         0xfeff          /* OS-specific range end */ | 
|---|
|  | 117 | #define ET_LOPROC       0xff00          /* Processor-specific range start */ | 
|---|
|  | 118 | #define ET_HIPROC       0xffff          /* Processor-specific range end */ | 
|---|
|  | 119 |  | 
|---|
|  | 120 | /* Legal values for e_machine (architecture).  */ | 
|---|
|  | 121 | #define EM_NONE          0              /* No machine */ | 
|---|
|  | 122 | #define EM_MIPS          8              /* MIPS R3000 big-endian */ | 
|---|
|  | 123 | #define EM_MIPS_RS3_LE  10              /* MIPS R3000 little-endian */ | 
|---|
|  | 124 | #define EM_PPC          20              /* PowerPC */ | 
|---|
|  | 125 | #define EM_PPC64        21              /* PowerPC 64-bit */ | 
|---|
|  | 126 | #define EM_ARM          40              /* ARM */ | 
|---|
| [158] | 127 | #define EM_X86_64       62              /* AMD x86-64 architecture */ | 
|---|
| [1] | 128 |  | 
|---|
|  | 129 | /* Legal values for e_version (version).  */ | 
|---|
|  | 130 | #define EV_NONE         0               /* Invalid ELF version */ | 
|---|
|  | 131 | #define EV_CURRENT      1               /* Current version */ | 
|---|
|  | 132 | #define EV_NUM          2 | 
|---|
|  | 133 |  | 
|---|
|  | 134 | /* Program segment header.  */ | 
|---|
|  | 135 |  | 
|---|
|  | 136 | typedef struct | 
|---|
|  | 137 | { | 
|---|
|  | 138 | Elf32_Word      p_type;         /* Segment type */ | 
|---|
|  | 139 | Elf32_Off       p_offset;       /* Segment file offset */ | 
|---|
|  | 140 | Elf32_Addr      p_vaddr;        /* Segment virtual address */ | 
|---|
|  | 141 | Elf32_Addr      p_paddr;        /* Segment physical address */ | 
|---|
|  | 142 | Elf32_Word      p_filesz;       /* Segment size in file */ | 
|---|
|  | 143 | Elf32_Word      p_memsz;        /* Segment size in memory */ | 
|---|
|  | 144 | Elf32_Word      p_flags;        /* Segment flags */ | 
|---|
|  | 145 | Elf32_Word      p_align;    /* Segment alignment */ | 
|---|
| [156] | 146 | } | 
|---|
| [1] | 147 | Elf32_Phdr; | 
|---|
|  | 148 |  | 
|---|
|  | 149 | /* Legal values for p_type (segment type).  */ | 
|---|
|  | 150 | #define PT_NULL         0               /* Program header table entry unused */ | 
|---|
|  | 151 | #define PT_LOAD         1               /* Loadable program segment */ | 
|---|
|  | 152 | #define PT_DYNAMIC      2               /* Dynamic linking information */ | 
|---|
|  | 153 | #define PT_INTERP       3               /* Program interpreter */ | 
|---|
|  | 154 | #define PT_NOTE         4               /* Auxiliary information */ | 
|---|
|  | 155 | #define PT_SHLIB        5               /* Reserved */ | 
|---|
|  | 156 | #define PT_PHDR         6               /* Entry for header table itself */ | 
|---|
|  | 157 | #define PT_TLS          7               /* Thread-local storage segment */ | 
|---|
|  | 158 | #define PT_NUM          8               /* Number of defined types */ | 
|---|
|  | 159 | #define PT_LOOS         0x60000000      /* Start of OS-specific */ | 
|---|
|  | 160 | #define PT_GNU_EH_FRAME 0x6474e550      /* GCC .eh_frame_hdr segment */ | 
|---|
|  | 161 | #define PT_GNU_STACK    0x6474e551      /* Indicates stack executability */ | 
|---|
|  | 162 | #define PT_GNU_RELRO    0x6474e552      /* Read-only after relocation */ | 
|---|
|  | 163 | #define PT_LOSUNW       0x6ffffffa | 
|---|
|  | 164 | #define PT_SUNWBSS      0x6ffffffa      /* Sun Specific segment */ | 
|---|
|  | 165 | #define PT_SUNWSTACK    0x6ffffffb      /* Stack segment */ | 
|---|
|  | 166 | #define PT_HISUNW       0x6fffffff | 
|---|
|  | 167 | #define PT_HIOS         0x6fffffff      /* End of OS-specific */ | 
|---|
|  | 168 | #define PT_LOPROC       0x70000000      /* Start of processor-specific */ | 
|---|
|  | 169 | #define PT_HIPROC       0x7fffffff      /* End of processor-specific */ | 
|---|
|  | 170 |  | 
|---|
|  | 171 | /* Legal values for p_flags (segment flags).  */ | 
|---|
|  | 172 | #define PF_X            (1 << 0)        /* Segment is executable */ | 
|---|
|  | 173 | #define PF_W            (1 << 1)        /* Segment is writable */ | 
|---|
|  | 174 | #define PF_R            (1 << 2)        /* Segment is readable */ | 
|---|
|  | 175 | #define PF_MASKOS       0x0ff00000      /* OS-specific */ | 
|---|
|  | 176 | #define PF_MASKPROC     0xf0000000      /* Processor-specific */ | 
|---|
|  | 177 |  | 
|---|
|  | 178 |  | 
|---|
|  | 179 | /**************************************************************************************** | 
|---|
| [156] | 180 | * This function registers in VMM the CODE and DATA vsegs defined in the .elf file. | 
|---|
| [1] | 181 | * The segments are not loaded in memory. | 
|---|
| [156] | 182 | * It also registers the process entry point in VMM. | 
|---|
| [1] | 183 | **************************************************************************************** | 
|---|
| [204] | 184 | * @ pathname : local pointer on .elf file pathname (in kernel space). | 
|---|
| [1] | 185 | * @ process  : local pointer on target process descriptor. | 
|---|
|  | 186 | ***************************************************************************************/ | 
|---|
|  | 187 | error_t elf_load_process( char      * pathname, | 
|---|
|  | 188 | process_t * process); | 
|---|
|  | 189 |  | 
|---|
|  | 190 | #endif  /* elf.h */ | 
|---|