1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/*
* Header file for nanoMIPS disassembler component of QEMU
*
* Copyright (C) 2018 Wave Computing, Inc.
* Copyright (C) 2018 Matthew Fortune <matthew.fortune@mips.com>
* Copyright (C) 2018 Aleksandar Markovic <amarkovic@wavecomp.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef DISAS_NANOMIPS_H
#define DISAS_NANOMIPS_H
#include <string>
typedef int64_t int64;
typedef uint64_t uint64;
typedef uint32_t uint32;
typedef uint16_t uint16;
typedef uint64_t img_address;
enum TABLE_ENTRY_TYPE {
instruction,
call_instruction,
branch_instruction,
return_instruction,
reserved_block,
pool,
};
enum TABLE_ATTRIBUTE_TYPE {
MIPS64_ = 0x00000001,
XNP_ = 0x00000002,
XMMS_ = 0x00000004,
EVA_ = 0x00000008,
DSP_ = 0x00000010,
MT_ = 0x00000020,
EJTAG_ = 0x00000040,
TLBINV_ = 0x00000080,
CP0_ = 0x00000100,
CP1_ = 0x00000200,
CP2_ = 0x00000400,
UDI_ = 0x00000800,
MCU_ = 0x00001000,
VZ_ = 0x00002000,
TLB_ = 0x00004000,
MVH_ = 0x00008000,
ALL_ATTRIBUTES = 0xffffffffull,
};
typedef struct Dis_info {
img_address m_pc;
} Dis_info;
typedef bool (*conditional_function)(uint64 instruction);
typedef std::string (*disassembly_function)(uint64 instruction,
Dis_info *info);
class NMD
{
public:
int Disassemble(const uint16 *data, std::string & dis,
TABLE_ENTRY_TYPE & type, Dis_info *info);
private:
struct Pool {
TABLE_ENTRY_TYPE type;
struct Pool *next_table;
int next_table_size;
int instructions_size;
uint64 mask;
uint64 value;
disassembly_function disassembly;
conditional_function condition;
uint64 attributes;
};
uint64 extract_op_code_value(const uint16 *data, int size);
int Disassemble(const uint16 *data, std::string & dis,
TABLE_ENTRY_TYPE & type, const Pool *table, int table_size,
Dis_info *info);
static Pool P_SYSCALL[2];
static Pool P_RI[4];
static Pool P_ADDIU[2];
static Pool P_TRAP[2];
static Pool P_CMOVE[2];
static Pool P_D_MT_VPE[2];
static Pool P_E_MT_VPE[2];
static Pool _P_MT_VPE[2];
static Pool P_MT_VPE[8];
static Pool P_DVP[2];
static Pool P_SLTU[2];
static Pool _POOL32A0[128];
static Pool ADDQ__S__PH[2];
static Pool MUL__S__PH[2];
static Pool ADDQH__R__PH[2];
static Pool ADDQH__R__W[2];
static Pool ADDU__S__QB[2];
static Pool ADDU__S__PH[2];
static Pool ADDUH__R__QB[2];
static Pool SHRAV__R__PH[2];
static Pool SHRAV__R__QB[2];
static Pool SUBQ__S__PH[2];
static Pool SUBQH__R__PH[2];
static Pool SUBQH__R__W[2];
static Pool SUBU__S__QB[2];
static Pool SUBU__S__PH[2];
static Pool SHRA__R__PH[2];
static Pool SUBUH__R__QB[2];
static Pool SHLLV__S__PH[2];
static Pool SHLL__S__PH[4];
static Pool PRECR_SRA__R__PH_W[2];
static Pool _POOL32A5[128];
static Pool PP_LSX[16];
static Pool PP_LSXS[16];
static Pool P_LSX[2];
static Pool POOL32Axf_1_0[4];
static Pool POOL32Axf_1_1[4];
static Pool POOL32Axf_1_3[4];
static Pool POOL32Axf_1_4[2];
static Pool MAQ_S_A__W_PHR[2];
static Pool MAQ_S_A__W_PHL[2];
static Pool POOL32Axf_1_5[2];
static Pool POOL32Axf_1_7[4];
static Pool POOL32Axf_1[8];
static Pool POOL32Axf_2_DSP__0_7[8];
static Pool POOL32Axf_2_DSP__8_15[8];
static Pool POOL32Axf_2_DSP__16_23[8];
static Pool POOL32Axf_2_DSP__24_31[8];
static Pool POOL32Axf_2[4];
static Pool POOL32Axf_4[128];
static Pool POOL32Axf_5_group0[32];
static Pool POOL32Axf_5_group1[32];
static Pool ERETx[2];
static Pool POOL32Axf_5_group3[32];
static Pool POOL32Axf_5[4];
static Pool SHRA__R__QB[2];
static Pool POOL32Axf_7[8];
static Pool POOL32Axf[8];
static Pool _POOL32A7[8];
static Pool P32A[8];
static Pool P_GP_D[2];
static Pool P_GP_W[4];
static Pool POOL48I[32];
static Pool PP_SR[4];
static Pool P_SR_F[8];
static Pool P_SR[2];
static Pool P_SLL[5];
static Pool P_SHIFT[16];
static Pool P_ROTX[4];
static Pool P_INS[4];
static Pool P_EXT[4];
static Pool P_U12[16];
static Pool RINT_fmt[2];
static Pool ADD_fmt0[2];
static Pool SELEQZ_fmt[2];
static Pool CLASS_fmt[2];
static Pool SUB_fmt0[2];
static Pool SELNEZ_fmt[2];
static Pool MUL_fmt0[2];
static Pool SEL_fmt[2];
static Pool DIV_fmt0[2];
static Pool ADD_fmt1[2];
static Pool SUB_fmt1[2];
static Pool MUL_fmt1[2];
static Pool MADDF_fmt[2];
static Pool DIV_fmt1[2];
static Pool MSUBF_fmt[2];
static Pool POOL32F_0[64];
static Pool MIN_fmt[2];
static Pool MAX_fmt[2];
static Pool MINA_fmt[2];
static Pool MAXA_fmt[2];
static Pool CVT_L_fmt[2];
static Pool RSQRT_fmt[2];
static Pool FLOOR_L_fmt[2];
static Pool CVT_W_fmt[2];
static Pool SQRT_fmt[2];
static Pool FLOOR_W_fmt[2];
static Pool RECIP_fmt[2];
static Pool CEIL_L_fmt[2];
static Pool CEIL_W_fmt[2];
static Pool TRUNC_L_fmt[2];
static Pool TRUNC_W_fmt[2];
static Pool ROUND_L_fmt[2];
static Pool ROUND_W_fmt[2];
static Pool POOL32Fxf_0[64];
static Pool MOV_fmt[4];
static Pool ABS_fmt[4];
static Pool NEG_fmt[4];
static Pool CVT_D_fmt[4];
static Pool CVT_S_fmt[4];
static Pool POOL32Fxf_1[32];
static Pool POOL32Fxf[4];
static Pool POOL32F_3[8];
static Pool CMP_condn_S[32];
static Pool CMP_condn_D[32];
static Pool POOL32F_5[8];
static Pool POOL32F[8];
static Pool POOL32S_0[64];
static Pool POOL32Sxf_4[128];
static Pool POOL32Sxf[8];
static Pool POOL32S_4[8];
static Pool POOL32S[8];
static Pool P_LUI[2];
static Pool P_GP_LH[2];
static Pool P_GP_SH[2];
static Pool P_GP_CP1[4];
static Pool P_GP_M64[4];
static Pool P_GP_BH[8];
static Pool P_LS_U12[16];
static Pool P_PREF_S9_[2];
static Pool P_LS_S0[16];
static Pool ASET_ACLR[2];
static Pool P_LL[4];
static Pool P_SC[4];
static Pool P_LLD[8];
static Pool P_SCD[8];
static Pool P_LS_S1[16];
static Pool P_PREFE[2];
static Pool P_LLE[4];
static Pool P_SCE[4];
static Pool P_LS_E0[16];
static Pool P_LS_WM[2];
static Pool P_LS_UAWM[2];
static Pool P_LS_DM[2];
static Pool P_LS_UADM[2];
static Pool P_LS_S9[8];
static Pool P_BAL[2];
static Pool P_BALRSC[2];
static Pool P_J[16];
static Pool P_BR3A[32];
static Pool P_BR1[4];
static Pool P_BR2[4];
static Pool P_BRI[8];
static Pool P32[32];
static Pool P16_SYSCALL[2];
static Pool P16_RI[4];
static Pool P16_MV[2];
static Pool P16_SHIFT[2];
static Pool POOL16C_00[4];
static Pool POOL16C_0[2];
static Pool P16C[2];
static Pool P16_A1[2];
static Pool P_ADDIU_RS5_[2];
static Pool P16_A2[2];
static Pool P16_ADDU[2];
static Pool P16_JRC[2];
static Pool P16_BR1[2];
static Pool P16_BR[2];
static Pool P16_SR[2];
static Pool P16_4X4[4];
static Pool P16_LB[4];
static Pool P16_LH[4];
static Pool P16[32];
static Pool MAJOR[2];
};
#endif
|