#pragma once

#include "../../types.h"
#include "../../lnxboot.h"

#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_TLS     7

struct [[gnu::packed]] Elf64_Ehdr {
	c8  e_ident[16];
	u16 e_type;
	u16 e_machine;
	u32 e_version;
	u64 e_entry;
	u64 e_phoff;
	u64 e_shoff;
	u32 e_flags;
	u16 e_ehsize;
	u16 e_phentsize;
	u16 e_phnum;
	u16 e_shentsize;
	u16 e_shentnum;
	u16 e_shstrndx;
};

struct [[gnu::packed]] Elf64_Phdr {
	u32 p_type;
	u32 p_flags;
	u64 p_offset;
	u64 p_vaddr;
	u64 p_paddr;
	u64 p_filesz;
	u64 p_memsz;
	u64 p_align;
};

/// We don't have space to allocate memory, so we have no idea where we can pass back ELF state, we'll have to do this all at once
void ElfExecute(void* Binary, void* LoadAddr, struct boot_params*);