From 078186809262ca9e5bf696934ff0c61f924bde11 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 15 Jul 2020 01:37:16 +0200 Subject: [PATCH] UserspaceEmulator: Implement IDIV_RM32 --- DevTools/UserspaceEmulator/SoftCPU.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index 9670aa8274..e20a2bbcef 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -908,7 +908,25 @@ void SoftCPU::ENTER32(const X86::Instruction&) { TODO(); } void SoftCPU::ESCAPE(const X86::Instruction&) { TODO(); } void SoftCPU::HLT(const X86::Instruction&) { TODO(); } void SoftCPU::IDIV_RM16(const X86::Instruction&) { TODO(); } -void SoftCPU::IDIV_RM32(const X86::Instruction&) { TODO(); } + +void SoftCPU::IDIV_RM32(const X86::Instruction& insn) +{ + auto divisor = insn.modrm().read32(*this, insn); + if (divisor == 0) { + warn() << "Divide by zero"; + TODO(); + } + i64 dividend = ((i64)edx() << 32) | eax(); + auto result = dividend / divisor; + if (result > NumericLimits::max()) { + warn() << "Divide overflow"; + TODO(); + } + + set_eax(result); + set_edx(dividend % divisor); +} + void SoftCPU::IDIV_RM8(const X86::Instruction&) { TODO(); } void SoftCPU::IMUL_RM16(const X86::Instruction&) { TODO(); } void SoftCPU::IMUL_RM32(const X86::Instruction&) { TODO(); }