refactor: replace manual debug_putchar with libkos::println!

Init, storage server, and hello app now use println!/print! macros
instead of manual byte-by-byte UART output.
This commit is contained in:
2026-10-19 01:00:33 +02:00
parent 052d7c4a64
commit 818eaecadd
3 changed files with 27 additions and 58 deletions

View File

@@ -1,5 +1,7 @@
#![no_std]
extern crate alloc;
use types::address::{EntryPoint, StackPointer, VirtualAddress};
use types::bounded::{CapSlot, PageCount};
use types::permission::{Permission, PermissionSet};
@@ -16,32 +18,6 @@ const STORAGE_EP: CapSlot = CapSlot::const_new(2);
const DISPLAY_EP: CapSlot = CapSlot::const_new(3);
const INPUT_EP: CapSlot = CapSlot::const_new(5);
fn debug_print(s: &[u8]) {
for &b in s {
syscall::debug_putchar(b);
}
}
fn debug_hex(mut val: usize) {
debug_print(b"0x");
if val == 0 {
syscall::debug_putchar(b'0');
return;
}
let mut buf = [0u8; 16];
let mut i = 0;
while val > 0 {
let d = (val & 0xF) as u8;
buf[i] = if d < 10 { b'0' + d } else { b'a' + d - 10 };
val >>= 4;
i += 1;
}
while i > 0 {
i -= 1;
syscall::debug_putchar(buf[i]);
}
}
fn request_file(shared_buf: *mut u8, filename: &[u8]) -> usize {
unsafe {
for (i, &b) in filename.iter().enumerate() {
@@ -122,35 +98,31 @@ fn load_binary(shared_buf: *mut u8, filename: &[u8]) -> Option<LoadedProcess> {
struct ServerInfo {
filename: &'static [u8],
name: &'static [u8],
name: &'static str,
}
const SERVERS: &[ServerInfo] = &[
ServerInfo { filename: b"log.elf", name: b"log" },
ServerInfo { filename: b"permis.elf", name: b"permis" },
ServerInfo { filename: b"session.elf", name: b"session" },
ServerInfo { filename: b"log.elf", name: "log" },
ServerInfo { filename: b"permis.elf", name: "permis" },
ServerInfo { filename: b"session.elf", name: "session" },
];
pub fn run(shared_buf_va: usize) -> ! {
let shared_buf = shared_buf_va as *mut u8;
debug_print(b"init: started (pid=");
debug_hex(syscall::get_process_id().raw() as usize);
debug_print(b")\n");
libkos::println!("init: started (pid={:#x})", syscall::get_process_id().raw());
let ipc_perms = PermissionSet::empty()
.with(Permission::Read)
.with(Permission::Execute);
for server in SERVERS {
debug_print(b"init: loading ");
debug_print(server.name);
debug_print(b"... ");
libkos::print!("init: loading {}... ", server.name);
let loaded = match load_binary(shared_buf, server.filename) {
Some(l) => l,
None => {
debug_print(b"SKIP\n");
libkos::println!("SKIP");
continue;
}
};
@@ -160,22 +132,20 @@ pub fn run(shared_buf_va: usize) -> ! {
syscall::spawn_thread_in(loaded.process_cap, loaded.entry_point, USER_STACK_TOP);
}
debug_print(b"ok (entry=");
debug_hex(loaded.entry_point.raw());
debug_print(b")\n");
libkos::println!("ok (entry={:#x})", loaded.entry_point.raw());
}
debug_print(b"init: loading snake... ");
libkos::print!("init: loading snake... ");
if let Some(snake) = load_binary(shared_buf, b"snake.elf") {
syscall::delegate(INPUT_EP, snake.process_cap, ipc_perms);
syscall::delegate(DISPLAY_EP, snake.process_cap, ipc_perms);
syscall::spawn_thread_in(snake.process_cap, snake.entry_point, USER_STACK_TOP);
debug_print(b"ok\n");
libkos::println!("ok");
} else {
debug_print(b"SKIP\n");
libkos::println!("SKIP");
}
debug_print(b"init: all loaded, supervising\n");
libkos::println!("init: all loaded, supervising");
loop {
syscall::yield_now();