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