forked from sysprog21/rv32emu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelf.h
54 lines (42 loc) · 1.06 KB
/
elf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
/* A minimal ELF parser */
#include <stdint.h>
#include "c_map.h"
#include "io.h"
#include "riscv.h"
typedef uint32_t Elf32_Addr;
typedef uint32_t Elf32_Off;
typedef uint16_t Elf32_Half;
typedef uint32_t Elf32_Word;
enum {
EI_MAG0 = 0,
EI_MAG1 = 1,
EI_MAG2 = 2,
EI_MAG3 = 3,
EI_CLASS = 4,
EI_DATA = 5,
EI_VERSION = 6,
EI_OSABI = 7,
EI_ABIVERSION = 8,
EI_PAD = 9,
EI_NIDENT = 16,
};
struct Elf32_Sym {
Elf32_Word st_name;
Elf32_Addr st_value;
Elf32_Word st_size;
uint8_t st_info;
uint8_t st_other;
Elf32_Half st_shndx;
};
typedef struct elf_internal elf_t;
elf_t *elf_new();
void elf_delete(elf_t *e);
/* Open an ELF file from specified path */
bool elf_open(elf_t *e, const char *path);
/* Find a symbol entry */
const struct Elf32_Sym *elf_get_symbol(elf_t *e, const char *name);
/* Find symbole from a specified ELF file */
const char *elf_find_symbol(elf_t *e, uint32_t addr);
/* Load the ELF file into a memory abstraction */
bool elf_load(elf_t *e, struct riscv_t *rv, memory_t *mem);