diff --git a/src/p_elf.h b/src/p_elf.h index cfcef310..39c3cd27 100644 --- a/src/p_elf.h +++ b/src/p_elf.h @@ -35,143 +35,23 @@ **************************************************************************/ // The ELF file header. This appears at the start of every ELF file. -struct Elf_LE32_Ehdr +template +struct TT_Elf32_Ehdr { unsigned char e_ident[16]; /* Magic number and other info */ - LE16 e_type; /* Object file type */ - LE16 e_machine; /* Architecture */ - LE32 e_version; /* Object file version */ - LE32 e_entry; /* Entry point virtual address */ - LE32 e_phoff; /* Program header table file offset */ - LE32 e_shoff; /* Section header table file offset */ - LE32 e_flags; /* Processor-specific flags */ - LE16 e_ehsize; /* ELF header size in bytes */ - LE16 e_phentsize; /* Program header table entry size */ - LE16 e_phnum; /* Program header table entry count */ - LE16 e_shentsize; /* Section header table entry size */ - LE16 e_shnum; /* Section header table entry count */ - LE16 e_shstrndx; /* Section header string table index */ - - // Values for e_type - enum { - ET_NONE = 0, /* No file type */ - ET_REL = 1, /* Relocatable file */ - ET_EXEC = 2, /* Executable file */ - ET_DYN = 3, /* Shared object file */ - ET_CORE = 4 /* Core file */ - }; -} -__attribute_packed; - - -// Program segment header. -struct Elf_LE32_Phdr -{ - LE32 p_type; /* Segment type */ - LE32 p_offset; /* Segment file offset */ - LE32 p_vaddr; /* Segment virtual address */ - LE32 p_paddr; /* Segment physical address */ - LE32 p_filesz; /* Segment size in file */ - LE32 p_memsz; /* Segment size in memory */ - LE32 p_flags; /* Segment flags */ - LE32 p_align; /* Segment alignment */ - - // Values for p_type - enum { - PT_LOAD = 1, /* Loadable program segment */ - PT_DYNAMIC = 2, /* Dynamic linking information */ - PT_INTERP = 3, /* Name of program interpreter */ - PT_PHDR = 6 /* Entry for header table itself */ - }; - - // Values for p_flags - enum { PF_X = (1 << 0) }; /* Segment is executable */ - enum { PF_W = (1 << 1) }; /* Segment is writable */ - enum { PF_R = (1 << 2) }; /* Segment is readable */ -} -__attribute_packed; - - -struct Elf_LE32_Shdr -{ - LE32 sh_name; /* Section name (string tbl index) */ - LE32 sh_type; /* Section type */ - LE32 sh_flags; /* Section flags */ - LE32 sh_addr; /* Section virtual addr at execution */ - LE32 sh_offset; /* Section file offset */ - LE32 sh_size; /* Section size in bytes */ - LE32 sh_link; /* Link to another section */ - LE32 sh_info; /* Additional section information */ - LE32 sh_addralign; /* Section alignment */ - LE32 sh_entsize; /* Entry size if section holds table */ - - enum { // values for sh_type - SHT_NULL = 0, /* Section header table entry unused */ - SHT_PROGBITS = 1,/* Program data */ - SHT_SYMTAB = 2, /* Symbol table */ - SHT_STRTAB = 3, /* String table */ - SHT_RELA = 4, /* Relocation entries with addends */ - SHT_HASH = 5, /* Symbol hash table */ - SHT_DYNAMIC = 6, /* Dynamic linking information */ - SHT_NOTE = 7, /* Notes */ - SHT_NOBITS = 8, /* Program space with no data (bss) */ - SHT_REL = 9, /* Relocation entries, no addends */ - SHT_SHLIB = 10, /* Reserved */ - SHT_DYNSYM = 11, /* Dynamic linker symbol table */ - /* 12, 13 hole */ - SHT_INIT_ARRAY = 14, /* Array of constructors */ - SHT_FINI_ARRAY = 15, /* Array of destructors */ - SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */ - SHT_GROUP = 17, /* Section group */ - SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */ - SHT_NUM = 19 /* Number of defined types. */ - }; - - enum { // values for sh_flags - SHF_WRITE = (1 << 0), /* Writable */ - SHF_ALLOC = (1 << 1), /* Occupies memory during execution */ - SHF_EXECINSTR = (1 << 2), /* Executable */ - SHF_MERGE = (1 << 4), /* Might be merged */ - SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */ - SHF_INFO_LINK = (1 << 6), /* `sh_info' contains SHT index */ - SHF_LINK_ORDER = (1 << 7), /* Preserve order after combining */ - }; -} -__attribute_packed; - -struct Elf_LE32_Dyn -{ - LE32 d_tag; - LE32 d_val; - - enum { // tags - DT_NULL = 0, /* End flag */ - DT_NEEDED = 1, /* Name of needed library */ - DT_STRTAB = 5, /* String table */ - DT_STRSZ = 10 /* Sizeof string table */ - }; -} -__attribute_packed; - -typedef unsigned int u32; -typedef unsigned short u16; - -struct Elf32_Ehdr -{ - unsigned char e_ident[16]; /* Magic number and other info */ - u16 e_type; /* Object file type */ - u16 e_machine; /* Architecture */ - u32 e_version; /* Object file version */ - u32 e_entry; /* Entry point virtual address */ - u32 e_phoff; /* Program header table file offset */ - u32 e_shoff; /* Section header table file offset */ - u32 e_flags; /* Processor-specific flags */ - u16 e_ehsize; /* ELF header size in bytes */ - u16 e_phentsize; /* Program header table entry size */ - u16 e_phnum; /* Program header table entry count */ - u16 e_shentsize; /* Section header table entry size */ - u16 e_shnum; /* Section header table entry count */ - u16 e_shstrndx; /* Section header string table index */ + TT16 e_type; /* Object file type */ + TT16 e_machine; /* Architecture */ + TT32 e_version; /* Object file version */ + TT32 e_entry; /* Entry point virtual address */ + TT32 e_phoff; /* Program header table file offset */ + TT32 e_shoff; /* Section header table file offset */ + TT32 e_flags; /* Processor-specific flags */ + TT16 e_ehsize; /* ELF header size in bytes */ + TT16 e_phentsize; /* Program header table entry size */ + TT16 e_phnum; /* Program header table entry count */ + TT16 e_shentsize; /* Section header table entry size */ + TT16 e_shnum; /* Section header table entry count */ + TT16 e_shstrndx; /* Section header string table index */ enum { // e_ident EI_CLASS = 4, @@ -205,16 +85,17 @@ __attribute_packed; // Program segment header. -struct Elf32_Phdr +template +struct TT_Elf32_Phdr { - u32 p_type; /* Segment type */ - u32 p_offset; /* Segment file offset */ - u32 p_vaddr; /* Segment virtual address */ - u32 p_paddr; /* Segment physical address */ - u32 p_filesz; /* Segment size in file */ - u32 p_memsz; /* Segment size in memory */ - u32 p_flags; /* Segment flags */ - u32 p_align; /* Segment alignment */ + TT32 p_type; /* Segment type */ + TT32 p_offset; /* Segment file offset */ + TT32 p_vaddr; /* Segment virtual address */ + TT32 p_paddr; /* Segment physical address */ + TT32 p_filesz; /* Segment size in file */ + TT32 p_memsz; /* Segment size in memory */ + TT32 p_flags; /* Segment flags */ + TT32 p_align; /* Segment alignment */ // Values for p_type enum { @@ -232,18 +113,19 @@ struct Elf32_Phdr __attribute_packed; -struct Elf32_Shdr +template +struct TT_Elf32_Shdr { - u32 sh_name; /* Section name (string tbl index) */ - u32 sh_type; /* Section type */ - u32 sh_flags; /* Section flags */ - u32 sh_addr; /* Section virtual addr at execution */ - u32 sh_offset; /* Section file offset */ - u32 sh_size; /* Section size in bytes */ - u32 sh_link; /* Link to another section */ - u32 sh_info; /* Additional section information */ - u32 sh_addralign; /* Section alignment */ - u32 sh_entsize; /* Entry size if section holds table */ + TT32 sh_name; /* Section name (string tbl index) */ + TT32 sh_type; /* Section type */ + TT32 sh_flags; /* Section flags */ + TT32 sh_addr; /* Section virtual addr at execution */ + TT32 sh_offset; /* Section file offset */ + TT32 sh_size; /* Section size in bytes */ + TT32 sh_link; /* Link to another section */ + TT32 sh_info; /* Additional section information */ + TT32 sh_addralign; /* Section alignment */ + TT32 sh_entsize; /* Entry size if section holds table */ enum { // values for sh_type SHT_NULL = 0, /* Section header table entry unused */ @@ -279,10 +161,12 @@ struct Elf32_Shdr } __attribute_packed; -struct Elf32_Dyn + +template +struct TT_Elf32_Dyn { - u32 d_tag; - u32 d_val; + TT32 d_tag; + TT32 d_val; enum { // tags DT_NULL = 0, /* End flag */ @@ -293,6 +177,20 @@ struct Elf32_Dyn } __attribute_packed; + +/************************************************************************* +// now for the actual types +**************************************************************************/ + +typedef TT_Elf32_Ehdr Elf_LE32_Ehdr; +typedef TT_Elf32_Phdr Elf_LE32_Phdr; +typedef TT_Elf32_Shdr Elf_LE32_Shdr; + +typedef TT_Elf32_Ehdr Elf32_Ehdr; +typedef TT_Elf32_Phdr Elf32_Phdr; +typedef TT_Elf32_Shdr Elf32_Shdr; + + #endif /* already included */