mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Refactored floating point handlers into specialized classes for better organization and maintainability
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FABS instruction (D9 E1)
|
||||
/// </summary>
|
||||
public class FabsHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FabsHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FabsHandler(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)
|
||||
{
|
||||
// FABS is D9 E1
|
||||
if (opcode != 0xD9) return false;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the next byte is E1
|
||||
byte nextByte = Decoder.PeakByte();
|
||||
return nextByte == 0xE1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FABS 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 second byte of the opcode
|
||||
byte secondByte = Decoder.ReadByte();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fabs;
|
||||
|
||||
// FABS has no operands
|
||||
instruction.StructuredOperands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FCHS instruction (D9 E0)
|
||||
/// </summary>
|
||||
public class FchsHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FchsHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FchsHandler(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)
|
||||
{
|
||||
// FCHS is D9 E0
|
||||
if (opcode != 0xD9) return false;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the next byte is E0
|
||||
byte nextByte = Decoder.PeakByte();
|
||||
return nextByte == 0xE0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FCHS 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 second byte of the opcode
|
||||
byte secondByte = Decoder.ReadByte();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fchs;
|
||||
|
||||
// FCHS has no operands
|
||||
instruction.StructuredOperands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FIADD int32 instruction (DA /0)
|
||||
/// </summary>
|
||||
public class FiaddInt32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FiaddInt32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FiaddInt32Handler(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)
|
||||
{
|
||||
// FIADD is DA /0
|
||||
if (opcode != 0xDA) 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);
|
||||
byte mod = (byte)((modRm >> 6) & 0x3);
|
||||
|
||||
// Only handle memory operands (mod != 3)
|
||||
return reg == 0 && mod != 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FIADD int32 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
|
||||
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fiadd;
|
||||
|
||||
// Set the structured operands - the operand already has the correct size from ReadModRM
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
rawOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FIDIV int32 instruction (DA /6)
|
||||
/// </summary>
|
||||
public class FidivInt32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FidivInt32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FidivInt32Handler(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)
|
||||
{
|
||||
// FIDIV is DA /6
|
||||
if (opcode != 0xDA) 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);
|
||||
byte mod = (byte)((modRm >> 6) & 0x3);
|
||||
|
||||
// Only handle memory operands (mod != 3)
|
||||
return reg == 6 && mod != 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FIDIV int32 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
|
||||
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fidiv;
|
||||
|
||||
// Set the structured operands - the operand already has the correct size from ReadModRM
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
rawOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FIDIVR int32 instruction (DA /7)
|
||||
/// </summary>
|
||||
public class FidivrInt32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FidivrInt32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FidivrInt32Handler(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)
|
||||
{
|
||||
// FIDIVR is DA /7
|
||||
if (opcode != 0xDA) 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);
|
||||
byte mod = (byte)((modRm >> 6) & 0x3);
|
||||
|
||||
// Only handle memory operands (mod != 3)
|
||||
return reg == 7 && mod != 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FIDIVR int32 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
|
||||
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fidivr;
|
||||
|
||||
// Set the structured operands - the operand already has the correct size from ReadModRM
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
rawOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FIMUL int32 instruction (DA /1)
|
||||
/// </summary>
|
||||
public class FimulInt32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FimulInt32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FimulInt32Handler(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)
|
||||
{
|
||||
// FIMUL is DA /1
|
||||
if (opcode != 0xDA) 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);
|
||||
byte mod = (byte)((modRm >> 6) & 0x3);
|
||||
|
||||
// Only handle memory operands (mod != 3)
|
||||
return reg == 1 && mod != 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FIMUL int32 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
|
||||
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fimul;
|
||||
|
||||
// Set the structured operands - the operand already has the correct size from ReadModRM
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
rawOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FISUB int32 instruction (DA /4)
|
||||
/// </summary>
|
||||
public class FisubInt32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FisubInt32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FisubInt32Handler(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)
|
||||
{
|
||||
// FISUB is DA /4
|
||||
if (opcode != 0xDA) 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);
|
||||
byte mod = (byte)((modRm >> 6) & 0x3);
|
||||
|
||||
// Only handle memory operands (mod != 3)
|
||||
return reg == 4 && mod != 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FISUB int32 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
|
||||
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fisub;
|
||||
|
||||
// Set the structured operands - the operand already has the correct size from ReadModRM
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
rawOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for FISUBR int32 instruction (DA /5)
|
||||
/// </summary>
|
||||
public class FisubrInt32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the FisubrInt32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public FisubrInt32Handler(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)
|
||||
{
|
||||
// FISUBR is DA /5
|
||||
if (opcode != 0xDA) 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);
|
||||
byte mod = (byte)((modRm >> 6) & 0x3);
|
||||
|
||||
// Only handle memory operands (mod != 3)
|
||||
return reg == 5 && mod != 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a FISUBR int32 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
|
||||
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Fisubr;
|
||||
|
||||
// Set the structured operands - the operand already has the correct size from ReadModRM
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
rawOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user