1/* @title: ELF */
2#include <compiler.h>
3#include <stdint.h>
4#pragma once
5
6struct elf64_ident {
7 uint32_t magic;
8 uint8_t class;
9 uint8_t data;
10 uint8_t version;
11 uint8_t os_abi;
12 uint8_t abi_version;
13 uint8_t pad[7];
14} __packed;
15
16struct elf64_ehdr {
17 struct elf64_ident ident;
18 uint16_t type;
19 uint16_t machine;
20 uint32_t version;
21 uint64_t entry;
22 uint64_t phoff;
23 uint64_t shoff;
24 uint32_t flags;
25 uint16_t ehsize;
26 uint16_t phentsize;
27 uint16_t phnum;
28 uint16_t shentsize;
29 uint16_t shnum;
30 uint16_t shstrndx;
31} __packed;
32
33struct elf64_phdr {
34 uint32_t type;
35 uint32_t flags;
36 uint64_t offset;
37 uint64_t vaddr;
38 uint64_t paddr;
39 uint64_t filesz;
40 uint64_t memsz;
41 uint64_t align;
42} __packed;
43
44/* returns entry point */
45uint64_t elf_load(const void *elf_data);
46
47__attribute__((noreturn)) void
48enter_userspace(uintptr_t entry_point, uintptr_t user_stack_top,
49 uint16_t user_cs, uint16_t user_ss, uintptr_t user_pml4_phys);
50
51void syscall_setup(void *syscall_entry);
52
53uintptr_t map_user_stack(uintptr_t user_pml4_phys);
54
55void elf_map(uintptr_t user_pml4_phys, void *elf_data);
56
57#define PT_LOAD 1
58#define PF_X 0x1
59#define PF_W 0x2
60#define PF_R 0x4
61