()
| 1063 | ]); |
| 1064 | assert!( |
| 1065 | matches!(outcome, StepOutcome::Halted(25)), |
| 1066 | "expected Halted(25), got {outcome:?}" |
| 1067 | ); |
| 1068 | } |
| 1069 | |
| 1070 | #[test] |
| 1071 | fn test_ecall_write_uart() { |
| 1072 | // Write "hi\n" to stdout via ecall 64, then exit. Registers are named by |
| 1073 | // number here: t0=x5, t1=x6, sp=x2, a0=x10, a1=x11, a2=x12, a7=x17. |
| 1074 | let assembled = Assembler::assemble(&[ |
| 1075 | ri(RealInstruction::Addi(Addi::new(5, 2, -4))), // t0 = sp - 4 (buffer ptr) |
| 1076 | ri(RealInstruction::Addi(Addi::new(6, 0, 0x68))), // t1 = 'h' (104) |
| 1077 | ri(RealInstruction::Sb(Sb::new(5, 6, 0))), // sb t1, 0(t0) |
| 1078 | ri(RealInstruction::Addi(Addi::new(6, 0, 0x69))), // t1 = 'i' (105) |
| 1079 | ri(RealInstruction::Sb(Sb::new(5, 6, 1))), // sb t1, 1(t0) |
| 1080 | ri(RealInstruction::Addi(Addi::new(6, 0, 0x0A))), // t1 = '\n' (10) |
| 1081 | ri(RealInstruction::Sb(Sb::new(5, 6, 2))), // sb t1, 2(t0) |
| 1082 | // ecall write: a0=1 (fd=stdout), a1=buf, a2=3 (len), a7=64 |
| 1083 | ri(RealInstruction::Addi(Addi::new(10, 0, 1))), // a0 = 1 (fd) |
| 1084 | ri(RealInstruction::Add(Add::new(11, 5, 0))), // a1 = t0 (buf ptr) |
| 1085 | ri(RealInstruction::Addi(Addi::new(12, 0, 3))), // a2 = 3 (len) |
| 1086 | ri(RealInstruction::Addi(Addi::new(17, 0, 64))), // a7 = 64 (write) |
nothing calls this directly
no test coverage detected