[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 | |
---|
[227] | 30 | #define EI_NIDENT (16) |
---|
| 31 | |
---|
| 32 | /* 32bit version */ |
---|
[1] | 33 | typedef uint16_t Elf32_Half; |
---|
| 34 | typedef uint32_t Elf32_Word; |
---|
[227] | 35 | typedef int32_t Elf32_Sword; |
---|
[1] | 36 | typedef uint32_t Elf32_Addr; |
---|
| 37 | typedef uint32_t Elf32_Off; |
---|
| 38 | |
---|
[227] | 39 | /* 64bit version */ |
---|
| 40 | typedef uint16_t Elf64_Half; |
---|
| 41 | typedef uint32_t Elf64_Word; |
---|
[273] | 42 | typedef int32_t Elf64_Sword; |
---|
| 43 | typedef uint64_t Elf64_Xword; |
---|
[227] | 44 | typedef uint64_t Elf64_Addr; |
---|
| 45 | typedef uint64_t Elf64_Off; |
---|
[1] | 46 | |
---|
[227] | 47 | /* ELF header - 32bit version. */ |
---|
[1] | 48 | typedef struct |
---|
| 49 | { |
---|
[227] | 50 | unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ |
---|
[1] | 51 | Elf32_Half e_type; /* Object file type */ |
---|
| 52 | Elf32_Half e_machine; /* Architecture */ |
---|
| 53 | Elf32_Word e_version; /* Object file version */ |
---|
[227] | 54 | Elf32_Addr e_entry; /* Entry point virtual address */ |
---|
| 55 | Elf32_Off e_phoff; /* Program header table file offset */ |
---|
| 56 | Elf32_Off e_shoff; /* Section header table file offset */ |
---|
[1] | 57 | Elf32_Word e_flags; /* Processor-specific flags */ |
---|
| 58 | Elf32_Half e_ehsize; /* ELF header size in bytes */ |
---|
| 59 | Elf32_Half e_phentsize; /* Program header table entry size */ |
---|
| 60 | Elf32_Half e_phnum; /* Program header table entry count */ |
---|
| 61 | Elf32_Half e_shentsize; /* Section header table entry size */ |
---|
| 62 | Elf32_Half e_shnum; /* Section header table entry count */ |
---|
| 63 | Elf32_Half e_shstrndx; /* Section header string table index */ |
---|
[156] | 64 | } |
---|
[1] | 65 | Elf32_Ehdr; |
---|
| 66 | |
---|
[227] | 67 | /* ELF header - 64bit version. */ |
---|
| 68 | typedef struct |
---|
| 69 | { |
---|
| 70 | unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ |
---|
| 71 | Elf64_Half e_type; /* Object file type */ |
---|
| 72 | Elf64_Half e_machine; /* Architecture */ |
---|
| 73 | Elf64_Word e_version; /* Object file version */ |
---|
| 74 | Elf64_Addr e_entry; /* Entry point virtual address */ |
---|
| 75 | Elf64_Off e_phoff; /* Program header table file offset */ |
---|
| 76 | Elf64_Off e_shoff; /* Section header table file offset */ |
---|
| 77 | Elf64_Word e_flags; /* Processor-specific flags */ |
---|
| 78 | Elf64_Half e_ehsize; /* ELF header size in bytes */ |
---|
| 79 | Elf64_Half e_phentsize; /* Program header table entry size */ |
---|
| 80 | Elf64_Half e_phnum; /* Program header table entry count */ |
---|
| 81 | Elf64_Half e_shentsize; /* Section header table entry size */ |
---|
| 82 | Elf64_Half e_shnum; /* Section header table entry count */ |
---|
| 83 | Elf64_Half e_shstrndx; /* Section header string table index */ |
---|
| 84 | } |
---|
| 85 | Elf64_Ehdr; |
---|
| 86 | |
---|
[157] | 87 | /* |
---|
| 88 | * Fields in the e_ident array. The EI_* macros are indices into the |
---|
| 89 | * array. The macros under each EI_* macro are the values the byte |
---|
| 90 | * may have. |
---|
| 91 | */ |
---|
[1] | 92 | #define EI_MAG0 0 /* File identification byte 0 index */ |
---|
| 93 | #define ELFMAG0 0x7f /* Magic number byte 0 */ |
---|
| 94 | |
---|
| 95 | #define EI_MAG1 1 /* File identification byte 1 index */ |
---|
| 96 | #define ELFMAG1 'E' /* Magic number byte 1 */ |
---|
| 97 | |
---|
| 98 | #define EI_MAG2 2 /* File identification byte 2 index */ |
---|
| 99 | #define ELFMAG2 'L' /* Magic number byte 2 */ |
---|
| 100 | |
---|
| 101 | #define EI_MAG3 3 /* File identification byte 3 index */ |
---|
| 102 | #define ELFMAG3 'F' /* Magic number byte 3 */ |
---|
| 103 | |
---|
| 104 | #define EI_CLASS 4 /* File class byte index */ |
---|
| 105 | #define ELFCLASSNONE 0 /* Invalid class */ |
---|
| 106 | #define ELFCLASS32 1 /* 32-bit objects */ |
---|
[270] | 107 | #define ELFCLASS64 2 /* 64-bit objects */ |
---|
| 108 | |
---|
[1] | 109 | #define ELFCLASSNUM 3 |
---|
| 110 | |
---|
| 111 | #define EI_DATA 5 /* Data encoding byte index */ |
---|
| 112 | #define ELFDATANONE 0 /* Invalid data encoding */ |
---|
| 113 | #define ELFDATA2LSB 1 /* 2's complement, little endian */ |
---|
| 114 | #define ELFDATA2MSB 2 /* 2's complement, big endian */ |
---|
| 115 | #define ELFDATANUM 3 |
---|
| 116 | |
---|
| 117 | #define EI_VERSION 6 /* File version byte index */ |
---|
| 118 | /* Value must be EV_CURRENT */ |
---|
| 119 | |
---|
| 120 | #define EI_OSABI 7 /* OS ABI identification */ |
---|
| 121 | #define ELFOSABI_NONE 0 /* UNIX System V ABI */ |
---|
| 122 | |
---|
| 123 | /* Legal values for e_type (object file type). */ |
---|
| 124 | #define ET_NONE 0 /* No file type */ |
---|
| 125 | #define ET_REL 1 /* Relocatable file */ |
---|
| 126 | #define ET_EXEC 2 /* Executable file */ |
---|
| 127 | #define ET_DYN 3 /* Shared object file */ |
---|
| 128 | #define ET_CORE 4 /* Core file */ |
---|
| 129 | #define ET_NUM 5 /* Number of defined types */ |
---|
| 130 | #define ET_LOOS 0xfe00 /* OS-specific range start */ |
---|
| 131 | #define ET_HIOS 0xfeff /* OS-specific range end */ |
---|
| 132 | #define ET_LOPROC 0xff00 /* Processor-specific range start */ |
---|
| 133 | #define ET_HIPROC 0xffff /* Processor-specific range end */ |
---|
| 134 | |
---|
| 135 | /* Legal values for e_machine (architecture). */ |
---|
| 136 | #define EM_NONE 0 /* No machine */ |
---|
| 137 | #define EM_MIPS 8 /* MIPS R3000 big-endian */ |
---|
| 138 | #define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ |
---|
| 139 | #define EM_PPC 20 /* PowerPC */ |
---|
| 140 | #define EM_PPC64 21 /* PowerPC 64-bit */ |
---|
| 141 | #define EM_ARM 40 /* ARM */ |
---|
[158] | 142 | #define EM_X86_64 62 /* AMD x86-64 architecture */ |
---|
[1] | 143 | |
---|
| 144 | /* Legal values for e_version (version). */ |
---|
| 145 | #define EV_NONE 0 /* Invalid ELF version */ |
---|
| 146 | #define EV_CURRENT 1 /* Current version */ |
---|
| 147 | #define EV_NUM 2 |
---|
| 148 | |
---|
[227] | 149 | /* Program segment header - 32bit version. */ |
---|
[1] | 150 | typedef struct |
---|
| 151 | { |
---|
[227] | 152 | Elf32_Word p_type; /* Segment type */ |
---|
| 153 | Elf32_Off p_offset; /* Segment file offset */ |
---|
| 154 | Elf32_Addr p_vaddr; /* Segment virtual address */ |
---|
| 155 | Elf32_Addr p_paddr; /* Segment physical address */ |
---|
| 156 | Elf32_Word p_filesz; /* Segment size in file */ |
---|
| 157 | Elf32_Word p_memsz; /* Segment size in memory */ |
---|
| 158 | Elf32_Word p_flags; /* Segment flags */ |
---|
| 159 | Elf32_Word p_align; /* Segment alignment */ |
---|
[156] | 160 | } |
---|
[1] | 161 | Elf32_Phdr; |
---|
| 162 | |
---|
[227] | 163 | /* Program segment header - 64bit version. */ |
---|
| 164 | typedef struct |
---|
| 165 | { |
---|
| 166 | Elf64_Word p_type; /* Segment type */ |
---|
| 167 | Elf64_Word p_flags; /* Segment flags */ |
---|
| 168 | Elf64_Off p_offset; /* Segment file offset */ |
---|
| 169 | Elf64_Addr p_vaddr; /* Segment virtual address */ |
---|
| 170 | Elf64_Addr p_paddr; /* Segment physical address */ |
---|
[273] | 171 | Elf64_Xword p_filesz; /* Segment size in file */ |
---|
| 172 | Elf64_Xword p_memsz; /* Segment size in memory */ |
---|
| 173 | Elf64_Xword p_align; /* Segment alignment */ |
---|
[227] | 174 | } |
---|
| 175 | Elf64_Phdr; |
---|
| 176 | |
---|
[1] | 177 | /* Legal values for p_type (segment type). */ |
---|
| 178 | #define PT_NULL 0 /* Program header table entry unused */ |
---|
| 179 | #define PT_LOAD 1 /* Loadable program segment */ |
---|
| 180 | #define PT_DYNAMIC 2 /* Dynamic linking information */ |
---|
| 181 | #define PT_INTERP 3 /* Program interpreter */ |
---|
| 182 | #define PT_NOTE 4 /* Auxiliary information */ |
---|
| 183 | #define PT_SHLIB 5 /* Reserved */ |
---|
| 184 | #define PT_PHDR 6 /* Entry for header table itself */ |
---|
| 185 | #define PT_TLS 7 /* Thread-local storage segment */ |
---|
| 186 | #define PT_NUM 8 /* Number of defined types */ |
---|
| 187 | #define PT_LOOS 0x60000000 /* Start of OS-specific */ |
---|
| 188 | #define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */ |
---|
| 189 | #define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */ |
---|
| 190 | #define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ |
---|
| 191 | #define PT_LOSUNW 0x6ffffffa |
---|
| 192 | #define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ |
---|
| 193 | #define PT_SUNWSTACK 0x6ffffffb /* Stack segment */ |
---|
| 194 | #define PT_HISUNW 0x6fffffff |
---|
| 195 | #define PT_HIOS 0x6fffffff /* End of OS-specific */ |
---|
| 196 | #define PT_LOPROC 0x70000000 /* Start of processor-specific */ |
---|
| 197 | #define PT_HIPROC 0x7fffffff /* End of processor-specific */ |
---|
| 198 | |
---|
| 199 | /* Legal values for p_flags (segment flags). */ |
---|
| 200 | #define PF_X (1 << 0) /* Segment is executable */ |
---|
| 201 | #define PF_W (1 << 1) /* Segment is writable */ |
---|
| 202 | #define PF_R (1 << 2) /* Segment is readable */ |
---|
| 203 | #define PF_MASKOS 0x0ff00000 /* OS-specific */ |
---|
| 204 | #define PF_MASKPROC 0xf0000000 /* Processor-specific */ |
---|
| 205 | |
---|
[227] | 206 | #if defined(HAL_32BIT) |
---|
| 207 | #define Elf_Half Elf32_Half |
---|
| 208 | #define Elf_Word Elf32_Word |
---|
| 209 | #define Elf_Sword Elf32_Sword |
---|
| 210 | #define Elf_Addr Elf32_Addr |
---|
| 211 | #define Elf_Off Elf32_Off |
---|
| 212 | #define Elf_Ehdr Elf32_Ehdr |
---|
| 213 | #define Elf_Phdr Elf32_Phdr |
---|
[270] | 214 | #define ELFCLASS ELFCLASS32 |
---|
[227] | 215 | #elif defined (HAL_64BIT) |
---|
| 216 | #define Elf_Half Elf64_Half |
---|
| 217 | #define Elf_Word Elf64_Word |
---|
| 218 | #define Elf_Sword Elf64_Sword |
---|
[273] | 219 | #define Elf_Xword Elf64_Xword |
---|
[227] | 220 | #define Elf_Addr Elf64_Addr |
---|
| 221 | #define Elf_Off Elf64_Off |
---|
| 222 | #define Elf_Ehdr Elf64_Ehdr |
---|
| 223 | #define Elf_Phdr Elf64_Phdr |
---|
[270] | 224 | #define ELFCLASS ELFCLASS64 |
---|
[227] | 225 | #else |
---|
| 226 | #error "Must define HAL_64BIT/HAL_32BIT" |
---|
| 227 | #endif |
---|
[1] | 228 | |
---|
| 229 | /**************************************************************************************** |
---|
[156] | 230 | * This function registers in VMM the CODE and DATA vsegs defined in the .elf file. |
---|
[1] | 231 | * The segments are not loaded in memory. |
---|
[156] | 232 | * It also registers the process entry point in VMM. |
---|
[1] | 233 | **************************************************************************************** |
---|
[204] | 234 | * @ pathname : local pointer on .elf file pathname (in kernel space). |
---|
[1] | 235 | * @ process : local pointer on target process descriptor. |
---|
| 236 | ***************************************************************************************/ |
---|
| 237 | error_t elf_load_process( char * pathname, |
---|
| 238 | process_t * process); |
---|
| 239 | |
---|
| 240 | #endif /* elf.h */ |
---|