KeInitializeClock

VOID __stdcall KeInitializeClock(UINT64 Phase, _LOADER_PARAMETER_BLOCK *LoaderBlock){
  CHAR v2; 
  unsigned __int8 CurrentIrql; 
  char *LoadOptions; 
  __int64 v5; 
  UINT64 v6; 
  UINT64 Root; 
  BOOL v8; 
  __int64 v9; 
  int v10[8]; 
  _EM_RULE_STATE State; 
  _LARGE_INTEGER PerformanceFrequency; 
  __int64 v13; 
  __int128 v14; 
  UINT64 MaxIncrement[2]; 

  v13 = 0i64;
  PerformanceFrequency.QuadPart = 0i64;
  v14 = 0i64;
  *(_OWORD *)MaxIncrement = 0i64;
  if( (_DWORD)Phase )
  {
    if( (_DWORD)Phase == 1 )
    {
      KeQueryPerformanceCounter(&PerformanceFrequency);
      KiClockStateUpdateTimeout = 5 * PerformanceFrequency.QuadPart;
      (*(&KiProcessorBlock + (unsigned int)KiClockTimerOwner))->ClockOwner = 1;
      CurrentIrql = KeGetCurrentIrql();
      __writecr8(0xDui64);
      KiClockState = ClockStatePeriodic;
      off_140C00888[0]();
      KiSetPendingTick(0);
      off_140C00880[0]();
      LOBYTE(v9) = 1;
      ((void(__fastcall *)(__int64))off_140C00878[0])(v9);
      ((void(__fastcall *)(_QWORD, _QWORD, __int64 *))off_140C00890[0])(0i64, (unsigned int)KeMaximumIncrement, &v13);
      KiSetPendingTick(1u);
      Root = (UINT64)qword_140CEBF00.Root;
      KeTimeIncrement = v13;
      LODWORD(KiLastRequestedTimeIncrement) = KeMaximumIncrement;
      KeNonHrTimeIncrement = v13;
      KePseudoHrTimeIncrement = v13;
      dword_140C313FC = KeMaximumIncrement;
      if( (qword_140CEBF08 & 1) != 0 && qword_140CEBF00.Root )
        Root = (unsigned __int64)&qword_140CEBF00 ^ (unsigned __int64)qword_140CEBF00.Root;
      v8 = 0;
      if( Root )
      {
        while( 1 )
        {
          if( (unsigned int)KeMaximumIncrement < *(_DWORD *)(Root + 28) )
          {
            v6 = *(_QWORD *)Root;
            if( (qword_140CEBF08 & 1) != 0 )
            {
              if( !v6 )
                break;
              v6 ^= Root;
            }
            if( !v6 )
              break;
          }
          else
          {
            v6 = *(_QWORD *)(Root + 8);
            if( (qword_140CEBF08 & 1) != 0 )
            {
              if( !v6 )
              {
LABEL_31:
                v8 = 1;
                break;
              }
              v6 ^= Root;
            }
            if( !v6 )
              goto LABEL_31;
          }
          Root = v6;
        }
      }
      RtlRbInsertNodeEx((UINT64 *)&qword_140CEBF00, Root, v8, (UINT64)&KiDefaultClockIntervalRequest);
      byte_140C313F8 = 1;
      __writecr8(CurrentIrql);
      dword_140C31370 = KeTimeIncrement;
      dword_140C31374 = KeTimeIncrement;
      dword_140C31378 = KiLastRequestedTimeIncrement;
      dword_140C3137C = KiLastRequestedTimeIncrement;
    }
    else
    {
      if( (_DWORD)Phase != 2 )
        KeBugCheckEx(0x33u, (PVOID)1, (PVOID)(unsigned int)Phase, 0i64, 0i64);
      if( (_BYTE)KiDynamicTickDisableReason )
        goto LABEL_35;
      if( !(_BYTE)HvlHypervisorConnected || (HvlpFlags & 2) != 0 )
      {
        State = 1;
        EmClientQueryRuleState(&GUID_EM_CPU_TYPE_INTEL_DTT_DISABLE, &State);
        if( State == 2 )
          KiDynamicTickDisableReason = 3;
      }
      if( (_BYTE)KiDynamicTickDisableReason )
      {
LABEL_35:
        PoTraceDynamicTickDisabled();
        KiForceIdleDisabled = 1;
      }
      _InterlockedOr(v10, 0);
      KiDynamicTickInitialized = 1;
    }
  }
  else
  {
    LoadOptions = LoaderBlock->LoadOptions;
    qword_140C31368 = -1i64;
    qword_140C31388 = -1i64;
    if( LoadOptions )
    {
      strstr((UINT8 *)LoadOptions, (UINT8 *)"DISABLEDYNAMICTICK", v2);
      if( v5 )
        KiDynamicTickDisableReason = 1;
    }
    ((void(__fastcall *)(__int128 *))off_140C00870[0])(&v14);
    if( (v14 & 4) != 0 )
      KiClockTimerPerCpu = 1;
    if( (v14 & 2) != 0 )
      KiClockTimerHighLatency = 1;
    if( (v14 & 1) != 0 )
      BYTE2(Mm64BitPhysicalAddress) = 1;
    if( !(_BYTE)KiDynamicTickDisableReason && (v14 & 8) == 0 )
      KiDynamicTickDisableReason = 2;
    KiSetupTimeIncrement(MaxIncrement[0], LODWORD(MaxIncrement[1]));
  }
}

Referenced by:

InitBootProcessor
Phase1InitializationIoReady