mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
Now any initrd file is treated like a program image and passed to the loader to load as a process. Very rudimentary elf loading just allocates pages, copies sections, and sets the ELF's entrypoint as the RIP to iretq to.
99 lines
1.5 KiB
C++
99 lines
1.5 KiB
C++
#pragma once
|
|
#include <stdint.h>
|
|
#include "kutil/enum_bitfields.h"
|
|
|
|
namespace elf {
|
|
|
|
enum class wordsize : uint8_t { invalid, bits32, bits64 };
|
|
enum class encoding : uint8_t { invalid, lsb, msb };
|
|
enum class osabi : uint8_t { sysV, hpux, standalone = 255 };
|
|
enum class machine : uint16_t { none, x64 = 0x3e };
|
|
|
|
enum class filetype : uint16_t
|
|
{
|
|
none,
|
|
relocatable,
|
|
executable,
|
|
shared,
|
|
core
|
|
};
|
|
|
|
|
|
struct file_header
|
|
{
|
|
uint32_t magic;
|
|
|
|
wordsize word_size;
|
|
encoding endianness;
|
|
uint8_t ident_version;
|
|
osabi os_abi;
|
|
|
|
uint64_t reserved;
|
|
|
|
filetype file_type;
|
|
machine machine_type;
|
|
|
|
uint32_t version;
|
|
|
|
uint64_t entrypoint;
|
|
uint64_t ph_offset;
|
|
uint64_t sh_offset;
|
|
|
|
uint32_t flags;
|
|
|
|
uint16_t eh_size;
|
|
|
|
uint16_t ph_entsize;
|
|
uint16_t ph_num;
|
|
|
|
uint16_t sh_entsize;
|
|
uint16_t sh_num;
|
|
|
|
uint16_t sh_str_idx;
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
enum class segment_type : uint32_t { null, load, dynamic, interpreter, note };
|
|
|
|
struct program_header
|
|
{
|
|
segment_type type;
|
|
uint32_t flags;
|
|
uint64_t offset;
|
|
|
|
uint64_t vaddr;
|
|
uint64_t paddr;
|
|
|
|
uint64_t file_size;
|
|
uint64_t mem_size;
|
|
|
|
uint64_t align;
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
enum class section_type : uint32_t { null, progbits };
|
|
enum class section_flags : uint64_t
|
|
{
|
|
write = 0x01,
|
|
alloc = 0x02,
|
|
exec = 0x04,
|
|
};
|
|
|
|
struct section_header
|
|
{
|
|
uint32_t name_offset;
|
|
section_type type;
|
|
section_flags flags;
|
|
uint64_t addr;
|
|
uint64_t offset;
|
|
uint64_t size;
|
|
uint32_t link;
|
|
uint32_t info;
|
|
uint64_t align;
|
|
uint64_t entry_size;
|
|
} __attribute__ ((packed));
|
|
|
|
} // namespace elf
|
|
|
|
IS_BITFIELD(elf::section_flags);
|