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
29extern crate alloc;
30
31#[macro_use]
32extern crate bitflags;
33
34use log::*;
35
36#[path = "boards/qemu.rs"]
37mod board;
38
39#[macro_use]
40mod console;
41mod config;
42mod device_tree;
43mod lang_items;
44mod loader;
45mod logging;
46mod mm;
47mod sbi;
48mod sync;
49pub mod syscall;
50pub mod task;
51mod timer;
52pub mod trap;
53
54core::arch::global_asm!(include_str!("entry.asm"));
55core::arch::global_asm!(include_str!("link_app.S"));
56
57fn clear_bss() {
59 unsafe extern "C" {
60 safe fn sbss();
61 safe fn ebss();
62 }
63 unsafe {
64 core::slice::from_raw_parts_mut(
65 linker_symbol_addr!(sbss) as *mut u8,
66 linker_symbol_addr!(ebss) - linker_symbol_addr!(sbss),
67 )
68 .fill(0);
69 }
70}
71
72#[unsafe(no_mangle)]
74pub fn rust_main(_hart_id: usize, dtb_pa: usize) -> ! {
75 clear_bss();
76 logging::init();
77 device_tree::init(dtb_pa);
78 info!("[kernel] Hello, world!");
79 mm::init();
80 info!("[kernel] back to world!");
81 mm::remap_test();
82 trap::init();
83 trap::enable_timer_interrupt();
85 timer::set_next_trigger();
86 task::run_first_task();
87 panic!("Unreachable in rust_main!");
88}