Skip to content

Commit 4699214

Browse files
elliott10eternalcomet
authored andcommitted
Workaround to enable Sstatus.VS vector status bit for sg2002
1 parent 7af0f9d commit 4699214

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/riscv/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn sstatus_read() -> usize {
127127
pub fn flush_icache() {
128128
riscv::asm::fence_i();
129129

130-
/// Flushes the instruction cache for T-Head C9xx cores.
130+
// Flushes the instruction cache for T-Head C9xx cores.
131131
#[cfg(feature = "sg2002")]
132132
unsafe {
133133
// Ensure instruction fetch sees latest memory contents.

src/riscv/uspace.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,27 @@ impl UserContext {
2525
/// Creates a new context with the given entry point, user stack pointer,
2626
/// and the argument.
2727
pub fn new(entry: usize, ustack_top: VirtAddr, arg0: usize) -> Self {
28-
let flags = 0;
29-
#[cfg(feature = "fp-simd")]
30-
let flags = (0x3 << 23); // sstatus.VS
31-
32-
let mut sstatus = Sstatus::from_bits(0 | flags);
28+
let mut sstatus = Sstatus::from_bits(0);
3329
sstatus.set_spie(true); // enable interrupts
3430
sstatus.set_sum(true); // enable user memory access in supervisor mode
3531
#[cfg(feature = "fp-simd")]
3632
sstatus.set_fs(FS::Initial); // set the FPU to initial state
33+
info!(
34+
"UserContext new sstatus={:#x}, BITMASK={:#x}",
35+
sstatus.bits(),
36+
Sstatus::BITMASK
37+
);
38+
39+
#[cfg(feature = "sg2002")]
40+
unsafe {
41+
let set_sstatus = &mut sstatus as *mut Sstatus as *mut usize;
42+
let old_bits = *set_sstatus;
43+
44+
info!("Setting sstatus.VS for sg2002");
45+
*set_sstatus = old_bits | (0x3 << 23);
46+
debug!("Set sstatus new bits: {:#x}", *set_sstatus);
47+
}
3748

38-
debug!("UserContext new sstatus={:#x}", sstatus.bits());
3949
Self(TrapFrame {
4050
regs: GeneralRegisters {
4151
a0: arg0,

0 commit comments

Comments
 (0)