| 167 | assert_eq!(regs.read_x(5), 0x100); |
| 168 | // Bits set: 0x100 | 0x800 = 0x900 |
| 169 | assert_eq!( |
| 170 | csrs.read(addr::MIE).expect("writeback should succeed"), |
| 171 | 0x900 |
| 172 | ); |
| 173 | assert_eq!(next_pc, 0x8000_0004); |
| 174 | } |
| 175 | |
| 176 | #[test] |
| 177 | fn writeback_csrrc_clear_bits() { |
| 178 | let mut regs = Registers::new(); |
| 179 | let mut csrs = CsrFile::new(); |
| 180 | |
| 181 | // Use MIE instead of MIP: MIE has no WARL restrictions so all bits round-trip |
| 182 | csrs.write(addr::MIE, 0xF00) |
| 183 | .expect("writeback should succeed"); |
| 184 | |
| 185 | let mem_result = MemResult::Csr { |
| 186 | funct3: 3, // CSRRC |
| 187 | rd: 5, |
| 188 | rs1_uimm: 12, // a2 register (non-zero means do write) |
| 189 | csr: addr::MIE, |
| 190 | operand: 0x800, // Clear MEIE bit |
| 191 | old_val: 0xF00, |
| 192 | next_pc: 0x8000_0004, |
| 193 | }; |
| 194 | |
| 195 | let next_pc = writeback(mem_result, &mut regs, &mut csrs).expect("writeback should succeed"); |
| 196 | |