pmm: Misc bug fixes in pmm
This commit is contained in:
parent
96c184fdf6
commit
e466501f92
|
@ -100,7 +100,7 @@ void *freadall(struct file_handle *fd, uint32_t type) {
|
||||||
if (fd->readall) {
|
if (fd->readall) {
|
||||||
return fd->fd;
|
return fd->fd;
|
||||||
}
|
}
|
||||||
memmap_alloc_range((uint64_t)(size_t)fd->fd, ALIGN_UP(fd->size, 4096), type, false, true, false, false);
|
memmap_alloc_range((uint64_t)(size_t)fd->fd, ALIGN_UP(fd->size, 4096), type, 0, true, false, false);
|
||||||
fd->readall = true;
|
fd->readall = true;
|
||||||
return fd->fd;
|
return fd->fd;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -32,7 +32,7 @@ void *conv_mem_alloc(size_t count) {
|
||||||
if (base + count > 0x100000)
|
if (base + count > 0x100000)
|
||||||
panic(false, "Conventional memory allocation failed");
|
panic(false, "Conventional memory allocation failed");
|
||||||
|
|
||||||
if (memmap_alloc_range(base, count, MEMMAP_BOOTLOADER_RECLAIMABLE, true, false, false, false)) {
|
if (memmap_alloc_range(base, count, MEMMAP_BOOTLOADER_RECLAIMABLE, MEMMAP_USABLE, false, false, false)) {
|
||||||
void *ret = (void *)(uintptr_t)base;
|
void *ret = (void *)(uintptr_t)base;
|
||||||
// Zero out allocated space
|
// Zero out allocated space
|
||||||
memset(ret, 0, count);
|
memset(ret, 0, count);
|
||||||
|
@ -91,7 +91,7 @@ static const char *memmap_type(uint32_t type) {
|
||||||
|
|
||||||
void print_memmap(struct memmap_entry *mm, size_t size) {
|
void print_memmap(struct memmap_entry *mm, size_t size) {
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
printv("[%X -> %X] : %X <%s (%x)>\n",
|
print("[%X -> %X] : %X <%s (%x)>\n",
|
||||||
mm[i].base,
|
mm[i].base,
|
||||||
mm[i].base + mm[i].length,
|
mm[i].base + mm[i].length,
|
||||||
mm[i].length,
|
mm[i].length,
|
||||||
|
@ -277,7 +277,7 @@ void init_memmap(void) {
|
||||||
|
|
||||||
// Allocate bootloader itself
|
// Allocate bootloader itself
|
||||||
memmap_alloc_range(4096,
|
memmap_alloc_range(4096,
|
||||||
ALIGN_UP((uintptr_t)bss_end, 4096) - 4096, MEMMAP_BOOTLOADER_RECLAIMABLE, true, true, false, false);
|
ALIGN_UP((uintptr_t)bss_end, 4096) - 4096, MEMMAP_BOOTLOADER_RECLAIMABLE, 0, true, false, false);
|
||||||
|
|
||||||
sanitise_entries(memmap, &memmap_entries, false);
|
sanitise_entries(memmap, &memmap_entries, false);
|
||||||
|
|
||||||
|
@ -383,7 +383,6 @@ void init_memmap(void) {
|
||||||
bool old_skfp = sanitiser_keep_first_page;
|
bool old_skfp = sanitiser_keep_first_page;
|
||||||
sanitiser_keep_first_page = true;
|
sanitiser_keep_first_page = true;
|
||||||
sanitise_entries(memmap, &memmap_entries, false);
|
sanitise_entries(memmap, &memmap_entries, false);
|
||||||
sanitiser_keep_first_page = old_skfp;
|
|
||||||
|
|
||||||
allocations_disallowed = false;
|
allocations_disallowed = false;
|
||||||
|
|
||||||
|
@ -404,18 +403,20 @@ void init_memmap(void) {
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
print("pmm: WARNING: AllocatePages failure (%d)\n", status);
|
print("pmm: WARNING: AllocatePages failure (%d)\n", status);
|
||||||
memmap_alloc_range(memmap[i].base, memmap[i].length, MEMMAP_RESERVED, true, true, false, false);
|
memmap_alloc_range(memmap[i].base, memmap[i].length, MEMMAP_RESERVED, MEMMAP_USABLE, true, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(untouched_memmap, memmap, memmap_entries * sizeof(struct memmap_entry));
|
memcpy(untouched_memmap, memmap, memmap_entries * sizeof(struct memmap_entry));
|
||||||
untouched_memmap_entries = memmap_entries;
|
untouched_memmap_entries = memmap_entries;
|
||||||
|
|
||||||
|
sanitiser_keep_first_page = old_skfp;
|
||||||
|
|
||||||
size_t bootloader_size = ALIGN_UP((uintptr_t)__image_end - (uintptr_t)__image_base, 4096);
|
size_t bootloader_size = ALIGN_UP((uintptr_t)__image_end - (uintptr_t)__image_base, 4096);
|
||||||
|
|
||||||
// Allocate bootloader itself
|
// Allocate bootloader itself
|
||||||
memmap_alloc_range((uintptr_t)__image_base, bootloader_size,
|
memmap_alloc_range((uintptr_t)__image_base, bootloader_size,
|
||||||
MEMMAP_BOOTLOADER_RECLAIMABLE, false, true, false, true);
|
MEMMAP_BOOTLOADER_RECLAIMABLE, 0, true, false, true);
|
||||||
|
|
||||||
sanitise_entries(memmap, &memmap_entries, false);
|
sanitise_entries(memmap, &memmap_entries, false);
|
||||||
|
|
||||||
|
@ -551,7 +552,7 @@ void pmm_free(void *ptr, size_t count) {
|
||||||
count = ALIGN_UP(count, 4096);
|
count = ALIGN_UP(count, 4096);
|
||||||
if (allocations_disallowed)
|
if (allocations_disallowed)
|
||||||
panic(false, "Memory allocations disallowed");
|
panic(false, "Memory allocations disallowed");
|
||||||
memmap_alloc_range((uintptr_t)ptr, count, MEMMAP_USABLE, false, false, false, true);
|
memmap_alloc_range((uintptr_t)ptr, count, MEMMAP_USABLE, 0, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ext_mem_alloc(size_t count) {
|
void *ext_mem_alloc(size_t count) {
|
||||||
|
@ -591,7 +592,7 @@ void *ext_mem_alloc_type_aligned(size_t count, uint32_t type, size_t alignment)
|
||||||
|
|
||||||
// We now reserve the range we need.
|
// We now reserve the range we need.
|
||||||
int64_t aligned_length = entry_top - alloc_base;
|
int64_t aligned_length = entry_top - alloc_base;
|
||||||
memmap_alloc_range((uint64_t)alloc_base, (uint64_t)aligned_length, type, true, true, false, false);
|
memmap_alloc_range((uint64_t)alloc_base, (uint64_t)aligned_length, type, MEMMAP_USABLE, true, false, false);
|
||||||
|
|
||||||
void *ret = (void *)(size_t)alloc_base;
|
void *ret = (void *)(size_t)alloc_base;
|
||||||
|
|
||||||
|
|
|
@ -746,7 +746,7 @@ FEAT_END
|
||||||
skip_fb_init:
|
skip_fb_init:
|
||||||
memmap_alloc_range(fb.framebuffer_addr,
|
memmap_alloc_range(fb.framebuffer_addr,
|
||||||
(uint64_t)fb.framebuffer_pitch * fb.framebuffer_height,
|
(uint64_t)fb.framebuffer_pitch * fb.framebuffer_height,
|
||||||
MEMMAP_FRAMEBUFFER, false, false, false, true);
|
MEMMAP_FRAMEBUFFER, 0, false, false, true);
|
||||||
|
|
||||||
// Framebuffer feature
|
// Framebuffer feature
|
||||||
FEAT_START
|
FEAT_START
|
||||||
|
|
|
@ -426,7 +426,7 @@ noreturn void linux_load(char *config, char *cmdline) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (memmap_alloc_range(kernel_load_addr,
|
if (memmap_alloc_range(kernel_load_addr,
|
||||||
ALIGN_UP(kernel_file->size - real_mode_code_size, 4096),
|
ALIGN_UP(kernel_file->size - real_mode_code_size, 4096),
|
||||||
MEMMAP_BOOTLOADER_RECLAIMABLE, true, false, false, false))
|
MEMMAP_BOOTLOADER_RECLAIMABLE, MEMMAP_USABLE, false, false, false))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
kernel_load_addr += 0x100000;
|
kernel_load_addr += 0x100000;
|
||||||
|
@ -464,7 +464,7 @@ noreturn void linux_load(char *config, char *cmdline) {
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (memmap_alloc_range(modules_mem_base, ALIGN_UP(size_of_all_modules, 4096),
|
if (memmap_alloc_range(modules_mem_base, ALIGN_UP(size_of_all_modules, 4096),
|
||||||
MEMMAP_BOOTLOADER_RECLAIMABLE, true, false, false, false))
|
MEMMAP_BOOTLOADER_RECLAIMABLE, MEMMAP_USABLE, false, false, false))
|
||||||
break;
|
break;
|
||||||
modules_mem_base -= 4096;
|
modules_mem_base -= 4096;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue