Skip to content

Commit

Permalink
[feat] replace deprecated sbi_rt legacy console operations in riscv p…
Browse files Browse the repository at this point in the history
…latform
  • Loading branch information
hky1999 committed Oct 24, 2024
1 parent f03dcbb commit 746a8f4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions modules/axhal/src/platform/riscv64_qemu_virt/console.rs
Original file line number Diff line number Diff line change
@@ -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<u8> {
#[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)
}

0 comments on commit 746a8f4

Please sign in to comment.