refactor: unsafe only in adapter + libkos; forbid(unsafe_code) everywhere else; libkos Window (volatile, bounds-checked MMIO/DMA/shared mem), entry!, thread::spawn; MapRegion returns pages; kernel const-built (with_cores/install_platform); newtype addrs

This commit is contained in:
2026-10-27 21:43:24 +01:00
parent 83809bbe94
commit 842d14987c
107 changed files with 771 additions and 647 deletions

View File

@@ -1,2 +1 @@
pub mod mock;
pub mod qemu_uart;

View File

@@ -1,47 +0,0 @@
use port_input_device::{InputDevice, InputEvent, Key};
const UART_BASE: usize = 0x10000000;
const UART_LSR: usize = 5;
pub struct UartInputDevice {
base: usize,
}
impl UartInputDevice {
pub fn new() -> Self {
Self { base: UART_BASE }
}
fn read_byte(&self) -> Option<u8> {
let lsr = unsafe { core::ptr::read_volatile((self.base + UART_LSR) as *const u8) };
if lsr & 1 != 0 {
Some(unsafe { core::ptr::read_volatile(self.base as *const u8) })
} else {
None
}
}
fn byte_to_key(byte: u8) -> Key {
match byte {
b'w' | b'W' => Key::Up,
b's' | b'S' => Key::Down,
b'a' | b'A' => Key::Left,
b'd' | b'D' => Key::Right,
b'\r' | b'\n' => Key::Enter,
0x1B => Key::Escape,
c => Key::Char(c),
}
}
}
impl InputDevice for UartInputDevice {
fn poll(&mut self) -> Option<InputEvent> {
let byte = self.read_byte()?;
Some(InputEvent::KeyDown(Self::byte_to_key(byte)))
}
fn has_event(&self) -> bool {
let lsr = unsafe { core::ptr::read_volatile((self.base + UART_LSR) as *const u8) };
lsr & 1 != 0
}
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
pub mod adapters;
pub mod protocol;
@@ -9,10 +10,7 @@ pub mod server;
mod tests;
pub fn run() -> ! {
#[cfg(feature = "qemu-virt")]
let device = adapters::qemu_uart::UartInputDevice::new();
#[cfg(not(feature = "qemu-virt"))]
// The real devices are driven by bins/input-qemu.
let device = adapters::mock::MockInputDevice::new();
let mut srv = server::InputServer::new(device);

View File

@@ -1,9 +1,11 @@
#![no_std]
#![forbid(unsafe_code)]
#![no_main]
extern crate libkos;
#[unsafe(no_mangle)]
extern "C" fn main() {
libkos::entry!(main);
fn main() {
input_server::run();
}