diff --git a/Cargo.lock b/Cargo.lock index 6b1ae0e164..f04678404a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,6 +212,9 @@ dependencies = [ [[package]] name = "rmm" version = "0.1.0" +dependencies = [ + "bitflags 2.10.0", +] [[package]] name = "rustc-demangle" diff --git a/rmm/Cargo.toml b/rmm/Cargo.toml index 2fd94bd4bf..cbd10da6e2 100644 --- a/rmm/Cargo.toml +++ b/rmm/Cargo.toml @@ -4,10 +4,10 @@ version = "0.1.0" authors = ["Jeremy Soller "] edition = "2024" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +bitflags = "2" [features] -default = [] std = [] [[bin]] diff --git a/rmm/src/arch/aarch64.rs b/rmm/src/arch/aarch64.rs index d45fd6e059..fdf95afab9 100644 --- a/rmm/src/arch/aarch64.rs +++ b/rmm/src/arch/aarch64.rs @@ -99,6 +99,13 @@ impl Arch for AArch64Arch { } } +bitflags::bitflags! { + pub struct EntryFlags: usize { + const NO_CACHE = 1 << 2; + const DEV_MEM = 2 << 2; + } +} + const _: () = { assert!(AArch64Arch::PAGE_SIZE == 4096); assert!(AArch64Arch::PAGE_OFFSET_MASK == 0xFFF); diff --git a/rmm/src/arch/mod.rs b/rmm/src/arch/mod.rs index a6f072a17e..ee32fd58f4 100644 --- a/rmm/src/arch/mod.rs +++ b/rmm/src/arch/mod.rs @@ -3,27 +3,16 @@ use core::ptr; use crate::{PhysicalAddress, TableKind, VirtualAddress}; //TODO: Support having all page tables compile on all architectures +#[cfg(target_pointer_width = "64")] +pub mod aarch64; #[cfg(all(feature = "std", target_pointer_width = "64"))] -pub use self::emulate::EmulateArch; +pub mod emulate; +#[cfg(target_pointer_width = "64")] +pub mod riscv64; #[cfg(target_pointer_width = "32")] -pub use self::x86::X86Arch; +pub mod x86; #[cfg(target_pointer_width = "64")] -pub use self::{ - aarch64::AArch64Arch, - riscv64::{RiscV64Sv39Arch, RiscV64Sv48Arch}, - x86_64::X8664Arch, -}; - -#[cfg(target_pointer_width = "64")] -mod aarch64; -#[cfg(all(feature = "std", target_pointer_width = "64"))] -mod emulate; -#[cfg(target_pointer_width = "64")] -mod riscv64; -#[cfg(target_pointer_width = "32")] -mod x86; -#[cfg(target_pointer_width = "64")] -mod x86_64; +pub mod x86_64; pub trait Arch: Clone + Copy { /// Does the architecture use a separate page table for the kernel. diff --git a/rmm/src/arch/riscv64/mod.rs b/rmm/src/arch/riscv64/mod.rs index 894ef349e4..647c364372 100644 --- a/rmm/src/arch/riscv64/mod.rs +++ b/rmm/src/arch/riscv64/mod.rs @@ -3,3 +3,11 @@ pub use sv48::RiscV64Sv48Arch; mod sv39; mod sv48; + +bitflags::bitflags! { + pub struct EntryFlags: usize { + const NO_CACHE = 1 << 4; + const DEV_MEM = 0; + const WRITE_COMBINING = 0; + } +} diff --git a/rmm/src/arch/x86.rs b/rmm/src/arch/x86.rs index 6b506c33e7..7921f5c4db 100644 --- a/rmm/src/arch/x86.rs +++ b/rmm/src/arch/x86.rs @@ -57,6 +57,15 @@ impl Arch for X86Arch { } } +bitflags::bitflags! { + pub struct EntryFlags: usize { + const NO_CACHE = 1 << 4; + const HUGE_PAGE = 1 << 7; + const GLOBAL = 1 << 8; + const DEV_MEM = 0; + } +} + const _: () = { assert!(X86Arch::PAGE_SIZE == 4096); assert!(X86Arch::PAGE_OFFSET_MASK == 0xFFF); diff --git a/rmm/src/arch/x86_64.rs b/rmm/src/arch/x86_64.rs index 2dc2efbd42..36e82f4ebe 100644 --- a/rmm/src/arch/x86_64.rs +++ b/rmm/src/arch/x86_64.rs @@ -60,6 +60,15 @@ impl Arch for X8664Arch { } } +bitflags::bitflags! { + pub struct EntryFlags: usize { + const NO_CACHE = 1 << 4; + const HUGE_PAGE = 1 << 7; + const GLOBAL = 1 << 8; + const DEV_MEM = 0; + } +} + const _: () = { assert!(X8664Arch::PAGE_SIZE == 4096); assert!(X8664Arch::PAGE_OFFSET_MASK == 0xFFF); diff --git a/rmm/src/main.rs b/rmm/src/main.rs index 10ec7a8bc0..e0c6455a5d 100644 --- a/rmm/src/main.rs +++ b/rmm/src/main.rs @@ -1,7 +1,7 @@ #![cfg(target_pointer_width = "64")] use rmm::{ - Arch, BuddyAllocator, BumpAllocator, EmulateArch, Flusher, FrameAllocator, FrameCount, + emulate::EmulateArch, Arch, BuddyAllocator, BumpAllocator, Flusher, FrameAllocator, FrameCount, MemoryArea, PageFlags, PageFlushAll, PageMapper, PageTable, PhysicalAddress, TableKind, VirtualAddress, GIGABYTE, KILOBYTE, MEGABYTE, TERABYTE, }; diff --git a/src/acpi/hpet.rs b/src/acpi/hpet.rs index ed02c8128e..d25f4a5d1f 100644 --- a/src/acpi/hpet.rs +++ b/src/acpi/hpet.rs @@ -60,7 +60,7 @@ impl Hpet { unsafe { use crate::{ memory::{Frame, KernelMapper}, - paging::{entry::EntryFlags, Page, VirtualAddress}, + paging::{EntryFlags, Page, VirtualAddress}, }; use rmm::PageFlags; diff --git a/src/arch/aarch64/mod.rs b/src/arch/aarch64/mod.rs index 1e9e203328..ddd338cc2d 100644 --- a/src/arch/aarch64/mod.rs +++ b/src/arch/aarch64/mod.rs @@ -32,7 +32,7 @@ pub mod vectors; pub mod time; -pub use ::rmm::AArch64Arch as CurrentRmmArch; +pub use ::rmm::aarch64::AArch64Arch as CurrentRmmArch; pub use arch_copy_to_user as arch_copy_from_user; diff --git a/src/arch/aarch64/paging/entry.rs b/src/arch/aarch64/paging/entry.rs deleted file mode 100644 index 63c78e5d53..0000000000 --- a/src/arch/aarch64/paging/entry.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! # Page table entry -//! Some code borrowed from [Phil Opp's Blog](http://os.phil-opp.com/modifying-page-tables.html) - -bitflags! { - pub struct EntryFlags: usize { - const NO_CACHE = 1 << 2; - const DEV_MEM = 2 << 2; - } -} diff --git a/src/arch/aarch64/paging/mod.rs b/src/arch/aarch64/paging/mod.rs index 019628429b..02455fd77e 100644 --- a/src/arch/aarch64/paging/mod.rs +++ b/src/arch/aarch64/paging/mod.rs @@ -4,11 +4,12 @@ use crate::device::cpu::registers::control_regs; pub use super::CurrentRmmArch as RmmA; -pub use rmm::{Arch as RmmArch, PageFlags, PhysicalAddress, TableKind, VirtualAddress}; +pub use rmm::{ + aarch64::EntryFlags, Arch as RmmArch, PageFlags, PhysicalAddress, TableKind, VirtualAddress, +}; pub type PageMapper = rmm::PageMapper; -pub mod entry; pub mod mapper; /// Size of pages diff --git a/src/arch/riscv64/mod.rs b/src/arch/riscv64/mod.rs index 6893aa44d8..9fca214972 100644 --- a/src/arch/riscv64/mod.rs +++ b/src/arch/riscv64/mod.rs @@ -10,7 +10,7 @@ pub mod start; pub mod stop; pub mod time; -pub use ::rmm::RiscV64Sv48Arch as CurrentRmmArch; +pub use ::rmm::riscv64::RiscV64Sv48Arch as CurrentRmmArch; use core::arch::naked_asm; pub use arch_copy_to_user as arch_copy_from_user; diff --git a/src/arch/riscv64/paging/entry.rs b/src/arch/riscv64/paging/entry.rs deleted file mode 100644 index affe00f6d8..0000000000 --- a/src/arch/riscv64/paging/entry.rs +++ /dev/null @@ -1,11 +0,0 @@ -/// A page table entry -#[repr(packed(8))] -pub struct Entry(u64); - -bitflags! { - pub struct EntryFlags: usize { - const NO_CACHE = 1 << 4; - const DEV_MEM = 0; - const WRITE_COMBINING = 0; - } -} diff --git a/src/arch/riscv64/paging/mod.rs b/src/arch/riscv64/paging/mod.rs index 194cf7f043..0ac3e5dba5 100644 --- a/src/arch/riscv64/paging/mod.rs +++ b/src/arch/riscv64/paging/mod.rs @@ -1,12 +1,13 @@ #![allow(unused)] pub use super::CurrentRmmArch as RmmA; -pub use rmm::{Arch as RmmArch, PageFlags, PhysicalAddress, TableKind, VirtualAddress}; +pub use rmm::{ + aarch64::EntryFlags, Arch as RmmArch, PageFlags, PhysicalAddress, TableKind, VirtualAddress, +}; pub type PageMapper = rmm::PageMapper; pub use crate::rmm::KernelMapper; -pub mod entry; pub mod mapper; /// Size of pages diff --git a/src/arch/x86_shared/device/ioapic.rs b/src/arch/x86_shared/device/ioapic.rs index f7ada2d4aa..f0503a0c8d 100644 --- a/src/arch/x86_shared/device/ioapic.rs +++ b/src/arch/x86_shared/device/ioapic.rs @@ -9,7 +9,7 @@ use crate::acpi::madt::{self, Madt, MadtEntry, MadtIntSrcOverride, MadtIoApic}; use crate::{ arch::interrupt::irq, memory::{Frame, KernelMapper}, - paging::{entry::EntryFlags, Page, PageFlags, PhysicalAddress}, + paging::{EntryFlags, Page, PageFlags, PhysicalAddress}, }; use super::{local_apic::ApicId, pic}; diff --git a/src/arch/x86_shared/mod.rs b/src/arch/x86_shared/mod.rs index c0ca8d868e..3878669fb7 100644 --- a/src/arch/x86_shared/mod.rs +++ b/src/arch/x86_shared/mod.rs @@ -36,7 +36,7 @@ pub mod stop; pub mod time; #[cfg(target_arch = "x86")] -pub use ::rmm::X86Arch as CurrentRmmArch; +pub use ::rmm::x86::X86Arch as CurrentRmmArch; #[cfg(target_arch = "x86_64")] -pub use ::rmm::X8664Arch as CurrentRmmArch; +pub use ::rmm::x86_64::X8664Arch as CurrentRmmArch; diff --git a/src/arch/x86_shared/paging/mod.rs b/src/arch/x86_shared/paging/mod.rs index 18f1e69652..51f45e5c75 100644 --- a/src/arch/x86_shared/paging/mod.rs +++ b/src/arch/x86_shared/paging/mod.rs @@ -10,16 +10,10 @@ pub use rmm::{Arch as RmmArch, PageFlags, PhysicalAddress, TableKind, VirtualAdd pub type PageMapper = rmm::PageMapper; -pub mod entry { - bitflags! { - pub struct EntryFlags: usize { - const NO_CACHE = 1 << 4; - const HUGE_PAGE = 1 << 7; - const GLOBAL = 1 << 8; - const DEV_MEM = 0; - } - } -} +#[cfg(target_arch = "x86")] +pub use rmm::x86::EntryFlags; +#[cfg(target_arch = "x86_64")] +pub use rmm::x86_64::EntryFlags; pub mod mapper; diff --git a/src/memory/mod.rs b/src/memory/mod.rs index affe5f4b74..ce18237ecd 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -20,7 +20,7 @@ use crate::{ memory::{AccessMode, PfError}, }, kernel_executable_offsets::{__usercopy_end, __usercopy_start}, - paging::{entry::EntryFlags, Page, PageFlags}, + paging::{EntryFlags, Page, PageFlags}, sync::CleanLockToken, syscall::error::{Error, ENOMEM}, }; diff --git a/src/scheme/memory.rs b/src/scheme/memory.rs index e45f213418..c5634117e3 100644 --- a/src/scheme/memory.rs +++ b/src/scheme/memory.rs @@ -9,18 +9,14 @@ use crate::{ memory::{handle_notify_files, AddrSpace, AddrSpaceWrapper, Grant, PageSpan}, }, memory::{free_frames, used_frames, Frame, PAGE_SIZE}, - paging::VirtualAddress, + paging::{EntryFlags, VirtualAddress}, sync::CleanLockToken, - syscall::usercopy::UserSliceRw, -}; - -use crate::paging::entry::EntryFlags; - -use crate::syscall::{ - data::{Map, StatVfs}, - error::*, - flag::MapFlags, - usercopy::UserSliceWo, + syscall::{ + data::{Map, StatVfs}, + error::*, + flag::MapFlags, + usercopy::{UserSliceRw, UserSliceWo}, + }, }; use super::{CallerCtx, KernelScheme, OpenResult, StrOrBytes}; diff --git a/src/startup/memory.rs b/src/startup/memory.rs index 1ac3ffdf1f..24fc8f56c6 100644 --- a/src/startup/memory.rs +++ b/src/startup/memory.rs @@ -1,5 +1,5 @@ use crate::{ - arch::{consts::KERNEL_OFFSET, paging::entry::EntryFlags, rmm::page_flags, CurrentRmmArch}, + arch::{consts::KERNEL_OFFSET, paging::EntryFlags, rmm::page_flags, CurrentRmmArch}, memory::PAGE_SIZE, startup::{memory::BootloaderMemoryKind::Null, KernelArgs}, };