2025-04-17 23:48:09 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
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 FDIVR float64 instruction (DC /7)
|
2025-04-17 23:33:56 +03:00
|
|
|
/// </summary>
|
2025-04-17 23:48:09 +03:00
|
|
|
public class FdivrFloat64Handler : InstructionHandler
|
2025-04-17 23:33:56 +03:00
|
|
|
{
|
|
|
|
/// <summary>
|
2025-04-17 23:48:09 +03:00
|
|
|
/// Initializes a new instance of the FdivrFloat64Handler 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 FdivrFloat64Handler(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
|
|
|
// FDIVR is DC /7
|
|
|
|
if (opcode != 0xDC) return false;
|
2025-04-17 23:33:56 +03:00
|
|
|
|
|
|
|
if (!Decoder.CanReadByte())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-04-18 02:37:19 +03:00
|
|
|
// Check if the ModR/M byte has reg field = 7 and mod != 3 (memory operand)
|
2025-04-17 23:33:56 +03:00
|
|
|
byte modRm = Decoder.PeakByte();
|
|
|
|
byte reg = (byte)((modRm >> 3) & 0x7);
|
2025-04-18 02:37:19 +03:00
|
|
|
byte mod = (byte)((modRm >> 6) & 0x3);
|
2025-04-17 23:33:56 +03:00
|
|
|
|
2025-04-18 02:37:19 +03:00
|
|
|
// Only handle memory operands (mod != 3) with reg = 7
|
|
|
|
return reg == 7 && mod != 3;
|
2025-04-17 23:33:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-17 23:48:09 +03:00
|
|
|
/// Decodes a FDIVR 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;
|
|
|
|
}
|
|
|
|
|
2025-04-18 02:37:19 +03:00
|
|
|
// Read the ModR/M byte using the specialized FPU method for 64-bit operands
|
2025-04-18 00:44:57 +03:00
|
|
|
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu64();
|
2025-04-17 23:33:56 +03:00
|
|
|
|
2025-04-18 02:37:19 +03:00
|
|
|
// We've already verified reg field is 7 (FDIVR) in CanHandle
|
|
|
|
// and we only handle memory operands (mod != 3)
|
|
|
|
|
2025-04-17 23:33:56 +03:00
|
|
|
// Set the instruction type
|
|
|
|
instruction.Type = InstructionType.Fdivr;
|
|
|
|
|
2025-04-18 02:37:19 +03:00
|
|
|
// Set the structured operands - the operand already has the correct size from ReadModRMFpu64
|
|
|
|
instruction.StructuredOperands =
|
|
|
|
[
|
|
|
|
rawOperand
|
|
|
|
];
|
2025-04-17 23:33:56 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|