mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-26 15:32:04 +00:00
Capture default segments, fix base/index confusion.
This commit is contained in:
parent
13f49fe8bf
commit
9f63db991c
@ -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];
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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() <<
|
||||
|
Loading…
x
Reference in New Issue
Block a user