Coverage Report

Created: 2025-07-08 11:15

/src/binutils-gdb/opcodes/ia64-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* ia64-dis.c -- Disassemble ia64 instructions
2
   Copyright (C) 1998-2025 Free Software Foundation, Inc.
3
   Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
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 file; see the file COPYING.  If not, write to the
19
   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20
   02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include <assert.h>
24
25
#include "disassemble.h"
26
#include "opcode/ia64.h"
27
28
305k
#define NELEMS(a) ((int) (sizeof (a) / sizeof (a[0])))
29
30
/* Disassemble ia64 instruction.  */
31
32
/* Return the instruction type for OPCODE found in unit UNIT. */
33
34
static enum ia64_insn_type
35
unit_to_type (ia64_insn opcode, enum ia64_unit unit)
36
85.1k
{
37
85.1k
  enum ia64_insn_type type;
38
85.1k
  int op;
39
40
85.1k
  op = IA64_OP (opcode);
41
42
85.1k
  if (op >= 8 && (unit == IA64_UNIT_I || unit == IA64_UNIT_M))
43
19.5k
    {
44
19.5k
      type = IA64_TYPE_A;
45
19.5k
    }
46
65.5k
  else
47
65.5k
    {
48
65.5k
      switch (unit)
49
65.5k
  {
50
27.6k
  case IA64_UNIT_I:
51
27.6k
    type = IA64_TYPE_I; break;
52
23.2k
  case IA64_UNIT_M:
53
23.2k
    type = IA64_TYPE_M; break;
54
9.32k
  case IA64_UNIT_B:
55
9.32k
    type = IA64_TYPE_B; break;
56
3.61k
  case IA64_UNIT_F:
57
3.61k
    type = IA64_TYPE_F; break;
58
1.78k
        case IA64_UNIT_L:
59
1.78k
  case IA64_UNIT_X:
60
1.78k
    type = IA64_TYPE_X; break;
61
0
  default:
62
0
    type = -1;
63
65.5k
  }
64
65.5k
    }
65
85.1k
  return type;
66
85.1k
}
67
68
int
69
print_insn_ia64 (bfd_vma memaddr, struct disassemble_info *info)
70
103k
{
71
103k
  ia64_insn t0, t1, slot[3], template_val, s_bit, insn;
72
103k
  int slotnum, j, status, need_comma, retval, slot_multiplier;
73
103k
  const struct ia64_operand *odesc;
74
103k
  const struct ia64_opcode *idesc;
75
103k
  const char *err, *str, *tname;
76
103k
  uint64_t value;
77
103k
  bfd_byte bundle[16];
78
103k
  enum ia64_unit unit;
79
103k
  char regname[16];
80
81
103k
  if (info->bytes_per_line == 0)
82
103k
    info->bytes_per_line = 6;
83
103k
  info->display_endian = info->endian;
84
85
103k
  slot_multiplier = info->bytes_per_line;
86
103k
  retval = slot_multiplier;
87
88
103k
  slotnum = (((long) memaddr) & 0xf) / slot_multiplier;
89
103k
  if (slotnum > 2)
90
0
    return -1;
91
92
103k
  memaddr -= (memaddr & 0xf);
93
103k
  status = (*info->read_memory_func) (memaddr, bundle, sizeof (bundle), info);
94
103k
  if (status != 0)
95
388
    {
96
388
      (*info->memory_error_func) (status, memaddr, info);
97
388
      return -1;
98
388
    }
99
  /* bundles are always in little-endian byte order */
100
103k
  t0 = bfd_getl64 (bundle);
101
103k
  t1 = bfd_getl64 (bundle + 8);
102
103k
  s_bit = t0 & 1;
103
103k
  template_val = (t0 >> 1) & 0xf;
104
103k
  slot[0] = (t0 >>  5) & 0x1ffffffffffLL;
105
103k
  slot[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
106
103k
  slot[2] = (t1 >> 23) & 0x1ffffffffffLL;
107
108
103k
  tname = ia64_templ_desc[template_val].name;
109
103k
  if (slotnum == 0)
110
35.2k
    (*info->fprintf_func) (info->stream, "[%s] ", tname);
111
68.2k
  else
112
68.2k
    (*info->fprintf_func) (info->stream, "      ");
113
114
103k
  unit = ia64_templ_desc[template_val].exec_unit[slotnum];
115
116
103k
  if (template_val == 2 && slotnum == 1)
117
1.78k
    {
118
      /* skip L slot in MLI template: */
119
1.78k
      slotnum = 2;
120
1.78k
      retval += slot_multiplier;
121
1.78k
    }
122
123
103k
  insn = slot[slotnum];
124
125
103k
  if (unit == IA64_UNIT_NIL)
126
18.3k
    goto decoding_failed;
127
128
85.1k
  idesc = ia64_dis_opcode (insn, unit_to_type (insn, unit));
129
85.1k
  if (idesc == NULL)
130
35.2k
    goto decoding_failed;
131
132
  /* print predicate, if any: */
133
134
49.8k
  if ((idesc->flags & IA64_OPCODE_NO_PRED)
135
49.8k
      || (insn & 0x3f) == 0)
136
23.8k
    (*info->fprintf_func) (info->stream, "      ");
137
26.0k
  else
138
26.0k
    (*info->fprintf_func) (info->stream, "(p%02d) ", (int)(insn & 0x3f));
139
140
  /* now the actual instruction: */
141
142
49.8k
  (*info->fprintf_func) (info->stream, "%s", idesc->name);
143
49.8k
  if (idesc->operands[0])
144
49.3k
    (*info->fprintf_func) (info->stream, " ");
145
146
49.8k
  need_comma = 0;
147
152k
  for (j = 0; j < NELEMS (idesc->operands) && idesc->operands[j]; ++j)
148
103k
    {
149
103k
      odesc = elf64_ia64_operands + idesc->operands[j];
150
151
103k
      if (need_comma)
152
32.9k
  (*info->fprintf_func) (info->stream, ",");
153
154
103k
      if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
155
95
  {
156
    /* special case of 64 bit immediate load: */
157
95
    value = ((insn >> 13) & 0x7f) | (((insn >> 27) & 0x1ff) << 7)
158
95
      | (((insn >> 22) & 0x1f) << 16) | (((insn >> 21) & 0x1) << 21)
159
95
      | (slot[1] << 22) | (((insn >> 36) & 0x1) << 63);
160
95
  }
161
103k
      else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
162
235
        {
163
          /* 62-bit immediate for nop.x/break.x */
164
235
          value = ((slot[1] & 0x1ffffffffffLL) << 21)
165
235
            | (((insn >> 36) & 0x1) << 20)
166
235
            | ((insn >> 6) & 0xfffff);
167
235
        }
168
102k
      else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
169
78
  {
170
    /* 60-bit immediate for long branches. */
171
78
    value = (((insn >> 13) & 0xfffff)
172
78
       | (((insn >> 36) & 1) << 59)
173
78
       | (((slot[1] >> 2) & 0x7fffffffffLL) << 20)) << 4;
174
78
  }
175
102k
      else
176
102k
  {
177
102k
    err = (*odesc->extract) (odesc, insn, &value);
178
102k
    if (err)
179
0
      {
180
0
        (*info->fprintf_func) (info->stream, "%s", err);
181
0
        goto done;
182
0
      }
183
102k
  }
184
185
103k
  switch (odesc->op_class)
186
103k
    {
187
3.47k
    case IA64_OPND_CLASS_CST:
188
3.47k
      (*info->fprintf_func) (info->stream, "%s", odesc->str);
189
3.47k
      break;
190
191
53.8k
    case IA64_OPND_CLASS_REG:
192
53.8k
      if (odesc->str[0] == 'a' && odesc->str[1] == 'r')
193
172
        {
194
172
    switch (value)
195
172
      {
196
38
      case 0: case 1: case 2: case 3:
197
40
      case 4: case 5: case 6: case 7:
198
40
        sprintf (regname, "ar.k%u", (unsigned int) value);
199
40
        break;
200
1
      case 16:  strcpy (regname, "ar.rsc"); break;
201
0
      case 17:  strcpy (regname, "ar.bsp"); break;
202
1
      case 18:  strcpy (regname, "ar.bspstore"); break;
203
10
      case 19:  strcpy (regname, "ar.rnat"); break;
204
2
      case 21:  strcpy (regname, "ar.fcr"); break;
205
2
      case 24:  strcpy (regname, "ar.eflag"); break;
206
1
      case 25:  strcpy (regname, "ar.csd"); break;
207
22
      case 26:  strcpy (regname, "ar.ssd"); break;
208
1
      case 27:  strcpy (regname, "ar.cflg"); break;
209
0
      case 28:  strcpy (regname, "ar.fsr"); break;
210
6
      case 29:  strcpy (regname, "ar.fir"); break;
211
0
      case 30:  strcpy (regname, "ar.fdr"); break;
212
0
      case 32:  strcpy (regname, "ar.ccv"); break;
213
0
      case 36:  strcpy (regname, "ar.unat"); break;
214
4
      case 40:  strcpy (regname, "ar.fpsr"); break;
215
1
      case 44:  strcpy (regname, "ar.itc"); break;
216
0
      case 45:  strcpy (regname, "ar.ruc"); break;
217
63
      case 64:  strcpy (regname, "ar.pfs"); break;
218
1
      case 65:  strcpy (regname, "ar.lc"); break;
219
1
      case 66:  strcpy (regname, "ar.ec"); break;
220
16
      default:
221
16
        sprintf (regname, "ar%u", (unsigned int) value);
222
16
        break;
223
172
      }
224
172
    (*info->fprintf_func) (info->stream, "%s", regname);
225
172
        }
226
53.6k
      else if (odesc->str[0] == 'c' && odesc->str[1] == 'r')
227
39
        {
228
39
    switch (value)
229
39
      {
230
3
      case 0:       strcpy (regname, "cr.dcr"); break;
231
1
      case 1:       strcpy (regname, "cr.itm"); break;
232
0
      case 2:       strcpy (regname, "cr.iva"); break;
233
0
      case 8:       strcpy (regname, "cr.pta"); break;
234
0
      case 16:      strcpy (regname, "cr.ipsr"); break;
235
0
      case 17:      strcpy (regname, "cr.isr"); break;
236
0
      case 19:      strcpy (regname, "cr.iip"); break;
237
1
      case 20:      strcpy (regname, "cr.ifa"); break;
238
1
      case 21:      strcpy (regname, "cr.itir"); break;
239
1
      case 22:      strcpy (regname, "cr.iipa"); break;
240
0
      case 23:      strcpy (regname, "cr.ifs"); break;
241
0
      case 24:      strcpy (regname, "cr.iim"); break;
242
0
      case 25:      strcpy (regname, "cr.iha"); break;
243
0
      case 26:      strcpy (regname, "cr.iib0"); break;
244
0
      case 27:      strcpy (regname, "cr.iib1"); break;
245
1
      case 64:      strcpy (regname, "cr.lid"); break;
246
0
      case 65:      strcpy (regname, "cr.ivr"); break;
247
0
      case 66:      strcpy (regname, "cr.tpr"); break;
248
1
      case 67:      strcpy (regname, "cr.eoi"); break;
249
0
      case 68:      strcpy (regname, "cr.irr0"); break;
250
0
      case 69:      strcpy (regname, "cr.irr1"); break;
251
1
      case 70:      strcpy (regname, "cr.irr2"); break;
252
0
      case 71:      strcpy (regname, "cr.irr3"); break;
253
0
      case 72:      strcpy (regname, "cr.itv"); break;
254
0
      case 73:      strcpy (regname, "cr.pmv"); break;
255
1
      case 74:      strcpy (regname, "cr.cmcv"); break;
256
0
      case 80:      strcpy (regname, "cr.lrr0"); break;
257
0
      case 81:      strcpy (regname, "cr.lrr1"); break;
258
28
      default:
259
28
        sprintf (regname, "cr%u", (unsigned int) value);
260
28
        break;
261
39
      }
262
39
    (*info->fprintf_func) (info->stream, "%s", regname);
263
39
        }
264
53.6k
      else
265
53.6k
        (*info->fprintf_func) (info->stream, "%s%d", odesc->str, (int)value);
266
53.8k
      break;
267
268
53.8k
    case IA64_OPND_CLASS_IND:
269
2.53k
      (*info->fprintf_func) (info->stream, "%s[r%d]", odesc->str, (int)value);
270
2.53k
      break;
271
272
38.3k
    case IA64_OPND_CLASS_ABS:
273
38.3k
      str = 0;
274
38.3k
      if (odesc - elf64_ia64_operands == IA64_OPND_MBTYPE4)
275
3
        switch (value)
276
3
    {
277
0
    case 0x0: str = "@brcst"; break;
278
0
    case 0x8: str = "@mix"; break;
279
2
    case 0x9: str = "@shuf"; break;
280
0
    case 0xa: str = "@alt"; break;
281
0
    case 0xb: str = "@rev"; break;
282
3
    }
283
284
38.3k
      if (str)
285
2
        (*info->fprintf_func) (info->stream, "%s", str);
286
38.3k
      else if (odesc->flags & IA64_OPND_FLAG_DECIMAL_SIGNED)
287
7.03k
        (*info->fprintf_func) (info->stream, "%lld", (long long) value);
288
31.2k
      else if (odesc->flags & IA64_OPND_FLAG_DECIMAL_UNSIGNED)
289
5.16k
        (*info->fprintf_func) (info->stream, "%llu", (long long) value);
290
26.1k
      else
291
26.1k
        (*info->fprintf_func) (info->stream, "0x%llx", (long long) value);
292
38.3k
      break;
293
294
4.97k
    case IA64_OPND_CLASS_REL:
295
4.97k
      (*info->print_address_func) (memaddr + value, info);
296
4.97k
      break;
297
103k
    }
298
299
103k
      need_comma = 1;
300
103k
      if (j + 1 == idesc->num_outputs)
301
20.8k
  {
302
20.8k
    (*info->fprintf_func) (info->stream, "=");
303
20.8k
    need_comma = 0;
304
20.8k
  }
305
103k
    }
306
49.8k
  if (slotnum + 1 == ia64_templ_desc[template_val].group_boundary
307
49.8k
      || ((slotnum == 2) && s_bit))
308
5.20k
    (*info->fprintf_func) (info->stream, ";;");
309
310
49.8k
 done:
311
49.8k
  ia64_free_opcode ((struct ia64_opcode *)idesc);
312
103k
 failed:
313
103k
  if (slotnum == 2)
314
34.8k
    retval += 16 - 3*slot_multiplier;
315
103k
  return retval;
316
317
53.5k
 decoding_failed:
318
53.5k
  (*info->fprintf_func) (info->stream, "      data8 %#011llx", (long long) insn);
319
53.5k
  goto failed;
320
49.8k
}