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