Add MRAC (Memory Region Access Control) emulation#3656
Open
iyernaveenr wants to merge 1 commit intochipsalliance:mainfrom
Open
Add MRAC (Memory Region Access Control) emulation#3656iyernaveenr wants to merge 1 commit intochipsalliance:mainfrom
iyernaveenr wants to merge 1 commit intochipsalliance:mainfrom
Conversation
1729a0c to
dae5a65
Compare
Add optional emulation of the VeeR EL2 MRAC CSR (0x7C0) as a Bus wrapper that enforces per-region access rules: - Side-effect regions: reject non-word-aligned or non-word-sized access - Cacheable regions: widen reads to 64-bit aligned double-word fetches - Illegal combination (cacheable+sideeffect) mapped to sideeffect-only - Off by default (MracBus wraps inner bus, disabled flag bypasses checks) Add MRAC CSR to CsrFile with shared Rc<Cell<u32>> for synchronization between the CSR write path and the MracBus enforcement layer. Closes: chipsalliance#3601 Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.com>
dae5a65 to
42edadc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add MRAC (Memory Region Access Control) emulation
Implements MRAC CSR (0x7C0) support in the VeeR EL2 emulator, as described in the VeeR EL2 spec.
What this does
The 32-bit address space is split into 16 fixed 256MB regions, each with 2 control bits in the MRAC CSR:
LoadAddrMisaligned/StoreAddrMisaligned.Implementation
MracBus<TBus: Bus>wrapper insw-emulator/lib/bus/src/mrac_bus.rsthat intercepts reads/writes and enforces the region access rules before delegating to the inner bus.MRAC CSR (0x7C0) added to
CsrFilewith a sharedRc<Cell<u32>>that syncs CSR writes to the bus wrapper.--mracCLI flag on the emulator binary. When enabled, MRAC enforcement is active. When disabled (default), all accesses pass through unchanged.Why this matters
Without MRAC enforcement, the emulator does not detect access pattern bugs that would fail on real hardware. For example, reading a mailbox register at offset 4 in a non-side-effect region triggers a widened 64-bit read that also reads the adjacent lock register at offset 0 -- silently acquiring the lock. The side-effect flag prevents this by restricting reads to the exact requested address.
hw-model integration
The hw-model (
model_emulated.rs) is also wrapped inMracBus, but with enforcement disabled by default. This allows the infrastructure to be in place for future enabling. When enabled (MracBus::new(..., true)), 4 out of 30 hw-model tests fail due to mailbox access patterns that do not set the MRAC side-effect flag -- confirming that MRAC enforcement catches real access bugs. Enabling by default requires firmware/test updates to configure MRAC CSR correctly.Tests
9 unit tests covering:
Files changed
sw-emulator/lib/bus/src/mrac_bus.rs- new MracBus wrapper + 9 unit testssw-emulator/lib/bus/src/lib.rs- added mrac_bus module + exportsw-emulator/lib/cpu/src/csr_file.rs- added MRAC CSR (0x7C0)sw-emulator/lib/cpu/src/cpu.rs- added mrac param to Cpu::newsw-emulator/app/src/main.rs- --mrac CLI flag, MracBus wrappingsw-emulator/app/src/gdb/gdb_target.rs- updated Cpu typesw-emulator/compliance-test/src/main.rs- updated Cpu::new callssw-emulator/lib/cpu/src/instr/test_macros.rs- updated Cpu::new callshw-model/src/model_emulated.rs- wrapped in MracBus (disabled by default), updated all bus access pathsCloses #3601