Skip to main content

Regs

Struct Regs 

Source
pub struct Regs {
    pub r: [u32; 16],
    pub cpsr: Cpsr,
    /* private fields */
}
Expand description

The ARM register file: R0-R15 plus every mode’s banked registers and SPSR.

Banking follows real ARM hardware (and Mesen2’s SwitchMode) exactly: R8-R12 are shared by every mode EXCEPT FIQ (which gets its own private R8-R12); R13/R14 are banked separately per mode, INCLUDING a distinct “User” bank from the four privileged non-FIQ modes’ banks. This project’s other CPU cores don’t need this pattern (the 65C816 and SA-1 have no register banking), so it has no existing precedent to crib the shape from — ported straight from the reference memcpy-based save/restore sequence as explicit slice copies.

Fields§

§r: [u32; 16]

R0-R15 (R15 = PC) — the currently-banked-in view every instruction reads/writes.

§cpsr: Cpsr

The live CPSR (current mode + interrupt masks + condition flags).

Implementations§

Source§

impl Regs

Source

pub fn switch_mode(&mut self, new_mode: Mode)

Switch the active processor mode, banking R8-R14 in/out exactly like real ARM hardware (Mesen2 SwitchMode).

new_mode is masked to its real 5-bit hardware width THEN OR’d with mode::BIT unconditionally (bit 4 is always set on real hardware — every caller, including MSR’s raw mode field, relies on this rather than validating it themselves). The mask keeps self.cpsr.mode a clean 5-bit value everywhere it’s read (in particular Cpsr::to_u32’s packed layout, where a stray high bit would corrupt the adjacent interrupt-mask/reserved bits) even if some future caller passes an unmasked byte. A no-op if the mode is already active (matches the source’s early-return, and avoids a redundant full 7-register bank round-trip on every same-mode MSR).

Source

pub const fn spsr(&self) -> Cpsr

The current mode’s SPSR (Mesen2 GetSpsr). User/System (and any unrecognized mode, matching the source’s default: fallback) have no real SPSR; reading/writing it there is architecturally UNPREDICTABLE, and this port follows the source’s own choice of aliasing the live CPSR itself as a harmless, safe fallback rather than inventing new behavior.

Source

pub const fn spsr_mut(&mut self) -> &mut Cpsr

Mutable access to the current mode’s SPSR — see Self::spsr.

Trait Implementations§

Source§

impl Clone for Regs

Source§

fn clone(&self) -> Regs

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Regs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Regs

Source§

fn default() -> Regs

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Regs

Source§

fn eq(&self, other: &Regs) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Regs

Source§

impl Eq for Regs

Source§

impl StructuralPartialEq for Regs

Auto Trait Implementations§

§

impl Freeze for Regs

§

impl RefUnwindSafe for Regs

§

impl Send for Regs

§

impl Sync for Regs

§

impl Unpin for Regs

§

impl UnsafeUnpin for Regs

§

impl UnwindSafe for Regs

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.