summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 18bb65c552539ac123f12fa2abe40f47754b3f70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
    welcome_serial();
    halt()
}

fn print_serial(s: &str) {
    let mut bytes = s.bytes();
    while let Some(b) = bytes.next() {
        unsafe {core::arch::asm!(
            "out dx, al"
            , in("al") b
        )};
    };
}

fn println_serial(s: &str) {
    print_serial(s);
    print_serial("\n");
}

fn welcome_serial() {
    print_serial(ANSI_PINK);
    println_serial("\nWelcome to Bootle OS");
    println_serial("All code GPL licensed and freely available on git.mtgmonkey.net");
    print_serial("Enjoy your time! Press "); print_serial(ANSI_RED); print_serial("ctrl+a x"); print_serial(ANSI_PINK); println_serial(" to escape Qemu");
    print_serial(ANSI_CLEAR);
}

#[panic_handler]
fn panic(_: &PanicInfo) -> ! {
    print_serial("panicked");
    halt()
}

fn halt() -> ! {
    unsafe {core::arch::asm!(
        "hlt"
    )};
    halt()
}

const ANSI_CLEAR: &str = "\x1b[0m";
const ANSI_RED: &str = "\x1b[31m";
const ANSI_PINK: &str = "\x1b[35m";
const ANSI_GREEN: &str = "\x1b[32m";