feat: proper IPC-based boot — init loads servers from storage via IPC, VirtIO GPU driver

Complete microkernel boot pipeline: adapter loads only init + storage + display
from disk. Init bootstraps all other servers by reading binaries from the
storage server via IPC, parsing ELF, creating processes, mapping pages, and
spawning threads.

New syscalls:
- CreateEndpoint: userspace endpoint creation with full capability grant
- DebugPutchar: debug output to UART from userspace
- MapPage: cross-process page mapping (init loads binaries into children)
- SpawnThreadIn: spawn thread in another process via capability

Key fixes:
- Per-process L1 page tables for VPN[2]=0 (prevents cross-process corruption)
- Separate kernel_pt from page_tables[0] (init pid=0 overwrote kernel PT ref)
- Thread Running state set in switch_to_next (syscalls rejected without it)
- Pending IPC results applied during context switch
- SIE disabled during boot (timer can't preempt into unready processes)
- User heap VA starts at 0x40000 (avoids shared buffer at 0x30000)
- RequestPages maps at user VAs via per-process heap allocator

VirtIO GPU:
- Adapter probes for GPU device, initializes resource/scanout/backing
- Display server writes to mapped framebuffer, flushes via GPU virtqueue
- 640x480 BGRA framebuffer with transfer-to-host and resource-flush

Storage server:
- Userspace VirtIO block driver using pre-mapped MMIO and DMA pages
- FAT16 filesystem reader serving file-read requests via IPC
- Shared buffer protocol: init writes filename, storage writes file data

Echo app for IPC testing (adapter-loaded echo proved the pipeline end-to-end).
This commit is contained in:
2026-10-18 13:02:30 +02:00
parent ffde4065ba
commit 38f20cc3c4
41 changed files with 1676 additions and 808 deletions

View File

@@ -11,16 +11,81 @@ pub mod server;
#[path = "tests/mod.rs"]
mod tests;
use userspace::syscall;
const CMD_READ_FILE: usize = 1;
const SHARED_BUF_VA: usize = 0x30000;
const SHARED_BUF_SIZE: usize = 64 * 1024;
fn shared_buf() -> &'static mut [u8] {
unsafe { core::slice::from_raw_parts_mut(SHARED_BUF_VA as *mut u8, SHARED_BUF_SIZE) }
}
fn debug_print(s: &[u8]) {
for &b in s {
syscall::debug_putchar(b);
}
}
pub fn run() -> ! {
#[cfg(feature = "qemu-virt")]
{
let device = adapters::mock_block::MockBlockDevice::new(64);
let filesystem = fs::fat16::Fat16::mount(device);
if let Some(mut fs) = filesystem {
let mut srv = server::StorageServer::new(fs);
server_framework::serve(&mut srv, 0);
debug_print(b"storage: started\n");
let device = adapters::virtio_blk::VirtioBlockDevice::new();
let fat16 = fs::fat16::Fat16::mount(device);
if fat16.is_none() {
debug_print(b"storage: FAT16 mount failed\n");
loop { syscall::yield_now(); }
}
let mut fat16 = fat16.unwrap();
debug_print(b"storage: FAT16 mounted\n");
let ep: usize = 0;
loop {
let (w0, w1, _w2, _w3) = syscall::receive(ep);
match w0 {
CMD_READ_FILE => {
let filename_len = w1;
let buf = shared_buf();
let filename_len = filename_len.min(buf.len());
let mut name_buf = [0u8; 32];
let name_len = filename_len.min(32);
name_buf[..name_len].copy_from_slice(&buf[..name_len]);
debug_print(b"storage: read ");
debug_print(&name_buf[..name_len]);
debug_print(b"...");
let file_size = read_entire_file(&mut fat16, &name_buf[..name_len], buf);
debug_print(if file_size > 0 { b"ok\n" } else { b"NOT FOUND\n" });
syscall::send(ep, file_size, 0, 0, 0);
}
_ => {
syscall::send(ep, 0, 0, 0, 0);
}
}
}
loop { userspace::syscall::yield_now(); }
}
fn read_entire_file<B: block_device::BlockDevice>(
fat: &mut fs::fat16::Fat16<B>,
filename: &[u8],
out: &mut [u8],
) -> usize {
use filesystem::FileSystem;
let handle = match fat.open(filename) {
Some(h) => h,
None => return 0,
};
let size = fat.file_size(handle).unwrap_or(0);
let to_read = size.min(out.len());
let read = fat.read(handle, &mut out[..to_read]).unwrap_or(0);
fat.close(handle);
read
}