/* Internal function. Inserts a new descriptor into a sorted list */
EFI_STATUS CoreInsertGcdMapEntry(IN LIST_ENTRY *Link, IN EFI_GCD_MAP_ENTRY *Entry, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN EFI_GCD_MAP_ENTRY *TopEntry, IN EFI_GCD_MAP_ENTRY *BottomEntry)
/* Internal function. Inserts a new descriptor into a sorted list */
EFI_STATUS CoreInsertGcdMapEntry(IN LIST_ENTRY *Link, IN EFI_GCD_MAP_ENTRY *Entry, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN EFI_GCD_MAP_ENTRY *TopEntry, IN EFI_GCD_MAP_ENTRY *BottomEntry)
{
  ASSERT (Length != 0);
  if (BaseAddress > Entry->BaseAddress) {
    ASSERT (BottomEntry->Signature == 0);
    CopyMem (BottomEntry, Entry, sizeof (EFI_GCD_MAP_ENTRY));
    Entry->BaseAddress      = BaseAddress;
    BottomEntry->EndAddress = BaseAddress - 1;
    InsertTailList (Link, &BottomEntry->Link);
  }
  if ((BaseAddress + Length - 1) < Entry->EndAddress) {
    ASSERT (TopEntry->Signature == 0);
    CopyMem (TopEntry, Entry, sizeof (EFI_GCD_MAP_ENTRY));
    TopEntry->BaseAddress = BaseAddress + Length;
    Entry->EndAddress     = BaseAddress + Length - 1;
    InsertHeadList (Link, &TopEntry->Link);
  }
  return EFI_SUCCESS;
}