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