HalpInterruptParseMadt
NTSTATUS __stdcall HalpInterruptParseMadt(_MAPIC *MadtTable, UINT64 Phase, INT64 a3, UINT8 a4){
unsigned int v5;
unsigned int v6;
int v7;
unsigned int *APICTables;
char *v9;
char *v10;
unsigned int *v11;
__int64 v12;
char *v13;
unsigned int *v14;
char v15;
bool v16;
unsigned int v17;
char *v18;
__int64 v19;
unsigned int *v20;
__int64 v21;
__int64 v22;
__int64 v23;
unsigned int *v24;
unsigned int v25;
_DWORD *v26;
__int64 v27;
__int64 v29;
unsigned int *v30;
char v31;
_DWORD *v32;
unsigned int v33;
unsigned int v34;
_DWORD *v35;
unsigned int v36;
int v37;
unsigned int v38;
int v39;
unsigned int v40;
_DWORD *v41;
unsigned int v42;
char *v43;
__int64 v44;
char *v45;
unsigned __int64 v46;
__int128 v47;
__int128 v48;
__int128 v49;
__int128 v50;
char *v51;
__int64 v52;
char *v53;
unsigned int v54;
PSTR v55;
PSTR v56;
unsigned int v57;
int v58;
int v59;
PSTR *v60;
__int64 v61;
__int64 v62;
PSTR v63;
int v64;
char v65;
int v66;
unsigned int v67;
char *v68;
_LARGE_INTEGER v69;
int v70;
unsigned int v71;
PSTR MemoryInternal;
_OWORD *v73;
unsigned __int64 v74;
__int128 v75;
__int128 v76;
__int128 v77;
__int128 v78;
char *v79;
__int64 v80;
char *v81;
unsigned __int64 v82;
__int128 v83;
__int128 v84;
__int128 v85;
__int128 v86;
_INTERRUPT_LINE Line;
NTSTATUS v88;
Line = 0i64;
v5 = 0;
v6 = 0;
v88 = 0;
v7 = 0;
APICTables = MadtTable->APICTables;
v9 = (char *)MadtTable + MadtTable->Header.Length;
v10 = (char *)MadtTable->APICTables + 2;
v11 = MadtTable->APICTables;
if( (_DWORD)Phase )
{
if( v10 > v9 )
{
LABEL_39:
if( (unsigned int)qword_140C50640 > 1 )
{
v34 = 0;
if( (_DWORD)qword_140C50640 )
{
v35 = (char *)HalpInterruptProcessorState + 8;
while( *v35 != *(&CmpDummyThreadEvent + 1766) )
{
++v34;
v35 += 16;
if( v34 >= (unsigned int)qword_140C50640 )
goto LABEL_44;
}
v5 = v34;
}
LABEL_44:
v36 = ~(KeGetCurrentPrcb()->LogicalProcessorsPerCore - 1);
v37 = v36 & *(&CmpDummyThreadEvent + 1766);
v38 = ~(KeGetCurrentPrcb()->LogicalProcessorsPerCore * KeGetCurrentPrcb()->CoresPerPhysicalProcessor - 1);
v39 = v38 & *(&CmpDummyThreadEvent + 1766);
if( v5 )
{
v73 = HalpInterruptProcessorState;
v74 = (unsigned __int64)v5 << 6;
v75 = *(_OWORD *)HalpInterruptProcessorState;
v76 = *((_OWORD *)HalpInterruptProcessorState + 1);
v77 = *((_OWORD *)HalpInterruptProcessorState + 2);
v78 = *((_OWORD *)HalpInterruptProcessorState + 3);
*(_OWORD *)HalpInterruptProcessorState = *(_OWORD *)((char *)HalpInterruptProcessorState + v74);
v73[1] = *(_OWORD *)((char *)v73 + v74 + 16);
v73[2] = *(_OWORD *)((char *)v73 + v74 + 32);
v73[3] = *(_OWORD *)((char *)v73 + v74 + 48);
*(_OWORD *)((char *)v73 + v74) = v75;
*(_OWORD *)((char *)v73 + v74 + 16) = v76;
*(_OWORD *)((char *)v73 + v74 + 32) = v77;
*(_OWORD *)((char *)v73 + v74 + 48) = v78;
}
v40 = 1;
if( (unsigned int)qword_140C50640 > 1 )
{
v41 = (char *)HalpInterruptProcessorState + 72;
do
{
if( (v36 & *v41) != v37 )
break;
++v40;
v41 += 16;
}
while( v40 < (unsigned int)qword_140C50640 );
}
v42 = v40 + 1;
if( v40 + 1 < (unsigned int)qword_140C50640 )
{
v43 = (char *)HalpInterruptProcessorState + 64 * (unsigned __int64)v42;
v44 = (unsigned int)qword_140C50640 - v42;
do
{
if( (v36 & *((_DWORD *)v43 + 2)) == v37 )
{
v45 = (char *)HalpInterruptProcessorState;
v46 = (unsigned __int64)v40++ << 6;
v47 = *(_OWORD *)((char *)HalpInterruptProcessorState + v46);
v48 = *(_OWORD *)((char *)HalpInterruptProcessorState + v46 + 16);
v49 = *(_OWORD *)((char *)HalpInterruptProcessorState + v46 + 32);
v50 = *(_OWORD *)((char *)HalpInterruptProcessorState + v46 + 48);
*(_OWORD *)((char *)HalpInterruptProcessorState + v46) = *(_OWORD *)v43;
*(_OWORD *)&v45[v46 + 16] = *((_OWORD *)v43 + 1);
*(_OWORD *)&v45[v46 + 32] = *((_OWORD *)v43 + 2);
*(_OWORD *)&v45[v46 + 48] = *((_OWORD *)v43 + 3);
*(_OWORD *)v43 = v47;
*((_OWORD *)v43 + 1) = v48;
*((_OWORD *)v43 + 2) = v49;
*((_OWORD *)v43 + 3) = v50;
}
v43 += 64;
--v44;
}
while( v44 );
}
if( v40 > 1 )
*(&CmpDummyThreadEvent + 7136) = 1;
v51 = (char *)HalpInterruptProcessorState;
HalpInterruptSortProcessorTable((INT64)HalpInterruptProcessorState + 64, v40 - 1);
v52 = v40;
if( v40 < (unsigned int)qword_140C50640 )
{
v53 = &v51[64 * (unsigned __int64)v40 + 8];
do
{
if( (v38 & *(_DWORD *)v53) != v39 )
break;
++v40;
v53 += 64;
}
while( v40 < (unsigned int)qword_140C50640 );
}
v54 = v40 + 1;
if( v40 + 1 < (unsigned int)qword_140C50640 )
{
v79 = (char *)HalpInterruptProcessorState + 64 * (unsigned __int64)v54;
v80 = (unsigned int)qword_140C50640 - v54;
do
{
if( (v38 & *((_DWORD *)v79 + 2)) == v39 )
{
v81 = (char *)HalpInterruptProcessorState;
v82 = (unsigned __int64)v40++ << 6;
v83 = *(_OWORD *)((char *)HalpInterruptProcessorState + v82);
v84 = *(_OWORD *)((char *)HalpInterruptProcessorState + v82 + 16);
v85 = *(_OWORD *)((char *)HalpInterruptProcessorState + v82 + 32);
v86 = *(_OWORD *)((char *)HalpInterruptProcessorState + v82 + 48);
*(_OWORD *)((char *)HalpInterruptProcessorState + v82) = *(_OWORD *)v79;
*(_OWORD *)&v81[v82 + 16] = *((_OWORD *)v79 + 1);
*(_OWORD *)&v81[v82 + 32] = *((_OWORD *)v79 + 2);
*(_OWORD *)&v81[v82 + 48] = *((_OWORD *)v79 + 3);
*(_OWORD *)v79 = v83;
*((_OWORD *)v79 + 1) = v84;
*((_OWORD *)v79 + 2) = v85;
*((_OWORD *)v79 + 3) = v86;
}
v79 += 64;
--v80;
}
while( v80 );
}
HalpInterruptSortProcessorTable((INT64)HalpInterruptProcessorState + 64 * v52, v40 - (unsigned int)v52);
HalpInterruptSortProcessorTable(
(INT64)HalpInterruptProcessorState + 64 * (unsigned __int64)v40,
(unsigned int)qword_140C50640 - v40);
if( *(&CmpDummyThreadEvent + 7093) && *(&CmpDummyThreadEvent + 7136) )
HalpInterruptBlockSmtSiblings();
}
return v88;
}
while( 1 )
{
v29 = *((unsigned __int8 *)v11 + 1);
if( (unsigned __int8)v29 < 2u || (char *)v11 + v29 > v9 )
goto LABEL_39;
v30 = v11;
v11 = (unsigned int *)((char *)v11 + v29);
v31 = *(_BYTE *)v30;
if( *(_BYTE *)v30 || (_BYTE)v29 != 8 )
{
if( v31 == 9 && (_BYTE)v29 == 16 )
{
v32 = (char *)HalpInterruptProcessorState + 64 * (unsigned __int64)v6;
if( (v30[2] & 1) == 0 )
goto LABEL_38;
*v32 = v30[1];
v32[1] = v30[3];
v33 = v30[1];
goto LABEL_37;
}
if( v31 == 11
&& (unsigned __int8)v29 >= 0x28u
&& ((unsigned int)HalpInterruptGicVersion < 3 || (unsigned __int8)v29 >= 0x4Cu) )
{
v68 = (char *)HalpInterruptProcessorState + 64 * (unsigned __int64)v6;
if( (v30[3] & 1) != 0 )
{
v69 = *(_LARGE_INTEGER *)(v30 + 6);
if( v30[4] == 1 && v69.QuadPart )
v70 = HalpInterruptMapParkedPage(
v69,
(_LARGE_INTEGER *)HalpInterruptProcessorState + 8 * (unsigned __int64)v6);
else
v70 = -1073741811;
v88 = v70;
if( v70 == -1073741670 )
return -1073741670;
if( v70 >= 0 )
{
if( (unsigned int)HalpInterruptGicVersion < 3 )
v71 = v30[1];
else
v71 = (*(_QWORD *)(v30 + 17) >> 8) & 0xFF000000 | v30[17] & 0xFFFFFF;
*(_DWORD *)v68 = v71;
*((_DWORD *)v68 + 1) = v30[2];
*((_DWORD *)v68 + 2) = v30[1];
*((_DWORD *)v68 + 10) = v30[5];
if( *((_BYTE *)v30 + 1) < 0x4Cu )
{
*((_QWORD *)v68 + 6) = 0i64;
v68[45] = 0;
}
else
{
*((_QWORD *)v68 + 6) = *(_QWORD *)(v30 + 17);
v68[45] = 1;
if( *((_BYTE *)v30 + 1) >= 0x4Du )
v68[44] = *((_BYTE *)v30 + 76);
}
if( (v30[3] & 2) != 0 )
v68[14] = 1;
++v6;
}
}
}
else
{
if( v31 == 3 && (_BYTE)v29 == 8 )
{
MemoryInternal = HalpMmAllocateMemoryInternal(0x18ui64, MmCached);
v63 = MemoryInternal;
if( !MemoryInternal )
return -1073741670;
MemoryInternal[8] = 0;
*((_DWORD *)MemoryInternal + 4) = *((unsigned __int16 *)v30 + 1);
v66 = v30[1];
goto LABEL_90;
}
if( v31 == 4 && (_BYTE)v29 == 6 || v31 == 10 && (_BYTE)v29 == 12 )
{
v63 = HalpMmAllocateMemoryInternal(0x18ui64, MmCached);
if( !v63 )
return -1073741670;
*(_OWORD *)v63 = 0i64;
*((_QWORD *)v63 + 2) = 0i64;
v63[8] = 1;
if( *(_BYTE *)v30 == 4 )
{
v64 = *((unsigned __int8 *)v30 + 2);
*((_DWORD *)v63 + 3) = v64;
if( *((_BYTE *)v30 + 2) == 0xFF )
v64 = -1;
*((_DWORD *)v63 + 3) = v64;
*((_DWORD *)v63 + 4) = *(unsigned __int16 *)((char *)v30 + 3);
v65 = *((_BYTE *)v30 + 5);
}
else
{
*((_DWORD *)v63 + 3) = v30[1];
*((_DWORD *)v63 + 4) = *((unsigned __int16 *)v30 + 1);
v65 = *((_BYTE *)v30 + 8);
}
v66 = -(v65 != 0) - 4;
LABEL_90:
*((_DWORD *)v63 + 5) = v66;
*(_QWORD *)v63 = *(&CmpDummyThreadEvent + 893);
*(&CmpDummyThreadEvent + 893) = v63;
goto LABEL_38;
}
if( v31 == 2 && (_BYTE)v29 == 10 )
{
if( HalpInterruptGsiToLine(v30[1], &Line) >= 0 )
{
v55 = HalpMmAllocateMemoryInternal(0x28ui64, MmCached);
v56 = v55;
if( !v55 )
return -1073741670;
*(_OWORD *)v55 = 0i64;
*((_OWORD *)v55 + 1) = 0i64;
*((_QWORD *)v55 + 4) = 0i64;
v57 = *((unsigned __int8 *)v30 + 3);
if( v57 < 8 )
{
v58 = 45056;
}
else
{
v57 -= 8;
v58 = 45057;
}
*((_DWORD *)v56 + 4) = v58;
*((_DWORD *)v56 + 5) = v57;
*((_INTERRUPT_LINE *)v56 + 3) = Line;
v59 = 2;
if( (v30[2] & 3) < 2 )
v59 = 1;
*((_DWORD *)v56 + 9) = v59;
*((_DWORD *)v56 + 8) = (v30[2] & 8) == 0;
v60 = (PSTR *)*(&CmpDummyThreadEvent + 889);
if( (_UNKNOWN *)**(&CmpDummyThreadEvent + 889) != (_UNKNOWN *)((char *)&CmpDummyThreadEvent + 7104) )
__fastfail(3u);
*(_QWORD *)v56 = (char *)&CmpDummyThreadEvent + 7104;
*((_QWORD *)v56 + 1) = v60;
*v60 = v56;
*(&CmpDummyThreadEvent + 889) = v56;
}
v88 = 0;
}
}
}
else
{
v32 = (char *)HalpInterruptProcessorState + 64 * (unsigned __int64)v6;
if( (v30[1] & 1) != 0 )
{
*v32 = *((unsigned __int8 *)v30 + 3);
v32[1] = *((unsigned __int8 *)v30 + 2);
v33 = *((unsigned __int8 *)v30 + 3);
LABEL_37:
v32[2] = v33;
++v6;
}
}
LABEL_38:
if( (char *)v11 + 2 > v9 )
goto LABEL_39;
}
}
if( v10 <= v9 )
{
while( 1 )
{
v12 = *((unsigned __int8 *)v11 + 1);
if( (unsigned __int8)v12 < 2u )
goto LABEL_13;
v13 = (char *)v11 + v12;
if( (char *)v11 + v12 > v9 )
goto LABEL_13;
v14 = v11;
v11 = (unsigned int *)((char *)v11 + v12);
v15 = *(_BYTE *)v14;
if( !*(_BYTE *)v14 && (_BYTE)v12 == 8 )
break;
if( v15 == 9 && (_BYTE)v12 == 16 )
{
v16 = (v14[2] & 1) == 0;
goto LABEL_8;
}
if( v15 == 1 && (_BYTE)v12 == 12 )
{
++*(&CmpDummyThreadEvent + 1771);
}
else if( v15 == 11 && (unsigned __int8)v12 >= 0x28u )
{
v16 = (v14[3] & 1) == 0;
goto LABEL_8;
}
LABEL_12:
if( v13 + 2 > v9 )
goto LABEL_13;
}
v16 = (v14[1] & 1) == 0;
LABEL_8:
if( !v16 )
LODWORD(qword_140C50640) = (_DWORD)qword_140C50640 + 1;
if( (unsigned int)++v7 > HIDWORD(qword_140C50640) )
HIDWORD(qword_140C50640) = v7;
goto LABEL_12;
}
LABEL_13:
*(&CmpDummyThreadEvent + 884) = HalpMmAllocateMemoryInternal(
(unsigned int)(16 * *(&CmpDummyThreadEvent + 1771)),
MmCached);
if( *(&CmpDummyThreadEvent + 884) )
{
v17 = 0;
v18 = (char *)MadtTable + MadtTable->Header.Length;
if( v10 <= v18 )
{
do
{
v19 = *((unsigned __int8 *)APICTables + 1);
if( (unsigned __int8)v19 < 2u || (char *)APICTables + v19 > v18 )
break;
v20 = APICTables;
APICTables = (unsigned int *)((char *)APICTables + v19);
if( *(_BYTE *)v20 == 1 && (_BYTE)v19 == 12 )
{
v61 = *(&CmpDummyThreadEvent + 884);
v62 = 2i64 * v17++;
*(_DWORD *)(*(&CmpDummyThreadEvent + 884) + 8 * v62) = *((unsigned __int8 *)v20 + 2);
*(_DWORD *)(v61 + 8 * v62 + 4) = v20[1];
*(_DWORD *)(v61 + 8 * v62 + 8) = v20[2];
}
}
while( (char *)APICTables + 2 <= v18 );
}
if( *(&CmpDummyThreadEvent + 1771) )
{
v21 = *(&CmpDummyThreadEvent + 1771);
v22 = *(&CmpDummyThreadEvent + 1771);
v23 = *(&CmpDummyThreadEvent + 884) + 8i64;
v24 = (unsigned int *)(*(&CmpDummyThreadEvent + 884) + 12i64);
do
{
v25 = *(v24 - 1);
v26 = (_DWORD *)v23;
*v24 = -1;
v27 = v21;
do
{
if( *v26 > v25 )
{
v67 = *v26 - v25;
if( v67 < *v24 )
*v24 = v67;
}
v26 += 4;
--v27;
}
while( v27 );
v24 += 4;
--v22;
}
while( v22 );
}
return v88;
}
*(&CmpDummyThreadEvent + 1789) = 30;
return -1073741801;
}Referenced by:
HalpInterruptParseAcpiTables