12813126eSlogin #![no_std] // <1> 22813126eSlogin #![no_main] // <1> 3bb24249fSLoGin #![feature(alloc_error_handler)] 4*40fe15e0SLoGin #![feature(allocator_api)] 5*40fe15e0SLoGin #![feature(arbitrary_self_types)] 6935f40ecSlogin #![feature(const_mut_refs)] 7*40fe15e0SLoGin #![feature(core_intrinsics)] 813776c11Slogin #![feature(c_void_variant)] 9*40fe15e0SLoGin #![feature(drain_filter)] 10bb24249fSLoGin #![feature(panic_info_message)] 11bb24249fSLoGin #![feature(ptr_internals)] 12cde5492fSlogin #![feature(trait_upcasting)] 13*40fe15e0SLoGin #![feature(slice_ptr_get)] 14*40fe15e0SLoGin #![feature(vec_into_raw_parts)] 15*40fe15e0SLoGin 162813126eSlogin #[allow(non_upper_case_globals)] 172813126eSlogin #[allow(non_camel_case_types)] 182813126eSlogin #[allow(non_snake_case)] 19fb6c29d0Slogin use core::panic::PanicInfo; 20fb6c29d0Slogin 21adc1846bSlogin /// 导出x86_64架构相关的代码,命名为arch模块 2266f67c6aSlogin #[macro_use] 2366f67c6aSlogin mod arch; 2482d2e446Slogin #[macro_use] 25fb6c29d0Slogin mod libs; 26004e86ffSlogin #[macro_use] 27004e86ffSlogin mod include; 28004e86ffSlogin mod driver; // 如果driver依赖了libs,应该在libs后面导出 29ec53d23eSlogin mod exception; 30004e86ffSlogin mod filesystem; 31004e86ffSlogin mod io; 32004e86ffSlogin mod ipc; 3366f67c6aSlogin mod mm; 344454d1a2Slogin mod net; 3566f67c6aSlogin mod process; 3666f67c6aSlogin mod sched; 3766f67c6aSlogin mod smp; 384454d1a2Slogin mod syscall; 3901876902SGou Ngai mod time; 4082d2e446Slogin 41004e86ffSlogin #[macro_use] 42fb6c29d0Slogin extern crate alloc; 43c2481452Shoumkh #[macro_use] 444454d1a2Slogin extern crate bitflags; 45*40fe15e0SLoGin extern crate elf; 464454d1a2Slogin #[macro_use] 47c2481452Shoumkh extern crate lazy_static; 484454d1a2Slogin extern crate num; 49004e86ffSlogin #[macro_use] 504454d1a2Slogin extern crate num_derive; 514454d1a2Slogin extern crate smoltcp; 520d48c3c9Slogin extern crate thingbuf; 53bacd691cSlogin #[cfg(target_arch = "x86_64")] 54bacd691cSlogin extern crate x86; 55bacd691cSlogin 56*40fe15e0SLoGin use crate::mm::allocator::kernel_allocator::KernelAllocator; 572813126eSlogin 58fb6c29d0Slogin // <3> 5901876902SGou Ngai use crate::{ 60adc1846bSlogin arch::asm::current::current_pcb, 612b771e32SGou Ngai include::bindings::bindings::{process_do_exit, BLACK, GREEN}, 6213776c11Slogin net::net_core::net_init, 6301876902SGou Ngai }; 64fb6c29d0Slogin 65fb6c29d0Slogin // 声明全局的slab分配器 66fb6c29d0Slogin #[cfg_attr(not(test), global_allocator)] 67*40fe15e0SLoGin pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator; 68fb6c29d0Slogin 69fb6c29d0Slogin /// 全局的panic处理函数 702813126eSlogin #[panic_handler] 712813126eSlogin #[no_mangle] 7266f67c6aSlogin pub fn panic(info: &PanicInfo) -> ! { 7366f67c6aSlogin kerror!("Kernel Panic Occurred."); 7466f67c6aSlogin 7566f67c6aSlogin match info.location() { 7666f67c6aSlogin Some(loc) => { 7766f67c6aSlogin println!( 7866f67c6aSlogin "Location:\n\tFile: {}\n\tLine: {}, Column: {}", 7966f67c6aSlogin loc.file(), 8066f67c6aSlogin loc.line(), 8166f67c6aSlogin loc.column() 8266f67c6aSlogin ); 8366f67c6aSlogin } 8466f67c6aSlogin None => { 8566f67c6aSlogin println!("No location info"); 8666f67c6aSlogin } 8766f67c6aSlogin } 8866f67c6aSlogin 8966f67c6aSlogin match info.message() { 9066f67c6aSlogin Some(msg) => { 9166f67c6aSlogin println!("Message:\n\t{}", msg); 9266f67c6aSlogin } 9366f67c6aSlogin None => { 9466f67c6aSlogin println!("No panic message."); 9566f67c6aSlogin } 9666f67c6aSlogin } 9766f67c6aSlogin 9866f67c6aSlogin println!("Current PCB:\n\t{:?}", current_pcb()); 9966f67c6aSlogin unsafe { 10066f67c6aSlogin process_do_exit(u64::MAX); 10166f67c6aSlogin }; 10201876902SGou Ngai loop {} 1032813126eSlogin } 1042813126eSlogin 105fb6c29d0Slogin /// 该函数用作测试,在process.c的initial_kernel_thread()中调用了此函数 1062813126eSlogin #[no_mangle] 1072813126eSlogin pub extern "C" fn __rust_demo_func() -> i32 { 108fb6c29d0Slogin printk_color!(GREEN, BLACK, "__rust_demo_func()\n"); 109cde5492fSlogin let r = net_init(); 110cde5492fSlogin if r.is_err() { 111cde5492fSlogin kwarn!("net_init() failed: {:?}", r.err().unwrap()); 112cde5492fSlogin } 1132813126eSlogin return 0; 1142813126eSlogin } 115