diff --git a/qloader2.bin b/qloader2.bin index 2bc87efe..a65f4fce 100644 Binary files a/qloader2.bin and b/qloader2.bin differ diff --git a/src/lib/elf.c b/src/lib/elf.c index 35a9378d..336fef15 100644 --- a/src/lib/elf.c +++ b/src/lib/elf.c @@ -271,7 +271,7 @@ int elf32_load_section(struct file_handle *fd, void *buffer, const char *name, s return 2; } -int elf64_load(struct file_handle *fd, uint64_t *entry_point, uint64_t *top, uint64_t slide) { +int elf64_load(struct file_handle *fd, uint64_t *entry_point, uint64_t *top, uint64_t slide, uint32_t alloc_type) { struct elf64_hdr hdr; fread(fd, &hdr, 0, sizeof(struct elf64_hdr)); @@ -312,7 +312,7 @@ int elf64_load(struct file_handle *fd, uint64_t *entry_point, uint64_t *top, uin if (this_top > *top) *top = this_top; - memmap_alloc_range((size_t)load_vaddr, (size_t)phdr.p_memsz); + memmap_alloc_range((size_t)load_vaddr, (size_t)phdr.p_memsz, alloc_type); fread(fd, (void *)(uint32_t)load_vaddr, phdr.p_offset, phdr.p_filesz); @@ -335,7 +335,7 @@ int elf64_load(struct file_handle *fd, uint64_t *entry_point, uint64_t *top, uin return 0; } -int elf32_load(struct file_handle *fd, uint32_t *entry_point, uint32_t *top) { +int elf32_load(struct file_handle *fd, uint32_t *entry_point, uint32_t *top, uint32_t alloc_type) { struct elf32_hdr hdr; fread(fd, &hdr, 0, sizeof(struct elf32_hdr)); @@ -368,7 +368,7 @@ int elf32_load(struct file_handle *fd, uint32_t *entry_point, uint32_t *top) { if (this_top > *top) *top = this_top; - memmap_alloc_range((size_t)phdr.p_paddr, (size_t)phdr.p_memsz); + memmap_alloc_range((size_t)phdr.p_paddr, (size_t)phdr.p_memsz, alloc_type); fread(fd, (void *)phdr.p_paddr, phdr.p_offset, phdr.p_filesz); diff --git a/src/lib/elf.h b/src/lib/elf.h index 4b4b1b6a..c3467e6b 100644 --- a/src/lib/elf.h +++ b/src/lib/elf.h @@ -8,10 +8,10 @@ int elf_bits(struct file_handle *fd); -int elf64_load(struct file_handle *fd, uint64_t *entry_point, uint64_t *top, uint64_t slide); +int elf64_load(struct file_handle *fd, uint64_t *entry_point, uint64_t *top, uint64_t slide, uint32_t alloc_type); int elf64_load_section(struct file_handle *fd, void *buffer, const char *name, size_t limit, uint64_t slide); -int elf32_load(struct file_handle *fd, uint32_t *entry_point, uint32_t *top); +int elf32_load(struct file_handle *fd, uint32_t *entry_point, uint32_t *top, uint32_t alloc_type); int elf32_load_section(struct file_handle *fd, void *buffer, const char *name, size_t limit); #endif diff --git a/src/lib/memmap.c b/src/lib/memmap.c index d4da5f96..4ab1d69c 100644 --- a/src/lib/memmap.c +++ b/src/lib/memmap.c @@ -165,7 +165,7 @@ void init_memmap(void) { sanitise_entries(); } -void memmap_alloc_range(uint64_t base, uint64_t length) { +void memmap_alloc_range(uint64_t base, uint64_t length, uint32_t type) { uint64_t top = base + length; for (size_t i = 0; i < memmap_entries; i++) { @@ -206,7 +206,7 @@ void memmap_alloc_range(uint64_t base, uint64_t length) { } target = &memmap[memmap_entries++]; - target->type = MEMMAP_KERNEL_AND_MODULES; + target->type = type; target->base = base; target->length = length; diff --git a/src/lib/memmap.h b/src/lib/memmap.h index b33282dc..da587d5d 100644 --- a/src/lib/memmap.h +++ b/src/lib/memmap.h @@ -5,7 +5,7 @@ #include void init_memmap(void); -void memmap_alloc_range(uint64_t base, uint64_t length); +void memmap_alloc_range(uint64_t base, uint64_t length, uint32_t type); struct e820_entry_t *get_memmap(size_t *entries); void print_memmap(struct e820_entry_t *mm, size_t size); diff --git a/src/protos/linux.c b/src/protos/linux.c index 59cb83a0..a8a60f68 100644 --- a/src/protos/linux.c +++ b/src/protos/linux.c @@ -103,7 +103,7 @@ void linux_load(char *cmdline, int boot_drive) { // load kernel print("Loading kernel...\n"); - memmap_alloc_range(KERNEL_LOAD_ADDR, fd->size - real_mode_code_size); + memmap_alloc_range(KERNEL_LOAD_ADDR, fd->size - real_mode_code_size, 0); fread(fd, (void *)KERNEL_LOAD_ADDR, real_mode_code_size, fd->size - real_mode_code_size); char initrd_path[64]; @@ -125,7 +125,7 @@ void linux_load(char *cmdline, int boot_drive) { } print("Loading initrd...\n"); - memmap_alloc_range(INITRD_LOAD_ADDR, initrd.size); + memmap_alloc_range(INITRD_LOAD_ADDR, initrd.size, 0); fread(&initrd, (void *)INITRD_LOAD_ADDR, 0, initrd.size); *((uint32_t *)(real_mode_code + 0x218)) = (uint32_t)INITRD_LOAD_ADDR; diff --git a/src/protos/stivale.c b/src/protos/stivale.c index 1c5b9bc3..b086b371 100644 --- a/src/protos/stivale.c +++ b/src/protos/stivale.c @@ -145,10 +145,10 @@ void stivale_load(char *cmdline, int boot_drive) { switch (bits) { case 64: - elf64_load(fd, &entry_point, &top_used_addr, slide); + elf64_load(fd, &entry_point, &top_used_addr, slide, 10); break; case 32: - elf32_load(fd, (uint32_t *)&entry_point, (uint32_t *)&top_used_addr); + elf32_load(fd, (uint32_t *)&entry_point, (uint32_t *)&top_used_addr, 10); break; } @@ -192,7 +192,7 @@ void stivale_load(char *cmdline, int boot_drive) { ((uint32_t)top_used_addr & ~((uint32_t)0xfff)) + 0x1000 : (uint32_t)top_used_addr); - memmap_alloc_range((size_t)module_addr, f.size); + memmap_alloc_range((size_t)module_addr, f.size, 10); fread(&f, module_addr, 0, f.size); m->begin = (uint64_t)(size_t)module_addr; diff --git a/src/protos/stivale2.c b/src/protos/stivale2.c index b9360dfd..18ea0206 100644 --- a/src/protos/stivale2.c +++ b/src/protos/stivale2.c @@ -232,10 +232,10 @@ void stivale2_load(char *cmdline, int boot_drive) { switch (bits) { case 64: - elf64_load(fd, &entry_point, &top_used_addr, slide); + elf64_load(fd, &entry_point, &top_used_addr, slide, 0x1001); break; case 32: - elf32_load(fd, (uint32_t *)&entry_point, (uint32_t *)&top_used_addr); + elf32_load(fd, (uint32_t *)&entry_point, (uint32_t *)&top_used_addr, 0x1001); break; } @@ -301,7 +301,7 @@ void stivale2_load(char *cmdline, int boot_drive) { ((uint32_t)top_used_addr & ~((uint32_t)0xfff)) + 0x1000 : (uint32_t)top_used_addr); - memmap_alloc_range((size_t)module_addr, f.size); + memmap_alloc_range((size_t)module_addr, f.size, 0x1001); fread(&f, module_addr, 0, f.size); m->begin = (uint64_t)(size_t)module_addr; @@ -310,10 +310,10 @@ void stivale2_load(char *cmdline, int boot_drive) { top_used_addr = (uint64_t)(size_t)m->end; print("stivale2: Requested module %u:\n", i); - print(" Path: %s\n", module_file); - print(" String: %s\n", m->string); - print(" Begin: %X\n", m->begin); - print(" End: %X\n", m->end); + print(" Path: %s\n", module_file); + print(" String: %s\n", m->string); + print(" Begin: %X\n", m->begin); + print(" End: %X\n", m->end); } append_tag(&stivale2_struct, (struct stivale2_tag *)tag);