| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package arm64asm |
| 6 |
|
| 7 |
import ( |
| 8 |
"strconv" |
| 9 |
"strings" |
| 10 |
"testing" |
| 11 |
) |
| 12 |
|
| 13 |
func TestObjdumpARM64TestDecodeGNUSyntaxdata(t *testing.T) { |
| •14 |
t.Skip("https://github.com/golang/go/issues/66005") |
| 15 |
testObjdumpARM64(t, testdataCases(t, "gnu")) |
| 16 |
} |
| 17 |
func TestObjdumpARM64TestDecodeGoSyntaxdata(t *testing.T) { |
| •18 |
t.Skip("https://github.com/golang/go/issues/66005") |
| 19 |
testObjdumpARM64(t, testdataCases(t, "plan9")) |
| 20 |
} |
| 21 |
func TestObjdumpARM64Manual(t *testing.T) { testObjdumpARM64(t, hexCases(t, objdumpManualTests)) } |
| 22 |
func TestObjdumpARM64Cond(t *testing.T) { testObjdumpARM64(t, condCases(t)) } |
| 23 |
func TestObjdumpARM64(t *testing.T) { testObjdumpARM64(t, JSONCases(t)) } |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
var objdumpManualTests = ` |
| 31 |
bf2003d5 |
| 32 |
9f2003d5 |
| 33 |
7f2003d5 |
| 34 |
5f2003d5 |
| 35 |
3f2003d5 |
| 36 |
1f2003d5 |
| 37 |
df4d03d5 |
| 38 |
ff4d03d5 |
| 39 |
28d91b14 |
| 40 |
da6cb530 |
| 41 |
15e5e514 |
| 42 |
ff4603d5 |
| 43 |
df4803d5 |
| 44 |
bf4100d5 |
| 45 |
9f3f03d5 |
| 46 |
9f3e03d5 |
| 47 |
9f3d03d5 |
| 48 |
9f3b03d5 |
| 49 |
9f3a03d5 |
| 50 |
9f3903d5 |
| 51 |
9f3703d5 |
| 52 |
9f3603d5 |
| 53 |
9f3503d5 |
| 54 |
9f3303d5 |
| 55 |
9f3203d5 |
| 56 |
9f3103d5 |
| 57 |
ff4603d5 |
| 58 |
df4803d5 |
| 59 |
bf4100d5 |
| 60 |
a3681b53 |
| 61 |
47dc78d3 |
| 62 |
0500a012 |
| 63 |
0500e092 |
| 64 |
0500a052 |
| 65 |
0500a0d2 |
| 66 |
cd5a206e |
| 67 |
cd5a202e |
| 68 |
743d050e |
| 69 |
743d0a0e |
| 70 |
743d0c0e |
| 71 |
743d084e |
| 72 |
` |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
func allowedMismatchObjdump(text string, inst *Inst, dec ExtInst) bool { |
| 77 |
|
| 78 |
if hasPrefix(dec.text, todo...) { |
| 79 |
return true |
| 80 |
} |
| 81 |
|
| 82 |
if inst.Enc&0x000003ff == 0x000003ff && hasPrefix(dec.text, "negs") && hasPrefix(text, "cmp") { |
| 83 |
return true |
| 84 |
} |
| 85 |
|
| 86 |
if strings.HasSuffix(dec.text, " nv") && strings.HasSuffix(text, " al") { |
| 87 |
return true |
| 88 |
} |
| 89 |
if strings.HasPrefix(dec.text, "b.nv") && strings.HasPrefix(text, "b.al") { |
| 90 |
return true |
| 91 |
} |
| 92 |
|
| 93 |
if hasPrefix(dec.text, "hint", "mrs", "msr", "bfc", "orr", "mov") { |
| 94 |
return true |
| 95 |
} |
| 96 |
if strings.HasPrefix(text, "hint") { |
| 97 |
return true |
| 98 |
} |
| 99 |
|
| 100 |
if strings.Contains(text, "unknown instruction") && hasPrefix(dec.text, "fmla", "fmul", "fmulx", "fcvtzs", "fcvtzu", "fmls", "fmov", "scvtf", "ucvtf") { |
| 101 |
return true |
| 102 |
} |
| 103 |
|
| 104 |
for k, v := range oldObjdumpMismatch { |
| 105 |
if strings.HasPrefix(dec.text, k) && strings.Replace(dec.text, k, v, 1) == text { |
| 106 |
return true |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
if newForm, ok := newMnemonics[text]; ok && newForm == dec.text { |
| 114 |
return true |
| 115 |
} |
| 116 |
slcMismatches := map[string]string{ |
| 117 |
"pldslckeep": "#0x06", |
| 118 |
"plislckeep": "#0x0e", |
| 119 |
"pstslckeep": "#0x16", |
| 120 |
"pldslcstrm": "#0x07", |
| 121 |
"plislcstrm": "#0x0f", |
| 122 |
"pstslcstrm": "#0x17", |
| 123 |
} |
| 124 |
decTextNormalized := dec.text |
| 125 |
for k, v := range slcMismatches { |
| 126 |
decTextNormalized = strings.Replace(decTextNormalized, k, v, -1) |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
if strings.Replace(text, " ", "", -1) == strings.Replace(decTextNormalized, " ", "", -1) { |
| 131 |
return true |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
if strings.Contains(dec.text, "{") && strings.Contains(dec.text, "}") && strings.Contains(text, "{") { |
| 136 |
i1 := strings.Index(text, "{") |
| 137 |
j1 := strings.Index(text, "}") |
| 138 |
i2 := strings.Index(decTextNormalized, "{") |
| 139 |
j2 := strings.Index(decTextNormalized, "}") |
| 140 |
if i1 >= 0 && j1 > i1 && i2 >= 0 && j2 > i2 { |
| 141 |
list1 := strings.Replace(text[i1+1:j1], " ", "", -1) |
| 142 |
list2 := strings.Replace(decTextNormalized[i2+1:j2], " ", "", -1) |
| 143 |
rest1 := strings.Replace(text[:i1], " ", "", -1) + strings.Replace(text[j1+1:], " ", "", -1) |
| 144 |
rest2 := strings.Replace(decTextNormalized[:i2], " ", "", -1) + strings.Replace(decTextNormalized[j2+1:], " ", "", -1) |
| 145 |
if rest1 == rest2 { |
| 146 |
|
| 147 |
p1 := strings.Split(list1, ",") |
| 148 |
p2 := strings.FieldsFunc(list2, func(r rune) bool { return r == ',' || r == '-' }) |
| 149 |
|
| 150 |
if len(p1) > 0 && len(p2) > 0 { |
| 151 |
|
| 152 |
parseReg := func(s string) (int, string, bool) { |
| 153 |
if len(s) > 1 && (s[0] == 'v') { |
| 154 |
s = s[1:] |
| 155 |
} |
| 156 |
parts := strings.Split(s, ".") |
| 157 |
if len(parts) == 0 { |
| 158 |
return 0, "", false |
| 159 |
} |
| 160 |
num, err := strconv.Atoi(parts[0]) |
| 161 |
if err != nil { |
| 162 |
return 0, "", false |
| 163 |
} |
| 164 |
arr := "" |
| 165 |
if len(parts) > 1 { |
| 166 |
arr = parts[1] |
| 167 |
} |
| 168 |
return num, arr, true |
| 169 |
} |
| 170 |
|
| 171 |
startNum, startArr, ok1 := parseReg(p2[0]) |
| 172 |
endNum, _, ok2 := parseReg(p2[len(p2)-1]) |
| 173 |
|
| 174 |
if ok1 && ok2 { |
| 175 |
|
| 176 |
count := (endNum-startNum+32)%32 + 1 |
| 177 |
|
| 178 |
if len(p1) == count { |
| 179 |
match := true |
| 180 |
for i, regStr := range p1 { |
| 181 |
regNum, regArr, ok := parseReg(regStr) |
| 182 |
if !ok || regNum != (startNum+i)%32 || regArr != startArr { |
| 183 |
match = false |
| 184 |
break |
| 185 |
} |
| 186 |
} |
| 187 |
if match { |
| 188 |
return true |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
return false |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
var todo = strings.Fields(` |
| 201 |
sys |
| 202 |
at |
| 203 |
ic |
| 204 |
hvc |
| 205 |
smc |
| 206 |
`) |
| 207 |
|
| 208 |
|
| 209 |
var Ncover = strings.Fields(` |
| 210 |
sbfm |
| 211 |
asrv |
| 212 |
bfm |
| 213 |
ubfm |
| 214 |
lslv |
| 215 |
lsrv |
| 216 |
rorv |
| 217 |
ins |
| 218 |
dup |
| 219 |
`) |
| 220 |
|
| 221 |
|
| 222 |
var oldObjdumpMismatch = map[string]string{ |
| 223 |
|
| 224 |
"ldr": "ldur", |
| 225 |
"ldrb": "ldurb", |
| 226 |
"ldrh": "ldurh", |
| 227 |
"ldrsb": "ldursb", |
| 228 |
"ldrsh": "ldursh", |
| 229 |
"ldrsw": "ldursw", |
| 230 |
"str": "stur", |
| 231 |
"strb": "sturb", |
| 232 |
"strh": "sturh", |
| 233 |
"prfm": "prfum", |
| 234 |
} |
| 235 |
|
| 236 |
var newMnemonics = map[string]string{ |
| 237 |
"dsb #0x00": "ssbb", |
| 238 |
"dsb #0x04": "pssbb", |
| 239 |
} |