Code: Select all
// @brief Parses the memory map and returns the amount of RAM in the system.
uint64_t mem_map_parse(Memory_Map_Descriptor* memmap, uint64_t map_size, uint64_t desc_size)
{
uint8_t *startOfMemoryMap = (uint8_t *)memmap;
uint8_t *endOfMemoryMap = startOfMemoryMap + map_size;
uint8_t *offset = startOfMemoryMap;
uint32_t counter = 0;
serial_msg("\n\nMEMORY MAP:\n-=-=-=-=-=-\n");
while (offset < endOfMemoryMap)
{
Memory_Map_Descriptor *desc = (Memory_Map_Descriptor *)offset;
hex_str_serial(desc->physical_start);
serial_msg(": ");
serial_msg(memory_types[desc->type]);
serial_msg(" (");
dec_str_serial(desc->count);
serial_msg(")");
serial_msg("\n");
offset += desc_size;
counter++;
}
offset -= desc_size;
Memory_Map_Descriptor *desc = (Memory_Map_Descriptor *)offset;
hex_str_serial(desc->physical_start);
serial_msg(": ");
serial_msg(memory_types[desc->type]);
serial_msg(" (");
dec_str_serial(desc->count);
serial_msg(")");
serial_msg("\n");
return (((uint64_t)desc->physical_start) + ((desc->count * 0x1000)));
}
Code: Select all
void malloc_init(Memory_Map_Descriptor* memmap, uint64_t map_size, uint64_t desc_size)
{
serial_msg("\n");
dec_str_serial(((mem_map_parse(memmap, map_size, desc_size)) / 1024) / 1024);
serial_msg("MiB of RAM\n");
}
Code: Select all
5120MiB of RAM
I try allocating 6GiB:
Code: Select all
7168MiB of RAM
Forgive me if I am overlooking something, I am taking 8th grade pre-algebra at the moment...
...though this shouldn't be too complicated.