summaryrefslogtreecommitdiff
path: root/kernel/src/lib.rs
blob: 4e51d2214f429db376341a0d4bc596e357b01ac6 (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
52
53
54
#![no_main]
#![feature(compiler_builtins_lib)]
#![no_std]

extern crate compiler_builtins;

mod io;

use io::vga_text;
use core::fmt::Write;

#[no_mangle]
pub extern "C" fn _start() -> ! {
    let mut stdout = vga_text::OStream::new();
    stdout.clear();

    write!(&mut stdout, "hello world!");

    panic!("i has panicing");

    core::iter::successors(Some(0), |n| Some(n + 1))
        .for_each(|n| write!(&mut stdout, "hello world {}!", n).unwrap());

    loop {}
}

#[panic_handler]
#[no_mangle]
pub extern "C" fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
    let mut stderr = vga_text::OStream::new();
    stderr.set_state(vga_text::CharState::from_colors(
        vga_text::Color::LightRed,
        vga_text::Color::Red,
    ));
    stderr.clear();
    stderr.print(b"uff-os");
    stderr.set_row(10);
    stderr.set_state(vga_text::CharState::from_colors(
        vga_text::Color::White,
        vga_text::Color::Red,
    ));
    stderr.print_centered(b"<kernel panic>");
    stderr.set_row(14);
    let text = _info
        .payload()
        .downcast_ref::<&str>()
        .unwrap_or(&"no panic information is obtainable");
    stderr.set_state(vga_text::CharState::from_colors(
        vga_text::Color::Cyan,
        vga_text::Color::Red,
    ));
    stderr.print_centered(text.as_bytes());
    loop {}
}