asterinas/framework/aster-frame/src/lib.rs

122 lines
2.7 KiB
Rust
Raw Normal View History

2024-01-03 03:22:36 +00:00
// SPDX-License-Identifier: MPL-2.0
//! The framework part of Asterinas.
2022-08-23 09:50:07 +00:00
#![feature(alloc_error_handler)]
#![feature(const_mut_refs)]
#![feature(const_ptr_sub_ptr)]
#![feature(const_trait_impl)]
2023-12-02 09:23:08 +00:00
#![feature(coroutines)]
#![feature(fn_traits)]
#![feature(generic_const_exprs)]
2023-12-02 09:23:08 +00:00
#![feature(iter_from_coroutine)]
2023-09-21 02:16:33 +00:00
#![feature(let_chains)]
#![feature(negative_impls)]
#![feature(new_uninit)]
#![feature(panic_info_message)]
2023-10-30 05:29:01 +00:00
#![feature(ptr_sub_ptr)]
#![feature(strict_provenance)]
#![feature(pointer_is_aligned)]
#![allow(dead_code)]
#![allow(unused_variables)]
// The `generic_const_exprs` feature is incomplete however required for the page table
// const generic implementation. We are using this feature in a conservative manner.
#![allow(incomplete_features)]
#![no_std]
2022-08-26 15:59:20 +00:00
2022-08-08 01:01:42 +00:00
extern crate alloc;
#[cfg(ktest)]
2023-10-08 09:40:58 +00:00
#[macro_use]
2023-11-04 08:41:30 +00:00
extern crate ktest;
2023-10-08 09:40:58 +00:00
extern crate static_assertions;
2022-08-08 01:01:42 +00:00
pub mod arch;
pub mod boot;
2023-07-05 13:35:07 +00:00
pub mod bus;
pub mod collections;
2023-09-08 03:54:01 +00:00
pub mod console;
2022-08-08 01:01:42 +00:00
pub mod cpu;
mod error;
2023-07-23 10:40:41 +00:00
pub mod io_mem;
pub mod logger;
pub mod mm;
pub mod panicking;
2022-08-08 01:01:42 +00:00
pub mod prelude;
pub mod sync;
2022-08-08 01:01:42 +00:00
pub mod task;
2022-11-02 11:35:39 +00:00
pub mod trap;
2022-08-08 01:01:42 +00:00
pub mod user;
#[cfg(feature = "intel_tdx")]
use tdx_guest::init_tdx;
2023-02-22 14:57:19 +00:00
pub use self::{cpu::CpuLocal, error::Error, prelude::Result};
2023-03-06 06:19:23 +00:00
pub fn init() {
arch::before_all_init();
2023-02-22 14:57:19 +00:00
logger::init();
#[cfg(feature = "intel_tdx")]
let td_info = init_tdx().unwrap();
#[cfg(feature = "intel_tdx")]
early_println!(
"td gpaw: {}, td attributes: {:?}\nTDX guest is initialized",
2023-11-08 06:53:16 +00:00
td_info.gpaw,
td_info.attributes
);
mm::heap_allocator::init();
boot::init();
mm::page::allocator::init();
let mut boot_pt = mm::get_boot_pt();
let meta_pages = mm::init_page_meta(&mut boot_pt);
mm::misc_init();
2022-11-09 12:33:41 +00:00
trap::init();
arch::after_all_init();
2023-07-23 10:31:43 +00:00
bus::init();
mm::kspace::init_kernel_page_table(boot_pt, meta_pages);
invoke_ffi_init_funcs();
2022-09-05 06:41:15 +00:00
}
/// Invoke the initialization functions defined in the FFI.
/// The component system uses this function to call the initialization functions of
/// the components.
fn invoke_ffi_init_funcs() {
extern "C" {
fn __sinit_array();
fn __einit_array();
}
2023-09-04 03:04:42 +00:00
let call_len = (__einit_array as usize - __sinit_array as usize) / 8;
for i in 0..call_len {
unsafe {
2023-09-04 03:04:42 +00:00
let function = (__sinit_array as usize + 8 * i) as *const fn();
(*function)();
}
}
}
/// Simple unit tests for the ktest framework.
#[cfg(ktest)]
2023-11-04 08:41:30 +00:00
mod test {
#[ktest]
fn trivial_assertion() {
assert_eq!(0, 0);
}
#[ktest]
#[should_panic]
fn failing_assertion() {
assert_eq!(0, 1);
}
#[ktest]
#[should_panic(expected = "expected panic message")]
fn expect_panic() {
panic!("expected panic message");
}
2023-11-04 08:41:30 +00:00
}