1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

UserspaceEmulator: Implement MOV_seg_RM32 and MOV_seg_RM16

This allows hosted programs to write to segment registers. :^)
This commit is contained in:
Andreas Kling 2022-12-06 17:31:52 +01:00
parent bd1f39ebaa
commit 661a940ddd
2 changed files with 20 additions and 2 deletions

View file

@ -2153,8 +2153,24 @@ void SoftCPU::MOV_reg8_imm8(const X86::Instruction& insn)
gpr8(insn.reg8()) = shadow_wrap_as_initialized(insn.imm8());
}
void SoftCPU::MOV_seg_RM16(const X86::Instruction&) { TODO_INSN(); }
void SoftCPU::MOV_seg_RM32(const X86::Instruction&) { TODO_INSN(); }
void SoftCPU::write_segment_register(X86::SegmentRegister segment_register, ValueWithShadow<u16> value)
{
// FIXME: Validate the segment selector and raise exception if necessary.
// FIXME: Complain if uninitialized data is moved into a segment register.
m_segment[to_underlying(segment_register)] = value.value();
}
void SoftCPU::MOV_seg_RM16(X86::Instruction const& insn)
{
write_segment_register(insn.segment_register(), insn.modrm().read16(*this, insn));
}
void SoftCPU::MOV_seg_RM32(X86::Instruction const& insn)
{
// NOTE: This instruction performs a 32-bit read but only the bottom 16 bits are used since segment registers are 16-bit.
auto value = insn.modrm().read32(*this, insn);
write_segment_register(insn.segment_register(), ValueWithShadow<u16>(value.value(), value.shadow_as_value()));
}
void SoftCPU::MUL_RM16(const X86::Instruction& insn)
{