sparreal_kernel/hal_al/
run.rs

1use log::LevelFilter;
2
3use ansi_rgb::{Foreground, orange};
4
5use crate::{
6    driver,
7    globals::{self, PlatformInfoKind, global_val},
8    io, irq,
9    logger::KLogger,
10    platform::{self, app_main, platform_name, shutdown},
11    println, task,
12};
13
14pub fn run(plat: PlatformInfoKind) {
15    platform::irq_all_disable();
16    unsafe {
17        if let Err(e) = globals::setup(plat) {
18            println!("Global setup error: {}", e);
19            shutdown();
20        }
21    };
22    io::print::stdout_use_debug();
23    println!("Kernel starting...");
24    crate::mem::init();
25    let _ = log::set_logger(&KLogger);
26    log::set_max_level(LevelFilter::Trace);
27
28    unsafe { globals::setup_percpu() };
29
30    print_start_msg();
31
32    driver::init();
33    debug!("Driver initialized");
34    task::init();
35
36    irq::enable_all();
37
38    driver::probe();
39
40    app_main();
41
42    shutdown()
43}
44
45macro_rules! print_pair {
46    ($name:expr, $($arg:tt)*) => {
47        $crate::print!("{:<30}: {}\r\n", $name, format_args!($($arg)*));
48    };
49}
50
51fn print_start_msg() {
52    println!("{}", LOGO.fg(orange()));
53
54    print_pair!("Version", env!("CARGO_PKG_VERSION"));
55    print_pair!("Platfrom", "{}", platform_name());
56    print_pair!("Start CPU", "{}", platform::cpu_hard_id());
57
58    match &global_val().platform_info {
59        globals::PlatformInfoKind::DeviceTree(fdt) => {
60            print_pair!("FDT", "{:p}", fdt.get_addr());
61        }
62    }
63
64    if let Some(debug) = global_val().platform_info.debugcon()
65        && let Some(c) = debug.compatibles().next()
66    {
67        print_pair!("Debug Serial", "{}", c);
68    }
69}
70
71static LOGO: &str = r#"
72     _____                                         __
73    / ___/ ____   ____ _ _____ _____ ___   ____ _ / /
74    \__ \ / __ \ / __ `// ___// ___// _ \ / __ `// / 
75   ___/ // /_/ // /_/ // /   / /   /  __// /_/ // /  
76  /____// .___/ \__,_//_/   /_/    \___/ \__,_//_/   
77       /_/                                           
78"#;