aboutsummaryrefslogtreecommitdiff
path: root/gas/config/tc-visium.c
blob: fcb128a1abbcc93babc03b71e11098c723e1cc39 (plain)
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
/* This is the machine dependent code of the Visium Assembler.

   Copyright (C) 2005-2024 Free Software Foundation, Inc.

   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 2, 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 this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#include "as.h"
#include "safe-ctype.h"
#include "subsegs.h"
#include "obstack.h"

#include "opcode/visium.h"
#include "elf/visium.h"
#include "dwarf2dbg.h"
#include "dw2gencfi.h"

/* Relocations and fixups:

   There are two different cases where an instruction or data
   directive operand requires relocation, or fixup.

   1. Relative branch instructions, take an 16-bit signed word
   offset. The formula for computing the offset is this:

    offset = (destination - pc) / 4

   Branch instructions never branch to a label not declared
   locally, so the actual offset can always be computed by the assembler.
   However, we provide a relocation type to support this.

   2. Load literal instructions, such as MOVIU, which take a 16-bit
   literal operand. The literal may be the top or bottom half of
   a 32-bit value computed by the assembler, or by the linker. We provide
   two relocation types here.

   3. Data items (long, word and byte) preset with a value computed by
   the linker.  */


/* This string holds the chars that always start a comment. If the
   pre-processor is disabled, these aren't very useful.  */
const char comment_chars[] = "!;";

/* This array holds the chars that only start a comment at the beginning
   of a line.  If the line seems to have the form '# 123 filename' .line
   and .file directives will appear in the pre-processed output. Note that
   input_file.c hand checks for '#' at the beginning of the first line of
   the input file. This is because the compiler outputs #NO_APP at the
   beginning of its output. Also note that comments like this one will
   always work.  */
const char line_comment_chars[] = "#!;";
const char line_separator_chars[] = "";

/* Chars that can be used to separate mantissa from exponent in floating point
   numbers.  */
const char EXP_CHARS[] = "eE";

/* Chars that mean this number is a floating point constant, as in
   "0f12.456" or "0d1.2345e12".

   ...Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
   changed in read.c. Ideally it shouldn't have to know about it at all,
   but nothing is ideal around here.  */
const char FLT_CHARS[] = "rRsSfFdDxXeE";

/* The size of a relocation record.  */
const int md_reloc_size = 8;

/* The architecture for which we are assembling.  */
enum visium_arch_val
{
  VISIUM_ARCH_DEF,
  VISIUM_ARCH_MCM24,
  VISIUM_ARCH_MCM,
  VISIUM_ARCH_GR6
};

static enum visium_arch_val visium_arch = VISIUM_ARCH_DEF;

/* The opcode architecture for which we are assembling.  In contrast to the
   previous one, this only determines which instructions are supported.  */
static enum visium_opcode_arch_val visium_opcode_arch = VISIUM_OPCODE_ARCH_DEF;

/* Flags to set in the ELF header e_flags field.  */
static flagword visium_flags = 0;

/* More than this number of nops in an alignment op gets a branch instead.  */
static unsigned int nop_limit = 5;


/* Translate internal representation of relocation info to BFD target
   format.  */
arelent *
tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
{
  arelent *reloc;
  bfd_reloc_code_real_type code;

  reloc = XNEW (arelent);

  reloc->sym_ptr_ptr = XNEW (asymbol *);
  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;

  switch (fixp->fx_r_type)
    {
    case BFD_RELOC_8:
    case BFD_RELOC_16:
    case BFD_RELOC_32:
    case BFD_RELOC_8_PCREL:
    case BFD_RELOC_16_PCREL:
    case BFD_RELOC_32_PCREL:
    case BFD_RELOC_VISIUM_HI16:
    case BFD_RELOC_VISIUM_LO16:
    case BFD_RELOC_VISIUM_IM16:
    case BFD_RELOC_VISIUM_REL16:
    case BFD_RELOC_VISIUM_HI16_PCREL:
    case BFD_RELOC_VISIUM_LO16_PCREL:
    case BFD_RELOC_VISIUM_IM16_PCREL:
    case BFD_RELOC_VTABLE_INHERIT:
    case BFD_RELOC_VTABLE_ENTRY:
      code = fixp->fx_r_type;
      break;
    default:
      as_bad_where (fixp->fx_file, fixp->fx_line,
		    "internal error: unknown relocation type %d (`%s')",
		    fixp->fx_r_type,
		    bfd_get_reloc_code_name (fixp->fx_r_type));
      return 0;
    }

  reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  if (reloc->howto == 0)
    {
      as_bad_where (fixp->fx_file, fixp->fx_line,
		    "internal error: can't export reloc type %d (`%s')",
		    fixp->fx_r_type, bfd_get_reloc_code_name (code));
      return 0;
    }

  /* Write the addend.  */
  if (reloc->howto->pc_relative == 0)
    reloc->addend = fixp->fx_addnumber;
  else
    reloc->addend = fixp->fx_offset;

  return reloc;
}

static void visium_rdata (int);

static void visium_update_parity_bit (char *);
static char *parse_exp (char *, expressionS *);

/* This table describes all the machine specific pseudo-ops the assembler
   has to support, and that aren't handled elsewhere. The fields are:

   1: Pseudo-op name without dot.
   2: Function to call to execute this pseudo-op.
   3: Integer arg to pass to the function.  */
const pseudo_typeS md_pseudo_table[] =
{
  {"align", s_align_bytes, 0},
  {"noopt", s_ignore, 0},
  {"optim", s_ignore, 0},
  {"rdata", visium_rdata, 0},
  {"rodata", visium_rdata, 0},
  {0, 0, 0}
};


static void
visium_rdata (int xxx)
{
  char *save_line = input_line_pointer;
  static char section[] = ".rodata\n";

  /* Just pretend this is .section .rodata */
  input_line_pointer = section;
  obj_elf_section (xxx);
  input_line_pointer = save_line;
}

/* Align a section.  */
valueT
md_section_align (asection *seg, valueT addr)
{
  int align = bfd_section_alignment (seg);

  return ((addr + (1 << align) - 1) & -(1 << align));
}

void
md_number_to_chars (char *buf, valueT val, int n)
{
  number_to_chars_bigendian (buf, val, n);
}

symbolS *
md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
{
  return 0;
}

/* The parse options.  */
const char *md_shortopts = "m:";

struct option md_longopts[] =
{
  {NULL, no_argument, NULL, 0}
};

size_t md_longopts_size = sizeof (md_longopts);

struct visium_option_table
{
  char *option;			/* Option name to match.  */
  char *help;			/* Help information.  */
  int *var;			/* Variable to change.  */
  int value;			/* To what to change it.  */
  char *deprecated;		/* If non-null, print this message. */
};

static struct visium_option_table visium_opts[] =
{
  {NULL, NULL, NULL, 0, NULL}
};

struct visium_arch_option_table
{
  const char *name;
  enum visium_arch_val value;
};

static struct visium_arch_option_table visium_archs[] =
{
  {"mcm24", VISIUM_ARCH_MCM24},
  {"mcm",   VISIUM_ARCH_MCM},
  {"gr5",   VISIUM_ARCH_MCM},
  {"gr6",   VISIUM_ARCH_GR6},
};

struct visium_long_option_table
{
  const char *option;			/* Substring to match.  */
  const char *help;			/* Help information.  */
  int (*func) (const char *subopt);	/* Function to decode sub-option.  */
  const char *deprecated;		/* If non-null, print this message.  */
};

static int
visium_parse_arch (const char *str)
{
  unsigned int i;

  if (strlen (str) == 0)
    {
      as_bad ("missing architecture name `%s'", str);
      return 0;
    }

  for (i = 0; i < ARRAY_SIZE (visium_archs); i++)
    if (strcmp (visium_archs[i].name, str) == 0)
      {
	visium_arch = visium_archs[i].value;
	return 1;
      }

  as_bad ("unknown architecture `%s'\n", str);
  return 0;
}

static struct visium_long_option_table visium_long_opts[] =
{
  {"mtune=", "<arch_name>\t assemble for architecture <arch name>",
   visium_parse_arch, NULL},
  {NULL, NULL, NULL, NULL}
};

int
md_parse_option (int c, const char *arg)
{
  struct visium_option_table *opt;
  struct visium_long_option_table *lopt;

  switch (c)
    {
    case 'a':
      /* Listing option.  Just ignore these, we don't support additional
         ones.  */
      return 0;

    default:
      for (opt = visium_opts; opt->option != NULL; opt++)
	{
	  if (c == opt->option[0]
	      && ((arg == NULL && opt->option[1] == 0)
		  || strcmp (arg, opt->option + 1) == 0))
	    {
	      /* If the option is deprecated, tell the user.  */
	      if (opt->deprecated != NULL)
		as_tsktsk ("option `-%c%s' is deprecated: %s", c,
			   arg ? arg : "", opt->deprecated);

	      if (opt->var != NULL)
		*opt->var = opt->value;

	      return 1;
	    }
	}

      for (lopt = visium_long_opts; lopt->option != NULL; lopt++)
	{
	  /* These options are expected to have an argument.  */
	  if (c == lopt->option[0]
	      && arg != NULL
	      && strncmp (arg, lopt->option + 1,
			  strlen (lopt->option + 1)) == 0)
	    {
	      /* If the option is deprecated, tell the user.  */
	      if (lopt->deprecated != NULL)
		as_tsktsk ("option `-%c%s' is deprecated: %s", c, arg,
			   lopt->deprecated);

	      /* Call the sup-option parser.  */
	      return lopt->func (arg + strlen (lopt->option) - 1);
	    }
	}

      return 0;
    }

  return 1;
}

void
md_show_usage (FILE * fp)
{
  struct visium_option_table *opt;
  struct visium_long_option_table *lopt;

  fprintf (fp, " Visium-specific assembler options:\n");

  for (opt = visium_opts; opt->option != NULL; opt++)
    if (opt->help != NULL)
      fprintf (fp, "  -%-23s%s\n", opt->option, opt->help);

  for (lopt = visium_long_opts; lopt->option != NULL; lopt++)
    if (lopt->help != NULL)
      fprintf (fp, "  -%s%s\n", lopt->option, lopt->help);

}

/* Interface to relax_segment.  */

/* Return the estimate of the size of a machine dependent frag
   before any relaxing is done.  It may also create any necessary
   relocations.  */
int
md_estimate_size_before_relax (fragS * fragP,
			       segT segment ATTRIBUTE_UNUSED)
{
  fragP->fr_var = 4;
  return 4;
}

/* Get the address of a symbol during relaxation.  From tc-arm.c.  */
static addressT
relaxed_symbol_addr (fragS *fragp, long stretch)
{
  fragS *sym_frag;
  addressT addr;
  symbolS *sym;

  sym = fragp->fr_symbol;
  sym_frag = symbol_get_frag (sym);
  know (S_GET_SEGMENT (sym) != absolute_section
	|| sym_frag == &zero_address_frag);
  addr = S_GET_VALUE (sym) + fragp->fr_offset;

  /* If frag has yet to be reached on this pass, assume it will
     move by STRETCH just as we did.  If this is not so, it will
     be because some frag between grows, and that will force
     another pass.  */
  if (stretch != 0
      && sym_frag->relax_marker != fragp->relax_marker)
    {
      fragS *f;

      /* Adjust stretch for any alignment frag.  Note that if have
	 been expanding the earlier code, the symbol may be
	 defined in what appears to be an earlier frag.  FIXME:
	 This doesn't handle the fr_subtype field, which specifies
	 a maximum number of bytes to skip when doing an
	 alignment.  */
      for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
	{
	  if (f->fr_type == rs_align || f->fr_type == rs_align_code)
	    {
	      if (stretch < 0)
		stretch = - ((- stretch)
			     & ~ ((1 << (int) f->fr_offset) - 1));
	      else
		stretch &= ~ ((1 << (int) f->fr_offset) - 1);
	      if (stretch == 0)
		break;
	    }
	}
      if (f != NULL)
	addr += stretch;
    }

  return addr;
}

/* Relax a machine dependent frag.  This returns the amount by which
   the current size of the frag should change.  */
int
visium_relax_frag (asection *sec, fragS *fragP, long stretch)
{
  int old_size, new_size;
  addressT addr;

  /* We only handle relaxation for the BRR instruction.  */
  gas_assert (fragP->fr_subtype == mode_ci);

  if (!S_IS_DEFINED (fragP->fr_symbol)
      || sec != S_GET_SEGMENT (fragP->fr_symbol)
      || S_IS_WEAK (fragP->fr_symbol))
    return 0;

  old_size = fragP->fr_var;
  addr = relaxed_symbol_addr (fragP, stretch);

  /* If the target is the address of the instruction, we'll insert a NOP.  */
  if (addr == fragP->fr_address + fragP->fr_fix)
    new_size = 8;
  else
    new_size = 4;

  fragP->fr_var = new_size;
  return new_size - old_size;
}

/* Convert a machine dependent frag.  */
void
md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
		 fragS * fragP)
{
  char *buf = &fragP->fr_literal[0] + fragP->fr_fix;
  expressionS exp;
  fixS *fixP;

  /* We only handle relaxation for the BRR instruction.  */
  gas_assert (fragP->fr_subtype == mode_ci);

  /* Insert the NOP if requested.  */
  if (fragP->fr_var == 8)
    {
      memcpy (buf + 4, buf, 4);
      memset (buf, 0, 4);
      fragP->fr_fix += 4;
    }

  exp.X_op = O_symbol;
  exp.X_add_symbol = fragP->fr_symbol;
  exp.X_add_number = fragP->fr_offset;

  /* Now we can create the relocation at the correct offset.  */
  fixP = fix_new_exp (fragP, fragP->fr_fix, 4, &exp, 1, BFD_RELOC_VISIUM_REL16);
  fixP->fx_file = fragP->fr_file;
  fixP->fx_line = fragP->fr_line;
  fragP->fr_fix += 4;
  fragP->fr_var = 0;
}

/* The location from which a PC relative jump should be calculated,
   given a PC relative jump reloc.  */
long
visium_pcrel_from_section (fixS *fixP, segT sec)
{
  if (fixP->fx_addsy != (symbolS *) NULL
      && (!S_IS_DEFINED (fixP->fx_addsy)
	  || S_GET_SEGMENT (fixP->fx_addsy) != sec))
    {
      /* The symbol is undefined (or is defined but not in this section).
         Let the linker figure it out.  */
      return 0;
    }

  /* Return the address of the instruction.  */
  return fixP->fx_where + fixP->fx_frag->fr_address;
}

/* Indicate whether a fixup against a locally defined
   symbol should be adjusted to be against the section
   symbol.  */
bool
visium_fix_adjustable (fixS *fix)
{
  /* We need the symbol name for the VTABLE entries.  */
  return (fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
	  && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY);
}

/* Update the parity bit of the 4-byte instruction in BUF.  */
static void
visium_update_parity_bit (char *buf)
{
  int p1 = (buf[0] & 0x7f) ^ buf[1] ^ buf[2] ^ buf[3];
  int p2 = 0;
  int i;

  for (i = 1; i <= 8; i++)
    {
      p2 ^= (p1 & 1);
      p1 >>= 1;
    }

  buf[0] = (buf[0] & 0x7f) | ((p2 << 7) & 0x80);
}

/* This is called from HANDLE_ALIGN in write.c.  Fill in the contents
   of an rs_align_code fragment.  */
void
visium_handle_align (fragS *fragP)
{
  valueT count
    = fragP->fr_next->fr_address - (fragP->fr_address + fragP->fr_fix);
  valueT fix = count & 3;
  char *p = fragP->fr_literal + fragP->fr_fix;

  if (fix)
    {
      memset (p, 0, fix);
      p += fix;
      count -= fix;
      fragP->fr_fix += fix;
    }

  if (count == 0)
    return;

  fragP->fr_var = 4;

  if (count > 4 * nop_limit && count <= 131068)
    {
      struct frag *rest;

      /* Make a branch, then follow with nops.  Insert another
         frag to handle the nops.  */
      md_number_to_chars (p, 0x78000000 + (count >> 2), 4);
      visium_update_parity_bit (p);

      rest = xmalloc (SIZEOF_STRUCT_FRAG + 4);
      memcpy (rest, fragP, SIZEOF_STRUCT_FRAG);
      fragP->fr_next = rest;
      rest->fr_address += rest->fr_fix + 4;
      rest->fr_fix = 0;
      /* If we leave the next frag as rs_align_code we'll come here
	 again, resulting in a bunch of branches rather than a
	 branch followed by nops.  */
      rest->fr_type = rs_align;
      p = rest->fr_literal;
    }

  memset (p, 0, 4);
}

/* Apply a fixS to the frags, now that we know the value it ought to
   hold.  */
void
md_apply_fix (fixS * fixP, valueT * value, segT segment)
{
  char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  offsetT val;
  long insn;

  val = *value;

  gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);

  /* Remember value for tc_gen_reloc.  */
  fixP->fx_addnumber = val;

  /* Since DIFF_EXPR_OK is defined, .-foo gets turned into PC
     relative relocs. If this has happened, a non-PC relative
     reloc must be reinstalled with its PC relative version here.  */
  if (fixP->fx_pcrel)
    {
      switch (fixP->fx_r_type)
	{
	case BFD_RELOC_8:
	  fixP->fx_r_type = BFD_RELOC_8_PCREL;
	  break;
	case BFD_RELOC_16:
	  fixP->fx_r_type = BFD_RELOC_16_PCREL;
	  break;
	case BFD_RELOC_32:
	  fixP->fx_r_type = BFD_RELOC_32_PCREL;
	  break;
	case BFD_RELOC_VISIUM_HI16:
	  fixP->fx_r_type = BFD_RELOC_VISIUM_HI16_PCREL;
	  break;
	case BFD_RELOC_VISIUM_LO16:
	  fixP->fx_r_type = BFD_RELOC_VISIUM_LO16_PCREL;
	  break;
	case BFD_RELOC_VISIUM_IM16:
	  fixP->fx_r_type = BFD_RELOC_VISIUM_IM16_PCREL;
	  break;
	default:
	  break;
	}
    }

  /* If this is a data relocation, just output VAL.  */
  switch (fixP->fx_r_type)
    {
    case BFD_RELOC_8:
    case BFD_RELOC_8_PCREL:
      md_number_to_chars (buf, val, 1);
      break;
    case BFD_RELOC_16:
    case BFD_RELOC_16_PCREL:
      md_number_to_chars (buf, val, 2);
      break;
    case BFD_RELOC_32:
    case BFD_RELOC_32_PCREL:
      md_number_to_chars (buf, val, 4);
      break;
    case BFD_RELOC_VTABLE_INHERIT:
    case BFD_RELOC_VTABLE_ENTRY:
      fixP->fx_done = 0;
      break;
    default:
      /* It's a relocation against an instruction.  */
      insn = bfd_getb32 ((unsigned char *) buf);

      switch (fixP->fx_r_type)
	{
	case BFD_RELOC_VISIUM_REL16:
	  if (fixP->fx_addsy == NULL
	      || (S_IS_DEFINED (fixP->fx_addsy)
		  && S_GET_SEGMENT (fixP->fx_addsy) == segment))
	    {
	      if (val > 0x1fffc || val < -0x20000)
		as_bad_where
		 (fixP->fx_file, fixP->fx_line,
		  "16-bit word displacement out of range: value = %d",
		  (int) val);
	      val = (val >> 2);

	      insn = (insn & 0xffff0000) | (val & 0x0000ffff);
	    }
	  break;

	case BFD_RELOC_VISIUM_HI16:
	case BFD_RELOC_VISIUM_HI16_PCREL:
	  if (fixP->fx_addsy == NULL)
	    insn = (insn & 0xffff0000) | ((val >> 16) & 0x0000ffff);
	  break;

	case BFD_RELOC_VISIUM_LO16:
	case BFD_RELOC_VISIUM_LO16_PCREL:
	  if (fixP->fx_addsy == NULL)
	    insn = (insn & 0xffff0000) | (val & 0x0000ffff);
	  break;

	case BFD_RELOC_VISIUM_IM16:
	case BFD_RELOC_VISIUM_IM16_PCREL:
	  if (fixP->fx_addsy == NULL)
	    {
	      if ((val & 0xffff0000) != 0)
		as_bad_where (fixP->fx_file, fixP->fx_line,
			      "16-bit immediate out of range: value = %d",
			      (int) val);

	      insn = (insn & 0xffff0000) | val;
	    }
	  break;

	case BFD_RELOC_NONE:
	default:
	  as_bad_where (fixP->fx_file, fixP->fx_line,
			"bad or unhandled relocation type: 0x%02x",
			fixP->fx_r_type);
	  break;
	}

      bfd_putb32 (insn, (unsigned char *) buf);
      visium_update_parity_bit (buf);
      break;
    }

  /* Are we finished with this relocation now?  */
  if (fixP->fx_addsy == NULL)
    fixP->fx_done = 1;
}

char *
parse_exp (char *s, expressionS * op)
{
  char *save = input_line_pointer;
  char *new;

  if (!s)
    {
      return s;
    }

  input_line_pointer = s;
  expression (op);
  new = input_line_pointer;
  input_line_pointer = save;
  return new;
}

/* If the given string is a Visium opcode mnemonic return the code
   otherwise return -1. Use binary chop to find matching entry.  */
static int
get_opcode (int *code, enum addressing_mode *mode, char *flags, char *mnem)
{
  int l = 0;
  int r = sizeof (opcode_table) / sizeof (struct opcode_entry) - 1;

  do
    {
      int mid = (l + r) / 2;
      int ans = strcmp (mnem, opcode_table[mid].mnem);

      if (ans < 0)
	r = mid - 1;
      else if (ans > 0)
	l = mid + 1;
      else
	{
	  *code = opcode_table[mid].code;
	  *mode = opcode_table[mid].mode;
	  *flags = opcode_table[mid].flags;

	  return 0;
	}
    }
  while (l <= r);

  return -1;
}

/* This function is called when the assembler starts up. It is called
   after the options have been parsed and the output file has been
   opened.  */
void
md_begin (void)
{
  switch (visium_arch)
    {
    case VISIUM_ARCH_DEF:
      break;
    case VISIUM_ARCH_MCM24:
      visium_opcode_arch = VISIUM_OPCODE_ARCH_GR5;
      visium_flags |= EF_VISIUM_ARCH_MCM24;
      break;
    case VISIUM_ARCH_MCM:
      visium_opcode_arch = VISIUM_OPCODE_ARCH_GR5;
      visium_flags |= EF_VISIUM_ARCH_MCM;
      break;
    case VISIUM_ARCH_GR6:
      visium_opcode_arch = VISIUM_OPCODE_ARCH_GR6;
      visium_flags |= EF_VISIUM_ARCH_MCM | EF_VISIUM_ARCH_GR6;
      nop_limit = 2;
      break;
    default:
      gas_assert (0);
    }

  bfd_set_private_flags (stdoutput, visium_flags);
}

/* This is identical to the md_atof in m68k.c.  I think this is right,
   but I'm not sure.

   Turn a string in input_line_pointer into a floating point constant of type
   type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
   emitted is stored in *sizeP .  An error message is returned,
   or NULL on OK.  */

const char *
md_atof (int type, char *litP, int *sizeP)
{
  int i, prec;
  LITTLENUM_TYPE words[MAX_LITTLENUMS];
  char *t;

  switch (type)
    {
    case 'f':
    case 'F':
    case 's':
    case 'S':
      prec = 2;
      break;

    case 'd':
    case 'D':
    case 'r':
    case 'R':
      prec = 4;
      break;

    case 'x':
    case 'X':
      prec = 6;
      break;

    case 'p':
    case 'P':
      prec = 6;
      break;

    default:
      *sizeP = 0;
      return _("Bad call to MD_ATOF()");
    }

  t = atof_ieee (input_line_pointer, type, words);
  if (t)
    input_line_pointer = t;
  *sizeP = prec * sizeof (LITTLENUM_TYPE);

  if (target_big_endian)
    {
      for (i = 0; i < prec; i++)
	{
	  md_number_to_chars (litP, (valueT) words[i],
			      sizeof (LITTLENUM_TYPE));
	  litP += sizeof (LITTLENUM_TYPE);
	}
    }
  else
    {
      for (i = prec - 1; i >= 0; i--)
	{
	  md_number_to_chars (litP, (valueT) words[i],
			      sizeof (LITTLENUM_TYPE));
	  litP += sizeof (LITTLENUM_TYPE);
	}
    }

  return 0;
}

static inline char *
skip_space (char *s)
{
  while (*s == ' ' || *s == '\t')
    ++s;

  return s;
}

static int
parse_gen_reg (char **sptr, int *rptr)
{
  char *s = skip_space (*sptr);
  char buf[10];
  int cnt;
  int l, r;

  cnt = 0;
  memset (buf, '\0', 10);
  while ((ISALNUM (*s)) && cnt < 10)
    buf[cnt++] = TOLOWER (*s++);

  l = 0;
  r = sizeof (gen_reg_table) / sizeof (struct reg_entry) - 1;

  do
    {
      int mid = (l + r) / 2;
      int ans = strcmp (buf, gen_reg_table[mid].name);

      if (ans < 0)
	r = mid - 1;
      else if (ans > 0)
	l = mid + 1;
      else
	{
	  *rptr = gen_reg_table[mid].code;
	  *sptr = s;
	  return 0;
	}
    }
  while (l <= r);

  return -1;
}

static int
parse_fp_reg (char **sptr, int *rptr)
{
  char *s = skip_space (*sptr);
  char buf[10];
  int cnt;
  int l, r;

  cnt = 0;
  memset (buf, '\0', 10);
  while ((ISALNUM (*s)) && cnt < 10)
    buf[cnt++] = TOLOWER (*s++);

  l = 0;
  r = sizeof (fp_reg_table) / sizeof (struct reg_entry) - 1;

  do
    {
      int mid = (l + r) / 2;
      int ans = strcmp (buf, fp_reg_table[mid].name);

      if (ans < 0)
	r = mid - 1;
      else if (ans > 0)
	l = mid + 1;
      else
	{
	  *rptr = fp_reg_table[mid].code;
	  *sptr = s;
	  return 0;
	}
    }
  while (l <= r);

  return -1;
}

static int
parse_cc (char **sptr, int *rptr)
{
  char *s = skip_space (*sptr);
  char buf[10];
  int cnt;
  int l, r;

  cnt = 0;
  memset (buf, '\0', 10);
  while ((ISALNUM (*s)) && cnt < 10)
    buf[cnt++] = TOLOWER (*s++);

  l = 0;
  r = sizeof (cc_table) / sizeof (struct cc_entry) - 1;

  do
    {
      int mid = (l + r) / 2;
      int ans = strcmp (buf, cc_table[mid].name);

      if (ans < 0)
	r = mid - 1;
      else if (ans > 0)
	l = mid + 1;
      else
	{
	  *rptr = cc_table[mid].code;
	  *sptr = s;
	  return 0;
	}
    }
  while (l <= r);

  return -1;
}

/* Previous dest is the destination register number of the instruction
   before the current one.  */
static int previous_dest = 0;
static int previous_mode = 0;
static int condition_code = 0;
static int this_dest = 0;
static int this_mode = 0;


/* This is the main function in this file. It takes a line of assembly language
   source code and assembles it. Note, labels and pseudo ops have already
   been removed, so too has leading white space. */
void
md_assemble (char *str0)
{
  char *str = str0;
  int cnt;
  char mnem[10];
  int opcode;
  enum addressing_mode amode;
  char arch_flags;
  int ans;

  char *output;
  int reloc = 0;
  relax_substateT relax = 0;
  expressionS e1;
  int r1, r2, r3;
  int cc;
  int indx;

  /* Initialize the expression.  */
  e1.X_op = O_absent;

  /* Initialize destination register.
     If the instruction we just looked at is in the delay slot of an
     unconditional branch, then there is no index hazard.  */
  if ((previous_mode == mode_cad || previous_mode == mode_ci)
      && condition_code == 15)
    this_dest = 0;

  previous_dest = this_dest;
  previous_mode = this_mode;
  this_dest = 0;

  /* Drop leading whitespace (probably not required).  */
  while (*str == ' ')
    str++;

  /* Get opcode mnemonic and make sure it's in lower case.  */
  cnt = 0;
  memset (mnem, '\0', 10);
  while ((ISALNUM (*str) || *str == '.' || *str == '_') && cnt < 10)
    mnem[cnt++] = TOLOWER (*str++);

  /* Look up mnemonic in opcode table, and get the code,
     the instruction format, and the flags that indicate
     which family members support this mnemonic.  */
  if (get_opcode (&opcode, &amode, &arch_flags, mnem) < 0)
    {
      as_bad ("Unknown instruction mnemonic `%s'", mnem);
      return;
    }

  if ((VISIUM_OPCODE_ARCH_MASK (visium_opcode_arch) & arch_flags) == 0)
    {
      as_bad ("Architecture mismatch on `%s'", mnem);
      return;
    }

  this_mode = amode;

  switch (amode)
    {
    case mode_d:
      /* register :=
         Example:
         readmda r1  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      opcode |= (r1 << 10);
      this_dest = r1;
      break;

    case mode_a:
      /* op= register
         Example: asld r1  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("SourceA register required");
	  return;
	}
      opcode |= (r1 << 16);
      break;

    case mode_ab:
      /* register * register
         Example:
         mults r1,r2  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("SourceA register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceB register required");
	      return;
	    }
	  opcode |= (r1 << 16) | (r2 << 4);
	}
      else
	{
	  as_bad ("SourceB register required");
	  return;
	}
      break;

    case mode_da:
      /* register := register
         Example:
         extb.l  r1,r2  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA register required");
	      return;
	    }
	  opcode |= (r1 << 10) | (r2 << 16);
	}
      else
	{
	  as_bad ("SourceB register required");
	  return;
	}
      this_dest = r1;
      break;

    case mode_dab:
      /* register := register * register
         Example:
         add.l r1,r2,r3  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_gen_reg (&str, &r3);
	      if (ans < 0)
		{
		  as_bad ("SourceB register required");
		  return;
		}

	      /* Got three regs, assemble instruction.  */
	      opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
	    }
	  else
	    {
	      as_bad ("SourceA register required");
	      return;
	    }
	}
      else
	{
	  as_bad ("Dest register required");
	  return;
	}
      this_dest = r1;
      break;

    case mode_iab:
      /* 5-bit immediate * register * register
         Example:
         eamwrite 3,r1,r2  */
      str = parse_exp (str, &e1);
      str = skip_space (str);
      if (e1.X_op != O_absent && *str == ',')
	{
	  int eam_op = e1.X_add_number;

	  str = skip_space (str + 1);
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_gen_reg (&str, &r3);
	      if (ans < 0)
		{
		  as_bad ("SourceB register required");
		  return;
		}

	      /* Got three operands, assemble instruction.  */
	      if (eam_op < 0 || eam_op > 31)
		{
		  as_bad ("eam_op out of range");
		}
	      opcode |= ((eam_op & 0x1f) << 10) | (r2 << 16) | (r3 << 4);
	    }
	}
      else
	{
	  as_bad ("EAM_OP required");
	  return;
	}
      break;

    case mode_0ab:
      /* zero * register * register
         Example:
         cmp.l  r1,r2 */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("SourceA register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceB register required");
	      return;
	    }
	  opcode |= (r1 << 16) | (r2 << 4);
	}
      else
	{
	  as_bad ("SourceB register required");
	  return;
	}
      break;

    case mode_da0:
      /* register * register * zero
         Example:
         move.l  r1,r2  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA register required");
	      return;
	    }
	  opcode |= (r1 << 10) | (r2 << 16);
	}
      else
	{
	  as_bad ("SourceA register required");
	  return;
	}
      this_dest = r1;
      break;

    case mode_cad:
      /* condition * register * register
         Example:
         bra  tr,r1,r2  */
      ans = parse_cc (&str, &cc);
      if (ans < 0)
	{
	  as_bad ("condition code required");
	  return;
	}

      str = skip_space (str);
      if (*str == ',')
	{
	  str = skip_space (str + 1);
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_gen_reg (&str, &r3);
	      if (ans < 0)
		{
		  as_bad ("Dest register required");
		  return;
		}

	      /* Got three operands, assemble instruction.  */
	      opcode |= (cc << 27) | (r2 << 16) | (r3 << 10);
	    }
	  else
	    {
	      as_bad ("Dest register required");
	      return;
	    }
	}
      else
	{
	  as_bad ("SourceA register required");
	  return;
	}

      if (previous_mode == mode_cad || previous_mode == mode_ci)
	as_bad ("branch instruction in delay slot");

      /* For the GR6, BRA insns must be aligned on 64-bit boundaries.  */
      if (visium_arch == VISIUM_ARCH_GR6)
	do_align (3, NULL, 0, 0);

      this_dest = r3;
      condition_code = cc;
      break;

    case mode_das:
      /* register := register * 5-bit immediate/register shift count
         Example:
         asl.l  r1,r2,4  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_gen_reg (&str, &r3);
	      if (ans == 0)
		{
		  opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
		}
	      else
		{
		  str = parse_exp (str, &e1);
		  if (e1.X_op == O_constant)
		    {
		      int imm = e1.X_add_number;

		      if (imm < 0 || imm > 31)
			as_bad ("immediate value out of range");

		      opcode |=
			(r1 << 10) | (r2 << 16) | (1 << 9) | ((imm & 0x1f) <<
							      4);
		    }
		  else
		    {
		      as_bad ("immediate operand required");
		      return;
		    }
		}
	    }
	}
      else
	{
	  as_bad ("SourceA register required");
	  return;
	}
      this_dest = r1;
      break;

    case mode_di:
      /* register := 5-bit immediate
         Example:
         eamread r1,3  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  str = parse_exp (str, &e1);
	  if (e1.X_op == O_constant)
	    {
	      int opnd2 = e1.X_add_number;

	      if (opnd2 < 0 || opnd2 > 31)
		{
		  as_bad ("immediate operand out of range");
		  return;
		}
	      opcode |= (r1 << 10) | ((opnd2 & 0x1f) << 4);
	    }
	  else
	    {
	      as_bad ("immediate operand required");
	      return;
	    }
	}
      else
	{
	  as_bad ("immediate operand required");
	  return;
	}
      this_dest = r1;
      break;

    case mode_ir:
      /* 5-bit immediate * register, e.g. trace 1,r1  */
      str = parse_exp (str, &e1);
      str = skip_space (str);
      if (e1.X_op == O_constant && *str == ',')
	{
	  int opnd1 = e1.X_add_number;

	  str = skip_space (str + 1);
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA register required");
	      return;
	    }

	  /* Got two operands, assemble instruction.  */
	  if (opnd1 < 0 || opnd1 > 31)
	    {
	      as_bad ("1st operand out of range");
	    }
	  opcode |= ((opnd1 & 0x1f) << 10) | (r2 << 16);
	}
      else
	{
	  as_bad ("Immediate operand required");
	  return;
	}
      break;

    case mode_ai:
      /* register *= 16-bit unsigned immediate
         Example:
         addi  r1,123  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      opcode |= (r1 << 16);

      str = skip_space (str);
      if (*str != ',')
	{
	  as_bad ("immediate value missing");
	  return;
	}
      this_dest = r1;
      /* Fall through.  */

    case mode_i:
      /* MOVIL/WRTL traditionally get an implicit "%l" applied
	 to their immediate value.  For other opcodes, unless
	 the immediate value is decorated with "%u" or "%l"
	 it must be in the range 0 .. 65535.  */
      if ((opcode & 0x7fe00000) == 0x04800000
	  || (opcode & 0x7fe00000) == 0x05000000)
	reloc = BFD_RELOC_VISIUM_LO16;
      else
	reloc = BFD_RELOC_VISIUM_IM16;

      str = skip_space (str + 1);

      if (*str == '%')
	{
	  if (str[1] == 'u')
	    reloc = BFD_RELOC_VISIUM_HI16;
	  else if (str[1] == 'l')
	    reloc = BFD_RELOC_VISIUM_LO16;
	  else
	    {
	      as_bad ("bad char after %%");
	      return;
	    }

	  str += 2;
	}
      str = parse_exp (str, &e1);
      if (e1.X_op != O_absent)
	{
	  if (e1.X_op == O_constant)
	    {
	      int imm = e1.X_add_number;

	      if (reloc == BFD_RELOC_VISIUM_HI16)
		opcode |= ((imm >> 16) & 0xffff);
	      else if (reloc == BFD_RELOC_VISIUM_LO16)
		opcode |= (imm & 0xffff);
	      else
		{
		  if (imm < 0 || imm > 0xffff)
		    as_bad ("immediate value out of range");

		  opcode |= (imm & 0xffff);
		}
	      /* No relocation is needed.  */
	      reloc = 0;
	    }
	}
      else
	{
	  as_bad ("immediate value missing");
	  return;
	}
      break;

    case mode_bax:
      /* register * register * 5-bit immediate,
         SourceB * SourceA * Index
         Examples
         write.l (r1),r2
         write.l 3(r1),r2  */
      str = skip_space (str);

      indx = 0;
      if (*str != '(')
	{
	  str = parse_exp (str, &e1);
	  if (e1.X_op == O_constant)
	    {
	      indx = e1.X_add_number;

	      if (indx < 0 || indx > 31)
		{
		  as_bad ("Index out of range");
		  return;
		}
	    }
	  else
	    {
	      as_bad ("Index(SourceA) required");
	      return;
	    }
	}

      str = skip_space (str);

      if (*str != '(')
	{
	  as_bad ("Index(SourceA) required");
	  return;
	}

      str = skip_space (str + 1);

      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("SourceA register required");
	  return;
	}
      str = skip_space (str);
      if (*str != ')')
	{
	  as_bad ("(SourceA) required");
	  return;
	}
      str = skip_space (str + 1);

      if (*str == ',')
	{
	  str = skip_space (str + 1);
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceB register required");
	      return;
	    }
	}
      else
	{
	  as_bad ("SourceB register required");
	  return;
	}

      opcode |= (r1 << 16) | (r2 << 4) | ((indx & 0x1f) << 10);

      if (indx != 0 && previous_mode == mode_cad)
	{
	  /* We're in a delay slot.
	     If the base reg is the destination of the branch, then issue
	     an error message.
	     Otherwise it is safe to use the base and index.  */
	  if (previous_dest != 0 && r1 == previous_dest)
	    {
	      as_bad ("base register not ready");
	      return;
	    }
	}
      else if (previous_dest != 0
	       && r1 == previous_dest
	       && (visium_arch == VISIUM_ARCH_MCM
		   || visium_arch == VISIUM_ARCH_MCM24
		   || (visium_arch == VISIUM_ARCH_DEF && indx != 0)))
	{
	  as_warn ("base register not ready, NOP inserted.");
	  /* Insert a NOP before the write instruction.  */
	  output = frag_more (4);
	  memset (output, 0, 4);
	}
      break;

    case mode_dax:
      /*  register := register * 5-bit immediate
         Examples:
         read.b  r1,(r2)
         read.w  r1,3(r2)  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest register required");
	  return;
	}
      str = skip_space (str);
      if (*str != ',')
	{
	  as_bad ("SourceA required");
	  return;
	}
      str = skip_space (str + 1);

      indx = 0;
      if (*str != '(')
	{
	  str = parse_exp (str, &e1);
	  if (e1.X_op == O_constant)
	    {
	      indx = e1.X_add_number;

	      if (indx < 0 || indx > 31)
		{
		  as_bad ("Index out of range");
		  return;
		}
	    }
	  else
	    {
	      as_bad ("Immediate 0 to 31 required");
	      return;
	    }
	}
      if (*str != '(')
	{
	  as_bad ("(SourceA) required");
	  return;
	}
      str++;
      ans = parse_gen_reg (&str, &r2);
      if (ans < 0)
	{
	  as_bad ("SourceA register required");
	  return;
	}
      str = skip_space (str);
      if (*str != ')')
	{
	  as_bad ("(SourceA) required");
	  return;
	}
      str++;
      opcode |= (r1 << 10) | (r2 << 16) | ((indx & 0x1f) << 4);
      this_dest = r1;

      if (indx != 0 && previous_mode == mode_cad)
	{
	  /* We're in a delay slot.
	     If the base reg is the destination of the branch, then issue
	     an error message.
	     Otherwise it is safe to use the base and index.  */
	  if (previous_dest != 0 && r2 == previous_dest)
	    {
	      as_bad ("base register not ready");
	      return;
	    }
	}
      else if (previous_dest != 0
	       && r2 == previous_dest
	       && (visium_arch == VISIUM_ARCH_MCM
		   || visium_arch == VISIUM_ARCH_MCM24
		   || (visium_arch == VISIUM_ARCH_DEF && indx != 0)))
	{
	  as_warn ("base register not ready, NOP inserted.");
	  /* Insert a NOP before the read instruction.  */
	  output = frag_more (4);
	  memset (output, 0, 4);
	}
      break;

    case mode_s:
      /* special mode
         Example:
         nop  */
      str = skip_space (str);
      break;

    case mode_ci:
      /* condition * 16-bit signed word displacement
         Example:
         brr L1  */
      ans = parse_cc (&str, &cc);
      if (ans < 0)
	{
	  as_bad ("condition code required");
	  return;
	}
      opcode |= (cc << 27);

      str = skip_space (str);
      if (*str == ',')
	{
	  str = skip_space (str + 1);
	  str = parse_exp (str, &e1);
	  if (e1.X_op != O_absent)
	    {
	      if (e1.X_op == O_constant)
		{
		  int imm = e1.X_add_number;

		  if (imm < -32768 || imm > 32767)
		    as_bad ("immediate value out of range");

		  /* The GR6 doesn't correctly handle a 0 displacement
		     so we insert a NOP and change it to -1.  */
		  if (imm == 0 && cc != 0 && visium_arch == VISIUM_ARCH_GR6)
		    {
		      output = frag_more (4);
		      memset (output, 0, 4);
		      imm = -1;
		    }

		  opcode |= (imm & 0xffff);
		}
	      else if (e1.X_op == O_symbol)
		{
		  /* The GR6 doesn't correctly handle a 0 displacement
		     so the instruction requires relaxation.  */
		  if (cc != 0 && visium_arch == VISIUM_ARCH_GR6)
		    relax = amode;
		  else
		    reloc = BFD_RELOC_VISIUM_REL16;
		}
	      else
		{
		  as_bad ("immediate value missing");
		  return;
		}
	    }
	  else
	    {
	      as_bad ("immediate value missing");
	      return;
	    }
	}
      else
	{
	  as_bad ("immediate value missing");
	  return;
	}

      if (previous_mode == mode_cad || previous_mode == mode_ci)
	as_bad ("branch instruction in delay slot");

      condition_code = cc;
      break;

    case mode_fdab:
      /* float := float * float
         Example
         fadd    f4,f3,f2  */
      ans = parse_fp_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("floating point destination register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_fp_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("floating point SourceA register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_fp_reg (&str, &r3);
	      if (ans < 0)
		{
		  as_bad ("floating point SourceB register required");
		  return;
		}

	      /* Got 3 floating regs, assemble instruction.  */
	      opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
	    }
	  else
	    {
	      as_bad ("floating point SourceB register required");
	      return;
	    }
	}
      else
	{
	  as_bad ("floating point SourceA register required");
	  return;
	}
      break;

    case mode_ifdab:
      /* 4-bit immediate * float * float * float
         Example
         fpinst   10,f1,f2,f3  */
      str = parse_exp (str, &e1);
      str = skip_space (str);
      if (e1.X_op != O_absent && *str == ',')
	{
	  int finst = e1.X_add_number;

	  str = skip_space (str + 1);
	  ans = parse_fp_reg (&str, &r1);
	  if (ans < 0)
	    {
	      as_bad ("floating point destination register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_fp_reg (&str, &r2);
	      if (ans < 0)
		{
		  as_bad ("floating point SourceA register required");
		  return;
		}
	      str = skip_space (str);
	      if (*str == ',')
		{
		  str++;
		  ans = parse_fp_reg (&str, &r3);
		  if (ans < 0)
		    {
		      as_bad ("floating point SourceB register required");
		      return;
		    }

		  /* Got immediate and 3 floating regs,
		     assemble instruction.  */
		  if (finst < 0 || finst > 15)
		    as_bad ("finst out of range");

		  opcode |=
		    ((finst & 0xf) << 27) | (r1 << 10) | (r2 << 16) | (r3 <<
								       4);
		}
	      else
		{
		  as_bad ("floating point SourceB register required");
		  return;
		}
	    }
	  else
	    {
	      as_bad ("floating point SourceA register required");
	      return;
	    }
	}
      else
	{
	  as_bad ("finst missing");
	  return;
	}
      break;

    case mode_idfab:
      /* 4-bit immediate * register * float * float
         Example
         fpuread   4,r25,f2,f3  */
      str = parse_exp (str, &e1);
      str = skip_space (str);
      if (e1.X_op != O_absent && *str == ',')
	{
	  int finst = e1.X_add_number;

	  str = skip_space (str + 1);
	  ans = parse_gen_reg (&str, &r1);
	  if (ans < 0)
	    {
	      as_bad ("destination general register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_fp_reg (&str, &r2);
	      if (ans < 0)
		{
		  as_bad ("floating point SourceA register required");
		  return;
		}
	      str = skip_space (str);
	      if (*str == ',')
		{
		  str++;
		  ans = parse_fp_reg (&str, &r3);
		  if (ans < 0)
		    {
		      as_bad ("floating point SourceB register required");
		      return;
		    }

		  /* Got immediate and 3 floating regs,
		     assemble instruction.  */
		  if (finst < 0 || finst > 15)
		    as_bad ("finst out of range");

		  opcode |=
		    ((finst & 0xf) << 27) | (r1 << 10) | (r2 << 16) | (r3 <<
								       4);
		}
	      else
		{
		  as_bad ("floating point SourceB register required");
		  return;
		}
	    }
	  else
	    {
	      as_bad ("floating point SourceA register required");
	      return;
	    }
	}
      else
	{
	  as_bad ("finst missing");
	  return;
	}
      break;

    case mode_fda:
      /* float := float
         Example
         fsqrt    f4,f3  */
      ans = parse_fp_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("floating point destination register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_fp_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("floating point source register required");
	      return;
	    }

	  /* Got 2 floating regs, assemble instruction.  */
	  opcode |= (r1 << 10) | (r2 << 16);
	}
      else
	{
	  as_bad ("floating point source register required");
	  return;
	}
      break;

    case mode_fdra:
      /* float := register
         Example
         fload   f15,r6  */
      ans = parse_fp_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("floating point destination register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("SourceA general register required");
	      return;
	    }

	  /* Got 2 regs, assemble instruction.  */
	  opcode |= (r1 << 10) | (r2 << 16);
	}
      else
	{
	  as_bad ("SourceA general register required");
	  return;
	}
      break;

    case mode_rdfab:
      /* register := float * float
         Example
         fcmp    r0,f4,f8
         For the GR6, register must be r0 and can be omitted.  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  if (visium_opcode_arch == VISIUM_OPCODE_ARCH_GR5)
	    {
	      as_bad ("Dest general register required");
	      return;
	    }
	  r1 = 0;
	}
      else
	{
	  if (r1 != 0 && visium_opcode_arch != VISIUM_OPCODE_ARCH_GR5)
	    {
	      as_bad ("FCMP/FCMPE can only use r0 as Dest register");
	      return;
	     }

	  str = skip_space (str);
	  if (*str == ',')
	    str++;
	  else
	    {
	      as_bad ("floating point SourceA register required");
	      return;
	    }
	}

      ans = parse_fp_reg (&str, &r2);
      if (ans < 0)
	{
	  as_bad ("floating point SourceA register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_fp_reg (&str, &r3);
	  if (ans < 0)
	    {
	      as_bad ("floating point SourceB register required");
	      return;
	    }

	  /* Got 3 regs, assemble instruction.  */
	  opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
	}

      this_dest = r1;
      break;

    case mode_rdfa:
      /* register := float
         Example
         fstore r5,f12  */
      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("Dest general register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_fp_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("floating point source register required");
	      return;
	    }

	  /* Got 2 regs, assemble instruction.  */
	  opcode |= (r1 << 10) | (r2 << 16);
	}
      else
	{
	  as_bad ("floating point source register required");
	  return;
	}

      this_dest = r1;
      break;

    case mode_rrr:
      /* register register register, all sources and destinations
         Example:
         bmd   r1,r2,r3  */

      ans = parse_gen_reg (&str, &r1);
      if (ans < 0)
	{
	  as_bad ("destination address register required");
	  return;
	}
      str = skip_space (str);
      if (*str == ',')
	{
	  str++;
	  ans = parse_gen_reg (&str, &r2);
	  if (ans < 0)
	    {
	      as_bad ("source address register required");
	      return;
	    }
	  str = skip_space (str);
	  if (*str == ',')
	    {
	      str++;
	      ans = parse_gen_reg (&str, &r3);
	      if (ans < 0)
		{
		  as_bad ("count register required");
		  return;
		}

	      /* We insist on three registers but the opcode can only use
		 r1,r2,r3.  */
	      if (r1 != 1 || r2 != 2 || r3 != 3)
		{
		  as_bad ("BMI/BMD can only use format op r1,r2,r3");
		  return;
		}

	      /* Opcode is unmodified by what comes out of the table.  */
	    }
	  else
	    {
	      as_bad ("register required");
	      return;
	    }
	}
      else
	{
	  as_bad ("register required");
	  return;
	}

      this_dest = r1;
      break;

    default:
      break;
    }

  if (relax)
    output = frag_var (rs_machine_dependent, 8, 4, relax, e1.X_add_symbol,
		       e1.X_add_number, NULL);
  else
    output = frag_more (4);

  /* Build the 32-bit instruction in a host-endian-neutral fashion.  */
  output[0] = (opcode >> 24) & 0xff;
  output[1] = (opcode >> 16) & 0xff;
  output[2] = (opcode >> 8) & 0xff;
  output[3] = (opcode >> 0) & 0xff;

  if (relax)
    /* The size of the instruction is unknown, so tie the debug info to the
       start of the instruction.  */
    dwarf2_emit_insn (0);
  else
    {
      if (reloc)
	fix_new_exp (frag_now, output - frag_now->fr_literal, 4, &e1,
		     reloc == BFD_RELOC_VISIUM_REL16, reloc);
      else
	visium_update_parity_bit (output);

      dwarf2_emit_insn (4);
    }

  if (*str != '\0')
    as_bad ("junk after instruction");
}

void
visium_cfi_frame_initial_instructions (void)
{
  /* The CFA is in SP on function entry.  */
  cfi_add_CFA_def_cfa (23, 0);
}

int
visium_regname_to_dw2regnum (char *regname)
{
  if (!regname[0])
    return -1;

  if (regname[0] == 'f' && regname[1] == 'p' && !regname[2])
    return 22;

  if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
    return 23;

  if (regname[0] == 'm' && regname[1] == 'd' && !regname[3])
    switch (regname[2])
      {
      case 'b': return 32;
      case 'a': return 33;
      case 'c': return 34;
      default : return -1;
      }

  if (regname[0] == 'f' || regname[0] == 'r')
    {
      char *p;
      unsigned int regnum = strtoul (regname + 1, &p, 10);
      if (*p)
	return -1;
      if (regnum >= (regname[0] == 'f' ? 16 : 32))
	return -1;
      if (regname[0] == 'f')
	regnum += 35;
      return regnum;
    }

  return -1;
}