@@ -2583,6 +2583,25 @@ mod tests {
2583
2583
0x03 , 0xa5 , 0x0c , 0x00 , // lw a0, 0(s9); test MMIO read
2584
2584
0x93 , 0x05 , 0x70 , 0x60 , // li a1, 0x0607;
2585
2585
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
2586
2605
0x6f , 0x00 , 0x00 , 0x00 , // j .; shouldn't get here, but if so loop forever
2587
2606
] ;
2588
2607
@@ -2654,7 +2673,24 @@ mod tests {
2654
2673
. map ( |page| page. count_ones ( ) )
2655
2674
. sum ( ) ;
2656
2675
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
+ // SAFETY: Safe because the extension_id (which comes from the kernel) told us
2681
+ // how to use riscv_sbi
2682
+ let ch = & mut riscv_sbi. ret [ ..1 ] ;
2683
+ ch[ 0 ] = 0x2a ;
2684
+ }
2685
+ 1 /* SBI_EXT_0_1_CONSOLE_PUTCHAR */ => {
2686
+ // SAFETY: Safe because the extension_id (which comes from the kernel) told us
2687
+ // how to use riscv_sbi
2688
+ let ch = riscv_sbi. args [ 0 ] ;
2689
+ assert_eq ! ( ch, 0x2a ) ;
2690
+ break ;
2691
+ }
2692
+ _ => panic ! ( "unexpected extension_id: {:?}" , riscv_sbi. extension_id) ,
2693
+ }
2658
2694
}
2659
2695
r => panic ! ( "unexpected exit reason: {:?}" , r) ,
2660
2696
}
0 commit comments