@@ -2572,6 +2572,7 @@ mod tests {
25722572 #[ cfg( target_arch = "riscv64" ) ]
25732573 #[ test]
25742574 fn test_run_code ( ) {
2575+ use sbi_spec:: legacy:: * ;
25752576 use std:: io:: Write ;
25762577
25772578 let kvm = Kvm :: new ( ) . unwrap ( ) ;
@@ -2583,6 +2584,25 @@ mod tests {
25832584 0x03 , 0xa5 , 0x0c , 0x00 , // lw a0, 0(s9); test MMIO read
25842585 0x93 , 0x05 , 0x70 , 0x60 , // li a1, 0x0607;
25852586 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
25862606 0x6f , 0x00 , 0x00 , 0x00 , // j .; shouldn't get here, but if so loop forever
25872607 ] ;
25882608
@@ -2654,7 +2674,24 @@ mod tests {
26542674 . map ( |page| page. count_ones ( ) )
26552675 . sum ( ) ;
26562676 assert_eq ! ( dirty_pages, 1 ) ;
2657- break ;
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 ) ;
2691+ break ;
2692+ }
2693+ _ => panic ! ( "unexpected extension_id: {:?}" , riscv_sbi. extension_id) ,
2694+ }
26582695 }
26592696 r => panic ! ( "unexpected exit reason: {:?}" , r) ,
26602697 }
0 commit comments