HalpMap

UINT64 __stdcall HalpMap(LARGE_INTEGER PhysicalAddress, MEMORY_CACHING_TYPE CacheType, UINT8 FlushCurrentTLB){
  char v3; 
  int v4; 
  char v5; 
  __int64 v8; 
  unsigned __int64 v9; 
  unsigned int v10; 
  char *v11; 
  _HARDWARE_PTE *PteAddressSafe; 
  bool v13; 
  UINT64 v14; 
  __int64 v15; 
  unsigned __int64 v16; 
  __int64 v17; 
  LONGLONG v18; 
  unsigned int v20; 
  v4 = FlushCurrentTLB;
  v5 = v3;
  if( FlushCurrentTLB > 1u )
    return 0i64;
  if( v20 > 0x20 )
    return 0i64;
  v8 = 0x100000014i64;
  if( !_bittest64(&v8, v20) )
    return 0i64;
  v9 = (unsigned __int64)HalpHeapStart;
  v10 = 0;
  if( CacheType )
  {
    while( 2 )
    {
      v10 = 0;
      v11 = (char *)v9;
      while( 1 )
      {
        if( v11 == (char *)HalpHeapEnd )
          return 0i64;
        PteAddressSafe = HalpMmGetPteAddressSafe(v11);
        if( !PteAddressSafe )
          return 0i64;
        v11 += 4096;
        if( (*(_BYTE *)PteAddressSafe & 1) != 0 )
          break;
        if( ++v10 >= CacheType )
          goto LABEL_10;
      }
      v9 = (unsigned __int64)v11;
LABEL_10:
      if( v20 == 32 )
      {
        v13 = v10 < CacheType;
        if( v10 != CacheType )
        {
LABEL_12:
          if( v13 )
            continue;
          goto LABEL_13;
        }
        if( HalpIsHeap64KRegionExecutable(v9)
          || HalpIsHeap64KRegionExecutable(v9 + (unsigned int)((CacheType << 12) - 4096)) )
        {
          v10 = 0;
        }
      }
      break;
    }
    v13 = v10 < CacheType;
    goto LABEL_12;
  }
LABEL_13:
  v14 = v9 | PhysicalAddress.LowPart & 0xFFF;
  if( (VOID *)v9 == HalpHeapStart )
    HalpHeapStart = (VOID *)(v9 + (unsigned int)(CacheType << 12));
  if( v10 )
  {
    v15 = 3i64;
    if( v20 != 4 )
      v15 = 1i64;
    v16 = v15 | 0x8000000000000000ui64;
    if( v20 == 32 )
      v16 = v15;
    v17 = v16 | 0x18;
    if( v4 == 1 )
      v17 = v16;
    do
    {
      v18 = v17 | PhysicalAddress.QuadPart & 0xFFFFFFFFF000i64;
      PhysicalAddress.QuadPart += 4096i64;
      *((_QWORD *)MmGetPteBase() + ((v9 >> 12) & 0xFFFFFFFFFi64)) = v18;
      if( v5 )
        __invlpg((void *)v9);
      v9 += 4096i64;
      --v10;
    }
    while( v10 );
  }
  if( !v5 )
    HalpFlushTLB();
  return v14;
}

Referenced by:

HalMapIoSpace
HalpAcpiAllocateMemory
HalpAcpiCheckAndMapTable
HalpAcpiGetRsdt
HalpAcpiTableCacheInit
HalpAllocateEarlyPages
HalpAllocateNumaConfigData
HalpBlkAllocateAndShadowMemory
HalpBlkAllocatePageTablePage
HalpBlkInitializeVirtualAddressSpace
HalpInterruptMapParkedPage
HalpMapEarlyPages
HalpMapPhysicalMemory64
HalpMapPhysicalMemoryWriteThrough64
HalpMmAllocateMemoryInternal
HalpPciMapMmConfigPhysicalAddress
HalpPowerWriteResetCommand
HalpSetupAcpiPhase0
HalpUsbLegacyStopOhciInterrupt