Index: src/mips/simulator-mips.cc |
diff --git a/src/mips/simulator-mips.cc b/src/mips/simulator-mips.cc |
index 07cfcff5b4813e7d16276009b2ca7c3ca182b8f8..71dcda276646a2bed2257d4d2166b40f82b1a8d2 100644 |
--- a/src/mips/simulator-mips.cc |
+++ b/src/mips/simulator-mips.cc |
@@ -3833,12 +3833,51 @@ void Simulator::DecodeTypeRegisterSPECIAL3() { |
alu_out = static_cast<int32_t>(output); |
break; |
} |
- case SEB: |
- case SEH: |
- case WSBH: |
- alu_out = 0x12345678; |
- UNREACHABLE(); |
+ case SEB: { |
+ uint8_t input = static_cast<uint8_t>(rt()); |
+ uint32_t output = input; |
+ uint32_t mask = 0x00000080; |
+ |
+ // Extending sign |
+ if (mask & input) { |
+ output |= 0xFFFFFF00; |
+ } |
+ |
+ alu_out = static_cast<int32_t>(output); |
break; |
+ } |
+ case SEH: { |
+ uint16_t input = static_cast<uint16_t>(rt()); |
+ uint32_t output = input; |
+ uint32_t mask = 0x00008000; |
+ |
+ // Extending sign |
+ if (mask & input) { |
+ output |= 0xFFFF0000; |
+ } |
+ |
+ alu_out = static_cast<int32_t>(output); |
+ break; |
+ } |
+ case WSBH: { |
+ uint32_t input = static_cast<uint32_t>(rt()); |
+ uint32_t output = 0; |
+ |
+ uint32_t mask = 0xFF000000; |
+ for (int i = 0; i < 4; i++) { |
+ uint32_t tmp = mask & input; |
+ if (i % 2 == 0) { |
+ tmp = tmp >> 8; |
+ } else { |
+ tmp = tmp << 8; |
+ } |
+ output = output | tmp; |
+ mask = mask >> 8; |
+ } |
+ |
+ alu_out = static_cast<int32_t>(output); |
+ break; |
+ } |
default: { |
const uint8_t bp = get_instr()->Bp2Value(); |
sa >>= kBp2Bits; |