0
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:
bird_egop 2025-04-12 21:27:17 +03:00
parent fe0b04f5a1
commit 6ed6a7bd00
7 changed files with 42 additions and 14 deletions

View File

@ -114,8 +114,8 @@ public class FloatingPointHandler : InstructionHandler
/// </summary> /// </summary>
private static void InitializeTwoByteInstructions() private static void InitializeTwoByteInstructions()
{ {
// DF E0 - FNSTSW AX (Store FPU status word to AX without checking for pending unmasked floating-point exceptions) // We no longer need to handle FNSTSW AX (DF E0) here since we have a dedicated FnstswHandler
TwoByteInstructions.Add(0xDFE0, "fnstsw"); // that is registered before this handler in the InstructionHandlerFactory
// Add other two-byte instructions as needed // Add other two-byte instructions as needed
} }
@ -166,14 +166,8 @@ public class FloatingPointHandler : InstructionHandler
if (TwoByteInstructions.TryGetValue(twoByteOpcode, out string? mnemonic) && mnemonic != null) if (TwoByteInstructions.TryGetValue(twoByteOpcode, out string? mnemonic) && mnemonic != null)
{ {
instruction.Mnemonic = mnemonic; instruction.Mnemonic = mnemonic;
Decoder.SetPosition(position + 1); // Skip the second byte
// Special handling for specific instructions return true;
if (twoByteOpcode == 0xDFE0) // FNSTSW AX
{
instruction.Operands = "ax";
Decoder.SetPosition(position + 1); // Skip the second byte
return true;
}
} }
} }

View File

@ -1,3 +1,5 @@
using X86Disassembler.X86.Handlers.Test;
namespace X86Disassembler.X86.Handlers; namespace X86Disassembler.X86.Handlers;
using X86Disassembler.X86.Handlers.Group1; using X86Disassembler.X86.Handlers.Group1;

View File

@ -1,4 +1,4 @@
namespace X86Disassembler.X86.Handlers; namespace X86Disassembler.X86.Handlers.Test;
/// <summary> /// <summary>
/// Handler for TEST AL, imm8 instruction (0xA8) /// Handler for TEST AL, imm8 instruction (0xA8)

View File

@ -1,4 +1,4 @@
namespace X86Disassembler.X86.Handlers; namespace X86Disassembler.X86.Handlers.Test;
/// <summary> /// <summary>
/// Handler for TEST EAX, imm32 instruction (0xA9) /// Handler for TEST EAX, imm32 instruction (0xA9)

View File

@ -1,4 +1,4 @@
namespace X86Disassembler.X86.Handlers; namespace X86Disassembler.X86.Handlers.Test;
/// <summary> /// <summary>
/// Handler for TEST r/m8, r8 instruction (0x84) /// Handler for TEST r/m8, r8 instruction (0x84)

View File

@ -1,4 +1,4 @@
namespace X86Disassembler.X86.Handlers; namespace X86Disassembler.X86.Handlers.Test;
/// <summary> /// <summary>
/// Handler for TEST r/m32, r32 instruction (0x85) /// Handler for TEST r/m32, r32 instruction (0x85)

View 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);
}
}