00001 /*! \file include/kernel/elf32.h 00002 * \brief ELF32 file format header. 00003 * \author Andrea Righi <drizzt@inwind.it> 00004 * \date Last update: 2003-10-01 00005 * \note Copyright (©) 2003 Andrea Righi 00006 */ 00007 00008 #ifndef ELF32_H 00009 #define ELF32_H 00010 00011 /** \ingroup Kernel 00012 * \defgroup KElf32 ELF32 loader 00013 * The loader of the ELF32 format files. 00014 * @{ 00015 */ 00016 00017 // --- 32-bit ELF address types ----------------------------------------// 00018 00019 typedef uint32_t Elf32_Addr; 00020 typedef uint16_t Elf32_Half; 00021 typedef uint32_t Elf32_Off; 00022 typedef int32_t Elf32_Sword; 00023 typedef uint32_t Elf32_Word; 00024 00025 // -- ELF32 header -----------------------------------------------------// 00026 00027 #define EI_NIDENT 16 //!< Size of e_ident[]. 00028 00029 //! 32-bit ELF header. 00030 typedef struct elf32_hdr 00031 { 00032 unsigned char e_ident[EI_NIDENT]; 00033 Elf32_Half e_type; 00034 Elf32_Half e_machine; 00035 Elf32_Word e_version; 00036 Elf32_Addr e_entry; 00037 Elf32_Off e_phoff; 00038 Elf32_Off e_shoff; 00039 Elf32_Word e_flags; 00040 Elf32_Half e_ehsize; 00041 Elf32_Half e_phentsize; 00042 Elf32_Half phnum; 00043 Elf32_Half e_shentsize; 00044 Elf32_Half e_shnum; 00045 Elf32_Half e_shstrndx; 00046 } elf32_hdr_t; 00047 00048 #define EI_MAG0 0 //!< File magic number (0). 00049 #define EI_MAG1 1 //!< File magic number (1). 00050 #define EI_MAG2 2 //!< File magic number (2). 00051 #define EI_MAG3 3 //!< File magic number (3) 00052 #define EI_CLASS 4 //!< File class. 00053 #define EI_DATA 5 //!< Data encoding. 00054 #define EI_VERSION 6 //!< File version. 00055 #define EI_PAD 7 //!< Start of padding bytes. 00056 00057 #define ELF_MAG0 0x7F //!<< ELF magic number. 00058 #define ELF_MAG1 'E' //!<< ELF magic number[0]. 00059 #define ELF_MAG2 'L' //!< ELF magic number[1]. 00060 #define ELF_MAG3 'F' //!< ELF magic number[2]. 00061 00062 // ELF class or capacity // 00063 #define ELF_CLASSNONE 0 //!< Invalid class. 00064 #define ELF_CLASS32 1 //!< 32-bit objects. 00065 #define ELF_CLASS64 2 //!< 64-bit objects. 00066 00067 // ELF data encoding // 00068 #define ELF_DATANONE 0 //!< Invalid data encoding. 00069 #define ELF_DATA2LSB 1 //!< Least significant byte encoding. 00070 #define ELF_DATA2MSB 2 //!< Most significant byte encoding. 00071 00072 // --- ELF32 Sections --------------------------------------------------// 00073 00074 //! ELF32 Section header. 00075 typedef struct elf32_shdr 00076 { 00077 Elf32_Word sh_name; 00078 Elf32_Word sh_type; 00079 Elf32_Word sh_flags; 00080 Elf32_Addr sh_addr; 00081 Elf32_Off sh_offset; 00082 Elf32_Word sh_size; 00083 Elf32_Word sh_link; 00084 Elf32_Word sh_info; 00085 Elf32_Word sh_addralign; 00086 Elf32_Word sh_entsize; 00087 } elf32_shdr_t; 00088 00089 // Section types // 00090 00091 //! The section is inactive. 00092 #define SHT_NULL 0 00093 //! The section holds informations defined by the program, whose format 00094 //! and meaning are determined solely by the program. 00095 #define SHT_PROGBITS 1 00096 //! The section holds a symbol table. 00097 #define SHT_SYMTAB 2 00098 //! The section holds a string table. 00099 #define SHT_STRTAB 3 00100 //! The section holds relocation entries. 00101 #define SHT_RELA 4 00102 //! The section holds a symbol hash table. 00103 #define SHT_HASH 5 00104 //! The section holds informations for dynamic linking. 00105 #define SHT_DYNAMIC 6 00106 //! The section holds informations that marks the file in some way. 00107 #define SHT_NOTE 7 00108 //! A section of this type occupies no space in the file but otherwise 00109 //! resembles SHT_PROGBITS. Although this section contains no bytes, the 00110 //! \c sh_offset member contains the conceptual file offset. 00111 //! For example the ".bss" section can be considered a section of this 00112 //! type. 00113 #define SHT_NOBITS 8 00114 //! The section holds a relocation entries without explicit addends. 00115 #define SHT_REL 9 00116 //! This section type is reserved, but has unspecified semantics. 00117 #define SHT_SHLIB 10 00118 //! This section contains a set of dynamic linking symbols. 00119 #define SHT_DYNSYM 11 00120 //! Values in this exclusive range are reserved for processor-specific 00121 //! semantics. 00122 #define SHT_LOPROC 0x700000000 00123 //! Values in this exclusive range are reserved for processor-specific 00124 //! semantics. 00125 #define SHT_HIPROC 0x700000000 00126 //! This value specifies the lower bound of the range of indexes 00127 //! reserved for application programs. 00128 #define SHT_LOUSER 0x700000000 00129 //! This value specifies the upper bound of the range of indexes 00130 //! reserved for application programs. 00131 #define SHT_HIUSER 0x700000000 00132 00133 // Section attribute flags // 00134 00135 //! Data should be writable during the process execution. 00136 #define SHF_WRITE 0x1 00137 //! The section occupies memory during the process execution. 00138 #define SHF_ALLOC 0x2 00139 //! The section contains executable machine instructions. 00140 #define SHF_EXECINSTR 0x4 00141 //! All bits included in this mask are reserved for processor-specific 00142 //! semantics. 00143 #define SHF_MASKPROC 0xF00000000 00144 00145 // --- Prototypes ------------------------------------------------------// 00146 00147 uint32_t elf32_copy_sections(elf32_hdr_t *f); 00148 int elf32_load_file(char *file_name, void *file_buffer); 00149 int elf32_exec(void *f, int argc, char **argv); 00150 00151 /** @} */ // end of KElf32 00152 00153 #endif