diff --git a/.gitignore b/.gitignore index 770aba77..9fc90c58 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ easy-fs-fuse/Cargo.lock easy-fs-fuse/target/* tools/ pushall.sh +*.bak diff --git a/os/src/console.rs b/os/src/console.rs index dda4911a..cc6a91bf 100644 --- a/os/src/console.rs +++ b/os/src/console.rs @@ -1,3 +1,5 @@ +//! SBI console driver, for text output + use crate::sbi::console_putchar; use core::fmt::{self, Write}; @@ -16,6 +18,7 @@ pub fn print(args: fmt::Arguments) { Stdout.write_fmt(args).unwrap(); } +/// print string macro #[macro_export] macro_rules! print { ($fmt: literal $(, $($arg: tt)+)?) => { @@ -23,6 +26,7 @@ macro_rules! print { } } +/// println string macro #[macro_export] macro_rules! println { ($fmt: literal $(, $($arg: tt)+)?) => { diff --git a/os/src/lang_items.rs b/os/src/lang_items.rs index a6217a0c..db902c35 100644 --- a/os/src/lang_items.rs +++ b/os/src/lang_items.rs @@ -1,3 +1,5 @@ +//! The panic handler + use crate::sbi::shutdown; use core::panic::PanicInfo; @@ -5,13 +7,13 @@ use core::panic::PanicInfo; fn panic(info: &PanicInfo) -> ! { if let Some(location) = info.location() { println!( - "Panicked at {}:{} {}", + "[kernel] Panicked at {}:{} {}", location.file(), location.line(), info.message().unwrap() ); } else { - println!("Panicked: {}", info.message().unwrap()); + println!("[kernel] Panicked: {}", info.message().unwrap()); } shutdown() } diff --git a/os/src/main.rs b/os/src/main.rs index 0f8784b8..cb60ea69 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -1,3 +1,14 @@ +//! The main module and entrypoint +//! +//! The operating system and app also starts in this module. Kernel code starts +//! executing from `entry.asm`, after which [`rust_main()`] is called to +//! initialize various pieces of functionality [`clear_bss()`]. (See its source code for +//! details.) +//! +//! We then call [`println!`] to display `Hello, world!`. + +#![deny(missing_docs)] +#![deny(warnings)] #![no_std] #![no_main] #![feature(panic_info_message)] @@ -11,6 +22,7 @@ mod sbi; global_asm!(include_str!("entry.asm")); +/// clear BSS segment fn clear_bss() { extern "C" { fn sbss(); @@ -19,6 +31,7 @@ fn clear_bss() { (sbss as usize..ebss as usize).for_each(|a| unsafe { (a as *mut u8).write_volatile(0) }); } +/// the rust entry-point of os #[no_mangle] pub fn rust_main() -> ! { extern "C" {