From 081a2acd61381a1baa05d5521a62a2717c7111b7 Mon Sep 17 00:00:00 2001
From: Thomas Harte <thomas.harte@gmail.com>
Date: Wed, 9 Mar 2022 09:33:25 -0500
Subject: [PATCH] Fix shift group operand size.

---
 InstructionSets/x86/Decoder.cpp               |  2 +-
 .../Mac/Clock SignalTests/x86DecoderTests.mm  | 20 ++++++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/InstructionSets/x86/Decoder.cpp b/InstructionSets/x86/Decoder.cpp
index 3a18a11e5..ade1820c0 100644
--- a/InstructionSets/x86/Decoder.cpp
+++ b/InstructionSets/x86/Decoder.cpp
@@ -337,7 +337,7 @@ std::pair<int, typename Decoder<model>::InstructionT> Decoder<model>::decode(con
 				RequiresMin(i80186);
 				ShiftGroup();
 				source_ = Source::Immediate;
-				operand_size_ = operation_size_;
+				operand_size_ = DataSize::Byte;
 			break;
 			case 0xc2: RegData(RETN, None, data_size_);				break;
 			case 0xc3: Complete(RETN, None, None, DataSize::None);	break;
diff --git a/OSBindings/Mac/Clock SignalTests/x86DecoderTests.mm b/OSBindings/Mac/Clock SignalTests/x86DecoderTests.mm
index f89bdb0fa..6f2698ae9 100644
--- a/OSBindings/Mac/Clock SignalTests/x86DecoderTests.mm	
+++ b/OSBindings/Mac/Clock SignalTests/x86DecoderTests.mm	
@@ -426,7 +426,7 @@ std::vector<typename InstructionSet::x86::Decoder<model>::InstructionT> decode(c
 	//movs   DWORD PTR es:[edi],DWORD PTR ds:[esi]
 	//jns    0x00000035 (from 0x42)
 	//jge    0x00000060 (from 0x44)
-	test(instructions[24], DataSize::Word, Operation::POP, Source::DS, Source::DS);
+	test(instructions[24], DataSize::Word, Operation::POP, Source::None, Source::DS);
 	test(instructions[25], DataSize::DWord, Operation::MOVS);
 	test(instructions[26], Operation::JNS, 0, -0xd);
 	test(instructions[27], Operation::JNL, 0, 0x1c);
@@ -440,22 +440,32 @@ std::vector<typename InstructionSet::x86::Decoder<model>::InstructionT> decode(c
 	test(instructions[30], DataSize::DWord, Operation::PUSH, Source::eDX);
 	test(instructions[31], Operation::INT, 0xc4);
 
-	//jmp    0x29cf120d
+	//jmp    0x29cf120d (from 0x53)
 	//or     DWORD PTR [esi+0x1a],eax
 	//rcr    BYTE PTR [ebp-0x78],0x34
 	//movs   DWORD PTR es:[edi],DWORD PTR ds:[esi]
-	test(instructions[32], Operation::JMPN, 0x29cf120d);
-	test(instructions[33], Operation::OR, DataSize::DWord, Source::eAX, ScaleIndexBase(Source::eSI), 0, 0x1a);
+	test(instructions[32], Operation::JMPN, 0x29cf120d - 0x53);
+//	XCTAssertEqual(instructions[32].source(), Source::None);
+	test(instructions[33], DataSize::DWord, Operation::OR, Source::eAX, ScaleIndexBase(Source::eSI), 0, 0x1a);
+	test(instructions[34], DataSize::Byte, Operation::RCR, Source::Immediate, ScaleIndexBase(Source::eBP), 0x34, -0x78);
+	test(instructions[35], DataSize::DWord, Operation::MOVS);
 
 	//and    edx,0xffffffd0
 	//cmc
 	//inc    esp
 	//popf
+	test(instructions[36], DataSize::DWord, Operation::AND, Source::Immediate, Source::eDX);
+	test(instructions[37], DataSize::None, Operation::CMC);
+	test(instructions[38], DataSize::DWord, Operation::INC, Source::eSP);
+	test(instructions[39], DataSize::DWord, Operation::POPF);
+
 	//movs   DWORD PTR es:[edi],DWORD PTR ds:[esi]
-	// Note to self: divergance at or just after here.
 	//rcr    DWORD PTR [esi+0x4f],0x7
 	//push   ecx
 	//aam    0xed
+	test(instructions[40], DataSize::DWord, Operation::MOVS);
+	test(instructions[41], DataSize::DWord, Operation::RCR, Source::Immediate, ScaleIndexBase(Source::eSI), 0x07, 0x4f);
+
 	//mov    al,0x69
 	//xlat   BYTE PTR ds:[ebx]
 	//add    ch,al