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