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