Rename aster_main as ostd::main

This commit is contained in:
Jianfeng Jiang 2024-06-20 06:16:04 +00:00 committed by Tate, Hongliang Tian
parent 59350a8578
commit fe7251c413
20 changed files with 51 additions and 41 deletions

20
Cargo.lock generated
View File

@ -128,15 +128,6 @@ dependencies = [
"spin 0.9.8",
]
[[package]]
name = "aster-main"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.49",
]
[[package]]
name = "aster-network"
version = "0.1.0"
@ -1101,7 +1092,6 @@ dependencies = [
"align_ext",
"aml",
"array-init",
"aster-main",
"bit_field",
"bitflags 1.3.2",
"bitvec",
@ -1121,6 +1111,7 @@ dependencies = [
"num",
"num-derive",
"num-traits",
"ostd-macros",
"pod",
"rsdp",
"spin 0.9.8",
@ -1134,6 +1125,15 @@ dependencies = [
"xarray",
]
[[package]]
name = "ostd-macros"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.49",
]
[[package]]
name = "owo-colors"
version = "3.5.0"

View File

@ -3,7 +3,7 @@ resolver = "2"
members = [
"ostd",
"ostd/libs/align_ext",
"ostd/libs/aster-main",
"ostd/libs/ostd-macros",
"ostd/libs/id-alloc",
"ostd/libs/linux-bzimage/builder",
"ostd/libs/linux-bzimage/boot-params",

View File

@ -86,7 +86,7 @@ export
# or tested without OSDK.
NON_OSDK_CRATES := \
ostd/libs/align_ext \
ostd/libs/aster-main \
ostd/libs/ostd-macros \
ostd/libs/id-alloc \
ostd/libs/linux-bzimage/builder \
ostd/libs/linux-bzimage/boot-params \

View File

@ -51,7 +51,7 @@ myos/
#### Kernel project
The `src/lib.rs` file contains the code for a simple kernel.
The function marked with the `#[aster_main]` macro
The function marked with the `#[ostd::main]` macro
is considered the kernel entry point by OSDK.
The kernel
will print `Hello world from the guest kernel!`to the console

View File

@ -40,7 +40,7 @@ and then hand over control to the kernel entry point
to execute the kernel code.
**Note**: Only kernel projects (the projects
that defines the function marked with `#[aster_main]`)
that defines the function marked with `#[ostd::main]`)
can be run;
library projects cannot.

View File

@ -76,7 +76,7 @@ Here are some additional notes for the fields:
1. The type of current crate.
Optional. If not specified,
the default value is inferred from the usage of the macro `#[aster_main]`.
the default value is inferred from the usage of the macro `#[ostd::main]`.
if the macro is used, the default value is `kernel`.
Otherwise, the default value is `library`.

View File

@ -61,8 +61,8 @@ use ostd::mm::{PageFlags, PAGE_SIZE, Vaddr, FrameAllocOptions, VmIo, VmMapOption
/// The kernel's boot and initialization process is managed by Asterinas OSTD.
/// After the process is done, the kernel's execution environment
/// (e.g., stack, heap, tasks) will be ready for use and the entry function
/// labeled as `#[aster_main]` will be called.
#[aster_main]
/// labeled as `#[ostd::main]` will be called.
#[ostd::main]
pub fn main() {
let program_binary = include_bytes!("../hello_world");
let user_space = create_user_space(program_binary);

View File

@ -7,7 +7,7 @@ extern crate ostd;
use ostd::prelude::*;
#[aster_main]
#[ostd::main]
pub fn main() {
println!("[kernel] finish init ostd");
component::init_all(component::parse_metadata!()).unwrap();

View File

@ -3,7 +3,7 @@
use ostd::prelude::*;
#[aster_main]
#[ostd::main]
fn kernel_main() {
println!("Hello world from guest kernel!");
}

View File

@ -91,7 +91,7 @@ pub struct CrateInfo {
/// If there are multiple kernel crates or no kernel crates in the workspace,
/// this function will exit with an error.
///
/// A crate is considered a kernel crate if it utilizes the `aster_main` macro.
/// A crate is considered a kernel crate if it utilizes the `ostd::main` macro.
fn get_default_member(metadata: &serde_json::Value) -> &str {
let default_members = metadata
.get("workspace_default_members")
@ -127,7 +127,7 @@ fn get_default_member(metadata: &serde_json::Value) -> &str {
syn::parse_file(&content).unwrap()
};
contains_aster_main_macro(&file)
contains_ostd_main_macro(&file)
})
.collect()
};
@ -145,7 +145,7 @@ fn get_default_member(metadata: &serde_json::Value) -> &str {
packages[0].get("id").unwrap().as_str().unwrap()
}
fn contains_aster_main_macro(file: &syn::File) -> bool {
fn contains_ostd_main_macro(file: &syn::File) -> bool {
for item in &file.items {
let syn::Item::Fn(item_fn) = item else {
continue;
@ -153,7 +153,7 @@ fn contains_aster_main_macro(file: &syn::File) -> bool {
for attr in &item_fn.attrs {
let attr = format!("{}", attr.to_token_stream());
if attr.as_str() == "# [aster_main]" {
if attr.as_str() == "# [ostd :: main]" || attr.as_str() == "#[main]" {
return true;
}
}

View File

@ -5,7 +5,7 @@
use ostd::prelude::*;
#[aster_main]
#[ostd::main]
fn kernel_main() {
let avail_mem_as_mb = mylib::available_memory() / 1_000_000;
println!("The available memory is {} MB", avail_mem_as_mb);

View File

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
align_ext = { path = "libs/align_ext" }
aster-main = { path = "libs/aster-main" }
ostd-macros = { path = "libs/ostd-macros" }
bit_field = "0.10.1"
bitflags = "1.3"
bitvec = { version = "1.0", default-features = false, features = ["alloc"] }

View File

@ -1,5 +1,5 @@
[package]
name = "aster-main"
name = "ostd-macros"
version = "0.1.0"
edition = "2021"

View File

@ -4,15 +4,26 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};
/// The kernel entry point.
/// This macro is used to mark the kernel entry point.
///
/// # Example
///
/// ```norun
/// use ostd::prelude::*;
///
/// #[ostd::main]
/// pub fn main() {
/// println!("hello world");
/// }
/// ```
#[proc_macro_attribute]
pub fn aster_main(_attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
let main_fn = parse_macro_input!(item as ItemFn);
let main_fn_name = &main_fn.sig.ident;
quote!(
#[no_mangle]
pub fn __aster_main() -> ! {
pub fn __ostd_main() -> ! {
ostd::init();
#main_fn_name();
ostd::prelude::abort();

View File

@ -160,5 +160,5 @@ unsafe extern "sysv64" fn __linux_boot(params_ptr: *const BootParams) -> ! {
init_framebuffer_info,
init_memory_regions,
);
crate::boot::call_aster_main();
crate::boot::call_ostd_main();
}

View File

@ -404,5 +404,5 @@ unsafe extern "sysv64" fn __multiboot_entry(boot_magic: u32, boot_params: u64) -
init_framebuffer_info,
init_memory_regions,
);
crate::boot::call_aster_main();
crate::boot::call_ostd_main();
}

View File

@ -167,5 +167,5 @@ unsafe extern "sysv64" fn __multiboot2_entry(boot_magic: u32, boot_params: u64)
init_framebuffer_info,
init_memory_regions,
);
crate::boot::call_aster_main();
crate::boot::call_ostd_main();
}

View File

@ -67,7 +67,7 @@ macro_rules! define_global_static_boot_arguments {
///
/// For the introduction of a new boot protocol, the entry point could be a novel
/// one. The entry point function should register all the boot initialization
/// methods before `aster_main` is called. A boot initialization method takes a
/// methods before `ostd::main` is called. A boot initialization method takes a
/// reference of the global static boot information variable and initialize it,
/// so that the boot information it represents could be accessed in the kernel
/// anywhere.
@ -110,17 +110,17 @@ pub fn init() {
/// Calls the OSTD-user defined entrypoint of the actual kernel.
///
/// Any kernel that uses the `ostd` crate should define a function named
/// `aster_main` as the entrypoint.
pub fn call_aster_main() -> ! {
/// Any kernel that uses the `ostd` crate should define a function marked with
/// `ostd::main` as the entrypoint.
pub fn call_ostd_main() -> ! {
#[cfg(not(ktest))]
unsafe {
// The entry point of kernel code, which should be defined by the package that
// uses OSTD.
extern "Rust" {
fn __aster_main() -> !;
fn __ostd_main() -> !;
}
__aster_main();
__ostd_main();
}
#[cfg(ktest)]
unsafe {

View File

@ -44,12 +44,13 @@ pub mod task;
pub mod trap;
pub mod user;
pub use ostd_macros::main;
#[cfg(feature = "intel_tdx")]
use tdx_guest::init_tdx;
pub use self::{cpu::CpuLocal, error::Error, prelude::Result};
/// Initialize OSTD.
/// Initializes OSTD.
///
/// This function represents the first phase booting up the system. It makes
/// all functionalities of OSTD available after the call.

View File

@ -10,8 +10,6 @@ pub type Result<T> = core::result::Result<T, crate::error::Error>;
pub(crate) use alloc::{boxed::Box, sync::Arc, vec::Vec};
pub(crate) use core::any::Any;
pub use aster_main::aster_main;
pub use crate::{
early_print as print, early_println as println,
mm::{Paddr, Vaddr},