1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-03-25 06:30:38 +00:00

Add 286 and 386 instruction length tests.

This commit is contained in:
Thomas Harte 2022-03-11 09:48:51 -05:00
parent 91d75d7704
commit 40cafb95ed

View File

@ -29,14 +29,14 @@ template <typename InstructionT> void test(
const InstructionT &instruction,
DataSize size,
Operation operation,
InstructionSet::x86::DataPointer source,
std::optional<InstructionSet::x86::DataPointer> source,
std::optional<InstructionSet::x86::DataPointer> destination = std::nullopt,
std::optional<typename InstructionT::ImmediateT> operand = std::nullopt,
std::optional<typename InstructionT::DisplacementT> displacement = std::nullopt) {
XCTAssertEqual(instruction.operation_size(), InstructionSet::x86::DataSize(size));
XCTAssertEqual(instruction.operation, operation);
XCTAssert(instruction.source() == source);
if(source) XCTAssert(instruction.source() == *source);
if(destination) XCTAssert(instruction.destination() == *destination);
if(operand) XCTAssertEqual(instruction.operand(), *operand);
if(displacement) XCTAssertEqual(instruction.displacement(), *displacement);
@ -557,4 +557,75 @@ std::vector<typename InstructionSet::x86::Decoder<model>::InstructionT> decode(c
test(instructions[0], DataSize::DWord, Operation::ADD, Source::Immediate, ScaleIndexBase(Source::eDI), 0x9f683aa9, -0x42);
}
- (void)test286LengthLimit {
const auto instructions = decode<Model::i80286>({
0x90,
0x26, 0x90,
0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
});
XCTAssertEqual(instructions.size(), 12);
test(instructions[0], Operation::NOP);
test(instructions[1], Operation::NOP);
test(instructions[2], Operation::NOP);
test(instructions[3], Operation::NOP);
test(instructions[4], Operation::NOP);
test(instructions[5], Operation::NOP);
test(instructions[6], Operation::NOP);
test(instructions[7], Operation::NOP);
test(instructions[8], Operation::NOP);
test(instructions[9], Operation::NOP);
test(instructions[10], Operation::Invalid);
test(instructions[11], Operation::NOP);
}
- (void)test386LengthLimit {
const auto instructions = decode<Model::i80386>({
0x90,
0x26, 0x90,
0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x90,
});
XCTAssertEqual(instructions.size(), 17);
test(instructions[0], Operation::NOP);
test(instructions[1], Operation::NOP);
test(instructions[2], Operation::NOP);
test(instructions[3], Operation::NOP);
test(instructions[4], Operation::NOP);
test(instructions[5], Operation::NOP);
test(instructions[6], Operation::NOP);
test(instructions[7], Operation::NOP);
test(instructions[8], Operation::NOP);
test(instructions[9], Operation::NOP);
test(instructions[10], Operation::NOP);
test(instructions[11], Operation::NOP);
test(instructions[12], Operation::NOP);
test(instructions[13], Operation::NOP);
test(instructions[14], Operation::NOP);
test(instructions[15], Operation::Invalid);
test(instructions[16], Operation::NOP);
}
@end