12813126eSlogin #![no_std] // <1> 22813126eSlogin #![no_main] // <1> 3935f40ecSlogin #![feature(const_mut_refs)] 42813126eSlogin #![feature(core_intrinsics)] // <2> 5fb6c29d0Slogin #![feature(alloc_error_handler)] 666f67c6aSlogin #![feature(panic_info_message)] 71a2eaa40Slogin #![feature(drain_filter)] // 允许Vec的drain_filter特性 8151251b5Slogin #![feature(c_void_variant)] // used in kernel/src/exception/softirq.rs 92813126eSlogin #[allow(non_upper_case_globals)] 102813126eSlogin #[allow(non_camel_case_types)] 112813126eSlogin #[allow(non_snake_case)] 12fb6c29d0Slogin use core::panic::PanicInfo; 13fb6c29d0Slogin 14adc1846bSlogin /// 导出x86_64架构相关的代码,命名为arch模块 15adc1846bSlogin #[cfg(target_arch = "x86_64")] 16adc1846bSlogin #[path = "arch/x86_64/mod.rs"] 1766f67c6aSlogin #[macro_use] 1866f67c6aSlogin mod arch; 1982d2e446Slogin #[macro_use] 20fb6c29d0Slogin mod libs; 21004e86ffSlogin #[macro_use] 22004e86ffSlogin mod include; 23004e86ffSlogin mod driver; // 如果driver依赖了libs,应该在libs后面导出 24ec53d23eSlogin mod exception; 25004e86ffSlogin mod filesystem; 26004e86ffSlogin mod io; 27004e86ffSlogin mod ipc; 2866f67c6aSlogin mod mm; 294454d1a2Slogin mod net; 3066f67c6aSlogin mod process; 3166f67c6aSlogin mod sched; 3266f67c6aSlogin mod smp; 334454d1a2Slogin mod syscall; 3401876902SGou Ngai mod time; 3582d2e446Slogin 36004e86ffSlogin #[macro_use] 37fb6c29d0Slogin extern crate alloc; 38c2481452Shoumkh #[macro_use] 394454d1a2Slogin extern crate bitflags; 404454d1a2Slogin #[macro_use] 41c2481452Shoumkh extern crate lazy_static; 424454d1a2Slogin extern crate num; 43004e86ffSlogin #[macro_use] 444454d1a2Slogin extern crate num_derive; 454454d1a2Slogin extern crate smoltcp; 460d48c3c9Slogin extern crate thingbuf; 4784407d36Slogin 48*bacd691cSlogin #[cfg(target_arch = "x86_64")] 49*bacd691cSlogin extern crate x86; 50*bacd691cSlogin 51fb6c29d0Slogin use mm::allocator::KernelAllocator; 522813126eSlogin 53fb6c29d0Slogin // <3> 5401876902SGou Ngai use crate::{ 55adc1846bSlogin arch::asm::current::current_pcb, 562b771e32SGou Ngai include::bindings::bindings::{process_do_exit, BLACK, GREEN}, 5701876902SGou Ngai }; 58fb6c29d0Slogin 59fb6c29d0Slogin // 声明全局的slab分配器 60fb6c29d0Slogin #[cfg_attr(not(test), global_allocator)] 61fb6c29d0Slogin pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator {}; 62fb6c29d0Slogin 63fb6c29d0Slogin /// 全局的panic处理函数 642813126eSlogin #[panic_handler] 652813126eSlogin #[no_mangle] 6666f67c6aSlogin pub fn panic(info: &PanicInfo) -> ! { 6766f67c6aSlogin kerror!("Kernel Panic Occurred."); 6866f67c6aSlogin 6966f67c6aSlogin match info.location() { 7066f67c6aSlogin Some(loc) => { 7166f67c6aSlogin println!( 7266f67c6aSlogin "Location:\n\tFile: {}\n\tLine: {}, Column: {}", 7366f67c6aSlogin loc.file(), 7466f67c6aSlogin loc.line(), 7566f67c6aSlogin loc.column() 7666f67c6aSlogin ); 7766f67c6aSlogin } 7866f67c6aSlogin None => { 7966f67c6aSlogin println!("No location info"); 8066f67c6aSlogin } 8166f67c6aSlogin } 8266f67c6aSlogin 8366f67c6aSlogin match info.message() { 8466f67c6aSlogin Some(msg) => { 8566f67c6aSlogin println!("Message:\n\t{}", msg); 8666f67c6aSlogin } 8766f67c6aSlogin None => { 8866f67c6aSlogin println!("No panic message."); 8966f67c6aSlogin } 9066f67c6aSlogin } 9166f67c6aSlogin 9266f67c6aSlogin println!("Current PCB:\n\t{:?}", current_pcb()); 9366f67c6aSlogin unsafe { 9466f67c6aSlogin process_do_exit(u64::MAX); 9566f67c6aSlogin }; 9601876902SGou Ngai loop {} 972813126eSlogin } 982813126eSlogin 99fb6c29d0Slogin /// 该函数用作测试,在process.c的initial_kernel_thread()中调用了此函数 1002813126eSlogin #[no_mangle] 1012813126eSlogin pub extern "C" fn __rust_demo_func() -> i32 { 102fb6c29d0Slogin printk_color!(GREEN, BLACK, "__rust_demo_func()\n"); 1032813126eSlogin return 0; 1042813126eSlogin } 105