-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #324 from hermit-os/uefi-output
feat: modularize console implementation for late UEFI output
- Loading branch information
Showing
26 changed files
with
821 additions
and
731 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use core::ptr::NonNull; | ||
|
||
use hermit_dtb::Dtb; | ||
|
||
pub struct Console { | ||
stdout: NonNull<u8>, | ||
} | ||
|
||
fn stdout() -> u32 { | ||
/// Physical address of UART0 at Qemu's virt emulation | ||
const SERIAL_PORT_ADDRESS: u32 = 0x09000000; | ||
|
||
let dtb = unsafe { | ||
Dtb::from_raw(sptr::from_exposed_addr(super::DEVICE_TREE as usize)) | ||
.expect(".dtb file has invalid header") | ||
}; | ||
|
||
let property = dtb.get_property("/chosen", "stdout-path"); | ||
let uart_address = if let Some(stdout) = property { | ||
let stdout = core::str::from_utf8(stdout) | ||
.unwrap() | ||
.trim_matches(char::from(0)); | ||
if let Some(pos) = stdout.find('@') { | ||
let len = stdout.len(); | ||
u32::from_str_radix(&stdout[pos + 1..len], 16).unwrap_or(SERIAL_PORT_ADDRESS) | ||
} else { | ||
SERIAL_PORT_ADDRESS | ||
} | ||
} else { | ||
SERIAL_PORT_ADDRESS | ||
}; | ||
uart_address | ||
} | ||
|
||
impl Console { | ||
pub fn write_bytes(&mut self, bytes: &[u8]) { | ||
for byte in bytes.iter().copied() { | ||
unsafe { | ||
self.stdout.as_ptr().write_volatile(byte); | ||
} | ||
} | ||
} | ||
|
||
pub(super) fn get_stdout(&self) -> NonNull<u8> { | ||
self.stdout | ||
} | ||
|
||
pub(super) fn set_stdout(&mut self, stdout: NonNull<u8>) { | ||
self.stdout = stdout; | ||
} | ||
} | ||
|
||
impl Default for Console { | ||
fn default() -> Self { | ||
let stdout = NonNull::new(stdout() as *mut u8).unwrap(); | ||
Self { stdout } | ||
} | ||
} | ||
|
||
unsafe impl Send for Console {} |
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
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,33 +0,0 @@ | ||
pub struct SerialPort { | ||
port_address: u32, | ||
} | ||
|
||
impl SerialPort { | ||
pub const fn new(port_address: u32) -> Self { | ||
Self { port_address } | ||
} | ||
|
||
pub unsafe fn set_port(&mut self, addr: u32) { | ||
unsafe { | ||
core::ptr::write_volatile(&mut self.port_address, addr); | ||
} | ||
} | ||
|
||
pub unsafe fn get_port(&self) -> u32 { | ||
unsafe { core::ptr::read_volatile(&self.port_address) } | ||
} | ||
|
||
pub fn write_byte(&self, byte: u8) { | ||
unsafe { | ||
let port = | ||
sptr::from_exposed_addr_mut(core::ptr::read_volatile(&self.port_address) as usize); | ||
|
||
// LF newline characters need to be extended to CRLF over a real serial port. | ||
if byte == b'\n' { | ||
core::ptr::write_volatile(port, b'\r'); | ||
} | ||
|
||
core::ptr::write_volatile(port, byte); | ||
} | ||
} | ||
} | ||
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,15 +1,12 @@ | ||
#[cfg(target_arch = "aarch64")] | ||
pub use crate::arch::aarch64::*; | ||
#[cfg(target_arch = "riscv64")] | ||
pub use crate::arch::riscv64::*; | ||
#[cfg(all(target_arch = "x86_64", target_os = "none"))] | ||
pub use crate::arch::x86_64::*; | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
pub mod aarch64; | ||
|
||
#[cfg(target_arch = "riscv64")] | ||
pub mod riscv64; | ||
|
||
#[cfg(all(target_arch = "x86_64", target_os = "none"))] | ||
pub mod x86_64; | ||
cfg_if::cfg_if! { | ||
if #[cfg(target_arch = "aarch64")] { | ||
mod aarch64; | ||
pub use self::aarch64::*; | ||
} else if #[cfg(target_arch = "riscv64")] { | ||
mod riscv64; | ||
pub use self::riscv64::*; | ||
} else if #[cfg(all(target_arch = "x86_64"))] { | ||
mod x86_64; | ||
pub use self::x86_64::*; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use sbi_rt::Physical; | ||
use sptr::Strict; | ||
|
||
#[derive(Default)] | ||
pub struct Console(()); | ||
|
||
impl Console { | ||
pub fn write_bytes(&mut self, bytes: &[u8]) { | ||
sbi_rt::console_write(Physical::new(bytes.len(), bytes.as_ptr().addr(), 0)); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use uart_16550::SerialPort; | ||
|
||
pub struct Console { | ||
serial_port: SerialPort, | ||
} | ||
|
||
impl Console { | ||
pub fn write_bytes(&mut self, bytes: &[u8]) { | ||
for byte in bytes.iter().copied() { | ||
self.serial_port.send(byte); | ||
} | ||
} | ||
} | ||
|
||
impl Default for Console { | ||
fn default() -> Self { | ||
let mut serial_port = unsafe { SerialPort::new(0x3F8) }; | ||
serial_port.init(); | ||
Self { serial_port } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.