summaryrefslogtreecommitdiff
path: root/Source/Kernel/Linker/ElfBinary.class.h
blob: 1fb9929fdf977498fd440251b63303b44a00a2d5 (plain) (blame)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef DEF_ELFBINARY_CLASS_H
#define DEF_ELFBINARY_CLASS_H

#include <Linker/Binary.proto.h>
#include <SimpleList.class.h>

/* p_type */
#define	PT_NULL             0
#define	PT_LOAD             1
#define	PT_DYNAMIC          2
#define	PT_INTERP           3
#define	PT_NOTE             4
#define	PT_SHLIB            5
#define	PT_PHDR             6
#define	PT_LOPROC  0x70000000
#define	PT_HIPROC  0x7fffffff

struct elf_ehdr_t {
	u8int e_ident[16];      /* ELF identification */
	u16int e_type;             /* 2 (exec file) */
	u16int e_machine;          /* 3 (intel architecture) */
	u32int e_version;          /* 1 */
	u32int e_entry;            /* starting point */
	u32int e_phoff;            /* program header table offset */
	u32int e_shoff;            /* section header table offset */
	u32int e_flags;            /* various flags */
	u16int e_ehsize;           /* ELF header (this) size */

	u16int e_phentsize;        /* program header table entry size */
	u16int e_phnum;            /* number of entries */

	u16int e_shentsize;        /* section header table entry size */
	u16int e_shnum;            /* number of entries */

	u16int e_shstrndx;         /* index of the section name string table */
};

struct elf_phdr_t {
	u32int p_type;             /* type of segment */
	u32int p_offset;
	u32int p_vaddr;
	u32int p_paddr;
	u32int p_filesz;
	u32int p_memsz;
	u32int p_flags;
	u32int p_align;
};

struct phdr_t {
	elf_phdr_t h;
	u8int* data;
};

class ElfBinary : public Binary {
	private:
	elf_ehdr_t m_ehdr;
	SimpleList<phdr_t> *m_phdr;

	ElfBinary() {}

	public:
	virtual ~ElfBinary();
	static Binary* load(File& file);

	thread_entry_t toProcess(Process* p);
};

#endif