pub struct Regs {
pub gpr: [u64; 32],
pub hi: u64,
pub lo: u64,
}Expand description
General-purpose registers plus the HI/LO multiply-divide pair.
Fields§
§gpr: [u64; 32]32 general-purpose 64-bit registers. Index 0 is architecturally zero;
prefer Regs::read / Regs::write over touching this directly.
hi: u64HI — multiply high half, or division remainder.
lo: u64LO — multiply low half, or division quotient.
Implementations§
Source§impl Regs
impl Regs
Sourcepub const fn read(&self, i: u8) -> u64
pub const fn read(&self, i: u8) -> u64
Read a general register. $zero always reads as 0.
The index is masked to 5 bits first, then the $zero rule is applied
to the masked value. Checking before masking would let read(32) fall
through to gpr[32 & 31] — gpr[0] — and leak it if it were ever
corrupted. This is public API and cannot assume its caller pre-masked.
Sourcepub const fn write(&mut self, i: u8, v: u64)
pub const fn write(&mut self, i: u8, v: u64)
Write a general register. A write to $zero is discarded, which is
architectural, not a convenience: software relies on $zero staying zero
after instructions that nominally target it.
Masked to 5 bits before the $zero check, for the same reason as
Regs::read but with worse consequences: checking first would make
write(32, v) land in gpr[0] and corrupt the architectural zero — in
the one function whose entire purpose is preventing exactly that.