From 41bbedc41d0cdf72c4393465ee7e52eb138a36c9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Jul 2020 00:14:46 +0200 Subject: [PATCH] UserspaceEmulator: Implement the LODSB/LODSW/LODSD instructions Look how nice they look with the new loop instruction helpers. :^) --- DevTools/UserspaceEmulator/SoftCPU.cpp | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index d65dcad0e6..207c878489 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -1369,9 +1369,32 @@ void SoftCPU::LGS_reg32_mem32(const X86::Instruction&) { TODO(); } void SoftCPU::LIDT(const X86::Instruction&) { TODO(); } void SoftCPU::LLDT_RM16(const X86::Instruction&) { TODO(); } void SoftCPU::LMSW_RM16(const X86::Instruction&) { TODO(); } -void SoftCPU::LODSB(const X86::Instruction&) { TODO(); } -void SoftCPU::LODSD(const X86::Instruction&) { TODO(); } -void SoftCPU::LODSW(const X86::Instruction&) { TODO(); } + +template +ALWAYS_INLINE static void do_lods(SoftCPU& cpu, const X86::Instruction& insn) +{ + auto src_segment = cpu.segment(insn.segment_prefix().value_or(X86::SegmentRegister::DS)); + cpu.do_once_or_repeat(insn, [&] { + auto src = cpu.read_memory({ src_segment, cpu.source_index(insn.a32()) }); + cpu.gpr(X86::RegisterAL) = src; + cpu.step_source_index(insn.a32(), sizeof(T)); + }); +} + +void SoftCPU::LODSB(const X86::Instruction& insn) +{ + do_lods(*this, insn); +} + +void SoftCPU::LODSD(const X86::Instruction& insn) +{ + do_lods(*this, insn); +} + +void SoftCPU::LODSW(const X86::Instruction& insn) +{ + do_lods(*this, insn); +} void SoftCPU::LOOPNZ_imm8(const X86::Instruction& insn) {