mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-07-10 06:26:07 +08:00
add os[1-8]-ref for os refereces, add guide, add README
This commit is contained in:
77
os8-ref/src/main.rs
Normal file
77
os8-ref/src/main.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
//! The main module and entrypoint
|
||||
//!
|
||||
//! Various facilities of the kernels are implemented as submodules. The most
|
||||
//! important ones are:
|
||||
//!
|
||||
//! - [`trap`]: Handles all cases of switching from userspace to the kernel
|
||||
//! - [`task`]: Task management
|
||||
//! - [`syscall`]: System call handling and implementation
|
||||
//!
|
||||
//! The operating system also starts in this module. Kernel code starts
|
||||
//! executing from `entry.asm`, after which [`rust_main()`] is called to
|
||||
//! initialize various pieces of functionality. (See its source code for
|
||||
//! details.)
|
||||
//!
|
||||
//! We then call [`task::run_first_task()`] and for the first time go to
|
||||
//! userspace.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(alloc_error_handler)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[macro_use]
|
||||
mod console;
|
||||
mod config;
|
||||
mod drivers;
|
||||
mod fs;
|
||||
mod lang_items;
|
||||
mod logging;
|
||||
mod mm;
|
||||
mod sbi;
|
||||
mod sync;
|
||||
mod syscall;
|
||||
mod task;
|
||||
mod timer;
|
||||
mod trap;
|
||||
|
||||
core::arch::global_asm!(include_str!("entry.asm"));
|
||||
|
||||
/// clear BSS segment
|
||||
fn clear_bss() {
|
||||
extern "C" {
|
||||
fn sbss();
|
||||
fn ebss();
|
||||
}
|
||||
unsafe {
|
||||
core::slice::from_raw_parts_mut(sbss as usize as *mut u8, ebss as usize - sbss as usize)
|
||||
.fill(0);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// the rust entry-point of os
|
||||
pub fn rust_main() -> ! {
|
||||
clear_bss();
|
||||
logging::init();
|
||||
println!("[kernel] Hello, world!");
|
||||
mm::init();
|
||||
mm::remap_test();
|
||||
trap::init();
|
||||
trap::enable_timer_interrupt();
|
||||
timer::set_next_trigger();
|
||||
// Uncomment following lines and see what happens!
|
||||
// task::kernel_stackless_coroutine_test();
|
||||
// task::kernel_stackful_coroutine_test();
|
||||
fs::list_apps();
|
||||
task::add_initproc();
|
||||
task::run_tasks();
|
||||
panic!("Unreachable in rust_main!");
|
||||
}
|
||||
Reference in New Issue
Block a user