Coverage Report

Created: 2026-09-14 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/moxie-dis.c
Line
Count
Source
1
/* Disassemble moxie instructions.
2
   Copyright (C) 2009-2026 Free Software Foundation, Inc.
3
4
   This file is part of the GNU opcodes library.
5
6
   This library is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3, or (at your option)
9
   any later version.
10
11
   It is distributed in the hope that it will be useful, but WITHOUT
12
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14
   License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include <stdio.h>
23
24
#define STATIC_TABLE
25
#define DEFINE_TABLE
26
27
#include "opcode/moxie.h"
28
#include "disassemble.h"
29
30
static fprintf_ftype fpr;
31
static void *stream;
32
33
/* Macros to extract operands from the instruction word.  */
34
18.2k
#define OP_A(i) ((i >> 4) & 0xf)
35
13.5k
#define OP_B(i) (i & 0xf)
36
6.14k
#define INST2OFFSET(o) (((((o) & 0x3ff) ^ 0x200) - 0x200) * 2)
37
38
static const char * reg_names[16] =
39
  { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5",
40
    "$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" };
41
42
int
43
print_insn_moxie (bfd_vma addr, struct disassemble_info * info)
44
88.5k
{
45
88.5k
  int length = 2;
46
88.5k
  int status;
47
88.5k
  stream = info->stream;
48
88.5k
  const moxie_opc_info_t * opcode;
49
88.5k
  bfd_byte buffer[4];
50
88.5k
  unsigned short iword;
51
88.5k
  fpr = info->fprintf_func;
52
53
88.5k
  if ((status = info->read_memory_func (addr, buffer, 2, info)))
54
50
    goto fail;
55
56
88.4k
  if (info->endian == BFD_ENDIAN_BIG)
57
21.9k
    iword = bfd_getb16 (buffer);
58
66.4k
  else
59
66.4k
    iword = bfd_getl16 (buffer);
60
61
  /* Form 1 instructions have the high bit set to 0.  */
62
88.4k
  if ((iword & (1<<15)) == 0)
63
58.2k
    {
64
      /* Extract the Form 1 opcode.  */
65
58.2k
      opcode = &moxie_form1_opc_info[iword >> 8];
66
58.2k
      switch (opcode->itype)
67
58.2k
  {
68
1.98k
  case MOXIE_F1_NARG:
69
1.98k
    fpr (stream, "%s", opcode->name);
70
1.98k
    break;
71
962
  case MOXIE_F1_A:
72
962
    fpr (stream, "%s\t%s", opcode->name,
73
962
         reg_names[OP_A(iword)]);
74
962
    break;
75
9.06k
  case MOXIE_F1_AB:
76
9.06k
    fpr (stream, "%s\t%s, %s", opcode->name,
77
9.06k
         reg_names[OP_A(iword)],
78
9.06k
         reg_names[OP_B(iword)]);
79
9.06k
    break;
80
2.77k
  case MOXIE_F1_A4:
81
2.77k
    {
82
2.77k
      unsigned imm;
83
2.77k
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
84
7
        goto fail;
85
2.76k
      if (info->endian == BFD_ENDIAN_BIG)
86
927
        imm = bfd_getb32 (buffer);
87
1.83k
      else
88
1.83k
        imm = bfd_getl32 (buffer);
89
2.76k
      fpr (stream, "%s\t%s, 0x%x", opcode->name,
90
2.76k
     reg_names[OP_A(iword)], imm);
91
2.76k
      length = 6;
92
2.76k
    }
93
0
    break;
94
503
  case MOXIE_F1_4:
95
503
    {
96
503
      unsigned imm;
97
503
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
98
3
        goto fail;
99
500
      if (info->endian == BFD_ENDIAN_BIG)
100
45
        imm = bfd_getb32 (buffer);
101
455
      else
102
455
        imm = bfd_getl32 (buffer);
103
500
      fpr (stream, "%s\t0x%x", opcode->name, imm);
104
500
      length = 6;
105
500
    }
106
0
    break;
107
795
  case MOXIE_F1_M:
108
795
    {
109
795
      unsigned imm;
110
795
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
111
11
        goto fail;
112
784
      if (info->endian == BFD_ENDIAN_BIG)
113
136
        imm = bfd_getb32 (buffer);
114
648
      else
115
648
        imm = bfd_getl32 (buffer);
116
784
      fpr (stream, "%s\t", opcode->name);
117
784
      info->print_address_func ((bfd_vma) imm, info);
118
784
      length = 6;
119
784
    }
120
0
    break;
121
1.28k
  case MOXIE_F1_AiB:
122
1.28k
    fpr (stream, "%s\t(%s), %s", opcode->name,
123
1.28k
         reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
124
1.28k
    break;
125
1.12k
  case MOXIE_F1_ABi:
126
1.12k
    fpr (stream, "%s\t%s, (%s)", opcode->name,
127
1.12k
         reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
128
1.12k
    break;
129
978
  case MOXIE_F1_4A:
130
978
    {
131
978
      unsigned imm;
132
978
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
133
6
        goto fail;
134
972
      if (info->endian == BFD_ENDIAN_BIG)
135
224
        imm = bfd_getb32 (buffer);
136
748
      else
137
748
        imm = bfd_getl32 (buffer);
138
972
      fpr (stream, "%s\t0x%x, %s",
139
972
     opcode->name, imm, reg_names[OP_A(iword)]);
140
972
      length = 6;
141
972
    }
142
0
    break;
143
878
  case MOXIE_F1_AiB2:
144
878
    {
145
878
      unsigned imm;
146
878
      if ((status = info->read_memory_func (addr+2, buffer, 2, info)))
147
5
        goto fail;
148
873
      if (info->endian == BFD_ENDIAN_BIG)
149
158
        imm = bfd_getb16 (buffer);
150
715
      else
151
715
        imm = bfd_getl16 (buffer);
152
873
      fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
153
873
     imm,
154
873
     reg_names[OP_A(iword)],
155
873
     reg_names[OP_B(iword)]);
156
873
      length = 4;
157
873
    }
158
0
    break;
159
1.19k
  case MOXIE_F1_ABi2:
160
1.19k
    {
161
1.19k
      unsigned imm;
162
1.19k
      if ((status = info->read_memory_func (addr+2, buffer, 2, info)))
163
2
        goto fail;
164
1.19k
      if (info->endian == BFD_ENDIAN_BIG)
165
225
        imm = bfd_getb16 (buffer);
166
965
      else
167
965
        imm = bfd_getl16 (buffer);
168
1.19k
      fpr (stream, "%s\t%s, 0x%x(%s)",
169
1.19k
     opcode->name,
170
1.19k
     reg_names[OP_A(iword)],
171
1.19k
     imm,
172
1.19k
     reg_names[OP_B(iword)]);
173
1.19k
      length = 4;
174
1.19k
    }
175
0
    break;
176
36.7k
        case MOXIE_BAD:
177
36.7k
    fpr (stream, "bad");
178
36.7k
    break;
179
0
  default:
180
0
    abort();
181
58.2k
  }
182
58.2k
    }
183
30.2k
  else if ((iword & (1<<14)) == 0)
184
11.7k
    {
185
      /* Extract the Form 2 opcode.  */
186
11.7k
      opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
187
11.7k
      switch (opcode->itype)
188
11.7k
  {
189
11.7k
  case MOXIE_F2_A8V:
190
11.7k
    fpr (stream, "%s\t%s, 0x%x",
191
11.7k
         opcode->name,
192
11.7k
         reg_names[(iword >> 8) & 0xf],
193
11.7k
         iword & ((1 << 8) - 1));
194
11.7k
    break;
195
0
  case MOXIE_F2_NARG:
196
0
    fpr (stream, "%s", opcode->name);
197
0
    break;
198
0
        case MOXIE_BAD:
199
0
    fpr (stream, "bad");
200
0
    break;
201
0
  default:
202
0
    abort();
203
11.7k
  }
204
11.7k
    }
205
18.4k
  else
206
18.4k
    {
207
      /* Extract the Form 3 opcode.  */
208
18.4k
      opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
209
18.4k
      switch (opcode->itype)
210
18.4k
  {
211
6.14k
  case MOXIE_F3_PCREL:
212
6.14k
    fpr (stream, "%s\t", opcode->name);
213
6.14k
    info->print_address_func (addr + INST2OFFSET (iword) + 2, info);
214
6.14k
    break;
215
12.2k
        case MOXIE_BAD:
216
12.2k
    fpr (stream, "bad");
217
12.2k
    break;
218
0
  default:
219
0
    abort();
220
18.4k
  }
221
18.4k
    }
222
223
88.4k
  return length;
224
225
84
 fail:
226
84
  info->memory_error_func (status, addr, info);
227
84
  return -1;
228
88.4k
}