1 use crate::{ 2 arch::{ 3 init::{early_setup_arch, setup_arch, setup_arch_post}, 4 time::time_init, 5 CurrentIrqArch, CurrentSMPArch, CurrentSchedArch, 6 }, 7 driver::{base::init::driver_init, serial::serial_early_init, video::VideoRefreshManager}, 8 exception::{init::irq_init, softirq::softirq_init, InterruptArch}, 9 filesystem::vfs::core::vfs_init, 10 init::init_intertrait, 11 libs::{ 12 futex::futex::Futex, 13 lib_ui::{ 14 screen_manager::{scm_init, scm_reinit}, 15 textui::textui_init, 16 }, 17 printk::early_init_logging, 18 }, 19 mm::init::mm_init, 20 process::{kthread::kthread_init, process_init, ProcessManager}, 21 sched::SchedArch, 22 smp::{early_smp_init, SMPArch}, 23 syscall::Syscall, 24 time::{ 25 clocksource::clocksource_boot_finish, timekeeping::timekeeping_init, timer::timer_init, 26 }, 27 }; 28 29 /// The entry point for the kernel 30 /// 31 /// 前面可能会有一个架构相关的函数 32 pub fn start_kernel() -> ! { 33 // 进入内核后,中断应该是关闭的 34 assert!(!CurrentIrqArch::is_irq_enabled()); 35 36 do_start_kernel(); 37 38 CurrentSchedArch::initial_setup_sched_local(); 39 40 CurrentSchedArch::enable_sched_local(); 41 42 ProcessManager::arch_idle_func(); 43 } 44 45 #[inline(never)] 46 fn do_start_kernel() { 47 init_before_mem_init(); 48 early_init_logging(); 49 50 early_setup_arch().expect("setup_arch failed"); 51 unsafe { mm_init() }; 52 53 scm_reinit().unwrap(); 54 textui_init().unwrap(); 55 init_intertrait(); 56 57 vfs_init().expect("vfs init failed"); 58 driver_init().expect("driver init failed"); 59 60 #[cfg(target_arch = "x86_64")] 61 unsafe { 62 crate::include::bindings::bindings::acpi_init() 63 }; 64 crate::sched::sched_init(); 65 process_init(); 66 early_smp_init().expect("early smp init failed"); 67 irq_init().expect("irq init failed"); 68 setup_arch().expect("setup_arch failed"); 69 CurrentSMPArch::prepare_cpus().expect("prepare_cpus failed"); 70 71 // sched_init(); 72 softirq_init().expect("softirq init failed"); 73 Syscall::init().expect("syscall init failed"); 74 timekeeping_init(); 75 time_init(); 76 timer_init(); 77 kthread_init(); 78 clocksource_boot_finish(); 79 80 Futex::init(); 81 82 setup_arch_post().expect("setup_arch_post failed"); 83 84 #[cfg(all(target_arch = "x86_64", feature = "kvm"))] 85 crate::virt::kvm::kvm_init(); 86 } 87 88 /// 在内存管理初始化之前,执行的初始化 89 #[inline(never)] 90 fn init_before_mem_init() { 91 serial_early_init().expect("serial early init failed"); 92 let video_ok = unsafe { VideoRefreshManager::video_init().is_ok() }; 93 scm_init(video_ok); 94 } 95