12813126eSlogin #![no_std] // <1> 22813126eSlogin #![no_main] // <1> 32813126eSlogin #![feature(core_intrinsics)] // <2> 4fb6c29d0Slogin #![feature(alloc_error_handler)] 566f67c6aSlogin #![feature(panic_info_message)] 61a2eaa40Slogin #![feature(drain_filter)] // 允许Vec的drain_filter特性 762e46139SGou Ngai #![feature(c_void_variant)] //not stable, used in /home/su/Documents/VSCode/DragonOS/kernel/src/exception/softirq.rs 82813126eSlogin #[allow(non_upper_case_globals)] 92813126eSlogin #[allow(non_camel_case_types)] 102813126eSlogin #[allow(non_snake_case)] 11fb6c29d0Slogin use core::panic::PanicInfo; 12fb6c29d0Slogin 13adc1846bSlogin /// 导出x86_64架构相关的代码,命名为arch模块 14adc1846bSlogin #[cfg(target_arch = "x86_64")] 15adc1846bSlogin #[path = "arch/x86_64/mod.rs"] 1666f67c6aSlogin #[macro_use] 1766f67c6aSlogin mod arch; 18adc1846bSlogin 19587086d3Slogin mod driver; 20587086d3Slogin mod filesystem; 2166f67c6aSlogin #[macro_use] 2266f67c6aSlogin mod include; 2366f67c6aSlogin mod ipc; 2482d2e446Slogin #[macro_use] 25fb6c29d0Slogin mod libs; 26*ec53d23eSlogin mod exception; 2766f67c6aSlogin mod mm; 2866f67c6aSlogin mod process; 2966f67c6aSlogin mod sched; 3066f67c6aSlogin mod smp; 3101876902SGou Ngai mod time; 3282d2e446Slogin 33fb6c29d0Slogin extern crate alloc; 3482d2e446Slogin 35fb6c29d0Slogin use mm::allocator::KernelAllocator; 362813126eSlogin 37fb6c29d0Slogin // <3> 3801876902SGou Ngai use crate::{ 39adc1846bSlogin arch::asm::current::current_pcb, 4001876902SGou Ngai include::bindings::bindings::{process_do_exit, BLACK, GREEN}, 4101876902SGou Ngai }; 42fb6c29d0Slogin 43fb6c29d0Slogin // 声明全局的slab分配器 44fb6c29d0Slogin #[cfg_attr(not(test), global_allocator)] 45fb6c29d0Slogin pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator {}; 46fb6c29d0Slogin 47fb6c29d0Slogin /// 全局的panic处理函数 482813126eSlogin #[panic_handler] 492813126eSlogin #[no_mangle] 5066f67c6aSlogin pub fn panic(info: &PanicInfo) -> ! { 5166f67c6aSlogin kerror!("Kernel Panic Occurred."); 5266f67c6aSlogin 5366f67c6aSlogin match info.location() { 5466f67c6aSlogin Some(loc) => { 5566f67c6aSlogin println!( 5666f67c6aSlogin "Location:\n\tFile: {}\n\tLine: {}, Column: {}", 5766f67c6aSlogin loc.file(), 5866f67c6aSlogin loc.line(), 5966f67c6aSlogin loc.column() 6066f67c6aSlogin ); 6166f67c6aSlogin } 6266f67c6aSlogin None => { 6366f67c6aSlogin println!("No location info"); 6466f67c6aSlogin } 6566f67c6aSlogin } 6666f67c6aSlogin 6766f67c6aSlogin match info.message() { 6866f67c6aSlogin Some(msg) => { 6966f67c6aSlogin println!("Message:\n\t{}", msg); 7066f67c6aSlogin } 7166f67c6aSlogin None => { 7266f67c6aSlogin println!("No panic message."); 7366f67c6aSlogin } 7466f67c6aSlogin } 7566f67c6aSlogin 7666f67c6aSlogin println!("Current PCB:\n\t{:?}", current_pcb()); 7766f67c6aSlogin unsafe { 7866f67c6aSlogin process_do_exit(u64::MAX); 7966f67c6aSlogin }; 8001876902SGou Ngai loop {} 812813126eSlogin } 822813126eSlogin 83fb6c29d0Slogin /// 该函数用作测试,在process.c的initial_kernel_thread()中调用了此函数 842813126eSlogin #[no_mangle] 852813126eSlogin pub extern "C" fn __rust_demo_func() -> i32 { 86fb6c29d0Slogin printk_color!(GREEN, BLACK, "__rust_demo_func()\n"); 8761de2cdcSlogin 882813126eSlogin return 0; 892813126eSlogin } 90