Skip to content

Commit bdc1c71

Browse files
noonefuzyll
authored andcommitted
Add IL, intrinsics for TLB-related instructions
1 parent 0bf72f9 commit bdc1c71

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

arch/mips/arch_mips.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,12 @@ class MipsArchitecture: public Architecture
973973
return "_setLeftPart64";
974974
case MIPS_INTRIN_SET_RIGHT_PART64:
975975
return "_setRightPart64";
976+
case MIPS_INTRIN_TLBSET:
977+
return "_writeTLB";
978+
case MIPS_INTRIN_TLBGET:
979+
return "_readTLB";
980+
case MIPS_INTRIN_TLBSEARCH:
981+
return "_probeTLB";
976982

977983
case CNMIPS_INTRIN_SYNCIOBDMA:
978984
return "_synciobdma";
@@ -1034,6 +1040,9 @@ class MipsArchitecture: public Architecture
10341040
MIPS_INTRIN_GET_RIGHT_PART64,
10351041
MIPS_INTRIN_SET_LEFT_PART64,
10361042
MIPS_INTRIN_SET_RIGHT_PART64,
1043+
MIPS_INTRIN_TLBSET,
1044+
MIPS_INTRIN_TLBGET,
1045+
MIPS_INTRIN_TLBSEARCH,
10371046

10381047
CNMIPS_INTRIN_SYNCIOBDMA,
10391048
CNMIPS_INTRIN_SYNCS,
@@ -1173,6 +1182,24 @@ class MipsArchitecture: public Architecture
11731182
return {
11741183
NameAndType("rightpart", Type::IntegerType(8, false))
11751184
};
1185+
case MIPS_INTRIN_TLBSET:
1186+
return {
1187+
// we use the same order as the pseudocode
1188+
// in the documentation
1189+
NameAndType("index", Type::IntegerType(8, false)),
1190+
NameAndType("PageMask", Type::IntegerType(8, false)),
1191+
NameAndType("EntryHi", Type::IntegerType(8, false)),
1192+
NameAndType("EntryLo1", Type::IntegerType(8, false)),
1193+
NameAndType("EntryLo0", Type::IntegerType(8, false))
1194+
};
1195+
case MIPS_INTRIN_TLBGET:
1196+
return {
1197+
NameAndType("index", Type::IntegerType(8, false)),
1198+
};
1199+
case MIPS_INTRIN_TLBSEARCH:
1200+
return {
1201+
NameAndType("match", Type::IntegerType(8, false)),
1202+
};
11761203
default:
11771204
return vector<NameAndType>();
11781205
}
@@ -1216,6 +1243,19 @@ class MipsArchitecture: public Architecture
12161243
case MIPS_INTRIN_SET_LEFT_PART64:
12171244
case MIPS_INTRIN_SET_RIGHT_PART64:
12181245
return {Type::IntegerType(8, false)};
1246+
case MIPS_INTRIN_TLBGET:
1247+
return {
1248+
// we use the same order as the pseudocode
1249+
// in the documentation:
1250+
1251+
// PageMask, EntryHi, EntryLo1, EntryLo0
1252+
Type::IntegerType(8, false),
1253+
Type::IntegerType(8, false),
1254+
Type::IntegerType(8, false),
1255+
Type::IntegerType(8, false),
1256+
};
1257+
case MIPS_INTRIN_TLBSEARCH:
1258+
return { Type::IntegerType(8, false) };
12191259
default:
12201260
return vector<Confidence<Ref<Type>>>();
12211261
}

arch/mips/il.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,37 @@ bool GetLowLevelILForInstruction(Architecture* arch, uint64_t addr, LowLevelILFu
18421842
il.AddInstruction(il.Intrinsic({}, MIPS_INTRIN_CACHE, {il.Const(1, op1.immediate), GetILOperandMemoryAddress(il, op2, addrSize)}));
18431843
break;
18441844

1845+
case MIPS_TLBP:
1846+
il.AddInstruction(il.Intrinsic({RegisterOrFlag::Register(REG_INDEX)}, MIPS_INTRIN_TLBSEARCH, {il.Register(registerSize, REG_ENTRY_HI)}));
1847+
break;
1848+
case MIPS_TLBR:
1849+
il.AddInstruction(il.Intrinsic({
1850+
RegisterOrFlag::Register(REG_PAGE_MASK),
1851+
RegisterOrFlag::Register(REG_ENTRY_HI),
1852+
RegisterOrFlag::Register(REG_ENTRY_LO1),
1853+
RegisterOrFlag::Register(REG_ENTRY_LO0)
1854+
}, MIPS_INTRIN_TLBGET, { il.Register(registerSize, REG_INDEX) }));
1855+
break;
1856+
case MIPS_TLBWI:
1857+
il.AddInstruction(il.Intrinsic({}, MIPS_INTRIN_TLBSET, {
1858+
il.Register(registerSize, REG_INDEX),
1859+
il.Register(registerSize, REG_PAGE_MASK),
1860+
il.Register(registerSize, REG_ENTRY_HI),
1861+
il.Register(registerSize, REG_ENTRY_LO1),
1862+
il.Register(registerSize, REG_ENTRY_LO0)
1863+
}));
1864+
break;
1865+
case MIPS_TLBWR:
1866+
il.AddInstruction(il.Intrinsic({}, MIPS_INTRIN_TLBSET, {
1867+
il.Register(registerSize, REG_RANDOM),
1868+
il.Register(registerSize, REG_PAGE_MASK),
1869+
il.Register(registerSize, REG_ENTRY_HI),
1870+
il.Register(registerSize, REG_ENTRY_LO1),
1871+
il.Register(registerSize, REG_ENTRY_LO0)
1872+
}));
1873+
break;
1874+
1875+
18451876
case CNMIPS_BADDU:
18461877
il.AddInstruction(SetRegisterOrNop(il, 8, registerSize, op1.reg,
18471878
il.ZeroExtend(registerSize,
@@ -2135,10 +2166,6 @@ bool GetLowLevelILForInstruction(Architecture* arch, uint64_t addr, LowLevelILFu
21352166
case MIPS_MTHC1:
21362167
case MIPS_MTHC2:
21372168
case MIPS_PREFX:
2138-
case MIPS_TLBP:
2139-
case MIPS_TLBR:
2140-
case MIPS_TLBWI:
2141-
case MIPS_TLBWR:
21422169
case MIPS_WRPGPR:
21432170
case MIPS_RDPGPR:
21442171
case MIPS_RECIP1:

arch/mips/il.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ enum MipsIntrinsic : uint32_t
6565
MIPS_INTRIN_SET_LEFT_PART64,
6666
MIPS_INTRIN_SET_RIGHT_PART64,
6767

68+
MIPS_INTRIN_TLBSET,
69+
MIPS_INTRIN_TLBGET,
70+
MIPS_INTRIN_TLBSEARCH,
71+
6872
CNMIPS_INTRIN_SYNCIOBDMA,
6973
CNMIPS_INTRIN_SYNCS,
7074
CNMIPS_INTRIN_SYNCW,

0 commit comments

Comments
 (0)