1
2
3
4
5
6
7
8
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
168
169
170
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
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
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
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
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
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
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
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
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
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
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
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
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
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
1459
1460
1461
1462
1463
1464
1465
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
1500
1501
1502
1503
1504
1505
1506
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
1553
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
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
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
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
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
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
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
1868
1869
1870
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
1904
1905
1906
1907
1908
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
1953
1954
1955
1956
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
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
|
/* TI C6X assembler.
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Contributed by Joseph Myers <joseph@codesourcery.com>
Bernd Schmidt <bernds@codesourcery.com>
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to the Free
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
#include "as.h"
#include "dwarf2dbg.h"
#include "dw2gencfi.h"
#include "safe-ctype.h"
#include "subsegs.h"
#include "opcode/tic6x.h"
#include "elf/tic6x.h"
#include "elf32-tic6x.h"
/* Truncate and sign-extend at 32 bits, so that building on a 64-bit
host gives identical results to a 32-bit host. */
#define TRUNC(X) ((valueT) (X) & 0xffffffffU)
#define SEXT(X) ((TRUNC (X) ^ 0x80000000U) - 0x80000000U)
#define streq(a, b) (strcmp (a, b) == 0)
/* Stuff for .scomm symbols. */
static segT sbss_section;
static asection scom_section;
static asymbol scom_symbol;
const char comment_chars[] = ";";
const char line_comment_chars[] = "#*;";
const char line_separator_chars[] = "@";
const char EXP_CHARS[] = "eE";
const char FLT_CHARS[] = "dDfF";
const char *md_shortopts = "";
enum
{
OPTION_MARCH = OPTION_MD_BASE,
OPTION_MBIG_ENDIAN,
OPTION_MLITTLE_ENDIAN,
OPTION_MDSBT,
OPTION_MNO_DSBT,
OPTION_MPID,
OPTION_MPIC,
OPTION_MNO_PIC,
OPTION_MGENERATE_REL
};
struct option md_longopts[] =
{
{ "march", required_argument, NULL, OPTION_MARCH },
{ "mbig-endian", no_argument, NULL, OPTION_MBIG_ENDIAN },
{ "mlittle-endian", no_argument, NULL, OPTION_MLITTLE_ENDIAN },
{ "mdsbt", no_argument, NULL, OPTION_MDSBT },
{ "mno-dsbt", no_argument, NULL, OPTION_MNO_DSBT },
{ "mpid", required_argument, NULL, OPTION_MPID },
{ "mpic", no_argument, NULL, OPTION_MPIC },
{ "mno-pic", no_argument, NULL, OPTION_MNO_PIC },
{ "mgenerate-rel", no_argument, NULL, OPTION_MGENERATE_REL },
{ NULL, no_argument, NULL, 0 }
};
size_t md_longopts_size = sizeof (md_longopts);
/* The instructions enabled based only on the selected architecture
(all instructions, if no architecture specified). */
static unsigned short tic6x_arch_enable = (TIC6X_INSN_C62X
| TIC6X_INSN_C64X
| TIC6X_INSN_C64XP
| TIC6X_INSN_C67X
| TIC6X_INSN_C67XP
| TIC6X_INSN_C674X);
/* The instructions enabled based on the current set of features
(architecture, as modified by other options). */
static unsigned short tic6x_features;
/* The architecture attribute value, or C6XABI_Tag_ISA_none if
not yet set. */
static int tic6x_arch_attribute = C6XABI_Tag_ISA_none;
/* Whether any instructions at all have been seen. Once any
instructions have been seen, architecture attributes merge into the
previous attribute value rather than replacing it. */
static bool tic6x_seen_insns = false;
/* The number of registers in each register file supported by the
current architecture. */
static unsigned int tic6x_num_registers;
/* Whether predication on A0 is possible. */
static bool tic6x_predicate_a0;
/* Whether execute packets can cross fetch packet boundaries. */
static bool tic6x_can_cross_fp_boundary;
/* Whether there are constraints on simultaneous reads and writes of
40-bit data. */
static bool tic6x_long_data_constraints;
/* Whether compact instructions are available. */
static bool tic6x_compact_insns;
/* Whether to generate RELA relocations. */
static bool tic6x_generate_rela = true;
/* Whether the code uses DSBT addressing. */
static bool tic6x_dsbt;
/* Types of position-independent data (attribute values for
Tag_ABI_PID). */
typedef enum
{
tic6x_pid_no = 0,
tic6x_pid_near = 1,
tic6x_pid_far = 2
} tic6x_pid_type;
/* The type of data addressing used in this code. */
static tic6x_pid_type tic6x_pid;
/* Whether the code uses position-independent code. */
static bool tic6x_pic;
/* Table of supported architecture variants. */
typedef struct
{
const char *arch;
int attr;
unsigned short features;
} tic6x_arch_table;
static const tic6x_arch_table tic6x_arches[] =
{
{ "c62x", C6XABI_Tag_ISA_C62X, TIC6X_INSN_C62X },
{ "c64x", C6XABI_Tag_ISA_C64X, TIC6X_INSN_C62X | TIC6X_INSN_C64X },
{ "c64x+", C6XABI_Tag_ISA_C64XP, (TIC6X_INSN_C62X
| TIC6X_INSN_C64X
| TIC6X_INSN_C64XP) },
{ "c67x", C6XABI_Tag_ISA_C67X, TIC6X_INSN_C62X | TIC6X_INSN_C67X },
{ "c67x+", C6XABI_Tag_ISA_C67XP, (TIC6X_INSN_C62X
| TIC6X_INSN_C67X
| TIC6X_INSN_C67XP) },
{ "c674x", C6XABI_Tag_ISA_C674X, (TIC6X_INSN_C62X
| TIC6X_INSN_C64X
| TIC6X_INSN_C64XP
| TIC6X_INSN_C67X
| TIC6X_INSN_C67XP
| TIC6X_INSN_C674X) }
};
/* Caller saved register encodings. The standard frame layout uses this
order, starting from the highest address. There must be
TIC6X_NUM_UNWIND_REGS values. */
enum
{
UNWIND_A15,
UNWIND_B15,
UNWIND_B14,
UNWIND_B13,
UNWIND_B12,
UNWIND_B11,
UNWIND_B10,
UNWIND_B3,
UNWIND_A14,
UNWIND_A13,
UNWIND_A12,
UNWIND_A11,
UNWIND_A10
};
static void tic6x_output_unwinding (bool need_extab);
/* Return the frame unwind state for the current function, allocating
as necessary. */
static tic6x_unwind_info *tic6x_get_unwind (void)
{
tic6x_unwind_info *unwind;
unwind = seg_info (now_seg)->tc_segment_info_data.unwind;
if (unwind)
return unwind;
unwind = seg_info (now_seg)->tc_segment_info_data.text_unwind;
if (unwind)
return unwind;
unwind =XNEW (tic6x_unwind_info);
seg_info (now_seg)->tc_segment_info_data.unwind = unwind;
memset (unwind, 0, sizeof (*unwind));
return unwind;
}
/* Update the selected architecture based on ARCH, giving an error if
ARCH is an invalid value. Does not call tic6x_update_features; the
caller must do that if necessary. */
static void
tic6x_use_arch (const char *arch)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE (tic6x_arches); i++)
if (strcmp (arch, tic6x_arches[i].arch) == 0)
{
tic6x_arch_enable = tic6x_arches[i].features;
if (tic6x_seen_insns)
tic6x_arch_attribute
= elf32_tic6x_merge_arch_attributes (tic6x_arch_attribute,
tic6x_arches[i].attr);
else
tic6x_arch_attribute = tic6x_arches[i].attr;
return;
}
as_bad (_("unknown architecture '%s'"), arch);
}
/* Table of supported -mpid arguments. */
typedef struct
{
const char *arg;
tic6x_pid_type attr;
} tic6x_pid_type_table;
static const tic6x_pid_type_table tic6x_pid_types[] =
{
{ "no", tic6x_pid_no },
{ "near", tic6x_pid_near },
{ "far", tic6x_pid_far }
};
/* Handle -mpid=ARG. */
static void
tic6x_use_pid (const char *arg)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE (tic6x_pid_types); i++)
if (strcmp (arg, tic6x_pid_types[i].arg) == 0)
{
tic6x_pid = tic6x_pid_types[i].attr;
return;
}
as_bad (_("unknown -mpid= argument '%s'"), arg);
}
/* Parse a target-specific option. */
int
md_parse_option (int c, const char *arg)
{
switch (c)
{
case OPTION_MARCH:
tic6x_use_arch (arg);
break;
case OPTION_MBIG_ENDIAN:
target_big_endian = 1;
break;
case OPTION_MLITTLE_ENDIAN:
target_big_endian = 0;
break;
case OPTION_MDSBT:
tic6x_dsbt = 1;
break;
case OPTION_MNO_DSBT:
tic6x_dsbt = 0;
break;
case OPTION_MPID:
tic6x_use_pid (arg);
break;
case OPTION_MPIC:
tic6x_pic = 1;
break;
case OPTION_MNO_PIC:
tic6x_pic = 0;
break;
case OPTION_MGENERATE_REL:
tic6x_generate_rela = false;
break;
default:
return 0;
}
return 1;
}
void
md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
{
unsigned int i;
fputc ('\n', stream);
fprintf (stream, _("TMS320C6000 options:\n"));
fprintf (stream, _(" -march=ARCH enable instructions from architecture ARCH\n"));
fprintf (stream, _(" -mbig-endian generate big-endian code\n"));
fprintf (stream, _(" -mlittle-endian generate little-endian code\n"));
fprintf (stream, _(" -mdsbt code uses DSBT addressing\n"));
fprintf (stream, _(" -mno-dsbt code does not use DSBT addressing\n"));
fprintf (stream, _(" -mpid=no code uses position-dependent data addressing\n"));
fprintf (stream, _(" -mpid=near code uses position-independent data addressing,\n"
" GOT accesses use near DP addressing\n"));
fprintf (stream, _(" -mpid=far code uses position-independent data addressing,\n"
" GOT accesses use far DP addressing\n"));
fprintf (stream, _(" -mpic code addressing is position-independent\n"));
fprintf (stream, _(" -mno-pic code addressing is position-dependent\n"));
/* -mgenerate-rel is only for testsuite use and is deliberately
undocumented. */
fputc ('\n', stream);
fprintf (stream, _("Supported ARCH values are:"));
for (i = 0; i < ARRAY_SIZE (tic6x_arches); i++)
fprintf (stream, " %s", tic6x_arches[i].arch);
fputc ('\n', stream);
}
/* Update enabled features based on the current architecture and
related settings. */
static void
tic6x_update_features (void)
{
tic6x_features = tic6x_arch_enable;
tic6x_num_registers
= (tic6x_arch_enable & (TIC6X_INSN_C64X | TIC6X_INSN_C67XP)) ? 32 : 16;
tic6x_predicate_a0 = (tic6x_arch_enable & TIC6X_INSN_C64X) != 0;
tic6x_can_cross_fp_boundary
= (tic6x_arch_enable & (TIC6X_INSN_C64X | TIC6X_INSN_C67XP)) != 0;
tic6x_long_data_constraints = (tic6x_arch_enable & TIC6X_INSN_C64X) == 0;
tic6x_compact_insns = (tic6x_arch_enable & TIC6X_INSN_C64XP) != 0;
}
/* Do configuration after all options have been parsed. */
void
tic6x_after_parse_args (void)
{
tic6x_update_features ();
}
/* Parse a .cantunwind directive. */
static void
s_tic6x_cantunwind (int ignored ATTRIBUTE_UNUSED)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
/* GCC sometimes spits out superfluous .cantunwind directives, so ignore
them. */
if (unwind->data_bytes == 0)
return;
if (unwind->data_bytes != -1)
{
as_bad (_("unexpected .cantunwind directive"));
return;
}
demand_empty_rest_of_line ();
if (unwind->personality_routine || unwind->personality_index != -1)
as_bad (_("personality routine specified for cantunwind frame"));
unwind->personality_index = -2;
}
/* Parse a .handlerdata directive. */
static void
s_tic6x_handlerdata (int ignored ATTRIBUTE_UNUSED)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
if (!unwind->saved_seg)
{
as_bad (_("unexpected .handlerdata directive"));
return;
}
if (unwind->table_entry || unwind->personality_index == -2)
{
as_bad (_("duplicate .handlerdata directive"));
return;
}
if (unwind->personality_index == -1 && unwind->personality_routine == NULL)
{
as_bad (_("personality routine required before .handlerdata directive"));
return;
}
tic6x_output_unwinding (true);
}
/* Parse a .endp directive. */
static void
s_tic6x_endp (int ignored ATTRIBUTE_UNUSED)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
if (unwind->data_bytes != 0)
{
/* Output a .exidx entry if we have not already done so.
Then switch back to the text section. */
if (!unwind->table_entry)
tic6x_output_unwinding (false);
subseg_set (unwind->saved_seg, unwind->saved_subseg);
}
unwind->saved_seg = NULL;
unwind->table_entry = NULL;
unwind->data_bytes = 0;
}
/* Parse a .personalityindex directive. */
static void
s_tic6x_personalityindex (int ignored ATTRIBUTE_UNUSED)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
expressionS exp;
if (unwind->personality_routine || unwind->personality_index != -1)
as_bad (_("duplicate .personalityindex directive"));
expression (&exp);
if (exp.X_op != O_constant
|| exp.X_add_number < 0 || exp.X_add_number > 15)
{
as_bad (_("bad personality routine number"));
ignore_rest_of_line ();
return;
}
unwind->personality_index = exp.X_add_number;
demand_empty_rest_of_line ();
}
static void
s_tic6x_personality (int ignored ATTRIBUTE_UNUSED)
{
char *name, c;
tic6x_unwind_info *unwind = tic6x_get_unwind ();
if (unwind->personality_routine || unwind->personality_index != -1)
as_bad (_("duplicate .personality directive"));
c = get_symbol_name (&name);
unwind->personality_routine = symbol_find_or_make (name);
(void) restore_line_pointer (c);
demand_empty_rest_of_line ();
}
/* Parse a .arch directive. */
static void
s_tic6x_arch (int ignored ATTRIBUTE_UNUSED)
{
char c;
char *arch;
arch = input_line_pointer;
while (*input_line_pointer && !ISSPACE (*input_line_pointer))
input_line_pointer++;
c = *input_line_pointer;
*input_line_pointer = 0;
tic6x_use_arch (arch);
tic6x_update_features ();
*input_line_pointer = c;
demand_empty_rest_of_line ();
}
/* Parse a .ehtype directive. */
static void
s_tic6x_ehtype (int ignored ATTRIBUTE_UNUSED)
{
expressionS exp;
char *p;
#ifdef md_flush_pending_output
md_flush_pending_output ();
#endif
if (is_it_end_of_statement ())
{
demand_empty_rest_of_line ();
return;
}
#ifdef md_cons_align
md_cons_align (4);
#endif
expression (&exp);
if (exp.X_op != O_symbol)
{
as_bad (_("expected symbol"));
return;
}
p = frag_more (4);
memset (p, 0, 4);
fix_new_exp (frag_now, p - frag_now->fr_literal, 4,
&exp, 0, BFD_RELOC_C6000_EHTYPE);
demand_empty_rest_of_line ();
}
/* Parse a .nocmp directive. */
static void
s_tic6x_nocmp (int ignored ATTRIBUTE_UNUSED)
{
seg_info (now_seg)->tc_segment_info_data.nocmp = true;
demand_empty_rest_of_line ();
}
/* .scomm pseudo-op handler.
This is a new pseudo-op to handle putting objects in .scommon.
By doing this the linker won't need to do any work,
and more importantly it removes the implicit -G arg necessary to
correctly link the object file. */
static void
s_tic6x_scomm (int ignore ATTRIBUTE_UNUSED)
{
char *name;
char c;
char *p;
offsetT size;
symbolS *symbolP;
offsetT align;
int align2;
c = get_symbol_name (&name);
/* Just after name is now '\0'. */
p = input_line_pointer;
(void) restore_line_pointer (c);
SKIP_WHITESPACE ();
if (*input_line_pointer != ',')
{
as_bad (_("expected comma after symbol name"));
ignore_rest_of_line ();
return;
}
/* Skip ','. */
input_line_pointer++;
if ((size = get_absolute_expression ()) < 0)
{
/* xgettext:c-format */
as_warn (_("invalid length for .scomm directive"));
ignore_rest_of_line ();
return;
}
/* The third argument to .scomm is the alignment. */
if (*input_line_pointer != ',')
align = 8;
else
{
++input_line_pointer;
align = get_absolute_expression ();
if (align <= 0)
{
as_warn (_("alignment is not a positive number"));
align = 8;
}
}
/* Convert to a power of 2 alignment. */
if (align)
{
for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2)
continue;
if (align != 1)
{
as_bad (_("alignment is not a power of 2"));
ignore_rest_of_line ();
return;
}
}
else
align2 = 0;
*p = 0;
symbolP = symbol_find_or_make (name);
*p = c;
if (S_IS_DEFINED (symbolP))
{
/* xgettext:c-format */
as_bad (_("attempt to re-define symbol `%s'"),
S_GET_NAME (symbolP));
ignore_rest_of_line ();
return;
}
if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
{
/* xgettext:c-format */
as_bad (_("attempt to redefine `%s' with a different length"),
S_GET_NAME (symbolP));
ignore_rest_of_line ();
return;
}
if (symbol_get_obj (symbolP)->local)
{
segT old_sec = now_seg;
int old_subsec = now_subseg;
char *pfrag;
record_alignment (sbss_section, align2);
subseg_set (sbss_section, 0);
if (align2)
frag_align (align2, 0, 0);
if (S_GET_SEGMENT (symbolP) == sbss_section)
symbol_get_frag (symbolP)->fr_symbol = 0;
symbol_set_frag (symbolP, frag_now);
pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
(char *) 0);
*pfrag = 0;
S_SET_SIZE (symbolP, size);
S_SET_SEGMENT (symbolP, sbss_section);
S_CLEAR_EXTERNAL (symbolP);
subseg_set (old_sec, old_subsec);
}
else
{
S_SET_VALUE (symbolP, (valueT) size);
S_SET_ALIGN (symbolP, 1 << align2);
S_SET_EXTERNAL (symbolP);
S_SET_SEGMENT (symbolP, &scom_section);
}
symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
demand_empty_rest_of_line ();
}
/* Track for each attribute whether it has been set explicitly (and so
should not have a default value set by the assembler). */
static bool tic6x_attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
/* Parse a .c6xabi_attribute directive. */
static void
s_tic6x_c6xabi_attribute (int ignored ATTRIBUTE_UNUSED)
{
int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
tic6x_attributes_set_explicitly[tag] = true;
}
typedef struct
{
const char *name;
int tag;
} tic6x_attribute_table;
static const tic6x_attribute_table tic6x_attributes[] =
{
#define TAG(tag, value) { #tag, tag },
#include "elf/tic6x-attrs.h"
#undef TAG
};
/* Convert an attribute name to a number. */
int
tic6x_convert_symbolic_attribute (const char *name)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE (tic6x_attributes); i++)
if (strcmp (name, tic6x_attributes[i].name) == 0)
return tic6x_attributes[i].tag;
return -1;
}
const pseudo_typeS md_pseudo_table[] =
{
{ "arch", s_tic6x_arch, 0 },
{ "c6xabi_attribute", s_tic6x_c6xabi_attribute, 0 },
{ "nocmp", s_tic6x_nocmp, 0 },
{ "scomm", s_tic6x_scomm, 0 },
{ "word", cons, 4 },
{ "ehtype", s_tic6x_ehtype, 0 },
{ "endp", s_tic6x_endp, 0 },
{ "handlerdata", s_tic6x_handlerdata, 0 },
{ "personalityindex", s_tic6x_personalityindex, 0 },
{ "personality", s_tic6x_personality, 0 },
{ "cantunwind", s_tic6x_cantunwind, 0 },
{ 0, 0, 0 }
};
/* Hash table of opcodes. For each opcode name, this stores a pointer
to a tic6x_opcode_list listing (in an arbitrary order) all opcode
table entries with that name. */
static htab_t opcode_hash;
/* Initialize the assembler (called once at assembler startup). */
void
md_begin (void)
{
tic6x_opcode_id id;
flagword applicable;
segT seg;
subsegT subseg;
bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0);
/* Insert opcodes into the hash table. */
opcode_hash = str_htab_create ();
for (id = 0; id < tic6x_opcode_max; id++)
{
tic6x_opcode_list *opc = XNEW (tic6x_opcode_list);
opc->id = id;
opc->next = str_hash_find (opcode_hash, tic6x_opcode_table[id].name);
str_hash_insert (opcode_hash, tic6x_opcode_table[id].name, opc, 1);
}
/* Save the current subseg so we can restore it [it's the default one and
we don't want the initial section to be .sbss]. */
seg = now_seg;
subseg = now_subseg;
/* The sbss section is for local .scomm symbols. */
sbss_section = subseg_new (".bss", 0);
seg_info (sbss_section)->bss = 1;
/* This is copied from perform_an_assembly_pass. */
applicable = bfd_applicable_section_flags (stdoutput);
bfd_set_section_flags (sbss_section, applicable & SEC_ALLOC);
subseg_set (seg, subseg);
/* We must construct a fake section similar to bfd_com_section
but with the name .scommon. */
scom_section = *bfd_com_section_ptr;
scom_section.name = ".scommon";
scom_section.output_section = & scom_section;
scom_section.symbol = & scom_symbol;
scom_section.symbol_ptr_ptr = & scom_section.symbol;
scom_symbol = * bfd_com_section_ptr->symbol;
scom_symbol.name = ".scommon";
scom_symbol.section = & scom_section;
}
/* Whether the current line being parsed had the "||" parallel bars. */
static bool tic6x_line_parallel;
/* Whether the current line being parsed started "||^" to indicate an
SPMASKed parallel instruction. */
static bool tic6x_line_spmask;
/* If the current line being parsed had an instruction predicate, the
creg value for that predicate (which must be nonzero); otherwise
0. */
static unsigned int tic6x_line_creg;
/* If the current line being parsed had an instruction predicate, the
z value for that predicate; otherwise 0. */
static unsigned int tic6x_line_z;
/* Return 1 (updating input_line_pointer as appropriate) if the line
starting with C (immediately before input_line_pointer) starts with
pre-opcode text appropriate for this target, 0 otherwise. */
int
tic6x_unrecognized_line (int c)
{
char *p, *endp;
unsigned int z;
bool areg;
bool bad_predicate;
switch (c)
{
case '|':
if (input_line_pointer[0] == '|')
{
if (input_line_pointer[1] == '^')
{
tic6x_line_spmask = true;
input_line_pointer += 2;
}
else
input_line_pointer += 1;
if (tic6x_line_parallel)
as_bad (_("multiple '||' on same line"));
tic6x_line_parallel = true;
if (tic6x_line_creg)
as_bad (_("'||' after predicate"));
return 1;
}
return 0;
case '[':
/* If it doesn't look like a predicate at all, just return 0.
If it looks like one but not a valid one, give a better
error. */
p = input_line_pointer;
while (*p != ']' && !is_end_of_line[(unsigned char) *p])
p++;
if (*p != ']')
return 0;
endp = p + 1;
p = input_line_pointer;
z = 0;
bad_predicate = false;
if (*p == '!')
{
z = 1;
p++;
}
if (*p == 'A' || *p == 'a')
areg = true;
else if (*p == 'B' || *p == 'b')
areg = false;
else
{
areg = true; /* Avoid uninitialized warning. */
bad_predicate = true;
}
if (!bad_predicate)
{
p++;
if (*p != '0' && *p != '1' && *p != '2')
bad_predicate = true;
else if (p[1] != ']')
bad_predicate = true;
else
input_line_pointer = p + 2;
}
if (tic6x_line_creg)
as_bad (_("multiple predicates on same line"));
if (bad_predicate)
{
char ctmp = *endp;
*endp = 0;
as_bad (_("bad predicate '%s'"), input_line_pointer - 1);
*endp = ctmp;
input_line_pointer = endp;
return 1;
}
switch (*p)
{
case '0':
tic6x_line_creg = (areg ? 6 : 1);
if (areg && !tic6x_predicate_a0)
as_bad (_("predication on A0 not supported on this architecture"));
break;
case '1':
tic6x_line_creg = (areg ? 4 : 2);
break;
case '2':
tic6x_line_creg = (areg ? 5 : 3);
break;
default:
abort ();
}
tic6x_line_z = z;
return 1;
default:
return 0;
}
}
/* Do any target-specific handling of a label required. */
void
tic6x_frob_label (symbolS *sym)
{
segment_info_type *si;
tic6x_label_list *list;
if (tic6x_line_parallel)
{
as_bad (_("label after '||'"));
tic6x_line_parallel = false;
tic6x_line_spmask = false;
}
if (tic6x_line_creg)
{
as_bad (_("label after predicate"));
tic6x_line_creg = 0;
tic6x_line_z = 0;
}
si = seg_info (now_seg);
list = si->tc_segment_info_data.label_list;
si->tc_segment_info_data.label_list = XNEW (tic6x_label_list);
si->tc_segment_info_data.label_list->next = list;
si->tc_segment_info_data.label_list->label = sym;
/* Defining tc_frob_label overrides the ELF definition of
obj_frob_label, so we need to apply its effects here. */
dwarf2_emit_label (sym);
}
/* At end-of-line, give errors for start-of-line decorations that
needed an instruction but were not followed by one. */
static void
tic6x_end_of_line (void)
{
if (tic6x_line_parallel)
{
as_bad (_("'||' not followed by instruction"));
tic6x_line_parallel = false;
tic6x_line_spmask = false;
}
if (tic6x_line_creg)
{
as_bad (_("predicate not followed by instruction"));
tic6x_line_creg = 0;
tic6x_line_z = 0;
}
}
/* Do any target-specific handling of the start of a logical line. */
void
tic6x_start_line_hook (void)
{
tic6x_end_of_line ();
}
/* Do target-specific handling immediately after an input file from
the command line, and any other inputs it includes, have been
read. */
void
tic6x_cleanup (void)
{
tic6x_end_of_line ();
}
/* Do target-specific initialization after arguments have been
processed and the output file created. */
void
tic6x_init_after_args (void)
{
elf32_tic6x_set_use_rela_p (stdoutput, tic6x_generate_rela);
}
/* Free LIST of labels (possibly NULL). */
static void
tic6x_free_label_list (tic6x_label_list *list)
{
while (list)
{
tic6x_label_list *old = list;
list = list->next;
free (old);
}
}
/* Handle a data alignment of N bytes. */
void
tic6x_cons_align (int n ATTRIBUTE_UNUSED)
{
segment_info_type *seginfo = seg_info (now_seg);
/* Data means there is no current execute packet, and that any label
applies to that data rather than a subsequent instruction. */
tic6x_free_label_list (seginfo->tc_segment_info_data.label_list);
seginfo->tc_segment_info_data.label_list = NULL;
seginfo->tc_segment_info_data.execute_packet_frag = NULL;
seginfo->tc_segment_info_data.last_insn_lsb = NULL;
seginfo->tc_segment_info_data.spmask_addr = NULL;
seginfo->tc_segment_info_data.func_units_used = 0;
}
/* Handle an alignment directive. Return TRUE if the
machine-independent frag generation should be skipped. */
bool
tic6x_do_align (int n, char *fill, int len ATTRIBUTE_UNUSED, int max)
{
/* Given code alignments of 4, 8, 16 or 32 bytes, we try to handle
them in the md_finish pass by inserting NOPs in parallel with
previous instructions. We only do this in sections containing
nothing but instructions. Code alignments of 1 or 2 bytes have
no effect in such sections (but we record them with
machine-dependent frags anyway so they can be skipped or
converted to machine-independent), while those of more than 64
bytes cannot reliably be handled in this way. */
if (n > 0
&& max >= 0
&& max < (1 << n)
&& !need_pass_2
&& fill == NULL
&& subseg_text_p (now_seg))
{
fragS *align_frag;
char *p;
if (n > 5)
return false;
/* Machine-independent code would generate a frag here, but we
wish to handle it in a machine-dependent way. */
if (frag_now_fix () != 0)
{
if (frag_now->fr_type != rs_machine_dependent)
frag_wane (frag_now);
frag_new (0);
}
frag_grow (32);
align_frag = frag_now;
p = frag_var (rs_machine_dependent, 32, 32, max, NULL, n, NULL);
/* This must be the same as the frag to which a pointer was just
saved. */
if (p != align_frag->fr_literal)
abort ();
align_frag->tc_frag_data.is_insns = false;
return true;
}
else
return false;
}
/* Types of operand for parsing purposes. These are used as bit-masks
to tell tic6x_parse_operand what forms of operand are
permitted. */
#define TIC6X_OP_EXP 0x0001u
#define TIC6X_OP_REG 0x0002u
#define TIC6X_OP_REGPAIR 0x0004u
#define TIC6X_OP_IRP 0x0008u
#define TIC6X_OP_NRP 0x0010u
/* With TIC6X_OP_MEM_NOUNREG, the contents of a () offset are always
interpreted as an expression, which may be a symbol with the same
name as a register that ends up being implicitly DP-relative. With
TIC6X_OP_MEM_UNREG, the contents of a () offset are interpreted as
a register if they match one, and failing that as an expression,
which must be constant. */
#define TIC6X_OP_MEM_NOUNREG 0x0020u
#define TIC6X_OP_MEM_UNREG 0x0040u
#define TIC6X_OP_CTRL 0x0080u
#define TIC6X_OP_FUNC_UNIT 0x0100u
/* A register or register pair read by the assembler. */
typedef struct
{
/* The side the register is on (1 or 2). */
unsigned int side;
/* The register number (0 to 31). */
unsigned int num;
} tic6x_register;
/* Types of modification of a base address. */
typedef enum
{
tic6x_mem_mod_none,
tic6x_mem_mod_plus,
tic6x_mem_mod_minus,
tic6x_mem_mod_preinc,
tic6x_mem_mod_predec,
tic6x_mem_mod_postinc,
tic6x_mem_mod_postdec
} tic6x_mem_mod;
/* Scaled [] or unscaled () nature of an offset. */
typedef enum
{
tic6x_offset_none,
tic6x_offset_scaled,
tic6x_offset_unscaled
} tic6x_mem_scaling;
/* A memory operand read by the assembler. */
typedef struct
{
/* The base register. */
tic6x_register base_reg;
/* How the base register is modified. */
tic6x_mem_mod mod;
/* Whether there is an offset (required with plain "+" and "-"), and
whether it is scaled or unscaled if so. */
tic6x_mem_scaling scaled;
/* Whether the offset is a register (TRUE) or an expression
(FALSE). */
bool offset_is_reg;
/* The offset. */
union
{
expressionS exp;
tic6x_register reg;
} offset;
} tic6x_mem_ref;
/* A functional unit in SPMASK operands read by the assembler. */
typedef struct
{
/* The basic unit. */
tic6x_func_unit_base base;
/* The side (1 or 2). */
unsigned int side;
} tic6x_func_unit_operand;
/* An operand read by the assembler. */
typedef struct
{
/* The syntactic form of the operand, as one of the bit-masks
above. */
unsigned int form;
/* The operand value. */
union
{
/* An expression: TIC6X_OP_EXP. */
expressionS exp;
/* A register: TIC6X_OP_REG, TIC6X_OP_REGPAIR. */
tic6x_register reg;
/* A memory reference: TIC6X_OP_MEM_NOUNREG,
TIC6X_OP_MEM_UNREG. */
tic6x_mem_ref mem;
/* A control register: TIC6X_OP_CTRL. */
tic6x_ctrl_id ctrl;
/* A functional unit: TIC6X_OP_FUNC_UNIT. */
tic6x_func_unit_operand func_unit;
} value;
} tic6x_operand;
#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
/* Parse a register operand, or part of an operand, starting at *P.
If syntactically OK (including that the number is in the range 0 to
31, but not necessarily in range for this architecture), return
TRUE, putting the register side and number in *REG and update *P to
point immediately after the register number; otherwise return FALSE
without changing *P (but possibly changing *REG). Do not print any
diagnostics. */
static bool
tic6x_parse_register (char **p, tic6x_register *reg)
{
char *r = *p;
switch (*r)
{
case 'a':
case 'A':
reg->side = 1;
break;
case 'b':
case 'B':
reg->side = 2;
break;
default:
return false;
}
r++;
if (*r >= '0' && *r <= '9')
{
reg->num = *r - '0';
r++;
}
else
return false;
if (reg->num > 0 && *r >= '0' && *r <= '9')
{
reg->num = reg->num * 10 + (*r - '0');
r++;
}
if (*r >= '0' && *r <= '9')
return false;
if (reg->num >= 32)
return false;
*p = r;
return true;
}
/* Parse the initial two characters of a functional unit name starting
at *P. If OK, set *BASE and *SIDE and return true; otherwise,
return FALSE. */
static bool
tic6x_parse_func_unit_base (char *p, tic6x_func_unit_base *base,
unsigned int *side)
{
bool good_func_unit = true;
tic6x_func_unit_base maybe_base = tic6x_func_unit_nfu;
unsigned int maybe_side = 0;
switch (p[0])
{
case 'd':
case 'D':
maybe_base = tic6x_func_unit_d;
break;
case 'l':
case 'L':
maybe_base = tic6x_func_unit_l;
break;
case 'm':
case 'M':
maybe_base = tic6x_func_unit_m;
break;
case 's':
case 'S':
maybe_base = tic6x_func_unit_s;
break;
default:
good_func_unit = false;
break;
}
if (good_func_unit)
switch (p[1])
{
case '1':
maybe_side = 1;
break;
case '2':
maybe_side = 2;
break;
default:
good_func_unit = false;
break;
}
if (good_func_unit)
{
*base = maybe_base;
*side = maybe_side;
}
return good_func_unit;
}
/* Parse an operand starting at *P. If the operand parses OK, return
TRUE and store the value in *OP; otherwise return FALSE (possibly
changing *OP). In any case, update *P to point to the following
comma or end of line. The possible operand forms are given by
OP_FORMS. For diagnostics, this is operand OPNO of an opcode
starting at STR, length OPC_LEN. */
static bool
tic6x_parse_operand (char **p, tic6x_operand *op, unsigned int op_forms,
char *str, int opc_len, unsigned int opno)
{
bool operand_parsed = false;
char *q = *p;
if ((op_forms & (TIC6X_OP_MEM_NOUNREG | TIC6X_OP_MEM_UNREG))
== (TIC6X_OP_MEM_NOUNREG | TIC6X_OP_MEM_UNREG))
abort ();
/* Check for functional unit names for SPMASK and SPMASKR. */
if (!operand_parsed && (op_forms & TIC6X_OP_FUNC_UNIT))
{
tic6x_func_unit_base base = tic6x_func_unit_nfu;
unsigned int side = 0;
if (tic6x_parse_func_unit_base (q, &base, &side))
{
char *rq = q + 2;
skip_whitespace (rq);
if (is_end_of_line[(unsigned char) *rq] || *rq == ',')
{
op->form = TIC6X_OP_FUNC_UNIT;
op->value.func_unit.base = base;
op->value.func_unit.side = side;
operand_parsed = true;
q = rq;
}
}
}
/* Check for literal "irp". */
if (!operand_parsed && (op_forms & TIC6X_OP_IRP))
{
if ((q[0] == 'i' || q[0] == 'I')
&& (q[1] == 'r' || q[1] == 'R')
&& (q[2] == 'p' || q[2] == 'P'))
{
char *rq = q + 3;
skip_whitespace (rq);
if (is_end_of_line[(unsigned char) *rq] || *rq == ',')
{
op->form = TIC6X_OP_IRP;
operand_parsed = true;
q = rq;
}
}
}
/* Check for literal "nrp". */
if (!operand_parsed && (op_forms & TIC6X_OP_NRP))
{
if ((q[0] == 'n' || q[0] == 'N')
&& (q[1] == 'r' || q[1] == 'R')
&& (q[2] == 'p' || q[2] == 'P'))
{
char *rq = q + 3;
skip_whitespace (rq);
if (is_end_of_line[(unsigned char) *rq] || *rq == ',')
{
op->form = TIC6X_OP_NRP;
operand_parsed = true;
q = rq;
}
}
}
/* Check for control register names. */
if (!operand_parsed && (op_forms & TIC6X_OP_CTRL))
{
tic6x_ctrl_id crid;
for (crid = 0; crid < tic6x_ctrl_max; crid++)
{
size_t len = strlen (tic6x_ctrl_table[crid].name);
if (strncasecmp (tic6x_ctrl_table[crid].name, q, len) == 0)
{
char *rq = q + len;
skip_whitespace (rq);
if (is_end_of_line[(unsigned char) *rq] || *rq == ',')
{
op->form = TIC6X_OP_CTRL;
op->value.ctrl = crid;
operand_parsed = true;
q = rq;
if (!(tic6x_ctrl_table[crid].isa_variants & tic6x_features))
as_bad (_("control register '%s' not supported "
"on this architecture"),
tic6x_ctrl_table[crid].name);
}
}
}
}
/* See if this looks like a memory reference. */
if (!operand_parsed
&& (op_forms & (TIC6X_OP_MEM_NOUNREG | TIC6X_OP_MEM_UNREG)))
{
bool mem_ok = true;
char *mq = q;
tic6x_mem_mod mem_mod = tic6x_mem_mod_none;
tic6x_register base_reg;
bool require_offset, permit_offset;
tic6x_mem_scaling scaled;
bool offset_is_reg;
expressionS offset_exp;
tic6x_register offset_reg;
if (*mq == '*')
mq++;
else
mem_ok = false;
if (mem_ok)
{
skip_whitespace (mq);
switch (*mq)
{
case '+':
if (mq[1] == '+')
{
mem_mod = tic6x_mem_mod_preinc;
mq += 2;
}
else
{
mem_mod = tic6x_mem_mod_plus;
mq++;
}
break;
case '-':
if (mq[1] == '-')
{
mem_mod = tic6x_mem_mod_predec;
mq += 2;
}
else
{
mem_mod = tic6x_mem_mod_minus;
mq++;
}
break;
default:
break;
}
}
if (mem_ok)
{
skip_whitespace (mq);
mem_ok = tic6x_parse_register (&mq, &base_reg);
}
if (mem_ok && mem_mod == tic6x_mem_mod_none)
{
skip_whitespace (mq);
if (mq[0] == '+' && mq[1] == '+')
{
mem_mod = tic6x_mem_mod_postinc;
mq += 2;
}
else if (mq[0] == '-' && mq[1] == '-')
{
mem_mod = tic6x_mem_mod_postdec;
mq += 2;
}
}
if (mem_mod == tic6x_mem_mod_none)
permit_offset = false;
else
permit_offset = true;
if (mem_mod == tic6x_mem_mod_plus || mem_mod == tic6x_mem_mod_minus)
require_offset = true;
else
require_offset = false;
scaled = tic6x_offset_none;
offset_is_reg = false;
if (mem_ok && permit_offset)
{
char endc = 0;
skip_whitespace (mq);
switch (*mq)
{
case '[':
scaled = tic6x_offset_scaled;
mq++;
endc = ']';
break;
case '(':
scaled = tic6x_offset_unscaled;
mq++;
endc = ')';
break;
default:
break;
}
if (scaled != tic6x_offset_none)
{
skip_whitespace (mq);
if (scaled == tic6x_offset_scaled
|| (op_forms & TIC6X_OP_MEM_UNREG))
{
bool reg_ok;
char *rq = mq;
reg_ok = tic6x_parse_register (&rq, &offset_reg);
if (reg_ok)
{
skip_whitespace (rq);
if (*rq == endc)
{
mq = rq;
offset_is_reg = true;
}
}
}
if (!offset_is_reg)
{
char *save_input_line_pointer;
save_input_line_pointer = input_line_pointer;
input_line_pointer = mq;
expression (&offset_exp);
mq = input_line_pointer;
input_line_pointer = save_input_line_pointer;
}
skip_whitespace (mq);
if (*mq == endc)
mq++;
else
mem_ok = false;
}
}
if (mem_ok && require_offset && scaled == tic6x_offset_none)
mem_ok = false;
if (mem_ok)
{
skip_whitespace (mq);
if (!is_end_of_line[(unsigned char) *mq] && *mq != ',')
mem_ok = false;
}
if (mem_ok)
{
op->form = op_forms & (TIC6X_OP_MEM_NOUNREG | TIC6X_OP_MEM_UNREG);
op->value.mem.base_reg = base_reg;
op->value.mem.mod = mem_mod;
op->value.mem.scaled = scaled;
op->value.mem.offset_is_reg = offset_is_reg;
if (offset_is_reg)
op->value.mem.offset.reg = offset_reg;
else
op->value.mem.offset.exp = offset_exp;
operand_parsed = true;
q = mq;
if (base_reg.num >= tic6x_num_registers)
as_bad (_("register number %u not supported on this architecture"),
base_reg.num);
if (offset_is_reg && offset_reg.num >= tic6x_num_registers)
as_bad (_("register number %u not supported on this architecture"),
offset_reg.num);
}
}
/* See if this looks like a register or register pair. */
if (!operand_parsed && (op_forms & (TIC6X_OP_REG | TIC6X_OP_REGPAIR)))
{
tic6x_register first_reg, second_reg;
bool reg_ok;
char *rq = q;
reg_ok = tic6x_parse_register (&rq, &first_reg);
if (reg_ok)
{
if (*rq == ':' && (op_forms & TIC6X_OP_REGPAIR))
{
rq++;
reg_ok = tic6x_parse_register (&rq, &second_reg);
if (reg_ok)
{
skip_whitespace (rq);
if (is_end_of_line[(unsigned char) *rq] || *rq == ',')
{
if ((second_reg.num & 1)
|| (first_reg.num != second_reg.num + 1)
|| (first_reg.side != second_reg.side))
as_bad (_("register pair for operand %u of '%.*s'"
" not a valid even/odd pair"), opno,
opc_len, str);
op->form = TIC6X_OP_REGPAIR;
op->value.reg = second_reg;
operand_parsed = true;
q = rq;
}
}
}
else if (op_forms & TIC6X_OP_REG)
{
skip_whitespace (rq);
if (is_end_of_line[(unsigned char) *rq] || *rq == ',')
{
op->form = TIC6X_OP_REG;
op->value.reg = first_reg;
operand_parsed = true;
q = rq;
}
}
}
if (operand_parsed)
{
if (first_reg.num >= tic6x_num_registers)
as_bad (_("register number %u not supported on this architecture"),
first_reg.num);
if (op->form == TIC6X_OP_REGPAIR
&& second_reg.num >= tic6x_num_registers)
as_bad (_("register number %u not supported on this architecture"),
second_reg.num);
}
}
/* Otherwise, parse it as an expression. */
if (!operand_parsed && (op_forms & TIC6X_OP_EXP))
{
char *save_input_line_pointer;
save_input_line_pointer = input_line_pointer;
input_line_pointer = q;
op->form = TIC6X_OP_EXP;
expression (&op->value.exp);
q = input_line_pointer;
input_line_pointer = save_input_line_pointer;
operand_parsed = true;
}
if (operand_parsed)
{
/* Now the operand has been parsed, there must be nothing more
before the comma or end of line. */
skip_whitespace (q);
if (!is_end_of_line[(unsigned char) *q] && *q != ',')
{
operand_parsed = false;
as_bad (_("junk after operand %u of '%.*s'"), opno,
opc_len, str);
while (!is_end_of_line[(unsigned char) *q] && *q != ',')
q++;
}
}
else
{
/* This could not be parsed as any acceptable form of
operand. */
switch (op_forms)
{
case TIC6X_OP_REG | TIC6X_OP_REGPAIR:
as_bad (_("bad register or register pair for operand %u of '%.*s'"),
opno, opc_len, str);
break;
case TIC6X_OP_REG | TIC6X_OP_CTRL:
case TIC6X_OP_REG:
as_bad (_("bad register for operand %u of '%.*s'"),
opno, opc_len, str);
break;
case TIC6X_OP_REGPAIR:
as_bad (_("bad register pair for operand %u of '%.*s'"),
opno, opc_len, str);
break;
case TIC6X_OP_FUNC_UNIT:
as_bad (_("bad functional unit for operand %u of '%.*s'"),
opno, opc_len, str);
break;
default:
as_bad (_("bad operand %u of '%.*s'"),
opno, opc_len, str);
break;
}
while (!is_end_of_line[(unsigned char) *q] && *q != ',')
q++;
}
*p = q;
return operand_parsed;
}
/* Table of assembler operators and associated O_* values. */
typedef struct
{
const char *name;
operatorT op;
} tic6x_operator_table;
static const tic6x_operator_table tic6x_operators[] = {
#define O_dsbt_index O_md1
{ "dsbt_index", O_dsbt_index },
#define O_got O_md2
{ "got", O_got },
#define O_dpr_got O_md3
{ "dpr_got", O_dpr_got },
#define O_dpr_byte O_md4
{ "dpr_byte", O_dpr_byte },
#define O_dpr_hword O_md5
{ "dpr_hword", O_dpr_hword },
#define O_dpr_word O_md6
{ "dpr_word", O_dpr_word },
#define O_pcr_offset O_md7
{ "pcr_offset", O_pcr_offset }
};
/* Parse a name in some machine-specific way. Used on C6X to handle
assembler operators. */
int
tic6x_parse_name (const char *name, expressionS *exprP,
enum expr_mode mode ATTRIBUTE_UNUSED, char *nextchar)
{
char *p = input_line_pointer;
char c, *name_start, *name_end;
const char *inner_name;
unsigned int i;
operatorT op = O_illegal;
symbolS *sym, *op_sym = NULL;
if (*name != '$')
return 0;
for (i = 0; i < ARRAY_SIZE (tic6x_operators); i++)
if (strcasecmp (name + 1, tic6x_operators[i].name) == 0)
{
op = tic6x_operators[i].op;
break;
}
if (op == O_illegal)
return 0;
*input_line_pointer = *nextchar;
skip_whitespace (p);
if (*p != '(')
{
*input_line_pointer = 0;
return 0;
}
p++;
skip_whitespace (p);
if (!is_name_beginner (*p))
{
*input_line_pointer = 0;
return 0;
}
name_start = p;
p++;
while (is_part_of_name (*p))
p++;
name_end = p;
skip_whitespace (p);
if (op == O_pcr_offset)
{
char *op_name_start, *op_name_end;
if (*p != ',')
{
*input_line_pointer = 0;
return 0;
}
p++;
skip_whitespace (p);
if (!is_name_beginner (*p))
{
*input_line_pointer = 0;
return 0;
}
op_name_start = p;
p++;
while (is_part_of_name (*p))
p++;
op_name_end = p;
skip_whitespace (p);
c = *op_name_end;
*op_name_end = 0;
op_sym = symbol_find_or_make (op_name_start);
*op_name_end = c;
}
if (*p != ')')
{
*input_line_pointer = 0;
return 0;
}
input_line_pointer = p + 1;
*nextchar = *input_line_pointer;
*input_line_pointer = 0;
c = *name_end;
*name_end = 0;
inner_name = name_start;
if (op == O_dsbt_index && strcmp (inner_name, "__c6xabi_DSBT_BASE") != 0)
{
as_bad (_("$DSBT_INDEX must be used with __c6xabi_DSBT_BASE"));
inner_name = "__c6xabi_DSBT_BASE";
}
sym = symbol_find_or_make (inner_name);
*name_end = c;
exprP->X_op = op;
exprP->X_add_symbol = sym;
exprP->X_add_number = 0;
exprP->X_op_symbol = op_sym;
exprP->X_md = 0;
return 1;
}
/* Create a fixup for an expression. Same arguments as fix_new_exp,
plus FIX_ADDA which is TRUE for ADDA instructions (to indicate that
fixes resolving to constants should have those constants implicitly
shifted) and FALSE otherwise, but look for C6X-specific expression
types and adjust the relocations or give errors accordingly. */
static void
tic6x_fix_new_exp (fragS *frag, int where, int size, expressionS *exp,
int pcrel, bfd_reloc_code_real_type r_type,
bool fix_adda)
{
bfd_reloc_code_real_type new_reloc = BFD_RELOC_UNUSED;
symbolS *subsy = NULL;
fixS *fix;
switch (exp->X_op)
{
case O_dsbt_index:
switch (r_type)
{
case BFD_RELOC_C6000_SBR_U15_W:
new_reloc = BFD_RELOC_C6000_DSBT_INDEX;
break;
default:
as_bad (_("$DSBT_INDEX not supported in this context"));
return;
}
break;
case O_got:
switch (r_type)
{
case BFD_RELOC_C6000_SBR_U15_W:
new_reloc = BFD_RELOC_C6000_SBR_GOT_U15_W;
break;
default:
as_bad (_("$GOT not supported in this context"));
return;
}
break;
case O_dpr_got:
switch (r_type)
{
case BFD_RELOC_C6000_ABS_L16:
new_reloc = BFD_RELOC_C6000_SBR_GOT_L16_W;
break;
case BFD_RELOC_C6000_ABS_H16:
new_reloc = BFD_RELOC_C6000_SBR_GOT_H16_W;
break;
default:
as_bad (_("$DPR_GOT not supported in this context"));
return;
}
break;
case O_dpr_byte:
switch (r_type)
{
case BFD_RELOC_C6000_ABS_S16:
new_reloc = BFD_RELOC_C6000_SBR_S16;
break;
case BFD_RELOC_C6000_ABS_L16:
new_reloc = BFD_RELOC_C6000_SBR_L16_B;
break;
case BFD_RELOC_C6000_ABS_H16:
new_reloc = BFD_RELOC_C6000_SBR_H16_B;
break;
default:
as_bad (_("$DPR_BYTE not supported in this context"));
return;
}
break;
case O_dpr_hword:
switch (r_type)
{
case BFD_RELOC_C6000_ABS_L16:
new_reloc = BFD_RELOC_C6000_SBR_L16_H;
break;
case BFD_RELOC_C6000_ABS_H16:
new_reloc = BFD_RELOC_C6000_SBR_H16_H;
break;
default:
as_bad (_("$DPR_HWORD not supported in this context"));
return;
}
break;
case O_dpr_word:
switch (r_type)
{
case BFD_RELOC_C6000_ABS_L16:
new_reloc = BFD_RELOC_C6000_SBR_L16_W;
break;
case BFD_RELOC_C6000_ABS_H16:
new_reloc = BFD_RELOC_C6000_SBR_H16_W;
break;
default:
as_bad (_("$DPR_WORD not supported in this context"));
return;
}
break;
case O_pcr_offset:
subsy = exp->X_op_symbol;
switch (r_type)
{
case BFD_RELOC_C6000_ABS_S16:
case BFD_RELOC_C6000_ABS_L16:
new_reloc = BFD_RELOC_C6000_PCR_L16;
break;
case BFD_RELOC_C6000_ABS_H16:
new_reloc = BFD_RELOC_C6000_PCR_H16;
break;
default:
as_bad (_("$PCR_OFFSET not supported in this context"));
return;
}
break;
case O_symbol:
break;
default:
if (pcrel)
{
as_bad (_("invalid PC-relative operand"));
return;
}
break;
}
if (new_reloc == BFD_RELOC_UNUSED)
fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
else
fix = fix_new (frag, where, size, exp->X_add_symbol, exp->X_add_number,
pcrel, new_reloc);
fix->tc_fix_data.fix_subsy = subsy;
fix->tc_fix_data.fix_adda = fix_adda;
}
/* Generate a fix for a constant (.word etc.). Needed to ensure these
go through the error checking in tic6x_fix_new_exp. */
void
tic6x_cons_fix_new (fragS *frag, int where, int size, expressionS *exp,
bfd_reloc_code_real_type r_type)
{
switch (size)
{
case 1:
r_type = BFD_RELOC_8;
break;
case 2:
r_type = BFD_RELOC_16;
break;
case 4:
r_type = BFD_RELOC_32;
break;
default:
as_bad (_("no %d-byte relocations available"), size);
return;
}
tic6x_fix_new_exp (frag, where, size, exp, 0, r_type, false);
}
/* Initialize target-specific fix data. */
void
tic6x_init_fix_data (fixS *fixP)
{
fixP->tc_fix_data.fix_adda = false;
fixP->tc_fix_data.fix_subsy = NULL;
}
/* Return true if the fix can be handled by GAS, false if it must
be passed through to the linker. */
bool
tic6x_fix_adjustable (fixS *fixP)
{
switch (fixP->fx_r_type)
{
/* Adjust_reloc_syms doesn't know about the GOT. */
case BFD_RELOC_C6000_SBR_GOT_U15_W:
case BFD_RELOC_C6000_SBR_GOT_H16_W:
case BFD_RELOC_C6000_SBR_GOT_L16_W:
case BFD_RELOC_C6000_EHTYPE:
return 0;
case BFD_RELOC_C6000_PREL31:
return 0;
case BFD_RELOC_C6000_PCR_H16:
case BFD_RELOC_C6000_PCR_L16:
return 0;
default:
return 1;
}
}
/* Given the fine-grained form of an operand, return the coarse
(bit-mask) form. */
static unsigned int
tic6x_coarse_operand_form (tic6x_operand_form form)
{
switch (form)
{
case tic6x_operand_asm_const:
case tic6x_operand_link_const:
return TIC6X_OP_EXP;
case tic6x_operand_reg:
case tic6x_operand_xreg:
case tic6x_operand_dreg:
case tic6x_operand_areg:
case tic6x_operand_retreg:
return TIC6X_OP_REG;
case tic6x_operand_regpair:
case tic6x_operand_xregpair:
case tic6x_operand_dregpair:
return TIC6X_OP_REGPAIR;
case tic6x_operand_irp:
return TIC6X_OP_IRP;
case tic6x_operand_nrp:
return TIC6X_OP_NRP;
case tic6x_operand_ctrl:
return TIC6X_OP_CTRL;
case tic6x_operand_mem_short:
case tic6x_operand_mem_long:
case tic6x_operand_mem_deref:
return TIC6X_OP_MEM_NOUNREG;
case tic6x_operand_mem_ndw:
return TIC6X_OP_MEM_UNREG;
case tic6x_operand_func_unit:
return TIC6X_OP_FUNC_UNIT;
default:
abort ();
}
}
/* How an operand may match or not match a desired form. If different
instruction alternatives fail in different ways, the first failure
in this list determines the diagnostic. */
typedef enum
{
/* Matches. */
tic6x_match_matches,
/* Bad coarse form. */
tic6x_match_coarse,
/* Not constant. */
tic6x_match_non_const,
/* Register on wrong side. */
tic6x_match_wrong_side,
/* Not a valid address register. */
tic6x_match_bad_address,
/* Not a valid return address register. */
tic6x_match_bad_return,
/* Control register not readable. */
tic6x_match_ctrl_write_only,
/* Control register not writable. */
tic6x_match_ctrl_read_only,
/* Not a valid memory reference for this instruction. */
tic6x_match_bad_mem
} tic6x_operand_match;
/* Return whether an operand matches the given fine-grained form and
read/write usage, and, if it does not match, how it fails to match.
The main functional unit side is SIDE; the cross-path side is CROSS
(the same as SIDE if a cross path not used); the data side is
DATA_SIDE. */
static tic6x_operand_match
tic6x_operand_matches_form (const tic6x_operand *op, tic6x_operand_form form,
tic6x_rw rw, unsigned int side, unsigned int cross,
unsigned int data_side)
{
unsigned int coarse = tic6x_coarse_operand_form (form);
if (coarse != op->form)
return tic6x_match_coarse;
switch (form)
{
case tic6x_operand_asm_const:
if (op->value.exp.X_op == O_constant)
return tic6x_match_matches;
else
return tic6x_match_non_const;
case tic6x_operand_link_const:
case tic6x_operand_irp:
case tic6x_operand_nrp:
case tic6x_operand_func_unit:
/* All expressions are link-time constants, although there may
not be relocations to express them in the output file. "irp"
and "nrp" are unique operand values. All parsed functional
unit names are valid. */
return tic6x_match_matches;
case tic6x_operand_reg:
case tic6x_operand_regpair:
if (op->value.reg.side == side)
return tic6x_match_matches;
else
return tic6x_match_wrong_side;
case tic6x_operand_xreg:
case tic6x_operand_xregpair:
if (op->value.reg.side == cross)
return tic6x_match_matches;
else
return tic6x_match_wrong_side;
case tic6x_operand_dreg:
case tic6x_operand_dregpair:
if (op->value.reg.side == data_side)
return tic6x_match_matches;
else
return tic6x_match_wrong_side;
case tic6x_operand_areg:
if (op->value.reg.side != cross)
return tic6x_match_wrong_side;
else if (op->value.reg.side == 2
&& (op->value.reg.num == 14 || op->value.reg.num == 15))
return tic6x_match_matches;
else
return tic6x_match_bad_address;
case tic6x_operand_retreg:
if (op->value.reg.side != side)
return tic6x_match_wrong_side;
else if (op->value.reg.num != 3)
return tic6x_match_bad_return;
else
return tic6x_match_matches;
case tic6x_operand_ctrl:
switch (rw)
{
case tic6x_rw_read:
if (tic6x_ctrl_table[op->value.ctrl].rw == tic6x_rw_read
|| tic6x_ctrl_table[op->value.ctrl].rw == tic6x_rw_read_write)
return tic6x_match_matches;
else
return tic6x_match_ctrl_write_only;
case tic6x_rw_write:
if (tic6x_ctrl_table[op->value.ctrl].rw == tic6x_rw_write
|| tic6x_ctrl_table[op->value.ctrl].rw == tic6x_rw_read_write)
return tic6x_match_matches;
else
return tic6x_match_ctrl_read_only;
default:
abort ();
}
case tic6x_operand_mem_deref:
if (op->value.mem.mod != tic6x_mem_mod_none)
return tic6x_match_bad_mem;
else if (op->value.mem.scaled != tic6x_offset_none)
abort ();
else if (op->value.mem.base_reg.side != side)
return tic6x_match_bad_mem;
else
return tic6x_match_matches;
case tic6x_operand_mem_short:
case tic6x_operand_mem_ndw:
if (op->value.mem.base_reg.side != side)
return tic6x_match_bad_mem;
if (op->value.mem.mod == tic6x_mem_mod_none)
{
if (op->value.mem.scaled != tic6x_offset_none)
abort ();
return tic6x_match_matches;
}
if (op->value.mem.scaled == tic6x_offset_none)
{
if (op->value.mem.mod == tic6x_mem_mod_plus
|| op->value.mem.mod == tic6x_mem_mod_minus)
abort ();
return tic6x_match_matches;
}
if (op->value.mem.offset_is_reg)
{
if (op->value.mem.scaled == tic6x_offset_unscaled
&& form != tic6x_operand_mem_ndw)
abort ();
if (op->value.mem.offset.reg.side == side)
return tic6x_match_matches;
else
return tic6x_match_bad_mem;
}
else
{
if (op->value.mem.offset.exp.X_op == O_constant)
return tic6x_match_matches;
else
return tic6x_match_bad_mem;
}
case tic6x_operand_mem_long:
if (op->value.mem.base_reg.side == 2
&& (op->value.mem.base_reg.num == 14
|| op->value.mem.base_reg.num == 15))
{
switch (op->value.mem.mod)
{
case tic6x_mem_mod_none:
if (op->value.mem.scaled != tic6x_offset_none)
abort ();
return tic6x_match_matches;
case tic6x_mem_mod_plus:
if (op->value.mem.scaled == tic6x_offset_none)
abort ();
if (op->value.mem.offset_is_reg)
return tic6x_match_bad_mem;
else if (op->value.mem.scaled == tic6x_offset_scaled
&& op->value.mem.offset.exp.X_op != O_constant)
return tic6x_match_bad_mem;
else
return tic6x_match_matches;
case tic6x_mem_mod_minus:
case tic6x_mem_mod_preinc:
case tic6x_mem_mod_predec:
case tic6x_mem_mod_postinc:
case tic6x_mem_mod_postdec:
return tic6x_match_bad_mem;
default:
abort ();
}
}
else
return tic6x_match_bad_mem;
default:
abort ();
}
}
/* Return the number of bits shift used with DP-relative coding method
CODING. */
static unsigned int
tic6x_dpr_shift (tic6x_coding_method coding)
{
switch (coding)
{
case tic6x_coding_ulcst_dpr_byte:
return 0;
case tic6x_coding_ulcst_dpr_half:
return 1;
case tic6x_coding_ulcst_dpr_word:
return 2;
default:
abort ();
}
}
/* Return the relocation used with DP-relative coding method
CODING. */
static bfd_reloc_code_real_type
tic6x_dpr_reloc (tic6x_coding_method coding)
{
switch (coding)
{
case tic6x_coding_ulcst_dpr_byte:
return BFD_RELOC_C6000_SBR_U15_B;
case tic6x_coding_ulcst_dpr_half:
return BFD_RELOC_C6000_SBR_U15_H;
case tic6x_coding_ulcst_dpr_word:
return BFD_RELOC_C6000_SBR_U15_W;
default:
abort ();
}
}
/* Given a memory reference *MEM_REF as originally parsed, fill in
defaults for missing offsets. */
static void
tic6x_default_mem_ref (tic6x_mem_ref *mem_ref)
{
switch (mem_ref->mod)
{
case tic6x_mem_mod_none:
if (mem_ref->scaled != tic6x_offset_none)
abort ();
mem_ref->mod = tic6x_mem_mod_plus;
mem_ref->scaled = tic6x_offset_unscaled;
mem_ref->offset_is_reg = false;
memset (&mem_ref->offset.exp, 0, sizeof mem_ref->offset.exp);
mem_ref->offset.exp.X_op = O_constant;
mem_ref->offset.exp.X_add_number = 0;
mem_ref->offset.exp.X_unsigned = 0;
break;
case tic6x_mem_mod_plus:
case tic6x_mem_mod_minus:
if (mem_ref->scaled == tic6x_offset_none)
abort ();
break;
case tic6x_mem_mod_preinc:
case tic6x_mem_mod_predec:
case tic6x_mem_mod_postinc:
case tic6x_mem_mod_postdec:
if (mem_ref->scaled != tic6x_offset_none)
break;
mem_ref->scaled = tic6x_offset_scaled;
mem_ref->offset_is_reg = false;
memset (&mem_ref->offset.exp, 0, sizeof mem_ref->offset.exp);
mem_ref->offset.exp.X_op = O_constant;
mem_ref->offset.exp.X_add_number = 1;
mem_ref->offset.exp.X_unsigned = 0;
break;
default:
abort ();
}
}
/* Return the encoding in the 8-bit field of an SPMASK or SPMASKR
instruction of the specified UNIT, side SIDE. */
static unsigned int
tic6x_encode_spmask (tic6x_func_unit_base unit, unsigned int side)
{
switch (unit)
{
case tic6x_func_unit_l:
return 1 << (side - 1);
case tic6x_func_unit_s:
return 1 << (side + 1);
case tic6x_func_unit_d:
return 1 << (side + 3);
case tic6x_func_unit_m:
return 1 << (side + 5);
default:
abort ();
}
}
/* Try to encode the instruction with opcode number ID and operands
OPERANDS (number NUM_OPERANDS), creg value THIS_LINE_CREG and z
value THIS_LINE_Z; FUNC_UNIT_SIDE, FUNC_UNIT_CROSS and
FUNC_UNIT_DATA_SIDE describe the functional unit specification;
SPLOOP_II is the ii value from the previous SPLOOP-family
instruction, or 0 if not in such a loop; the only possible problems
are operands being out of range (they already match the
fine-grained form), and inappropriate predication. If this
succeeds, return the encoding and set *OK to true; otherwise return
0 and set *OK to FALSE. If a fix is needed, set *FIX_NEEDED to
true and fill in *FIX_EXP, *FIX_PCREL, *FX_R_TYPE and *FIX_ADDA.
Print error messages for failure if PRINT_ERRORS is true; the
opcode starts at STR and has length OPC_LEN. */
static unsigned int
tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
unsigned int num_operands, unsigned int this_line_creg,
unsigned int this_line_z, unsigned int func_unit_side,
unsigned int func_unit_cross,
unsigned int func_unit_data_side, int sploop_ii,
expressionS **fix_exp, int *fix_pcrel,
bfd_reloc_code_real_type *fx_r_type, bool *fix_adda,
bool *fix_needed, bool *ok,
bool print_errors, char *str, int opc_len)
{
const tic6x_opcode *opct;
const tic6x_insn_format *fmt;
unsigned int opcode_value;
unsigned int fld;
opct = &tic6x_opcode_table[id];
fmt = &tic6x_insn_format_table[opct->format];
opcode_value = fmt->cst_bits;
for (fld = 0; fld < opct->num_fixed_fields; fld++)
{
if (opct->fixed_fields[fld].min_val == opct->fixed_fields[fld].max_val)
{
const tic6x_insn_field *fldd;
fldd = tic6x_field_from_fmt (fmt, opct->fixed_fields[fld].field_id);
if (fldd == NULL)
abort ();
opcode_value |= opct->fixed_fields[fld].min_val << fldd->bitfields[0].low_pos;
}
}
for (fld = 0; fld < opct->num_variable_fields; fld++)
{
const tic6x_insn_field *fldd;
unsigned int value;
unsigned int opno;
unsigned int ffld;
offsetT sign_value;
unsigned int bits;
unsigned int fcyc_bits;
expressionS *expp;
expressionS ucexp;
tic6x_mem_ref mem;
fldd = tic6x_field_from_fmt (fmt, opct->variable_fields[fld].field_id);
if (fldd == NULL)
abort ();
opno = opct->variable_fields[fld].operand_num;
switch (opct->variable_fields[fld].coding_method)
{
case tic6x_coding_ucst:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
if (operands[opno].value.exp.X_op != O_constant)
abort ();
ucexp = operands[opno].value.exp;
unsigned_constant:
if (ucexp.X_add_number < 0
|| ucexp.X_add_number >= (1 << fldd->bitfields[0].width))
{
if (print_errors)
as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
opc_len, str);
*ok = false;
return 0;
}
value = ucexp.X_add_number;
break;
case tic6x_coding_scst:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
if (operands[opno].value.exp.X_op != O_constant)
{
value = 0;
/* Opcode table should not permit non-constants without
a known relocation for them. */
if (fldd->bitfields[0].low_pos != 7 || fldd->bitfields[0].width != 16)
abort ();
*fix_needed = true;
*fix_exp = &operands[opno].value.exp;
*fix_pcrel = 0;
*fx_r_type = BFD_RELOC_C6000_ABS_S16;
*fix_adda = false;
break;
}
sign_value = SEXT (operands[opno].value.exp.X_add_number);
signed_constant:
if (sign_value < -(1 << (fldd->bitfields[0].width - 1))
|| (sign_value >= (1 << (fldd->bitfields[0].width - 1))))
{
if (print_errors)
as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
opc_len, str);
*ok = false;
return 0;
}
value = sign_value + (1 << (fldd->bitfields[0].width - 1));
value ^= (1 << (fldd->bitfields[0].width - 1));
break;
case tic6x_coding_ucst_minus_one:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
if (operands[opno].value.exp.X_op != O_constant)
abort ();
if (operands[opno].value.exp.X_add_number <= 0
|| operands[opno].value.exp.X_add_number > (1 << fldd->bitfields[0].width))
{
if (print_errors)
as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
opc_len, str);
*ok = false;
return 0;
}
value = operands[opno].value.exp.X_add_number - 1;
break;
case tic6x_coding_scst_negate:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
if (operands[opno].value.exp.X_op != O_constant)
abort ();
sign_value = SEXT (-operands[opno].value.exp.X_add_number);
goto signed_constant;
case tic6x_coding_ulcst_dpr_byte:
case tic6x_coding_ulcst_dpr_half:
case tic6x_coding_ulcst_dpr_word:
bits = tic6x_dpr_shift (opct->variable_fields[fld].coding_method);
switch (operands[opno].form)
{
case TIC6X_OP_EXP:
if (operands[opno].value.exp.X_op == O_constant)
{
ucexp = operands[opno].value.exp;
goto unsigned_constant;
}
expp = &operands[opno].value.exp;
break;
case TIC6X_OP_MEM_NOUNREG:
mem = operands[opno].value.mem;
tic6x_default_mem_ref (&mem);
if (mem.offset_is_reg)
abort ();
if (mem.offset.exp.X_op == O_constant)
{
ucexp = mem.offset.exp;
if (mem.scaled == tic6x_offset_unscaled)
{
if (ucexp.X_add_number & ((1 << bits) - 1))
{
if (print_errors)
as_bad (_("offset in operand %u of '%.*s' not "
"divisible by %u"), opno + 1, opc_len,
str, 1u << bits);
*ok = false;
return 0;
}
ucexp.X_add_number >>= bits;
}
goto unsigned_constant;
}
if (mem.scaled != tic6x_offset_unscaled)
abort ();
if (operands[opno].value.mem.mod == tic6x_mem_mod_none
|| operands[opno].value.mem.scaled != tic6x_offset_unscaled
|| operands[opno].value.mem.offset_is_reg)
abort ();
expp = &operands[opno].value.mem.offset.exp;
break;
default:
abort ();
}
value = 0;
/* Opcode table should not use this encoding without a known
relocation. */
if (fldd->bitfields[0].low_pos != 8 || fldd->bitfields[0].width != 15)
abort ();
/* We do not check for offset divisibility here; such a
check is not needed at this point to encode the value,
and if there is eventually a problem it will be detected
either in md_apply_fix or at link time. */
*fix_needed = true;
*fix_exp = expp;
*fix_pcrel = 0;
*fx_r_type
= tic6x_dpr_reloc (opct->variable_fields[fld].coding_method);
if (operands[opno].form == TIC6X_OP_EXP)
*fix_adda = true;
else
*fix_adda = false;
break;
case tic6x_coding_lcst_low16:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
if (operands[opno].value.exp.X_op == O_constant)
value = operands[opno].value.exp.X_add_number & 0xffff;
else
{
value = 0;
/* Opcode table should not use this encoding without a
known relocation. */
if (fldd->bitfields[0].low_pos != 7 || fldd->bitfields[0].width != 16)
abort ();
*fix_needed = true;
*fix_exp = &operands[opno].value.exp;
*fix_pcrel = 0;
*fx_r_type = BFD_RELOC_C6000_ABS_L16;
*fix_adda = false;
}
break;
case tic6x_coding_lcst_high16:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
if (operands[opno].value.exp.X_op == O_constant)
value = (operands[opno].value.exp.X_add_number >> 16) & 0xffff;
else
{
value = 0;
/* Opcode table should not use this encoding without a
known relocation. */
if (fldd->bitfields[0].low_pos != 7 || fldd->bitfields[0].width != 16)
abort ();
*fix_needed = true;
*fix_exp = &operands[opno].value.exp;
*fix_pcrel = 0;
*fx_r_type = BFD_RELOC_C6000_ABS_H16;
*fix_adda = false;
}
break;
case tic6x_coding_pcrel:
case tic6x_coding_pcrel_half:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
value = 0;
*fix_needed = true;
*fix_exp = &operands[opno].value.exp;
*fix_pcrel = 1;
if (fldd->bitfields[0].low_pos == 7 && fldd->bitfields[0].width == 21)
*fx_r_type = BFD_RELOC_C6000_PCR_S21;
else if (fldd->bitfields[0].low_pos == 16 && fldd->bitfields[0].width == 12)
*fx_r_type = BFD_RELOC_C6000_PCR_S12;
else if (fldd->bitfields[0].low_pos == 13 && fldd->bitfields[0].width == 10)
*fx_r_type = BFD_RELOC_C6000_PCR_S10;
else if (fldd->bitfields[0].low_pos == 16 && fldd->bitfields[0].width == 7)
*fx_r_type = BFD_RELOC_C6000_PCR_S7;
else
/* Opcode table should not use this encoding without a
known relocation. */
abort ();
*fix_adda = false;
break;
case tic6x_coding_regpair_lsb:
switch (operands[opno].form)
{
case TIC6X_OP_REGPAIR:
value = operands[opno].value.reg.num;
break;
default:
abort ();
}
break;
case tic6x_coding_regpair_msb:
switch (operands[opno].form)
{
case TIC6X_OP_REGPAIR:
value = operands[opno].value.reg.num + 1;
break;
default:
abort ();
}
break;
case tic6x_coding_reg:
switch (operands[opno].form)
{
case TIC6X_OP_REG:
case TIC6X_OP_REGPAIR:
value = operands[opno].value.reg.num;
break;
case TIC6X_OP_MEM_NOUNREG:
case TIC6X_OP_MEM_UNREG:
value = operands[opno].value.mem.base_reg.num;
break;
default:
abort ();
}
break;
case tic6x_coding_areg:
switch (operands[opno].form)
{
case TIC6X_OP_REG:
value = (operands[opno].value.reg.num == 15 ? 1 : 0);
break;
case TIC6X_OP_MEM_NOUNREG:
value = (operands[opno].value.mem.base_reg.num == 15 ? 1 : 0);
break;
default:
abort ();
}
break;
case tic6x_coding_crlo:
if (operands[opno].form != TIC6X_OP_CTRL)
abort ();
value = tic6x_ctrl_table[operands[opno].value.ctrl].crlo;
break;
case tic6x_coding_crhi:
if (operands[opno].form != TIC6X_OP_CTRL)
abort ();
value = 0;
break;
case tic6x_coding_reg_shift:
if (operands[opno].form != TIC6X_OP_REGPAIR)
abort ();
value = operands[opno].value.reg.num >> 1;
break;
case tic6x_coding_mem_offset:
if (operands[opno].form != TIC6X_OP_MEM_NOUNREG)
abort ();
mem = operands[opno].value.mem;
tic6x_default_mem_ref (&mem);
if (mem.offset_is_reg)
{
if (mem.scaled != tic6x_offset_scaled)
abort ();
value = mem.offset.reg.num;
}
else
{
int scale;
if (mem.offset.exp.X_op != O_constant)
abort ();
switch (mem.scaled)
{
case tic6x_offset_scaled:
scale = 1;
break;
case tic6x_offset_unscaled:
scale = opct->operand_info[opno].size;
if (scale != 1 && scale != 2 && scale != 4 && scale != 8)
abort ();
break;
default:
abort ();
}
if (mem.offset.exp.X_add_number < 0
|| mem.offset.exp.X_add_number >= (1 << fldd->bitfields[0].width) * scale)
{
if (print_errors)
as_bad (_("offset in operand %u of '%.*s' out of range"),
opno + 1, opc_len, str);
*ok = false;
return 0;
}
if (mem.offset.exp.X_add_number % scale)
{
if (print_errors)
as_bad (_("offset in operand %u of '%.*s' not "
"divisible by %u"),
opno + 1, opc_len, str, scale);
*ok = false;
return 0;
}
value = mem.offset.exp.X_add_number / scale;
}
break;
case tic6x_coding_mem_offset_noscale:
if (operands[opno].form != TIC6X_OP_MEM_UNREG)
abort ();
mem = operands[opno].value.mem;
tic6x_default_mem_ref (&mem);
if (mem.offset_is_reg)
value = mem.offset.reg.num;
else
{
if (mem.offset.exp.X_op != O_constant)
abort ();
if (mem.offset.exp.X_add_number < 0
|| mem.offset.exp.X_add_number >= (1 << fldd->bitfields[0].width))
{
if (print_errors)
as_bad (_("offset in operand %u of '%.*s' out of range"),
opno + 1, opc_len, str);
*ok = false;
return 0;
}
value = mem.offset.exp.X_add_number;
}
break;
case tic6x_coding_mem_mode:
if (operands[opno].form != TIC6X_OP_MEM_NOUNREG
&& operands[opno].form != TIC6X_OP_MEM_UNREG)
abort ();
mem = operands[opno].value.mem;
tic6x_default_mem_ref (&mem);
switch (mem.mod)
{
case tic6x_mem_mod_plus:
value = 1;
break;
case tic6x_mem_mod_minus:
value = 0;
break;
case tic6x_mem_mod_preinc:
value = 9;
break;
case tic6x_mem_mod_predec:
value = 8;
break;
case tic6x_mem_mod_postinc:
value = 11;
break;
case tic6x_mem_mod_postdec:
value = 10;
break;
default:
abort ();
}
value += (mem.offset_is_reg ? 4 : 0);
break;
case tic6x_coding_scaled:
if (operands[opno].form != TIC6X_OP_MEM_UNREG)
abort ();
mem = operands[opno].value.mem;
tic6x_default_mem_ref (&mem);
switch (mem.scaled)
{
case tic6x_offset_unscaled:
value = 0;
break;
case tic6x_offset_scaled:
value = 1;
break;
default:
abort ();
}
break;
case tic6x_coding_spmask:
/* The position of such a field is hardcoded in the handling
of "||^". */
if (fldd->bitfields[0].low_pos != 18)
abort ();
value = 0;
for (opno = 0; opno < num_operands; opno++)
{
unsigned int v;
v = tic6x_encode_spmask (operands[opno].value.func_unit.base,
operands[opno].value.func_unit.side);
if (value & v)
{
if (print_errors)
as_bad (_("functional unit already masked for operand "
"%u of '%.*s'"), opno + 1, opc_len, str);
*ok = false;
return 0;
}
value |= v;
}
break;
case tic6x_coding_reg_unused:
/* This is a placeholder; correct handling goes along with
resource constraint checks. */
value = 0;
break;
case tic6x_coding_fstg:
case tic6x_coding_fcyc:
if (operands[opno].form != TIC6X_OP_EXP)
abort ();
if (operands[opno].value.exp.X_op != O_constant)
abort ();
if (!sploop_ii)
{
if (print_errors)
as_bad (_("'%.*s' instruction not in a software "
"pipelined loop"),
opc_len, str);
*ok = false;
return 0;
}
if (sploop_ii <= 1)
fcyc_bits = 0;
else if (sploop_ii <= 2)
fcyc_bits = 1;
else if (sploop_ii <= 4)
fcyc_bits = 2;
else if (sploop_ii <= 8)
fcyc_bits = 3;
else if (sploop_ii <= 14)
fcyc_bits = 4;
else
abort ();
if (fcyc_bits > fldd->bitfields[0].width)
abort ();
if (opct->variable_fields[fld].coding_method == tic6x_coding_fstg)
{
int i, t;
if (operands[opno].value.exp.X_add_number < 0
|| (operands[opno].value.exp.X_add_number
>= (1 << (fldd->bitfields[0].width - fcyc_bits))))
{
if (print_errors)
as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
opc_len, str);
*ok = false;
return 0;
}
value = operands[opno].value.exp.X_add_number;
for (t = 0, i = fcyc_bits; i < fldd->bitfields[0].width; i++)
{
t = (t << 1) | (value & 1);
value >>= 1;
}
value = t << fcyc_bits;
}
else
{
if (operands[opno].value.exp.X_add_number < 0
|| (operands[opno].value.exp.X_add_number >= sploop_ii))
{
if (print_errors)
as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
opc_len, str);
*ok = false;
return 0;
}
value = operands[opno].value.exp.X_add_number;
}
break;
case tic6x_coding_fu:
value = func_unit_side == 2 ? 1 : 0;
break;
case tic6x_coding_data_fu:
value = func_unit_data_side == 2 ? 1 : 0;
break;
case tic6x_coding_xpath:
value = func_unit_cross;
break;
default:
abort ();
}
for (ffld = 0; ffld < opct->num_fixed_fields; ffld++)
if ((opct->fixed_fields[ffld].field_id
== opct->variable_fields[fld].field_id)
&& (value < opct->fixed_fields[ffld].min_val
|| value > opct->fixed_fields[ffld].max_val))
{
if (print_errors)
as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
opc_len, str);
*ok = false;
return 0;
}
opcode_value |= value << fldd->bitfields[0].low_pos;
}
if (this_line_creg)
{
const tic6x_insn_field *creg;
const tic6x_insn_field *z;
creg = tic6x_field_from_fmt (fmt, tic6x_field_creg);
if (creg == NULL)
{
if (print_errors)
as_bad (_("instruction '%.*s' cannot be predicated"),
opc_len, str);
*ok = false;
return 0;
}
z = tic6x_field_from_fmt (fmt, tic6x_field_z);
/* If there is a creg field, there must be a z field; otherwise
there is an error in the format table. */
if (z == NULL)
abort ();
opcode_value |= this_line_creg << creg->bitfields[0].low_pos;
opcode_value |= this_line_z << z->bitfields[0].low_pos;
}
*ok = true;
return opcode_value;
}
/* Convert the target integer stored in N bytes in BUF to a host
integer, returning that value. */
static valueT
md_chars_to_number (char *buf, int n)
{
valueT result = 0;
unsigned char *p = (unsigned char *) buf;
if (target_big_endian)
{
while (n--)
{
result <<= 8;
result |= (*p++ & 0xff);
}
}
else
{
while (n--)
{
result <<= 8;
result |= (p[n] & 0xff);
}
}
return result;
}
/* Assemble the instruction starting at STR (an opcode, with the
opcode name all-lowercase). */
void
md_assemble (char *str)
{
char *p;
int opc_len;
bool this_line_parallel;
bool this_line_spmask;
unsigned int this_line_creg;
unsigned int this_line_z;
tic6x_label_list *this_insn_label_list;
segment_info_type *seginfo;
tic6x_opcode_list *opc_list, *opc;
tic6x_func_unit_base func_unit_base = tic6x_func_unit_nfu;
unsigned int func_unit_side = 0;
unsigned int func_unit_cross = 0;
unsigned int cross_side = 0;
unsigned int func_unit_data_side = 0;
unsigned int max_matching_opcodes, num_matching_opcodes;
tic6x_opcode_id *opcm = NULL;
unsigned int opc_rank[TIC6X_NUM_PREFER];
const tic6x_opcode *opct = NULL;
int min_rank, try_rank, max_rank;
bool num_operands_permitted[TIC6X_MAX_SOURCE_OPERANDS + 1] = { false };
unsigned int operand_forms[TIC6X_MAX_SOURCE_OPERANDS] = { 0 };
tic6x_operand operands[TIC6X_MAX_SOURCE_OPERANDS];
unsigned int max_num_operands;
unsigned int num_operands_read;
bool ok_this_arch, ok_this_fu, ok_this_arch_fu;
bool bad_operands = false;
unsigned int opcode_value;
bool encoded_ok;
bool fix_needed = false;
expressionS *fix_exp = NULL;
int fix_pcrel = 0;
bfd_reloc_code_real_type fx_r_type = BFD_RELOC_UNUSED;
bool fix_adda = false;
fragS *insn_frag;
char *output;
p = str;
while (*p && !is_end_of_line[(unsigned char) *p] && *p != ' ')
p++;
/* This function should only have been called when there is actually
an instruction to assemble. */
if (p == str)
abort ();
/* Now an instruction has been seen, architecture attributes from
.arch directives merge with rather than overriding the previous
value. */
tic6x_seen_insns = true;
/* If no .arch directives or -march options have been seen, we are
assessing instruction validity based on the C674X default, so set
the attribute accordingly. */
if (tic6x_arch_attribute == C6XABI_Tag_ISA_none)
tic6x_arch_attribute = C6XABI_Tag_ISA_C674X;
/* Reset global settings for parallel bars and predicates now to
avoid extra errors if there are problems with this opcode. */
this_line_parallel = tic6x_line_parallel;
this_line_spmask = tic6x_line_spmask;
this_line_creg = tic6x_line_creg;
this_line_z = tic6x_line_z;
tic6x_line_parallel = false;
tic6x_line_spmask = false;
tic6x_line_creg = 0;
tic6x_line_z = 0;
seginfo = seg_info (now_seg);
this_insn_label_list = seginfo->tc_segment_info_data.label_list;
seginfo->tc_segment_info_data.label_list = NULL;
opc_list = str_hash_find_n (opcode_hash, str, p - str);
if (opc_list == NULL)
{
char c = *p;
*p = 0;
as_bad (_("unknown opcode '%s'"), str);
*p = c;
return;
}
opc_len = p - str;
skip_whitespace (p);
/* See if there is something that looks like a functional unit
specifier. */
if (*p == '.')
{
bool good_func_unit;
tic6x_func_unit_base maybe_base = tic6x_func_unit_nfu;
unsigned int maybe_side = 0;
unsigned int maybe_cross = 0;
unsigned int maybe_data_side = 0;
good_func_unit = tic6x_parse_func_unit_base (p + 1, &maybe_base,
&maybe_side);
if (good_func_unit)
{
if (p[3] == ' ' || is_end_of_line[(unsigned char) p[3]])
p += 3;
else if ((p[3] == 'x' || p[3] == 'X')
&& (p[4] == ' ' || is_end_of_line[(unsigned char) p[4]]))
{
maybe_cross = 1;
p += 4;
}
else if (maybe_base == tic6x_func_unit_d
&& (p[3] == 't' || p[3] == 'T')
&& (p[4] == '1' || p[4] == '2')
&& (p[5] == ' ' || is_end_of_line[(unsigned char) p[5]]))
{
maybe_data_side = p[4] - '0';
p += 5;
}
else
good_func_unit = false;
}
if (good_func_unit)
{
func_unit_base = maybe_base;
func_unit_side = maybe_side;
func_unit_cross = maybe_cross;
cross_side = (func_unit_cross ? 3 - func_unit_side : func_unit_side);
func_unit_data_side = maybe_data_side;
}
skip_whitespace (p);
}
/* Determine which entries in the opcode table match, and the
associated permitted forms of operands. */
max_matching_opcodes = 0;
for (opc = opc_list; opc; opc = opc->next)
max_matching_opcodes++;
num_matching_opcodes = 0;
opcm = XNEWVEC (tic6x_opcode_id, max_matching_opcodes);
max_num_operands = 0;
ok_this_arch = false;
ok_this_fu = false;
ok_this_arch_fu = false;
for (opc = opc_list; opc; opc = opc->next)
{
unsigned int num_operands;
unsigned int i;
bool this_opc_arch_ok = true;
bool this_opc_fu_ok = true;
if (tic6x_insn_format_table[tic6x_opcode_table[opc->id].format].num_bits
!= 32)
continue;
if (!(tic6x_opcode_table[opc->id].isa_variants & tic6x_features))
this_opc_arch_ok = false;
if (tic6x_opcode_table[opc->id].func_unit != func_unit_base)
this_opc_fu_ok = false;
if (func_unit_side == 1
&& (tic6x_opcode_table[opc->id].flags & TIC6X_FLAG_SIDE_B_ONLY))
this_opc_fu_ok = false;
if (func_unit_cross
&& (tic6x_opcode_table[opc->id].flags & TIC6X_FLAG_NO_CROSS))
this_opc_fu_ok = false;
if (!func_unit_data_side
&& (tic6x_opcode_table[opc->id].flags
& (TIC6X_FLAG_LOAD | TIC6X_FLAG_STORE)))
this_opc_fu_ok = false;
if (func_unit_data_side
&& !(tic6x_opcode_table[opc->id].flags
& (TIC6X_FLAG_LOAD | TIC6X_FLAG_STORE)))
this_opc_fu_ok = false;
if (func_unit_data_side == 1
&& (tic6x_opcode_table[opc->id].flags & TIC6X_FLAG_SIDE_T2_ONLY))
this_opc_fu_ok = false;
if (this_opc_arch_ok)
ok_this_arch = true;
if (this_opc_fu_ok)
ok_this_fu = true;
if (!this_opc_arch_ok || !this_opc_fu_ok)
continue;
ok_this_arch_fu = true;
opcm[num_matching_opcodes] = opc->id;
num_matching_opcodes++;
num_operands = tic6x_opcode_table[opc->id].num_operands;
if (tic6x_opcode_table[opc->id].flags & TIC6X_FLAG_SPMASK)
{
if (num_operands != 1
|| (tic6x_opcode_table[opc->id].operand_info[0].form
!= tic6x_operand_func_unit))
abort ();
num_operands = 8;
for (i = 0; i < num_operands; i++)
{
operand_forms[i]
|= tic6x_coarse_operand_form (tic6x_operand_func_unit);
num_operands_permitted[i] = true;
}
}
else
{
for (i = 0; i < num_operands; i++)
{
tic6x_operand_form f
= tic6x_opcode_table[opc->id].operand_info[i].form;
operand_forms[i] |= tic6x_coarse_operand_form (f);
}
}
num_operands_permitted[num_operands] = true;
if (num_operands > max_num_operands)
max_num_operands = num_operands;
}
if (!ok_this_arch)
{
as_bad (_("'%.*s' instruction not supported on this architecture"),
opc_len, str);
free (opcm);
return;
}
if (!ok_this_fu)
{
as_bad (_("'%.*s' instruction not supported on this functional unit"),
opc_len, str);
free (opcm);
return;
}
if (!ok_this_arch_fu)
{
as_bad (_("'%.*s' instruction not supported on this functional unit"
" for this architecture"),
opc_len, str);
free (opcm);
return;
}
/* If there were no instructions matching the above availability
checks, we should now have given an error and returned. */
if (num_matching_opcodes == 0)
abort ();
num_operands_read = 0;
while (true)
{
skip_whitespace (p);
if (is_end_of_line[(unsigned char) *p])
{
if (num_operands_read > 0)
{
as_bad (_("missing operand after comma"));
bad_operands = true;
}
break;
}
if (max_num_operands == 0)
{
as_bad (_("too many operands to '%.*s'"), opc_len, str);
bad_operands = true;
break;
}
if (!tic6x_parse_operand (&p, &operands[num_operands_read],
operand_forms[num_operands_read], str, opc_len,
num_operands_read + 1))
bad_operands = true;
num_operands_read++;
if (is_end_of_line[(unsigned char) *p])
break;
else if (*p == ',')
{
p++;
if (num_operands_read == max_num_operands)
{
as_bad (_("too many operands to '%.*s'"), opc_len, str);
bad_operands = true;
break;
}
continue;
}
else
/* Operand parsing should consume whole operands. */
abort ();
}
if (!bad_operands && !num_operands_permitted[num_operands_read])
{
as_bad (_("bad number of operands to '%.*s'"), opc_len, str);
bad_operands = true;
}
if (!bad_operands)
{
/* Each operand is of the right syntactic form for some opcode
choice, and the number of operands is valid. Check that each
operand is OK in detail for some opcode choice with the right
number of operands. */
unsigned int i;
for (i = 0; i < num_operands_read; i++)
{
bool coarse_ok = false;
bool fine_ok = false;
tic6x_operand_match fine_failure = tic6x_match_matches;
unsigned int j;
for (j = 0; j < num_matching_opcodes; j++)
{
tic6x_operand_form f;
tic6x_rw rw;
unsigned int cf;
tic6x_operand_match this_fine_failure;
if (tic6x_opcode_table[opcm[j]].flags & TIC6X_FLAG_SPMASK)
{
f = tic6x_operand_func_unit;
rw = tic6x_rw_none;
}
else
{
if (tic6x_opcode_table[opcm[j]].num_operands
!= num_operands_read)
continue;
f = tic6x_opcode_table[opcm[j]].operand_info[i].form;
rw = tic6x_opcode_table[opcm[j]].operand_info[i].rw;
}
cf = tic6x_coarse_operand_form (f);
if (operands[i].form != cf)
continue;
coarse_ok = true;
this_fine_failure
= tic6x_operand_matches_form (&operands[i], f, rw,
func_unit_side,
cross_side,
func_unit_data_side);
if (this_fine_failure == tic6x_match_matches)
{
fine_ok = true;
break;
}
if (fine_failure == tic6x_match_matches
|| fine_failure > this_fine_failure)
fine_failure = this_fine_failure;
}
/* No instructions should have operand syntactic forms only
acceptable with certain numbers of operands, so no
diagnostic for this case. */
if (!coarse_ok)
abort ();
if (!fine_ok)
{
switch (fine_failure)
{
case tic6x_match_non_const:
as_bad (_("operand %u of '%.*s' not constant"),
i + 1, opc_len, str);
break;
case tic6x_match_wrong_side:
as_bad (_("operand %u of '%.*s' on wrong side"),
i + 1, opc_len, str);
break;
case tic6x_match_bad_return:
as_bad (_("operand %u of '%.*s' not a valid return "
"address register"),
i + 1, opc_len, str);
break;
case tic6x_match_ctrl_write_only:
as_bad (_("operand %u of '%.*s' is write-only"),
i + 1, opc_len, str);
break;
case tic6x_match_ctrl_read_only:
as_bad (_("operand %u of '%.*s' is read-only"),
i + 1, opc_len, str);
break;
case tic6x_match_bad_mem:
as_bad (_("operand %u of '%.*s' not a valid memory "
"reference"),
i + 1, opc_len, str);
break;
case tic6x_match_bad_address:
as_bad (_("operand %u of '%.*s' not a valid base "
"address register"),
i + 1, opc_len, str);
break;
default:
abort ();
}
bad_operands = true;
break;
}
}
}
if (!bad_operands)
{
/* Each operand is OK for some opcode choice, and the number of
operands is valid. Check whether there is an opcode choice
for which all operands are simultaneously valid. */
unsigned int i;
bool found_match = false;
for (i = 0; i < TIC6X_NUM_PREFER; i++)
opc_rank[i] = (unsigned int) -1;
min_rank = TIC6X_NUM_PREFER - 1;
max_rank = 0;
for (i = 0; i < num_matching_opcodes; i++)
{
unsigned int j;
bool this_matches = true;
if (!(tic6x_opcode_table[opcm[i]].flags & TIC6X_FLAG_SPMASK)
&& tic6x_opcode_table[opcm[i]].num_operands != num_operands_read)
continue;
for (j = 0; j < num_operands_read; j++)
{
tic6x_operand_form f;
tic6x_rw rw;
if (tic6x_opcode_table[opcm[i]].flags & TIC6X_FLAG_SPMASK)
{
f = tic6x_operand_func_unit;
rw = tic6x_rw_none;
}
else
{
f = tic6x_opcode_table[opcm[i]].operand_info[j].form;
rw = tic6x_opcode_table[opcm[i]].operand_info[j].rw;
}
if (tic6x_operand_matches_form (&operands[j], f, rw,
func_unit_side,
cross_side,
func_unit_data_side)
!= tic6x_match_matches)
{
this_matches = false;
break;
}
}
if (this_matches)
{
int rank = TIC6X_PREFER_VAL (tic6x_opcode_table[opcm[i]].flags);
if (rank < min_rank)
min_rank = rank;
if (rank > max_rank)
max_rank = rank;
if (opc_rank[rank] == (unsigned int) -1)
opc_rank[rank] = i;
else
/* The opcode table should provide a total ordering
for all cases where multiple matches may get
here. */
abort ();
found_match = true;
}
}
if (!found_match)
{
as_bad (_("bad operand combination for '%.*s'"), opc_len, str);
bad_operands = true;
}
}
if (bad_operands)
{
free (opcm);
return;
}
opcode_value = 0;
encoded_ok = false;
for (try_rank = max_rank; try_rank >= min_rank; try_rank--)
{
fix_needed = false;
if (opc_rank[try_rank] == (unsigned int) -1)
continue;
opcode_value = tic6x_try_encode (opcm[opc_rank[try_rank]], operands,
num_operands_read, this_line_creg,
this_line_z, func_unit_side,
func_unit_cross, func_unit_data_side,
seginfo->tc_segment_info_data.sploop_ii,
&fix_exp, &fix_pcrel, &fx_r_type,
&fix_adda, &fix_needed, &encoded_ok,
try_rank == min_rank,
str, opc_len);
if (encoded_ok)
{
opct = &tic6x_opcode_table[opcm[opc_rank[try_rank]]];
break;
}
}
free (opcm);
if (!encoded_ok)
return;
if (this_line_parallel)
{
insn_frag = seginfo->tc_segment_info_data.execute_packet_frag;
if (insn_frag == NULL)
{
as_bad (_("parallel instruction not following another instruction"));
return;
}
if (insn_frag->fr_fix >= 32)
{
as_bad (_("too many instructions in execute packet"));
return;
}
if (this_insn_label_list != NULL)
as_bad (_("label not at start of execute packet"));
if (opct->flags & TIC6X_FLAG_FIRST)
as_bad (_("'%.*s' instruction not at start of execute packet"),
opc_len, str);
*seginfo->tc_segment_info_data.last_insn_lsb |= 0x1;
output = insn_frag->fr_literal + insn_frag->fr_fix;
}
else
{
tic6x_label_list *l;
seginfo->tc_segment_info_data.spmask_addr = NULL;
seginfo->tc_segment_info_data.func_units_used = 0;
/* Start a new frag for this execute packet. */
if (frag_now_fix () != 0)
{
if (frag_now->fr_type != rs_machine_dependent)
frag_wane (frag_now);
frag_new (0);
}
frag_grow (32);
insn_frag = seginfo->tc_segment_info_data.execute_packet_frag = frag_now;
for (l = this_insn_label_list; l; l = l->next)
{
symbol_set_frag (l->label, frag_now);
S_SET_VALUE (l->label, 0);
S_SET_SEGMENT (l->label, now_seg);
}
tic6x_free_label_list (this_insn_label_list);
dwarf2_emit_insn (0);
output = frag_var (rs_machine_dependent, 32, 32, 0, NULL, 0, NULL);
/* This must be the same as the frag to which a pointer was just
saved. */
if (output != insn_frag->fr_literal)
abort ();
insn_frag->tc_frag_data.is_insns = true;
insn_frag->tc_frag_data.can_cross_fp_boundary
= tic6x_can_cross_fp_boundary;
}
if (func_unit_base != tic6x_func_unit_nfu)
{
unsigned int func_unit_enc;
func_unit_enc = tic6x_encode_spmask (func_unit_base, func_unit_side);
if (seginfo->tc_segment_info_data.func_units_used & func_unit_enc)
as_bad (_("functional unit already used in this execute packet"));
seginfo->tc_segment_info_data.func_units_used |= func_unit_enc;
}
if (opct->flags & TIC6X_FLAG_SPLOOP)
{
if (seginfo->tc_segment_info_data.sploop_ii)
as_bad (_("nested software pipelined loop"));
if (num_operands_read != 1
|| operands[0].form != TIC6X_OP_EXP
|| operands[0].value.exp.X_op != O_constant)
abort ();
seginfo->tc_segment_info_data.sploop_ii
= operands[0].value.exp.X_add_number;
}
else if (opct->flags & TIC6X_FLAG_SPKERNEL)
{
if (!seginfo->tc_segment_info_data.sploop_ii)
as_bad (_("'%.*s' instruction not in a software pipelined loop"),
opc_len, str);
seginfo->tc_segment_info_data.sploop_ii = 0;
}
if (this_line_spmask)
{
if (seginfo->tc_segment_info_data.spmask_addr == NULL)
as_bad (_("'||^' without previous SPMASK"));
else if (func_unit_base == tic6x_func_unit_nfu)
as_bad (_("cannot mask instruction using no functional unit"));
else
{
unsigned int spmask_opcode;
unsigned int mask_bit;
spmask_opcode
= md_chars_to_number (seginfo->tc_segment_info_data.spmask_addr,
4);
mask_bit = tic6x_encode_spmask (func_unit_base, func_unit_side);
mask_bit <<= 18;
if (spmask_opcode & mask_bit)
as_bad (_("functional unit already masked"));
spmask_opcode |= mask_bit;
md_number_to_chars (seginfo->tc_segment_info_data.spmask_addr,
spmask_opcode, 4);
}
}
record_alignment (now_seg, 5);
md_number_to_chars (output, opcode_value, 4);
if (fix_needed)
tic6x_fix_new_exp (insn_frag, output - insn_frag->fr_literal, 4, fix_exp,
fix_pcrel, fx_r_type, fix_adda);
insn_frag->fr_fix += 4;
insn_frag->fr_var -= 4;
seginfo->tc_segment_info_data.last_insn_lsb
= (target_big_endian ? output + 3 : output);
if (opct->flags & TIC6X_FLAG_SPMASK)
seginfo->tc_segment_info_data.spmask_addr = output;
}
/* Modify NEWVAL (32-bit) by inserting VALUE, shifted right by SHIFT
and the least significant BITS bits taken, at position POS. */
#define MODIFY_VALUE(NEWVAL, VALUE, SHIFT, POS, BITS) \
do { \
(NEWVAL) &= 0xffffffffU & ~(((1U << (BITS)) - 1) << (POS)); \
(NEWVAL) |= (((VALUE) >> (SHIFT)) & ((1U << (BITS)) - 1)) << (POS); \
} while (0)
/* Apply a fixup to the object file. */
void
md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
{
valueT value = *valP;
char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
value = SEXT (value);
*valP = value;
fixP->fx_offset = SEXT (fixP->fx_offset);
if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
fixP->fx_done = 1;
/* We do our own overflow checks. */
fixP->fx_no_overflow = 1;
switch (fixP->fx_r_type)
{
case BFD_RELOC_NONE:
case BFD_RELOC_C6000_EHTYPE:
/* Force output to the object file. */
fixP->fx_done = 0;
break;
case BFD_RELOC_32:
if (fixP->fx_done || !seg->use_rela_p)
md_number_to_chars (buf, value, 4);
break;
case BFD_RELOC_16:
if (fixP->fx_done || !seg->use_rela_p)
{
if (value + 0x8000 > 0xffff + 0x8000)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("value too large for 2-byte field"));
md_number_to_chars (buf, value, 2);
}
break;
case BFD_RELOC_8:
if (fixP->fx_done || !seg->use_rela_p)
{
if (value + 0x80 > 0xff + 0x80)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("value too large for 1-byte field"));
*buf = value;
}
break;
case BFD_RELOC_C6000_ABS_S16:
case BFD_RELOC_C6000_ABS_L16:
case BFD_RELOC_C6000_SBR_S16:
case BFD_RELOC_C6000_SBR_L16_B:
case BFD_RELOC_C6000_SBR_L16_H:
case BFD_RELOC_C6000_SBR_L16_W:
case BFD_RELOC_C6000_SBR_GOT_L16_W:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
int shift;
switch (fixP->fx_r_type)
{
case BFD_RELOC_C6000_SBR_L16_H:
shift = 1;
break;
case BFD_RELOC_C6000_SBR_L16_W:
case BFD_RELOC_C6000_SBR_GOT_L16_W:
shift = 2;
break;
default:
shift = 0;
break;
}
MODIFY_VALUE (newval, value, shift, 7, 16);
if ((value + 0x8000 > 0x7fff + 0x8000)
&& (fixP->fx_r_type == BFD_RELOC_C6000_ABS_S16
|| fixP->fx_r_type == BFD_RELOC_C6000_SBR_S16))
as_bad_where (fixP->fx_file, fixP->fx_line,
_("immediate offset out of range"));
md_number_to_chars (buf, newval, 4);
}
if (fixP->fx_done
&& fixP->fx_r_type != BFD_RELOC_C6000_ABS_S16
&& fixP->fx_r_type != BFD_RELOC_C6000_ABS_L16)
abort ();
break;
case BFD_RELOC_C6000_ABS_H16:
case BFD_RELOC_C6000_SBR_H16_B:
case BFD_RELOC_C6000_SBR_H16_H:
case BFD_RELOC_C6000_SBR_H16_W:
case BFD_RELOC_C6000_SBR_GOT_H16_W:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
int shift;
switch (fixP->fx_r_type)
{
case BFD_RELOC_C6000_SBR_H16_H:
shift = 17;
break;
case BFD_RELOC_C6000_SBR_H16_W:
case BFD_RELOC_C6000_SBR_GOT_H16_W:
shift = 18;
break;
default:
shift = 16;
break;
}
MODIFY_VALUE (newval, value, shift, 7, 16);
md_number_to_chars (buf, newval, 4);
}
if (fixP->fx_done && fixP->fx_r_type != BFD_RELOC_C6000_ABS_H16)
abort ();
break;
case BFD_RELOC_C6000_PCR_H16:
case BFD_RELOC_C6000_PCR_L16:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
int shift = fixP->fx_r_type == BFD_RELOC_C6000_PCR_H16 ? 16 : 0;
MODIFY_VALUE (newval, value, shift, 7, 16);
md_number_to_chars (buf, newval, 4);
}
break;
case BFD_RELOC_C6000_SBR_U15_B:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
MODIFY_VALUE (newval, value, 0, 8, 15);
if (value > 0x7fff)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("immediate offset out of range"));
md_number_to_chars (buf, newval, 4);
}
break;
case BFD_RELOC_C6000_SBR_U15_H:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
/* Constant ADDA operands, processed as constant when the
instruction is parsed, are encoded as-is rather than
shifted. If the operand of an ADDA instruction is now
constant (for example, the difference between two labels
found after the instruction), ensure it is encoded the
same way it would have been if the constant value had
been known when the instruction was parsed. */
if (fixP->tc_fix_data.fix_adda && fixP->fx_done)
value <<= 1;
MODIFY_VALUE (newval, value, 1, 8, 15);
if (value & 1)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("immediate offset not 2-byte-aligned"));
if (value > 0xfffe)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("immediate offset out of range"));
md_number_to_chars (buf, newval, 4);
}
break;
case BFD_RELOC_C6000_SBR_U15_W:
case BFD_RELOC_C6000_SBR_GOT_U15_W:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
/* Constant ADDA operands, processed as constant when the
instruction is parsed, are encoded as-is rather than
shifted. If the operand of an ADDA instruction is now
constant (for example, the difference between two labels
found after the instruction), ensure it is encoded the
same way it would have been if the constant value had
been known when the instruction was parsed. */
if (fixP->tc_fix_data.fix_adda && fixP->fx_done)
value <<= 2;
MODIFY_VALUE (newval, value, 2, 8, 15);
if (value & 3)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("immediate offset not 4-byte-aligned"));
if (value > 0x1fffc)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("immediate offset out of range"));
md_number_to_chars (buf, newval, 4);
}
if (fixP->fx_done && fixP->fx_r_type != BFD_RELOC_C6000_SBR_U15_W)
abort ();
break;
case BFD_RELOC_C6000_DSBT_INDEX:
if (value != 0)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("addend used with $DSBT_INDEX"));
if (fixP->fx_done)
abort ();
break;
case BFD_RELOC_C6000_PCR_S21:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
MODIFY_VALUE (newval, value, 2, 7, 21);
if (value & 3)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset not 4-byte-aligned"));
if (value + 0x400000 > 0x3ffffc + 0x400000)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset out of range"));
md_number_to_chars (buf, newval, 4);
}
break;
case BFD_RELOC_C6000_PCR_S12:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
MODIFY_VALUE (newval, value, 2, 16, 12);
if (value & 3)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset not 4-byte-aligned"));
if (value + 0x2000 > 0x1ffc + 0x2000)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset out of range"));
md_number_to_chars (buf, newval, 4);
}
break;
case BFD_RELOC_C6000_PCR_S10:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
MODIFY_VALUE (newval, value, 2, 13, 10);
if (value & 3)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset not 4-byte-aligned"));
if (value + 0x800 > 0x7fc + 0x800)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset out of range"));
md_number_to_chars (buf, newval, 4);
}
break;
case BFD_RELOC_C6000_PCR_S7:
if (fixP->fx_done || !seg->use_rela_p)
{
valueT newval = md_chars_to_number (buf, 4);
MODIFY_VALUE (newval, value, 2, 16, 7);
if (value & 3)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset not 4-byte-aligned"));
if (value + 0x100 > 0xfc + 0x100)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("PC-relative offset out of range"));
md_number_to_chars (buf, newval, 4);
}
break;
case BFD_RELOC_C6000_PREL31:
/* Force output to the object file. */
fixP->fx_done = 0;
break;
default:
abort ();
}
}
/* Convert a floating-point number to target (IEEE) format. */
const char *
md_atof (int type, char *litP, int *sizeP)
{
return ieee_md_atof (type, litP, sizeP, target_big_endian);
}
/* Adjust the frags in SECTION (see tic6x_md_finish). */
static void
tic6x_adjust_section (bfd *abfd ATTRIBUTE_UNUSED, segT section,
void *dummy ATTRIBUTE_UNUSED)
{
segment_info_type *info;
frchainS *frchp;
fragS *fragp;
bool have_code = false;
bool have_non_code = false;
info = seg_info (section);
if (info == NULL)
return;
for (frchp = info->frchainP; frchp; frchp = frchp->frch_next)
for (fragp = frchp->frch_root; fragp; fragp = fragp->fr_next)
switch (fragp->fr_type)
{
case rs_machine_dependent:
if (fragp->tc_frag_data.is_insns)
have_code = true;
break;
case rs_dummy:
case rs_fill:
if (fragp->fr_fix > 0)
have_non_code = true;
break;
default:
have_non_code = true;
break;
}
/* Process alignment requirements in a code-only section. */
if (have_code && !have_non_code)
{
/* If we need to insert an odd number of instructions to meet an
alignment requirement, there must have been an odd number of
instructions since the last 8-byte-aligned execute packet
boundary. So there must have been an execute packet with an
odd number (and so a number fewer than 8) of instructions
into which we can insert a NOP without breaking any previous
alignments.
If then we need to insert a number 2 mod 4 of instructions,
the number of instructions since the last 16-byte-aligned
execute packet boundary must be 2 mod 4. So between that
boundary and the following 8-byte-aligned boundary there must
either be at least one execute packet with 2-mod-4
instructions, or at least two with an odd number of
instructions; again, greedily inserting NOPs as soon as
possible suffices to meet the alignment requirement.
If then we need to insert 4 instructions, we look between the
last 32-byte-aligned boundary and the following
16-byte-aligned boundary. The sizes of the execute packets
in this range total 4 instructions mod 8, so again there is
room for greedy insertion of NOPs to meet the alignment
requirement, and before any intermediate point with 8-byte
(2-instruction) alignment requirement the sizes of execute
packets (and so the room for NOPs) will total 2 instructions
mod 4 so greedy insertion will not break such alignments.
So we can always meet these alignment requirements by
inserting NOPs in parallel with existing execute packets, and
by induction the approach described above inserts the minimum
number of such NOPs. */
/* The number of NOPs we are currently looking to insert, if we
have gone back to insert NOPs. */
unsigned int want_insert = 0;
/* Out of that number, the number inserted so far in the current
stage of the above algorithm. */
unsigned int want_insert_done_so_far = 0;
/* The position mod 32 at the start of the current frag. */
unsigned int pos = 0;
/* The locations in the frag chain of the most recent frags at
the start of which there is the given alignment. */
frchainS *frchp_last32, *frchp_last16, *frchp_last8;
fragS *fragp_last32, *fragp_last16, *fragp_last8;
unsigned int pos_last32, pos_last16, pos_last8;
frchp_last32 = frchp_last16 = frchp_last8 = info->frchainP;
fragp_last32 = fragp_last16 = fragp_last8 = info->frchainP->frch_root;
pos_last32 = pos_last16 = pos_last8 = 0;
for (frchp = info->frchainP; frchp; frchp = frchp->frch_next)
for (fragp = frchp->frch_root; fragp; fragp = fragp->fr_next)
look_at_frag:
{
bool go_back = false;
frchainS *frchp_next;
fragS *fragp_next;
if (fragp->fr_type != rs_machine_dependent)
continue;
if (fragp->tc_frag_data.is_insns
&& pos + fragp->fr_fix > 32
&& !fragp->tc_frag_data.can_cross_fp_boundary)
{
/* As described above, we should always have met an
alignment requirement by the time we come back to
it. */
if (want_insert)
abort ();
if (pos & 3)
abort ();
want_insert = (32 - pos) >> 2;
if (want_insert > 7)
abort ();
want_insert_done_so_far = 0;
go_back = true;
}
if (!fragp->tc_frag_data.is_insns)
{
unsigned int would_insert_bytes;
if (!(pos & ((1 << fragp->fr_offset) - 1)))
/* This alignment requirement is already met. */
continue;
/* As described above, we should always have met an
alignment requirement by the time we come back to
it. */
if (want_insert)
abort ();
/* We may not be able to meet this requirement within
the given number of characters. */
would_insert_bytes
= ((1 << fragp->fr_offset)
- (pos & ((1 << fragp->fr_offset) - 1)));
if (fragp->fr_subtype != 0
&& would_insert_bytes > fragp->fr_subtype)
continue;
/* An unmet alignment must be 8, 16 or 32 bytes;
smaller ones must always be met within code-only
sections and larger ones cause the section not to
be code-only. */
if (fragp->fr_offset != 3
&& fragp->fr_offset != 4
&& fragp->fr_offset != 5)
abort ();
if (would_insert_bytes & 3)
abort ();
want_insert = would_insert_bytes >> 2;
if (want_insert > 7)
abort ();
want_insert_done_so_far = 0;
go_back = true;
}
else if (want_insert && !go_back)
{
unsigned int num_insns = fragp->fr_fix >> 2;
unsigned int max_poss_nops = 8 - num_insns;
if (max_poss_nops)
{
unsigned int cur_want_nops, max_want_nops, do_nops, i;
if (want_insert & 1)
cur_want_nops = 1;
else if (want_insert & 2)
cur_want_nops = 2;
else if (want_insert & 4)
cur_want_nops = 4;
else
abort ();
max_want_nops = cur_want_nops - want_insert_done_so_far;
do_nops = (max_poss_nops < max_want_nops
? max_poss_nops
: max_want_nops);
for (i = 0; i < do_nops; i++)
{
md_number_to_chars (fragp->fr_literal + fragp->fr_fix,
0, 4);
if (target_big_endian)
fragp->fr_literal[fragp->fr_fix - 1] |= 0x1;
else
fragp->fr_literal[fragp->fr_fix - 4] |= 0x1;
fragp->fr_fix += 4;
fragp->fr_var -= 4;
}
want_insert_done_so_far += do_nops;
if (want_insert_done_so_far == cur_want_nops)
{
want_insert -= want_insert_done_so_far;
want_insert_done_so_far = 0;
if (want_insert)
go_back = true;
}
}
}
if (go_back)
{
if (want_insert & 1)
{
frchp = frchp_last8;
fragp = fragp_last8;
pos = pos_last8;
}
else if (want_insert & 2)
{
frchp = frchp_last8 = frchp_last16;
fragp = fragp_last8 = fragp_last16;
pos = pos_last8 = pos_last16;
}
else if (want_insert & 4)
{
frchp = frchp_last8 = frchp_last16 = frchp_last32;
fragp = fragp_last8 = fragp_last16 = fragp_last32;
pos = pos_last8 = pos_last16 = pos_last32;
}
else
abort ();
goto look_at_frag;
}
/* Update current position for moving past a code
frag. */
pos += fragp->fr_fix;
pos &= 31;
frchp_next = frchp;
fragp_next = fragp->fr_next;
if (fragp_next == NULL)
{
frchp_next = frchp->frch_next;
if (frchp_next != NULL)
fragp_next = frchp_next->frch_root;
}
if (!(pos & 7))
{
frchp_last8 = frchp_next;
fragp_last8 = fragp_next;
pos_last8 = pos;
}
if (!(pos & 15))
{
frchp_last16 = frchp_next;
fragp_last16 = fragp_next;
pos_last16 = pos;
}
if (!(pos & 31))
{
frchp_last32 = frchp_next;
fragp_last32 = fragp_next;
pos_last32 = pos;
}
}
}
/* Now convert the machine-dependent frags to machine-independent
ones. */
for (frchp = info->frchainP; frchp; frchp = frchp->frch_next)
for (fragp = frchp->frch_root; fragp; fragp = fragp->fr_next)
{
if (fragp->fr_type == rs_machine_dependent)
{
if (fragp->tc_frag_data.is_insns)
frag_wane (fragp);
else
{
fragp->fr_type = rs_align_code;
fragp->fr_var = 1;
*fragp->fr_literal = 0;
}
}
}
}
/* Initialize the machine-dependent parts of a frag. */
void
tic6x_frag_init (fragS *fragp)
{
fragp->tc_frag_data.is_insns = false;
fragp->tc_frag_data.can_cross_fp_boundary = false;
}
/* Set an attribute if it has not already been set by the user. */
static void
tic6x_set_attribute_int (int tag, int value)
{
if (tag < 1
|| tag >= NUM_KNOWN_OBJ_ATTRIBUTES)
abort ();
if (!tic6x_attributes_set_explicitly[tag])
if (!bfd_elf_add_proc_attr_int (stdoutput, tag, value))
as_fatal (_("error adding attribute: %s"),
bfd_errmsg (bfd_get_error ()));
}
/* Set object attributes deduced from the input file and command line
rather than given explicitly. */
static void
tic6x_set_attributes (void)
{
if (tic6x_arch_attribute == C6XABI_Tag_ISA_none)
tic6x_arch_attribute = C6XABI_Tag_ISA_C674X;
tic6x_set_attribute_int (Tag_ISA, tic6x_arch_attribute);
tic6x_set_attribute_int (Tag_ABI_DSBT, tic6x_dsbt);
tic6x_set_attribute_int (Tag_ABI_PID, tic6x_pid);
tic6x_set_attribute_int (Tag_ABI_PIC, tic6x_pic);
}
/* Do machine-dependent manipulations of the frag chains after all
input has been read and before the machine-independent sizing and
relaxing. */
void
tic6x_md_finish (void)
{
/* Set object attributes at this point if not explicitly set. */
tic6x_set_attributes ();
/* Meeting alignment requirements may require inserting NOPs in
parallel in execute packets earlier in the segment. Future
16-bit instruction generation involves whole-segment optimization
to determine the best choice and ordering of 32-bit or 16-bit
instructions. This doesn't fit will in the general relaxation
framework, so handle alignment and 16-bit instruction generation
here. */
bfd_map_over_sections (stdoutput, tic6x_adjust_section, NULL);
}
/* No machine-dependent frags at this stage; all converted in
tic6x_md_finish. */
void
md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec ATTRIBUTE_UNUSED,
fragS *fragp ATTRIBUTE_UNUSED)
{
abort ();
}
/* No machine-dependent frags at this stage; all converted in
tic6x_md_finish. */
int
md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
segT seg ATTRIBUTE_UNUSED)
{
abort ();
}
/* Put a number into target byte order. */
void
md_number_to_chars (char *buf, valueT val, int n)
{
if (target_big_endian)
number_to_chars_bigendian (buf, val, n);
else
number_to_chars_littleendian (buf, val, n);
}
/* Machine-dependent operand parsing not currently needed. */
void
md_operand (expressionS *op ATTRIBUTE_UNUSED)
{
}
/* PC-relative operands are relative to the start of the fetch
packet. */
long
tic6x_pcrel_from_section (fixS *fixp, segT sec)
{
if (fixp->fx_addsy != NULL
&& (!S_IS_DEFINED (fixp->fx_addsy)
|| S_GET_SEGMENT (fixp->fx_addsy) != sec))
return 0;
return (fixp->fx_where + fixp->fx_frag->fr_address) & ~(long) 0x1f;
}
/* Round up a section size to the appropriate boundary. */
valueT
md_section_align (segT segment ATTRIBUTE_UNUSED,
valueT size)
{
/* Round up section sizes to ensure that text sections consist of
whole fetch packets. */
int align = bfd_section_alignment (segment);
return ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
}
/* No special undefined symbol handling needed for now. */
symbolS *
md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
{
return NULL;
}
/* Translate internal representation of relocation info to BFD target
format. */
arelent *
tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
{
arelent *reloc;
asymbol *symbol;
bfd_reloc_code_real_type r_type;
reloc = XNEW (arelent);
reloc->sym_ptr_ptr = XNEW (asymbol *);
symbol = symbol_get_bfdsym (fixp->fx_addsy);
*reloc->sym_ptr_ptr = symbol;
reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
reloc->addend = (tic6x_generate_rela ? fixp->fx_offset : 0);
r_type = fixp->fx_r_type;
reloc->howto = bfd_reloc_type_lookup (stdoutput, r_type);
if (reloc->howto == NULL)
{
as_bad_where (fixp->fx_file, fixp->fx_line,
_("Cannot represent relocation type %s"),
bfd_get_reloc_code_name (r_type));
return NULL;
}
/* Correct for adjustments bfd_install_relocation will make. */
if (reloc->howto->pcrel_offset && reloc->howto->partial_inplace)
{
reloc->addend += reloc->address;
if (!bfd_is_com_section (bfd_asymbol_section (symbol)))
reloc->addend -= symbol->value;
}
if (r_type == BFD_RELOC_C6000_PCR_H16
|| r_type == BFD_RELOC_C6000_PCR_L16)
{
symbolS *t = fixp->tc_fix_data.fix_subsy;
segT sub_symbol_segment;
resolve_symbol_value (t);
sub_symbol_segment = S_GET_SEGMENT (t);
if (sub_symbol_segment == undefined_section)
as_bad_where (fixp->fx_file, fixp->fx_line,
_("undefined symbol %s in PCR relocation"),
S_GET_NAME (t));
else
{
reloc->addend = reloc->address & ~0x1F;
reloc->addend -= S_GET_VALUE (t);
}
}
return reloc;
}
/* Convert REGNAME to a DWARF-2 register number. */
int
tic6x_regname_to_dw2regnum (char *regname)
{
bool reg_ok;
tic6x_register reg;
char *rq = regname;
reg_ok = tic6x_parse_register (&rq, ®);
if (!reg_ok)
return -1;
switch (reg.side)
{
case 1: /* A regs. */
if (reg.num < 16)
return reg.num;
else if (reg.num < 32)
return (reg.num - 16) + 37;
else
return -1;
case 2: /* B regs. */
if (reg.num < 16)
return reg.num + 16;
else if (reg.num < 32)
return (reg.num - 16) + 53;
else
return -1;
default:
return -1;
}
}
/* Initialize the DWARF-2 unwind information for this procedure. */
void
tic6x_frame_initial_instructions (void)
{
/* CFA is initial stack pointer (B15). */
cfi_add_CFA_def_cfa (31, 0);
}
/* Start an exception table entry. If idx is nonzero this is an index table
entry. */
static void
tic6x_start_unwind_section (const segT text_seg, int idx)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
const char * text_name;
const char * prefix;
const char * prefix_once;
struct elf_section_match match;
size_t prefix_len;
size_t text_len;
char * sec_name;
size_t sec_name_len;
int type;
int flags;
int linkonce;
if (idx)
{
prefix = ELF_STRING_C6000_unwind;
prefix_once = ELF_STRING_C6000_unwind_once;
type = SHT_C6000_UNWIND;
}
else
{
prefix = ELF_STRING_C6000_unwind_info;
prefix_once = ELF_STRING_C6000_unwind_info_once;
type = SHT_PROGBITS;
}
text_name = segment_name (text_seg);
if (streq (text_name, ".text"))
text_name = "";
if (startswith (text_name, ".gnu.linkonce.t."))
{
prefix = prefix_once;
text_name += strlen (".gnu.linkonce.t.");
}
prefix_len = strlen (prefix);
text_len = strlen (text_name);
sec_name_len = prefix_len + text_len;
sec_name = XNEWVEC (char, sec_name_len + 1);
memcpy (sec_name, prefix, prefix_len);
memcpy (sec_name + prefix_len, text_name, text_len);
sec_name[prefix_len + text_len] = '\0';
flags = SHF_ALLOC;
linkonce = 0;
memset (&match, 0, sizeof (match));
/* Handle COMDAT group. */
if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
{
match.group_name = elf_group_name (text_seg);
if (match.group_name == NULL)
{
as_bad (_("group section `%s' has no group signature"),
segment_name (text_seg));
ignore_rest_of_line ();
return;
}
flags |= SHF_GROUP;
linkonce = 1;
}
obj_elf_change_section (sec_name, type, flags, 0, &match,
linkonce);
/* Set the section link for index tables. */
if (idx)
elf_linked_to_section (now_seg) = text_seg;
seg_info (now_seg)->tc_segment_info_data.text_unwind = unwind;
}
static const int
tic6x_unwind_frame_regs[TIC6X_NUM_UNWIND_REGS] =
/* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
{ 15, 31, 30, 29, 28, 27, 26, 19, 14, 13, 12, 11, 10 };
/* Register save offsets for __c6xabi_push_rts. */
static const int
tic6x_pop_rts_offset_little[TIC6X_NUM_UNWIND_REGS] =
/* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
{ -1, 1, 0, -3, -4, -7, -8,-11, -2, -5, -6, -9,-10};
static const int
tic6x_pop_rts_offset_big[TIC6X_NUM_UNWIND_REGS] =
/* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
{ -2, 1, 0, -4, -3, -8, -7,-12, -1, -6, -5,-10, -9};
/* Map from dwarf register number to unwind frame register number. */
static int
tic6x_unwind_reg_from_dwarf (int dwarf)
{
int reg;
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
{
if (tic6x_unwind_frame_regs[reg] == dwarf)
return reg;
}
return -1;
}
/* Unwinding bytecode definitions. */
#define UNWIND_OP_ADD_SP 0x00
#define UNWIND_OP_ADD_SP2 0xd2
#define UNWIND_OP2_POP 0x8000
#define UNWIND_OP2_POP_COMPACT 0xa000
#define UNWIND_OP_POP_REG 0xc0
#define UNWIND_OP_MV_FP 0xd0
#define UNWIND_OP_POP_RTS 0xd1
#define UNWIND_OP_RET 0xe0
/* Maximum stack adjustment for __c6xabi_unwind_cpp_pr3/4 */
#define MAX_COMPACT_SP_OFFSET (0x7f << 3)
static void
tic6x_flush_unwind_word (valueT data)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
char *ptr;
/* Create EXTAB entry if it does not exist. */
if (unwind->table_entry == NULL)
{
tic6x_start_unwind_section (unwind->saved_seg, 0);
frag_align (2, 0, 0);
record_alignment (now_seg, 2);
unwind->table_entry = expr_build_dot ();
ptr = frag_more (4);
unwind->frag_start = ptr;
}
else
{
/* Append additional word of data. */
ptr = frag_more (4);
}
md_number_to_chars (ptr, data, 4);
}
/* Add a single byte of unwinding data. */
static void
tic6x_unwind_byte (int byte)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
unwind->data_bytes++;
/* Only flush the first word after we know multiple words are required. */
if (unwind->data_bytes == 5)
{
if (unwind->personality_index == -1)
{
/* At this point we know we are too big for pr0. */
unwind->personality_index = 1;
tic6x_flush_unwind_word (0x81000000 | ((unwind->data >> 8) & 0xffff));
unwind->data = ((unwind->data & 0xff) << 8) | byte;
unwind->data_bytes++;
}
else
{
tic6x_flush_unwind_word (unwind->data);
unwind->data = byte;
}
}
else
{
unwind->data = (unwind->data << 8) | byte;
if ((unwind->data_bytes & 3) == 0 && unwind->data_bytes > 4)
{
tic6x_flush_unwind_word (unwind->data);
unwind->data = 0;
}
}
}
/* Add a two-byte unwinding opcode. */
static void
tic6x_unwind_2byte (int bytes)
{
tic6x_unwind_byte (bytes >> 8);
tic6x_unwind_byte (bytes & 0xff);
}
static void
tic6x_unwind_uleb (offsetT offset)
{
while (offset > 0x7f)
{
tic6x_unwind_byte ((offset & 0x7f) | 0x80);
offset >>= 7;
}
tic6x_unwind_byte (offset);
}
void
tic6x_cfi_startproc (void)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
unwind->personality_index = -1;
unwind->personality_routine = NULL;
if (unwind->table_entry)
as_bad (_("missing .endp before .cfi_startproc"));
unwind->table_entry = NULL;
unwind->data_bytes = -1;
}
static void
tic6x_output_exidx_entry (void)
{
char *ptr;
long where;
unsigned int marked_pr_dependency;
segT old_seg;
subsegT old_subseg;
tic6x_unwind_info *unwind = tic6x_get_unwind ();
old_seg = now_seg;
old_subseg = now_subseg;
/* Add index table entry. This is two words. */
tic6x_start_unwind_section (unwind->saved_seg, 1);
frag_align (2, 0, 0);
record_alignment (now_seg, 2);
ptr = frag_more (8);
memset (ptr, 0, 8);
where = frag_now_fix () - 8;
/* Self relative offset of the function start. */
fix_new (frag_now, where, 4, unwind->function_start, 0, 1,
BFD_RELOC_C6000_PREL31);
/* Indicate dependency on ABI-defined personality routines to the
linker, if it hasn't been done already. */
marked_pr_dependency
= seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
if (unwind->personality_index >= 0 && unwind->personality_index < 5
&& !(marked_pr_dependency & (1 << unwind->personality_index)))
{
static const char *const name[] =
{
"__c6xabi_unwind_cpp_pr0",
"__c6xabi_unwind_cpp_pr1",
"__c6xabi_unwind_cpp_pr2",
"__c6xabi_unwind_cpp_pr3",
"__c6xabi_unwind_cpp_pr4"
};
symbolS *pr = symbol_find_or_make (name[unwind->personality_index]);
fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
|= 1 << unwind->personality_index;
}
if (unwind->table_entry)
{
/* Self relative offset of the table entry. */
fix_new (frag_now, where + 4, 4, unwind->table_entry, 0, 1,
BFD_RELOC_C6000_PREL31);
}
else
{
/* Inline exception table entry. */
md_number_to_chars (ptr + 4, unwind->data, 4);
}
/* Restore the original section. */
subseg_set (old_seg, old_subseg);
}
static void
tic6x_output_unwinding (bool need_extab)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
unsigned safe_mask = unwind->safe_mask;
unsigned compact_mask = unwind->compact_mask;
unsigned reg_saved_mask = unwind->reg_saved_mask;
offsetT cfa_offset = unwind->cfa_offset;
long where;
int reg;
if (unwind->personality_index == -2)
{
/* Function can not be unwound. */
unwind->data = 1;
tic6x_output_exidx_entry ();
return;
}
if (unwind->personality_index == -1 && unwind->personality_routine == NULL)
{
/* Auto-select a personality routine if none specified. */
if (reg_saved_mask || cfa_offset >= MAX_COMPACT_SP_OFFSET)
unwind->personality_index = -1;
else if (safe_mask)
unwind->personality_index = 3;
else
unwind->personality_index = 4;
}
/* Calculate unwinding opcodes, and emit to EXTAB if necessary. */
unwind->table_entry = NULL;
if (unwind->personality_index == 3 || unwind->personality_index == 4)
{
if (cfa_offset >= MAX_COMPACT_SP_OFFSET)
{
as_bad (_("stack pointer offset too large for personality routine"));
return;
}
if (reg_saved_mask
|| (unwind->personality_index == 3 && compact_mask != 0)
|| (unwind->personality_index == 4 && safe_mask != 0))
{
as_bad (_("stack frame layout does not match personality routine"));
return;
}
unwind->data = (1u << 31) | (unwind->personality_index << 24);
if (unwind->cfa_reg == 15)
unwind->data |= 0x7f << 17;
else
unwind->data |= cfa_offset << (17 - 3);
if (unwind->personality_index == 3)
unwind->data |= safe_mask << 4;
else
unwind->data |= compact_mask << 4;
unwind->data |= unwind->return_reg;
unwind->data_bytes = 4;
}
else
{
if (unwind->personality_routine)
{
unwind->data = 0;
unwind->data_bytes = 5;
tic6x_flush_unwind_word (0);
/* First word is personality routine. */
where = frag_now_fix () - 4;
fix_new (frag_now, where, 4, unwind->personality_routine, 0, 1,
BFD_RELOC_C6000_PREL31);
}
else if (unwind->personality_index > 0)
{
unwind->data = 0x8000 | (unwind->personality_index << 8);
unwind->data_bytes = 2;
}
else /* pr0 or undecided */
{
unwind->data = 0x80;
unwind->data_bytes = 1;
}
if (unwind->return_reg != UNWIND_B3)
{
tic6x_unwind_byte (UNWIND_OP_RET | unwind->return_reg);
}
if (unwind->cfa_reg == 15)
{
tic6x_unwind_byte (UNWIND_OP_MV_FP);
}
else if (cfa_offset != 0)
{
cfa_offset >>= 3;
if (cfa_offset > 0x80)
{
tic6x_unwind_byte (UNWIND_OP_ADD_SP2);
tic6x_unwind_uleb (cfa_offset - 0x81);
}
else if (cfa_offset > 0x40)
{
tic6x_unwind_byte (UNWIND_OP_ADD_SP | 0x3f);
tic6x_unwind_byte (UNWIND_OP_ADD_SP | (cfa_offset - 0x40));
}
else
{
tic6x_unwind_byte (UNWIND_OP_ADD_SP | (cfa_offset - 1));
}
}
if (safe_mask)
tic6x_unwind_2byte (UNWIND_OP2_POP | unwind->safe_mask);
else if (unwind->pop_rts)
tic6x_unwind_byte (UNWIND_OP_POP_RTS);
else if (compact_mask)
tic6x_unwind_2byte (UNWIND_OP2_POP_COMPACT | unwind->compact_mask);
else if (reg_saved_mask)
{
offsetT cur_offset;
int val;
int last_val;
tic6x_unwind_byte (UNWIND_OP_POP_REG | unwind->saved_reg_count);
last_val = 0;
for (cur_offset = 0; unwind->saved_reg_count > 0; cur_offset -= 4)
{
val = 0xf;
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
{
if (!unwind->reg_saved[reg])
continue;
if (unwind->reg_offset[reg] == cur_offset)
{
unwind->saved_reg_count--;
val = reg;
break;
}
}
if ((cur_offset & 4) == 4)
tic6x_unwind_byte ((last_val << 4) | val);
else
last_val = val;
}
if ((cur_offset & 4) == 4)
tic6x_unwind_byte ((last_val << 4) | 0xf);
}
/* Pad with RETURN opcodes. */
while ((unwind->data_bytes & 3) != 0)
tic6x_unwind_byte (UNWIND_OP_RET | UNWIND_B3);
if (unwind->personality_index == -1 && unwind->personality_routine == NULL)
unwind->personality_index = 0;
}
/* Force creation of an EXTAB entry if an LSDA is required. */
if (need_extab && !unwind->table_entry)
{
if (unwind->data_bytes != 4)
abort ();
tic6x_flush_unwind_word (unwind->data);
}
else if (unwind->table_entry && !need_extab)
{
/* Add an empty descriptor if there is no user-specified data. */
char *ptr = frag_more (4);
md_number_to_chars (ptr, 0, 4);
}
/* Fill in length of unwinding bytecode. */
if (unwind->table_entry)
{
valueT tmp;
if (unwind->data_bytes > 0x400)
as_bad (_("too many unwinding instructions"));
if (unwind->personality_index == -1)
{
tmp = md_chars_to_number (unwind->frag_start + 4, 4);
tmp |= (valueT) ((unwind->data_bytes - 8) >> 2) << 24;
md_number_to_chars (unwind->frag_start + 4, tmp, 4);
}
else if (unwind->personality_index == 1 || unwind->personality_index == 2)
{
tmp = md_chars_to_number (unwind->frag_start, 4);
tmp |= ((unwind->data_bytes - 4) >> 2) << 16;
md_number_to_chars (unwind->frag_start, tmp, 4);
}
}
tic6x_output_exidx_entry ();
}
/* FIXME: This will get horribly confused if cfi directives are emitted for
function epilogue. */
void
tic6x_cfi_endproc (struct fde_entry *fde)
{
tic6x_unwind_info *unwind = tic6x_get_unwind ();
struct cfi_insn_data *insn;
int reg;
unsigned safe_mask = 0;
unsigned compact_mask = 0;
unsigned reg_saved_mask = 0;
offsetT cfa_offset = 0;
offsetT save_offset = 0;
unwind->cfa_reg = 31;
unwind->return_reg = UNWIND_B3;
unwind->saved_reg_count = 0;
unwind->pop_rts = false;
unwind->saved_seg = now_seg;
unwind->saved_subseg = now_subseg;
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
unwind->reg_saved[reg] = false;
/* Scan FDE instructions to build up stack frame layout. */
for (insn = fde->data; insn; insn = insn->next)
{
switch (insn->insn)
{
case DW_CFA_advance_loc:
break;
case DW_CFA_def_cfa:
unwind->cfa_reg = insn->u.ri.reg;
cfa_offset = insn->u.ri.offset;
break;
case DW_CFA_def_cfa_register:
unwind->cfa_reg = insn->u.r;
break;
case DW_CFA_def_cfa_offset:
cfa_offset = insn->u.i;
break;
case DW_CFA_undefined:
case DW_CFA_same_value:
reg = tic6x_unwind_reg_from_dwarf (insn->u.r);
if (reg >= 0)
unwind->reg_saved[reg] = false;
break;
case DW_CFA_offset:
reg = tic6x_unwind_reg_from_dwarf (insn->u.ri.reg);
if (reg < 0)
{
as_bad (_("unable to generate unwinding opcode for reg %d"),
insn->u.ri.reg);
return;
}
unwind->reg_saved[reg] = true;
unwind->reg_offset[reg] = insn->u.ri.offset;
if (insn->u.ri.reg == UNWIND_B3)
unwind->return_reg = UNWIND_B3;
break;
case DW_CFA_register:
if (insn->u.rr.reg1 != 19)
{
as_bad (_("unable to generate unwinding opcode for reg %d"),
insn->u.rr.reg1);
return;
}
reg = tic6x_unwind_reg_from_dwarf (insn->u.rr.reg2);
if (reg < 0)
{
as_bad (_("unable to generate unwinding opcode for reg %d"),
insn->u.rr.reg2);
return;
}
unwind->return_reg = reg;
unwind->reg_saved[UNWIND_B3] = false;
if (unwind->reg_saved[reg])
{
as_bad (_("unable to restore return address from "
"previously restored reg"));
return;
}
break;
case DW_CFA_restore:
case DW_CFA_remember_state:
case DW_CFA_restore_state:
case DW_CFA_GNU_window_save:
case CFI_escape:
case CFI_val_encoded_addr:
as_bad (_("unhandled CFA insn for unwinding (%d)"), insn->insn);
break;
default:
abort ();
}
}
if (unwind->cfa_reg != 15 && unwind->cfa_reg != 31)
{
as_bad (_("unable to generate unwinding opcode for frame pointer reg %d"),
unwind->cfa_reg);
return;
}
if (unwind->cfa_reg == 15)
{
if (cfa_offset != 0)
{
as_bad (_("unable to generate unwinding opcode for "
"frame pointer offset"));
return;
}
}
else
{
if ((cfa_offset & 7) != 0)
{
as_bad (_("unwound stack pointer not doubleword aligned"));
return;
}
}
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
{
if (unwind->reg_saved[reg])
reg_saved_mask |= 1 << (TIC6X_NUM_UNWIND_REGS - (reg + 1));
}
/* Check for standard "safe debug" frame layout */
if (reg_saved_mask)
{
save_offset = 0;
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
{
if (!unwind->reg_saved[reg])
continue;
if (target_big_endian
&& reg < TIC6X_NUM_UNWIND_REGS - 1
&& unwind->reg_saved[reg + 1]
&& tic6x_unwind_frame_regs[reg]
== tic6x_unwind_frame_regs[reg + 1] + 1
&& (tic6x_unwind_frame_regs[reg] & 1) == 1
&& (save_offset & 4) == 4)
{
/* Swapped pair */
if (save_offset != unwind->reg_offset[reg + 1]
|| save_offset - 4 != unwind->reg_offset[reg])
break;
save_offset -= 8;
reg++;
}
else
{
if (save_offset != unwind->reg_offset[reg])
break;
save_offset -= 4;
}
}
if (reg == TIC6X_NUM_UNWIND_REGS)
{
safe_mask = reg_saved_mask;
reg_saved_mask = 0;
}
}
/* Check for compact frame layout. */
if (reg_saved_mask)
{
save_offset = 0;
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
{
int reg2;
if (!unwind->reg_saved[reg])
continue;
if (reg < TIC6X_NUM_UNWIND_REGS - 1)
{
reg2 = reg + 1;
if (!unwind->reg_saved[reg2]
|| tic6x_unwind_frame_regs[reg]
!= tic6x_unwind_frame_regs[reg2] + 1
|| (tic6x_unwind_frame_regs[reg2] & 1) != 0
|| save_offset == 0)
reg2 = -1;
}
else
reg2 = -1;
if (reg2 >= 0)
{
int high_offset;
if (target_big_endian)
high_offset = 4; /* lower address = positive stack offset. */
else
high_offset = 0;
if (save_offset + 4 - high_offset != unwind->reg_offset[reg]
|| save_offset + high_offset != unwind->reg_offset[reg2])
{
break;
}
reg++;
}
else
{
if (save_offset != unwind->reg_offset[reg])
break;
}
save_offset -= 8;
}
if (reg == TIC6X_NUM_UNWIND_REGS)
{
compact_mask = reg_saved_mask;
reg_saved_mask = 0;
}
}
/* Check for __c6xabi_pop_rts format */
if (reg_saved_mask == 0x17ff)
{
const int *pop_rts_offset = target_big_endian
? tic6x_pop_rts_offset_big
: tic6x_pop_rts_offset_little;
save_offset = 0;
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
{
if (reg == UNWIND_B15)
continue;
if (unwind->reg_offset[reg] != pop_rts_offset[reg] * 4)
break;
}
if (reg == TIC6X_NUM_UNWIND_REGS)
{
unwind->pop_rts = true;
reg_saved_mask = 0;
}
}
/* If all else fails then describe the frame manually. */
if (reg_saved_mask)
{
save_offset = 0;
for (reg = 0; reg < TIC6X_NUM_UNWIND_REGS; reg++)
{
if (!unwind->reg_saved[reg])
continue;
unwind->saved_reg_count++;
/* Encoding uses 4 bits per word, so size of unwinding opcode data
limits the save area size. The exact cap will be figured out
later due to overflow, the 0x800 here is just a quick sanity
check to weed out obviously excessive offsets. */
if (unwind->reg_offset[reg] > 0 || unwind->reg_offset[reg] < -0x800
|| (unwind->reg_offset[reg] & 3) != 0)
{
as_bad (_("stack frame layout too complex for unwinder"));
return;
}
if (unwind->reg_offset[reg] < save_offset)
save_offset = unwind->reg_offset[reg] - 4;
}
}
/* Align to 8-byte boundary (stack grows towards negative offsets). */
save_offset &= ~7;
if (unwind->cfa_reg == 31 && !reg_saved_mask)
{
cfa_offset += save_offset;
if (cfa_offset < 0)
{
as_bad (_("unwound frame has negative size"));
return;
}
}
unwind->safe_mask = safe_mask;
unwind->compact_mask = compact_mask;
unwind->reg_saved_mask = reg_saved_mask;
unwind->cfa_offset = cfa_offset;
unwind->function_start = fde->start_address;
}
|