1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Capture default segments, fix base/index confusion.

This commit is contained in:
Thomas Harte 2023-09-22 11:07:09 -04:00
parent 13f49fe8bf
commit 9f63db991c
3 changed files with 43 additions and 19 deletions

View File

@ -663,19 +663,16 @@ std::pair<int, typename Decoder<model>::InstructionT> Decoder<model>::decode(con
// Classic 16-bit decoding: mode picks a displacement size,
// and a few fixed index+base pairs are defined.
constexpr ScaleIndexBase rm_table[8] = {
ScaleIndexBase(0, Source::eBX, Source::eSI),
ScaleIndexBase(0, Source::eBX, Source::eDI),
ScaleIndexBase(0, Source::eBP, Source::eSI),
ScaleIndexBase(0, Source::eBP, Source::eDI),
ScaleIndexBase(0, Source::None, Source::eSI),
ScaleIndexBase(0, Source::None, Source::eDI),
ScaleIndexBase(0, Source::None, Source::eBP),
ScaleIndexBase(0, Source::None, Source::eBX),
ScaleIndexBase(0, Source::eSI, Source::eBX),
ScaleIndexBase(0, Source::eDI, Source::eBX),
ScaleIndexBase(0, Source::eSI, Source::eBP),
ScaleIndexBase(0, Source::eDI, Source::eBP),
ScaleIndexBase(0, Source::eSI, Source::None),
ScaleIndexBase(0, Source::eDI, Source::None),
ScaleIndexBase(0, Source::eBP, Source::None),
ScaleIndexBase(0, Source::eBX, Source::None),
};
// TODO: unless overridden, BP and SP are always relative to ss; SI to ds; DI to es.
// Capture that.
sib_ = rm_table[rm];
}
}

View File

@ -623,6 +623,22 @@ class DataPointer {
return sib_.index();
}
/// @returns The default segment to use for this access.
constexpr Source default_segment() const {
switch(source_) {
default: return Source::None;
case Source::Indirect:
case Source::IndirectNoBase:
switch(base()) {
default: return Source::DS;
case Source::eBP:
case Source::eSP: return Source::SS;
case Source::eDI: return Source::ES;
}
}
}
template <bool obscure_indirectNoBase = false> constexpr Source base() const {
if constexpr (obscure_indirectNoBase) {
return (source_ <= Source::IndirectNoBase) ? Source::None : sib_.base();

View File

@ -131,14 +131,25 @@ constexpr char TestSuiteHome[] = "/Users/tharte/Projects/ProcessorTests/8088/v1"
instruction.operation_size() == InstructionSet::x86::DataSize::Byte ? 2 : 4
);
case Source::Indirect:
return (std::stringstream() <<
'[' <<
InstructionSet::x86::to_string(pointer.index(), data_size(instruction.address_size())) << '+' <<
InstructionSet::x86::to_string(pointer.base(), data_size(instruction.address_size())) << '+' <<
std::setfill('0') << std::setw(4) << std::uppercase << std::hex << instruction.offset() << 'h' <<
']'
).str();
case Source::Indirect: {
std::stringstream stream;
Source segment = Source::None;
switch(instruction.data_segment()) {
default: segment = instruction.data_segment(); break;
case Source::None: segment = pointer.default_segment(); break;
}
if(segment != Source::None && segment != Source::DS) {
stream << InstructionSet::x86::to_string(segment, InstructionSet::x86::DataSize::None) << ':';
}
stream << '[';
stream << InstructionSet::x86::to_string(pointer.base(), data_size(instruction.address_size())) << '+';
stream << InstructionSet::x86::to_string(pointer.index(), data_size(instruction.address_size())) << '+';
stream << std::setfill('0') << std::setw(4) << std::uppercase << std::hex << instruction.offset() << 'h';
stream << ']';
return stream.str();
}
case Source::DirectAddress:
return (std::stringstream() <<