Fork me on GitHub

root/include/fiwix/i386elf.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * fiwix/include/fiwix/i386elf.h
   3  */
   4 
   5 #ifndef _FIWIX_ELF_H
   6 #define _FIWIX_ELF_H
   7 
   8 typedef unsigned long   Elf32_Addr;
   9 typedef unsigned short  Elf32_Half;
  10 typedef unsigned long   Elf32_Off;
  11 typedef long            Elf32_Sword;
  12 typedef unsigned long   Elf32_Word;
  13 
  14 #define ELFMAG0         0x7f            /* EI_MAG */
  15 #define ELFMAG1         'E'
  16 #define ELFMAG2         'L'
  17 #define ELFMAG3         'F'
  18 #define ELFMAG          "\177ELF"
  19 #define SELFMAG         4
  20 
  21 #define EI_NIDENT       16
  22 
  23 typedef struct elf32_hdr{
  24   unsigned char e_ident[EI_NIDENT];     /* ELF "magic number" */
  25   Elf32_Half    e_type;                 /* File type */
  26   Elf32_Half    e_machine;              /* Target machine */
  27   Elf32_Word    e_version;              /* File version */
  28   Elf32_Addr    e_entry;                /* Entry point virtual address */
  29   Elf32_Off     e_phoff;                /* Program header table file offset */
  30   Elf32_Off     e_shoff;                /* Section header table file offset */
  31   Elf32_Word    e_flags;                /* File flags */
  32   Elf32_Half    e_ehsize;               /* Sizeof Ehdr (ELF header) */
  33   Elf32_Half    e_phentsize;            /* Sizeof Phdr (Program header) */
  34   Elf32_Half    e_phnum;                /* Number Phdrs (Program header) */
  35   Elf32_Half    e_shentsize;            /* Sizeof Shdr (Section header) */
  36   Elf32_Half    e_shnum;                /* Number Shdrs (Section header) */
  37   Elf32_Half    e_shstrndx;             /* Shdr string index */
  38 } Elf32_Ehdr;
  39 
  40 #define EI_MAG0         0               /* e_ident[] indexes */
  41 #define EI_MAG1         1
  42 #define EI_MAG2         2
  43 #define EI_MAG3         3
  44 #define EI_CLASS        4
  45 #define EI_DATA         5
  46 #define EI_VERSION      6
  47 #define EI_PAD          7
  48 
  49 #define ELFCLASSNONE    0               /* EI_CLASS */
  50 #define ELFCLASS32      1
  51 #define ELFCLASS64      2
  52 #define ELFCLASSNUM     3
  53 
  54 #define ELFDATANONE     0               /* e_ident[EI_DATA] */
  55 #define ELFDATA2LSB     1
  56 #define ELFDATA2MSB     2
  57 #define ELFDATANUM      3
  58 
  59 /* ELF file types */
  60 #define ET_NONE   0
  61 #define ET_REL    1
  62 #define ET_EXEC   2
  63 #define ET_DYN    3
  64 #define ET_CORE   4
  65 #define ET_LOPROC 5
  66 #define ET_HIPROC 6
  67 
  68 #define EM_386    3
  69 
  70 #define EV_NONE         0               /* e_version, EI_VERSION */
  71 #define EV_CURRENT      1
  72 #define EV_NUM          2
  73 
  74 typedef struct elf32_phdr{
  75   Elf32_Word    p_type;                 /* Entry type */
  76   Elf32_Off     p_offset;               /* File offset */
  77   Elf32_Addr    p_vaddr;                /* Virtual address */
  78   Elf32_Addr    p_paddr;                /* Physical address */
  79   Elf32_Word    p_filesz;               /* File size */
  80   Elf32_Word    p_memsz;                /* Memory size */
  81   Elf32_Word    p_flags;                /* Entry flags */
  82   Elf32_Word    p_align;                /* Memory & file alignment */
  83 } Elf32_Phdr;
  84 
  85 /* segment types stored in the image headers */
  86 #define PT_NULL    0
  87 #define PT_LOAD    1
  88 #define PT_DYNAMIC 2
  89 #define PT_INTERP  3
  90 #define PT_NOTE    4
  91 #define PT_SHLIB   5
  92 #define PT_PHDR    6
  93 #define PT_NUM     7
  94 #define PT_LOPROC  0x70000000
  95 #define PT_HIPROC  0x7fffffff
  96 
  97 /* permission types on sections in the program header, p_flags. */
  98 #define PF_R    0x4
  99 #define PF_W    0x2
 100 #define PF_X    0x1
 101 
 102 #define PF_MASKPROC     0xf0000000
 103 
 104 typedef struct {
 105   Elf32_Word    sh_name;                /* Section name, index in string tbl */
 106   Elf32_Word    sh_type;                /* Type of section */
 107   Elf32_Word    sh_flags;               /* Miscellaneous section attributes */
 108   Elf32_Addr    sh_addr;                /* Section virtual addr at execution */
 109   Elf32_Off     sh_offset;              /* Section file offset */
 110   Elf32_Word    sh_size;                /* Size of section in bytes */
 111   Elf32_Word    sh_link;                /* Index of another section */
 112   Elf32_Word    sh_info;                /* Additional section information */
 113   Elf32_Word    sh_addralign;           /* Section alignment */
 114   Elf32_Word    sh_entsize;             /* Entry size if section holds table */
 115 } Elf32_Shdr;
 116 
 117 /* sh_type */
 118 #define SHT_NULL        0
 119 #define SHT_PROGBITS    1
 120 #define SHT_SYMTAB      2
 121 #define SHT_STRTAB      3
 122 #define SHT_RELA        4
 123 #define SHT_HASH        5
 124 #define SHT_DYNAMIC     6
 125 #define SHT_NOTE        7
 126 #define SHT_NOBITS      8
 127 #define SHT_REL         9
 128 #define SHT_SHLIB       10
 129 #define SHT_DYNSYM      11
 130 #define SHT_NUM         12
 131 
 132 #define SHT_LOPROC      0x70000000
 133 #define SHT_HIPROC      0x7fffffff
 134 #define SHT_LOUSER      0x80000000
 135 #define SHT_HIUSER      0xffffffff
 136 
 137 /* sh_flags */
 138 #define SHF_WRITE       0x1
 139 #define SHF_ALLOC       0x2
 140 #define SHF_EXECINSTR   0x4
 141 
 142 /* special section indexes */
 143 #define SHN_UNDEF       0
 144 #define SHN_LORESERVE   0xff00
 145 #define SHN_ABS         0xfff1
 146 #define SHN_COMMON      0xfff2
 147 #define SHN_HIRESERVE   0xffff
 148 #define SHN_LOPROC      0xff00
 149 #define SHN_HIPROC      0xff1f
 150  
 151 typedef struct elf32_sym{
 152   Elf32_Word    st_name;                /* Symbol name, index in string tbl */
 153   Elf32_Addr    st_value;               /* Value of the symbol */
 154   Elf32_Word    st_size;                /* Associated symbol size */
 155   unsigned char st_info;                /* Type and binding attributes */
 156   unsigned char st_other;               /* No defined meaning, 0 */
 157   Elf32_Half    st_shndx;               /* Associated section index */
 158 } Elf32_Sym;
 159 
 160 #define ELF32_ST_BIND(info)     ((info) >> 4)
 161 #define ELF32_ST_TYPE(info)     (((unsigned int) info) & 0xf)
 162 
 163 /* This info is needed when parsing the symbol table */
 164 #define STB_LOCAL  0
 165 #define STB_GLOBAL 1
 166 #define STB_WEAK   2
 167 #define STB_NUM    3
 168 
 169 #define STT_NOTYPE  0
 170 #define STT_OBJECT  1
 171 #define STT_FUNC    2
 172 #define STT_SECTION 3
 173 #define STT_FILE    4
 174 #define STT_NUM     5
 175 
 176 typedef struct elf32_rel {
 177   Elf32_Addr    r_offset;       /* Location at which to apply the action */
 178   Elf32_Word    r_info;         /* Index and type of relocation */
 179 } Elf32_Rel;
 180 
 181 typedef struct elf32_rela{
 182   Elf32_Addr    r_offset;       /* Location at which to apply the action */
 183   Elf32_Word    r_info;         /* Index and type of relocation */
 184   Elf32_Sword   r_addend;       /* Constant addend used to compute value */
 185 } Elf32_Rela;
 186 
 187 /* The following are used with relocations */
 188 #define ELF32_R_SYM(info)       ((info) >> 8)
 189 #define ELF32_R_TYPE(info)      ((info) & 0xff)
 190 
 191 /* This is the info that is needed to parse the dynamic section of the file */
 192 #define DT_NULL         0
 193 #define DT_NEEDED       1
 194 #define DT_PLTRELSZ     2
 195 #define DT_PLTGOT       3
 196 #define DT_HASH         4
 197 #define DT_STRTAB       5
 198 #define DT_SYMTAB       6
 199 #define DT_RELA         7
 200 #define DT_RELASZ       8
 201 #define DT_RELAENT      9
 202 #define DT_STRSZ        10
 203 #define DT_SYMENT       11
 204 #define DT_INIT         12
 205 #define DT_FINI         13
 206 #define DT_SONAME       14
 207 #define DT_RPATH        15
 208 #define DT_SYMBOLIC     16
 209 #define DT_REL          17
 210 #define DT_RELSZ        18
 211 #define DT_RELENT       19
 212 #define DT_PLTREL       20
 213 #define DT_DEBUG        21
 214 #define DT_TEXTREL      22
 215 #define DT_JMPREL       23
 216 #define DT_LOPROC       0x70000000
 217 #define DT_HIPROC       0x7fffffff
 218 
 219 /* Symbolic values for the entries in the auxiliary table
 220    put on the initial stack */
 221 #define AT_NULL   0     /* end of vector */
 222 #define AT_IGNORE 1     /* entry should be ignored */
 223 #define AT_EXECFD 2     /* file descriptor of program */
 224 #define AT_PHDR   3     /* program headers for program */
 225 #define AT_PHENT  4     /* size of program header entry */
 226 #define AT_PHNUM  5     /* number of program headers */
 227 #define AT_PAGESZ 6     /* system page size */
 228 #define AT_BASE   7     /* base address of interpreter */
 229 #define AT_FLAGS  8     /* flags */
 230 #define AT_ENTRY  9     /* entry point of program */
 231 #define AT_NOTELF 10    /* program is not ELF */
 232 #define AT_UID    11    /* real uid */
 233 #define AT_EUID   12    /* effective uid */
 234 #define AT_GID    13    /* real gid */
 235 #define AT_EGID   14    /* effective gid */
 236 
 237 
 238 typedef struct dynamic{
 239   Elf32_Sword d_tag;                    /* entry tabg value */
 240   union{
 241     Elf32_Sword d_val;
 242     Elf32_Addr  d_ptr;
 243   } d_un;
 244 } Elf32_Dyn;
 245 
 246 #define R_386_NONE      0
 247 #define R_386_32        1
 248 #define R_386_PC32      2
 249 #define R_386_GOT32     3
 250 #define R_386_PLT32     4
 251 #define R_386_COPY      5
 252 #define R_386_GLOB_DAT  6
 253 #define R_386_JMP_SLOT  7
 254 #define R_386_RELATIVE  8
 255 #define R_386_GOTOFF    9
 256 #define R_386_GOTPC     10
 257 #define R_386_NUM       11
 258 
 259 /* Notes used in ET_CORE */
 260 #define NT_PRSTATUS     1
 261 #define NT_PRFPREG      2
 262 #define NT_PRPSINFO     3
 263 #define NT_TASKSTRUCT   4
 264 
 265 /* Note header in a PT_NOTE section */
 266 typedef struct elf32_note {
 267   Elf32_Word    n_namesz;       /* Name size */
 268   Elf32_Word    n_descsz;       /* Content size */
 269   Elf32_Word    n_type;         /* Content type */
 270 } Elf32_Nhdr;
 271 
 272 #define ELF_START_MMAP 0x80000000
 273 
 274 extern Elf32_Dyn _DYNAMIC [];
 275 #define elfhdr          elf32_hdr
 276 #define elf_phdr        elf32_phdr
 277 #define elf_note        elf32_note
 278 
 279 #endif /* _FIWIX_ELF_H */

/* [previous][next][first][last][top][bottom][index][help] */