1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Implement PUSHes and POPs.

This commit is contained in:
Thomas Harte 2023-10-18 15:59:39 -04:00
parent 02cea3047e
commit 617be7cba7
2 changed files with 39 additions and 5 deletions

View File

@ -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 <typename IntT, typename MemoryT, typename RegistersT>
void push(IntT value, MemoryT &memory, RegistersT &registers) {
void push(IntT &value, MemoryT &memory, RegistersT &registers) {
registers.sp_ -= sizeof(IntT);
memory.template access<IntT>(
InstructionSet::x86::Source::SS,
@ -1341,6 +1343,17 @@ inline void shr(IntT &destination, uint8_t count, Status &status) {
status.set_from<IntT, Flag::Sign, Flag::Zero, Flag::ParityOdd>(destination);
}
template <typename MemoryT, typename RegistersT>
void popf(MemoryT &memory, RegistersT &registers, Status &status) {
status.set(pop<uint16_t>(memory, registers));
}
template <typename MemoryT, typename RegistersT>
void pushf(MemoryT &memory, RegistersT &registers, Status &status) {
uint16_t value = status.get();
push<uint16_t>(value, memory, registers);
}
}
template <
@ -1360,7 +1373,7 @@ template <
[[maybe_unused]] IOT &io
) {
using IntT = typename DataSizeType<data_size>::type;
using AddressT = typename AddressT<is_32bit(model)>::type;
// using AddressT = typename AddressT<is_32bit(model)>::type;
// Establish source() and destination() shorthand to fetch data if necessary.
IntT immediate;
@ -1551,6 +1564,11 @@ template <
return;
case Operation::XLAT: Primitive::xlat<uint16_t>(instruction, memory, registers); return;
case Operation::POP: source() = Primitive::pop<IntT>(memory, registers); break;
case Operation::PUSH: Primitive::push<IntT>(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.

View File

@ -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",