mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 11:51:17 +03:00
Fixed floating point instruction handling. Removed redundant FNSTSW AX check from FloatingPointHandler and added dedicated test for FnstswHandler.
This commit is contained in:
parent
fe0b04f5a1
commit
6ed6a7bd00
@ -114,8 +114,8 @@ public class FloatingPointHandler : InstructionHandler
|
||||
/// </summary>
|
||||
private static void InitializeTwoByteInstructions()
|
||||
{
|
||||
// DF E0 - FNSTSW AX (Store FPU status word to AX without checking for pending unmasked floating-point exceptions)
|
||||
TwoByteInstructions.Add(0xDFE0, "fnstsw");
|
||||
// We no longer need to handle FNSTSW AX (DF E0) here since we have a dedicated FnstswHandler
|
||||
// that is registered before this handler in the InstructionHandlerFactory
|
||||
|
||||
// Add other two-byte instructions as needed
|
||||
}
|
||||
@ -166,16 +166,10 @@ public class FloatingPointHandler : InstructionHandler
|
||||
if (TwoByteInstructions.TryGetValue(twoByteOpcode, out string? mnemonic) && mnemonic != null)
|
||||
{
|
||||
instruction.Mnemonic = mnemonic;
|
||||
|
||||
// Special handling for specific instructions
|
||||
if (twoByteOpcode == 0xDFE0) // FNSTSW AX
|
||||
{
|
||||
instruction.Operands = "ax";
|
||||
Decoder.SetPosition(position + 1); // Skip the second byte
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The opcode index in our tables (0-7 for D8-DF)
|
||||
int opcodeIndex = opcode - 0xD8;
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Handlers.Test;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers;
|
||||
|
||||
using X86Disassembler.X86.Handlers.Group1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers;
|
||||
namespace X86Disassembler.X86.Handlers.Test;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for TEST AL, imm8 instruction (0xA8)
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers;
|
||||
namespace X86Disassembler.X86.Handlers.Test;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for TEST EAX, imm32 instruction (0xA9)
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers;
|
||||
namespace X86Disassembler.X86.Handlers.Test;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for TEST r/m8, r8 instruction (0x84)
|
@ -1,4 +1,4 @@
|
||||
namespace X86Disassembler.X86.Handlers;
|
||||
namespace X86Disassembler.X86.Handlers.Test;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for TEST r/m32, r32 instruction (0x85)
|
32
X86DisassemblerTests/FloatingPointInstructionTests.cs
Normal file
32
X86DisassemblerTests/FloatingPointInstructionTests.cs
Normal file
@ -0,0 +1,32 @@
|
||||
namespace X86DisassemblerTests;
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
using X86Disassembler.X86;
|
||||
using X86Disassembler.X86.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for floating-point instruction handlers
|
||||
/// </summary>
|
||||
public class FloatingPointInstructionTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the FnstswHandler for decoding FNSTSW AX instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void FnstswHandler_DecodesFnstswAx_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
// FNSTSW AX (DF E0)
|
||||
byte[] codeBuffer = new byte[] { 0xDF, 0xE0 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("fnstsw", instruction.Mnemonic);
|
||||
Assert.Equal("ax", instruction.Operands);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user