1 #![no_std] // <1> 2 #![no_main] // <1> 3 #![feature(alloc_error_handler)] 4 #![feature(allocator_api)] 5 #![feature(arbitrary_self_types)] 6 #![feature(asm_const)] 7 #![feature(const_mut_refs)] 8 #![feature(core_intrinsics)] 9 #![feature(c_void_variant)] 10 #![feature(drain_filter)] 11 #![feature(is_some_and)] 12 #![feature(naked_functions)] 13 #![feature(panic_info_message)] 14 #![feature(ptr_internals)] 15 #![feature(trait_upcasting)] 16 #![feature(slice_ptr_get)] 17 #![feature(vec_into_raw_parts)] 18 19 #[allow(non_upper_case_globals)] 20 #[allow(non_camel_case_types)] 21 #[allow(non_snake_case)] 22 use core::panic::PanicInfo; 23 24 /// 导出x86_64架构相关的代码,命名为arch模块 25 #[macro_use] 26 mod arch; 27 #[macro_use] 28 mod libs; 29 #[macro_use] 30 mod include; 31 mod driver; // 如果driver依赖了libs,应该在libs后面导出 32 mod exception; 33 mod filesystem; 34 mod ipc; 35 mod mm; 36 mod net; 37 mod process; 38 mod sched; 39 mod smp; 40 mod syscall; 41 mod time; 42 43 #[macro_use] 44 extern crate alloc; 45 #[macro_use] 46 extern crate bitflags; 47 extern crate elf; 48 #[macro_use] 49 extern crate lazy_static; 50 extern crate memoffset; 51 extern crate num; 52 #[macro_use] 53 extern crate num_derive; 54 extern crate smoltcp; 55 extern crate thingbuf; 56 #[cfg(target_arch = "x86_64")] 57 extern crate x86; 58 59 use crate::mm::allocator::kernel_allocator::KernelAllocator; 60 61 use crate::process::ProcessManager; 62 63 // 声明全局的分配器 64 #[cfg_attr(not(test), global_allocator)] 65 pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator; 66 67 /// 全局的panic处理函数 68 #[panic_handler] 69 #[no_mangle] 70 pub fn panic(info: &PanicInfo) -> ! { 71 kerror!("Kernel Panic Occurred."); 72 73 match info.location() { 74 Some(loc) => { 75 println!( 76 "Location:\n\tFile: {}\n\tLine: {}, Column: {}", 77 loc.file(), 78 loc.line(), 79 loc.column() 80 ); 81 } 82 None => { 83 println!("No location info"); 84 } 85 } 86 87 match info.message() { 88 Some(msg) => { 89 println!("Message:\n\t{}", msg); 90 } 91 None => { 92 println!("No panic message."); 93 } 94 } 95 96 println!("Current PCB:\n\t{:?}", *(ProcessManager::current_pcb())); 97 ProcessManager::exit(usize::MAX); 98 } 99