3 // In mips.igen, the semantics for many of the instructions were created
4 // using code generated by gencode. Those semantic segments could be
8 // <insn-word> { "+" <insn-word> }
15 // { <insn-mnemonic> }
20 // IGEN config - mips16
21 // :option:16::insn-bit-size:16
22 // :option:16::hi-bit-nr:15
23 :option:16::insn-specifying-widths:true
24 :option:16::gen-delayed-branch:false
26 // IGEN config - mips32/64..
27 // :option:32::insn-bit-size:32
28 // :option:32::hi-bit-nr:31
29 :option:32::insn-specifying-widths:true
30 :option:32::gen-delayed-branch:false
33 // Generate separate simulators for each target
34 // :option:::multi-sim:true
37 // Models known by this simulator are defined below.
41 // Instructions and related functions for these models are included in
43 :model:::mipsI:mips3000:
44 :model:::mipsII:mips6000:
45 :model:::mipsIII:mips4000:
46 :model:::mipsIV:mips8000:
50 // Standard MIPS ISA instructions used for these models are listed here,
51 // as are functions needed by those standard instructions. Instructions
52 // which are model-dependent and which are not in the standard MIPS ISAs
53 // (or which pre-date or use different encodings than the standard
54 // instructions) are (for the most part) in separate .igen files.
55 :model:::vr4100:mips4100: // vr.igen
56 :model:::vr5000:mips5000:
57 :model:::r3900:mips3900: // tx.igen
59 // MIPS Application Specific Extensions (ASEs)
61 // Instructions for the ASEs are in separate .igen files.
62 :model:::mips16:mips16: // m16.igen (and m16.dc)
65 // Pseudo instructions known by IGEN
68 SignalException (ReservedInstruction, 0);
72 // Pseudo instructions known by interp.c
73 // For grep - RSVD_INSTRUCTION, RSVD_INSTRUCTION_MASK
74 000000,5.*,5.*,5.*,5.OP,000101:SPECIAL:32::RSVD
77 SignalException (ReservedInstruction, instruction_0);
84 // Simulate a 32 bit delayslot instruction
87 :function:::address_word:delayslot32:address_word target
89 instruction_word delay_insn;
90 sim_events_slip (SD, 1);
92 CIA = CIA + 4; /* NOTE not mips16 */
93 STATE |= simDELAYSLOT;
94 delay_insn = IMEM32 (CIA); /* NOTE not mips16 */
95 ENGINE_ISSUE_PREFIX_HOOK();
96 idecode_issue (CPU_, delay_insn, (CIA));
97 STATE &= ~simDELAYSLOT;
101 :function:::address_word:nullify_next_insn32:
103 sim_events_slip (SD, 1);
104 dotrace (SD, CPU, tracefh, 2, CIA + 4, 4, "load instruction");
110 // Check that an access to a HI/LO register meets timing requirements
112 // The following requirements exist:
114 // - A MT {HI,LO} update was not immediatly preceeded by a MF {HI,LO} read
115 // - A OP {HI,LO} update was not immediatly preceeded by a MF {HI,LO} read
116 // - A MF {HI,LO} read was not corrupted by a preceeding MT{LO,HI} update
117 // corruption occures when MT{LO,HI} is preceeded by a OP {HI,LO}.
120 :function:::int:check_mf_cycles:hilo_history *history, signed64 time, const char *new
122 if (history->mf.timestamp + 3 > time)
124 sim_engine_abort (SD, CPU, CIA, "HILO: %s: %s at 0x%08lx too close to MF at 0x%08lx\n",
125 itable[MY_INDEX].name,
127 (long) history->mf.cia);
133 :function:::int:check_mt_hilo:hilo_history *history
134 *mipsI,mipsII,mipsIII,mipsIV:
138 signed64 time = sim_events_time (SD);
139 int ok = check_mf_cycles (SD_, history, time, "MT");
140 history->mt.timestamp = time;
141 history->mt.cia = CIA;
145 :function:::int:check_mt_hilo:hilo_history *history
148 signed64 time = sim_events_time (SD);
149 history->mt.timestamp = time;
150 history->mt.cia = CIA;
155 :function:::int:check_mf_hilo:hilo_history *history, hilo_history *peer
156 *mipsI,mipsII,mipsIII,mipsIV:
161 signed64 time = sim_events_time (SD);
164 && peer->mt.timestamp > history->op.timestamp
165 && history->mt.timestamp < history->op.timestamp
166 && ! (history->mf.timestamp > history->op.timestamp
167 && history->mf.timestamp < peer->mt.timestamp)
168 && ! (peer->mf.timestamp > history->op.timestamp
169 && peer->mf.timestamp < peer->mt.timestamp))
171 /* The peer has been written to since the last OP yet we have
173 sim_engine_abort (SD, CPU, CIA, "HILO: %s: MF at 0x%08lx following OP at 0x%08lx corrupted by MT at 0x%08lx\n",
174 itable[MY_INDEX].name,
176 (long) history->op.cia,
177 (long) peer->mt.cia);
180 history->mf.timestamp = time;
181 history->mf.cia = CIA;
187 :function:::int:check_mult_hilo:hilo_history *hi, hilo_history *lo
188 *mipsI,mipsII,mipsIII,mipsIV:
192 signed64 time = sim_events_time (SD);
193 int ok = (check_mf_cycles (SD_, hi, time, "OP")
194 && check_mf_cycles (SD_, lo, time, "OP"));
195 hi->op.timestamp = time;
196 lo->op.timestamp = time;
202 // The r3900 mult and multu insns _can_ be exectuted immediatly after
204 :function:::int:check_mult_hilo:hilo_history *hi, hilo_history *lo
207 /* FIXME: could record the fact that a stall occured if we want */
208 signed64 time = sim_events_time (SD);
209 hi->op.timestamp = time;
210 lo->op.timestamp = time;
217 :function:::int:check_div_hilo:hilo_history *hi, hilo_history *lo
218 *mipsI,mipsII,mipsIII,mipsIV:
223 signed64 time = sim_events_time (SD);
224 int ok = (check_mf_cycles (SD_, hi, time, "OP")
225 && check_mf_cycles (SD_, lo, time, "OP"));
226 hi->op.timestamp = time;
227 lo->op.timestamp = time;
238 // MIPS Architecture:
240 // CPU Instruction Set (mipsI - mipsIV)
245 000000,5.RS,5.RT,5.RD,00000,100000:SPECIAL:32::ADD
246 "add r<RD>, r<RS>, r<RT>"
247 *mipsI,mipsII,mipsIII,mipsIV:
252 TRACE_ALU_INPUT2 (GPR[RS], GPR[RT]);
254 ALU32_BEGIN (GPR[RS]);
256 ALU32_END (GPR[RD]); /* This checks for overflow. */
258 TRACE_ALU_RESULT (GPR[RD]);
263 001000,5.RS,5.RT,16.IMMEDIATE:NORMAL:32::ADDI
264 "addi r<RT>, r<RS>, <IMMEDIATE>"
265 *mipsI,mipsII,mipsIII,mipsIV:
270 TRACE_ALU_INPUT2 (GPR[RS], EXTEND16 (IMMEDIATE));
272 ALU32_BEGIN (GPR[RS]);
273 ALU32_ADD (EXTEND16 (IMMEDIATE));
274 ALU32_END (GPR[RT]); /* This checks for overflow. */
276 TRACE_ALU_RESULT (GPR[RT]);
281 :function:::void:do_addiu:int rs, int rt, unsigned16 immediate
283 TRACE_ALU_INPUT2 (GPR[rs], EXTEND16 (immediate));
284 GPR[rt] = EXTEND32 (GPR[rs] + EXTEND16 (immediate));
285 TRACE_ALU_RESULT (GPR[rt]);
288 001001,5.RS,5.RT,16.IMMEDIATE:NORMAL:32::ADDIU
289 "addiu r<RT>, r<RS>, <IMMEDIATE>"
290 *mipsI,mipsII,mipsIII,mipsIV:
295 do_addiu (SD_, RS, RT, IMMEDIATE);
300 :function:::void:do_addu:int rs, int rt, int rd
302 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
303 GPR[rd] = EXTEND32 (GPR[rs] + GPR[rt]);
304 TRACE_ALU_RESULT (GPR[rd]);
307 000000,5.RS,5.RT,5.RD,00000,100001:SPECIAL:32::ADDU
308 "addu r<RD>, r<RS>, r<RT>"
309 *mipsI,mipsII,mipsIII,mipsIV:
314 do_addu (SD_, RS, RT, RD);
319 :function:::void:do_and:int rs, int rt, int rd
321 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
322 GPR[rd] = GPR[rs] & GPR[rt];
323 TRACE_ALU_RESULT (GPR[rd]);
326 000000,5.RS,5.RT,5.RD,00000,100100:SPECIAL:32::AND
327 "and r<RD>, r<RS>, r<RT>"
328 *mipsI,mipsII,mipsIII,mipsIV:
333 do_and (SD_, RS, RT, RD);
338 001100,5.RS,5.RT,16.IMMEDIATE:NORMAL:32::ANDI
339 "and r<RT>, r<RS>, <IMMEDIATE>"
340 *mipsI,mipsII,mipsIII,mipsIV:
345 TRACE_ALU_INPUT2 (GPR[RS], IMMEDIATE);
346 GPR[RT] = GPR[RS] & IMMEDIATE;
347 TRACE_ALU_RESULT (GPR[RT]);
352 000100,5.RS,5.RT,16.OFFSET:NORMAL:32::BEQ
353 "beq r<RS>, r<RT>, <OFFSET>"
354 *mipsI,mipsII,mipsIII,mipsIV:
359 address_word offset = EXTEND16 (OFFSET) << 2;
361 if ((signed_word) GPR[RS] == (signed_word) GPR[RT])
363 mark_branch_bug (NIA+offset);
364 DELAY_SLOT (NIA + offset);
370 010100,5.RS,5.RT,16.OFFSET:NORMAL:32::BEQL
371 "beql r<RS>, r<RT>, <OFFSET>"
379 address_word offset = EXTEND16 (OFFSET) << 2;
381 if ((signed_word) GPR[RS] == (signed_word) GPR[RT])
383 mark_branch_bug (NIA+offset);
384 DELAY_SLOT (NIA + offset);
387 NULLIFY_NEXT_INSTRUCTION ();
392 000001,5.RS,00001,16.OFFSET:REGIMM:32::BGEZ
393 "bgez r<RS>, <OFFSET>"
394 *mipsI,mipsII,mipsIII,mipsIV:
399 address_word offset = EXTEND16 (OFFSET) << 2;
401 if ((signed_word) GPR[RS] >= 0)
403 mark_branch_bug (NIA+offset);
404 DELAY_SLOT (NIA + offset);
410 000001,5.RS!31,10001,16.OFFSET:REGIMM:32::BGEZAL
411 "bgezal r<RS>, <OFFSET>"
412 *mipsI,mipsII,mipsIII,mipsIV:
417 address_word offset = EXTEND16 (OFFSET) << 2;
420 if ((signed_word) GPR[RS] >= 0)
422 mark_branch_bug (NIA+offset);
423 DELAY_SLOT (NIA + offset);
429 000001,5.RS!31,10011,16.OFFSET:REGIMM:32::BGEZALL
430 "bgezall r<RS>, <OFFSET>"
438 address_word offset = EXTEND16 (OFFSET) << 2;
441 /* NOTE: The branch occurs AFTER the next instruction has been
443 if ((signed_word) GPR[RS] >= 0)
445 mark_branch_bug (NIA+offset);
446 DELAY_SLOT (NIA + offset);
449 NULLIFY_NEXT_INSTRUCTION ();
454 000001,5.RS,00011,16.OFFSET:REGIMM:32::BGEZL
455 "bgezl r<RS>, <OFFSET>"
463 address_word offset = EXTEND16 (OFFSET) << 2;
465 if ((signed_word) GPR[RS] >= 0)
467 mark_branch_bug (NIA+offset);
468 DELAY_SLOT (NIA + offset);
471 NULLIFY_NEXT_INSTRUCTION ();
476 000111,5.RS,00000,16.OFFSET:NORMAL:32::BGTZ
477 "bgtz r<RS>, <OFFSET>"
478 *mipsI,mipsII,mipsIII,mipsIV:
483 address_word offset = EXTEND16 (OFFSET) << 2;
485 if ((signed_word) GPR[RS] > 0)
487 mark_branch_bug (NIA+offset);
488 DELAY_SLOT (NIA + offset);
494 010111,5.RS,00000,16.OFFSET:NORMAL:32::BGTZL
495 "bgtzl r<RS>, <OFFSET>"
503 address_word offset = EXTEND16 (OFFSET) << 2;
505 /* NOTE: The branch occurs AFTER the next instruction has been
507 if ((signed_word) GPR[RS] > 0)
509 mark_branch_bug (NIA+offset);
510 DELAY_SLOT (NIA + offset);
513 NULLIFY_NEXT_INSTRUCTION ();
518 000110,5.RS,00000,16.OFFSET:NORMAL:32::BLEZ
519 "blez r<RS>, <OFFSET>"
520 *mipsI,mipsII,mipsIII,mipsIV:
525 address_word offset = EXTEND16 (OFFSET) << 2;
527 /* NOTE: The branch occurs AFTER the next instruction has been
529 if ((signed_word) GPR[RS] <= 0)
531 mark_branch_bug (NIA+offset);
532 DELAY_SLOT (NIA + offset);
538 010110,5.RS,00000,16.OFFSET:NORMAL:32::BLEZL
539 "bgezl r<RS>, <OFFSET>"
547 address_word offset = EXTEND16 (OFFSET) << 2;
549 if ((signed_word) GPR[RS] <= 0)
551 mark_branch_bug (NIA+offset);
552 DELAY_SLOT (NIA + offset);
555 NULLIFY_NEXT_INSTRUCTION ();
560 000001,5.RS,00000,16.OFFSET:REGIMM:32::BLTZ
561 "bltz r<RS>, <OFFSET>"
562 *mipsI,mipsII,mipsIII,mipsIV:
567 address_word offset = EXTEND16 (OFFSET) << 2;
569 if ((signed_word) GPR[RS] < 0)
571 mark_branch_bug (NIA+offset);
572 DELAY_SLOT (NIA + offset);
578 000001,5.RS!31,10000,16.OFFSET:REGIMM:32::BLTZAL
579 "bltzal r<RS>, <OFFSET>"
580 *mipsI,mipsII,mipsIII,mipsIV:
585 address_word offset = EXTEND16 (OFFSET) << 2;
588 /* NOTE: The branch occurs AFTER the next instruction has been
590 if ((signed_word) GPR[RS] < 0)
592 mark_branch_bug (NIA+offset);
593 DELAY_SLOT (NIA + offset);
599 000001,5.RS!31,10010,16.OFFSET:REGIMM:32::BLTZALL
600 "bltzall r<RS>, <OFFSET>"
608 address_word offset = EXTEND16 (OFFSET) << 2;
611 if ((signed_word) GPR[RS] < 0)
613 mark_branch_bug (NIA+offset);
614 DELAY_SLOT (NIA + offset);
617 NULLIFY_NEXT_INSTRUCTION ();
622 000001,5.RS,00010,16.OFFSET:REGIMM:32::BLTZL
623 "bltzl r<RS>, <OFFSET>"
631 address_word offset = EXTEND16 (OFFSET) << 2;
633 /* NOTE: The branch occurs AFTER the next instruction has been
635 if ((signed_word) GPR[RS] < 0)
637 mark_branch_bug (NIA+offset);
638 DELAY_SLOT (NIA + offset);
641 NULLIFY_NEXT_INSTRUCTION ();
646 000101,5.RS,5.RT,16.OFFSET:NORMAL:32::BNE
647 "bne r<RS>, r<RT>, <OFFSET>"
648 *mipsI,mipsII,mipsIII,mipsIV:
653 address_word offset = EXTEND16 (OFFSET) << 2;
655 if ((signed_word) GPR[RS] != (signed_word) GPR[RT])
657 mark_branch_bug (NIA+offset);
658 DELAY_SLOT (NIA + offset);
664 010101,5.RS,5.RT,16.OFFSET:NORMAL:32::BNEL
665 "bnel r<RS>, r<RT>, <OFFSET>"
673 address_word offset = EXTEND16 (OFFSET) << 2;
675 if ((signed_word) GPR[RS] != (signed_word) GPR[RT])
677 mark_branch_bug (NIA+offset);
678 DELAY_SLOT (NIA + offset);
681 NULLIFY_NEXT_INSTRUCTION ();
686 000000,20.CODE,001101:SPECIAL:32::BREAK
688 *mipsI,mipsII,mipsIII,mipsIV:
693 /* Check for some break instruction which are reserved for use by the simulator. */
694 unsigned int break_code = instruction_0 & HALT_INSTRUCTION_MASK;
695 if (break_code == (HALT_INSTRUCTION & HALT_INSTRUCTION_MASK) ||
696 break_code == (HALT_INSTRUCTION2 & HALT_INSTRUCTION_MASK))
698 sim_engine_halt (SD, CPU, NULL, cia,
699 sim_exited, (unsigned int)(A0 & 0xFFFFFFFF));
701 else if (break_code == (BREAKPOINT_INSTRUCTION & HALT_INSTRUCTION_MASK) ||
702 break_code == (BREAKPOINT_INSTRUCTION2 & HALT_INSTRUCTION_MASK))
704 if (STATE & simDELAYSLOT)
705 PC = cia - 4; /* reference the branch instruction */
708 SignalException(BreakPoint, instruction_0);
713 /* If we get this far, we're not an instruction reserved by the sim. Raise
715 SignalException(BreakPoint, instruction_0);
721 000000,5.RS,5.RT,5.RD,00000,101100:SPECIAL:64::DADD
722 "dadd r<RD>, r<RS>, r<RT>"
728 TRACE_ALU_INPUT2 (GPR[RS], GPR[RT]);
730 ALU64_BEGIN (GPR[RS]);
732 ALU64_END (GPR[RD]); /* This checks for overflow. */
734 TRACE_ALU_RESULT (GPR[RD]);
739 011000,5.RS,5.RT,16.IMMEDIATE:NORMAL:64::DADDI
740 "daddi r<RT>, r<RS>, <IMMEDIATE>"
746 TRACE_ALU_INPUT2 (GPR[RS], EXTEND16 (IMMEDIATE));
748 ALU64_BEGIN (GPR[RS]);
749 ALU64_ADD (EXTEND16 (IMMEDIATE));
750 ALU64_END (GPR[RT]); /* This checks for overflow. */
752 TRACE_ALU_RESULT (GPR[RT]);
757 :function:::void:do_daddiu:int rs, int rt, unsigned16 immediate
759 TRACE_ALU_INPUT2 (GPR[rs], EXTEND16 (immediate));
760 GPR[rt] = GPR[rs] + EXTEND16 (immediate);
761 TRACE_ALU_RESULT (GPR[rt]);
764 011001,5.RS,5.RT,16.IMMEDIATE:NORMAL:64::DADDIU
765 "daddiu r<RT>, r<RS>, <IMMEDIATE>"
771 do_daddiu (SD_, RS, RT, IMMEDIATE);
776 :function:::void:do_daddu:int rs, int rt, int rd
778 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
779 GPR[rd] = GPR[rs] + GPR[rt];
780 TRACE_ALU_RESULT (GPR[rd]);
783 000000,5.RS,5.RT,5.RD,00000,101101:SPECIAL:64::DADDU
784 "daddu r<RD>, r<RS>, r<RT>"
790 do_daddu (SD_, RS, RT, RD);
795 :function:::void:do_ddiv:int rs, int rt
797 check_div_hilo (SD_, HIHISTORY, LOHISTORY);
798 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
800 signed64 n = GPR[rs];
801 signed64 d = GPR[rt];
806 lo = SIGNED64 (0x8000000000000000);
809 else if (d == -1 && n == SIGNED64 (0x8000000000000000))
811 lo = SIGNED64 (0x8000000000000000);
822 TRACE_ALU_RESULT2 (HI, LO);
825 000000,5.RS,5.RT,0000000000,011110:SPECIAL:64::DDIV
832 do_ddiv (SD_, RS, RT);
837 :function:::void:do_ddivu:int rs, int rt
839 check_div_hilo (SD_, HIHISTORY, LOHISTORY);
840 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
842 unsigned64 n = GPR[rs];
843 unsigned64 d = GPR[rt];
848 lo = SIGNED64 (0x8000000000000000);
859 TRACE_ALU_RESULT2 (HI, LO);
862 000000,5.RS,5.RT,0000000000,011111:SPECIAL:64::DDIVU
869 do_ddivu (SD_, RS, RT);
874 :function:::void:do_div:int rs, int rt
876 check_div_hilo (SD_, HIHISTORY, LOHISTORY);
877 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
879 signed32 n = GPR[rs];
880 signed32 d = GPR[rt];
883 LO = EXTEND32 (0x80000000);
886 else if (n == SIGNED32 (0x80000000) && d == -1)
888 LO = EXTEND32 (0x80000000);
893 LO = EXTEND32 (n / d);
894 HI = EXTEND32 (n % d);
897 TRACE_ALU_RESULT2 (HI, LO);
900 000000,5.RS,5.RT,0000000000,011010:SPECIAL:32::DIV
902 *mipsI,mipsII,mipsIII,mipsIV:
907 do_div (SD_, RS, RT);
912 :function:::void:do_divu:int rs, int rt
914 check_div_hilo (SD_, HIHISTORY, LOHISTORY);
915 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
917 unsigned32 n = GPR[rs];
918 unsigned32 d = GPR[rt];
921 LO = EXTEND32 (0x80000000);
926 LO = EXTEND32 (n / d);
927 HI = EXTEND32 (n % d);
930 TRACE_ALU_RESULT2 (HI, LO);
933 000000,5.RS,5.RT,0000000000,011011:SPECIAL:32::DIVU
935 *mipsI,mipsII,mipsIII,mipsIV:
940 do_divu (SD_, RS, RT);
945 :function:::void:do_dmultx:int rs, int rt, int rd, int signed_p
955 unsigned64 op1 = GPR[rs];
956 unsigned64 op2 = GPR[rt];
957 check_mult_hilo (SD_, HIHISTORY, LOHISTORY);
958 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
959 /* make signed multiply unsigned */
974 /* multiply out the 4 sub products */
975 m00 = ((unsigned64) VL4_8 (op1) * (unsigned64) VL4_8 (op2));
976 m10 = ((unsigned64) VH4_8 (op1) * (unsigned64) VL4_8 (op2));
977 m01 = ((unsigned64) VL4_8 (op1) * (unsigned64) VH4_8 (op2));
978 m11 = ((unsigned64) VH4_8 (op1) * (unsigned64) VH4_8 (op2));
979 /* add the products */
980 mid = ((unsigned64) VH4_8 (m00)
981 + (unsigned64) VL4_8 (m10)
982 + (unsigned64) VL4_8 (m01));
983 lo = U8_4 (mid, m00);
985 + (unsigned64) VH4_8 (mid)
986 + (unsigned64) VH4_8 (m01)
987 + (unsigned64) VH4_8 (m10));
997 /* save the result HI/LO (and a gpr) */
1002 TRACE_ALU_RESULT2 (HI, LO);
1005 :function:::void:do_dmult:int rs, int rt, int rd
1007 do_dmultx (SD_, rs, rt, rd, 1);
1010 000000,5.RS,5.RT,0000000000,011100:SPECIAL:64::DMULT
1011 "dmult r<RS>, r<RT>"
1015 do_dmult (SD_, RS, RT, 0);
1018 000000,5.RS,5.RT,5.RD,00000,011100:SPECIAL:64::DMULT
1019 "dmult r<RS>, r<RT>":RD == 0
1020 "dmult r<RD>, r<RS>, r<RT>"
1023 do_dmult (SD_, RS, RT, RD);
1028 :function:::void:do_dmultu:int rs, int rt, int rd
1030 do_dmultx (SD_, rs, rt, rd, 0);
1033 000000,5.RS,5.RT,0000000000,011101:SPECIAL:64::DMULTU
1034 "dmultu r<RS>, r<RT>"
1038 do_dmultu (SD_, RS, RT, 0);
1041 000000,5.RS,5.RT,5.RD,00000,011101:SPECIAL:64::DMULTU
1042 "dmultu r<RD>, r<RS>, r<RT>":RD == 0
1043 "dmultu r<RS>, r<RT>"
1046 do_dmultu (SD_, RS, RT, RD);
1049 :function:::void:do_dsll:int rt, int rd, int shift
1051 GPR[rd] = GPR[rt] << shift;
1054 :function:::void:do_dsllv:int rs, int rt, int rd
1056 int s = MASKED64 (GPR[rs], 5, 0);
1057 GPR[rd] = GPR[rt] << s;
1061 000000,00000,5.RT,5.RD,5.SHIFT,111000:SPECIAL:64::DSLL
1062 "dsll r<RD>, r<RT>, <SHIFT>"
1068 do_dsll (SD_, RT, RD, SHIFT);
1072 000000,00000,5.RT,5.RD,5.SHIFT,111100:SPECIAL:64::DSLL32
1073 "dsll32 r<RD>, r<RT>, <SHIFT>"
1080 GPR[RD] = GPR[RT] << s;
1083 000000,5.RS,5.RT,5.RD,00000,010100:SPECIAL:64::DSLLV
1084 "dsllv r<RD>, r<RT>, r<RS>"
1090 do_dsllv (SD_, RS, RT, RD);
1093 :function:::void:do_dsra:int rt, int rd, int shift
1095 GPR[rd] = ((signed64) GPR[rt]) >> shift;
1099 000000,00000,5.RT,5.RD,5.SHIFT,111011:SPECIAL:64::DSRA
1100 "dsra r<RD>, r<RT>, <SHIFT>"
1106 do_dsra (SD_, RT, RD, SHIFT);
1110 000000,00000,5.RT,5.RD,5.SHIFT,111111:SPECIAL:64::DSRA32
1111 "dsra32 r<RT>, r<RD>, <SHIFT>"
1118 GPR[RD] = ((signed64) GPR[RT]) >> s;
1122 :function:::void:do_dsrav:int rs, int rt, int rd
1124 int s = MASKED64 (GPR[rs], 5, 0);
1125 TRACE_ALU_INPUT2 (GPR[rt], s);
1126 GPR[rd] = ((signed64) GPR[rt]) >> s;
1127 TRACE_ALU_RESULT (GPR[rd]);
1130 000000,5.RS,5.RT,5.RD,00000,010111:SPECIAL:64::DSRAV
1131 "dsrav r<RT>, r<RD>, r<RS>"
1137 do_dsrav (SD_, RS, RT, RD);
1140 :function:::void:do_dsrl:int rt, int rd, int shift
1142 GPR[rd] = (unsigned64) GPR[rt] >> shift;
1146 000000,00000,5.RT,5.RD,5.SHIFT,111010:SPECIAL:64::DSRL
1147 "dsrl r<RD>, r<RT>, <SHIFT>"
1153 do_dsrl (SD_, RT, RD, SHIFT);
1157 000000,00000,5.RT,5.RD,5.SHIFT,111110:SPECIAL:64::DSRL32
1158 "dsrl32 r<RD>, r<RT>, <SHIFT>"
1165 GPR[RD] = (unsigned64) GPR[RT] >> s;
1169 :function:::void:do_dsrlv:int rs, int rt, int rd
1171 int s = MASKED64 (GPR[rs], 5, 0);
1172 GPR[rd] = (unsigned64) GPR[rt] >> s;
1177 000000,5.RS,5.RT,5.RD,00000,010110:SPECIAL:64::DSRLV
1178 "dsrlv r<RD>, r<RT>, r<RS>"
1184 do_dsrlv (SD_, RS, RT, RD);
1188 000000,5.RS,5.RT,5.RD,00000,101110:SPECIAL:64::DSUB
1189 "dsub r<RD>, r<RS>, r<RT>"
1195 TRACE_ALU_INPUT2 (GPR[RS], GPR[RT]);
1197 ALU64_BEGIN (GPR[RS]);
1198 ALU64_SUB (GPR[RT]);
1199 ALU64_END (GPR[RD]); /* This checks for overflow. */
1201 TRACE_ALU_RESULT (GPR[RD]);
1205 :function:::void:do_dsubu:int rs, int rt, int rd
1207 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
1208 GPR[rd] = GPR[rs] - GPR[rt];
1209 TRACE_ALU_RESULT (GPR[rd]);
1212 000000,5.RS,5.RT,5.RD,00000,101111:SPECIAL:64::DSUBU
1213 "dsubu r<RD>, r<RS>, r<RT>"
1219 do_dsubu (SD_, RS, RT, RD);
1223 000010,26.INSTR_INDEX:NORMAL:32::J
1225 *mipsI,mipsII,mipsIII,mipsIV:
1230 /* NOTE: The region used is that of the delay slot NIA and NOT the
1231 current instruction */
1232 address_word region = (NIA & MASK (63, 28));
1233 DELAY_SLOT (region | (INSTR_INDEX << 2));
1237 000011,26.INSTR_INDEX:NORMAL:32::JAL
1239 *mipsI,mipsII,mipsIII,mipsIV:
1244 /* NOTE: The region used is that of the delay slot and NOT the
1245 current instruction */
1246 address_word region = (NIA & MASK (63, 28));
1248 DELAY_SLOT (region | (INSTR_INDEX << 2));
1251 000000,5.RS,00000,5.RD,00000,001001:SPECIAL:32::JALR
1252 "jalr r<RS>":RD == 31
1254 *mipsI,mipsII,mipsIII,mipsIV:
1259 address_word temp = GPR[RS];
1265 000000,5.RS,000000000000000,001000:SPECIAL:32::JR
1267 *mipsI,mipsII,mipsIII,mipsIV:
1272 DELAY_SLOT (GPR[RS]);
1276 :function:::unsigned_word:do_load:unsigned access, address_word base, address_word offset
1278 address_word mask = (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3);
1279 address_word reverseendian = (ReverseEndian ? (mask ^ access) : 0);
1280 address_word bigendiancpu = (BigEndianCPU ? (mask ^ access) : 0);
1287 vaddr = base + offset;
1288 if ((vaddr & access) != 0)
1290 SIM_CORE_SIGNAL (SD, STATE_CPU (SD, 0), cia, read_map, access+1, vaddr, read_transfer, sim_core_unaligned_signal);
1292 AddressTranslation (vaddr, isDATA, isLOAD, &paddr, &uncached, isTARGET, isREAL);
1293 paddr = ((paddr & ~mask) | ((paddr & mask) ^ reverseendian));
1294 LoadMemory (&memval, NULL, uncached, access, paddr, vaddr, isDATA, isREAL);
1295 byte = ((vaddr & mask) ^ bigendiancpu);
1296 return (memval >> (8 * byte));
1300 100000,5.BASE,5.RT,16.OFFSET:NORMAL:32::LB
1301 "lb r<RT>, <OFFSET>(r<BASE>)"
1302 *mipsI,mipsII,mipsIII,mipsIV:
1307 GPR[RT] = EXTEND8 (do_load (SD_, AccessLength_BYTE, GPR[BASE], EXTEND16 (OFFSET)));
1311 100100,5.BASE,5.RT,16.OFFSET:NORMAL:32::LBU
1312 "lbu r<RT>, <OFFSET>(r<BASE>)"
1313 *mipsI,mipsII,mipsIII,mipsIV:
1318 GPR[RT] = do_load (SD_, AccessLength_BYTE, GPR[BASE], EXTEND16 (OFFSET));
1322 110111,5.BASE,5.RT,16.OFFSET:NORMAL:64::LD
1323 "ld r<RT>, <OFFSET>(r<BASE>)"
1329 GPR[RT] = EXTEND64 (do_load (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET)));
1333 1101,ZZ!0!1!3,5.BASE,5.RT,16.OFFSET:NORMAL:64::LDCz
1334 "ldc<ZZ> r<RT>, <OFFSET>(r<BASE>)"
1342 COP_LD (ZZ, RT, do_load (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET)));
1348 011010,5.BASE,5.RT,16.OFFSET:NORMAL:64::LDL
1349 "ldl r<RT>, <OFFSET>(r<BASE>)"
1355 GPR[RT] = do_load_left (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
1359 011011,5.BASE,5.RT,16.OFFSET:NORMAL:64::LDR
1360 "ldr r<RT>, <OFFSET>(r<BASE>)"
1366 GPR[RT] = do_load_right (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
1370 100001,5.BASE,5.RT,16.OFFSET:NORMAL:32::LH
1371 "lh r<RT>, <OFFSET>(r<BASE>)"
1372 *mipsI,mipsII,mipsIII,mipsIV:
1377 GPR[RT] = EXTEND16 (do_load (SD_, AccessLength_HALFWORD, GPR[BASE], EXTEND16 (OFFSET)));
1381 100101,5.BASE,5.RT,16.OFFSET:NORMAL:32::LHU
1382 "lhu r<RT>, <OFFSET>(r<BASE>)"
1383 *mipsI,mipsII,mipsIII,mipsIV:
1388 GPR[RT] = do_load (SD_, AccessLength_HALFWORD, GPR[BASE], EXTEND16 (OFFSET));
1392 110000,5.BASE,5.RT,16.OFFSET:NORMAL:32::LL
1393 "ll r<RT>, <OFFSET>(r<BASE>)"
1400 unsigned32 instruction = instruction_0;
1401 signed_word offset = SIGNEXTEND((signed_word)((instruction >> 0) & 0x0000FFFF),16);
1402 int destreg = ((instruction >> 16) & 0x0000001F);
1403 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
1405 address_word vaddr = ((unsigned64)op1 + offset);
1408 if ((vaddr & 3) != 0)
1410 SIM_CORE_SIGNAL (SD, CPU, cia, read_map, 4, vaddr, read_transfer, sim_core_unaligned_signal);
1414 if (AddressTranslation(vaddr,isDATA,isLOAD,&paddr,&uncached,isTARGET,isREAL))
1416 unsigned64 memval = 0;
1417 unsigned64 memval1 = 0;
1418 unsigned64 mask = 0x7;
1419 unsigned int shift = 2;
1420 unsigned int reverse = (ReverseEndian ? (mask >> shift) : 0);
1421 unsigned int bigend = (BigEndianCPU ? (mask >> shift) : 0);
1423 paddr = ((paddr & ~mask) | ((paddr & mask) ^ (reverse << shift)));
1424 LoadMemory(&memval,&memval1,uncached,AccessLength_WORD,paddr,vaddr,isDATA,isREAL);
1425 byte = ((vaddr & mask) ^ (bigend << shift));
1426 GPR[destreg] = (SIGNEXTEND(((memval >> (8 * byte)) & 0xFFFFFFFF),32));
1434 110100,5.BASE,5.RT,16.OFFSET:NORMAL:64::LLD
1435 "lld r<RT>, <OFFSET>(r<BASE>)"
1441 unsigned32 instruction = instruction_0;
1442 signed_word offset = SIGNEXTEND((signed_word)((instruction >> 0) & 0x0000FFFF),16);
1443 int destreg = ((instruction >> 16) & 0x0000001F);
1444 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
1446 address_word vaddr = ((unsigned64)op1 + offset);
1449 if ((vaddr & 7) != 0)
1451 SIM_CORE_SIGNAL (SD, CPU, cia, read_map, 8, vaddr, read_transfer, sim_core_unaligned_signal);
1455 if (AddressTranslation(vaddr,isDATA,isLOAD,&paddr,&uncached,isTARGET,isREAL))
1457 unsigned64 memval = 0;
1458 unsigned64 memval1 = 0;
1459 LoadMemory(&memval,&memval1,uncached,AccessLength_DOUBLEWORD,paddr,vaddr,isDATA,isREAL);
1460 GPR[destreg] = memval;
1468 001111,00000,5.RT,16.IMMEDIATE:NORMAL:32::LUI
1469 "lui r<RT>, <IMMEDIATE>"
1470 *mipsI,mipsII,mipsIII,mipsIV:
1475 TRACE_ALU_INPUT1 (IMMEDIATE);
1476 GPR[RT] = EXTEND32 (IMMEDIATE << 16);
1477 TRACE_ALU_RESULT (GPR[RT]);
1481 100011,5.BASE,5.RT,16.OFFSET:NORMAL:32::LW
1482 "lw r<RT>, <OFFSET>(r<BASE>)"
1483 *mipsI,mipsII,mipsIII,mipsIV:
1488 GPR[RT] = EXTEND32 (do_load (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET)));
1492 1100,ZZ!0!1!3,5.BASE,5.RT,16.OFFSET:NORMAL:32::LWCz
1493 "lwc<ZZ> r<RT>, <OFFSET>(r<BASE>)"
1494 *mipsI,mipsII,mipsIII,mipsIV:
1499 COP_LW (ZZ, RT, do_load (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET)));
1503 :function:::unsigned_word:do_load_left:unsigned access, address_word base, address_word offset, unsigned_word rt
1505 address_word mask = (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3);
1506 address_word reverseendian = (ReverseEndian ? -1 : 0);
1507 address_word bigendiancpu = (BigEndianCPU ? -1 : 0);
1516 unsigned_word lhs_mask;
1519 vaddr = base + offset;
1520 AddressTranslation (vaddr, isDATA, isLOAD, &paddr, &uncached, isTARGET, isREAL);
1521 paddr = (paddr ^ (reverseendian & mask));
1522 if (BigEndianMem == 0)
1523 paddr = paddr & ~access;
1525 /* compute where within the word/mem we are */
1526 byte = ((vaddr ^ bigendiancpu) & access); /* 0..access */
1527 word = ((vaddr ^ bigendiancpu) & (mask & ~access)) / (access + 1); /* 0..1 */
1528 nr_lhs_bits = 8 * byte + 8;
1529 nr_rhs_bits = 8 * access - 8 * byte;
1530 /* nr_lhs_bits + nr_rhs_bits == 8 * (accesss + 1) */
1532 /* fprintf (stderr, "l[wd]l: 0x%08lx%08lx 0x%08lx%08lx %d:%d %d+%d\n",
1533 (long) ((unsigned64) vaddr >> 32), (long) vaddr,
1534 (long) ((unsigned64) paddr >> 32), (long) paddr,
1535 word, byte, nr_lhs_bits, nr_rhs_bits); */
1537 LoadMemory (&memval, NULL, uncached, byte, paddr, vaddr, isDATA, isREAL);
1540 /* GPR{31..32-NR_LHS_BITS} = memval{NR_LHS_BITS-1..0} */
1541 temp = (memval << nr_rhs_bits);
1545 /* GPR{31..32-NR_LHS_BITS = memval{32+NR_LHS_BITS..32} */
1546 temp = (memval >> nr_lhs_bits);
1548 lhs_mask = LSMASK (nr_lhs_bits + nr_rhs_bits - 1, nr_rhs_bits);
1549 rt = (rt & ~lhs_mask) | (temp & lhs_mask);
1551 /* fprintf (stderr, "l[wd]l: 0x%08lx%08lx -> 0x%08lx%08lx & 0x%08lx%08lx -> 0x%08lx%08lx\n",
1552 (long) ((unsigned64) memval >> 32), (long) memval,
1553 (long) ((unsigned64) temp >> 32), (long) temp,
1554 (long) ((unsigned64) lhs_mask >> 32), (long) lhs_mask,
1555 (long) (rt >> 32), (long) rt); */
1560 100010,5.BASE,5.RT,16.OFFSET:NORMAL:32::LWL
1561 "lwl r<RT>, <OFFSET>(r<BASE>)"
1562 *mipsI,mipsII,mipsIII,mipsIV:
1567 GPR[RT] = EXTEND32 (do_load_left (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]));
1571 :function:::unsigned_word:do_load_right:unsigned access, address_word base, address_word offset, unsigned_word rt
1573 address_word mask = (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3);
1574 address_word reverseendian = (ReverseEndian ? -1 : 0);
1575 address_word bigendiancpu = (BigEndianCPU ? -1 : 0);
1582 vaddr = base + offset;
1583 AddressTranslation (vaddr, isDATA, isLOAD, &paddr, &uncached, isTARGET, isREAL);
1584 /* NOTE: SPEC is wrong, has `BigEndianMem == 0' not `BigEndianMem != 0' */
1585 paddr = (paddr ^ (reverseendian & mask));
1586 if (BigEndianMem != 0)
1587 paddr = paddr & ~access;
1588 byte = ((vaddr & mask) ^ (bigendiancpu & mask));
1589 /* NOTE: SPEC is wrong, had `byte' not `access - byte'. See SW. */
1590 LoadMemory (&memval, NULL, uncached, access - (access & byte), paddr, vaddr, isDATA, isREAL);
1591 /* printf ("lr: 0x%08lx %d@0x%08lx 0x%08lx\n",
1592 (long) paddr, byte, (long) paddr, (long) memval); */
1594 unsigned_word screen = LSMASK (8 * (access - (byte & access) + 1) - 1, 0);
1596 rt |= (memval >> (8 * byte)) & screen;
1602 100110,5.BASE,5.RT,16.OFFSET:NORMAL:32::LWR
1603 "lwr r<RT>, <OFFSET>(r<BASE>)"
1604 *mipsI,mipsII,mipsIII,mipsIV:
1609 GPR[RT] = EXTEND32 (do_load_right (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]));
1613 100111,5.BASE,5.RT,16.OFFSET:NORMAL:32::LWU
1614 "lwu r<RT>, <OFFSET>(r<BASE>)"
1620 GPR[RT] = do_load (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET));
1624 :function:::void:do_mfhi:int rd
1626 check_mf_hilo (SD_, HIHISTORY, LOHISTORY);
1627 TRACE_ALU_INPUT1 (HI);
1629 TRACE_ALU_RESULT (GPR[rd]);
1632 000000,0000000000,5.RD,00000,010000:SPECIAL:32::MFHI
1634 *mipsI,mipsII,mipsIII,mipsIV:
1644 :function:::void:do_mflo:int rd
1646 check_mf_hilo (SD_, LOHISTORY, HIHISTORY);
1647 TRACE_ALU_INPUT1 (LO);
1649 TRACE_ALU_RESULT (GPR[rd]);
1652 000000,0000000000,5.RD,00000,010010:SPECIAL:32::MFLO
1654 *mipsI,mipsII,mipsIII,mipsIV:
1664 000000,5.RS,5.RT,5.RD,00000,001011:SPECIAL:32::MOVN
1665 "movn r<RD>, r<RS>, r<RT>"
1675 000000,5.RS,5.RT,5.RD,00000,001010:SPECIAL:32::MOVZ
1676 "movz r<RD>, r<RS>, r<RT>"
1686 000000,5.RS,000000000000000,010001:SPECIAL:32::MTHI
1688 *mipsI,mipsII,mipsIII,mipsIV:
1693 check_mt_hilo (SD_, HIHISTORY);
1699 000000,5.RS,000000000000000,010011:SPECIAL:32::MTLO
1701 *mipsI,mipsII,mipsIII,mipsIV:
1706 check_mt_hilo (SD_, LOHISTORY);
1712 :function:::void:do_mult:int rs, int rt, int rd
1715 check_mult_hilo (SD_, HIHISTORY, LOHISTORY);
1716 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
1717 prod = (((signed64)(signed32) GPR[rs])
1718 * ((signed64)(signed32) GPR[rt]));
1719 LO = EXTEND32 (VL4_8 (prod));
1720 HI = EXTEND32 (VH4_8 (prod));
1723 TRACE_ALU_RESULT2 (HI, LO);
1726 000000,5.RS,5.RT,0000000000,011000:SPECIAL:32::MULT
1728 *mipsI,mipsII,mipsIII,mipsIV:
1731 do_mult (SD_, RS, RT, 0);
1735 000000,5.RS,5.RT,5.RD,00000,011000:SPECIAL:32::MULT
1736 "mult r<RS>, r<RT>":RD == 0
1737 "mult r<RD>, r<RS>, r<RT>"
1741 do_mult (SD_, RS, RT, RD);
1745 :function:::void:do_multu:int rs, int rt, int rd
1748 check_mult_hilo (SD_, HIHISTORY, LOHISTORY);
1749 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
1750 prod = (((unsigned64)(unsigned32) GPR[rs])
1751 * ((unsigned64)(unsigned32) GPR[rt]));
1752 LO = EXTEND32 (VL4_8 (prod));
1753 HI = EXTEND32 (VH4_8 (prod));
1756 TRACE_ALU_RESULT2 (HI, LO);
1759 000000,5.RS,5.RT,0000000000,011001:SPECIAL:32::MULTU
1760 "multu r<RS>, r<RT>"
1761 *mipsI,mipsII,mipsIII,mipsIV:
1764 do_multu (SD_, RS, RT, 0);
1767 000000,5.RS,5.RT,5.RD,00000,011001:SPECIAL:32::MULTU
1768 "multu r<RS>, r<RT>":RD == 0
1769 "multu r<RD>, r<RS>, r<RT>"
1773 do_multu (SD_, RS, RT, RD);
1777 :function:::void:do_nor:int rs, int rt, int rd
1779 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
1780 GPR[rd] = ~ (GPR[rs] | GPR[rt]);
1781 TRACE_ALU_RESULT (GPR[rd]);
1784 000000,5.RS,5.RT,5.RD,00000,100111:SPECIAL:32::NOR
1785 "nor r<RD>, r<RS>, r<RT>"
1786 *mipsI,mipsII,mipsIII,mipsIV:
1791 do_nor (SD_, RS, RT, RD);
1795 :function:::void:do_or:int rs, int rt, int rd
1797 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
1798 GPR[rd] = (GPR[rs] | GPR[rt]);
1799 TRACE_ALU_RESULT (GPR[rd]);
1802 000000,5.RS,5.RT,5.RD,00000,100101:SPECIAL:32::OR
1803 "or r<RD>, r<RS>, r<RT>"
1804 *mipsI,mipsII,mipsIII,mipsIV:
1809 do_or (SD_, RS, RT, RD);
1814 :function:::void:do_ori:int rs, int rt, unsigned immediate
1816 TRACE_ALU_INPUT2 (GPR[rs], immediate);
1817 GPR[rt] = (GPR[rs] | immediate);
1818 TRACE_ALU_RESULT (GPR[rt]);
1821 001101,5.RS,5.RT,16.IMMEDIATE:NORMAL:32::ORI
1822 "ori r<RT>, r<RS>, <IMMEDIATE>"
1823 *mipsI,mipsII,mipsIII,mipsIV:
1828 do_ori (SD_, RS, RT, IMMEDIATE);
1832 110011,5.RS,nnnnn,16.OFFSET:NORMAL:32::PREF
1836 unsigned32 instruction = instruction_0;
1837 signed_word offset = SIGNEXTEND((signed_word)((instruction >> 0) & 0x0000FFFF),16);
1838 int hint = ((instruction >> 16) & 0x0000001F);
1839 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
1841 address_word vaddr = ((unsigned64)op1 + offset);
1845 if (AddressTranslation(vaddr,isDATA,isLOAD,&paddr,&uncached,isTARGET,isREAL))
1846 Prefetch(uncached,paddr,vaddr,isDATA,hint);
1851 :function:::void:do_store:unsigned access, address_word base, address_word offset, unsigned_word word
1853 address_word mask = (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3);
1854 address_word reverseendian = (ReverseEndian ? (mask ^ access) : 0);
1855 address_word bigendiancpu = (BigEndianCPU ? (mask ^ access) : 0);
1862 vaddr = base + offset;
1863 if ((vaddr & access) != 0)
1865 SIM_CORE_SIGNAL (SD, STATE_CPU(SD, 0), cia, read_map, access+1, vaddr, write_transfer, sim_core_unaligned_signal);
1867 AddressTranslation (vaddr, isDATA, isSTORE, &paddr, &uncached, isTARGET, isREAL);
1868 paddr = ((paddr & ~mask) | ((paddr & mask) ^ reverseendian));
1869 byte = ((vaddr & mask) ^ bigendiancpu);
1870 memval = (word << (8 * byte));
1871 StoreMemory (uncached, access, memval, 0, paddr, vaddr, isREAL);
1875 101000,5.BASE,5.RT,16.OFFSET:NORMAL:32::SB
1876 "sb r<RT>, <OFFSET>(r<BASE>)"
1877 *mipsI,mipsII,mipsIII,mipsIV:
1882 do_store (SD_, AccessLength_BYTE, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
1886 111000,5.BASE,5.RT,16.OFFSET:NORMAL:32::SC
1887 "sc r<RT>, <OFFSET>(r<BASE>)"
1894 unsigned32 instruction = instruction_0;
1895 signed_word offset = SIGNEXTEND((signed_word)((instruction >> 0) & 0x0000FFFF),16);
1896 signed_word op2 = GPR[((instruction >> 16) & 0x0000001F)];
1897 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
1899 address_word vaddr = ((unsigned64)op1 + offset);
1902 if ((vaddr & 3) != 0)
1904 SIM_CORE_SIGNAL (SD, CPU, cia, read_map, 4, vaddr, write_transfer, sim_core_unaligned_signal);
1908 if (AddressTranslation(vaddr,isDATA,isSTORE,&paddr,&uncached,isTARGET,isREAL))
1910 unsigned64 memval = 0;
1911 unsigned64 memval1 = 0;
1912 unsigned64 mask = 0x7;
1914 paddr = ((paddr & ~mask) | ((paddr & mask) ^ (ReverseEndian << 2)));
1915 byte = ((vaddr & mask) ^ (BigEndianCPU << 2));
1916 memval = ((unsigned64) op2 << (8 * byte));
1919 StoreMemory(uncached,AccessLength_WORD,memval,memval1,paddr,vaddr,isREAL);
1921 GPR[(instruction >> 16) & 0x0000001F] = LLBIT;
1928 111100,5.BASE,5.RT,16.OFFSET:NORMAL:64::SCD
1929 "scd r<RT>, <OFFSET>(r<BASE>)"
1935 unsigned32 instruction = instruction_0;
1936 signed_word offset = SIGNEXTEND((signed_word)((instruction >> 0) & 0x0000FFFF),16);
1937 signed_word op2 = GPR[((instruction >> 16) & 0x0000001F)];
1938 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
1940 address_word vaddr = ((unsigned64)op1 + offset);
1943 if ((vaddr & 7) != 0)
1945 SIM_CORE_SIGNAL (SD, CPU, cia, read_map, 8, vaddr, write_transfer, sim_core_unaligned_signal);
1949 if (AddressTranslation(vaddr,isDATA,isSTORE,&paddr,&uncached,isTARGET,isREAL))
1951 unsigned64 memval = 0;
1952 unsigned64 memval1 = 0;
1956 StoreMemory(uncached,AccessLength_DOUBLEWORD,memval,memval1,paddr,vaddr,isREAL);
1958 GPR[(instruction >> 16) & 0x0000001F] = LLBIT;
1965 111111,5.BASE,5.RT,16.OFFSET:NORMAL:64::SD
1966 "sd r<RT>, <OFFSET>(r<BASE>)"
1972 do_store (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
1976 1111,ZZ!0!1!3,5.BASE,5.RT,16.OFFSET:NORMAL:64::SDCz
1977 "sdc<ZZ> r<RT>, <OFFSET>(r<BASE>)"
1984 do_store (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET), COP_SD (ZZ, RT));
1988 101100,5.BASE,5.RT,16.OFFSET:NORMAL:64::SDL
1989 "sdl r<RT>, <OFFSET>(r<BASE>)"
1995 do_store_left (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
1999 101101,5.BASE,5.RT,16.OFFSET:NORMAL:64::SDR
2000 "sdr r<RT>, <OFFSET>(r<BASE>)"
2006 do_store_right (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
2010 101001,5.BASE,5.RT,16.OFFSET:NORMAL:32::SH
2011 "sh r<RT>, <OFFSET>(r<BASE>)"
2012 *mipsI,mipsII,mipsIII,mipsIV:
2017 do_store (SD_, AccessLength_HALFWORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
2021 :function:::void:do_sll:int rt, int rd, int shift
2023 unsigned32 temp = (GPR[rt] << shift);
2024 TRACE_ALU_INPUT2 (GPR[rt], shift);
2025 GPR[rd] = EXTEND32 (temp);
2026 TRACE_ALU_RESULT (GPR[rd]);
2029 000000,00000,5.RT,5.RD,5.SHIFT,000000:SPECIAL:32::SLL
2030 "nop":RD == 0 && RT == 0 && SHIFT == 0
2031 "sll r<RD>, r<RT>, <SHIFT>"
2032 *mipsI,mipsII,mipsIII,mipsIV:
2037 /* Skip shift for NOP, so that there won't be lots of extraneous
2039 if (RD != 0 || RT != 0 || SHIFT != 0)
2040 do_sll (SD_, RT, RD, SHIFT);
2044 :function:::void:do_sllv:int rs, int rt, int rd
2046 int s = MASKED (GPR[rs], 4, 0);
2047 unsigned32 temp = (GPR[rt] << s);
2048 TRACE_ALU_INPUT2 (GPR[rt], s);
2049 GPR[rd] = EXTEND32 (temp);
2050 TRACE_ALU_RESULT (GPR[rd]);
2053 000000,5.RS,5.RT,5.RD,00000,000100:SPECIAL:32::SLLV
2054 "sllv r<RD>, r<RT>, r<RS>"
2055 *mipsI,mipsII,mipsIII,mipsIV:
2060 do_sllv (SD_, RS, RT, RD);
2064 :function:::void:do_slt:int rs, int rt, int rd
2066 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
2067 GPR[rd] = ((signed_word) GPR[rs] < (signed_word) GPR[rt]);
2068 TRACE_ALU_RESULT (GPR[rd]);
2071 000000,5.RS,5.RT,5.RD,00000,101010:SPECIAL:32::SLT
2072 "slt r<RD>, r<RS>, r<RT>"
2073 *mipsI,mipsII,mipsIII,mipsIV:
2078 do_slt (SD_, RS, RT, RD);
2082 :function:::void:do_slti:int rs, int rt, unsigned16 immediate
2084 TRACE_ALU_INPUT2 (GPR[rs], EXTEND16 (immediate));
2085 GPR[rt] = ((signed_word) GPR[rs] < (signed_word) EXTEND16 (immediate));
2086 TRACE_ALU_RESULT (GPR[rt]);
2089 001010,5.RS,5.RT,16.IMMEDIATE:NORMAL:32::SLTI
2090 "slti r<RT>, r<RS>, <IMMEDIATE>"
2091 *mipsI,mipsII,mipsIII,mipsIV:
2096 do_slti (SD_, RS, RT, IMMEDIATE);
2100 :function:::void:do_sltiu:int rs, int rt, unsigned16 immediate
2102 TRACE_ALU_INPUT2 (GPR[rs], EXTEND16 (immediate));
2103 GPR[rt] = ((unsigned_word) GPR[rs] < (unsigned_word) EXTEND16 (immediate));
2104 TRACE_ALU_RESULT (GPR[rt]);
2107 001011,5.RS,5.RT,16.IMMEDIATE:NORMAL:32::SLTIU
2108 "sltiu r<RT>, r<RS>, <IMMEDIATE>"
2109 *mipsI,mipsII,mipsIII,mipsIV:
2114 do_sltiu (SD_, RS, RT, IMMEDIATE);
2119 :function:::void:do_sltu:int rs, int rt, int rd
2121 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
2122 GPR[rd] = ((unsigned_word) GPR[rs] < (unsigned_word) GPR[rt]);
2123 TRACE_ALU_RESULT (GPR[rd]);
2126 000000,5.RS,5.RT,5.RD,00000,101011:SPECIAL:32::SLTU
2127 "sltu r<RD>, r<RS>, r<RT>"
2128 *mipsI,mipsII,mipsIII,mipsIV:
2133 do_sltu (SD_, RS, RT, RD);
2137 :function:::void:do_sra:int rt, int rd, int shift
2139 signed32 temp = (signed32) GPR[rt] >> shift;
2140 TRACE_ALU_INPUT2 (GPR[rt], shift);
2141 GPR[rd] = EXTEND32 (temp);
2142 TRACE_ALU_RESULT (GPR[rd]);
2145 000000,00000,5.RT,5.RD,5.SHIFT,000011:SPECIAL:32::SRA
2146 "sra r<RD>, r<RT>, <SHIFT>"
2147 *mipsI,mipsII,mipsIII,mipsIV:
2152 do_sra (SD_, RT, RD, SHIFT);
2157 :function:::void:do_srav:int rs, int rt, int rd
2159 int s = MASKED (GPR[rs], 4, 0);
2160 signed32 temp = (signed32) GPR[rt] >> s;
2161 TRACE_ALU_INPUT2 (GPR[rt], s);
2162 GPR[rd] = EXTEND32 (temp);
2163 TRACE_ALU_RESULT (GPR[rd]);
2166 000000,5.RS,5.RT,5.RD,00000,000111:SPECIAL:32::SRAV
2167 "srav r<RD>, r<RT>, r<RS>"
2168 *mipsI,mipsII,mipsIII,mipsIV:
2173 do_srav (SD_, RS, RT, RD);
2178 :function:::void:do_srl:int rt, int rd, int shift
2180 unsigned32 temp = (unsigned32) GPR[rt] >> shift;
2181 TRACE_ALU_INPUT2 (GPR[rt], shift);
2182 GPR[rd] = EXTEND32 (temp);
2183 TRACE_ALU_RESULT (GPR[rd]);
2186 000000,00000,5.RT,5.RD,5.SHIFT,000010:SPECIAL:32::SRL
2187 "srl r<RD>, r<RT>, <SHIFT>"
2188 *mipsI,mipsII,mipsIII,mipsIV:
2193 do_srl (SD_, RT, RD, SHIFT);
2197 :function:::void:do_srlv:int rs, int rt, int rd
2199 int s = MASKED (GPR[rs], 4, 0);
2200 unsigned32 temp = (unsigned32) GPR[rt] >> s;
2201 TRACE_ALU_INPUT2 (GPR[rt], s);
2202 GPR[rd] = EXTEND32 (temp);
2203 TRACE_ALU_RESULT (GPR[rd]);
2206 000000,5.RS,5.RT,5.RD,00000,000110:SPECIAL:32::SRLV
2207 "srlv r<RD>, r<RT>, r<RS>"
2208 *mipsI,mipsII,mipsIII,mipsIV:
2213 do_srlv (SD_, RS, RT, RD);
2217 000000,5.RS,5.RT,5.RD,00000,100010:SPECIAL:32::SUB
2218 "sub r<RD>, r<RS>, r<RT>"
2219 *mipsI,mipsII,mipsIII,mipsIV:
2224 TRACE_ALU_INPUT2 (GPR[RS], GPR[RT]);
2226 ALU32_BEGIN (GPR[RS]);
2227 ALU32_SUB (GPR[RT]);
2228 ALU32_END (GPR[RD]); /* This checks for overflow. */
2230 TRACE_ALU_RESULT (GPR[RD]);
2234 :function:::void:do_subu:int rs, int rt, int rd
2236 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
2237 GPR[rd] = EXTEND32 (GPR[rs] - GPR[rt]);
2238 TRACE_ALU_RESULT (GPR[rd]);
2241 000000,5.RS,5.RT,5.RD,00000,100011:SPECIAL:32::SUBU
2242 "subu r<RD>, r<RS>, r<RT>"
2243 *mipsI,mipsII,mipsIII,mipsIV:
2248 do_subu (SD_, RS, RT, RD);
2252 101011,5.BASE,5.RT,16.OFFSET:NORMAL:32::SW
2253 "sw r<RT>, <OFFSET>(r<BASE>)"
2254 *mipsI,mipsII,mipsIII,mipsIV:
2259 do_store (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
2263 1110,ZZ!0!1!3,5.BASE,5.RT,16.OFFSET:NORMAL:32::SWCz
2264 "swc<ZZ> r<RT>, <OFFSET>(r<BASE>)"
2265 *mipsI,mipsII,mipsIII,mipsIV:
2270 do_store (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET), COP_SW (ZZ, RT));
2275 :function:::void:do_store_left:unsigned access, address_word base, address_word offset, unsigned_word rt
2277 address_word mask = (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3);
2278 address_word reverseendian = (ReverseEndian ? -1 : 0);
2279 address_word bigendiancpu = (BigEndianCPU ? -1 : 0);
2289 vaddr = base + offset;
2290 AddressTranslation (vaddr, isDATA, isSTORE, &paddr, &uncached, isTARGET, isREAL);
2291 paddr = (paddr ^ (reverseendian & mask));
2292 if (BigEndianMem == 0)
2293 paddr = paddr & ~access;
2295 /* compute where within the word/mem we are */
2296 byte = ((vaddr ^ bigendiancpu) & access); /* 0..access */
2297 word = ((vaddr ^ bigendiancpu) & (mask & ~access)) / (access + 1); /* 0..1 */
2298 nr_lhs_bits = 8 * byte + 8;
2299 nr_rhs_bits = 8 * access - 8 * byte;
2300 /* nr_lhs_bits + nr_rhs_bits == 8 * (accesss + 1) */
2301 /* fprintf (stderr, "s[wd]l: 0x%08lx%08lx 0x%08lx%08lx %d:%d %d+%d\n",
2302 (long) ((unsigned64) vaddr >> 32), (long) vaddr,
2303 (long) ((unsigned64) paddr >> 32), (long) paddr,
2304 word, byte, nr_lhs_bits, nr_rhs_bits); */
2308 memval = (rt >> nr_rhs_bits);
2312 memval = (rt << nr_lhs_bits);
2314 /* fprintf (stderr, "s[wd]l: 0x%08lx%08lx -> 0x%08lx%08lx\n",
2315 (long) ((unsigned64) rt >> 32), (long) rt,
2316 (long) ((unsigned64) memval >> 32), (long) memval); */
2317 StoreMemory (uncached, byte, memval, 0, paddr, vaddr, isREAL);
2321 101010,5.BASE,5.RT,16.OFFSET:NORMAL:32::SWL
2322 "swl r<RT>, <OFFSET>(r<BASE>)"
2323 *mipsI,mipsII,mipsIII,mipsIV:
2328 do_store_left (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
2332 :function:::void:do_store_right:unsigned access, address_word base, address_word offset, unsigned_word rt
2334 address_word mask = (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3);
2335 address_word reverseendian = (ReverseEndian ? -1 : 0);
2336 address_word bigendiancpu = (BigEndianCPU ? -1 : 0);
2343 vaddr = base + offset;
2344 AddressTranslation (vaddr, isDATA, isSTORE, &paddr, &uncached, isTARGET, isREAL);
2345 paddr = (paddr ^ (reverseendian & mask));
2346 if (BigEndianMem != 0)
2348 byte = ((vaddr & mask) ^ (bigendiancpu & mask));
2349 memval = (rt << (byte * 8));
2350 StoreMemory (uncached, access - (access & byte), memval, 0, paddr, vaddr, isREAL);
2353 101110,5.BASE,5.RT,16.OFFSET:NORMAL:32::SWR
2354 "swr r<RT>, <OFFSET>(r<BASE>)"
2355 *mipsI,mipsII,mipsIII,mipsIV:
2360 do_store_right (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET), GPR[RT]);
2364 000000,000000000000000,5.STYPE,001111:SPECIAL:32::SYNC
2374 SyncOperation (STYPE);
2378 000000,20.CODE,001100:SPECIAL:32::SYSCALL
2380 *mipsI,mipsII,mipsIII,mipsIV:
2385 SignalException(SystemCall, instruction_0);
2389 000000,5.RS,5.RT,10.CODE,110100:SPECIAL:32::TEQ
2397 if ((signed_word) GPR[RS] == (signed_word) GPR[RT])
2398 SignalException(Trap, instruction_0);
2402 000001,5.RS,01100,16.IMMEDIATE:REGIMM:32::TEQI
2403 "teqi r<RS>, <IMMEDIATE>"
2410 if ((signed_word) GPR[RS] == (signed_word) EXTEND16 (IMMEDIATE))
2411 SignalException(Trap, instruction_0);
2415 000000,5.RS,5.RT,10.CODE,110000:SPECIAL:32::TGE
2423 if ((signed_word) GPR[RS] >= (signed_word) GPR[RT])
2424 SignalException(Trap, instruction_0);
2428 000001,5.RS,01000,16.IMMEDIATE:REGIMM:32::TGEI
2429 "tgei r<RS>, <IMMEDIATE>"
2436 if ((signed_word) GPR[RS] >= (signed_word) EXTEND16 (IMMEDIATE))
2437 SignalException(Trap, instruction_0);
2441 000001,5.RS,01001,16.IMMEDIATE:REGIMM:32::TGEIU
2442 "tgeiu r<RS>, <IMMEDIATE>"
2449 if ((unsigned_word) GPR[RS] >= (unsigned_word) EXTEND16 (IMMEDIATE))
2450 SignalException(Trap, instruction_0);
2454 000000,5.RS,5.RT,10.CODE,110001:SPECIAL:32::TGEU
2462 if ((unsigned_word) GPR[RS] >= (unsigned_word) GPR[RT])
2463 SignalException(Trap, instruction_0);
2467 000000,5.RS,5.RT,10.CODE,110010:SPECIAL:32::TLT
2475 if ((signed_word) GPR[RS] < (signed_word) GPR[RT])
2476 SignalException(Trap, instruction_0);
2480 000001,5.RS,01010,16.IMMEDIATE:REGIMM:32::TLTI
2481 "tlti r<RS>, <IMMEDIATE>"
2488 if ((signed_word) GPR[RS] < (signed_word) EXTEND16 (IMMEDIATE))
2489 SignalException(Trap, instruction_0);
2493 000001,5.RS,01011,16.IMMEDIATE:REGIMM:32::TLTIU
2494 "tltiu r<RS>, <IMMEDIATE>"
2501 if ((unsigned_word) GPR[RS] < (unsigned_word) EXTEND16 (IMMEDIATE))
2502 SignalException(Trap, instruction_0);
2506 000000,5.RS,5.RT,10.CODE,110011:SPECIAL:32::TLTU
2514 if ((unsigned_word) GPR[RS] < (unsigned_word) GPR[RT])
2515 SignalException(Trap, instruction_0);
2519 000000,5.RS,5.RT,10.CODE,110110:SPECIAL:32::TNE
2527 if ((signed_word) GPR[RS] != (signed_word) GPR[RT])
2528 SignalException(Trap, instruction_0);
2532 000001,5.RS,01110,16.IMMEDIATE:REGIMM:32::TNEI
2533 "tne r<RS>, <IMMEDIATE>"
2540 if ((signed_word) GPR[RS] != (signed_word) EXTEND16 (IMMEDIATE))
2541 SignalException(Trap, instruction_0);
2545 :function:::void:do_xor:int rs, int rt, int rd
2547 TRACE_ALU_INPUT2 (GPR[rs], GPR[rt]);
2548 GPR[rd] = GPR[rs] ^ GPR[rt];
2549 TRACE_ALU_RESULT (GPR[rd]);
2552 000000,5.RS,5.RT,5.RD,00000,100110:SPECIAL:32::XOR
2553 "xor r<RD>, r<RS>, r<RT>"
2554 *mipsI,mipsII,mipsIII,mipsIV:
2559 do_xor (SD_, RS, RT, RD);
2563 :function:::void:do_xori:int rs, int rt, unsigned16 immediate
2565 TRACE_ALU_INPUT2 (GPR[rs], immediate);
2566 GPR[rt] = GPR[rs] ^ immediate;
2567 TRACE_ALU_RESULT (GPR[rt]);
2570 001110,5.RS,5.RT,16.IMMEDIATE:NORMAL:32::XORI
2571 "xori r<RT>, r<RS>, <IMMEDIATE>"
2572 *mipsI,mipsII,mipsIII,mipsIV:
2577 do_xori (SD_, RS, RT, IMMEDIATE);
2582 // MIPS Architecture:
2584 // FPU Instruction Set (COP1 & COP1X)
2592 case fmt_single: return "s";
2593 case fmt_double: return "d";
2594 case fmt_word: return "w";
2595 case fmt_long: return "l";
2596 default: return "?";
2606 default: return "?";
2626 :%s::::COND:int cond
2630 case 00: return "f";
2631 case 01: return "un";
2632 case 02: return "eq";
2633 case 03: return "ueq";
2634 case 04: return "olt";
2635 case 05: return "ult";
2636 case 06: return "ole";
2637 case 07: return "ule";
2638 case 010: return "sf";
2639 case 011: return "ngle";
2640 case 012: return "seq";
2641 case 013: return "ngl";
2642 case 014: return "lt";
2643 case 015: return "nge";
2644 case 016: return "le";
2645 case 017: return "ngt";
2646 default: return "?";
2651 010001,10,3.FMT,00000,5.FS,5.FD,000101:COP1:32,f::ABS.fmt
2652 "abs.%s<FMT> f<FD>, f<FS>"
2653 *mipsI,mipsII,mipsIII,mipsIV:
2658 unsigned32 instruction = instruction_0;
2659 int destreg = ((instruction >> 6) & 0x0000001F);
2660 int fs = ((instruction >> 11) & 0x0000001F);
2661 int format = ((instruction >> 21) & 0x00000007);
2663 if ((format != fmt_single) && (format != fmt_double))
2664 SignalException(ReservedInstruction,instruction);
2666 StoreFPR(destreg,format,AbsoluteValue(ValueFPR(fs,format),format));
2672 010001,10,3.FMT,5.FT,5.FS,5.FD,000000:COP1:32,f::ADD.fmt
2673 "add.%s<FMT> f<FD>, f<FS>, f<FT>"
2674 *mipsI,mipsII,mipsIII,mipsIV:
2679 unsigned32 instruction = instruction_0;
2680 int destreg = ((instruction >> 6) & 0x0000001F);
2681 int fs = ((instruction >> 11) & 0x0000001F);
2682 int ft = ((instruction >> 16) & 0x0000001F);
2683 int format = ((instruction >> 21) & 0x00000007);
2685 if ((format != fmt_single) && (format != fmt_double))
2686 SignalException(ReservedInstruction, instruction);
2688 StoreFPR(destreg,format,Add(ValueFPR(fs,format),ValueFPR(ft,format),format));
2699 010001,01000,3.0,1.ND,1.TF,16.OFFSET:COP1S:32,f::BC1a
2700 "bc1%s<TF>%s<ND> <OFFSET>"
2701 *mipsI,mipsII,mipsIII:
2703 check_branch_bug ();
2704 TRACE_BRANCH_INPUT (PREVCOC1());
2705 if (PREVCOC1() == TF)
2707 address_word dest = NIA + (EXTEND16 (OFFSET) << 2);
2708 TRACE_BRANCH_RESULT (dest);
2709 mark_branch_bug (dest);
2714 TRACE_BRANCH_RESULT (0);
2715 NULLIFY_NEXT_INSTRUCTION ();
2719 TRACE_BRANCH_RESULT (NIA);
2723 010001,01000,3.CC,1.ND,1.TF,16.OFFSET:COP1S:32,f::BC1b
2724 "bc1%s<TF>%s<ND> <OFFSET>":CC == 0
2725 "bc1%s<TF>%s<ND> <CC>, <OFFSET>"
2731 check_branch_bug ();
2732 if (GETFCC(CC) == TF)
2734 address_word dest = NIA + (EXTEND16 (OFFSET) << 2);
2735 mark_branch_bug (dest);
2740 NULLIFY_NEXT_INSTRUCTION ();
2753 :function:::void:do_c_cond_fmt:int fmt, int ft, int fs, int cc, int cond, instruction_word insn
2755 if ((fmt != fmt_single) && (fmt != fmt_double))
2756 SignalException (ReservedInstruction, insn);
2763 unsigned64 ofs = ValueFPR (fs, fmt);
2764 unsigned64 oft = ValueFPR (ft, fmt);
2765 if (NaN (ofs, fmt) || NaN (oft, fmt))
2767 if (FCSR & FP_ENABLE (IO))
2769 FCSR |= FP_CAUSE (IO);
2770 SignalExceptionFPE ();
2778 less = Less (ofs, oft, fmt);
2779 equal = Equal (ofs, oft, fmt);
2782 condition = (((cond & (1 << 2)) && less)
2783 || ((cond & (1 << 1)) && equal)
2784 || ((cond & (1 << 0)) && unordered));
2785 SETFCC (cc, condition);
2789 010001,10,3.FMT,5.FT,5.FS,3.0,00,11,4.COND:COP1:32::C.cond.fmta
2790 "c.%s<COND>.%s<FMT> f<FS>, f<FT>"
2791 *mipsI,mipsII,mipsIII:
2793 do_c_cond_fmt (SD_, FMT, FT, FS, 0, COND, instruction_0);
2796 010001,10,3.FMT,5.FT,5.FS,3.CC,00,11,4.COND:COP1:32::C.cond.fmtb
2797 "c.%s<COND>.%s<FMT> f<FS>, f<FT>":CC == 0
2798 "c.%s<COND>.%s<FMT> <CC>, f<FS>, f<FT>"
2804 do_c_cond_fmt (SD_, FMT, FT, FS, CC, COND, instruction_0);
2808 010001,10,3.FMT,00000,5.FS,5.FD,001010:COP1:64::CEIL.L.fmt
2809 "ceil.l.%s<FMT> f<FD>, f<FS>"
2816 unsigned32 instruction = instruction_0;
2817 int destreg = ((instruction >> 6) & 0x0000001F);
2818 int fs = ((instruction >> 11) & 0x0000001F);
2819 int format = ((instruction >> 21) & 0x00000007);
2821 if ((format != fmt_single) && (format != fmt_double))
2822 SignalException(ReservedInstruction,instruction);
2824 StoreFPR(destreg,fmt_long,Convert(FP_RM_TOPINF,ValueFPR(fs,format),format,fmt_long));
2829 010001,10,3.FMT,00000,5.FS,5.FD,001110:COP1:32::CEIL.W
2837 unsigned32 instruction = instruction_0;
2838 int destreg = ((instruction >> 6) & 0x0000001F);
2839 int fs = ((instruction >> 11) & 0x0000001F);
2840 int format = ((instruction >> 21) & 0x00000007);
2842 if ((format != fmt_single) && (format != fmt_double))
2843 SignalException(ReservedInstruction,instruction);
2845 StoreFPR(destreg,fmt_word,Convert(FP_RM_TOPINF,ValueFPR(fs,format),format,fmt_word));
2852 010001,00,X,10,5.RT,5.FS,00000000000:COP1Sa:32::CxC1
2853 "c%s<X>c1 r<RT>, f<FS>"
2861 PENDING_FILL(FCR0IDX,VL4_8(GPR[RT]));
2863 PENDING_FILL(FCR31IDX,VL4_8(GPR[RT]));
2865 PENDING_SCHED(FCSR, FCR31 & (1<<23), 1, 23);
2868 { /* control from */
2870 PENDING_FILL(RT,SIGNEXTEND(FCR0,32));
2872 PENDING_FILL(RT,SIGNEXTEND(FCR31,32));
2876 010001,00,X,10,5.RT,5.FS,00000000000:COP1Sb:32::CxC1
2877 "c%s<X>c1 r<RT>, f<FS>"
2886 TRACE_ALU_INPUT1 (GPR[RT]);
2889 FCR0 = VL4_8(GPR[RT]);
2890 TRACE_ALU_RESULT (FCR0);
2894 FCR31 = VL4_8(GPR[RT]);
2895 SETFCC(0,((FCR31 & (1 << 23)) ? 1 : 0));
2896 TRACE_ALU_RESULT (FCR31);
2900 TRACE_ALU_RESULT0 ();
2905 { /* control from */
2908 TRACE_ALU_INPUT1 (FCR0);
2909 GPR[RT] = SIGNEXTEND (FCR0, 32);
2913 TRACE_ALU_INPUT1 (FCR31);
2914 GPR[RT] = SIGNEXTEND (FCR31, 32);
2916 TRACE_ALU_RESULT (GPR[RT]);
2923 // FIXME: Does not correctly differentiate between mips*
2925 010001,10,3.FMT,00000,5.FS,5.FD,100001:COP1:32::CVT.D.fmt
2926 "cvt.d.%s<FMT> f<FD>, f<FS>"
2927 *mipsI,mipsII,mipsIII,mipsIV:
2932 unsigned32 instruction = instruction_0;
2933 int destreg = ((instruction >> 6) & 0x0000001F);
2934 int fs = ((instruction >> 11) & 0x0000001F);
2935 int format = ((instruction >> 21) & 0x00000007);
2937 if ((format == fmt_double) | 0)
2938 SignalException(ReservedInstruction,instruction);
2940 StoreFPR(destreg,fmt_double,Convert(GETRM(),ValueFPR(fs,format),format,fmt_double));
2945 010001,10,3.FMT,00000,5.FS,5.FD,100101:COP1:64::CVT.L.fmt
2946 "cvt.l.%s<FMT> f<FD>, f<FS>"
2953 unsigned32 instruction = instruction_0;
2954 int destreg = ((instruction >> 6) & 0x0000001F);
2955 int fs = ((instruction >> 11) & 0x0000001F);
2956 int format = ((instruction >> 21) & 0x00000007);
2958 if ((format == fmt_long) | ((format == fmt_long) || (format == fmt_word)))
2959 SignalException(ReservedInstruction,instruction);
2961 StoreFPR(destreg,fmt_long,Convert(GETRM(),ValueFPR(fs,format),format,fmt_long));
2967 // FIXME: Does not correctly differentiate between mips*
2969 010001,10,3.FMT,00000,5.FS,5.FD,100000:COP1:32::CVT.S.fmt
2970 "cvt.s.%s<FMT> f<FD>, f<FS>"
2971 *mipsI,mipsII,mipsIII,mipsIV:
2976 unsigned32 instruction = instruction_0;
2977 int destreg = ((instruction >> 6) & 0x0000001F);
2978 int fs = ((instruction >> 11) & 0x0000001F);
2979 int format = ((instruction >> 21) & 0x00000007);
2981 if ((format == fmt_single) | 0)
2982 SignalException(ReservedInstruction,instruction);
2984 StoreFPR(destreg,fmt_single,Convert(GETRM(),ValueFPR(fs,format),format,fmt_single));
2989 010001,10,3.FMT,00000,5.FS,5.FD,100100:COP1:32::CVT.W.fmt
2990 "cvt.w.%s<FMT> f<FD>, f<FS>"
2991 *mipsI,mipsII,mipsIII,mipsIV:
2996 unsigned32 instruction = instruction_0;
2997 int destreg = ((instruction >> 6) & 0x0000001F);
2998 int fs = ((instruction >> 11) & 0x0000001F);
2999 int format = ((instruction >> 21) & 0x00000007);
3001 if ((format == fmt_word) | ((format == fmt_long) || (format == fmt_word)))
3002 SignalException(ReservedInstruction,instruction);
3004 StoreFPR(destreg,fmt_word,Convert(GETRM(),ValueFPR(fs,format),format,fmt_word));
3009 010001,10,3.FMT,5.FT,5.FS,5.FD,000011:COP1:32::DIV.fmt
3010 "div.%s<FMT> f<FD>, f<FS>, f<FT>"
3011 *mipsI,mipsII,mipsIII,mipsIV:
3016 unsigned32 instruction = instruction_0;
3017 int destreg = ((instruction >> 6) & 0x0000001F);
3018 int fs = ((instruction >> 11) & 0x0000001F);
3019 int ft = ((instruction >> 16) & 0x0000001F);
3020 int format = ((instruction >> 21) & 0x00000007);
3022 if ((format != fmt_single) && (format != fmt_double))
3023 SignalException(ReservedInstruction,instruction);
3025 StoreFPR(destreg,format,Divide(ValueFPR(fs,format),ValueFPR(ft,format),format));
3032 010001,00,X,01,5.RT,5.FS,00000000000:COP1Sa:64::DMxC1
3033 "dm%s<X>c1 r<RT>, f<FS>"
3038 if (SizeFGR() == 64)
3039 PENDING_FILL((FS + FGRIDX),GPR[RT]);
3040 else if ((FS & 0x1) == 0)
3042 PENDING_FILL(((FS + 1) + FGRIDX),VH4_8(GPR[RT]));
3043 PENDING_FILL((FS + FGRIDX),VL4_8(GPR[RT]));
3048 if (SizeFGR() == 64)
3049 PENDING_FILL(RT,FGR[FS]);
3050 else if ((FS & 0x1) == 0)
3051 PENDING_FILL(RT,(SET64HI(FGR[FS+1]) | FGR[FS]));
3054 if (STATE_VERBOSE_P(SD))
3056 "Warning: PC 0x%lx: semantic_DMxC1_COP1Sa 32-bit use of odd FPR number\n",
3058 PENDING_FILL(RT,SET64HI(0xDEADC0DE) | 0xBAD0BAD0);
3062 010001,00,X,01,5.RT,5.FS,00000000000:COP1Sb:64::DMxC1
3063 "dm%s<X>c1 r<RT>, f<FS>"
3071 if (SizeFGR() == 64)
3072 StoreFPR (FS, fmt_uninterpreted_64, GPR[RT]);
3073 else if ((FS & 0x1) == 0)
3074 StoreFPR (FS, fmt_uninterpreted_64, SET64HI (FGR[FS+1]) | FGR[FS]);
3078 if (SizeFGR() == 64)
3080 else if ((FS & 0x1) == 0)
3081 GPR[RT] = SET64HI (FGR[FS+1]) | FGR[FS];
3084 if (STATE_VERBOSE_P(SD))
3086 "Warning: PC 0x%lx: DMxC1 32-bit use of odd FPR number\n",
3088 GPR[RT] = SET64HI (0xDEADC0DE) | 0xBAD0BAD0;
3094 010001,10,3.FMT,00000,5.FS,5.FD,001011:COP1:64::FLOOR.L.fmt
3095 "floor.l.%s<FMT> f<FD>, f<FS>"
3102 unsigned32 instruction = instruction_0;
3103 int destreg = ((instruction >> 6) & 0x0000001F);
3104 int fs = ((instruction >> 11) & 0x0000001F);
3105 int format = ((instruction >> 21) & 0x00000007);
3107 if ((format != fmt_single) && (format != fmt_double))
3108 SignalException(ReservedInstruction,instruction);
3110 StoreFPR(destreg,fmt_long,Convert(FP_RM_TOMINF,ValueFPR(fs,format),format,fmt_long));
3115 010001,10,3.FMT,00000,5.FS,5.FD,001111:COP1:32::FLOOR.W.fmt
3116 "floor.w.%s<FMT> f<FD>, f<FS>"
3124 unsigned32 instruction = instruction_0;
3125 int destreg = ((instruction >> 6) & 0x0000001F);
3126 int fs = ((instruction >> 11) & 0x0000001F);
3127 int format = ((instruction >> 21) & 0x00000007);
3129 if ((format != fmt_single) && (format != fmt_double))
3130 SignalException(ReservedInstruction,instruction);
3132 StoreFPR(destreg,fmt_word,Convert(FP_RM_TOMINF,ValueFPR(fs,format),format,fmt_word));
3137 110101,5.BASE,5.FT,16.OFFSET:COP1:64::LDC1
3138 "ldc1 f<FT>, <OFFSET>(r<BASE>)"
3147 COP_LD (1, FT, do_load (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET)));
3151 010011,5.BASE,5.INDEX,5.0,5.FD,000001:COP1X:64::LDXC1
3152 "ldxc1 f<FD>, r<INDEX>(r<BASE>)"
3156 COP_LD (1, FD, do_load (SD_, AccessLength_DOUBLEWORD, GPR[BASE], GPR[INDEX]));
3161 110001,5.BASE,5.FT,16.OFFSET:COP1:32::LWC1
3162 "lwc1 f<FT>, <OFFSET>(r<BASE>)"
3163 *mipsI,mipsII,mipsIII,mipsIV:
3168 COP_LW (1, FT, do_load (SD_, AccessLength_WORD, GPR[BASE], EXTEND16 (OFFSET)));
3172 010011,5.BASE,5.INDEX,5.0,5.FD,000000:COP1X:32::LWXC1
3173 "lwxc1 f<FD>, r<INDEX>(r<BASE>)"
3177 COP_LW (1, FD, do_load (SD_, AccessLength_WORD, GPR[BASE], GPR[INDEX]));
3183 // FIXME: Not correct for mips*
3185 010011,5.FR,5.FT,5.FS,5.FD,100,001:COP1X:32,f::MADD.D
3186 "madd.d f<FD>, f<FR>, f<FS>, f<FT>"
3190 unsigned32 instruction = instruction_0;
3191 int destreg = ((instruction >> 6) & 0x0000001F);
3192 int fs = ((instruction >> 11) & 0x0000001F);
3193 int ft = ((instruction >> 16) & 0x0000001F);
3194 int fr = ((instruction >> 21) & 0x0000001F);
3196 StoreFPR(destreg,fmt_double,Add(Multiply(ValueFPR(fs,fmt_double),ValueFPR(ft,fmt_double),fmt_double),ValueFPR(fr,fmt_double),fmt_double));
3201 010011,5.FR,5.FT,5.FS,5.FD,100,000:COP1X:32,f::MADD.S
3202 "madd.s f<FD>, f<FR>, f<FS>, f<FT>"
3206 unsigned32 instruction = instruction_0;
3207 int destreg = ((instruction >> 6) & 0x0000001F);
3208 int fs = ((instruction >> 11) & 0x0000001F);
3209 int ft = ((instruction >> 16) & 0x0000001F);
3210 int fr = ((instruction >> 21) & 0x0000001F);
3212 StoreFPR(destreg,fmt_single,Add(Multiply(ValueFPR(fs,fmt_single),ValueFPR(ft,fmt_single),fmt_single),ValueFPR(fr,fmt_single),fmt_single));
3219 010001,00,X,00,5.RT,5.FS,00000000000:COP1Sa:32::MxC1
3220 "m%s<X>c1 r<RT>, f<FS>"
3227 if (SizeFGR() == 64)
3229 if (STATE_VERBOSE_P(SD))
3231 "Warning: PC 0x%lx: MTC1 not DMTC1 with 64 bit regs\n",
3233 PENDING_FILL ((FS + FGRIDX), (SET64HI(0xDEADC0DE) | VL4_8(GPR[RT])));
3236 PENDING_FILL ((FS + FGRIDX), VL4_8(GPR[RT]));
3239 PENDING_FILL (RT, SIGNEXTEND(FGR[FS],32));
3241 010001,00,X,00,5.RT,5.FS,00000000000:COP1Sb:32::MxC1
3242 "m%s<X>c1 r<RT>, f<FS>"
3251 StoreFPR (FS, fmt_uninterpreted_32, VL4_8 (GPR[RT]));
3253 GPR[RT] = SIGNEXTEND(FGR[FS],32);
3257 010001,10,3.FMT,00000,5.FS,5.FD,000110:COP1:32::MOV.fmt
3258 "mov.%s<FMT> f<FD>, f<FS>"
3259 *mipsI,mipsII,mipsIII,mipsIV:
3264 unsigned32 instruction = instruction_0;
3265 int destreg = ((instruction >> 6) & 0x0000001F);
3266 int fs = ((instruction >> 11) & 0x0000001F);
3267 int format = ((instruction >> 21) & 0x00000007);
3269 StoreFPR(destreg,format,ValueFPR(fs,format));
3276 000000,5.RS,3.CC,0,1.TF,5.RD,00000,000001:SPECIAL:32::MOVtf
3277 "mov%s<TF> r<RD>, r<RS>, <CC>"
3281 if (GETFCC(CC) == TF)
3288 010001,10,3.FMT,3.CC,0,1.TF,5.FS,5.FD,010001:COP1:32::MOVtf.fmt
3289 "mov%s<TF>.%s<FMT> f<FD>, f<FS>, <CC>"
3293 unsigned32 instruction = instruction_0;
3294 int format = ((instruction >> 21) & 0x00000007);
3296 if (GETFCC(CC) == TF)
3297 StoreFPR (FD, format, ValueFPR (FS, format));
3299 StoreFPR (FD, format, ValueFPR (FD, format));
3304 010001,10,3.FMT,5.RT,5.FS,5.FD,010011:COP1:32::MOVN.fmt
3305 "movn.%s<FMT> f<FD>, f<FS>, r<RT>"
3310 StoreFPR (FD, FMT, ValueFPR (FS, FMT));
3312 StoreFPR (FD, FMT, ValueFPR (FD, FMT));
3319 // MOVT.fmt see MOVtf.fmt
3323 010001,10,3.FMT,5.RT,5.FS,5.FD,010010:COP1:32::MOVZ.fmt
3324 "movz.%s<FMT> f<FD>, f<FS>, r<RT>"
3329 StoreFPR (FD, FMT, ValueFPR (FS, FMT));
3331 StoreFPR (FD, FMT, ValueFPR (FD, FMT));
3336 010011,5.FR,5.FT,5.FS,5.FD,101,001:COP1X:32::MSUB.D
3337 "msub.d f<FD>, f<FR>, f<FS>, f<FT>"
3341 unsigned32 instruction = instruction_0;
3342 int destreg = ((instruction >> 6) & 0x0000001F);
3343 int fs = ((instruction >> 11) & 0x0000001F);
3344 int ft = ((instruction >> 16) & 0x0000001F);
3345 int fr = ((instruction >> 21) & 0x0000001F);
3347 StoreFPR(destreg,fmt_double,Sub(Multiply(ValueFPR(fs,fmt_double),ValueFPR(ft,fmt_double),fmt_double),ValueFPR(fr,fmt_double),fmt_double));
3353 010011,5.FR,5.FT,5.FS,5.FD,101000:COP1X:32::MSUB.S
3354 "msub.s f<FD>, f<FR>, f<FS>, f<FT>"
3358 unsigned32 instruction = instruction_0;
3359 int destreg = ((instruction >> 6) & 0x0000001F);
3360 int fs = ((instruction >> 11) & 0x0000001F);
3361 int ft = ((instruction >> 16) & 0x0000001F);
3362 int fr = ((instruction >> 21) & 0x0000001F);
3364 StoreFPR(destreg,fmt_single,Sub(Multiply(ValueFPR(fs,fmt_single),ValueFPR(ft,fmt_single),fmt_single),ValueFPR(fr,fmt_single),fmt_single));
3372 010001,10,3.FMT,5.FT,5.FS,5.FD,000010:COP1:32::MUL.fmt
3373 "mul.%s<FMT> f<FD>, f<FS>, f<FT>"
3374 *mipsI,mipsII,mipsIII,mipsIV:
3379 unsigned32 instruction = instruction_0;
3380 int destreg = ((instruction >> 6) & 0x0000001F);
3381 int fs = ((instruction >> 11) & 0x0000001F);
3382 int ft = ((instruction >> 16) & 0x0000001F);
3383 int format = ((instruction >> 21) & 0x00000007);
3385 if ((format != fmt_single) && (format != fmt_double))
3386 SignalException(ReservedInstruction,instruction);
3388 StoreFPR(destreg,format,Multiply(ValueFPR(fs,format),ValueFPR(ft,format),format));
3393 010001,10,3.FMT,00000,5.FS,5.FD,000111:COP1:32::NEG.fmt
3394 "neg.%s<FMT> f<FD>, f<FS>"
3395 *mipsI,mipsII,mipsIII,mipsIV:
3400 unsigned32 instruction = instruction_0;
3401 int destreg = ((instruction >> 6) & 0x0000001F);
3402 int fs = ((instruction >> 11) & 0x0000001F);
3403 int format = ((instruction >> 21) & 0x00000007);
3405 if ((format != fmt_single) && (format != fmt_double))
3406 SignalException(ReservedInstruction,instruction);
3408 StoreFPR(destreg,format,Negate(ValueFPR(fs,format),format));
3414 010011,5.FR,5.FT,5.FS,5.FD,110001:COP1X:32::NMADD.D
3415 "nmadd.d f<FD>, f<FR>, f<FS>, f<FT>"
3419 unsigned32 instruction = instruction_0;
3420 int destreg = ((instruction >> 6) & 0x0000001F);
3421 int fs = ((instruction >> 11) & 0x0000001F);
3422 int ft = ((instruction >> 16) & 0x0000001F);
3423 int fr = ((instruction >> 21) & 0x0000001F);
3425 StoreFPR(destreg,fmt_double,Negate(Add(Multiply(ValueFPR(fs,fmt_double),ValueFPR(ft,fmt_double),fmt_double),ValueFPR(fr,fmt_double),fmt_double),fmt_double));
3431 010011,5.FR,5.FT,5.FS,5.FD,110000:COP1X:32::NMADD.S
3432 "nmadd.s f<FD>, f<FR>, f<FS>, f<FT>"
3436 unsigned32 instruction = instruction_0;
3437 int destreg = ((instruction >> 6) & 0x0000001F);
3438 int fs = ((instruction >> 11) & 0x0000001F);
3439 int ft = ((instruction >> 16) & 0x0000001F);
3440 int fr = ((instruction >> 21) & 0x0000001F);
3442 StoreFPR(destreg,fmt_single,Negate(Add(Multiply(ValueFPR(fs,fmt_single),ValueFPR(ft,fmt_single),fmt_single),ValueFPR(fr,fmt_single),fmt_single),fmt_single));
3448 010011,5.FR,5.FT,5.FS,5.FD,111001:COP1X:32::NMSUB.D
3449 "nmsub.d f<FD>, f<FR>, f<FS>, f<FT>"
3453 unsigned32 instruction = instruction_0;
3454 int destreg = ((instruction >> 6) & 0x0000001F);
3455 int fs = ((instruction >> 11) & 0x0000001F);
3456 int ft = ((instruction >> 16) & 0x0000001F);
3457 int fr = ((instruction >> 21) & 0x0000001F);
3459 StoreFPR(destreg,fmt_double,Negate(Sub(Multiply(ValueFPR(fs,fmt_double),ValueFPR(ft,fmt_double),fmt_double),ValueFPR(fr,fmt_double),fmt_double),fmt_double));
3465 010011,5.FR,5.FT,5.FS,5.FD,111000:COP1X:32::NMSUB.S
3466 "nmsub.s f<FD>, f<FR>, f<FS>, f<FT>"
3470 unsigned32 instruction = instruction_0;
3471 int destreg = ((instruction >> 6) & 0x0000001F);
3472 int fs = ((instruction >> 11) & 0x0000001F);
3473 int ft = ((instruction >> 16) & 0x0000001F);
3474 int fr = ((instruction >> 21) & 0x0000001F);
3476 StoreFPR(destreg,fmt_single,Negate(Sub(Multiply(ValueFPR(fs,fmt_single),ValueFPR(ft,fmt_single),fmt_single),ValueFPR(fr,fmt_single),fmt_single),fmt_single));
3481 010011,5.BASE,5.INDEX,5.HINT,00000001111:COP1X:32::PREFX
3482 "prefx <HINT>, r<INDEX>(r<BASE>)"
3486 unsigned32 instruction = instruction_0;
3487 int fs = ((instruction >> 11) & 0x0000001F);
3488 signed_word op2 = GPR[((instruction >> 16) & 0x0000001F)];
3489 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
3491 address_word vaddr = ((unsigned64)op1 + (unsigned64)op2);
3494 if (AddressTranslation(vaddr,isDATA,isLOAD,&paddr,&uncached,isTARGET,isREAL))
3495 Prefetch(uncached,paddr,vaddr,isDATA,fs);
3499 010001,10,3.FMT,00000,5.FS,5.FD,010101:COP1:32::RECIP.fmt
3500 "recip.%s<FMT> f<FD>, f<FS>"
3504 unsigned32 instruction = instruction_0;
3505 int destreg = ((instruction >> 6) & 0x0000001F);
3506 int fs = ((instruction >> 11) & 0x0000001F);
3507 int format = ((instruction >> 21) & 0x00000007);
3509 if ((format != fmt_single) && (format != fmt_double))
3510 SignalException(ReservedInstruction,instruction);
3512 StoreFPR(destreg,format,Recip(ValueFPR(fs,format),format));
3517 010001,10,3.FMT,00000,5.FS,5.FD,001000:COP1:64::ROUND.L.fmt
3518 "round.l.%s<FMT> f<FD>, f<FS>"
3525 unsigned32 instruction = instruction_0;
3526 int destreg = ((instruction >> 6) & 0x0000001F);
3527 int fs = ((instruction >> 11) & 0x0000001F);
3528 int format = ((instruction >> 21) & 0x00000007);
3530 if ((format != fmt_single) && (format != fmt_double))
3531 SignalException(ReservedInstruction,instruction);
3533 StoreFPR(destreg,fmt_long,Convert(FP_RM_NEAREST,ValueFPR(fs,format),format,fmt_long));
3538 010001,10,3.FMT,00000,5.FS,5.FD,001100:COP1:32::ROUND.W.fmt
3539 "round.w.%s<FMT> f<FD>, f<FS>"
3547 unsigned32 instruction = instruction_0;
3548 int destreg = ((instruction >> 6) & 0x0000001F);
3549 int fs = ((instruction >> 11) & 0x0000001F);
3550 int format = ((instruction >> 21) & 0x00000007);
3552 if ((format != fmt_single) && (format != fmt_double))
3553 SignalException(ReservedInstruction,instruction);
3555 StoreFPR(destreg,fmt_word,Convert(FP_RM_NEAREST,ValueFPR(fs,format),format,fmt_word));
3560 010001,10,3.FMT,00000,5.FS,5.FD,010110:COP1:32::RSQRT.fmt
3562 "rsqrt.%s<FMT> f<FD>, f<FS>"
3565 unsigned32 instruction = instruction_0;
3566 int destreg = ((instruction >> 6) & 0x0000001F);
3567 int fs = ((instruction >> 11) & 0x0000001F);
3568 int format = ((instruction >> 21) & 0x00000007);
3570 if ((format != fmt_single) && (format != fmt_double))
3571 SignalException(ReservedInstruction,instruction);
3573 StoreFPR(destreg,format,Recip(SquareRoot(ValueFPR(fs,format),format),format));
3578 111101,5.BASE,5.FT,16.OFFSET:COP1:64::SDC1
3579 "sdc1 f<FT>, <OFFSET>(r<BASE>)"
3588 do_store (SD_, AccessLength_DOUBLEWORD, GPR[BASE], EXTEND16 (OFFSET), COP_SD (1, FT));
3592 010011,5.BASE,5.INDEX,5.FS,00000001001:COP1X:64::SDXC1
3593 "ldxc1 f<FS>, r<INDEX>(r<BASE>)"
3597 do_store (SD_, AccessLength_DOUBLEWORD, GPR[BASE], GPR[INDEX], COP_SD (1, FS));
3601 010001,10,3.FMT,00000,5.FS,5.FD,000100:COP1:32::SQRT.fmt
3602 "sqrt.%s<FMT> f<FD>, f<FS>"
3610 unsigned32 instruction = instruction_0;
3611 int destreg = ((instruction >> 6) & 0x0000001F);
3612 int fs = ((instruction >> 11) & 0x0000001F);
3613 int format = ((instruction >> 21) & 0x00000007);
3615 if ((format != fmt_single) && (format != fmt_double))
3616 SignalException(ReservedInstruction,instruction);
3618 StoreFPR(destreg,format,(SquareRoot(ValueFPR(fs,format),format)));
3623 010001,10,3.FMT,5.FT,5.FS,5.FD,000001:COP1:32::SUB.fmt
3624 "sub.%s<FMT> f<FD>, f<FS>, f<FT>"
3625 *mipsI,mipsII,mipsIII,mipsIV:
3630 unsigned32 instruction = instruction_0;
3631 int destreg = ((instruction >> 6) & 0x0000001F);
3632 int fs = ((instruction >> 11) & 0x0000001F);
3633 int ft = ((instruction >> 16) & 0x0000001F);
3634 int format = ((instruction >> 21) & 0x00000007);
3636 if ((format != fmt_single) && (format != fmt_double))
3637 SignalException(ReservedInstruction,instruction);
3639 StoreFPR(destreg,format,Sub(ValueFPR(fs,format),ValueFPR(ft,format),format));
3645 111001,5.BASE,5.FT,16.OFFSET:COP1:32::SWC1
3646 "swc1 f<FT>, <OFFSET>(r<BASE>)"
3647 *mipsI,mipsII,mipsIII,mipsIV:
3652 unsigned32 instruction = instruction_0;
3653 signed_word offset = EXTEND16 (OFFSET);
3654 int destreg UNUSED = ((instruction >> 16) & 0x0000001F);
3655 signed_word op1 UNUSED = GPR[((instruction >> 21) & 0x0000001F)];
3657 address_word vaddr = ((uword64)op1 + offset);
3660 if ((vaddr & 3) != 0)
3662 SIM_CORE_SIGNAL (SD, CPU, cia, read_map, AccessLength_WORD+1, vaddr, write_transfer, sim_core_unaligned_signal);
3666 if (AddressTranslation(vaddr,isDATA,isSTORE,&paddr,&uncached,isTARGET,isREAL))
3669 uword64 memval1 = 0;
3670 uword64 mask = (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3);
3671 address_word reverseendian = (ReverseEndian ?(mask ^ AccessLength_WORD): 0);
3672 address_word bigendiancpu = (BigEndianCPU ?(mask ^ AccessLength_WORD): 0);
3674 paddr = ((paddr & ~mask) | ((paddr & mask) ^ reverseendian));
3675 byte = ((vaddr & mask) ^ bigendiancpu);
3676 memval = (((uword64)COP_SW(((instruction >> 26) & 0x3),destreg)) << (8 * byte));
3677 StoreMemory(uncached,AccessLength_WORD,memval,memval1,paddr,vaddr,isREAL);
3684 010011,5.BASE,5.INDEX,5.FS,00000,001000:COP1X:32::SWXC1
3685 "swxc1 f<FS>, r<INDEX>(r<BASE>)"
3689 unsigned32 instruction = instruction_0;
3690 int fs = ((instruction >> 11) & 0x0000001F);
3691 signed_word op2 = GPR[((instruction >> 16) & 0x0000001F)];
3692 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
3694 address_word vaddr = ((unsigned64)op1 + op2);
3697 if ((vaddr & 3) != 0)
3699 SIM_CORE_SIGNAL (SD, CPU, cia, read_map, 4, vaddr, write_transfer, sim_core_unaligned_signal);
3703 if (AddressTranslation(vaddr,isDATA,isSTORE,&paddr,&uncached,isTARGET,isREAL))
3705 unsigned64 memval = 0;
3706 unsigned64 memval1 = 0;
3707 unsigned64 mask = 0x7;
3709 paddr = ((paddr & ~mask) | ((paddr & mask) ^ (ReverseEndian << 2)));
3710 byte = ((vaddr & mask) ^ (BigEndianCPU << 2));
3711 memval = (((unsigned64)COP_SW(1,fs)) << (8 * byte));
3713 StoreMemory(uncached,AccessLength_WORD,memval,memval1,paddr,vaddr,isREAL);
3721 010001,10,3.FMT,00000,5.FS,5.FD,001001:COP1:64::TRUNC.L.fmt
3722 "trunc.l.%s<FMT> f<FD>, f<FS>"
3729 unsigned32 instruction = instruction_0;
3730 int destreg = ((instruction >> 6) & 0x0000001F);
3731 int fs = ((instruction >> 11) & 0x0000001F);
3732 int format = ((instruction >> 21) & 0x00000007);
3734 if ((format != fmt_single) && (format != fmt_double))
3735 SignalException(ReservedInstruction,instruction);
3737 StoreFPR(destreg,fmt_long,Convert(FP_RM_TOZERO,ValueFPR(fs,format),format,fmt_long));
3742 010001,10,3.FMT,00000,5.FS,5.FD,001101:COP1:32::TRUNC.W
3743 "trunc.w.%s<FMT> f<FD>, f<FS>"
3751 unsigned32 instruction = instruction_0;
3752 int destreg = ((instruction >> 6) & 0x0000001F);
3753 int fs = ((instruction >> 11) & 0x0000001F);
3754 int format = ((instruction >> 21) & 0x00000007);
3756 if ((format != fmt_single) && (format != fmt_double))
3757 SignalException(ReservedInstruction,instruction);
3759 StoreFPR(destreg,fmt_word,Convert(FP_RM_TOZERO,ValueFPR(fs,format),format,fmt_word));
3765 // MIPS Architecture:
3767 // System Control Instruction Set (COP0)
3771 010000,01000,00000,16.OFFSET:COP0:32::BC0F
3773 *mipsI,mipsII,mipsIII,mipsIV:
3777 010000,01000,00000,16.OFFSET:COP0:32::BC0F
3779 // stub needed for eCos as tx39 hardware bug workaround
3786 010000,01000,00010,16.OFFSET:COP0:32::BC0FL
3788 *mipsI,mipsII,mipsIII,mipsIV:
3793 010000,01000,00001,16.OFFSET:COP0:32::BC0T
3795 *mipsI,mipsII,mipsIII,mipsIV:
3799 010000,01000,00011,16.OFFSET:COP0:32::BC0TL
3801 *mipsI,mipsII,mipsIII,mipsIV:
3806 101111,5.BASE,5.OP,16.OFFSET:NORMAL:32::CACHE
3813 unsigned32 instruction = instruction_0;
3814 signed_word offset = SIGNEXTEND((signed_word)((instruction >> 0) & 0x0000FFFF),16);
3815 int hint = ((instruction >> 16) & 0x0000001F);
3816 signed_word op1 = GPR[((instruction >> 21) & 0x0000001F)];
3818 address_word vaddr = (op1 + offset);
3821 if (AddressTranslation(vaddr,isDATA,isLOAD,&paddr,&uncached,isTARGET,isREAL))
3822 CacheOp(hint,vaddr,paddr,instruction);
3827 010000,1,0000000000000000000,111001:COP0:32::DI
3829 *mipsI,mipsII,mipsIII,mipsIV:
3834 010000,00001,5.RT,5.RD,00000000000:COP0:64::DMFC0
3835 "dmfc0 r<RT>, r<RD>"
3838 DecodeCoproc (instruction_0);
3842 010000,00101,5.RT,5.RD,00000000000:COP0:64::DMTC0
3843 "dmtc0 r<RT>, r<RD>"
3846 DecodeCoproc (instruction_0);
3850 010000,1,0000000000000000000,111000:COP0:32::EI
3852 *mipsI,mipsII,mipsIII,mipsIV:
3857 010000,1,0000000000000000000,011000:COP0:32::ERET
3864 if (SR & status_ERL)
3866 /* Oops, not yet available */
3867 sim_io_printf (SD, "Warning: ERET when SR[ERL] set not supported");
3879 010000,00000,5.RT,5.RD,00000,6.REGX:COP0:32::MFC0
3880 "mfc0 r<RT>, r<RD> # <REGX>"
3881 *mipsI,mipsII,mipsIII,mipsIV:
3886 TRACE_ALU_INPUT0 ();
3887 DecodeCoproc (instruction_0);
3888 TRACE_ALU_RESULT (GPR[RT]);
3891 010000,00100,5.RT,5.RD,00000,6.REGX:COP0:32::MTC0
3892 "mtc0 r<RT>, r<RD> # <REGX>"
3893 *mipsI,mipsII,mipsIII,mipsIV:
3898 DecodeCoproc (instruction_0);
3902 010000,1,0000000000000000000,010000:COP0:32::RFE
3904 *mipsI,mipsII,mipsIII,mipsIV:
3909 DecodeCoproc (instruction_0);
3913 0100,ZZ!0!1!3,5.COP_FUN0!8,5.COP_FUN1,16.COP_FUN2:NORMAL:32::COPz
3914 "cop<ZZ> <COP_FUN0><COP_FUN1><COP_FUN2>"
3915 *mipsI,mipsII,mipsIII,mipsIV:
3919 DecodeCoproc (instruction_0);
3924 010000,1,0000000000000000000,001000:COP0:32::TLBP
3926 *mipsI,mipsII,mipsIII,mipsIV:
3931 010000,1,0000000000000000000,000001:COP0:32::TLBR
3933 *mipsI,mipsII,mipsIII,mipsIV:
3938 010000,1,0000000000000000000,000010:COP0:32::TLBWI
3940 *mipsI,mipsII,mipsIII,mipsIV:
3945 010000,1,0000000000000000000,000110:COP0:32::TLBWR
3947 *mipsI,mipsII,mipsIII,mipsIV: