1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-25 16:31:42 +00:00

Implement LEAVE, almost.

This commit is contained in:
Thomas Harte 2023-11-14 11:39:36 -05:00
parent 2533fd2da9
commit aafa7de536
2 changed files with 18 additions and 1 deletions

View File

@ -216,8 +216,10 @@ template <
Primitive::idiv<true, IntT>(pair_high(), pair_low(), source_r(), context);
break;
} else {
// TODO: perform LEAVE as of the 80186.
static_assert(int(Operation::IDIV_REP) == int(Operation::LEAVE));
if constexpr (std::is_same_v<IntT, uint16_t> || std::is_same_v<IntT, uint32_t>) {
Primitive::leave<IntT>();
}
}
return;

View File

@ -144,6 +144,21 @@ void pusha(
}
}
template <typename IntT, typename ContextT>
void leave(
ContextT &context
) {
// TODO: should use StackAddressSize to determine assignment of bp to sp.
// Probably make that a static constexpr on registers.
if constexpr (std::is_same_v<IntT, uint32_t>) {
context.registers.esp() = context.registers.ebp();
context.registers.ebp() = pop<uint32_t, false>(context);
} else {
context.registers.sp() = context.registers.bp();
context.registers.bp() = pop<uint16_t, false>(context);
}
}
}
#endif /* Stack_hpp */