From 67d364cc89351d910274167a57e12de5938b62ab Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 9 Oct 2023 16:21:04 -0400 Subject: [PATCH] Add faulty SUB, SBB. --- .../Implementation/PerformImplementation.hpp | 44 +++++++++++ OSBindings/Mac/Clock SignalTests/8088Tests.mm | 77 +++++++++++-------- 2 files changed, 88 insertions(+), 33 deletions(-) diff --git a/InstructionSets/x86/Implementation/PerformImplementation.hpp b/InstructionSets/x86/Implementation/PerformImplementation.hpp index 6c09d50ba..593980bf0 100644 --- a/InstructionSets/x86/Implementation/PerformImplementation.hpp +++ b/InstructionSets/x86/Implementation/PerformImplementation.hpp @@ -434,6 +434,44 @@ void add(IntT &destination, IntT source, Status &status) { destination = result; } +template +void sbb(IntT &destination, IntT source, Status &status) { + /* + DEST ← DEST - (SRC + CF); + */ + /* + The OF, SF, ZF, AF, CF, and PF flags are set according to the result. + */ + const IntT result = destination + source + status.carry_bit(); + + status.carry = !Numeric::carried_out() - 1>(destination, IntT(~source), result); + status.auxiliary_carry = !Numeric::carried_in<4>(destination, IntT(~source), result); + status.sign = result & top_bit(); + status.zero = status.parity = result; + status.overflow = overflow(destination, source, result); + + destination = result; +} + +template +void sub(IntT &destination, IntT source, Status &status) { + /* + DEST ← DEST - SRC; + */ + /* + The OF, SF, ZF, AF, CF, and PF flags are set according to the result. + */ + const IntT result = destination - source; + + status.carry = !Numeric::carried_out() - 1>(destination, IntT(~source), result); + status.auxiliary_carry = !Numeric::carried_in<4>(destination, IntT(~source), result); + status.sign = result & top_bit(); + status.zero = status.parity = result; + status.overflow = overflow(destination, source, result); + + destination = result; +} + template void and_(IntT &destination, IntT source, Status &status) { /* @@ -593,8 +631,14 @@ template < case Operation::ESC: case Operation::NOP: return; + case Operation::HLT: flow_controller.halt(); return; + case Operation::WAIT: flow_controller.wait(); return; + case Operation::ADC: Primitive::adc(destination(), source(), status); break; case Operation::ADD: Primitive::add(destination(), source(), status); break; + case Operation::SBB: Primitive::sbb(destination(), source(), status); break; + case Operation::SUB: Primitive::sub(destination(), source(), status); break; + case Operation::AND: Primitive::and_(destination(), source(), status); break; case Operation::CALLrel: diff --git a/OSBindings/Mac/Clock SignalTests/8088Tests.mm b/OSBindings/Mac/Clock SignalTests/8088Tests.mm index 59f35beb9..8c0831006 100644 --- a/OSBindings/Mac/Clock SignalTests/8088Tests.mm +++ b/OSBindings/Mac/Clock SignalTests/8088Tests.mm @@ -220,6 +220,9 @@ class FlowController { registers_.ip_ = offset; } + void halt() {} + void wait() {} + private: Memory &memory_; Registers ®isters_; @@ -275,43 +278,51 @@ struct FailedExecution { - (NSArray *)testFiles { NSString *path = [NSString stringWithUTF8String:TestSuiteHome]; NSSet *allowList = [NSSet setWithArray:@[ - @"37.json.gz", // AAA - @"3F.json.gz", // AAS - @"D4.json.gz", // AAM - @"D5.json.gz", // AAD - @"27.json.gz", // DAA - @"2F.json.gz", // DAS +// @"37.json.gz", // AAA +// @"3F.json.gz", // AAS +// @"D4.json.gz", // AAM +// @"D5.json.gz", // AAD +// @"27.json.gz", // DAA +// @"2F.json.gz", // DAS +// +// @"98.json.gz", // CBW +// @"99.json.gz", // CWD +// +// // ESC +// @"D8.json.gz", @"D9.json.gz", @"DA.json.gz", @"DB.json.gz", +// @"DC.json.gz", @"DD.json.gz", @"DE.json.gz", @"DE.json.gz", +// +// // NOP +// @"90.json.gz", +// +// // ADC +// @"10.json.gz", @"11.json.gz", @"12.json.gz", @"13.json.gz", @"14.json.gz", @"15.json.gz", +// @"80.2.json.gz", @"81.2.json.gz", @"83.2.json.gz", +// +// // ADD +// @"00.json.gz", @"01.json.gz", @"02.json.gz", @"03.json.gz", @"04.json.gz", @"05.json.gz", +// @"80.0.json.gz", @"81.0.json.gz", @"83.0.json.gz", - @"98.json.gz", // CBW - @"99.json.gz", // CWD + // SBB +// @"18.json.gz", @"19.json.gz", @"1A.json.gz", @"1B.json.gz", @"1C.json.gz", @"1D.json.gz", +// @"80.3.json.gz", @"81.3.json.gz", @"83.3.json.gz", - // ESC - @"D8.json.gz", @"D9.json.gz", @"DA.json.gz", @"DB.json.gz", - @"DC.json.gz", @"DD.json.gz", @"DE.json.gz", @"DE.json.gz", - - // NOP - @"90.json.gz", - - // ADC - @"10.json.gz", @"11.json.gz", @"12.json.gz", @"13.json.gz", @"14.json.gz", @"15.json.gz", - @"80.2.json.gz", @"81.2.json.gz", @"83.2.json.gz", - - // ADD - @"00.json.gz", @"01.json.gz", @"02.json.gz", @"03.json.gz", @"04.json.gz", @"05.json.gz", - @"80.0.json.gz", @"81.0.json.gz", @"83.0.json.gz", + // SUB + @"28.json.gz", //@"29.json.gz", @"2A.json.gz", @"2B.json.gz", @"2C.json.gz", @"2D.json.gz", +// @"80.5.json.gz", @"81.5.json.gz", @"83.5.json.gz", // 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", - - // CALL - @"E8.json.gz", @"FF.2.json.gz", - @"9A.json.gz", @"FF.3.json.gz", - - @"F8.json.gz", // CLC - @"FC.json.gz", // CLD - @"FA.json.gz", // CLI - @"F5.json.gz", // CMC +// @"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", +// +// // CALL +// @"E8.json.gz", @"FF.2.json.gz", +// @"9A.json.gz", @"FF.3.json.gz", +// +// @"F8.json.gz", // CLC +// @"FC.json.gz", // CLD +// @"FA.json.gz", // CLI +// @"F5.json.gz", // CMC ]]; NSSet *ignoreList = nil;