1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-29 16:55:59 +00:00

Extend SIB test, correct decoder.

This commit is contained in:
Thomas Harte 2022-03-08 15:03:37 -05:00
parent 0cbb481fa4
commit 926a373591
3 changed files with 8 additions and 7 deletions

View File

@ -629,7 +629,7 @@ std::pair<int, typename Decoder<model>::InstructionT> Decoder<model>::decode(con
displacement_size_ = sizes[mod];
memreg = Source::Indirect;
if(allow_sib_) {
if(address_size_ == AddressSize::b32) {
// 32-bit decoding: the range of potential indirections is expanded,
// and may segue into obtaining a SIB.
sib_ = ScaleIndexBase(0, Source::None, reg_table[rm]);
@ -931,7 +931,6 @@ template <Model model> void Decoder<model>::set_32bit_protected_mode(bool enable
return;
}
allow_sib_ = enabled;
if(enabled) {
default_address_size_ = address_size_ = AddressSize::b32;
default_data_size_ = data_size_ = DataSize::DWord;

View File

@ -196,7 +196,6 @@ template <Model model> class Decoder {
DataSize default_data_size_ = DataSize::Word;
AddressSize address_size_ = AddressSize::b16;
DataSize data_size_ = DataSize::Word;
bool allow_sib_ = false;
/// Resets size capture and all fields with default values.
void reset_parsing() {

View File

@ -333,13 +333,16 @@ std::vector<typename InstructionSet::x86::Decoder<model>::InstructionT> decode(c
- (void)testSIB {
const auto instructions = decode<Model::i80386>({
// add edx, -0x7d(ebp + eax*2)
0x01, 0x54, 0x45, 0x83
0x01, 0x54, 0x45, 0x83,
// add edx, -0x80(si)
0x67, 0x01, 0x54, 0x80,
}, true);
XCTAssertEqual(instructions.size(), 1);
XCTAssertEqual(instructions.size(), 2);
test(instructions[0], DataSize::DWord, Operation::ADD, Source::eDX, ScaleIndexBase(1, Source::eAX, Source::eBP), 0x00, -125);
// Noting that a multiplier of 2 is a scale of 1,
// since the scale is in log2.
test(instructions[1], DataSize::DWord, Operation::ADD, Source::eDX, ScaleIndexBase(Source::eSI), 0x00, -128);
XCTAssertEqual(instructions[1].address_size(), AddressSize::b16);
}
@end