diff --git a/sandbox/base/main.c b/sandbox/base/main.c index 18cc69b..2720858 100644 --- a/sandbox/base/main.c +++ b/sandbox/base/main.c @@ -13,6 +13,19 @@ #define ALLOC_START_MB 16 #define ALLOC_END_MB 18 +struct mem_map_region { + phys_addr_t base; + phys_addr_t limit; + enum { REGION_FREE, REGION_RESERVED } status; +}; + +static struct mem_map_region mem_map[] = { + { .base = 0x00000000, .limit = 0x0000ffff, .status = REGION_RESERVED }, + { .base = 0x00010000, .limit = 0x0004ffff, .status = REGION_FREE }, + { .base = 0x00050000, .limit = 0x0005ffff, .status = REGION_RESERVED }, + { .base = 0x00060000, .limit = 0x000affff, .status = REGION_FREE }, +}; + /* virtual address of where system memory is mapped */ static void *system_memory = NULL; @@ -38,6 +51,27 @@ int main(int argc, const char **argv) return -1; } + phys_addr_t pmem_base = UINTPTR_MAX, pmem_limit = 0; + size_t nr_mem_map_entries = sizeof mem_map / sizeof mem_map[0]; + + for (size_t i = 0; i < nr_mem_map_entries; i++) { + if (mem_map[i].base < pmem_base) { + pmem_base = mem_map[i].base; + } + + if (mem_map[i].limit > pmem_limit) { + pmem_limit = mem_map[i].limit; + } + } + + memblock_add(pmem_base, pmem_limit); + + for (size_t i = 0; i < nr_mem_map_entries; i++) { + if (mem_map[i].status == REGION_RESERVED) { + memblock_reserve(mem_map[i].base, mem_map[i].limit); + } + } + printf("allocated %u MiB (0x%zx bytes) of memory to act as system RAM at %p\n", MEMORY_SIZE_MB, MB_TO_BYTES(MEMORY_SIZE_MB), system_memory); uintptr_t voffset = (uintptr_t)system_memory; @@ -48,11 +82,6 @@ int main(int argc, const char **argv) memblock_add(0, MB_TO_BYTES(MEMORY_SIZE_MB)); - memblock_reserve(0x00000, 0x40000); - memblock_reserve(0x60000, 0x20000); - memblock_reserve(0x30000, 0x40000); - memblock_reserve(0x100000, 0x10000); - for (int i = 0; i < 8; i++) { int size = 512 + (rand() % 16384);