1
2
3
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
36
37
41
45
49
53
57
61
65
69
73
77
81
85
89
93
97
101
105
106
107
108
117
118
119
120
121
122
125
128
131
134
137
140
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
294
298
302
307
312
317
326
335
344
353
362
371
380
389
398
399
402
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
431
432
433
434
435
436
437
438
439
440
441
442
443
444
449
454
459
465
471
478
487
496
505
514
523
532
541
550
559
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
606
611
616
621
626
631
636
641
646
649
654
659
664
669
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
727
728
729
730
731
732
733
734
735
736
737
738
743
747
752
757
762
767
772
777
782
785
790
795
800
805
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
859
860
861
862
863
864
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
924
925
926
927
928
932
937
938
939
940
941
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1029
1030
1031
1032
1036
1040
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1078
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1120
1121
1124
1125
1129
1130
1131
1132
1133
1134
1135
1140
1145
1148
1152
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1236
1237
1238
1239
1240
1241
1242
1243
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1278
1279
1280
1281
1282
1283
1284
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1334
1335
1336
1337
1338
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1412
1413
1418
1419
1423
1424
1428
1429
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1461
1462
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1502
1503
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1591
1593
1595
1596
1598
1600
1602
1603
1605
1607
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1766
1767
1768
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1830
1831
1832
1833
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
/* ... */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <helper/replacements.h>
#include "armv8.h"
#include "arm_disassembler.h"
#include "register.h"
#include <helper/binarybuffer.h>
#include <helper/command.h>
#include <helper/nvp.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "armv8_opcodes.h"
#include "target.h"
#include "target_type.h"
#include "semihosting_common.h"
14 includes
static const char * const armv8_state_strings[] = {
"AArch32", "Thumb", "Jazelle", "ThumbEE", "AArch64",
...};
static const struct {
const char *name;
unsigned psr;
...} armv8_mode_data[] = {
{
.name = "USR",
.psr = ARM_MODE_USR,
...},
{
.name = "FIQ",
.psr = ARM_MODE_FIQ,
...},
{
.name = "IRQ",
.psr = ARM_MODE_IRQ,
...},
{
.name = "SVC",
.psr = ARM_MODE_SVC,
...},
{
.name = "MON",
.psr = ARM_MODE_MON,
...},
{
.name = "ABT",
.psr = ARM_MODE_ABT,
...},
{
.name = "HYP",
.psr = ARM_MODE_HYP,
...},
{
.name = "UND",
.psr = ARM_MODE_UND,
...},
{
.name = "SYS",
.psr = ARM_MODE_SYS,
...},
{
.name = "EL0T",
.psr = ARMV8_64_EL0T,
...},
{
.name = "EL1T",
.psr = ARMV8_64_EL1T,
...},
{
.name = "EL1H",
.psr = ARMV8_64_EL1H,
...},
{
.name = "EL2T",
.psr = ARMV8_64_EL2T,
...},
{
.name = "EL2H",
.psr = ARMV8_64_EL2H,
...},
{
.name = "EL3T",
.psr = ARMV8_64_EL3T,
...},
{
.name = "EL3H",
.psr = ARMV8_64_EL3H,
...},
...};
const char *armv8_mode_name(unsigned psr_mode)
{
for (unsigned i = 0; i < ARRAY_SIZE(armv8_mode_data); i++) {
if (armv8_mode_data[i].psr == psr_mode)
return armv8_mode_data[i].name;
}for (unsigned i = 0; i < ARRAY_SIZE(armv8_mode_data); i++) { ... }
LOG_ERROR("unrecognized psr mode: %#02x", psr_mode);
return "UNRECOGNIZED";
}{ ... }
static uint8_t armv8_pa_size(uint32_t ps)
{
uint8_t ret = 0;
switch (ps) {
case 0:
ret = 32;
break;case 0:
case 1:
ret = 36;
break;case 1:
case 2:
ret = 40;
break;case 2:
case 3:
ret = 42;
break;case 3:
case 4:
ret = 44;
break;case 4:
case 5:
ret = 48;
break;case 5:
default:
LOG_INFO("Unknown physical address size");
break;default
}switch (ps) { ... }
return ret;
}{ ... }
static __attribute__((unused)) int armv8_read_ttbcr32(struct target *target)
{
struct armv8_common *armv8 = target_to_armv8(target);
struct arm_dpm *dpm = armv8->arm.dpm;
uint32_t ttbcr, ttbcr_n;
int retval = dpm->prepare(dpm);
if (retval != ERROR_OK)
goto done;
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_MRC(15, 0, 0, 2, 0, 2),
&ttbcr);
if (retval != ERROR_OK)
goto done;
LOG_DEBUG("ttbcr %" PRIx32, ttbcr);
ttbcr_n = ttbcr & 0x7;
armv8->armv8_mmu.ttbcr = ttbcr;
/* ... */
armv8->armv8_mmu.ttbr_range[0] = 0xffffffff >> ttbcr_n;
armv8->armv8_mmu.ttbr_range[1] = 0xffffffff;
armv8->armv8_mmu.ttbr_mask[0] = 0xffffffff << (14 - ttbcr_n);
armv8->armv8_mmu.ttbr_mask[1] = 0xffffffff << 14;
LOG_DEBUG("ttbr1 %s, ttbr0_mask %" PRIx32 " ttbr1_mask %" PRIx32,
(ttbcr_n != 0) ? "used" : "not used",
armv8->armv8_mmu.ttbr_mask[0],
armv8->armv8_mmu.ttbr_mask[1]);
done:
dpm->finish(dpm);
return retval;
}{ ... }
static int armv8_read_ttbcr(struct target *target)
{
struct armv8_common *armv8 = target_to_armv8(target);
struct arm_dpm *dpm = armv8->arm.dpm;
struct arm *arm = &armv8->arm;
uint32_t ttbcr;
uint64_t ttbcr_64;
int retval = dpm->prepare(dpm);
if (retval != ERROR_OK)
goto done;
memset(&armv8->armv8_mmu.ttbr1_used, 0, sizeof(armv8->armv8_mmu.ttbr1_used));
memset(&armv8->armv8_mmu.ttbr0_mask, 0, sizeof(armv8->armv8_mmu.ttbr0_mask));
switch (armv8_curel_from_core_mode(arm->core_mode)) {
case SYSTEM_CUREL_EL3:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS(SYSTEM_TCR_EL3, 0),
&ttbcr);
retval += dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_TTBR0_EL3, 0),
&armv8->ttbr_base);
if (retval != ERROR_OK)
goto done;
armv8->va_size = 64 - (ttbcr & 0x3F);
armv8->pa_size = armv8_pa_size((ttbcr >> 16) & 7);
armv8->page_size = (ttbcr >> 14) & 3;
break;case SYSTEM_CUREL_EL3:
case SYSTEM_CUREL_EL2:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS(SYSTEM_TCR_EL2, 0),
&ttbcr);
retval += dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_TTBR0_EL2, 0),
&armv8->ttbr_base);
if (retval != ERROR_OK)
goto done;
armv8->va_size = 64 - (ttbcr & 0x3F);
armv8->pa_size = armv8_pa_size((ttbcr >> 16) & 7);
armv8->page_size = (ttbcr >> 14) & 3;
break;case SYSTEM_CUREL_EL2:
case SYSTEM_CUREL_EL0:
armv8_dpm_modeswitch(dpm, ARMV8_64_EL1H);
case SYSTEM_CUREL_EL0:
case SYSTEM_CUREL_EL1:
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_TCR_EL1, 0),
&ttbcr_64);
armv8->va_size = 64 - (ttbcr_64 & 0x3F);
armv8->pa_size = armv8_pa_size((ttbcr_64 >> 32) & 7);
armv8->page_size = (ttbcr_64 >> 14) & 3;
armv8->armv8_mmu.ttbr1_used = (((ttbcr_64 >> 16) & 0x3F) != 0) ? 1 : 0;
armv8->armv8_mmu.ttbr0_mask = 0x0000FFFFFFFFFFFFULL;
retval += dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_TTBR0_EL1 | (armv8->armv8_mmu.ttbr1_used), 0),
&armv8->ttbr_base);
if (retval != ERROR_OK)
goto done;
break;case SYSTEM_CUREL_EL1:
default:
LOG_ERROR("unknown core state");
retval = ERROR_FAIL;
break;default
}switch (armv8_curel_from_core_mode(arm->core_mode)) { ... }
if (retval != ERROR_OK)
goto done;
if (armv8->armv8_mmu.ttbr1_used == 1)
LOG_INFO("TTBR0 access above %" PRIx64, (uint64_t)(armv8->armv8_mmu.ttbr0_mask));
done:
armv8_dpm_modeswitch(dpm, ARM_MODE_ANY);
dpm->finish(dpm);
return retval;
}{ ... }
static int armv8_get_pauth_mask(struct armv8_common *armv8, uint64_t *mask)
{
struct arm *arm = &armv8->arm;
int retval = ERROR_OK;
if (armv8->va_size == 0)
retval = armv8_read_ttbcr(arm->target);
if (retval != ERROR_OK)
return retval;
*mask = ~(((uint64_t)1 << armv8->va_size) - 1);
return retval;
}{ ... }
static int armv8_read_reg(struct armv8_common *armv8, int regnum, uint64_t *regval)
{
struct arm_dpm *dpm = &armv8->dpm;
unsigned int curel = armv8_curel_from_core_mode(dpm->arm->core_mode);
int retval;
uint32_t value;
uint64_t value_64;
if (!regval)
return ERROR_FAIL;
switch (regnum) {
case 0 ... 30:
retval = dpm->instr_read_data_dcc_64(dpm,
ARMV8_MSR_GP(SYSTEM_DBG_DBGDTR_EL0, regnum), &value_64);
break;case 0 ... 30:
case ARMV8_SP:
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MOVFSP_64(0), &value_64);
break;case ARMV8_SP:
case ARMV8_PC:
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS_DLR(0), &value_64);
break;case ARMV8_PC:
case ARMV8_XPSR:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS_DSPSR(0), &value);
value_64 = value;
break;case ARMV8_XPSR:
case ARMV8_FPSR:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS_FPSR(0), &value);
value_64 = value;
break;case ARMV8_FPSR:
case ARMV8_FPCR:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS_FPCR(0), &value);
value_64 = value;
break;case ARMV8_FPCR:
case ARMV8_ELR_EL1:
if (curel < SYSTEM_CUREL_EL1) {
LOG_DEBUG("ELR_EL1 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL1) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_ELR_EL1, 0), &value_64);
break;case ARMV8_ELR_EL1:
case ARMV8_ELR_EL2:
if (curel < SYSTEM_CUREL_EL2) {
LOG_DEBUG("ELR_EL2 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL2) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_ELR_EL2, 0), &value_64);
break;case ARMV8_ELR_EL2:
case ARMV8_ELR_EL3:
if (curel < SYSTEM_CUREL_EL3) {
LOG_DEBUG("ELR_EL3 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL3) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_ELR_EL3, 0), &value_64);
break;case ARMV8_ELR_EL3:
case ARMV8_ESR_EL1:
if (curel < SYSTEM_CUREL_EL1) {
LOG_DEBUG("ESR_EL1 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL1) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_ESR_EL1, 0), &value_64);
break;case ARMV8_ESR_EL1:
case ARMV8_ESR_EL2:
if (curel < SYSTEM_CUREL_EL2) {
LOG_DEBUG("ESR_EL2 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL2) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_ESR_EL2, 0), &value_64);
break;case ARMV8_ESR_EL2:
case ARMV8_ESR_EL3:
if (curel < SYSTEM_CUREL_EL3) {
LOG_DEBUG("ESR_EL3 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL3) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_ESR_EL3, 0), &value_64);
break;case ARMV8_ESR_EL3:
case ARMV8_SPSR_EL1:
if (curel < SYSTEM_CUREL_EL1) {
LOG_DEBUG("SPSR_EL1 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL1) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_SPSR_EL1, 0), &value_64);
break;case ARMV8_SPSR_EL1:
case ARMV8_SPSR_EL2:
if (curel < SYSTEM_CUREL_EL2) {
LOG_DEBUG("SPSR_EL2 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL2) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_SPSR_EL2, 0), &value_64);
break;case ARMV8_SPSR_EL2:
case ARMV8_SPSR_EL3:
if (curel < SYSTEM_CUREL_EL3) {
LOG_DEBUG("SPSR_EL3 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL3) { ... }
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MRS(SYSTEM_SPSR_EL3, 0), &value_64);
break;case ARMV8_SPSR_EL3:
case ARMV8_PAUTH_CMASK:
case ARMV8_PAUTH_DMASK:
retval = armv8_get_pauth_mask(armv8, &value_64);
break;case ARMV8_PAUTH_DMASK:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
if (retval == ERROR_OK)
*regval = value_64;
return retval;
}{ ... }
static int armv8_read_reg_simdfp_aarch64(struct armv8_common *armv8, int regnum, uint64_t *lvalue, uint64_t *hvalue)
{
int retval = ERROR_FAIL;
struct arm_dpm *dpm = &armv8->dpm;
switch (regnum) {
case ARMV8_V0 ... ARMV8_V31:
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MOV_GPR_VFP(0, (regnum - ARMV8_V0), 1), hvalue);
if (retval != ERROR_OK)
return retval;
retval = dpm->instr_read_data_r0_64(dpm,
ARMV8_MOV_GPR_VFP(0, (regnum - ARMV8_V0), 0), lvalue);
break;
case ARMV8_V0 ... ARMV8_V31:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
return retval;
}{ ... }
static int armv8_write_reg(struct armv8_common *armv8, int regnum, uint64_t value_64)
{
struct arm_dpm *dpm = &armv8->dpm;
unsigned int curel = armv8_curel_from_core_mode(dpm->arm->core_mode);
int retval;
uint32_t value;
switch (regnum) {
case 0 ... 30:
retval = dpm->instr_write_data_dcc_64(dpm,
ARMV8_MRS(SYSTEM_DBG_DBGDTR_EL0, regnum),
value_64);
break;case 0 ... 30:
case ARMV8_SP:
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MOVTSP_64(0),
value_64);
break;case ARMV8_SP:
case ARMV8_PC:
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_DLR(0),
value_64);
break;case ARMV8_PC:
case ARMV8_XPSR:
value = value_64;
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MSR_DSPSR(0),
value);
break;case ARMV8_XPSR:
case ARMV8_FPSR:
value = value_64;
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MSR_FPSR(0),
value);
break;case ARMV8_FPSR:
case ARMV8_FPCR:
value = value_64;
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MSR_FPCR(0),
value);
break;
case ARMV8_FPCR:
case ARMV8_ELR_EL1:
if (curel < SYSTEM_CUREL_EL1) {
LOG_DEBUG("ELR_EL1 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL1) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_ELR_EL1, 0), value_64);
break;case ARMV8_ELR_EL1:
case ARMV8_ELR_EL2:
if (curel < SYSTEM_CUREL_EL2) {
LOG_DEBUG("ELR_EL2 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL2) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_ELR_EL2, 0), value_64);
break;case ARMV8_ELR_EL2:
case ARMV8_ELR_EL3:
if (curel < SYSTEM_CUREL_EL3) {
LOG_DEBUG("ELR_EL3 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL3) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_ELR_EL3, 0), value_64);
break;case ARMV8_ELR_EL3:
case ARMV8_ESR_EL1:
if (curel < SYSTEM_CUREL_EL1) {
LOG_DEBUG("ESR_EL1 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL1) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_ESR_EL1, 0), value_64);
break;case ARMV8_ESR_EL1:
case ARMV8_ESR_EL2:
if (curel < SYSTEM_CUREL_EL2) {
LOG_DEBUG("ESR_EL2 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL2) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_ESR_EL2, 0), value_64);
break;case ARMV8_ESR_EL2:
case ARMV8_ESR_EL3:
if (curel < SYSTEM_CUREL_EL3) {
LOG_DEBUG("ESR_EL3 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL3) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_ESR_EL3, 0), value_64);
break;case ARMV8_ESR_EL3:
case ARMV8_SPSR_EL1:
if (curel < SYSTEM_CUREL_EL1) {
LOG_DEBUG("SPSR_EL1 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL1) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_SPSR_EL1, 0), value_64);
break;case ARMV8_SPSR_EL1:
case ARMV8_SPSR_EL2:
if (curel < SYSTEM_CUREL_EL2) {
LOG_DEBUG("SPSR_EL2 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL2) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_SPSR_EL2, 0), value_64);
break;case ARMV8_SPSR_EL2:
case ARMV8_SPSR_EL3:
if (curel < SYSTEM_CUREL_EL3) {
LOG_DEBUG("SPSR_EL3 not accessible in EL%u", curel);
retval = ERROR_FAIL;
break;
}if (curel < SYSTEM_CUREL_EL3) { ... }
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MSR_GP(SYSTEM_SPSR_EL3, 0), value_64);
break;case ARMV8_SPSR_EL3:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
return retval;
}{ ... }
static int armv8_write_reg_simdfp_aarch64(struct armv8_common *armv8, int regnum, uint64_t lvalue, uint64_t hvalue)
{
int retval = ERROR_FAIL;
struct arm_dpm *dpm = &armv8->dpm;
switch (regnum) {
case ARMV8_V0 ... ARMV8_V31:
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MOV_VFP_GPR((regnum - ARMV8_V0), 0, 1), hvalue);
if (retval != ERROR_OK)
return retval;
retval = dpm->instr_write_data_r0_64(dpm,
ARMV8_MOV_VFP_GPR((regnum - ARMV8_V0), 0, 0), lvalue);
break;
case ARMV8_V0 ... ARMV8_V31:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
return retval;
}{ ... }
static int armv8_read_reg32(struct armv8_common *armv8, int regnum, uint64_t *regval)
{
struct arm_dpm *dpm = &armv8->dpm;
uint32_t value = 0;
int retval;
if (!regval)
return ERROR_FAIL;
switch (regnum) {
case ARMV8_R0 ... ARMV8_R14:
retval = dpm->instr_read_data_dcc(dpm,
ARMV4_5_MCR(14, 0, regnum, 0, 5, 0),
&value);
break;case ARMV8_R0 ... ARMV8_R14:
case ARMV8_SP:
retval = dpm->instr_read_data_dcc(dpm,
ARMV4_5_MCR(14, 0, 13, 0, 5, 0),
&value);
break;case ARMV8_SP:
case ARMV8_PC:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRC_DLR(0),
&value);
break;case ARMV8_PC:
case ARMV8_XPSR:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRC_DSPSR(0),
&value);
break;case ARMV8_XPSR:
case ARMV8_ELR_EL1:
retval = dpm->instr_read_data_dcc(dpm,
ARMV4_5_MCR(14, 0, 14, 0, 5, 0),
&value);
break;case ARMV8_ELR_EL1:
case ARMV8_ELR_EL2:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS_T1(0, 14, 0, 1),
&value);
break;case ARMV8_ELR_EL2:
case ARMV8_ELR_EL3:
retval = dpm->instr_read_data_dcc(dpm,
ARMV4_5_MCR(14, 0, 14, 0, 5, 0),
&value);
break;case ARMV8_ELR_EL3:
case ARMV8_ESR_EL1:
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_MRC(15, 0, 0, 5, 0, 0),
&value);
break;case ARMV8_ESR_EL1:
case ARMV8_ESR_EL2:
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_MRC(15, 4, 0, 5, 2, 0),
&value);
break;case ARMV8_ESR_EL2:
case ARMV8_ESR_EL3:
retval = ERROR_FAIL;
break;case ARMV8_ESR_EL3:
case ARMV8_SPSR_EL1:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS_XPSR_T1(1, 0),
&value);
break;case ARMV8_SPSR_EL1:
case ARMV8_SPSR_EL2:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS_XPSR_T1(1, 0),
&value);
break;case ARMV8_SPSR_EL2:
case ARMV8_SPSR_EL3:
retval = dpm->instr_read_data_r0(dpm,
ARMV8_MRS_XPSR_T1(1, 0),
&value);
break;case ARMV8_SPSR_EL3:
case ARMV8_FPSR:
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_VMRS(0), &value);
break;case ARMV8_FPSR:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
if (retval == ERROR_OK)
*regval = value;
return retval;
}{ ... }
static int armv8_read_reg_simdfp_aarch32(struct armv8_common *armv8, int regnum, uint64_t *lvalue, uint64_t *hvalue)
{
int retval = ERROR_FAIL;
struct arm_dpm *dpm = &armv8->dpm;
struct reg *reg_r1 = dpm->arm->core_cache->reg_list + ARMV8_R1;
uint32_t value_r0 = 0, value_r1 = 0;
unsigned num = (regnum - ARMV8_V0) << 1;
switch (regnum) {
case ARMV8_V0 ... ARMV8_V15:
reg_r1->dirty = true;
/* ... */
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_VMOV(1, 1, 0, (num >> 4), (num & 0xf)),
&value_r0);
if (retval != ERROR_OK)
return retval;
retval = dpm->instr_read_data_dcc(dpm,
ARMV4_5_MCR(14, 0, 1, 0, 5, 0),
&value_r1);
if (retval != ERROR_OK)
return retval;
*lvalue = value_r1;
*lvalue = ((*lvalue) << 32) | value_r0;
num++;
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_VMOV(1, 1, 0, (num >> 4), (num & 0xf)),
&value_r0);
if (retval != ERROR_OK)
return retval;
retval = dpm->instr_read_data_dcc(dpm,
ARMV4_5_MCR(14, 0, 1, 0, 5, 0),
&value_r1);
if (retval != ERROR_OK)
return retval;
*hvalue = value_r1;
*hvalue = ((*hvalue) << 32) | value_r0;
break;case ARMV8_V0 ... ARMV8_V15:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
return retval;
}{ ... }
static int armv8_write_reg32(struct armv8_common *armv8, int regnum, uint64_t value)
{
struct arm_dpm *dpm = &armv8->dpm;
int retval;
switch (regnum) {
case ARMV8_R0 ... ARMV8_R14:
retval = dpm->instr_write_data_dcc(dpm,
ARMV4_5_MRC(14, 0, regnum, 0, 5, 0), value);
break;case ARMV8_R0 ... ARMV8_R14:
case ARMV8_SP:
retval = dpm->instr_write_data_dcc(dpm,
ARMV4_5_MRC(14, 0, 13, 0, 5, 0), value);
break;case ARMV8_SP:
case ARMV8_PC:
/* ... */
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MCR_DLR(0), value);
break;case ARMV8_PC:
case ARMV8_XPSR:
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MCR_DSPSR(0), value);
break;case ARMV8_XPSR:
case ARMV8_ELR_EL1:
retval = dpm->instr_write_data_dcc(dpm,
ARMV4_5_MRC(14, 0, 14, 0, 5, 0),
value);
break;case ARMV8_ELR_EL1:
case ARMV8_ELR_EL2:
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MSR_GP_T1(0, 14, 0, 1),
value);
break;case ARMV8_ELR_EL2:
case ARMV8_ELR_EL3:
retval = dpm->instr_write_data_dcc(dpm,
ARMV4_5_MRC(14, 0, 14, 0, 5, 0),
value);
break;case ARMV8_ELR_EL3:
case ARMV8_ESR_EL1:
retval = dpm->instr_write_data_r0(dpm,
ARMV4_5_MCR(15, 0, 0, 5, 0, 0),
value);
break;case ARMV8_ESR_EL1:
case ARMV8_ESR_EL2:
retval = dpm->instr_write_data_r0(dpm,
ARMV4_5_MCR(15, 4, 0, 5, 2, 0),
value);
break;case ARMV8_ESR_EL2:
case ARMV8_ESR_EL3:
retval = ERROR_FAIL;
break;case ARMV8_ESR_EL3:
case ARMV8_SPSR_EL1:
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MSR_GP_XPSR_T1(1, 0, 15),
value);
break;case ARMV8_SPSR_EL1:
case ARMV8_SPSR_EL2:
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MSR_GP_XPSR_T1(1, 0, 15),
value);
break;case ARMV8_SPSR_EL2:
case ARMV8_SPSR_EL3:
retval = dpm->instr_write_data_r0(dpm,
ARMV8_MSR_GP_XPSR_T1(1, 0, 15),
value);
break;case ARMV8_SPSR_EL3:
case ARMV8_FPSR:
retval = dpm->instr_write_data_r0(dpm,
ARMV4_5_VMSR(0), value);
break;case ARMV8_FPSR:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
return retval;
}{ ... }
static int armv8_write_reg_simdfp_aarch32(struct armv8_common *armv8, int regnum, uint64_t lvalue, uint64_t hvalue)
{
int retval = ERROR_FAIL;
struct arm_dpm *dpm = &armv8->dpm;
struct reg *reg_r1 = dpm->arm->core_cache->reg_list + ARMV8_R1;
uint32_t value_r0 = 0, value_r1 = 0;
unsigned num = (regnum - ARMV8_V0) << 1;
switch (regnum) {
case ARMV8_V0 ... ARMV8_V15:
reg_r1->dirty = true;
value_r1 = lvalue >> 32;
value_r0 = lvalue & 0xFFFFFFFF;
retval = dpm->instr_write_data_dcc(dpm,
ARMV4_5_MRC(14, 0, 1, 0, 5, 0),
value_r1);
if (retval != ERROR_OK)
return retval;
/* ... */
retval = dpm->instr_write_data_r0(dpm,
ARMV4_5_VMOV(0, 1, 0, (num >> 4), (num & 0xf)),
value_r0);
if (retval != ERROR_OK)
return retval;
num++;
value_r1 = hvalue >> 32;
value_r0 = hvalue & 0xFFFFFFFF;
retval = dpm->instr_write_data_dcc(dpm,
ARMV4_5_MRC(14, 0, 1, 0, 5, 0),
value_r1);
if (retval != ERROR_OK)
return retval;
retval = dpm->instr_write_data_r0(dpm,
ARMV4_5_VMOV(0, 1, 0, (num >> 4), (num & 0xf)),
value_r0);
break;case ARMV8_V0 ... ARMV8_V15:
default:
retval = ERROR_FAIL;
break;default
}switch (regnum) { ... }
return retval;
}{ ... }
void armv8_select_reg_access(struct armv8_common *armv8, bool is_aarch64)
{
if (is_aarch64) {
armv8->read_reg_u64 = armv8_read_reg;
armv8->write_reg_u64 = armv8_write_reg;
armv8->read_reg_u128 = armv8_read_reg_simdfp_aarch64;
armv8->write_reg_u128 = armv8_write_reg_simdfp_aarch64;
}if (is_aarch64) { ... } else {
armv8->read_reg_u64 = armv8_read_reg32;
armv8->write_reg_u64 = armv8_write_reg32;
armv8->read_reg_u128 = armv8_read_reg_simdfp_aarch32;
armv8->write_reg_u128 = armv8_write_reg_simdfp_aarch32;
}else { ... }
}{ ... }
int armv8_read_mpidr(struct armv8_common *armv8)
{
int retval = ERROR_FAIL;
struct arm *arm = &armv8->arm;
struct arm_dpm *dpm = armv8->arm.dpm;
uint32_t mpidr;
retval = dpm->prepare(dpm);
if (retval != ERROR_OK)
goto done;
if (armv8_curel_from_core_mode(arm->core_mode) < SYSTEM_CUREL_EL1) {
retval = armv8_dpm_modeswitch(dpm, ARMV8_64_EL1H);
if (retval != ERROR_OK)
return retval;
}if (armv8_curel_from_core_mode(arm->core_mode) < SYSTEM_CUREL_EL1) { ... }
retval = dpm->instr_read_data_r0(dpm, armv8_opcode(armv8, READ_REG_MPIDR), &mpidr);
if (retval != ERROR_OK)
goto done;
if (mpidr & 1U<<31) {
armv8->multi_processor_system = (mpidr >> 30) & 1;
armv8->cluster_id = (mpidr >> 8) & 0xf;
armv8->cpu_id = mpidr & 0x3;
LOG_INFO("%s cluster %x core %x %s", target_name(armv8->arm.target),
armv8->cluster_id,
armv8->cpu_id,
armv8->multi_processor_system == 0 ? "multi core" : "single core");
}if (mpidr & 1U<<31) { ... } else
LOG_ERROR("mpidr not in multiprocessor format");
done:
armv8_dpm_modeswitch(dpm, ARM_MODE_ANY);
dpm->finish(dpm);
return retval;
}{ ... }
/* ... */
void armv8_set_cpsr(struct arm *arm, uint32_t cpsr)
{
uint32_t mode = cpsr & 0x1F;
/* ... */
if (arm->cpsr) {
buf_set_u32(arm->cpsr->value, 0, 32, cpsr);
arm->cpsr->valid = true;
arm->cpsr->dirty = false;
}if (arm->cpsr) { ... }
enum arm_state state = 0xFF;
if ((cpsr & 0x10) != 0) {
if (cpsr & (1 << 5)) {
if (cpsr & (1 << 24)) {
LOG_WARNING("ThumbEE -- incomplete support");
state = ARM_STATE_THUMB_EE;
}if (cpsr & (1 << 24)) { ... } else
state = ARM_STATE_THUMB;
}if (cpsr & (1 << 5)) { ... } else {
if (cpsr & (1 << 24)) {
LOG_ERROR("Jazelle state handling is BROKEN!");
state = ARM_STATE_JAZELLE;
}if (cpsr & (1 << 24)) { ... } else
state = ARM_STATE_ARM;
}else { ... }
}if ((cpsr & 0x10) != 0) { ... } else {
state = ARM_STATE_AARCH64;
}else { ... }
arm->core_state = state;
arm->core_mode = mode;
LOG_DEBUG("set CPSR %#8.8x: %s mode, %s state", (unsigned) cpsr,
armv8_mode_name(arm->core_mode),
armv8_state_strings[arm->core_state]);
}{ ... }
static void armv8_show_fault_registers32(struct armv8_common *armv8)
{
uint32_t dfsr, ifsr, dfar, ifar;
struct arm_dpm *dpm = armv8->arm.dpm;
int retval;
retval = dpm->prepare(dpm);
if (retval != ERROR_OK)
return;
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_MRC(15, 0, 0, 5, 0, 0),
&dfsr);
if (retval != ERROR_OK)
goto done;
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_MRC(15, 0, 0, 5, 0, 1),
&ifsr);
if (retval != ERROR_OK)
goto done;
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_MRC(15, 0, 0, 6, 0, 0),
&dfar);
if (retval != ERROR_OK)
goto done;
retval = dpm->instr_read_data_r0(dpm,
ARMV4_5_MRC(15, 0, 0, 6, 0, 2),
&ifar);
if (retval != ERROR_OK)
goto done;
LOG_USER("Data fault registers DFSR: %8.8" PRIx32
", DFAR: %8.8" PRIx32, dfsr, dfar);
LOG_USER("Instruction fault registers IFSR: %8.8" PRIx32
", IFAR: %8.8" PRIx32, ifsr, ifar);
done:
dpm->finish(dpm);
}{ ... }
static __attribute__((unused)) void armv8_show_fault_registers(struct target *target)
{
struct armv8_common *armv8 = target_to_armv8(target);
if (armv8->arm.core_state != ARM_STATE_AARCH64)
armv8_show_fault_registers32(armv8);
}{ ... }
int armv8_mmu_translate_va(struct target *target, target_addr_t va, target_addr_t *val)
{
return ERROR_OK;
}{ ... }
static void armv8_decode_cacheability(int attr)
{
if (attr == 0) {
LOG_USER_N("UNPREDICTABLE");
return;
}if (attr == 0) { ... }
if (attr == 4) {
LOG_USER_N("Non-cacheable");
return;
}if (attr == 4) { ... }
switch (attr & 0xC) {
case 0:
LOG_USER_N("Write-Through Transient");
break;case 0:
case 0x4:
LOG_USER_N("Write-Back Transient");
break;case 0x4:
case 0x8:
LOG_USER_N("Write-Through Non-transient");
break;case 0x8:
case 0xC:
LOG_USER_N("Write-Back Non-transient");
break;case 0xC:
}switch (attr & 0xC) { ... }
if (attr & 2)
LOG_USER_N(" Read-Allocate");
else
LOG_USER_N(" No-Read Allocate");
if (attr & 1)
LOG_USER_N(" Write-Allocate");
else
LOG_USER_N(" No-Write Allocate");
}{ ... }
static void armv8_decode_memory_attr(int attr)
{
if (attr == 0x40) {
LOG_USER("Normal Memory, Inner Non-cacheable, "
"Outer Non-cacheable, XS=0");
}if (attr == 0x40) { ... } else if (attr == 0xA0) {
LOG_USER("Normal Memory, Inner Write-through Cacheable, "
"Outer Write-through Cacheable, Read-Allocate, "
"No-Write Allocate, Non-transient, XS=0");
}else if (attr == 0xA0) { ... } else if (attr == 0xF0) {
LOG_USER("Tagged Normal Memory, Inner Write-Back, "
"Outer Write-Back, Read-Allocate, Write-Allocate, "
"Non-transient");
}else if (attr == 0xF0) { ... } else if ((attr & 0xF0) == 0) {
switch (attr & 0xC) {
case 0:
LOG_USER_N("Device-nGnRnE Memory");
break;case 0:
case 0x4:
LOG_USER_N("Device-nGnRE Memory");
break;case 0x4:
case 0x8:
LOG_USER_N("Device-nGRE Memory");
break;case 0x8:
case 0xC:
LOG_USER_N("Device-GRE Memory");
break;case 0xC:
}switch (attr & 0xC) { ... }
if (attr & 1)
LOG_USER(", XS=0");
else
LOG_USER_N("\n");
}else if ((attr & 0xF0) == 0) { ... } else {
LOG_USER_N("Normal Memory, Inner ");
armv8_decode_cacheability(attr & 0xF);
LOG_USER_N(", Outer ");
armv8_decode_cacheability(attr >> 4);
LOG_USER_N("\n");
}else { ... }
}{ ... }
int armv8_mmu_translate_va_pa(struct target *target, target_addr_t va,
target_addr_t *val, int meminfo)
{
struct armv8_common *armv8 = target_to_armv8(target);
struct arm *arm = target_to_arm(target);
struct arm_dpm *dpm = &armv8->dpm;
enum arm_mode target_mode = ARM_MODE_ANY;
uint32_t retval;
uint32_t instr = 0;
uint64_t par;
static const char * const shared_name[] = {
"Non-", "UNDEFINED ", "Outer ", "Inner "
...};
static const char * const secure_name[] = {
"Secure", "Not Secure"
...};
if (target->state != TARGET_HALTED) {
LOG_TARGET_ERROR(target, "not halted");
return ERROR_TARGET_NOT_HALTED;
}if (target->state != TARGET_HALTED) { ... }
retval = dpm->prepare(dpm);
if (retval != ERROR_OK)
return retval;
switch (armv8_curel_from_core_mode(arm->core_mode)) {
case SYSTEM_CUREL_EL0:
instr = ARMV8_SYS(SYSTEM_ATS12E0R, 0);
target_mode = ARMV8_64_EL2H;
break;case SYSTEM_CUREL_EL0:
case SYSTEM_CUREL_EL1:
instr = ARMV8_SYS(SYSTEM_ATS12E1R, 0);
target_mode = ARMV8_64_EL2H;
break;case SYSTEM_CUREL_EL1:
case SYSTEM_CUREL_EL2:
instr = ARMV8_SYS(SYSTEM_ATS1E2R, 0);
break;case SYSTEM_CUREL_EL2:
case SYSTEM_CUREL_EL3:
instr = ARMV8_SYS(SYSTEM_ATS1E3R, 0);
break;
case SYSTEM_CUREL_EL3:
default:
break;default
}switch (armv8_curel_from_core_mode(arm->core_mode)) { ... };
if (target_mode != ARM_MODE_ANY)
armv8_dpm_modeswitch(dpm, target_mode);
retval = dpm->instr_write_data_r0_64(dpm, instr, (uint64_t)va);
if (retval == ERROR_OK)
retval = dpm->instr_read_data_r0_64(dpm, ARMV8_MRS(SYSTEM_PAR_EL1, 0), &par);
if (target_mode != ARM_MODE_ANY)
armv8_dpm_modeswitch(dpm, ARM_MODE_ANY);
dpm->finish(dpm);
if (retval != ERROR_OK)
return retval;
if (par & 1) {
LOG_ERROR("Address translation failed at stage %i, FST=%x, PTW=%i",
((int)(par >> 9) & 1)+1, (int)(par >> 1) & 0x3f, (int)(par >> 8) & 1);
*val = 0;
retval = ERROR_FAIL;
}if (par & 1) { ... } else {
*val = (par & 0xFFFFFFFFF000UL) | (va & 0xFFF);
if (meminfo) {
int SH = (par >> 7) & 3;
int NS = (par >> 9) & 1;
int ATTR = (par >> 56) & 0xFF;
LOG_USER("%sshareable, %s",
shared_name[SH], secure_name[NS]);
armv8_decode_memory_attr(ATTR);
}if (meminfo) { ... }
}else { ... }
return retval;
}{ ... }
COMMAND_HANDLER(armv8_handle_exception_catch_command)
{
struct target *target = get_current_target(CMD_CTX);
struct armv8_common *armv8 = target_to_armv8(target);
uint32_t edeccr = 0;
unsigned int argp = 0;
int retval;
static const struct nvp nvp_ecatch_modes[] = {
{ .name = "off", .value = 0 },
{ .name = "nsec_el1", .value = (1 << 5) },
{ .name = "nsec_el2", .value = (2 << 5) },
{ .name = "nsec_el12", .value = (3 << 5) },
{ .name = "sec_el1", .value = (1 << 1) },
{ .name = "sec_el3", .value = (4 << 1) },
{ .name = "sec_el13", .value = (5 << 1) },
{ .name = NULL, .value = -1 },
...};
const struct nvp *n;
if (CMD_ARGC == 0) {
const char *sec = NULL, *nsec = NULL;
retval = mem_ap_read_atomic_u32(armv8->debug_ap,
armv8->debug_base + CPUV8_DBG_ECCR, &edeccr);
if (retval != ERROR_OK)
return retval;
n = nvp_value2name(nvp_ecatch_modes, edeccr & 0x0f);
if (n->name)
sec = n->name;
n = nvp_value2name(nvp_ecatch_modes, edeccr & 0xf0);
if (n->name)
nsec = n->name;
if (!sec || !nsec) {
LOG_WARNING("Exception Catch: unknown exception catch configuration: EDECCR = %02" PRIx32, edeccr & 0xff);
return ERROR_FAIL;
}if (!sec || !nsec) { ... }
command_print(CMD, "Exception Catch: Secure: %s, Non-Secure: %s", sec, nsec);
return ERROR_OK;
}if (CMD_ARGC == 0) { ... }
while (argp < CMD_ARGC) {
n = nvp_name2value(nvp_ecatch_modes, CMD_ARGV[argp]);
if (!n->name) {
LOG_ERROR("Unknown option: %s", CMD_ARGV[argp]);
return ERROR_FAIL;
}if (!n->name) { ... }
LOG_DEBUG("found: %s", n->name);
edeccr |= n->value;
argp++;
}while (argp < CMD_ARGC) { ... }
retval = mem_ap_write_atomic_u32(armv8->debug_ap,
armv8->debug_base + CPUV8_DBG_ECCR, edeccr);
if (retval != ERROR_OK)
return retval;
return ERROR_OK;
}{ ... }
COMMAND_HANDLER(armv8_pauth_command)
{
struct target *target = get_current_target(CMD_CTX);
struct armv8_common *armv8 = target_to_armv8(target);
return CALL_COMMAND_HANDLER(handle_command_parse_bool,
&armv8->enable_pauth,
"pauth feature");
}{ ... }
int armv8_handle_cache_info_command(struct command_invocation *cmd,
struct armv8_cache_common *armv8_cache)
{
if (armv8_cache->info == -1) {
command_print(cmd, "cache not yet identified");
return ERROR_OK;
}if (armv8_cache->info == -1) { ... }
if (armv8_cache->display_cache_info)
armv8_cache->display_cache_info(cmd, armv8_cache);
return ERROR_OK;
}{ ... }
static int armv8_setup_semihosting(struct target *target, int enable)
{
return ERROR_OK;
}{ ... }
int armv8_init_arch_info(struct target *target, struct armv8_common *armv8)
{
struct arm *arm = &armv8->arm;
arm->arch_info = armv8;
target->arch_info = &armv8->arm;
arm->setup_semihosting = armv8_setup_semihosting;
armv8->arm.target = target;
armv8->arm.common_magic = ARM_COMMON_MAGIC;
armv8->common_magic = ARMV8_COMMON_MAGIC;
armv8->armv8_mmu.armv8_cache.l2_cache = NULL;
armv8->armv8_mmu.armv8_cache.info = -1;
armv8->armv8_mmu.armv8_cache.flush_all_data_cache = NULL;
armv8->armv8_mmu.armv8_cache.display_cache_info = NULL;
return ERROR_OK;
}{ ... }
static int armv8_aarch64_state(struct target *target)
{
struct arm *arm = target_to_arm(target);
if (arm->common_magic != ARM_COMMON_MAGIC) {
LOG_ERROR("BUG: called for a non-ARM target");
return ERROR_FAIL;
}if (arm->common_magic != ARM_COMMON_MAGIC) { ... }
LOG_USER("%s halted in %s state due to %s, current mode: %s\n"
"cpsr: 0x%8.8" PRIx32 " pc: 0x%" PRIx64 "%s",
target_name(target),
armv8_state_strings[arm->core_state],
debug_reason_name(target),
armv8_mode_name(arm->core_mode),
buf_get_u32(arm->cpsr->value, 0, 32),
buf_get_u64(arm->pc->value, 0, 64),
(target->semihosting && target->semihosting->is_active) ? ", semihosting" : "");
return ERROR_OK;
}{ ... }
int armv8_arch_state(struct target *target)
{
static const char * const state[] = {
"disabled", "enabled"
...};
struct armv8_common *armv8 = target_to_armv8(target);
struct arm *arm = &armv8->arm;
if (armv8->common_magic != ARMV8_COMMON_MAGIC) {
LOG_ERROR("BUG: called for a non-Armv8 target");
return ERROR_COMMAND_SYNTAX_ERROR;
}if (armv8->common_magic != ARMV8_COMMON_MAGIC) { ... }
if (arm->core_state == ARM_STATE_AARCH64)
armv8_aarch64_state(target);
else
arm_arch_state(target);
LOG_USER("MMU: %s, D-Cache: %s, I-Cache: %s",
state[armv8->armv8_mmu.mmu_enabled],
state[armv8->armv8_mmu.armv8_cache.d_u_cache_enabled],
state[armv8->armv8_mmu.armv8_cache.i_cache_enabled]);
if (arm->core_mode == ARM_MODE_ABT)
armv8_show_fault_registers(target);
if (target->debug_reason == DBG_REASON_WATCHPOINT)
LOG_USER("Watchpoint triggered at " TARGET_ADDR_FMT, armv8->dpm.wp_addr);
return ERROR_OK;
}{ ... }
static struct reg_data_type aarch64_vector_base_types[] = {
{REG_TYPE_IEEE_DOUBLE, "ieee_double", 0, {NULL} },
{REG_TYPE_UINT64, "uint64", 0, {NULL} },
{REG_TYPE_INT64, "int64", 0, {NULL} },
{REG_TYPE_IEEE_SINGLE, "ieee_single", 0, {NULL} },
{REG_TYPE_UINT32, "uint32", 0, {NULL} },
{REG_TYPE_INT32, "int32", 0, {NULL} },
{REG_TYPE_UINT16, "uint16", 0, {NULL} },
{REG_TYPE_INT16, "int16", 0, {NULL} },
{REG_TYPE_UINT8, "uint8", 0, {NULL} },
{REG_TYPE_INT8, "int8", 0, {NULL} },
{REG_TYPE_UINT128, "uint128", 0, {NULL} },
{REG_TYPE_INT128, "int128", 0, {NULL} }
...};
static struct reg_data_type_vector aarch64_vector_types[] = {
{aarch64_vector_base_types + 0, 2},
{aarch64_vector_base_types + 1, 2},
{aarch64_vector_base_types + 2, 2},
{aarch64_vector_base_types + 3, 4},
{aarch64_vector_base_types + 4, 4},
{aarch64_vector_base_types + 5, 4},
{aarch64_vector_base_types + 6, 8},
{aarch64_vector_base_types + 7, 8},
{aarch64_vector_base_types + 8, 16},
{aarch64_vector_base_types + 9, 16},
{aarch64_vector_base_types + 10, 01},
{aarch64_vector_base_types + 11, 01},
...};
static struct reg_data_type aarch64_fpu_vector[] = {
{REG_TYPE_ARCH_DEFINED, "v2d", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 0} },
{REG_TYPE_ARCH_DEFINED, "v2u", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 1} },
{REG_TYPE_ARCH_DEFINED, "v2i", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 2} },
{REG_TYPE_ARCH_DEFINED, "v4f", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 3} },
{REG_TYPE_ARCH_DEFINED, "v4u", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 4} },
{REG_TYPE_ARCH_DEFINED, "v4i", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 5} },
{REG_TYPE_ARCH_DEFINED, "v8u", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 6} },
{REG_TYPE_ARCH_DEFINED, "v8i", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 7} },
{REG_TYPE_ARCH_DEFINED, "v16u", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 8} },
{REG_TYPE_ARCH_DEFINED, "v16i", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 9} },
{REG_TYPE_ARCH_DEFINED, "v1u", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 10} },
{REG_TYPE_ARCH_DEFINED, "v1i", REG_TYPE_CLASS_VECTOR, {aarch64_vector_types + 11} },
...};
static struct reg_data_type_union_field aarch64_union_fields_vnd[] = {
{"f", aarch64_fpu_vector + 0, aarch64_union_fields_vnd + 1},
{"u", aarch64_fpu_vector + 1, aarch64_union_fields_vnd + 2},
{"s", aarch64_fpu_vector + 2, NULL},
...};
static struct reg_data_type_union_field aarch64_union_fields_vns[] = {
{"f", aarch64_fpu_vector + 3, aarch64_union_fields_vns + 1},
{"u", aarch64_fpu_vector + 4, aarch64_union_fields_vns + 2},
{"s", aarch64_fpu_vector + 5, NULL},
...};
static struct reg_data_type_union_field aarch64_union_fields_vnh[] = {
{"u", aarch64_fpu_vector + 6, aarch64_union_fields_vnh + 1},
{"s", aarch64_fpu_vector + 7, NULL},
...};
static struct reg_data_type_union_field aarch64_union_fields_vnb[] = {
{"u", aarch64_fpu_vector + 8, aarch64_union_fields_vnb + 1},
{"s", aarch64_fpu_vector + 9, NULL},
...};
static struct reg_data_type_union_field aarch64_union_fields_vnq[] = {
{"u", aarch64_fpu_vector + 10, aarch64_union_fields_vnq + 1},
{"s", aarch64_fpu_vector + 11, NULL},
...};
static struct reg_data_type_union aarch64_union_types[] = {
{aarch64_union_fields_vnd},
{aarch64_union_fields_vns},
{aarch64_union_fields_vnh},
{aarch64_union_fields_vnb},
{aarch64_union_fields_vnq},
...};
static struct reg_data_type aarch64_fpu_union[] = {
{REG_TYPE_ARCH_DEFINED, "vnd", REG_TYPE_CLASS_UNION, {.reg_type_union = aarch64_union_types + 0} },
{REG_TYPE_ARCH_DEFINED, "vns", REG_TYPE_CLASS_UNION, {.reg_type_union = aarch64_union_types + 1} },
{REG_TYPE_ARCH_DEFINED, "vnh", REG_TYPE_CLASS_UNION, {.reg_type_union = aarch64_union_types + 2} },
{REG_TYPE_ARCH_DEFINED, "vnb", REG_TYPE_CLASS_UNION, {.reg_type_union = aarch64_union_types + 3} },
{REG_TYPE_ARCH_DEFINED, "vnq", REG_TYPE_CLASS_UNION, {.reg_type_union = aarch64_union_types + 4} },
...};
static struct reg_data_type_union_field aarch64v_union_fields[] = {
{"d", aarch64_fpu_union + 0, aarch64v_union_fields + 1},
{"s", aarch64_fpu_union + 1, aarch64v_union_fields + 2},
{"h", aarch64_fpu_union + 2, aarch64v_union_fields + 3},
{"b", aarch64_fpu_union + 3, aarch64v_union_fields + 4},
{"q", aarch64_fpu_union + 4, NULL},
...};
static struct reg_data_type_union aarch64v_union[] = {
{aarch64v_union_fields}
...};
static struct reg_data_type aarch64v[] = {
{REG_TYPE_ARCH_DEFINED, "aarch64v", REG_TYPE_CLASS_UNION,
{.reg_type_union = aarch64v_union} ...},
...};
static struct reg_data_type_bitfield aarch64_cpsr_bits[] = {
{ 0, 0, REG_TYPE_UINT8 },
{ 2, 3, REG_TYPE_UINT8 },
{ 4, 4, REG_TYPE_UINT8 },
{ 6, 6, REG_TYPE_BOOL },
{ 7, 7, REG_TYPE_BOOL },
{ 8, 8, REG_TYPE_BOOL },
{ 9, 9, REG_TYPE_BOOL },
{ 20, 20, REG_TYPE_BOOL },
{ 21, 21, REG_TYPE_BOOL },
{ 28, 28, REG_TYPE_BOOL },
{ 29, 29, REG_TYPE_BOOL },
{ 30, 30, REG_TYPE_BOOL },
{ 31, 31, REG_TYPE_BOOL },
...};
static struct reg_data_type_flags_field aarch64_cpsr_fields[] = {
{ "SP", aarch64_cpsr_bits + 0, aarch64_cpsr_fields + 1 },
{ "EL", aarch64_cpsr_bits + 1, aarch64_cpsr_fields + 2 },
{ "nRW", aarch64_cpsr_bits + 2, aarch64_cpsr_fields + 3 },
{ "F",