summaryrefslogtreecommitdiffstats
path: root/include/elf.h
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2025-09-10 13:28:28 -0400
committerJon Santmyer <jon@jonsantmyer.com>2025-09-10 13:28:28 -0400
commit7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5 (patch)
treeaef9904e2495ce840319f2815cd859c47294c88a /include/elf.h
parent032a7bc4d79efea100a00cf3464bea3249a07ff6 (diff)
downloadjove-kernel-7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5.tar.gz
jove-kernel-7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5.tar.bz2
jove-kernel-7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5.zip
refactor paging code. regression on loading init program
Diffstat (limited to 'include/elf.h')
-rw-r--r--include/elf.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/include/elf.h b/include/elf.h
new file mode 100644
index 0000000..05e3e83
--- /dev/null
+++ b/include/elf.h
@@ -0,0 +1,110 @@
+#ifndef _JOVE_ELF_H
+#define _JOVE_ELF_H 1
+
+#include <stdint.h>
+
+/*A subset of the SystemV ELF ABI that only loads statically linked binaries.*/
+
+typedef uint16_t Elf32_Half;
+typedef uint32_t Elf32_Word;
+typedef uint32_t Elf32_Addr;
+typedef uint32_t Elf32_Off;
+
+typedef Elf32_Half Elf64_Half;
+typedef Elf32_Word Elf64_Word;
+typedef uint64_t Elf64_Xword;
+typedef uintptr_t Elf64_Addr;
+typedef uint64_t Elf64_Off;
+
+enum {
+ EI_MAG0 = 0,
+ EI_MAG1,
+ EI_MAG2,
+ EI_MAG3,
+ EI_CLASS,
+ EI_DATA,
+ EI_VERSION,
+ EI_OSABI,
+ EI_ABIVERSION,
+ EI_PAD
+};
+#define EI_NIDENT 16
+
+#define ELFMAG0 0x7f
+#define ELFMAG1 'E'
+#define ELFMAG2 'L'
+#define ELFMAG3 'F'
+
+#define ELFCLASSNONE 0
+#define ELFCLASS64 2
+
+#define ELFDATANONE 0
+#define ELFDATA2LSB 1
+
+#define ET_NONE 0
+#define ET_EXEC 2
+
+#define EM_X86_64 62
+
+#define EV_NONE 0
+#define EV_CURRENT 1
+
+typedef struct {
+ unsigned char e_ident[EI_NIDENT];
+ Elf64_Half e_type;
+ Elf64_Half e_machine;
+ Elf64_Word e_version;
+ Elf64_Addr e_entry;
+ Elf64_Off e_phoff;
+ Elf64_Off e_shoff;
+ Elf64_Word e_flags;
+ Elf64_Half e_ehsize;
+ Elf64_Half e_phentsize;
+ Elf64_Half e_phnum;
+ Elf64_Half e_shentsize;
+ Elf64_Half e_shnum;
+ Elf64_Half e_shstrndx;
+} Elf64_Ehdr;
+
+#define SHT_NULL 0
+#define SHT_PROGBITS 1
+#define SHT_NOBITS 8
+
+#define SHF_WRITE 0x1
+#define SHF_ALLOC 0x2
+
+typedef struct {
+ Elf64_Word sh_name;
+ Elf64_Word sh_type;
+ Elf64_Xword sh_flags;
+ Elf64_Addr sh_addr;
+ Elf64_Off sh_offset;
+ Elf64_Xword sh_size;
+ Elf64_Word sh_link;
+ Elf64_Word sh_info;
+ Elf64_Xword sh_addralign;
+ Elf64_Xword sh_entsize;
+} Elf64_Shdr;
+
+#define PT_NULL 0
+#define PT_LOAD 1
+
+#define PF_X 1
+#define PF_W 2
+#define PF_R 4
+
+typedef struct
+{
+ Elf64_Word p_type;
+ Elf64_Word p_flags;
+ Elf64_Off p_offset;
+ Elf64_Addr p_vaddr;
+ Elf64_Addr p_paddr;
+ Elf64_Xword p_filesz;
+ Elf64_Xword p_memsz;
+ Elf64_Xword p_align;
+} Elf64_Phdr;
+
+int elf64_ehdr_valid(Elf64_Ehdr *ehdr);
+
+#endif