KiInitializeMTRR
VOID __stdcall KiInitializeMTRR(UINT8 LastProcessor){
UINT8 v1;
char v2;
unsigned __int64 v3;
unsigned __int64 v4;
unsigned int v5;
__int64 v6;
unsigned int v7;
unsigned __int64 v8;
unsigned __int64 v9;
__int64 v10;
unsigned __int64 v11;
__int64 v12;
struct _KPRCB *CurrentPrcb;
VOID **PoolWithTag;
size_t v15;
VOID **v16;
v1 = LastProcessor;
v2 = 1;
if( !KeGetPcr()->Prcb.Number )
{
qword_140C2B128 = __readmsr(0xFEu);
KiMtrrInfo = __readmsr(0x2FFu);
CurrentPrcb = KeGetCurrentPrcb();
byte_140C2B131 = 0;
if( CurrentPrcb->CpuVendor == 1 && (__readmsr(0xC0010010) & 0x40000) != 0 )
byte_140C2B131 = 1;
if( (((_BYTE)qword_140C2B128 != 0) & _bittest64(&KiMtrrInfo, 0xBu)) != 0 )
{
if( ((unsigned __int8)KeFeatureBits & 0x40) == 0 && (qword_140C2B128 & 0x400) != 0 )
qword_140C2B128 &= ~0x400ui64;
PoolWithTag = (VOID **)qword_140C2B138;
v15 = 16 * (unsigned __int8)qword_140C2B128;
if( qword_140C2B138
|| (PoolWithTag = ExAllocatePoolWithTag(0x200ui64, v15, 538993995i64), (qword_140C2B138 = PoolWithTag) != 0i64) )
{
memset(PoolWithTag, 0i64, v15);
}
v16 = (VOID **)qword_140C2B140;
if( qword_140C2B140
|| (qword_140C2B128 & 0x100) != 0
&& (v16 = ExAllocatePoolWithTag(0x200ui64, 0x58ui64, 538993995i64), (qword_140C2B140 = v16) != 0i64) )
{
memset(v16, 0i64, 0x58u);
}
}
else
{
if( ((unsigned __int8)KeFeatureBits & 0x40) != 0
&& (qword_140C2B128 & 0x1FF) != 0
&& (KiMtrrInfo & 0x800) == 0
&& (CurrentPrcb->CpuVendor != 1 || (_BYTE)KiMtrrInfo != 6)
&& (_BYTE)KdDebuggerEnabled )
{
DbgPrintEx(0x65u, 0, "Caching is disabled by incorrect MTRR settings.\n");
__debugbreak();
}
v2 = 0;
}
}
if( qword_140C2B138 && (qword_140C2B140 || (qword_140C2B128 & 0x100) == 0) )
{
v3 = __readmsr(0xFEu);
if( ((unsigned __int8)KeFeatureBits & 0x40) == 0 && (v3 & 0x400) != 0 )
v3 &= ~0x400ui64;
if( v3 != qword_140C2B128 )
KeBugCheckEx(0x3Eu, (PVOID)0x40, 0i64, 0i64, 0i64);
if( __readmsr(0x2FFu) != KiMtrrInfo )
DbgPrintEx(0x65u, 0, "KiInitializeMTRR: MTRR_MSR_DEFAULT is not consistent between processors.\n");
}
else
{
v2 = 0;
LOBYTE(v3) = 0;
}
if( !v2 )
goto LABEL_51;
if( !KeGetPcr()->Prcb.Number )
{
if( qword_140C2B140 )
KiReadFixedMtrr((UINT64 *)qword_140C2B140);
v4 = (unsigned __int8)v3;
v5 = 0;
if( (_BYTE)v3 )
{
v6 = 0i64;
v7 = 513;
do
{
v8 = __readmsr(v7 - 1);
v9 = __readmsr(v7);
v11 = v9;
if( (v9 & 0x800) != 0 )
{
v10 = v9 & KiMtrrMaskMask;
if( ((v10 + KiMaskToLength(v9 & KiMtrrMaskMask)) & ~(1i64 << KiMtrrMaxRangeShift)) != 0 )
{
DbgPrintEx(0x65u, 0, "KiInitializeMTRR: Found non-contiguous MTRR mask!\n");
v2 = 0;
}
v12 = 2 * v6;
*((_QWORD *)qword_140C2B138 + v12) = v8;
*((_QWORD *)qword_140C2B138 + v12 + 1) = v11;
}
++v5;
v7 += 2;
v6 = v5;
}
while( v5 < v4 );
v1 = LastProcessor;
}
}
if( v2 )
{
if( v1 )
{
byte_140C2B130 = 1;
if( KeGetCurrentIrql() < 2u )
{
MmLockPagableSectionByHandle(ExPageLockHandle);
KeRestoreMtrrBroadcast();
MiLockPagableImageSection(ExPageLockHandle, 0);
}
}
}
else
{
LABEL_51:
if( qword_140C2B138 )
{
ExFreePoolWithTag(qword_140C2B138, 0);
qword_140C2B138 = 0i64;
}
if( qword_140C2B140 )
{
ExFreePoolWithTag(qword_140C2B140, 0);
qword_140C2B140 = 0i64;
}
}
}Referenced by:
KiInitMachineDependent