HalpInterruptEnableNmi

INT64 __stdcall HalpInterruptEnableNmi(){
  unsigned __int8 v0; 
  struct _KPRCB *CurrentPrcb; 
  ULONG_PTR v2; 
  unsigned int v3; 
  unsigned __int64 v4; 
  unsigned int v5; 
  __int64 v6; 
  char v7; 
  int v8; 
  int v9; 
  int v10; 
  int v11; 
  int v12; 
  __int64 v14; 
  __int64 v15; 
  ULONG_PTR *Lines; 
  __int64 v17; 
  ULONG_PTR *v18; 
  int v19; 
  INT64 v20; 
  unsigned int v21; 
  __int64 v22; 
  unsigned int v23; 
  INT64 v24[2]; 
  __int128 v25; 
  __int128 v26; 
  __int64 v27; 
  __int128 v28; 
  __int128 *v29; 
  __int128 v30; 
  __int128 v31; 
  v22 = 0i64;
  v23 = 0;
  v28 = 0i64;
  v29 = 0i64;
  v31 = 0i64;
  v27 = 0i64;
  *(_OWORD *)v24 = 0i64;
  v25 = 0i64;
  v26 = 0i64;
  v30 = 0i64;
  v0 = HalpAcquireHighLevelLock(&HalpInterruptLock);
  CurrentPrcb = KeGetCurrentPrcb();
  v2 = 0i64;
  v3 = 0;
  v4 = v0;
  v5 = HalpInterruptProcessorCount;
  if( (_DWORD)HalpInterruptProcessorCount )
  {
    while( 1 )
    {
      v2 = HalpInterruptProcessorState + ((unsigned __int64)v3 << 6);
      if( *(_WORD *)(v2 + 16) == *((unsigned __int8 *)CurrentPrcb + 208)
        && *(_BYTE *)(v2 + 18) == *((_BYTE *)CurrentPrcb + 209) )
      {
        break;
      }
      if( ++v3 >= (unsigned int)HalpInterruptProcessorCount )
        goto LABEL_7;
    }
    v5 = v3;
  }
LABEL_7:
  if( v5 == (_DWORD)HalpInterruptProcessorCount )
    KeBugCheckEx(
      0x5Cu,
      0x104ui64,
      *((unsigned __int8 *)CurrentPrcb + 209) | ((unsigned __int64)*((unsigned __int8 *)CurrentPrcb + 208) << 8),
      (unsigned int)HalpInterruptProcessorCount,
      0i64);
  v6 = HalpInterruptNmiSources;
  if( !HalpInterruptNmiSources )
  {
LABEL_21:
    v12 = 0;
    goto LABEL_22;
  }
  while( 1 )
  {
    v7 = 0;
    if( *(_BYTE *)(v6 + 8) )
      break;
    if( !*((_DWORD *)CurrentPrcb + 9) )
      goto LABEL_13;
LABEL_20:
    v6 = *(_QWORD *)v6;
    if( !v6 )
      goto LABEL_21;
  }
  if( !*(_BYTE *)(v2 + 13) )
    goto LABEL_20;
  v8 = *(_DWORD *)(v6 + 12);
  if( v8 != -1 && v8 != *(_DWORD *)(v2 + 4) )
    goto LABEL_20;
  v7 = 1;
LABEL_13:
  *(_OWORD *)v24 = 0i64;
  v9 = 0;
  v27 = 0i64;
  v25 = 0i64;
  v26 = 0i64;
  v30 = 0i64;
  if( *(_BYTE *)(v6 + 8) )
  {
    if( (*(_DWORD *)(v6 + 16) & 0xC) != 12 )
      v9 = 1;
    LODWORD(v24[1]) = v9;
    v10 = ((*(_BYTE *)(v6 + 16) & 3) == 3) + 1;
  }
  else
  {
    if( (*(_DWORD *)(v6 + 16) & 8) == 0 )
      v9 = 1;
    LODWORD(v24[1]) = v9;
    v10 = 2 - ((*(_BYTE *)(v6 + 16) & 3u) < 2);
  }
  v28 = 0ui64;
  *(_QWORD *)&v25 = 0x2FFFFFFFFi64;
  LODWORD(v30) = v30 & 0x80000000 | 0x40000002;
  v29 = &v30;
  LODWORD(v24[0]) = v10;
  HIDWORD(v24[1]) = 16;
  if( v7 )
  {
    LODWORD(v28) = 5;
    v11 = *(_DWORD *)(HalpInterruptController + 232);
    HIDWORD(v22) = *(_DWORD *)(v6 + 20);
    LODWORD(v22) = v11;
LABEL_19:
    v12 = HalpInterruptSetLineState(&v22, 0, 15, v9, v10, (__int64)&v28, (__int64)&v25, v21);
    if( v12 < 0 )
      goto LABEL_22;
    goto LABEL_20;
  }
  if( (int)HalpInterruptGsiToLine(*(_DWORD *)(v6 + 20), &v22) < 0 )
  {
    HalpInterruptLastProblem = 18;
    goto LABEL_20;
  }
  if( HalpInterruptPhysicalModeOnly )
  {
    LODWORD(v28) = 3;
  }
  else
  {
    v31 = 0i64;
    v14 = *((unsigned int *)CurrentPrcb + 9);
    LODWORD(v28) = 1;
    v15 = 0i64;
    _bittestandset64(&v15, KiProcessorIndexToNumberMappingTable[v14] & 0x3F);
    *(_QWORD *)&v31 = v15;
    *((_QWORD *)&v28 + 1) = &v31;
  }
  Lines = HalpInterruptFindLines((int *)&v22);
  if( Lines )
  {
    if( !*(_BYTE *)(Lines[6] + 16i64 * v23 + 12) )
    {
      v18 = HalpInterruptLookupController(v22);
      if( !v18 )
      {
        HalpInterruptLastProblem = 17;
        goto LABEL_52;
      }
      v19 = HalpInterruptDestinationToTarget(v17, (__int64)&v28, (__int64)&v25 + 8);
      if( v19 < 0 )
      {
        *((_DWORD *)v18 + 74) = v19;
        HalpInterruptLastProblem = 19;
        v18[38] = (ULONG_PTR)"minkernel\\hals\\lib\\interrupts\\common\\intrupt.c";
        *((_DWORD *)v18 + 73) = 19;
        *((_DWORD *)v18 + 78) = 1546;
        goto LABEL_52;
      }
      if( (*(_DWORD *)(HalpInterruptController + 220) & 0x100) != 0 && *((_BYTE *)KeGetCurrentPrcb() + 141) != 1 )
      {
        HalpIommuUpdateRemappingTableEntry(0, v30 & 0x3FFFFFFF, (INT64)v24);
        DWORD2(v25) = 7;
        LODWORD(v26) = v30 & 0x3FFFFFFF;
      }
      if( qword_140C4A168 )
      {
        v12 = HalpHvMapDeviceInterrupt(*((_DWORD *)v18 + 58), v20, (INT64)v24, 0i64);
        if( v12 < 0 )
        {
          *((_DWORD *)v18 + 74) = v12;
          HalpInterruptLastProblem = 31;
          *((_DWORD *)v18 + 73) = 31;
          v18[38] = (ULONG_PTR)"minkernel\\hals\\lib\\interrupts\\common\\intrupt.c";
          *((_DWORD *)v18 + 78) = 1597;
          goto LABEL_22;
        }
      }
      HIDWORD(v24[1]) &= ~0x10u;
      v12 = HalpInterruptSetRemappedLineStateInternal((__int64)v18, (int *)&v22, (__int64)v24);
      if( v12 < 0 )
        goto LABEL_22;
      v9 = v24[1];
      v10 = v24[0];
    }
    goto LABEL_19;
  }
  HalpInterruptLastProblem = 18;
LABEL_52:
  v12 = -1073741275;
LABEL_22:
  KxReleaseSpinLock(&HalpInterruptLock);
  __writecr8(v4);
  return(unsigned int)v12;
}

Referenced by:

HalpDpPostReplaceInitialization
HalpPostSleepMP