Skip to main content

Tlb

Struct Tlb 

Source
pub struct Tlb { /* private fields */ }
Expand description

The joint TLB plus its instruction micro-TLB.

Implementations§

Source§

impl Tlb

Source

pub const fn new() -> Self

A TLB in its power-on state.

The manual calls the reset contents undefined (UM §6.4.4, p. 183) and ADR 0004 requires reproducibility, so a fixed state must be chosen — but all-zero is not a usable choice, and that is not obvious.

Zeroing gives all 32 entries VPN2 = 0 and ASID = 0. Since V does not participate in matching, any access to virtual page-pair 0 then matches all 32 entries at once, which is the TLB-shutdown condition — so the very first KUSEG access to low memory would brick the TLB.

Each entry therefore gets a distinct VPN2 near the top of the field, so no two coincide and none sits where software is likely to look. Recorded as accuracy-ledger D-4: a deliberate deviation, chosen because real hardware powers up with arbitrary contents that do not coincide, and zero is the one arbitrary value that does.

Source

pub const fn is_shutdown(&self) -> bool

Has the TLB shut down? “the processor must be reset to restart” (UM Fig. 6-6, p. 167).

Source

pub const fn entry(&self, i: usize) -> Entry

Read an entry (for TLBR and for tests).

Source

pub const fn page_size(mask: u32) -> u64

The page size an entry maps, in bytes, from its PageMask.

PageMask bits 24:13 select 4K…16M (UM Table 5-7, p. 149). “When the Mask field is not one of the values shown in Table 5-7, the operation of the TLB is undefined” — we take the mask at face value, which is a documented-undefined choice rather than a hardware fact.

Source

pub const fn pair_size(mask: u32) -> u64

The size of the even/odd pair an entry covers — twice Tlb::page_size, and the granularity the VPN2 tag is compared at.

Source

pub fn lookup( &mut self, vaddr: u64, asid: u8, store: bool, ) -> Result<Translated, TlbFault>

Look up a virtual address.

store selects the D-bit check; asid is the current EntryHi.ASID.

§Errors

TlbFault describing which of the three TLB exceptions to raise.

Source

pub fn write_entry(&mut self, index: usize, cop0: &Cop0)

TLBWI / TLBWR — write EntryHi/EntryLo0/EntryLo1/PageMask into entry index.

Source

pub fn read_entry(&self, index: usize, cop0: &mut Cop0)

TLBR — read entry index back into the COP0 registers.

Source

pub fn probe(&self, cop0: &mut Cop0)

TLBP — probe for an entry matching the current EntryHi.

Sets Index to the matching index, or sets Index.P (bit 31) on a miss: “Set to 1 when the previous TLBProbe (TLBP) instruction was unsuccessful” (UM §5.4.1, p. 146).

What the low bits hold on a miss is undocumented (accuracy-ledger U-2). This implementation leaves them zero — a guess, not a fact.

Source

pub fn jtlb_has_match(&self, vaddr: u64, asid: u8) -> bool

Does any entry match, without translating or shutting down?

Used by the instruction-fetch path to decide whether a micro-TLB reload can actually happen: the 3-PCycle penalty is “incurred when the micro-TLB is updated from the JTLB” (UM §4.6.2), so a lookup that misses the JTLB too must not be charged for a reload that never occurred.

Source

pub fn itlb_probe(&mut self, vaddr: u64, asid: u8) -> bool

Probe the instruction micro-TLB, reporting whether it hit.

A miss costs ITLB_MISS_PCYCLES and is a stall, not an exception — the JTLB is then consulted, and only a JTLB miss raises.

Source

pub fn itlb_fill(&mut self, vaddr: u64, asid: u8)

Fill a micro-TLB way from the JTLB after a miss.

Trait Implementations§

Source§

impl Clone for Tlb

Source§

fn clone(&self) -> Tlb

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 Tlb

Source§

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

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

impl Default for Tlb

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Tlb

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 PartialEq for Tlb

Source§

fn eq(&self, other: &Tlb) -> 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 Serialize for Tlb

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

impl Eq for Tlb

Source§

impl StructuralPartialEq for Tlb

Auto Trait Implementations§

§

impl Freeze for Tlb

§

impl RefUnwindSafe for Tlb

§

impl Send for Tlb

§

impl Sync for Tlb

§

impl Unpin for Tlb

§

impl UnsafeUnpin for Tlb

§

impl UnwindSafe for Tlb

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>,