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