From 746a8f4f59e78b8dfab39f0df2d28a1dae2a313e Mon Sep 17 00:00:00 2001 From: hky1999 <976929993@qq.com> Date: Thu, 24 Oct 2024 14:00:01 +0800 Subject: [PATCH] [feat] replace deprecated sbi_rt legacy console operations in riscv platform --- .../src/platform/riscv64_qemu_virt/console.rs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/axhal/src/platform/riscv64_qemu_virt/console.rs b/modules/axhal/src/platform/riscv64_qemu_virt/console.rs index a7ec3e6465..e6d9156b27 100644 --- a/modules/axhal/src/platform/riscv64_qemu_virt/console.rs +++ b/modules/axhal/src/platform/riscv64_qemu_virt/console.rs @@ -1,14 +1,22 @@ +use core::ptr::addr_of; + +use memory_addr::VirtAddr; + +use crate::mem::virt_to_phys; + /// Writes a byte to the console. pub fn putchar(c: u8) { - #[allow(deprecated)] - sbi_rt::legacy::console_putchar(c as usize); + sbi_rt::console_write_byte(c); } /// Reads a byte from the console, or returns [`None`] if no input is available. pub fn getchar() -> Option { - #[allow(deprecated)] - match sbi_rt::legacy::console_getchar() as isize { - -1 => None, - c => Some(c as u8), - } + let c: u8 = 0; + sbi_rt::console_read(sbi_rt::Physical::new( + 1, + virt_to_phys(VirtAddr::from_ptr_of(addr_of!(c))).as_usize(), + 0, + )) + .ok() + .map(|_| c) }