0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 16:18:37 +03:00

Test fixes

This commit is contained in:
bird_egop
2025-04-16 18:30:17 +03:00
parent d4eb920e2f
commit 6719cff2af
38 changed files with 469 additions and 170 deletions

View File

@ -66,7 +66,7 @@ public class Float32OperationHandler : InstructionHandler
}
// Read the ModR/M byte
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM();
// Set the instruction type based on the reg field
instruction.Type = InstructionTypes[(int)reg];
@ -74,8 +74,29 @@ public class Float32OperationHandler : InstructionHandler
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Ensure the memory operand has the correct size (32-bit float)
operand.Size = 32;
// Create a new memory operand with 32-bit size using the appropriate factory method
Operand operand;
if (rawOperand is DirectMemoryOperand directMemory)
{
operand = OperandFactory.CreateDirectMemoryOperand(directMemory.Address, 32);
}
else if (rawOperand is BaseRegisterMemoryOperand baseRegMemory)
{
operand = OperandFactory.CreateBaseRegisterMemoryOperand(baseRegMemory.BaseRegister, 32);
}
else if (rawOperand is DisplacementMemoryOperand dispMemory)
{
operand = OperandFactory.CreateDisplacementMemoryOperand(dispMemory.BaseRegister, dispMemory.Displacement, 32);
}
else if (rawOperand is ScaledIndexMemoryOperand scaledMemory)
{
operand = OperandFactory.CreateScaledIndexMemoryOperand(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement, 32);
}
else
{
operand = rawOperand;
}
// Set the structured operands
instruction.StructuredOperands =

View File

@ -66,7 +66,7 @@ public class Float64OperationHandler : InstructionHandler
}
// Read the ModR/M byte
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM64(); // Use the 64-bit version
var (mod, reg, rm, rawOperand) = ModRMDecoder.ReadModRM64(); // Use the 64-bit version
// Set the instruction type based on the reg field
instruction.Type = InstructionTypes[(int)reg];
@ -74,8 +74,29 @@ public class Float64OperationHandler : InstructionHandler
// For memory operands, set the operand
if (mod != 3) // Memory operand
{
// Ensure the memory operand has the correct size (64-bit float)
operand.Size = 64;
// Create a new memory operand with 64-bit size using the appropriate factory method
Operand operand;
if (rawOperand is DirectMemoryOperand directMemory)
{
operand = OperandFactory.CreateDirectMemoryOperand(directMemory.Address, 64);
}
else if (rawOperand is BaseRegisterMemoryOperand baseRegMemory)
{
operand = OperandFactory.CreateBaseRegisterMemoryOperand(baseRegMemory.BaseRegister, 64);
}
else if (rawOperand is DisplacementMemoryOperand dispMemory)
{
operand = OperandFactory.CreateDisplacementMemoryOperand(dispMemory.BaseRegister, dispMemory.Displacement, 64);
}
else if (rawOperand is ScaledIndexMemoryOperand scaledMemory)
{
operand = OperandFactory.CreateScaledIndexMemoryOperand(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement, 64);
}
else
{
operand = rawOperand;
}
// Set the structured operands
instruction.StructuredOperands =

View File

@ -120,8 +120,8 @@ public class Int16OperationHandler : InstructionHandler
return false;
}
// Read the ModR/M byte
var (mod, reg, rm, memoryOperand) = ModRMDecoder.ReadModRM();
// Read the ModR/M byte, specifying that we're dealing with 16-bit operands
var (mod, reg, rm, memoryOperand) = ModRMDecoder.ReadModRM16();
// Handle based on addressing mode
if (mod != 3) // Memory operand
@ -129,10 +129,8 @@ public class Int16OperationHandler : InstructionHandler
// Set the instruction type based on the reg field
instruction.Type = MemoryInstructionTypes[(int)reg];
// For memory operands, we need to set the size to 16-bit
// Create a new memory operand with 16-bit size
// Note: The operand size is already set to 16-bit by the ReadModRM16 method
var int16Operand = memoryOperand;
int16Operand.Size = 16;
// Set the structured operands
instruction.StructuredOperands =

View File

@ -107,7 +107,7 @@ public class LoadStoreControlHandler : InstructionHandler
}
// Read the ModR/M byte
var (mod, reg, rm, memoryOperand) = ModRMDecoder.ReadModRM();
var (mod, reg, rm, rawMemoryOperand) = ModRMDecoder.ReadModRM();
// Handle based on addressing mode
if (mod != 3) // Memory operand
@ -115,16 +115,60 @@ public class LoadStoreControlHandler : InstructionHandler
// Set the instruction type based on the reg field
instruction.Type = MemoryInstructionTypes[(int)reg];
// Set the size based on the operation
// Create a new memory operand with the appropriate size based on the operation
Operand memoryOperand;
if (reg == RegisterIndex.A || reg == RegisterIndex.C || reg == RegisterIndex.D) // fld, fst, fstp
{
// Keep the default 32-bit size for floating point operations
memoryOperand.Size = 32;
// Create a 32-bit memory operand for floating point operations
if (rawMemoryOperand is DirectMemoryOperand directMemory)
{
memoryOperand = OperandFactory.CreateDirectMemoryOperand(directMemory.Address, 32);
}
else if (rawMemoryOperand is BaseRegisterMemoryOperand baseRegMemory)
{
memoryOperand = OperandFactory.CreateBaseRegisterMemoryOperand(baseRegMemory.BaseRegister, 32);
}
else if (rawMemoryOperand is DisplacementMemoryOperand dispMemory)
{
memoryOperand = OperandFactory.CreateDisplacementMemoryOperand(dispMemory.BaseRegister, dispMemory.Displacement, 32);
}
else if (rawMemoryOperand is ScaledIndexMemoryOperand scaledMemory)
{
memoryOperand = OperandFactory.CreateScaledIndexMemoryOperand(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement, 32);
}
else
{
memoryOperand = rawMemoryOperand;
}
}
else if (reg == RegisterIndex.Di || reg == RegisterIndex.Bp) // fldcw, fnstcw
{
// Set to 16-bit for control word operations
memoryOperand.Size = 16;
// Create a 16-bit memory operand for control word operations
if (rawMemoryOperand is DirectMemoryOperand directMemory)
{
memoryOperand = OperandFactory.CreateDirectMemoryOperand16(directMemory.Address);
}
else if (rawMemoryOperand is BaseRegisterMemoryOperand baseRegMemory)
{
memoryOperand = OperandFactory.CreateBaseRegisterMemoryOperand16(baseRegMemory.BaseRegister);
}
else if (rawMemoryOperand is DisplacementMemoryOperand dispMemory)
{
memoryOperand = OperandFactory.CreateDisplacementMemoryOperand16(dispMemory.BaseRegister, dispMemory.Displacement);
}
else if (rawMemoryOperand is ScaledIndexMemoryOperand scaledMemory)
{
memoryOperand = OperandFactory.CreateScaledIndexMemoryOperand16(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement);
}
else
{
memoryOperand = rawMemoryOperand;
}
}
else
{
memoryOperand = rawMemoryOperand;
}
// Set the structured operands

View File

@ -121,7 +121,7 @@ public class LoadStoreFloat64Handler : InstructionHandler
}
// Read the ModR/M byte
var (mod, reg, rm, memoryOperand) = ModRMDecoder.ReadModRM();
var (mod, reg, rm, rawMemoryOperand) = ModRMDecoder.ReadModRM();
// Set the instruction type based on the mod and reg fields
if (mod != 3) // Memory operand
@ -132,18 +132,33 @@ public class LoadStoreFloat64Handler : InstructionHandler
switch (reg)
{
case RegisterIndex.A: // FLD m64real
// Set the structured operands
memoryOperand.Size = 64; // Set size to 64 bits for double precision
instruction.StructuredOperands =
[
memoryOperand
];
return true;
case RegisterIndex.C: // FST m64real
case RegisterIndex.D: // FSTP m64real
// Create a new memory operand with 64-bit size using the appropriate factory method
Operand memoryOperand;
if (rawMemoryOperand is DirectMemoryOperand directMemory)
{
memoryOperand = OperandFactory.CreateDirectMemoryOperand(directMemory.Address, 64);
}
else if (rawMemoryOperand is BaseRegisterMemoryOperand baseRegMemory)
{
memoryOperand = OperandFactory.CreateBaseRegisterMemoryOperand(baseRegMemory.BaseRegister, 64);
}
else if (rawMemoryOperand is DisplacementMemoryOperand dispMemory)
{
memoryOperand = OperandFactory.CreateDisplacementMemoryOperand(dispMemory.BaseRegister, dispMemory.Displacement, 64);
}
else if (rawMemoryOperand is ScaledIndexMemoryOperand scaledMemory)
{
memoryOperand = OperandFactory.CreateScaledIndexMemoryOperand(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement, 64);
}
else
{
memoryOperand = rawMemoryOperand;
}
// Set the structured operands
memoryOperand.Size = 64; // Set size to 64 bits for double precision
instruction.StructuredOperands =
[
memoryOperand

View File

@ -121,7 +121,7 @@ public class LoadStoreInt32Handler : InstructionHandler
}
// Read the ModR/M byte
var (mod, reg, rm, memoryOperand) = ModRMDecoder.ReadModRM();
var (mod, reg, rm, rawMemoryOperand) = ModRMDecoder.ReadModRM();
// Handle based on addressing mode
if (mod != 3) // Memory operand
@ -129,16 +129,46 @@ public class LoadStoreInt32Handler : InstructionHandler
// Set the instruction type based on the reg field
instruction.Type = MemoryInstructionTypes[(int)reg];
// Set the size based on the operation
// Create a new memory operand with the appropriate size based on the operation
Operand memoryOperand;
int operandSize;
if (reg == RegisterIndex.A || reg == RegisterIndex.C || reg == RegisterIndex.D) // 32-bit integer operations
{
// Keep the default 32-bit size
memoryOperand.Size = 32;
// Use 32-bit size for integer operations
operandSize = 32;
}
else if (reg == RegisterIndex.Di || reg == RegisterIndex.Bp) // 80-bit extended precision operations
{
// Set to 80-bit for extended precision
memoryOperand.Size = 80;
// Use 80-bit size for extended precision operations
operandSize = 80;
}
else
{
// Default size
operandSize = 32;
}
// Create the appropriate memory operand with the correct size
if (rawMemoryOperand is DirectMemoryOperand directMemory)
{
memoryOperand = OperandFactory.CreateDirectMemoryOperand(directMemory.Address, operandSize);
}
else if (rawMemoryOperand is BaseRegisterMemoryOperand baseRegMemory)
{
memoryOperand = OperandFactory.CreateBaseRegisterMemoryOperand(baseRegMemory.BaseRegister, operandSize);
}
else if (rawMemoryOperand is DisplacementMemoryOperand dispMemory)
{
memoryOperand = OperandFactory.CreateDisplacementMemoryOperand(dispMemory.BaseRegister, dispMemory.Displacement, operandSize);
}
else if (rawMemoryOperand is ScaledIndexMemoryOperand scaledMemory)
{
memoryOperand = OperandFactory.CreateScaledIndexMemoryOperand(scaledMemory.IndexRegister, scaledMemory.Scale, scaledMemory.BaseRegister, scaledMemory.Displacement, operandSize);
}
else
{
memoryOperand = rawMemoryOperand;
}
// Set the structured operands