mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-09 00:37:27 +00:00
Add a force-user-aware accessor.
This commit is contained in:
parent
dd127f64fe
commit
41c471ca52
@ -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 ®(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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user