openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

elf.h (8588B)


      1 /* $Id: //depot/blt/include/elf.h#4 $
      2 **
      3 ** Copyright 1998 Sidney Cammeresi
      4 ** All rights reserved.
      5 **
      6 ** Redistribution and use in source and binary forms, with or without
      7 ** modification, are permitted provided that the following conditions
      8 ** are met:
      9 **
     10 ** 1. Redistributions of source code must retain the above copyright
     11 **    notice, this list of conditions, and the following disclaimer.
     12 ** 2. Redistributions in binary form must reproduce the above copyright
     13 **    notice, this list of conditions, and the following disclaimer in the
     14 **    documentation and/or other materials provided with the distribution.
     15 ** 3. The name of the author may not be used to endorse or promote products
     16 **    derived from this software without specific prior written permission.
     17 **
     18 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 */
     29 
     30 #ifndef __ELF_H__
     31 #define __ELF_H__
     32 
     33 #define EI_NIDENT 16
     34 
     35 /* ELF header */
     36 typedef struct
     37 {
     38 	unsigned char e_ident [EI_NIDENT];
     39 	unsigned short e_type, e_machine;
     40 	unsigned int e_version, e_entry, e_phoff, e_shoff, e_flags;
     41 	unsigned short e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum,
     42 			e_shstrndx;
     43 } elf32_hdr_t;
     44 
     45 #define ELF_MAGIC        0x464c457f
     46 
     47 /* e_ident indices */
     48 #define EI_MAG0          0 /* 0x7F */
     49 #define EI_MAG1          1 /* 'E' */
     50 #define EI_MAG2          2 /* 'L' */
     51 #define EI_MAG3          3 /* 'F' */
     52 #define EI_CLASS         4 /* file class */
     53 #define EI_DATA          5 /* data encoding */
     54 #define EI_VERSION       6 /* file version */
     55 #define EI_PAD           7 /* start of padding bytes */
     56 
     57 /* e_ident data */
     58 #define ELFCLASSNONE     0 /* invalid class */
     59 #define ELFCLASS32       1 /* 32-bit objects */
     60 #define ELFCLASS64       2 /* 64-bit objects */
     61 #define ELFDATANONE      0 /* invalid data encoding */
     62 #define ELFDATA2LSB      1 /* little-endian */
     63 #define ELFDATA2MSB      2 /* big-endian */
     64 
     65 /* e_type */
     66 #define ET_NONE          0 /* no file type */
     67 #define ET_REL           1 /* relocatable file */
     68 #define ET_EXEC          2 /* executable file */
     69 #define ET_DYN           3 /* shared object file */
     70 #define ET_CORE          4 /* core file */
     71 #define ET_LOPROC   0xFF00 /* beginning processor specific range */
     72 #define ET_HIPROC   0xFFFF /* end of processor specific range */
     73 
     74 /* e_machine */
     75 #define EM_NONE          0 /* no machine */
     76 #define EM_M32           1 /* AT&T WE 32100 */
     77 #define EM_SPARC         2 /* SPARC */
     78 #define EM_386           3 /* Intel 386 */
     79 #define EM_68K           4 /* Motorola 68000 */
     80 #define EM_88K           5 /* Motorola 88000 */
     81 #define EM_486           6 /* Intel 486 - unused */
     82 #define EM_860           7 /* Intel 80860 */
     83 #define EM_MIPS          8 /* MIPS R3000 big-endian */
     84 #define EM_MIPS_RS4_BE  10 /* MIPS R4000 big-endian */
     85 #define EM_SPARC64      11 /* SPARC V9 64-bit */
     86 #define EM_HPPA         15 /* HP PA-RISC */
     87 #define EM_PPC          20 /* PowerPC */
     88 
     89 /* e_version */
     90 #define EV_NONE          0 /* invalid version */
     91 #define EV_CURRENT       1 /* current version */
     92 
     93 /* section header */
     94 typedef struct
     95 {
     96 	unsigned int sh_name, sh_type, sh_flags, sh_addr, sh_offset, sh_size,
     97 			sh_link, sh_info, sh_addralign, sh_entsize;
     98 } elf32_sec_hdr_t;
     99 
    100 /* sh_type */
    101 #define SHT_NULL         0 /* section header is inactive */
    102 #define SHT_PROGBITS     1 /* program specific information */
    103 #define SHT_SYMTAB       2 /* symbol table, only one of these */
    104 #define SHT_STRTAB       3 /* string table */
    105 #define SHT_RELA         4 /* relocation entries with addends - ? */
    106 #define SHT_HASH         5 /* symbol hash table, only one of these */
    107 #define SHT_DYNAMIC      6 /* dynamic linking information, only one of these */
    108 #define SHT_NOTE         7 /* file marking information */
    109 #define SHT_NOBITS       8 /* occupies no space, but similar to SHT_PROGBITS */
    110 #define SHT_REL          9 /* relocation entries without addends - ? */
    111 #define SHT_SHLIB       10 /* reserved and unspecified */
    112 #define SHT_DYNSYM      11 /* symbol table for dynamic linking, only one */
    113 
    114 #define SHF_WRITE        1 /* section should be writable */
    115 #define SHF_ALLOC        2 /* section occupies memory during execution */
    116 #define SHF_EXECINSTR    4 /* section contains executable text */
    117 #define SHF_MASKPROC     0xF0000000 /* reserved for machine specific data */
    118 
    119 /* program header */
    120 typedef struct
    121 {
    122 	unsigned int p_type, p_offset, p_vaddr, p_paddr, p_filesz, p_memsz, p_flags,
    123 			p_align;
    124 } elf32_pgm_hdr_t;
    125 
    126 /* p_type */
    127 #define PT_NULL          0 /* array element unused */
    128 #define PT_LOAD          1 /* loadable segment */
    129 #define PT_DYNAMIC       2 /* contains dynamic linking information */
    130 #define PT_INTERP        3 /* location and size of path to interpreter */
    131 #define PT_NOTE          4 /* location and size of auxillary information */
    132 #define PT_SHLIB         5 /* reserved and unspecified */
    133 #define PT_PHDR          6 /* location and size of program header table */
    134 #define PT_LOPROC        0x70000000 /* reserved for processor specific use */
    135 #define PT_HIPROC        0x7FFFFFFF /* end of range */
    136 
    137 typedef struct
    138 {
    139 	int d_tag;
    140 	union
    141 	{
    142 		unsigned int d_val, d_ptr;
    143 	} d_un;
    144 } elf32_dyn_t;
    145 
    146 /* d_tag */
    147 #define DT_NULL           0 /* ignored, but mandatory */
    148 #define DT_NEEDED         1 /* name of needed library */
    149 #define DT_PLTRELSZ       2 /* size of plt */
    150 #define DT_PLTGOT         3
    151 #define DT_HASH           4
    152 #define DT_STRTAB         5 /* string table with symbol and library names */
    153 #define DT_SYMTAB         6
    154 #define DT_RELA           7
    155 #define DT_REL           17 /* reloc entries for data */
    156 #define DT_RELSZ         18
    157 #define DT_RELENT        19
    158 #define DT_PLTREL        20
    159 #define DT_JMPREL        23 /* reloc entries associated with plt */
    160 
    161 /* relocation entry without addend */
    162 typedef struct
    163 {
    164 	unsigned int r_offset, r_info;
    165 } elf32_rel_t;
    166 
    167 /* relocation entry with addend */
    168 typedef struct
    169 {
    170 	unsigned int r_offset, r_info, r_addend;
    171 } elf32_rela_t;
    172 
    173 #define ELF32_R_SYM(i)    ((i) >> 8)
    174 #define ELF32_R_TYPE(i)   ((unsigned char) (i))
    175 #define ELF32_R_INFO(i,j) (((i) << 8) + (unsigned char) (j))
    176 
    177 #define R_386_NONE        0 /* none */
    178 #define R_386_32          1
    179 #define R_386_PC32        2
    180 #define R_386_GOT32       3
    181 #define R_386_PLT32       4
    182 #define R_386_COPY        5
    183 #define R_386_GLOB_DAT    6
    184 #define R_386_JMP_SLOT    7 /* location of procedure linkage table entry */
    185 #define R_386_RELATIVE    8
    186 #define R_386_GOTOFF      9
    187 #define R_386_GOTPC      10
    188 
    189 typedef struct
    190 {
    191 	unsigned int st_name, st_value, st_size;
    192 	unsigned char st_info, st_other;
    193 	unsigned short st_shndx;
    194 } elf32_sym_t;
    195 
    196 #define ELF32_ST_BIND(i)    ((i) >> 4)
    197 #define ELF32_ST_TYPE(i)    ((i) & 0xF)
    198 #define ELF32_ST_INFO(i,j)  (((i) << 4) + ((j) & 0xF))
    199 
    200 #define STT_NOTYPE          0 /* type not specified */
    201 #define STT_OBJECT          1 /* symbol references data */
    202 #define STT_FUNC            2 /* symbol represents text */
    203 #define STT_SECTION         3 /* symbol is a section */
    204 #define STT_FILE            4 /* object file */
    205 #define STT_LOPROC         13 /* reserved for processor */
    206 #define STT_MEDPROC        14 /* reserved for processor */
    207 #define STT_HIPROC         15 /* reserved for processor */
    208 
    209 #define SHN_UNDEF           0
    210 #define SHN_LORESERVE  0xff00
    211 #define SHN_LOPROC     0xff00
    212 #define SHN_HIPROC     0xff1f
    213 #define SHN_ABS        0xfff1
    214 #define SHN_COMMON     0xfff2
    215 #define SHN_HIRESERVE  0xffff
    216 
    217 #ifdef __cplusplus
    218 extern "C" {
    219 #endif
    220 
    221 	elf32_sec_hdr_t *_elf_find_section_hdr (elf32_hdr_t *hdr, char *name);
    222 	elf32_sec_hdr_t *elf_find_section_hdr (elf32_hdr_t *hdr, char *name);
    223 	void *_elf_lookup_sym (int filenum, const char *name);
    224 	void *elf_lookup_sym (int filenum, const char *name);
    225 	void *_elf_find_section_data (elf32_hdr_t *hdr, char *name);
    226 	void *elf_find_section_data (elf32_hdr_t *hdr, char *name);
    227 	int _elf_section_size (elf32_hdr_t *hdr, char *name);
    228 	int elf_section_size (elf32_hdr_t *hdr, char *name);
    229 
    230 #ifdef __cplusplus
    231 }
    232 #endif
    233 
    234 
    235 #endif
    236