-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] replace deprecated sbi_rt legacy console operations in riscv p…
…latform
- Loading branch information
Showing
1 changed file
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |