Rename aster_main as ostd::main
This commit is contained in:
parent
59350a8578
commit
fe7251c413
|
@ -128,15 +128,6 @@ dependencies = [
|
||||||
"spin 0.9.8",
|
"spin 0.9.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aster-main"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.49",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aster-network"
|
name = "aster-network"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -1101,7 +1092,6 @@ dependencies = [
|
||||||
"align_ext",
|
"align_ext",
|
||||||
"aml",
|
"aml",
|
||||||
"array-init",
|
"array-init",
|
||||||
"aster-main",
|
|
||||||
"bit_field",
|
"bit_field",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bitvec",
|
"bitvec",
|
||||||
|
@ -1121,6 +1111,7 @@ dependencies = [
|
||||||
"num",
|
"num",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"ostd-macros",
|
||||||
"pod",
|
"pod",
|
||||||
"rsdp",
|
"rsdp",
|
||||||
"spin 0.9.8",
|
"spin 0.9.8",
|
||||||
|
@ -1134,6 +1125,15 @@ dependencies = [
|
||||||
"xarray",
|
"xarray",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ostd-macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.49",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "owo-colors"
|
name = "owo-colors"
|
||||||
version = "3.5.0"
|
version = "3.5.0"
|
||||||
|
|
|
@ -3,7 +3,7 @@ resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"ostd",
|
"ostd",
|
||||||
"ostd/libs/align_ext",
|
"ostd/libs/align_ext",
|
||||||
"ostd/libs/aster-main",
|
"ostd/libs/ostd-macros",
|
||||||
"ostd/libs/id-alloc",
|
"ostd/libs/id-alloc",
|
||||||
"ostd/libs/linux-bzimage/builder",
|
"ostd/libs/linux-bzimage/builder",
|
||||||
"ostd/libs/linux-bzimage/boot-params",
|
"ostd/libs/linux-bzimage/boot-params",
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -86,7 +86,7 @@ export
|
||||||
# or tested without OSDK.
|
# or tested without OSDK.
|
||||||
NON_OSDK_CRATES := \
|
NON_OSDK_CRATES := \
|
||||||
ostd/libs/align_ext \
|
ostd/libs/align_ext \
|
||||||
ostd/libs/aster-main \
|
ostd/libs/ostd-macros \
|
||||||
ostd/libs/id-alloc \
|
ostd/libs/id-alloc \
|
||||||
ostd/libs/linux-bzimage/builder \
|
ostd/libs/linux-bzimage/builder \
|
||||||
ostd/libs/linux-bzimage/boot-params \
|
ostd/libs/linux-bzimage/boot-params \
|
||||||
|
|
|
@ -51,7 +51,7 @@ myos/
|
||||||
#### Kernel project
|
#### Kernel project
|
||||||
|
|
||||||
The `src/lib.rs` file contains the code for a simple kernel.
|
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.
|
is considered the kernel entry point by OSDK.
|
||||||
The kernel
|
The kernel
|
||||||
will print `Hello world from the guest kernel!`to the console
|
will print `Hello world from the guest kernel!`to the console
|
||||||
|
|
|
@ -40,7 +40,7 @@ and then hand over control to the kernel entry point
|
||||||
to execute the kernel code.
|
to execute the kernel code.
|
||||||
|
|
||||||
**Note**: Only kernel projects (the projects
|
**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;
|
can be run;
|
||||||
library projects cannot.
|
library projects cannot.
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ Here are some additional notes for the fields:
|
||||||
1. The type of current crate.
|
1. The type of current crate.
|
||||||
|
|
||||||
Optional. If not specified,
|
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`.
|
if the macro is used, the default value is `kernel`.
|
||||||
Otherwise, the default value is `library`.
|
Otherwise, the default value is `library`.
|
||||||
|
|
||||||
|
|
|
@ -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.
|
/// The kernel's boot and initialization process is managed by Asterinas OSTD.
|
||||||
/// After the process is done, the kernel's execution environment
|
/// After the process is done, the kernel's execution environment
|
||||||
/// (e.g., stack, heap, tasks) will be ready for use and the entry function
|
/// (e.g., stack, heap, tasks) will be ready for use and the entry function
|
||||||
/// labeled as `#[aster_main]` will be called.
|
/// labeled as `#[ostd::main]` will be called.
|
||||||
#[aster_main]
|
#[ostd::main]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let program_binary = include_bytes!("../hello_world");
|
let program_binary = include_bytes!("../hello_world");
|
||||||
let user_space = create_user_space(program_binary);
|
let user_space = create_user_space(program_binary);
|
||||||
|
|
|
@ -7,7 +7,7 @@ extern crate ostd;
|
||||||
|
|
||||||
use ostd::prelude::*;
|
use ostd::prelude::*;
|
||||||
|
|
||||||
#[aster_main]
|
#[ostd::main]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
println!("[kernel] finish init ostd");
|
println!("[kernel] finish init ostd");
|
||||||
component::init_all(component::parse_metadata!()).unwrap();
|
component::init_all(component::parse_metadata!()).unwrap();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use ostd::prelude::*;
|
use ostd::prelude::*;
|
||||||
|
|
||||||
#[aster_main]
|
#[ostd::main]
|
||||||
fn kernel_main() {
|
fn kernel_main() {
|
||||||
println!("Hello world from guest kernel!");
|
println!("Hello world from guest kernel!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ pub struct CrateInfo {
|
||||||
/// If there are multiple kernel crates or no kernel crates in the workspace,
|
/// If there are multiple kernel crates or no kernel crates in the workspace,
|
||||||
/// this function will exit with an error.
|
/// 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 {
|
fn get_default_member(metadata: &serde_json::Value) -> &str {
|
||||||
let default_members = metadata
|
let default_members = metadata
|
||||||
.get("workspace_default_members")
|
.get("workspace_default_members")
|
||||||
|
@ -127,7 +127,7 @@ fn get_default_member(metadata: &serde_json::Value) -> &str {
|
||||||
syn::parse_file(&content).unwrap()
|
syn::parse_file(&content).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
contains_aster_main_macro(&file)
|
contains_ostd_main_macro(&file)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
@ -145,7 +145,7 @@ fn get_default_member(metadata: &serde_json::Value) -> &str {
|
||||||
packages[0].get("id").unwrap().as_str().unwrap()
|
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 {
|
for item in &file.items {
|
||||||
let syn::Item::Fn(item_fn) = item else {
|
let syn::Item::Fn(item_fn) = item else {
|
||||||
continue;
|
continue;
|
||||||
|
@ -153,7 +153,7 @@ fn contains_aster_main_macro(file: &syn::File) -> bool {
|
||||||
|
|
||||||
for attr in &item_fn.attrs {
|
for attr in &item_fn.attrs {
|
||||||
let attr = format!("{}", attr.to_token_stream());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use ostd::prelude::*;
|
use ostd::prelude::*;
|
||||||
|
|
||||||
#[aster_main]
|
#[ostd::main]
|
||||||
fn kernel_main() {
|
fn kernel_main() {
|
||||||
let avail_mem_as_mb = mylib::available_memory() / 1_000_000;
|
let avail_mem_as_mb = mylib::available_memory() / 1_000_000;
|
||||||
println!("The available memory is {} MB", avail_mem_as_mb);
|
println!("The available memory is {} MB", avail_mem_as_mb);
|
||||||
|
|
|
@ -7,7 +7,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
align_ext = { path = "libs/align_ext" }
|
align_ext = { path = "libs/align_ext" }
|
||||||
aster-main = { path = "libs/aster-main" }
|
ostd-macros = { path = "libs/ostd-macros" }
|
||||||
bit_field = "0.10.1"
|
bit_field = "0.10.1"
|
||||||
bitflags = "1.3"
|
bitflags = "1.3"
|
||||||
bitvec = { version = "1.0", default-features = false, features = ["alloc"] }
|
bitvec = { version = "1.0", default-features = false, features = ["alloc"] }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "aster-main"
|
name = "ostd-macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
|
@ -4,15 +4,26 @@ use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, ItemFn};
|
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]
|
#[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 = parse_macro_input!(item as ItemFn);
|
||||||
let main_fn_name = &main_fn.sig.ident;
|
let main_fn_name = &main_fn.sig.ident;
|
||||||
|
|
||||||
quote!(
|
quote!(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn __aster_main() -> ! {
|
pub fn __ostd_main() -> ! {
|
||||||
ostd::init();
|
ostd::init();
|
||||||
#main_fn_name();
|
#main_fn_name();
|
||||||
ostd::prelude::abort();
|
ostd::prelude::abort();
|
|
@ -160,5 +160,5 @@ unsafe extern "sysv64" fn __linux_boot(params_ptr: *const BootParams) -> ! {
|
||||||
init_framebuffer_info,
|
init_framebuffer_info,
|
||||||
init_memory_regions,
|
init_memory_regions,
|
||||||
);
|
);
|
||||||
crate::boot::call_aster_main();
|
crate::boot::call_ostd_main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,5 +404,5 @@ unsafe extern "sysv64" fn __multiboot_entry(boot_magic: u32, boot_params: u64) -
|
||||||
init_framebuffer_info,
|
init_framebuffer_info,
|
||||||
init_memory_regions,
|
init_memory_regions,
|
||||||
);
|
);
|
||||||
crate::boot::call_aster_main();
|
crate::boot::call_ostd_main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,5 +167,5 @@ unsafe extern "sysv64" fn __multiboot2_entry(boot_magic: u32, boot_params: u64)
|
||||||
init_framebuffer_info,
|
init_framebuffer_info,
|
||||||
init_memory_regions,
|
init_memory_regions,
|
||||||
);
|
);
|
||||||
crate::boot::call_aster_main();
|
crate::boot::call_ostd_main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
/// 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
|
/// 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,
|
/// reference of the global static boot information variable and initialize it,
|
||||||
/// so that the boot information it represents could be accessed in the kernel
|
/// so that the boot information it represents could be accessed in the kernel
|
||||||
/// anywhere.
|
/// anywhere.
|
||||||
|
@ -110,17 +110,17 @@ pub fn init() {
|
||||||
|
|
||||||
/// Calls the OSTD-user defined entrypoint of the actual kernel.
|
/// Calls the OSTD-user defined entrypoint of the actual kernel.
|
||||||
///
|
///
|
||||||
/// Any kernel that uses the `ostd` crate should define a function named
|
/// Any kernel that uses the `ostd` crate should define a function marked with
|
||||||
/// `aster_main` as the entrypoint.
|
/// `ostd::main` as the entrypoint.
|
||||||
pub fn call_aster_main() -> ! {
|
pub fn call_ostd_main() -> ! {
|
||||||
#[cfg(not(ktest))]
|
#[cfg(not(ktest))]
|
||||||
unsafe {
|
unsafe {
|
||||||
// The entry point of kernel code, which should be defined by the package that
|
// The entry point of kernel code, which should be defined by the package that
|
||||||
// uses OSTD.
|
// uses OSTD.
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
fn __aster_main() -> !;
|
fn __ostd_main() -> !;
|
||||||
}
|
}
|
||||||
__aster_main();
|
__ostd_main();
|
||||||
}
|
}
|
||||||
#[cfg(ktest)]
|
#[cfg(ktest)]
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -44,12 +44,13 @@ pub mod task;
|
||||||
pub mod trap;
|
pub mod trap;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
|
pub use ostd_macros::main;
|
||||||
#[cfg(feature = "intel_tdx")]
|
#[cfg(feature = "intel_tdx")]
|
||||||
use tdx_guest::init_tdx;
|
use tdx_guest::init_tdx;
|
||||||
|
|
||||||
pub use self::{cpu::CpuLocal, error::Error, prelude::Result};
|
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
|
/// This function represents the first phase booting up the system. It makes
|
||||||
/// all functionalities of OSTD available after the call.
|
/// all functionalities of OSTD available after the call.
|
||||||
|
|
|
@ -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 alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||||
pub(crate) use core::any::Any;
|
pub(crate) use core::any::Any;
|
||||||
|
|
||||||
pub use aster_main::aster_main;
|
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
early_print as print, early_println as println,
|
early_print as print, early_println as println,
|
||||||
mm::{Paddr, Vaddr},
|
mm::{Paddr, Vaddr},
|
||||||
|
|
Loading…
Reference in New Issue