This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COM logger removed due to Sync issues and custom panic handler added
- Loading branch information
Showing
7 changed files
with
158 additions
and
18 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
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
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,28 @@ | ||
//! The module containing various constants that may be modified by developers. | ||
|
||
#![allow(dead_code)] | ||
|
||
use crate::logger::{UartComPort, UartLogger}; | ||
|
||
/// The logging level. | ||
pub const LOGGING_LEVEL: log::LevelFilter = log::LevelFilter::Trace; | ||
|
||
/// Once in how many iterations stats should be sent to the serial output. | ||
/// Ignored when [`LOGGING_LEVEL`] is `Trace`. | ||
pub const SERIAL_OUTPUT_INTERVAL: u64 = 500; | ||
|
||
/// Once in how many iterations stats should be displayed on the console. | ||
/// Ignored when `stdout_stats_report` is disabled. | ||
pub const CONSOLE_OUTPUT_INTERVAL: u64 = 1000; | ||
|
||
/// How long a single fuzzing iteration can spend within the guest-mode, in TSC. | ||
/// If the more than this is spent, a timer fires and aborts the VM. | ||
pub const GUEST_EXEC_TIMEOUT_IN_TSC: u64 = 200_000_000; | ||
|
||
/// The number of fuzzing iterations to be done for single input. The lower, the | ||
/// more frequently new files are selected, and it is slightly costly. Ignored | ||
/// when `random_byte_modification` is disabled. | ||
pub const MAX_ITERATION_COUNT_PER_FILE: u64 = 10_000; | ||
|
||
/// The COM port to be used for UART logging. | ||
pub static UART_LOGGER: UartLogger = UartLogger::new(UartComPort::Com2); |
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,101 @@ | ||
//! The module containing the UART (serial port) logger implementation. | ||
// Inspired by Ian Kronquist's work: https://github.com/iankronquist/rustyvisor/blob/83b53ac104d85073858ba83326a28a6e08d1af12/pcuart/src/lib.rs | ||
// Credits: https://github.com/tandasat/Hypervisor-101-in-Rust/blob/main/hypervisor/src/logger.rs | ||
|
||
#![allow(dead_code)] | ||
|
||
use { | ||
crate::{ | ||
config::{LOGGING_LEVEL, UART_LOGGER}, | ||
intel::support::{inb, outb}, | ||
}, | ||
core::{fmt, fmt::Write}, | ||
spin::Mutex, | ||
}; | ||
|
||
/// Initializes the logger instance. | ||
pub fn init_uart_logger() { | ||
log::set_logger(&UART_LOGGER) | ||
.map(|()| log::set_max_level(LOGGING_LEVEL)) | ||
.unwrap(); | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
#[repr(u16)] | ||
pub(crate) enum UartComPort { | ||
Com1 = 0x3f8, | ||
Com2 = 0x2f8, | ||
} | ||
|
||
#[derive(Default)] | ||
struct Uart { | ||
io_port_base: u16, | ||
} | ||
|
||
impl Uart { | ||
const fn new(port: UartComPort) -> Self { | ||
Self { | ||
io_port_base: port as u16, | ||
} | ||
} | ||
} | ||
|
||
const UART_OFFSET_TRANSMITTER_HOLDING_BUFFER: u16 = 0; | ||
const UART_OFFSET_LINE_STATUS: u16 = 5; | ||
|
||
impl Write for Uart { | ||
// Writes bytes `string` to the serial port. | ||
fn write_str(&mut self, string: &str) -> Result<(), fmt::Error> { | ||
for byte in string.bytes() { | ||
while (inb(self.io_port_base + UART_OFFSET_LINE_STATUS) & 0x20) == 0 {} | ||
outb( | ||
self.io_port_base + UART_OFFSET_TRANSMITTER_HOLDING_BUFFER, | ||
byte, | ||
); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub struct UartLogger { | ||
port: Mutex<Uart>, | ||
} | ||
|
||
impl UartLogger { | ||
pub(crate) const fn new(port: UartComPort) -> Self { | ||
Self { | ||
port: Mutex::new(Uart::new(port)), | ||
} | ||
} | ||
|
||
fn lock(&self) -> spin::MutexGuard<'_, Uart> { | ||
self.port.lock() | ||
} | ||
} | ||
|
||
impl log::Log for UartLogger { | ||
fn enabled(&self, metadata: &log::Metadata<'_>) -> bool { | ||
metadata.level() <= log::Level::Trace | ||
} | ||
|
||
fn log(&self, record: &log::Record<'_>) { | ||
if self.enabled(record.metadata()) { | ||
let _ = writeln!( | ||
self.lock(), | ||
"#{}:{}: {}", | ||
apic_id(), | ||
record.level(), | ||
record.args() | ||
); | ||
} | ||
} | ||
|
||
fn flush(&self) {} | ||
} | ||
|
||
/// Gets an APIC ID. | ||
fn apic_id() -> u32 { | ||
// See: (AMD) CPUID Fn0000_0001_EBX LocalApicId, LogicalProcessorCount, CLFlush | ||
// See: (Intel) Table 3-8. Information Returned by CPUID Instruction | ||
x86::cpuid::cpuid!(0x1).ebx >> 24 | ||
} |