2025-04-17 23:48:09 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.FloatingPoint.LoadStore;
|
2025-04-17 23:33:56 +03:00
|
|
|
|
2025-04-17 23:48:09 +03:00
|
|
|
using X86Disassembler.X86.Operands;
|
2025-04-17 23:33:56 +03:00
|
|
|
|
|
|
|
/// <summary>
|
2025-04-17 23:48:09 +03:00
|
|
|
/// Handler for FST float64 instruction (DD /2)
|
2025-04-17 23:33:56 +03:00
|
|
|
/// </summary>
|
2025-04-17 23:48:09 +03:00
|
|
|
public class FstFloat64Handler : InstructionHandler
|
2025-04-17 23:33:56 +03:00
|
|
|
{
|
|
|
|
/// <summary>
|
2025-04-17 23:48:09 +03:00
|
|
|
/// Initializes a new instance of the FstFloat64Handler class
|
2025-04-17 23:33:56 +03:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
2025-04-17 23:48:09 +03:00
|
|
|
public FstFloat64Handler(InstructionDecoder decoder)
|
2025-04-17 23:33:56 +03:00
|
|
|
: 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)
|
|
|
|
{
|
2025-04-17 23:48:09 +03:00
|
|
|
// FST is DD /2
|
|
|
|
if (opcode != 0xDD) return false;
|
2025-04-17 23:33:56 +03:00
|
|
|
|
|
|
|
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>
|
2025-04-17 23:48:09 +03:00
|
|
|
/// Decodes a FST float64 instruction
|
2025-04-17 23:33:56 +03:00
|
|
|
/// </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;
|
|
|
|
}
|
|
|
|
}
|