Skip to main content

Cpu

Struct Cpu 

Source
pub struct Cpu {
    pub regs: Regs,
    pub pc: u64,
    pub pipeline: Pipeline,
    pub retired: u64,
}
Expand description

NEC VR4300 architectural state.

This is the skeleton register file only; the decode/execute pipeline, the CP0 TLB, and the CP1 FPU are roadmap phases left as marked TODOs.

Fields§

§regs: Regs

The register file: 32 GPRs plus HI/LO. $zero’s hardwiring lives in Regs::read/Regs::write so no call site can forget it.

§pc: u64

Program counter (virtual address).

§pipeline: Pipeline

The five-stage pipeline: four inter-stage latches plus control state (ADR 0007). Advanced one PClock per Cpu::tick.

§retired: u64

Retired-work tally: instructions retired since power-on, for the golden-log differ.

This is not a time position and nothing schedules against it — the scheduler derives every cycle position from its one master_ticks counter (ADR 0006). A work tally is the one kind of counter that is still allowed to be incremented; see System::cpu_cycles() for the CPU’s position.

Implementations§

Source§

impl Cpu

Source

pub const fn new() -> Self

Construct at power-on / cold reset.

gpr[0] is the architectural zero register. Any phase alignment, where applicable, comes from the seeded scheduler PRNG (the determinism contract — see docs/adr/0004), never the OS RNG.

Source

pub const fn set_pc(&mut self, pc: u64)

Set the program counter (used by golden-log automation harnesses).

Source

pub fn tick<B: Bus>(&mut self, bus: &mut B)

Advance the CPU by one PClock — not one instruction.

The scheduler calls this on every CPU edge (every 2nd master tick, ADR 0006). At least 5 PCycles are required to execute an instruction (UM §4.1), and DDIV stalls the whole pipeline for 69 (UM Table 3-12), so a tick is emphatically not an instruction.

Hot path: keep allocation-free (no Vec/Box in tick). The bus argument is the &mut Bus the scheduler hands down each step. Prefer Cpu::tick_at when a scheduler is present. This path holds the COP0 Count timeline still, because Count is derived from the master clock (ADR 0006) and this function has no access to it — so Count/Compare and the timer interrupt do not advance. That is deliberate: guessing a rate here would be wrong, and Count runs at half PClock, not one step per call.

Source

pub fn tick_at<B: Bus>(&mut self, bus: &mut B, count_now: u64)

Step one PCycle with the scheduler’s Count timeline supplied.

The scheduler owns master_ticks and derives count_ticks from it (ADR 0006); the CPU turns that into the architectural, guest-writable Count. Passing it in rather than incrementing locally is what keeps master_ticks the only incremented counter in the core.

Trait Implementations§

Source§

impl Clone for Cpu

Source§

fn clone(&self) -> Cpu

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 Cpu

Source§

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

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

impl Default for Cpu

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Cpu

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Cpu

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Cpu

§

impl RefUnwindSafe for Cpu

§

impl Send for Cpu

§

impl Sync for Cpu

§

impl Unpin for Cpu

§

impl UnsafeUnpin for Cpu

§

impl UnwindSafe for Cpu

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,