2024-01-03 03:22:36 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2023-12-25 07:27:41 +00:00
|
|
|
//! The framework part of Asterinas.
|
2022-08-23 09:50:07 +00:00
|
|
|
#![feature(alloc_error_handler)]
|
2023-11-04 16:14:28 +00:00
|
|
|
#![feature(const_mut_refs)]
|
|
|
|
|
#![feature(const_ptr_sub_ptr)]
|
2023-03-09 05:26:54 +00:00
|
|
|
#![feature(const_trait_impl)]
|
2023-12-02 09:23:08 +00:00
|
|
|
#![feature(coroutines)]
|
2023-11-04 16:14:28 +00:00
|
|
|
#![feature(fn_traits)]
|
2023-12-02 09:23:08 +00:00
|
|
|
#![feature(iter_from_coroutine)]
|
2023-09-21 02:16:33 +00:00
|
|
|
#![feature(let_chains)]
|
2023-11-04 16:14:28 +00:00
|
|
|
#![feature(negative_impls)]
|
|
|
|
|
#![feature(new_uninit)]
|
|
|
|
|
#![feature(panic_info_message)]
|
2023-10-30 05:29:01 +00:00
|
|
|
#![feature(ptr_sub_ptr)]
|
2023-11-04 16:14:28 +00:00
|
|
|
#![feature(strict_provenance)]
|
2024-05-09 12:17:57 +00:00
|
|
|
#![feature(pointer_is_aligned)]
|
2023-11-04 16:14:28 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
#![allow(unused_variables)]
|
|
|
|
|
#![no_std]
|
2022-08-26 15:59:20 +00:00
|
|
|
|
2022-08-08 01:01:42 +00:00
|
|
|
extern crate alloc;
|
2024-02-21 08:58:40 +00:00
|
|
|
#[cfg(ktest)]
|
2023-10-08 09:40:58 +00:00
|
|
|
#[macro_use]
|
2023-11-04 08:41:30 +00:00
|
|
|
extern crate ktest;
|
|
|
|
|
#[macro_use]
|
2023-10-08 09:40:58 +00:00
|
|
|
extern crate static_assertions;
|
2022-08-08 01:01:42 +00:00
|
|
|
|
2023-03-25 09:27:09 +00:00
|
|
|
pub mod arch;
|
2023-07-25 04:22:03 +00:00
|
|
|
pub mod boot;
|
2023-07-05 13:35:07 +00:00
|
|
|
pub mod bus;
|
2024-04-08 06:26:36 +00:00
|
|
|
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;
|
2023-07-25 02:18:20 +00:00
|
|
|
pub mod logger;
|
2023-11-04 16:14:28 +00:00
|
|
|
pub mod panicking;
|
2022-08-08 01:01:42 +00:00
|
|
|
pub mod prelude;
|
2022-08-17 08:40:55 +00:00
|
|
|
pub mod sync;
|
2022-08-08 01:01:42 +00:00
|
|
|
pub mod task;
|
|
|
|
|
pub mod timer;
|
2022-11-02 11:35:39 +00:00
|
|
|
pub mod trap;
|
2022-08-08 01:01:42 +00:00
|
|
|
pub mod user;
|
|
|
|
|
pub mod vm;
|
|
|
|
|
|
2023-08-28 03:30:19 +00:00
|
|
|
#[cfg(feature = "intel_tdx")]
|
2023-09-10 11:23:53 +00:00
|
|
|
use tdx_guest::init_tdx;
|
2023-02-22 14:57:19 +00:00
|
|
|
|
2024-02-25 14:09:24 +00:00
|
|
|
pub use self::{cpu::CpuLocal, error::Error, prelude::Result};
|
|
|
|
|
|
2023-03-06 06:19:23 +00:00
|
|
|
pub fn init() {
|
2023-03-25 09:27:09 +00:00
|
|
|
arch::before_all_init();
|
2023-02-22 14:57:19 +00:00
|
|
|
logger::init();
|
2023-08-28 03:30:19 +00:00
|
|
|
#[cfg(feature = "intel_tdx")]
|
2023-09-10 11:23:53 +00:00
|
|
|
let td_info = init_tdx().unwrap();
|
2023-08-28 03:30:19 +00:00
|
|
|
#[cfg(feature = "intel_tdx")]
|
2023-11-08 06:54:00 +00:00
|
|
|
early_println!(
|
2023-08-28 03:30:19 +00:00
|
|
|
"td gpaw: {}, td attributes: {:?}\nTDX guest is initialized",
|
2023-11-08 06:53:16 +00:00
|
|
|
td_info.gpaw,
|
|
|
|
|
td_info.attributes
|
2023-08-28 03:30:19 +00:00
|
|
|
);
|
2023-07-25 04:22:03 +00:00
|
|
|
vm::heap_allocator::init();
|
|
|
|
|
boot::init();
|
2023-03-16 11:36:48 +00:00
|
|
|
vm::init();
|
2022-11-09 12:33:41 +00:00
|
|
|
trap::init();
|
2023-03-25 09:27:09 +00:00
|
|
|
arch::after_all_init();
|
2023-07-23 10:31:43 +00:00
|
|
|
bus::init();
|
2023-11-04 16:14:28 +00:00
|
|
|
invoke_ffi_init_funcs();
|
2022-09-05 06:41:15 +00:00
|
|
|
}
|
2023-02-27 08:18:04 +00:00
|
|
|
|
2023-11-04 16:14:28 +00:00
|
|
|
fn invoke_ffi_init_funcs() {
|
2023-02-27 08:18:04 +00:00
|
|
|
extern "C" {
|
2023-07-19 02:08:59 +00:00
|
|
|
fn __sinit_array();
|
|
|
|
|
fn __einit_array();
|
2023-02-27 08:18:04 +00:00
|
|
|
}
|
2023-09-04 03:04:42 +00:00
|
|
|
let call_len = (__einit_array as usize - __sinit_array as usize) / 8;
|
2023-02-27 08:18:04 +00:00
|
|
|
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();
|
2023-02-27 08:18:04 +00:00
|
|
|
(*function)();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 06:44:26 +00:00
|
|
|
/// Simple unit tests for the ktest framework.
|
2024-02-21 08:58:40 +00:00
|
|
|
#[cfg(ktest)]
|
2023-11-04 08:41:30 +00:00
|
|
|
mod test {
|
|
|
|
|
#[ktest]
|
|
|
|
|
fn trivial_assertion() {
|
|
|
|
|
assert_eq!(0, 0);
|
|
|
|
|
}
|
2023-11-04 16:14:28 +00:00
|
|
|
|
|
|
|
|
#[ktest]
|
|
|
|
|
#[should_panic]
|
|
|
|
|
fn failing_assertion() {
|
|
|
|
|
assert_eq!(0, 1);
|
|
|
|
|
}
|
2023-11-06 06:44:26 +00:00
|
|
|
|
|
|
|
|
#[ktest]
|
|
|
|
|
#[should_panic(expected = "expected panic message")]
|
|
|
|
|
fn expect_panic() {
|
|
|
|
|
panic!("expected panic message");
|
|
|
|
|
}
|
2023-11-04 08:41:30 +00:00
|
|
|
}
|