@@ -2572,6 +2572,7 @@ mod tests {
2572
2572
#[ cfg( target_arch = "riscv64" ) ]
2573
2573
#[ test]
2574
2574
fn test_run_code ( ) {
2575
+ use sbi_spec:: legacy:: * ;
2575
2576
use std:: io:: Write ;
2576
2577
2577
2578
let kvm = Kvm :: new ( ) . unwrap ( ) ;
@@ -2583,6 +2584,25 @@ mod tests {
2583
2584
0x03 , 0xa5 , 0x0c , 0x00 , // lw a0, 0(s9); test MMIO read
2584
2585
0x93 , 0x05 , 0x70 , 0x60 , // li a1, 0x0607;
2585
2586
0x23 , 0xa0 , 0xbc , 0x00 , // sw a1, 0(s9); test MMIO write
2587
+ //sbi_console_getchar
2588
+ 0x01 , 0x45 , // li a0, 0
2589
+ 0x81 , 0x45 , // li a1, 0
2590
+ 0x01 , 0x46 , // li a2, 0
2591
+ 0x81 , 0x46 , // li a3, 0
2592
+ 0x01 , 0x47 , // li a4, 0
2593
+ 0x81 , 0x47 , // li a5, 0
2594
+ 0x01 , 0x48 , // li a6, 0
2595
+ 0x89 , 0x48 , // li a7, 2
2596
+ 0x73 , 0x00 , 0x00 , 0x00 , //ecall
2597
+ //sbi_console_putchar
2598
+ 0x81 , 0x45 , // li a1, 0
2599
+ 0x01 , 0x46 , // li a2, 0
2600
+ 0x81 , 0x46 , // li a3, 0
2601
+ 0x01 , 0x47 , // li a4, 0
2602
+ 0x81 , 0x47 , // li a5, 0
2603
+ 0x01 , 0x48 , // li a6, 0
2604
+ 0x85 , 0x48 , // li a7, 1
2605
+ 0x73 , 0x00 , 0x00 , 0x00 , //ecall
2586
2606
0x6f , 0x00 , 0x00 , 0x00 , // j .; shouldn't get here, but if so loop forever
2587
2607
] ;
2588
2608
@@ -2654,7 +2674,24 @@ mod tests {
2654
2674
. map ( |page| page. count_ones ( ) )
2655
2675
. sum ( ) ;
2656
2676
assert_eq ! ( dirty_pages, 1 ) ;
2677
+ }
2678
+ VcpuExit :: RiscvSbi ( riscv_sbi) => {
2679
+ match riscv_sbi. extension_id as usize {
2680
+ LEGACY_CONSOLE_GETCHAR => {
2681
+ // SAFETY: Safe because the extension_id (which comes from the kernel) told us
2682
+ // ow to use riscv_sbi
2683
+ let ch = & mut riscv_sbi. ret [ ..1 ] ;
2684
+ ch[ 0 ] = 0x2a ;
2685
+ }
2686
+ LEGACY_CONSOLE_PUTCHAR => {
2687
+ // SAFETY: Safe because the extension_id (which comes from the kernel) told us
2688
+ // how to use riscv_sbi
2689
+ let ch = riscv_sbi. args [ 0 ] ;
2690
+ assert_eq ! ( ch, 0x2a ) ;
2657
2691
break ;
2692
+ }
2693
+ _ => panic ! ( "unexpected extension_id: {:?}" , riscv_sbi. extension_id) ,
2694
+ }
2658
2695
}
2659
2696
r => panic ! ( "unexpected exit reason: {:?}" , r) ,
2660
2697
}
0 commit comments