Started implementing a boot-time memory manager
This commit is contained in:
@@ -1,7 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/mman.h>
|
||||
#include "memblock.h"
|
||||
|
||||
/* we're working with 4MiB of simulated system RAM */
|
||||
#define MEMORY_SIZE 0x400000ULL
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
printf("Hello, world\n");
|
||||
void *system_memory = mmap(
|
||||
NULL,
|
||||
MEMORY_SIZE,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS,
|
||||
-1, 0);
|
||||
|
||||
if (system_memory == MAP_FAILED) {
|
||||
perror("mmap");
|
||||
fprintf(stderr, "cannot allocate simulated system RAM buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("allocated 0x%llx bytes of memory to act as system RAM at %p\n", MEMORY_SIZE, system_memory);
|
||||
|
||||
memblock_add(0, MEMORY_SIZE);
|
||||
|
||||
memblock_reserve(0x10000, 0x40000);
|
||||
memblock_reserve(0x60000, 0x20000);
|
||||
memblock_reserve(0x30000, 0x40000);
|
||||
|
||||
printf("memory regions:\n");
|
||||
for (unsigned int i = 0; i < memblock.memory.count; i++) {
|
||||
printf("\t%08" PRIxPTR "-%08" PRIxPTR "\n",
|
||||
memblock.memory.regions[i].base,
|
||||
memblock.memory.regions[i].limit);
|
||||
}
|
||||
|
||||
printf("reserved regions:\n");
|
||||
for (unsigned int i = 0; i < memblock.reserved.count; i++) {
|
||||
printf("\t%08" PRIxPTR "-%08" PRIxPTR "\n",
|
||||
memblock.reserved.regions[i].base,
|
||||
memblock.reserved.regions[i].limit);
|
||||
}
|
||||
|
||||
munmap(system_memory, MEMORY_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user