Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions proofs/Fl4Spec/PORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ Conventions of the ported base layer that later modules rely on.
`timeoutMessage` (C `TIMEOUT_REPLY_MESSAGE`), `arch_cap_badge`,
`reply_bits` (5), `parse_time_arg`, `words_from_time`; `ntfn_bits` is the
MCS value 6, not X64's non-MCS 5.
- **FL4 deviation, initial user selectors.** The x86-64 user context starts
with `CS = 0x33` and `SS = 0x2B`, matching [the Rust register constants](../../crates/fl4-core/src/arch/x86_64/regs.rs#L16-L17).
The pinned l4v context starts with `CS = 0x2B` and `SS = 0x33`.
- **FL4 extension, architecture-relative object codes 7–11.** [`archDataToObjType`](Decode.lean#L461-L475)
decodes these as VCPU, EPT PML4, EPT PDPT, EPT PD, and EPT PT, respectively.
The pinned l4v decoder returns `None` for each of these codes.
- **FL4 deviation, 1 GiB pages only with CPU support** (#65): `arch_state`
has an extra field `x64Plat` (the platform record `X64Platform`, set at
boot and never written after), whose `hugePages` is FL4's ks `FEATURES &
Expand Down
124 changes: 124 additions & 0 deletions proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchCap.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import L4vRefX64.Equiv.ArchVSpace
import L4vRefX64.Spec.ArchCSpace_A
import L4vRefX64.Spec.ArchIpcCancel_A

namespace L4vRefX64.Equiv.ArchCap

open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel
open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Machine
open Fl4Spec Classical

noncomputable section

theorem archIsPhysical_eq (cap : Arch_Structs_A.arch_cap) :
Fl4Spec.archIsPhysical (embArchCap cap) = ArchCSpace_A.arch_is_physical cap := by
cases cap <;> rfl

theorem updateCnodeCapData_eq (data : Word) :
Fl4Spec.updateCnodeCapData data = ArchCSpace_A.update_cnode_cap_data data := by
unfold Fl4Spec.updateCnodeCapData ArchCSpace_A.update_cnode_cap_data
simp only [holLet, holUnsigned, holWordAnd, holWordShiftr,
ArchCSpace_A.cnode_guard_size_bits, ArchCSpace_A.cnode_padding_bits,
HolNumeral.ofNatVal, HolZero.zeroVal, HolAdd.addVal, mask_eq]
rfl

theorem archSameRegionAs_iff (a b : Arch_Structs_A.arch_cap) :
ArchCSpace_A.arch_same_region_as a b = true ↔
Fl4Spec.archSameRegionAs (embArchCap a) (embArchCap b) := by
cases a <;> cases b <;>
simp [ArchCSpace_A.arch_same_region_as, Fl4Spec.archSameRegionAs, embArchCap,
holEx_eq_true, holEq_eq_true, holConj_eq_true, holDisj_eq_true, holLe_eq_true,
HolOrd.leVal, holLet, HolAdd.addVal, HolSub.subVal, HolOne.oneVal, holWordShiftl,
pageBitsForSize_eq, and_assoc, and_comm, and_left_comm]

theorem sameAobjectAs_iff (a b : Arch_Structs_A.arch_cap) :
ArchCSpace_A.same_aobject_as a b = true ↔
Fl4Spec.sameAobjectAs (embArchCap a) (embArchCap b) := by
cases a <;> cases b <;>
simp only [ArchCSpace_A.same_aobject_as, holCaseProd, Arch_Structs_A.case_arch_cap,
embArchCap, Fl4Spec.sameAobjectAs]
all_goals first
| exact archSameRegionAs_iff _ _
| simp [holEq_eq_true, holConj_eq_true, holLe_eq_true, HolOrd.leVal, HolAdd.addVal,
HolSub.subVal, HolOne.oneVal, pageBitsForSize_eq, embVMPageSize_injective.eq_iff]
rename_i dev ref rights mapType pageSize mapping dev' ref' rights' mapType' pageSize' mapping'
intro hdev href hsize
cases pageSize <;> rfl

theorem archIsCapRevocable_iff (newCap srcCap : Structures_A.cap) :
ArchCSpace_A.arch_is_cap_revocable newCap srcCap = true ↔
Fl4Spec.archIsCapRevocable (embCap newCap) (embCap srcCap) := by
unfold ArchCSpace_A.arch_is_cap_revocable Fl4Spec.archIsCapRevocable
have hport : (∃ f l, newCap = .ArchObjectCap (.IOPortCap f l)) ↔
∃ f l owner, embCap newCap = .archObjectCap (.ioPortCap f l owner) := by
cases newCap with
| ArchObjectCap arch => cases arch <;> simp [embCap, embArchCap]
| _ => simp [embCap]
simp only [holIf_eq, holEx_eq_true, holEq_eq_true, hport]
split
· rw [holEq_eq_true]
change srcCap = .ArchObjectCap .IOPortControlCap ↔
embCap srcCap = embCap (.ArchObjectCap .IOPortControlCap)
exact embCap_injective.eq_iff.symm
· simp

theorem archCapCleanupOpt_eq (cap : Arch_Structs_A.arch_cap) :
Fl4Spec.archCapCleanupOpt (embArchCap cap) = embCap (ArchIpcCancel_A.arch_cap_cleanup_opt cap) := by
cases cap <;> rfl

def embArchGenObjRef : ArchIpcCancel_A.arch_gen_obj_ref → Fl4Spec.ArchGenObjRef
| .IOPortRef port => .ioPortRef port

theorem archGenObjRefs_eq (cap : Arch_Structs_A.arch_cap) :
Fl4Spec.archGenObjRefs (embArchCap cap) =
embArchGenObjRef '' ArchIpcCancel_A.arch_gen_obj_refs cap := by
cases cap <;>
simp [Fl4Spec.archGenObjRefs, ArchIpcCancel_A.arch_gen_obj_refs, Arch_Structs_A.case_arch_cap,
embArchCap, embArchGenObjRef, HolCompleteLattice.holBot, holImage, holInsert, Set.image_singleton]
case IOPortCap first last =>
have hs : Set.insert first (∅ : Set (BitVec 16)) = {first} := by
ext port
simp [Set.insert]
rw [hs, Set.image_singleton, Set.image_singleton]
rfl

variable {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop}
variable {ZH ZL : Type} [Nonempty ZH] [Deterministic_A.state_ext_class ZH] [StateExt ZL]
variable [ser : StateExtRel RestRel ZH ZL]

local notation "SR" => StateRel RestRel ser.exstRel

theorem archDeriveCap_equiv (cap : Arch_Structs_A.arch_cap) :
MRelE SR (FunRel embSyscallError) (FunRel embCap)
(ArchVSpace_A.arch_derive_cap cap) (Fl4Spec.archDeriveCap (embArchCap cap)) := by
cases cap with
| PageTableCap _ mapping | PageDirectoryCap _ mapping | PDPointerTableCap _ mapping
| PML4Cap _ mapping =>
cases mapping
· exact mrele_throwError rfl
· exact mrele_returnOk rfl
| _ => exact mrele_returnOk rfl

theorem setIoportMask_equiv (first last : BitVec 16) (value : Bool) :
MRel SR Eq (ArchIpcCancel_A.set_ioport_mask first last value) (Fl4Spec.setIoportMask first last value) := by
unfold ArchIpcCancel_A.set_ioport_mask Fl4Spec.setIoportMask
refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ hs => by rw [hs.archState_eq]; rfl)
fun portsH portsL hports => ?_
subst hports
refine mrel_bind (mrel_return (Ra := Eq) ?_) fun newH newL hnew => ?_
· funext port
simp [holIf_eq, holConj_eq_true, holLe_eq_true, HolOrd.leVal]
· subst hnew
refine mrel_modify fun _ _ hs => ?_
have harch := congrArg (fun ar : ArchState => { ar with x64AllocatedIoPorts := newH }) hs.archState_eq
exact { hs with archState_eq := harch }

theorem archPostCapDeletion_equiv (cap : Arch_Structs_A.arch_cap) :
MRel SR Eq (ArchIpcCancel_A.arch_post_cap_deletion cap) (Fl4Spec.archPostCapDeletion (embArchCap cap)) := by
cases cap with
| IOPortCap first last => exact setIoportMask_equiv first last false
| _ => exact mrel_return rfl

end

end L4vRefX64.Equiv.ArchCap
Loading