| 140 | 0x4678 |
| 141 | ); |
| 142 | assert_eq!(next_pc, 0x8000_0004); |
| 143 | } |
| 144 | |
| 145 | #[test] |
| 146 | fn writeback_csrrs_set_bits() { |
| 147 | let mut regs = Registers::new(); |
| 148 | let mut csrs = CsrFile::new(); |
| 149 | |
| 150 | // Initial MIE = 0x100 |
| 151 | csrs.write(addr::MIE, 0x100) |
| 152 | .expect("writeback should succeed"); |
| 153 | |
| 154 | let mem_result = MemResult::Csr { |
| 155 | funct3: 2, // CSRRS |
| 156 | rd: 5, |
| 157 | rs1_uimm: 11, // a1 register (non-zero means do write) |
| 158 | csr: addr::MIE, |
| 159 | operand: 0x800, // Set MTIE bit |
| 160 | old_val: 0x100, |
| 161 | next_pc: 0x8000_0004, |
| 162 | }; |
| 163 | |
| 164 | let next_pc = writeback(mem_result, &mut regs, &mut csrs).expect("writeback should succeed"); |
| 165 | |
| 166 | // Old value returned |
| 167 | assert_eq!(regs.read_x(5), 0x100); |
| 168 | // Bits set: 0x100 | 0x800 = 0x900 |
| 169 | assert_eq!( |