Skip to content

Commit 34e078e

Browse files
committed
fix: restore target specific dependencies
1 parent d4d79d3 commit 34e078e

File tree

7 files changed

+59
-119
lines changed

7 files changed

+59
-119
lines changed

Cargo.lock

Lines changed: 28 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

page_table_entry/Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ rust-version.workspace = true
1515
[features]
1616
arm-el2 = []
1717

18-
all = []
18+
all = ["dep:aarch64-cpu", "dep:x86_64"]
1919

2020
[dependencies]
2121
bitflags = "2.9"
2222
memory_addr.workspace = true
2323

24-
[dev-dependencies]
24+
# Target-specific dependencies
25+
aarch64-cpu = { version = "10.0", optional = true }
26+
x86_64 = { version = "0.15", optional = true }
27+
28+
[target.'cfg(target_arch = "aarch64")'.dependencies]
2529
aarch64-cpu = "10.0"
2630

31+
[target.'cfg(target_arch = "x86_64")'.dependencies]
32+
x86_64 = "0.15"
33+
2734
[package.metadata.docs.rs]
2835
all-features = true

page_table_entry/src/arch/aarch64.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,17 @@ impl DescriptorAttr {
9898
impl MemAttr {
9999
/// The MAIR_ELx register should be set to this value to match the memory
100100
/// attributes in the descriptors.
101-
///
102-
/// ```
103-
/// # use aarch64_cpu::registers::MAIR_EL1;
104-
/// # use page_table_entry::aarch64::MemAttr;
105-
/// // Device-nGnRE memory
106-
/// let attr0 = MAIR_EL1::Attr0_Device::nonGathering_nonReordering_EarlyWriteAck.value;
107-
/// // Normal memory
108-
/// let attr1 = MAIR_EL1::Attr1_Normal_Inner::WriteBack_NonTransient_ReadWriteAlloc.value
109-
/// | MAIR_EL1::Attr1_Normal_Outer::WriteBack_NonTransient_ReadWriteAlloc.value;
110-
/// let attr2 = MAIR_EL1::Attr2_Normal_Inner::NonCacheable.value
111-
/// + MAIR_EL1::Attr2_Normal_Outer::NonCacheable.value;
112-
/// assert_eq!(MemAttr::MAIR_VALUE, attr0 | attr1 | attr2);
113-
/// ```
114-
pub const MAIR_VALUE: u64 = 0x44_ff_04;
101+
pub const MAIR_VALUE: u64 = {
102+
use aarch64_cpu::registers::MAIR_EL1;
103+
// Device-nGnRE memory
104+
let attr0 = MAIR_EL1::Attr0_Device::nonGathering_nonReordering_EarlyWriteAck.value;
105+
// Normal memory
106+
let attr1 = MAIR_EL1::Attr1_Normal_Inner::WriteBack_NonTransient_ReadWriteAlloc.value
107+
| MAIR_EL1::Attr1_Normal_Outer::WriteBack_NonTransient_ReadWriteAlloc.value;
108+
let attr2 = MAIR_EL1::Attr2_Normal_Inner::NonCacheable.value
109+
+ MAIR_EL1::Attr2_Normal_Outer::NonCacheable.value;
110+
attr0 | attr1 | attr2
111+
};
115112
}
116113

117114
impl From<DescriptorAttr> for MappingFlags {

page_table_entry/src/arch/x86_64.rs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,10 @@
22
33
use core::fmt;
44
use memory_addr::PhysAddr;
5+
use x86_64::structures::paging::page_table::PageTableFlags as PTF;
56

67
use crate::{GenericPTE, MappingFlags};
78

8-
bitflags::bitflags! {
9-
/// Possible flags for a page table entry.
10-
///
11-
/// Reference: https://docs.rs/crate/x86_64/0.15.2/source/src/structures/paging/page_table.rs
12-
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
13-
pub struct PTF: u64 {
14-
/// Specifies whether the mapped frame or page table is loaded in memory.
15-
const PRESENT = 1;
16-
/// Controls whether writes to the mapped frames are allowed.
17-
///
18-
/// If this bit is unset in a level 1 page table entry, the mapped frame is read-only.
19-
/// If this bit is unset in a higher level page table entry the complete range of mapped
20-
/// pages is read-only.
21-
const WRITABLE = 1 << 1;
22-
/// Controls whether accesses from userspace (i.e. ring 3) are permitted.
23-
const USER_ACCESSIBLE = 1 << 2;
24-
/// If this bit is set, a “write-through” policy is used for the cache, else a “write-back”
25-
/// policy is used.
26-
const WRITE_THROUGH = 1 << 3;
27-
/// Disables caching for the pointed entry is cacheable.
28-
const NO_CACHE = 1 << 4;
29-
/// Set by the CPU when the mapped frame or page table is accessed.
30-
const ACCESSED = 1 << 5;
31-
/// Set by the CPU on a write to the mapped frame.
32-
const DIRTY = 1 << 6;
33-
/// Specifies that the entry maps a huge frame instead of a page table. Only allowed in
34-
/// P2 or P3 tables.
35-
const HUGE_PAGE = 1 << 7;
36-
/// Indicates that the mapping is present in all address spaces, so it isn't flushed from
37-
/// the TLB on an address space switch.
38-
const GLOBAL = 1 << 8;
39-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
40-
const BIT_9 = 1 << 9;
41-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
42-
const BIT_10 = 1 << 10;
43-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
44-
const BIT_11 = 1 << 11;
45-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
46-
const BIT_52 = 1 << 52;
47-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
48-
const BIT_53 = 1 << 53;
49-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
50-
const BIT_54 = 1 << 54;
51-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
52-
const BIT_55 = 1 << 55;
53-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
54-
const BIT_56 = 1 << 56;
55-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
56-
const BIT_57 = 1 << 57;
57-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
58-
const BIT_58 = 1 << 58;
59-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
60-
const BIT_59 = 1 << 59;
61-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
62-
const BIT_60 = 1 << 60;
63-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
64-
const BIT_61 = 1 << 61;
65-
/// Available to the OS, can be used to store additional data, e.g. custom flags.
66-
const BIT_62 = 1 << 62;
67-
/// Forbid code execution from the mapped frames.
68-
///
69-
/// Can be only used when the no-execute page protection feature is enabled in the EFER
70-
/// register.
71-
const NO_EXECUTE = 1 << 63;
72-
}
73-
}
74-
759
impl From<PTF> for MappingFlags {
7610
fn from(f: PTF) -> Self {
7711
if !f.contains(PTF::PRESENT) {

page_table_multiarch/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ rust-version.workspace = true
1616
default = []
1717
copy-from = ["dep:bitmaps"]
1818

19-
all = ["page_table_entry/all"]
19+
all = ["page_table_entry/all", "dep:riscv", "dep:x86_64"]
2020

2121
[dependencies]
2222
log = "0.4"
2323
memory_addr.workspace = true
2424
page_table_entry.workspace = true
2525
bitmaps = { version = "3.2", default-features = false, optional = true }
2626

27+
# Target-specific dependencies
28+
riscv = { version = "0.14", default-features = false, optional = true }
29+
x86_64 = { version = "0.15", optional = true }
30+
2731
[target.'cfg(target_arch = "x86_64")'.dependencies]
28-
x86 = "0.52"
32+
x86_64 = "0.15"
2933

3034
[target.'cfg(any(target_arch = "riscv32", target_arch = "riscv64"))'.dependencies]
3135
riscv = { version = "0.14", default-features = false }

page_table_multiarch/src/arch/riscv.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ pub trait SvVirtAddr: memory_addr::MemoryAddr + Send + Sync {
1212
impl SvVirtAddr for memory_addr::VirtAddr {
1313
#[inline]
1414
fn flush_tlb(vaddr: Option<Self>) {
15-
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
1615
if let Some(vaddr) = vaddr {
1716
riscv::asm::sfence_vma(0, vaddr.as_usize())
1817
} else {
1918
riscv::asm::sfence_vma_all();
2019
}
21-
#[cfg(not(any(target_arch = "riscv32", target_arch = "riscv64")))]
22-
let _ = vaddr;
2320
}
2421
}
2522

page_table_multiarch/src/arch/x86_64.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ impl PagingMetaData for X64PagingMetaData {
1414

1515
#[inline]
1616
fn flush_tlb(vaddr: Option<memory_addr::VirtAddr>) {
17-
#[cfg(target_arch = "x86_64")]
18-
unsafe {
19-
if let Some(vaddr) = vaddr {
20-
x86::tlb::flush(vaddr.into());
21-
} else {
22-
x86::tlb::flush_all();
23-
}
17+
if let Some(vaddr) = vaddr {
18+
x86_64::instructions::tlb::flush(x86_64::VirtAddr::new(vaddr.as_usize() as u64));
19+
} else {
20+
x86_64::instructions::tlb::flush_all();
2421
}
25-
#[cfg(not(target_arch = "x86_64"))]
26-
let _ = vaddr;
2722
}
2823
}
2924

0 commit comments

Comments
 (0)