Skip to content

Conversation

nemecad
Copy link

@nemecad nemecad commented Sep 4, 2025

This PR addresses some previous feedback, most notably:

  • Set-associative TLB (machine::TLB): Implements a set-associative Translation Lookaside Buffer (TLB) frontend over physical memory, handling virtual to physical translation, flush, and replacement policy.
  • Pluggable Replacement Policies (machine::TLBPolicy): Abstract TLB replacement policy interface & implementations (RAND, LRU, LFU, PLRU) for set-associative tables.
  • SV32 Page-Table Walker (machine::PageTableWalker): Performs multi-level page-table walks (SV32) in memory to resolve a virtual address to a physical one.
  • Sv32Pte Bitfield Helpers (sv32.h): SV32-specific definitions: page-table entry (PTE) bitfields, shifts/masks, and PTE to physical address helpers.
  • VirtualAddress (virtual_address.h): Lightweight VirtualAddress wrapper offering raw access, alignment checks, arithmetic, and comparisons.
  • Add supervisor CSRs and sstatus handling: supervisor CSRs (sstatus, stvec, sscratch, sepc, scause, stval, satp) and a write handler that presents sstatus as a masked view of mstatus so supervisor-visible bits stay in sync.
  • Store current privilege level in CoreState: tracking of the hart's current privilege level in CoreState so exception/return handling and visualization can read/update it from the central CoreState structure.

Tests:

  • Add SV32 page-table + TLB integration tests: a set of small assembly tests that exercise the SV32 page-table walker, SATP enablement and the new TLB code. The tests create a root page table and map a virtual page at 0xC4000000, then exercise several scenarios. The tests verify page-table walker behaviour, SATP switching and TLB caching/flush logic. Tests were written based on the consultation.

UI Components:

  • Show current privilege level in core state view:
Snímek obrazovky 2025-09-04 115127
  • Virtual memory configuration to NewDialog:
Snímek obrazovky 2025-09-04 115904
  • TLB visualization and statistics dock:
Snímek obrazovky 2025-09-04 115521
  • VM toggle and "As CPU" memory access view:
Snímek obrazovky 2025-09-04 120034

Add tracking of the hart's current privilege level to the core state so code
handling exceptions/returns and visualization can read/update it from the
central CoreState structure.
Add supervisor CSRs (sstatus, stvec, sscratch, sepc, scause, stval, satp)
and a write handler that presents sstatus as a masked view of mstatus so
supervisor-visible bits stay in sync.
Add a configurable TLB and a full SV32 page-table walker.
The walker implements two-level SV32 walks
and raises page-fault exceptions for invalid mappings.
The TLB supports I/D caches, SATP awareness (SATP
writes flush the TLB), and caching of resolved mappings.
Add a set of small assembly tests that exercise the SV32 page-table walker,
SATP enablement and the new TLB code. The tests create a root page
table and map a virtual page at 0xC4000000, then exercise several scenarios.
The tests verify page-table walker behaviour, SATP switching and TLB caching/flush logic.
Tests were written based on the consultation.
Add privilege level mapping to the GUI so the current hart privilege
(UNPRIV, SUPERV, HYPERV, MACHINE) is displayed in core state visualization.
Extend NewDialog with controls for virtual memory setup, including TLB
number of sets, associativity, and replacement policy.
Introduce new components for displaying and
tracking TLB state similar to cache. TLBViewBlock and TLBAddressBlock render per-set
and per-way TLB contents, updated on tlb_update signals. TLBViewScene
assembles these views based on associativity. TLBDock integrates into
the GUI, showing hit/miss counts, memory accesses, stall cycles, hit rate,
and speed improvement, with live updates from the TLB.
Extend memory viewer with a checkbox to toggle between
virtual and physical address display when VM is enabled.
Introduce an "As CPU" access option in the cached access selector to
render memory contents as observed by the CPU through the
frontend interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant