1#![deny(missing_docs)]
18#![deny(warnings)]
19#![no_std]
20#![no_main]
21
22macro_rules! linker_symbol_addr {
23 ($symbol:path) => {
24 ($symbol as *const ()).addr()
25 };
26}
27
28use core::arch::global_asm;
29
30use log::*;
31#[macro_use]
32mod console;
33pub mod batch;
34mod lang_items;
35mod logging;
36mod sbi;
37mod sync;
38pub mod syscall;
39pub mod trap;
40
41global_asm!(include_str!("entry.asm"));
42global_asm!(include_str!("link_app.S"));
43
44fn clear_bss() {
46 unsafe extern "C" {
47 safe fn sbss();
48 safe fn ebss();
49 }
50 unsafe {
51 core::slice::from_raw_parts_mut(
52 linker_symbol_addr!(sbss) as *mut u8,
53 linker_symbol_addr!(ebss) - linker_symbol_addr!(sbss),
54 )
55 .fill(0);
56 }
57}
58
59#[unsafe(no_mangle)]
61pub fn rust_main() -> ! {
62 unsafe extern "C" {
63 safe fn stext(); safe fn etext(); safe fn srodata(); safe fn erodata(); safe fn sdata(); safe fn edata(); safe fn sbss(); safe fn ebss(); safe fn boot_stack_lower_bound(); safe fn boot_stack_top(); }
74 clear_bss();
75 logging::init();
76 println!("[kernel] Hello, world!");
77 trace!(
78 "[kernel] .text [{:#x}, {:#x})",
79 linker_symbol_addr!(stext),
80 linker_symbol_addr!(etext)
81 );
82 debug!(
83 "[kernel] .rodata [{:#x}, {:#x})",
84 linker_symbol_addr!(srodata),
85 linker_symbol_addr!(erodata)
86 );
87 info!(
88 "[kernel] .data [{:#x}, {:#x})",
89 linker_symbol_addr!(sdata),
90 linker_symbol_addr!(edata)
91 );
92 warn!(
93 "[kernel] boot_stack top=bottom={:#x}, lower_bound={:#x}",
94 linker_symbol_addr!(boot_stack_top),
95 linker_symbol_addr!(boot_stack_lower_bound)
96 );
97 error!(
98 "[kernel] .bss [{:#x}, {:#x})",
99 linker_symbol_addr!(sbss),
100 linker_symbol_addr!(ebss)
101 );
102 trap::init();
103 batch::init();
104 batch::run_next_app();
105}