1 #![no_std] // <1> 2 #![no_main] // <1> 3 #![feature(const_mut_refs)] 4 #![feature(core_intrinsics)] // <2> 5 #![feature(alloc_error_handler)] 6 #![feature(panic_info_message)] 7 #![feature(drain_filter)] // 允许Vec的drain_filter特性 8 #![feature(c_void_variant)] //not stable, used in /home/su/Documents/VSCode/DragonOS/kernel/src/exception/softirq.rs 9 #[allow(non_upper_case_globals)] 10 #[allow(non_camel_case_types)] 11 #[allow(non_snake_case)] 12 use core::panic::PanicInfo; 13 14 /// 导出x86_64架构相关的代码,命名为arch模块 15 #[cfg(target_arch = "x86_64")] 16 #[path = "arch/x86_64/mod.rs"] 17 #[macro_use] 18 mod arch; 19 20 mod driver; 21 mod filesystem; 22 #[macro_use] 23 mod include; 24 mod ipc; 25 #[macro_use] 26 mod libs; 27 mod exception; 28 mod mm; 29 mod process; 30 mod sched; 31 mod smp; 32 mod time; 33 34 extern crate alloc; 35 36 use mm::allocator::KernelAllocator; 37 38 // <3> 39 use crate::{ 40 arch::asm::current::current_pcb, 41 include::bindings::bindings::{process_do_exit, BLACK, GREEN}, 42 }; 43 44 // 声明全局的slab分配器 45 #[cfg_attr(not(test), global_allocator)] 46 pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator {}; 47 48 /// 全局的panic处理函数 49 #[panic_handler] 50 #[no_mangle] 51 pub fn panic(info: &PanicInfo) -> ! { 52 kerror!("Kernel Panic Occurred."); 53 54 match info.location() { 55 Some(loc) => { 56 println!( 57 "Location:\n\tFile: {}\n\tLine: {}, Column: {}", 58 loc.file(), 59 loc.line(), 60 loc.column() 61 ); 62 } 63 None => { 64 println!("No location info"); 65 } 66 } 67 68 match info.message() { 69 Some(msg) => { 70 println!("Message:\n\t{}", msg); 71 } 72 None => { 73 println!("No panic message."); 74 } 75 } 76 77 println!("Current PCB:\n\t{:?}", current_pcb()); 78 unsafe { 79 process_do_exit(u64::MAX); 80 }; 81 loop {} 82 } 83 84 /// 该函数用作测试,在process.c的initial_kernel_thread()中调用了此函数 85 #[no_mangle] 86 pub extern "C" fn __rust_demo_func() -> i32 { 87 printk_color!(GREEN, BLACK, "__rust_demo_func()\n"); 88 89 return 0; 90 } 91