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