Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] SBE/UBE/MBE Bit in mstatus Register Does Not Affect Endianness of Explicit Memory Accesses #2695

Open
1 task done
riscv914 opened this issue Jan 8, 2025 · 0 comments
Labels
Type:Bug For bugs in the RTL, Documentation, Verification environment or Tool and Build system

Comments

@riscv914
Copy link

riscv914 commented Jan 8, 2025

Is there an existing CVA6 bug for this?

  • I have searched the existing bug issues

Bug Description

According to the RISC-V ISA specification, the MBE, SBE, and UBE bits in the mstatus and mstatush registers control the endianness of memory accesses, except for instruction fetches, which are always little-endian. Specifically:

  • MBE controls whether memory accesses from M-mode are little-endian (MBE=0) or big-endian (MBE=1).
  • SBE controls the endianness for memory accesses in S-mode, provided S-mode is supported.
  • UBE controls the endianness for memory accesses in U-mode, provided U-mode is supported.
  • The SBE field is essential for controlling endianness in supervisor-level memory management operations like page table accesses. If the SBE bit changes, M-mode software is required to execute the SFENCE.VMA instruction to ensure consistency in accessing supervisor-level structures.

However, on the CVA6 core, setting the MBE bit in mstatus does not affect the expected behavior of explicit load and store operations. Specifically, even when the MBE bit is manipulated (by clearing or setting it), the endianness of the subsequent sw (store word) and lb (load byte) instructions is not affected as expected.


Code for Reproducing the Bug:

asm volatile ("csrr t0, mstatus");
asm volatile ("li t0, 0x2000000000"); // Clear MBE (bit 20)
asm volatile ("csrc mstatus, t0");
asm volatile ("csrr t0, mstatus");
asm volatile ("li t0, 0x12345678");
asm volatile ("li t1, 0x81000000");
asm volatile ("sw t0, 0(t1)");
asm volatile ("lb t0, 0(t1)");

asm volatile ("li t0, 0x2000000000"); // Set MBE (bit 20)
asm volatile ("csrs mstatus, t0");
asm volatile ("csrr t0, mstatus");
asm volatile ("li t0, 0x12345678");
asm volatile ("li t1, 0x81000000");
asm volatile ("sw t0, 0(t1)");
asm volatile ("lb t0, 0(t1)");
asm volatile ("addi t0,t0,0");

Expected Behavior:

When the MBE bit in mstatus is cleared or set, the endianness of memory accesses (explicit loads and stores) should change accordingly. Specifically, the sw (store word) and lb (load byte) instructions should behave as expected with the appropriate endianness (little-endian when MBE=0, big-endian when MBE=1).


Observed Behavior:

When manipulating the MBE bit in mstatus, the endianness of memory accesses is not affected, and the behavior of sw and lb instructions does not change as expected.


CVA6 commit: 2155d0e
Build config: cv64a6_imafdch_sv39_wb

@riscv914 riscv914 added the Type:Bug For bugs in the RTL, Documentation, Verification environment or Tool and Build system label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type:Bug For bugs in the RTL, Documentation, Verification environment or Tool and Build system
Projects
None yet
Development

No branches or pull requests

1 participant