HalpInterruptInitializeLocalUnit

NTSTATUS __stdcall HalpInterruptInitializeLocalUnit(PVOID BugCheckParameter3, DOUBLE XMM1_8){
  __int64 v2; 
  int v4; 
  int v5; 
  PROCESSOR_NUMBER *v6; 
  NTSTATUS v7; 
  __int64 v8; 
  __int64(__fastcall *v9)(_QWORD); 
  int v10; 
  char v12; 
  __int64(__fastcall *v13)(_QWORD, __int128 *); 
  int v14; 
  int v15; 
  unsigned int v16; 
  __int64 v17; 
  __int64 v18; 
  __int64(__fastcall *v19)(_QWORD, UINT64 *, __int128 *, __int64); 
  ULONG_PTR v20; 
  int v21; 
  ULONG_PTR BugCheckParameter4; 
  __int128 v23; 
  __int64 v24; 
  int v25; 
  UINT64 LocalUnitIdentifier; 
  LODWORD(LocalUnitIdentifier) = 0;
  v23 = 0i64;
  v24 = 0i64;
  LODWORD(v2) = *((_DWORD *)KeGetPcr() + 105);
  _disable();
  v4 = v25 & 0x200;
  v5 = (*((__int64(__fastcall **)(_QWORD, _QWORD, __int64))BugCheckParameter3 + 4))(
         *((_QWORD *)BugCheckParameter3 + 2),
         (unsigned int)v2,
         223i64);
  v7 = v5;
  if( v5 < 0 )
  {
    HalpInterruptLastProblem = 4;
    *((_QWORD *)BugCheckParameter3 + 38) = "minkernel\\hals\\lib\\interrupts\\common\\intsup.c";
    *((_DWORD *)BugCheckParameter3 + 73) = 4;
    *((_DWORD *)BugCheckParameter3 + 74) = v5;
    *((_DWORD *)BugCheckParameter3 + 78) = 571;
    goto LABEL_13;
  }
  if( !*((_DWORD *)KeGetPcr() + 105) )
    HalpInterruptP0LocalId = LocalUnitIdentifier;
  HalpInterruptMarkProcessorStarted((unsigned int)LocalUnitIdentifier, v6);
  if( *(_DWORD *)(HalpInterruptTargets + 24 * v2) )
  {
    if( !HalpInterruptPhysicalModeOnly )
    {
      v9 = (__int64(__fastcall *)(_QWORD))*((_QWORD *)BugCheckParameter3 + 10);
      if( v9 )
      {
        v10 = v9(*((_QWORD *)BugCheckParameter3 + 2));
        if( v10 < 0 )
        {
          LODWORD(BugCheckParameter4) = 782;
          HalpInterruptSetProblemEx(
            (_REGISTERED_INTERRUPT_CONTROLLER *)BugCheckParameter3,
            InterruptProblemSetLogicalIdFailed,
            v10,
            "minkernel\\hals\\lib\\interrupts\\common\\intsup.c",
            BugCheckParameter4);
          KeBugCheckEx(0x5Cu, 0x200ui64, HalpInterruptLastProblem, (ULONG_PTR)BugCheckParameter3, v20);
        }
      }
    }
    goto LABEL_8;
  }
  v12 = 0;
  if( HalpInterruptPhysicalModeOnly )
    goto LABEL_34;
  if( !HalpInterruptClusterModeForced
    && !HalpInterruptClusterModeEnabled
    && (!HalpInterruptMaxClusterSize || (unsigned int)HalpInterruptProcessorCount <= HalpInterruptLogicalFlatLimit) )
  {
    LODWORD(v23) = 5;
    DWORD2(v23) = 1 << v2;
    goto LABEL_22;
  }
  if( HalpInterruptNextCluster >= (unsigned int)HalpInterruptMaxCluster
    || (*((_DWORD *)BugCheckParameter3 + 55) & 8) == 0 )
  {
LABEL_34:
    DWORD2(v23) = LocalUnitIdentifier;
    LODWORD(v23) = 4;
    if( HalpInterruptPhysicalModeOnly )
      goto LABEL_35;
  }
  else
  {
    v12 = 1;
    DWORD2(v23) = HalpInterruptNextCluster;
    HIDWORD(v23) = 1 << HalpInterruptNextClusterIndex;
    LODWORD(v23) = 6;
  }
LABEL_22:
  v13 = (__int64(__fastcall *)(_QWORD, __int128 *))*((_QWORD *)BugCheckParameter3 + 10);
  if( v13 )
  {
    v14 = v13(*((_QWORD *)BugCheckParameter3 + 2), &v23);
    v15 = v23;
LABEL_24:
    v16 = DWORD2(v23);
    goto LABEL_25;
  }
  v19 = (__int64(__fastcall *)(_QWORD, UINT64 *, __int128 *, __int64))*((_QWORD *)BugCheckParameter3 + 18);
  if( !v19 )
    goto LABEL_35;
  LOBYTE(v8) = 1;
  v12 = 0;
  v14 = v19(*((_QWORD *)BugCheckParameter3 + 2), &LocalUnitIdentifier, &v23, v8);
  v15 = v23;
  if( (_DWORD)v23 != 6 )
    goto LABEL_24;
  v16 = DWORD2(v23);
  if( DWORD2(v23) >= (unsigned int)HalpInterruptMaxCluster )
  {
    v16 = LocalUnitIdentifier;
    v15 = 4;
    LODWORD(v23) = 4;
    v14 = -1073741823;
    DWORD2(v23) = LocalUnitIdentifier;
  }
LABEL_25:
  if( v14 >= 0 )
  {
    HalpInterruptLogicalMode = 1;
    if( v15 == 6 )
    {
      HalpInterruptClusterModeEnabled = 1;
      if( v16 > HalpInterruptNextCluster )
        HalpInterruptNextCluster = v16;
    }
    if( v12 )
    {
      if( ++HalpInterruptNextClusterIndex >= (unsigned int)HalpInterruptMaxClusterSize )
      {
        HalpInterruptNextClusterIndex = 0;
        ++HalpInterruptNextCluster;
      }
    }
    v17 = HalpInterruptTargets;
    *(_OWORD *)(HalpInterruptTargets + 24 * v2) = v23;
    *(_QWORD *)(v17 + 24 * v2 + 16) = v24;
    if( (_DWORD)v23 != 4 )
      goto LABEL_8;
    goto LABEL_36;
  }
LABEL_35:
  v18 = HalpInterruptTargets;
  *(_DWORD *)(HalpInterruptTargets + 24 * v2) = 4;
  *(_DWORD *)(v18 + 24 * v2 + 8) = LocalUnitIdentifier;
LABEL_36:
  KeAddProcessorAffinityEx(&HalpInterruptPhysicalTargets, v2);
LABEL_8:
  v7 = HalpInitializeCmciVector((__int64)BugCheckParameter3, LocalUnitIdentifier);
  if( v7 < 0 )
  {
    *((_DWORD *)BugCheckParameter3 + 74) = v7;
    HalpInterruptLastProblem = 10;
    *((_DWORD *)BugCheckParameter3 + 73) = 10;
    *((_QWORD *)BugCheckParameter3 + 38) = "minkernel\\hals\\lib\\interrupts\\common\\intsup.c";
    *((_DWORD *)BugCheckParameter3 + 78) = 803;
  }
  else
  {
    v7 = HalpInitializeDeferredErrorVector((__int64)BugCheckParameter3, LocalUnitIdentifier);
    if( v7 < 0 )
    {
      *((_DWORD *)BugCheckParameter3 + 74) = v7;
      HalpInterruptLastProblem = 38;
      *((_DWORD *)BugCheckParameter3 + 73) = 38;
      *((_QWORD *)BugCheckParameter3 + 38) = "minkernel\\hals\\lib\\interrupts\\common\\intsup.c";
      *((_DWORD *)BugCheckParameter3 + 78) = 816;
    }
    else
    {
      if( (*((_DWORD *)BugCheckParameter3 + 55) & 2) != 0 )
        (*((void(__fastcall **)(_QWORD, _QWORD))BugCheckParameter3 + 6))(*((_QWORD *)BugCheckParameter3 + 2), 0i64);
      if( (unsigned int)(*((_DWORD *)BugCheckParameter3 + 54) - 3) <= 1
        && (*((_DWORD *)BugCheckParameter3 + 56) & 1) != 0 )
      {
        v21 = HalpInterruptRestoreController((__int64)BugCheckParameter3, 1);
        v7 = v21;
        if( v21 < 0 )
          KeBugCheckEx(0x5Cu, 0x200ui64, HalpInterruptLastProblem, 4ui64, v21);
      }
    }
  }
LABEL_13:
  if( v4 )
    _enable();
  return v7;
}

Referenced by:

HalpInterruptInitializeController
HalpInterruptReinitializeThisProcessor
HalpInterruptResetThisProcessor