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

float handlers

This commit is contained in:
bird_egop
2025-04-18 02:37:19 +03:00
parent 18ecf31c46
commit e967c0e0c0
27 changed files with 646 additions and 776 deletions

View File

@ -31,11 +31,13 @@ public class FaddFloat32Handler : InstructionHandler
return false;
}
// Check if the ModR/M byte has reg field = 0
// Check if the ModR/M byte has reg field = 0 and mod != 3 (memory operand)
byte modRm = Decoder.PeakByte();
byte reg = (byte)((modRm >> 3) & 0x7);
byte mod = (byte)((modRm >> 6) & 0x3);
return reg == 0;
// Only handle memory operands (mod != 3) with reg = 0
return reg == 0 && mod != 3;
}
/// <summary>
@ -51,40 +53,20 @@ public class FaddFloat32Handler : InstructionHandler
return false;
}
// Read the ModR/M byte using the specialized FPU method
// Read the ModR/M byte using the specialized FPU method for 32-bit operands
var (mod, reg, fpuRm, rawOperand) = ModRMDecoder.ReadModRMFpu();
// Verify reg field is 0 (FADD)
if (reg != 0)
{
return false;
}
// We've already verified reg field is 0 (FADD) in CanHandle
// and we only handle memory operands (mod != 3)
// 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
];
}
// Set the structured operands - the operand already has the correct size from ReadModRMFpu
instruction.StructuredOperands =
[
rawOperand
];
return true;
}