mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Updated instruction handlers to use Type and StructuredOperands instead of Mnemonic and Operands
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.FloatingPoint;
|
||||
|
||||
/// <summary>
|
||||
@ -5,74 +7,72 @@ namespace X86Disassembler.X86.Handlers.FloatingPoint;
|
||||
/// </summary>
|
||||
public class Int32OperationHandler : InstructionHandler
|
||||
{
|
||||
// Memory operand mnemonics for DA opcode - operations on int32
|
||||
private static readonly string[] MemoryMnemonics =
|
||||
// Memory operand instruction types for DA opcode - operations on int32
|
||||
private static readonly InstructionType[] MemoryInstructionTypes =
|
||||
[
|
||||
"fiadd", // 0
|
||||
"fimul", // 1
|
||||
"ficom", // 2
|
||||
"ficomp", // 3
|
||||
"fisub", // 4
|
||||
"fisubr", // 5
|
||||
"fidiv", // 6
|
||||
"fidivr" // 7
|
||||
InstructionType.Unknown, // fiadd - not in enum
|
||||
InstructionType.Unknown, // fimul - not in enum
|
||||
InstructionType.Unknown, // ficom - not in enum
|
||||
InstructionType.Unknown, // ficomp - not in enum
|
||||
InstructionType.Unknown, // fisub - not in enum
|
||||
InstructionType.Unknown, // fisubr - not in enum
|
||||
InstructionType.Unknown, // fidiv - not in enum
|
||||
InstructionType.Unknown // fidivr - not in enum
|
||||
];
|
||||
|
||||
// Register-register operations mapping (mod=3)
|
||||
private static readonly Dictionary<(RegisterIndex Reg, RegisterIndex Rm), (string Mnemonic, string Operands)> RegisterOperations = new()
|
||||
private static readonly Dictionary<(RegisterIndex Reg, RegisterIndex Rm), (InstructionType Type, FpuRegisterIndex DestIndex, FpuRegisterIndex SrcIndex)> RegisterOperations = new()
|
||||
{
|
||||
// FCMOVB st(0), st(i)
|
||||
{ (RegisterIndex.A, RegisterIndex.A), ("fcmovb", "st(0), st(0)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.C), ("fcmovb", "st(0), st(1)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.D), ("fcmovb", "st(0), st(2)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.B), ("fcmovb", "st(0), st(3)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.Sp), ("fcmovb", "st(0), st(4)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.Bp), ("fcmovb", "st(0), st(5)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.Si), ("fcmovb", "st(0), st(6)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.Di), ("fcmovb", "st(0), st(7)") },
|
||||
{ (RegisterIndex.A, RegisterIndex.A), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST0) },
|
||||
{ (RegisterIndex.A, RegisterIndex.C), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST1) },
|
||||
{ (RegisterIndex.A, RegisterIndex.D), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST2) },
|
||||
{ (RegisterIndex.A, RegisterIndex.B), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST3) },
|
||||
{ (RegisterIndex.A, RegisterIndex.Sp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST4) },
|
||||
{ (RegisterIndex.A, RegisterIndex.Bp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST5) },
|
||||
{ (RegisterIndex.A, RegisterIndex.Si), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST6) },
|
||||
{ (RegisterIndex.A, RegisterIndex.Di), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST7) },
|
||||
|
||||
// FCMOVE st(0), st(i)
|
||||
{ (RegisterIndex.B, RegisterIndex.A), ("fcmove", "st(0), st(0)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.C), ("fcmove", "st(0), st(1)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.D), ("fcmove", "st(0), st(2)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.B), ("fcmove", "st(0), st(3)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.Sp), ("fcmove", "st(0), st(4)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.Bp), ("fcmove", "st(0), st(5)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.Si), ("fcmove", "st(0), st(6)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.Di), ("fcmove", "st(0), st(7)") },
|
||||
{ (RegisterIndex.B, RegisterIndex.A), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST0) },
|
||||
{ (RegisterIndex.B, RegisterIndex.C), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST1) },
|
||||
{ (RegisterIndex.B, RegisterIndex.D), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST2) },
|
||||
{ (RegisterIndex.B, RegisterIndex.B), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST3) },
|
||||
{ (RegisterIndex.B, RegisterIndex.Sp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST4) },
|
||||
{ (RegisterIndex.B, RegisterIndex.Bp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST5) },
|
||||
{ (RegisterIndex.B, RegisterIndex.Si), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST6) },
|
||||
{ (RegisterIndex.B, RegisterIndex.Di), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST7) },
|
||||
|
||||
// FCMOVBE st(0), st(i)
|
||||
{ (RegisterIndex.C, RegisterIndex.A), ("fcmovbe", "st(0), st(0)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.C), ("fcmovbe", "st(0), st(1)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.D), ("fcmovbe", "st(0), st(2)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.B), ("fcmovbe", "st(0), st(3)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.Sp), ("fcmovbe", "st(0), st(4)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.Bp), ("fcmovbe", "st(0), st(5)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.Si), ("fcmovbe", "st(0), st(6)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.Di), ("fcmovbe", "st(0), st(7)") },
|
||||
{ (RegisterIndex.C, RegisterIndex.A), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST0) },
|
||||
{ (RegisterIndex.C, RegisterIndex.C), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST1) },
|
||||
{ (RegisterIndex.C, RegisterIndex.D), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST2) },
|
||||
{ (RegisterIndex.C, RegisterIndex.B), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST3) },
|
||||
{ (RegisterIndex.C, RegisterIndex.Sp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST4) },
|
||||
{ (RegisterIndex.C, RegisterIndex.Bp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST5) },
|
||||
{ (RegisterIndex.C, RegisterIndex.Si), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST6) },
|
||||
{ (RegisterIndex.C, RegisterIndex.Di), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST7) },
|
||||
|
||||
// FCMOVU st(0), st(i)
|
||||
{ (RegisterIndex.D, RegisterIndex.A), ("fcmovu", "st(0), st(0)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.C), ("fcmovu", "st(0), st(1)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.D), ("fcmovu", "st(0), st(2)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.B), ("fcmovu", "st(0), st(3)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.Sp), ("fcmovu", "st(0), st(4)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.Bp), ("fcmovu", "st(0), st(5)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.Si), ("fcmovu", "st(0), st(6)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.Di), ("fcmovu", "st(0), st(7)") },
|
||||
{ (RegisterIndex.D, RegisterIndex.A), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST0) },
|
||||
{ (RegisterIndex.D, RegisterIndex.C), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST1) },
|
||||
{ (RegisterIndex.D, RegisterIndex.D), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST2) },
|
||||
{ (RegisterIndex.D, RegisterIndex.B), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST3) },
|
||||
{ (RegisterIndex.D, RegisterIndex.Sp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST4) },
|
||||
{ (RegisterIndex.D, RegisterIndex.Bp), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST5) },
|
||||
{ (RegisterIndex.D, RegisterIndex.Si), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST6) },
|
||||
{ (RegisterIndex.D, RegisterIndex.Di), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST7) },
|
||||
|
||||
// Special case
|
||||
{ (RegisterIndex.Di, RegisterIndex.B), ("fucompp", "") }
|
||||
{ (RegisterIndex.Di, RegisterIndex.B), (InstructionType.Unknown, FpuRegisterIndex.ST0, FpuRegisterIndex.ST0) }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Int32OperationHandler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public Int32OperationHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public Int32OperationHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -100,30 +100,43 @@ public class Int32OperationHandler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
var (mod, reg, rm, memoryOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Handle based on addressing mode
|
||||
if (mod != 3) // Memory operand
|
||||
{
|
||||
// Set the mnemonic based on the reg field
|
||||
instruction.Mnemonic = MemoryMnemonics[(int)reg];
|
||||
// Set the instruction type based on the reg field
|
||||
instruction.Type = MemoryInstructionTypes[(int)reg];
|
||||
|
||||
// Set the operands (already has dword ptr prefix for int32)
|
||||
instruction.Operands = memOperand;
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
memoryOperand
|
||||
];
|
||||
}
|
||||
else // Register operand (ST(i))
|
||||
{
|
||||
// Look up the register operation in our dictionary
|
||||
// Look up the instruction type in the register operations dictionary
|
||||
if (RegisterOperations.TryGetValue((reg, rm), out var operation))
|
||||
{
|
||||
instruction.Mnemonic = operation.Mnemonic;
|
||||
instruction.Operands = operation.Operands;
|
||||
instruction.Type = operation.Type;
|
||||
|
||||
// Create the FPU register operands
|
||||
var destOperand = OperandFactory.CreateFPURegisterOperand(operation.DestIndex);
|
||||
var srcOperand = OperandFactory.CreateFPURegisterOperand(operation.SrcIndex);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destOperand,
|
||||
srcOperand
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown instruction
|
||||
instruction.Mnemonic = "??";
|
||||
instruction.Operands = "";
|
||||
instruction.Type = InstructionType.Unknown;
|
||||
instruction.StructuredOperands = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user