Coverage Report

Created: 2026-11-21 09:00

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
15.7k
#define OP_A(i) ((i >> 4) & 0xf)
35
11.4k
#define OP_B(i) (i & 0xf)
36
6.59k
#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
78.3k
{
45
78.3k
  int length = 2;
46
78.3k
  int status;
47
78.3k
  stream = info->stream;
48
78.3k
  const moxie_opc_info_t * opcode;
49
78.3k
  bfd_byte buffer[4];
50
78.3k
  unsigned short iword;
51
78.3k
  fpr = info->fprintf_func;
52
53
78.3k
  if ((status = info->read_memory_func (addr, buffer, 2, info)))
54
52
    goto fail;
55
56
78.2k
  if (info->endian == BFD_ENDIAN_BIG)
57
25.8k
    iword = bfd_getb16 (buffer);
58
52.3k
  else
59
52.3k
    iword = bfd_getl16 (buffer);
60
61
  /* Form 1 instructions have the high bit set to 0.  */
62
78.2k
  if ((iword & (1<<15)) == 0)
63
51.0k
    {
64
      /* Extract the Form 1 opcode.  */
65
51.0k
      opcode = &moxie_form1_opc_info[iword >> 8];
66
51.0k
      switch (opcode->itype)
67
51.0k
  {
68
1.89k
  case MOXIE_F1_NARG:
69
1.89k
    fpr (stream, "%s", opcode->name);
70
1.89k
    break;
71
1.12k
  case MOXIE_F1_A:
72
1.12k
    fpr (stream, "%s\t%s", opcode->name,
73
1.12k
         reg_names[OP_A(iword)]);
74
1.12k
    break;
75
7.39k
  case MOXIE_F1_AB:
76
7.39k
    fpr (stream, "%s\t%s, %s", opcode->name,
77
7.39k
         reg_names[OP_A(iword)],
78
7.39k
         reg_names[OP_B(iword)]);
79
7.39k
    break;
80
2.41k
  case MOXIE_F1_A4:
81
2.41k
    {
82
2.41k
      unsigned imm;
83
2.41k
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
84
4
        goto fail;
85
2.40k
      if (info->endian == BFD_ENDIAN_BIG)
86
1.01k
        imm = bfd_getb32 (buffer);
87
1.39k
      else
88
1.39k
        imm = bfd_getl32 (buffer);
89
2.40k
      fpr (stream, "%s\t%s, 0x%x", opcode->name,
90
2.40k
     reg_names[OP_A(iword)], imm);
91
2.40k
      length = 6;
92
2.40k
    }
93
0
    break;
94
487
  case MOXIE_F1_4:
95
487
    {
96
487
      unsigned imm;
97
487
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
98
3
        goto fail;
99
484
      if (info->endian == BFD_ENDIAN_BIG)
100
57
        imm = bfd_getb32 (buffer);
101
427
      else
102
427
        imm = bfd_getl32 (buffer);
103
484
      fpr (stream, "%s\t0x%x", opcode->name, imm);
104
484
      length = 6;
105
484
    }
106
0
    break;
107
615
  case MOXIE_F1_M:
108
615
    {
109
615
      unsigned imm;
110
615
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
111
6
        goto fail;
112
609
      if (info->endian == BFD_ENDIAN_BIG)
113
157
        imm = bfd_getb32 (buffer);
114
452
      else
115
452
        imm = bfd_getl32 (buffer);
116
609
      fpr (stream, "%s\t", opcode->name);
117
609
      info->print_address_func ((bfd_vma) imm, info);
118
609
      length = 6;
119
609
    }
120
0
    break;
121
1.13k
  case MOXIE_F1_AiB:
122
1.13k
    fpr (stream, "%s\t(%s), %s", opcode->name,
123
1.13k
         reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
124
1.13k
    break;
125
1.38k
  case MOXIE_F1_ABi:
126
1.38k
    fpr (stream, "%s\t%s, (%s)", opcode->name,
127
1.38k
         reg_names[OP_A(iword)], reg_names[OP_B(iword)]);
128
1.38k
    break;
129
799
  case MOXIE_F1_4A:
130
799
    {
131
799
      unsigned imm;
132
799
      if ((status = info->read_memory_func (addr + 2, buffer, 4, info)))
133
5
        goto fail;
134
794
      if (info->endian == BFD_ENDIAN_BIG)
135
280
        imm = bfd_getb32 (buffer);
136
514
      else
137
514
        imm = bfd_getl32 (buffer);
138
794
      fpr (stream, "%s\t0x%x, %s",
139
794
     opcode->name, imm, reg_names[OP_A(iword)]);
140
794
      length = 6;
141
794
    }
142
0
    break;
143
720
  case MOXIE_F1_AiB2:
144
720
    {
145
720
      unsigned imm;
146
720
      if ((status = info->read_memory_func (addr+2, buffer, 2, info)))
147
2
        goto fail;
148
718
      if (info->endian == BFD_ENDIAN_BIG)
149
208
        imm = bfd_getb16 (buffer);
150
510
      else
151
510
        imm = bfd_getl16 (buffer);
152
718
      fpr (stream, "%s\t0x%x(%s), %s", opcode->name,
153
718
     imm,
154
718
     reg_names[OP_A(iword)],
155
718
     reg_names[OP_B(iword)]);
156
718
      length = 4;
157
718
    }
158
0
    break;
159
824
  case MOXIE_F1_ABi2:
160
824
    {
161
824
      unsigned imm;
162
824
      if ((status = info->read_memory_func (addr+2, buffer, 2, info)))
163
1
        goto fail;
164
823
      if (info->endian == BFD_ENDIAN_BIG)
165
268
        imm = bfd_getb16 (buffer);
166
555
      else
167
555
        imm = bfd_getl16 (buffer);
168
823
      fpr (stream, "%s\t%s, 0x%x(%s)",
169
823
     opcode->name,
170
823
     reg_names[OP_A(iword)],
171
823
     imm,
172
823
     reg_names[OP_B(iword)]);
173
823
      length = 4;
174
823
    }
175
0
    break;
176
32.2k
        case MOXIE_BAD:
177
32.2k
    fpr (stream, "bad");
178
32.2k
    break;
179
0
  default:
180
0
    abort();
181
51.0k
  }
182
51.0k
    }
183
27.2k
  else if ((iword & (1<<14)) == 0)
184
10.1k
    {
185
      /* Extract the Form 2 opcode.  */
186
10.1k
      opcode = &moxie_form2_opc_info[(iword >> 12) & 3];
187
10.1k
      switch (opcode->itype)
188
10.1k
  {
189
10.1k
  case MOXIE_F2_A8V:
190
10.1k
    fpr (stream, "%s\t%s, 0x%x",
191
10.1k
         opcode->name,
192
10.1k
         reg_names[(iword >> 8) & 0xf],
193
10.1k
         iword & ((1 << 8) - 1));
194
10.1k
    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
10.1k
  }
204
10.1k
    }
205
17.0k
  else
206
17.0k
    {
207
      /* Extract the Form 3 opcode.  */
208
17.0k
      opcode = &moxie_form3_opc_info[(iword >> 10) & 15];
209
17.0k
      switch (opcode->itype)
210
17.0k
  {
211
6.59k
  case MOXIE_F3_PCREL:
212
6.59k
    fpr (stream, "%s\t", opcode->name);
213
6.59k
    info->print_address_func (addr + INST2OFFSET (iword) + 2, info);
214
6.59k
    break;
215
10.4k
        case MOXIE_BAD:
216
10.4k
    fpr (stream, "bad");
217
10.4k
    break;
218
0
  default:
219
0
    abort();
220
17.0k
  }
221
17.0k
    }
222
223
78.2k
  return length;
224
225
73
 fail:
226
73
  info->memory_error_func (status, addr, info);
227
73
  return -1;
228
78.2k
}