1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-17 21:30:14 +00:00

Add a force-user-aware accessor.

This commit is contained in:
Thomas Harte 2024-04-04 20:17:44 -04:00
parent dd127f64fe
commit 41c471ca52

View File

@ -342,6 +342,33 @@ struct Registers {
return active_[static_cast<size_t>(offset)];
}
/// @returns A reference to the register at @c offset. If @c force_user_mode is true,
/// this will the the user-mode register. Otherwise it'll be that for the current mode. These references
/// are guaranteed to remain valid only until the next mode change.
template <bool force_user_mode>
uint32_t &reg(uint32_t offset) {
if constexpr (!force_user_mode) {
return active_[offset];
}
switch(mode_) {
case Mode::User: return active_[offset];
case Mode::Supervisor:
case Mode::IRQ:
if(offset == 13 || offset == 14) {
return user_registers_[offset - 8];
}
return active_[offset];
case Mode::FIQ:
if(offset >= 8 && offset < 15) {
return user_registers_[offset - 8];
}
return active_[offset];
}
}
private:
Mode mode_ = Mode::Supervisor;