Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/mips-dis.c
Line
Count
Source
1
/* Print mips instructions for GDB, the GNU debugger, or for objdump.
2
   Copyright (C) 1989-2026 Free Software Foundation, Inc.
3
   Contributed by Nobuyuki Hikichi(hikichi@sra.co.jp).
4
5
   This file is part of the GNU opcodes library.
6
7
   This library is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   It is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "disassemble.h"
24
#include "libiberty.h"
25
#include "opcode/mips.h"
26
#include "opintl.h"
27
#include "elf-bfd.h"
28
#include "elf/mips.h"
29
#include "elfxx-mips.h"
30
31
/* FIXME: These are needed to figure out if the code is mips16 or
32
   not. The low bit of the address is often a good indicator.  No
33
   symbol table is available when this code runs out in an embedded
34
   system as when it is used for disassembler support in a monitor.  */
35
36
#if !defined(EMBEDDED_ENV)
37
#define SYMTAB_AVAILABLE 1
38
#endif
39
40
/* Mips instructions are at maximum this many bytes long.  */
41
2.14M
#define INSNLEN 4
42
43

44
/* FIXME: These should be shared with gdb somehow.  */
45
46
struct mips_cp0sel_name
47
{
48
  unsigned int cp0reg;
49
  unsigned int sel;
50
  const char * const name;
51
};
52
53
static const char * const mips_gpr_names_numeric[32] =
54
{
55
  "$0",   "$1",   "$2",   "$3",   "$4",   "$5",   "$6",   "$7",
56
  "$8",   "$9",   "$10",  "$11",  "$12",  "$13",  "$14",  "$15",
57
  "$16",  "$17",  "$18",  "$19",  "$20",  "$21",  "$22",  "$23",
58
  "$24",  "$25",  "$26",  "$27",  "$28",  "$29",  "$30",  "$31"
59
};
60
61
static const char * const mips_gpr_names_oldabi[32] =
62
{
63
  "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
64
  "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
65
  "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
66
  "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra"
67
};
68
69
static const char * const mips_gpr_names_newabi[32] =
70
{
71
  "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
72
  "a4",   "a5",   "a6",   "a7",   "t0",   "t1",   "t2",   "t3",
73
  "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
74
  "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra"
75
};
76
77
static const char * const mips_fpr_names_numeric[32] =
78
{
79
  "$f0",  "$f1",  "$f2",  "$f3",  "$f4",  "$f5",  "$f6",  "$f7",
80
  "$f8",  "$f9",  "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
81
  "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
82
  "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31"
83
};
84
85
static const char * const mips_fpr_names_32[32] =
86
{
87
  "fv0",  "fv0f", "fv1",  "fv1f", "ft0",  "ft0f", "ft1",  "ft1f",
88
  "ft2",  "ft2f", "ft3",  "ft3f", "fa0",  "fa0f", "fa1",  "fa1f",
89
  "ft4",  "ft4f", "ft5",  "ft5f", "fs0",  "fs0f", "fs1",  "fs1f",
90
  "fs2",  "fs2f", "fs3",  "fs3f", "fs4",  "fs4f", "fs5",  "fs5f"
91
};
92
93
static const char * const mips_fpr_names_o64[32] =
94
{
95
  "fv0",  "fv1",  "ft0",  "ft1",  "ft2",  "ft3",  "ft4",  "ft5",
96
  "ft6",  "ft7",  "ft8",  "ft9",  "fa0",  "fa1",  "ft10", "ft11",
97
  "ft12", "ft13", "ft14", "ft15", "fs0",  "fs1",  "fs2",  "fs3",
98
  "fs4",  "fs5",  "fs6",  "fs7",  "fs8",  "fs9",  "fs10", "fs11",
99
};
100
101
static const char * const mips_fpr_names_n32[32] =
102
{
103
  "fv0",  "ft14", "fv1",  "ft15", "ft0",  "ft1",  "ft2",  "ft3",
104
  "ft4",  "ft5",  "ft6",  "ft7",  "fa0",  "fa1",  "fa2",  "fa3",
105
  "fa4",  "fa5",  "fa6",  "fa7",  "fs0",  "ft8",  "fs1",  "ft9",
106
  "fs2",  "ft10", "fs3",  "ft11", "fs4",  "ft12", "fs5",  "ft13"
107
};
108
109
static const char * const mips_fpr_names_64[32] =
110
{
111
  "fv0",  "ft12", "fv1",  "ft13", "ft0",  "ft1",  "ft2",  "ft3",
112
  "ft4",  "ft5",  "ft6",  "ft7",  "fa0",  "fa1",  "fa2",  "fa3",
113
  "fa4",  "fa5",  "fa6",  "fa7",  "ft8",  "ft9",  "ft10", "ft11",
114
  "fs0",  "fs1",  "fs2",  "fs3",  "fs4",  "fs5",  "fs6",  "fs7"
115
};
116
117
static const char * const mips_fpr_names_eabi32[32] =
118
{
119
  "fv0",  "fv0f", "fv1",  "fv1f", "ft0",  "ft0f",  "ft1", "ft1f",
120
  "ft2",  "ft2f", "ft3",  "ft3f", "fa0",  "fa0f",  "fa1", "fa1f",
121
  "fa2",  "fa2f", "fa3",  "fa3f", "fs0",  "fs0f",  "fs1", "fs1f",
122
  "fs2",  "fs2f", "fs3",  "fs3f", "fs4",  "fs4f",  "fs5", "fs5f",
123
};
124
125
static const char * const mips_fpr_names_eabi64[32] =
126
{
127
  "fv0",  "fv1",  "ft0",  "ft1",  "ft2",  "ft3",  "ft4",  "ft5",
128
  "ft6",  "ft7",  "ft8",  "ft9",  "fa0",  "fa1",  "fa2",  "fa3",
129
  "fa4",  "fa5",  "fa6",  "fa7",  "fs0",  "fs1",  "fs2",  "fs3",
130
  "fs4",  "fs5",  "fs6",  "fs7",  "fs8",  "fs9",  "fs10", "fs11",
131
};
132
133
static const char * const mips_cp0_names_numeric[32] =
134
{
135
  "$0",   "$1",   "$2",   "$3",   "$4",   "$5",   "$6",   "$7",
136
  "$8",   "$9",   "$10",  "$11",  "$12",  "$13",  "$14",  "$15",
137
  "$16",  "$17",  "$18",  "$19",  "$20",  "$21",  "$22",  "$23",
138
  "$24",  "$25",  "$26",  "$27",  "$28",  "$29",  "$30",  "$31"
139
};
140
141
static const char * const mips_cp1_names_numeric[32] =
142
{
143
  "$0",   "$1",   "$2",   "$3",   "$4",   "$5",   "$6",   "$7",
144
  "$8",   "$9",   "$10",  "$11",  "$12",  "$13",  "$14",  "$15",
145
  "$16",  "$17",  "$18",  "$19",  "$20",  "$21",  "$22",  "$23",
146
  "$24",  "$25",  "$26",  "$27",  "$28",  "$29",  "$30",  "$31"
147
};
148
149
static const char * const mips_cp0_names_r3900[32] =
150
{
151
  "$0",           "$1",           "$2",           "c0_config",
152
  "$4",           "$5",           "$6",           "c0_cache",
153
  "c0_badvaddr",  "$9",           "$10",          "$11",
154
  "c0_sr",        "c0_cause",     "c0_epc",       "c0_prid",
155
  "c0_debug",     "c0_depc",      "$18",          "$19",
156
  "$20",          "$21",          "$22",          "$23",
157
  "$24",          "$25",          "$26",          "$27",
158
  "$28",          "$29",          "$30",          "$31",
159
};
160
161
static const char * const mips_cp0_names_r3000[32] =
162
{
163
  "c0_index",     "c0_random",    "c0_entrylo",   "$3",
164
  "c0_context",   "$5",           "$6",           "$7",
165
  "c0_badvaddr",  "$9",           "c0_entryhi",   "$11",
166
  "c0_sr",        "c0_cause",     "c0_epc",       "c0_prid",
167
  "$16",          "$17",          "$18",          "$19",
168
  "$20",          "$21",          "$22",          "$23",
169
  "$24",          "$25",          "$26",          "$27",
170
  "$28",          "$29",          "$30",          "$31",
171
};
172
173
static const char * const mips_cp0_names_r4000[32] =
174
{
175
  "c0_index",     "c0_random",    "c0_entrylo0",  "c0_entrylo1",
176
  "c0_context",   "c0_pagemask",  "c0_wired",     "$7",
177
  "c0_badvaddr",  "c0_count",     "c0_entryhi",   "c0_compare",
178
  "c0_sr",        "c0_cause",     "c0_epc",       "c0_prid",
179
  "c0_config",    "c0_lladdr",    "c0_watchlo",   "c0_watchhi",
180
  "c0_xcontext",  "$21",          "$22",          "$23",
181
  "$24",          "$25",          "c0_ecc",       "c0_cacheerr",
182
  "c0_taglo",     "c0_taghi",     "c0_errorepc",  "$31",
183
};
184
185
static const char * const mips_cp0_names_r5900[32] =
186
{
187
  "c0_index",     "c0_random",    "c0_entrylo0",  "c0_entrylo1",
188
  "c0_context",   "c0_pagemask",  "c0_wired",     "$7",
189
  "c0_badvaddr",  "c0_count",     "c0_entryhi",   "c0_compare",
190
  "c0_sr",        "c0_cause",     "c0_epc",       "c0_prid",
191
  "c0_config",    "$17",          "$18",          "$19",
192
  "$20",          "$21",          "$22",          "c0_badpaddr",
193
  "c0_depc",      "c0_perfcnt",   "$26",          "$27",
194
  "c0_taglo",     "c0_taghi",     "c0_errorepc",  "$31"
195
};
196
197
static const char * const mips_cp0_names_mips3264[32] =
198
{
199
  "c0_index",     "c0_random",    "c0_entrylo0",  "c0_entrylo1",
200
  "c0_context",   "c0_pagemask",  "c0_wired",     "$7",
201
  "c0_badvaddr",  "c0_count",     "c0_entryhi",   "c0_compare",
202
  "c0_status",    "c0_cause",     "c0_epc",       "c0_prid",
203
  "c0_config",    "c0_lladdr",    "c0_watchlo",   "c0_watchhi",
204
  "c0_xcontext",  "$21",          "$22",          "c0_debug",
205
  "c0_depc",      "c0_perfcnt",   "c0_errctl",    "c0_cacheerr",
206
  "c0_taglo",     "c0_taghi",     "c0_errorepc",  "c0_desave",
207
};
208
209
static const char * const mips_cp1_names_mips[32] =
210
{
211
  "c1_fir",       "$1",           "$2",           "$3",
212
  "$4",           "$5",           "$6",           "$7",
213
  "$8",           "$9",           "$10",          "$11",
214
  "$12",          "$13",          "$14",          "$15",
215
  "$16",          "$17",          "$18",          "$19",
216
  "$20",          "$21",          "$22",          "$23",
217
  "$24",          "$25",          "$26",          "$27",
218
  "$28",          "$29",          "$30",          "c1_fcsr"
219
};
220
221
static const char * const mips_cp1_names_mips3264[32] =
222
{
223
  "c1_fir",       "c1_ufr",       "$2",           "$3",
224
  "c1_unfr",      "$5",           "$6",           "$7",
225
  "$8",           "$9",           "$10",          "$11",
226
  "$12",          "$13",          "$14",          "$15",
227
  "$16",          "$17",          "$18",          "$19",
228
  "$20",          "$21",          "$22",          "$23",
229
  "$24",          "c1_fccr",      "c1_fexr",      "$27",
230
  "c1_fenr",      "$29",          "$30",          "c1_fcsr"
231
};
232
233
static const struct mips_cp0sel_name mips_cp0sel_names_mips3264[] =
234
{
235
  { 16, 1, "c0_config1"   },
236
  { 16, 2, "c0_config2"   },
237
  { 16, 3, "c0_config3"   },
238
  { 18, 1, "c0_watchlo,1" },
239
  { 18, 2, "c0_watchlo,2" },
240
  { 18, 3, "c0_watchlo,3" },
241
  { 18, 4, "c0_watchlo,4" },
242
  { 18, 5, "c0_watchlo,5" },
243
  { 18, 6, "c0_watchlo,6" },
244
  { 18, 7, "c0_watchlo,7" },
245
  { 19, 1, "c0_watchhi,1" },
246
  { 19, 2, "c0_watchhi,2" },
247
  { 19, 3, "c0_watchhi,3" },
248
  { 19, 4, "c0_watchhi,4" },
249
  { 19, 5, "c0_watchhi,5" },
250
  { 19, 6, "c0_watchhi,6" },
251
  { 19, 7, "c0_watchhi,7" },
252
  { 25, 1, "c0_perfcnt,1" },
253
  { 25, 2, "c0_perfcnt,2" },
254
  { 25, 3, "c0_perfcnt,3" },
255
  { 25, 4, "c0_perfcnt,4" },
256
  { 25, 5, "c0_perfcnt,5" },
257
  { 25, 6, "c0_perfcnt,6" },
258
  { 25, 7, "c0_perfcnt,7" },
259
  { 27, 1, "c0_cacheerr,1"  },
260
  { 27, 2, "c0_cacheerr,2"  },
261
  { 27, 3, "c0_cacheerr,3"  },
262
  { 28, 1, "c0_datalo"    },
263
  { 29, 1, "c0_datahi"    }
264
};
265
266
static const char * const mips_cp0_names_mips3264r2[32] =
267
{
268
  "c0_index",     "c0_random",    "c0_entrylo0",  "c0_entrylo1",
269
  "c0_context",   "c0_pagemask",  "c0_wired",     "c0_hwrena",
270
  "c0_badvaddr",  "c0_count",     "c0_entryhi",   "c0_compare",
271
  "c0_status",    "c0_cause",     "c0_epc",       "c0_prid",
272
  "c0_config",    "c0_lladdr",    "c0_watchlo",   "c0_watchhi",
273
  "c0_xcontext",  "$21",          "$22",          "c0_debug",
274
  "c0_depc",      "c0_perfcnt",   "c0_errctl",    "c0_cacheerr",
275
  "c0_taglo",     "c0_taghi",     "c0_errorepc",  "c0_desave",
276
};
277
278
static const struct mips_cp0sel_name mips_cp0sel_names_mips3264r2[] =
279
{
280
  {  4, 1, "c0_contextconfig" },
281
  {  0, 1, "c0_mvpcontrol"  },
282
  {  0, 2, "c0_mvpconf0"  },
283
  {  0, 3, "c0_mvpconf1"  },
284
  {  1, 1, "c0_vpecontrol"  },
285
  {  1, 2, "c0_vpeconf0"  },
286
  {  1, 3, "c0_vpeconf1"  },
287
  {  1, 4, "c0_yqmask"    },
288
  {  1, 5, "c0_vpeschedule" },
289
  {  1, 6, "c0_vpeschefback"  },
290
  {  2, 1, "c0_tcstatus"  },
291
  {  2, 2, "c0_tcbind"    },
292
  {  2, 3, "c0_tcrestart" },
293
  {  2, 4, "c0_tchalt"    },
294
  {  2, 5, "c0_tccontext" },
295
  {  2, 6, "c0_tcschedule"  },
296
  {  2, 7, "c0_tcschefback" },
297
  {  5, 1, "c0_pagegrain" },
298
  {  6, 1, "c0_srsconf0"  },
299
  {  6, 2, "c0_srsconf1"  },
300
  {  6, 3, "c0_srsconf2"  },
301
  {  6, 4, "c0_srsconf3"  },
302
  {  6, 5, "c0_srsconf4"  },
303
  { 12, 1, "c0_intctl"    },
304
  { 12, 2, "c0_srsctl"    },
305
  { 12, 3, "c0_srsmap"    },
306
  { 15, 1, "c0_ebase"   },
307
  { 16, 1, "c0_config1"   },
308
  { 16, 2, "c0_config2"   },
309
  { 16, 3, "c0_config3"   },
310
  { 18, 1, "c0_watchlo,1" },
311
  { 18, 2, "c0_watchlo,2" },
312
  { 18, 3, "c0_watchlo,3" },
313
  { 18, 4, "c0_watchlo,4" },
314
  { 18, 5, "c0_watchlo,5" },
315
  { 18, 6, "c0_watchlo,6" },
316
  { 18, 7, "c0_watchlo,7" },
317
  { 19, 1, "c0_watchhi,1" },
318
  { 19, 2, "c0_watchhi,2" },
319
  { 19, 3, "c0_watchhi,3" },
320
  { 19, 4, "c0_watchhi,4" },
321
  { 19, 5, "c0_watchhi,5" },
322
  { 19, 6, "c0_watchhi,6" },
323
  { 19, 7, "c0_watchhi,7" },
324
  { 23, 1, "c0_tracecontrol"  },
325
  { 23, 2, "c0_tracecontrol2" },
326
  { 23, 3, "c0_usertracedata" },
327
  { 23, 4, "c0_tracebpc"  },
328
  { 25, 1, "c0_perfcnt,1" },
329
  { 25, 2, "c0_perfcnt,2" },
330
  { 25, 3, "c0_perfcnt,3" },
331
  { 25, 4, "c0_perfcnt,4" },
332
  { 25, 5, "c0_perfcnt,5" },
333
  { 25, 6, "c0_perfcnt,6" },
334
  { 25, 7, "c0_perfcnt,7" },
335
  { 27, 1, "c0_cacheerr,1"  },
336
  { 27, 2, "c0_cacheerr,2"  },
337
  { 27, 3, "c0_cacheerr,3"  },
338
  { 28, 1, "c0_datalo"    },
339
  { 28, 2, "c0_taglo1"    },
340
  { 28, 3, "c0_datalo1"   },
341
  { 28, 4, "c0_taglo2"    },
342
  { 28, 5, "c0_datalo2"   },
343
  { 28, 6, "c0_taglo3"    },
344
  { 28, 7, "c0_datalo3"   },
345
  { 29, 1, "c0_datahi"    },
346
  { 29, 2, "c0_taghi1"    },
347
  { 29, 3, "c0_datahi1"   },
348
  { 29, 4, "c0_taghi2"    },
349
  { 29, 5, "c0_datahi2"   },
350
  { 29, 6, "c0_taghi3"    },
351
  { 29, 7, "c0_datahi3"   },
352
};
353
354
/* SB-1: MIPS64 (mips_cp0_names_mips3264) with minor mods.  */
355
static const char * const mips_cp0_names_sb1[32] =
356
{
357
  "c0_index",     "c0_random",    "c0_entrylo0",  "c0_entrylo1",
358
  "c0_context",   "c0_pagemask",  "c0_wired",     "$7",
359
  "c0_badvaddr",  "c0_count",     "c0_entryhi",   "c0_compare",
360
  "c0_status",    "c0_cause",     "c0_epc",       "c0_prid",
361
  "c0_config",    "c0_lladdr",    "c0_watchlo",   "c0_watchhi",
362
  "c0_xcontext",  "$21",          "$22",          "c0_debug",
363
  "c0_depc",      "c0_perfcnt",   "c0_errctl",    "c0_cacheerr_i",
364
  "c0_taglo_i",   "c0_taghi_i",   "c0_errorepc",  "c0_desave",
365
};
366
367
static const struct mips_cp0sel_name mips_cp0sel_names_sb1[] =
368
{
369
  { 16, 1, "c0_config1"   },
370
  { 18, 1, "c0_watchlo,1" },
371
  { 19, 1, "c0_watchhi,1" },
372
  { 22, 0, "c0_perftrace" },
373
  { 23, 3, "c0_edebug"    },
374
  { 25, 1, "c0_perfcnt,1" },
375
  { 25, 2, "c0_perfcnt,2" },
376
  { 25, 3, "c0_perfcnt,3" },
377
  { 25, 4, "c0_perfcnt,4" },
378
  { 25, 5, "c0_perfcnt,5" },
379
  { 25, 6, "c0_perfcnt,6" },
380
  { 25, 7, "c0_perfcnt,7" },
381
  { 26, 1, "c0_buserr_pa" },
382
  { 27, 1, "c0_cacheerr_d"  },
383
  { 27, 3, "c0_cacheerr_d_pa" },
384
  { 28, 1, "c0_datalo_i"  },
385
  { 28, 2, "c0_taglo_d"   },
386
  { 28, 3, "c0_datalo_d"  },
387
  { 29, 1, "c0_datahi_i"  },
388
  { 29, 2, "c0_taghi_d"   },
389
  { 29, 3, "c0_datahi_d"  },
390
};
391
392
/* Xlr cop0 register names.  */
393
static const char * const mips_cp0_names_xlr[32] = {
394
  "c0_index",     "c0_random",    "c0_entrylo0",  "c0_entrylo1",
395
  "c0_context",   "c0_pagemask",  "c0_wired",     "$7",
396
  "c0_badvaddr",  "c0_count",     "c0_entryhi",   "c0_compare",
397
  "c0_status",    "c0_cause",     "c0_epc",       "c0_prid",
398
  "c0_config",    "c0_lladdr",    "c0_watchlo",   "c0_watchhi",
399
  "c0_xcontext",  "$21",          "$22",          "c0_debug",
400
  "c0_depc",      "c0_perfcnt",   "c0_errctl",    "c0_cacheerr_i",
401
  "c0_taglo_i",   "c0_taghi_i",   "c0_errorepc",  "c0_desave",
402
};
403
404
/* XLR's CP0 Select Registers.  */
405
406
static const struct mips_cp0sel_name mips_cp0sel_names_xlr[] = {
407
  {  9, 6, "c0_extintreq"       },
408
  {  9, 7, "c0_extintmask"      },
409
  { 15, 1, "c0_ebase"           },
410
  { 16, 1, "c0_config1"         },
411
  { 16, 2, "c0_config2"         },
412
  { 16, 3, "c0_config3"         },
413
  { 16, 7, "c0_procid2"         },
414
  { 18, 1, "c0_watchlo,1"       },
415
  { 18, 2, "c0_watchlo,2"       },
416
  { 18, 3, "c0_watchlo,3"       },
417
  { 18, 4, "c0_watchlo,4"       },
418
  { 18, 5, "c0_watchlo,5"       },
419
  { 18, 6, "c0_watchlo,6"       },
420
  { 18, 7, "c0_watchlo,7"       },
421
  { 19, 1, "c0_watchhi,1"       },
422
  { 19, 2, "c0_watchhi,2"       },
423
  { 19, 3, "c0_watchhi,3"       },
424
  { 19, 4, "c0_watchhi,4"       },
425
  { 19, 5, "c0_watchhi,5"       },
426
  { 19, 6, "c0_watchhi,6"       },
427
  { 19, 7, "c0_watchhi,7"       },
428
  { 25, 1, "c0_perfcnt,1"       },
429
  { 25, 2, "c0_perfcnt,2"       },
430
  { 25, 3, "c0_perfcnt,3"       },
431
  { 25, 4, "c0_perfcnt,4"       },
432
  { 25, 5, "c0_perfcnt,5"       },
433
  { 25, 6, "c0_perfcnt,6"       },
434
  { 25, 7, "c0_perfcnt,7"       },
435
  { 27, 1, "c0_cacheerr,1"      },
436
  { 27, 2, "c0_cacheerr,2"      },
437
  { 27, 3, "c0_cacheerr,3"      },
438
  { 28, 1, "c0_datalo"          },
439
  { 29, 1, "c0_datahi"          }
440
};
441
442
static const char * const mips_hwr_names_numeric[32] =
443
{
444
  "$0",   "$1",   "$2",   "$3",   "$4",   "$5",   "$6",   "$7",
445
  "$8",   "$9",   "$10",  "$11",  "$12",  "$13",  "$14",  "$15",
446
  "$16",  "$17",  "$18",  "$19",  "$20",  "$21",  "$22",  "$23",
447
  "$24",  "$25",  "$26",  "$27",  "$28",  "$29",  "$30",  "$31"
448
};
449
450
static const char * const mips_hwr_names_mips3264r2[32] =
451
{
452
  "hwr_cpunum",   "hwr_synci_step", "hwr_cc",     "hwr_ccres",
453
  "$4",          "$5",            "$6",           "$7",
454
  "$8",   "$9",   "$10",  "$11",  "$12",  "$13",  "$14",  "$15",
455
  "$16",  "$17",  "$18",  "$19",  "$20",  "$21",  "$22",  "$23",
456
  "$24",  "$25",  "$26",  "$27",  "$28",  "$29",  "$30",  "$31"
457
};
458
459
static const char * const msa_control_names[32] =
460
{
461
  "msa_ir", "msa_csr",  "msa_access", "msa_save",
462
  "msa_modify", "msa_request",  "msa_map",  "msa_unmap",
463
  "$8",   "$9",   "$10",  "$11",  "$12",  "$13",  "$14",  "$15",
464
  "$16",  "$17",  "$18",  "$19",  "$20",  "$21",  "$22",  "$23",
465
  "$24",  "$25",  "$26",  "$27",  "$28",  "$29",  "$30",  "$31"
466
};
467
468
struct mips_abi_choice
469
{
470
  const char * name;
471
  const char * const *gpr_names;
472
  const char * const *fpr_names;
473
};
474
475
struct mips_abi_choice mips_abi_choices[] =
476
{
477
  { "numeric", mips_gpr_names_numeric, mips_fpr_names_numeric },
478
  { "32", mips_gpr_names_oldabi, mips_fpr_names_32 },
479
  { "o64", mips_gpr_names_oldabi, mips_fpr_names_o64 },
480
  { "n32", mips_gpr_names_newabi, mips_fpr_names_n32 },
481
  { "64", mips_gpr_names_newabi, mips_fpr_names_64 },
482
  { "eabi32", mips_gpr_names_newabi, mips_fpr_names_eabi32 },
483
  { "eabi64", mips_gpr_names_newabi, mips_fpr_names_eabi64 },
484
};
485
486
struct mips_arch_choice
487
{
488
  const char *name;
489
  int bfd_mach_valid;
490
  unsigned long bfd_mach;
491
  int processor;
492
  int isa;
493
  int ase;
494
  const char * const *cp0_names;
495
  const struct mips_cp0sel_name *cp0sel_names;
496
  unsigned int cp0sel_names_len;
497
  const char * const *cp1_names;
498
  const char * const *hwr_names;
499
};
500
501
const struct mips_arch_choice mips_arch_choices[] =
502
{
503
  { "numeric",  0, 0, 0, 0, 0,
504
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_numeric,
505
    mips_hwr_names_numeric },
506
507
  { "r3000",  1, bfd_mach_mips3000, CPU_R3000, ISA_MIPS1, 0,
508
    mips_cp0_names_r3000, NULL, 0, mips_cp1_names_mips,
509
    mips_hwr_names_numeric },
510
  { "r3900",  1, bfd_mach_mips3900, CPU_R3900, ISA_MIPS1, 0,
511
    mips_cp0_names_r3900, NULL, 0, mips_cp1_names_numeric,
512
    mips_hwr_names_numeric },
513
  { "r4000",  1, bfd_mach_mips4000, CPU_R4000, ISA_MIPS3, 0,
514
    mips_cp0_names_r4000, NULL, 0, mips_cp1_names_mips,
515
    mips_hwr_names_numeric },
516
  { "r4010",  1, bfd_mach_mips4010, CPU_R4010, ISA_MIPS2, 0,
517
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
518
    mips_hwr_names_numeric },
519
  { "allegrex", 1, bfd_mach_mips_allegrex, CPU_ALLEGREX, ISA_MIPS2, 0,
520
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_numeric,
521
    mips_hwr_names_numeric },
522
  { "vr4100", 1, bfd_mach_mips4100, CPU_VR4100, ISA_MIPS3, 0,
523
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
524
    mips_hwr_names_numeric },
525
  { "vr4111", 1, bfd_mach_mips4111, CPU_R4111, ISA_MIPS3, 0,
526
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
527
    mips_hwr_names_numeric },
528
  { "vr4120", 1, bfd_mach_mips4120, CPU_VR4120, ISA_MIPS3, 0,
529
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
530
    mips_hwr_names_numeric },
531
  { "r4300",  1, bfd_mach_mips4300, CPU_R4300, ISA_MIPS3, 0,
532
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
533
    mips_hwr_names_numeric },
534
  { "r4400",  1, bfd_mach_mips4400, CPU_R4400, ISA_MIPS3, 0,
535
    mips_cp0_names_r4000, NULL, 0, mips_cp1_names_mips,
536
    mips_hwr_names_numeric },
537
  { "r4600",  1, bfd_mach_mips4600, CPU_R4600, ISA_MIPS3, 0,
538
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
539
    mips_hwr_names_numeric },
540
  { "r4650",  1, bfd_mach_mips4650, CPU_R4650, ISA_MIPS3, 0,
541
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
542
    mips_hwr_names_numeric },
543
  { "tx49", 1, bfd_mach_mips_tx49, CPU_TX49, ISA_MIPS3, 0,
544
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
545
    mips_hwr_names_numeric },
546
  { "r5000",  1, bfd_mach_mips5000, CPU_R5000, ISA_MIPS4, 0,
547
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
548
    mips_hwr_names_numeric },
549
  { "vr5400", 1, bfd_mach_mips5400, CPU_VR5400, ISA_MIPS4, 0,
550
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
551
    mips_hwr_names_numeric },
552
  { "vr5500", 1, bfd_mach_mips5500, CPU_VR5500, ISA_MIPS4, 0,
553
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
554
    mips_hwr_names_numeric },
555
  { "r5900",  1, bfd_mach_mips5900, CPU_R5900, ISA_MIPS3, 0,
556
    mips_cp0_names_r5900, NULL, 0, mips_cp1_names_mips,
557
    mips_hwr_names_numeric },
558
  { "r6000",  1, bfd_mach_mips6000, CPU_R6000, ISA_MIPS2, 0,
559
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
560
    mips_hwr_names_numeric },
561
  { "rm7000", 1, bfd_mach_mips7000, CPU_RM7000, ISA_MIPS4, 0,
562
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
563
    mips_hwr_names_numeric },
564
  { "rm9000", 1, bfd_mach_mips7000, CPU_RM7000, ISA_MIPS4, 0,
565
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
566
    mips_hwr_names_numeric },
567
  { "r8000",  1, bfd_mach_mips8000, CPU_R8000, ISA_MIPS4, 0,
568
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
569
    mips_hwr_names_numeric },
570
  { "r10000", 1, bfd_mach_mips10000, CPU_R10000, ISA_MIPS4, 0,
571
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
572
    mips_hwr_names_numeric },
573
  { "r12000", 1, bfd_mach_mips12000, CPU_R12000, ISA_MIPS4, 0,
574
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
575
    mips_hwr_names_numeric },
576
  { "r14000", 1, bfd_mach_mips14000, CPU_R14000, ISA_MIPS4, 0,
577
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
578
    mips_hwr_names_numeric },
579
  { "r16000", 1, bfd_mach_mips16000, CPU_R16000, ISA_MIPS4, 0,
580
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
581
    mips_hwr_names_numeric },
582
  { "mips5",  1, bfd_mach_mips5, CPU_MIPS5, ISA_MIPS5, 0,
583
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
584
    mips_hwr_names_numeric },
585
586
  /* For stock MIPS32, disassemble all applicable MIPS-specified ASEs.
587
     Note that MIPS-3D and MDMX are not applicable to MIPS32.  (See
588
     _MIPS32 Architecture For Programmers Volume I: Introduction to the
589
     MIPS32 Architecture_ (MIPS Document Number MD00082, Revision 0.95),
590
     page 1.  */
591
  { "mips32", 1, bfd_mach_mipsisa32, CPU_MIPS32,
592
    ISA_MIPS32,  ASE_SMARTMIPS,
593
    mips_cp0_names_mips3264,
594
    mips_cp0sel_names_mips3264, ARRAY_SIZE (mips_cp0sel_names_mips3264),
595
    mips_cp1_names_mips3264, mips_hwr_names_numeric },
596
597
  { "mips32r2", 1, bfd_mach_mipsisa32r2, CPU_MIPS32R2,
598
    ISA_MIPS32R2,
599
    (ASE_SMARTMIPS | ASE_DSP | ASE_DSPR2 | ASE_EVA | ASE_MIPS3D
600
     | ASE_MT | ASE_MCU | ASE_VIRT | ASE_MSA | ASE_XPA),
601
    mips_cp0_names_mips3264r2,
602
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
603
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
604
605
  { "mips32r3", 1, bfd_mach_mipsisa32r3, CPU_MIPS32R3,
606
    ISA_MIPS32R3,
607
    (ASE_SMARTMIPS | ASE_DSP | ASE_DSPR2 | ASE_EVA | ASE_MIPS3D
608
     | ASE_MT | ASE_MCU | ASE_VIRT | ASE_MSA | ASE_XPA),
609
    mips_cp0_names_mips3264r2,
610
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
611
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
612
613
  { "mips32r5", 1, bfd_mach_mipsisa32r5, CPU_MIPS32R5,
614
    ISA_MIPS32R5,
615
    (ASE_SMARTMIPS | ASE_DSP | ASE_DSPR2 | ASE_EVA | ASE_MIPS3D
616
     | ASE_MT | ASE_MCU | ASE_VIRT | ASE_MSA | ASE_XPA),
617
    mips_cp0_names_mips3264r2,
618
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
619
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
620
621
  { "mips32r6", 1, bfd_mach_mipsisa32r6, CPU_MIPS32R6,
622
    ISA_MIPS32R6,
623
    (ASE_EVA | ASE_MSA | ASE_VIRT | ASE_XPA | ASE_MCU | ASE_MT | ASE_DSP
624
     | ASE_DSPR2 | ASE_DSPR3 | ASE_CRC | ASE_GINV),
625
    mips_cp0_names_mips3264r2,
626
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
627
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
628
629
  /* For stock MIPS64, disassemble all applicable MIPS-specified ASEs.  */
630
  { "mips64", 1, bfd_mach_mipsisa64, CPU_MIPS64,
631
    ISA_MIPS64,  ASE_MIPS3D | ASE_MDMX,
632
    mips_cp0_names_mips3264,
633
    mips_cp0sel_names_mips3264, ARRAY_SIZE (mips_cp0sel_names_mips3264),
634
    mips_cp1_names_mips3264, mips_hwr_names_numeric },
635
636
  { "mips64r2", 1, bfd_mach_mipsisa64r2, CPU_MIPS64R2,
637
    ISA_MIPS64R2,
638
    (ASE_MIPS3D | ASE_DSP | ASE_DSPR2 | ASE_DSP64 | ASE_EVA | ASE_MT
639
     | ASE_MCU | ASE_VIRT | ASE_VIRT64 | ASE_MSA | ASE_MSA64 | ASE_XPA),
640
    mips_cp0_names_mips3264r2,
641
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
642
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
643
644
  { "mips64r3", 1, bfd_mach_mipsisa64r3, CPU_MIPS64R3,
645
    ISA_MIPS64R3,
646
    (ASE_MIPS3D | ASE_DSP | ASE_DSPR2 | ASE_DSP64 | ASE_EVA | ASE_MT
647
     | ASE_MCU | ASE_VIRT | ASE_VIRT64 | ASE_MSA | ASE_MSA64 | ASE_XPA),
648
    mips_cp0_names_mips3264r2,
649
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
650
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
651
652
  { "mips64r5", 1, bfd_mach_mipsisa64r5, CPU_MIPS64R5,
653
    ISA_MIPS64R5,
654
    (ASE_MIPS3D | ASE_DSP | ASE_DSPR2 | ASE_DSP64 | ASE_EVA | ASE_MT
655
     | ASE_MCU | ASE_VIRT | ASE_VIRT64 | ASE_MSA | ASE_MSA64 | ASE_XPA),
656
    mips_cp0_names_mips3264r2,
657
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
658
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
659
660
  { "mips64r6", 1, bfd_mach_mipsisa64r6, CPU_MIPS64R6,
661
    ISA_MIPS64R6,
662
    (ASE_EVA | ASE_MSA | ASE_MSA64 | ASE_XPA | ASE_VIRT | ASE_VIRT64
663
     | ASE_MCU | ASE_MT | ASE_DSP | ASE_DSPR2 | ASE_DSPR3 | ASE_CRC
664
     | ASE_CRC64 | ASE_GINV),
665
    mips_cp0_names_mips3264r2,
666
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
667
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
668
669
  { "interaptiv-mr2", 1, bfd_mach_mips_interaptiv_mr2, CPU_INTERAPTIV_MR2,
670
    ISA_MIPS32R3,
671
    ASE_MT | ASE_EVA | ASE_DSP | ASE_DSPR2 | ASE_MIPS16E2 | ASE_MIPS16E2_MT,
672
    mips_cp0_names_mips3264r2,
673
    mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
674
    mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
675
676
  { "sb1",  1, bfd_mach_mips_sb1, CPU_SB1,
677
    ISA_MIPS64 | INSN_SB1,  ASE_MIPS3D,
678
    mips_cp0_names_sb1,
679
    mips_cp0sel_names_sb1, ARRAY_SIZE (mips_cp0sel_names_sb1),
680
    mips_cp1_names_mips3264, mips_hwr_names_numeric },
681
682
  { "loongson2e",   1, bfd_mach_mips_loongson_2e, CPU_LOONGSON_2E,
683
    ISA_MIPS3 | INSN_LOONGSON_2E, 0, mips_cp0_names_numeric,
684
    NULL, 0, mips_cp1_names_mips, mips_hwr_names_numeric },
685
686
  { "loongson2f",   1, bfd_mach_mips_loongson_2f, CPU_LOONGSON_2F,
687
    ISA_MIPS3 | INSN_LOONGSON_2F, ASE_LOONGSON_MMI, mips_cp0_names_numeric,
688
    NULL, 0, mips_cp1_names_mips, mips_hwr_names_numeric },
689
690
  /* The loongson3a is an alias of gs464 for compatibility */
691
  { "loongson3a",   1, bfd_mach_mips_gs464, CPU_GS464,
692
    ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT,
693
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips3264,
694
    mips_hwr_names_numeric },
695
696
  { "gs464",   1, bfd_mach_mips_gs464, CPU_GS464,
697
    ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT,
698
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips3264,
699
    mips_hwr_names_numeric },
700
701
  { "gs464e",   1, bfd_mach_mips_gs464e, CPU_GS464E,
702
    ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT
703
    | ASE_LOONGSON_EXT2, mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips3264,
704
    mips_hwr_names_numeric },
705
706
  { "gs264e",   1, bfd_mach_mips_gs264e, CPU_GS264E,
707
    ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT
708
    | ASE_LOONGSON_EXT2 | ASE_MSA | ASE_MSA64, mips_cp0_names_numeric, NULL,
709
    0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
710
711
  { "octeon",   1, bfd_mach_mips_octeon, CPU_OCTEON,
712
    ISA_MIPS64R2 | INSN_OCTEON, 0, mips_cp0_names_numeric, NULL, 0,
713
    mips_cp1_names_mips3264, mips_hwr_names_numeric },
714
715
  { "octeon+",   1, bfd_mach_mips_octeonp, CPU_OCTEONP,
716
    ISA_MIPS64R2 | INSN_OCTEONP, 0, mips_cp0_names_numeric,
717
    NULL, 0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
718
719
  { "octeon2",   1, bfd_mach_mips_octeon2, CPU_OCTEON2,
720
    ISA_MIPS64R2 | INSN_OCTEON2, 0, mips_cp0_names_numeric,
721
    NULL, 0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
722
723
  { "octeon3",   1, bfd_mach_mips_octeon3, CPU_OCTEON3,
724
    ISA_MIPS64R5 | INSN_OCTEON3, ASE_VIRT | ASE_VIRT64,
725
    mips_cp0_names_numeric,
726
    NULL, 0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
727
728
  { "xlr", 1, bfd_mach_mips_xlr, CPU_XLR,
729
    ISA_MIPS64 | INSN_XLR, 0,
730
    mips_cp0_names_xlr,
731
    mips_cp0sel_names_xlr, ARRAY_SIZE (mips_cp0sel_names_xlr),
732
    mips_cp1_names_mips3264, mips_hwr_names_numeric },
733
734
  /* XLP is mostly like XLR, with the prominent exception it is being
735
     MIPS64R2.  */
736
  { "xlp", 1, bfd_mach_mips_xlr, CPU_XLR,
737
    ISA_MIPS64R2 | INSN_XLR, 0,
738
    mips_cp0_names_xlr,
739
    mips_cp0sel_names_xlr, ARRAY_SIZE (mips_cp0sel_names_xlr),
740
    mips_cp1_names_mips3264, mips_hwr_names_numeric },
741
742
  /* This entry, mips16, is here only for ISA/processor selection; do
743
     not print its name.  */
744
  { "",   1, bfd_mach_mips16, CPU_MIPS16, ISA_MIPS64,
745
    ASE_MIPS16E2 | ASE_MIPS16E2_MT,
746
    mips_cp0_names_numeric, NULL, 0, mips_cp1_names_numeric,
747
    mips_hwr_names_numeric },
748
};
749
750
/* ISA and processor type to disassemble for, and register names to use.
751
   set_default_mips_dis_options and parse_mips_dis_options fill in these
752
   values.  */
753
static int mips_processor;
754
static int mips_isa;
755
static int mips_ase;
756
static int micromips_ase;
757
static const char * const *mips_gpr_names;
758
static const char * const *mips_fpr_names;
759
static const char * const *mips_cp0_names;
760
static const struct mips_cp0sel_name *mips_cp0sel_names;
761
static int mips_cp0sel_names_len;
762
static const char * const *mips_cp1_names;
763
static const char * const *mips_hwr_names;
764
765
/* Other options */
766
static int no_aliases;  /* If set disassemble as most general inst.  */
767

768
static const struct mips_abi_choice *
769
choose_abi_by_name (const char *name, unsigned int namelen)
770
18.1k
{
771
18.1k
  const struct mips_abi_choice *c;
772
18.1k
  unsigned int i;
773
774
141k
  for (i = 0, c = NULL; i < ARRAY_SIZE (mips_abi_choices) && c == NULL; i++)
775
123k
    if (strncmp (mips_abi_choices[i].name, name, namelen) == 0
776
8.25k
  && strlen (mips_abi_choices[i].name) == namelen)
777
798
      c = &mips_abi_choices[i];
778
779
18.1k
  return c;
780
18.1k
}
781
782
static const struct mips_arch_choice *
783
choose_arch_by_name (const char *name, unsigned int namelen)
784
29.1k
{
785
29.1k
  const struct mips_arch_choice *c = NULL;
786
29.1k
  unsigned int i;
787
788
1.51M
  for (i = 0, c = NULL; i < ARRAY_SIZE (mips_arch_choices) && c == NULL; i++)
789
1.48M
    if (strncmp (mips_arch_choices[i].name, name, namelen) == 0
790
12.9k
  && strlen (mips_arch_choices[i].name) == namelen)
791
10.2k
      c = &mips_arch_choices[i];
792
793
29.1k
  return c;
794
29.1k
}
795
796
static const struct mips_arch_choice *
797
choose_arch_by_number (unsigned long mach)
798
1.97M
{
799
1.97M
  static unsigned long hint_bfd_mach;
800
1.97M
  static const struct mips_arch_choice *hint_arch_choice;
801
1.97M
  const struct mips_arch_choice *c;
802
1.97M
  unsigned int i;
803
804
  /* We optimize this because even if the user specifies no
805
     flags, this will be done for every instruction!  */
806
1.97M
  if (hint_bfd_mach == mach
807
1.69M
      && hint_arch_choice != NULL
808
1.69M
      && hint_arch_choice->bfd_mach == hint_bfd_mach)
809
1.69M
    return hint_arch_choice;
810
811
15.1M
  for (i = 0, c = NULL; i < ARRAY_SIZE (mips_arch_choices) && c == NULL; i++)
812
14.8M
    {
813
14.8M
      if (mips_arch_choices[i].bfd_mach_valid
814
14.5M
    && mips_arch_choices[i].bfd_mach == mach)
815
2.53k
  {
816
2.53k
    c = &mips_arch_choices[i];
817
2.53k
    hint_bfd_mach = mach;
818
2.53k
    hint_arch_choice = c;
819
2.53k
  }
820
14.8M
    }
821
286k
  return c;
822
1.97M
}
823
824
/* Check if the object uses NewABI conventions.  */
825
826
static int
827
is_newabi (Elf_Internal_Ehdr *header)
828
968k
{
829
  /* There are no old-style ABIs which use 64-bit ELF.  */
830
968k
  if (header->e_ident[EI_CLASS] == ELFCLASS64)
831
261k
    return 1;
832
833
  /* If a 32-bit ELF file, n32 is a new-style ABI.  */
834
707k
  if ((header->e_flags & EF_MIPS_ABI2) != 0)
835
7.54k
    return 1;
836
837
699k
  return 0;
838
707k
}
839
840
/* Check if the object has microMIPS ASE code.  */
841
842
static int
843
is_micromips (Elf_Internal_Ehdr *header)
844
968k
{
845
968k
  if ((header->e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0)
846
633k
    return 1;
847
848
335k
  return 0;
849
968k
}
850
851
/* Convert ASE flags from .MIPS.abiflags to internal values.  */
852
853
static unsigned long
854
mips_convert_abiflags_ases (unsigned long afl_ases)
855
0
{
856
0
  unsigned long opcode_ases = 0;
857
858
0
  if (afl_ases & AFL_ASE_DSP)
859
0
    opcode_ases |= ASE_DSP;
860
0
  if (afl_ases & AFL_ASE_DSPR2)
861
0
    opcode_ases |= ASE_DSPR2;
862
0
  if (afl_ases & AFL_ASE_EVA)
863
0
    opcode_ases |= ASE_EVA;
864
0
  if (afl_ases & AFL_ASE_MCU)
865
0
    opcode_ases |= ASE_MCU;
866
0
  if (afl_ases & AFL_ASE_MDMX)
867
0
    opcode_ases |= ASE_MDMX;
868
0
  if (afl_ases & AFL_ASE_MIPS3D)
869
0
    opcode_ases |= ASE_MIPS3D;
870
0
  if (afl_ases & AFL_ASE_MT)
871
0
    opcode_ases |= ASE_MT;
872
0
  if (afl_ases & AFL_ASE_SMARTMIPS)
873
0
    opcode_ases |= ASE_SMARTMIPS;
874
0
  if (afl_ases & AFL_ASE_VIRT)
875
0
    opcode_ases |= ASE_VIRT;
876
0
  if (afl_ases & AFL_ASE_MSA)
877
0
    opcode_ases |= ASE_MSA;
878
0
  if (afl_ases & AFL_ASE_XPA)
879
0
    opcode_ases |= ASE_XPA;
880
0
  if (afl_ases & AFL_ASE_DSPR3)
881
0
    opcode_ases |= ASE_DSPR3;
882
0
  if (afl_ases & AFL_ASE_MIPS16E2)
883
0
    opcode_ases |= ASE_MIPS16E2;
884
0
  return opcode_ases;
885
0
}
886
887
/* Calculate combination ASE flags from regular ASE flags.  */
888
889
static unsigned long
890
mips_calculate_combination_ases (int opcode_isa, unsigned long opcode_ases)
891
2.00M
{
892
2.00M
  unsigned long combination_ases = 0;
893
894
2.00M
  if ((opcode_ases & (ASE_XPA | ASE_VIRT)) == (ASE_XPA | ASE_VIRT))
895
338k
    combination_ases |= ASE_XPA_VIRT;
896
2.00M
  if ((opcode_ases & (ASE_MIPS16E2 | ASE_MT)) == (ASE_MIPS16E2 | ASE_MT))
897
23.5k
    combination_ases |= ASE_MIPS16E2_MT;
898
2.00M
  if ((opcode_ases & ASE_EVA)
899
361k
      && ((opcode_isa & INSN_ISA_MASK) == ISA_MIPS64R6
900
172k
    || (opcode_isa & INSN_ISA_MASK) == ISA_MIPS32R6))
901
288k
    combination_ases |= ASE_EVA_R6;
902
2.00M
  return combination_ases;
903
2.00M
}
904
905
static void
906
set_default_mips_dis_options (struct disassemble_info *info)
907
1.97M
{
908
1.97M
  const struct mips_arch_choice *chosen_arch;
909
910
  /* Defaults: mipsIII/r3000 (?!), no microMIPS ASE (any compressed code
911
     is MIPS16 ASE) (o)32-style ("oldabi") GPR names, and numeric FPR,
912
     CP0 register, and HWR names.  */
913
1.97M
  mips_isa = ISA_MIPS3;
914
1.97M
  mips_processor = CPU_R3000;
915
1.97M
  micromips_ase = 0;
916
1.97M
  mips_ase = 0;
917
1.97M
  mips_gpr_names = mips_gpr_names_oldabi;
918
1.97M
  mips_fpr_names = mips_fpr_names_numeric;
919
1.97M
  mips_cp0_names = mips_cp0_names_numeric;
920
1.97M
  mips_cp0sel_names = NULL;
921
1.97M
  mips_cp0sel_names_len = 0;
922
1.97M
  mips_cp1_names = mips_cp1_names_numeric;
923
1.97M
  mips_hwr_names = mips_hwr_names_numeric;
924
1.97M
  no_aliases = 0;
925
926
  /* Set ISA, architecture, and cp0 register names as best we can.  */
927
#if ! SYMTAB_AVAILABLE
928
  /* This is running out on a target machine, not in a host tool.
929
     FIXME: Where does mips_target_info come from?  */
930
  target_processor = mips_target_info.processor;
931
  mips_isa = mips_target_info.isa;
932
  mips_ase = mips_target_info.ase;
933
#else
934
1.97M
  chosen_arch = choose_arch_by_number (info->mach);
935
1.97M
  if (chosen_arch != NULL)
936
1.69M
    {
937
1.69M
      mips_processor = chosen_arch->processor;
938
1.69M
      mips_isa = chosen_arch->isa;
939
1.69M
      mips_ase = chosen_arch->ase;
940
1.69M
      mips_cp0_names = chosen_arch->cp0_names;
941
1.69M
      mips_cp0sel_names = chosen_arch->cp0sel_names;
942
1.69M
      mips_cp0sel_names_len = chosen_arch->cp0sel_names_len;
943
1.69M
      mips_cp1_names = chosen_arch->cp1_names;
944
1.69M
      mips_hwr_names = chosen_arch->hwr_names;
945
1.69M
    }
946
947
  /* Update settings according to the ELF file header flags.  */
948
1.97M
  if (info->flavour == bfd_target_elf_flavour && info->section != NULL)
949
968k
    {
950
968k
      struct bfd *abfd = info->section->owner;
951
968k
      Elf_Internal_Ehdr *header = elf_elfheader (abfd);
952
968k
      Elf_Internal_ABIFlags_v0 *abiflags = NULL;
953
954
      /* We won't ever get here if !HAVE_BFD_MIPS_ELF_GET_ABIFLAGS,
955
   because we won't then have a MIPS/ELF BFD, however we need
956
   to guard against a link error in a `--enable-targets=...'
957
   configuration with a 32-bit host where the MIPS target is
958
   a secondary, or with MIPS/ECOFF configurations.  */
959
968k
#ifdef HAVE_BFD_MIPS_ELF_GET_ABIFLAGS
960
968k
      abiflags = bfd_mips_elf_get_abiflags (abfd);
961
968k
#endif
962
      /* If an ELF "newabi" binary, use the n32/(n)64 GPR names.  */
963
968k
      if (is_newabi (header))
964
269k
  mips_gpr_names = mips_gpr_names_newabi;
965
      /* If a microMIPS binary, then don't use MIPS16 bindings.  */
966
968k
      micromips_ase = is_micromips (header);
967
      /* OR in any extra ASE flags set in ELF file structures.  */
968
968k
      if (abiflags)
969
0
  mips_ase |= mips_convert_abiflags_ases (abiflags->ases);
970
968k
      else if (header->e_flags & EF_MIPS_ARCH_ASE_MDMX)
971
260k
  mips_ase |= ASE_MDMX;
972
968k
    }
973
1.97M
#endif
974
1.97M
  mips_ase |= mips_calculate_combination_ases (mips_isa, mips_ase);
975
1.97M
}
976
977
/* Parse an ASE disassembler option and set the corresponding global
978
   ASE flag(s).  Return TRUE if successful, FALSE otherwise.  */
979
980
static bool
981
parse_mips_ase_option (const char *option)
982
718k
{
983
718k
  if (startswith (option, "msa"))
984
3.13k
    {
985
3.13k
      mips_ase |= ASE_MSA;
986
3.13k
      if ((mips_isa & INSN_ISA_MASK) == ISA_MIPS64R2
987
2.90k
     || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R3
988
2.69k
     || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R5
989
2.46k
     || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R6)
990
916
    mips_ase |= ASE_MSA64;
991
3.13k
      return true;
992
3.13k
    }
993
994
715k
  if (startswith (option, "virt"))
995
11.5k
    {
996
11.5k
      mips_ase |= ASE_VIRT;
997
11.5k
      if (mips_isa & ISA_MIPS64R2
998
2.82k
    || mips_isa & ISA_MIPS64R3
999
306
    || mips_isa & ISA_MIPS64R5
1000
0
    || mips_isa & ISA_MIPS64R6)
1001
11.5k
  mips_ase |= ASE_VIRT64;
1002
11.5k
      return true;
1003
11.5k
    }
1004
1005
703k
  if (startswith (option, "xpa"))
1006
830
    {
1007
830
      mips_ase |= ASE_XPA;
1008
830
      return true;
1009
830
    }
1010
1011
702k
  if (startswith (option, "ginv"))
1012
1.89k
    {
1013
1.89k
      mips_ase |= ASE_GINV;
1014
1.89k
      return true;
1015
1.89k
    }
1016
1017
701k
  if (startswith (option, "loongson-mmi"))
1018
4.81k
    {
1019
4.81k
      mips_ase |= ASE_LOONGSON_MMI;
1020
4.81k
      return true;
1021
4.81k
    }
1022
1023
696k
  if (startswith (option, "loongson-cam"))
1024
506
    {
1025
506
      mips_ase |= ASE_LOONGSON_CAM;
1026
506
      return true;
1027
506
    }
1028
  
1029
  /* Put here for match ext2 frist */
1030
695k
  if (startswith (option, "loongson-ext2"))
1031
454
    {
1032
454
      mips_ase |= ASE_LOONGSON_EXT2;
1033
454
      return true;
1034
454
    }
1035
1036
695k
  if (startswith (option, "loongson-ext"))
1037
4.75k
    {
1038
4.75k
      mips_ase |= ASE_LOONGSON_EXT;
1039
4.75k
      return true;
1040
4.75k
    }
1041
1042
690k
  return false;
1043
695k
}
1044
1045
static void
1046
parse_mips_dis_option (const char *option, unsigned int len)
1047
723k
{
1048
723k
  unsigned int i, optionlen, vallen;
1049
723k
  const char *val;
1050
723k
  const struct mips_abi_choice *chosen_abi;
1051
723k
  const struct mips_arch_choice *chosen_arch;
1052
1053
  /* Try to match options that are simple flags */
1054
723k
  if (startswith (option, "no-aliases"))
1055
5.49k
    {
1056
5.49k
      no_aliases = 1;
1057
5.49k
      return;
1058
5.49k
    }
1059
1060
718k
  if (parse_mips_ase_option (option))
1061
27.9k
    {
1062
27.9k
      mips_ase |= mips_calculate_combination_ases (mips_isa, mips_ase);
1063
27.9k
      return;
1064
27.9k
    }
1065
1066
  /* Look for the = that delimits the end of the option name.  */
1067
8.50M
  for (i = 0; i < len; i++)
1068
7.97M
    if (option[i] == '=')
1069
153k
      break;
1070
1071
690k
  if (i == 0)    /* Invalid option: no name before '='.  */
1072
1.14k
    return;
1073
689k
  if (i == len)    /* Invalid option: no '='.  */
1074
537k
    return;
1075
151k
  if (i == (len - 1))  /* Invalid option: no value after '='.  */
1076
822
    return;
1077
1078
151k
  optionlen = i;
1079
151k
  val = option + (optionlen + 1);
1080
151k
  vallen = len - (optionlen + 1);
1081
1082
151k
  if (strncmp ("gpr-names", option, optionlen) == 0
1083
6.04k
      && strlen ("gpr-names") == optionlen)
1084
3.44k
    {
1085
3.44k
      chosen_abi = choose_abi_by_name (val, vallen);
1086
3.44k
      if (chosen_abi != NULL)
1087
268
  mips_gpr_names = chosen_abi->gpr_names;
1088
3.44k
      return;
1089
3.44k
    }
1090
1091
147k
  if (strncmp ("fpr-names", option, optionlen) == 0
1092
2.07k
      && strlen ("fpr-names") == optionlen)
1093
1.75k
    {
1094
1.75k
      chosen_abi = choose_abi_by_name (val, vallen);
1095
1.75k
      if (chosen_abi != NULL)
1096
294
  mips_fpr_names = chosen_abi->fpr_names;
1097
1.75k
      return;
1098
1.75k
    }
1099
1100
145k
  if (strncmp ("cp0-names", option, optionlen) == 0
1101
5.87k
      && strlen ("cp0-names") == optionlen)
1102
5.32k
    {
1103
5.32k
      chosen_arch = choose_arch_by_name (val, vallen);
1104
5.32k
      if (chosen_arch != NULL)
1105
4.48k
  {
1106
4.48k
    mips_cp0_names = chosen_arch->cp0_names;
1107
4.48k
    mips_cp0sel_names = chosen_arch->cp0sel_names;
1108
4.48k
    mips_cp0sel_names_len = chosen_arch->cp0sel_names_len;
1109
4.48k
  }
1110
5.32k
      return;
1111
5.32k
    }
1112
1113
140k
  if (strncmp ("cp1-names", option, optionlen) == 0
1114
10.4k
      && strlen ("cp1-names") == optionlen)
1115
9.80k
    {
1116
9.80k
      chosen_arch = choose_arch_by_name (val, vallen);
1117
9.80k
      if (chosen_arch != NULL)
1118
994
  mips_cp1_names = chosen_arch->cp1_names;
1119
9.80k
      return;
1120
9.80k
    }
1121
1122
130k
  if (strncmp ("hwr-names", option, optionlen) == 0
1123
1.30k
      && strlen ("hwr-names") == optionlen)
1124
1.05k
    {
1125
1.05k
      chosen_arch = choose_arch_by_name (val, vallen);
1126
1.05k
      if (chosen_arch != NULL)
1127
228
  mips_hwr_names = chosen_arch->hwr_names;
1128
1.05k
      return;
1129
1.05k
    }
1130
1131
129k
  if (strncmp ("reg-names", option, optionlen) == 0
1132
59.4k
      && strlen ("reg-names") == optionlen)
1133
12.9k
    {
1134
      /* We check both ABI and ARCH here unconditionally, so
1135
   that "numeric" will do the desirable thing: select
1136
   numeric register names for all registers.  Other than
1137
   that, a given name probably won't match both.  */
1138
12.9k
      chosen_abi = choose_abi_by_name (val, vallen);
1139
12.9k
      if (chosen_abi != NULL)
1140
236
  {
1141
236
    mips_gpr_names = chosen_abi->gpr_names;
1142
236
    mips_fpr_names = chosen_abi->fpr_names;
1143
236
  }
1144
12.9k
      chosen_arch = choose_arch_by_name (val, vallen);
1145
12.9k
      if (chosen_arch != NULL)
1146
4.58k
  {
1147
4.58k
    mips_cp0_names = chosen_arch->cp0_names;
1148
4.58k
    mips_cp0sel_names = chosen_arch->cp0sel_names;
1149
4.58k
    mips_cp0sel_names_len = chosen_arch->cp0sel_names_len;
1150
4.58k
    mips_cp1_names = chosen_arch->cp1_names;
1151
4.58k
    mips_hwr_names = chosen_arch->hwr_names;
1152
4.58k
  }
1153
12.9k
      return;
1154
12.9k
    }
1155
1156
  /* Invalid option.  */
1157
129k
}
1158
1159
static void
1160
parse_mips_dis_options (const char *options)
1161
1.97M
{
1162
1.97M
  const char *option_end;
1163
1164
1.97M
  if (options == NULL)
1165
1.68M
    return;
1166
1167
1.46M
  while (*options != '\0')
1168
1.16M
    {
1169
      /* Skip empty options.  */
1170
1.16M
      if (*options == ',')
1171
443k
  {
1172
443k
    options++;
1173
443k
    continue;
1174
443k
  }
1175
1176
      /* We know that *options is neither NUL or a comma.  */
1177
723k
      option_end = options + 1;
1178
10.8M
      while (*option_end != ',' && *option_end != '\0')
1179
10.1M
  option_end++;
1180
1181
723k
      parse_mips_dis_option (options, option_end - options);
1182
1183
      /* Go on to the next one.  If option_end points to a comma, it
1184
   will be skipped above.  */
1185
723k
      options = option_end;
1186
723k
    }
1187
296k
}
1188
1189
static const struct mips_cp0sel_name *
1190
lookup_mips_cp0sel_name (const struct mips_cp0sel_name *names,
1191
       unsigned int len,
1192
       unsigned int cp0reg,
1193
       unsigned int sel)
1194
3.68k
{
1195
3.68k
  unsigned int i;
1196
1197
49.8k
  for (i = 0; i < len; i++)
1198
47.0k
    if (names[i].cp0reg == cp0reg && names[i].sel == sel)
1199
919
      return &names[i];
1200
2.77k
  return NULL;
1201
3.68k
}
1202
1203
/* Print register REGNO, of type TYPE, for instruction OPCODE.  */
1204
1205
static void
1206
print_reg (struct disassemble_info *info, const struct mips_opcode *opcode,
1207
     enum mips_reg_operand_type type, int regno)
1208
2.45M
{
1209
2.45M
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
1210
1211
2.45M
  switch (type)
1212
2.45M
    {
1213
2.33M
    case OP_REG_GP:
1214
2.33M
      infprintf (info->stream, dis_style_register, "%s",
1215
2.33M
     mips_gpr_names[regno]);
1216
2.33M
      break;
1217
1218
42.5k
    case OP_REG_FP:
1219
42.5k
      infprintf (info->stream, dis_style_register, "%s",
1220
42.5k
     mips_fpr_names[regno]);
1221
42.5k
      break;
1222
1223
1.92k
    case OP_REG_CCC:
1224
1.92k
      if (opcode->pinfo & (FP_D | FP_S))
1225
1.45k
  infprintf (info->stream, dis_style_register, "$fcc%d", regno);
1226
477
      else
1227
477
  infprintf (info->stream, dis_style_register, "$cc%d", regno);
1228
1.92k
      break;
1229
1230
6.32k
    case OP_REG_VEC:
1231
6.32k
      if (opcode->membership & INSN_5400)
1232
1.38k
  infprintf (info->stream, dis_style_register, "$f%d", regno);
1233
4.94k
      else
1234
4.94k
  infprintf (info->stream, dis_style_register, "$v%d", regno);
1235
6.32k
      break;
1236
1237
3.05k
    case OP_REG_ACC:
1238
3.05k
      infprintf (info->stream, dis_style_register, "$ac%d", regno);
1239
3.05k
      break;
1240
1241
29.5k
    case OP_REG_COPRO:
1242
29.5k
      if (opcode->name[strlen (opcode->name) - 1] == '0')
1243
4.90k
  infprintf (info->stream, dis_style_register, "%s", mips_cp0_names[regno]);
1244
24.6k
      else
1245
24.6k
  infprintf (info->stream, dis_style_register, "$%d", regno);
1246
29.5k
      break;
1247
1248
1.01k
    case OP_REG_CONTROL:
1249
1.01k
      if (opcode->name[strlen (opcode->name) - 1] == '1')
1250
424
  infprintf (info->stream, dis_style_register, "%s", mips_cp1_names[regno]);
1251
588
      else
1252
588
  infprintf (info->stream, dis_style_register, "$%d", regno);
1253
1.01k
      break;
1254
1255
597
    case OP_REG_HW:
1256
597
      infprintf (info->stream, dis_style_register, "%s", mips_hwr_names[regno]);
1257
597
      break;
1258
1259
17.2k
    case OP_REG_VF:
1260
17.2k
      infprintf (info->stream, dis_style_register, "$vf%d", regno);
1261
17.2k
      break;
1262
1263
1.20k
    case OP_REG_VI:
1264
1.20k
      infprintf (info->stream, dis_style_register, "$vi%d", regno);
1265
1.20k
      break;
1266
1267
439
    case OP_REG_R5900_I:
1268
439
      infprintf (info->stream, dis_style_register, "$I");
1269
439
      break;
1270
1271
615
    case OP_REG_R5900_Q:
1272
615
      infprintf (info->stream, dis_style_register, "$Q");
1273
615
      break;
1274
1275
205
    case OP_REG_R5900_R:
1276
205
      infprintf (info->stream, dis_style_register, "$R");
1277
205
      break;
1278
1279
469
    case OP_REG_R5900_ACC:
1280
469
      infprintf (info->stream, dis_style_register, "$ACC");
1281
469
      break;
1282
1283
19.1k
    case OP_REG_MSA:
1284
19.1k
      infprintf (info->stream, dis_style_register, "$w%d", regno);
1285
19.1k
      break;
1286
1287
551
    case OP_REG_MSA_CTRL:
1288
551
      infprintf (info->stream, dis_style_register, "%s",
1289
551
     msa_control_names[regno]);
1290
551
      break;
1291
1292
2.45M
    }
1293
2.45M
}
1294

1295
/* Used to track the state carried over from previous operands in
1296
   an instruction.  */
1297
struct mips_print_arg_state {
1298
  /* The value of the last OP_INT seen.  We only use this for OP_MSB,
1299
     where the value is known to be unsigned and small.  */
1300
  unsigned int last_int;
1301
1302
  /* The type and number of the last OP_REG seen.  We only use this for
1303
     OP_REPEAT_DEST_REG and OP_REPEAT_PREV_REG.  */
1304
  enum mips_reg_operand_type last_reg_type;
1305
  unsigned int last_regno;
1306
  unsigned int dest_regno;
1307
  unsigned int seen_dest;
1308
};
1309
1310
/* Initialize STATE for the start of an instruction.  */
1311
1312
static inline void
1313
init_print_arg_state (struct mips_print_arg_state *state)
1314
2.40M
{
1315
2.40M
  memset (state, 0, sizeof (*state));
1316
2.40M
}
1317
1318
/* Print OP_VU0_SUFFIX or OP_VU0_MATCH_SUFFIX operand OPERAND,
1319
   whose value is given by UVAL.  */
1320
1321
static void
1322
print_vu0_channel (struct disassemble_info *info,
1323
       const struct mips_operand *operand, unsigned int uval,
1324
       enum disassembler_style style)
1325
22.2k
{
1326
22.2k
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
1327
1328
22.2k
  if (operand->size == 4)
1329
16.6k
    infprintf (info->stream, style, "%s%s%s%s",
1330
16.6k
      uval & 8 ? "x" : "",
1331
16.6k
      uval & 4 ? "y" : "",
1332
16.6k
      uval & 2 ? "z" : "",
1333
16.6k
      uval & 1 ? "w" : "");
1334
5.65k
  else if (operand->size == 2)
1335
5.65k
    infprintf (info->stream, style, "%c", "xyzw"[uval]);
1336
0
  else
1337
0
    abort ();
1338
22.2k
}
1339
1340
/* Record information about a register operand.  */
1341
1342
static void
1343
mips_seen_register (struct mips_print_arg_state *state,
1344
        unsigned int regno,
1345
        enum mips_reg_operand_type reg_type)
1346
3.85M
{
1347
3.85M
  state->last_reg_type = reg_type;
1348
3.85M
  state->last_regno = regno;
1349
1350
3.85M
  if (!state->seen_dest)
1351
2.05M
    {
1352
2.05M
      state->seen_dest = 1;
1353
2.05M
      state->dest_regno = regno;
1354
2.05M
    }
1355
3.85M
}
1356
1357
/* Print SAVE/RESTORE instruction operands according to the argument
1358
   register mask AMASK, the number of static registers saved NSREG,
1359
   the $ra, $s0 and $s1 register specifiers RA, S0 and S1 respectively,
1360
   and the frame size FRAME_SIZE.  */
1361
1362
static void
1363
mips_print_save_restore (struct disassemble_info *info, unsigned int amask,
1364
       unsigned int nsreg, unsigned int ra,
1365
       unsigned int s0, unsigned int s1,
1366
       unsigned int frame_size)
1367
12.2k
{
1368
12.2k
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
1369
12.2k
  unsigned int nargs, nstatics, smask, i, j;
1370
12.2k
  void *is = info->stream;
1371
12.2k
  const char *sep;
1372
1373
12.2k
  if (amask == MIPS_SVRS_ALL_ARGS)
1374
431
    {
1375
431
      nargs = 4;
1376
431
      nstatics = 0;
1377
431
    }
1378
11.7k
  else if (amask == MIPS_SVRS_ALL_STATICS)
1379
1.79k
    {
1380
1.79k
      nargs = 0;
1381
1.79k
      nstatics = 4;
1382
1.79k
    }
1383
9.98k
  else
1384
9.98k
    {
1385
9.98k
      nargs = amask >> 2;
1386
9.98k
      nstatics = amask & 3;
1387
9.98k
    }
1388
1389
12.2k
  sep = "";
1390
12.2k
  if (nargs > 0)
1391
1.99k
    {
1392
1.99k
      infprintf (is, dis_style_register, "%s", mips_gpr_names[4]);
1393
1.99k
      if (nargs > 1)
1394
1.00k
  infprintf (is, dis_style_register, "-%s", mips_gpr_names[4 + nargs - 1]);
1395
1.99k
      sep = ",";
1396
1.99k
    }
1397
1398
12.2k
  infprintf (is, dis_style_text, "%s", sep);
1399
12.2k
  infprintf (is, dis_style_immediate, "%d", frame_size);
1400
1401
12.2k
  if (ra)      /* $ra */
1402
8.31k
    {
1403
8.31k
      infprintf (is, dis_style_text, ",");
1404
8.31k
      infprintf (is, dis_style_register, "%s", mips_gpr_names[31]);
1405
8.31k
    }
1406
1407
12.2k
  smask = 0;
1408
12.2k
  if (s0)      /* $s0 */
1409
9.12k
    smask |= 1 << 0;
1410
12.2k
  if (s1)      /* $s1 */
1411
6.72k
    smask |= 1 << 1;
1412
12.2k
  if (nsreg > 0)    /* $s2-$s8 */
1413
2.66k
    smask |= ((1 << nsreg) - 1) << 2;
1414
1415
93.8k
  for (i = 0; i < 9; i++)
1416
81.6k
    if (smask & (1 << i))
1417
10.1k
      {
1418
10.1k
  infprintf (is, dis_style_text, ",");
1419
10.1k
  infprintf (is, dis_style_register, "%s",
1420
10.1k
       mips_gpr_names[i == 8 ? 30 : (16 + i)]);
1421
  /* Skip over string of set bits.  */
1422
28.7k
  for (j = i; smask & (2 << j); j++)
1423
18.5k
    continue;
1424
10.1k
  if (j > i)
1425
7.07k
    {
1426
7.07k
      infprintf (is, dis_style_text, "-");
1427
7.07k
      infprintf (is, dis_style_register, "%s",
1428
7.07k
           mips_gpr_names[j == 8 ? 30 : (16 + j)]);
1429
7.07k
    }
1430
10.1k
  i = j + 1;
1431
10.1k
      }
1432
  /* Statics $ax - $a3.  */
1433
12.2k
  if (nstatics == 1)
1434
1.17k
    {
1435
1.17k
      infprintf (is, dis_style_text, ",");
1436
1.17k
      infprintf (is, dis_style_register, "%s", mips_gpr_names[7]);
1437
1.17k
    }
1438
11.0k
  else if (nstatics > 0)
1439
2.68k
    {
1440
2.68k
      infprintf (is, dis_style_text, ",");
1441
2.68k
      infprintf (is, dis_style_register, "%s",
1442
2.68k
     mips_gpr_names[7 - nstatics + 1]);
1443
2.68k
      infprintf (is, dis_style_text, "-");
1444
2.68k
      infprintf (is, dis_style_register, "%s", mips_gpr_names[7]);
1445
2.68k
    }
1446
12.2k
}
1447
1448
1449
/* Print operand OPERAND of OPCODE, using STATE to track inter-operand state.
1450
   UVAL is the encoding of the operand (shifted into bit 0) and BASE_PC is
1451
   the base address for OP_PCREL operands.  */
1452
1453
static void
1454
print_insn_arg (struct disassemble_info *info,
1455
    struct mips_print_arg_state *state,
1456
    const struct mips_opcode *opcode,
1457
    const struct mips_operand *operand,
1458
    bfd_vma base_pc,
1459
    unsigned int uval)
1460
3.85M
{
1461
3.85M
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
1462
3.85M
  void *is = info->stream;
1463
1464
3.85M
  switch (operand->type)
1465
3.85M
    {
1466
1.09M
    case OP_INT:
1467
1.09M
      {
1468
1.09M
  const struct mips_int_operand *int_op;
1469
1470
1.09M
  int_op = (const struct mips_int_operand *) operand;
1471
1.09M
  uval = mips_decode_int_operand (int_op, uval);
1472
1.09M
  state->last_int = uval;
1473
1.09M
  if (int_op->print_hex)
1474
199k
    infprintf (is, dis_style_immediate, "0x%x", uval);
1475
898k
  else
1476
898k
    infprintf (is, dis_style_immediate, "%d", uval);
1477
1.09M
      }
1478
1.09M
      break;
1479
1480
16.8k
    case OP_MAPPED_INT:
1481
16.8k
      {
1482
16.8k
  const struct mips_mapped_int_operand *mint_op;
1483
1484
16.8k
  mint_op = (const struct mips_mapped_int_operand *) operand;
1485
16.8k
  uval = mint_op->int_map[uval];
1486
16.8k
  state->last_int = uval;
1487
16.8k
  if (mint_op->print_hex)
1488
10.4k
    infprintf (is, dis_style_immediate, "0x%x", uval);
1489
6.35k
  else
1490
6.35k
    infprintf (is, dis_style_immediate, "%d", uval);
1491
16.8k
      }
1492
16.8k
      break;
1493
1494
5.98k
    case OP_MSB:
1495
5.98k
      {
1496
5.98k
  const struct mips_msb_operand *msb_op;
1497
1498
5.98k
  msb_op = (const struct mips_msb_operand *) operand;
1499
5.98k
  uval += msb_op->bias;
1500
5.98k
  if (msb_op->add_lsb)
1501
3.19k
    uval -= state->last_int;
1502
5.98k
  infprintf (is, dis_style_immediate, "0x%x", uval);
1503
5.98k
      }
1504
5.98k
      break;
1505
1506
2.12M
    case OP_REG:
1507
2.39M
    case OP_OPTIONAL_REG:
1508
2.39M
      {
1509
2.39M
  const struct mips_reg_operand *reg_op;
1510
1511
2.39M
  reg_op = (const struct mips_reg_operand *) operand;
1512
2.39M
  uval = mips_decode_reg_operand (reg_op, uval);
1513
2.39M
  print_reg (info, opcode, reg_op->reg_type, uval);
1514
1515
2.39M
  mips_seen_register (state, uval, reg_op->reg_type);
1516
2.39M
      }
1517
2.39M
      break;
1518
1519
3.22k
    case OP_REG_PAIR:
1520
3.22k
      {
1521
3.22k
  const struct mips_reg_pair_operand *pair_op;
1522
1523
3.22k
  pair_op = (const struct mips_reg_pair_operand *) operand;
1524
3.22k
  print_reg (info, opcode, pair_op->reg_type,
1525
3.22k
       pair_op->reg1_map[uval]);
1526
3.22k
  infprintf (is, dis_style_text, ",");
1527
3.22k
  print_reg (info, opcode, pair_op->reg_type,
1528
3.22k
       pair_op->reg2_map[uval]);
1529
3.22k
      }
1530
3.22k
      break;
1531
1532
237k
    case OP_PCREL:
1533
237k
      {
1534
237k
  const struct mips_pcrel_operand *pcrel_op;
1535
1536
237k
  pcrel_op = (const struct mips_pcrel_operand *) operand;
1537
237k
  info->target = mips_decode_pcrel_operand (pcrel_op, base_pc, uval);
1538
1539
  /* For jumps and branches clear the ISA bit except for
1540
     the GDB disassembler.  */
1541
237k
  if (pcrel_op->include_isa_bit
1542
206k
      && info->flavour != bfd_target_unknown_flavour)
1543
181k
    info->target &= -2;
1544
1545
237k
  (*info->print_address_func) (info->target, info);
1546
237k
      }
1547
237k
      break;
1548
1549
337
    case OP_PERF_REG:
1550
337
      infprintf (is, dis_style_register, "%d", uval);
1551
337
      break;
1552
1553
7.49k
    case OP_ADDIUSP_INT:
1554
7.49k
      {
1555
7.49k
  int sval;
1556
1557
7.49k
  sval = mips_signed_operand (operand, uval) * 4;
1558
7.49k
  if (sval >= -8 && sval < 8)
1559
506
    sval ^= 0x400;
1560
7.49k
  infprintf (is, dis_style_immediate, "%d", sval);
1561
7.49k
  break;
1562
2.12M
      }
1563
1564
1.82k
    case OP_CLO_CLZ_DEST:
1565
1.82k
      {
1566
1.82k
  unsigned int reg1, reg2;
1567
1568
1.82k
  reg1 = uval & 31;
1569
1.82k
  reg2 = uval >> 5;
1570
  /* If one is zero use the other.  */
1571
1.82k
  if (reg1 == reg2 || reg2 == 0)
1572
798
    infprintf (is, dis_style_register, "%s", mips_gpr_names[reg1]);
1573
1.03k
  else if (reg1 == 0)
1574
335
    infprintf (is, dis_style_register, "%s", mips_gpr_names[reg2]);
1575
695
  else
1576
695
    {
1577
      /* Bogus, result depends on processor.  */
1578
695
      infprintf (is, dis_style_register, "%s", mips_gpr_names[reg1]);
1579
695
      infprintf (is, dis_style_text, " or ");
1580
695
      infprintf (is, dis_style_register, "%s", mips_gpr_names[reg2]);
1581
695
    }
1582
1.82k
      }
1583
1.82k
      break;
1584
1585
373
    case OP_SAME_RS_RT:
1586
14.2k
    case OP_CHECK_PREV:
1587
32.0k
    case OP_NON_ZERO_REG:
1588
32.0k
      {
1589
32.0k
  print_reg (info, opcode, OP_REG_GP, uval & 31);
1590
32.0k
  mips_seen_register (state, uval, OP_REG_GP);
1591
32.0k
      }
1592
32.0k
      break;
1593
1594
8.89k
    case OP_LWM_SWM_LIST:
1595
8.89k
      if (operand->size == 2)
1596
3.59k
  {
1597
3.59k
    if (uval == 0)
1598
2.58k
      {
1599
2.58k
        infprintf (is, dis_style_register, "%s",
1600
2.58k
       mips_gpr_names[16]);
1601
2.58k
        infprintf (is, dis_style_text, ",");
1602
2.58k
        infprintf (is, dis_style_register, "%s",
1603
2.58k
       mips_gpr_names[31]);
1604
2.58k
      }
1605
1.00k
    else
1606
1.00k
      {
1607
1.00k
        infprintf (is, dis_style_register, "%s",
1608
1.00k
       mips_gpr_names[16]);
1609
1.00k
        infprintf (is, dis_style_text, "-");
1610
1.00k
        infprintf (is, dis_style_register, "%s",
1611
1.00k
       mips_gpr_names[16 + uval]);
1612
1.00k
        infprintf (is, dis_style_text, ",");
1613
1.00k
        infprintf (is, dis_style_register, "%s",
1614
1.00k
       mips_gpr_names[31]);
1615
1.00k
      }
1616
3.59k
  }
1617
5.30k
      else
1618
5.30k
  {
1619
5.30k
    int s_reg_encode;
1620
1621
5.30k
    s_reg_encode = uval & 0xf;
1622
5.30k
    if (s_reg_encode != 0)
1623
4.83k
      {
1624
4.83k
        if (s_reg_encode == 1)
1625
933
    infprintf (is, dis_style_register, "%s", mips_gpr_names[16]);
1626
3.90k
        else if (s_reg_encode < 9)
1627
1.43k
    {
1628
1.43k
      infprintf (is, dis_style_register, "%s",
1629
1.43k
           mips_gpr_names[16]);
1630
1.43k
      infprintf (is, dis_style_text, "-");
1631
1.43k
      infprintf (is, dis_style_register, "%s",
1632
1.43k
           mips_gpr_names[15 + s_reg_encode]);
1633
1.43k
    }
1634
2.46k
        else if (s_reg_encode == 9)
1635
1.47k
    {
1636
1.47k
      infprintf (is, dis_style_register, "%s",
1637
1.47k
           mips_gpr_names[16]);
1638
1.47k
      infprintf (is, dis_style_text, "-");
1639
1.47k
      infprintf (is, dis_style_register, "%s",
1640
1.47k
           mips_gpr_names[23]);
1641
1.47k
      infprintf (is, dis_style_text, ",");
1642
1.47k
      infprintf (is, dis_style_register, "%s",
1643
1.47k
           mips_gpr_names[30]);
1644
1.47k
    }
1645
992
        else
1646
992
    infprintf (is, dis_style_text, "UNKNOWN");
1647
4.83k
      }
1648
1649
5.30k
    if (uval & 0x10) /* For ra.  */
1650
2.15k
      {
1651
2.15k
        if (s_reg_encode == 0)
1652
338
    infprintf (is, dis_style_register, "%s", mips_gpr_names[31]);
1653
1.81k
        else
1654
1.81k
    {
1655
1.81k
      infprintf (is, dis_style_text, ",");
1656
1.81k
      infprintf (is, dis_style_register, "%s",
1657
1.81k
           mips_gpr_names[31]);
1658
1.81k
    }
1659
2.15k
      }
1660
5.30k
  }
1661
8.89k
      break;
1662
1663
3.83k
    case OP_ENTRY_EXIT_LIST:
1664
3.83k
      {
1665
3.83k
  const char *sep;
1666
3.83k
  unsigned int amask, smask;
1667
1668
3.83k
  sep = "";
1669
3.83k
  amask = (uval >> 3) & 7;
1670
3.83k
  if (amask > 0 && amask < 5)
1671
1.75k
    {
1672
1.75k
      infprintf (is, dis_style_register, "%s", mips_gpr_names[4]);
1673
1.75k
      if (amask > 1)
1674
604
        {
1675
604
    infprintf (is, dis_style_text, "-");
1676
604
    infprintf (is, dis_style_register, "%s",
1677
604
         mips_gpr_names[amask + 3]);
1678
604
        }
1679
1.75k
      sep = ",";
1680
1.75k
    }
1681
1682
3.83k
  smask = (uval >> 1) & 3;
1683
3.83k
  if (smask == 3)
1684
1.98k
    {
1685
1.98k
      infprintf (is, dis_style_text, "%s??", sep);
1686
1.98k
      sep = ",";
1687
1.98k
    }
1688
1.84k
  else if (smask > 0)
1689
775
    {
1690
775
      infprintf (is, dis_style_text, "%s", sep);
1691
775
      infprintf (is, dis_style_register, "%s", mips_gpr_names[16]);
1692
775
      if (smask > 1)
1693
404
        {
1694
404
    infprintf (is, dis_style_text, "-");
1695
404
    infprintf (is, dis_style_register, "%s",
1696
404
         mips_gpr_names[smask + 15]);
1697
404
        }
1698
775
      sep = ",";
1699
775
    }
1700
1701
3.83k
  if (uval & 1)
1702
3.09k
    {
1703
3.09k
      infprintf (is, dis_style_text, "%s", sep);
1704
3.09k
      infprintf (is, dis_style_register, "%s", mips_gpr_names[31]);
1705
3.09k
      sep = ",";
1706
3.09k
    }
1707
1708
3.83k
  if (amask == 5 || amask == 6)
1709
834
    {
1710
834
      infprintf (is, dis_style_text, "%s", sep);
1711
834
      infprintf (is, dis_style_register, "%s", mips_fpr_names[0]);
1712
834
      if (amask == 6)
1713
351
        {
1714
351
    infprintf (is, dis_style_text, "-");
1715
351
    infprintf (is, dis_style_register, "%s", mips_fpr_names[1]);
1716
351
        }
1717
834
    }
1718
3.83k
      }
1719
3.83k
      break;
1720
1721
0
    case OP_SAVE_RESTORE_LIST:
1722
      /* Should be handled by the caller due to complex behavior.  */
1723
0
      abort ();
1724
1725
3.48k
    case OP_MDMX_IMM_REG:
1726
3.48k
      {
1727
3.48k
  unsigned int vsel;
1728
1729
3.48k
  vsel = uval >> 5;
1730
3.48k
  uval &= 31;
1731
3.48k
  if ((vsel & 0x10) == 0)
1732
1.21k
    {
1733
1.21k
      int fmt;
1734
1735
1.21k
      vsel &= 0x0f;
1736
3.04k
      for (fmt = 0; fmt < 3; fmt++, vsel >>= 1)
1737
2.63k
        if ((vsel & 1) == 0)
1738
805
    break;
1739
1.21k
      print_reg (info, opcode, OP_REG_VEC, uval);
1740
1.21k
      infprintf (is, dis_style_text, "[");
1741
1.21k
      infprintf (is, dis_style_immediate, "%d", vsel >> 1);
1742
1.21k
      infprintf (is, dis_style_text, "]");
1743
1.21k
    }
1744
2.26k
  else if ((vsel & 0x08) == 0)
1745
1.55k
    print_reg (info, opcode, OP_REG_VEC, uval);
1746
716
  else
1747
716
    infprintf (is, dis_style_immediate, "0x%x", uval);
1748
3.48k
      }
1749
3.48k
      break;
1750
1751
12.1k
    case OP_REPEAT_PREV_REG:
1752
12.1k
      print_reg (info, opcode, state->last_reg_type, state->last_regno);
1753
12.1k
      break;
1754
1755
1.17k
    case OP_REPEAT_DEST_REG:
1756
1.17k
      print_reg (info, opcode, state->last_reg_type, state->dest_regno);
1757
1.17k
      break;
1758
1759
6.89k
    case OP_PC:
1760
6.89k
      infprintf (is, dis_style_register, "$pc");
1761
6.89k
      break;
1762
1763
1.23k
    case OP_REG28:
1764
1.23k
      print_reg (info, opcode, OP_REG_GP, 28);
1765
1.23k
      break;
1766
1767
1.16k
    case OP_VU0_SUFFIX:
1768
16.7k
    case OP_VU0_MATCH_SUFFIX:
1769
16.7k
      print_vu0_channel (info, operand, uval, dis_style_register);
1770
16.7k
      break;
1771
1772
1.28k
    case OP_IMM_INDEX:
1773
1.28k
      infprintf (is, dis_style_text, "[");
1774
1.28k
      infprintf (is, dis_style_immediate, "%d", uval);
1775
1.28k
      infprintf (is, dis_style_text, "]");
1776
1.28k
      break;
1777
1778
364
    case OP_REG_INDEX:
1779
364
      infprintf (is, dis_style_text, "[");
1780
364
      print_reg (info, opcode, OP_REG_GP, uval);
1781
364
      infprintf (is, dis_style_text, "]");
1782
364
      break;
1783
3.85M
    }
1784
3.85M
}
1785
1786
/* Validate the arguments for INSN, which is described by OPCODE.
1787
   Use DECODE_OPERAND to get the encoding of each operand.  */
1788
1789
static bool
1790
validate_insn_args (const struct mips_opcode *opcode,
1791
        const struct mips_operand *(*decode_operand) (const char *),
1792
        unsigned int insn)
1793
929k
{
1794
929k
  struct mips_print_arg_state state;
1795
929k
  const struct mips_operand *operand;
1796
929k
  const char *s;
1797
929k
  unsigned int uval;
1798
1799
929k
  init_print_arg_state (&state);
1800
4.99M
  for (s = opcode->args; *s; ++s)
1801
4.07M
    {
1802
4.07M
      switch (*s)
1803
4.07M
  {
1804
1.12M
  case ',':
1805
1.44M
  case '(':
1806
1.76M
  case ')':
1807
1.76M
    break;
1808
1809
279
  case '#':
1810
279
    ++s;
1811
279
    break;
1812
1813
2.31M
  default:
1814
2.31M
    operand = decode_operand (s);
1815
1816
2.31M
    if (operand)
1817
2.31M
      {
1818
2.31M
        uval = mips_extract_operand (operand, insn);
1819
2.31M
        switch (operand->type)
1820
2.31M
    {
1821
1.18M
    case OP_REG:
1822
1.42M
    case OP_OPTIONAL_REG:
1823
1.42M
      {
1824
1.42M
        const struct mips_reg_operand *reg_op;
1825
1826
1.42M
        reg_op = (const struct mips_reg_operand *) operand;
1827
1.42M
        uval = mips_decode_reg_operand (reg_op, uval);
1828
1.42M
        mips_seen_register (&state, uval, reg_op->reg_type);
1829
1.42M
      }
1830
1.42M
    break;
1831
1832
6.43k
    case OP_SAME_RS_RT:
1833
6.43k
      {
1834
6.43k
        unsigned int reg1, reg2;
1835
1836
6.43k
        reg1 = uval & 31;
1837
6.43k
        reg2 = uval >> 5;
1838
1839
6.43k
        if (reg1 != reg2 || reg1 == 0)
1840
6.06k
          return false;
1841
6.43k
      }
1842
373
    break;
1843
1844
21.4k
    case OP_CHECK_PREV:
1845
21.4k
      {
1846
21.4k
        const struct mips_check_prev_operand *prev_op;
1847
1848
21.4k
        prev_op = (const struct mips_check_prev_operand *) operand;
1849
1850
21.4k
        if (!prev_op->zero_ok && uval == 0)
1851
1.20k
          return false;
1852
1853
20.2k
        if (((prev_op->less_than_ok && uval < state.last_regno)
1854
14.9k
      || (prev_op->greater_than_ok && uval > state.last_regno)
1855
7.25k
      || (prev_op->equal_ok && uval == state.last_regno)))
1856
13.8k
          break;
1857
1858
6.33k
        return false;
1859
20.2k
      }
1860
1861
20.0k
    case OP_NON_ZERO_REG:
1862
20.0k
      {
1863
20.0k
        if (uval == 0)
1864
1.39k
          return false;
1865
20.0k
      }
1866
18.6k
    break;
1867
1868
611k
    case OP_INT:
1869
628k
    case OP_MAPPED_INT:
1870
633k
    case OP_MSB:
1871
637k
    case OP_REG_PAIR:
1872
779k
    case OP_PCREL:
1873
779k
    case OP_PERF_REG:
1874
787k
    case OP_ADDIUSP_INT:
1875
788k
    case OP_CLO_CLZ_DEST:
1876
797k
    case OP_LWM_SWM_LIST:
1877
797k
    case OP_ENTRY_EXIT_LIST:
1878
801k
    case OP_MDMX_IMM_REG:
1879
813k
    case OP_REPEAT_PREV_REG:
1880
814k
    case OP_REPEAT_DEST_REG:
1881
820k
    case OP_PC:
1882
820k
    case OP_REG28:
1883
821k
    case OP_VU0_SUFFIX:
1884
836k
    case OP_VU0_MATCH_SUFFIX:
1885
838k
    case OP_IMM_INDEX:
1886
838k
    case OP_REG_INDEX:
1887
838k
    case OP_SAVE_RESTORE_LIST:
1888
838k
      break;
1889
2.31M
    }
1890
2.31M
      }
1891
2.29M
    if (*s == 'm' || *s == '+' || *s == '-')
1892
549k
      ++s;
1893
4.07M
  }
1894
4.07M
    }
1895
914k
  return true;
1896
929k
}
1897
1898
/* Print the arguments for INSN, which is described by OPCODE.
1899
   Use DECODE_OPERAND to get the encoding of each operand.  Use BASE_PC
1900
   as the base of OP_PCREL operands, adjusting by LENGTH if the OP_PCREL
1901
   operand is for a branch or jump.  */
1902
1903
static void
1904
print_insn_args (struct disassemble_info *info,
1905
     const struct mips_opcode *opcode,
1906
     const struct mips_operand *(*decode_operand) (const char *),
1907
     unsigned int insn, bfd_vma insn_pc, unsigned int length)
1908
837k
{
1909
837k
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
1910
837k
  void *is = info->stream;
1911
837k
  struct mips_print_arg_state state;
1912
837k
  const struct mips_operand *operand;
1913
837k
  const char *s;
1914
1915
837k
  init_print_arg_state (&state);
1916
4.88M
  for (s = opcode->args; *s; ++s)
1917
4.04M
    {
1918
4.04M
      switch (*s)
1919
4.04M
  {
1920
1.11M
  case ',':
1921
1.43M
  case '(':
1922
1.75M
  case ')':
1923
1.75M
    infprintf (is, dis_style_text, "%c", *s);
1924
1.75M
    break;
1925
1926
279
  case '#':
1927
279
    ++s;
1928
279
    infprintf (is, dis_style_text, "%c%c", *s, *s);
1929
279
    break;
1930
1931
2.28M
  default:
1932
2.28M
    operand = decode_operand (s);
1933
2.28M
    if (!operand)
1934
0
      {
1935
        /* xgettext:c-format */
1936
0
        infprintf (is, dis_style_text,
1937
0
       _("# internal error, undefined operand in `%s %s'"),
1938
0
       opcode->name, opcode->args);
1939
0
        return;
1940
0
      }
1941
1942
2.28M
    if (operand->type == OP_SAVE_RESTORE_LIST)
1943
363
      {
1944
        /* Handle this case here because of the complex behavior.  */
1945
363
        unsigned int amask = (insn >> 15) & 0xf;
1946
363
        unsigned int nsreg = (insn >> 23) & 0x7;
1947
363
        unsigned int ra = insn & 0x1000;      /* $ra */
1948
363
        unsigned int s0 = insn & 0x800;     /* $s0 */
1949
363
        unsigned int s1 = insn & 0x400;     /* $s1 */
1950
363
        unsigned int frame_size = (((insn >> 15) & 0xf0)
1951
363
           | ((insn >> 6) & 0x0f)) * 8;
1952
363
        mips_print_save_restore (info, amask, nsreg, ra, s0, s1,
1953
363
               frame_size);
1954
363
      }
1955
2.28M
    else if (operand->type == OP_REG
1956
1.17M
       && s[1] == ','
1957
617k
       && (s[2] == 'H' || s[2] == 'J')
1958
2.77k
       && opcode->name[strlen (opcode->name) - 1] == '0')
1959
2.46k
      {
1960
        /* Coprocessor register 0 with sel field.  */
1961
2.46k
        const struct mips_cp0sel_name *n;
1962
2.46k
        unsigned int reg, sel;
1963
1964
2.46k
        reg = mips_extract_operand (operand, insn);
1965
2.46k
        s += 2;
1966
2.46k
        operand = decode_operand (s);
1967
2.46k
        sel = mips_extract_operand (operand, insn);
1968
1969
        /* CP0 register including 'sel' code for mftc0, to be
1970
     printed textually if known.  If not known, print both
1971
     CP0 register name and sel numerically since CP0 register
1972
     with sel 0 may have a name unrelated to register being
1973
     printed.  */
1974
2.46k
        n = lookup_mips_cp0sel_name (mips_cp0sel_names,
1975
2.46k
             mips_cp0sel_names_len,
1976
2.46k
             reg, sel);
1977
2.46k
        if (n != NULL)
1978
417
    infprintf (is, dis_style_register, "%s", n->name);
1979
2.04k
        else
1980
2.04k
    {
1981
2.04k
      infprintf (is, dis_style_register, "$%d", reg);
1982
2.04k
      infprintf (is, dis_style_text, ",");
1983
2.04k
      infprintf (is, dis_style_immediate, "%d", sel);
1984
2.04k
    }
1985
2.46k
      }
1986
2.28M
    else
1987
2.28M
      {
1988
2.28M
        bfd_vma base_pc = insn_pc;
1989
1990
        /* Adjust the PC relative base so that branch/jump insns use
1991
     the following PC as the base but genuinely PC relative
1992
     operands use the current PC.  */
1993
2.28M
        if (operand->type == OP_PCREL)
1994
142k
    {
1995
142k
      const struct mips_pcrel_operand *pcrel_op;
1996
1997
142k
      pcrel_op = (const struct mips_pcrel_operand *) operand;
1998
      /* The include_isa_bit flag is sufficient to distinguish
1999
         branch/jump from other PC relative operands.  */
2000
142k
      if (pcrel_op->include_isa_bit)
2001
140k
        base_pc += length;
2002
142k
    }
2003
2004
2.28M
        print_insn_arg (info, &state, opcode, operand, base_pc,
2005
2.28M
            mips_extract_operand (operand, insn));
2006
2.28M
      }
2007
2.28M
    if (*s == 'm' || *s == '+' || *s == '-')
2008
548k
      ++s;
2009
2.28M
    break;
2010
4.04M
  }
2011
4.04M
    }
2012
837k
}
2013

2014
/* Print the mips instruction at address MEMADDR in debugged memory,
2015
   on using INFO.  Returns length of the instruction, in bytes, which is
2016
   always INSNLEN.  BIGENDIAN must be 1 if this is big-endian code, 0 if
2017
   this is little-endian code.  */
2018
2019
static int
2020
print_insn_mips (bfd_vma memaddr,
2021
     int word,
2022
     struct disassemble_info *info)
2023
713k
{
2024
713k
#define GET_OP(insn, field)     \
2025
825k
  (((insn) >> OP_SH_##field) & OP_MASK_##field)
2026
713k
  static const struct mips_opcode *mips_hash[OP_MASK_OP + 1];
2027
713k
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
2028
713k
  const struct mips_opcode *op;
2029
713k
  static bool init = 0;
2030
713k
  void *is = info->stream;
2031
2032
  /* Build a hash table to shorten the search time.  */
2033
713k
  if (! init)
2034
3
    {
2035
3
      unsigned int i;
2036
2037
195
      for (i = 0; i <= OP_MASK_OP; i++)
2038
192
  {
2039
126k
    for (op = mips_opcodes; op < &mips_opcodes[NUMOPCODES]; op++)
2040
126k
      {
2041
126k
        if (op->pinfo == INSN_MACRO
2042
111k
      || (no_aliases && (op->pinfo2 & INSN2_ALIAS)))
2043
14.6k
    continue;
2044
111k
        if (i == GET_OP (op->match, OP))
2045
192
    {
2046
192
      mips_hash[i] = op;
2047
192
      break;
2048
192
    }
2049
111k
      }
2050
192
  }
2051
2052
3
      init = 1;
2053
3
    }
2054
2055
713k
  info->bytes_per_chunk = INSNLEN;
2056
713k
  info->display_endian = info->endian;
2057
713k
  info->insn_info_valid = 1;
2058
713k
  info->branch_delay_insns = 0;
2059
713k
  info->data_size = 0;
2060
713k
  info->insn_type = dis_nonbranch;
2061
713k
  info->target = 0;
2062
713k
  info->target2 = 0;
2063
2064
713k
  op = mips_hash[GET_OP (word, OP)];
2065
713k
  if (op != NULL)
2066
713k
    {
2067
882M
      for (; op < &mips_opcodes[NUMOPCODES]; op++)
2068
882M
  {
2069
882M
    if (op->pinfo != INSN_MACRO
2070
808M
        && !(no_aliases && (op->pinfo2 & INSN2_ALIAS))
2071
808M
        && (word & op->mask) == op->match)
2072
871k
      {
2073
        /* We always disassemble the jalx instruction, except for MIPS r6.  */
2074
871k
        if (!opcode_is_member (op, mips_isa, mips_ase, mips_processor)
2075
399k
     && (strcmp (op->name, "jalx")
2076
3.40k
         || (mips_isa & INSN_ISA_MASK) == ISA_MIPS32R6
2077
2.21k
         || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R6))
2078
399k
    continue;
2079
2080
        /* Figure out instruction type and branch delay information.  */
2081
471k
        if ((op->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2082
30.8k
          {
2083
30.8k
      if ((op->pinfo & (INSN_WRITE_GPR_31 | INSN_WRITE_1)) != 0)
2084
19.2k
        info->insn_type = dis_jsr;
2085
11.6k
      else
2086
11.6k
        info->insn_type = dis_branch;
2087
30.8k
      info->branch_delay_insns = 1;
2088
30.8k
    }
2089
440k
        else if ((op->pinfo & (INSN_COND_BRANCH_DELAY
2090
440k
             | INSN_COND_BRANCH_LIKELY)) != 0)
2091
35.7k
    {
2092
35.7k
      if ((op->pinfo & INSN_WRITE_GPR_31) != 0)
2093
851
        info->insn_type = dis_condjsr;
2094
34.8k
      else
2095
34.8k
        info->insn_type = dis_condbranch;
2096
35.7k
      info->branch_delay_insns = 1;
2097
35.7k
    }
2098
405k
        else if ((op->pinfo & (INSN_STORE_MEMORY
2099
405k
             | INSN_LOAD_MEMORY)) != 0)
2100
136k
    info->insn_type = dis_dref;
2101
2102
471k
        if (!validate_insn_args (op, decode_mips_operand, word))
2103
15.0k
    continue;
2104
2105
456k
        infprintf (is, dis_style_mnemonic, "%s", op->name);
2106
456k
        if (op->pinfo2 & INSN2_VU0_CHANNEL_SUFFIX)
2107
5.57k
    {
2108
5.57k
      unsigned int uval;
2109
2110
5.57k
      infprintf (is, dis_style_mnemonic, ".");
2111
5.57k
      uval = mips_extract_operand (&mips_vu0_channel_mask, word);
2112
5.57k
      print_vu0_channel (info, &mips_vu0_channel_mask, uval,
2113
5.57k
             dis_style_mnemonic);
2114
5.57k
    }
2115
2116
456k
        if (op->args[0])
2117
409k
    {
2118
409k
      infprintf (is, dis_style_text, "\t");
2119
409k
      print_insn_args (info, op, decode_mips_operand, word,
2120
409k
           memaddr, 4);
2121
409k
    }
2122
2123
456k
        return INSNLEN;
2124
471k
      }
2125
882M
  }
2126
713k
    }
2127
257k
#undef GET_OP
2128
2129
  /* Handle undefined instructions.  */
2130
257k
  info->insn_type = dis_noninsn;
2131
257k
  infprintf (is, dis_style_assembler_directive, ".word");
2132
257k
  infprintf (is, dis_style_text, "\t");
2133
257k
  infprintf (is, dis_style_immediate, "0x%x", word);
2134
257k
  return INSNLEN;
2135
713k
}
2136

2137
/* Disassemble an operand for a mips16 instruction.  */
2138
2139
static void
2140
print_mips16_insn_arg (struct disassemble_info *info,
2141
           struct mips_print_arg_state *state,
2142
           const struct mips_opcode *opcode,
2143
           char type, bfd_vma memaddr,
2144
           unsigned insn, bool use_extend,
2145
           unsigned extend, bool is_offset)
2146
2.68M
{
2147
2.68M
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
2148
2.68M
  void *is = info->stream;
2149
2.68M
  const struct mips_operand *operand, *ext_operand;
2150
2.68M
  unsigned short ext_size;
2151
2.68M
  unsigned int uval;
2152
2.68M
  bfd_vma baseaddr;
2153
2154
2.68M
  if (!use_extend)
2155
2.51M
    extend = 0;
2156
2157
2.68M
  switch (type)
2158
2.68M
    {
2159
803k
    case ',':
2160
953k
    case '(':
2161
1.10M
    case ')':
2162
1.10M
      infprintf (is, dis_style_text, "%c", type);
2163
1.10M
      break;
2164
2165
1.58M
    default:
2166
1.58M
      operand = decode_mips16_operand (type, false);
2167
1.58M
      if (!operand)
2168
0
  {
2169
    /* xgettext:c-format */
2170
0
    infprintf (is, dis_style_text, _("# internal error, undefined operand in `%s %s'"),
2171
0
         opcode->name, opcode->args);
2172
0
    return;
2173
0
  }
2174
2175
1.58M
      if (operand->type == OP_SAVE_RESTORE_LIST)
2176
11.8k
  {
2177
    /* Handle this case here because of the complex interaction
2178
       with the EXTEND opcode.  */
2179
11.8k
    unsigned int amask = extend & 0xf;
2180
11.8k
    unsigned int nsreg = (extend >> 8) & 0x7;
2181
11.8k
    unsigned int ra = insn & 0x40;      /* $ra */
2182
11.8k
    unsigned int s0 = insn & 0x20;      /* $s0 */
2183
11.8k
    unsigned int s1 = insn & 0x10;      /* $s1 */
2184
11.8k
    unsigned int frame_size = ((extend & 0xf0) | (insn & 0x0f)) * 8;
2185
11.8k
    if (frame_size == 0 && !use_extend)
2186
2.31k
      frame_size = 128;
2187
11.8k
    mips_print_save_restore (info, amask, nsreg, ra, s0, s1, frame_size);
2188
11.8k
    break;
2189
11.8k
  }
2190
2191
1.57M
      if (is_offset && operand->type == OP_INT)
2192
150k
  {
2193
150k
    const struct mips_int_operand *int_op;
2194
2195
150k
    int_op = (const struct mips_int_operand *) operand;
2196
150k
    info->insn_type = dis_dref;
2197
150k
    info->data_size = 1 << int_op->shift;
2198
150k
  }
2199
2200
1.57M
      ext_size = 0;
2201
1.57M
      if (use_extend)
2202
101k
  {
2203
101k
    ext_operand = decode_mips16_operand (type, true);
2204
101k
    if (ext_operand != operand
2205
70.5k
        || (operand->type == OP_INT && operand->lsb == 0
2206
3.45k
      && mips_opcode_32bit_p (opcode)))
2207
34.3k
      {
2208
34.3k
        ext_size = ext_operand->size;
2209
34.3k
        operand = ext_operand;
2210
34.3k
      }
2211
101k
  }
2212
1.57M
      if (operand->size == 26)
2213
9.43k
  uval = ((extend & 0x1f) << 21) | ((extend & 0x3e0) << 11) | insn;
2214
1.56M
      else if (ext_size == 16 || ext_size == 9)
2215
28.9k
  uval = ((extend & 0x1f) << 11) | (extend & 0x7e0) | (insn & 0x1f);
2216
1.53M
      else if (ext_size == 15)
2217
1.63k
  uval = ((extend & 0xf) << 11) | (extend & 0x7f0) | (insn & 0xf);
2218
1.53M
      else if (ext_size == 6)
2219
3.02k
  uval = ((extend >> 6) & 0x1f) | (extend & 0x20);
2220
1.52M
      else
2221
1.52M
  uval = mips_extract_operand (operand, (extend << 16) | insn);
2222
1.57M
      if (ext_size == 9)
2223
2.47k
  uval &= (1U << ext_size) - 1;
2224
2225
1.57M
      baseaddr = memaddr + 2;
2226
1.57M
      if (operand->type == OP_PCREL)
2227
95.6k
  {
2228
95.6k
    const struct mips_pcrel_operand *pcrel_op;
2229
2230
95.6k
    pcrel_op = (const struct mips_pcrel_operand *) operand;
2231
95.6k
    if (!pcrel_op->include_isa_bit && use_extend)
2232
3.32k
      baseaddr = memaddr - 2;
2233
92.3k
    else if (!pcrel_op->include_isa_bit)
2234
26.2k
      {
2235
26.2k
        bfd_byte buffer[2];
2236
2237
        /* If this instruction is in the delay slot of a JAL/JALX
2238
     instruction, the base address is the address of the
2239
     JAL/JALX instruction.  If it is in the delay slot of
2240
     a JR/JALR instruction, the base address is the address
2241
     of the JR/JALR instruction.  This test is unreliable:
2242
     we have no way of knowing whether the previous word is
2243
     instruction or data.  */
2244
26.2k
        if (info->read_memory_func (memaddr - 4, buffer, 2, info) == 0
2245
13.0k
      && (((info->endian == BFD_ENDIAN_BIG
2246
13.0k
      ? bfd_getb16 (buffer)
2247
13.0k
      : bfd_getl16 (buffer))
2248
13.0k
           & 0xf800) == 0x1800))
2249
308
    baseaddr = memaddr - 4;
2250
25.9k
        else if (info->read_memory_func (memaddr - 2, buffer, 2,
2251
25.9k
                 info) == 0
2252
12.8k
           && (((info->endian == BFD_ENDIAN_BIG
2253
12.8k
           ? bfd_getb16 (buffer)
2254
12.8k
           : bfd_getl16 (buffer))
2255
12.8k
          & 0xf89f) == 0xe800)
2256
34
           && (((info->endian == BFD_ENDIAN_BIG
2257
34
           ? bfd_getb16 (buffer)
2258
34
           : bfd_getl16 (buffer))
2259
34
          & 0x0060) != 0x0060))
2260
31
    baseaddr = memaddr - 2;
2261
25.9k
        else
2262
25.9k
    baseaddr = memaddr;
2263
26.2k
      }
2264
95.6k
  }
2265
2266
1.57M
      print_insn_arg (info, state, opcode, operand, baseaddr + 1, uval);
2267
1.57M
      break;
2268
2.68M
    }
2269
2.68M
}
2270
2271
2272
/* Check if the given address is the last word of a MIPS16 PLT entry.
2273
   This word is data and depending on the value it may interfere with
2274
   disassembly of further PLT entries.  We make use of the fact PLT
2275
   symbols are marked BSF_SYNTHETIC.  */
2276
static bool
2277
is_mips16_plt_tail (struct disassemble_info *info, bfd_vma addr)
2278
676k
{
2279
676k
  if (info->symbols
2280
38
      && info->symbols[0]
2281
38
      && (info->symbols[0]->flags & BSF_SYNTHETIC)
2282
0
      && addr == bfd_asymbol_value (info->symbols[0]) + 12)
2283
0
    return true;
2284
2285
676k
  return false;
2286
676k
}
2287
2288
/* Whether none, a 32-bit or a 16-bit instruction match has been done.  */
2289
2290
enum match_kind
2291
{
2292
  MATCH_NONE,
2293
  MATCH_FULL,
2294
  MATCH_SHORT
2295
};
2296
2297
/* Disassemble mips16 instructions.  */
2298
2299
static int
2300
print_insn_mips16 (bfd_vma memaddr, struct disassemble_info *info)
2301
676k
{
2302
676k
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
2303
676k
  int status;
2304
676k
  bfd_byte buffer[4];
2305
676k
  const struct mips_opcode *op, *opend;
2306
676k
  struct mips_print_arg_state state;
2307
676k
  void *is = info->stream;
2308
676k
  bool have_second;
2309
676k
  bool extend_only;
2310
676k
  unsigned int second;
2311
676k
  unsigned int first;
2312
676k
  unsigned int full;
2313
2314
676k
  info->bytes_per_chunk = 2;
2315
676k
  info->display_endian = info->endian;
2316
676k
  info->insn_info_valid = 1;
2317
676k
  info->branch_delay_insns = 0;
2318
676k
  info->data_size = 0;
2319
676k
  info->target = 0;
2320
676k
  info->target2 = 0;
2321
2322
676k
#define GET_OP(insn, field) \
2323
676k
  (((insn) >> MIPS16OP_SH_##field) & MIPS16OP_MASK_##field)
2324
  /* Decode PLT entry's GOT slot address word.  */
2325
676k
  if (is_mips16_plt_tail (info, memaddr))
2326
0
    {
2327
0
      info->insn_type = dis_noninsn;
2328
0
      status = (*info->read_memory_func) (memaddr, buffer, 4, info);
2329
0
      if (status == 0)
2330
0
  {
2331
0
    unsigned int gotslot;
2332
2333
0
    if (info->endian == BFD_ENDIAN_BIG)
2334
0
      gotslot = bfd_getb32 (buffer);
2335
0
    else
2336
0
      gotslot = bfd_getl32 (buffer);
2337
0
    infprintf (is, dis_style_assembler_directive, ".word");
2338
0
    infprintf (is, dis_style_text, "\t");
2339
0
    infprintf (is, dis_style_immediate, "0x%x", gotslot);
2340
2341
0
    return 4;
2342
0
  }
2343
0
    }
2344
676k
  else
2345
676k
    {
2346
676k
      info->insn_type = dis_nonbranch;
2347
676k
      status = (*info->read_memory_func) (memaddr, buffer, 2, info);
2348
676k
    }
2349
676k
  if (status != 0)
2350
1.24k
    {
2351
1.24k
      (*info->memory_error_func) (status, memaddr, info);
2352
1.24k
      return -1;
2353
1.24k
    }
2354
2355
675k
  extend_only = false;
2356
2357
675k
  if (info->endian == BFD_ENDIAN_BIG)
2358
176k
    first = bfd_getb16 (buffer);
2359
499k
  else
2360
499k
    first = bfd_getl16 (buffer);
2361
2362
675k
  status = (*info->read_memory_func) (memaddr + 2, buffer, 2, info);
2363
675k
  if (status == 0)
2364
674k
    {
2365
674k
      have_second = true;
2366
674k
      if (info->endian == BFD_ENDIAN_BIG)
2367
176k
  second = bfd_getb16 (buffer);
2368
498k
      else
2369
498k
  second = bfd_getl16 (buffer);
2370
674k
      full = (first << 16) | second;
2371
674k
    }
2372
1.37k
  else
2373
1.37k
    {
2374
1.37k
      have_second = false;
2375
1.37k
      second = 0;
2376
1.37k
      full = first;
2377
1.37k
    }
2378
2379
  /* FIXME: Should probably use a hash table on the major opcode here.  */
2380
2381
675k
  opend = mips16_opcodes + bfd_mips16_num_opcodes;
2382
69.0M
  for (op = mips16_opcodes; op < opend; op++)
2383
69.0M
    {
2384
69.0M
      enum match_kind match;
2385
2386
69.0M
      if (!opcode_is_member (op, mips_isa, mips_ase, mips_processor))
2387
13.3M
  continue;
2388
2389
55.6M
      if (op->pinfo == INSN_MACRO
2390
43.3M
    || (no_aliases && (op->pinfo2 & INSN2_ALIAS)))
2391
12.3M
  match = MATCH_NONE;
2392
43.2M
      else if (mips_opcode_32bit_p (op))
2393
7.88M
  {
2394
7.88M
    if (have_second
2395
7.85M
        && (full & op->mask) == op->match)
2396
18.2k
      match = MATCH_FULL;
2397
7.86M
    else
2398
7.86M
      match = MATCH_NONE;
2399
7.88M
  }
2400
35.4M
      else if ((first & op->mask) == op->match)
2401
581k
  {
2402
581k
    match = MATCH_SHORT;
2403
581k
    second = 0;
2404
581k
    full = first;
2405
581k
  }
2406
34.8M
      else if ((first & 0xf800) == 0xf000
2407
4.84M
         && have_second
2408
4.83M
         && !extend_only
2409
4.53M
         && (second & op->mask) == op->match)
2410
40.8k
  {
2411
40.8k
    if (op->pinfo2 & INSN2_SHORT_ONLY)
2412
8.14k
      {
2413
8.14k
        match = MATCH_NONE;
2414
8.14k
        extend_only = true;
2415
8.14k
      }
2416
32.7k
    else
2417
32.7k
      match = MATCH_FULL;
2418
40.8k
  }
2419
34.7M
      else
2420
34.7M
  match = MATCH_NONE;
2421
2422
55.6M
      if (match != MATCH_NONE)
2423
632k
  {
2424
632k
    const char *s;
2425
2426
632k
    infprintf (is, dis_style_mnemonic, "%s", op->name);
2427
632k
    if (op->args[0] != '\0')
2428
632k
      infprintf (is, dis_style_text, "\t");
2429
2430
632k
    init_print_arg_state (&state);
2431
3.32M
    for (s = op->args; *s != '\0'; s++)
2432
2.69M
      {
2433
2.69M
        if (*s == ','
2434
808k
      && s[1] == 'w'
2435
23.0k
      && GET_OP (full, RX) == GET_OP (full, RY))
2436
3.25k
    {
2437
      /* Skip the register and the comma.  */
2438
3.25k
      ++s;
2439
3.25k
      continue;
2440
3.25k
    }
2441
2.69M
        if (*s == ','
2442
805k
      && s[1] == 'v'
2443
11.1k
      && GET_OP (full, RZ) == GET_OP (full, RX))
2444
1.75k
    {
2445
      /* Skip the register and the comma.  */
2446
1.75k
      ++s;
2447
1.75k
      continue;
2448
1.75k
    }
2449
2.68M
        if (s[0] == 'N'
2450
1.64k
      && s[1] == ','
2451
1.22k
      && s[2] == 'O'
2452
1.22k
      && op->name[strlen (op->name) - 1] == '0')
2453
1.22k
    {
2454
      /* Coprocessor register 0 with sel field.  */
2455
1.22k
      const struct mips_cp0sel_name *n;
2456
1.22k
      const struct mips_operand *operand;
2457
1.22k
      unsigned int reg, sel;
2458
2459
1.22k
      operand = decode_mips16_operand (*s, true);
2460
1.22k
      reg = mips_extract_operand (operand, (first << 16) | second);
2461
1.22k
      s += 2;
2462
1.22k
      operand = decode_mips16_operand (*s, true);
2463
1.22k
      sel = mips_extract_operand (operand, (first << 16) | second);
2464
2465
      /* CP0 register including 'sel' code for mftc0, to be
2466
         printed textually if known.  If not known, print both
2467
         CP0 register name and sel numerically since CP0 register
2468
         with sel 0 may have a name unrelated to register being
2469
         printed.  */
2470
1.22k
      n = lookup_mips_cp0sel_name (mips_cp0sel_names,
2471
1.22k
                 mips_cp0sel_names_len,
2472
1.22k
                 reg, sel);
2473
1.22k
      if (n != NULL)
2474
502
        infprintf (is, dis_style_register, "%s", n->name);
2475
727
      else
2476
727
        {
2477
727
          infprintf (is, dis_style_register, "$%d", reg);
2478
727
          infprintf (is, dis_style_text, ",");
2479
727
          infprintf (is, dis_style_immediate, "%d", sel);
2480
727
        }
2481
1.22k
    }
2482
2.68M
        else
2483
2.68M
    switch (match)
2484
2.68M
      {
2485
173k
        case MATCH_FULL:
2486
173k
          print_mips16_insn_arg (info, &state, op, *s, memaddr + 2,
2487
173k
               second, true, first, s[1] == '(');
2488
173k
          break;
2489
2.51M
        case MATCH_SHORT:
2490
2.51M
          print_mips16_insn_arg (info, &state, op, *s, memaddr,
2491
2.51M
               first, false, 0, s[1] == '(');
2492
2.51M
          break;
2493
0
        case MATCH_NONE:  /* Stop the compiler complaining.  */
2494
0
          break;
2495
2.68M
      }
2496
2.68M
      }
2497
2498
    /* Figure out branch instruction type and delay slot information.  */
2499
632k
    if ((op->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
2500
10.8k
      info->branch_delay_insns = 1;
2501
632k
    if ((op->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
2502
622k
        || (op->pinfo2 & INSN2_UNCOND_BRANCH) != 0)
2503
30.3k
      {
2504
30.3k
        if ((op->pinfo & INSN_WRITE_GPR_31) != 0)
2505
9.55k
    info->insn_type = dis_jsr;
2506
20.7k
        else
2507
20.7k
    info->insn_type = dis_branch;
2508
30.3k
      }
2509
602k
    else if ((op->pinfo2 & INSN2_COND_BRANCH) != 0)
2510
37.3k
      info->insn_type = dis_condbranch;
2511
2512
632k
    return match == MATCH_FULL ? 4 : 2;
2513
632k
  }
2514
55.6M
    }
2515
42.5k
#undef GET_OP
2516
2517
42.5k
  infprintf (is, dis_style_assembler_directive, ".short");
2518
42.5k
  infprintf (is, dis_style_text, "\t");
2519
42.5k
  infprintf (is, dis_style_immediate, "0x%x", first);
2520
42.5k
  info->insn_type = dis_noninsn;
2521
2522
42.5k
  return 2;
2523
675k
}
2524
2525
/* Disassemble microMIPS instructions.  */
2526
2527
static int
2528
print_insn_micromips (bfd_vma memaddr, struct disassemble_info *info)
2529
585k
{
2530
585k
  const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
2531
585k
  const struct mips_opcode *op, *opend;
2532
585k
  void *is = info->stream;
2533
585k
  bfd_byte buffer[2];
2534
585k
  unsigned int higher;
2535
585k
  unsigned int length;
2536
585k
  int status;
2537
585k
  unsigned int insn;
2538
2539
585k
  info->bytes_per_chunk = 2;
2540
585k
  info->display_endian = info->endian;
2541
585k
  info->insn_info_valid = 1;
2542
585k
  info->branch_delay_insns = 0;
2543
585k
  info->data_size = 0;
2544
585k
  info->insn_type = dis_nonbranch;
2545
585k
  info->target = 0;
2546
585k
  info->target2 = 0;
2547
2548
585k
  status = (*info->read_memory_func) (memaddr, buffer, 2, info);
2549
585k
  if (status != 0)
2550
440
    {
2551
440
      (*info->memory_error_func) (status, memaddr, info);
2552
440
      return -1;
2553
440
    }
2554
2555
585k
  length = 2;
2556
2557
585k
  if (info->endian == BFD_ENDIAN_BIG)
2558
267k
    insn = bfd_getb16 (buffer);
2559
317k
  else
2560
317k
    insn = bfd_getl16 (buffer);
2561
2562
585k
  if ((insn & 0x1c00) == 0x0000 || (insn & 0x1000) == 0x1000)
2563
419k
    {
2564
      /* This is a 32-bit microMIPS instruction.  */
2565
419k
      higher = insn;
2566
2567
419k
      status = (*info->read_memory_func) (memaddr + 2, buffer, 2, info);
2568
419k
      if (status != 0)
2569
323
  {
2570
323
    infprintf (is, dis_style_text, "micromips 0x%x", higher);
2571
323
    (*info->memory_error_func) (status, memaddr + 2, info);
2572
323
    return -1;
2573
323
  }
2574
2575
419k
      if (info->endian == BFD_ENDIAN_BIG)
2576
198k
  insn = bfd_getb16 (buffer);
2577
221k
      else
2578
221k
  insn = bfd_getl16 (buffer);
2579
2580
419k
      insn = insn | (higher << 16);
2581
2582
419k
      length += 2;
2583
419k
    }
2584
2585
  /* FIXME: Should probably use a hash table on the major opcode here.  */
2586
2587
584k
  opend = micromips_opcodes + bfd_micromips_num_opcodes;
2588
400M
  for (op = micromips_opcodes; op < opend; op++)
2589
400M
    {
2590
400M
      if (op->pinfo != INSN_MACRO
2591
322M
    && !(no_aliases && (op->pinfo2 & INSN2_ALIAS))
2592
322M
    && (insn & op->mask) == op->match
2593
577k
    && ((length == 2 && (op->mask & 0xffff0000) == 0)
2594
433k
        || (length == 4 && (op->mask & 0xffff0000) != 0)))
2595
458k
  {
2596
458k
    if (!validate_insn_args (op, decode_micromips_operand, insn))
2597
0
      continue;
2598
2599
458k
    infprintf (is, dis_style_mnemonic, "%s", op->name);
2600
2601
458k
    if (op->args[0])
2602
428k
      {
2603
428k
        infprintf (is, dis_style_text, "\t");
2604
428k
        print_insn_args (info, op, decode_micromips_operand, insn,
2605
428k
             memaddr + 1, length);
2606
428k
      }
2607
2608
    /* Figure out instruction type and branch delay information.  */
2609
458k
    if ((op->pinfo
2610
458k
         & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY)) != 0)
2611
51.3k
      info->branch_delay_insns = 1;
2612
458k
    if (((op->pinfo & INSN_UNCOND_BRANCH_DELAY)
2613
458k
         | (op->pinfo2 & INSN2_UNCOND_BRANCH)) != 0)
2614
31.5k
      {
2615
31.5k
        if ((op->pinfo & (INSN_WRITE_GPR_31 | INSN_WRITE_1)) != 0)
2616
22.5k
    info->insn_type = dis_jsr;
2617
9.03k
        else
2618
9.03k
    info->insn_type = dis_branch;
2619
31.5k
      }
2620
426k
    else if (((op->pinfo & INSN_COND_BRANCH_DELAY)
2621
426k
        | (op->pinfo2 & INSN2_COND_BRANCH)) != 0)
2622
20.5k
      {
2623
20.5k
        if ((op->pinfo & INSN_WRITE_GPR_31) != 0)
2624
1.43k
    info->insn_type = dis_condjsr;
2625
19.0k
        else
2626
19.0k
    info->insn_type = dis_condbranch;
2627
20.5k
      }
2628
405k
    else if ((op->pinfo
2629
405k
        & (INSN_STORE_MEMORY | INSN_LOAD_MEMORY)) != 0)
2630
180k
      info->insn_type = dis_dref;
2631
2632
458k
    return length;
2633
458k
  }
2634
400M
    }
2635
2636
126k
  infprintf (is, dis_style_assembler_directive, ".short");
2637
126k
  infprintf (is, dis_style_text, "\t");
2638
126k
  if (length != 2)
2639
105k
    {
2640
105k
      infprintf (is, dis_style_immediate, "0x%x", (insn >> 16) & 0xffff);
2641
105k
      infprintf (is, dis_style_text, ", ");
2642
105k
    }
2643
126k
  infprintf (is, dis_style_immediate, "0x%x", (insn & 0xffff));
2644
2645
126k
  info->insn_type = dis_noninsn;
2646
2647
126k
  return length;
2648
584k
}
2649
2650
/* Return 1 if a symbol associated with the location being disassembled
2651
   indicates a compressed mode, either MIPS16 or microMIPS, according to
2652
   MICROMIPS_P.  We iterate over all the symbols at the address being
2653
   considered assuming if at least one of them indicates code compression,
2654
   then such code has been genuinely produced here (other symbols could
2655
   have been derived from function symbols defined elsewhere or could
2656
   define data).  Otherwise, return 0.  */
2657
2658
static bool
2659
is_compressed_mode_p (struct disassemble_info *info, bool micromips_p)
2660
1.43M
{
2661
1.43M
  int i;
2662
1.43M
  int l;
2663
2664
1.43M
  for (i = info->symtab_pos, l = i + info->num_symbols; i < l; i++)
2665
564
    if (((info->symtab[i])->flags & BSF_SYNTHETIC) != 0
2666
0
  && ((!micromips_p
2667
0
       && ELF_ST_IS_MIPS16 ((*info->symbols)->udata.i))
2668
0
      || (micromips_p
2669
0
    && ELF_ST_IS_MICROMIPS ((*info->symbols)->udata.i))))
2670
0
      return 1;
2671
564
    else if (bfd_asymbol_flavour (info->symtab[i]) == bfd_target_elf_flavour
2672
564
        && info->symtab[i]->section == info->section)
2673
496
      {
2674
496
  elf_symbol_type *symbol = (elf_symbol_type *) info->symtab[i];
2675
496
  if ((!micromips_p
2676
248
       && ELF_ST_IS_MIPS16 (symbol->internal_elf_sym.st_other))
2677
458
      || (micromips_p
2678
248
    && ELF_ST_IS_MICROMIPS (symbol->internal_elf_sym.st_other)))
2679
38
    return 1;
2680
496
      }
2681
2682
1.43M
  return 0;
2683
1.43M
}
2684
2685
/* In an environment where we do not know the symbol type of the
2686
   instruction we are forced to assume that the low order bit of the
2687
   instructions' address may mark it as a mips16 instruction.  If we
2688
   are single stepping, or the pc is within the disassembled function,
2689
   this works.  Otherwise, we need a clue.  Sometimes.  */
2690
2691
static int
2692
_print_insn_mips (bfd_vma memaddr,
2693
      struct disassemble_info *info,
2694
      enum bfd_endian endianness)
2695
1.97M
{
2696
1.97M
  bfd_byte buffer[INSNLEN];
2697
1.97M
  int status;
2698
2699
1.97M
  set_default_mips_dis_options (info);
2700
1.97M
  parse_mips_dis_options (info->disassembler_options);
2701
2702
1.97M
  if (info->mach == bfd_mach_mips16)
2703
364k
    return print_insn_mips16 (memaddr, info);
2704
1.61M
  if (info->mach == bfd_mach_mips_micromips)
2705
254k
    return print_insn_micromips (memaddr, info);
2706
2707
1.35M
#if 1
2708
  /* FIXME: If odd address, this is CLEARLY a compressed instruction.  */
2709
  /* Only a few tools will work this way.  */
2710
1.35M
  if (memaddr & 0x01)
2711
643k
    {
2712
643k
      if (micromips_ase)
2713
331k
  return print_insn_micromips (memaddr, info);
2714
312k
      else
2715
312k
  return print_insn_mips16 (memaddr, info);
2716
643k
    }
2717
715k
#endif
2718
2719
715k
#if SYMTAB_AVAILABLE
2720
715k
  if (is_compressed_mode_p (info, true))
2721
0
    return print_insn_micromips (memaddr, info);
2722
715k
  if (is_compressed_mode_p (info, false))
2723
38
    return print_insn_mips16 (memaddr, info);
2724
715k
#endif
2725
2726
715k
  status = (*info->read_memory_func) (memaddr, buffer, INSNLEN, info);
2727
715k
  if (status == 0)
2728
713k
    {
2729
713k
      int insn;
2730
2731
713k
      if (endianness == BFD_ENDIAN_BIG)
2732
311k
  insn = bfd_getb32 (buffer);
2733
402k
      else
2734
402k
  insn = bfd_getl32 (buffer);
2735
2736
713k
      return print_insn_mips (memaddr, insn, info);
2737
713k
    }
2738
2.00k
  else
2739
2.00k
    {
2740
2.00k
      (*info->memory_error_func) (status, memaddr, info);
2741
2.00k
      return -1;
2742
2.00k
    }
2743
715k
}
2744
2745
int
2746
print_insn_big_mips (bfd_vma memaddr, struct disassemble_info *info)
2747
853k
{
2748
853k
  return _print_insn_mips (memaddr, info, BFD_ENDIAN_BIG);
2749
853k
}
2750
2751
int
2752
print_insn_little_mips (bfd_vma memaddr, struct disassemble_info *info)
2753
1.12M
{
2754
1.12M
  return _print_insn_mips (memaddr, info, BFD_ENDIAN_LITTLE);
2755
1.12M
}
2756

2757
/* Indices into option argument vector for options accepting an argument.
2758
   Use MIPS_OPTION_ARG_NONE for options accepting no argument.  */
2759
typedef enum
2760
{
2761
  MIPS_OPTION_ARG_NONE = -1,
2762
  MIPS_OPTION_ARG_ABI,
2763
  MIPS_OPTION_ARG_ARCH,
2764
  MIPS_OPTION_ARG_SIZE
2765
} mips_option_arg_t;
2766
2767
/* Valid MIPS disassembler options.  */
2768
static struct
2769
{
2770
  const char *name;
2771
  const char *description;
2772
  mips_option_arg_t arg;
2773
} mips_options[] =
2774
{
2775
  { "no-aliases", N_("Use canonical instruction forms.\n"),
2776
      MIPS_OPTION_ARG_NONE },
2777
  { "msa",        N_("Recognize MSA instructions.\n"),
2778
      MIPS_OPTION_ARG_NONE },
2779
  { "virt",       N_("Recognize the virtualization ASE instructions.\n"),
2780
      MIPS_OPTION_ARG_NONE },
2781
  { "xpa",        N_("Recognize the eXtended Physical Address (XPA) ASE\n\
2782
                  instructions.\n"),
2783
      MIPS_OPTION_ARG_NONE },
2784
  { "ginv",       N_("Recognize the Global INValidate (GINV) ASE "
2785
         "instructions.\n"),
2786
      MIPS_OPTION_ARG_NONE },
2787
  { "loongson-mmi",
2788
      N_("Recognize the Loongson MultiMedia extensions "
2789
         "Instructions (MMI) ASE instructions.\n"),
2790
      MIPS_OPTION_ARG_NONE },
2791
  { "loongson-cam",
2792
      N_("Recognize the Loongson Content Address Memory (CAM) "
2793
         " instructions.\n"),
2794
      MIPS_OPTION_ARG_NONE },
2795
  { "loongson-ext",
2796
      N_("Recognize the Loongson EXTensions (EXT) "
2797
         " instructions.\n"),
2798
      MIPS_OPTION_ARG_NONE },
2799
  { "loongson-ext2",
2800
      N_("Recognize the Loongson EXTensions R2 (EXT2) "
2801
         " instructions.\n"),
2802
      MIPS_OPTION_ARG_NONE },
2803
  { "gpr-names=", N_("Print GPR names according to specified ABI.\n\
2804
                  Default: based on binary being disassembled.\n"),
2805
      MIPS_OPTION_ARG_ABI },
2806
  { "fpr-names=", N_("Print FPR names according to specified ABI.\n\
2807
                  Default: numeric.\n"),
2808
      MIPS_OPTION_ARG_ABI },
2809
  { "cp0-names=", N_("Print CP0 register names according to specified "
2810
         "architecture.\n\
2811
                  Default: based on binary being disassembled.\n"),
2812
      MIPS_OPTION_ARG_ARCH },
2813
  { "hwr-names=", N_("Print HWR names according to specified architecture.\n\
2814
                  Default: based on binary being disassembled.\n"),
2815
      MIPS_OPTION_ARG_ARCH },
2816
  { "reg-names=", N_("Print GPR and FPR names according to specified ABI.\n"),
2817
      MIPS_OPTION_ARG_ABI },
2818
  { "reg-names=", N_("Print CP0 register and HWR names according to "
2819
         "specified\n\
2820
                  architecture."),
2821
      MIPS_OPTION_ARG_ARCH }
2822
};
2823
2824
/* Build the structure representing valid MIPS disassembler options.
2825
   This is done dynamically for maintenance ease purpose; a static
2826
   initializer would be unreadable.  */
2827
2828
const disasm_options_and_args_t *
2829
disassembler_options_mips (void)
2830
0
{
2831
0
  static disasm_options_and_args_t *opts_and_args;
2832
2833
0
  if (opts_and_args == NULL)
2834
0
    {
2835
0
      size_t num_options = ARRAY_SIZE (mips_options);
2836
0
      size_t num_args = MIPS_OPTION_ARG_SIZE;
2837
0
      disasm_option_arg_t *args;
2838
0
      disasm_options_t *opts;
2839
0
      size_t i;
2840
0
      size_t j;
2841
2842
0
      args = XNEWVEC (disasm_option_arg_t, num_args + 1);
2843
2844
0
      args[MIPS_OPTION_ARG_ABI].name = "ABI";
2845
0
      args[MIPS_OPTION_ARG_ABI].values
2846
0
  = XNEWVEC (const char *, ARRAY_SIZE (mips_abi_choices) + 1);
2847
0
      for (i = 0; i < ARRAY_SIZE (mips_abi_choices); i++)
2848
0
  args[MIPS_OPTION_ARG_ABI].values[i] = mips_abi_choices[i].name;
2849
      /* The array we return must be NULL terminated.  */
2850
0
      args[MIPS_OPTION_ARG_ABI].values[i] = NULL;
2851
2852
0
      args[MIPS_OPTION_ARG_ARCH].name = "ARCH";
2853
0
      args[MIPS_OPTION_ARG_ARCH].values
2854
0
  = XNEWVEC (const char *, ARRAY_SIZE (mips_arch_choices) + 1);
2855
0
      for (i = 0, j = 0; i < ARRAY_SIZE (mips_arch_choices); i++)
2856
0
  if (*mips_arch_choices[i].name != '\0')
2857
0
    args[MIPS_OPTION_ARG_ARCH].values[j++] = mips_arch_choices[i].name;
2858
      /* The array we return must be NULL terminated.  */
2859
0
      args[MIPS_OPTION_ARG_ARCH].values[j] = NULL;
2860
2861
      /* The array we return must be NULL terminated.  */
2862
0
      args[MIPS_OPTION_ARG_SIZE].name = NULL;
2863
0
      args[MIPS_OPTION_ARG_SIZE].values = NULL;
2864
2865
0
      opts_and_args = XNEW (disasm_options_and_args_t);
2866
0
      opts_and_args->args = args;
2867
2868
0
      opts = &opts_and_args->options;
2869
0
      opts->name = XNEWVEC (const char *, num_options + 1);
2870
0
      opts->description = XNEWVEC (const char *, num_options + 1);
2871
0
      opts->arg = XNEWVEC (const disasm_option_arg_t *, num_options + 1);
2872
0
      for (i = 0; i < num_options; i++)
2873
0
  {
2874
0
    opts->name[i] = mips_options[i].name;
2875
0
    opts->description[i] = _(mips_options[i].description);
2876
0
    if (mips_options[i].arg != MIPS_OPTION_ARG_NONE)
2877
0
      opts->arg[i] = &args[mips_options[i].arg];
2878
0
    else
2879
0
      opts->arg[i] = NULL;
2880
0
  }
2881
      /* The array we return must be NULL terminated.  */
2882
0
      opts->name[i] = NULL;
2883
0
      opts->description[i] = NULL;
2884
0
      opts->arg[i] = NULL;
2885
0
    }
2886
2887
0
  return opts_and_args;
2888
0
}
2889
2890
void
2891
print_mips_disassembler_options (FILE *stream)
2892
0
{
2893
0
  const disasm_options_and_args_t *opts_and_args;
2894
0
  const disasm_option_arg_t *args;
2895
0
  const disasm_options_t *opts;
2896
0
  size_t max_len = 0;
2897
0
  size_t i;
2898
0
  size_t j;
2899
2900
0
  opts_and_args = disassembler_options_mips ();
2901
0
  opts = &opts_and_args->options;
2902
0
  args = opts_and_args->args;
2903
2904
0
  fprintf (stream, _("\n\
2905
0
The following MIPS specific disassembler options are supported for use\n\
2906
0
with the -M switch (multiple options should be separated by commas):\n\n"));
2907
2908
  /* Compute the length of the longest option name.  */
2909
0
  for (i = 0; opts->name[i] != NULL; i++)
2910
0
    {
2911
0
      size_t len = strlen (opts->name[i]);
2912
2913
0
      if (opts->arg[i] != NULL)
2914
0
  len += strlen (opts->arg[i]->name);
2915
0
      if (max_len < len)
2916
0
  max_len = len;
2917
0
    }
2918
2919
0
  for (i = 0, max_len++; opts->name[i] != NULL; i++)
2920
0
    {
2921
0
      fprintf (stream, "  %s", opts->name[i]);
2922
0
      if (opts->arg[i] != NULL)
2923
0
  fprintf (stream, "%s", opts->arg[i]->name);
2924
0
      if (opts->description[i] != NULL)
2925
0
  {
2926
0
    size_t len = strlen (opts->name[i]);
2927
2928
0
    if (opts->arg[i] != NULL)
2929
0
      len += strlen (opts->arg[i]->name);
2930
0
    fprintf (stream,
2931
0
       "%*c %s", (int) (max_len - len), ' ', opts->description[i]);
2932
0
  }
2933
0
      fprintf (stream, _("\n"));
2934
0
    }
2935
2936
0
  for (i = 0; args[i].name != NULL; i++)
2937
0
    {
2938
0
      if (args[i].values == NULL)
2939
0
  continue;
2940
0
      fprintf (stream, _("\n\
2941
0
  For the options above, the following values are supported for \"%s\":\n   "),
2942
0
         args[i].name);
2943
0
      for (j = 0; args[i].values[j] != NULL; j++)
2944
0
  fprintf (stream, " %s", args[i].values[j]);
2945
0
      fprintf (stream, _("\n"));
2946
0
    }
2947
2948
  fprintf (stream, _("\n"));
2949
0
}