nbd: Add max-connections to nbd-server-start
[qemu.git] / disas / nanomips.cpp
1 /*
2 * Source file for nanoMIPS disassembler component of QEMU
3 *
4 * Copyright (C) 2018 Wave Computing, Inc.
5 * Copyright (C) 2018 Matthew Fortune <matthew.fortune@mips.com>
6 * Copyright (C) 2018 Aleksandar Markovic <amarkovic@wavecomp.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22
23 /*
24 * Documentation used while implementing this component:
25 *
26 * [1] "MIPS® Architecture Base: nanoMIPS32(tm) Instruction Set Technical
27 * Reference Manual", Revision 01.01, April 27, 2018
28 */
29
30 extern "C" {
31 #include "qemu/osdep.h"
32 #include "disas/dis-asm.h"
33 }
34
35 #include <cstring>
36 #include <stdexcept>
37 #include <sstream>
38 #include <stdio.h>
39 #include <stdarg.h>
40
41 #include "nanomips.h"
42
43 #define IMGASSERTONCE(test)
44
45
46 int nanomips_dis(char *buf,
47 unsigned address,
48 unsigned short one,
49 unsigned short two,
50 unsigned short three)
51 {
52 std::string disasm;
53 uint16 bits[3] = {one, two, three};
54
55 NMD::TABLE_ENTRY_TYPE type;
56 NMD d(address, NMD::ALL_ATTRIBUTES);
57 int size = d.Disassemble(bits, disasm, type);
58
59 strcpy(buf, disasm.c_str());
60 return size;
61 }
62
63 int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info)
64 {
65 int status;
66 bfd_byte buffer[2];
67 uint16_t insn1 = 0, insn2 = 0, insn3 = 0;
68 char buf[200];
69
70 info->bytes_per_chunk = 2;
71 info->display_endian = info->endian;
72 info->insn_info_valid = 1;
73 info->branch_delay_insns = 0;
74 info->data_size = 0;
75 info->insn_type = dis_nonbranch;
76 info->target = 0;
77 info->target2 = 0;
78
79 status = (*info->read_memory_func)(memaddr, buffer, 2, info);
80 if (status != 0) {
81 (*info->memory_error_func)(status, memaddr, info);
82 return -1;
83 }
84
85 if (info->endian == BFD_ENDIAN_BIG) {
86 insn1 = bfd_getb16(buffer);
87 } else {
88 insn1 = bfd_getl16(buffer);
89 }
90 (*info->fprintf_func)(info->stream, "%04x ", insn1);
91
92 /* Handle 32-bit opcodes. */
93 if ((insn1 & 0x1000) == 0) {
94 status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info);
95 if (status != 0) {
96 (*info->memory_error_func)(status, memaddr + 2, info);
97 return -1;
98 }
99
100 if (info->endian == BFD_ENDIAN_BIG) {
101 insn2 = bfd_getb16(buffer);
102 } else {
103 insn2 = bfd_getl16(buffer);
104 }
105 (*info->fprintf_func)(info->stream, "%04x ", insn2);
106 } else {
107 (*info->fprintf_func)(info->stream, " ");
108 }
109 /* Handle 48-bit opcodes. */
110 if ((insn1 >> 10) == 0x18) {
111 status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info);
112 if (status != 0) {
113 (*info->memory_error_func)(status, memaddr + 4, info);
114 return -1;
115 }
116
117 if (info->endian == BFD_ENDIAN_BIG) {
118 insn3 = bfd_getb16(buffer);
119 } else {
120 insn3 = bfd_getl16(buffer);
121 }
122 (*info->fprintf_func)(info->stream, "%04x ", insn3);
123 } else {
124 (*info->fprintf_func)(info->stream, " ");
125 }
126
127 int length = nanomips_dis(buf, memaddr, insn1, insn2, insn3);
128
129 /* FIXME: Should probably use a hash table on the major opcode here. */
130
131 (*info->fprintf_func) (info->stream, "%s", buf);
132 if (length > 0) {
133 return length / 8;
134 }
135
136 info->insn_type = dis_noninsn;
137
138 return insn3 ? 6 : insn2 ? 4 : 2;
139 }
140
141
142 namespace img
143 {
144 address addr32(address a)
145 {
146 return a;
147 }
148
149 std::string format(const char *format, ...)
150 {
151 char buffer[256];
152 va_list args;
153 va_start(args, format);
154 int err = vsprintf(buffer, format, args);
155 if (err < 0) {
156 perror(buffer);
157 }
158 va_end(args);
159 return buffer;
160 }
161
162 std::string format(const char *format,
163 std::string s)
164 {
165 char buffer[256];
166
167 sprintf(buffer, format, s.c_str());
168
169 return buffer;
170 }
171
172 std::string format(const char *format,
173 std::string s1,
174 std::string s2)
175 {
176 char buffer[256];
177
178 sprintf(buffer, format, s1.c_str(), s2.c_str());
179
180 return buffer;
181 }
182
183 std::string format(const char *format,
184 std::string s1,
185 std::string s2,
186 std::string s3)
187 {
188 char buffer[256];
189
190 sprintf(buffer, format, s1.c_str(), s2.c_str(), s3.c_str());
191
192 return buffer;
193 }
194
195 std::string format(const char *format,
196 std::string s1,
197 std::string s2,
198 std::string s3,
199 std::string s4)
200 {
201 char buffer[256];
202
203 sprintf(buffer, format, s1.c_str(), s2.c_str(), s3.c_str(),
204 s4.c_str());
205
206 return buffer;
207 }
208
209 std::string format(const char *format,
210 std::string s1,
211 std::string s2,
212 std::string s3,
213 std::string s4,
214 std::string s5)
215 {
216 char buffer[256];
217
218 sprintf(buffer, format, s1.c_str(), s2.c_str(), s3.c_str(),
219 s4.c_str(), s5.c_str());
220
221 return buffer;
222 }
223
224 std::string format(const char *format,
225 uint64 d,
226 std::string s2)
227 {
228 char buffer[256];
229
230 sprintf(buffer, format, d, s2.c_str());
231
232 return buffer;
233 }
234
235 std::string format(const char *format,
236 std::string s1,
237 uint64 d,
238 std::string s2)
239 {
240 char buffer[256];
241
242 sprintf(buffer, format, s1.c_str(), d, s2.c_str());
243
244 return buffer;
245 }
246
247 std::string format(const char *format,
248 std::string s1,
249 std::string s2,
250 uint64 d)
251 {
252 char buffer[256];
253
254 sprintf(buffer, format, s1.c_str(), s2.c_str(), d);
255
256 return buffer;
257 }
258
259 char as_char(int c)
260 {
261 return static_cast<char>(c);
262 }
263 };
264
265
266 std::string to_string(img::address a)
267 {
268 char buffer[256];
269 sprintf(buffer, "0x%" PRIx64, a);
270 return buffer;
271 }
272
273
274 uint64 extract_bits(uint64 data, uint32 bit_offset, uint32 bit_size)
275 {
276 return (data << (64 - (bit_size + bit_offset))) >> (64 - bit_size);
277 }
278
279
280 int64 sign_extend(int64 data, int msb)
281 {
282 uint64 shift = 63 - msb;
283 return (data << shift) >> shift;
284 }
285
286
287 uint64 NMD::renumber_registers(uint64 index, uint64 *register_list,
288 size_t register_list_size)
289 {
290 if (index < register_list_size) {
291 return register_list[index];
292 }
293
294 throw std::runtime_error(img::format(
295 "Invalid register mapping index %" PRIu64
296 ", size of list = %zu",
297 index, register_list_size));
298 }
299
300
301 /*
302 * NMD::decode_gpr_gpr4() - decoder for 'gpr4' gpr encoding type
303 *
304 * Map a 4-bit code to the 5-bit register space according to this pattern:
305 *
306 * 1 0
307 * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
308 * | | | | | | | | | | | | | | | |
309 * | | | | | | | | | | | | | | | |
310 * | | | | | | | | | | | └---------------┐
311 * | | | | | | | | | | └---------------┐ |
312 * | | | | | | | | | └---------------┐ | |
313 * | | | | | | | | └---------------┐ | | |
314 * | | | | | | | | | | | | | | | |
315 * | | | | | | | | | | | | | | | |
316 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
317 * 3 2 1 0
318 *
319 * Used in handling following instructions:
320 *
321 * - ADDU[4X4]
322 * - LW[4X4]
323 * - MOVEP[REV]
324 * - MUL[4X4]
325 * - SW[4X4]
326 */
327 uint64 NMD::decode_gpr_gpr4(uint64 d)
328 {
329 static uint64 register_list[] = { 8, 9, 10, 11, 4, 5, 6, 7,
330 16, 17, 18, 19, 20, 21, 22, 23 };
331 return renumber_registers(d, register_list,
332 sizeof(register_list) / sizeof(register_list[0]));
333 }
334
335
336 /*
337 * NMD::decode_gpr_gpr4_zero() - decoder for 'gpr4.zero' gpr encoding type
338 *
339 * Map a 4-bit code to the 5-bit register space according to this pattern:
340 *
341 * 1 0
342 * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
343 * | | | | | | | | | | | | | | | |
344 * | | | | | | | | | | | | └---------------------┐
345 * | | | | | | | | | | | └---------------┐ |
346 * | | | | | | | | | | └---------------┐ | |
347 * | | | | | | | | | └---------------┐ | | |
348 * | | | | | | | | └---------------┐ | | | |
349 * | | | | | | | | | | | | | | | |
350 * | | | | | | | | | | | | | | | |
351 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
352 * 3 2 1 0
353 *
354 * This pattern is the same one used for 'gpr4' gpr encoding type, except for
355 * the input value 3, that is mapped to the output value 0 instead of 11.
356 *
357 * Used in handling following instructions:
358 *
359 * - MOVE.BALC
360 * - MOVEP
361 * - SW[4X4]
362 */
363 uint64 NMD::decode_gpr_gpr4_zero(uint64 d)
364 {
365 static uint64 register_list[] = { 8, 9, 10, 0, 4, 5, 6, 7,
366 16, 17, 18, 19, 20, 21, 22, 23 };
367 return renumber_registers(d, register_list,
368 sizeof(register_list) / sizeof(register_list[0]));
369 }
370
371
372 /*
373 * NMD::decode_gpr_gpr3() - decoder for 'gpr3' gpr encoding type
374 *
375 * Map a 3-bit code to the 5-bit register space according to this pattern:
376 *
377 * 7 6 5 4 3 2 1 0
378 * | | | | | | | |
379 * | | | | | | | |
380 * | | | └-----------------------┐
381 * | | └-----------------------┐ |
382 * | └-----------------------┐ | |
383 * └-----------------------┐ | | |
384 * | | | | | | | |
385 * ┌-------┘ | | | | | | |
386 * | ┌-------┘ | | | | | |
387 * | | ┌-------┘ | | | | |
388 * | | | ┌-------┘ | | | |
389 * | | | | | | | |
390 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
391 * 3 2 1 0
392 *
393 * Used in handling following instructions:
394 *
395 * - ADDIU[R1.SP]
396 * - ADDIU[R2]
397 * - ADDU[16]
398 * - AND[16]
399 * - ANDI[16]
400 * - BEQC[16]
401 * - BEQZC[16]
402 * - BNEC[16]
403 * - BNEZC[16]
404 * - LB[16]
405 * - LBU[16]
406 * - LH[16]
407 * - LHU[16]
408 * - LI[16]
409 * - LW[16]
410 * - LW[GP16]
411 * - LWXS[16]
412 * - NOT[16]
413 * - OR[16]
414 * - SB[16]
415 * - SH[16]
416 * - SLL[16]
417 * - SRL[16]
418 * - SUBU[16]
419 * - SW[16]
420 * - XOR[16]
421 */
422 uint64 NMD::decode_gpr_gpr3(uint64 d)
423 {
424 static uint64 register_list[] = { 16, 17, 18, 19, 4, 5, 6, 7 };
425 return renumber_registers(d, register_list,
426 sizeof(register_list) / sizeof(register_list[0]));
427 }
428
429
430 /*
431 * NMD::decode_gpr_gpr3_src_store() - decoder for 'gpr3.src.store' gpr encoding
432 * type
433 *
434 * Map a 3-bit code to the 5-bit register space according to this pattern:
435 *
436 * 7 6 5 4 3 2 1 0
437 * | | | | | | | |
438 * | | | | | | | └-----------------------┐
439 * | | | └-----------------------┐ |
440 * | | └-----------------------┐ | |
441 * | └-----------------------┐ | | |
442 * └-----------------------┐ | | | |
443 * | | | | | | | |
444 * ┌-------┘ | | | | | | |
445 * | ┌-------┘ | | | | | |
446 * | | ┌-------┘ | | | | |
447 * | | | | | | | |
448 * | | | | | | | |
449 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
450 * 3 2 1 0
451 *
452 * This pattern is the same one used for 'gpr3' gpr encoding type, except for
453 * the input value 0, that is mapped to the output value 0 instead of 16.
454 *
455 * Used in handling following instructions:
456 *
457 * - SB[16]
458 * - SH[16]
459 * - SW[16]
460 * - SW[GP16]
461 */
462 uint64 NMD::decode_gpr_gpr3_src_store(uint64 d)
463 {
464 static uint64 register_list[] = { 0, 17, 18, 19, 4, 5, 6, 7 };
465 return renumber_registers(d, register_list,
466 sizeof(register_list) / sizeof(register_list[0]));
467 }
468
469
470 /*
471 * NMD::decode_gpr_gpr2_reg1() - decoder for 'gpr2.reg1' gpr encoding type
472 *
473 * Map a 2-bit code to the 5-bit register space according to this pattern:
474 *
475 * 3 2 1 0
476 * | | | |
477 * | | | |
478 * | | | └-------------------┐
479 * | | └-------------------┐ |
480 * | └-------------------┐ | |
481 * └-------------------┐ | | |
482 * | | | |
483 * | | | |
484 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
485 * 3 2 1 0
486 *
487 * Used in handling following instructions:
488 *
489 * - MOVEP
490 * - MOVEP[REV]
491 */
492 uint64 NMD::decode_gpr_gpr2_reg1(uint64 d)
493 {
494 static uint64 register_list[] = { 4, 5, 6, 7 };
495 return renumber_registers(d, register_list,
496 sizeof(register_list) / sizeof(register_list[0]));
497 }
498
499
500 /*
501 * NMD::decode_gpr_gpr2_reg2() - decoder for 'gpr2.reg2' gpr encoding type
502 *
503 * Map a 2-bit code to the 5-bit register space according to this pattern:
504 *
505 * 3 2 1 0
506 * | | | |
507 * | | | |
508 * | | | └-----------------┐
509 * | | └-----------------┐ |
510 * | └-----------------┐ | |
511 * └-----------------┐ | | |
512 * | | | |
513 * | | | |
514 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
515 * 3 2 1 0
516 *
517 * Used in handling following instructions:
518 *
519 * - MOVEP
520 * - MOVEP[REV]
521 */
522 uint64 NMD::decode_gpr_gpr2_reg2(uint64 d)
523 {
524 static uint64 register_list[] = { 5, 6, 7, 8 };
525 return renumber_registers(d, register_list,
526 sizeof(register_list) / sizeof(register_list[0]));
527 }
528
529
530 /*
531 * NMD::decode_gpr_gpr1() - decoder for 'gpr1' gpr encoding type
532 *
533 * Map a 1-bit code to the 5-bit register space according to this pattern:
534 *
535 * 1 0
536 * | |
537 * | |
538 * | └---------------------┐
539 * └---------------------┐ |
540 * | |
541 * | |
542 * | |
543 * | |
544 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
545 * 3 2 1 0
546 *
547 * Used in handling following instruction:
548 *
549 * - MOVE.BALC
550 */
551 uint64 NMD::decode_gpr_gpr1(uint64 d)
552 {
553 static uint64 register_list[] = { 4, 5 };
554 return renumber_registers(d, register_list,
555 sizeof(register_list) / sizeof(register_list[0]));
556 }
557
558
559 uint64 NMD::copy(uint64 d)
560 {
561 return d;
562 }
563
564
565 int64 NMD::copy(int64 d)
566 {
567 return d;
568 }
569
570
571 int64 NMD::neg_copy(uint64 d)
572 {
573 return 0ll - d;
574 }
575
576
577 int64 NMD::neg_copy(int64 d)
578 {
579 return -d;
580 }
581
582
583 /* strange wrapper around gpr3 */
584 uint64 NMD::encode_rs3_and_check_rs3_ge_rt3(uint64 d)
585 {
586 return decode_gpr_gpr3(d);
587 }
588
589
590 /* strange wrapper around gpr3 */
591 uint64 NMD::encode_rs3_and_check_rs3_lt_rt3(uint64 d)
592 {
593 return decode_gpr_gpr3(d);
594 }
595
596
597 /* nop - done by extraction function */
598 uint64 NMD::encode_s_from_address(uint64 d)
599 {
600 return d;
601 }
602
603
604 /* nop - done by extraction function */
605 uint64 NMD::encode_u_from_address(uint64 d)
606 {
607 return d;
608 }
609
610
611 /* nop - done by extraction function */
612 uint64 NMD::encode_s_from_s_hi(uint64 d)
613 {
614 return d;
615 }
616
617
618 uint64 NMD::encode_count3_from_count(uint64 d)
619 {
620 IMGASSERTONCE(d < 8);
621 return d == 0ull ? 8ull : d;
622 }
623
624
625 uint64 NMD::encode_shift3_from_shift(uint64 d)
626 {
627 IMGASSERTONCE(d < 8);
628 return d == 0ull ? 8ull : d;
629 }
630
631
632 /* special value for load literal */
633 int64 NMD::encode_eu_from_s_li16(uint64 d)
634 {
635 IMGASSERTONCE(d < 128);
636 return d == 127 ? -1 : (int64)d;
637 }
638
639
640 uint64 NMD::encode_msbd_from_size(uint64 d)
641 {
642 IMGASSERTONCE(d < 32);
643 return d + 1;
644 }
645
646
647 uint64 NMD::encode_eu_from_u_andi16(uint64 d)
648 {
649 IMGASSERTONCE(d < 16);
650 if (d == 12) {
651 return 0x00ffull;
652 }
653 if (d == 13) {
654 return 0xffffull;
655 }
656 return d;
657 }
658
659
660 uint64 NMD::encode_msbd_from_pos_and_size(uint64 d)
661 {
662 IMGASSERTONCE(0);
663 return d;
664 }
665
666
667 /* save16 / restore16 ???? */
668 uint64 NMD::encode_rt1_from_rt(uint64 d)
669 {
670 return d ? 31 : 30;
671 }
672
673
674 /* ? */
675 uint64 NMD::encode_lsb_from_pos_and_size(uint64 d)
676 {
677 return d;
678 }
679
680
681 std::string NMD::save_restore_list(uint64 rt, uint64 count, uint64 gp)
682 {
683 std::string str;
684
685 for (uint64 counter = 0; counter != count; counter++) {
686 bool use_gp = gp && (counter == count - 1);
687 uint64 this_rt = use_gp ? 28 : ((rt & 0x10) | (rt + counter)) & 0x1f;
688 str += img::format(",%s", GPR(this_rt));
689 }
690
691 return str;
692 }
693
694
695 std::string NMD::GPR(uint64 reg)
696 {
697 static const char *gpr_reg[32] = {
698 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
699 "a4", "a5", "a6", "a7", "r12", "r13", "r14", "r15",
700 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
701 "r24", "r25", "k0", "k1", "gp", "sp", "fp", "ra"
702 };
703
704 if (reg < 32) {
705 return gpr_reg[reg];
706 }
707
708 throw std::runtime_error(img::format("Invalid GPR register index %" PRIu64,
709 reg));
710 }
711
712
713 std::string NMD::FPR(uint64 reg)
714 {
715 static const char *fpr_reg[32] = {
716 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
717 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
718 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
719 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
720 };
721
722 if (reg < 32) {
723 return fpr_reg[reg];
724 }
725
726 throw std::runtime_error(img::format("Invalid FPR register index %" PRIu64,
727 reg));
728 }
729
730
731 std::string NMD::AC(uint64 reg)
732 {
733 static const char *ac_reg[4] = {
734 "ac0", "ac1", "ac2", "ac3"
735 };
736
737 if (reg < 4) {
738 return ac_reg[reg];
739 }
740
741 throw std::runtime_error(img::format("Invalid AC register index %" PRIu64,
742 reg));
743 }
744
745
746 std::string NMD::IMMEDIATE(uint64 value)
747 {
748 return img::format("0x%" PRIx64, value);
749 }
750
751
752 std::string NMD::IMMEDIATE(int64 value)
753 {
754 return img::format("%" PRId64, value);
755 }
756
757
758 std::string NMD::CPR(uint64 reg)
759 {
760 /* needs more work */
761 return img::format("CP%" PRIu64, reg);
762 }
763
764
765 std::string NMD::ADDRESS(uint64 value, int instruction_size)
766 {
767 /* token for string replace */
768 /* const char TOKEN_REPLACE = (char)0xa2; */
769 img::address address = m_pc + value + instruction_size;
770 /* symbol replacement */
771 /* return img::as_char(TOKEN_REPLACE) + to_string(address); */
772 return to_string(address);
773 }
774
775
776 uint64 NMD::extract_op_code_value(const uint16 * data, int size)
777 {
778 switch (size) {
779 case 16:
780 return data[0];
781 case 32:
782 return ((uint64)data[0] << 16) | data[1];
783 case 48:
784 return ((uint64)data[0] << 32) | ((uint64)data[1] << 16) | data[2];
785 default:
786 return data[0];
787 }
788 }
789
790
791 int NMD::Disassemble(const uint16 * data, std::string & dis,
792 NMD::TABLE_ENTRY_TYPE & type)
793 {
794 return Disassemble(data, dis, type, MAJOR, 2);
795 }
796
797
798 /*
799 * Recurse through tables until the instruction is found then return
800 * the string and size
801 *
802 * inputs:
803 * pointer to a word stream,
804 * disassember table and size
805 * returns:
806 * instruction size - negative is error
807 * disassembly string - on error will constain error string
808 */
809 int NMD::Disassemble(const uint16 * data, std::string & dis,
810 NMD::TABLE_ENTRY_TYPE & type, const Pool *table,
811 int table_size)
812 {
813 try
814 {
815 for (int i = 0; i < table_size; i++) {
816 uint64 op_code = extract_op_code_value(data,
817 table[i].instructions_size);
818 if ((op_code & table[i].mask) == table[i].value) {
819 /* possible match */
820 conditional_function cond = table[i].condition;
821 if ((cond == 0) || (this->*cond)(op_code)) {
822 try
823 {
824 if (table[i].type == pool) {
825 return Disassemble(data, dis, type,
826 table[i].next_table,
827 table[i].next_table_size);
828 } else if ((table[i].type == instruction) ||
829 (table[i].type == call_instruction) ||
830 (table[i].type == branch_instruction) ||
831 (table[i].type == return_instruction)) {
832 if ((table[i].attributes != 0) &&
833 (m_requested_instruction_categories &
834 table[i].attributes) == 0) {
835 /*
836 * failed due to instruction having
837 * an ASE attribute and the requested version
838 * not having that attribute
839 */
840 dis = "ASE attribute missmatch";
841 return -5;
842 }
843 disassembly_function dis_fn = table[i].disassembly;
844 if (dis_fn == 0) {
845 dis = "disassembler failure - bad table entry";
846 return -6;
847 }
848 type = table[i].type;
849 dis = (this->*dis_fn)(op_code);
850 return table[i].instructions_size;
851 } else {
852 dis = "reserved instruction";
853 return -2;
854 }
855 }
856 catch (std::runtime_error & e)
857 {
858 dis = e.what();
859 return -3; /* runtime error */
860 }
861 }
862 }
863 }
864 }
865 catch (std::exception & e)
866 {
867 dis = e.what();
868 return -4; /* runtime error */
869 }
870
871 dis = "failed to disassemble";
872 return -1; /* failed to disassemble */
873 }
874
875
876 uint64 NMD::extract_code_18_to_0(uint64 instruction)
877 {
878 uint64 value = 0;
879 value |= extract_bits(instruction, 0, 19);
880 return value;
881 }
882
883
884 uint64 NMD::extract_shift3_2_1_0(uint64 instruction)
885 {
886 uint64 value = 0;
887 value |= extract_bits(instruction, 0, 3);
888 return value;
889 }
890
891
892 uint64 NMD::extract_u_11_10_9_8_7_6_5_4_3__s3(uint64 instruction)
893 {
894 uint64 value = 0;
895 value |= extract_bits(instruction, 3, 9) << 3;
896 return value;
897 }
898
899
900 uint64 NMD::extract_count_3_2_1_0(uint64 instruction)
901 {
902 uint64 value = 0;
903 value |= extract_bits(instruction, 0, 4);
904 return value;
905 }
906
907
908 uint64 NMD::extract_rtz3_9_8_7(uint64 instruction)
909 {
910 uint64 value = 0;
911 value |= extract_bits(instruction, 7, 3);
912 return value;
913 }
914
915
916 uint64 NMD::extract_u_17_to_1__s1(uint64 instruction)
917 {
918 uint64 value = 0;
919 value |= extract_bits(instruction, 1, 17) << 1;
920 return value;
921 }
922
923
924 int64 NMD::extract_s__se9_20_19_18_17_16_15_14_13_12_11(uint64 instruction)
925 {
926 int64 value = 0;
927 value |= extract_bits(instruction, 11, 10);
928 value = sign_extend(value, 9);
929 return value;
930 }
931
932
933 int64 NMD::extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(uint64 instruction)
934 {
935 int64 value = 0;
936 value |= extract_bits(instruction, 0, 1) << 11;
937 value |= extract_bits(instruction, 1, 10) << 1;
938 value = sign_extend(value, 11);
939 return value;
940 }
941
942
943 uint64 NMD::extract_u_10(uint64 instruction)
944 {
945 uint64 value = 0;
946 value |= extract_bits(instruction, 10, 1);
947 return value;
948 }
949
950
951 uint64 NMD::extract_rtz4_27_26_25_23_22_21(uint64 instruction)
952 {
953 uint64 value = 0;
954 value |= extract_bits(instruction, 21, 3);
955 value |= extract_bits(instruction, 25, 1) << 3;
956 return value;
957 }
958
959
960 uint64 NMD::extract_sa_15_14_13_12_11(uint64 instruction)
961 {
962 uint64 value = 0;
963 value |= extract_bits(instruction, 11, 5);
964 return value;
965 }
966
967
968 uint64 NMD::extract_shift_4_3_2_1_0(uint64 instruction)
969 {
970 uint64 value = 0;
971 value |= extract_bits(instruction, 0, 5);
972 return value;
973 }
974
975
976 uint64 NMD::extract_shiftx_10_9_8_7__s1(uint64 instruction)
977 {
978 uint64 value = 0;
979 value |= extract_bits(instruction, 7, 4) << 1;
980 return value;
981 }
982
983
984 uint64 NMD::extract_hint_25_24_23_22_21(uint64 instruction)
985 {
986 uint64 value = 0;
987 value |= extract_bits(instruction, 21, 5);
988 return value;
989 }
990
991
992 uint64 NMD::extract_count3_14_13_12(uint64 instruction)
993 {
994 uint64 value = 0;
995 value |= extract_bits(instruction, 12, 3);
996 return value;
997 }
998
999
1000 int64 NMD::extract_s__se31_0_11_to_2_20_to_12_s12(uint64 instruction)
1001 {
1002 int64 value = 0;
1003 value |= extract_bits(instruction, 0, 1) << 31;
1004 value |= extract_bits(instruction, 2, 10) << 21;
1005 value |= extract_bits(instruction, 12, 9) << 12;
1006 value = sign_extend(value, 31);
1007 return value;
1008 }
1009
1010
1011 int64 NMD::extract_s__se7_0_6_5_4_3_2_1_s1(uint64 instruction)
1012 {
1013 int64 value = 0;
1014 value |= extract_bits(instruction, 0, 1) << 7;
1015 value |= extract_bits(instruction, 1, 6) << 1;
1016 value = sign_extend(value, 7);
1017 return value;
1018 }
1019
1020
1021 uint64 NMD::extract_u2_10_9(uint64 instruction)
1022 {
1023 uint64 value = 0;
1024 value |= extract_bits(instruction, 9, 2);
1025 return value;
1026 }
1027
1028
1029 uint64 NMD::extract_code_25_24_23_22_21_20_19_18_17_16(uint64 instruction)
1030 {
1031 uint64 value = 0;
1032 value |= extract_bits(instruction, 16, 10);
1033 return value;
1034 }
1035
1036
1037 uint64 NMD::extract_rs_20_19_18_17_16(uint64 instruction)
1038 {
1039 uint64 value = 0;
1040 value |= extract_bits(instruction, 16, 5);
1041 return value;
1042 }
1043
1044
1045 uint64 NMD::extract_u_2_1__s1(uint64 instruction)
1046 {
1047 uint64 value = 0;
1048 value |= extract_bits(instruction, 1, 2) << 1;
1049 return value;
1050 }
1051
1052
1053 uint64 NMD::extract_stripe_6(uint64 instruction)
1054 {
1055 uint64 value = 0;
1056 value |= extract_bits(instruction, 6, 1);
1057 return value;
1058 }
1059
1060
1061 uint64 NMD::extract_ac_15_14(uint64 instruction)
1062 {
1063 uint64 value = 0;
1064 value |= extract_bits(instruction, 14, 2);
1065 return value;
1066 }
1067
1068
1069 uint64 NMD::extract_shift_20_19_18_17_16(uint64 instruction)
1070 {
1071 uint64 value = 0;
1072 value |= extract_bits(instruction, 16, 5);
1073 return value;
1074 }
1075
1076
1077 uint64 NMD::extract_rdl_25_24(uint64 instruction)
1078 {
1079 uint64 value = 0;
1080 value |= extract_bits(instruction, 24, 1);
1081 return value;
1082 }
1083
1084
1085 int64 NMD::extract_s__se10_0_9_8_7_6_5_4_3_2_1_s1(uint64 instruction)
1086 {
1087 int64 value = 0;
1088 value |= extract_bits(instruction, 0, 1) << 10;
1089 value |= extract_bits(instruction, 1, 9) << 1;
1090 value = sign_extend(value, 10);
1091 return value;
1092 }
1093
1094
1095 uint64 NMD::extract_eu_6_5_4_3_2_1_0(uint64 instruction)
1096 {
1097 uint64 value = 0;
1098 value |= extract_bits(instruction, 0, 7);
1099 return value;
1100 }
1101
1102
1103 uint64 NMD::extract_shift_5_4_3_2_1_0(uint64 instruction)
1104 {
1105 uint64 value = 0;
1106 value |= extract_bits(instruction, 0, 6);
1107 return value;
1108 }
1109
1110
1111 uint64 NMD::extract_count_19_18_17_16(uint64 instruction)
1112 {
1113 uint64 value = 0;
1114 value |= extract_bits(instruction, 16, 4);
1115 return value;
1116 }
1117
1118
1119 uint64 NMD::extract_code_2_1_0(uint64 instruction)
1120 {
1121 uint64 value = 0;
1122 value |= extract_bits(instruction, 0, 3);
1123 return value;
1124 }
1125
1126
1127 uint64 NMD::extract_u_11_10_9_8_7_6_5_4_3_2_1_0(uint64 instruction)
1128 {
1129 uint64 value = 0;
1130 value |= extract_bits(instruction, 0, 12);
1131 return value;
1132 }
1133
1134
1135 uint64 NMD::extract_rs_4_3_2_1_0(uint64 instruction)
1136 {
1137 uint64 value = 0;
1138 value |= extract_bits(instruction, 0, 5);
1139 return value;
1140 }
1141
1142
1143 uint64 NMD::extract_u_20_to_3__s3(uint64 instruction)
1144 {
1145 uint64 value = 0;
1146 value |= extract_bits(instruction, 3, 18) << 3;
1147 return value;
1148 }
1149
1150
1151 uint64 NMD::extract_u_3_2_1_0__s2(uint64 instruction)
1152 {
1153 uint64 value = 0;
1154 value |= extract_bits(instruction, 0, 4) << 2;
1155 return value;
1156 }
1157
1158
1159 uint64 NMD::extract_cofun_25_24_23(uint64 instruction)
1160 {
1161 uint64 value = 0;
1162 value |= extract_bits(instruction, 3, 23);
1163 return value;
1164 }
1165
1166
1167 uint64 NMD::extract_u_2_1_0__s2(uint64 instruction)
1168 {
1169 uint64 value = 0;
1170 value |= extract_bits(instruction, 0, 3) << 2;
1171 return value;
1172 }
1173
1174
1175 uint64 NMD::extract_rd3_3_2_1(uint64 instruction)
1176 {
1177 uint64 value = 0;
1178 value |= extract_bits(instruction, 1, 3);
1179 return value;
1180 }
1181
1182
1183 uint64 NMD::extract_sa_15_14_13_12(uint64 instruction)
1184 {
1185 uint64 value = 0;
1186 value |= extract_bits(instruction, 12, 4);
1187 return value;
1188 }
1189
1190
1191 uint64 NMD::extract_rt_25_24_23_22_21(uint64 instruction)
1192 {
1193 uint64 value = 0;
1194 value |= extract_bits(instruction, 21, 5);
1195 return value;
1196 }
1197
1198
1199 uint64 NMD::extract_ru_7_6_5_4_3(uint64 instruction)
1200 {
1201 uint64 value = 0;
1202 value |= extract_bits(instruction, 3, 5);
1203 return value;
1204 }
1205
1206
1207 uint64 NMD::extract_u_17_to_0(uint64 instruction)
1208 {
1209 uint64 value = 0;
1210 value |= extract_bits(instruction, 0, 18);
1211 return value;
1212 }
1213
1214
1215 uint64 NMD::extract_rsz4_4_2_1_0(uint64 instruction)
1216 {
1217 uint64 value = 0;
1218 value |= extract_bits(instruction, 0, 3);
1219 value |= extract_bits(instruction, 4, 1) << 3;
1220 return value;
1221 }
1222
1223
1224 int64 NMD::extract_s__se21_0_20_to_1_s1(uint64 instruction)
1225 {
1226 int64 value = 0;
1227 value |= extract_bits(instruction, 0, 1) << 21;
1228 value |= extract_bits(instruction, 1, 20) << 1;
1229 value = sign_extend(value, 21);
1230 return value;
1231 }
1232
1233
1234 uint64 NMD::extract_op_25_to_3(uint64 instruction)
1235 {
1236 uint64 value = 0;
1237 value |= extract_bits(instruction, 3, 23);
1238 return value;
1239 }
1240
1241
1242 uint64 NMD::extract_rs4_4_2_1_0(uint64 instruction)
1243 {
1244 uint64 value = 0;
1245 value |= extract_bits(instruction, 0, 3);
1246 value |= extract_bits(instruction, 4, 1) << 3;
1247 return value;
1248 }
1249
1250
1251 uint64 NMD::extract_bit_23_22_21(uint64 instruction)
1252 {
1253 uint64 value = 0;
1254 value |= extract_bits(instruction, 21, 3);
1255 return value;
1256 }
1257
1258
1259 uint64 NMD::extract_rt_41_40_39_38_37(uint64 instruction)
1260 {
1261 uint64 value = 0;
1262 value |= extract_bits(instruction, 37, 5);
1263 return value;
1264 }
1265
1266
1267 int64 NMD::extract_shift__se5_21_20_19_18_17_16(uint64 instruction)
1268 {
1269 int64 value = 0;
1270 value |= extract_bits(instruction, 16, 6);
1271 value = sign_extend(value, 5);
1272 return value;
1273 }
1274
1275
1276 uint64 NMD::extract_rd2_3_8(uint64 instruction)
1277 {
1278 uint64 value = 0;
1279 value |= extract_bits(instruction, 3, 1) << 1;
1280 value |= extract_bits(instruction, 8, 1);
1281 return value;
1282 }
1283
1284
1285 uint64 NMD::extract_code_17_to_0(uint64 instruction)
1286 {
1287 uint64 value = 0;
1288 value |= extract_bits(instruction, 0, 18);
1289 return value;
1290 }
1291
1292
1293 uint64 NMD::extract_size_20_19_18_17_16(uint64 instruction)
1294 {
1295 uint64 value = 0;
1296 value |= extract_bits(instruction, 16, 5);
1297 return value;
1298 }
1299
1300
1301 int64 NMD::extract_s__se8_15_7_6_5_4_3_2_s2(uint64 instruction)
1302 {
1303 int64 value = 0;
1304 value |= extract_bits(instruction, 2, 6) << 2;
1305 value |= extract_bits(instruction, 15, 1) << 8;
1306 value = sign_extend(value, 8);
1307 return value;
1308 }
1309
1310
1311 uint64 NMD::extract_u_15_to_0(uint64 instruction)
1312 {
1313 uint64 value = 0;
1314 value |= extract_bits(instruction, 0, 16);
1315 return value;
1316 }
1317
1318
1319 uint64 NMD::extract_fs_20_19_18_17_16(uint64 instruction)
1320 {
1321 uint64 value = 0;
1322 value |= extract_bits(instruction, 16, 5);
1323 return value;
1324 }
1325
1326
1327 int64 NMD::extract_s__se8_15_7_6_5_4_3_2_1_0(uint64 instruction)
1328 {
1329 int64 value = 0;
1330 value |= extract_bits(instruction, 0, 8);
1331 value |= extract_bits(instruction, 15, 1) << 8;
1332 value = sign_extend(value, 8);
1333 return value;
1334 }
1335
1336
1337 uint64 NMD::extract_stype_20_19_18_17_16(uint64 instruction)
1338 {
1339 uint64 value = 0;
1340 value |= extract_bits(instruction, 16, 5);
1341 return value;
1342 }
1343
1344
1345 uint64 NMD::extract_rtl_11(uint64 instruction)
1346 {
1347 uint64 value = 0;
1348 value |= extract_bits(instruction, 9, 1);
1349 return value;
1350 }
1351
1352
1353 uint64 NMD::extract_hs_20_19_18_17_16(uint64 instruction)
1354 {
1355 uint64 value = 0;
1356 value |= extract_bits(instruction, 16, 5);
1357 return value;
1358 }
1359
1360
1361 uint64 NMD::extract_sel_13_12_11(uint64 instruction)
1362 {
1363 uint64 value = 0;
1364 value |= extract_bits(instruction, 11, 3);
1365 return value;
1366 }
1367
1368
1369 uint64 NMD::extract_lsb_4_3_2_1_0(uint64 instruction)
1370 {
1371 uint64 value = 0;
1372 value |= extract_bits(instruction, 0, 5);
1373 return value;
1374 }
1375
1376
1377 uint64 NMD::extract_gp_2(uint64 instruction)
1378 {
1379 uint64 value = 0;
1380 value |= extract_bits(instruction, 2, 1);
1381 return value;
1382 }
1383
1384
1385 uint64 NMD::extract_rt3_9_8_7(uint64 instruction)
1386 {
1387 uint64 value = 0;
1388 value |= extract_bits(instruction, 7, 3);
1389 return value;
1390 }
1391
1392
1393 uint64 NMD::extract_ft_25_24_23_22_21(uint64 instruction)
1394 {
1395 uint64 value = 0;
1396 value |= extract_bits(instruction, 21, 5);
1397 return value;
1398 }
1399
1400
1401 uint64 NMD::extract_u_17_16_15_14_13_12_11(uint64 instruction)
1402 {
1403 uint64 value = 0;
1404 value |= extract_bits(instruction, 11, 7);
1405 return value;
1406 }
1407
1408
1409 uint64 NMD::extract_cs_20_19_18_17_16(uint64 instruction)
1410 {
1411 uint64 value = 0;
1412 value |= extract_bits(instruction, 16, 5);
1413 return value;
1414 }
1415
1416
1417 uint64 NMD::extract_rt4_9_7_6_5(uint64 instruction)
1418 {
1419 uint64 value = 0;
1420 value |= extract_bits(instruction, 5, 3);
1421 value |= extract_bits(instruction, 9, 1) << 3;
1422 return value;
1423 }
1424
1425
1426 uint64 NMD::extract_msbt_10_9_8_7_6(uint64 instruction)
1427 {
1428 uint64 value = 0;
1429 value |= extract_bits(instruction, 6, 5);
1430 return value;
1431 }
1432
1433
1434 uint64 NMD::extract_u_5_4_3_2_1_0__s2(uint64 instruction)
1435 {
1436 uint64 value = 0;
1437 value |= extract_bits(instruction, 0, 6) << 2;
1438 return value;
1439 }
1440
1441
1442 uint64 NMD::extract_sa_15_14_13(uint64 instruction)
1443 {
1444 uint64 value = 0;
1445 value |= extract_bits(instruction, 13, 3);
1446 return value;
1447 }
1448
1449
1450 int64 NMD::extract_s__se14_0_13_to_1_s1(uint64 instruction)
1451 {
1452 int64 value = 0;
1453 value |= extract_bits(instruction, 0, 1) << 14;
1454 value |= extract_bits(instruction, 1, 13) << 1;
1455 value = sign_extend(value, 14);
1456 return value;
1457 }
1458
1459
1460 uint64 NMD::extract_rs3_6_5_4(uint64 instruction)
1461 {
1462 uint64 value = 0;
1463 value |= extract_bits(instruction, 4, 3);
1464 return value;
1465 }
1466
1467
1468 uint64 NMD::extract_u_31_to_0__s32(uint64 instruction)
1469 {
1470 uint64 value = 0;
1471 value |= extract_bits(instruction, 0, 32) << 32;
1472 return value;
1473 }
1474
1475
1476 uint64 NMD::extract_shift_10_9_8_7_6(uint64 instruction)
1477 {
1478 uint64 value = 0;
1479 value |= extract_bits(instruction, 6, 5);
1480 return value;
1481 }
1482
1483
1484 uint64 NMD::extract_cs_25_24_23_22_21(uint64 instruction)
1485 {
1486 uint64 value = 0;
1487 value |= extract_bits(instruction, 21, 5);
1488 return value;
1489 }
1490
1491
1492 uint64 NMD::extract_shiftx_11_10_9_8_7_6(uint64 instruction)
1493 {
1494 uint64 value = 0;
1495 value |= extract_bits(instruction, 6, 6);
1496 return value;
1497 }
1498
1499
1500 uint64 NMD::extract_rt_9_8_7_6_5(uint64 instruction)
1501 {
1502 uint64 value = 0;
1503 value |= extract_bits(instruction, 5, 5);
1504 return value;
1505 }
1506
1507
1508 uint64 NMD::extract_op_25_24_23_22_21(uint64 instruction)
1509 {
1510 uint64 value = 0;
1511 value |= extract_bits(instruction, 21, 5);
1512 return value;
1513 }
1514
1515
1516 uint64 NMD::extract_u_6_5_4_3_2_1_0__s2(uint64 instruction)
1517 {
1518 uint64 value = 0;
1519 value |= extract_bits(instruction, 0, 7) << 2;
1520 return value;
1521 }
1522
1523
1524 uint64 NMD::extract_bit_16_15_14_13_12_11(uint64 instruction)
1525 {
1526 uint64 value = 0;
1527 value |= extract_bits(instruction, 11, 6);
1528 return value;
1529 }
1530
1531
1532 uint64 NMD::extract_mask_20_19_18_17_16_15_14(uint64 instruction)
1533 {
1534 uint64 value = 0;
1535 value |= extract_bits(instruction, 14, 7);
1536 return value;
1537 }
1538
1539
1540 uint64 NMD::extract_eu_3_2_1_0(uint64 instruction)
1541 {
1542 uint64 value = 0;
1543 value |= extract_bits(instruction, 0, 4);
1544 return value;
1545 }
1546
1547
1548 uint64 NMD::extract_u_7_6_5_4__s4(uint64 instruction)
1549 {
1550 uint64 value = 0;
1551 value |= extract_bits(instruction, 4, 4) << 4;
1552 return value;
1553 }
1554
1555
1556 int64 NMD::extract_s__se8_15_7_6_5_4_3_s3(uint64 instruction)
1557 {
1558 int64 value = 0;
1559 value |= extract_bits(instruction, 3, 5) << 3;
1560 value |= extract_bits(instruction, 15, 1) << 8;
1561 value = sign_extend(value, 8);
1562 return value;
1563 }
1564
1565
1566 uint64 NMD::extract_ft_15_14_13_12_11(uint64 instruction)
1567 {
1568 uint64 value = 0;
1569 value |= extract_bits(instruction, 11, 5);
1570 return value;
1571 }
1572
1573
1574 int64 NMD::extract_s__se31_15_to_0_31_to_16(uint64 instruction)
1575 {
1576 int64 value = 0;
1577 value |= extract_bits(instruction, 0, 16) << 16;
1578 value |= extract_bits(instruction, 16, 16);
1579 value = sign_extend(value, 31);
1580 return value;
1581 }
1582
1583
1584 uint64 NMD::extract_u_20_19_18_17_16_15_14_13(uint64 instruction)
1585 {
1586 uint64 value = 0;
1587 value |= extract_bits(instruction, 13, 8);
1588 return value;
1589 }
1590
1591
1592 uint64 NMD::extract_u_17_to_2__s2(uint64 instruction)
1593 {
1594 uint64 value = 0;
1595 value |= extract_bits(instruction, 2, 16) << 2;
1596 return value;
1597 }
1598
1599
1600 uint64 NMD::extract_rd_15_14_13_12_11(uint64 instruction)
1601 {
1602 uint64 value = 0;
1603 value |= extract_bits(instruction, 11, 5);
1604 return value;
1605 }
1606
1607
1608 uint64 NMD::extract_c0s_20_19_18_17_16(uint64 instruction)
1609 {
1610 uint64 value = 0;
1611 value |= extract_bits(instruction, 16, 5);
1612 return value;
1613 }
1614
1615
1616 uint64 NMD::extract_code_1_0(uint64 instruction)
1617 {
1618 uint64 value = 0;
1619 value |= extract_bits(instruction, 0, 2);
1620 return value;
1621 }
1622
1623
1624 int64 NMD::extract_s__se25_0_24_to_1_s1(uint64 instruction)
1625 {
1626 int64 value = 0;
1627 value |= extract_bits(instruction, 0, 1) << 25;
1628 value |= extract_bits(instruction, 1, 24) << 1;
1629 value = sign_extend(value, 25);
1630 return value;
1631 }
1632
1633
1634 uint64 NMD::extract_u_1_0(uint64 instruction)
1635 {
1636 uint64 value = 0;
1637 value |= extract_bits(instruction, 0, 2);
1638 return value;
1639 }
1640
1641
1642 uint64 NMD::extract_u_3_8__s2(uint64 instruction)
1643 {
1644 uint64 value = 0;
1645 value |= extract_bits(instruction, 3, 1) << 3;
1646 value |= extract_bits(instruction, 8, 1) << 2;
1647 return value;
1648 }
1649
1650
1651 uint64 NMD::extract_fd_15_14_13_12_11(uint64 instruction)
1652 {
1653 uint64 value = 0;
1654 value |= extract_bits(instruction, 11, 5);
1655 return value;
1656 }
1657
1658
1659 uint64 NMD::extract_u_4_3_2_1_0__s2(uint64 instruction)
1660 {
1661 uint64 value = 0;
1662 value |= extract_bits(instruction, 0, 5) << 2;
1663 return value;
1664 }
1665
1666
1667 uint64 NMD::extract_rtz4_9_7_6_5(uint64 instruction)
1668 {
1669 uint64 value = 0;
1670 value |= extract_bits(instruction, 5, 3);
1671 value |= extract_bits(instruction, 9, 1) << 3;
1672 return value;
1673 }
1674
1675
1676 uint64 NMD::extract_sel_15_14_13_12_11(uint64 instruction)
1677 {
1678 uint64 value = 0;
1679 value |= extract_bits(instruction, 11, 5);
1680 return value;
1681 }
1682
1683
1684 uint64 NMD::extract_ct_25_24_23_22_21(uint64 instruction)
1685 {
1686 uint64 value = 0;
1687 value |= extract_bits(instruction, 21, 5);
1688 return value;
1689 }
1690
1691
1692 uint64 NMD::extract_u_20_to_2__s2(uint64 instruction)
1693 {
1694 uint64 value = 0;
1695 value |= extract_bits(instruction, 2, 19) << 2;
1696 return value;
1697 }
1698
1699
1700 int64 NMD::extract_s__se3_4_2_1_0(uint64 instruction)
1701 {
1702 int64 value = 0;
1703 value |= extract_bits(instruction, 0, 3);
1704 value |= extract_bits(instruction, 4, 1) << 3;
1705 value = sign_extend(value, 3);
1706 return value;
1707 }
1708
1709
1710 uint64 NMD::extract_u_3_2_1_0__s1(uint64 instruction)
1711 {
1712 uint64 value = 0;
1713 value |= extract_bits(instruction, 0, 4) << 1;
1714 return value;
1715 }
1716
1717
1718
1719 bool NMD::ADDIU_32__cond(uint64 instruction)
1720 {
1721 uint64 rt = extract_rt_25_24_23_22_21(instruction);
1722 return rt != 0;
1723 }
1724
1725
1726 bool NMD::ADDIU_RS5__cond(uint64 instruction)
1727 {
1728 uint64 rt = extract_rt_9_8_7_6_5(instruction);
1729 return rt != 0;
1730 }
1731
1732
1733 bool NMD::BALRSC_cond(uint64 instruction)
1734 {
1735 uint64 rt = extract_rt_25_24_23_22_21(instruction);
1736 return rt != 0;
1737 }
1738
1739
1740 bool NMD::BEQC_16__cond(uint64 instruction)
1741 {
1742 uint64 rs3 = extract_rs3_6_5_4(instruction);
1743 uint64 rt3 = extract_rt3_9_8_7(instruction);
1744 uint64 u = extract_u_3_2_1_0__s1(instruction);
1745 return rs3 < rt3 && u != 0;
1746 }
1747
1748
1749 bool NMD::BNEC_16__cond(uint64 instruction)
1750 {
1751 uint64 rs3 = extract_rs3_6_5_4(instruction);
1752 uint64 rt3 = extract_rt3_9_8_7(instruction);
1753 uint64 u = extract_u_3_2_1_0__s1(instruction);
1754 return rs3 >= rt3 && u != 0;
1755 }
1756
1757
1758 bool NMD::MOVE_cond(uint64 instruction)
1759 {
1760 uint64 rt = extract_rt_9_8_7_6_5(instruction);
1761 return rt != 0;
1762 }
1763
1764
1765 bool NMD::P16_BR1_cond(uint64 instruction)
1766 {
1767 uint64 u = extract_u_3_2_1_0__s1(instruction);
1768 return u != 0;
1769 }
1770
1771
1772 bool NMD::PREF_S9__cond(uint64 instruction)
1773 {
1774 uint64 hint = extract_hint_25_24_23_22_21(instruction);
1775 return hint != 31;
1776 }
1777
1778
1779 bool NMD::PREFE_cond(uint64 instruction)
1780 {
1781 uint64 hint = extract_hint_25_24_23_22_21(instruction);
1782 return hint != 31;
1783 }
1784
1785
1786 bool NMD::SLTU_cond(uint64 instruction)
1787 {
1788 uint64 rd = extract_rd_15_14_13_12_11(instruction);
1789 return rd != 0;
1790 }
1791
1792
1793
1794 /*
1795 * ABS.D fd, fs - Floating Point Absolute Value
1796 *
1797 * 3 2 1
1798 * 10987654321098765432109876543210
1799 * 010001 00000 000101
1800 * fmt -----
1801 * fs -----
1802 * fd -----
1803 */
1804 std::string NMD::ABS_D(uint64 instruction)
1805 {
1806 uint64 fd_value = extract_ft_25_24_23_22_21(instruction);
1807 uint64 fs_value = extract_fs_20_19_18_17_16(instruction);
1808
1809 std::string fs = FPR(copy(fs_value));
1810 std::string fd = FPR(copy(fd_value));
1811
1812 return img::format("ABS.D %s, %s", fd, fs);
1813 }
1814
1815
1816 /*
1817 * ABS.S fd, fs - Floating Point Absolute Value
1818 *
1819 * 3 2 1
1820 * 10987654321098765432109876543210
1821 * 010001 00000 000101
1822 * fmt -----
1823 * fd -----
1824 * fs -----
1825 */
1826 std::string NMD::ABS_S(uint64 instruction)
1827 {
1828 uint64 fd_value = extract_ft_25_24_23_22_21(instruction);
1829 uint64 fs_value = extract_fs_20_19_18_17_16(instruction);
1830
1831 std::string fs = FPR(copy(fs_value));
1832 std::string fd = FPR(copy(fd_value));
1833
1834 return img::format("ABS.S %s, %s", fd, fs);
1835 }
1836
1837
1838 /*
1839 * [DSP] ABSQ_S.PH rt, rs - Find absolute value of two fractional halfwords
1840 * with 16-bit saturation
1841 *
1842 * 3 2 1
1843 * 10987654321098765432109876543210
1844 * 001000 0001000100111111
1845 * rt -----
1846 * rs -----
1847 */
1848 std::string NMD::ABSQ_S_PH(uint64 instruction)
1849 {
1850 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
1851 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
1852
1853 std::string rt = GPR(copy(rt_value));
1854 std::string rs = GPR(copy(rs_value));
1855
1856 return img::format("ABSQ_S.PH %s, %s", rt, rs);
1857 }
1858
1859
1860 /*
1861 * [DSP] ABSQ_S.QB rt, rs - Find absolute value of four fractional byte values
1862 * with 8-bit saturation
1863 *
1864 * 3 2 1
1865 * 10987654321098765432109876543210
1866 * 001000 0000000100111111
1867 * rt -----
1868 * rs -----
1869 */
1870 std::string NMD::ABSQ_S_QB(uint64 instruction)
1871 {
1872 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
1873 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
1874
1875 std::string rt = GPR(copy(rt_value));
1876 std::string rs = GPR(copy(rs_value));
1877
1878 return img::format("ABSQ_S.QB %s, %s", rt, rs);
1879 }
1880
1881
1882 /*
1883 * [DSP] ABSQ_S.W rt, rs - Find absolute value of fractional word with 32-bit
1884 * saturation
1885 *
1886 * 3 2 1
1887 * 10987654321098765432109876543210
1888 * 001000 0010000100111111
1889 * rt -----
1890 * rs -----
1891 */
1892 std::string NMD::ABSQ_S_W(uint64 instruction)
1893 {
1894 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
1895 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
1896
1897 std::string rt = GPR(copy(rt_value));
1898 std::string rs = GPR(copy(rs_value));
1899
1900 return img::format("ABSQ_S.W %s, %s", rt, rs);
1901 }
1902
1903
1904 /*
1905 *
1906 *
1907 * 3 2 1
1908 * 10987654321098765432109876543210
1909 * 001000 0010000100111111
1910 * rt -----
1911 * rs -----
1912 */
1913 std::string NMD::ACLR(uint64 instruction)
1914 {
1915 uint64 bit_value = extract_bit_23_22_21(instruction);
1916 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
1917 int64 s_value = extract_s__se8_15_7_6_5_4_3_2_1_0(instruction);
1918
1919 std::string bit = IMMEDIATE(copy(bit_value));
1920 std::string s = IMMEDIATE(copy(s_value));
1921 std::string rs = GPR(copy(rs_value));
1922
1923 return img::format("ACLR %s, %s(%s)", bit, s, rs);
1924 }
1925
1926
1927 /*
1928 *
1929 *
1930 * 3 2 1
1931 * 10987654321098765432109876543210
1932 * 001000 0010000100111111
1933 * rt -----
1934 * rs -----
1935 */
1936 std::string NMD::ADD(uint64 instruction)
1937 {
1938 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
1939 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
1940 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
1941
1942 std::string rd = GPR(copy(rd_value));
1943 std::string rs = GPR(copy(rs_value));
1944 std::string rt = GPR(copy(rt_value));
1945
1946 return img::format("ADD %s, %s, %s", rd, rs, rt);
1947 }
1948
1949
1950 /*
1951 * ADD.D fd, fs, ft - Floating Point Add
1952 *
1953 * 3 2 1
1954 * 10987654321098765432109876543210
1955 * 010001 000101
1956 * fmt -----
1957 * ft -----
1958 * fs -----
1959 * fd -----
1960 */
1961 std::string NMD::ADD_D(uint64 instruction)
1962 {
1963 uint64 ft_value = extract_ft_25_24_23_22_21(instruction);
1964 uint64 fs_value = extract_fs_20_19_18_17_16(instruction);
1965 uint64 fd_value = extract_fd_15_14_13_12_11(instruction);
1966
1967 std::string ft = FPR(copy(ft_value));
1968 std::string fs = FPR(copy(fs_value));
1969 std::string fd = FPR(copy(fd_value));
1970
1971 return img::format("ADD.D %s, %s, %s", fd, fs, ft);
1972 }
1973
1974
1975 /*
1976 * ADD.S fd, fs, ft - Floating Point Add
1977 *
1978 * 3 2 1
1979 * 10987654321098765432109876543210
1980 * 010001 000101
1981 * fmt -----
1982 * ft -----
1983 * fs -----
1984 * fd -----
1985 */
1986 std::string NMD::ADD_S(uint64 instruction)
1987 {
1988 uint64 ft_value = extract_ft_25_24_23_22_21(instruction);
1989 uint64 fs_value = extract_fs_20_19_18_17_16(instruction);
1990 uint64 fd_value = extract_fd_15_14_13_12_11(instruction);
1991
1992 std::string ft = FPR(copy(ft_value));
1993 std::string fs = FPR(copy(fs_value));
1994 std::string fd = FPR(copy(fd_value));
1995
1996 return img::format("ADD.S %s, %s, %s", fd, fs, ft);
1997 }
1998
1999
2000 /*
2001 *
2002 *
2003 * 3 2 1
2004 * 10987654321098765432109876543210
2005 * 001000 0010000100111111
2006 * rt -----
2007 * rs -----
2008 */
2009 std::string NMD::ADDIU_32_(uint64 instruction)
2010 {
2011 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2012 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2013 uint64 u_value = extract_u_15_to_0(instruction);
2014
2015 std::string rt = GPR(copy(rt_value));
2016 std::string rs = GPR(copy(rs_value));
2017 std::string u = IMMEDIATE(copy(u_value));
2018
2019 return img::format("ADDIU %s, %s, %s", rt, rs, u);
2020 }
2021
2022
2023 /*
2024 *
2025 *
2026 * 3 2 1
2027 * 10987654321098765432109876543210
2028 * 001000 0010000100111111
2029 * rt -----
2030 * rs -----
2031 */
2032 std::string NMD::ADDIU_48_(uint64 instruction)
2033 {
2034 uint64 rt_value = extract_rt_41_40_39_38_37(instruction);
2035 int64 s_value = extract_s__se31_15_to_0_31_to_16(instruction);
2036
2037 std::string rt = GPR(copy(rt_value));
2038 std::string s = IMMEDIATE(copy(s_value));
2039
2040 return img::format("ADDIU %s, %s", rt, s);
2041 }
2042
2043
2044 /*
2045 *
2046 *
2047 * 3 2 1
2048 * 10987654321098765432109876543210
2049 * 001000 0010000100111111
2050 * rt -----
2051 * rs -----
2052 */
2053 std::string NMD::ADDIU_GP48_(uint64 instruction)
2054 {
2055 uint64 rt_value = extract_rt_41_40_39_38_37(instruction);
2056 int64 s_value = extract_s__se31_15_to_0_31_to_16(instruction);
2057
2058 std::string rt = GPR(copy(rt_value));
2059 std::string s = IMMEDIATE(copy(s_value));
2060
2061 return img::format("ADDIU %s, $%d, %s", rt, 28, s);
2062 }
2063
2064
2065 /*
2066 *
2067 *
2068 * 3 2 1
2069 * 10987654321098765432109876543210
2070 * 001000 0010000100111111
2071 * rt -----
2072 * rs -----
2073 */
2074 std::string NMD::ADDIU_GP_B_(uint64 instruction)
2075 {
2076 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2077 uint64 u_value = extract_u_17_to_0(instruction);
2078
2079 std::string rt = GPR(copy(rt_value));
2080 std::string u = IMMEDIATE(copy(u_value));
2081
2082 return img::format("ADDIU %s, $%d, %s", rt, 28, u);
2083 }
2084
2085
2086 /*
2087 *
2088 *
2089 * 3 2 1
2090 * 10987654321098765432109876543210
2091 * 001000 0010000100111111
2092 * rt -----
2093 * rs -----
2094 */
2095 std::string NMD::ADDIU_GP_W_(uint64 instruction)
2096 {
2097 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2098 uint64 u_value = extract_u_20_to_2__s2(instruction);
2099
2100 std::string rt = GPR(copy(rt_value));
2101 std::string u = IMMEDIATE(copy(u_value));
2102
2103 return img::format("ADDIU %s, $%d, %s", rt, 28, u);
2104 }
2105
2106
2107 /*
2108 *
2109 *
2110 * 3 2 1
2111 * 10987654321098765432109876543210
2112 * 001000 0010000100111111
2113 * rt -----
2114 * rs -----
2115 */
2116 std::string NMD::ADDIU_NEG_(uint64 instruction)
2117 {
2118 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2119 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2120 uint64 u_value = extract_u_11_10_9_8_7_6_5_4_3_2_1_0(instruction);
2121
2122 std::string rt = GPR(copy(rt_value));
2123 std::string rs = GPR(copy(rs_value));
2124 std::string u = IMMEDIATE(neg_copy(u_value));
2125
2126 return img::format("ADDIU %s, %s, %s", rt, rs, u);
2127 }
2128
2129
2130 /*
2131 *
2132 *
2133 * 3 2 1
2134 * 10987654321098765432109876543210
2135 * 001000 0010000100111111
2136 * rt -----
2137 * rs -----
2138 */
2139 std::string NMD::ADDIU_R1_SP_(uint64 instruction)
2140 {
2141 uint64 u_value = extract_u_5_4_3_2_1_0__s2(instruction);
2142 uint64 rt3_value = extract_rt3_9_8_7(instruction);
2143
2144 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
2145 std::string u = IMMEDIATE(copy(u_value));
2146
2147 return img::format("ADDIU %s, $%d, %s", rt3, 29, u);
2148 }
2149
2150
2151 /*
2152 *
2153 *
2154 * 3 2 1
2155 * 10987654321098765432109876543210
2156 * 001000 0010000100111111
2157 * rt -----
2158 * rs -----
2159 */
2160 std::string NMD::ADDIU_R2_(uint64 instruction)
2161 {
2162 uint64 rt3_value = extract_rt3_9_8_7(instruction);
2163 uint64 rs3_value = extract_rs3_6_5_4(instruction);
2164 uint64 u_value = extract_u_2_1_0__s2(instruction);
2165
2166 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
2167 std::string rs3 = GPR(decode_gpr_gpr3(rs3_value));
2168 std::string u = IMMEDIATE(copy(u_value));
2169
2170 return img::format("ADDIU %s, %s, %s", rt3, rs3, u);
2171 }
2172
2173
2174 /*
2175 * ADDIU[RS5] rt, s5 - Add Signed Word and Set Carry Bit
2176 *
2177 * 5432109876543210
2178 * 100100 1
2179 * rt -----
2180 * s - ---
2181 */
2182 std::string NMD::ADDIU_RS5_(uint64 instruction)
2183 {
2184 uint64 rt_value = extract_rt_9_8_7_6_5(instruction);
2185 int64 s_value = extract_s__se3_4_2_1_0(instruction);
2186
2187 std::string rt = GPR(copy(rt_value));
2188 std::string s = IMMEDIATE(copy(s_value));
2189
2190 return img::format("ADDIU %s, %s", rt, s);
2191 }
2192
2193
2194 /*
2195 *
2196 *
2197 * 3 2 1
2198 * 10987654321098765432109876543210
2199 * 001000 x1110000101
2200 * rt -----
2201 * rs -----
2202 * rd -----
2203 */
2204 std::string NMD::ADDIUPC_32_(uint64 instruction)
2205 {
2206 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2207 int64 s_value = extract_s__se21_0_20_to_1_s1(instruction);
2208
2209 std::string rt = GPR(copy(rt_value));
2210 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
2211
2212 return img::format("ADDIUPC %s, %s", rt, s);
2213 }
2214
2215
2216 /*
2217 *
2218 *
2219 * 3 2 1
2220 * 10987654321098765432109876543210
2221 * 001000 x1110000101
2222 * rt -----
2223 * rs -----
2224 * rd -----
2225 */
2226 std::string NMD::ADDIUPC_48_(uint64 instruction)
2227 {
2228 uint64 rt_value = extract_rt_41_40_39_38_37(instruction);
2229 int64 s_value = extract_s__se31_15_to_0_31_to_16(instruction);
2230
2231 std::string rt = GPR(copy(rt_value));
2232 std::string s = ADDRESS(encode_s_from_address(s_value), 6);
2233
2234 return img::format("ADDIUPC %s, %s", rt, s);
2235 }
2236
2237
2238 /*
2239 * [DSP] ADDQ.PH rd, rt, rs - Add fractional halfword vectors
2240 *
2241 * 3 2 1
2242 * 10987654321098765432109876543210
2243 * 001000 00000001101
2244 * rt -----
2245 * rs -----
2246 * rd -----
2247 */
2248 std::string NMD::ADDQ_PH(uint64 instruction)
2249 {
2250 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2251 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2252 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2253
2254 std::string rd = GPR(copy(rd_value));
2255 std::string rs = GPR(copy(rs_value));
2256 std::string rt = GPR(copy(rt_value));
2257
2258 return img::format("ADDQ.PH %s, %s, %s", rd, rs, rt);
2259 }
2260
2261
2262 /*
2263 * [DSP] ADDQ_S.PH rd, rt, rs - Add fractional halfword vectors with 16-bit
2264 * saturation
2265 *
2266 * 3 2 1
2267 * 10987654321098765432109876543210
2268 * 001000 10000001101
2269 * rt -----
2270 * rs -----
2271 * rd -----
2272 */
2273 std::string NMD::ADDQ_S_PH(uint64 instruction)
2274 {
2275 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2276 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2277 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2278
2279 std::string rd = GPR(copy(rd_value));
2280 std::string rs = GPR(copy(rs_value));
2281 std::string rt = GPR(copy(rt_value));
2282
2283 return img::format("ADDQ_S.PH %s, %s, %s", rd, rs, rt);
2284 }
2285
2286
2287 /*
2288 * [DSP] ADDQ_S.W rd, rt, rs - Add fractional words with 32-bit saturation
2289 *
2290 * 3 2 1
2291 * 10987654321098765432109876543210
2292 * 001000 x1100000101
2293 * rt -----
2294 * rs -----
2295 * rd -----
2296 */
2297 std::string NMD::ADDQ_S_W(uint64 instruction)
2298 {
2299 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2300 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2301 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2302
2303 std::string rd = GPR(copy(rd_value));
2304 std::string rs = GPR(copy(rs_value));
2305 std::string rt = GPR(copy(rt_value));
2306
2307 return img::format("ADDQ_S.W %s, %s, %s", rd, rs, rt);
2308 }
2309
2310
2311 /*
2312 * [DSP] ADDQH.PH rd, rt, rs - Add fractional halfword vectors and shift
2313 * right to halve results
2314 *
2315 * 3 2 1
2316 * 10987654321098765432109876543210
2317 * 001000 00001001101
2318 * rt -----
2319 * rs -----
2320 * rd -----
2321 */
2322 std::string NMD::ADDQH_PH(uint64 instruction)
2323 {
2324 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2325 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2326 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2327
2328 std::string rd = GPR(copy(rd_value));
2329 std::string rs = GPR(copy(rs_value));
2330 std::string rt = GPR(copy(rt_value));
2331
2332 return img::format("ADDQH.PH %s, %s, %s", rd, rs, rt);
2333 }
2334
2335
2336 /*
2337 * [DSP] ADDQH_R.PH rd, rt, rs - Add fractional halfword vectors and shift
2338 * right to halve results with rounding
2339 *
2340 * 3 2 1
2341 * 10987654321098765432109876543210
2342 * 001000 10001001101
2343 * rt -----
2344 * rs -----
2345 * rd -----
2346 */
2347 std::string NMD::ADDQH_R_PH(uint64 instruction)
2348 {
2349 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2350 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2351 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2352
2353 std::string rd = GPR(copy(rd_value));
2354 std::string rs = GPR(copy(rs_value));
2355 std::string rt = GPR(copy(rt_value));
2356
2357 return img::format("ADDQH_R.PH %s, %s, %s", rd, rs, rt);
2358 }
2359
2360
2361 /*
2362 * [DSP] ADDQH_R.W rd, rt, rs - Add fractional words and shift right to halve
2363 * results with rounding
2364 *
2365 * 3 2 1
2366 * 10987654321098765432109876543210
2367 * 001000 00010001101
2368 * rt -----
2369 * rs -----
2370 * rd -----
2371 */
2372 std::string NMD::ADDQH_R_W(uint64 instruction)
2373 {
2374 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2375 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2376 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2377
2378 std::string rd = GPR(copy(rd_value));
2379 std::string rs = GPR(copy(rs_value));
2380 std::string rt = GPR(copy(rt_value));
2381
2382 return img::format("ADDQH_R.W %s, %s, %s", rd, rs, rt);
2383 }
2384
2385
2386 /*
2387 * [DSP] ADDQH.W rd, rt, rs - Add fractional words and shift right to halve
2388 * results
2389 *
2390 * 3 2 1
2391 * 10987654321098765432109876543210
2392 * 001000 10010001101
2393 * rt -----
2394 * rs -----
2395 * rd -----
2396 */
2397 std::string NMD::ADDQH_W(uint64 instruction)
2398 {
2399 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2400 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2401 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2402
2403 std::string rd = GPR(copy(rd_value));
2404 std::string rs = GPR(copy(rs_value));
2405 std::string rt = GPR(copy(rt_value));
2406
2407 return img::format("ADDQH.W %s, %s, %s", rd, rs, rt);
2408 }
2409
2410
2411 /*
2412 * [DSP] ADDSC rd, rt, rs - Add two signed words and set carry bit
2413 *
2414 * 3 2 1
2415 * 10987654321098765432109876543210
2416 * 001000 x1110000101
2417 * rt -----
2418 * rs -----
2419 * rd -----
2420 */
2421 std::string NMD::ADDSC(uint64 instruction)
2422 {
2423 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2424 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2425 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2426
2427 std::string rd = GPR(copy(rd_value));
2428 std::string rs = GPR(copy(rs_value));
2429 std::string rt = GPR(copy(rt_value));
2430
2431 return img::format("ADDSC %s, %s, %s", rd, rs, rt);
2432 }
2433
2434
2435 /*
2436 * ADDU[16] rd3, rs3, rt3 -
2437 *
2438 * 5432109876543210
2439 * 101100 0
2440 * rt3 ---
2441 * rs3 ---
2442 * rd3 ---
2443 */
2444 std::string NMD::ADDU_16_(uint64 instruction)
2445 {
2446 uint64 rt3_value = extract_rt3_9_8_7(instruction);
2447 uint64 rs3_value = extract_rs3_6_5_4(instruction);
2448 uint64 rd3_value = extract_rd3_3_2_1(instruction);
2449
2450 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
2451 std::string rs3 = GPR(decode_gpr_gpr3(rs3_value));
2452 std::string rd3 = GPR(decode_gpr_gpr3(rd3_value));
2453
2454 return img::format("ADDU %s, %s, %s", rd3, rs3, rt3);
2455 }
2456
2457
2458 /*
2459 *
2460 *
2461 * 3 2 1
2462 * 10987654321098765432109876543210
2463 * 001000 x1110000101
2464 * rt -----
2465 * rs -----
2466 * rd -----
2467 */
2468 std::string NMD::ADDU_32_(uint64 instruction)
2469 {
2470 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2471 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2472 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2473
2474 std::string rd = GPR(copy(rd_value));
2475 std::string rs = GPR(copy(rs_value));
2476 std::string rt = GPR(copy(rt_value));
2477
2478 return img::format("ADDU %s, %s, %s", rd, rs, rt);
2479 }
2480
2481
2482 /*
2483 *
2484 *
2485 * 3 2 1
2486 * 10987654321098765432109876543210
2487 * 001000 x1110000101
2488 * rt -----
2489 * rs -----
2490 * rd -----
2491 */
2492 std::string NMD::ADDU_4X4_(uint64 instruction)
2493 {
2494 uint64 rt4_value = extract_rt4_9_7_6_5(instruction);
2495 uint64 rs4_value = extract_rs4_4_2_1_0(instruction);
2496
2497 std::string rs4 = GPR(decode_gpr_gpr4(rs4_value));
2498 std::string rt4 = GPR(decode_gpr_gpr4(rt4_value));
2499
2500 return img::format("ADDU %s, %s", rs4, rt4);
2501 }
2502
2503
2504 /*
2505 * [DSP] ADDU.PH rd, rt, rs - Add two pairs of unsigned halfwords
2506 *
2507 * 3 2 1
2508 * 10987654321098765432109876543210
2509 * 001000 00100001101
2510 * rt -----
2511 * rs -----
2512 * rd -----
2513 */
2514 std::string NMD::ADDU_PH(uint64 instruction)
2515 {
2516 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2517 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2518 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2519
2520 std::string rd = GPR(copy(rd_value));
2521 std::string rs = GPR(copy(rs_value));
2522 std::string rt = GPR(copy(rt_value));
2523
2524 return img::format("ADDU.PH %s, %s, %s", rd, rs, rt);
2525 }
2526
2527
2528 /*
2529 * ADDU.QB rd, rt, rs - Unsigned Add Quad Byte Vectors
2530 *
2531 * 3 2 1
2532 * 10987654321098765432109876543210
2533 * 001000 00011001101
2534 * rt -----
2535 * rs -----
2536 * rd -----
2537 */
2538 std::string NMD::ADDU_QB(uint64 instruction)
2539 {
2540 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2541 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2542 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2543
2544 std::string rd = GPR(copy(rd_value));
2545 std::string rs = GPR(copy(rs_value));
2546 std::string rt = GPR(copy(rt_value));
2547
2548 return img::format("ADDU.QB %s, %s, %s", rd, rs, rt);
2549 }
2550
2551
2552 /*
2553 * [DSP] ADDU_S.PH rd, rt, rs - Add two pairs of unsigned halfwords with 16-bit
2554 * saturation
2555 *
2556 * 3 2 1
2557 * 10987654321098765432109876543210
2558 * 001000 10100001101
2559 * rt -----
2560 * rs -----
2561 * rd -----
2562 */
2563 std::string NMD::ADDU_S_PH(uint64 instruction)
2564 {
2565 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2566 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2567 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2568
2569 std::string rd = GPR(copy(rd_value));
2570 std::string rs = GPR(copy(rs_value));
2571 std::string rt = GPR(copy(rt_value));
2572
2573 return img::format("ADDU_S.PH %s, %s, %s", rd, rs, rt);
2574 }
2575
2576
2577 /*
2578 * ADDU_S.QB rd, rt, rs - Unsigned Add Quad Byte Vectors
2579 *
2580 * 3 2 1
2581 * 10987654321098765432109876543210
2582 * 001000 10011001101
2583 * rt -----
2584 * rs -----
2585 * rd -----
2586 */
2587 std::string NMD::ADDU_S_QB(uint64 instruction)
2588 {
2589 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2590 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2591 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2592
2593 std::string rd = GPR(copy(rd_value));
2594 std::string rs = GPR(copy(rs_value));
2595 std::string rt = GPR(copy(rt_value));
2596
2597 return img::format("ADDU_S.QB %s, %s, %s", rd, rs, rt);
2598 }
2599
2600
2601 /*
2602 * ADDUH.QB rd, rt, rs - Unsigned Add Vector Quad-Bytes And Right Shift
2603 * to Halve Results
2604 *
2605 * 3 2 1
2606 * 10987654321098765432109876543210
2607 * 001000 00101001101
2608 * rt -----
2609 * rs -----
2610 * rd -----
2611 */
2612 std::string NMD::ADDUH_QB(uint64 instruction)
2613 {
2614 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2615 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2616 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2617
2618 std::string rd = GPR(copy(rd_value));
2619 std::string rs = GPR(copy(rs_value));
2620 std::string rt = GPR(copy(rt_value));
2621
2622 return img::format("ADDUH.QB %s, %s, %s", rd, rs, rt);
2623 }
2624
2625
2626 /*
2627 * ADDUH_R.QB rd, rt, rs - Unsigned Add Vector Quad-Bytes And Right Shift
2628 * to Halve Results
2629 *
2630 * 3 2 1
2631 * 10987654321098765432109876543210
2632 * 001000 10101001101
2633 * rt -----
2634 * rs -----
2635 * rd -----
2636 */
2637 std::string NMD::ADDUH_R_QB(uint64 instruction)
2638 {
2639 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2640 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2641 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2642
2643 std::string rd = GPR(copy(rd_value));
2644 std::string rs = GPR(copy(rs_value));
2645 std::string rt = GPR(copy(rt_value));
2646
2647 return img::format("ADDUH_R.QB %s, %s, %s", rd, rs, rt);
2648 }
2649
2650 /*
2651 * ADDWC rd, rt, rs - Add Word with Carry Bit
2652 *
2653 * 3 2 1
2654 * 10987654321098765432109876543210
2655 * 001000 x1111000101
2656 * rt -----
2657 * rs -----
2658 * rd -----
2659 */
2660 std::string NMD::ADDWC(uint64 instruction)
2661 {
2662 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2663 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2664 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2665
2666 std::string rd = GPR(copy(rd_value));
2667 std::string rs = GPR(copy(rs_value));
2668 std::string rt = GPR(copy(rt_value));
2669
2670 return img::format("ADDWC %s, %s, %s", rd, rs, rt);
2671 }
2672
2673
2674 /*
2675 *
2676 *
2677 * 3 2 1
2678 * 10987654321098765432109876543210
2679 * 001000 x1110000101
2680 * rt -----
2681 * rs -----
2682 * rd -----
2683 */
2684 std::string NMD::ALUIPC(uint64 instruction)
2685 {
2686 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2687 int64 s_value = extract_s__se31_0_11_to_2_20_to_12_s12(instruction);
2688
2689 std::string rt = GPR(copy(rt_value));
2690 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
2691
2692 return img::format("ALUIPC %s, %%pcrel_hi(%s)", rt, s);
2693 }
2694
2695
2696 /*
2697 * AND[16] rt3, rs3 -
2698 *
2699 * 5432109876543210
2700 * 101100
2701 * rt3 ---
2702 * rs3 ---
2703 * eu ----
2704 */
2705 std::string NMD::AND_16_(uint64 instruction)
2706 {
2707 uint64 rt3_value = extract_rt3_9_8_7(instruction);
2708 uint64 rs3_value = extract_rs3_6_5_4(instruction);
2709
2710 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
2711 std::string rs3 = GPR(decode_gpr_gpr3(rs3_value));
2712
2713 return img::format("AND %s, %s", rs3, rt3);
2714 }
2715
2716
2717 /*
2718 *
2719 *
2720 * 3 2 1
2721 * 10987654321098765432109876543210
2722 * 001000 x1110000101
2723 * rt -----
2724 * rs -----
2725 * rd -----
2726 */
2727 std::string NMD::AND_32_(uint64 instruction)
2728 {
2729 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2730 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2731 uint64 rd_value = extract_rd_15_14_13_12_11(instruction);
2732
2733 std::string rd = GPR(copy(rd_value));
2734 std::string rs = GPR(copy(rs_value));
2735 std::string rt = GPR(copy(rt_value));
2736
2737 return img::format("AND %s, %s, %s", rd, rs, rt);
2738 }
2739
2740
2741 /*
2742 * ANDI rt, rs, u -
2743 *
2744 * 5432109876543210
2745 * 101100
2746 * rt3 ---
2747 * rs3 ---
2748 * eu ----
2749 */
2750 std::string NMD::ANDI_16_(uint64 instruction)
2751 {
2752 uint64 rt3_value = extract_rt3_9_8_7(instruction);
2753 uint64 rs3_value = extract_rs3_6_5_4(instruction);
2754 uint64 eu_value = extract_eu_3_2_1_0(instruction);
2755
2756 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
2757 std::string rs3 = GPR(decode_gpr_gpr3(rs3_value));
2758 std::string eu = IMMEDIATE(encode_eu_from_u_andi16(eu_value));
2759
2760 return img::format("ANDI %s, %s, %s", rt3, rs3, eu);
2761 }
2762
2763
2764 /*
2765 *
2766 *
2767 * 3 2 1
2768 * 10987654321098765432109876543210
2769 * 001000 x1110000101
2770 * rt -----
2771 * rs -----
2772 * rd -----
2773 */
2774 std::string NMD::ANDI_32_(uint64 instruction)
2775 {
2776 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2777 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2778 uint64 u_value = extract_u_11_10_9_8_7_6_5_4_3_2_1_0(instruction);
2779
2780 std::string rt = GPR(copy(rt_value));
2781 std::string rs = GPR(copy(rs_value));
2782 std::string u = IMMEDIATE(copy(u_value));
2783
2784 return img::format("ANDI %s, %s, %s", rt, rs, u);
2785 }
2786
2787
2788 /*
2789 *
2790 *
2791 * 3 2 1
2792 * 10987654321098765432109876543210
2793 * 001000 x1110000101
2794 * rt -----
2795 * rs -----
2796 * rd -----
2797 */
2798 std::string NMD::APPEND(uint64 instruction)
2799 {
2800 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2801 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2802 uint64 sa_value = extract_sa_15_14_13_12_11(instruction);
2803
2804 std::string rt = GPR(copy(rt_value));
2805 std::string rs = GPR(copy(rs_value));
2806 std::string sa = IMMEDIATE(copy(sa_value));
2807
2808 return img::format("APPEND %s, %s, %s", rt, rs, sa);
2809 }
2810
2811
2812 /*
2813 *
2814 *
2815 * 3 2 1
2816 * 10987654321098765432109876543210
2817 * 001000 x1110000101
2818 * rt -----
2819 * rs -----
2820 * rd -----
2821 */
2822 std::string NMD::ASET(uint64 instruction)
2823 {
2824 uint64 bit_value = extract_bit_23_22_21(instruction);
2825 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2826 int64 s_value = extract_s__se8_15_7_6_5_4_3_2_1_0(instruction);
2827
2828 std::string bit = IMMEDIATE(copy(bit_value));
2829 std::string s = IMMEDIATE(copy(s_value));
2830 std::string rs = GPR(copy(rs_value));
2831
2832 return img::format("ASET %s, %s(%s)", bit, s, rs);
2833 }
2834
2835
2836 /*
2837 *
2838 *
2839 * 3 2 1
2840 * 10987654321098765432109876543210
2841 * 001000 x1110000101
2842 * rt -----
2843 * rs -----
2844 * rd -----
2845 */
2846 std::string NMD::BALC_16_(uint64 instruction)
2847 {
2848 int64 s_value = extract_s__se10_0_9_8_7_6_5_4_3_2_1_s1(instruction);
2849
2850 std::string s = ADDRESS(encode_s_from_address(s_value), 2);
2851
2852 return img::format("BALC %s", s);
2853 }
2854
2855
2856 /*
2857 *
2858 *
2859 * 3 2 1
2860 * 10987654321098765432109876543210
2861 * 001000 x1110000101
2862 * rt -----
2863 * rs -----
2864 * rd -----
2865 */
2866 std::string NMD::BALC_32_(uint64 instruction)
2867 {
2868 int64 s_value = extract_s__se25_0_24_to_1_s1(instruction);
2869
2870 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
2871
2872 return img::format("BALC %s", s);
2873 }
2874
2875
2876 /*
2877 *
2878 *
2879 * 3 2 1
2880 * 10987654321098765432109876543210
2881 * 001000 x1110000101
2882 * rt -----
2883 * rs -----
2884 * rd -----
2885 */
2886 std::string NMD::BALRSC(uint64 instruction)
2887 {
2888 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2889 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
2890
2891 std::string rt = GPR(copy(rt_value));
2892 std::string rs = GPR(copy(rs_value));
2893
2894 return img::format("BALRSC %s, %s", rt, rs);
2895 }
2896
2897
2898 /*
2899 *
2900 *
2901 * 3 2 1
2902 * 10987654321098765432109876543210
2903 * 001000 x1110000101
2904 * rt -----
2905 * rs -----
2906 * rd -----
2907 */
2908 std::string NMD::BBEQZC(uint64 instruction)
2909 {
2910 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2911 uint64 bit_value = extract_bit_16_15_14_13_12_11(instruction);
2912 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
2913
2914 std::string rt = GPR(copy(rt_value));
2915 std::string bit = IMMEDIATE(copy(bit_value));
2916 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
2917
2918 return img::format("BBEQZC %s, %s, %s", rt, bit, s);
2919 }
2920
2921
2922 /*
2923 *
2924 *
2925 * 3 2 1
2926 * 10987654321098765432109876543210
2927 * 001000 x1110000101
2928 * rt -----
2929 * rs -----
2930 * rd -----
2931 */
2932 std::string NMD::BBNEZC(uint64 instruction)
2933 {
2934 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
2935 uint64 bit_value = extract_bit_16_15_14_13_12_11(instruction);
2936 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
2937
2938 std::string rt = GPR(copy(rt_value));
2939 std::string bit = IMMEDIATE(copy(bit_value));
2940 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
2941
2942 return img::format("BBNEZC %s, %s, %s", rt, bit, s);
2943 }
2944
2945
2946 /*
2947 *
2948 *
2949 * 3 2 1
2950 * 10987654321098765432109876543210
2951 * 001000 x1110000101
2952 * rt -----
2953 * rs -----
2954 * rd -----
2955 */
2956 std::string NMD::BC_16_(uint64 instruction)
2957 {
2958 int64 s_value = extract_s__se10_0_9_8_7_6_5_4_3_2_1_s1(instruction);
2959
2960 std::string s = ADDRESS(encode_s_from_address(s_value), 2);
2961
2962 return img::format("BC %s", s);
2963 }
2964
2965
2966 /*
2967 *
2968 *
2969 * 3 2 1
2970 * 10987654321098765432109876543210
2971 * 001000 x1110000101
2972 * rt -----
2973 * rs -----
2974 * rd -----
2975 */
2976 std::string NMD::BC_32_(uint64 instruction)
2977 {
2978 int64 s_value = extract_s__se25_0_24_to_1_s1(instruction);
2979
2980 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
2981
2982 return img::format("BC %s", s);
2983 }
2984
2985
2986 /*
2987 *
2988 *
2989 * 3 2 1
2990 * 10987654321098765432109876543210
2991 * 001000 x1110000101
2992 * rt -----
2993 * rs -----
2994 * rd -----
2995 */
2996 std::string NMD::BC1EQZC(uint64 instruction)
2997 {
2998 uint64 ft_value = extract_ft_25_24_23_22_21(instruction);
2999 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3000
3001 std::string ft = FPR(copy(ft_value));
3002 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3003
3004 return img::format("BC1EQZC %s, %s", ft, s);
3005 }
3006
3007
3008 /*
3009 *
3010 *
3011 * 3 2 1
3012 * 10987654321098765432109876543210
3013 * 001000 x1110000101
3014 * rt -----
3015 * rs -----
3016 * rd -----
3017 */
3018 std::string NMD::BC1NEZC(uint64 instruction)
3019 {
3020 uint64 ft_value = extract_ft_25_24_23_22_21(instruction);
3021 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3022
3023 std::string ft = FPR(copy(ft_value));
3024 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3025
3026 return img::format("BC1NEZC %s, %s", ft, s);
3027 }
3028
3029
3030 /*
3031 *
3032 *
3033 * 3 2 1
3034 * 10987654321098765432109876543210
3035 * 001000 x1110000101
3036 * rt -----
3037 * rs -----
3038 * rd -----
3039 */
3040 std::string NMD::BC2EQZC(uint64 instruction)
3041 {
3042 uint64 ct_value = extract_ct_25_24_23_22_21(instruction);
3043 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3044
3045 std::string ct = CPR(copy(ct_value));
3046 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3047
3048 return img::format("BC2EQZC %s, %s", ct, s);
3049 }
3050
3051
3052 /*
3053 *
3054 *
3055 * 3 2 1
3056 * 10987654321098765432109876543210
3057 * 001000 x1110000101
3058 * rt -----
3059 * rs -----
3060 * rd -----
3061 */
3062 std::string NMD::BC2NEZC(uint64 instruction)
3063 {
3064 uint64 ct_value = extract_ct_25_24_23_22_21(instruction);
3065 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3066
3067 std::string ct = CPR(copy(ct_value));
3068 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3069
3070 return img::format("BC2NEZC %s, %s", ct, s);
3071 }
3072
3073
3074 /*
3075 *
3076 *
3077 * 3 2 1
3078 * 10987654321098765432109876543210
3079 * 001000 x1110000101
3080 * rt -----
3081 * rs -----
3082 * rd -----
3083 */
3084 std::string NMD::BEQC_16_(uint64 instruction)
3085 {
3086 uint64 rt3_value = extract_rt3_9_8_7(instruction);
3087 uint64 rs3_value = extract_rs3_6_5_4(instruction);
3088 uint64 u_value = extract_u_3_2_1_0__s1(instruction);
3089
3090 std::string rs3 = GPR(encode_rs3_and_check_rs3_lt_rt3(rs3_value));
3091 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
3092 std::string u = ADDRESS(encode_u_from_address(u_value), 2);
3093
3094 return img::format("BEQC %s, %s, %s", rs3, rt3, u);
3095 }
3096
3097
3098 /*
3099 *
3100 *
3101 * 3 2 1
3102 * 10987654321098765432109876543210
3103 * 001000 x1110000101
3104 * rt -----
3105 * rs -----
3106 * rd -----
3107 */
3108 std::string NMD::BEQC_32_(uint64 instruction)
3109 {
3110 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3111 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
3112 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3113
3114 std::string rs = GPR(copy(rs_value));
3115 std::string rt = GPR(copy(rt_value));
3116 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3117
3118 return img::format("BEQC %s, %s, %s", rs, rt, s);
3119 }
3120
3121
3122 /*
3123 *
3124 *
3125 * 3 2 1
3126 * 10987654321098765432109876543210
3127 * 001000 x1110000101
3128 * rt -----
3129 * rs -----
3130 * rd -----
3131 */
3132 std::string NMD::BEQIC(uint64 instruction)
3133 {
3134 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3135 uint64 u_value = extract_u_17_16_15_14_13_12_11(instruction);
3136 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
3137
3138 std::string rt = GPR(copy(rt_value));
3139 std::string u = IMMEDIATE(copy(u_value));
3140 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3141
3142 return img::format("BEQIC %s, %s, %s", rt, u, s);
3143 }
3144
3145
3146 /*
3147 *
3148 *
3149 * 3 2 1
3150 * 10987654321098765432109876543210
3151 * 001000 x1110000101
3152 * rt -----
3153 * rs -----
3154 * rd -----
3155 */
3156 std::string NMD::BEQZC_16_(uint64 instruction)
3157 {
3158 uint64 rt3_value = extract_rt3_9_8_7(instruction);
3159 int64 s_value = extract_s__se7_0_6_5_4_3_2_1_s1(instruction);
3160
3161 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
3162 std::string s = ADDRESS(encode_s_from_address(s_value), 2);
3163
3164 return img::format("BEQZC %s, %s", rt3, s);
3165 }
3166
3167
3168 /*
3169 *
3170 *
3171 * 3 2 1
3172 * 10987654321098765432109876543210
3173 * 001000 x1110000101
3174 * rt -----
3175 * rs -----
3176 * rd -----
3177 */
3178 std::string NMD::BGEC(uint64 instruction)
3179 {
3180 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3181 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
3182 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3183
3184 std::string rs = GPR(copy(rs_value));
3185 std::string rt = GPR(copy(rt_value));
3186 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3187
3188 return img::format("BGEC %s, %s, %s", rs, rt, s);
3189 }
3190
3191
3192 /*
3193 *
3194 *
3195 * 3 2 1
3196 * 10987654321098765432109876543210
3197 * 001000 x1110000101
3198 * rt -----
3199 * rs -----
3200 * rd -----
3201 */
3202 std::string NMD::BGEIC(uint64 instruction)
3203 {
3204 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3205 uint64 u_value = extract_u_17_16_15_14_13_12_11(instruction);
3206 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
3207
3208 std::string rt = GPR(copy(rt_value));
3209 std::string u = IMMEDIATE(copy(u_value));
3210 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3211
3212 return img::format("BGEIC %s, %s, %s", rt, u, s);
3213 }
3214
3215
3216 /*
3217 *
3218 *
3219 * 3 2 1
3220 * 10987654321098765432109876543210
3221 * 001000 x1110000101
3222 * rt -----
3223 * rs -----
3224 * rd -----
3225 */
3226 std::string NMD::BGEIUC(uint64 instruction)
3227 {
3228 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3229 uint64 u_value = extract_u_17_16_15_14_13_12_11(instruction);
3230 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
3231
3232 std::string rt = GPR(copy(rt_value));
3233 std::string u = IMMEDIATE(copy(u_value));
3234 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3235
3236 return img::format("BGEIUC %s, %s, %s", rt, u, s);
3237 }
3238
3239
3240 /*
3241 *
3242 *
3243 * 3 2 1
3244 * 10987654321098765432109876543210
3245 * 001000 x1110000101
3246 * rt -----
3247 * rs -----
3248 * rd -----
3249 */
3250 std::string NMD::BGEUC(uint64 instruction)
3251 {
3252 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3253 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
3254 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3255
3256 std::string rs = GPR(copy(rs_value));
3257 std::string rt = GPR(copy(rt_value));
3258 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3259
3260 return img::format("BGEUC %s, %s, %s", rs, rt, s);
3261 }
3262
3263
3264 /*
3265 *
3266 *
3267 * 3 2 1
3268 * 10987654321098765432109876543210
3269 * 001000 x1110000101
3270 * rt -----
3271 * rs -----
3272 * rd -----
3273 */
3274 std::string NMD::BLTC(uint64 instruction)
3275 {
3276 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3277 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
3278 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3279
3280 std::string rs = GPR(copy(rs_value));
3281 std::string rt = GPR(copy(rt_value));
3282 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3283
3284 return img::format("BLTC %s, %s, %s", rs, rt, s);
3285 }
3286
3287
3288 /*
3289 *
3290 *
3291 * 3 2 1
3292 * 10987654321098765432109876543210
3293 * 001000 x1110000101
3294 * rt -----
3295 * rs -----
3296 * rd -----
3297 */
3298 std::string NMD::BLTIC(uint64 instruction)
3299 {
3300 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3301 uint64 u_value = extract_u_17_16_15_14_13_12_11(instruction);
3302 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
3303
3304 std::string rt = GPR(copy(rt_value));
3305 std::string u = IMMEDIATE(copy(u_value));
3306 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3307
3308 return img::format("BLTIC %s, %s, %s", rt, u, s);
3309 }
3310
3311
3312 /*
3313 *
3314 *
3315 * 3 2 1
3316 * 10987654321098765432109876543210
3317 * 001000 x1110000101
3318 * rt -----
3319 * rs -----
3320 * rd -----
3321 */
3322 std::string NMD::BLTIUC(uint64 instruction)
3323 {
3324 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3325 uint64 u_value = extract_u_17_16_15_14_13_12_11(instruction);
3326 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
3327
3328 std::string rt = GPR(copy(rt_value));
3329 std::string u = IMMEDIATE(copy(u_value));
3330 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3331
3332 return img::format("BLTIUC %s, %s, %s", rt, u, s);
3333 }
3334
3335
3336 /*
3337 *
3338 *
3339 * 3 2 1
3340 * 10987654321098765432109876543210
3341 * 001000 x1110000101
3342 * rt -----
3343 * rs -----
3344 * rd -----
3345 */
3346 std::string NMD::BLTUC(uint64 instruction)
3347 {
3348 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3349 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
3350 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3351
3352 std::string rs = GPR(copy(rs_value));
3353 std::string rt = GPR(copy(rt_value));
3354 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3355
3356 return img::format("BLTUC %s, %s, %s", rs, rt, s);
3357 }
3358
3359
3360 /*
3361 *
3362 *
3363 * 3 2 1
3364 * 10987654321098765432109876543210
3365 * 001000 x1110000101
3366 * rt -----
3367 * rs -----
3368 * rd -----
3369 */
3370 std::string NMD::BNEC_16_(uint64 instruction)
3371 {
3372 uint64 rt3_value = extract_rt3_9_8_7(instruction);
3373 uint64 rs3_value = extract_rs3_6_5_4(instruction);
3374 uint64 u_value = extract_u_3_2_1_0__s1(instruction);
3375
3376 std::string rs3 = GPR(encode_rs3_and_check_rs3_ge_rt3(rs3_value));
3377 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
3378 std::string u = ADDRESS(encode_u_from_address(u_value), 2);
3379
3380 return img::format("BNEC %s, %s, %s", rs3, rt3, u);
3381 }
3382
3383
3384 /*
3385 *
3386 *
3387 * 3 2 1
3388 * 10987654321098765432109876543210
3389 * 001000 x1110000101
3390 * rt -----
3391 * rs -----
3392 * rd -----
3393 */
3394 std::string NMD::BNEC_32_(uint64 instruction)
3395 {
3396 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3397 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
3398 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3399
3400 std::string rs = GPR(copy(rs_value));
3401 std::string rt = GPR(copy(rt_value));
3402 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3403
3404 return img::format("BNEC %s, %s, %s", rs, rt, s);
3405 }
3406
3407
3408 /*
3409 *
3410 *
3411 * 3 2 1
3412 * 10987654321098765432109876543210
3413 * 001000 x1110000101
3414 * rt -----
3415 * rs -----
3416 * rd -----
3417 */
3418 std::string NMD::BNEIC(uint64 instruction)
3419 {
3420 uint64 rt_value = extract_rt_25_24_23_22_21(instruction);
3421 uint64 u_value = extract_u_17_16_15_14_13_12_11(instruction);
3422 int64 s_value = extract_s__se11_0_10_9_8_7_6_5_4_3_2_1_0_s1(instruction);
3423
3424 std::string rt = GPR(copy(rt_value));
3425 std::string u = IMMEDIATE(copy(u_value));
3426 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3427
3428 return img::format("BNEIC %s, %s, %s", rt, u, s);
3429 }
3430
3431
3432 /*
3433 *
3434 *
3435 * 3 2 1
3436 * 10987654321098765432109876543210
3437 * 001000 x1110000101
3438 * rt -----
3439 * rs -----
3440 * rd -----
3441 */
3442 std::string NMD::BNEZC_16_(uint64 instruction)
3443 {
3444 uint64 rt3_value = extract_rt3_9_8_7(instruction);
3445 int64 s_value = extract_s__se7_0_6_5_4_3_2_1_s1(instruction);
3446
3447 std::string rt3 = GPR(decode_gpr_gpr3(rt3_value));
3448 std::string s = ADDRESS(encode_s_from_address(s_value), 2);
3449
3450 return img::format("BNEZC %s, %s", rt3, s);
3451 }
3452
3453
3454 /*
3455 * [DSP] BPOSGE32C offset - Branch on greater than or equal to value 32 in
3456 * DSPControl Pos field
3457 *
3458 * 3 2 1
3459 * 10987654321098765432109876543210
3460 * 100010xxxxx0010001
3461 * s[13:1] -------------
3462 * s[14] -
3463 */
3464 std::string NMD::BPOSGE32C(uint64 instruction)
3465 {
3466 int64 s_value = extract_s__se14_0_13_to_1_s1(instruction);
3467
3468 std::string s = ADDRESS(encode_s_from_address(s_value), 4);
3469
3470 return img::format("BPOSGE32C %s", s);
3471 }
3472
3473
3474 /*
3475 *
3476 *
3477 * 3 2 1
3478 * 10987654321098765432109876543210
3479 * 001000 x1110000101
3480 * rt -----
3481 * rs -----
3482 * rd -----
3483 */
3484 std::string NMD::BREAK_16_(uint64 instruction)
3485 {
3486 uint64 code_value = extract_code_2_1_0(instruction);
3487
3488 std::string code = IMMEDIATE(copy(code_value));
3489
3490 return img::format("BREAK %s", code);
3491 }
3492
3493
3494 /*
3495 * BREAK code - Break. Cause a Breakpoint exception
3496 *
3497 * 3 2 1
3498 * 10987654321098765432109876543210
3499 * 001000 x1110000101
3500 * rt -----
3501 * rs -----
3502 * rd -----
3503 */
3504 std::string NMD::BREAK_32_(uint64 instruction)
3505 {
3506 uint64 code_value = extract_code_18_to_0(instruction);
3507
3508 std::string code = IMMEDIATE(copy(code_value));
3509
3510 return img::format("BREAK %s", code);
3511 }
3512
3513
3514 /*
3515 *
3516 *
3517 * 3 2 1
3518 * 10987654321098765432109876543210
3519 * 001000 x1110000101
3520 * rt -----
3521 * rs -----
3522 * rd -----
3523 */
3524 std::string NMD::BRSC(uint64 instruction)
3525 {
3526 uint64 rs_value = extract_rs_20_19_18_17_16(instruction);
3527
3528 std::string rs = GPR(copy(rs_value));
3529
3530 return img::format("BRSC %s", rs);
3531 }
3532
3533
3534 /*
3535 *
3536 *
3537 * 3 2 1
3538 * 10987654321098765432109876543210
3539 * 001000 x1110000101
3540 * rt -----
3541 * rs -----
3542 * rd -----
3543 */