Coverage Report

Created: 2026-10-02 09:53

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
17.9k
#define OP_A(i) ((i >> 4) & 0xf)
35
13.3k
#define OP_B(i) (i & 0xf)
36
6.08k
#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
87.7k
{
45
87.7k
  int length = 2;
46
87.7k
  int status;
47
87.7k
  stream = info->stream;
48
87.7k
  const moxie_opc_info_t * opcode;
49
87.7k
  bfd_byte buffer[4];
50
87.7k
  unsigned short iword;
51
87.7k
  fpr = info->fprintf_func;
52
53
87.7k
  if ((status = info->read_memory_func (addr, buffer, 2, info)))
54
53
    goto fail;
55
56
87.7k
  if (info->endian == BFD_ENDIAN_BIG)
57
21.9k
    iword = bfd_getb16 (buffer);
58
65.7k
  else
59
65.7k
    iword = bfd_getl16 (buffer);
60
61
  /* Form 1 instructions have the high bit set to 0.  */
62
87.7k
  if ((iword & (1<<15)) == 0)
63
57.5k
    {
64
      /* Extract the Form 1 opcode.  */
65
57.5k
      opcode = &moxie_form1_opc_info[iword >> 8];
66
57.5k
      switch (opcode->itype)
67
57.5k
  {
68
1.98k
  case MOXIE_F1_NARG:
69
1.98k
    fpr (stream, "%s", opcode->name);
70
1.98k
    break;
71
928
  case MOXIE_F1_A:
72
928
    fpr (stream, "%s\t%s", opcode->name,
73
928
         reg_names[OP_A(iword)]);
74
928
    break;
75
8.89k
  case MOXIE_F1_AB:
76
8.89k
    fpr (stream, "%s\t%s, %s", opcode->name,
77
8.89k
         reg_names[OP_A(iword)],
78
8.89k
         reg_names[OP_B(iword)]);
79
8.89k
    break;
80
2.74k
  case MOXIE_F1_A4:
81
2.74k
    {
82
2.74k
      unsigned imm;
83
2.74k
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
84
8
        goto fail;
85
2.74k
      if (info->endian == BFD_ENDIAN_BIG)
86
927
        imm = bfd_getb32 (buffer);
87
1.81k
      else
88
1.81k
        imm = bfd_getl32 (buffer);
89
2.74k
      fpr (stream, "%s\t%s, 0x%x", opcode->name,
90
2.74k
     reg_names[OP_A(iword)], imm);
91
2.74k
      length = 6;
92
2.74k
    }
93
0
    break;
94
509
  case MOXIE_F1_4:
95
509
    {
96
509
      unsigned imm;
97
509
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
98
3
        goto fail;
99
506
      if (info->endian == BFD_ENDIAN_BIG)
100
45
        imm = bfd_getb32 (buffer);
101
461
      else
102
461
        imm = bfd_getl32 (buffer);
103
506
      fpr (stream, "%s\t0x%x", opcode->name, imm);
104
506
      length = 6;
105
506
    }
106
0
    break;
107
788
  case MOXIE_F1_M:
108
788
    {
109
788
      unsigned imm;
110
788
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
111
11
        goto fail;
112
777
      if (info->endian == BFD_ENDIAN_BIG)
113
136
        imm = bfd_getb32 (buffer);
114
641
      else
115
641
        imm = bfd_getl32 (buffer);
116
777
      fpr (stream, "%s\t", opcode->name);
117
777
      info->print_address_func ((bfd_vma) imm, info);
118
777
      length = 6;
119
777
    }
120
0
    break;
121
1.27k
  case MOXIE_F1_AiB:
122
1.27k
    fpr (stream, "%s\t(%s), %s", opcode->name,
123
1.27k
         reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
124
1.27k
    break;
125
1.11k
  case MOXIE_F1_ABi:
126
1.11k
    fpr (stream, "%s\t%s, (%s)", opcode->name,
127
1.11k
         reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
128
1.11k
    break;
129
973
  case MOXIE_F1_4A:
130
973
    {
131
973
      unsigned imm;
132
973
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
133
6
        goto fail;
134
967
      if (info->endian == BFD_ENDIAN_BIG)
135
224
        imm = bfd_getb32 (buffer);
136
743
      else
137
743
        imm = bfd_getl32 (buffer);
138
967
      fpr (stream, "%s\t0x%x, %s",
139
967
     opcode->name, imm, reg_names[OP_A(iword)]);
140
967
      length = 6;
141
967
    }
142
0
    break;
143
888
  case MOXIE_F1_AiB2:
144
888
    {
145
888
      unsigned imm;
146
888
      if ((status = info->read_memory_func (addr+2, buffer, 2, info)))
147
5
        goto fail;
148
883
      if (info->endian == BFD_ENDIAN_BIG)
149
158
        imm = bfd_getb16 (buffer);
150
725
      else
151
725
        imm = bfd_getl16 (buffer);
152
883
      fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
153
883
     imm,
154
883
     reg_names[OP_A(iword)],
155
883
     reg_names[OP_B(iword)]);
156
883
      length = 4;
157
883
    }
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.18k
      if (info->endian == BFD_ENDIAN_BIG)
165
225
        imm = bfd_getb16 (buffer);
166
963
      else
167
963
        imm = bfd_getl16 (buffer);
168
1.18k
      fpr (stream, "%s\t%s, 0x%x(%s)",
169
1.18k
     opcode->name,
170
1.18k
     reg_names[OP_A(iword)],
171
1.18k
     imm,
172
1.18k
     reg_names[OP_B(iword)]);
173
1.18k
      length = 4;
174
1.18k
    }
175
0
    break;
176
36.2k
        case MOXIE_BAD:
177
36.2k
    fpr (stream, "bad");
178
36.2k
    break;
179
0
  default:
180
0
    abort();
181
57.5k
  }
182
57.5k
    }
183
30.2k
  else if ((iword & (1<<14)) == 0)
184
11.8k
    {
185
      /* Extract the Form 2 opcode.  */
186
11.8k
      opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
187
11.8k
      switch (opcode->itype)
188
11.8k
  {
189
11.8k
  case MOXIE_F2_A8V:
190
11.8k
    fpr (stream, "%s\t%s, 0x%x",
191
11.8k
         opcode->name,
192
11.8k
         reg_names[(iword >> 8) & 0xf],
193
11.8k
         iword & ((1 << 8) - 1));
194
11.8k
    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.8k
  }
204
11.8k
    }
205
18.3k
  else
206
18.3k
    {
207
      /* Extract the Form 3 opcode.  */
208
18.3k
      opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
209
18.3k
      switch (opcode->itype)
210
18.3k
  {
211
6.08k
  case MOXIE_F3_PCREL:
212
6.08k
    fpr (stream, "%s\t", opcode->name);
213
6.08k
    info->print_address_func (addr + INST2OFFSET (iword) + 2, info);
214
6.08k
    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.3k
  }
221
18.3k
    }
222
223
87.7k
  return length;
224
225
88
 fail:
226
88
  info->memory_error_func (status, addr, info);
227
88
  return -1;
228
87.7k
}