Sort memmap entries

This commit is contained in:
mintsuki 2020-06-05 19:09:57 +02:00
parent e91cb82222
commit b616e8014a
2 changed files with 16 additions and 0 deletions

Binary file not shown.

View File

@ -59,6 +59,22 @@ static void memmap_align_free_entries(void) {
struct e820_entry_t *get_memmap(size_t *entries) {
memmap_align_free_entries();
// Sort the entries
for (size_t p = 0; p < memmap_entries - 1; p++) {
uint64_t min = memmap[p].base;
size_t min_index = p;
for (size_t i = p; i < memmap_entries; i++) {
if (memmap[i].base < min) {
min = memmap[i].base;
min_index = i;
}
}
struct e820_entry_t min_e = memmap[min_index];
memmap[min_index] = memmap[p];
memmap[p] = min_e;
}
*entries = memmap_entries;
return memmap;
}