From a424208399288be8cb961d802b9415c827550f35 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 12 Jul 2020 14:53:19 +0200 Subject: [PATCH] UserspaceEmulator: Implement DIV_RM32 Not using inline assembly for this one since flags are undefined after a DIV instruction anyway. --- 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 0fe312b81c..1575c01ee5 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -804,7 +804,25 @@ void SoftCPU::DEC_reg32(const X86::Instruction& insn) } void SoftCPU::DIV_RM16(const X86::Instruction&) { TODO(); } -void SoftCPU::DIV_RM32(const X86::Instruction&) { TODO(); } + +void SoftCPU::DIV_RM32(const X86::Instruction& insn) +{ + auto divisor = insn.modrm().read32(*this, insn); + if (divisor == 0) { + warn() << "Divide by zero"; + TODO(); + } + u64 dividend = ((u64)edx() << 32) | eax(); + auto result = dividend / divisor; + if (result > NumericLimits::max()) { + warn() << "Divide overflow"; + TODO(); + } + + set_eax(result); + set_edx(dividend % divisor); +} + void SoftCPU::DIV_RM8(const X86::Instruction&) { TODO(); } void SoftCPU::ENTER16(const X86::Instruction&) { TODO(); } void SoftCPU::ENTER32(const X86::Instruction&) { TODO(); }