xref: /DragonOS/kernel/src/lib.rs (revision a03c4f9dee5705207325c56629c0ccd219168f10)
1 #![no_main] // <1>
2 #![feature(alloc_error_handler)]
3 #![feature(allocator_api)]
4 #![feature(arbitrary_self_types)]
5 #![feature(asm_const)]
6 #![feature(const_mut_refs)]
7 #![feature(const_trait_impl)]
8 #![feature(const_refs_to_cell)]
9 #![feature(core_intrinsics)]
10 #![feature(c_void_variant)]
11 #![feature(drain_filter)]
12 #![feature(is_some_and)]
13 #![feature(naked_functions)]
14 #![feature(panic_info_message)]
15 #![feature(ptr_internals)]
16 #![feature(trait_upcasting)]
17 #![feature(slice_ptr_get)]
18 #![feature(vec_into_raw_parts)]
19 #![cfg_attr(target_os = "none", no_std)]
20 
21 #[cfg(test)]
22 #[macro_use]
23 extern crate std;
24 
25 #[allow(non_upper_case_globals)]
26 #[allow(non_camel_case_types)]
27 #[allow(non_snake_case)]
28 use core::panic::PanicInfo;
29 
30 /// 导出x86_64架构相关的代码,命名为arch模块
31 #[macro_use]
32 mod arch;
33 #[macro_use]
34 mod libs;
35 #[macro_use]
36 mod include;
37 mod driver; // 如果driver依赖了libs,应该在libs后面导出
38 mod exception;
39 mod filesystem;
40 mod init;
41 mod ipc;
42 mod mm;
43 mod net;
44 mod process;
45 mod sched;
46 mod smp;
47 mod syscall;
48 mod time;
49 
50 #[macro_use]
51 extern crate alloc;
52 #[macro_use]
53 extern crate bitflags;
54 extern crate elf;
55 #[macro_use]
56 extern crate lazy_static;
57 extern crate memoffset;
58 extern crate num;
59 #[macro_use]
60 extern crate num_derive;
61 extern crate smoltcp;
62 extern crate thingbuf;
63 #[macro_use]
64 extern crate intertrait;
65 #[cfg(target_arch = "x86_64")]
66 extern crate x86;
67 
68 use crate::mm::allocator::kernel_allocator::KernelAllocator;
69 
70 use crate::process::ProcessManager;
71 
72 // 声明全局的分配器
73 #[cfg_attr(not(test), global_allocator)]
74 pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator;
75 
76 /// 全局的panic处理函数
77 #[cfg(target_os = "none")]
78 #[panic_handler]
79 #[no_mangle]
80 pub fn panic(info: &PanicInfo) -> ! {
81     kerror!("Kernel Panic Occurred.");
82 
83     match info.location() {
84         Some(loc) => {
85             println!(
86                 "Location:\n\tFile: {}\n\tLine: {}, Column: {}",
87                 loc.file(),
88                 loc.line(),
89                 loc.column()
90             );
91         }
92         None => {
93             println!("No location info");
94         }
95     }
96 
97     match info.message() {
98         Some(msg) => {
99             println!("Message:\n\t{}", msg);
100         }
101         None => {
102             println!("No panic message.");
103         }
104     }
105 
106     println!("Current PCB:\n\t{:?}", *(ProcessManager::current_pcb()));
107     ProcessManager::exit(usize::MAX);
108 }
109