1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-10 12:29:01 +00:00

Switch for now to block-level decoding.

It's easier to step debug.
This commit is contained in:
Thomas Harte 2021-01-03 20:07:46 -05:00
parent 29cf96c703
commit a8738b533a

View File

@ -38,22 +38,33 @@ namespace {
- (void)decode:(const std::initializer_list<uint8_t> &)stream {
CPU::Decoder::x86::Decoder decoder(CPU::Decoder::x86::Model::i8086);
// Start with a very dumb implementation: post one byte at a time.
// TODO: test that byte-at-a-time decoding gives the same results, as a freebie.
// instructions.clear();
// for(auto item: stream) {
// const auto next = decoder.decode(&item, 1);
// if(next.size() > 0) {
// instructions.push_back(next);
// }
// }
instructions.clear();
for(auto item: stream) {
const auto next = decoder.decode(&item, 1);
if(next.size() > 0) {
instructions.push_back(next);
}
const uint8_t *byte = stream.begin();
while(byte != stream.end()) {
const auto next = decoder.decode(byte, stream.end() - byte);
if(next.size() <= 0) break;
instructions.push_back(next);
byte += next.size();
}
}
// MARK: - Tests
- (void)testSequence1 {
// 0x6a 0x65 decodes as PUSH $65 in Online Disassembler; The 8086 Book doesn't seem to think that's
// valid. So I've manually omitted it below.
[self decode:{
0x2d, 0x77, 0xea, 0x72, 0xfc, 0x4b, 0xb5, 0x28, 0xc3, 0xca, 0x26, 0x48, 0x65, 0x6d, 0x7b, 0x9f,
0xc2, 0x65, 0x42, 0x4e, 0xef, 0x70, 0x20, 0x94, 0xc4, 0xd4, 0x93, 0x43, 0x3c, 0x8e, 0x6a, 0x65,
0xc2, 0x65, 0x42, 0x4e, 0xef, 0x70, 0x20, 0x94, 0xc4, 0xd4, 0x93, 0x43, 0x3c, 0x8e, /* 0x6a, 0x65, */
0x1a, 0x78, 0x45, 0x10, 0x7f, 0x3c, 0x19, 0x5a, 0x16, 0x31, 0x64, 0x2c, 0xe7, 0xc6, 0x7d, 0xb0,
0xb5, 0x49, 0x67, 0x61, 0xba, 0xc0, 0xcb, 0x14, 0x7e, 0x71, 0xd0, 0x50, 0x78, 0x3d, 0x03, 0x1d,
0xe5, 0xc9, 0x97, 0xc3, 0x9b, 0xe6, 0xd3, 0x6c, 0x58, 0x4d, 0x76, 0x80, 0x44, 0xd6, 0x9f, 0xa5,
@ -63,7 +74,7 @@ namespace {
}];
// 68 instructions are expected.
XCTAssertEqual(instructions.size(), 68);
XCTAssertEqual(instructions.size(), 67);
// sub $0xea77,%ax
// jb 0x00000001