From 6bbc6fef9a638c70f498c3b0dc7a127b81421e77 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Wed, 16 Oct 2013 03:44:06 +0000 Subject: [PATCH] [SOFT386] Allow the DS segment to overriden in LODS, MOVS and CMPS. svn path=/branches/ntvdm/; revision=60689 --- lib/soft386/opcodes.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/soft386/opcodes.c b/lib/soft386/opcodes.c index 8f7488b392d..5acac3d2e85 100644 --- a/lib/soft386/opcodes.c +++ b/lib/soft386/opcodes.c @@ -6080,6 +6080,7 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeMovs) { ULONG Data, DataSize; BOOLEAN OperandSize, AddressSize; + SOFT386_SEG_REGS Segment = SOFT386_REG_DS; OperandSize = AddressSize = State->SegmentRegs[SOFT386_REG_CS].Size; @@ -6098,6 +6099,12 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeMovs) AddressSize = !AddressSize; } + if (State->PrefixFlags & SOFT386_PREFIX_SEG) + { + /* Use the override segment instead of DS */ + Segment = State->SegmentOverride; + } + /* Calculate the size */ if (Opcode == 0xA4) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT); @@ -6148,7 +6155,7 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeMovs) /* Read from memory */ if (!Soft386ReadMemory(State, - SOFT386_REG_DS, + Segment, AddressSize ? State->GeneralRegs[SOFT386_REG_ESI].Long : State->GeneralRegs[SOFT386_REG_ESI].LowWord, FALSE, @@ -6267,6 +6274,7 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeCmps) ULONG FirstValue = 0, SecondValue = 0, Result; ULONG DataSize, DataMask, SignFlag; BOOLEAN OperandSize, AddressSize; + SOFT386_SEG_REGS Segment = SOFT386_REG_DS; OperandSize = AddressSize = State->SegmentRegs[SOFT386_REG_CS].Size; @@ -6285,12 +6293,10 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeCmps) AddressSize = !AddressSize; } - if ((State->PrefixFlags & SOFT386_PREFIX_REP) - || (State->PrefixFlags & SOFT386_PREFIX_REPNZ)) + if (State->PrefixFlags & SOFT386_PREFIX_SEG) { - // TODO: The REP/REPZ/REPNZ prefixes need to be implemented! - Soft386Exception(State, SOFT386_EXCEPTION_UD); - return FALSE; + /* Use the override segment instead of DS */ + Segment = State->SegmentOverride; } /* Calculate the size */ @@ -6303,7 +6309,7 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeCmps) /* Read from the first source operand */ if (!Soft386ReadMemory(State, - SOFT386_REG_DS, + Segment, AddressSize ? State->GeneralRegs[SOFT386_REG_ESI].Long : State->GeneralRegs[SOFT386_REG_ESI].LowWord, FALSE, @@ -6553,6 +6559,7 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeLods) { ULONG DataSize; BOOLEAN OperandSize, AddressSize; + SOFT386_SEG_REGS Segment = SOFT386_REG_DS; OperandSize = AddressSize = State->SegmentRegs[SOFT386_REG_CS].Size; @@ -6571,6 +6578,12 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeLods) AddressSize = !AddressSize; } + if (State->PrefixFlags & SOFT386_PREFIX_SEG) + { + /* Use the override segment instead of DS */ + Segment = State->SegmentOverride; + } + /* Calculate the size */ if (Opcode == 0xAC) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT); @@ -6598,7 +6611,7 @@ SOFT386_OPCODE_HANDLER(Soft386OpcodeLods) /* Read from the source operand */ if (!Soft386ReadMemory(State, - SOFT386_REG_DS, + Segment, AddressSize ? State->GeneralRegs[SOFT386_REG_ESI].Long : State->GeneralRegs[SOFT386_REG_ESI].LowWord, FALSE,