HalpDmaInitMemory

INT64 __fastcall HalpDmaInitMemory(INT64 a1){
  unsigned int v2; 
  int v3; 
  UINT64 v4; 
  unsigned int i; 
  UINT64 v6; 
  INT64 result; 
  LARGE_INTEGER MaxPhysicalAddress; 
  HalpDmaAdapterListLock = 0i64;
  qword_140C4BCA8 = (__int64)&HalpDmaAdapterList;
  HalpDmaAdapterList = (__int64)&HalpDmaAdapterList;
  LOWORD(HalpNewAdapter.Header.Lock) = 1;
  HalpNewAdapter.Header.Size = 6;
  HalpNewAdapter.Header.SignalState = 1;
  HalpNewAdapter.Header.WaitListHead.Blink = &HalpNewAdapter.Header.WaitListHead;
  HalpNewAdapter.Header.WaitListHead.Flink = &HalpNewAdapter.Header.WaitListHead;
  MaxPhysicalAddress.QuadPart = 0x1000000i64;
  qword_140C4B920 = HalpAllocPhysicalMemory((_LOADER_PARAMETER_BLOCK *)a1, &MaxPhysicalAddress);
  dword_140C4B918 = qword_140C4B920 != 0 ? 0x10000 : 0;
  qword_140C4BAE0 = HalpAllocPhysicalMemory((_LOADER_PARAMETER_BLOCK *)a1, &MaxPhysicalAddress);
  v2 = 32;
  dword_140C4BAD8 = qword_140C4BAE0 != 0 ? 0x10000 : 0;
  v3 = (unsigned __int64)HalpMaximumPhysicalMemoryAddress < 0x100000000i64 ? 0x10000 : 196608;
  do
  {
    MaxPhysicalAddress.QuadPart = (1i64 << v2) - 1;
    v4 = HalpAllocPhysicalMemory((_LOADER_PARAMETER_BLOCK *)a1, &MaxPhysicalAddress);
    if( v4 )
      break;
    ++v2;
  }
  while( v2 <= 0x20 );
  qword_140C4BA00 = v4;
  dword_140C4B9F8 = v4 != 0 ? v3 : 0;
  if( v2 >= 0x40 )
    qword_140C4B9C8 = -1i64;
  else
    qword_140C4B9C8 = (1i64 << v2) - 1;
  for( i = 32; i <= 0x20; ++i )
  {
    MaxPhysicalAddress.QuadPart = (1i64 << i) - 1;
    v6 = HalpAllocPhysicalMemory((_LOADER_PARAMETER_BLOCK *)a1, &MaxPhysicalAddress);
    if( v6 )
      break;
  }
  qword_140C4BBC0 = v6;
  result = -(__int64)v6;
  dword_140C4BBB8 = result != 0 ? v3 : 0;
  if( i >= 0x40 )
  {
    qword_140C4BB88 = -1i64;
  }
  else
  {
    result = (1i64 << i) - 1;
    qword_140C4BB88 = result;
  }
  return result;
}

Referenced by:

HalpDmaInitDiscard