Skip to content

Commit c6d62d7

Browse files
committed
uefi: migrate to uart_16550 based logger
1 parent afcccd6 commit c6d62d7

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

common/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ pub mod level_4_entries;
3434
pub mod load_kernel;
3535
/// Provides a logger that logs output as text in various formats.
3636
pub mod logger;
37-
/// Provides a type that logs output as text to a Serial Being port.
38-
pub mod serial;
3937

4038
const PAGE_SIZE: u64 = 4096;
4139

common/src/logger.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
use crate::{framebuffer::FrameBufferWriter, serial::SerialPort};
1+
use crate::framebuffer::FrameBufferWriter;
22
use bootloader_api::info::FrameBufferInfo;
33
use conquer_once::spin::OnceCell;
44
use core::fmt::Write;
55
use spinning_top::Spinlock;
6+
use uart_16550::backend::PioBackend;
7+
use uart_16550::{Config, Uart16550Tty};
68

79
/// The global logger instance used for the `log` crate.
810
pub static LOGGER: OnceCell<LockedLogger> = OnceCell::uninit();
911

1012
/// A logger instance protected by a spinlock.
1113
pub struct LockedLogger {
1214
framebuffer: Option<Spinlock<FrameBufferWriter>>,
13-
serial: Option<Spinlock<SerialPort>>,
15+
serial: Option<Spinlock<Uart16550Tty<PioBackend>>>,
1416
}
1517

1618
impl LockedLogger {
@@ -27,7 +29,17 @@ impl LockedLogger {
2729
};
2830

2931
let serial = match serial_logger_status {
30-
true => Some(Spinlock::new(unsafe { SerialPort::init() })),
32+
true => {
33+
// SAFETY: We have exclusive access to the device.
34+
//
35+
// This returns `None` if the config is invalid or the self-test fails.
36+
// We do not panic here because we want to continue booting.
37+
unsafe {
38+
Uart16550Tty::new_port(0x3f8, Config::default())
39+
.ok()
40+
.map(Spinlock::new)
41+
}
42+
}
3143
false => None,
3244
};
3345

0 commit comments

Comments
 (0)