From f4102e7db42d12dddcc2a3d689027e7be46434e9 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Wed, 11 Feb 2026 17:28:13 +0800 Subject: [PATCH] Rename `call_ostd_main` to `start_kernel` --- ostd/src/arch/loongarch/boot/mod.rs | 4 ++-- ostd/src/arch/riscv/boot/mod.rs | 4 ++-- ostd/src/arch/x86/boot/linux_boot/mod.rs | 4 ++-- ostd/src/arch/x86/boot/multiboot/mod.rs | 4 ++-- ostd/src/arch/x86/boot/multiboot2/mod.rs | 4 ++-- ostd/src/boot/mod.rs | 11 +++++++---- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ostd/src/arch/loongarch/boot/mod.rs b/ostd/src/arch/loongarch/boot/mod.rs index 7620b268c..a43e39673 100644 --- a/ostd/src/arch/loongarch/boot/mod.rs +++ b/ostd/src/arch/loongarch/boot/mod.rs @@ -125,7 +125,7 @@ unsafe extern "C" fn loongarch_boot( let cmdline_ptr = paddr_to_vaddr(cmdline_paddr) as *const i8; let cmdline = unsafe { CStr::from_ptr(cmdline_ptr) }.to_str(); - use crate::boot::{EARLY_INFO, EarlyBootInfo, call_ostd_main}; + use crate::boot::{EARLY_INFO, EarlyBootInfo, start_kernel}; EARLY_INFO.call_once(|| EarlyBootInfo { bootloader_name: parse_bootloader_name(), @@ -138,5 +138,5 @@ unsafe extern "C" fn loongarch_boot( // SAFETY: The safety is guaranteed by the safety preconditions and the fact that we call it // once after setting up necessary resources. - unsafe { call_ostd_main() }; + unsafe { start_kernel() }; } diff --git a/ostd/src/arch/riscv/boot/mod.rs b/ostd/src/arch/riscv/boot/mod.rs index 7fe2d339c..20eebd39d 100644 --- a/ostd/src/arch/riscv/boot/mod.rs +++ b/ostd/src/arch/riscv/boot/mod.rs @@ -128,7 +128,7 @@ unsafe extern "C" fn riscv_boot(hart_id: usize, device_tree_paddr: usize) -> ! { let fdt = unsafe { fdt::Fdt::from_ptr(device_tree_ptr).unwrap() }; DEVICE_TREE.call_once(|| fdt); - use crate::boot::{EARLY_INFO, EarlyBootInfo, call_ostd_main}; + use crate::boot::{EARLY_INFO, EarlyBootInfo, start_kernel}; EARLY_INFO.call_once(|| EarlyBootInfo { bootloader_name: parse_bootloader_name(), @@ -141,5 +141,5 @@ unsafe extern "C" fn riscv_boot(hart_id: usize, device_tree_paddr: usize) -> ! { // SAFETY: The safety is guaranteed by the safety preconditions and the fact that we call it // once after setting up necessary resources. - unsafe { call_ostd_main() }; + unsafe { start_kernel() }; } diff --git a/ostd/src/arch/x86/boot/linux_boot/mod.rs b/ostd/src/arch/x86/boot/linux_boot/mod.rs index 9046fa3df..2c7ea1303 100644 --- a/ostd/src/arch/x86/boot/linux_boot/mod.rs +++ b/ostd/src/arch/x86/boot/linux_boot/mod.rs @@ -205,7 +205,7 @@ unsafe extern "sysv64" fn __linux_boot(params_ptr: *const BootParams) -> ! { let params = unsafe { &*params_ptr }; assert_eq!({ params.hdr.header }, LINUX_BOOT_HEADER_MAGIC); - use crate::boot::{EARLY_INFO, EarlyBootInfo, call_ostd_main}; + use crate::boot::{EARLY_INFO, EarlyBootInfo, start_kernel}; #[cfg(feature = "cvm_guest")] init_cvm_guest(); @@ -221,5 +221,5 @@ unsafe extern "sysv64" fn __linux_boot(params_ptr: *const BootParams) -> ! { // SAFETY: The safety is guaranteed by the safety preconditions and the fact that we call it // once after setting up necessary resources. - unsafe { call_ostd_main() }; + unsafe { start_kernel() }; } diff --git a/ostd/src/arch/x86/boot/multiboot/mod.rs b/ostd/src/arch/x86/boot/multiboot/mod.rs index bf650b64e..d28f1545b 100644 --- a/ostd/src/arch/x86/boot/multiboot/mod.rs +++ b/ostd/src/arch/x86/boot/multiboot/mod.rs @@ -376,7 +376,7 @@ unsafe extern "sysv64" fn __multiboot_entry(boot_magic: u32, boot_params: u64) - let mb1_info = unsafe { &*(paddr_to_vaddr(boot_params as usize) as *const MultibootLegacyInfo) }; - use crate::boot::{EARLY_INFO, EarlyBootInfo, call_ostd_main}; + use crate::boot::{EARLY_INFO, EarlyBootInfo, start_kernel}; EARLY_INFO.call_once(|| EarlyBootInfo { bootloader_name: parse_bootloader_name(mb1_info).unwrap_or("Unknown Multiboot Loader"), @@ -389,5 +389,5 @@ unsafe extern "sysv64" fn __multiboot_entry(boot_magic: u32, boot_params: u64) - // SAFETY: The safety is guaranteed by the safety preconditions and the fact that we call it // once after setting up necessary resources. - unsafe { call_ostd_main() }; + unsafe { start_kernel() }; } diff --git a/ostd/src/arch/x86/boot/multiboot2/mod.rs b/ostd/src/arch/x86/boot/multiboot2/mod.rs index 6d8f37a6e..7d703a610 100644 --- a/ostd/src/arch/x86/boot/multiboot2/mod.rs +++ b/ostd/src/arch/x86/boot/multiboot2/mod.rs @@ -151,7 +151,7 @@ unsafe extern "sysv64" fn __multiboot2_entry(boot_magic: u32, boot_params: u64) let mb2_info = unsafe { BootInformation::load(boot_params as *const BootInformationHeader).unwrap() }; - use crate::boot::{EARLY_INFO, EarlyBootInfo, call_ostd_main}; + use crate::boot::{EARLY_INFO, EarlyBootInfo, start_kernel}; EARLY_INFO.call_once(|| EarlyBootInfo { bootloader_name: parse_bootloader_name(&mb2_info).unwrap_or("Unknown Multiboot2 Loader"), @@ -164,5 +164,5 @@ unsafe extern "sysv64" fn __multiboot2_entry(boot_magic: u32, boot_params: u64) // SAFETY: The safety is guaranteed by the safety preconditions and the fact that we call it // once after setting up necessary resources. - unsafe { call_ostd_main() }; + unsafe { start_kernel() }; } diff --git a/ostd/src/boot/mod.rs b/ostd/src/boot/mod.rs index 0c0b8367c..1d1b6e39c 100644 --- a/ostd/src/boot/mod.rs +++ b/ostd/src/boot/mod.rs @@ -113,10 +113,13 @@ pub(crate) fn init_after_heap() { }); } -/// Initializes OSTD and then jumps to the `#[ostd::main]` entry point. +/// Starts the kernel. /// -/// Any kernel that uses the `ostd` crate should define a function marked with -/// `#[ostd::main]` as the kernel's entry function. +/// The job of this function is to continue the early bootstrap (started in [`arch::boot`]) +/// and performs the initialization of OSTD. +/// Eventually, it transfers control to the entrypoint function +/// that the user of OSTD defines with `#[ostd::main]`, +/// which completes the kernel initialization. /// /// # Safety /// @@ -124,7 +127,7 @@ pub(crate) fn init_after_heap() { /// [`arch::boot`] module. /// /// [`arch::boot`]: crate::arch::boot -pub(crate) unsafe fn call_ostd_main() -> ! { +pub(crate) unsafe fn start_kernel() -> ! { // The entry point of kernel code, which should be defined by the package that // uses OSTD. unsafe extern "Rust" {