Sort the memmory map provided to the guest A sorted memory map seems to be the defacto standard. This is just a trivial bubble sort, but this doesn't seem to be called often enough or take any noticable time for something more complicated. Signed-off-by: Alex Williamson --- diff -r df27743a1e0a edk2-sparse/EdkModulePkg/Core/Dxe/Mem/Page.c --- a/edk2-sparse/EdkModulePkg/Core/Dxe/Mem/Page.c Wed Oct 10 11:59:15 2007 -0600 +++ b/edk2-sparse/EdkModulePkg/Core/Dxe/Mem/Page.c Wed Oct 10 11:59:28 2007 -0600 @@ -1363,6 +1363,10 @@ Returns: LIST_ENTRY *Link; MEMORY_MAP *Entry; EFI_GCD_MAP_ENTRY *GcdMapEntry; + EFI_MEMORY_DESCRIPTOR *MemoryMapBase = MemoryMap; + EFI_MEMORY_DESCRIPTOR *MemoryMapA, *MemoryMapB; + EFI_MEMORY_DESCRIPTOR MemoryMapSpare; + BOOLEAN Sorted; // // Make sure the parameters are valid @@ -1477,7 +1481,26 @@ Returns: } } } - + + // + // Simple bubble sort + // + do { + Sorted = TRUE; + MemoryMapA = MemoryMapBase; + MemoryMapB = NextMemoryDescriptor(MemoryMapA, Size); + while (MemoryMapB < MemoryMap) { + if (MemoryMapA->PhysicalStart > MemoryMapB->PhysicalStart) { + CopyMem(&MemoryMapSpare, MemoryMapA, sizeof (EFI_MEMORY_DESCRIPTOR)); + CopyMem(MemoryMapA, MemoryMapB, sizeof (EFI_MEMORY_DESCRIPTOR)); + CopyMem(MemoryMapB, &MemoryMapSpare, sizeof (EFI_MEMORY_DESCRIPTOR)); + Sorted = FALSE; + } + MemoryMapA = MemoryMapB; + MemoryMapB = NextMemoryDescriptor(MemoryMapB, Size); + } + } while (Sorted == FALSE); + Status = EFI_SUCCESS; Done: