Fix broken memory types in stivale

This commit is contained in:
mintsuki 2020-08-11 18:00:51 +02:00
parent 6296d27c11
commit a002f05110
8 changed files with 21 additions and 21 deletions

Binary file not shown.

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -5,7 +5,7 @@
#include <lib/e820.h>
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);

View File

@ -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;

View File

@ -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;

View File

@ -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);