Sorting source tree a bit
[tpg/acess2.git] / KernelLand / Kernel / bin / elf.h
diff --git a/KernelLand/Kernel/bin/elf.h b/KernelLand/Kernel/bin/elf.h
new file mode 100644 (file)
index 0000000..13b5373
--- /dev/null
@@ -0,0 +1,287 @@
+/**\r
+ * \file elf.h\r
+ * \brief ELF Exeutable Loader\r
+ */\r
+#ifndef _BIN_ELF_H\r
+#define _BIN_ELF_H\r
+\r
+typedef Uint16 Elf64_Half;\r
+typedef Uint32 Elf64_Word;\r
+typedef Uint64 Elf64_Addr;\r
+typedef Uint64 Elf64_Off;\r
+typedef Uint64 Elf64_Xword;\r
+\r
+enum e_ident_values\r
+{\r
+       EI_MAG0,\r
+       EI_MAG1,\r
+       EI_MAG2,\r
+       EI_MAG3,\r
+       EI_CLASS,\r
+       EI_DATA,\r
+       EI_VERSION,\r
+       EI_OSABI,\r
+       EI_ABIVERSION,\r
+       EI_PAD,\r
+       EI_NIDENT = 16,\r
+};\r
+\r
+#define ELFCLASS32     1\r
+#define ELFCLASS64     2\r
+\r
+/**\r
+ * \brief ELF File Header\r
+ */\r
+struct sElf32_Ehdr\r
+{\r
+       union {\r
+               char    ident[16];      //!< Identifier Bytes\r
+               struct {\r
+                       Uint    Ident1;\r
+                       Uint    Ident2;\r
+                       Uint    HashTable;\r
+                       Uint    SymTable;\r
+               } misc;\r
+       };\r
+       Uint16  filetype;       //!< File Type\r
+       Uint16  machine;        //!< Machine / Arch\r
+       Uint32  version;        //!< Version (File?)\r
+       Uint32  entrypoint;     //!< Entry Point\r
+       Uint32  phoff;  //!< Program Header Offset\r
+       Uint32  shoff;  //!< Section Header Offset\r
+       Uint32  flags;  //!< Flags\r
+       Uint16  headersize;     //!< Header Size\r
+       Uint16  phentsize;      //!< Program Header Entry Size\r
+       Uint16  phentcount;     //!< Program Header Entry Count\r
+       Uint16  shentsize;      //!< Section Header Entry Size\r
+       Uint16  shentcount;     //!< Section Header Entry Count\r
+       Uint16  shstrindex;     //!< Section Header String Table Index\r
+} __attribute__ ((packed));\r
+\r
+typedef struct\r
+{\r
+       unsigned char   e_ident[16];\r
+       Elf64_Half      e_type;\r
+       Elf64_Half      e_machine;\r
+       Elf64_Word      e_version;\r
+       Elf64_Addr      e_entry;\r
+       Elf64_Off       e_phoff;\r
+       Elf64_Off       e_shoff;\r
+       Elf64_Word      e_flags;\r
+       Elf64_Half      e_ehsize;\r
+       Elf64_Half      e_phentsize;\r
+       Elf64_Half      e_phnum;\r
+       Elf64_Half      e_shentsize;\r
+       Elf64_Half      e_shnum;\r
+       Elf64_Half      e_shstrndx;\r
+} Elf64_Ehdr;\r
+\r
+/**\r
+ * \brief Executable Types\r
+ */\r
+enum eElf32_ExecTypes\r
+{\r
+       ET_NONE = 0,    //!< NULL Type\r
+       ET_REL  = 1,    //!< Relocatable (Object)\r
+       ET_EXEC = 2,    //!< Executable\r
+       ET_DYN  = 3,    //!< Dynamic Library\r
+       ET_CORE = 4,    //!< Core?\r
+       ET_LOPROC = 0xFF00,     //!< Low Impl Defined\r
+       ET_HIPROC = 0xFFFF      //!< High Impl Defined\r
+};\r
+\r
+/**\r
+ \name Section IDs\r
+ \{\r
+*/\r
+#define SHN_UNDEF              0       //!< Undefined Section\r
+#define SHN_LORESERVE  0xFF00  //!< Low Reserved\r
+#define SHN_LOPROC     0xFF00  //!< Low Impl Defined\r
+#define SHN_HIPROC     0xFF1F  //!< High Impl Defined\r
+#define SHN_ABS        0xFFF1  //!< Absolute Address (Base: 0, Size: -1)\r
+#define SHN_COMMON     0xFFF2  //!< Common\r
+#define SHN_HIRESERVE  0xFFFF  //!< High Reserved\r
+//! \}\r
+\r
+/**\r
+ \enum eElfSectionTypes\r
+ \brief ELF Section Types\r
+*/\r
+enum eElfSectionTypes {\r
+       SHT_NULL,       //0\r
+       SHT_PROGBITS,   //1\r
+       SHT_SYMTAB,     //2\r
+       SHT_STRTAB,     //3\r
+       SHT_RELA,       //4\r
+       SHT_HASH,       //5\r
+       SHT_DYNAMIC,    //6\r
+       SHT_NOTE,       //7\r
+       SHT_NOBITS,     //8\r
+       SHT_REL,        //9\r
+       SHT_SHLIB,      //A\r
+       SHT_DYNSYM,     //B\r
+       SHT_LAST,       //C\r
+       SHT_LOPROC = 0x70000000,\r
+       SHT_HIPROC = 0x7fffffff,\r
+       SHT_LOUSER = 0x80000000,\r
+       SHT_HIUSER = 0xffffffff\r
+};\r
+\r
+#define SHF_WRITE      0x1\r
+#define SHF_ALLOC      0x2\r
+#define SHF_EXECINSTR  0x4\r
+#define SHF_MASKPROC   0xf0000000\r
+\r
+struct sElf32_Shent {\r
+       Uint32  name;\r
+       Uint32  type;\r
+       Uint32  flags;\r
+       Uint32  address;\r
+       Uint32  offset;\r
+       Uint32  size;\r
+       Uint32  link;\r
+       Uint32  info;\r
+       Uint32  addralign;\r
+       Uint32  entsize;\r
+} __attribute__ ((packed));    //sizeof = 40\r
+\r
+typedef struct\r
+{\r
+       Elf64_Word      sh_name;\r
+       Elf64_Word      sh_type;\r
+       Elf64_Xword     sh_flags;\r
+       Elf64_Addr      sh_addr;\r
+       Elf64_Off       sh_offset;\r
+       Elf64_Xword     sh_size;\r
+       Elf64_Word      sh_link;\r
+       Elf64_Word      sh_info;\r
+       Elf64_Xword     sh_addralign;\r
+       Elf64_Xword     sh_entsize;\r
+} Elf64_Shdr;\r
+\r
+struct elf_sym_s {\r
+       union {\r
+               Uint32  nameOfs;\r
+               char    *name;\r
+       };\r
+       Uint32  value;  //Address\r
+       Uint32  size;\r
+       Uint8   info;\r
+       Uint8   other;\r
+       Uint16  shndx;\r
+} __attribute__ ((packed));\r
+#define        STN_UNDEF       0       // Undefined Symbol\r
+\r
+enum {\r
+       PT_NULL,        //0\r
+       PT_LOAD,        //1\r
+       PT_DYNAMIC,     //2\r
+       PT_INTERP,      //3\r
+       PT_NOTE,        //4\r
+       PT_SHLIB,       //5\r
+       PT_PHDR,        //6\r
+       PT_LOPROC = 0x70000000,\r
+       PT_HIPROC = 0x7fffffff\r
+};\r
+\r
+struct sElf32_Phdr {\r
+       Uint32  Type;\r
+       Uint32  Offset;\r
+       Uint32  VAddr;\r
+       Uint32  PAddr;\r
+       Uint32  FileSize;\r
+       Uint32  MemSize;\r
+       Uint32  Flags;\r
+       Uint32  Align;\r
+} __attribute__ ((packed));\r
+\r
+typedef struct\r
+{\r
+       Elf64_Word      p_type;\r
+       Elf64_Word      p_flags;\r
+       Elf64_Off       p_offset;\r
+       Elf64_Addr      p_vaddr;\r
+       Elf64_Addr      p_paddr;\r
+       Elf64_Xword     p_filesz;\r
+       Elf64_Xword     p_memsz;\r
+       Elf64_Xword     p_align;\r
+} Elf64_Phdr;\r
+\r
+#define PF_X   1\r
+#define PF_W   2\r
+#define PF_R   4\r
+\r
+struct elf32_rel_s {\r
+       Uint32  r_offset;\r
+       Uint32  r_info;\r
+} __attribute__ ((packed));\r
+\r
+struct elf32_rela_s {\r
+       Uint32  r_offset;\r
+       Uint32  r_info;\r
+       Sint32  r_addend;\r
+} __attribute__ ((packed));\r
+\r
+enum {\r
+       R_386_NONE = 0, // none\r
+       R_386_32,       // S+A\r
+       R_386_PC32,     // S+A-P\r
+       R_386_GOT32,    // G+A-P\r
+       R_386_PLT32,    // L+A-P\r
+       R_386_COPY,     // none\r
+       R_386_GLOB_DAT, // S\r
+       R_386_JMP_SLOT, // S\r
+       R_386_RELATIVE, // B+A\r
+       R_386_GOTOFF,   // S+A-GOT\r
+       R_386_GOTPC,    // GOT+A-P\r
+       R_386_LAST      // none\r
+};\r
+\r
+#define        ELF32_R_SYM(i)  ((i)>>8)        // Takes an info value and returns a symbol index\r
+#define        ELF32_R_TYPE(i) ((i)&0xFF)      // Takes an info value and returns a type\r
+#define        ELF32_R_INFO(s,t)       (((s)<<8)+((t)&0xFF))   // Takes a type and symbol index and returns an info value\r
+\r
+struct elf32_dyn_s {\r
+       Uint32  d_tag;\r
+       Uint32  d_val;  //Also d_ptr\r
+} __attribute__ ((packed));\r
+\r
+enum {\r
+       DT_NULL,        //!< Marks End of list\r
+       DT_NEEDED,      //!< Offset in strtab to needed library\r
+       DT_PLTRELSZ,    //!< Size in bytes of PLT\r
+       DT_PLTGOT,      //!< Address of PLT/GOT\r
+       DT_HASH,        //!< Address of symbol hash table\r
+       DT_STRTAB,      //!< String Table address\r
+       DT_SYMTAB,      //!< Symbol Table address\r
+       DT_RELA,        //!< Relocation table address\r
+       DT_RELASZ,      //!< Size of relocation table\r
+       DT_RELAENT,     //!< Size of entry in relocation table\r
+       DT_STRSZ,       //!< Size of string table\r
+       DT_SYMENT,      //!< Size of symbol table entry\r
+       DT_INIT,        //!< Address of initialisation function\r
+       DT_FINI,        //!< Address of termination function\r
+       DT_SONAME,      //!< String table offset of so name\r
+       DT_RPATH,       //!< String table offset of library path\r
+       DT_SYMBOLIC,//!< Reverse order of symbol searching for library, search libs first then executable\r
+       DT_REL,         //!< Relocation Entries (Elf32_Rel instead of Elf32_Rela)\r
+       DT_RELSZ,       //!< Size of above table (bytes)\r
+       DT_RELENT,      //!< Size of entry in above table\r
+       DT_PLTREL,      //!< Relocation entry of PLT\r
+       DT_DEBUG,       //!< Debugging Entry - Unknown contents\r
+       DT_TEXTREL,     //!< Indicates that modifcations to a non-writeable segment may occur\r
+       DT_JMPREL,      //!< Address of PLT only relocation entries\r
+       DT_LOPROC = 0x70000000, //!< Low Definable\r
+       DT_HIPROC = 0x7FFFFFFF  //!< High Definable\r
+};\r
+\r
+typedef struct sElf32_Ehdr     Elf32_Ehdr;\r
+typedef struct sElf32_Phdr     Elf32_Phdr;\r
+typedef struct sElf32_Shent    Elf32_Shent;\r
+typedef struct elf_sym_s       elf_symtab;\r
+typedef struct elf_sym_s       Elf32_Sym;\r
+typedef struct elf32_rel_s     Elf32_Rel;\r
+typedef struct elf32_rela_s    Elf32_Rela;\r
+typedef struct elf32_dyn_s     Elf32_Dyn;\r
+\r
+#endif // defined(_EXE_ELF_H)\r

UCC git Repository :: git.ucc.asn.au