mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
Adjust the format of imports in Asterinas
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
92e488e727
commit
cfcef6965a
@ -3,20 +3,22 @@
|
||||
//! 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 core::ffi::CStr;
|
||||
|
||||
use linux_boot_params::{BootParams, E820Type, LINUX_BOOT_HEADER_MAGIC};
|
||||
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();
|
||||
|
||||
fn init_bootloader_name(bootloader_name: &'static Once<String>) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::arch::global_asm;
|
||||
|
||||
use multiboot2::MemoryAreaType;
|
||||
use spin::Once;
|
||||
|
||||
@ -14,8 +16,6 @@ use crate::{
|
||||
vm::paddr_to_vaddr,
|
||||
};
|
||||
|
||||
use core::arch::global_asm;
|
||||
|
||||
global_asm!(include_str!("header.S"));
|
||||
|
||||
pub(super) const MULTIBOOT_ENTRY_MAGIC: u32 = 0x2BADB002;
|
||||
|
@ -4,16 +4,16 @@ use alloc::{
|
||||
string::{String, ToString},
|
||||
vec::Vec,
|
||||
};
|
||||
use core::arch::global_asm;
|
||||
|
||||
use multiboot2::{BootInformation, BootInformationHeader, MemoryAreaType};
|
||||
use spin::Once;
|
||||
|
||||
use crate::boot::{
|
||||
kcmdline::KCmdlineArg,
|
||||
memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType},
|
||||
BootloaderAcpiArg, BootloaderFramebufferArg,
|
||||
};
|
||||
use spin::Once;
|
||||
|
||||
use core::arch::global_asm;
|
||||
|
||||
global_asm!(include_str!("header.S"));
|
||||
|
||||
|
@ -1,17 +1,14 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::{fmt, sync::Arc, vec::Vec};
|
||||
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 spin::Once;
|
||||
use trapframe::TrapFrame;
|
||||
|
||||
use super::device::serial::SerialPort;
|
||||
use super::kernel::IO_APIC;
|
||||
use super::{device::serial::SerialPort, kernel::IO_APIC};
|
||||
use crate::{sync::SpinLock, trap::IrqLine};
|
||||
|
||||
#[inline]
|
||||
pub fn print(args: fmt::Arguments) {
|
||||
|
@ -2,23 +2,28 @@
|
||||
|
||||
//! CPU.
|
||||
|
||||
use core::arch::x86_64::{_fxrstor, _fxsave};
|
||||
use core::fmt::Debug;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use bitvec::{prelude::Lsb0, slice::IterOnes};
|
||||
use trapframe::{GeneralRegs, UserContext as RawUserContext};
|
||||
use core::{
|
||||
arch::x86_64::{_fxrstor, _fxsave},
|
||||
fmt::Debug,
|
||||
};
|
||||
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
use crate::arch::tdx_guest::{handle_virtual_exception, TdxTrapFrame};
|
||||
use bitvec::prelude::BitVec;
|
||||
use bitvec::{
|
||||
prelude::{BitVec, Lsb0},
|
||||
slice::IterOnes,
|
||||
};
|
||||
use log::debug;
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
use tdx_guest::tdcall;
|
||||
use trapframe::{GeneralRegs, UserContext as RawUserContext};
|
||||
use x86_64::registers::rflags::RFlags;
|
||||
|
||||
use crate::trap::call_irq_callback_functions;
|
||||
use crate::user::{UserContextApi, UserContextApiInternal, UserEvent};
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
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.
|
||||
pub fn num_cpus() -> u32 {
|
||||
|
@ -3,9 +3,8 @@
|
||||
use acpi::{fadt::Fadt, sdt::Signature};
|
||||
use x86_64::instructions::port::{ReadOnlyAccess, WriteOnlyAccess};
|
||||
|
||||
use crate::arch::x86::kernel::acpi::ACPI_TABLES;
|
||||
|
||||
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_DATA: IoPort<u8, ReadOnlyAccess> = unsafe { IoPort::new(0x71) };
|
||||
|
@ -2,11 +2,13 @@
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
pub use x86_64::instructions::port::{
|
||||
PortReadAccess as IoPortReadAccess, PortWriteAccess as IoPortWriteAccess, ReadOnlyAccess,
|
||||
ReadWriteAccess, WriteOnlyAccess,
|
||||
pub use x86_64::{
|
||||
instructions::port::{
|
||||
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.
|
||||
///
|
||||
|
@ -1,11 +1,12 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::collections::BTreeMap;
|
||||
use core::mem::size_of;
|
||||
|
||||
use alloc::collections::BTreeMap;
|
||||
use log::warn;
|
||||
use pod::Pod;
|
||||
|
||||
use super::second_stage::{PageTableEntry, PageTableFlags};
|
||||
use crate::{
|
||||
bus::pci::PciDeviceLocation,
|
||||
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 63:12 is the context-table pointer pointing to this bus's context-table.
|
||||
#[derive(Pod, Clone, Copy)]
|
||||
|
@ -1,17 +1,16 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt::Debug;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use bitflags::bitflags;
|
||||
use log::info;
|
||||
use spin::Once;
|
||||
use trapframe::TrapFrame;
|
||||
use volatile::{access::ReadWrite, Volatile};
|
||||
|
||||
use crate::{trap::IrqLine, vm::Vaddr};
|
||||
|
||||
use super::remapping::Capability;
|
||||
use crate::{trap::IrqLine, vm::Vaddr};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FaultEventRegisters {
|
||||
|
@ -8,6 +8,7 @@ use volatile::{
|
||||
Volatile,
|
||||
};
|
||||
|
||||
use super::{context_table::RootTable, IommuError};
|
||||
use crate::{
|
||||
arch::{
|
||||
iommu::fault,
|
||||
@ -19,8 +20,6 @@ use crate::{
|
||||
vm::paddr_to_vaddr,
|
||||
};
|
||||
|
||||
use super::{context_table::RootTable, IommuError};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RemappingRegisters {
|
||||
version: Volatile<&'static u32, ReadOnly>,
|
||||
|
@ -1,12 +1,12 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::sync::Mutex;
|
||||
use alloc::{boxed::Box, fmt::Debug, sync::Arc, vec::Vec};
|
||||
|
||||
use spin::Once;
|
||||
use trapframe::TrapFrame;
|
||||
|
||||
use crate::{
|
||||
sync::{SpinLock, SpinLockGuard},
|
||||
sync::{Mutex, SpinLock, SpinLockGuard},
|
||||
util::recycle_allocator::RecycleAllocator,
|
||||
};
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::{fmt::Debug, mem::size_of, slice::Iter};
|
||||
|
||||
use acpi::{sdt::Signature, AcpiTable};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::vm::paddr_to_vaddr;
|
||||
|
||||
use super::{
|
||||
remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp},
|
||||
SdtHeaderWrapper,
|
||||
};
|
||||
use crate::vm::paddr_to_vaddr;
|
||||
|
||||
/// 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.
|
||||
|
@ -3,20 +3,21 @@
|
||||
pub mod dmar;
|
||||
pub mod remapping;
|
||||
|
||||
use alloc::borrow::ToOwned;
|
||||
use core::{
|
||||
ops::{Deref, DerefMut},
|
||||
ptr::NonNull,
|
||||
};
|
||||
|
||||
use crate::vm::paddr_to_vaddr;
|
||||
use acpi::{sdt::SdtHeader, AcpiHandler, AcpiTable, AcpiTables};
|
||||
use log::{info, warn};
|
||||
use spin::Once;
|
||||
|
||||
use crate::{
|
||||
boot::{self, BootloaderAcpiArg},
|
||||
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
|
||||
pub static ACPI_TABLES: Once<SpinLock<AcpiTables<AcpiMemoryHandler>>> = Once::new();
|
||||
|
@ -4,9 +4,8 @@
|
||||
//! 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.
|
||||
|
||||
use core::{fmt::Debug, mem::size_of};
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::{fmt::Debug, mem::size_of};
|
||||
|
||||
/// DMA-remapping hardware unit definition (DRHD).
|
||||
///
|
||||
|
@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
use acpi::PlatformInfo;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use bit_field::BitField;
|
||||
use log::info;
|
||||
use spin::Once;
|
||||
|
@ -1,11 +1,12 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::sync::Mutex;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::sync::Arc;
|
||||
use alloc::{boxed::Box, sync::Arc};
|
||||
|
||||
use log::info;
|
||||
use spin::Once;
|
||||
|
||||
use crate::sync::Mutex;
|
||||
|
||||
pub mod ioapic;
|
||||
pub mod x2apic;
|
||||
pub mod xapic;
|
||||
|
@ -1,11 +1,10 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::sync::Mutex;
|
||||
use crate::vm;
|
||||
use spin::Once;
|
||||
use x86::apic::xapic;
|
||||
|
||||
use super::ApicTimer;
|
||||
use crate::{sync::Mutex, vm};
|
||||
|
||||
const IA32_APIC_BASE_MSR: u32 = 0x1B;
|
||||
const IA32_APIC_BASE_MSR_BSP: u32 = 0x100; // Processor is a BSP
|
||||
|
@ -1,12 +1,14 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::arch::x86::device::io_port::{IoPort, WriteOnlyAccess};
|
||||
use crate::trap::IrqLine;
|
||||
use core::sync::atomic::Ordering::Relaxed;
|
||||
use core::sync::atomic::{AtomicBool, AtomicU8};
|
||||
use core::sync::atomic::{AtomicBool, AtomicU8, Ordering::Relaxed};
|
||||
|
||||
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_DATA: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0x21) };
|
||||
static SLAVE_CMD: IoPort<u8, WriteOnlyAccess> = unsafe { IoPort::new(0xA0) };
|
||||
|
@ -4,6 +4,7 @@ use core::{
|
||||
arch::x86_64::_rdtsc,
|
||||
sync::atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use trapframe::TrapFrame;
|
||||
use x86::cpuid::cpuid;
|
||||
|
@ -1,12 +1,13 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::sync::Mutex;
|
||||
use alloc::{collections::BTreeMap, fmt};
|
||||
|
||||
use pod::Pod;
|
||||
use x86_64::{instructions::tlb, structures::paging::PhysFrame, VirtAddr};
|
||||
|
||||
use crate::{
|
||||
config::ENTRY_COUNT,
|
||||
sync::Mutex,
|
||||
vm::{
|
||||
page_table::{table_of, PageTableEntryTrait, PageTableFlagsTrait},
|
||||
Paddr, Vaddr,
|
||||
|
@ -1,9 +1,11 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use tdx_guest::{
|
||||
serial_println, tdcall,
|
||||
tdcall::TdgVeInfo,
|
||||
tdvmcall,
|
||||
tdvmcall::{cpuid, hlt, rdmsr, wrmsr, IoSize},
|
||||
{serial_println, tdcall, tdvmcall, TdxVirtualExceptionType},
|
||||
TdxVirtualExceptionType,
|
||||
};
|
||||
|
||||
pub trait TdxTrapFrame {
|
||||
|
@ -1,22 +1,31 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use core::arch::x86_64::_rdtsc;
|
||||
use core::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use x86::cpuid::cpuid;
|
||||
use core::{
|
||||
arch::x86_64::_rdtsc,
|
||||
sync::atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use spin::Once;
|
||||
use trapframe::TrapFrame;
|
||||
use x86::msr::{wrmsr, IA32_TSC_DEADLINE};
|
||||
|
||||
use crate::arch::kernel::tsc::init_tsc_freq;
|
||||
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 x86::{
|
||||
cpuid::cpuid,
|
||||
msr::{wrmsr, IA32_TSC_DEADLINE},
|
||||
};
|
||||
|
||||
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() {
|
||||
init_tsc_freq();
|
||||
|
@ -1,15 +1,19 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{trap::IrqLine, vm::paddr_to_vaddr};
|
||||
use acpi::{AcpiError, HpetInfo};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use acpi::{AcpiError, HpetInfo};
|
||||
use spin::Once;
|
||||
use volatile::{
|
||||
access::{ReadOnly, ReadWrite},
|
||||
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();
|
||||
|
||||
const OFFSET_ID_REGISTER: usize = 0x000;
|
||||
|
@ -4,18 +4,17 @@ pub mod apic;
|
||||
pub mod hpet;
|
||||
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 core::{
|
||||
any::Any,
|
||||
sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering},
|
||||
};
|
||||
|
||||
use spin::Once;
|
||||
use trapframe::TrapFrame;
|
||||
|
||||
use crate::arch::x86::kernel;
|
||||
use crate::sync::SpinLock;
|
||||
use crate::trap::IrqLine;
|
||||
|
||||
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
|
||||
/// convenient for timer. What's more, the frequency cannot be set too high or too low, 1000Hz is
|
||||
|
@ -15,6 +15,7 @@ use alloc::{
|
||||
vec,
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
use log::warn;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
|
@ -7,13 +7,13 @@
|
||||
pub mod kcmdline;
|
||||
pub mod memory_region;
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
|
||||
use kcmdline::KCmdlineArg;
|
||||
use spin::Once;
|
||||
|
||||
use self::memory_region::MemoryRegion;
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use spin::Once;
|
||||
|
||||
/// ACPI information from the bootloader.
|
||||
///
|
||||
/// The boot crate can choose either providing the raw RSDP physical address or
|
||||
@ -119,9 +119,10 @@ pub fn call_aster_main() -> ! {
|
||||
}
|
||||
#[cfg(ktest)]
|
||||
{
|
||||
use crate::arch::qemu::{exit_qemu, QemuExitCode};
|
||||
use alloc::{boxed::Box, string::ToString};
|
||||
use core::any::Any;
|
||||
|
||||
use crate::arch::qemu::{exit_qemu, QemuExitCode};
|
||||
crate::init();
|
||||
let fn_catch_unwind = &(unwinding::panic::catch_unwind::<(), fn()>
|
||||
as fn(fn()) -> Result<(), Box<(dyn Any + Send + 'static)>>);
|
||||
|
@ -1,11 +1,11 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::{collections::VecDeque, fmt::Debug, sync::Arc, vec::Vec};
|
||||
|
||||
use log::{debug, error};
|
||||
|
||||
use crate::bus::BusProbeError;
|
||||
|
||||
use super::device::MmioCommonDevice;
|
||||
use crate::bus::BusProbeError;
|
||||
|
||||
pub trait MmioDevice: Sync + Send + Debug {
|
||||
fn device_id(&self) -> u32;
|
||||
|
@ -3,14 +3,13 @@
|
||||
use int_to_c_enum::TryFromInt;
|
||||
use log::info;
|
||||
|
||||
use super::VIRTIO_MMIO_MAGIC;
|
||||
use crate::{
|
||||
io_mem::IoMem,
|
||||
trap::IrqLine,
|
||||
vm::{paddr_to_vaddr, Paddr, VmIo},
|
||||
};
|
||||
|
||||
use super::VIRTIO_MMIO_MAGIC;
|
||||
|
||||
/// MMIO Common device.
|
||||
/// TODO: Implement universal access to MMIO devices since we are temporarily
|
||||
/// using specific virtio device as implementation of CommonDevice.
|
||||
|
@ -5,18 +5,17 @@
|
||||
pub mod bus;
|
||||
pub mod device;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::ops::Range;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use log::debug;
|
||||
|
||||
use self::bus::MmioBus;
|
||||
use crate::{
|
||||
arch::kernel::IO_APIC, bus::mmio::device::MmioCommonDevice, sync::SpinLock, trap::IrqLine,
|
||||
vm::paddr_to_vaddr,
|
||||
};
|
||||
|
||||
use self::bus::MmioBus;
|
||||
|
||||
const VIRTIO_MMIO_MAGIC: u32 = 0x74726976;
|
||||
|
||||
pub static MMIO_BUS: SpinLock<MmioBus> = SpinLock::new(MmioBus::new());
|
||||
|
@ -1,13 +1,12 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::{collections::VecDeque, sync::Arc, vec::Vec};
|
||||
use core::fmt::Debug;
|
||||
|
||||
use alloc::{collections::VecDeque, sync::Arc, vec::Vec};
|
||||
use log::{debug, error};
|
||||
|
||||
use crate::bus::BusProbeError;
|
||||
|
||||
use super::{device_info::PciDeviceId, PciCommonDevice};
|
||||
use crate::bus::BusProbeError;
|
||||
|
||||
pub trait PciDevice: Sync + Send + Debug {
|
||||
fn device_id(&self) -> PciDeviceId;
|
||||
|
@ -3,7 +3,6 @@
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use self::{msix::CapabilityMsixData, vendor::CapabilityVndrData};
|
||||
|
||||
use super::{
|
||||
cfg_space::{PciDeviceCommonCfgOffset, Status},
|
||||
common_device::PciCommonDevice,
|
||||
|
@ -1,7 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::bus::pci::{common_device::PciCommonDevice, device_info::PciDeviceLocation};
|
||||
use crate::{Error, Result};
|
||||
use crate::{
|
||||
bus::pci::{common_device::PciCommonDevice, device_info::PciDeviceLocation},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
|
@ -1,11 +1,11 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::sync::Arc;
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
use crate::{io_mem::IoMem, Error, Result};
|
||||
|
||||
use super::PciDeviceLocation;
|
||||
use crate::{io_mem::IoMem, Error, Result};
|
||||
|
||||
#[repr(u16)]
|
||||
pub enum PciDeviceCommonCfgOffset {
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
use core::iter;
|
||||
|
||||
use crate::arch::pci::{PCI_ADDRESS_PORT, PCI_DATA_PORT};
|
||||
|
||||
use super::cfg_space::PciDeviceCommonCfgOffset;
|
||||
use crate::arch::pci::{PCI_ADDRESS_PORT, PCI_DATA_PORT};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct PciDeviceId {
|
||||
|
@ -56,10 +56,10 @@ pub mod cfg_space;
|
||||
pub mod common_device;
|
||||
mod device_info;
|
||||
|
||||
use crate::sync::Mutex;
|
||||
pub use device_info::{PciDeviceId, PciDeviceLocation};
|
||||
|
||||
use self::{bus::PciBus, common_device::PciCommonDevice};
|
||||
use crate::sync::Mutex;
|
||||
|
||||
pub static PCI_BUS: Mutex<PciBus> = Mutex::new(PciBus::new());
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
//! CPU.
|
||||
|
||||
use core::{cell::UnsafeCell, ops::Deref};
|
||||
|
||||
use crate::trap::disable_local;
|
||||
use core::cell::UnsafeCell;
|
||||
use core::ops::Deref;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_arch = "x86_64")]{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use core::{mem::size_of, ops::Range};
|
||||
|
||||
use pod::Pod;
|
||||
|
||||
use crate::{
|
||||
|
@ -43,12 +43,11 @@ pub mod user;
|
||||
mod util;
|
||||
pub mod vm;
|
||||
|
||||
pub use self::cpu::CpuLocal;
|
||||
pub use self::error::Error;
|
||||
pub use self::prelude::Result;
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
use tdx_guest::init_tdx;
|
||||
|
||||
pub use self::{cpu::CpuLocal, error::Error, prelude::Result};
|
||||
|
||||
pub fn init() {
|
||||
arch::before_all_init();
|
||||
logger::init();
|
||||
|
@ -1,9 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{config::DEFAULT_LOG_LEVEL, early_println};
|
||||
|
||||
use log::{Metadata, Record};
|
||||
|
||||
use crate::{config::DEFAULT_LOG_LEVEL, early_println};
|
||||
|
||||
const LOGGER: Logger = Logger {};
|
||||
|
||||
struct Logger {}
|
||||
|
@ -5,14 +5,16 @@
|
||||
use alloc::{boxed::Box, string::ToString};
|
||||
use core::ffi::c_void;
|
||||
|
||||
use crate::arch::qemu::{exit_qemu, QemuExitCode};
|
||||
use crate::{early_print, early_println};
|
||||
use log::error;
|
||||
|
||||
use crate::{
|
||||
arch::qemu::{exit_qemu, QemuExitCode},
|
||||
early_print, early_println,
|
||||
};
|
||||
|
||||
extern crate cfg_if;
|
||||
extern crate gimli;
|
||||
use gimli::Register;
|
||||
|
||||
use unwinding::{
|
||||
abi::{
|
||||
UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_FindEnclosingFunction,
|
||||
|
@ -4,9 +4,7 @@
|
||||
|
||||
pub type Result<T> = core::result::Result<T, crate::error::Error>;
|
||||
|
||||
pub(crate) use alloc::boxed::Box;
|
||||
pub(crate) use alloc::sync::Arc;
|
||||
pub(crate) use alloc::vec::Vec;
|
||||
pub(crate) use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||
pub(crate) use core::any::Any;
|
||||
|
||||
pub use crate::vm::{Paddr, Vaddr};
|
||||
|
@ -1,7 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use core::fmt::{self};
|
||||
use core::sync::atomic::{AtomicU64, Ordering::Relaxed};
|
||||
use core::{
|
||||
fmt::{self},
|
||||
sync::atomic::{AtomicU64, Ordering::Relaxed},
|
||||
};
|
||||
|
||||
use align_ext::AlignExt;
|
||||
|
||||
|
@ -10,10 +10,12 @@ mod rwmutex;
|
||||
mod spin;
|
||||
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::rwlock::{RwLock, RwLockReadGuard, RwLockUpgradeableGuard, RwLockWriteGuard};
|
||||
pub use self::rwmutex::{RwMutex, RwMutexReadGuard, RwMutexUpgradeableGuard, RwMutexWriteGuard};
|
||||
pub use self::spin::{SpinLock, SpinLockGuard};
|
||||
pub use self::wait::WaitQueue;
|
||||
pub use self::{
|
||||
atomic_bits::AtomicBits,
|
||||
mutex::{Mutex, MutexGuard},
|
||||
rwlock::{RwLock, RwLockReadGuard, RwLockUpgradeableGuard, RwLockWriteGuard},
|
||||
rwmutex::{RwMutex, RwMutexReadGuard, RwMutexUpgradeableGuard, RwMutexWriteGuard},
|
||||
spin::{SpinLock, SpinLockGuard},
|
||||
wait::WaitQueue,
|
||||
};
|
||||
|
@ -1,11 +1,13 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::WaitQueue;
|
||||
use core::cell::UnsafeCell;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::{
|
||||
cell::UnsafeCell,
|
||||
fmt,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
|
||||
use core::fmt;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use super::WaitQueue;
|
||||
|
||||
/// A mutex with waitqueue.
|
||||
pub struct Mutex<T> {
|
||||
|
@ -1,14 +1,19 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use core::cell::UnsafeCell;
|
||||
use core::fmt;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::sync::atomic::AtomicUsize;
|
||||
use core::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
|
||||
use core::{
|
||||
cell::UnsafeCell,
|
||||
fmt,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::atomic::{
|
||||
AtomicUsize,
|
||||
Ordering::{AcqRel, Acquire, Relaxed, Release},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::task::{disable_preempt, DisablePreemptGuard};
|
||||
use crate::trap::disable_local;
|
||||
use crate::trap::DisabledLocalIrqGuard;
|
||||
use crate::{
|
||||
task::{disable_preempt, DisablePreemptGuard},
|
||||
trap::{disable_local, DisabledLocalIrqGuard},
|
||||
};
|
||||
|
||||
/// Spin-based Read-write Lock
|
||||
///
|
||||
|
@ -1,10 +1,14 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use core::cell::UnsafeCell;
|
||||
use core::fmt;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::sync::atomic::AtomicUsize;
|
||||
use core::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
|
||||
use core::{
|
||||
cell::UnsafeCell,
|
||||
fmt,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::atomic::{
|
||||
AtomicUsize,
|
||||
Ordering::{AcqRel, Acquire, Relaxed, Release},
|
||||
},
|
||||
};
|
||||
|
||||
use super::WaitQueue;
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use core::cell::UnsafeCell;
|
||||
use core::fmt;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use core::{
|
||||
cell::UnsafeCell,
|
||||
fmt,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
|
||||
use crate::task::{disable_preempt, DisablePreemptGuard};
|
||||
use crate::trap::disable_local;
|
||||
use crate::trap::DisabledLocalIrqGuard;
|
||||
use crate::{
|
||||
task::{disable_preempt, DisablePreemptGuard},
|
||||
trap::{disable_local, DisabledLocalIrqGuard},
|
||||
};
|
||||
|
||||
/// A spin lock.
|
||||
pub struct SpinLock<T> {
|
||||
|
@ -1,13 +1,18 @@
|
||||
// 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 bitflags::bitflags;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use core::time::Duration;
|
||||
use core::{
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
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.
|
||||
///
|
||||
|
@ -8,7 +8,9 @@ mod scheduler;
|
||||
#[allow(clippy::module_inception)]
|
||||
mod task;
|
||||
|
||||
pub use self::priority::Priority;
|
||||
pub use self::processor::{current_task, disable_preempt, preempt, schedule, DisablePreemptGuard};
|
||||
pub use self::scheduler::{add_task, set_scheduler, Scheduler};
|
||||
pub use self::task::{Task, TaskAdapter, TaskOptions, TaskStatus};
|
||||
pub use self::{
|
||||
priority::Priority,
|
||||
processor::{current_task, disable_preempt, preempt, schedule, DisablePreemptGuard},
|
||||
scheduler::{add_task, set_scheduler, Scheduler},
|
||||
task::{Task, TaskAdapter, TaskOptions, TaskStatus},
|
||||
};
|
||||
|
@ -1,20 +1,16 @@
|
||||
// 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 crate::sync::Mutex;
|
||||
use crate::trap::disable_local;
|
||||
|
||||
use core::sync::atomic::Ordering::Relaxed;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use super::{
|
||||
scheduler::{fetch_task, GLOBAL_SCHEDULER},
|
||||
task::{context_switch, TaskContext},
|
||||
Task, TaskStatus,
|
||||
};
|
||||
use alloc::sync::Arc;
|
||||
use lazy_static::lazy_static;
|
||||
use crate::{cpu_local, sync::Mutex, trap::disable_local};
|
||||
|
||||
pub struct Processor {
|
||||
current: Option<Arc<Task>>,
|
||||
|
@ -1,11 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::sync::SpinLock;
|
||||
use crate::task::Task;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::{prelude::*, sync::SpinLock, task::Task};
|
||||
|
||||
lazy_static! {
|
||||
pub(crate) static ref GLOBAL_SCHEDULER: SpinLock<GlobalScheduler> =
|
||||
SpinLock::new(GlobalScheduler { scheduler: None });
|
||||
|
@ -1,20 +1,21 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::arch::mm::PageTableFlags;
|
||||
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, LinkedListAtomicLink};
|
||||
|
||||
use intrusive_collections::intrusive_adapter;
|
||||
use intrusive_collections::LinkedListAtomicLink;
|
||||
|
||||
use super::add_task;
|
||||
use super::priority::Priority;
|
||||
use super::processor::{current_task, schedule};
|
||||
use super::{
|
||||
add_task,
|
||||
priority::Priority,
|
||||
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"));
|
||||
|
||||
|
@ -2,12 +2,14 @@
|
||||
|
||||
//! 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};
|
||||
|
||||
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.
|
||||
///
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
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")]
|
||||
use tdx_guest::tdcall;
|
||||
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")]
|
||||
impl TdxTrapFrame for TrapFrame {
|
||||
fn rax(&self) -> usize {
|
||||
|
@ -1,12 +1,16 @@
|
||||
// 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 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;
|
||||
|
||||
/// An Interrupt ReQuest(IRQ) line. User can use `alloc` or `alloc_specific` to get specific IRQ line.
|
||||
|
@ -3,11 +3,12 @@
|
||||
mod handler;
|
||||
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 trapframe::TrapFrame;
|
||||
|
||||
pub(crate) use self::handler::call_irq_callback_functions;
|
||||
pub use self::irq::{disable_local, DisabledLocalIrqGuard, IrqCallbackFunction, IrqLine};
|
||||
|
||||
pub(crate) fn init() {
|
||||
unsafe {
|
||||
trapframe::init();
|
||||
|
@ -2,12 +2,10 @@
|
||||
|
||||
//! User space.
|
||||
|
||||
use crate::cpu::UserContext;
|
||||
use crate::prelude::*;
|
||||
use crate::task::Task;
|
||||
use crate::vm::VmSpace;
|
||||
use trapframe::TrapFrame;
|
||||
|
||||
use crate::{cpu::UserContext, prelude::*, task::Task, vm::VmSpace};
|
||||
|
||||
/// A user space.
|
||||
///
|
||||
/// Each user space has a VM address space and allows a task to execute in
|
||||
|
@ -3,15 +3,16 @@
|
||||
use alloc::sync::Arc;
|
||||
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 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,
|
||||
/// which guarantees that the device and the CPU can
|
||||
@ -163,9 +164,10 @@ impl HasPaddr for DmaCoherent {
|
||||
|
||||
#[if_cfg_ktest]
|
||||
mod test {
|
||||
use alloc::vec;
|
||||
|
||||
use super::*;
|
||||
use crate::vm::VmAllocOptions;
|
||||
use alloc::vec;
|
||||
|
||||
#[ktest]
|
||||
fn map_with_coherent_device() {
|
||||
|
@ -1,18 +1,17 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use core::arch::x86_64::_mm_clflush;
|
||||
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 core::{arch::x86_64::_mm_clflush, ops::Range};
|
||||
|
||||
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
|
||||
/// before reading or after writing to ensure consistency.
|
||||
@ -198,9 +197,10 @@ impl HasPaddr for DmaStream {
|
||||
|
||||
#[if_cfg_ktest]
|
||||
mod test {
|
||||
use alloc::vec;
|
||||
|
||||
use super::*;
|
||||
use crate::vm::VmAllocOptions;
|
||||
use alloc::vec;
|
||||
|
||||
#[ktest]
|
||||
fn streaming_map() {
|
||||
|
@ -4,14 +4,13 @@ mod dma_coherent;
|
||||
mod dma_stream;
|
||||
|
||||
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_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
|
||||
/// memory, the addresses used by the device are device addresses.
|
||||
|
@ -6,13 +6,12 @@ use core::{
|
||||
marker::PhantomData,
|
||||
ops::{BitAnd, BitOr, Not, Range},
|
||||
};
|
||||
|
||||
use pod::Pod;
|
||||
|
||||
use super::{frame_allocator, HasPaddr, Paddr, VmIo};
|
||||
use crate::{config::PAGE_SIZE, prelude::*, Error};
|
||||
|
||||
use super::{frame_allocator, HasPaddr};
|
||||
use super::{Paddr, VmIo};
|
||||
|
||||
/// A collection of page frames (physical memory pages).
|
||||
///
|
||||
/// For the most parts, `VmFrameVec` is like `Vec<VmFrame>`. But the
|
||||
|
@ -1,15 +1,18 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use align_ext::AlignExt;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use align_ext::AlignExt;
|
||||
use buddy_system_allocator::FrameAllocator;
|
||||
use log::info;
|
||||
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 crate::{
|
||||
boot::memory_region::{MemoryRegion, MemoryRegionType},
|
||||
config::PAGE_SIZE,
|
||||
sync::SpinLock,
|
||||
};
|
||||
|
||||
pub(super) static FRAME_ALLOCATOR: Once<SpinLock<FrameAllocator>> = Once::new();
|
||||
|
||||
|
@ -1,20 +1,23 @@
|
||||
// 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::{
|
||||
alloc::{GlobalAlloc, Layout},
|
||||
ptr::NonNull,
|
||||
};
|
||||
|
||||
use align_ext::AlignExt;
|
||||
use buddy_system_allocator::Heap;
|
||||
use log::debug;
|
||||
|
||||
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]
|
||||
static HEAP_ALLOCATOR: LockedHeapWithRescue<32> = LockedHeapWithRescue::new(rescue);
|
||||
|
@ -1,9 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::prelude::*;
|
||||
use inherit_methods_macro::inherit_methods;
|
||||
use pod::Pod;
|
||||
|
||||
use inherit_methods_macro::inherit_methods;
|
||||
use crate::prelude::*;
|
||||
|
||||
/// A trait that enables reading/writing data from/to a VM object,
|
||||
/// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`.
|
||||
|
@ -1,15 +1,16 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::collections::{btree_map::Entry, BTreeMap};
|
||||
use core::fmt;
|
||||
|
||||
use super::page_table::{PageTable, PageTableConfig, UserMode};
|
||||
use crate::{
|
||||
arch::mm::{PageTableEntry, PageTableFlags},
|
||||
config::{PAGE_SIZE, PHYS_OFFSET},
|
||||
vm::is_page_aligned,
|
||||
vm::{VmAllocOptions, VmFrame, VmFrameVec, VmReader, VmWriter},
|
||||
prelude::*,
|
||||
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)]
|
||||
pub struct MapArea {
|
||||
|
@ -19,24 +19,23 @@ mod options;
|
||||
pub(crate) mod page_table;
|
||||
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 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
|
||||
pub trait HasPaddr {
|
||||
|
@ -1,8 +1,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{prelude::*, Error};
|
||||
|
||||
use super::{frame::VmFrameFlags, frame_allocator, VmFrame, VmFrameVec, VmSegment};
|
||||
use crate::{prelude::*, Error};
|
||||
|
||||
/// Options for allocating physical memory pages (or frames).
|
||||
///
|
||||
|
@ -1,5 +1,12 @@
|
||||
// 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 crate::{
|
||||
arch::mm::{is_kernel_vaddr, is_user_vaddr, tlb_flush, PageTableEntry},
|
||||
@ -7,11 +14,6 @@ use crate::{
|
||||
sync::SpinLock,
|
||||
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 {
|
||||
fn new() -> Self;
|
||||
|
@ -1,17 +1,11 @@
|
||||
// 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 super::VmFrameVec;
|
||||
use super::{is_page_aligned, Vaddr};
|
||||
use super::{MapArea, MemorySet};
|
||||
use crate::{prelude::*, Error};
|
||||
use bitflags::bitflags;
|
||||
|
||||
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.
|
||||
///
|
||||
|
@ -3,17 +3,17 @@
|
||||
//! Test runner enabling control over the tests.
|
||||
//!
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::format_args;
|
||||
|
||||
use owo_colors::OwoColorize;
|
||||
|
||||
use crate::{
|
||||
path::{KtestPath, SuffixTrie},
|
||||
tree::{KtestCrate, KtestTree},
|
||||
CatchUnwindImpl, KtestError, KtestItem, KtestIter,
|
||||
};
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::format_args;
|
||||
|
||||
use owo_colors::OwoColorize;
|
||||
|
||||
pub enum KtestResult {
|
||||
Ok,
|
||||
Failed,
|
||||
|
@ -262,10 +262,10 @@ const EDDMAXNR: usize = 6;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use core::mem::offset_of;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_screen_info_offsets() {
|
||||
assert_eq!(offset_of!(ScreenInfo, orig_x), 0x00);
|
||||
|
@ -22,9 +22,8 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use xmas_elf::program::SegmentData;
|
||||
|
||||
use mapping::{SetupFileOffset, SetupVA};
|
||||
use xmas_elf::program::SegmentData;
|
||||
|
||||
/// The type of the bzImage that we are building through `make_bzimage`.
|
||||
///
|
||||
|
@ -8,11 +8,11 @@
|
||||
//! The reference to the Linux PE header definition:
|
||||
//! https://github.com/torvalds/linux/blob/master/include/linux/pe.h
|
||||
|
||||
use std::{mem::size_of, ops::Range};
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use serde::Serialize;
|
||||
|
||||
use std::{mem::size_of, ops::Range};
|
||||
|
||||
use crate::mapping::{SetupFileOffset, SetupVA, LEGACY_SETUP_SEC_SIZE, SETUP32_LMA};
|
||||
|
||||
// The MS-DOS header.
|
||||
|
@ -1,15 +1,16 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use linux_boot_params::BootParams;
|
||||
use uefi::{
|
||||
data_types::Handle,
|
||||
proto::loaded_image::LoadedImage,
|
||||
table::{boot::MemoryMap, Boot, Runtime, SystemTable},
|
||||
};
|
||||
|
||||
use linux_boot_params::BootParams;
|
||||
|
||||
use super::paging::{Ia32eFlags, PageNumber, PageTableCreator};
|
||||
use super::relocation::apply_rela_dyn_relocations;
|
||||
use super::{
|
||||
paging::{Ia32eFlags, PageNumber, PageTableCreator},
|
||||
relocation::apply_rela_dyn_relocations,
|
||||
};
|
||||
|
||||
#[export_name = "efi_stub_entry"]
|
||||
extern "sysv64" fn efi_stub_entry(handle: Handle, mut system_table: SystemTable<Boot>) -> ! {
|
||||
|
@ -1,9 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use linux_boot_params::BootParams;
|
||||
|
||||
use core::arch::{asm, global_asm};
|
||||
|
||||
use linux_boot_params::BootParams;
|
||||
|
||||
global_asm!(include_str!("header.S"));
|
||||
|
||||
global_asm!(include_str!("setup.S"));
|
||||
|
@ -1,9 +1,10 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// Copyright(c) 2023-2024 Intel Corporation.
|
||||
|
||||
use crate::{tdcall::TdcallArgs, tdvmcall::TdVmcallArgs};
|
||||
use core::arch::global_asm;
|
||||
|
||||
use crate::{tdcall::TdcallArgs, tdvmcall::TdVmcallArgs};
|
||||
|
||||
global_asm!(include_str!("tdcall.asm"));
|
||||
global_asm!(include_str!("tdvmcall.asm"));
|
||||
|
||||
|
@ -11,12 +11,14 @@ mod asm;
|
||||
pub mod tdcall;
|
||||
pub mod tdvmcall;
|
||||
|
||||
pub use self::tdcall::{get_veinfo, TdxVirtualExceptionType};
|
||||
pub use self::tdvmcall::print;
|
||||
|
||||
use raw_cpuid::{native_cpuid::cpuid_count, CpuIdResult};
|
||||
use tdcall::{InitError, TdgVpInfo};
|
||||
|
||||
pub use self::{
|
||||
tdcall::{get_veinfo, TdxVirtualExceptionType},
|
||||
tdvmcall::print,
|
||||
};
|
||||
|
||||
pub fn init_tdx() -> Result<TdgVpInfo, InitError> {
|
||||
check_tdx_guest()?;
|
||||
Ok(tdcall::get_tdinfo()?)
|
||||
|
@ -5,10 +5,12 @@
|
||||
//! 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)
|
||||
|
||||
use crate::asm::asm_td_call;
|
||||
use bitflags::bitflags;
|
||||
use core::fmt;
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
use crate::asm::asm_td_call;
|
||||
|
||||
/// TDCALL Instruction Leaf Numbers Definition.
|
||||
#[repr(u64)]
|
||||
pub enum TdcallNum {
|
||||
|
@ -8,15 +8,17 @@
|
||||
//! resumes the TD via a SEAMCALL [TDH.VP.ENTER] invocation.
|
||||
extern crate alloc;
|
||||
|
||||
use crate::asm::asm_td_vmcall;
|
||||
use alloc::fmt;
|
||||
use bitflags::bitflags;
|
||||
use core::fmt::Write;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use x86_64::{
|
||||
registers::rflags::{self, RFlags},
|
||||
structures::port::PortRead,
|
||||
};
|
||||
|
||||
use crate::asm::asm_td_vmcall;
|
||||
|
||||
/// TDVMCALL Instruction Leaf Numbers Definition.
|
||||
#[repr(u64)]
|
||||
pub enum TdVmcallNum {
|
||||
|
Reference in New Issue
Block a user