Expand description
Address translation: trit-sliced page tables.
§Why these numbers
A page is 3^6 = 729 trytes, matching the emulator’s allocation granule. A page table entry is one word, three trytes, so a page holds 3^5 = 243 entries and an index into a table is five trits.
Five-trit indices are what make the layout work: a page table is exactly one page. Allocating a table is allocating a page, with nothing left over and nothing spanning a boundary. Seven-trit indices would give a three-level walk instead of four, but each table would then be nine pages.
Four levels of five trits is twenty trits of page number, which with the six-trit offset makes a 26-trit virtual address. That is one trit short of the architectural word, so the top trit of a virtual address must be zero while translation is on. This is the same bargain x86-64 strikes in requiring canonical addresses, and it costs a third of a space nothing is close to filling.
trits 0..6 offset within the page
trits 6..11 level 0 index
trits 11..16 level 1 index
trits 16..21 level 2 index
trits 21..26 level 3 index
trit 26 must be zero§Entry format
trits 0..20 physical page number
trit 20 valid
trit 21 readable
trit 22 writable
trit 23 executable
trit 24 user-accessible
trit 25 leaf: maps a page rather than naming the next table
trit 26 reserved, must be zeroA leaf above level 0 maps a superpage: the index trits not yet consumed join the offset, so a leaf at level 1 maps 3^11 trytes.
Modules§
- flag
- Trit positions of the entry’s flags.
Structs§
- Entry
- One page table entry.
Enums§
- Access
- What an access is for. Each needs a different permission.
Constants§
- INDEX_
TRITS - Trits of index per level.
- LEVELS
- How many levels the walk descends.
- OFFSET_
TRITS - Trits of offset within a page.
- PAGE_
TRYTES - Trytes per page: 3^6.
- PPN_
TRITS - Trits of physical page number in an entry.
Functions§
- index
- The index this level takes from a virtual address.
- is_
canonical - True if the address fits the 26 trits translation can express.
- page_
span - The size in trytes of a page mapped by a leaf at
level. - passthrough
- The part of a virtual address a leaf at
levelpasses through unchanged.