mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-19 16:08:02 +03:00
tests and handler fixes
This commit is contained in:
@ -3,15 +3,15 @@ namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FDIVR ST(i), ST instruction (DC F8-FF)
|
||||
/// Handler for FDIV ST(i), ST instruction (DC F8-FF)
|
||||
/// </summary>
|
||||
public class FdivrStiStHandler_FDIVStiSt : InstructionHandler
|
||||
public class FdivStiStHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FdivrStiStHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FdivrStiStHandler_FDIVStiSt(InstructionDecoder decoder)
|
||||
public FdivStiStHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
@ -23,7 +23,7 @@ public class FdivrStiStHandler_FDIVStiSt : InstructionHandler
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// FDIVR ST(i), ST is DC F8-FF
|
||||
// FDIV ST(i), ST is DC F8-FF
|
||||
if (opcode != 0xDC) return false;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -39,7 +39,7 @@ public class FdivrStiStHandler_FDIVStiSt : InstructionHandler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FDIVR ST(i), ST instruction
|
||||
/// Decodes a FDIV ST(i), ST instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
@ -55,7 +55,7 @@ public class FdivrStiStHandler_FDIVStiSt : InstructionHandler
|
||||
var stIndex = (FpuRegisterIndex)(Decoder.ReadByte() - 0xF8);
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fdivr;
|
||||
instruction.Type = InstructionType.Fdiv;
|
||||
|
||||
// Create the FPU register operands
|
||||
var stiOperand = OperandFactory.CreateFPURegisterOperand(stIndex);
|
||||
|
@ -3,15 +3,15 @@ namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FDIVRP ST(i), ST instruction (DE F8-FF)
|
||||
/// Handler for FDIVP ST(i), ST instruction (DE F8-FF)
|
||||
/// </summary>
|
||||
public class FdivrpStiStHandler_FDIVPStiSt : InstructionHandler
|
||||
public class FdivpStiStHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FdivrpStiStHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FdivrpStiStHandler_FDIVPStiSt(InstructionDecoder decoder)
|
||||
public FdivpStiStHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
@ -23,7 +23,7 @@ public class FdivrpStiStHandler_FDIVPStiSt : InstructionHandler
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// FDIVRP ST(i), ST is DE F8-FF
|
||||
// FDIVP ST(i), ST is DE F8-FF
|
||||
if (opcode != 0xDE) return false;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -39,7 +39,7 @@ public class FdivrpStiStHandler_FDIVPStiSt : InstructionHandler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FDIVRP ST(i), ST instruction
|
||||
/// Decodes a FDIVP ST(i), ST instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
@ -55,7 +55,7 @@ public class FdivrpStiStHandler_FDIVPStiSt : InstructionHandler
|
||||
var stIndex = (FpuRegisterIndex)(Decoder.ReadByte() - 0xF8);
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fdivrp;
|
||||
instruction.Type = InstructionType.Fdivp;
|
||||
|
||||
// Create the FPU register operands
|
||||
var stiOperand = OperandFactory.CreateFPURegisterOperand(stIndex);
|
||||
|
@ -3,15 +3,15 @@ namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FDIV ST(i), ST instruction (DC F0-F7)
|
||||
/// Handler for FDIVR ST(i), ST instruction (DC F0-F7)
|
||||
/// </summary>
|
||||
public class FdivStiStHandler_FDIVRStiSt : InstructionHandler
|
||||
public class FdivrStiStHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FdivStiStHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FdivStiStHandler_FDIVRStiSt(InstructionDecoder decoder)
|
||||
public FdivrStiStHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
@ -23,7 +23,7 @@ public class FdivStiStHandler_FDIVRStiSt : InstructionHandler
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// FDIV ST(i), ST is DC F0-F7
|
||||
// FDIVR ST(i), ST is DC F0-F7
|
||||
if (opcode != 0xDC) return false;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -39,7 +39,7 @@ public class FdivStiStHandler_FDIVRStiSt : InstructionHandler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FDIV ST(i), ST instruction
|
||||
/// Decodes a FDIVR ST(i), ST instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
@ -55,7 +55,7 @@ public class FdivStiStHandler_FDIVRStiSt : InstructionHandler
|
||||
var stIndex = (FpuRegisterIndex)(Decoder.ReadByte() - 0xF0);
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fdiv;
|
||||
instruction.Type = InstructionType.Fdivr;
|
||||
|
||||
// Create the FPU register operands
|
||||
var stiOperand = OperandFactory.CreateFPURegisterOperand(stIndex);
|
||||
|
@ -3,15 +3,15 @@ namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FDIVP ST(i), ST instruction (DE F0-F7)
|
||||
/// Handler for FDIVRP ST(i), ST instruction (DE F0-F7)
|
||||
/// </summary>
|
||||
public class FdivpStiStHandler_FDIVRPStiSt : InstructionHandler
|
||||
public class FdivrpStiStHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FdivpStiStHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FdivpStiStHandler_FDIVRPStiSt(InstructionDecoder decoder)
|
||||
public FdivrpStiStHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
@ -23,7 +23,7 @@ public class FdivpStiStHandler_FDIVRPStiSt : InstructionHandler
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// FDIVP ST(i), ST is DE F0-F7
|
||||
// FDIVRP ST(i), ST is DE F0-F7
|
||||
if (opcode != 0xDE) return false;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -39,7 +39,7 @@ public class FdivpStiStHandler_FDIVRPStiSt : InstructionHandler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FDIVP ST(i), ST instruction
|
||||
/// Decodes a FDIVRP ST(i), ST instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
@ -55,7 +55,7 @@ public class FdivpStiStHandler_FDIVRPStiSt : InstructionHandler
|
||||
var stIndex = (FpuRegisterIndex)(Decoder.ReadByte() - 0xF0);
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fdivp;
|
||||
instruction.Type = InstructionType.Fdivrp;
|
||||
|
||||
// Create the FPU register operands
|
||||
var stiOperand = OperandFactory.CreateFPURegisterOperand(stIndex);
|
||||
|
@ -0,0 +1,116 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Control;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FSTSW instruction (with WAIT prefix 0x9B)
|
||||
/// Handles both:
|
||||
/// - FSTSW AX (0x9B 0xDF 0xE0)
|
||||
/// - FSTSW m2byte (0x9B 0xDD /7)
|
||||
/// </summary>
|
||||
public class FstswHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FstswHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FstswHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// FSTSW starts with the WAIT prefix (0x9B)
|
||||
if (opcode != 0x9B) return false;
|
||||
|
||||
// Check if we can read the next byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the next byte is 0xDF (for FSTSW AX) or 0xDD (for FSTSW m2byte)
|
||||
|
||||
var (nextByte, modRM) = Decoder.PeakTwoBytes();
|
||||
|
||||
if (nextByte != 0xDF && nextByte != 0xDD)
|
||||
return false;
|
||||
|
||||
if (nextByte == 0xDF)
|
||||
{
|
||||
// For FSTSW AX, check if we can peek at the third byte and it's 0xE0
|
||||
|
||||
return modRM == 0xE0;
|
||||
}
|
||||
else // nextByte == 0xDD
|
||||
{
|
||||
// For FSTSW m2byte, check if we can peek at ModR/M byte and reg field = 7
|
||||
byte regField = ModRMDecoder.GetRegFromModRM(modRM);
|
||||
|
||||
// The reg field must be 7 for FSTSW m2byte
|
||||
return regField == 7;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes an FSTSW instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Skip the WAIT prefix (0x9B) - we already read it in CanHandle
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the second byte (0xDF for AX variant, 0xDD for memory variant)
|
||||
byte secondByte = Decoder.ReadByte();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fstsw;
|
||||
|
||||
if (secondByte == 0xDF)
|
||||
{
|
||||
// FSTSW AX variant
|
||||
// Read the 0xE0 byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte e0Byte = Decoder.ReadByte();
|
||||
if (e0Byte != 0xE0)
|
||||
return false;
|
||||
|
||||
// Create the AX register operand
|
||||
var axOperand = OperandFactory.CreateRegisterOperand(RegisterIndex.A, 16);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
axOperand
|
||||
];
|
||||
}
|
||||
else if (secondByte == 0xDD)
|
||||
{
|
||||
// FSTSW m2byte variant
|
||||
// Use ModRMDecoder to read and decode the ModR/M byte for 16-bit memory operand
|
||||
var (mod, reg, rm, memoryOperand) = ModRMDecoder.ReadModRM16();
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
memoryOperand
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -54,39 +54,15 @@ public class FildInt64Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, rawMemoryOperand) = ModRMDecoder.ReadModRM();
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM64();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fild;
|
||||
|
||||
// Create a 64-bit memory operand
|
||||
Operand memoryOperand;
|
||||
|
||||
if (rawMemoryOperand is DirectMemoryOperand directMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateDirectMemoryOperand(directMemory.Address, 64);
|
||||
}
|
||||
else if (rawMemoryOperand is BaseRegisterMemoryOperand baseMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateBaseRegisterMemoryOperand(baseMemory.BaseRegister, 64);
|
||||
}
|
||||
else if (rawMemoryOperand is DisplacementMemoryOperand dispMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateDisplacementMemoryOperand(dispMemory.BaseRegister, dispMemory.Displacement, 64);
|
||||
}
|
||||
else if (rawMemoryOperand is ScaledIndexMemoryOperand scaledMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateScaledIndexMemoryOperand(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement, 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
memoryOperand = rawMemoryOperand;
|
||||
}
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
memoryOperand
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
|
@ -54,39 +54,15 @@ public class FistpInt64Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, rawMemoryOperand) = ModRMDecoder.ReadModRM();
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM64();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fistp;
|
||||
|
||||
// Create a 64-bit memory operand
|
||||
Operand memoryOperand;
|
||||
|
||||
if (rawMemoryOperand is DirectMemoryOperand directMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateDirectMemoryOperand(directMemory.Address, 64);
|
||||
}
|
||||
else if (rawMemoryOperand is BaseRegisterMemoryOperand baseMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateBaseRegisterMemoryOperand(baseMemory.BaseRegister, 64);
|
||||
}
|
||||
else if (rawMemoryOperand is DisplacementMemoryOperand dispMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateDisplacementMemoryOperand(dispMemory.BaseRegister, dispMemory.Displacement, 64);
|
||||
}
|
||||
else if (rawMemoryOperand is ScaledIndexMemoryOperand scaledMemory)
|
||||
{
|
||||
memoryOperand = OperandFactory.CreateScaledIndexMemoryOperand(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement, 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
memoryOperand = rawMemoryOperand;
|
||||
}
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
memoryOperand
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
|
@ -52,7 +52,7 @@ public class FldFloat64Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte using the specialized FPU method
|
||||
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
|
||||
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu64();
|
||||
|
||||
// Verify reg field is 0 (FLD)
|
||||
if (reg != 0)
|
||||
|
@ -52,7 +52,7 @@ public class FstFloat64Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte using the specialized FPU method
|
||||
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
|
||||
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu64();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fst;
|
||||
|
@ -52,7 +52,7 @@ public class FstpFloat64Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte using the specialized FPU method
|
||||
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
|
||||
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu64();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fstp;
|
||||
|
@ -418,6 +418,7 @@ public class InstructionHandlerFactory
|
||||
|
||||
// Other floating point handlers
|
||||
_handlers.Add(new FloatingPoint.Control.FnstswHandler(_decoder)); // FNSTSW AX (DF E0)
|
||||
_handlers.Add(new FloatingPoint.Control.FstswHandler(_decoder)); // FSTSW AX (9B DF E0)
|
||||
|
||||
// DB opcode handlers (int32 operations and extended precision)
|
||||
_handlers.Add(new FloatingPoint.LoadStore.FildInt32Handler(_decoder)); // FILD int32 (DB /0)
|
||||
|
Reference in New Issue
Block a user