]> git.dujemihanovic.xyz Git - nameless-os.git/blob - boot/x86/stage3/elf.h
Load ELF kernel instead of flat binary
[nameless-os.git] / boot / x86 / stage3 / elf.h
1 #ifndef BOOT_X86_ELF_H
2 #define BOOT_X86_ELF_H
3
4 #include <stdint.h>
5
6 /* Some constants we will test against. */
7 #define ELF_MAGIC 0x464c457f
8 #define ELF_32BIT 0x1
9 #define ELF_LITTLE_ENDIAN 0x1
10 #define ELF_SYSV_ABI 0x0
11 #define ELF_TYPE_EXECUTABLE 0x2
12 #define ELF_X86_ISA 0x3
13
14 #define ELF_PT_LOAD 0x1
15
16 #define ELF_FLAG_EXECUTABLE 0x1
17 #define ELF_FLAG_WRITABLE 0x2
18 #define ELF_FLAG_READABLE 0x4
19
20 /* Return error codes for the functions. */
21 #define ELF_HEADER_INVALID 5
22 #define MISMATCHED_SYSTEM 6
23 #define NOT_EXECUTABLE 7
24
25 struct elf_header {
26 uint32_t magic;
27 uint8_t bits;
28 uint8_t endianness;
29 uint8_t header_ver; /* always 1 */
30 uint8_t os_abi;
31 uint8_t padding[8];
32 uint16_t type;
33 uint16_t machine;
34 uint32_t elf_ver; /* always 1 */
35 void (*entry)(void *, int);
36 uint32_t program_hdr; /* offset into file */
37 uint32_t section_hdr;
38 uint32_t flags;
39 uint16_t hdr_size;
40 uint16_t ph_entry_size;
41 uint16_t ph_entry_count;
42 uint16_t sh_entry_size;
43 uint16_t sh_entry_count;
44 uint16_t sh_name_index;
45 };
46
47 struct program_header {
48 uint32_t seg_type;
49 uint32_t file_offset;
50 void *vaddr;
51 uint32_t undefined;
52 uint32_t filesz;
53 uint32_t memsz;
54 uint32_t flags;
55 uint32_t align;
56 };
57
58 extern int execute_elf(struct elf_header *header, void *arg1, int arg2);
59
60 #endif