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