Skip to main content

ostd/specs/arch/
mod.rs

1//! Architecture selection and shared memory specifications.
2//!
3//! # Verified Properties
4//!
5//! [`CurrentArch`] selects the target's implementation of the contracts in [`model`].
6//! The erased [`valid_frame_paddr`] predicate requires base-page alignment and an
7//! address below that implementation's modeled physical-memory bound. Shared
8//! constants are re-exported from the executable architecture and memory modules.
9//! The model's conversion lemmas establish bounds, round trips, and alignment
10//! within the linear mapping window. Paging configurations must prove the layout
11//! requirements declared by `PagingConstsTrait`.
12use vstd::prelude::*;
13
14use crate::mm::{
15    Paddr, Vaddr,
16    kspace::{LINEAR_MAPPING_BASE_VADDR, VMALLOC_BASE_VADDR, paddr_to_vaddr},
17};
18
19pub mod model;
20pub use model::*;
21
22// Compatibility re-exports for proof modules that still use `specs::arch`.
23// The authoritative values live in the executable memory/architecture modules.
24pub use crate::{
25    arch::mm::{NR_ENTRIES, NR_LEVELS, PAGE_SIZE},
26    mm::{MAX_NR_PAGES, MAX_PADDR},
27};
28
29#[cfg(target_arch = "x86_64")]
30mod x86;
31#[cfg(target_arch = "x86_64")]
32pub use x86::*;
33
34#[cfg(target_arch = "riscv64")]
35mod riscv;
36#[cfg(target_arch = "riscv64")]
37pub use riscv::*;
38
39#[cfg(target_arch = "loongarch64")]
40mod loongarch;
41#[cfg(target_arch = "loongarch64")]
42pub use loongarch::*;
43verus! {
44
45/// The architecture selected by the current verification target.
46#[cfg(target_arch = "x86_64")]
47pub type CurrentArch = x86::X86Arch;
48
49/// The architecture selected by the current verification target.
50#[cfg(target_arch = "riscv64")]
51pub type CurrentArch = riscv::RiscvArch;
52
53#[cfg(target_arch = "loongarch64")]
54pub type CurrentArch = loongarch::LoongArch;
55
56/// A physical address that can identify a base-page frame on the selected architecture.
57pub open spec fn valid_frame_paddr(paddr: Paddr) -> bool {
58    valid_frame_paddr_for::<CurrentArch>(paddr)
59}
60
61pub proof fn lemma_linear_mapping_base_vaddr_properties()
62    ensures
63        LINEAR_MAPPING_BASE_VADDR % PAGE_SIZE == 0,
64        LINEAR_MAPPING_BASE_VADDR < VMALLOC_BASE_VADDR,
65{
66    CurrentArch::lemma_model_requirements();
67}
68
69/// Converts a virtual address in the linear mapping to a physical address.
70#[verifier::inline]
71pub open spec fn vaddr_to_paddr(va: Vaddr) -> usize
72    recommends
73        LINEAR_MAPPING_BASE_VADDR <= va < VMALLOC_BASE_VADDR,
74{
75    model::vaddr_to_paddr_for::<CurrentArch>(va)
76}
77
78/// Relates the current linear mapping to its architecture model and inverse.
79pub broadcast proof fn lemma_paddr_to_vaddr_properties(pa: Paddr)
80    requires
81        pa < VMALLOC_BASE_VADDR - LINEAR_MAPPING_BASE_VADDR,
82    ensures
83        #[trigger] paddr_to_vaddr(pa) == model::paddr_to_vaddr_for::<CurrentArch>(pa),
84        LINEAR_MAPPING_BASE_VADDR <= #[trigger] paddr_to_vaddr(pa) < VMALLOC_BASE_VADDR,
85        #[trigger] vaddr_to_paddr(paddr_to_vaddr(pa)) == pa,
86{
87    lemma_paddr_to_vaddr_properties_for::<CurrentArch>(pa);
88}
89
90pub broadcast proof fn lemma_vaddr_to_paddr_properties(va: Vaddr)
91    requires
92        LINEAR_MAPPING_BASE_VADDR <= va < VMALLOC_BASE_VADDR,
93    ensures
94        #[trigger] vaddr_to_paddr(va) < VMALLOC_BASE_VADDR - LINEAR_MAPPING_BASE_VADDR,
95        #[trigger] paddr_to_vaddr(vaddr_to_paddr(va)) == va,
96{
97    lemma_vaddr_to_paddr_properties_for::<CurrentArch>(va);
98}
99
100pub proof fn lemma_max_paddr_range()
101    ensures
102        MAX_PADDR < VMALLOC_BASE_VADDR - LINEAR_MAPPING_BASE_VADDR,
103        MAX_PADDR + LINEAR_MAPPING_BASE_VADDR < usize::MAX,
104{
105    CurrentArch::lemma_model_requirements();
106}
107
108} // verus!