From e948a678145dcca0ea9bca6c981efeb0f1049e17 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 12 Oct 2023 13:54:51 -0400 Subject: [PATCH] Implement SAHF, LAHF. --- .../Implementation/PerformImplementation.hpp | 28 +++++++++++++++++++ OSBindings/Mac/Clock SignalTests/8088Tests.mm | 10 ++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/InstructionSets/x86/Implementation/PerformImplementation.hpp b/InstructionSets/x86/Implementation/PerformImplementation.hpp index f1defbfe5..88e35246a 100644 --- a/InstructionSets/x86/Implementation/PerformImplementation.hpp +++ b/InstructionSets/x86/Implementation/PerformImplementation.hpp @@ -1,4 +1,5 @@ // +// // PerformImplementation.hpp // Clock Signal // @@ -789,6 +790,30 @@ void into(Status &status, FlowControllerT &flow_controller) { } } +inline void sahf(uint8_t &ah, Status &status) { + /* + EFLAGS(SF:ZF:0:AF:0:PF:1:CF) ← AH; + */ + status.set_from(ah); + status.set_from(!(ah & 0x40)); + status.set_from(ah & 0x10); + status.set_from(!(ah & 0x04)); + status.set_from(ah & 0x01); +} + +inline void lahf(uint8_t &ah, Status &status) { + /* + AH ← EFLAGS(SF:ZF:0:AF:0:PF:1:CF); + */ + ah = + (status.flag() ? 0x80 : 0x00) | + (status.flag() ? 0x40 : 0x00) | + (status.flag() ? 0x10 : 0x00) | + (status.flag() ? 0x00 : 0x04) | + 0x02 | + (status.flag() ? 0x01 : 0x00); +} + template void cbw(IntT &ax) { constexpr IntT test_bit = 1 << (sizeof(IntT) * 4 - 1); @@ -941,6 +966,9 @@ template < case Operation::INT: Primitive::int_(instruction.operand(), flow_controller); return; case Operation::INTO: Primitive::into(status, flow_controller); return; + case Operation::SAHF: Primitive::sahf(registers.ah(), status); return; + case Operation::LAHF: Primitive::lahf(registers.ah(), status); return; + case Operation::JO: jcc(status.condition()); return; case Operation::JNO: jcc(!status.condition()); return; case Operation::JB: jcc(status.condition()); return; diff --git a/OSBindings/Mac/Clock SignalTests/8088Tests.mm b/OSBindings/Mac/Clock SignalTests/8088Tests.mm index d9cfb059e..ed157cf01 100644 --- a/OSBindings/Mac/Clock SignalTests/8088Tests.mm +++ b/OSBindings/Mac/Clock SignalTests/8088Tests.mm @@ -282,7 +282,7 @@ struct FailedExecution { - (NSArray *)testFiles { NSString *path = [NSString stringWithUTF8String:TestSuiteHome]; NSSet *allowList = [NSSet setWithArray:@[ - @"37.json.gz", // AAA +/* @"37.json.gz", // AAA @"3F.json.gz", // AAS @"D4.json.gz", // AAM @"D5.json.gz", // AAD @@ -371,8 +371,10 @@ struct FailedExecution { // INT, INT3 @"CC.json.gz", @"CD.json.gz", +*/ + @"9E.json.gz", // SAHF + @"9F.json.gz", // LAHF - // TODO: LAHF, SAHF // TODO: LDS, LES // TODO: LEA @@ -381,7 +383,7 @@ struct FailedExecution { // TODO: LOOP, LOOPE, LOOPNE // TODO: MOV - +/* // AND @"20.json.gz", @"21.json.gz", @"22.json.gz", @"23.json.gz", @"24.json.gz", @"25.json.gz", @"80.4.json.gz", @"81.4.json.gz", @"83.4.json.gz", @@ -431,7 +433,7 @@ struct FailedExecution { // TODO: XLAT // TODO: SALC, SETMO, SETMOC - +*/ ]]; NSSet *ignoreList = nil;