Skip to content

Commit 71e7b5c

Browse files
author
BillXiang
committed
riscv64: Add test for KVM_EXIT_RISCV_SBI exit
Introduce sbi-spec and add tests for LEGACY_CONSOLE_GETCHAR and LEGACY_CONSOLE_PUTCHAR. Signed-off-by: BillXiang <[email protected]>
1 parent 88bb53a commit 71e7b5c

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

kvm-ioctls/src/ioctls/vcpu.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,25 @@ mod tests {
25832583
0x03, 0xa5, 0x0c, 0x00, // lw a0, 0(s9); test MMIO read
25842584
0x93, 0x05, 0x70, 0x60, // li a1, 0x0607;
25852585
0x23, 0xa0, 0xbc, 0x00, // sw a1, 0(s9); test MMIO write
2586+
//sbi_console_getchar
2587+
0x01, 0x45, // li a0, 0
2588+
0x81, 0x45, // li a1, 0
2589+
0x01, 0x46, // li a2, 0
2590+
0x81, 0x46, // li a3, 0
2591+
0x01, 0x47, // li a4, 0
2592+
0x81, 0x47, // li a5, 0
2593+
0x01, 0x48, // li a6, 0
2594+
0x89, 0x48, // li a7, 2
2595+
0x73, 0x00, 0x00, 0x00, //ecall
2596+
//sbi_console_putchar
2597+
0x81, 0x45, // li a1, 0
2598+
0x01, 0x46, // li a2, 0
2599+
0x81, 0x46, // li a3, 0
2600+
0x01, 0x47, // li a4, 0
2601+
0x81, 0x47, // li a5, 0
2602+
0x01, 0x48, // li a6, 0
2603+
0x85, 0x48, // li a7, 1
2604+
0x73, 0x00, 0x00, 0x00, //ecall
25862605
0x6f, 0x00, 0x00, 0x00, // j .; shouldn't get here, but if so loop forever
25872606
];
25882607

@@ -2654,7 +2673,20 @@ mod tests {
26542673
.map(|page| page.count_ones())
26552674
.sum();
26562675
assert_eq!(dirty_pages, 1);
2657-
break;
2676+
}
2677+
VcpuExit::RiscvSbi(riscv_sbi) => {
2678+
match riscv_sbi.extension_id as usize {
2679+
2 /* SBI_EXT_0_1_CONSOLE_GETCHAR */ => {
2680+
let ch = &mut riscv_sbi.ret[..1];
2681+
ch[0] = 0x2a;
2682+
}
2683+
1 /* SBI_EXT_0_1_CONSOLE_PUTCHAR */ => {
2684+
let ch = riscv_sbi.args[0];
2685+
assert_eq!(ch, 0x2a);
2686+
break;
2687+
}
2688+
_ => panic!("unexpected extension_id: {:?}", riscv_sbi.extension_id),
2689+
}
26582690
}
26592691
r => panic!("unexpected exit reason: {:?}", r),
26602692
}

0 commit comments

Comments
 (0)