Skip to content

Commit 33078a8

Browse files
dependabot[bot]retrage
authored andcommitted
build: Bump uart_16550 from 0.4.0 to 0.6.0
Bumps [uart_16550](https://github.com/rust-osdev/uart_16550) from 0.4.0 to 0.6.0. - [Release notes](https://github.com/rust-osdev/uart_16550/releases) - [Changelog](https://github.com/rust-osdev/uart_16550/blob/v0.6.0/CHANGELOG.md) - [Commits](rust-osdev/uart_16550@v0.4.0...v0.6.0) --- updated-dependencies: - dependency-name: uart_16550 dependency-version: 0.6.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
1 parent 286a40e commit 33078a8

4 files changed

Lines changed: 49 additions & 46 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fdt = "0.1.5"
3939
chrono = { version = "0.4", default-features = false }
4040

4141
[target.'cfg(target_arch = "x86_64")'.dependencies]
42-
uart_16550 = "0.4.0"
42+
uart_16550 = "0.6.0"
4343
x86_64 = { version = "0.15.4", default-features = false, features = [
4444
"instructions",
4545
] }

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn boot_from_device(
180180
#[cfg(target_arch = "x86_64")]
181181
#[no_mangle]
182182
pub extern "C" fn rust64_start(#[cfg(not(feature = "coreboot"))] pvh_info: &pvh::StartInfo) -> ! {
183-
serial::PORT.borrow_mut().init();
183+
serial::init();
184184
logger::init();
185185

186186
arch::x86_64::sse::enable_sse();
@@ -202,7 +202,7 @@ pub extern "C" fn rust64_start(x0: *const u8) -> ! {
202202
arch::aarch64::paging::setup();
203203

204204
// Use atomic operation before MMU enabled may cause exception, see https://www.ipshop.xyz/5909.html
205-
serial::PORT.borrow_mut().init();
205+
serial::init();
206206
logger::init();
207207

208208
let info = fdt::StartInfo::new(
@@ -225,7 +225,7 @@ pub extern "C" fn rust64_start(x0: *const u8) -> ! {
225225
pub extern "C" fn rust64_start(a0: u64, a1: *const u8) -> ! {
226226
use crate::bootinfo::{EntryType, Info, MemoryEntry};
227227

228-
serial::PORT.borrow_mut().init();
228+
serial::init();
229229
logger::init();
230230

231231
info!("Starting on RV64 0x{:x} 0x{:x}", a0, a1 as u64,);

src/serial.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use atomic_refcell::AtomicRefCell;
1212
use crate::{arch::aarch64::layout::map, uart_pl011::Pl011 as UartPl011};
1313

1414
#[cfg(target_arch = "x86_64")]
15-
use uart_16550::SerialPort as Uart16550;
15+
use uart_16550::{backend::PioBackend, Config, Uart16550Tty};
1616

1717
#[cfg(target_arch = "riscv64")]
1818
use crate::uart_mmio::UartMmio;
1919

2020
// We use COM1 as it is the standard first serial port.
2121
#[cfg(target_arch = "x86_64")]
22-
pub static PORT: AtomicRefCell<Uart16550> = AtomicRefCell::new(unsafe { Uart16550::new(0x3f8) });
22+
pub static PORT: AtomicRefCell<Option<Uart16550Tty<PioBackend>>> = AtomicRefCell::new(None);
2323

2424
#[cfg(target_arch = "aarch64")]
2525
pub static PORT: AtomicRefCell<UartPl011> =
@@ -31,10 +31,41 @@ const SERIAL_PORT_ADDRESS: u64 = 0x1000_0000;
3131
#[cfg(target_arch = "riscv64")]
3232
pub static PORT: AtomicRefCell<UartMmio> = AtomicRefCell::new(UartMmio::new(SERIAL_PORT_ADDRESS));
3333

34+
#[cfg(target_arch = "x86_64")]
35+
pub fn init() {
36+
let mut port = PORT.borrow_mut();
37+
38+
if port.is_none() {
39+
*port = Some(unsafe {
40+
Uart16550Tty::new_port(0x3f8, Config::default())
41+
.expect("Failed to initialize UART16550")
42+
});
43+
}
44+
}
45+
46+
#[cfg(not(target_arch = "x86_64"))]
47+
pub fn init() {
48+
PORT.borrow_mut().init();
49+
}
50+
3451
pub struct Serial;
3552
impl fmt::Write for Serial {
3653
fn write_str(&mut self, s: &str) -> fmt::Result {
37-
PORT.borrow_mut().write_str(s)
54+
#[cfg(target_arch = "x86_64")]
55+
{
56+
let mut port = PORT.borrow_mut();
57+
58+
if let Some(port) = port.as_mut() {
59+
return fmt::Write::write_str(port, s);
60+
}
61+
62+
Ok(())
63+
}
64+
65+
#[cfg(not(target_arch = "x86_64"))]
66+
{
67+
PORT.borrow_mut().write_str(s)
68+
}
3869
}
3970
}
4071

0 commit comments

Comments
 (0)