Adjust the format of imports in Asterinas

This commit is contained in:
Chen Chengjun
2024-02-25 22:09:24 +08:00
committed by Tate, Hongliang Tian
parent 92e488e727
commit cfcef6965a
384 changed files with 2264 additions and 2059 deletions

View File

@ -3,20 +3,22 @@
//! The Linux 64-bit Boot Protocol supporting module. //! The Linux 64-bit Boot Protocol supporting module.
//! //!
use linux_boot_params::{BootParams, E820Type, LINUX_BOOT_HEADER_MAGIC};
use crate::boot::{
kcmdline::KCmdlineArg,
memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType},
BootloaderAcpiArg, BootloaderFramebufferArg,
};
use crate::{config::PHYS_OFFSET, vm::paddr_to_vaddr};
use alloc::{borrow::ToOwned, format, string::String, vec::Vec}; use alloc::{borrow::ToOwned, format, string::String, vec::Vec};
use core::ffi::CStr; use core::ffi::CStr;
use linux_boot_params::{BootParams, E820Type, LINUX_BOOT_HEADER_MAGIC};
use spin::Once; use spin::Once;
use crate::{
boot::{
kcmdline::KCmdlineArg,
memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType},
BootloaderAcpiArg, BootloaderFramebufferArg,
},
config::PHYS_OFFSET,
vm::paddr_to_vaddr,
};
static BOOT_PARAMS: Once<BootParams> = Once::new(); static BOOT_PARAMS: Once<BootParams> = Once::new();
fn init_bootloader_name(bootloader_name: &'static Once<String>) { fn init_bootloader_name(bootloader_name: &'static Once<String>) {

View File

@ -1,6 +1,8 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::{string::String, vec::Vec}; use alloc::{string::String, vec::Vec};
use core::arch::global_asm;
use multiboot2::MemoryAreaType; use multiboot2::MemoryAreaType;
use spin::Once; use spin::Once;
@ -14,8 +16,6 @@ use crate::{
vm::paddr_to_vaddr, vm::paddr_to_vaddr,
}; };
use core::arch::global_asm;
global_asm!(include_str!("header.S")); global_asm!(include_str!("header.S"));
pub(super) const MULTIBOOT_ENTRY_MAGIC: u32 = 0x2BADB002; pub(super) const MULTIBOOT_ENTRY_MAGIC: u32 = 0x2BADB002;

View File

@ -4,16 +4,16 @@ use alloc::{
string::{String, ToString}, string::{String, ToString},
vec::Vec, vec::Vec,
}; };
use core::arch::global_asm;
use multiboot2::{BootInformation, BootInformationHeader, MemoryAreaType}; use multiboot2::{BootInformation, BootInformationHeader, MemoryAreaType};
use spin::Once;
use crate::boot::{ use crate::boot::{
kcmdline::KCmdlineArg, kcmdline::KCmdlineArg,
memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType}, memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType},
BootloaderAcpiArg, BootloaderFramebufferArg, BootloaderAcpiArg, BootloaderFramebufferArg,
}; };
use spin::Once;
use core::arch::global_asm;
global_asm!(include_str!("header.S")); global_asm!(include_str!("header.S"));

View File

@ -1,17 +1,14 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::{fmt, sync::Arc, vec::Vec};
use core::fmt::Write; use core::fmt::Write;
use crate::sync::SpinLock;
use crate::trap::IrqLine;
use alloc::fmt;
use alloc::{sync::Arc, vec::Vec};
use log::debug; use log::debug;
use spin::Once; use spin::Once;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use super::device::serial::SerialPort; use super::{device::serial::SerialPort, kernel::IO_APIC};
use super::kernel::IO_APIC; use crate::{sync::SpinLock, trap::IrqLine};
#[inline] #[inline]
pub fn print(args: fmt::Arguments) { pub fn print(args: fmt::Arguments) {

View File

@ -2,23 +2,28 @@
//! CPU. //! CPU.
use core::arch::x86_64::{_fxrstor, _fxsave};
use core::fmt::Debug;
use alloc::vec::Vec; use alloc::vec::Vec;
use bitvec::{prelude::Lsb0, slice::IterOnes}; use core::{
use trapframe::{GeneralRegs, UserContext as RawUserContext}; arch::x86_64::{_fxrstor, _fxsave},
fmt::Debug,
};
#[cfg(feature = "intel_tdx")] use bitvec::{
use crate::arch::tdx_guest::{handle_virtual_exception, TdxTrapFrame}; prelude::{BitVec, Lsb0},
use bitvec::prelude::BitVec; slice::IterOnes,
};
use log::debug; use log::debug;
#[cfg(feature = "intel_tdx")] #[cfg(feature = "intel_tdx")]
use tdx_guest::tdcall; use tdx_guest::tdcall;
use trapframe::{GeneralRegs, UserContext as RawUserContext};
use x86_64::registers::rflags::RFlags; use x86_64::registers::rflags::RFlags;
use crate::trap::call_irq_callback_functions; #[cfg(feature = "intel_tdx")]
use crate::user::{UserContextApi, UserContextApiInternal, UserEvent}; use crate::arch::tdx_guest::{handle_virtual_exception, TdxTrapFrame};
use crate::{
trap::call_irq_callback_functions,
user::{UserContextApi, UserContextApiInternal, UserEvent},
};
/// Returns the number of CPUs. /// Returns the number of CPUs.
pub fn num_cpus() -> u32 { pub fn num_cpus() -> u32 {

View File

@ -3,9 +3,8 @@
use acpi::{fadt::Fadt, sdt::Signature}; use acpi::{fadt::Fadt, sdt::Signature};
use x86_64::instructions::port::{ReadOnlyAccess, WriteOnlyAccess}; use x86_64::instructions::port::{ReadOnlyAccess, WriteOnlyAccess};
use crate::arch::x86::kernel::acpi::ACPI_TABLES;
use super::io_port::IoPort; use super::io_port::IoPort;
use crate::arch::x86::kernel::acpi::ACPI_TABLES;
pub static CMOS_ADDRESS: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0x70) }; pub static CMOS_ADDRESS: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0x70) };
pub static CMOS_DATA: IoPort<u8, ReadOnlyAccess> = unsafe { IoPort::new(0x71) }; pub static CMOS_DATA: IoPort<u8, ReadOnlyAccess> = unsafe { IoPort::new(0x71) };

View File

@ -2,11 +2,13 @@
use core::marker::PhantomData; use core::marker::PhantomData;
pub use x86_64::instructions::port::{ pub use x86_64::{
PortReadAccess as IoPortReadAccess, PortWriteAccess as IoPortWriteAccess, ReadOnlyAccess, instructions::port::{
ReadWriteAccess, WriteOnlyAccess, PortReadAccess as IoPortReadAccess, PortWriteAccess as IoPortWriteAccess, ReadOnlyAccess,
ReadWriteAccess, WriteOnlyAccess,
},
structures::port::{PortRead, PortWrite},
}; };
pub use x86_64::structures::port::{PortRead, PortWrite};
/// An I/O port, representing a specific address in the I/O address of x86. /// An I/O port, representing a specific address in the I/O address of x86.
/// ///

View File

@ -1,11 +1,12 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::collections::BTreeMap;
use core::mem::size_of; use core::mem::size_of;
use alloc::collections::BTreeMap;
use log::warn; use log::warn;
use pod::Pod; use pod::Pod;
use super::second_stage::{PageTableEntry, PageTableFlags};
use crate::{ use crate::{
bus::pci::PciDeviceLocation, bus::pci::PciDeviceLocation,
vm::{ vm::{
@ -15,8 +16,6 @@ use crate::{
}, },
}; };
use super::second_stage::{PageTableEntry, PageTableFlags};
/// Bit 0 is `Present` bit, indicating whether this entry is present. /// Bit 0 is `Present` bit, indicating whether this entry is present.
/// Bit 63:12 is the context-table pointer pointing to this bus's context-table. /// Bit 63:12 is the context-table pointer pointing to this bus's context-table.
#[derive(Pod, Clone, Copy)] #[derive(Pod, Clone, Copy)]

View File

@ -1,17 +1,16 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::vec::Vec;
use core::fmt::Debug; use core::fmt::Debug;
use alloc::vec::Vec;
use bitflags::bitflags; use bitflags::bitflags;
use log::info; use log::info;
use spin::Once; use spin::Once;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use volatile::{access::ReadWrite, Volatile}; use volatile::{access::ReadWrite, Volatile};
use crate::{trap::IrqLine, vm::Vaddr};
use super::remapping::Capability; use super::remapping::Capability;
use crate::{trap::IrqLine, vm::Vaddr};
#[derive(Debug)] #[derive(Debug)]
pub struct FaultEventRegisters { pub struct FaultEventRegisters {

View File

@ -8,6 +8,7 @@ use volatile::{
Volatile, Volatile,
}; };
use super::{context_table::RootTable, IommuError};
use crate::{ use crate::{
arch::{ arch::{
iommu::fault, iommu::fault,
@ -19,8 +20,6 @@ use crate::{
vm::paddr_to_vaddr, vm::paddr_to_vaddr,
}; };
use super::{context_table::RootTable, IommuError};
#[derive(Debug)] #[derive(Debug)]
pub struct RemappingRegisters { pub struct RemappingRegisters {
version: Volatile<&'static u32, ReadOnly>, version: Volatile<&'static u32, ReadOnly>,

View File

@ -1,12 +1,12 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::sync::Mutex;
use alloc::{boxed::Box, fmt::Debug, sync::Arc, vec::Vec}; use alloc::{boxed::Box, fmt::Debug, sync::Arc, vec::Vec};
use spin::Once; use spin::Once;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use crate::{ use crate::{
sync::{SpinLock, SpinLockGuard}, sync::{Mutex, SpinLock, SpinLockGuard},
util::recycle_allocator::RecycleAllocator, util::recycle_allocator::RecycleAllocator,
}; };

View File

@ -1,16 +1,15 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::vec::Vec;
use core::{fmt::Debug, mem::size_of, slice::Iter}; use core::{fmt::Debug, mem::size_of, slice::Iter};
use acpi::{sdt::Signature, AcpiTable}; use acpi::{sdt::Signature, AcpiTable};
use alloc::vec::Vec;
use crate::vm::paddr_to_vaddr;
use super::{ use super::{
remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp}, remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp},
SdtHeaderWrapper, SdtHeaderWrapper,
}; };
use crate::vm::paddr_to_vaddr;
/// DMA Remapping structure. When IOMMU is enabled, the structure should be present in the ACPI table, /// DMA Remapping structure. When IOMMU is enabled, the structure should be present in the ACPI table,
/// and the user can use the DRHD table in this structure to obtain the register base addresses used to configure functions such as IOMMU. /// and the user can use the DRHD table in this structure to obtain the register base addresses used to configure functions such as IOMMU.

View File

@ -3,20 +3,21 @@
pub mod dmar; pub mod dmar;
pub mod remapping; pub mod remapping;
use alloc::borrow::ToOwned;
use core::{ use core::{
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
ptr::NonNull, ptr::NonNull,
}; };
use crate::vm::paddr_to_vaddr; use acpi::{sdt::SdtHeader, AcpiHandler, AcpiTable, AcpiTables};
use log::{info, warn};
use spin::Once;
use crate::{ use crate::{
boot::{self, BootloaderAcpiArg}, boot::{self, BootloaderAcpiArg},
sync::SpinLock, sync::SpinLock,
vm::paddr_to_vaddr,
}; };
use acpi::{sdt::SdtHeader, AcpiHandler, AcpiTable, AcpiTables};
use alloc::borrow::ToOwned;
use log::{info, warn};
use spin::Once;
/// RSDP information, key is the signature, value is the virtual address of the signature /// RSDP information, key is the signature, value is the virtual address of the signature
pub static ACPI_TABLES: Once<SpinLock<AcpiTables<AcpiMemoryHandler>>> = Once::new(); pub static ACPI_TABLES: Once<SpinLock<AcpiTables<AcpiMemoryHandler>>> = Once::new();

View File

@ -4,9 +4,8 @@
//! This file defines these structures and provides a "Debug" implementation to see the value inside these structures. //! This file defines these structures and provides a "Debug" implementation to see the value inside these structures.
//! Most of the introduction are copied from Intel vt-directed-io-specification. //! Most of the introduction are copied from Intel vt-directed-io-specification.
use core::{fmt::Debug, mem::size_of};
use alloc::{string::String, vec::Vec}; use alloc::{string::String, vec::Vec};
use core::{fmt::Debug, mem::size_of};
/// DMA-remapping hardware unit definition (DRHD). /// DMA-remapping hardware unit definition (DRHD).
/// ///

View File

@ -1,8 +1,8 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::{vec, vec::Vec};
use acpi::PlatformInfo; use acpi::PlatformInfo;
use alloc::vec;
use alloc::vec::Vec;
use bit_field::BitField; use bit_field::BitField;
use log::info; use log::info;
use spin::Once; use spin::Once;

View File

@ -1,11 +1,12 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::sync::Mutex; use alloc::{boxed::Box, sync::Arc};
use alloc::boxed::Box;
use alloc::sync::Arc;
use log::info; use log::info;
use spin::Once; use spin::Once;
use crate::sync::Mutex;
pub mod ioapic; pub mod ioapic;
pub mod x2apic; pub mod x2apic;
pub mod xapic; pub mod xapic;

View File

@ -1,11 +1,10 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::sync::Mutex;
use crate::vm;
use spin::Once; use spin::Once;
use x86::apic::xapic; use x86::apic::xapic;
use super::ApicTimer; use super::ApicTimer;
use crate::{sync::Mutex, vm};
const IA32_APIC_BASE_MSR: u32 = 0x1B; const IA32_APIC_BASE_MSR: u32 = 0x1B;
const IA32_APIC_BASE_MSR_BSP: u32 = 0x100; // Processor is a BSP const IA32_APIC_BASE_MSR_BSP: u32 = 0x100; // Processor is a BSP

View File

@ -1,12 +1,14 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::arch::x86::device::io_port::{IoPort, WriteOnlyAccess}; use core::sync::atomic::{AtomicBool, AtomicU8, Ordering::Relaxed};
use crate::trap::IrqLine;
use core::sync::atomic::Ordering::Relaxed;
use core::sync::atomic::{AtomicBool, AtomicU8};
use log::info; use log::info;
use crate::{
arch::x86::device::io_port::{IoPort, WriteOnlyAccess},
trap::IrqLine,
};
static MASTER_CMD: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0x20) }; static MASTER_CMD: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0x20) };
static MASTER_DATA: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0x21) }; static MASTER_DATA: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0x21) };
static SLAVE_CMD: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0xA0) }; static SLAVE_CMD: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0xA0) };

View File

@ -4,6 +4,7 @@ use core::{
arch::x86_64::_rdtsc, arch::x86_64::_rdtsc,
sync::atomic::{AtomicBool, AtomicU64, Ordering}, sync::atomic::{AtomicBool, AtomicU64, Ordering},
}; };
use log::info; use log::info;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use x86::cpuid::cpuid; use x86::cpuid::cpuid;

View File

@ -1,12 +1,13 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::sync::Mutex;
use alloc::{collections::BTreeMap, fmt}; use alloc::{collections::BTreeMap, fmt};
use pod::Pod; use pod::Pod;
use x86_64::{instructions::tlb, structures::paging::PhysFrame, VirtAddr}; use x86_64::{instructions::tlb, structures::paging::PhysFrame, VirtAddr};
use crate::{ use crate::{
config::ENTRY_COUNT, config::ENTRY_COUNT,
sync::Mutex,
vm::{ vm::{
page_table::{table_of, PageTableEntryTrait, PageTableFlagsTrait}, page_table::{table_of, PageTableEntryTrait, PageTableFlagsTrait},
Paddr, Vaddr, Paddr, Vaddr,

View File

@ -1,9 +1,11 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use tdx_guest::{ use tdx_guest::{
serial_println, tdcall,
tdcall::TdgVeInfo, tdcall::TdgVeInfo,
tdvmcall,
tdvmcall::{cpuid, hlt, rdmsr, wrmsr, IoSize}, tdvmcall::{cpuid, hlt, rdmsr, wrmsr, IoSize},
{serial_println, tdcall, tdvmcall, TdxVirtualExceptionType}, TdxVirtualExceptionType,
}; };
pub trait TdxTrapFrame { pub trait TdxTrapFrame {

View File

@ -1,22 +1,31 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::sync::Arc; use alloc::sync::Arc;
use core::arch::x86_64::_rdtsc; use core::{
use core::sync::atomic::{AtomicBool, AtomicU64, Ordering}; arch::x86_64::_rdtsc,
use x86::cpuid::cpuid; sync::atomic::{AtomicBool, AtomicU64, Ordering},
};
use log::info; use log::info;
use spin::Once; use spin::Once;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use x86::msr::{wrmsr, IA32_TSC_DEADLINE}; use x86::{
cpuid::cpuid,
use crate::arch::kernel::tsc::init_tsc_freq; msr::{wrmsr, IA32_TSC_DEADLINE},
use crate::arch::timer::pit::OperatingMode; };
use crate::arch::x86::kernel::apic::{DivideConfig, APIC_INSTANCE};
use crate::arch::x86::kernel::tsc::TSC_FREQ;
use crate::trap::IrqLine;
use super::TIMER_FREQ; use super::TIMER_FREQ;
use crate::{
arch::{
kernel::tsc::init_tsc_freq,
timer::pit::OperatingMode,
x86::kernel::{
apic::{DivideConfig, APIC_INSTANCE},
tsc::TSC_FREQ,
},
},
trap::IrqLine,
};
pub fn init() { pub fn init() {
init_tsc_freq(); init_tsc_freq();

View File

@ -1,15 +1,19 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::{trap::IrqLine, vm::paddr_to_vaddr};
use acpi::{AcpiError, HpetInfo};
use alloc::vec::Vec; use alloc::vec::Vec;
use acpi::{AcpiError, HpetInfo};
use spin::Once; use spin::Once;
use volatile::{ use volatile::{
access::{ReadOnly, ReadWrite}, access::{ReadOnly, ReadWrite},
Volatile, Volatile,
}; };
use crate::arch::x86::kernel::{acpi::ACPI_TABLES, apic::ioapic}; use crate::{
arch::x86::kernel::{acpi::ACPI_TABLES, apic::ioapic},
trap::IrqLine,
vm::paddr_to_vaddr,
};
static HPET_INSTANCE: Once<Hpet> = Once::new(); static HPET_INSTANCE: Once<Hpet> = Once::new();
const OFFSET_ID_REGISTER: usize = 0x000; const OFFSET_ID_REGISTER: usize = 0x000;

View File

@ -4,18 +4,17 @@ pub mod apic;
pub mod hpet; pub mod hpet;
pub mod pit; pub mod pit;
use core::any::Any;
use core::sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering};
use alloc::{boxed::Box, collections::BinaryHeap, sync::Arc, vec::Vec}; use alloc::{boxed::Box, collections::BinaryHeap, sync::Arc, vec::Vec};
use core::{
any::Any,
sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering},
};
use spin::Once; use spin::Once;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use crate::arch::x86::kernel;
use crate::sync::SpinLock;
use crate::trap::IrqLine;
use self::apic::APIC_TIMER_CALLBACK; use self::apic::APIC_TIMER_CALLBACK;
use crate::{arch::x86::kernel, sync::SpinLock, trap::IrqLine};
/// The timer frequency (Hz). Here we choose 1000Hz since 1000Hz is easier for unit conversion and /// The timer frequency (Hz). Here we choose 1000Hz since 1000Hz is easier for unit conversion and
/// convenient for timer. What's more, the frequency cannot be set too high or too low, 1000Hz is /// convenient for timer. What's more, the frequency cannot be set too high or too low, 1000Hz is

View File

@ -15,6 +15,7 @@ use alloc::{
vec, vec,
vec::Vec, vec::Vec,
}; };
use log::warn; use log::warn;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]

View File

@ -7,13 +7,13 @@
pub mod kcmdline; pub mod kcmdline;
pub mod memory_region; pub mod memory_region;
use alloc::{string::String, vec::Vec};
use kcmdline::KCmdlineArg; use kcmdline::KCmdlineArg;
use spin::Once;
use self::memory_region::MemoryRegion; use self::memory_region::MemoryRegion;
use alloc::{string::String, vec::Vec};
use spin::Once;
/// ACPI information from the bootloader. /// ACPI information from the bootloader.
/// ///
/// The boot crate can choose either providing the raw RSDP physical address or /// The boot crate can choose either providing the raw RSDP physical address or
@ -119,9 +119,10 @@ pub fn call_aster_main() -> ! {
} }
#[cfg(ktest)] #[cfg(ktest)]
{ {
use crate::arch::qemu::{exit_qemu, QemuExitCode};
use alloc::{boxed::Box, string::ToString}; use alloc::{boxed::Box, string::ToString};
use core::any::Any; use core::any::Any;
use crate::arch::qemu::{exit_qemu, QemuExitCode};
crate::init(); crate::init();
let fn_catch_unwind = &(unwinding::panic::catch_unwind::<(), fn()> let fn_catch_unwind = &(unwinding::panic::catch_unwind::<(), fn()>
as fn(fn()) -> Result<(), Box<(dyn Any + Send + 'static)>>); as fn(fn()) -> Result<(), Box<(dyn Any + Send + 'static)>>);

View File

@ -1,11 +1,11 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::{collections::VecDeque, fmt::Debug, sync::Arc, vec::Vec}; use alloc::{collections::VecDeque, fmt::Debug, sync::Arc, vec::Vec};
use log::{debug, error}; use log::{debug, error};
use crate::bus::BusProbeError;
use super::device::MmioCommonDevice; use super::device::MmioCommonDevice;
use crate::bus::BusProbeError;
pub trait MmioDevice: Sync + Send + Debug { pub trait MmioDevice: Sync + Send + Debug {
fn device_id(&self) -> u32; fn device_id(&self) -> u32;

View File

@ -3,14 +3,13 @@
use int_to_c_enum::TryFromInt; use int_to_c_enum::TryFromInt;
use log::info; use log::info;
use super::VIRTIO_MMIO_MAGIC;
use crate::{ use crate::{
io_mem::IoMem, io_mem::IoMem,
trap::IrqLine, trap::IrqLine,
vm::{paddr_to_vaddr, Paddr, VmIo}, vm::{paddr_to_vaddr, Paddr, VmIo},
}; };
use super::VIRTIO_MMIO_MAGIC;
/// MMIO Common device. /// MMIO Common device.
/// TODO: Implement universal access to MMIO devices since we are temporarily /// TODO: Implement universal access to MMIO devices since we are temporarily
/// using specific virtio device as implementation of CommonDevice. /// using specific virtio device as implementation of CommonDevice.

View File

@ -5,18 +5,17 @@
pub mod bus; pub mod bus;
pub mod device; pub mod device;
use alloc::vec::Vec;
use core::ops::Range; use core::ops::Range;
use alloc::vec::Vec;
use log::debug; use log::debug;
use self::bus::MmioBus;
use crate::{ use crate::{
arch::kernel::IO_APIC, bus::mmio::device::MmioCommonDevice, sync::SpinLock, trap::IrqLine, arch::kernel::IO_APIC, bus::mmio::device::MmioCommonDevice, sync::SpinLock, trap::IrqLine,
vm::paddr_to_vaddr, vm::paddr_to_vaddr,
}; };
use self::bus::MmioBus;
const VIRTIO_MMIO_MAGIC: u32 = 0x74726976; const VIRTIO_MMIO_MAGIC: u32 = 0x74726976;
pub static MMIO_BUS: SpinLock<MmioBus> = SpinLock::new(MmioBus::new()); pub static MMIO_BUS: SpinLock<MmioBus> = SpinLock::new(MmioBus::new());

View File

@ -1,13 +1,12 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::{collections::VecDeque, sync::Arc, vec::Vec};
use core::fmt::Debug; use core::fmt::Debug;
use alloc::{collections::VecDeque, sync::Arc, vec::Vec};
use log::{debug, error}; use log::{debug, error};
use crate::bus::BusProbeError;
use super::{device_info::PciDeviceId, PciCommonDevice}; use super::{device_info::PciDeviceId, PciCommonDevice};
use crate::bus::BusProbeError;
pub trait PciDevice: Sync + Send + Debug { pub trait PciDevice: Sync + Send + Debug {
fn device_id(&self) -> PciDeviceId; fn device_id(&self) -> PciDeviceId;

View File

@ -3,7 +3,6 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use self::{msix::CapabilityMsixData, vendor::CapabilityVndrData}; use self::{msix::CapabilityMsixData, vendor::CapabilityVndrData};
use super::{ use super::{
cfg_space::{PciDeviceCommonCfgOffset, Status}, cfg_space::{PciDeviceCommonCfgOffset, Status},
common_device::PciCommonDevice, common_device::PciCommonDevice,

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::bus::pci::{common_device::PciCommonDevice, device_info::PciDeviceLocation}; use crate::{
use crate::{Error, Result}; bus::pci::{common_device::PciCommonDevice, device_info::PciDeviceLocation},
Error, Result,
};
/// Vendor specific capability. Users can access this capability area at will, /// Vendor specific capability. Users can access this capability area at will,
/// except for the PCI configuration space which cannot be accessed at will through this structure. /// except for the PCI configuration space which cannot be accessed at will through this structure.

View File

@ -1,11 +1,11 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::sync::Arc; use alloc::sync::Arc;
use bitflags::bitflags; use bitflags::bitflags;
use crate::{io_mem::IoMem, Error, Result};
use super::PciDeviceLocation; use super::PciDeviceLocation;
use crate::{io_mem::IoMem, Error, Result};
#[repr(u16)] #[repr(u16)]
pub enum PciDeviceCommonCfgOffset { pub enum PciDeviceCommonCfgOffset {

View File

@ -2,9 +2,8 @@
use core::iter; use core::iter;
use crate::arch::pci::{PCI_ADDRESS_PORT, PCI_DATA_PORT};
use super::cfg_space::PciDeviceCommonCfgOffset; use super::cfg_space::PciDeviceCommonCfgOffset;
use crate::arch::pci::{PCI_ADDRESS_PORT, PCI_DATA_PORT};
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct PciDeviceId { pub struct PciDeviceId {

View File

@ -56,10 +56,10 @@ pub mod cfg_space;
pub mod common_device; pub mod common_device;
mod device_info; mod device_info;
use crate::sync::Mutex;
pub use device_info::{PciDeviceId, PciDeviceLocation}; pub use device_info::{PciDeviceId, PciDeviceLocation};
use self::{bus::PciBus, common_device::PciCommonDevice}; use self::{bus::PciBus, common_device::PciCommonDevice};
use crate::sync::Mutex;
pub static PCI_BUS: Mutex<PciBus> = Mutex::new(PciBus::new()); pub static PCI_BUS: Mutex<PciBus> = Mutex::new(PciBus::new());

View File

@ -2,9 +2,9 @@
//! CPU. //! CPU.
use core::{cell::UnsafeCell, ops::Deref};
use crate::trap::disable_local; use crate::trap::disable_local;
use core::cell::UnsafeCell;
use core::ops::Deref;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_arch = "x86_64")]{ if #[cfg(target_arch = "x86_64")]{

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use core::{mem::size_of, ops::Range}; use core::{mem::size_of, ops::Range};
use pod::Pod; use pod::Pod;
use crate::{ use crate::{

View File

@ -43,12 +43,11 @@ pub mod user;
mod util; mod util;
pub mod vm; pub mod vm;
pub use self::cpu::CpuLocal;
pub use self::error::Error;
pub use self::prelude::Result;
#[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 fn init() { pub fn init() {
arch::before_all_init(); arch::before_all_init();
logger::init(); logger::init();

View File

@ -1,9 +1,9 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::{config::DEFAULT_LOG_LEVEL, early_println};
use log::{Metadata, Record}; use log::{Metadata, Record};
use crate::{config::DEFAULT_LOG_LEVEL, early_println};
const LOGGER: Logger = Logger {}; const LOGGER: Logger = Logger {};
struct Logger {} struct Logger {}

View File

@ -5,14 +5,16 @@
use alloc::{boxed::Box, string::ToString}; use alloc::{boxed::Box, string::ToString};
use core::ffi::c_void; use core::ffi::c_void;
use crate::arch::qemu::{exit_qemu, QemuExitCode};
use crate::{early_print, early_println};
use log::error; use log::error;
use crate::{
arch::qemu::{exit_qemu, QemuExitCode},
early_print, early_println,
};
extern crate cfg_if; extern crate cfg_if;
extern crate gimli; extern crate gimli;
use gimli::Register; use gimli::Register;
use unwinding::{ use unwinding::{
abi::{ abi::{
UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_FindEnclosingFunction, UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_FindEnclosingFunction,

View File

@ -4,9 +4,7 @@
pub type Result<T> = core::result::Result<T, crate::error::Error>; pub type Result<T> = core::result::Result<T, crate::error::Error>;
pub(crate) use alloc::boxed::Box; pub(crate) use alloc::{boxed::Box, sync::Arc, vec::Vec};
pub(crate) use alloc::sync::Arc;
pub(crate) use alloc::vec::Vec;
pub(crate) use core::any::Any; pub(crate) use core::any::Any;
pub use crate::vm::{Paddr, Vaddr}; pub use crate::vm::{Paddr, Vaddr};

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use core::fmt::{self}; use core::{
use core::sync::atomic::{AtomicU64, Ordering::Relaxed}; fmt::{self},
sync::atomic::{AtomicU64, Ordering::Relaxed},
};
use align_ext::AlignExt; use align_ext::AlignExt;

View File

@ -10,10 +10,12 @@ mod rwmutex;
mod spin; mod spin;
mod wait; mod wait;
pub use self::atomic_bits::AtomicBits;
pub use self::mutex::{Mutex, MutexGuard};
// pub use self::rcu::{pass_quiescent_state, OwnerPtr, Rcu, RcuReadGuard, RcuReclaimer}; // pub use self::rcu::{pass_quiescent_state, OwnerPtr, Rcu, RcuReadGuard, RcuReclaimer};
pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockUpgradeableGuard, RwLockWriteGuard}; pub use self::{
pub use self::rwmutex::{RwMutex, RwMutexReadGuard, RwMutexUpgradeableGuard, RwMutexWriteGuard}; atomic_bits::AtomicBits,
pub use self::spin::{SpinLock, SpinLockGuard}; mutex::{Mutex, MutexGuard},
pub use self::wait::WaitQueue; rwlock::{RwLock, RwLockReadGuard, RwLockUpgradeableGuard, RwLockWriteGuard},
rwmutex::{RwMutex, RwMutexReadGuard, RwMutexUpgradeableGuard, RwMutexWriteGuard},
spin::{SpinLock, SpinLockGuard},
wait::WaitQueue,
};

View File

@ -1,11 +1,13 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use super::WaitQueue; use core::{
use core::cell::UnsafeCell; cell::UnsafeCell,
use core::ops::{Deref, DerefMut}; fmt,
ops::{Deref, DerefMut},
sync::atomic::{AtomicBool, Ordering},
};
use core::fmt; use super::WaitQueue;
use core::sync::atomic::{AtomicBool, Ordering};
/// A mutex with waitqueue. /// A mutex with waitqueue.
pub struct Mutex<T> { pub struct Mutex<T> {

View File

@ -1,14 +1,19 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use core::cell::UnsafeCell; use core::{
use core::fmt; cell::UnsafeCell,
use core::ops::{Deref, DerefMut}; fmt,
use core::sync::atomic::AtomicUsize; ops::{Deref, DerefMut},
use core::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release}; sync::atomic::{
AtomicUsize,
Ordering::{AcqRel, Acquire, Relaxed, Release},
},
};
use crate::task::{disable_preempt, DisablePreemptGuard}; use crate::{
use crate::trap::disable_local; task::{disable_preempt, DisablePreemptGuard},
use crate::trap::DisabledLocalIrqGuard; trap::{disable_local, DisabledLocalIrqGuard},
};
/// Spin-based Read-write Lock /// Spin-based Read-write Lock
/// ///

View File

@ -1,10 +1,14 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use core::cell::UnsafeCell; use core::{
use core::fmt; cell::UnsafeCell,
use core::ops::{Deref, DerefMut}; fmt,
use core::sync::atomic::AtomicUsize; ops::{Deref, DerefMut},
use core::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release}; sync::atomic::{
AtomicUsize,
Ordering::{AcqRel, Acquire, Relaxed, Release},
},
};
use super::WaitQueue; use super::WaitQueue;

View File

@ -1,13 +1,16 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use core::cell::UnsafeCell; use core::{
use core::fmt; cell::UnsafeCell,
use core::ops::{Deref, DerefMut}; fmt,
use core::sync::atomic::{AtomicBool, Ordering}; ops::{Deref, DerefMut},
sync::atomic::{AtomicBool, Ordering},
};
use crate::task::{disable_preempt, DisablePreemptGuard}; use crate::{
use crate::trap::disable_local; task::{disable_preempt, DisablePreemptGuard},
use crate::trap::DisabledLocalIrqGuard; trap::{disable_local, DisabledLocalIrqGuard},
};
/// A spin lock. /// A spin lock.
pub struct SpinLock<T> { pub struct SpinLock<T> {

View File

@ -1,13 +1,18 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use super::SpinLock;
use crate::arch::timer::{add_timeout_list, TIMER_FREQ};
use alloc::{collections::VecDeque, sync::Arc}; use alloc::{collections::VecDeque, sync::Arc};
use bitflags::bitflags; use core::{
use core::sync::atomic::{AtomicBool, Ordering}; sync::atomic::{AtomicBool, Ordering},
use core::time::Duration; time::Duration,
};
use crate::task::{add_task, current_task, schedule, Task, TaskStatus}; use bitflags::bitflags;
use super::SpinLock;
use crate::{
arch::timer::{add_timeout_list, TIMER_FREQ},
task::{add_task, current_task, schedule, Task, TaskStatus},
};
/// A wait queue. /// A wait queue.
/// ///

View File

@ -8,7 +8,9 @@ mod scheduler;
#[allow(clippy::module_inception)] #[allow(clippy::module_inception)]
mod task; mod task;
pub use self::priority::Priority; pub use self::{
pub use self::processor::{current_task, disable_preempt, preempt, schedule, DisablePreemptGuard}; priority::Priority,
pub use self::scheduler::{add_task, set_scheduler, Scheduler}; processor::{current_task, disable_preempt, preempt, schedule, DisablePreemptGuard},
pub use self::task::{Task, TaskAdapter, TaskOptions, TaskStatus}; scheduler::{add_task, set_scheduler, Scheduler},
task::{Task, TaskAdapter, TaskOptions, TaskStatus},
};

View File

@ -1,20 +1,16 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use core::sync::atomic::AtomicUsize; use alloc::sync::Arc;
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
use crate::cpu_local; use lazy_static::lazy_static;
use crate::sync::Mutex;
use crate::trap::disable_local;
use core::sync::atomic::Ordering::Relaxed;
use super::{ use super::{
scheduler::{fetch_task, GLOBAL_SCHEDULER}, scheduler::{fetch_task, GLOBAL_SCHEDULER},
task::{context_switch, TaskContext}, task::{context_switch, TaskContext},
Task, TaskStatus, Task, TaskStatus,
}; };
use alloc::sync::Arc; use crate::{cpu_local, sync::Mutex, trap::disable_local};
use lazy_static::lazy_static;
pub struct Processor { pub struct Processor {
current: Option<Arc<Task>>, current: Option<Arc<Task>>,

View File

@ -1,11 +1,9 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::prelude::*;
use crate::sync::SpinLock;
use crate::task::Task;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use crate::{prelude::*, sync::SpinLock, task::Task};
lazy_static! { lazy_static! {
pub(crate) static ref GLOBAL_SCHEDULER: SpinLock<GlobalScheduler> = pub(crate) static ref GLOBAL_SCHEDULER: SpinLock<GlobalScheduler> =
SpinLock::new(GlobalScheduler { scheduler: None }); SpinLock::new(GlobalScheduler { scheduler: None });

View File

@ -1,20 +1,21 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::arch::mm::PageTableFlags; use intrusive_collections::{intrusive_adapter, LinkedListAtomicLink};
use crate::config::{KERNEL_STACK_SIZE, PAGE_SIZE};
use crate::cpu::CpuSet;
use crate::prelude::*;
use crate::sync::{Mutex, MutexGuard};
use crate::user::UserSpace;
use crate::vm::page_table::KERNEL_PAGE_TABLE;
use crate::vm::{VmAllocOptions, VmSegment};
use intrusive_collections::intrusive_adapter; use super::{
use intrusive_collections::LinkedListAtomicLink; add_task,
priority::Priority,
use super::add_task; processor::{current_task, schedule},
use super::priority::Priority; };
use super::processor::{current_task, schedule}; use crate::{
arch::mm::PageTableFlags,
config::{KERNEL_STACK_SIZE, PAGE_SIZE},
cpu::CpuSet,
prelude::*,
sync::{Mutex, MutexGuard},
user::UserSpace,
vm::{page_table::KERNEL_PAGE_TABLE, VmAllocOptions, VmSegment},
};
core::arch::global_asm!(include_str!("switch.S")); core::arch::global_asm!(include_str!("switch.S"));

View File

@ -2,12 +2,14 @@
//! Timer. //! Timer.
use crate::arch::timer::{add_timeout_list, TimerCallback, TICK};
use crate::prelude::*;
use crate::{arch::timer::TIMER_FREQ, sync::SpinLock};
use core::{sync::atomic::Ordering, time::Duration}; use core::{sync::atomic::Ordering, time::Duration};
pub use crate::arch::timer::read_monotonic_milli_seconds; pub use crate::arch::timer::read_monotonic_milli_seconds;
use crate::{
arch::timer::{add_timeout_list, TimerCallback, TICK, TIMER_FREQ},
prelude::*,
sync::SpinLock,
};
/// A timer invokes a callback function after a specified span of time elapsed. /// A timer invokes a callback function after a specified span of time elapsed.
/// ///

View File

@ -2,14 +2,14 @@
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use crate::{arch::irq::IRQ_LIST, cpu::CpuException, cpu_local};
#[cfg(feature = "intel_tdx")]
use crate::arch::tdx_guest::{handle_virtual_exception, TdxTrapFrame};
#[cfg(feature = "intel_tdx")] #[cfg(feature = "intel_tdx")]
use tdx_guest::tdcall; use tdx_guest::tdcall;
use trapframe::TrapFrame; use trapframe::TrapFrame;
#[cfg(feature = "intel_tdx")]
use crate::arch::tdx_guest::{handle_virtual_exception, TdxTrapFrame};
use crate::{arch::irq::IRQ_LIST, cpu::CpuException, cpu_local};
#[cfg(feature = "intel_tdx")] #[cfg(feature = "intel_tdx")]
impl TdxTrapFrame for TrapFrame { impl TdxTrapFrame for TrapFrame {
fn rax(&self) -> usize { fn rax(&self) -> usize {

View File

@ -1,12 +1,16 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::arch::irq::{self, IrqCallbackHandle, NOT_USING_IRQ};
use crate::task::{disable_preempt, DisablePreemptGuard};
use crate::{prelude::*, Error};
use core::fmt::Debug; use core::fmt::Debug;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use crate::{
arch::irq::{self, IrqCallbackHandle, NOT_USING_IRQ},
prelude::*,
task::{disable_preempt, DisablePreemptGuard},
Error,
};
pub type IrqCallbackFunction = dyn Fn(&TrapFrame) + Sync + Send + 'static; pub type IrqCallbackFunction = dyn Fn(&TrapFrame) + Sync + Send + 'static;
/// An Interrupt ReQuest(IRQ) line. User can use `alloc` or `alloc_specific` to get specific IRQ line. /// An Interrupt ReQuest(IRQ) line. User can use `alloc` or `alloc_specific` to get specific IRQ line.

View File

@ -3,11 +3,12 @@
mod handler; mod handler;
mod irq; mod irq;
pub(crate) use self::handler::call_irq_callback_functions;
pub use self::irq::{disable_local, DisabledLocalIrqGuard, IrqCallbackFunction, IrqLine};
pub use handler::in_interrupt_context; pub use handler::in_interrupt_context;
pub use trapframe::TrapFrame; pub use trapframe::TrapFrame;
pub(crate) use self::handler::call_irq_callback_functions;
pub use self::irq::{disable_local, DisabledLocalIrqGuard, IrqCallbackFunction, IrqLine};
pub(crate) fn init() { pub(crate) fn init() {
unsafe { unsafe {
trapframe::init(); trapframe::init();

View File

@ -2,12 +2,10 @@
//! User space. //! User space.
use crate::cpu::UserContext;
use crate::prelude::*;
use crate::task::Task;
use crate::vm::VmSpace;
use trapframe::TrapFrame; use trapframe::TrapFrame;
use crate::{cpu::UserContext, prelude::*, task::Task, vm::VmSpace};
/// A user space. /// A user space.
/// ///
/// Each user space has a VM address space and allows a task to execute in /// Each user space has a VM address space and allows a task to execute in

View File

@ -3,15 +3,16 @@
use alloc::sync::Arc; use alloc::sync::Arc;
use core::ops::Deref; use core::ops::Deref;
use crate::arch::{iommu, mm::PageTableFlags};
use crate::vm::{
dma::{dma_type, Daddr, DmaType},
paddr_to_vaddr,
page_table::KERNEL_PAGE_TABLE,
HasPaddr, Paddr, VmIo, VmReader, VmSegment, VmWriter, PAGE_SIZE,
};
use super::{check_and_insert_dma_mapping, remove_dma_mapping, DmaError, HasDaddr}; use super::{check_and_insert_dma_mapping, remove_dma_mapping, DmaError, HasDaddr};
use crate::{
arch::{iommu, mm::PageTableFlags},
vm::{
dma::{dma_type, Daddr, DmaType},
paddr_to_vaddr,
page_table::KERNEL_PAGE_TABLE,
HasPaddr, Paddr, VmIo, VmReader, VmSegment, VmWriter, PAGE_SIZE,
},
};
/// A coherent (or consistent) DMA mapping, /// A coherent (or consistent) DMA mapping,
/// which guarantees that the device and the CPU can /// which guarantees that the device and the CPU can
@ -163,9 +164,10 @@ impl HasPaddr for DmaCoherent {
#[if_cfg_ktest] #[if_cfg_ktest]
mod test { mod test {
use alloc::vec;
use super::*; use super::*;
use crate::vm::VmAllocOptions; use crate::vm::VmAllocOptions;
use alloc::vec;
#[ktest] #[ktest]
fn map_with_coherent_device() { fn map_with_coherent_device() {

View File

@ -1,18 +1,17 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::sync::Arc; use alloc::sync::Arc;
use core::arch::x86_64::_mm_clflush; use core::{arch::x86_64::_mm_clflush, ops::Range};
use core::ops::Range;
use crate::arch::iommu;
use crate::error::Error;
use crate::vm::{
dma::{dma_type, Daddr, DmaType},
HasPaddr, Paddr, VmSegment, PAGE_SIZE,
};
use crate::vm::{VmIo, VmReader, VmWriter};
use super::{check_and_insert_dma_mapping, remove_dma_mapping, DmaError, HasDaddr}; use super::{check_and_insert_dma_mapping, remove_dma_mapping, DmaError, HasDaddr};
use crate::{
arch::iommu,
error::Error,
vm::{
dma::{dma_type, Daddr, DmaType},
HasPaddr, Paddr, VmIo, VmReader, VmSegment, VmWriter, PAGE_SIZE,
},
};
/// A streaming DMA mapping. Users must synchronize data /// A streaming DMA mapping. Users must synchronize data
/// before reading or after writing to ensure consistency. /// before reading or after writing to ensure consistency.
@ -198,9 +197,10 @@ impl HasPaddr for DmaStream {
#[if_cfg_ktest] #[if_cfg_ktest]
mod test { mod test {
use alloc::vec;
use super::*; use super::*;
use crate::vm::VmAllocOptions; use crate::vm::VmAllocOptions;
use alloc::vec;
#[ktest] #[ktest]
fn streaming_map() { fn streaming_map() {

View File

@ -4,14 +4,13 @@ mod dma_coherent;
mod dma_stream; mod dma_stream;
use alloc::collections::BTreeSet; use alloc::collections::BTreeSet;
use spin::Once;
use crate::{arch::iommu::has_iommu, config::PAGE_SIZE, sync::SpinLock};
use super::Paddr;
pub use dma_coherent::DmaCoherent; pub use dma_coherent::DmaCoherent;
pub use dma_stream::{DmaDirection, DmaStream}; pub use dma_stream::{DmaDirection, DmaStream};
use spin::Once;
use super::Paddr;
use crate::{arch::iommu::has_iommu, config::PAGE_SIZE, sync::SpinLock};
/// If a device performs DMA to read or write system /// If a device performs DMA to read or write system
/// memory, the addresses used by the device are device addresses. /// memory, the addresses used by the device are device addresses.

View File

@ -6,13 +6,12 @@ use core::{
marker::PhantomData, marker::PhantomData,
ops::{BitAnd, BitOr, Not, Range}, ops::{BitAnd, BitOr, Not, Range},
}; };
use pod::Pod; use pod::Pod;
use super::{frame_allocator, HasPaddr, Paddr, VmIo};
use crate::{config::PAGE_SIZE, prelude::*, Error}; use crate::{config::PAGE_SIZE, prelude::*, Error};
use super::{frame_allocator, HasPaddr};
use super::{Paddr, VmIo};
/// A collection of page frames (physical memory pages). /// A collection of page frames (physical memory pages).
/// ///
/// For the most parts, `VmFrameVec` is like `Vec<VmFrame>`. But the /// For the most parts, `VmFrameVec` is like `Vec<VmFrame>`. But the

View File

@ -1,15 +1,18 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use align_ext::AlignExt;
use alloc::vec::Vec; use alloc::vec::Vec;
use align_ext::AlignExt;
use buddy_system_allocator::FrameAllocator; use buddy_system_allocator::FrameAllocator;
use log::info; use log::info;
use spin::Once; use spin::Once;
use crate::boot::memory_region::{MemoryRegion, MemoryRegionType};
use crate::{config::PAGE_SIZE, sync::SpinLock};
use super::{frame::VmFrameFlags, VmFrame, VmFrameVec, VmSegment}; use super::{frame::VmFrameFlags, VmFrame, VmFrameVec, VmSegment};
use crate::{
boot::memory_region::{MemoryRegion, MemoryRegionType},
config::PAGE_SIZE,
sync::SpinLock,
};
pub(super) static FRAME_ALLOCATOR: Once<SpinLock<FrameAllocator>> = Once::new(); pub(super) static FRAME_ALLOCATOR: Once<SpinLock<FrameAllocator>> = Once::new();

View File

@ -1,20 +1,23 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::config::{KERNEL_HEAP_SIZE, PAGE_SIZE};
use crate::prelude::*;
use crate::sync::SpinLock;
use crate::trap::disable_local;
use crate::vm::frame_allocator::FRAME_ALLOCATOR;
use crate::Error;
use align_ext::AlignExt;
use buddy_system_allocator::Heap;
use core::{ use core::{
alloc::{GlobalAlloc, Layout}, alloc::{GlobalAlloc, Layout},
ptr::NonNull, ptr::NonNull,
}; };
use align_ext::AlignExt;
use buddy_system_allocator::Heap;
use log::debug; use log::debug;
use super::paddr_to_vaddr; use super::paddr_to_vaddr;
use crate::{
config::{KERNEL_HEAP_SIZE, PAGE_SIZE},
prelude::*,
sync::SpinLock,
trap::disable_local,
vm::frame_allocator::FRAME_ALLOCATOR,
Error,
};
#[global_allocator] #[global_allocator]
static HEAP_ALLOCATOR: LockedHeapWithRescue<32> = LockedHeapWithRescue::new(rescue); static HEAP_ALLOCATOR: LockedHeapWithRescue<32> = LockedHeapWithRescue::new(rescue);

View File

@ -1,9 +1,9 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::prelude::*; use inherit_methods_macro::inherit_methods;
use pod::Pod; use pod::Pod;
use inherit_methods_macro::inherit_methods; use crate::prelude::*;
/// A trait that enables reading/writing data from/to a VM object, /// A trait that enables reading/writing data from/to a VM object,
/// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`. /// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`.

View File

@ -1,15 +1,16 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::collections::{btree_map::Entry, BTreeMap};
use core::fmt;
use super::page_table::{PageTable, PageTableConfig, UserMode}; use super::page_table::{PageTable, PageTableConfig, UserMode};
use crate::{ use crate::{
arch::mm::{PageTableEntry, PageTableFlags}, arch::mm::{PageTableEntry, PageTableFlags},
config::{PAGE_SIZE, PHYS_OFFSET}, config::{PAGE_SIZE, PHYS_OFFSET},
vm::is_page_aligned, prelude::*,
vm::{VmAllocOptions, VmFrame, VmFrameVec, VmReader, VmWriter}, vm::{is_page_aligned, VmAllocOptions, VmFrame, VmFrameVec, VmReader, VmWriter},
Error,
}; };
use crate::{prelude::*, Error};
use alloc::collections::{btree_map::Entry, BTreeMap};
use core::fmt;
#[derive(Debug)] #[derive(Debug)]
pub struct MapArea { pub struct MapArea {

View File

@ -19,24 +19,23 @@ mod options;
pub(crate) mod page_table; pub(crate) mod page_table;
mod space; mod space;
use crate::config::{KERNEL_OFFSET, PAGE_SIZE, PHYS_OFFSET}; use alloc::{borrow::ToOwned, vec::Vec};
pub use self::dma::{DmaCoherent, DmaDirection, DmaStream, HasDaddr};
pub use self::frame::{VmFrame, VmFrameVec, VmFrameVecIter, VmReader, VmSegment, VmWriter};
pub use self::io::VmIo;
pub use self::options::VmAllocOptions;
pub use self::space::{VmMapOptions, VmPerm, VmSpace};
pub use self::{
memory_set::{MapArea, MemorySet},
page_table::PageTable,
};
use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use spin::Once; use spin::Once;
use crate::boot::memory_region::{MemoryRegion, MemoryRegionType}; pub use self::{
dma::{DmaCoherent, DmaDirection, DmaStream, HasDaddr},
frame::{VmFrame, VmFrameVec, VmFrameVecIter, VmReader, VmSegment, VmWriter},
io::VmIo,
memory_set::{MapArea, MemorySet},
options::VmAllocOptions,
page_table::PageTable,
space::{VmMapOptions, VmPerm, VmSpace},
};
use crate::{
boot::memory_region::{MemoryRegion, MemoryRegionType},
config::{KERNEL_OFFSET, PAGE_SIZE, PHYS_OFFSET},
};
/// Get physical address trait /// Get physical address trait
pub trait HasPaddr { pub trait HasPaddr {

View File

@ -1,8 +1,7 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::{prelude::*, Error};
use super::{frame::VmFrameFlags, frame_allocator, VmFrame, VmFrameVec, VmSegment}; use super::{frame::VmFrameFlags, frame_allocator, VmFrame, VmFrameVec, VmSegment};
use crate::{prelude::*, Error};
/// Options for allocating physical memory pages (or frames). /// Options for allocating physical memory pages (or frames).
/// ///

View File

@ -1,5 +1,12 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::{vec, vec::Vec};
use core::{fmt::Debug, marker::PhantomData, mem::size_of};
use log::trace;
use pod::Pod;
use spin::Once;
use super::{paddr_to_vaddr, Paddr, Vaddr, VmAllocOptions}; use super::{paddr_to_vaddr, Paddr, Vaddr, VmAllocOptions};
use crate::{ use crate::{
arch::mm::{is_kernel_vaddr, is_user_vaddr, tlb_flush, PageTableEntry}, arch::mm::{is_kernel_vaddr, is_user_vaddr, tlb_flush, PageTableEntry},
@ -7,11 +14,6 @@ use crate::{
sync::SpinLock, sync::SpinLock,
vm::VmFrame, vm::VmFrame,
}; };
use alloc::{vec, vec::Vec};
use core::{fmt::Debug, marker::PhantomData, mem::size_of};
use log::trace;
use pod::Pod;
use spin::Once;
pub trait PageTableFlagsTrait: Clone + Copy + Sized + Pod + Debug { pub trait PageTableFlagsTrait: Clone + Copy + Sized + Pod + Debug {
fn new() -> Self; fn new() -> Self;

View File

@ -1,17 +1,11 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::arch::mm::PageTableFlags;
use crate::config::PAGE_SIZE;
use crate::sync::Mutex;
use bitflags::bitflags;
use core::ops::Range; use core::ops::Range;
use super::VmFrameVec; use bitflags::bitflags;
use super::{is_page_aligned, Vaddr};
use super::{MapArea, MemorySet};
use crate::{prelude::*, Error};
use super::VmIo; use super::{is_page_aligned, MapArea, MemorySet, Vaddr, VmFrameVec, VmIo};
use crate::{arch::mm::PageTableFlags, config::PAGE_SIZE, prelude::*, sync::Mutex, Error};
/// Virtual memory space. /// Virtual memory space.
/// ///

View File

@ -3,17 +3,17 @@
//! Test runner enabling control over the tests. //! Test runner enabling control over the tests.
//! //!
use alloc::{string::String, vec::Vec};
use core::format_args;
use owo_colors::OwoColorize;
use crate::{ use crate::{
path::{KtestPath, SuffixTrie}, path::{KtestPath, SuffixTrie},
tree::{KtestCrate, KtestTree}, tree::{KtestCrate, KtestTree},
CatchUnwindImpl, KtestError, KtestItem, KtestIter, CatchUnwindImpl, KtestError, KtestItem, KtestIter,
}; };
use alloc::{string::String, vec::Vec};
use core::format_args;
use owo_colors::OwoColorize;
pub enum KtestResult { pub enum KtestResult {
Ok, Ok,
Failed, Failed,

View File

@ -262,10 +262,10 @@ const EDDMAXNR: usize = 6;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
use core::mem::offset_of; use core::mem::offset_of;
use super::*;
#[test] #[test]
fn test_screen_info_offsets() { fn test_screen_info_offsets() {
assert_eq!(offset_of!(ScreenInfo, orig_x), 0x00); assert_eq!(offset_of!(ScreenInfo, orig_x), 0x00);

View File

@ -22,9 +22,8 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use xmas_elf::program::SegmentData;
use mapping::{SetupFileOffset, SetupVA}; use mapping::{SetupFileOffset, SetupVA};
use xmas_elf::program::SegmentData;
/// The type of the bzImage that we are building through `make_bzimage`. /// The type of the bzImage that we are building through `make_bzimage`.
/// ///

View File

@ -8,11 +8,11 @@
//! The reference to the Linux PE header definition: //! The reference to the Linux PE header definition:
//! https://github.com/torvalds/linux/blob/master/include/linux/pe.h //! https://github.com/torvalds/linux/blob/master/include/linux/pe.h
use std::{mem::size_of, ops::Range};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use serde::Serialize; use serde::Serialize;
use std::{mem::size_of, ops::Range};
use crate::mapping::{SetupFileOffset, SetupVA, LEGACY_SETUP_SEC_SIZE, SETUP32_LMA}; use crate::mapping::{SetupFileOffset, SetupVA, LEGACY_SETUP_SEC_SIZE, SETUP32_LMA};
// The MS-DOS header. // The MS-DOS header.

View File

@ -1,15 +1,16 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use linux_boot_params::BootParams;
use uefi::{ use uefi::{
data_types::Handle, data_types::Handle,
proto::loaded_image::LoadedImage, proto::loaded_image::LoadedImage,
table::{boot::MemoryMap, Boot, Runtime, SystemTable}, table::{boot::MemoryMap, Boot, Runtime, SystemTable},
}; };
use linux_boot_params::BootParams; use super::{
paging::{Ia32eFlags, PageNumber, PageTableCreator},
use super::paging::{Ia32eFlags, PageNumber, PageTableCreator}; relocation::apply_rela_dyn_relocations,
use super::relocation::apply_rela_dyn_relocations; };
#[export_name = "efi_stub_entry"] #[export_name = "efi_stub_entry"]
extern "sysv64" fn efi_stub_entry(handle: Handle, mut system_table: SystemTable<Boot>) -> ! { extern "sysv64" fn efi_stub_entry(handle: Handle, mut system_table: SystemTable<Boot>) -> ! {

View File

@ -1,9 +1,9 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use linux_boot_params::BootParams;
use core::arch::{asm, global_asm}; use core::arch::{asm, global_asm};
use linux_boot_params::BootParams;
global_asm!(include_str!("header.S")); global_asm!(include_str!("header.S"));
global_asm!(include_str!("setup.S")); global_asm!(include_str!("setup.S"));

View File

@ -1,9 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
// Copyright(c) 2023-2024 Intel Corporation. // Copyright(c) 2023-2024 Intel Corporation.
use crate::{tdcall::TdcallArgs, tdvmcall::TdVmcallArgs};
use core::arch::global_asm; use core::arch::global_asm;
use crate::{tdcall::TdcallArgs, tdvmcall::TdVmcallArgs};
global_asm!(include_str!("tdcall.asm")); global_asm!(include_str!("tdcall.asm"));
global_asm!(include_str!("tdvmcall.asm")); global_asm!(include_str!("tdvmcall.asm"));

View File

@ -11,12 +11,14 @@ mod asm;
pub mod tdcall; pub mod tdcall;
pub mod tdvmcall; pub mod tdvmcall;
pub use self::tdcall::{get_veinfo, TdxVirtualExceptionType};
pub use self::tdvmcall::print;
use raw_cpuid::{native_cpuid::cpuid_count, CpuIdResult}; use raw_cpuid::{native_cpuid::cpuid_count, CpuIdResult};
use tdcall::{InitError, TdgVpInfo}; use tdcall::{InitError, TdgVpInfo};
pub use self::{
tdcall::{get_veinfo, TdxVirtualExceptionType},
tdvmcall::print,
};
pub fn init_tdx() -> Result<TdgVpInfo, InitError> { pub fn init_tdx() -> Result<TdgVpInfo, InitError> {
check_tdx_guest()?; check_tdx_guest()?;
Ok(tdcall::get_tdinfo()?) Ok(tdcall::get_tdinfo()?)

View File

@ -5,10 +5,12 @@
//! It is used to call guest-side Intel TDX functions. For more information about //! It is used to call guest-side Intel TDX functions. For more information about
//! TDCALL, please refer to the [Intel® TDX Module v1.5 ABI Specification](https://cdrdv2.intel.com/v1/dl/getContent/733579) //! TDCALL, please refer to the [Intel® TDX Module v1.5 ABI Specification](https://cdrdv2.intel.com/v1/dl/getContent/733579)
use crate::asm::asm_td_call;
use bitflags::bitflags;
use core::fmt; use core::fmt;
use bitflags::bitflags;
use crate::asm::asm_td_call;
/// TDCALL Instruction Leaf Numbers Definition. /// TDCALL Instruction Leaf Numbers Definition.
#[repr(u64)] #[repr(u64)]
pub enum TdcallNum { pub enum TdcallNum {

View File

@ -8,15 +8,17 @@
//! resumes the TD via a SEAMCALL [TDH.VP.ENTER] invocation. //! resumes the TD via a SEAMCALL [TDH.VP.ENTER] invocation.
extern crate alloc; extern crate alloc;
use crate::asm::asm_td_vmcall;
use alloc::fmt; use alloc::fmt;
use bitflags::bitflags;
use core::fmt::Write; use core::fmt::Write;
use bitflags::bitflags;
use x86_64::{ use x86_64::{
registers::rflags::{self, RFlags}, registers::rflags::{self, RFlags},
structures::port::PortRead, structures::port::PortRead,
}; };
use crate::asm::asm_td_vmcall;
/// TDVMCALL Instruction Leaf Numbers Definition. /// TDVMCALL Instruction Leaf Numbers Definition.
#[repr(u64)] #[repr(u64)]
pub enum TdVmcallNum { pub enum TdVmcallNum {

View File

@ -4,10 +4,14 @@ use std::path::PathBuf;
use clap::{crate_version, Args, Parser}; use clap::{crate_version, Args, Parser};
use crate::commands::{execute_check_command, execute_clippy_command, execute_new_command}; use crate::{
use crate::config_manager::boot::{BootLoader, BootProtocol}; commands::{execute_check_command, execute_clippy_command, execute_new_command},
use crate::config_manager::qemu::QemuMachine; config_manager::{
use crate::config_manager::{BuildConfig, RunConfig, TestConfig}; boot::{BootLoader, BootProtocol},
qemu::QemuMachine,
BuildConfig, RunConfig, TestConfig,
},
};
pub fn main() { pub fn main() {
let osdk_subcommand = match Cli::parse() { let osdk_subcommand = match Cli::parse() {

View File

@ -2,12 +2,10 @@
use std::process; use std::process;
use crate::commands::utils::create_target_json;
use crate::error::Errno;
use crate::error_msg;
use crate::utils::get_cargo_metadata;
use super::utils::{cargo, COMMON_CARGO_ARGS}; use super::utils::{cargo, COMMON_CARGO_ARGS};
use crate::{
commands::utils::create_target_json, error::Errno, error_msg, utils::get_cargo_metadata,
};
pub fn execute_check_command() { pub fn execute_check_command() {
let target_json_path = { let target_json_path = {

View File

@ -2,11 +2,10 @@
use std::process; use std::process;
use crate::error_msg;
use crate::utils::get_cargo_metadata;
use crate::{commands::utils::create_target_json, error::Errno};
use super::utils::{cargo, COMMON_CARGO_ARGS}; use super::utils::{cargo, COMMON_CARGO_ARGS};
use crate::{
commands::utils::create_target_json, error::Errno, error_msg, utils::get_cargo_metadata,
};
pub fn execute_clippy_command() { pub fn execute_clippy_command() {
let target_json_path = { let target_json_path = {

View File

@ -7,6 +7,6 @@ mod clippy;
mod new; mod new;
mod utils; mod utils;
pub use self::check::execute_check_command; pub use self::{
pub use self::clippy::execute_clippy_command; check::execute_check_command, clippy::execute_clippy_command, new::execute_new_command,
pub use self::new::execute_new_command; };

View File

@ -1,13 +1,13 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::path::PathBuf; use std::{fs, path::PathBuf, process, str::FromStr};
use std::str::FromStr;
use std::{fs, process};
use crate::cli::NewArgs; use crate::{
use crate::error::Errno; cli::NewArgs,
use crate::error_msg; error::Errno,
use crate::utils::{cargo_new_lib, get_cargo_metadata, ASTER_FRAME_DEP}; error_msg,
utils::{cargo_new_lib, get_cargo_metadata, ASTER_FRAME_DEP},
};
pub fn execute_new_command(args: &NewArgs) { pub fn execute_new_command(args: &NewArgs) {
cargo_new_lib(&args.crate_name); cargo_new_lib(&args.crate_name);

View File

@ -1,8 +1,10 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::fs; use std::{
use std::path::{Path, PathBuf}; fs,
use std::process::Command; path::{Path, PathBuf},
process::Command,
};
pub const COMMON_CARGO_ARGS: &[&str] = &[ pub const COMMON_CARGO_ARGS: &[&str] = &[
"-Zbuild-std=core,alloc,compiler_builtins", "-Zbuild-std=core,alloc,compiler_builtins",

View File

@ -1,10 +1,8 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::path::PathBuf; use std::{path::PathBuf, process};
use std::process;
use crate::error::Errno; use crate::{error::Errno, error_msg};
use crate::error_msg;
/// Arguments for creating bootdev image and how to boot with vmm. /// Arguments for creating bootdev image and how to boot with vmm.
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]

View File

@ -1,16 +1,15 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::path::PathBuf; use std::{path::PathBuf, process};
use std::process;
use regex::Regex; use regex::Regex;
use serde::Deserialize; use serde::Deserialize;
use crate::error::Errno; use super::{
use crate::error_msg; boot::Boot,
qemu::{CfgQemu, Qemu},
use super::boot::Boot; };
use super::qemu::{CfgQemu, Qemu}; use crate::{error::Errno, error_msg};
/// The osdk manifest from configuration file and command line arguments. /// The osdk manifest from configuration file and command line arguments.
#[derive(Debug)] #[derive(Debug)]

View File

@ -9,18 +9,22 @@ pub mod boot;
pub mod manifest; pub mod manifest;
pub mod qemu; pub mod qemu;
use std::path::PathBuf; use std::{fs, path::PathBuf, process};
use std::{fs, process};
use indexmap::{IndexMap, IndexSet}; use indexmap::{IndexMap, IndexSet};
use which::which; use which::which;
use self::boot::BootLoader; use self::{
use self::manifest::{OsdkManifest, TomlManifest}; boot::BootLoader,
use crate::cli::{BuildArgs, CargoArgs, OsdkArgs, RunArgs, TestArgs}; manifest::{OsdkManifest, TomlManifest},
use crate::error::Errno; };
use crate::utils::get_cargo_metadata; use crate::{
use crate::{error_msg, warn_msg}; cli::{BuildArgs, CargoArgs, OsdkArgs, RunArgs, TestArgs},
error::Errno,
error_msg,
utils::get_cargo_metadata,
warn_msg,
};
/// Configurations for build subcommand /// Configurations for build subcommand
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,16 +1,14 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::collections::BTreeMap; use std::{collections::BTreeMap, fmt, path::PathBuf, process};
use std::path::PathBuf;
use std::{fmt, process};
use serde::de::{self, Visitor}; use serde::{
use serde::{Deserialize, Deserializer}; de::{self, Visitor},
Deserialize, Deserializer,
use crate::error::Errno; };
use crate::error_msg;
use super::get_key; use super::get_key;
use crate::{error::Errno, error_msg};
/// Arguments for creating bootdev image and how to boot with vmm. /// Arguments for creating bootdev image and how to boot with vmm.
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]

View File

@ -1,13 +1,18 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::fs; use std::{
use std::path::{Path, PathBuf}; fs,
path::{Path, PathBuf},
};
use crate::config_manager::manifest::{OsdkManifest, TomlManifest, FEATURE_REGEX}; use crate::{
cli::CargoArgs,
use crate::cli::CargoArgs; config_manager::{
use crate::config_manager::get_feature_strings; get_feature_strings,
use crate::test::utils::{assert_success, cargo_osdk, create_workspace}; manifest::{OsdkManifest, TomlManifest, FEATURE_REGEX},
},
test::utils::{assert_success, cargo_osdk, create_workspace},
};
#[test] #[test]
fn deserialize_osdk_manifest() { fn deserialize_osdk_manifest() {

View File

@ -2,11 +2,14 @@
//! The common utils for crate unit test //! The common utils for crate unit test
use std::{
ffi::OsStr,
fs::{self, create_dir_all},
path::{Path, PathBuf},
process::Output,
};
use assert_cmd::Command; use assert_cmd::Command;
use std::ffi::OsStr;
use std::fs::{self, create_dir_all};
use std::path::{Path, PathBuf};
use std::process::Output;
pub fn cargo_osdk<T: AsRef<OsStr>, I: IntoIterator<Item = T>>(args: I) -> Command { pub fn cargo_osdk<T: AsRef<OsStr>, I: IntoIterator<Item = T>>(args: I) -> Command {
let mut command = Command::cargo_bin("cargo-osdk").unwrap(); let mut command = Command::cargo_bin("cargo-osdk").unwrap();

View File

@ -1,13 +1,10 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::ffi::OsStr; use std::{ffi::OsStr, path::Path, process::Command};
use std::path::Path;
use std::process::Command;
use crate::error::Errno; use crate::{error::Errno, error_msg};
use crate::error_msg;
// FIXME: Crates belonging to Asterinas require a different dependency format. The dependency // FIXME: Crates belonging to Asterinas require a different dependency format. The dependency
// should be specified using a relative path instead of a URL. // should be specified using a relative path instead of a URL.
pub const ASTER_FRAME_DEP: &str = pub const ASTER_FRAME_DEP: &str =
"aster-frame = { git = \"https://github.com/asterinas/asterinas\", rev = \"f2f991b\" }"; "aster-frame = { git = \"https://github.com/asterinas/asterinas\", rev = \"f2f991b\" }";

View File

@ -2,9 +2,10 @@
//! Providing the utility to run the GDB scripts for the runner. //! Providing the utility to run the GDB scripts for the runner.
use crate::qemu_grub_efi;
use std::{fs::OpenOptions, io::Write, path::PathBuf, process::Command}; use std::{fs::OpenOptions, io::Write, path::PathBuf, process::Command};
use crate::qemu_grub_efi;
/// Run a GDB client. /// Run a GDB client.
/// ///
/// If argument `gdb_grub` is set true, it will run GRUB's gdb script. /// If argument `gdb_grub` is set true, it will run GRUB's gdb script.

View File

@ -1,13 +1,13 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use linux_bzimage_builder::{make_bzimage, BzImageType};
use std::{ use std::{
fs, fs,
io::Read, io::Read,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use linux_bzimage_builder::{make_bzimage, BzImageType};
use crate::BootProtocol; use crate::BootProtocol;
macro_rules! ovmf_prefix { macro_rules! ovmf_prefix {

View File

@ -9,16 +9,17 @@ pub mod tty;
mod urandom; mod urandom;
mod zero; mod zero;
use crate::fs::device::{add_node, Device, DeviceId, DeviceType}; pub use pty::{new_pty_pair, PtyMaster, PtySlave};
use crate::prelude::*;
pub use pty::new_pty_pair;
pub use pty::{PtyMaster, PtySlave};
pub use random::Random; pub use random::Random;
#[cfg(feature = "intel_tdx")] #[cfg(feature = "intel_tdx")]
pub use tdxguest::TdxGuest; pub use tdxguest::TdxGuest;
pub use urandom::Urandom; pub use urandom::Urandom;
use self::tty::get_n_tty; use self::tty::get_n_tty;
use crate::{
fs::device::{add_node, Device, DeviceId, DeviceType},
prelude::*,
};
/// Init the device node in fs, must be called after mounting rootfs. /// Init the device node in fs, must be called after mounting rootfs.
pub fn init() -> Result<()> { pub fn init() -> Result<()> {

View File

@ -1,10 +1,7 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use super::*; use super::*;
use crate::events::IoEvents; use crate::{events::IoEvents, fs::inode_handle::FileIo, prelude::*, process::signal::Poller};
use crate::fs::inode_handle::FileIo;
use crate::prelude::*;
use crate::process::signal::Poller;
pub struct Null; pub struct Null;

View File

@ -1,9 +1,13 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::fs::devpts::DevPts; use crate::{
use crate::fs::fs_resolver::{FsPath, FsResolver}; fs::{
use crate::fs::utils::{Dentry, Inode, InodeMode, InodeType}; devpts::DevPts,
use crate::prelude::*; fs_resolver::{FsPath, FsResolver},
utils::{Dentry, Inode, InodeMode, InodeType},
},
prelude::*,
};
#[allow(clippy::module_inception)] #[allow(clippy::module_inception)]
mod pty; mod pty;

View File

@ -1,20 +1,26 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use alloc::format; use alloc::format;
use ringbuf::{ring_buffer::RbBase, HeapRb, Rb}; use ringbuf::{ring_buffer::RbBase, HeapRb, Rb};
use crate::device::tty::line_discipline::LineDiscipline; use crate::{
use crate::device::tty::new_job_control_and_ldisc; device::tty::{line_discipline::LineDiscipline, new_job_control_and_ldisc},
use crate::events::IoEvents; events::IoEvents,
use crate::fs::device::{Device, DeviceId, DeviceType}; fs::{
use crate::fs::devpts::DevPts; device::{Device, DeviceId, DeviceType},
use crate::fs::fs_resolver::FsPath; devpts::DevPts,
use crate::fs::inode_handle::FileIo; fs_resolver::FsPath,
use crate::fs::utils::{AccessMode, Inode, InodeMode, IoctlCmd}; inode_handle::FileIo,
use crate::prelude::*; utils::{AccessMode, Inode, InodeMode, IoctlCmd},
use crate::process::signal::{Pollee, Poller}; },
use crate::process::{JobControl, Terminal}; prelude::*,
use crate::util::{read_val_from_user, write_val_to_user}; process::{
signal::{Pollee, Poller},
JobControl, Terminal,
},
util::{read_val_from_user, write_val_to_user},
};
const BUFFER_CAPACITY: usize = 4096; const BUFFER_CAPACITY: usize = 4096;

View File

@ -1,10 +1,14 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::events::IoEvents; use crate::{
use crate::fs::device::{Device, DeviceId, DeviceType}; events::IoEvents,
use crate::fs::inode_handle::FileIo; fs::{
use crate::prelude::*; device::{Device, DeviceId, DeviceType},
use crate::process::signal::Poller; inode_handle::FileIo,
},
prelude::*,
process::signal::Poller,
};
pub struct Random; pub struct Random;

View File

@ -1,14 +1,16 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use super::*;
use crate::error::Error;
use crate::events::IoEvents;
use crate::fs::inode_handle::FileIo;
use crate::fs::utils::IoctlCmd;
use crate::process::signal::Poller;
use crate::util::{read_val_from_user, write_val_to_user};
use tdx_guest::tdcall::{get_report, TdCallError}; use tdx_guest::tdcall::{get_report, TdCallError};
use super::*;
use crate::{
error::Error,
events::IoEvents,
fs::{inode_handle::FileIo, utils::IoctlCmd},
process::signal::Poller,
util::{read_val_from_user, write_val_to_user},
};
const TDX_REPORTDATA_LEN: usize = 64; const TDX_REPORTDATA_LEN: usize = 64;
const TDX_REPORT_LEN: usize = 1024; const TDX_REPORT_LEN: usize = 1024;

Some files were not shown because too many files have changed in this diff Show More