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