Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3408: Included support of 'al' for IT instructions, generalized support for IT instructions and included the 'nv' condition although it should never occur.

ghidorahrexd47317a9f8ee
diff --git a/Ghidra/Processors/ARM/data/languages/ARM.sinc b/Ghidra/Processors/ARM/data/languages/ARM.sinc
index dd2b35dede..efc48e1055 100644
--- a/Ghidra/Processors/ARM/data/languages/ARM.sinc
+++ b/Ghidra/Processors/ARM/data/languages/ARM.sinc
@@ -248,22 +248,22 @@ CheckInIT_ZN: is TMode=1 { ZR = tmpZR; NG = tmpNG; } # in old
@if defined(VERSION_6T2) || defined(VERSION_7)
# conditionals for instruction following IT Block
-thfcc: "eq" is cond_full=0 { local tmp = (ZR!=0); export tmp; }
-thfcc: "ne" is cond_full=1 { local tmp = (ZR==0); export tmp; }
-thfcc: "cs" is cond_full=2 { local tmp = (CY!=0); export tmp; }
-thfcc: "cc" is cond_full=3 { local tmp = (CY==0); export tmp; }
-thfcc: "mi" is cond_full=4 { local tmp = (NG!=0); export tmp; }
-thfcc: "pl" is cond_full=5 { local tmp = (NG==0); export tmp; }
-thfcc: "vs" is cond_full=6 { local tmp = (OV!=0); export tmp; }
-thfcc: "vc" is cond_full=7 { local tmp = (OV==0); export tmp; }
-thfcc: "hi" is cond_full=8 { local tmp = CY && !ZR; export tmp; }
-thfcc: "ls" is cond_full=9 { local tmp = !CY || ZR; export tmp; }
-thfcc: "ge" is cond_full=10 { local tmp = (NG == OV); export tmp; }
-thfcc: "lt" is cond_full=11 { local tmp = (NG != OV); export tmp; }
-thfcc: "gt" is cond_full=12 { local tmp = !ZR && (NG == OV); export tmp; }
-thfcc: "le" is cond_full=13 { local tmp = ZR || (NG != OV); export tmp; }
-# thfcc: "AL" is cond_full=14 { local tmp = 1; export tmp; }
-# thfcc: "NV" is cond_full=15 { local tmp = 0; export tmp; }
+thfcc: "eq" is cond_full=0 { local tmp:1 = (ZR!=0); export tmp; }
+thfcc: "ne" is cond_full=1 { local tmp:1 = (ZR==0); export tmp; }
+thfcc: "cs" is cond_full=2 { local tmp:1 = (CY!=0); export tmp; }
+thfcc: "cc" is cond_full=3 { local tmp:1 = (CY==0); export tmp; }
+thfcc: "mi" is cond_full=4 { local tmp:1 = (NG!=0); export tmp; }
+thfcc: "pl" is cond_full=5 { local tmp:1 = (NG==0); export tmp; }
+thfcc: "vs" is cond_full=6 { local tmp:1 = (OV!=0); export tmp; }
+thfcc: "vc" is cond_full=7 { local tmp:1 = (OV==0); export tmp; }
+thfcc: "hi" is cond_full=8 { local tmp:1 = CY && !ZR; export tmp; }
+thfcc: "ls" is cond_full=9 { local tmp:1 = !CY || ZR; export tmp; }
+thfcc: "ge" is cond_full=10 { local tmp:1 = (NG == OV); export tmp; }
+thfcc: "lt" is cond_full=11 { local tmp:1 = (NG != OV); export tmp; }
+thfcc: "gt" is cond_full=12 { local tmp:1 = !ZR && (NG == OV); export tmp; }
+thfcc: "le" is cond_full=13 { local tmp:1 = ZR || (NG != OV); export tmp; }
+thfcc: "al" is cond_full=14 { local tmp:1 = 1; export tmp; } #can happen
+thfcc: "nv" is cond_full=15 { local tmp:1 = 0; export tmp; } #unpredictable, shouldn't happen
# no ITcondition
diff --git a/Ghidra/Processors/ARM/data/languages/ARMTHUMBinstructions.sinc b/Ghidra/Processors/ARM/data/languages/ARMTHUMBinstructions.sinc
index 31a363f889..54d2ca13ae 100644
--- a/Ghidra/Processors/ARM/data/languages/ARMTHUMBinstructions.sinc
+++ b/Ghidra/Processors/ARM/data/languages/ARMTHUMBinstructions.sinc
@@ -306,8 +306,8 @@ it_thfcc: "ge" is fcond=10 { tmp:1 = (NG == OV); export tmp; }
it_thfcc: "lt" is fcond=11 { tmp:1 = (NG == OV); export tmp; }
it_thfcc: "gt" is fcond=12 { tmp:1 = !ZR && (NG == OV); export tmp; }
it_thfcc: "le" is fcond=13 { tmp:1 = !ZR && (NG == OV); export tmp; }
-
-@define IT_THFCC "it_thfcc & (thc0707=0 | thc0606=0 | thc0505=0)"
+it_thfcc: "al" is fcond=14 { tmp:1 = 1; export tmp; }
+it_thfcc: "nv" is fcond=15 { tmp:1 = 1; export tmp; } # Unpredictable
ByteRotate: "#"^rot is throt [rot = throt << 3; ] { export *[const]:1 rot; }
@@ -1829,24 +1829,24 @@ th2_SetMode: "#"^31 is thc0004=0x1f { setSystemMode(); }
@endif # VERSION_8
@if defined(VERSION_6T2) || defined(VERSION_7)
-X: "T" is TMode=1 & ((thc0404=1 & thc0303=1) | (thc0404=0 & thc0303=0)) & (thc0202=1 | thc0101=1 | thc0000=1) { }
-X: "E" is TMode=1 & ((thc0404=1 & thc0303=0) | (thc0404=0 & thc0303=1)) & (thc0202=1 | thc0101=1 | thc0000=1) { }
+X: "t" is TMode=1 & ((thc0404=1 & thc0303=1) | (thc0404=0 & thc0303=0)) & (thc0202=1 | thc0101=1 | thc0000=1) { }
+X: "e" is TMode=1 & ((thc0404=1 & thc0303=0) | (thc0404=0 & thc0303=1)) & (thc0202=1 | thc0101=1 | thc0000=1) { }
X: "" is TMode=1 & thc0404 & thc0303 & (thc0202=0 & thc0101=0 & thc0000=0) { }
-Y: "T" is TMode=1 & ((thc0404=1 & thc0202=1) | (thc0404=0 & thc0202=0)) & (thc0101=1 | thc0000=1) { }
-Y: "E" is TMode=1 & ((thc0404=1 & thc0202=0) | (thc0404=0 & thc0202=1)) & (thc0101=1 | thc0000=1) { }
+Y: "t" is TMode=1 & ((thc0404=1 & thc0202=1) | (thc0404=0 & thc0202=0)) & (thc0101=1 | thc0000=1) { }
+Y: "e" is TMode=1 & ((thc0404=1 & thc0202=0) | (thc0404=0 & thc0202=1)) & (thc0101=1 | thc0000=1) { }
Y: "" is TMode=1 & thc0404 & thc0202 & (thc0101=0 & thc0000=0) { }
-Z: "T" is TMode=1 & ((thc0404=1 & thc0101=1) | (thc0404=0 & thc0101=0)) & (thc0000=1) { }
-Z: "E" is TMode=1 & ((thc0404=1 & thc0101=0) | (thc0404=0 & thc0101=1)) & (thc0000=1) { }
+Z: "t" is TMode=1 & ((thc0404=1 & thc0101=1) | (thc0404=0 & thc0101=0)) & (thc0000=1) { }
+Z: "e" is TMode=1 & ((thc0404=1 & thc0101=0) | (thc0404=0 & thc0101=1)) & (thc0000=1) { }
Z: "" is TMode=1 & thc0404 & thc0101 & (thc0000=0) { }
XYZ: is TMode=1 & sop0003=8 { }
XYZ: X^Y^Z is TMode=1 & X & Y & Z { }
-:it^XYZ it_thfcc is TMode=1 & op8=0xbf & XYZ & $(IT_THFCC) & thc0507 & thc0004
+:it^XYZ it_thfcc is TMode=1 & op8=0xbf & XYZ & it_thfcc & thc0507 & thc0004
[ itmode=0; cond_base = thc0507; cond_shft=thc0004; globalset(inst_next,condit); ]
{
- # just sets up the condtion and IF Then/Else mask
+ # just sets up the condition and If Then/Else mask
}
:ldc^ItCond thcpn,thCRd,taddrmode5 is (TMode=1 & ItCond & op9=0x76 & thN6=0 & thL4=1; thCRd & thcpn) & taddrmode5