From 617be7cba74da32dc32ef13b296df431fd9f59fa Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 18 Oct 2023 15:59:39 -0400 Subject: [PATCH] Implement PUSHes and POPs. --- .../Implementation/PerformImplementation.hpp | 22 +++++++++++++++++-- OSBindings/Mac/Clock SignalTests/8088Tests.mm | 22 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/InstructionSets/x86/Implementation/PerformImplementation.hpp b/InstructionSets/x86/Implementation/PerformImplementation.hpp index d75a848e0..1f030f771 100644 --- a/InstructionSets/x86/Implementation/PerformImplementation.hpp +++ b/InstructionSets/x86/Implementation/PerformImplementation.hpp @@ -165,8 +165,10 @@ IntT *resolve( namespace Primitive { +// The below takes a reference in order properly to handle PUSH SP, which should place the value of SP after the +// push onto the stack. template -void push(IntT value, MemoryT &memory, RegistersT ®isters) { +void push(IntT &value, MemoryT &memory, RegistersT ®isters) { registers.sp_ -= sizeof(IntT); memory.template access( InstructionSet::x86::Source::SS, @@ -1341,6 +1343,17 @@ inline void shr(IntT &destination, uint8_t count, Status &status) { status.set_from(destination); } +template +void popf(MemoryT &memory, RegistersT ®isters, Status &status) { + status.set(pop(memory, registers)); +} + +template +void pushf(MemoryT &memory, RegistersT ®isters, Status &status) { + uint16_t value = status.get(); + push(value, memory, registers); +} + } template < @@ -1360,7 +1373,7 @@ template < [[maybe_unused]] IOT &io ) { using IntT = typename DataSizeType::type; - using AddressT = typename AddressT::type; +// using AddressT = typename AddressT::type; // Establish source() and destination() shorthand to fetch data if necessary. IntT immediate; @@ -1551,6 +1564,11 @@ template < return; case Operation::XLAT: Primitive::xlat(instruction, memory, registers); return; + + case Operation::POP: source() = Primitive::pop(memory, registers); break; + case Operation::PUSH: Primitive::push(source(), memory, registers); break; + case Operation::POPF: Primitive::popf(memory, registers, status); break; + case Operation::PUSHF: Primitive::pushf(memory, registers, status); break; } // Write to memory if required to complete this operation. diff --git a/OSBindings/Mac/Clock SignalTests/8088Tests.mm b/OSBindings/Mac/Clock SignalTests/8088Tests.mm index 9c1d3129b..ed06d0cc3 100644 --- a/OSBindings/Mac/Clock SignalTests/8088Tests.mm +++ b/OSBindings/Mac/Clock SignalTests/8088Tests.mm @@ -391,11 +391,11 @@ struct FailedExecution { @"8D.json.gz", // LEA // TODO: CMPS, LODS, MOVS, SCAS, STOS -*/ + @"E0.json.gz", // LOOPNE @"E1.json.gz", // LOOPE @"E2.json.gz", // LOOP -/* + // MOV @"88.json.gz", @"89.json.gz", @"8A.json.gz", @"8B.json.gz", @"8C.json.gz", @"8E.json.gz", @@ -426,9 +426,25 @@ struct FailedExecution { // NOP @"90.json.gz", +*/ + // POP + @"07.json.gz", @"0F.json.gz", @"17.json.gz", @"1F.json.gz", + @"58.json.gz", @"59.json.gz", @"5A.json.gz", @"5B.json.gz", + @"5C.json.gz", @"5D.json.gz", @"5E.json.gz", @"5F.json.gz", + @"8F.json.gz", - // TODO: POP, POPF, PUSH, PUSHF + // PUSH + @"06.json.gz", @"0E.json.gz", @"16.json.gz", @"1E.json.gz", + @"50.json.gz", @"51.json.gz", @"52.json.gz", @"53.json.gz", + @"54.json.gz", @"55.json.gz", @"56.json.gz", @"57.json.gz", + @"FF.6.json.gz", + // POPF + @"9D.json.gz", + + // PUSHF + @"9C.json.gz", +/* // RCL @"D0.2.json.gz", @"D2.2.json.gz", @"D1.2.json.gz", @"D3.2.json.gz",