HalInitializeBios

VOID __fastcall HalInitializeBios(INT64 a1, INT64 a2){
  int v2; 
  char *v3; 
  char *v5; 
  struct _MDL *PoolWithTag; 
  struct _MDL *v7; 
  __int64 *v8; 
  unsigned int v9; 
  __int64 v10; 
  __int64 v11; 
  __int64 ***v12; 
  __int64 **i; 
  unsigned __int64 v14; 
  __int64 v15; 
  void *v16; 
  void *v17; 
  __int64 v18; 
  INT64 v19; 
  UINT8 *v20; 
  UINT8 *v21; 
  INT64 *v22; 
  unsigned __int64 v23; 
  __int64 v24; 
  unsigned int v25; 
  unsigned __int64 v26; 
  INT64 *v27; 
  v2 = a1;
  v3 = *(char **)(a2 + 216);
  if( !v3 || (v5 = strupr(v3), !strstr(v5, "NOVGA")) )
  {
    if( v2 != -1 )
    {
      PoolWithTag = (struct _MDL *)ExAllocatePoolWithTag(NonPagedPoolNx, 0x830ui64, 0x206C6148ui64);
      v7 = PoolWithTag;
      if( !PoolWithTag )
        return;
      PoolWithTag->Next = 0i64;
      v8 = (__int64 *)&PoolWithTag[1];
      PoolWithTag->StartVa = 0i64;
      v9 = 0;
      PoolWithTag->ByteOffset = 0;
      PoolWithTag->Size = 2096;
      v10 = 0i64;
      PoolWithTag->ByteCount = 0x100000;
      PoolWithTag->MdlFlags = 2050;
      do
      {
        v11 = v10;
        if( v9 - 160 <= 0x1F )
          v11 = 240i64;
        ++v9;
        ++v10;
        *v8++ = v11;
      }
      while( v9 < 0x100 );
      v12 = (__int64 ***)(a2 + 32);
      for( i = *v12; i != (__int64 **)v12; i = (__int64 **)*i )
      {
        v14 = (unsigned __int64)i[3];
        if( v14 < 0x100 )
        {
          v23 = *((int *)i + 4);
          if( (unsigned int)v23 > 0x23 || (v24 = 0xBC0400040i64, !_bittest64(&v24, v23)) )
          {
            v25 = (unsigned int)i[3];
            v26 = (unsigned __int64)i[4] + v14 - 1;
            v14 = (unsigned int)v14;
            if( v26 > 0xFF )
              v26 = 255i64;
            if( (unsigned int)v14 <= v26 )
            {
              do
              {
                ++v25;
                *((_QWORD *)&v7[1].Next + v14) = 240i64;
                v14 = v25;
              }
              while( v25 <= v26 );
            }
          }
        }
      }
      HalpIoMemoryBase = MmMapLockedPagesSpecifyCache(v7, 0, MmCached, 0i64, 0, 0x40000020u);
      if( !HalpIoMemoryBase )
        goto LABEL_17;
      MmMapIoSpaceEx((_LARGE_INTEGER)655360i64, 0x20000ui64, 0x204ui64);
      v17 = v16;
      if( v16 )
      {
        v18 = HalpMmAllocCtxAlloc(v15, 0x2000i64);
        if( v18 )
        {
          HalpFrameBufferBase = (__int64)v17 - 655360;
          x86BiosInitializeBiosEx(v19, (INT64)HalpIoMemoryBase, (INT64)v17 - 655360, v18);
          MmMapIoSpaceEx(0i64, 0x800ui64, 4ui64);
          v21 = v20;
          if( v20 )
          {
            v22 = x86BiosTranslateAddress(0, 0);
            memmove((UINT8 *)v22, v21, 0x800ui64);
            MmUnmapIoSpace(v21, 0x800ui64);
            HalpVideoBiosPresent = 1;
            qword_140C005E8 = (__int64)HalpBiosDisplayReset;
LABEL_17:
            ExFreePoolWithTag(v7, 0);
            return;
          }
        }
        MmUnmapIoSpace(v17, 0x20000ui64);
        HalpFrameBufferBase = 0i64;
      }
      if( HalpIoMemoryBase )
      {
        MmUnmapLockedPages(HalpIoMemoryBase, v7);
        HalpIoMemoryBase = 0i64;
      }
      goto LABEL_17;
    }
    if( (*(_BYTE *)(*(_QWORD *)(a2 + 240) + 2624i64) & 4) == 0 )
    {
      HalpIoMemoryBase = 0i64;
      HalpFrameBufferBase = 0i64;
      qword_140C005E8 = (__int64)HalpBiosDisplayReset;
      HalpVideoBiosPresent = 1;
      x86BiosInitializeBiosEx((INT64)v3, 0i64, 0i64, 0x20000i64);
      v27 = x86BiosTranslateAddress(0, 0);
      memmove((UINT8 *)v27, 0i64, 0x800ui64);
    }
  }
}

Referenced by:

InitBootProcessor
KiInitializeBootStructures