From f70f5307220d80526bd3f12d86966156f4ec6752 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Jul 2020 00:15:36 +0200 Subject: [PATCH] UserspaceEmulator: Implement the SCASB/SCASW/SCASD instructions --- DevTools/UserspaceEmulator/SoftCPU.cpp | 28 +++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index 207c878489..7d6f8dfcd6 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -2014,9 +2014,31 @@ static T op_sar(SoftCPU& cpu, T data, u8 steps) DEFINE_GENERIC_SHIFT_ROTATE_INSN_HANDLERS(SAR, op_sar) -void SoftCPU::SCASB(const X86::Instruction&) { TODO(); } -void SoftCPU::SCASD(const X86::Instruction&) { TODO(); } -void SoftCPU::SCASW(const X86::Instruction&) { TODO(); } +template +ALWAYS_INLINE static void do_scas(SoftCPU& cpu, const X86::Instruction& insn) +{ + cpu.do_once_or_repeat(insn, [&] { + auto src = cpu.gpr(X86::RegisterAL); + auto dest = cpu.read_memory({ cpu.es(), cpu.destination_index(insn.a32()) }); + op_sub(cpu, dest, src); + cpu.step_destination_index(insn.a32(), sizeof(T)); + }); +} + +void SoftCPU::SCASB(const X86::Instruction& insn) +{ + do_scas(*this, insn); +} + +void SoftCPU::SCASD(const X86::Instruction& insn) +{ + do_scas(*this, insn); +} + +void SoftCPU::SCASW(const X86::Instruction& insn) +{ + do_scas(*this, insn); +} void SoftCPU::SETcc_RM8(const X86::Instruction& insn) {