> compile NEMU
221220000 张三 Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 16:50:21 up 6 days, 11:55, 1 user, load average: 0.39, 0.47, 0.41
This commit is contained in:
@ -10,8 +10,30 @@
|
||||
#endif
|
||||
|
||||
static uintptr_t loader(PCB *pcb, const char *filename) {
|
||||
TODO();
|
||||
return 0;
|
||||
// TODO();
|
||||
Elf_Ehdr ehdr;
|
||||
size_t ret;
|
||||
|
||||
size_t ramdisk_read(void *buf, size_t offset, size_t len);
|
||||
ret = ramdisk_read(&ehdr, 0, sizeof(ehdr));
|
||||
assert(ret == sizeof(ehdr));
|
||||
// assert(ehdr.e_ident[0] == 0x7f && ehdr.e_ident[1] == 'E' && ehdr.e_ident[2] == 'L' && ehdr.e_ident[3] == 'F');
|
||||
// assert(memcpy(ehdr.e_ident, ELFMAG, SELFMAG) == 0);
|
||||
assert(*(uint32_t *)ehdr.e_ident == 0x7f454746);
|
||||
|
||||
Elf_Phdr phdr[ehdr.e_phnum];
|
||||
assert(ehdr.e_phentsize % sizeof(Elf_Phdr) == ehdr.e_phnum);
|
||||
ret = ramdisk_read(&phdr, ehdr.e_phoff, ehdr.e_phentsize);
|
||||
assert(ret == sizeof(phdr));
|
||||
|
||||
for (int i = 0; i < ehdr.e_phnum; i ++) {
|
||||
if (phdr[i].p_type != PT_LOAD) continue;
|
||||
ret = ramdisk_read((void*)phdr[i].p_vaddr, phdr[i].p_offset, phdr[i].p_filesz);
|
||||
assert(ret == phdr[i].p_filesz);
|
||||
memset((uint8_t*)phdr[i].p_vaddr + phdr[i].p_filesz, 0, phdr[i].p_memsz - phdr[i].p_filesz);
|
||||
}
|
||||
|
||||
return ehdr.e_entry;
|
||||
}
|
||||
|
||||
void naive_uload(PCB *pcb, const char *filename) {
|
||||
|
Reference in New Issue
Block a user