mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 13:26:48 +00:00
Use TDVMCALL serial output in the early stages of kernel initialization
This commit is contained in:
parent
49e6cd2712
commit
b6cf27507c
@ -27,10 +27,7 @@ cfg_if! {
|
|||||||
if #[cfg(feature = "cvm_guest")] {
|
if #[cfg(feature = "cvm_guest")] {
|
||||||
pub(crate) mod tdx_guest;
|
pub(crate) mod tdx_guest;
|
||||||
|
|
||||||
use {
|
use ::tdx_guest::{init_tdx, tdcall::InitError};
|
||||||
crate::early_println,
|
|
||||||
::tdx_guest::{init_tdx, tdcall::InitError},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,9 +41,11 @@ use log::{info, warn};
|
|||||||
|
|
||||||
#[cfg(feature = "cvm_guest")]
|
#[cfg(feature = "cvm_guest")]
|
||||||
pub(crate) fn init_cvm_guest() {
|
pub(crate) fn init_cvm_guest() {
|
||||||
|
use ::tdx_guest::serial_println;
|
||||||
|
|
||||||
match init_tdx() {
|
match init_tdx() {
|
||||||
Ok(td_info) => {
|
Ok(td_info) => {
|
||||||
early_println!(
|
serial_println!(
|
||||||
"[kernel] Intel TDX initialized\n[kernel] td gpaw: {}, td attributes: {:?}",
|
"[kernel] Intel TDX initialized\n[kernel] td gpaw: {}, td attributes: {:?}",
|
||||||
td_info.gpaw,
|
td_info.gpaw,
|
||||||
td_info.attributes
|
td_info.attributes
|
||||||
|
@ -77,7 +77,10 @@ unsafe fn init() {
|
|||||||
mm::frame::allocator::init_early_allocator();
|
mm::frame::allocator::init_early_allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if_tdx_enabled!({
|
||||||
|
} else {
|
||||||
arch::serial::init();
|
arch::serial::init();
|
||||||
|
});
|
||||||
|
|
||||||
logger::init();
|
logger::init();
|
||||||
|
|
||||||
@ -106,6 +109,10 @@ unsafe fn init() {
|
|||||||
|
|
||||||
unsafe { arch::late_init_on_bsp() };
|
unsafe { arch::late_init_on_bsp() };
|
||||||
|
|
||||||
|
if_tdx_enabled!({
|
||||||
|
arch::serial::init();
|
||||||
|
});
|
||||||
|
|
||||||
smp::init();
|
smp::init();
|
||||||
|
|
||||||
// SAFETY: This function is called only once on the BSP.
|
// SAFETY: This function is called only once on the BSP.
|
||||||
|
@ -10,7 +10,7 @@ use super::{meta::AnyFrameMeta, segment::Segment, Frame};
|
|||||||
use crate::{
|
use crate::{
|
||||||
boot::memory_region::MemoryRegionType,
|
boot::memory_region::MemoryRegionType,
|
||||||
error::Error,
|
error::Error,
|
||||||
impl_frame_meta_for,
|
if_tdx_enabled, impl_frame_meta_for,
|
||||||
mm::{paddr_to_vaddr, Paddr, PAGE_SIZE},
|
mm::{paddr_to_vaddr, Paddr, PAGE_SIZE},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
util::range_difference,
|
util::range_difference,
|
||||||
@ -212,7 +212,13 @@ pub(crate) unsafe fn init() {
|
|||||||
// Truncate the early allocated frames if there is an overlap.
|
// Truncate the early allocated frames if there is an overlap.
|
||||||
for r1 in range_difference(&(region.base()..region.end()), &range_1) {
|
for r1 in range_difference(&(region.base()..region.end()), &range_1) {
|
||||||
for r2 in range_difference(&r1, &range_2) {
|
for r2 in range_difference(&r1, &range_2) {
|
||||||
|
if_tdx_enabled!({
|
||||||
|
use tdx_guest::serial_println;
|
||||||
|
|
||||||
|
serial_println!("Adding free frames to the allocator: {:x?}", r2);
|
||||||
|
} else {
|
||||||
log::info!("Adding free frames to the allocator: {:x?}", r2);
|
log::info!("Adding free frames to the allocator: {:x?}", r2);
|
||||||
|
});
|
||||||
get_global_frame_allocator().add_free_memory(r2.start, r2.len());
|
get_global_frame_allocator().add_free_memory(r2.start, r2.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ use log::info;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::mm::PagingConsts,
|
arch::mm::PagingConsts,
|
||||||
const_assert,
|
const_assert, if_tdx_enabled,
|
||||||
mm::{
|
mm::{
|
||||||
frame::allocator::{self, EarlyAllocatedFrameMeta},
|
frame::allocator::{self, EarlyAllocatedFrameMeta},
|
||||||
kspace::LINEAR_MAPPING_BASE_VADDR,
|
kspace::LINEAR_MAPPING_BASE_VADDR,
|
||||||
@ -447,10 +447,15 @@ pub(crate) unsafe fn init() -> Segment<MetaPageMeta> {
|
|||||||
regions.iter().map(|r| r.base() + r.len()).max().unwrap()
|
regions.iter().map(|r| r.base() + r.len()).max().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
info!(
|
if_tdx_enabled!({
|
||||||
"Initializing frame metadata for physical memory up to {:x}",
|
use tdx_guest::serial_println;
|
||||||
max_paddr
|
|
||||||
);
|
serial_println!("Initializing frame metadata for physical memory up to {:x}",
|
||||||
|
max_paddr)
|
||||||
|
} else {
|
||||||
|
info!("Initializing frame metadata for physical memory up to {:x}",
|
||||||
|
max_paddr);
|
||||||
|
});
|
||||||
|
|
||||||
add_temp_linear_mapping(max_paddr);
|
add_temp_linear_mapping(max_paddr);
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ use super::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
arch::mm::{PageTableEntry, PagingConsts},
|
arch::mm::{PageTableEntry, PagingConsts},
|
||||||
boot::memory_region::MemoryRegionType,
|
boot::memory_region::MemoryRegionType,
|
||||||
|
if_tdx_enabled,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The shortest supported address width is 39 bits. And the literal
|
/// The shortest supported address width is 39 bits. And the literal
|
||||||
@ -132,7 +133,13 @@ pub static KERNEL_PAGE_TABLE: Once<PageTable<KernelMode, PageTableEntry, PagingC
|
|||||||
/// This function should be called before:
|
/// This function should be called before:
|
||||||
/// - any initializer that modifies the kernel page table.
|
/// - any initializer that modifies the kernel page table.
|
||||||
pub fn init_kernel_page_table(meta_pages: Segment<MetaPageMeta>) {
|
pub fn init_kernel_page_table(meta_pages: Segment<MetaPageMeta>) {
|
||||||
|
if_tdx_enabled!({
|
||||||
|
use tdx_guest::serial_println;
|
||||||
|
|
||||||
|
serial_println!("Initializing the kernel page table");
|
||||||
|
} else {
|
||||||
info!("Initializing the kernel page table");
|
info!("Initializing the kernel page table");
|
||||||
|
});
|
||||||
|
|
||||||
let regions = &crate::boot::EARLY_INFO.get().unwrap().memory_regions;
|
let regions = &crate::boot::EARLY_INFO.get().unwrap().memory_regions;
|
||||||
let phys_mem_cap = regions.iter().map(|r| r.base() + r.len()).max().unwrap();
|
let phys_mem_cap = regions.iter().map(|r| r.base() + r.len()).max().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user