12813126eSlogin #![no_main] // <1> 2bb24249fSLoGin #![feature(alloc_error_handler)] 340fe15e0SLoGin #![feature(allocator_api)] 440fe15e0SLoGin #![feature(arbitrary_self_types)] 51496ba7bSLoGin #![feature(asm_const)] 65c4224e5SLoGin #![feature(concat_idents)] 7c566df45SLoGin #![feature(const_for)] 8935f40ecSlogin #![feature(const_mut_refs)] 906d5e247SLoGin #![feature(const_trait_impl)] 10a03c4f9dSLoGin #![feature(const_refs_to_cell)] 1140fe15e0SLoGin #![feature(core_intrinsics)] 1213776c11Slogin #![feature(c_void_variant)] 131a72a751SLoGin #![feature(extract_if)] 145c4224e5SLoGin #![feature(fn_align)] 15*dc9b4feaSLoGin #![feature(linked_list_retain)] 161496ba7bSLoGin #![feature(naked_functions)] 175c4224e5SLoGin #![feature(new_uninit)] 18bb24249fSLoGin #![feature(ptr_internals)] 19cde5492fSlogin #![feature(trait_upcasting)] 2040fe15e0SLoGin #![feature(slice_ptr_get)] 21bd70d2d1SLoGin #![feature(sync_unsafe_cell)] 2240fe15e0SLoGin #![feature(vec_into_raw_parts)] 23fba56231SLoGin #![cfg_attr(target_os = "none", no_std)] 24bd70d2d1SLoGin #![allow(internal_features)] 25840045afSLoGin // clippy的配置 26840045afSLoGin #![deny(clippy::all)] 27b5b571e0SLoGin #![allow(clippy::bad_bit_mask)] 28840045afSLoGin // DragonOS允许在函数中使用return语句(尤其是长函数时,我们推荐这么做) 29840045afSLoGin #![allow(clippy::let_and_return)] 30840045afSLoGin #![allow(clippy::needless_pass_by_ref_mut)] 31840045afSLoGin #![allow(clippy::needless_return)] 32b5b571e0SLoGin #![allow(clippy::single_char_pattern)] 33840045afSLoGin #![allow(clippy::upper_case_acronyms)] 34fba56231SLoGin 35fba56231SLoGin #[cfg(test)] 36fba56231SLoGin #[macro_use] 37fba56231SLoGin extern crate std; 3840fe15e0SLoGin 39fb6c29d0Slogin use core::panic::PanicInfo; 40fb6c29d0Slogin 41adc1846bSlogin /// 导出x86_64架构相关的代码,命名为arch模块 4266f67c6aSlogin #[macro_use] 4366f67c6aSlogin mod arch; 4482d2e446Slogin #[macro_use] 45fb6c29d0Slogin mod libs; 46004e86ffSlogin #[macro_use] 47004e86ffSlogin mod include; 487b32f508SLoGin mod debug; 49004e86ffSlogin mod driver; // 如果driver依赖了libs,应该在libs后面导出 50ec53d23eSlogin mod exception; 51004e86ffSlogin mod filesystem; 52fba56231SLoGin mod init; 53004e86ffSlogin mod ipc; 54196b75dcSLoGin mod misc; 5566f67c6aSlogin mod mm; 564454d1a2Slogin mod net; 5766f67c6aSlogin mod process; 5866f67c6aSlogin mod sched; 5966f67c6aSlogin mod smp; 604454d1a2Slogin mod syscall; 6101876902SGou Ngai mod time; 624fda81ceSLoGin 634fda81ceSLoGin #[cfg(target_arch = "x86_64")] 6440314b30SXiaoye Zheng mod virt; 6582d2e446Slogin 66004e86ffSlogin #[macro_use] 67fb6c29d0Slogin extern crate alloc; 68c2481452Shoumkh #[macro_use] 69393f6915SLoGin extern crate atomic_enum; 70393f6915SLoGin #[macro_use] 714454d1a2Slogin extern crate bitflags; 7240fe15e0SLoGin extern crate elf; 734454d1a2Slogin #[macro_use] 74c2481452Shoumkh extern crate lazy_static; 754454d1a2Slogin extern crate num; 76004e86ffSlogin #[macro_use] 774454d1a2Slogin extern crate num_derive; 784454d1a2Slogin extern crate smoltcp; 79fba56231SLoGin #[macro_use] 80fba56231SLoGin extern crate intertrait; 81bacd691cSlogin #[cfg(target_arch = "x86_64")] 82bacd691cSlogin extern crate x86; 83bacd691cSlogin 847b32f508SLoGin extern crate klog_types; 857a29d4fcSLoGin extern crate uefi; 867a29d4fcSLoGin extern crate uefi_raw; 87*dc9b4feaSLoGin #[macro_use] 88*dc9b4feaSLoGin extern crate wait_queue_macros; 897b32f508SLoGin 9040fe15e0SLoGin use crate::mm::allocator::kernel_allocator::KernelAllocator; 912813126eSlogin 921496ba7bSLoGin use crate::process::ProcessManager; 93fb6c29d0Slogin 944fda81ceSLoGin #[cfg(all(feature = "backtrace", target_arch = "x86_64"))] 95d470019bSLoGin extern crate mini_backtrace; 96d470019bSLoGin 97d470019bSLoGin extern "C" { 98d470019bSLoGin fn lookup_kallsyms(addr: u64, level: i32) -> i32; 99d470019bSLoGin } 100d470019bSLoGin 101abe3a6eaShanjiezhou // 声明全局的分配器 102fb6c29d0Slogin #[cfg_attr(not(test), global_allocator)] 10340fe15e0SLoGin pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator; 104fb6c29d0Slogin 105fb6c29d0Slogin /// 全局的panic处理函数 106fba56231SLoGin #[cfg(target_os = "none")] 1072813126eSlogin #[panic_handler] 1082813126eSlogin #[no_mangle] 10966f67c6aSlogin pub fn panic(info: &PanicInfo) -> ! { 1102eab6dd7S曾俊 use log::error; 1112eab6dd7S曾俊 1122eab6dd7S曾俊 error!("Kernel Panic Occurred."); 11366f67c6aSlogin 11466f67c6aSlogin match info.location() { 11566f67c6aSlogin Some(loc) => { 11666f67c6aSlogin println!( 11766f67c6aSlogin "Location:\n\tFile: {}\n\tLine: {}, Column: {}", 11866f67c6aSlogin loc.file(), 11966f67c6aSlogin loc.line(), 12066f67c6aSlogin loc.column() 12166f67c6aSlogin ); 12266f67c6aSlogin } 12366f67c6aSlogin None => { 12466f67c6aSlogin println!("No location info"); 12566f67c6aSlogin } 12666f67c6aSlogin } 127bd70d2d1SLoGin println!("Message:\n\t{}", info.message()); 12866f67c6aSlogin 1294fda81ceSLoGin #[cfg(all(feature = "backtrace", target_arch = "x86_64"))] 130d470019bSLoGin { 131d470019bSLoGin unsafe { 132d470019bSLoGin let bt = mini_backtrace::Backtrace::<16>::capture(); 133d470019bSLoGin println!("Rust Panic Backtrace:"); 134d470019bSLoGin let mut level = 0; 135d470019bSLoGin for frame in bt.frames { 136d470019bSLoGin lookup_kallsyms(frame as u64, level); 137d470019bSLoGin level += 1; 138d470019bSLoGin } 139d470019bSLoGin }; 140d470019bSLoGin } 141d470019bSLoGin 1422755467cS曾俊 println!("Current PCB:\n\t{:?}", (ProcessManager::current_pcb())); 143471d65cfSLoGin 1441496ba7bSLoGin ProcessManager::exit(usize::MAX); 1452813126eSlogin } 146