1#![deny(missing_docs)]
19#![deny(warnings)]
20#![no_std]
21#![no_main]
22
23macro_rules! linker_symbol_addr {
24 ($symbol:path) => {
25 ($symbol as *const ()).addr()
26 };
27}
28
29use core::arch::global_asm;
30use log::*;
31
32#[path = "boards/qemu.rs"]
33mod board;
34
35#[macro_use]
36mod console;
37mod config;
38mod device_tree;
39mod lang_items;
40mod loader;
41mod logging;
42mod sbi;
43mod sync;
44pub mod syscall;
45pub mod task;
46mod timer;
47pub mod trap;
48
49global_asm!(include_str!("entry.asm"));
50global_asm!(include_str!("link_app.S"));
51
52fn clear_bss() {
54 unsafe extern "C" {
55 safe fn sbss();
56 safe fn ebss();
57 }
58 unsafe {
59 core::slice::from_raw_parts_mut(
60 linker_symbol_addr!(sbss) as *mut u8,
61 linker_symbol_addr!(ebss) - linker_symbol_addr!(sbss),
62 )
63 .fill(0);
64 }
65}
66
67#[unsafe(no_mangle)]
69pub fn rust_main(_hart_id: usize, dtb_pa: usize) -> ! {
70 clear_bss();
71 logging::init();
72 device_tree::init(dtb_pa);
73 info!("[kernel] Hello, world!");
74 trap::init();
75 loader::load_apps();
76 trap::enable_timer_interrupt();
77 timer::set_next_trigger();
78 task::run_first_task();
79 panic!("Unreachable in rust_main!");
80}