diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-15 01:31:57 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-15 13:42:15 +0200 |
commit | 400a252720c0ff998fb60aa78e3a04ff21627033 (patch) | |
tree | 79e4133530e7330d36137e6482ae95145142cb5f /DevTools | |
parent | 036ce64cef03d926d45d7285769fbd353d10a291 (diff) | |
download | serenity-400a252720c0ff998fb60aa78e3a04ff21627033.zip |
UserspaceEmulator: Implement the CBW/CDQ/CWD/CWDE instructions
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/UserspaceEmulator/SoftCPU.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index 92701147dc..9670aa8274 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -763,8 +763,18 @@ void SoftCPU::CALL_imm32(const X86::Instruction& insn) set_eip(eip() + (i32)insn.imm32()); } -void SoftCPU::CBW(const X86::Instruction&) { TODO(); } -void SoftCPU::CDQ(const X86::Instruction&) { TODO(); } +void SoftCPU::CBW(const X86::Instruction&) +{ + set_ah((al() & 0x80) ? 0xff : 0x00); +} + +void SoftCPU::CDQ(const X86::Instruction&) +{ + if (eax() & 0x80000000) + set_edx(0xffffffff); + else + set_edx(0x00000000); +} void SoftCPU::CLC(const X86::Instruction&) { @@ -833,8 +843,17 @@ void SoftCPU::CMPXCHG_RM8_reg8(const X86::Instruction& insn) } void SoftCPU::CPUID(const X86::Instruction&) { TODO(); } -void SoftCPU::CWD(const X86::Instruction&) { TODO(); } -void SoftCPU::CWDE(const X86::Instruction&) { TODO(); } + +void SoftCPU::CWD(const X86::Instruction&) +{ + set_dx((ax() & 0x8000) ? 0xffff : 0x0000); +} + +void SoftCPU::CWDE(const X86::Instruction&) +{ + set_eax(sign_extended_to<u32>(ax())); +} + void SoftCPU::DAA(const X86::Instruction&) { TODO(); } void SoftCPU::DAS(const X86::Instruction&) { TODO(); } |