0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 08:18:36 +03:00

Refactor floating point handlers to use ReadModRMFpu method

This commit is contained in:
bird_egop
2025-04-17 23:33:56 +03:00
parent df453b930f
commit 963248dca0
15 changed files with 1164 additions and 9 deletions

View File

@ -0,0 +1,91 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FADD float32 instruction (D8 /0)
/// </summary>
public class FaddFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FaddFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FaddFloat32Handler(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)
{
// FADD is D8 /0
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 0
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 0;
}
/// <summary>
/// Decodes a FADD float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Verify reg field is 0 (FADD)
if (reg != 0)
{
return false;
}
// Set the instruction type
instruction.Type = InstructionType.Fadd;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,91 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FADD float64 instruction (DC /0)
/// </summary>
public class FaddFloat64Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FaddFloat64Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FaddFloat64Handler(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)
{
// FADD is DC /0
if (opcode != 0xDC) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 0
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 0;
}
/// <summary>
/// Decodes a FADD float64 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Verify reg field is 0 (FADD)
if (reg != 0)
{
return false;
}
// Set the instruction type
instruction.Type = InstructionType.Fadd;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM64
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For DC C0-DC FF, the operands are reversed: ST(i), ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
// Set the structured operands
instruction.StructuredOperands =
[
stiOperand,
st0Operand
];
}
return true;
}
}

View File

@ -0,0 +1,85 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FCOM float32 instruction (D8 /2)
/// </summary>
public class FcomFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FcomFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FcomFloat32Handler(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)
{
// FCOM is D8 /2
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 2
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 2;
}
/// <summary>
/// Decodes a FCOM float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fcom;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,85 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FCOMP float32 instruction (D8 /3)
/// </summary>
public class FcompFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FcompFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FcompFloat32Handler(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)
{
// FCOMP is D8 /3
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 3
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 3;
}
/// <summary>
/// Decodes a FCOMP float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fcomp;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,85 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FDIV float32 instruction (D8 /6)
/// </summary>
public class FdivFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FdivFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FdivFloat32Handler(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)
{
// FDIV is D8 /6
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 6
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 6;
}
/// <summary>
/// Decodes a FDIV float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fdiv;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,85 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FDIVR float32 instruction (D8 /7)
/// </summary>
public class FdivrFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FdivrFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FdivrFloat32Handler(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)
{
// FDIVR is D8 /7
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 7
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 7;
}
/// <summary>
/// Decodes a FDIVR float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fdivr;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,89 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FLD float32 instruction (D9 /0)
/// </summary>
public class FldFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FldFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FldFloat32Handler(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)
{
// FLD is D9 /0
if (opcode != 0xD9) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 0
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 0;
}
/// <summary>
/// Decodes an FLD float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Verify reg field is 0 (FLD)
if (reg != 0)
{
return false;
}
// Set the instruction type
instruction.Type = InstructionType.Fld;
// Handle based on addressing mode
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands with mod=3, this is FLD ST(i)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,87 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FMUL float32 instruction (D8 /1)
/// </summary>
public class FmulFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FmulFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FmulFloat32Handler(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)
{
// FMUL is D8 /1
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 1
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 1;
}
/// <summary>
/// Decodes a FMUL float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fmul;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
// Set the structured operands
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,85 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FMUL float64 instruction (DC /1)
/// </summary>
public class FmulFloat64Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FmulFloat64Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FmulFloat64Handler(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)
{
// FMUL is DC /1
if (opcode != 0xDC) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 1
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 1;
}
/// <summary>
/// Decodes a FMUL float64 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fmul;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM64
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For DC C0-DC FF, the operands are reversed: ST(i), ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
// Set the structured operands
instruction.StructuredOperands =
[
stiOperand,
st0Operand
];
}
return true;
}
}

View File

@ -0,0 +1,83 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FST float32 instruction (D9 /2)
/// </summary>
public class FstFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FstFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FstFloat32Handler(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)
{
// FST is D9 /2
if (opcode != 0xD9) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 2
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 2;
}
/// <summary>
/// Decodes an FST float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fst;
// Handle based on addressing mode
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands with mod=3, this is FST ST(i)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,83 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FSTP float32 instruction (D9 /3)
/// </summary>
public class FstpFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FstpFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FstpFloat32Handler(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)
{
// FSTP is D9 /3
if (opcode != 0xD9) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 3
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 3;
}
/// <summary>
/// Decodes an FSTP float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fstp;
// Handle based on addressing mode
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands with mod=3, this is FSTP ST(i)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,85 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FSUB float32 instruction (D8 /4)
/// </summary>
public class FsubFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FsubFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FsubFloat32Handler(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)
{
// FSUB is D8 /4
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 4
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 4;
}
/// <summary>
/// Decodes a FSUB float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fsub;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}

View File

@ -0,0 +1,85 @@
namespace X86Disassembler.X86.Handlers.FloatingPoint;
using Operands;
/// <summary>
/// Handler for FSUBR float32 instruction (D8 /5)
/// </summary>
public class FsubrFloat32Handler : InstructionHandler
{
/// <summary>
/// Initializes a new instance of the FsubrFloat32Handler class
/// </summary>
/// <param name="decoder">The instruction decoder that owns this handler</param>
public FsubrFloat32Handler(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)
{
// FSUBR is D8 /5
if (opcode != 0xD8) return false;
if (!Decoder.CanReadByte())
{
return false;
}
// Check if the ModR/M byte has reg field = 5
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
return reg == 5;
}
/// <summary>
/// Decodes a FSUBR float32 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)
{
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte using the specialized FPU method
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Set the instruction type
instruction.Type = InstructionType.Fsubr;
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Set the structured operands - the operand already has the correct size from ReadModRM
instruction.StructuredOperands =
[
rawOperand
];
}
else // Register operand (ST(i))
{
// For register operands, we need to handle the stack registers
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0); // ST(0)
var stiOperand = OperandFactory.CreateFPURegisterOperand(fpuRm); // ST(i)
// Set the structured operands
instruction.StructuredOperands =
[
st0Operand,
stiOperand
];
}
return true;
}
}