Added a memory map to sandbox memblock test

This commit is contained in:
2023-01-10 20:53:50 +00:00
parent 44cd04c57a
commit 39c2ee0e0f

View File

@@ -13,6 +13,19 @@
#define ALLOC_START_MB 16 #define ALLOC_START_MB 16
#define ALLOC_END_MB 18 #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 */ /* virtual address of where system memory is mapped */
static void *system_memory = NULL; static void *system_memory = NULL;
@@ -38,6 +51,27 @@ int main(int argc, const char **argv)
return -1; 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); 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; 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_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++) { for (int i = 0; i < 8; i++) {
int size = 512 + (rand() % 16384); int size = 512 + (rand() % 16384);