diff --git a/src/display.c b/src/display.c index 3dbf49ea..21bf41f3 100644 --- a/src/display.c +++ b/src/display.c @@ -369,12 +369,7 @@ int display_configure(const char *config) return -1; } - cur_boot_args.mem_size -= size; - fb_pa = cur_boot_args.phys_base + cur_boot_args.mem_size; - /* add guard page between RAM and framebuffer */ - // TODO: update mapping? - cur_boot_args.mem_size -= SZ_16K; - + fb_pa = top_of_memory_alloc(size); memset((void *)fb_pa, 0, size); tmp_dva = iova_alloc(dcp->iovad_dcp, size); diff --git a/src/utils.c b/src/utils.c index 23434762..ff8dd84b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -180,3 +180,23 @@ bool is_heap(void *addr) return p > top_of_kernel_data && p < top_of_ram; } + +// TODO: update mapping? +u64 top_of_memory_alloc(size_t size) +{ + static bool guard_page_inserted = false; + cur_boot_args.mem_size -= ALIGN_UP(size, SZ_16K); + u64 ret = cur_boot_args.phys_base + cur_boot_args.mem_size; + + if (!guard_page_inserted) { + cur_boot_args.mem_size -= SZ_16K; + guard_page_inserted = true; + } else { + // If the guard page was already there, move it down and allocate + // above it -- this is accomplished by simply shifting the allocated + // region by one page up. + ret += SZ_16K; + } + + return ret; +} diff --git a/src/utils.h b/src/utils.h index 1d053d2e..0e76221d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -440,5 +440,6 @@ extern struct vector_args next_stage; void deep_wfi(void); bool is_heap(void *addr); +u64 top_of_memory_alloc(size_t size); #endif