mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
new handlers and test fixes
This commit is contained in:
@ -49,10 +49,10 @@ public class MovRegImm32Handler : InstructionHandler
|
||||
uint imm32 = Decoder.ReadUInt32();
|
||||
|
||||
// Create the destination register operand
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg, 32);
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Create the source immediate operand
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm32, 32);
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm32);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
|
@ -38,7 +38,7 @@ public class MovRegImm8Handler : InstructionHandler
|
||||
instruction.Type = InstructionType.Mov;
|
||||
|
||||
// Register is encoded in the low 3 bits of the opcode
|
||||
RegisterIndex reg = (RegisterIndex)(opcode & 0x07);
|
||||
RegisterIndex8 reg = (RegisterIndex8)(opcode & 0x07);
|
||||
|
||||
// Read the immediate value
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -49,7 +49,7 @@ public class MovRegImm8Handler : InstructionHandler
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create the destination register operand
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg, 8);
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand8(reg);
|
||||
|
||||
// Create the source immediate operand
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm8, 8);
|
||||
|
@ -23,7 +23,22 @@ public class MovRm32Imm32Handler : InstructionHandler
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
return opcode == 0xC7;
|
||||
if (opcode != 0xC7)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Then check if we can peek at the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Peek at the ModR/M byte without advancing the position
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
|
||||
// MOV r/m8, imm8 only uses reg=0
|
||||
return reg == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -38,13 +53,7 @@ public class MovRm32Imm32Handler : InstructionHandler
|
||||
instruction.Type = InstructionType.Mov;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// MOV r/m32, imm32 only uses reg=0
|
||||
if (reg != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var (_, _, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we have enough bytes for the immediate value (4 bytes)
|
||||
if (!Decoder.CanReadUInt())
|
||||
@ -56,7 +65,7 @@ public class MovRm32Imm32Handler : InstructionHandler
|
||||
uint imm32 = Decoder.ReadUInt32();
|
||||
|
||||
// Create the immediate operand
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm32, 32);
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm32);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
|
@ -23,7 +23,23 @@ public class MovRm8Imm8Handler : InstructionHandler
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
return opcode == 0xC6;
|
||||
// First check if the opcode matches
|
||||
if (opcode != 0xC6)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Then check if we can peek at the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Peek at the ModR/M byte without advancing the position
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
|
||||
// MOV r/m8, imm8 only uses reg=0
|
||||
return reg == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -47,14 +63,8 @@ public class MovRm8Imm8Handler : InstructionHandler
|
||||
// For MOV r/m8, imm8 (0xC6):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value is the source operand
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// MOV r/m8, imm8 only uses reg=0
|
||||
if (reg != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var (_, _, _, destinationOperand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Note: The operand size is already set to 8-bit by the ReadModRM8 method
|
||||
|
||||
// Read the immediate value
|
||||
|
Reference in New Issue
Block a user