| 1110 | ri(RealInstruction::Addi(Addi::new(11, 0, 42))), // a1 = 42 |
| 1111 | ri(RealInstruction::Divu(Divu::new(10, 11, 0))), // a0 = divu(42, 0) = u64::MAX |
| 1112 | // Save result to s0 (x8) before overwriting a0 for exit |
| 1113 | ri(RealInstruction::Add(Add::new(8, 10, 0))), // s0 = a0 (preserved across ecall) |
| 1114 | ri(RealInstruction::Addi(Addi::new(17, 0, 93))), // a7 = 93 |
| 1115 | ri(RealInstruction::Addi(Addi::new(10, 0, 0))), // a0 = 0 (exit code) |
| 1116 | ri(RealInstruction::Ecall(Ecall::new())), |
| 1117 | ]); |
| 1118 | // s0=x8 should hold u64::MAX from the divu |
| 1119 | assert_eq!( |
| 1120 | vm.peek_reg(8), |
| 1121 | u64::MAX, |
| 1122 | "divu by zero should produce u64::MAX" |
| 1123 | ); |
| 1124 | } |
| 1125 | |
| 1126 | #[test] |
| 1127 | fn test_csr_instret() { |
| 1128 | // Run a few nops, then read instret via csrrs a0, 0xC02, x0, then exit. |
| 1129 | // The exit code (as i64) should be > 3 (we ran at least 3 nops + csrrs + addi + ecall). |
| 1130 | let (_, outcome) = assemble_and_run(vec![ |
| 1131 | ri(RealInstruction::Addi(Addi::new(0, 0, 0))), // nop 1 |
| 1132 | ri(RealInstruction::Addi(Addi::new(0, 0, 0))), // nop 2 |
| 1133 | ri(RealInstruction::Addi(Addi::new(0, 0, 0))), // nop 3 |