// // Created by rick on 4-10-23. // #include #include #include #include #define MEMMAP_ENTRIES 64 typedef struct { uintptr_t address; size_t length; uint8_t type; } mmap_entry; mmap_entry memmap[MEMMAP_ENTRIES] = {0}; void memmap_put_entry(uintptr_t address, size_t length, uint8_t type) { if (type == MMAP_TYPE_UNDEFINED || type > MMAP_LAST_TYPE) { panic("Bad memory type"); } if ((address & 0xFFF) != 0) { printf("MMap entry %8lx is not page aligned\n", address); } if (length % 4096 != 0) { printf("MMap entry %8lx not a full page %8lx\n", address, length); } for (int i = 0; i < MEMMAP_ENTRIES; ++i) { if (memmap[i].type == 0) { memmap[i].address = address; memmap[i].length = length; memmap[i].type = type; return; } } panic("No space left in memory map"); }