10#include <sys/kassert.h>
11#include <sys/sysctl.h>
17#include <machine/amd64.h>
18#include <machine/trap.h>
19#include <machine/pmap.h>
20#include <sys/thread.h>
21#include <sys/spinlock.h>
22#include <sys/loader.h>
66 if ((vaddr %
PGSIZE) != 0) {
102 if ((vaddr %
PGSIZE) != 0) {
142 Log(loader,
"Not a valid executable!\n");
146 Log(loader,
"%8s %16s %8s %8s\n",
"Offset",
"VAddr",
"FileSize",
"MemSize");
147 for (i = 0; i < ehdr->
e_phnum; i++)
150 if (phdr[i].p_type ==
PT_LOAD) {
153 Log(loader,
"%08llx %016llx %08llx %08llx\n", phdr[i].p_offset,
154 phdr[i].p_vaddr, phdr[i].p_filesz, phdr[i].p_memsz);
160 Log(loader,
"AllocMap %016llx %08llx\n", va, memsz);
195 Panic(
"Not enough memory!");
200 Panic(
"Loading init process failed!");
201 status =
VFS_Read(initvn, pg, 0, 1024);
203 Panic(
"Reading init process failed!");
222 Log(loader,
"Jumping to userspace\n");
245 memset(&tf, 0,
sizeof(tf));
258 Panic(
"Unreachable: Trap_Pop() returned!\n");
unsigned char e_ident[EI_NIDENT]
int Copy_Out(void *fromkernel, uintptr_t touser, uintptr_t len)
uint64_t Handle_Add(Process *proc, Handle *handle)
#define Log(_module, _format,...)
void * PAlloc_AllocPage()
bool Loader_Load(Thread *thr, VNode *vn, void *buf, uint64_t len)
bool Loader_CheckHeader(const Elf64_Ehdr *ehdr)
static void LoaderLoadSegment(AS *as, VNode *vn, uintptr_t vaddr, uintptr_t offset, uintptr_t len)
static void LoaderZeroSegment(AS *as, uintptr_t vaddr, uintptr_t len)
Handle * Console_OpenHandle()
#define MEM_USERSPACE_STKTOP
#define MEM_USERSPACE_STKLEN
void PMap_LoadAS(AS *space)
uintptr_t PMap_Translate(AS *space, uintptr_t va)
#define MEM_USERSPACE_STKBASE
bool PMap_AllocMap(AS *as, uint64_t virt, uint64_t len, uint64_t flags)
void * memset(void *dst, int c, size_t len)
void Trap_Pop(TrapFrame *tf)
int VFS_Read(VNode *fn, void *buf, uint64_t off, uint64_t len)
VNode * VFS_Lookup(const char *path)
void Panic(const char *str)