MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / writeback_csrrw

Function writeback_csrrw

crates/virtual-machine/tests/vm_writeback.rs:115–139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113
114#[test]
115fn writeback_csrrw() {
116 let mut regs = Registers::new();
117 let mut csrs = CsrFile::new();
118
119 // Set initial MSTATUS: 0x0234 has MPP[12:11]=0 (User, valid) - no WARL change
120 csrs.write(addr::MSTATUS, 0x0234)
121 .expect("writeback should succeed");
122
123 let mem_result = MemResult::Csr {
124 funct3: 1, // CSRRW
125 rd: 5,
126 rs1_uimm: 0,
127 csr: addr::MSTATUS,
128 operand: 0x4678, // MPP[12:11]=0 (valid), no WARL change
129 old_val: 0x0234,
130 next_pc: 0x8000_0004,
131 };
132
133 let next_pc = writeback(mem_result, &mut regs, &mut csrs).expect("writeback should succeed");
134
135 // Old value written to rd
136 assert_eq!(regs.read_x(5), 0x0234);
137 // New value written to CSR
138 assert_eq!(
139 csrs.read(addr::MSTATUS).expect("writeback should succeed"),
140 0x4678
141 );
142 assert_eq!(next_pc, 0x8000_0004);

Callers

nothing calls this directly

Calls 2

writebackFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected