Skip to main content

mini_loader/
lib.rs

1#![no_std]
2
3use core::{ffi::c_int, hint::spin_loop};
4use syscalls::{Sysno, raw_syscall};
5mod arch;
6
7#[inline(always)]
8fn write_stdout(bytes: &[u8]) {
9    unsafe {
10        let _ = raw_syscall!(Sysno::write, 1, bytes.as_ptr(), bytes.len());
11    }
12}
13
14#[inline]
15pub fn print_char(c: char) {
16    let mut buffer = [0u8; 4];
17    let encoded = c.encode_utf8(&mut buffer);
18    write_stdout(encoded.as_bytes());
19}
20
21#[inline]
22pub fn print_str(s: &str) {
23    write_stdout(s.as_bytes());
24}
25
26pub fn exit(status: c_int) -> ! {
27    unsafe {
28        let _ = raw_syscall!(Sysno::exit, status);
29    }
30    loop {
31        spin_loop();
32    }
33}
34
35pub fn fatal(message: &str) -> ! {
36    print_str(message);
37    exit(-1);
38}