HalpWdatDiscover

INT64 __fastcall HalpWdatDiscover(){
  LARGE_INTEGER *AcpiTable; 
  LARGE_INTEGER *v1; 
  WATCHDOG_TIMER_RESOURCE_TABLE *Wdrt; 
  int v4; 
  UINT64 v5; 
  INT64 v6; 
  char v7; 
  __int64 v8; 
  UINT64 v9; 
  INT64 v10; 
  unsigned __int64 v11; 
  bool v12; 
  TIMER_INITIALIZATION_BLOCK result; 
  INT64 v14[2]; 
  unsigned int v15; 
  unsigned int v16; 
  unsigned int v17; 
  char a4; 
  ULONG a3; 
  UINT64 OutputValue; 
  LODWORD(OutputValue) = 0;
  a3 = 0;
  memset((INT64)&result, 0i64);
  memset((INT64)v14, 0i64);
  result.Header = (SOC_INITIALIZATION_HEADER)0x9000000001i64;
  a4 = 0;
  AcpiTable = HalSocGetAcpiTable(0x54414457ui64);
  v1 = HalSocGetAcpiTable(0x54524457ui64);
  Wdrt = (WATCHDOG_TIMER_RESOURCE_TABLE *)v1;
  if( AcpiTable )
  {
    v4 = HalpWdatProcessWdatInternalData((INT64)AcpiTable, v14, &a3, &a4);
  }
  else
  {
    if( !v1 )
      return 0i64;
    v14[1] = (INT64)v1;
    v4 = HalpWdatProcessWdrtInternalData((__int64)v1, v14, &a3, &a4);
  }
  v7 = a4;
  if( v4 >= 0 )
  {
    if( !a4 )
      return 0i64;
    if( v17 )
    {
      v8 = v15;
      if( v15 >= v16 )
      {
        result.Capabilities = 163872;
        LOBYTE(v6) = 32;
        if( HalpWdatExecuteActionBeforeInitialize(v6, v5, &OutputValue, (WATCHDOG_TIMER_ACTION_TABLE *)AcpiTable, Wdrt) >= 0
          && (_DWORD)OutputValue == 1 )
        {
          result.Capabilities = 426016;
          LOBYTE(v10) = 33;
          HalpWdatExecuteActionBeforeInitialize(v10, v9, 0i64, (WATCHDOG_TIMER_ACTION_TABLE *)AcpiTable, Wdrt);
        }
        v11 = (unsigned __int64)v17 * v8 / 0x3E8;
        if( v11 <= 0x12C436C73CE5i64 )
        {
          v5 = 894000 * v11;
          v6 = 63i64;
          result.CounterBitWidth = 63;
          do
          {
            if( (1i64 << v6) - 1 < v5 )
              break;
            v12 = (_DWORD)v6 == 1;
            v6 = (unsigned int)(v6 - 1);
          }
          while( !v12 );
          result.CounterBitWidth = v6;
          if( !(_DWORD)v6 )
            goto LABEL_20;
        }
        else
        {
          result.CounterBitWidth = 64;
        }
        result.FunctionTable.AcknowledgeInterrupt = 0i64;
        result.InternalData = 0i64;
        result.Identifier = 0;
        result.FunctionTable.Initialize = HalpWdatInitialize;
        result.FunctionTable.ArmTimer = (PTIMER_ARM_TIMER)HalpWdatArmTimer;
        result.FunctionTable.Stop = (PTIMER_STOP)HalpWdatStop;
        result.InternalDataSize = a3;
        result.CounterFrequency = 894000i64;
        result.KnownType = TimerWDAT;
        HalpTimerRegister(&result, 0i64);
      }
    }
  }
LABEL_20:
  if( v7 )
  {
    LOBYTE(v6) = 11;
    HalpWdatExecuteActionBeforeInitialize(v6, v5, 0i64, (WATCHDOG_TIMER_ACTION_TABLE *)AcpiTable, Wdrt);
  }
  return 0i64;
}

Referenced by:

HalpTimerRegisterBuiltinPluginsCommon