1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-16 11:30:22 +00:00

Implement BOUND.

This commit is contained in:
Thomas Harte 2023-11-13 22:33:46 -05:00
parent 60cec9fc67
commit 1552500b10
3 changed files with 42 additions and 7 deletions

View File

@ -213,7 +213,27 @@ void into(
ContextT &context
) {
if(context.flags.template flag<Flag::Overflow>()) {
interrupt(Interrupt::OnOverflow, context);
interrupt(Interrupt::Overflow, context);
}
}
template <typename IntT, typename InstructionT, typename ContextT>
void bound(
const InstructionT &instruction,
read_t<IntT> destination,
read_t<IntT> source,
ContextT &context
) {
using sIntT = typename std::make_signed<IntT>::type;
const auto source_segment = instruction.data_segment();
context.memory.preauthorise_read(source_segment, source, 2*sizeof(IntT));
const sIntT lower_bound = sIntT(context.memory.template access<uint16_t, AccessType::PreauthorisedRead>(source_segment, source));
source += 2;
const sIntT upper_bound = sIntT(context.memory.template access<uint16_t, AccessType::PreauthorisedRead>(source_segment, source));
if(sIntT(destination) < lower_bound || sIntT(destination) > upper_bound) {
interrupt(Interrupt::BoundRangeExceeded, context);
}
}

View File

@ -328,8 +328,8 @@ template <
}
break;
} else {
// TODO: perform BOUND as of the 80186.
static_assert(int(Operation::SETMOC) == int(Operation::BOUND));
Primitive::bound<IntT>(instruction, destination_r(), source_r(), context);
}
return;

View File

@ -12,11 +12,26 @@
namespace InstructionSet::x86 {
enum Interrupt {
DivideError = 0,
SingleStep = 1,
NMI = 2,
OneByte = 3,
OnOverflow = 4,
DivideError = 0,
SingleStep = 1,
NMI = 2,
Breakpoint = 3,
Overflow = 4,
BoundRangeExceeded = 5,
InvalidOpcode = 6,
DeviceNotAvailable = 7,
DoubleFault = 8,
CoprocessorSegmentOverrun = 9,
InvalidTSS = 10,
SegmentNotPresent = 11,
StackSegmentFault = 12,
GeneralProtectionFault = 13,
PageFault = 14,
/* 15 is reserved */
FloatingPointException = 16,
AlignmentCheck = 17,
MachineCheck = 18,
};
}