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