1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-04-19 20:37:34 +00:00

Use indexed descriptors.

This commit is contained in:
Thomas Harte 2025-03-21 11:20:33 -04:00
parent e7218c0321
commit d3dbdb153c
3 changed files with 22 additions and 35 deletions

View File

@ -159,7 +159,8 @@ public:
// Helper for instruction fetch.
//
std::pair<const uint8_t *, size_t> next_code() const {
const uint32_t start = segments_.cs_.to_linear(registers_.ip());
const uint32_t start =
segments_.descriptors[InstructionSet::x86::Source::CS].to_linear(registers_.ip()) & 0xf'ffff;
return std::make_pair(&memory[start], 0x10'000 - start);
}
@ -183,18 +184,8 @@ private:
Registers<x86_model> &registers_;
const Segments<x86_model> &segments_;
const InstructionSet::x86::Descriptor &descriptor(const InstructionSet::x86::Source segment) const {
using Source = InstructionSet::x86::Source;
switch(segment) {
default: return segments_.ds_;
case Source::ES: return segments_.es_;
case Source::CS: return segments_.cs_;
case Source::SS: return segments_.ss_;
}
}
uint32_t address(const InstructionSet::x86::Source segment, const uint16_t offset) const {
return descriptor(segment).to_linear(offset) & 0xf'ffff;
return segments_.descriptors[segment].to_linear(offset) & 0xf'ffff;
}
template <AccessType type>

View File

@ -47,21 +47,26 @@ public:
uint16_t &ip() { return ip_; }
uint16_t &es() { return es_; }
uint16_t &cs() { return cs_; }
uint16_t &ds() { return ds_; }
uint16_t &ss() { return ss_; }
uint16_t es() const { return es_; }
uint16_t cs() const { return cs_; }
uint16_t ds() const { return ds_; }
uint16_t ss() const { return ss_; }
uint16_t &es() { return segments_[Source::ES]; }
uint16_t &cs() { return segments_[Source::CS]; }
uint16_t &ds() { return segments_[Source::DS]; }
uint16_t &ss() { return segments_[Source::SS]; }
uint16_t es() const { return segments_[Source::ES]; }
uint16_t cs() const { return segments_[Source::CS]; }
uint16_t ds() const { return segments_[Source::DS]; }
uint16_t ss() const { return segments_[Source::SS]; }
uint16_t segment(const InstructionSet::x86::Source segment) const {
return segments_[segment];
}
void reset() {
cs_ = 0xffff;
segments_[Source::CS] = 0xffff;
ip_ = 0;
}
private:
using Source = InstructionSet::x86::Source;
CPU::RegisterPair16 ax_;
CPU::RegisterPair16 cx_;
CPU::RegisterPair16 dx_;
@ -71,8 +76,8 @@ private:
uint16_t bp_;
uint16_t si_;
uint16_t di_;
uint16_t es_, cs_, ds_, ss_;
uint16_t ip_;
InstructionSet::x86::SegmentRegisterSet<uint16_t> segments_;
};
template <>

View File

@ -26,13 +26,8 @@ public:
/// Posted by @c perform after any operation which *might* have affected a segment register.
void did_update(const Source segment) {
switch(segment) {
default: break;
case Source::ES: es_.set_segment(registers_.es()); break;
case Source::CS: cs_.set_segment(registers_.cs()); break;
case Source::DS: ds_.set_segment(registers_.ds()); break;
case Source::SS: ss_.set_segment(registers_.ss()); break;
}
if(!is_segment_register(segment)) return;
descriptors[segment].set_segment(registers_.segment(segment));
}
void did_update(DescriptorTable) {}
@ -44,14 +39,10 @@ public:
did_update(Source::SS);
}
Descriptor es_, cs_, ds_, ss_;
InstructionSet::x86::SegmentRegisterSet<Descriptor> descriptors;
bool operator ==(const Segments &rhs) const {
return
es_ == rhs.es_ &&
cs_ == rhs.cs_ &&
ds_ == rhs.ds_ &&
ss_ == rhs.ss_;
return descriptors == rhs.descriptors_;
}
private: