OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [services/] [elfloader/] [elf_types.h] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      elf-file loader class declaration.
6
 */
7
 
8
#ifndef __DEBUGGER_ELF_TYPES_H__
9
#define __DEBUGGER_ELF_TYPES_H__
10
 
11
#include <inttypes.h>
12
 
13
namespace debugger {
14
 
15
//#define EI_NIDENT 16
16
#define ARCH_64BITS
17
 
18
#ifdef ARCH_64BITS
19
typedef uint64_t   Elf32_Addr;
20
typedef uint64_t   Elf32_Off;
21
#else
22
typedef unsigned int   Elf32_Addr;
23
typedef unsigned int   Elf32_Off;
24
#endif
25
typedef unsigned short Elf32_Half;
26
typedef signed   int   Elf32_Sword;
27
typedef unsigned int   Elf32_Word;
28
 
29
static const char MAGIC_BYTES[]  = {0x7f,'E','L','F',0};
30
 
31
enum E_EI {
32
    EI_MAG0,
33
    EI_MAG1,
34
    EI_MAG2,
35
    EI_MAG3,
36
    EI_CLASS,
37
    EI_DATA,
38
    EI_VERSION,
39
    EI_PAD,
40
    EI_NIDENT=16
41
};
42
static const uint8_t ELFCLASSNONE = 0;
43
static const uint8_t ELFCLASS32   = 1;
44
static const uint8_t ELFCLASS64   = 2;
45
 
46
static const uint8_t ELFDATANONE  = 0;
47
static const uint8_t ELFDATA2LSB  = 1;
48
static const uint8_t ELFDATA2MSB  = 2;
49
 
50
static const uint8_t EV_NONE      = 0;          // Invalid version
51
static const uint8_t EV_CURRENT   = 1;          // Current version
52
//etype values:
53
static const Elf32_Half ET_NONE      = 0;       // no file type
54
static const Elf32_Half ET_REL       = 1;       // rellocatable file
55
static const Elf32_Half ET_EXEC      = 2;       // executable file
56
static const Elf32_Half ET_DYN       = 3;       // shared object file
57
static const Elf32_Half ET_CORE      = 4;       // core file
58
static const Elf32_Half ET_LOPROC    = 0xff00;  // Processor-specific
59
static const Elf32_Half ET_HIPROC    = 0xffff;  // Processor-specific
60
//emachine values:
61
static const Elf32_Half EM_NONE      = 0;       // No machine
62
static const Elf32_Half EM_M32       = 1;       // AT&T WE 32100
63
static const Elf32_Half EM_SPARC     = 2;       // SPARC
64
static const Elf32_Half EM_386       = 3;       // Intel 386
65
static const Elf32_Half EM_68K       = 4;       // Motorola 68000
66
static const Elf32_Half EM_88K       = 5;       // Motorola 88000
67
static const Elf32_Half EM_860       = 7;       // Intel 80860
68
static const Elf32_Half EM_MIPS      = 8;       // MIPS RS3000
69
 
70
typedef struct ElfHeaderType
71
{
72
    unsigned char e_ident[EI_NIDENT];
73
    Elf32_Half e_type;      // Shared/Executable/Rellocalable etc
74
    Elf32_Half e_machine;   // SPARC, X86 etc
75
    Elf32_Word e_version;   //
76
    uint64_t e_entry;     // entry point
77
    uint64_t  e_phoff;     // Program header offset
78
    uint64_t  e_shoff;     // Section Header offset
79
    Elf32_Word e_flags;
80
    Elf32_Half e_ehsize;
81
    Elf32_Half e_phentsize; // size of one entry in the Program header. All entries are the same size
82
    Elf32_Half e_phnum;     // number of entries in a Program header
83
    Elf32_Half e_shentsize; // entry size in the section header table. all entries are the same size
84
    Elf32_Half e_shnum;     // number of section header entries
85
    Elf32_Half e_shstrndx;
86
} ElfHeaderType;
87
 
88
//sh_type:
89
static const Elf32_Word SHT_NULL      = 0;          // section header is inactive
90
static const Elf32_Word SHT_PROGBITS  = 1;          // section with CPU instructions
91
static const Elf32_Word SHT_SYMTAB    = 2;          // section contains symbols table (also as SHT_DYNSIM)
92
static const Elf32_Word SHT_STRTAB    = 3;          // section holds string table
93
static const Elf32_Word SHT_RELA      = 4;          // section with relocation data
94
static const Elf32_Word SHT_HASH      = 5;          // section with hash table. Must be for the dynamic lib
95
static const Elf32_Word SHT_DYNAMIC   = 6;          // section holds information for dynamic linking.
96
static const Elf32_Word SHT_NOTE      = 7;
97
static const Elf32_Word SHT_NOBITS    = 8;          // section with not initialized data
98
static const Elf32_Word SHT_REL       = 9;
99
static const Elf32_Word SHT_SHLIB     = 10;
100
static const Elf32_Word SHT_DYNSYM    = 11;         // section contains debug symbol table
101
static const Elf32_Word SHT_LOPROC    = 0x70000000;
102
static const Elf32_Word SHT_HIPROC    = 0x7fffffff;
103
static const Elf32_Word SHT_HIUSER    = 0xffffffff;
104
//sh_flags:
105
static const Elf32_Word SHF_WRITE     = 0x1;        // section contains data that should be writable during process execution.
106
static const Elf32_Word SHF_ALLOC     = 0x2;        // section occupies memory during process execution. 
107
static const Elf32_Word SHF_EXECINSTR = 0x4;        // section contains executable machine instructions.
108
static const Elf32_Word SHF_MASKPROC  = 0xf0000000; // processor-specific sematic
109
 
110
typedef struct SectionHeaderType
111
{
112
    Elf32_Word    sh_name;//Index in a header section table (gives name of section)
113
    Elf32_Word    sh_type;
114
    uint64_t        sh_flags;
115
    uint64_t        sh_addr;
116
    uint64_t        sh_offset;
117
    uint64_t        sh_size;
118
    Elf32_Word    sh_link;
119
    Elf32_Word    sh_info;
120
    uint64_t    sh_addralign;
121
    uint64_t    sh_entsize;
122
} SectionHeaderType;
123
 
124
 
125
#define ELF32_ST_BIND(i) ((i)>>4)
126
#define ELF32_ST_TYPE(i) ((i)&0xf)
127
#define ELF32_ST_INFO(b,t) (((b)<<4) + ((t)&0xf))
128
 
129
static const unsigned char STB_LOCAL   = 0;
130
static const unsigned char STB_GLOBAL  = 1;
131
static const unsigned char STB_WEAK    = 2;
132
static const unsigned char STB_LOPROC  = 13;
133
static const unsigned char STB_HIPROC  = 15;
134
 
135
static const unsigned char STT_NOTYPE  = 0;
136
static const unsigned char STT_OBJECT  = 1;
137
static const unsigned char STT_FUNC    = 2;
138
static const unsigned char STT_SECTION = 3;
139
static const unsigned char STT_FILE    = 4;
140
static const unsigned char STT_LOPROC  = 13;
141
static const unsigned char STT_HIPROC  = 15;
142
 
143
typedef struct SymbolTableType
144
{
145
    Elf32_Word    st_name;
146
    uint8_t st_info;
147
    uint8_t st_other;
148
    Elf32_Half    st_shndx;
149
    uint64_t    st_value;
150
    uint64_t    st_size;
151
} SymbolTableType;
152
 
153
 
154
//p_type:
155
static const Elf32_Word PT_NULL     = 0;
156
static const Elf32_Word PT_LOAD     = 1;
157
static const Elf32_Word PT_DYNAMIC  = 2;
158
static const Elf32_Word PT_INTERP   = 3;
159
static const Elf32_Word PT_NOTE     = 4;
160
static const Elf32_Word PT_SHLIB    = 5;
161
static const Elf32_Word PT_PHDR     = 6;
162
static const Elf32_Word PT_LOPROC   = 0x70000000;
163
static const Elf32_Word PT_HIPROC   = 0x7fffffff;
164
 
165
typedef struct ProgramHeaderType
166
{
167
  uint32_t    p_type;
168
  uint32_t    p_offset;
169
  uint64_t    p_vaddr;
170
  uint64_t    p_paddr;
171
  uint64_t    p_filesz;
172
  uint64_t    p_memsz;
173
  uint64_t    p_flags;
174
  uint64_t    p_align;
175
} ProgramHeaderType;
176
 
177
}  // namespace debugger
178
 
179
#endif  // __DEBUGGER_ELF_TYPES_H__

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.