diff --git a/proofs/Fl4Spec/PORTING.md b/proofs/Fl4Spec/PORTING.md index b892bf2c5..13995d52c 100644 --- a/proofs/Fl4Spec/PORTING.md +++ b/proofs/Fl4Spec/PORTING.md @@ -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 & diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchCap.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchCap.lean new file mode 100644 index 000000000..4f5671960 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchCap.lean @@ -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 diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchDecode.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchDecode.lean new file mode 100644 index 000000000..d88157cbf --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchDecode.lean @@ -0,0 +1,1274 @@ +import L4vRefX64.Equiv.Decode +import L4vRefX64.Equiv.VSpaceAccess + +namespace L4vRefX64.Equiv.ArchDecode + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Deterministic +open L4vRefX64.Equiv.CSpace L4vRefX64.Equiv.VSpaceRoot L4vRefX64.Equiv.VSpaceAccess +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.Types L4vRefX64.Equiv.Decode +open Fl4Spec Classical + +noncomputable section + +theorem attribsFromWord_eq (word : Data) : + Fl4Spec.attribsFromWord word = embVMAttrs (ArchVMAttributes_A.attribs_from_word word) := by + unfold Fl4Spec.attribsFromWord ArchVMAttributes_A.attribs_from_word embVMAttrs + simp only [Fl4Spec.testBit, holLet_eq, holIf_eq, holWordBit, HolZero.zeroVal, + HolOne.oneVal, HolNumeral.ofNatVal] + split_ifs <;> + simp [holInsert_eq, HolCompleteLattice.holBot, embVMAttribute, embTableAttr, Set.image_insert_eq] + +theorem filterVmAttributes_eq (attrs : Set ArchVMAttributes_A.vm_attribute) : + Fl4Spec.filterVmAttributes (embVMAttrs attrs) = embTableAttrs (ArchDecode_A.filter_vm_attributes attrs) := by + ext attr + simp only [Fl4Spec.filterVmAttributes, ArchDecode_A.filter_vm_attributes, embVMAttrs, embTableAttrs, + holCollect_eq, Set.mem_ofPred_eq, Set.mem_image, holBex, decide_eq_true_eq, holEq_eq_true] + constructor + · rintro ⟨v, ⟨u, hu, rfl⟩, hv⟩ + cases u with + | PTAttr original => + exact ⟨original, ⟨.PTAttr original, hu, rfl⟩, VMAttribute.ptAttr.inj hv⟩ + | _ => cases hv + · rintro ⟨original, ⟨u, hu, rfl⟩, rfl⟩ + exact ⟨.ptAttr (embTableAttr original), ⟨.PTAttr original, hu, rfl⟩, 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 + +private theorem lookupErrorOnFailure_step {αH αL : Type} [Nonempty αH] + {Ra : αH → αL → Prop} (source : Bool) + {mH : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure αH)} + {mL : LFMonad ZL αL} {sH : Structures_A.state ZH} {sL : State ZL} + (hm : MRelStep SR (SumExceptRel (FunRel embLookupFailure) Ra) (mH sH) (mL.run sL)) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) Ra) + (Exceptions_A.lookup_error_on_failure source mH sH) ((Fl4Spec.lookupErrorOnFailure source mL).run sL) := by + unfold Exceptions_A.lookup_error_on_failure Fl4Spec.lookupErrorOnFailure + refine mrelStep_handleE_mem hm fun eH eL he tH tL ht _ => ?_ + subst he + exact mrele_throwError (by simp [FunRel, embSyscallError]) tH tL ht + + +private theorem checkedUnit_state {σ ε : Type} {s next : σ} {u : Unit} (b : Bool) (err : ε) + (hm : (Sum.inr u, next) ∈ (holWhenE b (holThrowError err) s).1) : next = s := by + cases b <;> simp [holWhenE, holThrowError, holReturnOk, holReturn] at hm + exact hm + +private theorem returnOk_value_state {σ ε α : Type} {s next : σ} {x y : α} + (hm : (Sum.inr (α := ε) x, next) ∈ (holReturnOk y s).1) : x = y ∧ next = s := by + simpa only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] using hm + +private def read_root_cap (cap : Structures_A.cap) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error (ObjRef × Asid)) := + match cap with + | .ArchObjectCap (.PML4Cap ptr (some asid)) => holReturnOk (ptr, asid) + | _ => holThrowError (.InvalidCapability 1) + +private theorem read_root_cap_equiv (cap : Structures_A.cap) : + MRelE SR (FunRel embSyscallError) Eq (read_root_cap cap) + (match embCap cap with + | .archObjectCap (.pml4Cap ptr (some asid)) => NonDetE.returnOk (ptr, asid) + | _ => NonDetE.throwError (.invalidCapability 1)) := by + cases cap with + | ArchObjectCap arch => + cases arch with + | PML4Cap _ map => cases map <;> first | exact mrele_returnOk rfl | exact mrele_throwError rfl + | _ => exact mrele_throwError rfl + | _ => exact mrele_throwError rfl + +omit [Nonempty ZH] [Deterministic_A.state_ext_class ZH] in +private theorem read_root_cap_reached {s next : Structures_A.state ZH} + {cap : Structures_A.cap} {root : ObjRef} {asid : Asid} + (hm : (Sum.inr (root, asid), next) ∈ (read_root_cap cap s).1) : + next = s ∧ cap = .ArchObjectCap (.PML4Cap root (some asid)) := by + cases cap with + | ArchObjectCap arch => + cases arch with + | PML4Cap ptr map => + cases map with + | none => simp [read_root_cap, holThrowError, holReturn] at hm + | some mapped => + have hm' := returnOk_value_state (show (Sum.inr (α := ExceptionTypes_A.syscall_error) + (root, asid), next) ∈ (holReturnOk (ptr, mapped) s).1 from hm) + obtain ⟨eq, heq⟩ := hm' + obtain ⟨rfl, rfl⟩ := Prod.mk.inj eq + exact ⟨heq, rfl⟩ + | _ => simp [read_root_cap, holThrowError, holReturn] at hm + | _ => simp [read_root_cap, holThrowError, holReturn] at hm + +private def table_mapping_p + (mapping : Option (Asid × VSpaceRef)) (bits : Nat) (vaddr : VSpaceRef) (rootCap : Structures_A.cap) + (next : ObjRef → Asid → VSpaceRef → + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + holBindE (holWhenE (holNot (holEq mapping none)) (holThrowError (.InvalidCapability 0))) (holKBind + (holBindE (holReturnOk (holWordAnd vaddr (holWordNot (holWordMask bits)))) fun aligned => + holBindE (read_root_cap rootCap) fun (root, asid) => + holBindE (holWhenE (holLt Machine_A.user_vtop aligned) (holThrowError (.InvalidArgument 0))) (holKBind + (holBindE (Exceptions_A.lookup_error_on_failure false (ArchVSpace_A.find_vspace_for_asid asid)) fun found => + holBindE (holWhenE (holNot (holEq found root)) (holThrowError (.InvalidCapability 1))) + (holKBind (next root asid aligned)))))) + +private theorem tableMapping_equiv + (mapping : Option (Asid × VSpaceRef)) (bits : Nat) (vaddr : VSpaceRef) (rootCap : Structures_A.cap) + {nextH : ObjRef → Asid → VSpaceRef → + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation)} + {nextL : ObjRef → Asid → VSpaceRef → SEMonad ZL ArchInvocation} + (hnext : ∀ root asid aligned, + MRelE SR (FunRel embSyscallError) (FunRel embArchInv) + (nextH root asid aligned) (nextL root asid aligned)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hroot : ∀ root asid, rootCap = .ArchObjectCap (.PML4Cap root (some asid)) → BaseAsid asid) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (table_mapping_p mapping bits vaddr rootCap nextH sH) + ((do + NonDetE.whenE (mapping ≠ none) (NonDetE.throwError (.invalidCapability 0)) + let aligned ← NonDetE.returnOk (vaddr &&& ~~~(Fl4Spec.mask bits)) + let (root, asid) ← (match embCap rootCap with + | .archObjectCap (.pml4Cap ptr (some asid)) => NonDetE.returnOk (ptr, asid) + | _ => NonDetE.throwError (.invalidCapability 1) : SEMonad ZL (ObjRef × Asid)) + NonDetE.whenE (Fl4Spec.userVtop < aligned) (NonDetE.throwError (.invalidArgument 0)) + let found ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.findVspaceForAsid asid) + NonDetE.whenE (found ≠ root) (NonDetE.throwError (.invalidCapability 1)) + nextL root asid aligned : SEMonad ZL ArchInvocation).run sL) := by + unfold table_mapping_p + refine mrelStep_kbindE_mem + (mrele_whenE (Re := FunRel embSyscallError) (by simp [holNot_eq_true, holEq_eq_true]) (fun _ => mrele_throwError rfl) sH sL hs) + fun u tH tL ht hm => ?_ + have hst := checkedUnit_state _ (ExceptionTypes_A.syscall_error.InvalidCapability 0) hm + subst tH + have hmasks : holWordAnd vaddr (holWordNot (holWordMask bits)) = + (vaddr &&& ~~~(Fl4Spec.mask bits)) := by rw [mask_eq]; rfl + refine mrelStep_bindE_mem (mrele_returnOk (Re := FunRel embSyscallError) (Ra := Eq) hmasks _ _ ht) + fun aH aL ha vH vL hv hm2 => ?_ + subst ha + have he := (returnOk_value_state hm2).2 + subst vH + refine mrelStep_bindE_mem (read_root_cap_equiv rootCap sH vL hv) + fun pH pL hp wH wL hw hm3 => ?_ + subst hp + obtain ⟨root, asid⟩ := pH + obtain ⟨heq, hparsed⟩ := read_root_cap_reached hm3 + subst wH + refine mrelStep_kbindE_mem (mrele_whenE (Re := FunRel embSyscallError) (by rw [holLt_eq_true]; rfl) + (fun _ => mrele_throwError rfl) _ _ hw) fun v xH xL hx hm4 => ?_ + have hst' := checkedUnit_state _ (ExceptionTypes_A.syscall_error.InvalidArgument 0) hm4 + subst xH + have hb' := hx.baseCarriers_iff.mpr (hs.baseCarriers_iff.mp hb) + refine mrelStep_bindE_mem + (lookupErrorOnFailure_step false (findVspaceForAsid_equiv asid (hroot root asid hparsed) hx hb')) + fun fH fL hf yH yL hy _ => ?_ + subst hf + exact mrele_kbindE (mrele_whenE (Re := FunRel embSyscallError) (by simp [holNot_eq_true, holEq_eq_true]) + (fun _ => mrele_throwError rfl)) (hnext root asid aH) yH yL hy + + +/-- The native PML4 caps returned by extra-capability lookup have upstream-width ASIDs. -/ +def RootCapsInBaseRange (caps : List (Structures_A.cap × CslotPtr)) : Prop := + ∀ root asid slot, (.ArchObjectCap (.PML4Cap root (some asid)), slot) ∈ caps → BaseAsid asid + +private def table_decoder_p (mapLabel unmapLabel : ArchInvocationLabels_H.arch_invocation_label) + (label : Data) (args : List Data) (caps : List (Structures_A.cap × CslotPtr)) + (cap : Arch_Structs_A.arch_cap) (mapping : Option (Asid × VSpaceRef)) (bits : Nat) + (map : ObjRef → Asid → VSpaceRef → + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation)) + (unmap : ArchInvocation_A.arch_invocation) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel mapLabel)) + (holIf (holConj (holLt 1 args.length) (holLt 0 caps.length)) + (table_mapping_p mapping bits (holNth args 0) (holNth caps 0).1 map) + (holThrowError .TruncatedMessage)) + (holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel unmapLabel)) + (holBindE (holLiftE (IpcCancel_A.is_final_cap (.ArchObjectCap cap))) fun final => + holBindE (holUnlessE final (holThrowError .RevokeFirst)) (holKBind (holReturnOk unmap))) + (holThrowError .IllegalOperation)) + + +omit [StateExt ZL] in +private theorem bindRootCap_eq {α : Type} (cap : Cap) + (next : ObjRef × Asid → SEMonad ZL α) : + (do + let (root, asid) ← match cap with + | .archObjectCap (.pml4Cap root (some asid)) => NonDetE.returnOk (root, asid) + | _ => NonDetE.throwError (.invalidCapability 1) + next (root, asid) : SEMonad ZL α) = + ((match cap with + | .archObjectCap (.pml4Cap root (some asid)) => NonDetE.returnOk (root, asid) + | _ => NonDetE.throwError (.invalidCapability 1) : SEMonad ZL (ObjRef × Asid)) >>= next) := by + cases cap with + | archObjectCap arch => + cases arch with + | pml4Cap _ map => cases map <;> rfl + | _ => rfl + | _ => rfl + +private theorem tableDecoder_equiv (mapLabel unmapLabel : ArchInvocationLabels_H.arch_invocation_label) + (label : Data) (args : List Data) (caps : List (Structures_A.cap × CslotPtr)) + (cap : Arch_Structs_A.arch_cap) (mapping : Option (Asid × VSpaceRef)) (bits : Nat) + {mapH : ObjRef → Asid → VSpaceRef → + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation)} + {mapL : ObjRef → Asid → VSpaceRef → SEMonad ZL ArchInvocation} + (hmap : ∀ root asid aligned, MRelE SR (FunRel embSyscallError) (FunRel embArchInv) + (mapH root asid aligned) (mapL root asid aligned)) + (unmap : ArchInvocation_A.arch_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hbase : RootCapsInBaseRange caps) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (table_decoder_p mapLabel unmapLabel label args caps cap mapping bits mapH unmap sH) + ((if Fl4Spec.invocationType label = embInvocationLabel (.ArchInvocationLabel mapLabel) then + if args.length > 1 ∧ (caps.map fun (p : Structures_A.cap × CslotPtr) => match p with | (c, sl) => (embCap c, sl)).length > 0 then do + let rootCap := (the ((caps.map fun (p : Structures_A.cap × CslotPtr) => match p with | (c, sl) => (embCap c, sl))[0]?)).1 + NonDetE.whenE (mapping ≠ none) (NonDetE.throwError (.invalidCapability 0)) + let aligned ← NonDetE.returnOk ((the args[0]?) &&& ~~~(Fl4Spec.mask bits)) + let (root, asid) ← match rootCap with + | .archObjectCap (.pml4Cap ptr (some asid)) => NonDetE.returnOk (ptr, asid) + | _ => NonDetE.throwError (.invalidCapability 1) + NonDetE.whenE (Fl4Spec.userVtop < aligned) (NonDetE.throwError (.invalidArgument 0)) + let found ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.findVspaceForAsid asid) + NonDetE.whenE (found ≠ root) (NonDetE.throwError (.invalidCapability 1)) + mapL root asid aligned + else NonDetE.throwError .truncatedMessage + else if Fl4Spec.invocationType label = embInvocationLabel (.ArchInvocationLabel unmapLabel) then do + let final ← NonDetE.liftE (Fl4Spec.isFinalCap (embCap (.ArchObjectCap cap))) + NonDetE.unlessE final (NonDetE.throwError .revokeFirst) + NonDetE.returnOk (embArchInv unmap) + else NonDetE.throwError .illegalOperation : SEMonad ZL ArchInvocation).run sL) := by + unfold table_decoder_p + by_cases hm : Fl4Spec.invocationType label = embInvocationLabel (.ArchInvocationLabel mapLabel) + · rw [holIf_eq, ite_eq_left ((archInvocationLabel_iff label _).mpr hm), ite_eq_left hm] + have hlen : holConj (holLt 1 args.length) (holLt 0 caps.length) = true ↔ + 1 < args.length ∧ 0 < (caps.map fun (p : Structures_A.cap × CslotPtr) => match p with | (c, sl) => (embCap c, sl)).length := by + rw [holConj_eq_true, holLt_eq_true, holLt_eq_true, List.length_map] + rfl + by_cases hargs : 1 < args.length ∧ 0 < caps.length + · rw [holIf_eq, ite_eq_left (hlen.mpr (by simpa only [List.length_map] using hargs)), + ite_eq_left (by simpa only [List.length_map] using hargs)] + dsimp only + have hmap0 := the_getElem_map + (fun (p : Structures_A.cap × CslotPtr) => match p with | (c, sl) => (embCap c, sl)) caps 0 hargs.2 + rw [hmap0] + have he : (match holNth caps 0 with | (c, sl) => (embCap c, sl)).1 = + embCap (holNth caps 0).1 := by cases holNth caps 0; rfl + rw [he] + have hjoin (aligned : VSpaceRef) := bindRootCap_eq (embCap (holNth caps 0).1) + (fun p => do + NonDetE.whenE (Fl4Spec.userVtop < aligned) (NonDetE.throwError (.invalidArgument 0)) + let found ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.findVspaceForAsid p.2) + NonDetE.whenE (found ≠ p.1) (NonDetE.throwError (.invalidCapability 1)) + mapL p.1 p.2 aligned) + simp only [hjoin] + apply tableMapping_equiv mapping bits _ _ hmap hs hb + intro root asid hr + have hmem : holNth caps 0 ∈ caps := by + simp only [holNth, List.getElem?_eq_getElem hargs.2, holTheOpt] + exact List.getElem_mem _ + have heq : holNth caps 0 = (.ArchObjectCap (.PML4Cap root (some asid)), (holNth caps 0).2) := + Prod.ext hr rfl + rw [heq] at hmem + exact hbase root asid _ hmem + · have hnot : ¬(1 < args.length ∧ 0 < (caps.map fun (p : Structures_A.cap × CslotPtr) => match p with | (c, sl) => (embCap c, sl)).length) := by + simpa only [List.length_map] using hargs + rw [holIf_eq, ite_eq_right (mt hlen.mp hnot), ite_eq_right hnot] + exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + · rw [holIf_eq, ite_eq_right (mt (archInvocationLabel_iff label _).mp hm), ite_eq_right hm] + exact (mrele_if (Re := FunRel embSyscallError) (Ra := FunRel embArchInv) + (archInvocationLabel_iff label (.ArchInvocationLabel unmapLabel)) + (fun _ => by + refine mrele_bindE (mrele_liftE (isFinalCap_equiv (.ArchObjectCap cap))) fun fH fL hf => ?_ + subst hf + exact mrele_kbindE (mrele_unlessE Iff.rfl (fun _ => mrele_throwError rfl)) (mrele_returnOk rfl)) + (fun _ => mrele_throwError rfl)) sH sL hs + +/-- l4v: ArchDecode_A.decode_page_table_invocation, with the FL4 invocation ABI. -/ +def decode_page_table_invocation_p (label : Data) (args : List Data) (slot : CslotPtr) + (ptr : ObjRef) (mapping : Option (Asid × VSpaceRef)) (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + table_decoder_p .X64PageTableMap .X64PageTableUnmap label args caps (.PageTableCap ptr mapping) + mapping Arch_Structs_A.pd_shift_bits + (fun root asid addr => + holBindE (Exceptions_A.lookup_error_on_failure false (ArchVSpaceAcc_A.lookup_pd_slot root addr)) fun target => + holBindE (holLiftE (ArchVSpaceAcc_A.get_pde target)) fun old => + holBindE (holUnlessE (holEq old .InvalidPDE) (holThrowError .DeleteFirst)) (holKBind + (holBindE (holReturnOk (Arch_Structs_A.pde.PageTablePDE (Platform.addrFromPPtr ptr) + (ArchDecode_A.filter_vm_attributes (ArchVMAttributes_A.attribs_from_word (holNth args 1))) + VMRights_A.vm_read_write)) fun entry => + holBindE (holReturnOk (Structures_A.cap.ArchObjectCap (.PageTableCap ptr (some (asid, addr))))) fun cap => + holReturnOk (.InvokePageTable (.PageTableMap cap slot entry target root))))) + (.InvokePageTable (.PageTableUnmap (.ArchObjectCap (.PageTableCap ptr mapping)) slot)) + +theorem patched_decodePageTableInvocation_equiv (label : Data) (args : List Data) (slot : CslotPtr) + (ptr : ObjRef) (mapping : Option (Asid × VSpaceRef)) (caps : List (Structures_A.cap × CslotPtr)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hbase : RootCapsInBaseRange caps) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (decode_page_table_invocation_p label args slot ptr mapping caps sH) + ((Fl4Spec.decodePageTableInvocation label args slot (embArchCap (.PageTableCap ptr mapping)) + (caps.map fun (cap, slot) => (embCap cap, slot))).run sL) := by + let mapL : ObjRef → Asid → VSpaceRef → SEMonad ZL ArchInvocation := fun root asid addr => do + let target ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.lookupPdSlot root addr) + let old ← NonDetE.liftE (Fl4Spec.getPde target) + NonDetE.unlessE (old = .invalidPDE) (NonDetE.throwError .deleteFirst) + let entry ← NonDetE.returnOk (PDE.pageTablePDE (Fl4Spec.addrFromPPtr ptr) + (Fl4Spec.filterVmAttributes (Fl4Spec.attribsFromWord (the args[1]?))) vmReadWrite) + let cap ← NonDetE.returnOk (Cap.archObjectCap (.pageTableCap ptr (some (asid, addr)))) + NonDetE.returnOk (.invokePageTable (.pageTableMap cap slot entry target root)) + unfold decode_page_table_invocation_p Fl4Spec.decodePageTableInvocation + simp only [embArchCap] + refine tableDecoder_equiv .X64PageTableMap .X64PageTableUnmap label args caps + (.PageTableCap ptr mapping) mapping Arch_Structs_A.pd_shift_bits (mapL := mapL) ?_ _ hs hb hbase + intro root asid addr + unfold mapL + refine mrele_bindE (lookupErrorOnFailure_equiv false (lookupPdSlot_equiv root addr)) fun dH dL hd => ?_ + subst hd + refine mrele_bindE (mrele_liftE (getPde_equiv dH)) fun pH pL hp => ?_ + subst hp + refine mrele_kbindE (mrele_unlessE (by + rw [holEq_eq_true] + cases pH <;> simp [embPDE]) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := FunRel embPDE) (by + simp only [FunRel, embPDE, addrFromPPtr_eq, attribsFromWord_eq, filterVmAttributes_eq, vmReadWrite_eq] + rfl)) fun eH eL he => ?_ + subst he + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) rfl) fun cH cL hc => ?_ + subst hc + exact mrele_returnOk rfl + +/-- l4v: ArchDecode_A.decode_page_directory_invocation, with the FL4 invocation ABI. -/ +def decode_page_directory_invocation_p (label : Data) (args : List Data) (slot : CslotPtr) + (ptr : ObjRef) (mapping : Option (Asid × VSpaceRef)) (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + table_decoder_p .X64PageDirectoryMap .X64PageDirectoryUnmap label args caps (.PageDirectoryCap ptr mapping) + mapping Arch_Structs_A.pdpt_shift_bits + (fun root asid addr => + holBindE (Exceptions_A.lookup_error_on_failure false (ArchVSpaceAcc_A.lookup_pdpt_slot root addr)) fun target => + holBindE (holLiftE (ArchVSpaceAcc_A.get_pdpte target)) fun old => + holBindE (holUnlessE (holEq old .InvalidPDPTE) (holThrowError .DeleteFirst)) (holKBind + (holBindE (holReturnOk (Arch_Structs_A.pdpte.PageDirectoryPDPTE (Platform.addrFromPPtr ptr) + (ArchDecode_A.filter_vm_attributes (ArchVMAttributes_A.attribs_from_word (holNth args 1))) + VMRights_A.vm_read_write)) fun entry => + holBindE (holReturnOk (Structures_A.cap.ArchObjectCap (.PageDirectoryCap ptr (some (asid, addr))))) fun cap => + holReturnOk (.InvokePageDirectory (.PageDirectoryMap cap slot entry target root))))) + (.InvokePageDirectory (.PageDirectoryUnmap (.ArchObjectCap (.PageDirectoryCap ptr mapping)) slot)) + +theorem patched_decodePageDirectoryInvocation_equiv (label : Data) (args : List Data) (slot : CslotPtr) + (ptr : ObjRef) (mapping : Option (Asid × VSpaceRef)) (caps : List (Structures_A.cap × CslotPtr)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hbase : RootCapsInBaseRange caps) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (decode_page_directory_invocation_p label args slot ptr mapping caps sH) + ((Fl4Spec.decodePageDirectoryInvocation label args slot (embArchCap (.PageDirectoryCap ptr mapping)) + (caps.map fun (cap, slot) => (embCap cap, slot))).run sL) := by + let mapL : ObjRef → Asid → VSpaceRef → SEMonad ZL ArchInvocation := fun root asid addr => do + let target ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.lookupPdptSlot root addr) + let old ← NonDetE.liftE (Fl4Spec.getPdpte target) + NonDetE.unlessE (old = .invalidPDPTE) (NonDetE.throwError .deleteFirst) + let entry ← NonDetE.returnOk (PDPTE.pageDirectoryPDPTE (Fl4Spec.addrFromPPtr ptr) + (Fl4Spec.filterVmAttributes (Fl4Spec.attribsFromWord (the args[1]?))) vmReadWrite) + let cap ← NonDetE.returnOk (Cap.archObjectCap (.pageDirectoryCap ptr (some (asid, addr)))) + NonDetE.returnOk (.invokePageDirectory (.pageDirectoryMap cap slot entry target root)) + unfold decode_page_directory_invocation_p Fl4Spec.decodePageDirectoryInvocation + simp only [embArchCap] + refine tableDecoder_equiv .X64PageDirectoryMap .X64PageDirectoryUnmap label args caps + (.PageDirectoryCap ptr mapping) mapping Arch_Structs_A.pdpt_shift_bits (mapL := mapL) ?_ _ hs hb hbase + intro root asid addr + unfold mapL + refine mrele_bindE (lookupErrorOnFailure_equiv false (lookupPdptSlot_equiv root addr)) fun dH dL hd => ?_ + subst hd + refine mrele_bindE (mrele_liftE (getPdpte_equiv dH)) fun pH pL hp => ?_ + subst hp + refine mrele_kbindE (mrele_unlessE (by + rw [holEq_eq_true] + cases pH <;> simp [embPDPTE]) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := FunRel embPDPTE) (by + simp only [FunRel, embPDPTE, addrFromPPtr_eq, attribsFromWord_eq, filterVmAttributes_eq, vmReadWrite_eq] + rfl)) fun eH eL he => ?_ + subst he + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) rfl) fun cH cL hc => ?_ + subst hc + exact mrele_returnOk rfl + +/-- l4v: ArchDecode_A.decode_pdpt_invocation, with the FL4 invocation ABI. -/ +def decode_pdpt_invocation_p (label : Data) (args : List Data) (slot : CslotPtr) + (ptr : ObjRef) (mapping : Option (Asid × VSpaceRef)) (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + table_decoder_p .X64PDPTMap .X64PDPTUnmap label args caps (.PDPointerTableCap ptr mapping) + mapping Arch_Structs_A.pml4_shift_bits + (fun root asid addr => + holBindE (holReturnOk (ArchVSpaceAcc_A.lookup_pml4_slot root addr)) fun target => + holBindE (holLiftE (ArchVSpaceAcc_A.get_pml4e target)) fun old => + holBindE (holUnlessE (holEq old .InvalidPML4E) (holThrowError .DeleteFirst)) (holKBind + (holBindE (holReturnOk (Arch_Structs_A.pml4e.PDPointerTablePML4E (Platform.addrFromPPtr ptr) + (ArchDecode_A.filter_vm_attributes (ArchVMAttributes_A.attribs_from_word (holNth args 1))) + VMRights_A.vm_read_write)) fun entry => + holBindE (holReturnOk (Structures_A.cap.ArchObjectCap (.PDPointerTableCap ptr (some (asid, addr))))) fun cap => + holReturnOk (.InvokePDPT (.PDPTMap cap slot entry target root))))) + (.InvokePDPT (.PDPTUnmap (.ArchObjectCap (.PDPointerTableCap ptr mapping)) slot)) + +theorem patched_decodePdptInvocation_equiv (label : Data) (args : List Data) (slot : CslotPtr) + (ptr : ObjRef) (mapping : Option (Asid × VSpaceRef)) (caps : List (Structures_A.cap × CslotPtr)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hbase : RootCapsInBaseRange caps) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (decode_pdpt_invocation_p label args slot ptr mapping caps sH) + ((Fl4Spec.decodePdptInvocation label args slot (embArchCap (.PDPointerTableCap ptr mapping)) + (caps.map fun (cap, slot) => (embCap cap, slot))).run sL) := by + let mapL : ObjRef → Asid → VSpaceRef → SEMonad ZL ArchInvocation := fun root asid addr => do + let target ← NonDetE.returnOk (Fl4Spec.lookupPml4Slot root addr) + let old ← NonDetE.liftE (Fl4Spec.getPml4e target) + NonDetE.unlessE (old = .invalidPML4E) (NonDetE.throwError .deleteFirst) + let entry ← NonDetE.returnOk (PML4E.pdPointerTablePML4E (Fl4Spec.addrFromPPtr ptr) + (Fl4Spec.filterVmAttributes (Fl4Spec.attribsFromWord (the args[1]?))) vmReadWrite) + let cap ← NonDetE.returnOk (Cap.archObjectCap (.pdPointerTableCap ptr (some (asid, addr)))) + NonDetE.returnOk (.invokePDPT (.pdptMap cap slot entry target root)) + unfold decode_pdpt_invocation_p Fl4Spec.decodePdptInvocation + simp only [embArchCap] + refine tableDecoder_equiv .X64PDPTMap .X64PDPTUnmap label args caps + (.PDPointerTableCap ptr mapping) mapping Arch_Structs_A.pml4_shift_bits (mapL := mapL) ?_ _ hs hb hbase + intro root asid addr + unfold mapL + refine mrele_bindE (mrele_returnOk (Ra := Eq) (lookupPml4Slot_eq root addr).symm) fun dH dL hd => ?_ + subst hd + refine mrele_bindE (mrele_liftE (getPml4e_equiv dH)) fun pH pL hp => ?_ + subst hp + refine mrele_kbindE (mrele_unlessE (by + rw [holEq_eq_true] + cases pH <;> simp [embPML4E]) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := FunRel embPML4E) (by + simp only [FunRel, embPML4E, addrFromPPtr_eq, attribsFromWord_eq, filterVmAttributes_eq, vmReadWrite_eq] + rfl)) fun eH eL he => ?_ + subst he + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) rfl) fun cH cL hc => ?_ + subst hc + exact mrele_returnOk rfl + +private theorem embVMAttribute_injective : Function.Injective embVMAttribute := by + intro a b h + cases a <;> cases b <;> simp [embVMAttribute] at h + · rename_i x y + cases x <;> cases y <;> simp_all [embTableAttr] + all_goals rfl + +private theorem vmAttrs_diff (attrs mask : Set ArchVMAttributes_A.vm_attribute) : + embVMAttrs (attrs \ mask) = embVMAttrs attrs \ embVMAttrs mask := + set_image_diff embVMAttribute_injective attrs mask + +theorem attrMask_eq : Fl4Spec.attrMask = embVMAttrs ArchVSpace_A.attr_mask := by + simp [Fl4Spec.attrMask, embVMAttrs, ArchVSpace_A.attr_mask, holInsert_eq, + HolCompleteLattice.holBot, Set.image_insert_eq, embVMAttribute, embTableAttr] + +theorem attrMaskPat_eq : Fl4Spec.attrMask' = embVMAttrs ArchVSpace_A.attr_mask' := by + unfold Fl4Spec.attrMask' ArchVSpace_A.attr_mask' embVMAttrs + rw [attrMask_eq] + simp [embVMAttrs, HolCompleteLattice.holSup, holInsert_eq, HolCompleteLattice.holBot, + Set.image_insert_eq, embVMAttribute] + +theorem checkVpAlignment_equiv (size : MachineTypes.vmpage_size) (addr : VSpaceRef) : + MRelE SR (FunRel embSyscallError) Eq + (ArchDecode_A.check_vp_alignment size addr) + (Fl4Spec.checkVpAlignment (embVMPageSize size) addr) := by + unfold ArchDecode_A.check_vp_alignment Fl4Spec.checkVpAlignment + exact mrele_unlessE (by rw [pageBitsForSize_eq]; exact isAligned_iff _ _) + (fun _ => mrele_throwError rfl) + +theorem ensureSafeMapping_equiv (entry : Arch_Structs_A.vm_page_entry) (slot : ObjRef) : + MRelE SR (FunRel embSyscallError) Eq + (ArchVSpace_A.ensure_safe_mapping (entry, slot)) + (Fl4Spec.ensureSafeMapping (embVMPageEntry entry, slot)) := by + cases entry with + | VMPTE pte => cases pte <;> exact mrele_returnOk rfl + | VMPDE pde => + cases pde with + | InvalidPDE => exact mrele_returnOk rfl + | PageTablePDE _ _ _ => exact mrele_fail_liftE + | LargePagePDE _ _ _ => + refine mrele_bindE (mrele_liftE (getPde_equiv slot)) fun eH eL he => ?_ + subst he + cases eH <;> first | exact mrele_returnOk rfl | exact mrele_throwError rfl + | VMPDPTE pdpte => + cases pdpte with + | InvalidPDPTE => exact mrele_returnOk rfl + | PageDirectoryPDPTE _ _ _ => exact mrele_fail_liftE + | HugePagePDPTE _ _ _ => + refine mrele_bindE (mrele_liftE (getPdpte_equiv slot)) fun eH eL he => ?_ + subst he + cases eH <;> first | exact mrele_returnOk rfl | exact mrele_throwError rfl + +private theorem createHugeMapping_equiv (base addr root : ObjRef) (rs : Set CapRights_A.rights) + (attrs : Set ArchVMAttributes_A.vm_attribute) : + MRelE SR (FunRel embSyscallError) (ProdRel (FunRel embVMPageEntry) Eq) + (ArchVSpace_A.create_mapping_entries base addr .X64HugePage rs attrs root) + (do + let slot ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.lookupPdptSlot root addr) + NonDetE.returnOk (.vmPDPTE (.hugePagePDPTE base (embVMAttrs attrs \ Fl4Spec.attrMask') + (embRightsSet rs)), slot)) := by + unfold ArchVSpace_A.create_mapping_entries + refine mrele_bindE (lookupErrorOnFailure_equiv false (lookupPdptSlot_equiv root addr)) + fun tH tL ht => ?_ + subst ht + exact mrele_returnOk ⟨by simp [FunRel, embVMPageEntry, embPDPTE, HolSub.subVal, attrMaskPat_eq, vmAttrs_diff], + rfl⟩ + +omit [StateExt ZL] in +private theorem createHugeMapping_read (base addr root : ObjRef) (rs : VMRights) + (attrs : VMAttributes) (s : State ZL) : + (Fl4Spec.createMappingEntries base addr .x64HugePage rs attrs root).run s = + ((do + NonDetE.unlessE s.archState.x64Plat.hugePages (NonDetE.throwError .illegalOperation) + let slot ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.lookupPdptSlot root addr) + NonDetE.returnOk (.vmPDPTE (.hugePagePDPTE base (attrs \ Fl4Spec.attrMask') rs), slot) : + SEMonad ZL (VMPageEntry × ObjRef)).run s) := by + unfold Fl4Spec.createMappingEntries + let next : Bool → SEMonad ZL (VMPageEntry × ObjRef) := fun huge => do + NonDetE.unlessE huge (NonDetE.throwError .illegalOperation) + let slot ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.lookupPdptSlot root addr) + NonDetE.returnOk (.vmPDPTE (.hugePagePDPTE base (attrs \ Fl4Spec.attrMask') rs), slot) + change NonDet.bind + (NonDet.bind (NonDet.gets fun st : State ZL => st.archState.x64Plat.hugePages) + (fun huge => NonDet.pure (.ok huge))) (ExceptT.bindCont next) s = + (next s.archState.x64Plat.hugePages).run s + simp [NonDet.bind, NonDet.gets, NonDet.pure, ExceptT.bindCont] + rfl + +theorem patched_createMappingEntries_equiv (size : MachineTypes.vmpage_size) + (base addr root : ObjRef) (rs : Set CapRights_A.rights) (attrs : Set ArchVMAttributes_A.vm_attribute) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (huge : Bool) (hhuge : size = .X64HugePage → huge = sL.archState.x64Plat.hugePages) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (ProdRel (FunRel embVMPageEntry) Eq)) + (Patched.create_mapping_entries huge base addr size rs attrs root sH) + ((Fl4Spec.createMappingEntries base addr (embVMPageSize size) (embRightsSet rs) (embVMAttrs attrs) root).run sL) := by + cases size with + | X64SmallPage => + refine (mrele_bindE (Re := FunRel embSyscallError) + (lookupErrorOnFailure_equiv false (lookupPtSlot_equiv root addr)) fun tH tL ht => ?_) sH sL hs + subst ht + exact mrele_returnOk ⟨by simp [FunRel, embVMPageEntry, embPTE, HolSub.subVal, attrMask_eq, vmAttrs_diff], rfl⟩ + | X64LargePage => + refine (mrele_bindE (Re := FunRel embSyscallError) + (lookupErrorOnFailure_equiv false (lookupPdSlot_equiv root addr)) fun tH tL ht => ?_) sH sL hs + subst ht + exact mrele_returnOk ⟨by simp [FunRel, embVMPageEntry, embPDE, HolSub.subVal, attrMask_eq, vmAttrs_diff], rfl⟩ + | X64HugePage => + have hplatform := hhuge rfl + change MRelStep SR (SumExceptRel (FunRel embSyscallError) (ProdRel (FunRel embVMPageEntry) Eq)) + _ ((Fl4Spec.createMappingEntries base addr .x64HugePage (embRightsSet rs) (embVMAttrs attrs) root).run sL) + rw [createHugeMapping_read, ← hplatform] + cases huge + · change MRelStep SR (SumExceptRel (FunRel embSyscallError) (ProdRel (FunRel embVMPageEntry) Eq)) + (holThrowError .IllegalOperation sH) + (NonDet.bind (NonDet.pure (.error .illegalOperation : Except SyscallError Unit)) + (ExceptT.bindCont _) sL) + rw [IpcCancel.nonDet_bind_pure_left] + exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + · change MRelStep SR (SumExceptRel (FunRel embSyscallError) (ProdRel (FunRel embVMPageEntry) Eq)) + (ArchVSpace_A.create_mapping_entries base addr .X64HugePage rs attrs root sH) + (NonDet.bind (NonDet.pure (.ok () : Except SyscallError Unit)) (ExceptT.bindCont _) sL) + rw [IpcCancel.nonDet_bind_pure_left] + exact createHugeMapping_equiv base addr root rs attrs sH sL hs + +private theorem freeAsidPoolSelect_eq (pool : AsidLowIndex → Option ObjRef) (base : Asid) : + Deterministic_A.free_asid_pool_select pool base = Fl4Spec.freeAsidPoolSelect pool base := by + let eligible : AsidLowIndex × Option ObjRef → Bool := fun (idx, entry) => + decide (ucast 64 idx + base ≠ 0 ∧ entry = none) + have hfilter : holCaseProd (fun (idx : AsidLowIndex) (entry : Option ObjRef) => + holConj (holNot (holEq (HolAdd.addVal (holUcast (w := 64) idx) base) HolZero.zeroVal)) + (holEq entry none)) = eligible := by + funext p + obtain ⟨idx, entry⟩ := p + apply Bool.eq_iff_iff.mpr + simp only [eligible, holCaseProd_eq, holConj_eq_true, holNot_eq_true, ne_eq, + holEq_eq_true, decide_eq_true_eq] + rfl + unfold Deterministic_A.free_asid_pool_select Fl4Spec.freeAsidPoolSelect + have hassocs : holAssocs pool = Fl4Spec.assocs pool := rfl + have hhead (xs : List (AsidLowIndex × Option ObjRef)) : holHd xs = Fl4Spec.the xs.head? := by + cases xs <;> rfl + rw [holListFilter, hassocs, hfilter, hhead] + +private def free_pool_indices (pool : AsidLowIndex → Option ObjRef) (base : Asid) : + Set AsidLowIndex := + HolCompleteLattice.holInf (HolNeg.negVal (holDom pool)) + (holCollect fun x => holNot (holEq (holUcast (w := 64) x + base) 0)) + +private theorem freePoolIndices_eq (pool : AsidLowIndex → Option ObjRef) (base : Asid) : + free_pool_indices pool base = (Fl4Spec.dom pool)ᶜ ∩ {idx | Fl4Spec.ucast 64 idx + base ≠ 0} := by + unfold free_pool_indices + ext idx + simp only [HolCompleteLattice.holInf, Set.mem_inter_iff, holCollect_eq, Set.mem_ofPred_eq, + holNot_eq_true, ne_eq, holEq_eq_true] + rfl + +/-- l4v: the ASID-pool branch of ArchDecode_A.arch_decode_invocation, with the FL4 labels. -/ +def decode_asid_pool_invocation_p (label : Data) (poolPtr base : ObjRef) + (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64ASIDPoolAssign)) + (holIf (holLt 0 caps.length) + (let (pd, pdSlot) := holNth caps 0 + match pd with + | .ArchObjectCap (.PML4Cap _ none) => + holBindE (holLiftE (holGets fun s => s.arch_state.x64_asid_table)) fun table => + holBindE (holReturnOk (table (ArchVSpaceAcc_A.asid_high_bits_of base))) fun ptr => + holBindE (holWhenE (holEq ptr none) (holThrowError (.FailedLookup false .InvalidRoot))) (holKBind + (holBindE (holWhenE (holNot (holEq poolPtr (holTheOpt ptr))) (holThrowError (.InvalidCapability 0))) (holKBind + (holBindE (holLiftE (ArchVSpaceAcc_A.get_asid_pool poolPtr)) fun pool => + holBindE (holReturnOk (free_pool_indices pool base)) fun free => + holBindE (holWhenE (holEq free ∅) (holThrowError .DeleteFirst)) (holKBind + (holBindE (holLiftE (Deterministic_A.select_ext + (fun _ => Deterministic_A.free_asid_pool_select pool base) free)) fun offset => + holReturnOk (.InvokeASIDPool (.Assign (holUcast (w := 64) offset + base) poolPtr pdSlot)))))))) + | _ => holThrowError (.InvalidCapability 1)) + (holThrowError .TruncatedMessage)) + (holThrowError .IllegalOperation) + +theorem patched_decodeAsidPoolInvocation_equiv (label : Data) (args : List Data) (slot : CslotPtr) + (capIndex : CapRef) (poolPtr base : ObjRef) (caps : List (Structures_A.cap × CslotPtr)) + (hbase : BaseAsid base) : + MRelE SR (FunRel embSyscallError) (FunRel embArchInv) + (decode_asid_pool_invocation_p label poolPtr base caps) + (Fl4Spec.archDecodeInvocation label args capIndex slot (embArchCap (.ASIDPoolCap poolPtr base)) + (caps.map fun (cap, slot) => (embCap cap, slot))) := by + unfold decode_asid_pool_invocation_p Fl4Spec.archDecodeInvocation + refine mrele_if (archInvocationLabel_iff label (.ArchInvocationLabel .X64ASIDPoolAssign)) + ?_ (fun _ => mrele_throwError rfl) + intro _ + refine mrele_if (by rw [holLt_eq_true, List.length_map]; rfl) ?_ (fun _ => mrele_throwError rfl) + intro hlen + cases caps with + | nil => simp at hlen + | cons head tail => + obtain ⟨c, cs⟩ := head + cases c with + | ArchObjectCap a => + cases a with + | PML4Cap p ma => + cases ma with + | some _ => exact mrele_throwError rfl + | none => + refine mrele_bindE (mrele_liftE (mrel_gets + (Ra := fun tH tL => tH (ArchVSpaceAcc_A.asid_high_bits_of base) = tL (Fl4Spec.asidHighBitsOf base)) + (fun _ _ h => (asidTable_eq h base hbase).symm))) fun tH tL ht => ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) ht) fun pH pL hp => ?_ + subst hp + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) (by rw [holEq_eq_true]) rfl fun _ => ?_ + have hthe : Fl4Spec.the pH = holTheOpt pH := by cases pH <;> rfl + refine mrele_kbindE (mrele_whenE (by rw [hthe]; simp [holNot_eq_true, holEq_eq_true]) + (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_liftE (getAsidPool_equiv poolPtr)) fun pH pL hp => ?_ + subst hp + refine mrele_bindE (mrele_returnOk (Ra := Eq) (freePoolIndices_eq pH base)) fun fH fL hf => ?_ + subst hf + refine mrele_kbindE (mrele_whenE (by rw [holEq_eq_true]) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_liftE (selectExt_equiv + (fun _ _ _ => freeAsidPoolSelect_eq pH base) (setRel_eq fH) + (fun _ _ h => by subst h; rfl))) fun oH oL ho => ?_ + subst ho + exact mrele_returnOk rfl + | _ => exact mrele_throwError rfl + | _ => exact mrele_throwError rfl + +private theorem freeAsidSelect_eq (table : AsidHighIndex → Option ObjRef) : + Patched.free_asid_select_p table = Fl4Spec.freeAsidSelect table := by + let eligible : AsidHighIndex × Option ObjRef → Bool := fun (idx, entry) => + decide (idx ≤ 2 ^ Fl4Spec.asidHighBits - 1 ∧ entry = none) + have hfilter : holCaseProd (fun (idx : AsidHighIndex) (entry : Option ObjRef) => + holConj (holLe idx (2 ^ (11 : Nat) - 1)) (holEq entry none)) = eligible := by + funext p + obtain ⟨idx, entry⟩ := p + apply Bool.eq_iff_iff.mpr + simp only [eligible, holCaseProd_eq, holConj_eq_true, holLe_eq_true, holEq_eq_true, decide_eq_true_eq] + rfl + unfold Patched.free_asid_select_p Fl4Spec.freeAsidSelect + have hassocs : holAssocs table = Fl4Spec.assocs table := rfl + have hhead (xs : List (AsidHighIndex × Option ObjRef)) : holHd xs = Fl4Spec.the xs.head? := by + cases xs <;> rfl + rw [holListFilter, hassocs, hfilter, hhead] + +/-- l4v: the ASID-control branch of ArchDecode_A.arch_decode_invocation, +using the widened ASID index and FL4 invocation labels. -/ +def decode_asid_control_invocation_p (label : Data) (args : List Data) + (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64ASIDControlMakePool)) + (holIf (holConj (holLt 1 args.length) (holLt 1 caps.length)) + (let (untyped, parent) := holNth caps 0 + let root := (holNth caps 1).1 + holBindE (holLiftE (holGets fun s => Patched.widen_asid_table s.arch_state.x64_asid_table)) fun table => + holBindE (holReturnOk (HolNeg.negVal (holDom table))) fun free => + holBindE (holWhenE (holEq free ∅) (holThrowError .DeleteFirst)) (holKBind + (holBindE (holLiftE (Deterministic_A.select_ext (fun _ => Patched.free_asid_select_p table) free)) fun idx => + holBindE (holReturnOk (holWordShiftl (holUcast (w := 64) idx) MiscMachine_A.asid_low_bits)) fun base => + holBindE (match untyped with + | .UntypedCap false ptr bits _ => holReturnOk (ptr, bits) + | _ => holThrowError (.InvalidCapability 1)) fun (ptr, bits) => + holBindE (holIf (holEq bits MachineTypes.pageBits) + (holBindE (CSpace_A.ensure_no_children parent) (holKBind (holReturnOk ptr))) + (holThrowError (.InvalidCapability 1))) fun frame => + holBindE (lookup_target_slot_p root (holToBl (holNth args 0)) (holUnsigned (holNth args 1))) fun dst => + holBindE (ensure_empty_p dst) (holKBind + (holReturnOk (.InvokeASIDControl (.MakePool frame dst parent base))))))) + (holThrowError .TruncatedMessage)) + (holThrowError .IllegalOperation) + +theorem patched_decodeAsidControlInvocation_equiv (label : Data) (args : List Data) + (slot : CslotPtr) (capIndex : CapRef) (caps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embArchInv) + (decode_asid_control_invocation_p label args caps) + (Fl4Spec.archDecodeInvocation label args capIndex slot (embArchCap .ASIDControlCap) + (caps.map fun (cap, slot) => (embCap cap, slot))) := by + unfold decode_asid_control_invocation_p Fl4Spec.archDecodeInvocation + refine mrele_if (archInvocationLabel_iff label (.ArchInvocationLabel .X64ASIDControlMakePool)) + ?_ (fun _ => mrele_throwError rfl) + intro _ + refine mrele_if (by rw [holConj_eq_true, holLt_eq_true, holLt_eq_true, List.length_map]; rfl) + ?_ (fun _ => mrele_throwError rfl) + intro hlen + cases caps with + | nil => simp at hlen + | cons first rest => + cases rest with + | nil => simp at hlen + | cons second rest => + obtain ⟨untyped, parent⟩ := first + obtain ⟨root, rootSlot⟩ := second + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) (fun _ _ hs => by + rw [hs.archState_eq] + rfl))) fun tH tL ht => ?_ + subst ht + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun fH fL hf => ?_ + subst hf + refine mrele_kbindE (mrele_whenE (by rw [holEq_eq_true]) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_liftE (selectExt_equiv + (fun _ _ _ => freeAsidSelect_eq tH) (setRel_eq fH) (fun _ _ h => by subst h; rfl))) + fun iH iL hi => ?_ + subst hi + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun bH bL hb => ?_ + subst hb + cases untyped <;> + try exact mrele_bindE (Ra := fun _ _ => False) (mrele_throwError rfl) (fun _ _ h => h.elim) + rename_i dev ptr bits _ + cases dev + rotate_left + · exact mrele_bindE (Ra := fun _ _ => False) (mrele_throwError rfl) (fun _ _ h => h.elim) + refine mrele_bindE (mrele_returnOk (Ra := Eq) (show (ptr, bits) = (ptr, bits) from rfl)) + fun uH uL hu => ?_ + subst hu + obtain ⟨ptr, bits⟩ := uH + refine mrele_bindE (mrele_if (by rw [holEq_eq_true]; rfl) + (fun _ => mrele_kbindE (ensureNoChildren_equiv parent) (mrele_returnOk rfl)) + (fun _ => mrele_throwError rfl)) fun fH fL hf => ?_ + subst hf + refine mrele_bindE (patched_lookupTargetSlot_equiv root _ _) fun dH dL hd => ?_ + subst hd + exact mrele_kbindE (patched_ensureEmpty_equiv dH) (mrele_returnOk rfl) + +private theorem nonDetBind_assoc {σ α β γ : Type} + (m : NonDet σ α) (f : α → NonDet σ β) (g : β → NonDet σ γ) : + NonDet.bind (NonDet.bind m f) g = NonDet.bind m (fun a => NonDet.bind (f a) g) := by + funext s + apply Prod.ext + · ext result + simp only [NonDet.bind, Set.mem_ofPred_eq] + constructor + · rintro ⟨b, ⟨a, ha, hb⟩, hr⟩ + exact ⟨a, ha, b, hb, hr⟩ + · rintro ⟨a, ha, b, hb, hr⟩ + exact ⟨b, ⟨a, ha, hb⟩, hr⟩ + · simp only [NonDet.bind, Set.mem_ofPred_eq, eq_iff_iff] + aesop + +private theorem exceptBind_assoc {σ ε α β γ : Type} + (m : NonDetE σ ε α) (f : α → NonDetE σ ε β) (g : β → NonDetE σ ε γ) : + ((m >>= f) >>= g) = (m >>= fun a => f a >>= g) := by + change NonDet.bind (NonDet.bind m.run (ExceptT.bindCont fun a => (f a).run)) + (ExceptT.bindCont fun b => (g b).run) = + NonDet.bind m.run (ExceptT.bindCont fun a => + NonDet.bind (f a).run (ExceptT.bindCont fun b => (g b).run)) + rw [nonDetBind_assoc] + congr 1 + funext result s + cases result with + | error e => exact congrFun (IpcCancel.nonDet_bind_pure_left _ _) s + | ok a => rfl + +private def check_page_mapping_p (mapping : Option (Asid × VSpaceRef)) + (mapType : MachineTypes.vmmap_type) (size : MachineTypes.vmpage_size) + (asid : Asid) (vaddr : VSpaceRef) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Unit) := + match mapping with + | some (oldAsid, oldAddr) => + holBindE (holWhenE (holNot (holEq oldAsid asid)) (holThrowError (.InvalidCapability 1))) + (holKBind (holBindE (holWhenE (holNot (holEq mapType .VMVSpaceMap)) (holThrowError .IllegalOperation)) + (holKBind (holWhenE (holNot (holEq oldAddr vaddr)) (holThrowError (.InvalidArgument 0)))))) + | none => + holBindE (holReturnOk (vaddr + holWordShiftl 1 (MachineTypes.pageBitsForSize size))) fun top => + holWhenE (holDisj (holLt Machine_A.user_vtop vaddr) (holLt Machine_A.user_vtop top)) + (holThrowError (.InvalidArgument 0)) + +private def checkPageMapping (mapping : Option (Asid × VSpaceRef)) + (mapType : VMMapType) (size : VMPageSize) (asid : Asid) (vaddr : VSpaceRef) : + SEMonad ZL Unit := + match mapping with + | some (oldAsid, oldAddr) => do + NonDetE.whenE (oldAsid ≠ asid) (NonDetE.throwError (.invalidCapability 1)) + NonDetE.whenE (mapType ≠ .vmVSpaceMap) (NonDetE.throwError .illegalOperation) + NonDetE.whenE (oldAddr ≠ vaddr) (NonDetE.throwError (.invalidArgument 0)) + | none => do + let top ← NonDetE.returnOk (vaddr + (1 <<< Fl4Spec.pageBitsForSize size)) + NonDetE.whenE (vaddr > Fl4Spec.userVtop ∨ top > Fl4Spec.userVtop) + (NonDetE.throwError (.invalidArgument 0)) + +private theorem checkPageMapping_equiv (mapping : Option (Asid × VSpaceRef)) + (mapType : MachineTypes.vmmap_type) (size : MachineTypes.vmpage_size) + (asid : Asid) (vaddr : VSpaceRef) : + MRelE SR (FunRel embSyscallError) Eq + (check_page_mapping_p mapping mapType size asid vaddr) + (checkPageMapping mapping (embVMMapType mapType) (embVMPageSize size) asid vaddr) := by + cases mapping with + | some p => + obtain ⟨oldAsid, oldAddr⟩ := p + unfold check_page_mapping_p checkPageMapping + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true]) + (fun _ => mrele_throwError rfl)) ?_ + refine mrele_kbindE (mrele_whenE (by cases mapType <;> simp [holNot_eq_true, holEq_eq_true, embVMMapType]) + (fun _ => mrele_throwError rfl)) ?_ + exact mrele_whenE (by simp [holNot_eq_true, holEq_eq_true]) (fun _ => mrele_throwError rfl) + | none => + unfold check_page_mapping_p checkPageMapping + refine mrele_bindE (mrele_returnOk (Ra := Eq) (by rw [pageBitsForSize_eq]; rfl)) fun tH tL ht => ?_ + subst ht + exact mrele_whenE (by rw [holDisj_eq_true, holLt_eq_true, holLt_eq_true]; rfl) + (fun _ => mrele_throwError rfl) + +omit [Nonempty ZH] [Deterministic_A.state_ext_class ZH] in +private theorem checkPageMapping_state (mapping : Option (Asid × VSpaceRef)) + (mapType : MachineTypes.vmmap_type) (size : MachineTypes.vmpage_size) + (asid : Asid) (vaddr : VSpaceRef) + {s next : Structures_A.state ZH} {u : Unit} + (h : (Sum.inr u, next) ∈ (check_page_mapping_p mapping mapType size asid vaddr s).1) : + next = s := by + cases mapping with + | some p => + obtain ⟨oldAsid, oldAddr⟩ := p + simp only [check_page_mapping_p, holBindE, holBind, holKBind, Set.mem_ofPred_eq] at h + obtain ⟨⟨res, t⟩, h₁, h₂⟩ := h + cases res with + | inl e => simp [holThrowError, holReturn] at h₂ + | inr _ => + rw [checkedUnit_state _ _ h₁] at h₂ + obtain ⟨⟨res, w⟩, h₂₁, h₂₂⟩ := h₂ + cases res with + | inl e => simp [holThrowError, holReturn] at h₂₂ + | inr _ => + rw [checkedUnit_state _ _ h₂₁] at h₂₂ + exact checkedUnit_state _ _ h₂₂ + | none => + simp only [check_page_mapping_p, holBindE, holBind, Set.mem_ofPred_eq] at h + obtain ⟨⟨res, t⟩, h₁, h₂⟩ := h + cases res with + | inl _ => simp [holReturnOk, holReturn] at h₁ + | inr _ => + rw [(returnOk_value_state h₁).2] at h₂ + exact checkedUnit_state _ _ h₂ + +private def finish_page_map_p (huge dev : Bool) (ptr : ObjRef) + (rights : Set CapRights_A.rights) (size : MachineTypes.vmpage_size) + (root : ObjRef) (asid : Asid) (vaddr mask attr : Data) (cte : CslotPtr) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + holBindE (Patched.create_mapping_entries huge (Platform.addrFromPPtr ptr) vaddr size + (VMRights_A.mask_vm_rights rights (CSpace_A.data_to_rights mask)) + (ArchVMAttributes_A.attribs_from_word attr) root) fun entries => + holBindE (ArchVSpace_A.ensure_safe_mapping entries) (holKBind + (holReturnOk (.InvokePage (.PageMap + (.ArchObjectCap (.PageCap dev ptr rights .VMVSpaceMap size (some (asid, vaddr)))) cte entries root)))) + +private theorem finishPageMap_equiv (huge dev : Bool) (ptr : ObjRef) + (rights : Set CapRights_A.rights) (size : MachineTypes.vmpage_size) + (root : ObjRef) (asid : Asid) (vaddr mask attr : Data) (cte : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hhuge : size = .X64HugePage → huge = sL.archState.x64Plat.hugePages) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (finish_page_map_p huge dev ptr rights size root asid vaddr mask attr cte sH) + ((do + let entries ← Fl4Spec.createMappingEntries (Fl4Spec.addrFromPPtr ptr) vaddr (embVMPageSize size) + (Fl4Spec.maskVmRights (embRightsSet rights) (Fl4Spec.dataToRights mask)) + (Fl4Spec.attribsFromWord attr) root + Fl4Spec.ensureSafeMapping entries + NonDetE.returnOk (.invokePage (.pageMap + (.archObjectCap (.pageCap dev ptr (embRightsSet rights) .vmVSpaceMap (embVMPageSize size) + (some (asid, vaddr)))) cte entries root)) : SEMonad ZL ArchInvocation).run sL) := by + unfold finish_page_map_p + rw [addrFromPPtr_eq, dataToRights_eq, maskVmRights_eq, attribsFromWord_eq] + refine mrelStep_bindE_mem (patched_createMappingEntries_equiv size _ _ _ _ _ hs huge hhuge) + fun eH eL he tH tL ht _ => ?_ + obtain ⟨entry, target⟩ := eH + obtain ⟨entry', target'⟩ := eL + obtain ⟨he, ht'⟩ := he + subst he + subst ht' + exact mrele_kbindE (ensureSafeMapping_equiv entry target) + (mrele_returnOk (Ra := FunRel embArchInv) rfl) tH tL ht + +private def PreservesState {σ α : Type} (m : NonDet σ α) : Prop := + ∀ {s t a}, (a, t) ∈ (m s).1 → t = s + +private theorem preservesState_bind {σ α β : Type} {m : NonDet σ α} + {next : α → NonDet σ β} (hm : PreservesState m) (hn : ∀ a, PreservesState (next a)) : + PreservesState (NonDet.bind m next) := by + rintro s t b ⟨⟨a, u⟩, h₁, h₂⟩ + exact (hn a h₂).trans (hm h₁) + +private theorem preservesState_pure {σ α : Type} (a : α) : PreservesState (NonDet.pure (σ := σ) a) := by + intro s t b h + exact (Prod.mk.inj (Set.mem_singleton_iff.mp h)).2 + +private theorem preservesState_fail {σ α : Type} : PreservesState (NonDet.fail (σ := σ) (α := α)) := by + intro s t a h + exact (Set.mem_empty_iff_false _ |>.mp h).elim + +private theorem preservesState_gets {σ α : Type} (f : σ → α) : + PreservesState (NonDet.gets f) := by + intro s t a h + exact preservesState_pure (f s) h + +private theorem preservesState_bindE {σ ε α β : Type} {m : NonDetE σ ε α} + {next : α → NonDetE σ ε β} + (hm : PreservesState m.run) (hn : ∀ a, PreservesState (next a).run) : + PreservesState (m >>= next).run := by + change PreservesState (NonDet.bind m.run (ExceptT.bindCont fun a => (next a).run)) + apply preservesState_bind hm + intro outcome + cases outcome with + | error e => + change PreservesState (NonDet.pure (σ := σ) (Except.error e : Except ε β)) + apply preservesState_pure + | ok a => exact hn a + +private theorem preservesState_liftE {σ ε α : Type} {m : NonDet σ α} + (hm : PreservesState m) : PreservesState (NonDetE.liftE (ε := ε) m).run := +by + change PreservesState (NonDet.bind m (fun a => NonDet.pure (Except.ok a : Except ε α))) + apply preservesState_bind hm + intro a + apply preservesState_pure + +private theorem preservesState_returnOk {σ ε α : Type} (a : α) : + PreservesState (NonDetE.returnOk (σ := σ) (ε := ε) a).run := + @preservesState_pure σ (Except ε α) (Except.ok a) + +private theorem preservesState_throwError {σ ε α : Type} (e : ε) : + PreservesState (NonDetE.throwError (σ := σ) (α := α) e).run := + @preservesState_pure σ (Except ε α) (Except.error e) + +private theorem preservesState_whenError {σ ε : Type} (P : Prop) [Decidable P] (e : ε) : + PreservesState (NonDetE.whenE (σ := σ) P (NonDetE.throwError e)).run := by + unfold NonDetE.whenE + split + · exact @preservesState_throwError σ ε Unit e + · exact @preservesState_returnOk σ ε Unit () + +omit [StateExt ZL] in +private theorem checkPageMapping_preservesState (mapping : Option (Asid × VSpaceRef)) + (mapType : VMMapType) (size : VMPageSize) (asid : Asid) (vaddr : VSpaceRef) : + PreservesState (checkPageMapping (ZL := ZL) mapping mapType size asid vaddr).run := by + cases mapping with + | some p => + obtain ⟨oldAsid, oldAddr⟩ := p + unfold checkPageMapping + exact preservesState_bindE (preservesState_whenError _ _) fun _ => + preservesState_bindE (preservesState_whenError _ _) fun _ => preservesState_whenError _ _ + | none => + unfold checkPageMapping + exact preservesState_bindE (preservesState_returnOk _) fun _ => preservesState_whenError _ _ + +omit [StateExt ZL] in +private theorem getAsidPool_preservesState (ptr : ObjRef) : + PreservesState (Fl4Spec.getAsidPool (Z := ZL) ptr) := by + unfold Fl4Spec.getAsidPool + apply preservesState_bind + · intro s t a h + change (a, t) ∈ (NonDet.assertOpt (s.kheap ptr) s).1 at h + cases hk : s.kheap ptr with + | none => exact preservesState_fail (by simpa only [hk, NonDet.assertOpt] using h) + | some obj => exact preservesState_pure obj (by simpa only [hk, NonDet.assertOpt] using h) + · intro obj + cases obj with + | archObj arch => cases arch <;> first | exact preservesState_pure _ | exact preservesState_fail + | _ => exact preservesState_fail + +omit [StateExt ZL] in +private theorem lookupAsidRoot_preservesState (asid : Asid) : + PreservesState (Fl4Spec.lookupErrorOnFailure false (Fl4Spec.findVspaceForAsid (Z := ZL) asid)).run := by + have hlookup : PreservesState (Fl4Spec.findVspaceForAsid (Z := ZL) asid).run := by + unfold Fl4Spec.findVspaceForAsid + refine preservesState_bindE (preservesState_liftE (ε := LookupFailure) ?_) fun _ => ?_ + · intro s t a h + change asid > 0 ∧ (a, t) = ((), s) at h + exact (Prod.mk.inj h.2).2 + refine preservesState_bindE (preservesState_liftE (preservesState_gets _)) fun _ => ?_ + refine preservesState_bindE (preservesState_returnOk _) fun poolPtr => ?_ + cases poolPtr with + | none => + exact preservesState_bindE (preservesState_throwError LookupFailure.invalidRoot) fun _ => + preservesState_bindE (preservesState_returnOk _) fun root => + by cases root <;> first | apply preservesState_returnOk | apply preservesState_throwError + | some ptr => + refine preservesState_bindE (preservesState_liftE (getAsidPool_preservesState ptr)) fun pool => ?_ + refine preservesState_bindE (preservesState_returnOk _) fun root => ?_ + cases root <;> first | apply preservesState_returnOk | apply preservesState_throwError + unfold Fl4Spec.lookupErrorOnFailure NonDetE.handleE ExceptT.mk ExceptT.run + apply preservesState_bind + · exact hlookup + intro result + cases result with + | error e => + exact @preservesState_throwError (State ZL) SyscallError ObjRef (.failedLookup false e) + | ok a => exact @preservesState_pure (State ZL) (Except SyscallError ObjRef) (.ok a) + +omit [StateExt ZL] in +private theorem checkVpAlignment_preservesState (size : VMPageSize) (addr : Word) : + PreservesState (Fl4Spec.checkVpAlignment (Z := ZL) size addr).run := by + unfold Fl4Spec.checkVpAlignment NonDetE.unlessE + split <;> first | apply preservesState_returnOk | apply preservesState_throwError + +private def page_map_p (huge dev : Bool) (ptr : ObjRef) (rights : Set CapRights_A.rights) + (mapType : MachineTypes.vmmap_type) (size : MachineTypes.vmpage_size) + (mapping : Option (Asid × VSpaceRef)) (vaddr mask attr : Data) (cte : CslotPtr) + (rootCap : Structures_A.cap) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + holBindE (read_root_cap rootCap) fun (root, asid) => + holBindE (check_page_mapping_p mapping mapType size asid vaddr) fun _ => + holBindE (Exceptions_A.lookup_error_on_failure false (ArchVSpace_A.find_vspace_for_asid asid)) fun found => + holBindE (holWhenE (holNot (holEq found root)) (holThrowError (.InvalidCapability 1))) fun _ => + holBindE (holReturnOk (VMRights_A.mask_vm_rights rights (CSpace_A.data_to_rights mask))) fun _ => + holBindE (ArchDecode_A.check_vp_alignment size vaddr) fun _ => + finish_page_map_p huge dev ptr rights size root asid vaddr mask attr cte + +private def pageMapAfterRoot (dev : Bool) (ptr : ObjRef) (rights : VMRights) + (mapType : VMMapType) (size : VMPageSize) (mapping : Option (Asid × VSpaceRef)) + (vaddr mask attr : Data) (cte : CslotPtr) (p : ObjRef × Asid) : + SEMonad ZL ArchInvocation := do + let (root, asid) := p + checkPageMapping mapping mapType size asid vaddr + let found ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.findVspaceForAsid asid) + NonDetE.whenE (found ≠ root) (NonDetE.throwError (.invalidCapability 1)) + let vmRights ← NonDetE.returnOk (Fl4Spec.maskVmRights rights (Fl4Spec.dataToRights mask)) + Fl4Spec.checkVpAlignment size vaddr + let entries ← Fl4Spec.createMappingEntries (Fl4Spec.addrFromPPtr ptr) vaddr size vmRights + (Fl4Spec.attribsFromWord attr) root + Fl4Spec.ensureSafeMapping entries + NonDetE.returnOk (.invokePage (.pageMap + (.archObjectCap (.pageCap dev ptr rights .vmVSpaceMap size (some (asid, vaddr)))) cte entries root)) + +private theorem pageMap_equiv (huge dev : Bool) (ptr : ObjRef) (rights : Set CapRights_A.rights) + (mapType : MachineTypes.vmmap_type) (size : MachineTypes.vmpage_size) + (mapping : Option (Asid × VSpaceRef)) (vaddr mask attr : Data) (cte : CslotPtr) + (rootCap : Structures_A.cap) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hroot : ∀ root asid, rootCap = .ArchObjectCap (.PML4Cap root (some asid)) → BaseAsid asid) + (hhuge : size = .X64HugePage → huge = sL.archState.x64Plat.hugePages) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (page_map_p huge dev ptr rights mapType size mapping vaddr mask attr cte rootCap sH) + ((do + let rootAndAsid ← (match embCap rootCap with + | .archObjectCap (.pml4Cap root (some asid)) => NonDetE.returnOk (root, asid) + | _ => NonDetE.throwError (.invalidCapability 1) : SEMonad ZL (ObjRef × Asid)) + pageMapAfterRoot dev ptr (embRightsSet rights) (embVMMapType mapType) (embVMPageSize size) + mapping vaddr mask attr cte rootAndAsid : SEMonad ZL ArchInvocation).run sL) := by + unfold page_map_p + refine mrelStep_bindE_mem_both (read_root_cap_equiv rootCap sH sL hs) + fun pH pL hp tH tL ht hmH hmL => ?_ + subst hp + obtain ⟨root, asid⟩ := pH + obtain ⟨hst, hcap⟩ := read_root_cap_reached hmH + subst tH + have hstL : tL = sL := by + rw [hcap] at hmL + exact preservesState_returnOk (ε := SyscallError) (root, asid) hmL + subst tL + unfold pageMapAfterRoot + refine mrelStep_bindE_mem_both ((checkPageMapping_equiv mapping mapType size asid vaddr) sH sL ht) + fun uH uL _ tH tL ht hcheckH hcheckL => ?_ + have hst := checkPageMapping_state _ _ _ _ _ hcheckH + have hstL := checkPageMapping_preservesState _ _ _ _ _ hcheckL + subst tH + subst tL + refine mrelStep_bindE_mem_both + (lookupErrorOnFailure_step false (findVspaceForAsid_equiv asid (hroot root asid hcap) ht hb)) + fun fH fL hf tH tL ht _ hlookupL => ?_ + subst hf + have hstL := lookupAsidRoot_preservesState asid hlookupL + subst tL + refine mrelStep_bindE_mem_both + ((mrele_whenE (Re := FunRel embSyscallError) (by simp [holNot_eq_true, holEq_eq_true]) + (fun _ => mrele_throwError rfl)) tH sL ht) + fun _ _ _ uH uL hu _ hguardL => ?_ + have hstL := preservesState_whenError _ (.invalidCapability 1 : SyscallError) hguardL + subst uL + refine mrelStep_bindE_mem_both + ((mrele_returnOk (Re := FunRel embSyscallError) (Ra := FunRel embRightsSet) + (by rw [FunRel, dataToRights_eq, maskVmRights_eq])) uH sL hu) + fun rightsH rightsL hr rH rL hrState hrightsH hrightsL => ?_ + subst hr + have heq := (returnOk_value_state hrightsH).1 + subst rightsH + have hstL := preservesState_returnOk (ε := SyscallError) _ hrightsL + subst rL + refine mrelStep_bindE_mem_both ((checkVpAlignment_equiv size vaddr) rH sL hrState) + fun _ _ _ aH aL ha _ halignL => ?_ + have hstL := checkVpAlignment_preservesState _ _ halignL + subst aL + have hfinish := finishPageMap_equiv huge dev ptr rights size root asid vaddr mask attr cte ha hhuge + rw [dataToRights_eq, maskVmRights_eq] at hfinish + exact hfinish + +/-- l4v: ArchDecode_A.X64_A.decode_page_invocation with FL4 labels +and the explicit huge-page platform check. -/ +def decode_page_invocation_p (huge : Bool) (label : Data) (args : List Data) + (cte : CslotPtr) (cap : Arch_Structs_A.arch_cap) (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + match cap with + | .PageCap dev ptr rights mapType size mapping => + holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64PageMap)) + (holIf (holConj (holLt 2 args.length) (holLt 0 caps.length)) + (page_map_p huge dev ptr rights mapType size mapping (holNth args 0) (holNth args 1) (holNth args 2) + cte (holNth caps 0).1) + (holThrowError .TruncatedMessage)) + (holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64PageUnmap)) + (holReturnOk (.InvokePage (.PageUnmap cap cte))) + (holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64PageGetAddress)) + (holReturnOk (.InvokePage (.PageGetAddr ptr))) (holThrowError .IllegalOperation))) + | _ => holFail + +theorem patched_decodePageInvocation_equiv (label : Data) (args : List Data) (cte : CslotPtr) + (cap : Arch_Structs_A.arch_cap) (caps : List (Structures_A.cap × CslotPtr)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hbase : RootCapsInBaseRange caps) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (decode_page_invocation_p sL.archState.x64Plat.hugePages label args cte cap caps sH) + ((Fl4Spec.decodePageInvocation label args cte (embArchCap cap) + (caps.map fun (c, slot) => (embCap c, slot))).run sL) := by + unfold decode_page_invocation_p Fl4Spec.decodePageInvocation + cases cap <;> try exact mrele_fail_liftE (Re := FunRel embSyscallError) (Ra := FunRel embArchInv) sH sL hs + case PageCap dev ptr rights mapType size mapping => + dsimp only [embArchCap] + by_cases hmap : Fl4Spec.invocationType label = .archInvocationLabel .x64PageMap + · rw [holIf_eq, ite_eq_left ((archInvocationLabel_iff label (.ArchInvocationLabel .X64PageMap)).mpr hmap), ite_eq_left hmap] + by_cases hlen : 2 < args.length ∧ 0 < caps.length + · have hl : holConj (holLt 2 args.length) (holLt 0 caps.length) = true := by + rwa [holConj_eq_true, holLt_eq_true, holLt_eq_true] + simp only [List.length_map, holIf_eq, ite_eq_left hl, ite_eq_left hlen] + obtain ⟨vaddr, mask, attr, rest, rfl⟩ : + ∃ vaddr mask attr rest, args = vaddr :: mask :: attr :: rest := by + cases args with + | nil => simp at hlen + | cons vaddr args => + cases args with + | nil => simp at hlen + | cons mask args => + cases args with + | nil => simp at hlen + | cons attr rest => exact ⟨vaddr, mask, attr, rest, rfl⟩ + let args := vaddr :: mask :: attr :: rest + rw [the_getElem_map + (fun (p : Structures_A.cap × CslotPtr) => (embCap p.1, p.2)) caps 0 hlen.2] + have hcap : ∀ root asid, (holNth caps 0).1 = .ArchObjectCap (.PML4Cap root (some asid)) → + BaseAsid asid := by + intro root asid he + have hfirst : holNth caps 0 ∈ caps := by + simp only [holNth, List.getElem?_eq_getElem hlen.2, holTheOpt] + exact List.getElem_mem _ + have heq : holNth caps 0 = (.ArchObjectCap (.PML4Cap root (some asid)), (holNth caps 0).2) := + Prod.ext he rfl + rw [heq] at hfirst + exact hbase root asid _ hfirst + let next := pageMapAfterRoot (ZL := ZL) dev ptr (embRightsSet rights) (embVMMapType mapType) + (embVMPageSize size) mapping (holNth args 0) (holNth args 1) (holNth args 2) cte + have hjoin := bindRootCap_eq (embCap (holNth caps 0).1) next + have hbody := pageMap_equiv sL.archState.x64Plat.hugePages dev ptr rights mapType size mapping + (holNth args 0) (holNth args 1) (holNth args 2) cte (holNth caps 0).1 hs hb hcap (fun _ => rfl) + change MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) _ + (((match embCap (holNth caps 0).1 with + | .archObjectCap (.pml4Cap root (some asid)) => NonDetE.returnOk (root, asid) + | _ => NonDetE.throwError (.invalidCapability 1) : SEMonad ZL (ObjRef × Asid)) >>= next).run sL) + at hbody + rw [← hjoin] at hbody + generalize embCap (holNth caps 0).1 = decodedRoot at hbody ⊢ + cases mapping + case' some p => rcases p with ⟨mapAsid, mapAddr⟩ + all_goals cases decodedRoot + case' none.archObjectCap arch => cases arch + case' some.archObjectCap arch => cases arch + case' none.archObjectCap.pml4Cap ptr info => cases info + case' some.archObjectCap.pml4Cap ptr info => cases info + all_goals + simp only [next, pageMapAfterRoot, checkPageMapping, exceptBind_assoc, args, holNth, Fl4Spec.the, + holTheOpt, List.getElem?_cons_zero, List.getElem?_cons_succ] at hbody ⊢ + exact hbody + · have hl : ¬holConj (holLt 2 args.length) (holLt 0 caps.length) = true := by + rwa [holConj_eq_true, holLt_eq_true, holLt_eq_true] + simp only [List.length_map, holIf_eq, ite_eq_right hl, ite_eq_right hlen] + exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + · rw [holIf_eq, ite_eq_right (mt (archInvocationLabel_iff label (.ArchInvocationLabel .X64PageMap)).mp hmap), ite_eq_right hmap] + exact (mrele_if (Re := FunRel embSyscallError) (Ra := FunRel embArchInv) + (archInvocationLabel_iff label (.ArchInvocationLabel .X64PageUnmap)) + (fun _ => mrele_returnOk rfl) + (fun _ => mrele_if (archInvocationLabel_iff label (.ArchInvocationLabel .X64PageGetAddress)) + (fun _ => mrele_returnOk rfl) (fun _ => mrele_throwError rfl))) sH sL hs + +/-- l4v: ArchDecode_A.X64_A.arch_decode_invocation, using the native FL4 ABI, +ASID index width, and huge-page platform check. -/ +def arch_decode_invocation_p (huge : Bool) (label : Data) (args : List Data) (slot : CslotPtr) + (cap : Arch_Structs_A.arch_cap) (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + match cap with + | .PageTableCap p info => decode_page_table_invocation_p label args slot p info caps + | .PageDirectoryCap p info => decode_page_directory_invocation_p label args slot p info caps + | .PDPointerTableCap p info => decode_pdpt_invocation_p label args slot p info caps + | .PageCap .. => decode_page_invocation_p huge label args slot cap caps + | .ASIDControlCap => decode_asid_control_invocation_p label args caps + | .ASIDPoolCap p base => decode_asid_pool_invocation_p label p base caps + | .IOPortCap .. => decode_port_invocation_p label args cap + | .IOPortControlCap => decode_ioport_control_invocation_p label args slot (caps.map Prod.fst) + | .PML4Cap .. => holThrowError .IllegalOperation + +/-- [P] The state and the capability arguments admit the common native ASID carrier. -/ +theorem patched_archDecodeInvocation_equiv (label : Data) (args : List Data) + (capIndex : CapRef) (slot : CslotPtr) (cap : Arch_Structs_A.arch_cap) + (caps : List (Structures_A.cap × CslotPtr)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hroot : RootCapsInBaseRange caps) + (hpool : ∀ p base, cap = .ASIDPoolCap p base → BaseAsid base) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embArchInv)) + (arch_decode_invocation_p sL.archState.x64Plat.hugePages label args slot cap caps sH) + ((Fl4Spec.archDecodeInvocation label args capIndex slot (embArchCap cap) + (caps.map fun (c, s) => (embCap c, s))).run sL) := by + cases cap with + | PageTableCap ptr info => + exact patched_decodePageTableInvocation_equiv label args slot ptr info caps hs hb hroot + | PageDirectoryCap ptr info => + exact patched_decodePageDirectoryInvocation_equiv label args slot ptr info caps hs hb hroot + | PDPointerTableCap ptr info => + exact patched_decodePdptInvocation_equiv label args slot ptr info caps hs hb hroot + | PageCap dev ptr rights mapType size info => + exact patched_decodePageInvocation_equiv label args slot (.PageCap dev ptr rights mapType size info) caps hs hb hroot + | ASIDControlCap => + exact patched_decodeAsidControlInvocation_equiv label args slot capIndex caps sH sL hs + | ASIDPoolCap ptr base => + exact patched_decodeAsidPoolInvocation_equiv label args slot capIndex ptr base caps (hpool ptr base rfl) sH sL hs + | IOPortCap first last => + exact patched_decodePortInvocation_equiv label args (.IOPortCap first last) sH sL hs + | IOPortControlCap => + have hmap : ((caps.map Prod.fst).map embCap) = + (caps.map fun p => (embCap p.1, p.2)).map Prod.fst := by simp [List.map_map, Function.comp_def] + have hproof := patched_decodeIoportControlInvocation_equiv label args slot .IOPortControlCap + (caps.map Prod.fst) sH sL hs + rw [hmap] at hproof + exact hproof + | PML4Cap _ _ => exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + +end + +end L4vRefX64.Equiv.ArchDecode diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchInvoke.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchInvoke.lean new file mode 100644 index 000000000..0f9402f7e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchInvoke.lean @@ -0,0 +1,836 @@ +import L4vRefX64.Equiv.ArchCap +import L4vRefX64.Equiv.CSpace +import L4vRefX64.Equiv.Hardware +import L4vRefX64.Equiv.VSpaceUnmap +import L4vRefX64.Equiv.Retype +import L4vRefX64.Spec.Arch_A + +namespace L4vRefX64.Equiv.ArchInvoke + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.ArchCap L4vRefX64.Equiv.CSpace L4vRefX64.Equiv.Hardware +open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.VSpaceRoot L4vRefX64.Equiv.Retype +open L4vRefX64.Equiv.VSpaceAccess L4vRefX64.Equiv.VSpaceUnmap L4vRefX64.Equiv.Machine +open Fl4Spec Classical + +noncomputable section + +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 + +private theorem portIn_equiv {mH : HolNonDet (MachineTypes.machine_state_ext Unit) Data} + {mL : MachineMonad Data} (hm : MRel (MachineStateRel RestRel) Eq mH mL) : + MRel SR Eq (Arch_A.port_in mH) (Fl4Spec.portIn mL) := by + unfold Arch_A.port_in Fl4Spec.portIn + refine mrel_bind (mrel_doMachineOp hm) fun wH wL hw => ?_ + subst hw + exact mrel_return rfl + +private theorem portOut_equiv {n : Nat} {fH : BitVec n → HolNonDet (MachineTypes.machine_state_ext Unit) Unit} + {fL : BitVec n → MachineMonad Unit} (w : BitVec n) + (hm : MRel (MachineStateRel RestRel) Eq (fH w) (fL w)) : + MRel SR Eq (Arch_A.port_out fH w) (Fl4Spec.portOut fL w) := + mrel_kbind (mrel_doMachineOp hm) (mrel_return rfl) + +theorem performIoPortInvocation_equiv (hop : OpaqueRel RestRel) + (i : ArchInvocation_A.io_port_invocation) : + MRel SR Eq (Arch_A.perform_io_port_invocation i) (Fl4Spec.performIoPortInvocation (embIoPortInv i)) := by + obtain ⟨port, data⟩ := i + cases data + · exact portIn_equiv (in8_equiv hop port) + · exact portIn_equiv (in16_equiv hop port) + · exact portIn_equiv (in32_equiv hop port) + · rename_i w + exact portOut_equiv w (out8_equiv hop port w) + · rename_i w + exact portOut_equiv w (out16_equiv hop port w) + · rename_i w + exact portOut_equiv w (out32_equiv hop port w) + +/-- l4v: Arch_A.X64_A.perform_ioport_control_invocation with the FL4 cap insertion. -/ +def perform_ioport_control_invocation_p : ArchInvocation_A.io_port_control_invocation → + HolNonDet (Structures_A.state ZH) Unit + | .IOPortControlInvocation first last dest control => + let cap : Structures_A.cap := .ArchObjectCap (.IOPortCap first last) + holBind (ArchIpcCancel_A.set_ioport_mask first last true) fun _ => + holBind (holReturn cap) fun _ => + cap_insert_p cap control dest + +/-- [P] The destination admits capability insertion after the I/O mask is updated. -/ +def IoportControlSafe (i : ArchInvocation_A.io_port_control_invocation) (s : Structures_A.state ZH) : Prop := + match i with + | .IOPortControlInvocation first last dest control => + ∀ t, ((), t) ∈ (ArchIpcCancel_A.set_ioport_mask first last true s).1 → + CapInsertSafe (.ArchObjectCap (.IOPortCap first last)) control dest t + +theorem patched_performIoportControlInvocation_equiv (i : ArchInvocation_A.io_port_control_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hi : IoportControlSafe i sH) : + MRelStep SR Eq (perform_ioport_control_invocation_p i sH) + (Fl4Spec.performIoportControlInvocation (embIoPortControlInv i) sL) := by + obtain ⟨first, last, dest, control⟩ := i + unfold perform_ioport_control_invocation_p Fl4Spec.performIoportControlInvocation embIoPortControlInv + refine mrelStep_bind_mem (setIoportMask_equiv first last true sH sL hs) fun u _ _ tH tL ht hmem => ?_ + cases u + let cap : Structures_A.cap := .ArchObjectCap (.IOPortCap first last) + refine mrelStep_bind_mem ((mrel_return (Ra := FunRel embCap) (aH := cap) rfl) tH tL ht) + fun cH _ _ rH rL hr hread => ?_ + have hsame : rH = tH := by simpa [holReturn] using (Prod.mk.inj (Set.mem_singleton_iff.mp hread)).2 + subst rH + exact patched_capInsert_equiv cap control dest hr (hi tH hmem) + +theorem storeAsidPoolEntry_equiv (poolPtr : ObjRef) (asid : Asid) (root : Option ObjRef) : + MRel SR Eq (Arch_A.store_asid_pool_entry poolPtr asid root) (Fl4Spec.storeAsidPoolEntry poolPtr asid root) := by + unfold Arch_A.store_asid_pool_entry Fl4Spec.storeAsidPoolEntry + refine mrel_bind (getAsidPool_equiv poolPtr) fun pH pL hp => ?_ + subst hp + refine mrel_bind (mrel_return (Ra := Eq) (by + rw [asidLowBitsOf_eq, holFunUpd_eq] + funext index + by_cases h : index = ArchVSpaceAcc_A.asid_low_bits_of asid + · subst index + simp + · simp [Function.update, h])) fun tH tL ht => ?_ + subst ht + exact setObject_equiv poolPtr (.ArchObj (.ASIDPool tH)) + +/-- l4v: Arch_A.X64_A.perform_asid_pool_invocation with patched CSlot access. -/ +def perform_asid_pool_invocation_p : ArchInvocation_A.asid_pool_invocation → + HolNonDet (Structures_A.state ZH) Unit + | .Assign asid pool slot => + holBind (get_cap_p slot) fun + | .ArchObjectCap (.PML4Cap root _) => + holBind (set_cap_p (.ArchObjectCap (.PML4Cap root (some asid))) slot) fun _ => + Arch_A.store_asid_pool_entry pool asid (some root) + | _ => holFail + +/-- [P] The reached PML4 cap is writable in the common CSlot layout. -/ +def AsidPoolPerformSafe (i : ArchInvocation_A.asid_pool_invocation) (s : Structures_A.state ZH) : Prop := + match i with + | .Assign asid _ slot => + ∀ root mapping t, (.ArchObjectCap (.PML4Cap root mapping), t) ∈ (get_cap_p slot s).1 → + SetCapSafe (.ArchObjectCap (.PML4Cap root (some asid))) slot t + +theorem patched_performAsidPoolInvocation_equiv (i : ArchInvocation_A.asid_pool_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hi : AsidPoolPerformSafe i sH) : + MRelStep SR Eq (perform_asid_pool_invocation_p i sH) + (Fl4Spec.performAsidPoolInvocation (embAsidPoolInv i) sL) := by + obtain ⟨asid, pool, slot⟩ := i + unfold perform_asid_pool_invocation_p Fl4Spec.performAsidPoolInvocation embAsidPoolInv + refine mrelStep_bind_mem (patched_getCap_equiv slot sH sL hs) fun capH capL hcap tH tL ht hmem => ?_ + subst hcap + cases capH with + | ArchObjectCap arch => + cases arch with + | PML4Cap root mapping => + refine mrelStep_bind_mem (patched_setCap_equiv_at _ slot ht (hi root mapping tH hmem)) + fun _ _ _ uH uL hu _ => ?_ + exact storeAsidPoolEntry_equiv pool asid (some root) uH uL hu + | _ => exact mrel_fail tH tL ht + | _ => exact mrel_fail tH tL ht + +private def set_asid_table_entry (base : Asid) (frame : ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (holGets fun s => s.arch_state.x64_asid_table) fun table => + holBind (holReturn (Function.update table (ArchVSpaceAcc_A.asid_high_bits_of base) (some frame))) fun next => + holModify (Structures_A.abstract_state.arch_state_update + (Arch_Structs_A.arch_state.x64_asid_table_update (fun _ => next))) + +private theorem setAsidTableEntry_equiv (base : Asid) (frame : ObjRef) (hbase : BaseAsid base) : + MRel SR Eq (set_asid_table_entry base frame) + (do + let table ← NonDet.gets fun s : State ZL => s.archState.x64AsidTable + let next ← pure (Function.update table (Fl4Spec.asidHighBitsOf base) (some frame)) + NonDet.modify fun s => { s with archState := { s.archState with x64AsidTable := next } }) := by + unfold set_asid_table_entry + refine mrel_bind (Ra := fun tH tL => tL = Patched.widen_asid_table tH) + (mrel_gets fun _ _ h => by rw [h.archState_eq]; rfl) fun tH tL ht => ?_ + subst tL + refine mrel_bind (Ra := fun tH tL => tL = Patched.widen_asid_table tH) (mrel_return ?_) fun nH nL hn => ?_ + · rw [← asidHighBitsOf_cast base] + exact widenAsidTable_update _ _ _ (asidHighBitsOf_lt base hbase) + subst nL + refine mrel_modify fun _ _ hs => ?_ + have harch := congrArg (fun ar : ArchState => { ar with x64AsidTable := Patched.widen_asid_table nH }) hs.archState_eq + exact { hs with archState_eq := harch } + +/-- l4v: Arch_A.X64_A.perform_asid_control_invocation with base-carrier retype and CSlot access. -/ +def perform_asid_control_invocation_p : ArchInvocation_A.asid_control_invocation → + HolNonDet (Structures_A.state ZH) Unit + | .MakePool frame slot parent base => + holBind (Retype_A.delete_objects frame MachineTypes.pageBits) fun _ => + holBind (get_cap_p parent) fun cap => + holBind (set_cap_p (CSpace_A.max_free_index_update cap) parent) fun _ => + holBind (retype_region_p frame 1 0 (.ArchObject .ASIDPoolObj) false) fun _ => + holBind (cap_insert_p (.ArchObjectCap (.ASIDPoolCap frame base)) parent slot) fun _ => + holBind (holAssert (holEq (ArchVSpaceAcc_A.asid_low_bits_of base) 0)) fun _ => + set_asid_table_entry base frame + +/-- [P] MakePool uses a common-range ASID base and the reached parent and destination admit writes. -/ +def AsidControlPerformSafe (i : ArchInvocation_A.asid_control_invocation) (s : Structures_A.state ZH) : Prop := + match i with + | .MakePool frame slot parent base => + BaseAsid base ∧ + ∀ t, ((), t) ∈ (Retype_A.delete_objects frame MachineTypes.pageBits s).1 → + ∀ cap u, (cap, u) ∈ (get_cap_p parent t).1 → + SetCapSafe (CSpace_A.max_free_index_update cap) parent u ∧ + ∀ v, ((), v) ∈ (set_cap_p (CSpace_A.max_free_index_update cap) parent u).1 → + ∀ objects w, (objects, w) ∈ (retype_region_p frame 1 0 (.ArchObject .ASIDPoolObj) false v).1 → + CapInsertSafe (.ArchObjectCap (.ASIDPoolCap frame base)) parent slot w + +theorem patched_performAsidControlInvocation_equiv (hop : OpaqueRel RestRel) + (i : ArchInvocation_A.asid_control_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hi : AsidControlPerformSafe i sH) : + MRelStep SR Eq (perform_asid_control_invocation_p i sH) + (Fl4Spec.performAsidControlInvocation (embAsidControlInv i) sL) := by + obtain ⟨frame, slot, parent, base⟩ := i + unfold perform_asid_control_invocation_p Fl4Spec.performAsidControlInvocation embAsidControlInv + obtain ⟨hbase, hi⟩ := hi + refine mrelStep_bind_mem (deleteObjects_equiv frame _ sH sL hs) fun a _ _ tH tL ht hmem => ?_ + cases a + refine mrelStep_bind_mem (patched_getCap_equiv parent tH tL ht) fun capH capL hcap uH uL hu hread => ?_ + subst hcap + obtain ⟨hwrite, hins⟩ := hi tH hmem capH uH hread + rw [maxFreeIndexUpdate_eq] + refine mrelStep_bind_mem (patched_setCap_equiv_at _ parent hu hwrite) fun b _ _ vH vL hv hw => ?_ + cases b + refine mrelStep_bind_mem (patched_retypeRegion_equiv hop frame 1 0 (.ArchObject .ASIDPoolObj) false vH vL hv) + fun objs _ _ wH wL hw' hobjects => ?_ + refine mrelStep_bind_mem (patched_capInsert_equiv _ parent slot hw' (hins vH hw objs wH hobjects)) + fun _ _ _ xH xL hx _ => ?_ + exact mrel_kbind (mrel_assert (by rw [asidLowBitsOf_eq, holEq_eq_true])) + (setAsidTableEntry_equiv base frame hbase) xH xL hx + +private def store_mapping_entry (entry : Arch_Structs_A.vm_page_entry) (target : ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + match entry with + | .VMPTE pte => ArchVSpaceAcc_A.store_pte target pte + | .VMPDE pde => ArchVSpaceAcc_A.store_pde target pde + | .VMPDPTE pdpte => ArchVSpaceAcc_A.store_pdpte target pdpte + +private theorem storeMappingEntry_equiv (entry : Arch_Structs_A.vm_page_entry) (target : ObjRef) : + MRel SR Eq (store_mapping_entry entry target) + (match embVMPageEntry entry with + | .vmPTE pte => Fl4Spec.storePte target pte + | .vmPDE pde => Fl4Spec.storePde target pde + | .vmPDPTE pdpte => Fl4Spec.storePdpte target pdpte) := by + cases entry + · exact storePte_equiv _ _ + · exact storePde_equiv _ _ + · exact storePdpte_equiv _ _ + +private def perform_native_map {α : Type} (cap : Structures_A.cap) (slot : CslotPtr) + (store : HolNonDet (Structures_A.state ZH) Unit) (asid : Option Asid) + (after : Asid → HolNonDet (Structures_A.state ZH) α) : + HolNonDet (Structures_A.state ZH) α := + holBind (set_cap_p cap slot) fun _ => + holBind store fun _ => holBind (asid.elim holFail holReturn) after + +private theorem performNativeMap_equiv {α : Type} (cap : Structures_A.cap) + (slot : CslotPtr) (asid : Option Asid) + {storeH : HolNonDet (Structures_A.state ZH) Unit} {storeL : SMonad ZL Unit} + {afterH : Asid → HolNonDet (Structures_A.state ZH) α} {afterL : Asid → SMonad ZL α} + (hstore : MRel SR Eq storeH storeL) (hafter : ∀ a, MRel SR Eq (afterH a) (afterL a)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hw : SetCapSafe cap slot sH) : + MRelStep SR Eq (perform_native_map cap slot storeH asid afterH sH) + ((do + Fl4Spec.setCap (embCap cap) slot + storeL + let a ← asid.elim NonDet.fail NonDet.pure + afterL a) sL) := by + unfold perform_native_map + refine mrelStep_bind_mem (patched_setCap_equiv_at cap slot hs hw) fun _ _ _ tH tL ht _ => ?_ + refine mrel_kbind hstore (mrel_bind (Rb := Eq) (Ra := Eq) ?_ ?_) tH tL ht + · cases asid + · exact mrel_fail + · exact mrel_return rfl + · intro a b hab + subst hab + exact hafter a + +private theorem invalidateNativeMap_equiv (hop : OpaqueRel RestRel) (root : ObjRef) (a : Asid) : + MRel SR Eq (ArchVSpace_A.invalidate_page_structure_cache_asid (Platform.addrFromPPtr root) a) + (Fl4Spec.invalidatePageStructureCacheAsid (Fl4Spec.addrFromPPtr root) a) := by + rw [addrFromPPtr_eq] + exact invalidatePageStructureCacheAsid_equiv hop (Fl4Spec.addrFromPPtr root) a + +/-- l4v: the PageMap branch of Arch_A.X64_A.perform_page_invocation, with base-slot writes. -/ +def perform_page_map_p (cap : Structures_A.cap) (slot : CslotPtr) + (entry : Arch_Structs_A.vm_page_entry) (target root : ObjRef) : + HolNonDet (Structures_A.state ZH) (List Data) := + perform_native_map cap slot (store_mapping_entry entry target) + (match cap with + | .ArchObjectCap (.PageCap _ _ _ _ _ (some (asid, _))) => some asid + | _ => none) fun a => + holBind (ArchVSpace_A.invalidate_page_structure_cache_asid (Platform.addrFromPPtr root) a) + fun _ => holReturn [] + +/-- [P] The capability slot admits this mapping-capability write. -/ +theorem patched_performPageMap_equiv (hop : OpaqueRel RestRel) + (cap : Structures_A.cap) (slot : CslotPtr) (entry : Arch_Structs_A.vm_page_entry) (target root : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hw : SetCapSafe cap slot sH) : + MRelStep SR Eq (perform_page_map_p cap slot entry target root sH) + (Fl4Spec.performPageInvocation (embPageInv (.PageMap cap slot (entry, target) root)) sL) := by + have hmap := performNativeMap_equiv cap slot + (match cap with + | .ArchObjectCap (.PageCap _ _ _ _ _ (some (asid, _))) => some asid + | _ => none) (storeMappingEntry_equiv entry target) + (fun a => mrel_kbind (invalidateNativeMap_equiv hop root a) + (mrel_return (show ([] : List Data) = [] from rfl))) hs hw + cases cap with + | ArchObjectCap arch => + cases arch with + | PageCap dev ptr rights mt size mapping => + cases mapping + · cases entry <;> exact hmap + · rename_i pair + rcases pair with ⟨asid, addr⟩ + cases entry <;> exact hmap + | _ => cases entry <;> exact hmap + | _ => cases entry <;> exact hmap + +/-- l4v: the PageTableMap branch of Arch_A.X64_A.perform_page_table_invocation, with base-slot writes. -/ +def perform_page_table_map_p (cap : Structures_A.cap) (slot : CslotPtr) + (entry : Arch_Structs_A.pde) (target root : ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + perform_native_map cap slot (ArchVSpaceAcc_A.store_pde target entry) + (match cap with + | .ArchObjectCap (.PageTableCap _ (some (asid, _))) => some asid + | _ => none) (ArchVSpace_A.invalidate_page_structure_cache_asid (Platform.addrFromPPtr root)) + +/-- [P] The capability slot admits this mapping-capability write. -/ +theorem patched_performPageTableMap_equiv (hop : OpaqueRel RestRel) + (cap : Structures_A.cap) (slot : CslotPtr) (entry : Arch_Structs_A.pde) (target root : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hw : SetCapSafe cap slot sH) : + MRelStep SR Eq (perform_page_table_map_p cap slot entry target root sH) + (Fl4Spec.performPageTableInvocation (embPageTableInv (.PageTableMap cap slot entry target root)) sL) := by + have hmap := performNativeMap_equiv cap slot + (match cap with + | .ArchObjectCap (.PageTableCap _ (some (asid, _))) => some asid + | _ => none) (storePde_equiv target entry) (invalidateNativeMap_equiv hop root) hs hw + cases cap with + | ArchObjectCap arch => + cases arch with + | PageTableCap obj mapping => + cases mapping + · exact hmap + · rename_i pair + rcases pair with ⟨asid, addr⟩ + exact hmap + | _ => exact hmap + | _ => exact hmap + +/-- l4v: the PageDirectoryMap branch of Arch_A.X64_A.perform_page_directory_invocation, with base-slot writes. -/ +def perform_page_directory_map_p (cap : Structures_A.cap) (slot : CslotPtr) + (entry : Arch_Structs_A.pdpte) (target root : ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + perform_native_map cap slot (ArchVSpaceAcc_A.store_pdpte target entry) + (match cap with + | .ArchObjectCap (.PageDirectoryCap _ (some (asid, _))) => some asid + | _ => none) (ArchVSpace_A.invalidate_page_structure_cache_asid (Platform.addrFromPPtr root)) + +/-- [P] The capability slot admits this mapping-capability write. -/ +theorem patched_performPageDirectoryMap_equiv (hop : OpaqueRel RestRel) + (cap : Structures_A.cap) (slot : CslotPtr) (entry : Arch_Structs_A.pdpte) (target root : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hw : SetCapSafe cap slot sH) : + MRelStep SR Eq (perform_page_directory_map_p cap slot entry target root sH) + (Fl4Spec.performPageDirectoryInvocation (embPageDirectoryInv (.PageDirectoryMap cap slot entry target root)) sL) := by + have hmap := performNativeMap_equiv cap slot + (match cap with + | .ArchObjectCap (.PageDirectoryCap _ (some (asid, _))) => some asid + | _ => none) (storePdpte_equiv target entry) (invalidateNativeMap_equiv hop root) hs hw + cases cap with + | ArchObjectCap arch => + cases arch with + | PageDirectoryCap obj mapping => + cases mapping + · exact hmap + · rename_i pair + rcases pair with ⟨asid, addr⟩ + exact hmap + | _ => exact hmap + | _ => exact hmap + +/-- l4v: the PDPTMap branch of Arch_A.X64_A.perform_pdpt_invocation, with base-slot writes. -/ +def perform_pdpt_map_p (cap : Structures_A.cap) (slot : CslotPtr) + (entry : Arch_Structs_A.pml4e) (target root : ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + perform_native_map cap slot (ArchVSpaceAcc_A.store_pml4e target entry) + (match cap with + | .ArchObjectCap (.PDPointerTableCap _ (some (asid, _))) => some asid + | _ => none) (ArchVSpace_A.invalidate_page_structure_cache_asid (Platform.addrFromPPtr root)) + +/-- [P] The capability slot admits this mapping-capability write. -/ +theorem patched_performPdptMap_equiv (hop : OpaqueRel RestRel) + (cap : Structures_A.cap) (slot : CslotPtr) (entry : Arch_Structs_A.pml4e) (target root : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hw : SetCapSafe cap slot sH) : + MRelStep SR Eq (perform_pdpt_map_p cap slot entry target root sH) + (Fl4Spec.performPdptInvocation (embPdptInv (.PDPTMap cap slot entry target root)) sL) := by + have hmap := performNativeMap_equiv cap slot + (match cap with + | .ArchObjectCap (.PDPointerTableCap _ (some (asid, _))) => some asid + | _ => none) (storePml4e_equiv target entry) (invalidateNativeMap_equiv hop root) hs hw + cases cap with + | ArchObjectCap arch => + cases arch with + | PDPointerTableCap obj mapping => + cases mapping + · exact hmap + · rename_i pair + rcases pair with ⟨asid, addr⟩ + exact hmap + | _ => exact hmap + | _ => exact hmap + +private theorem nonDetBindAssoc {σ α β γ : Type} (m : NonDet σ α) + (f : α → NonDet σ β) (g : β → NonDet σ γ) : + NonDet.bind (NonDet.bind m f) g = NonDet.bind m (fun x => NonDet.bind (f x) g) := by + funext s + apply Prod.ext + · ext pair + simp only [NonDet.bind, Set.mem_ofPred_eq] + constructor + · rintro ⟨y, ⟨x, hx, hy⟩, h⟩ + exact ⟨x, hx, y, hy, h⟩ + · rintro ⟨x, hx, y, hy, h⟩ + exact ⟨y, ⟨x, hx, hy⟩, h⟩ + · simp only [NonDet.bind, Set.mem_ofPred_eq] + apply propext + constructor + · rintro ((hm | ⟨x, hx, hf⟩) | ⟨y, ⟨x, hx, hy⟩, hg⟩) + · exact Or.inl hm + · exact Or.inr ⟨x, hx, Or.inl hf⟩ + · exact Or.inr ⟨x, hx, Or.inr ⟨y, hy, hg⟩⟩ + · rintro (hm | ⟨x, hx, hf | ⟨y, hy, hg⟩⟩) + · exact Or.inl (Or.inl hm) + · exact Or.inl (Or.inr ⟨x, hx, hf⟩) + · exact Or.inr ⟨y, ⟨x, hx, hy⟩, hg⟩ + +private def clear_mapping_cap_p (slot : CslotPtr) (mt : Option MachineTypes.vmmap_type) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (get_cap_p slot) fun cap => + set_cap_p (.ArchObjectCap (ArchVSpace_A.update_map_data cap.the_arch_cap none mt)) slot + +private def mappingCapSupported (cap : Structures_A.cap) (mt : Option MachineTypes.vmmap_type) : Prop := + match cap with + | .ArchObjectCap (.PageCap ..) => mt.isSome = true + | .ArchObjectCap (.PageTableCap ..) | .ArchObjectCap (.PageDirectoryCap ..) + | .ArchObjectCap (.PDPointerTableCap ..) => True + | _ => False + +/-- [P] A successful slot read supplies a native mapping cap and permits its write-back. -/ +def ClearMappingCapSafe (slot : CslotPtr) (mt : Option MachineTypes.vmmap_type) + (s : Structures_A.state ZH) : Prop := + ∀ cap t, (cap, t) ∈ (get_cap_p slot s).1 → + mappingCapSupported cap mt ∧ + SetCapSafe (.ArchObjectCap (ArchVSpace_A.update_map_data cap.the_arch_cap none mt)) slot t + +private theorem updatedMapCap_eq (cap : Structures_A.cap) (mt : Option MachineTypes.vmmap_type) + (h : mappingCapSupported cap mt) : + embArchCap (ArchVSpace_A.update_map_data cap.the_arch_cap none mt) = + Fl4Spec.updateMapData (embCap cap).theArchCap none (mt.map embVMMapType) := by + cases cap <;> try contradiction + rename_i arch + cases arch <;> try contradiction + case PageCap => + cases mt + · contradiction + · rfl + all_goals rfl + +private theorem clearMappingCap_equiv (slot : CslotPtr) (mt : Option MachineTypes.vmmap_type) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hc : ClearMappingCapSafe slot mt sH) : + MRelStep SR Eq (clear_mapping_cap_p slot mt sH) + ((do + let arch ← NonDet.liftM Cap.theArchCap (Fl4Spec.getCap slot) + Fl4Spec.setCap (.archObjectCap (Fl4Spec.updateMapData arch none + (mt.map embVMMapType))) slot) sL) := by + change MRelStep SR Eq _ (NonDet.bind (NonDet.liftM Cap.theArchCap (Fl4Spec.getCap slot)) + (fun arch => Fl4Spec.setCap (.archObjectCap (Fl4Spec.updateMapData arch none + (mt.map embVMMapType))) slot) sL) + rw [NonDet.liftM, nonDetBindAssoc] + unfold clear_mapping_cap_p + refine mrelStep_bind_mem (patched_getCap_equiv slot sH sL hs) fun capH capL hcap tH tL ht hread => ?_ + subst hcap + rw [IpcCancel.nonDet_bind_pure_left] + obtain ⟨hk, hw⟩ := hc capH tH hread + have hset := patched_setCap_equiv_at _ slot ht hw + change MRelStep SR Eq _ (Fl4Spec.setCap (.archObjectCap + (embArchCap (ArchVSpace_A.update_map_data capH.the_arch_cap none mt))) slot tL) at hset + rw [updatedMapCap_eq capH mt hk] at hset + exact hset + +private theorem clearMappingAfterPure_equiv (slot : CslotPtr) (mt : Option MachineTypes.vmmap_type) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hc : ∀ t, ((), t) ∈ (holReturn () sH).1 → ClearMappingCapSafe slot mt t) : + MRelStep SR Eq (holBind (holReturn ()) (fun _ => clear_mapping_cap_p slot mt) sH) + ((do + let arch ← NonDet.liftM Cap.theArchCap (Fl4Spec.getCap slot) + Fl4Spec.setCap (.archObjectCap (Fl4Spec.updateMapData arch none + (mt.map embVMMapType))) slot) sL) := by + rw [KHeap.holBind_return_left] + exact clearMappingCap_equiv slot mt hs (hc sH (by simp [holReturn])) + +private def mapped_page_unmap (size : MachineTypes.vmpage_size) (base : ObjRef) + (mapping : Option (Asid × VSpaceRef)) : HolNonDet (Structures_A.state ZH) Unit := + mapping.elim (holReturn ()) fun (asid, addr) => ArchVSpace_A.unmap_page size asid addr base + +/-- l4v: Arch_A.X64_A.perform_page_invocation_unmap with base-slot reads and writes. -/ +def perform_page_invocation_unmap_p (cap : Arch_Structs_A.arch_cap) (slot : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + match cap with + | .PageCap _ base _ _ size mapping => + holBind (mapped_page_unmap size base mapping) fun _ => clear_mapping_cap_p slot (some .VMNoMap) + | _ => holFail + +/-- [P] Frame unmapping admits the original ASID range and the reached cap update. -/ +def PageUnmapSafe (cap : Arch_Structs_A.arch_cap) (slot : CslotPtr) (s : Structures_A.state ZH) : Prop := + match cap with + | .PageCap _ base _ _ size mapping => + (∀ asid addr, mapping = some (asid, addr) → BaseAsid asid) ∧ + ∀ t, ((), t) ∈ (mapped_page_unmap size base mapping s).1 → ClearMappingCapSafe slot (some .VMNoMap) t + | _ => True + +theorem patched_performPageInvocationUnmap_equiv (hop : OpaqueRel RestRel) + (cap : Arch_Structs_A.arch_cap) (slot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (hi : PageUnmapSafe cap slot sH) : + MRelStep SR Eq (perform_page_invocation_unmap_p cap slot sH) + (Fl4Spec.performPageInvocationUnmap (embArchCap cap) slot sL) := by + cases cap <;> try exact mrel_fail sH sL hs + case PageCap dev base rights mt size mapping => + obtain ⟨ha, hc⟩ := hi + cases mapping with + | none => + exact clearMappingAfterPure_equiv slot (some .VMNoMap) hs hc + | some pair => + obtain ⟨asid, addr⟩ := pair + refine mrelStep_bind_mem (unmapPage_equiv hop size asid addr base (ha asid addr rfl) hs hb) + fun _ _ _ tH tL ht hm => ?_ + exact clearMappingCap_equiv slot (some .VMNoMap) ht (hc tH hm) + +private def mapped_page_table_unmap (p : ObjRef) (mapping : Option (Asid × VSpaceRef)) : + HolNonDet (Structures_A.state ZH) Unit := + mapping.elim (holReturn ()) fun (asid, addr) => + holBind (ArchVSpace_A.unmap_page_table asid addr p) fun _ => + holMapMx (fun slot => ArchVSpaceAcc_A.store_pte slot .InvalidPTE) + (holUptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Arch_Structs_A.pt_bits) - 1)) + +/-- l4v: the PageTableUnmap branch of Arch_A.X64_A.perform_page_table_invocation. -/ +def perform_page_table_unmap_p (cap : Structures_A.cap) (slot : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + match cap with + | .ArchObjectCap (.PageTableCap p mapping) => + holBind (mapped_page_table_unmap p mapping) fun _ => clear_mapping_cap_p slot none + | _ => holFail + +/-- [P] Table unmapping admits the original ASID range and the reached cap update. -/ +def PageTableUnmapSafe (cap : Structures_A.cap) (slot : CslotPtr) (s : Structures_A.state ZH) : Prop := + match cap with + | .ArchObjectCap (.PageTableCap p mapping) => + (∀ asid addr, mapping = some (asid, addr) → BaseAsid asid) ∧ + ∀ t, ((), t) ∈ (mapped_page_table_unmap p mapping s).1 → ClearMappingCapSafe slot none t + | _ => True + +theorem patched_performPageTableUnmap_equiv (hop : OpaqueRel RestRel) + (cap : Structures_A.cap) (slot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (hi : PageTableUnmapSafe cap slot sH) : + MRelStep SR Eq (perform_page_table_unmap_p cap slot sH) + (Fl4Spec.performPageTableInvocation (embPageTableInv (.PageTableUnmap cap slot)) sL) := by + cases cap <;> try exact mrel_fail sH sL hs + rename_i arch + cases arch <;> try exact mrel_fail sH sL hs + case PageTableCap p mapping => + obtain ⟨ha, hc⟩ := hi + cases mapping with + | none => + exact clearMappingAfterPure_equiv slot none hs hc + | some pair => + obtain ⟨asid, addr⟩ := pair + have hunmap := unmapPageTable_equiv hop asid addr p (ha asid addr rfl) hs hb + have hclear : MRel SR Eq + (holMapMx (fun target => ArchVSpaceAcc_A.store_pte target .InvalidPTE) + (holUptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Arch_Structs_A.pt_bits) - 1))) + (NonDet.mapMx (fun target => Fl4Spec.storePte target .invalidPTE) + (Fl4Spec.uptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Fl4Spec.ptBits) - 1))) := by + rw [holUptoEnumStep_eq] + exact mrel_mapMx (Rb := Eq) (fun a _ hab => + hab ▸ storePte_equiv a .InvalidPTE) (listRel_eq _) + have hprefix := mrelStep_bind_mem hunmap fun _ _ _ tH tL ht _ => hclear tH tL ht + simp only [Fl4Spec.performPageTableInvocation, embPageTableInv, embCap, embArchCap, + Bind.bind, Pure.pure, IpcCancel.nonDet_bind_pure_left] + change MRelStep SR Eq _ (NonDet.bind (Fl4Spec.unmapPageTable asid addr p) + (fun _ => NonDet.bind + (NonDet.mapMx (fun target => Fl4Spec.storePte target .invalidPTE) + (Fl4Spec.uptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Fl4Spec.ptBits) - 1))) + (fun _ => do + let arch ← NonDet.liftM Cap.theArchCap (Fl4Spec.getCap slot) + Fl4Spec.setCap (.archObjectCap (Fl4Spec.updateMapData arch none none)) slot)) sL) + rw [← nonDetBindAssoc] + refine mrelStep_bind_mem hprefix fun _ _ _ tH tL ht hm => ?_ + exact clearMappingCap_equiv slot none ht (hc tH hm) + +private def mapped_page_directory_unmap (p : ObjRef) (mapping : Option (Asid × VSpaceRef)) : + HolNonDet (Structures_A.state ZH) Unit := + mapping.elim (holReturn ()) fun (asid, addr) => + holBind (ArchVSpace_A.unmap_pd asid addr p) fun _ => + holMapMx (fun slot => ArchVSpaceAcc_A.store_pde slot .InvalidPDE) + (holUptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Arch_Structs_A.pd_bits) - 1)) + +/-- l4v: the PageDirectoryUnmap branch of Arch_A.X64_A.perform_page_directory_invocation. -/ +def perform_page_directory_unmap_p (cap : Structures_A.cap) (slot : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + match cap with + | .ArchObjectCap (.PageDirectoryCap p mapping) => + holBind (mapped_page_directory_unmap p mapping) fun _ => clear_mapping_cap_p slot none + | _ => holFail + +/-- [P] Table unmapping admits the original ASID range and the reached cap update. -/ +def PageDirectoryUnmapSafe (cap : Structures_A.cap) (slot : CslotPtr) (s : Structures_A.state ZH) : Prop := + match cap with + | .ArchObjectCap (.PageDirectoryCap p mapping) => + (∀ asid addr, mapping = some (asid, addr) → BaseAsid asid) ∧ + ∀ t, ((), t) ∈ (mapped_page_directory_unmap p mapping s).1 → ClearMappingCapSafe slot none t + | _ => True + +theorem patched_performPageDirectoryUnmap_equiv (hop : OpaqueRel RestRel) + (cap : Structures_A.cap) (slot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (hi : PageDirectoryUnmapSafe cap slot sH) : + MRelStep SR Eq (perform_page_directory_unmap_p cap slot sH) + (Fl4Spec.performPageDirectoryInvocation (embPageDirectoryInv (.PageDirectoryUnmap cap slot)) sL) := by + cases cap <;> try exact mrel_fail sH sL hs + rename_i arch + cases arch <;> try exact mrel_fail sH sL hs + case PageDirectoryCap p mapping => + obtain ⟨ha, hc⟩ := hi + cases mapping with + | none => + exact clearMappingAfterPure_equiv slot none hs hc + | some pair => + obtain ⟨asid, addr⟩ := pair + have hunmap := unmapPd_equiv hop asid addr p (ha asid addr rfl) hs hb + have hclear : MRel SR Eq + (holMapMx (fun target => ArchVSpaceAcc_A.store_pde target .InvalidPDE) + (holUptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Arch_Structs_A.pd_bits) - 1))) + (NonDet.mapMx (fun target => Fl4Spec.storePde target .invalidPDE) + (Fl4Spec.uptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Fl4Spec.pdBits) - 1))) := by + rw [holUptoEnumStep_eq] + exact mrel_mapMx (Rb := Eq) (fun a _ hab => + hab ▸ storePde_equiv a .InvalidPDE) (listRel_eq _) + have hprefix := mrelStep_bind_mem hunmap fun _ _ _ tH tL ht _ => hclear tH tL ht + simp only [Fl4Spec.performPageDirectoryInvocation, embPageDirectoryInv, embCap, embArchCap, + Bind.bind, Pure.pure, IpcCancel.nonDet_bind_pure_left] + change MRelStep SR Eq _ (NonDet.bind (Fl4Spec.unmapPd asid addr p) + (fun _ => NonDet.bind + (NonDet.mapMx (fun target => Fl4Spec.storePde target .invalidPDE) + (Fl4Spec.uptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Fl4Spec.pdBits) - 1))) + (fun _ => do + let arch ← NonDet.liftM Cap.theArchCap (Fl4Spec.getCap slot) + Fl4Spec.setCap (.archObjectCap (Fl4Spec.updateMapData arch none none)) slot)) sL) + rw [← nonDetBindAssoc] + refine mrelStep_bind_mem hprefix fun _ _ _ tH tL ht hm => ?_ + exact clearMappingCap_equiv slot none ht (hc tH hm) + +private def mapped_pdpt_unmap (p : ObjRef) (mapping : Option (Asid × VSpaceRef)) : + HolNonDet (Structures_A.state ZH) Unit := + mapping.elim (holReturn ()) fun (asid, addr) => + holBind (ArchVSpace_A.unmap_pdpt asid addr p) fun _ => + holMapMx (fun slot => ArchVSpaceAcc_A.store_pdpte slot .InvalidPDPTE) + (holUptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Arch_Structs_A.pdpt_bits) - 1)) + +/-- l4v: the PDPTUnmap branch of Arch_A.X64_A.perform_pdpt_invocation. -/ +def perform_pdpt_unmap_p (cap : Structures_A.cap) (slot : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + match cap with + | .ArchObjectCap (.PDPointerTableCap p mapping) => + holBind (mapped_pdpt_unmap p mapping) fun _ => clear_mapping_cap_p slot none + | _ => holFail + +/-- [P] Table unmapping admits the original ASID range and the reached cap update. -/ +def PdptUnmapSafe (cap : Structures_A.cap) (slot : CslotPtr) (s : Structures_A.state ZH) : Prop := + match cap with + | .ArchObjectCap (.PDPointerTableCap p mapping) => + (∀ asid addr, mapping = some (asid, addr) → BaseAsid asid) ∧ + ∀ t, ((), t) ∈ (mapped_pdpt_unmap p mapping s).1 → ClearMappingCapSafe slot none t + | _ => True + +theorem patched_performPdptUnmap_equiv (hop : OpaqueRel RestRel) + (cap : Structures_A.cap) (slot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (hi : PdptUnmapSafe cap slot sH) : + MRelStep SR Eq (perform_pdpt_unmap_p cap slot sH) + (Fl4Spec.performPdptInvocation (embPdptInv (.PDPTUnmap cap slot)) sL) := by + cases cap <;> try exact mrel_fail sH sL hs + rename_i arch + cases arch <;> try exact mrel_fail sH sL hs + case PDPointerTableCap p mapping => + obtain ⟨ha, hc⟩ := hi + cases mapping with + | none => + exact clearMappingAfterPure_equiv slot none hs hc + | some pair => + obtain ⟨asid, addr⟩ := pair + have hunmap := unmapPdpt_equiv hop asid addr p (ha asid addr rfl) hs hb + have hclear : MRel SR Eq + (holMapMx (fun target => ArchVSpaceAcc_A.store_pdpte target .InvalidPDPTE) + (holUptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Arch_Structs_A.pdpt_bits) - 1))) + (NonDet.mapMx (fun target => Fl4Spec.storePdpte target .invalidPDPTE) + (Fl4Spec.uptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Fl4Spec.pdptBits) - 1))) := by + rw [holUptoEnumStep_eq] + exact mrel_mapMx (Rb := Eq) (fun a _ hab => + hab ▸ storePdpte_equiv a .InvalidPDPTE) (listRel_eq _) + have hprefix := mrelStep_bind_mem hunmap fun _ _ _ tH tL ht _ => hclear tH tL ht + simp only [Fl4Spec.performPdptInvocation, embPdptInv, embCap, embArchCap, + Bind.bind, Pure.pure, IpcCancel.nonDet_bind_pure_left] + change MRelStep SR Eq _ (NonDet.bind (Fl4Spec.unmapPdpt asid addr p) + (fun _ => NonDet.bind + (NonDet.mapMx (fun target => Fl4Spec.storePdpte target .invalidPDPTE) + (Fl4Spec.uptoEnumStep p (p + ((1 : Word) <<< Fl4Spec.wordSizeBits)) + (p + ((1 : Word) <<< Fl4Spec.pdptBits) - 1))) + (fun _ => do + let arch ← NonDet.liftM Cap.theArchCap (Fl4Spec.getCap slot) + Fl4Spec.setCap (.archObjectCap (Fl4Spec.updateMapData arch none none)) slot)) sL) + rw [← nonDetBindAssoc] + refine mrelStep_bind_mem hprefix fun _ _ _ tH tL ht hm => ?_ + exact clearMappingCap_equiv slot none ht (hc tH hm) + +/-- l4v: Arch_A.X64_A.perform_page_invocation with related base-slot updates. -/ +def perform_page_invocation_p : ArchInvocation_A.page_invocation → + HolNonDet (Structures_A.state ZH) (List Data) + | .PageMap cap slot (entry, target) root => perform_page_map_p cap slot entry target root + | .PageUnmap cap slot => + match cap with + | .PageCap _ _ _ mt _ mapping => + holBind (match mapping with + | none => holReturn () + | some _ => match mt with + | .VMVSpaceMap => perform_page_invocation_unmap_p cap slot + | _ => holFail) fun _ => holReturn [] + | _ => holFail + | .PageGetAddr ptr => holReturn [Platform.addrFromPPtr ptr] + +/-- [P] Native frame invocations admit their actual writes and use ASIDs in the common range. -/ +def PagePerformSafe (i : ArchInvocation_A.page_invocation) (s : Structures_A.state ZH) : Prop := + match i with + | .PageMap cap slot _ _ => SetCapSafe cap slot s + | .PageUnmap (.PageCap d p r .VMVSpaceMap sz (some a)) slot => + PageUnmapSafe (.PageCap d p r .VMVSpaceMap sz (some a)) slot s + | _ => True + +theorem patched_performPageInvocation_equiv (hop : OpaqueRel RestRel) + (i : ArchInvocation_A.page_invocation) {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hb : BaseCarriers sL) (hi : PagePerformSafe i sH) : + MRelStep SR Eq (perform_page_invocation_p i sH) (Fl4Spec.performPageInvocation (embPageInv i) sL) := by + cases i with + | PageMap cap slot data root => + obtain ⟨entry, target⟩ := data + exact patched_performPageMap_equiv hop cap slot entry target root hs hi + | PageGetAddr ptr => exact mrel_return (show [Platform.addrFromPPtr ptr] = _ by rw [addrFromPPtr_eq]) sH sL hs + | PageUnmap cap slot => + cases cap <;> try exact mrel_fail sH sL hs + case PageCap dev base rights mt size mapping => + cases mapping with + | none => + change MRelStep SR Eq (holBind (holReturn ()) (fun _ => holReturn []) sH) _ + rw [KHeap.holBind_return_left] + exact mrel_return rfl sH sL hs + | some pair => + obtain ⟨asid, addr⟩ := pair + cases mt + all_goals + first + | exact mrelStep_bind_mem + (patched_performPageInvocationUnmap_equiv hop _ slot hs hb hi) + (fun _ _ _ tH tL ht _ => mrel_return rfl tH tL ht) + | exact mrel_kbind (Ra := Eq) mrel_fail (mrel_return (show ([] : List Data) = [] from rfl)) sH sL hs + +private def arch_no_return_p (m : HolNonDet (Structures_A.state ZH) Unit) : + HolNonDet (Structures_A.state ZH) (List Data) := holBind m fun _ => holReturn [] + +/-- l4v: Arch_A.X64_A.arch_perform_invocation with the checked base carriers. -/ +def arch_perform_invocation_p (i : ArchInvocation_A.arch_invocation) : + HolNonDet (Structures_A.state ZH) (Sum Unit (List Data)) := + holLiftE <| match i with + | .InvokePageTable (.PageTableMap cap slot entry target root) => + arch_no_return_p (perform_page_table_map_p cap slot entry target root) + | .InvokePageTable (.PageTableUnmap cap slot) => arch_no_return_p (perform_page_table_unmap_p cap slot) + | .InvokePageDirectory (.PageDirectoryMap cap slot entry target root) => + arch_no_return_p (perform_page_directory_map_p cap slot entry target root) + | .InvokePageDirectory (.PageDirectoryUnmap cap slot) => + arch_no_return_p (perform_page_directory_unmap_p cap slot) + | .InvokePDPT (.PDPTMap cap slot entry target root) => arch_no_return_p (perform_pdpt_map_p cap slot entry target root) + | .InvokePDPT (.PDPTUnmap cap slot) => arch_no_return_p (perform_pdpt_unmap_p cap slot) + | .InvokePage oper => perform_page_invocation_p oper + | .InvokeASIDControl oper => arch_no_return_p (perform_asid_control_invocation_p oper) + | .InvokeASIDPool oper => arch_no_return_p (perform_asid_pool_invocation_p oper) + | .InvokeIOPort oper => Arch_A.perform_io_port_invocation oper + | .InvokeIOPortControl oper => arch_no_return_p (perform_ioport_control_invocation_p oper) + +/-- [P] The selected architecture operation admits the native cap, ASID and retype carriers. -/ +def ArchPerformSafe (i : ArchInvocation_A.arch_invocation) (s : Structures_A.state ZH) : Prop := + match i with + | .InvokePageTable (.PageTableMap cap slot ..) + | .InvokePageDirectory (.PageDirectoryMap cap slot ..) + | .InvokePDPT (.PDPTMap cap slot ..) => SetCapSafe cap slot s + | .InvokePageTable (.PageTableUnmap cap slot) => PageTableUnmapSafe cap slot s + | .InvokePageDirectory (.PageDirectoryUnmap cap slot) => PageDirectoryUnmapSafe cap slot s + | .InvokePDPT (.PDPTUnmap cap slot) => PdptUnmapSafe cap slot s + | .InvokePage oper => PagePerformSafe oper s + | .InvokeASIDControl oper => AsidControlPerformSafe oper s + | .InvokeASIDPool oper => AsidPoolPerformSafe oper s + | .InvokeIOPort _ => True + | .InvokeIOPortControl oper => IoportControlSafe oper s + +private theorem archNoReturn_equiv {mH : HolNonDet (Structures_A.state ZH) Unit} + {mL : SMonad ZL Unit} {sH : Structures_A.state ZH} {sL : State ZL} + (hm : MRelStep SR Eq (mH sH) (mL sL)) : + MRelStep SR Eq (arch_no_return_p mH sH) (Fl4Spec.archNoReturn mL sL) := + mrelStep_bind_mem hm fun _ _ _ tH tL ht _ => mrel_return rfl tH tL ht + +theorem patched_archPerformInvocation_equiv (hop : OpaqueRel RestRel) (i : ArchInvocation_A.arch_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hi : ArchPerformSafe i sH) : + MRelStep SR (SumExceptRel Eq Eq) (arch_perform_invocation_p i sH) + ((Fl4Spec.archPerformInvocation (embArchInv i)).run sL) := by + cases i with + | InvokePage oper => exact mrelStep_liftE (patched_performPageInvocation_equiv hop oper hs hb hi) + | InvokePageTable oper => + cases oper + · exact mrelStep_liftE (archNoReturn_equiv (patched_performPageTableMap_equiv hop _ _ _ _ _ hs hi)) + · exact mrelStep_liftE (archNoReturn_equiv (patched_performPageTableUnmap_equiv hop _ _ hs hb hi)) + | InvokePageDirectory oper => + cases oper + · exact mrelStep_liftE (archNoReturn_equiv (patched_performPageDirectoryMap_equiv hop _ _ _ _ _ hs hi)) + · exact mrelStep_liftE (archNoReturn_equiv (patched_performPageDirectoryUnmap_equiv hop _ _ hs hb hi)) + | InvokePDPT oper => + cases oper + · exact mrelStep_liftE (archNoReturn_equiv (patched_performPdptMap_equiv hop _ _ _ _ _ hs hi)) + · exact mrelStep_liftE (archNoReturn_equiv (patched_performPdptUnmap_equiv hop _ _ hs hb hi)) + | InvokeASIDControl oper => + exact mrelStep_liftE (archNoReturn_equiv (patched_performAsidControlInvocation_equiv hop oper hs hi)) + | InvokeASIDPool oper => + exact mrelStep_liftE (archNoReturn_equiv (patched_performAsidPoolInvocation_equiv oper hs hi)) + | InvokeIOPort oper => exact mrelStep_liftE (performIoPortInvocation_equiv hop oper sH sL hs) + | InvokeIOPortControl oper => + exact mrelStep_liftE (archNoReturn_equiv (patched_performIoportControlInvocation_equiv oper hs hi)) + +end + +end L4vRefX64.Equiv.ArchInvoke diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchSwitch.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchSwitch.lean new file mode 100644 index 000000000..eb4a67ffa --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchSwitch.lean @@ -0,0 +1,51 @@ +import L4vRefX64.Equiv.Fpu +import L4vRefX64.Equiv.VSpaceRoot +import L4vRefX64.Spec.Arch_A + +namespace L4vRefX64.Equiv.ArchSwitch + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Fpu L4vRefX64.Equiv.VSpaceRoot +open Fl4Spec Classical + +noncomputable section + +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 archSwitchToThread_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : ReferenceBaseCarriers sH) : + MRelStep SR Eq (Arch_A.arch_switch_to_thread thread sH) (Fl4Spec.archSwitchToThread thread sL) := by + unfold Arch_A.arch_switch_to_thread Fl4Spec.archSwitchToThread + refine mrelStep_bind_mem (setVmRoot_equiv thread hs (hs.baseCarriers_iff.mpr hb)) + fun _ _ _ s1H s1L hs1 _ => ?_ + exact lazyFpuRestore_equiv hop thread s1H s1L hs1 + +theorem archSwitchToIdleThread_equiv + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : ReferenceBaseCarriers sH) : + MRelStep SR Eq (Arch_A.arch_switch_to_idle_thread sH) (Fl4Spec.archSwitchToIdleThread sL) := by + unfold Arch_A.arch_switch_to_idle_thread Fl4Spec.archSwitchToIdleThread + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.idleThread_eq.symm) sH sL hs) + fun tH tL ht s1H s1L hs1 hm => ?_ + subst ht + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm + obtain ⟨_, heq⟩ := hm + subst s1H + exact setVmRoot_equiv tH hs1 (hs1.baseCarriers_iff.mpr hb) + +theorem archPrepareNextDomain_equiv (hop : OpaqueRel RestRel) : + MRel SR Eq Arch_A.arch_prepare_next_domain Fl4Spec.archPrepareNextDomain := + switchLocalFpuOwner_equiv hop none + +theorem archActivateIdleThread_equiv (thread : ObjRef) : + MRel SR Eq (Arch_A.arch_activate_idle_thread thread) (Fl4Spec.archActivateIdleThread thread) := + mrel_return rfl + +end + +end L4vRefX64.Equiv.ArchSwitch diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchVSpace.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchVSpace.lean new file mode 100644 index 000000000..b1f98398e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/ArchVSpace.lean @@ -0,0 +1,124 @@ +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Equiv.IpcCancel +import L4vRefX64.Equiv.Types +import L4vRefX64.Patched + +namespace L4vRefX64.Equiv.ArchVSpace + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec +open L4vRefX64.Equiv.Machine +open L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.Types +open L4vRefX64.Equiv.KHeap +open L4vRefX64.Equiv.CSpaceAcc +open L4vRefX64.Equiv.IpcCancel +open Fl4Spec +open Classical + +noncomputable section + +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 inUserFrame_iff {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (p : ObjRef) : + ArchVSpace_A.in_user_frame p sH = true ↔ Fl4Spec.inUserFrame p sL := by + unfold ArchVSpace_A.in_user_frame Fl4Spec.inUserFrame + simp only [holEx_eq_true, holEq_eq_true] + constructor + · rintro ⟨sz, h⟩ + refine ⟨embVMPageSize sz, ?_⟩ + rw [pageBitsForSize_eq, mask_eq, hs.kheap_eq] + change (sH.kheap (holWordAnd p (holWordNot (holWordMask (MachineTypes.pageBitsForSize sz))))).map + embKernelObject = _ + rw [h]; rfl + · rintro ⟨szL, h⟩ + refine ⟨unembVMPageSize szL, ?_⟩ + have hsz : embVMPageSize (unembVMPageSize szL) = szL := embVMPageSize_unemb szL + rw [← hsz, pageBitsForSize_eq, mask_eq, hs.kheap_eq] at h + cases hk : sH.kheap (holWordAnd p (holWordNot (holWordMask (MachineTypes.pageBitsForSize (unembVMPageSize szL))))) with + | none => + simp only [holWordAnd, holWordNot] at hk + simp [hk] at h + | some ko => + simp only [holWordAnd, holWordNot] at hk + simp only [hk, Option.map_some, Option.some.injEq] at h + cases ko with + | ArchObj ao => + cases ao with + | DataPage dev sz' => + simp only [embKernelObject, embArchKobj, KernelObject.archObj.injEq, + ArchKernelObj.dataPage.injEq] at h + rcases h with ⟨rfl, hsz'⟩ + rw [embVMPageSize_injective hsz'] + | _ => simp [embKernelObject, embArchKobj] at h + | _ => simp [embKernelObject] at h + +theorem patched_lookupIpcBuffer_equiv (isReceiver : Bool) (thread : ObjRef) : + MRel SR Eq (Patched.lookupIpcBuffer isReceiver thread) (Fl4Spec.lookupIpcBuffer isReceiver thread) := by + unfold Patched.lookupIpcBuffer Patched.lookupIpcBufferAt Fl4Spec.lookupIpcBuffer + refine mrel_bind (threadGet_equiv (fun _ => rfl) thread) fun ptrH ptrL hptr => ?_ + subst hptr + change MRel SR Eq _ (NonDet.bind (NonDet.pure (thread, Fl4Spec.tcbCnodeIndex 2)) _) + rw [KHeap.holBind_return_left, nonDet_bind_pure_left] + refine mrel_bind (getCap_equiv_nonExt (thread, Fl4Spec.tcbCnodeIndex 2) + (show Fl4Spec.tcbCnodeIndex 2 ≠ Fl4Spec.tcbCnodeIndex 5 from by decide)) fun capH capL hcap => ?_ + subst hcap + cases capH with + | ArchObjectCap ac => + cases ac with + | PageCap dev base rights mapType size mapping => + simp only [Patched.ipcBufferAddress, embCap, embArchCap] + have hreadWrite : VMRights_A.vm_read_write ⊆ rights ↔ + Fl4Spec.vmReadWrite ⊆ embRightsSet rights := by + rw [vmReadWrite_eq] + exact (Set.image_subset_image_iff embRights_injective).symm + have hreadOnly : VMRights_A.vm_read_only ⊆ rights ↔ + Fl4Spec.vmReadOnly ⊆ embRightsSet rights := by + rw [vmReadOnly_eq] + exact (Set.image_subset_image_iff embRights_injective).symm + have hcond : holDisj (holLe VMRights_A.vm_read_write rights) + (holConj (holLe VMRights_A.vm_read_only rights) (holNot isReceiver)) = true ↔ + (Fl4Spec.vmReadWrite ⊆ embRightsSet rights ∨ + Fl4Spec.vmReadOnly ⊆ embRightsSet rights ∧ ¬ isReceiver) := by + simp only [holDisj_eq_true, holConj_eq_true, holLe_eq_true, HolOrd.leVal, + holNot_eq_true, hreadWrite, hreadOnly] + by_cases h : Fl4Spec.vmReadWrite ⊆ embRightsSet rights ∨ + Fl4Spec.vmReadOnly ⊆ embRightsSet rights ∧ ¬ isReceiver + · simp only [hcond.mpr h, holIf_true, ite_eq_left h] + exact mrel_return (by rw [pageBitsForSize_eq, mask_eq]; rfl) + · have hH : holDisj (holLe VMRights_A.vm_read_write rights) + (holConj (holLe VMRights_A.vm_read_only rights) (holNot isReceiver)) = false := + Bool.eq_false_iff.mpr (h ∘ hcond.mp) + simp only [hH, holIf_false, ite_eq_right h] + exact mrel_return rfl + | _ => exact mrel_return rfl + | _ => exact mrel_return rfl + +theorem checkValidIpcBuffer_equiv (vptr : VSpaceRef) (c : Structures_A.cap) : + MRelE SR (FunRel embSyscallError) Eq + (ArchVSpace_A.check_valid_ipc_buffer vptr c) + (Fl4Spec.checkValidIpcBuffer vptr (embCap c)) := by + cases c with + | ArchObjectCap a => + cases a with + | PageCap dev p R m sz mp => + cases dev with + | true => exact mrele_throwError rfl + | false => + unfold ArchVSpace_A.check_valid_ipc_buffer Fl4Spec.checkValidIpcBuffer + simp only [Structures_A.case_cap, Arch_Structs_A.case_arch_cap, holCaseBool_false, + embCap, embArchCap] + refine mrele_kbindE (mrele_whenE (by rw [msgAlignBits_eq]; simp [holNot_eq_true, isAligned_iff]) + fun _ => mrele_throwError rfl) (mrele_returnOk rfl) + | _ => exact mrele_throwError rfl + | _ => exact mrele_throwError rfl + +end + +end L4vRefX64.Equiv.ArchVSpace diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/CSpace.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/CSpace.lean new file mode 100644 index 000000000..8df3b56a1 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/CSpace.lean @@ -0,0 +1,2752 @@ +import L4vRefX64.Patched +import L4vRefX64.Equiv.IpcCancel +import L4vRefX64.Equiv.Retype +import L4vRefX64.Equiv.VSpaceUnmap +import L4vRefX64.Equiv.Fpu +import L4vRefX64.Equiv.SchedContext +import L4vRefX64.Spec.CSpace_A +import Mathlib.Data.Set.Lattice.Order + +namespace L4vRefX64.Equiv.CSpace + +open L4vRefX64.Prim L4vRefX64.Rel L4vRefX64.Spec +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.Deterministic L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.CSpaceAcc +open L4vRefX64.Equiv.IpcCancel +open L4vRefX64.Equiv.ArchCap L4vRefX64.Equiv.Retype L4vRefX64.Equiv.Types +open L4vRefX64.Equiv.VSpaceUnmap L4vRefX64.Equiv.Fpu L4vRefX64.Equiv.SchedContext +open Fl4Spec Classical + +noncomputable section + +def embRecDelCall : CSpace_A.rec_del_call → RecDelCall + | .CTEDeleteCall slot exposed => .cTEDeleteCall slot exposed + | .FinaliseSlotCall slot exposed => .finaliseSlotCall slot exposed + | .ReduceZombieCall cap slot exposed => .reduceZombieCall (embCap cap) slot exposed + +def embCapclass : CSpace_A.capclass → Capclass + | .PhysicalClass => .physicalClass + | .OtherCapClass => .otherCapClass + +/-! ## Pure CSpace_A functions -/ + +theorem acapRightsUpdate_eq (R : Set CapRights_A.rights) (c : Arch_Structs_A.arch_cap) : + Fl4Spec.acapRightsUpdate (embRightsSet R) (embArchCap c) = + embArchCap (Arch_Structs_A.acap_rights_update R c) := by + cases c with + | PageCap dev ref _ mapType sz as => + simp [Fl4Spec.acapRightsUpdate, Arch_Structs_A.acap_rights_update, + Arch_Structs_A.case_arch_cap, embArchCap, validateVmRights_eq] + | _ => rfl + +theorem capRightsUpdate_eq (R : Set CapRights_A.rights) (c : Structures_A.cap) : + Fl4Spec.capRightsUpdate (embRightsSet R) (embCap c) = + embCap (Structures_A.cap_rights_update R c) := by + cases c with + | EndpointCap r b _ => rfl + | NotificationCap r b _ => + simp only [Fl4Spec.capRightsUpdate, Structures_A.cap_rights_update, + Structures_A.case_cap, embCap, HolSub.subVal, holInsert_eq, HolCompleteLattice.holBot] + congr 1; ext x; rw [← embRights_unemb x] + simp only [Set.mem_sdiff, Set.mem_insert_iff, Set.mem_singleton_iff, Set.mem_empty_iff_false, + embRightsSet_mem, or_false] + cases unembRights x <;> simp [embRights] + | ReplyCap t _ => + simp only [Fl4Spec.capRightsUpdate, Structures_A.cap_rights_update, + Structures_A.case_cap, embCap, HolCompleteLattice.holSup, HolSub.subVal, + holInsert_eq, HolCompleteLattice.holBot] + congr 1; ext x; rw [← embRights_unemb x] + simp only [Set.mem_union, Set.mem_sdiff, Set.mem_insert_iff, Set.mem_singleton_iff, + Set.mem_empty_iff_false, embRightsSet_mem, or_false] + cases unembRights x <;> simp [embRights] + | ArchObjectCap a => + simp only [Fl4Spec.capRightsUpdate, Structures_A.cap_rights_update, + Structures_A.case_cap, embCap] + rw [acapRightsUpdate_eq] + | _ => rfl + +theorem maskCap_eq (R : Set CapRights_A.rights) (c : Structures_A.cap) : + Fl4Spec.maskCap (embRightsSet R) (embCap c) = embCap (Structures_A.mask_cap R c) := by + cases c with + | EndpointCap r b rs => + simp [Fl4Spec.maskCap, Structures_A.mask_cap, Structures_A.case_cap, + Fl4Spec.capRights, Structures_A.cap_rights, embCap, Fl4Spec.capRightsUpdate, + Structures_A.cap_rights_update, HolCompleteLattice.holInf, embRightsSet_inter] + | NotificationCap r b rs => + unfold Fl4Spec.maskCap Structures_A.mask_cap + change Fl4Spec.capRightsUpdate (embRightsSet rs ∩ embRightsSet R) (embCap (.NotificationCap r b rs)) = + embCap (Structures_A.cap_rights_update (rs ∩ R) (.NotificationCap r b rs)) + rw [← embRightsSet_inter, capRightsUpdate_eq] + | ReplyCap t rs => + unfold Fl4Spec.maskCap Structures_A.mask_cap + change Fl4Spec.capRightsUpdate (embRightsSet rs ∩ embRightsSet R) (embCap (.ReplyCap t rs)) = + embCap (Structures_A.cap_rights_update (rs ∩ R) (.ReplyCap t rs)) + rw [← embRightsSet_inter, capRightsUpdate_eq] + | ArchObjectCap a => + cases a with + | PageCap d p rs m sz mapping => + unfold Fl4Spec.maskCap Structures_A.mask_cap + change Fl4Spec.capRightsUpdate (embRightsSet rs ∩ embRightsSet R) (embCap (.ArchObjectCap (.PageCap d p rs m sz mapping))) = + embCap (Structures_A.cap_rights_update (rs ∩ R) (.ArchObjectCap (.PageCap d p rs m sz mapping))) + rw [← embRightsSet_inter, capRightsUpdate_eq] + | _ => rfl + | _ => rfl + +theorem dataToRights_eq (data : Data) : + Fl4Spec.dataToRights data = embRightsSet (CSpace_A.data_to_rights data) := by + ext r + unfold Fl4Spec.dataToRights CSpace_A.data_to_rights embRightsSet + simp only [holLet, holCollect, Set.mem_image, Set.mem_ofPred_eq] + rw [show Fl4Spec.dataTo16 data = Machine_A.data_to_16 data from rfl] + cases r with + | allowRead => + constructor + · intro h; exact ⟨.AllowRead, by simpa [CapRights_A.case_rights, holWordBit, testBit, HolOne.oneVal] using h, rfl⟩ + · rintro ⟨x, hx, hxe⟩; cases x <;> try cases hxe + simpa [CapRights_A.case_rights, holWordBit, testBit, HolOne.oneVal] using hx + | allowWrite => + constructor + · intro h; exact ⟨.AllowWrite, by simpa [CapRights_A.case_rights, holWordBit, testBit, HolZero.zeroVal] using h, rfl⟩ + · rintro ⟨x, hx, hxe⟩; cases x <;> try cases hxe + simpa [CapRights_A.case_rights, holWordBit, testBit, HolZero.zeroVal] using hx + | allowGrant => + constructor + · intro h; exact ⟨.AllowGrant, by simpa [CapRights_A.case_rights, holWordBit, testBit, HolNumeral.ofNatVal] using h, rfl⟩ + · rintro ⟨x, hx, hxe⟩; cases x <;> try cases hxe + simpa [CapRights_A.case_rights, holWordBit, testBit, HolNumeral.ofNatVal] using hx + | allowGrantReply => + constructor + · intro h; exact ⟨.AllowGrantReply, by simpa [CapRights_A.case_rights, holWordBit, testBit, HolNumeral.ofNatVal] using h, rfl⟩ + · rintro ⟨x, hx, hxe⟩; cases x <;> try cases hxe + simpa [CapRights_A.case_rights, holWordBit, testBit, HolNumeral.ofNatVal] using hx + +theorem maxFreeIndex_eq (n : Nat) : + Fl4Spec.maxFreeIndex n = CSpace_A.max_free_index n := rfl + +theorem isUntypedCap_eq (c : Structures_A.cap) : + Fl4Spec.isUntypedCap (embCap c) = Structures_A.is_untyped_cap c := by + cases c <;> rfl + +theorem freeIndexUpdate_eq (g : Nat → Nat) (c : Structures_A.cap) : + Fl4Spec.freeIndexUpdate g (embCap c) = embCap (CSpace_A.free_index_update g c) := by + cases c <;> rfl + +theorem untypedSzBits_eq (c : Structures_A.cap) : + Fl4Spec.untypedSzBits (embCap c) = CSpace_A.untyped_sz_bits c := by + cases c with + | UntypedCap _ _ _ _ => rfl + | _ => + unfold Fl4Spec.untypedSzBits CSpace_A.untyped_sz_bits Fl4Spec.undefined holUndefined + congr 1 + +theorem maxFreeIndexUpdate_eq (c : Structures_A.cap) : + Fl4Spec.maxFreeIndexUpdate (embCap c) = embCap (CSpace_A.max_free_index_update c) := by + unfold Fl4Spec.maxFreeIndexUpdate CSpace_A.max_free_index_update + rw [untypedSzBits_eq, freeIndexUpdate_eq]; rfl + +private theorem badgeUpdate_eq (w : Badge) (cap : Structures_A.cap) : + Fl4Spec.badgeUpdate w (embCap cap) = embCap (Structures_A.badge_update w cap) := by + cases cap <;> rfl + +private theorem isArchCap_eq (cap : Structures_A.cap) : + Fl4Spec.isArchCap (embCap cap) = Structures_A.is_arch_cap cap := by + cases cap <;> rfl + +theorem isEpCap_eq (c : Structures_A.cap) : + Fl4Spec.isEpCap (embCap c) = Structures_A.is_ep_cap c := by cases c <;> rfl + +theorem isNtfnCap_eq (c : Structures_A.cap) : + Fl4Spec.isNtfnCap (embCap c) = Structures_A.is_ntfn_cap c := by cases c <;> rfl + +theorem updateCapData_eq (preserve : Bool) (w : Data) (cap : Structures_A.cap) : + Fl4Spec.updateCapData preserve w (embCap cap) = + embCap (CSpace_A.update_cap_data preserve w cap) := by + cases cap with + | EndpointCap r b rs => + unfold Fl4Spec.updateCapData CSpace_A.update_cap_data + simp only [isEpCap_eq, Structures_A.is_ep_cap, ↓reduceIte] + have hb : Fl4Spec.capEpBadge (embCap (.EndpointCap r b rs)) = b := rfl + simp only [hb, Structures_A.cap_ep_badge, holIf_eq, holConj_eq_true, + holEq_eq_true, holNot_eq_true, HolZero.zeroVal, badgeUpdate_eq, apply_ite embCap, ite_true] + cases preserve <;> simp [embCap] + | NotificationCap r b rs => + unfold Fl4Spec.updateCapData CSpace_A.update_cap_data + simp only [isEpCap_eq, isNtfnCap_eq, Structures_A.is_ep_cap, Structures_A.is_ntfn_cap, + Bool.false_eq_true, ↓reduceIte, holIf_false] + have hb : Fl4Spec.capEpBadge (embCap (.NotificationCap r b rs)) = b := rfl + simp only [hb, Structures_A.cap_ep_badge, holIf_eq, holConj_eq_true, + holEq_eq_true, holNot_eq_true, HolZero.zeroVal, badgeUpdate_eq, apply_ite embCap, ite_true] + cases preserve <;> simp [embCap] + | CNodeCap oref bits guard => + unfold Fl4Spec.updateCapData CSpace_A.update_cap_data + rw [isEpCap_eq, isNtfnCap_eq, isCnodeCap_eq] + simp only [Structures_A.is_ep_cap, Structures_A.is_ntfn_cap, Structures_A.is_cnode_cap, + Structures_A.case_cap, Bool.false_eq_true, ↓reduceIte, holIf_false, holIf_true, + embCap, Fl4Spec.theCnodeCap, Structures_A.the_cnode_cap, + updateCnodeCapData_eq, holLet, holCaseProd_eq] + rcases ArchCSpace_A.update_cnode_cap_data w with ⟨gs, guardWord⟩ + simp only [holSize_bv, holListDrop, holToBl, toBl, HolSub.subVal, HolAdd.addVal, + holIf_eq, holLt_eq_true, HolOrd.ltVal, wordBits_eq, gt_iff_lt] + by_cases h : Machine_Word_64_Basics.word_bits < gs + bits <;> simp [h] + | ArchObjectCap ac => rfl + | _ => rfl + +theorem longRunningDelete_eq (c : Structures_A.cap) : + Fl4Spec.longRunningDelete (embCap c) = CSpace_A.long_running_delete c := by + cases c <;> rfl + +theorem locateSlot_eq (slot : CslotPtr) (n : Nat) : + Fl4Spec.locateSlot slot n = CSpace_A.locate_slot slot n := by + rcases slot with ⟨a, b⟩ + rfl + +theorem canFastFinalise_eq (c : Structures_A.cap) : + Fl4Spec.canFastFinalise (embCap c) = CSpace_A.can_fast_finalise c := by + cases c <;> rfl + +/-- `capRemoveable` agrees on every `NullCap` and `Zombie` (the only caps ever produced as +`remainder` by `finalise_cap`). On other caps both sides are `undefined`. -/ +theorem capRemoveable_iff_nullOrZombie (c : Structures_A.cap) (slot : CslotPtr) + (h : c = .NullCap ∨ ∃ p b n, c = .Zombie p b n) : + CSpace_A.cap_removeable c slot = true ↔ Fl4Spec.capRemoveable (embCap c) slot := by + rcases h with rfl | ⟨p, b, n, rfl⟩ + · simp [CSpace_A.cap_removeable, Fl4Spec.capRemoveable, embCap] + · simp [CSpace_A.cap_removeable, Fl4Spec.capRemoveable, embCap, + holDisj_eq_true, holConj_eq_true, holEq_eq_true, holListReplicate, + zombieCteBits_eq, HolZero.zeroVal, HolOne.oneVal] + +theorem capCyclicZombie_iff (c : Structures_A.cap) (slot : CslotPtr) : + CSpace_A.cap_cyclic_zombie c slot = true ↔ Fl4Spec.capCyclicZombie (embCap c) slot := by + cases c with + | Zombie p b n => + simp [CSpace_A.cap_cyclic_zombie, Fl4Spec.capCyclicZombie, embCap, + Structures_A.case_cap, holEq_eq_true, holListReplicate, zombieCteBits_eq] + | _ => + simp [CSpace_A.cap_cyclic_zombie, Fl4Spec.capCyclicZombie, embCap, Structures_A.case_cap] + +theorem exposedRdcall_eq (c : CSpace_A.rec_del_call) : + Fl4Spec.exposedRdcall (embRecDelCall c) = CSpace_A.exposed_rdcall c := by + cases c <;> rfl + +theorem isCTEDeleteCall_eq (c : CSpace_A.rec_del_call) : + Fl4Spec.isCTEDeleteCall (embRecDelCall c) = CSpace_A.isCTEDeleteCall c := by + cases c <;> rfl + +theorem slotRdcall_eq (c : CSpace_A.rec_del_call) : + Fl4Spec.slotRdcall (embRecDelCall c) = CSpace_A.slot_rdcall c := by + cases c <;> rfl + +theorem getBadge_eq (c : Structures_A.cap) : + Fl4Spec.getBadge (embCap c) = CSpace_A.get_badge c := by + cases c <;> rfl + +theorem isPhysical_eq (c : Structures_A.cap) : + Fl4Spec.isPhysical (embCap c) = CSpace_A.is_physical c := by + cases c with + | ArchObjectCap ac => exact archIsPhysical_eq ac + | _ => rfl + +theorem archObjSize_eq (cap : Arch_Structs_A.arch_cap) : + Fl4Spec.archObjSize (embArchCap cap) = Arch_Structs_A.arch_obj_size cap := by + cases cap with + | PageCap dev ptr rights mapType size mapping => exact pageBitsForSize_eq size + | _ => rfl + +theorem objSize_eq_nonNtfn (c : Structures_A.cap) + (h1 : ∀ r b rs, c ≠ .NotificationCap r b rs) + (h2 : c ≠ .DomainCap ∧ c ≠ .SchedControlCap ∧ c ≠ .IRQControlCap ∧ ∀ i, c ≠ .IRQHandlerCap i) : + Fl4Spec.objSize (embCap c) = Structures_A.obj_size c := by + cases c with + | NotificationCap r b rs => exact (h1 r b rs rfl).elim + | DomainCap => exact (h2.1 rfl).elim + | SchedControlCap => exact (h2.2.1 rfl).elim + | IRQControlCap => exact (h2.2.2.1 rfl).elim + | IRQHandlerCap i => exact (h2.2.2.2 i rfl).elim + | NullCap => rfl + | UntypedCap d r b fi => rfl + | EndpointCap _ _ _ => rfl + | CNodeCap _ b _ => rfl + | ThreadCap _ => rfl + | SchedContextCap _ b => rfl + | ReplyCap _ _ => rfl + | Zombie _ zb _ => cases zb <;> rfl + | ArchObjectCap a => + simp [Fl4Spec.objSize, Structures_A.obj_size, embCap, archObjSize_eq]; rfl + +/-- **Exact Delta Theorem #1c (`objSize` on NotificationCap):** `64` (`1 <<< 6`) vs `32` (`1 <<< 5`). -/ +theorem objSize_ntfn_delta (r b rs) : + Fl4Spec.objSize (embCap (.NotificationCap r b rs)) = 64 ∧ + Structures_A.obj_size (.NotificationCap r b rs) = 32 := + ⟨rfl, rfl⟩ + +theorem isThreadCap_eq (c : Structures_A.cap) : + Fl4Spec.isThreadCap (embCap c) = Structures_A.is_thread_cap c := by cases c <;> rfl + +theorem isSchedContextCap_eq (c : Structures_A.cap) : + Fl4Spec.isSchedContextCap (embCap c) = Structures_A.is_sched_context_cap c := by cases c <;> rfl + +theorem sameRegionAs_iff_nonNtfn (c c' : Structures_A.cap) + (hntfn : Structures_A.is_untyped_cap c = true → Structures_A.is_ntfn_cap c' = false) : + CSpace_A.same_region_as c c' = true ↔ Fl4Spec.sameRegionAs (embCap c) (embCap c') := by + cases c with + | NullCap => simp [CSpace_A.same_region_as, Fl4Spec.sameRegionAs, embCap] + | UntypedCap dev r bits free => + have hnot : ∀ r' b' rs', c' ≠ .NotificationCap r' b' rs' := by + intro r' b' rs' h + have := hntfn rfl + rw [h] at this; simp [Structures_A.is_ntfn_cap] at this + change CSpace_A.same_region_as (.UntypedCap dev r bits free) c' = true ↔ + Fl4Spec.sameRegionAs (.untypedCap dev r bits free) (embCap c') + unfold CSpace_A.same_region_as Fl4Spec.sameRegionAs + simp only [holConj_eq_true, holLe_eq_true, HolOrd.leVal, HolSub.subVal, HolAdd.addVal, + HolOne.oneVal, holWordShiftl, isPhysical_eq, objRefOf_eq] + refine and_congr_right fun hphys => ?_ + have h2 : c' ≠ .DomainCap ∧ c' ≠ .SchedControlCap ∧ c' ≠ .IRQControlCap ∧ + ∀ i, c' ≠ .IRQHandlerCap i := by + cases c' <;> simp [CSpace_A.is_physical, Structures_A.case_cap] at hphys ⊢ + rw [objSize_eq_nonNtfn c' hnot h2]; rfl + | EndpointCap r b rs => + change CSpace_A.same_region_as (.EndpointCap r b rs) c' = true ↔ + Fl4Spec.sameRegionAs (.endpointCap r b (embRightsSet rs)) (embCap c') + simp [CSpace_A.same_region_as, Fl4Spec.sameRegionAs, + holConj_eq_true, holEq_eq_true, isEpCap_eq, objRefOf_eq] + | NotificationCap r b rs => + change CSpace_A.same_region_as (.NotificationCap r b rs) c' = true ↔ + Fl4Spec.sameRegionAs (.notificationCap r b (embRightsSet rs)) (embCap c') + simp [CSpace_A.same_region_as, Fl4Spec.sameRegionAs, + holConj_eq_true, holEq_eq_true, isNtfnCap_eq, objRefOf_eq] + | CNodeCap r bits g => + change CSpace_A.same_region_as (.CNodeCap r bits g) c' = true ↔ + Fl4Spec.sameRegionAs (.cnodeCap r bits g) (embCap c') + unfold CSpace_A.same_region_as Fl4Spec.sameRegionAs + simp only [holConj_eq_true, holEq_eq_true, isCnodeCap_eq, objRefOf_eq] + cases c' <;> simp [embCap, Structures_A.is_cnode_cap, Structures_A.bits_of, + Structures_A.case_cap, Fl4Spec.bitsOf] + | ReplyCap n cr => + unfold CSpace_A.same_region_as Fl4Spec.sameRegionAs + simp only [embCap, holEx_eq_true, holEq_eq_true] + cases c' with + | ReplyCap n' cr' => + simp only [Cap.replyCap.injEq, Structures_A.cap.ReplyCap.injEq] + constructor + · rintro ⟨_, rfl, _⟩; exact ⟨_, rfl, rfl⟩ + · rintro ⟨_, rfl, _⟩; exact ⟨cr', rfl, rfl⟩ + | _ => simp + | ThreadCap r => + change CSpace_A.same_region_as (.ThreadCap r) c' = true ↔ + Fl4Spec.sameRegionAs (.threadCap r) (embCap c') + simp [CSpace_A.same_region_as, Fl4Spec.sameRegionAs, + holConj_eq_true, holEq_eq_true, isThreadCap_eq, objRefOf_eq] + | SchedContextCap sc n => + change CSpace_A.same_region_as (.SchedContextCap sc n) c' = true ↔ + Fl4Spec.sameRegionAs (.schedContextCap sc n) (embCap c') + unfold CSpace_A.same_region_as Fl4Spec.sameRegionAs + simp only [holConj_eq_true, holEq_eq_true, isSchedContextCap_eq, objRefOf_eq] + cases c' <;> simp [embCap, Structures_A.is_sched_context_cap, Structures_A.bits_of, + Structures_A.case_cap, Fl4Spec.bitsOf] + | SchedControlCap => + cases c' <;> simp [CSpace_A.same_region_as, Fl4Spec.sameRegionAs, embCap, holEq] + | Zombie r b n => simp [CSpace_A.same_region_as, Fl4Spec.sameRegionAs, embCap] + | IRQControlCap => + unfold CSpace_A.same_region_as Fl4Spec.sameRegionAs + simp only [embCap, holDisj_eq_true, holEx_eq_true, holConj_eq_true, holEq_eq_true] + cases c' with + | IRQControlCap => simp + | IRQHandlerCap irq => simp + | ArchObjectCap ac => + simp [Structures_A.cap.is_ArchObjectCap, Fl4Spec.isArchCap, + ArchCSpace_A.is_irq_control_descendant, Fl4Spec.isIrqControlDescendant] + | _ => simp [Structures_A.cap.is_ArchObjectCap, Fl4Spec.isArchCap] + | DomainCap => + cases c' <;> simp [CSpace_A.same_region_as, Fl4Spec.sameRegionAs, embCap, holEq] + | IRQHandlerCap n => + unfold CSpace_A.same_region_as Fl4Spec.sameRegionAs + cases c' with + | IRQHandlerCap n' => + simp [embCap, holEq_eq_true] + | _ => simp [embCap, holEq] + | ArchObjectCap ac => + unfold CSpace_A.same_region_as Fl4Spec.sameRegionAs + cases c' with + | ArchObjectCap ac' => + simpa [embCap, Structures_A.case_cap] using archSameRegionAs_iff ac ac' + | _ => simp [embCap, Structures_A.case_cap] + +/-- Patched `obj_size` (Delta #1: `NotificationCap` has size `2^6 = 64`). -/ +def obj_size_p (c : Structures_A.cap) : BitVec 64 := + match c with + | .NotificationCap _ _ _ => 64 + | _ => Structures_A.obj_size c + +theorem patched_objSize_eq (c : Structures_A.cap) (hphys : CSpace_A.is_physical c = true) : + Fl4Spec.objSize (embCap c) = obj_size_p c := by + cases c with + | NotificationCap r b rs => exact (objSize_ntfn_delta r b rs).1 + | DomainCap | SchedControlCap | IRQControlCap | IRQHandlerCap _ => + simp [CSpace_A.is_physical, Structures_A.case_cap] at hphys + | Zombie _ bits _ => cases bits <;> rfl + | ArchObjectCap a => + change Fl4Spec.objSize (embCap (.ArchObjectCap a)) = Structures_A.obj_size (.ArchObjectCap a) + exact objSize_eq_nonNtfn (.ArchObjectCap a) (by intro _ _ _ h; cases h) + ⟨(by intro h; cases h), (by intro h; cases h), (by intro h; cases h), (by intro _ h; cases h)⟩ + | _ => rfl + +/-- Patched `same_region_as` using `obj_size_p` (Delta #1). -/ +def same_region_as_p : Structures_A.cap → Structures_A.cap → Bool + | .UntypedCap _ r bits _, c' => + holConj (CSpace_A.is_physical c') + (holConj (holLe r (Structures_A.obj_ref_of c')) + (holConj (holLe (Structures_A.obj_ref_of c') (HolSub.subVal (HolAdd.addVal (Structures_A.obj_ref_of c') (obj_size_p c')) (HolOne.oneVal (α := BitVec 64)))) + (holLe (HolSub.subVal (HolAdd.addVal (Structures_A.obj_ref_of c') (obj_size_p c')) (HolOne.oneVal (α := BitVec 64))) + (HolSub.subVal (HolAdd.addVal r (holWordShiftl (HolOne.oneVal (α := BitVec 64)) bits)) (HolOne.oneVal (α := BitVec 64)))))) + | c, c' => CSpace_A.same_region_as c c' + +theorem patched_sameRegionAs_iff (c c' : Structures_A.cap) : + same_region_as_p c c' = true ↔ Fl4Spec.sameRegionAs (embCap c) (embCap c') := by + by_cases hu : Structures_A.is_untyped_cap c = true + · cases c with + | UntypedCap dev r bits free => + change same_region_as_p (.UntypedCap dev r bits free) c' = true ↔ + Fl4Spec.sameRegionAs (.untypedCap dev r bits free) (embCap c') + unfold same_region_as_p Fl4Spec.sameRegionAs + simp only [holConj_eq_true, holLe_eq_true, HolOrd.leVal, HolSub.subVal, HolAdd.addVal, + HolOne.oneVal, holWordShiftl, isPhysical_eq, objRefOf_eq] + refine and_congr_right fun hphys => ?_ + rw [patched_objSize_eq c' hphys]; rfl + | _ => simp [Structures_A.is_untyped_cap] at hu + · have hsame : same_region_as_p c c' = CSpace_A.same_region_as c c' := by + cases c <;> simp [same_region_as_p, Structures_A.is_untyped_cap] at hu ⊢ + rw [hsame] + exact sameRegionAs_iff_nonNtfn c c' (fun h => absurd h hu) + +/-- `sameObjectAs` agrees unconditionally with unmodified `CSpace_A.same_object_as` (its +`UntypedCap` arm is `False` on both sides, so Delta #1 does not affect `sameObjectAs`!). -/ +theorem sameObjectAs_iff (cp cp' : Structures_A.cap) : + CSpace_A.same_object_as cp cp' = true ↔ Fl4Spec.sameObjectAs (embCap cp) (embCap cp') := by + cases cp with + | UntypedCap _ _ _ _ => + simp [CSpace_A.same_object_as, Fl4Spec.sameObjectAs, embCap, holCaseProd_eq, Structures_A.case_cap] + | IRQControlCap => + simp [CSpace_A.same_object_as, Fl4Spec.sameObjectAs, embCap, holCaseProd_eq, Structures_A.case_cap] + | ArchObjectCap ac => + cases cp' with + | ArchObjectCap ac' => + simpa [CSpace_A.same_object_as, Fl4Spec.sameObjectAs, embCap, holCaseProd_eq, + Structures_A.case_cap] using sameAobjectAs_iff ac ac' + | _ => + unfold CSpace_A.same_object_as Fl4Spec.sameObjectAs + simp only [embCap, holCaseProd_eq, Structures_A.case_cap] + exact sameRegionAs_iff_nonNtfn (.ArchObjectCap ac) _ (by intro h; simp [Structures_A.is_untyped_cap] at h) + | _ => + unfold CSpace_A.same_object_as Fl4Spec.sameObjectAs + simp only [embCap, holCaseProd_eq, Structures_A.case_cap] + exact sameRegionAs_iff_nonNtfn _ cp' (by intro h; simp [Structures_A.is_untyped_cap] at h) + +theorem shouldBeParentOf_iff_nonNtfn (c : Structures_A.cap) (orig : Bool) + (c' : Structures_A.cap) (orig' : Bool) + (hntfn : Structures_A.is_untyped_cap c = true → Structures_A.is_ntfn_cap c' = false) : + CSpace_A.should_be_parent_of c orig c' orig' = true ↔ + Fl4Spec.shouldBeParentOf (embCap c) orig (embCap c') orig' := by + unfold CSpace_A.should_be_parent_of Fl4Spec.shouldBeParentOf + simp only [holConj_eq_true, sameRegionAs_iff_nonNtfn c c' hntfn] + refine and_congr_right fun _ => and_congr_right fun hsr => ?_ + cases c with + | EndpointCap ref badge rs => + cases c' with + | EndpointCap ref' badge' rs' => + simp [embCap, Structures_A.case_cap, holImp_eq_true, holNot_eq_true, ne_eq, holEq_eq_true, + holConj_eq_true, HolZero.zeroVal, Structures_A.cap_ep_badge, Fl4Spec.capEpBadge] + | _ => simp [Fl4Spec.sameRegionAs, embCap, Fl4Spec.isEpCap] at hsr + | NotificationCap ref badge rs => + cases c' with + | NotificationCap ref' badge' rs' => + simp [embCap, Structures_A.case_cap, holImp_eq_true, holNot_eq_true, ne_eq, holEq_eq_true, + holConj_eq_true, HolZero.zeroVal, Structures_A.cap_ep_badge, Fl4Spec.capEpBadge] + | _ => simp [Fl4Spec.sameRegionAs, embCap, Fl4Spec.isNtfnCap] at hsr + | ArchObjectCap ac => + cases c' with + | ArchObjectCap ac' => + simp [embCap, Structures_A.case_cap, + ArchCSpace_A.should_be_arch_parent_of, Fl4Spec.shouldBeArchParentOf] + | _ => simp [Fl4Spec.sameRegionAs, embCap] at hsr + | _ => simp [embCap, Structures_A.case_cap] + +/-- Patched `should_be_parent_of` using `same_region_as_p` (Delta #1). -/ +def should_be_parent_of_p (c : Structures_A.cap) (orig : Bool) + (c' : Structures_A.cap) (orig' : Bool) : Bool := + holConj orig (holConj (same_region_as_p c c') + (match c with + | .EndpointCap _ badge _ => holImp (holNot (holEq badge 0#64)) (holConj (holEq (Structures_A.cap_ep_badge c') badge) (holNot orig')) + | .NotificationCap _ badge _ => holImp (holNot (holEq badge 0#64)) (holConj (holEq (Structures_A.cap_ep_badge c') badge) (holNot orig')) + | .ArchObjectCap ac => ArchCSpace_A.should_be_arch_parent_of ac c'.the_arch_cap orig' + | _ => true)) + +theorem patched_shouldBeParentOf_iff (c : Structures_A.cap) (orig : Bool) + (c' : Structures_A.cap) (orig' : Bool) : + should_be_parent_of_p c orig c' orig' = true ↔ + Fl4Spec.shouldBeParentOf (embCap c) orig (embCap c') orig' := by + by_cases hu : Structures_A.is_untyped_cap c = true + · cases c with + | UntypedCap dev r bits free => + unfold should_be_parent_of_p Fl4Spec.shouldBeParentOf + simp [holConj_eq_true, patched_sameRegionAs_iff, embCap] + | _ => simp [Structures_A.is_untyped_cap] at hu + · have hEq : should_be_parent_of_p c orig c' orig' = CSpace_A.should_be_parent_of c orig c' orig' := by + cases c with + | UntypedCap _ _ _ _ => simp [Structures_A.is_untyped_cap] at hu + | _ => rfl + rw [hEq] + exact shouldBeParentOf_iff_nonNtfn c orig c' orig' (fun h => absurd h hu) + +/-- Side condition for `is_cap_revocable newCap srcCap`: when `newCap` is an Endpoint, +or Notification cap, `srcCap` has a badge-bearing constructor. -/ +def DeriveSrcValid (newCap srcCap : Structures_A.cap) : Prop := + ((∃ r b rs, newCap = .EndpointCap r b rs) → + (∃ r b rs, srcCap = .EndpointCap r b rs) ∨ (∃ r b rs, srcCap = .NotificationCap r b rs)) ∧ + ((∃ r b rs, newCap = .NotificationCap r b rs) → + (∃ r b rs, srcCap = .EndpointCap r b rs) ∨ (∃ r b rs, srcCap = .NotificationCap r b rs)) + +theorem isCapRevocable_iff (newCap srcCap : Structures_A.cap) + (hsrc : DeriveSrcValid newCap srcCap) : + CSpace_A.is_cap_revocable newCap srcCap = true ↔ + Fl4Spec.isCapRevocable (embCap newCap) (embCap srcCap) := by + cases newCap with + | UntypedCap dev r bits f => + simp [CSpace_A.is_cap_revocable, Fl4Spec.isCapRevocable, embCap, Structures_A.case_cap] + | EndpointCap r b rs => + rcases hsrc.1 ⟨r, b, rs, rfl⟩ with ⟨r', b', rs', rfl⟩ | ⟨r', b', rs', rfl⟩ <;> + simp [CSpace_A.is_cap_revocable, Fl4Spec.isCapRevocable, embCap, Structures_A.case_cap, + holNot_eq_true, ne_eq, holEq_eq_true, Structures_A.cap_ep_badge, Fl4Spec.capEpBadge] + | NotificationCap r b rs => + rcases hsrc.2 ⟨r, b, rs, rfl⟩ with ⟨r', b', rs', rfl⟩ | ⟨r', b', rs', rfl⟩ <;> + simp [CSpace_A.is_cap_revocable, Fl4Spec.isCapRevocable, embCap, Structures_A.case_cap, + holNot_eq_true, ne_eq, holEq_eq_true, Structures_A.cap_ep_badge, Fl4Spec.capEpBadge] + | IRQHandlerCap irq => + cases srcCap <;> simp [CSpace_A.is_cap_revocable, Fl4Spec.isCapRevocable, embCap, + Structures_A.case_cap, holEq] + | ArchObjectCap ac => + unfold CSpace_A.is_cap_revocable Fl4Spec.isCapRevocable + simpa [embCap, Structures_A.case_cap] using archIsCapRevocable_iff (.ArchObjectCap ac) srcCap + | _ => + simp [CSpace_A.is_cap_revocable, Fl4Spec.isCapRevocable, embCap, Structures_A.case_cap] + +theorem hasCancelSendRights_iff (c : Structures_A.cap) : + CSpace_A.has_cancel_send_rights c = true ↔ Fl4Spec.hasCancelSendRights (embCap c) := by + cases c with + | EndpointCap r b rs => + unfold CSpace_A.has_cancel_send_rights Fl4Spec.hasCancelSendRights + simp only [embCap, Structures_A.case_cap, holEq_eq_true, Fl4Spec.allRights, CapRights_A.all_rights, + HolCompleteLattice.holTop] + rw [← embRightsSet_univ, embRightsSet_eq_iff] + | _ => + simp [CSpace_A.has_cancel_send_rights, Fl4Spec.hasCancelSendRights, embCap, Structures_A.case_cap] + +private theorem aobjRef_eq (a : Arch_Structs_A.arch_cap) : + Fl4Spec.aobjRef (embArchCap a) = Arch_Structs_A.aobj_ref a := by + cases a <;> rfl + +theorem objRefs_eq (c : Structures_A.cap) : + Fl4Spec.objRefs (embCap c) = Structures_A.obj_refs c := by + cases c with + | ArchObjectCap a => + ext r; simp only [Fl4Spec.objRefs, Structures_A.obj_refs, embCap, aobjRef_eq] + cases Arch_Structs_A.aobj_ref a <;> simp [holSetOption] + | _ => + ext r; simp [Fl4Spec.objRefs, Structures_A.obj_refs, embCap, holInsert_eq, HolCompleteLattice.holBot] + + +def embGenObjRef : IpcCancel_A.gen_obj_ref → GenObjRef + | .ObjRef ref => .objRef ref + | .IRQRef irq => .iRQRef irq + | .ArchRef ref => .archRef (embArchGenObjRef ref) + +theorem embGenObjRef_injective : Function.Injective embGenObjRef := by + intro a b h + cases a <;> cases b <;> simp [embGenObjRef] at h + · exact congrArg _ h + · exact congrArg _ h + · rename_i x y + cases x + cases y + exact congrArg IpcCancel_A.gen_obj_ref.ArchRef (by simpa [embArchGenObjRef] using h) + +theorem archCapSetMap_eq {αH αL : Type} [Nonempty αH] + (e : αH → αL) (fH : Arch_Structs_A.arch_cap → Set αH) (fL : ArchCap → Set αL) + (hf : ∀ ac, fL (embArchCap ac) = e '' fH ac) (c : Structures_A.cap) : + Fl4Spec.archCapSetMap fL (embCap c) = e '' IpcCancel_A.arch_cap_set_map fH c := by + cases c with + | ArchObjectCap ac => exact hf ac + | _ => simp [Fl4Spec.archCapSetMap, IpcCancel_A.arch_cap_set_map, HolCompleteLattice.holBot, + embCap, Structures_A.case_cap] + +theorem genObjRefs_eq (c : Structures_A.cap) : + Fl4Spec.genObjRefs (embCap c) = embGenObjRef '' IpcCancel_A.gen_obj_refs c := by + unfold Fl4Spec.genObjRefs IpcCancel_A.gen_obj_refs Fl4Spec.archGenRefs + have harch : ∀ ac, Fl4Spec.archGenObjRefs (embArchCap ac) = + embArchGenObjRef '' ArchIpcCancel_A.arch_gen_obj_refs ac := archGenObjRefs_eq + simp only [HolCompleteLattice.holSup, holImage, Set.image_union, Set.image_image] + rw [objRefs_eq, capIrqs_eq, + archCapSetMap_eq embArchGenObjRef ArchIpcCancel_A.arch_gen_obj_refs + Fl4Spec.archGenObjRefs harch] + simp only [Set.image_image, embGenObjRef] + +theorem genObjRefs_nullCap : Fl4Spec.genObjRefs Cap.nullCap = ∅ := by + simp [Fl4Spec.genObjRefs, Fl4Spec.objRefs, Fl4Spec.capIrqs, Fl4Spec.capIrqOpt, + Fl4Spec.archGenRefs, Fl4Spec.archCapSetMap] + +section CSpaceMonad +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 ensureNoChildren_equiv (slot : CslotPtr) : + MRelE SR (FunRel embSyscallError) Eq + (CSpace_A.ensure_no_children slot) (Fl4Spec.ensureNoChildren slot) := by + unfold CSpace_A.ensure_no_children Fl4Spec.ensureNoChildren + refine mrele_bindE (mrele_liftE (mrel_gets fun _ _ hs => hs.cdt_eq.symm)) fun cdtH cdtL hcdt => ?_ + subst hcdt + exact mrele_whenE (by simp [holEx_eq_true, holEq_eq_true]) (fun _ => mrele_throwError rfl) + +theorem setUntypedCapAsFull_equiv_nonExt (srcCap newCap : Structures_A.cap) (srcSlot : CslotPtr) + (hslot : NonExtTcbSlot srcSlot.2) : + MRel SR Eq + (CSpace_A.set_untyped_cap_as_full srcCap newCap srcSlot) + (Fl4Spec.setUntypedCapAsFull (embCap srcCap) (embCap newCap) srcSlot) := by + unfold CSpace_A.set_untyped_cap_as_full Fl4Spec.setUntypedCapAsFull + refine mrel_if ?_ (fun h => ?_) (fun _ => mrel_return rfl) + · simp only [holConj_eq_true, holEq_eq_true, isUntypedCap_eq, objRefOf_eq] + refine and_congr_right fun hu1 => and_congr_right fun hu2 => and_congr_right fun _ => ?_ + cases srcCap <;> try simp [Structures_A.is_untyped_cap] at hu1 + cases newCap <;> try simp [Structures_A.is_untyped_cap] at hu2 + rfl + · have hmfu := maxFreeIndexUpdate_eq srcCap + rw [hmfu] + exact setCap_equiv_nonExt (CSpace_A.max_free_index_update srcCap) srcSlot hslot + +theorem deriveCap_equiv (slot : CslotPtr) (cap : Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embCap) + (CSpace_A.derive_cap slot cap) (Fl4Spec.deriveCap slot (embCap cap)) := by + cases cap with + | ArchObjectCap c => exact archDeriveCap_equiv c + | UntypedCap dev ptr sz f => + unfold CSpace_A.derive_cap Fl4Spec.deriveCap + exact mrele_kbindE (ensureNoChildren_equiv slot) (mrele_returnOk rfl) + | Zombie ptr n sz => exact mrele_returnOk rfl + | IRQControlCap => exact mrele_returnOk rfl + | _ => exact mrele_returnOk rfl + +/-- Patched `get_cap` using `Patched.tcb_cnode_map` (Delta #4). -/ +def get_cap_p (slot : CslotPtr) : HolNonDet (Structures_A.state ZH) Structures_A.cap := + holBind (KHeap_A.get_object slot.1) fun obj => + holBind (match obj with + | .CNode sz cnode => holBind (holAssert (Structures_A.well_formed_cnode_n sz cnode)) (holKBind (holReturn cnode)) + | .TCB tcb => holReturn (Patched.tcb_cnode_map tcb) + | _ => holFail) fun caps => + holAssertOpt (caps slot.2) + +theorem patched_getCap_equiv (slot : CslotPtr) : + MRel SR (FunRel embCap) (get_cap_p slot) (Fl4Spec.getCap slot) := by + rcases slot with ⟨oref, cref⟩ + unfold get_cap_p Fl4Spec.getCap + refine mrel_bind (getObject_equiv oref) fun koH koL hko => ?_ + subst hko + cases koH with + | CNode sz cn => + simp only [embKernelObject] + rw [L4vRefX64.Equiv.KHeap.holBind_assoc] + refine mrel_bind (mrel_assert (wellFormedCnodeN_iff sz cn)) fun _ _ _ => ?_ + simp only [holKBind_eq] + refine mrel_bind (Ra := fun (fH : List Bool → Option Structures_A.cap) (fL : CnodeIndex → Option Cap) => + OptRel (FunRel embCap) (fH cref) (fL cref)) + (mrel_return (by rw [optRel_funRel]; rfl)) + fun _ _ hf => mrel_assertOpt hf + | TCB tcb => + simp only [embKernelObject] + refine mrel_bind (Ra := fun (fH : List Bool → Option Structures_A.cap) (fL : CnodeIndex → Option Cap) => + OptRel (FunRel embCap) (fH cref) (fL cref)) + (mrel_return ((optRel_funRel embCap _ _).mpr (Patched.patched_tcbCnodeMap_eq tcb cref))) + fun _ _ hf => mrel_assertOpt hf + | Endpoint _ | Notification _ | SchedContext _ _ | Reply _ | ArchObj _ => + simp only [embKernelObject] + exact mrel_bind mrel_fail fun _ _ h => False.elim h + + +/-- The extra base TCB slot admits writes of NullCap. Ordinary CNodes still +interpret the same bit string according to their own radix. -/ +def set_cap_p (cap : Structures_A.cap) (slot : CslotPtr) : HolNonDet (Structures_A.state ZH) Unit := + if NonExtTcbSlot slot.2 then CSpaceAcc_A.set_cap cap slot + else holBind (KHeap_A.get_object slot.1) fun + | .TCB tcb => if cap = .NullCap then KHeap_A.set_object slot.1 (.TCB tcb) else holFail + | _ => CSpaceAcc_A.set_cap cap slot + +def NonExtCapSlot (slot : CslotPtr) (s : Structures_A.state ZH) : Prop := + NonExtTcbSlot slot.2 ∨ ∀ tcb, s.kheap slot.1 ≠ some (.TCB tcb) + +def SetCapSafe (cap : Structures_A.cap) (slot : CslotPtr) (s : Structures_A.state ZH) : Prop := + NonExtCapSlot slot s ∨ cap = .NullCap + +theorem patched_setCap_equiv_at (cap : Structures_A.cap) (slot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : SetCapSafe cap slot sH) : + MRelStep SR Eq (set_cap_p cap slot sH) (Fl4Spec.setCap (embCap cap) slot sL) := by + rcases slot with ⟨ptr, cref⟩ + unfold set_cap_p + by_cases hslot : NonExtTcbSlot cref + · simp only [hslot, ↓reduceIte] + exact setCap_equiv_nonExt cap (ptr, cref) hslot sH sL hs + have hept : cref = Fl4Spec.tcbCnodeIndex 5 := Classical.not_not.mp hslot + subst cref + simp only [hslot, ↓reduceIte] + unfold Fl4Spec.setCap + refine mrelStep_bind_mem (getObject_equiv ptr sH sL hs) fun objH objL hobj s1H s1L hs1 hm => ?_ + subst hobj + have ⟨hheap, hstate⟩ := getObject_member hm + subst s1H + have hget : KHeap_A.get_object ptr sH = ({(objH, sH)}, false) := by + change holAssertOpt (sH.kheap ptr) sH = _ + rw [hheap] + rfl + cases objH with + | TCB tcb => + have hcap : cap = .NullCap := by + rcases hsafe with ⟨hc | ht⟩ | hk + · exact False.elim (hslot hc) + · exact False.elim (ht tcb hheap) + · exact hk + subst cap + have hupdate : + (do + let o ← (pure (.tcb { embTcb tcb with tcbEpt := Cap.nullCap }) : + SMonad ZL KernelObject) + Fl4Spec.setObject ptr o) = + Fl4Spec.setObject (Z := ZL) ptr (embKernelObject (.TCB tcb)) := by + funext s + exact nonDet_bind_singleton_at _ (show NonDet.pure _ s = _ from rfl) + simp only [↓reduceIte, embKernelObject, embCap] + simp [tcbCnodeIndex, toBl, hupdate] + exact setObject_equiv ptr (.TCB tcb) sH s1L hs1 + | CNode sz cn => + unfold CSpaceAcc_A.set_cap + simp only [holCaseProd_eq] + rw [hol_bind_singleton_at _ hget] + simp only [Structures_A.case_kernel_object, embKernelObject] + have hcond : holConj (holMember (Fl4Spec.tcbCnodeIndex 5) (holDom cn)) (Structures_A.well_formed_cnode_n sz cn) = true ↔ + (Fl4Spec.tcbCnodeIndex 5) ∈ Fl4Spec.dom (embCnodeContents cn) ∧ Fl4Spec.wellFormedCnodeN sz (embCnodeContents cn) := by + simp [holConj_eq_true, holMember_eq_true, Fl4Spec.dom, holDom, embCnodeContents, wellFormedCnodeN_iff] + have hcn : Function.update (embCnodeContents cn) (Fl4Spec.tcbCnodeIndex 5) (some (embCap cap)) = + embCnodeContents (holFunUpd cn (Fl4Spec.tcbCnodeIndex 5) (some cap)) := by + funext k + unfold embCnodeContents holFunUpd Function.update + split_ifs <;> first | (subst ‹k = _›; rfl) | rfl + by_cases hL : (Fl4Spec.tcbCnodeIndex 5) ∈ Fl4Spec.dom (embCnodeContents cn) ∧ + Fl4Spec.wellFormedCnodeN sz (embCnodeContents cn) + · have hH := hcond.mpr hL + simp only [hH, holIf_true, holFunApp] + rw [ite_eq_left hL] + exact (mrel_bind (Ra := FunRel embKernelObject) + (mrel_return (by simp [FunRel, embKernelObject, hcn])) fun oH oL ho => by + subst ho + exact setObject_equiv ptr oH) sH s1L hs1 + · have hH := Bool.eq_false_iff.mpr (mt hcond.mp hL) + simp only [hH, holIf_false] + rw [ite_eq_right hL] + exact (mrel_bind mrel_fail fun _ _ h => False.elim h) sH s1L hs1 + | Endpoint _ | Notification _ | SchedContext _ _ | Reply _ | ArchObj _ => + unfold CSpaceAcc_A.set_cap + simp only [holCaseProd_eq] + rw [hol_bind_singleton_at _ hget] + exact (mrel_bind mrel_fail fun _ _ h => False.elim h) sH s1L hs1 + +theorem holTheDefault_of_existsUnique {α : Type} {d : α} {P : α → Bool} {Q : α → Prop} + (hu : ∃! x, P x = true) (hQ : ∀ x, P x = true → Q x) : Q (holTheDefault d P) := by + unfold holTheDefault + simp only [hu, ↓reduceDIte] + exact hQ _ (Classical.choose_spec hu).1 + +theorem holTheDefault_eq_of_iff {α : Type} {d a : α} {P : α → Bool} + (h : ∀ x, P x = true ↔ x = a) : holTheDefault d P = a := + holTheDefault_of_existsUnique ⟨a, (h a).mpr rfl, fun y hy => (h y).mp hy⟩ (fun _ hx => (h _).mp hx) + +theorem holBindE_returnOk_left {σ ε α β : Type} (a : α) + (f : α → HolNonDet σ (Sum ε β)) : + holBindE (holReturnOk a) f = f a := by + funext s + apply Prod.ext + · ext p; simp [holBindE, holBind, holReturnOk, holReturn] + · simp [holBindE, holBind, holReturnOk, holReturn] + +theorem holBindE_congr_at {σ ε α β : Type} + {m : HolNonDet σ (Sum ε α)} {f g : α → HolNonDet σ (Sum ε β)} {s : σ} + (hfg : ∀ a st, (Sum.inr a, st) ∈ (m s).1 → f a st = g a st) : + holBindE m f s = holBindE m g s := by + apply Prod.ext + · ext p + simp only [holBindE, holBind, Set.mem_ofPred_eq] + constructor <;> rintro ⟨⟨r, st⟩, hmem, hp⟩ <;> refine ⟨(r, st), hmem, ?_⟩ + · cases r with + | inl e => exact hp + | inr a => dsimp only at hp ⊢; rwa [← hfg a st hmem] + · cases r with + | inl e => exact hp + | inr a => dsimp only at hp ⊢; rwa [hfg a st hmem] + · simp only [holBindE, holBind, decide_eq_decide] + constructor <;> rintro (h | ⟨⟨r, st⟩, hmem, hf⟩) + · exact Or.inl h + · right; refine ⟨(r, st), hmem, ?_⟩ + cases r with + | inl e => exact hf + | inr a => dsimp only at hf ⊢; rwa [← hfg a st hmem] + · exact Or.inl h + · right; refine ⟨(r, st), hmem, ?_⟩ + cases r with + | inl e => exact hf + | inr a => dsimp only at hf ⊢; rwa [hfg a st hmem] + +/-- Well-founded recursive `resolve_address_bits'` parameterized by the `getCap` monadic op. -/ +def holResolveAddrBits + (gc : CslotPtr → HolNonDet (Structures_A.state ZH) Structures_A.cap) + (p : Structures_A.cap × CapRef) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure (CslotPtr × CapRef)) := + match p.1 with + | .CNodeCap oref radix_bits guard => + if _h0 : radix_bits + guard.length = 0 then holFail + else + holBindE (holWhenE (holNot (holLe guard p.2)) + (holThrowError (.GuardMismatch p.2.length guard))) + (holKBind (holBindE (holWhenE (holLt p.2.length (radix_bits + guard.length)) + (holThrowError (.DepthMismatch p.2.length (radix_bits + guard.length)))) + (holKBind (holBindE (holReturnOk ((p.2.drop guard.length).take radix_bits)) fun offset => + let rest := p.2.drop (radix_bits + guard.length) + if _hr : rest = [] then holReturnOk ((oref, offset), []) + else holBindE (holLiftE (gc (oref, offset))) fun next_cap => + if Structures_A.is_cnode_cap next_cap then holResolveAddrBits gc (next_cap, rest) + else holReturnOk ((oref, offset), rest))))) + | _ => holThrowError .InvalidRoot +termination_by p.2.length +decreasing_by + simp only [List.length_drop] + have : p.2.length ≠ 0 := by + intro h; apply _hr; simp [rest, List.drop_eq_nil_of_le, h] + omega + +theorem getCap_state_eq {slot : CslotPtr} + {sH sH' : Structures_A.state ZH} {c : Structures_A.cap} + (hm : (c, sH') ∈ (CSpaceAcc_A.get_cap slot sH).1) : sH' = sH := by + unfold CSpaceAcc_A.get_cap KHeap_A.get_object KHeap_A.read_object holSwp at hm + simp only [holCaseProd_eq] at hm + cases hk : sH.kheap slot.1 with + | none => simp [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holFail] at hm + | some ko => + rcases hm with ⟨⟨o, s1⟩, hm1, ⟨cs, s2⟩, hm2, hm3⟩ + simp only [hk, holFunApp, holGetsThe, holAssertOpt, holReturn, Set.mem_singleton_iff, + Prod.mk.injEq] at hm1 + rcases hm1 with ⟨ho, hs1⟩ + rw [ho, hs1] at hm2 + cases ko with + | CNode sz cn => + simp only [Structures_A.case_kernel_object, holBind, holAssert, holKBind, holReturn, + Set.mem_singleton_iff] at hm2 + rcases hm2 with ⟨⟨_, s1'⟩, ⟨_, hs1'⟩, hm2'⟩ + simp only [Prod.mk.injEq] at hm2' + rcases hm2' with ⟨hcs, hs2⟩ + dsimp only at hm3 + rw [hcs, hs2] at hm3 + cases h : cn slot.2 with + | none => simp [h, holAssertOpt, holFail] at hm3 + | some c' => + simp only [h, holAssertOpt, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm3 + exact hm3.2.trans (congrArg Prod.snd hs1') + | TCB tcb => + simp only [Structures_A.case_kernel_object, holReturn, Set.mem_singleton_iff, + Prod.mk.injEq] at hm2 + rcases hm2 with ⟨hcs, hs2⟩ + dsimp only at hm3 + rw [hcs, hs2] at hm3 + cases h : Structures_A.tcb_cnode_map tcb slot.2 with + | none => simp [h, holAssertOpt, holFail] at hm3 + | some c' => simp [h, holAssertOpt, holReturn] at hm3; exact hm3.2 + | _ => simp [Structures_A.case_kernel_object, holFail] at hm2 + +/-- Single-step equality of `resolve_address_bits'` body with `holResolveAddrBits` +whenever recursive calls agree on strictly shorter `rest`. -/ +private theorem resolveAddrBits_body_eq + (f : HolItself ZH × (Structures_A.cap × CapRef) → + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure (CslotPtr × CapRef))) + (z : HolItself ZH) (cap : Structures_A.cap) (cref : CapRef) + (hrec : ∀ oref rbits guard s offset rest next_cap, + cap = .CNodeCap oref rbits guard → + rbits + guard.length ≠ 0 → + (Sum.inr (), s) ∈ (holWhenE (holNot (holLe guard cref)) + (holThrowError (ExceptionTypes_A.lookup_failure.GuardMismatch cref.length guard)) s).1 → + (Sum.inr (), s) ∈ (holWhenE (holLt cref.length (rbits + guard.length)) + (holThrowError (ExceptionTypes_A.lookup_failure.DepthMismatch cref.length (rbits + guard.length))) s).1 → + offset = (cref.drop guard.length).take rbits → + rest = cref.drop (rbits + guard.length) → + rest ≠ [] → + (Sum.inr next_cap, s) ∈ (holLiftE (ε := ExceptionTypes_A.lookup_failure) (CSpaceAcc_A.get_cap (tv_z := ZH) (oref, offset)) s).1 → + Structures_A.is_cnode_cap next_cap = true → + f (z, next_cap, rest) = holResolveAddrBits CSpaceAcc_A.get_cap (next_cap, rest)) : + (Structures_A.case_cap + (holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ _ _ _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ _ _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ _ _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun oref radix_bits guard => + holIf (holEq (HolAdd.addVal radix_bits (holSize guard)) (HolZero.zeroVal (α := Nat))) + (holFail : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure (CslotPtr × CapRef))) + (holBindE (holWhenE (holNot (holLe guard cref)) + (holFunApp (holThrowError (α := Unit)) (.GuardMismatch (holSize cref) guard))) + (holKBind (holBindE (holWhenE (holLt (holSize cref) (HolAdd.addVal radix_bits (holSize guard))) + (holFunApp (holThrowError (α := Unit)) (.DepthMismatch (holSize cref) (HolAdd.addVal radix_bits (holSize guard))))) + (holKBind (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.lookup_failure)) (holListTake radix_bits (holListDrop (holSize guard) cref))) fun offset => + holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.lookup_failure)) (holListDrop (HolAdd.addVal radix_bits (holSize guard)) cref)) fun rest => + holIf (holEq rest []) + (holReturnOk (ε := ExceptionTypes_A.lookup_failure) ((oref, offset), [])) + (holBindE (holFunApp (holLiftE (ε := ExceptionTypes_A.lookup_failure)) (CSpaceAcc_A.get_cap (tv_z := ZH) (oref, offset))) fun next_cap => + holIf (Structures_A.is_cnode_cap next_cap) + (f (z, next_cap, rest)) + (holReturnOk (ε := ExceptionTypes_A.lookup_failure) ((oref, offset), rest))))))))) + (fun _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ _ _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) + (fun _ => holThrowError (α := CslotPtr × CapRef) .InvalidRoot) cap) = + holResolveAddrBits CSpaceAcc_A.get_cap (cap, cref) := by + rw [holResolveAddrBits.eq_1] + cases cap with + | CNodeCap oref rbits guard => + simp only [Structures_A.case_cap, holIf_eq, holEq_eq_true, HolAdd.addVal, Nat.add_eq, + HolZero.zeroVal, holSize_list, holFunApp, holListTake, holListDrop] + by_cases h0 : rbits + guard.length = 0 + · simp [h0] + · simp only [h0, ↓reduceIte] + funext s + refine holBindE_congr_at fun _ s1 hm1 => ?_ + have hs1 : s1 = s := by + cases hgd : holNot (holLe guard cref) with + | true => simp [holWhenE, hgd, holThrowError, holReturn] at hm1 + | false => simp [holWhenE, hgd, holReturnOk, holReturn] at hm1; exact hm1 + rw [hs1] at hm1 ⊢ + refine holBindE_congr_at fun _ s2 hm2 => ?_ + have hs2 : s2 = s := by + cases hdp : holLt cref.length (rbits + guard.length) with + | true => simp [holWhenE, hdp, holThrowError, holReturn] at hm2 + | false => simp [holWhenE, hdp, holReturnOk, holReturn] at hm2; exact hm2 + rw [hs2] at hm2 ⊢ + refine holBindE_congr_at fun offset s3 hm3 => ?_ + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hm3 + rcases hm3 with ⟨hoff, hs3⟩ + rw [hoff, hs3] + rw [holBindE_returnOk_left] + by_cases hrest : cref.drop (rbits + guard.length) = [] + · simp [hrest] + · simp only [hrest, ↓reduceIte] + refine holBindE_congr_at fun next_cap s4 hm4 => ?_ + have hs4 : s4 = s := by + unfold holLiftE holLiftM at hm4 + simp only [holBind, holReturn, Set.mem_singleton_iff] at hm4 + rcases hm4 with ⟨⟨c, s'⟩, hgc, hm_eq⟩ + cases hm_eq + exact getCap_state_eq hgc + rw [hs4] at hm4 ⊢ + by_cases hcn : Structures_A.is_cnode_cap next_cap = true + · simp only [hcn, ↓reduceIte] + rw [hrec oref rbits guard s ((cref.drop guard.length).take rbits) + (cref.drop (rbits + guard.length)) next_cap rfl h0 hm1 hm2 rfl rfl hrest hm4 hcn] + · simp [hcn] + | _ => rfl + +/-- Exact graph characterization of Isabelle's `CSpace_A.resolve_address_bits'_graph`. -/ +theorem resolveAddressBits'_graph_iff (x : HolItself ZH × (Structures_A.cap × CapRef)) + (y : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure (CslotPtr × CapRef))) : + CSpace_A.resolve_address_bits'_graph x y = true ↔ + y = holResolveAddrBits CSpaceAcc_A.get_cap x.2 := by + constructor + · intro h + unfold CSpace_A.resolve_address_bits'_graph at h + rw [holLfp_rel_eq_true] at h + have hP : (fun a b => decide (b = holResolveAddrBits CSpaceAcc_A.get_cap a.2)) x y = true := by + apply h + intro a b hstep + simp only [holEx_eq_true, holConj_eq_true, holEq_eq_true, holAll_eq_true, holImp_eq_true, + holMember_eq_true, holNot_eq_true, ne_eq] at hstep + rcases hstep with ⟨f, z, cap, cref, rfl, rfl, hrec⟩ + rw [decide_eq_true_eq] + apply resolveAddrBits_body_eq f z cap cref + intro oref rbits guard s offset rest next_cap hcap h0 hm1 hm2 hoff hrest hne hgc hcn + have hc := hrec oref rbits guard () s s () s offset s rest s next_cap s + hcap h0 + (by simpa [holSize_list, holFunApp] using hm1) + (by simpa [holSize_list, holFunApp, HolAdd.addVal] using hm2) + (by simp [holFunApp, holReturnOk, holReturn, holListTake, holListDrop, holSize_list, hoff]) + (by simp [holFunApp, holReturnOk, holReturn, holListDrop, holSize_list, HolAdd.addVal, hrest]) + hne + (by simpa [holFunApp] using hgc) + hcn + exact of_decide_eq_true hc + exact of_decide_eq_true hP + · intro hy + subst hy + suffices ∀ n (z : HolItself ZH) (cap : Structures_A.cap) (cref : CapRef), + cref.length ≤ n → + CSpace_A.resolve_address_bits'_graph (z, cap, cref) + (holResolveAddrBits CSpaceAcc_A.get_cap (cap, cref)) = true by + exact this x.2.2.length x.1 x.2.1 x.2.2 (Nat.le_refl _) + intro n + induction n with + | zero => + intro z cap cref hlen + have hnil : cref = [] := List.eq_nil_of_length_eq_zero (Nat.eq_zero_of_le_zero hlen) + subst hnil + unfold CSpace_A.resolve_address_bits'_graph + rw [holLfp_rel_eq_true] + intro P hP + apply hP + simp only [holEx_eq_true, holConj_eq_true, holEq_eq_true, holAll_eq_true, holImp_eq_true, + holMember_eq_true, holNot_eq_true, ne_eq] + refine ⟨fun a => holResolveAddrBits CSpaceAcc_A.get_cap a.2, z, cap, [], rfl, ?_, ?_⟩ + · exact (resolveAddrBits_body_eq (fun a => holResolveAddrBits CSpaceAcc_A.get_cap a.2) z cap [] + (fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ => rfl)).symm + · intro oref rbits guard _ s s1 _ s2 offset s3 rest s4 next_cap s5 _ _ _ _ _ hrest hne + simp [holFunApp, holReturnOk, holReturn, holListDrop] at hrest + exact absurd hrest.1 hne + | succ k ih => + intro z cap cref hlen + unfold CSpace_A.resolve_address_bits'_graph + rw [holLfp_rel_eq_true] + intro P hP + apply hP + simp only [holEx_eq_true, holConj_eq_true, holEq_eq_true, holAll_eq_true, holImp_eq_true, + holMember_eq_true, holNot_eq_true, ne_eq] + refine ⟨fun a => holResolveAddrBits CSpaceAcc_A.get_cap a.2, z, cap, cref, rfl, ?_, ?_⟩ + · exact (resolveAddrBits_body_eq (fun a => holResolveAddrBits CSpaceAcc_A.get_cap a.2) z cap cref + (fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ => rfl)).symm + · intro oref rbits guard _ s s1 _ s2 offset s3 rest s4 next_cap s5 hcap h0 _ _ _ hrest hne _ _ + simp only [holFunApp, holReturnOk, holReturn, holListDrop, holSize_list, HolAdd.addVal, + Nat.add_eq, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hrest + have hrlen : rest.length ≤ k := by + rw [hrest.1, List.length_drop] + have h0' : rbits + guard.length ≠ 0 := by + intro heq; apply h0; simp [HolAdd.addVal, Nat.add_eq, HolZero.zeroVal, holSize_list, heq] + have hpos : cref.length ≠ 0 := by + intro h0''; apply hne; rw [hrest.1, List.drop_eq_nil_of_le]; omega + omega + have hsub := ih z next_cap rest hrlen + unfold CSpace_A.resolve_address_bits'_graph at hsub + rw [holLfp_rel_eq_true] at hsub + exact hsub P hP + +theorem resolveAddressBits_eq_rec (p : Structures_A.cap × CapRef) : + CSpace_A.resolve_address_bits (tv_z := ZH) p = holResolveAddrBits CSpaceAcc_A.get_cap p := by + unfold CSpace_A.resolve_address_bits CSpace_A.resolve_address_bits' CSpace_A.resolve_address_bits'_sumC + exact holTheDefault_eq_of_iff (resolveAddressBits'_graph_iff (HolItself.type, p)) + +theorem mrele_fail_liftE {εH εL αH αL : Type} [Nonempty αH] + {Re : εH → εL → Prop} {Ra : αH → αL → Prop} : + MRelE SR Re Ra holFail (NonDetE.liftE NonDet.fail) := by + have heq : (holFail : HolNonDet (Structures_A.state ZH) (Sum εH αH)) = + holLiftE (holFail : HolNonDet (Structures_A.state ZH) αH) := by + funext s + apply Prod.ext + · ext p; simp [holLiftE, holLiftM, holBind, holFail] + · simp [holLiftE, holLiftM, holBind, holFail] + rw [heq] + exact mrele_liftE mrel_fail + +/-- Patched `resolve_address_bits` using `get_cap_p` (Delta #4). -/ +def resolve_address_bits_p (p : Structures_A.cap × CapRef) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure (CslotPtr × CapRef)) := + holResolveAddrBits get_cap_p p + +theorem patched_resolveAddressBits'_equiv (p : Structures_A.cap × CapRef) : + MRelE SR (FunRel embLookupFailure) Eq + (resolve_address_bits_p p) (Fl4Spec.resolveAddressBits' (embCap p.1, p.2)) := by + suffices ∀ n (cap : Structures_A.cap) (cref : CapRef), cref.length ≤ n → + MRelE SR (FunRel embLookupFailure) Eq + (resolve_address_bits_p (cap, cref)) (Fl4Spec.resolveAddressBits' (embCap cap, cref)) by + exact this p.2.length p.1 p.2 (Nat.le_refl _) + intro n + induction n with + | zero => + intro cap cref hlen + have hnil : cref = [] := List.eq_nil_of_length_eq_zero (Nat.eq_zero_of_le_zero hlen) + subst hnil + unfold resolve_address_bits_p + rw [holResolveAddrBits.eq_1, Fl4Spec.resolveAddressBits'.eq_1] + cases cap with + | CNodeCap oref rbits guard => + simp only [embCap] + by_cases h0 : rbits + guard.length = 0 + · simp only [h0, ↓reduceDIte] + exact mrele_fail_liftE + · simp only [h0, ↓reduceDIte] + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holLe_eq_true, HolOrd.leVal]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE (by simp [holLt_eq_true, HolOrd.ltVal]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun offH offL hoff => ?_ + subst hoff + simp only [List.drop_nil, ↓reduceDIte] + exact mrele_returnOk rfl + | _ => exact mrele_throwError rfl + | succ k ih => + intro cap cref hlen + unfold resolve_address_bits_p + rw [holResolveAddrBits.eq_1, Fl4Spec.resolveAddressBits'.eq_1] + cases cap with + | CNodeCap oref rbits guard => + simp only [embCap] + by_cases h0 : rbits + guard.length = 0 + · simp only [h0, ↓reduceDIte] + exact mrele_fail_liftE + · simp only [h0, ↓reduceDIte] + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holLe_eq_true, HolOrd.leVal]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE (by simp [holLt_eq_true, HolOrd.ltVal]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun offH offL hoff => ?_ + subst hoff + by_cases hr : cref.drop (rbits + guard.length) = [] + · simp only [hr, ↓reduceDIte] + exact mrele_returnOk rfl + · simp only [hr, ↓reduceDIte] + refine mrele_bindE (mrele_liftE (patched_getCap_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) (oref, offH))) + fun ncH ncL hnc => ?_ + subst hnc + rw [isCnodeCap_eq] + by_cases hcn : Structures_A.is_cnode_cap ncH = true + · simp only [hcn, ↓reduceIte] + have hrlen : (cref.drop (rbits + guard.length)).length ≤ k := by + rw [List.length_drop] + have hpos : cref.length ≠ 0 := by intro h0'; apply hr; rw [List.drop_eq_nil_of_le]; omega + omega + exact ih ncH (cref.drop (rbits + guard.length)) hrlen + · simp only [hcn, Bool.false_eq_true, ↓reduceIte] + exact mrele_returnOk rfl + | _ => exact mrele_throwError rfl + +/-- `get_cap` and `get_cap_p` coincide at any slot whose object is not a TCB. -/ +theorem getCap_eq_patched_of_not_tcb {slot : CslotPtr} {sH : Structures_A.state ZH} + (hnt : ∀ t, sH.kheap slot.1 ≠ some (.TCB t)) : + CSpaceAcc_A.get_cap slot sH = get_cap_p slot sH := by + unfold CSpaceAcc_A.get_cap get_cap_p KHeap_A.get_object KHeap_A.read_object holSwp + cases hk : sH.kheap slot.1 with + | none => simp [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holFail] + | some ko => + cases ko with + | TCB t => exact absurd hk (hnt t) + | _ => simp [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holReturn, Structures_A.case_kernel_object] + +/-! ## Lookup, CapTransfer, Fast Finalise, Cap Swap/Move/Insert -/ + +def lookup_slot_for_thread_p (thread : ObjRef) (cref : CapRef) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure (CslotPtr × CapRef)) := + holBindE (holLiftE (holGetsThe (KHeap_A.get_tcb thread))) fun tcb => + resolve_address_bits_p (tcb.tcb_ctable, cref) + +theorem patched_lookupSlotForThread_equiv (thread : ObjRef) (cref : CapRef) : + MRelE SR (FunRel embLookupFailure) Eq + (lookup_slot_for_thread_p thread cref) (Fl4Spec.lookupSlotForThread thread cref) := by + unfold lookup_slot_for_thread_p Fl4Spec.lookupSlotForThread + refine mrele_bindE (mrele_liftE (mrel_getsThe (getTcb_equiv thread))) fun tH tL ht => ?_ + subst ht + exact patched_resolveAddressBits'_equiv (tH.tcb_ctable, cref) + +def lookup_cap_and_slot_p (thread : ObjRef) (cptr : CapRef) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure (Structures_A.cap × CslotPtr)) := + holBindE (lookup_slot_for_thread_p thread cptr) fun (slot, _) => + holBindE (holLiftE (get_cap_p slot)) fun cap => holReturnOk (cap, slot) + +theorem patched_lookupCapAndSlot_equiv (thread : ObjRef) (cptr : CapRef) : + MRelE SR (FunRel embLookupFailure) (ProdRel (FunRel embCap) Eq) + (lookup_cap_and_slot_p thread cptr) (Fl4Spec.lookupCapAndSlot thread cptr) := by + unfold lookup_cap_and_slot_p Fl4Spec.lookupCapAndSlot + refine mrele_bindE (patched_lookupSlotForThread_equiv thread cptr) fun pH pL hp => ?_ + subst hp + rcases pH with ⟨slot, cr⟩ + refine mrele_bindE (mrele_liftE (patched_getCap_equiv slot)) fun cH cL hc => ?_ + subst hc + exact mrele_returnOk ⟨rfl, rfl⟩ + +def lookup_cap_p (thread : ObjRef) (ref : CapRef) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure Structures_A.cap) := + holBindE (lookup_slot_for_thread_p thread ref) fun (ref', _) => + holLiftE (get_cap_p ref') + +theorem patched_lookupCap_equiv (thread : ObjRef) (ref : CapRef) : + MRelE SR (FunRel embLookupFailure) (FunRel embCap) + (lookup_cap_p thread ref) (Fl4Spec.lookupCap thread ref) := by + unfold lookup_cap_p Fl4Spec.lookupCap + refine mrele_bindE (patched_lookupSlotForThread_equiv thread ref) fun pH pL hp => ?_ + subst hp + rcases pH with ⟨slot, cr⟩ + exact mrele_liftE (patched_getCap_equiv slot) + +def lookup_slot_for_cnode_op_p (is_source : Bool) (croot : Structures_A.cap) (ptr : CapRef) (depth : Nat) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error CslotPtr) := + holIf (Structures_A.is_cnode_cap croot) + (holBindE (holWhenE (holDisj (holLt depth 1) (holLt Machine_Word_64_Basics.word_bits depth)) + (holThrowError (.RangeError 1 (holOfNat Machine_Word_64_Basics.word_bits)))) + (holKBind (Exceptions_A.lookup_error_on_failure is_source + (holBindE (holReturnOk (ptr.drop (ptr.length - depth))) fun ptrbits => + holBindE (resolve_address_bits_p (croot, ptrbits)) fun (slot, rem) => + match rem with + | [] => holReturnOk slot + | _ => holThrowError (.DepthMismatch rem.length 0))))) + (holThrowError (.FailedLookup is_source .InvalidRoot)) + +theorem patched_lookupSlotForCnodeOp_equiv (isSource : Bool) (croot : Structures_A.cap) + (ptr : CapRef) (depth : Nat) : + MRelE SR (FunRel embSyscallError) Eq + (lookup_slot_for_cnode_op_p isSource croot ptr depth) + (Fl4Spec.lookupSlotForCnodeOp isSource (embCap croot) ptr depth) := by + unfold lookup_slot_for_cnode_op_p Fl4Spec.lookupSlotForCnodeOp + rw [isCnodeCap_eq] + refine mrele_if Iff.rfl (fun _ => ?_) (fun _ => mrele_throwError rfl) + refine mrele_kbindE (mrele_whenE (by simp [holDisj_eq_true, holLt_eq_true, HolOrd.ltVal, wordBits_eq, gt_iff_lt]) + fun _ => mrele_throwError (by rfl)) ?_ + refine lookupErrorOnFailure_equiv isSource ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pbH pbL hpb => ?_ + subst hpb + refine mrele_bindE (patched_resolveAddressBits'_equiv (croot, pbH)) fun pH pL hp => ?_ + subst hp + rcases pH with ⟨slot, rem⟩ + cases rem with + | nil => exact mrele_returnOk rfl + | cons b bs => exact mrele_throwError rfl + +def lookup_source_slot_p := lookup_slot_for_cnode_op_p (ZH := ZH) true +def lookup_target_slot_p := lookup_slot_for_cnode_op_p (ZH := ZH) false +def lookup_pivot_slot_p := lookup_slot_for_cnode_op_p (ZH := ZH) true + +theorem captransferFromWords_equiv (ptr : Word) : + MRel SR (FunRel embCapTransfer) + (CSpace_A.captransfer_from_words ptr) (Fl4Spec.captransferFromWords ptr) := by + unfold CSpace_A.captransfer_from_words Fl4Spec.captransferFromWords + refine mrel_bind (mrel_doMachineOp (loadWord_equiv ptr)) fun w0H w0L hw0 => ?_ + subst hw0 + refine mrel_bind (mrel_doMachineOp (loadWord_equiv _)) fun w1H w1L hw1 => ?_ + subst hw1 + refine mrel_bind (mrel_doMachineOp (loadWord_equiv _)) fun w2H w2L hw2 => ?_ + subst hw2 + exact mrel_return (by + unfold FunRel embCapTransfer; simp only [dataToCptr_eq]) + +theorem loadCapTransfer_equiv (buffer : ObjRef) : + MRel SR (FunRel embCapTransfer) + (CSpace_A.load_cap_transfer buffer) (Fl4Spec.loadCapTransfer buffer) := by + unfold CSpace_A.load_cap_transfer Fl4Spec.loadCapTransfer + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun offH offL hoff => ?_ + subst hoff + exact captransferFromWords_equiv _ + +def get_receive_slots_p : ObjRef → Option ObjRef → HolNonDet (Structures_A.state ZH) (List CslotPtr) + | thread, some buffer => + holBind (CSpace_A.load_cap_transfer buffer) fun ct => + Exceptions_A.empty_on_failure + (holBindE (Exceptions_A.unify_failure (lookup_cap_p thread ct.ct_receive_root)) fun cnode => + holBindE (Exceptions_A.unify_failure (lookup_target_slot_p cnode ct.ct_receive_index (holUnsigned ct.ct_receive_depth))) fun slot => + holBindE (holLiftE (get_cap_p slot)) fun cap => + holBindE (holWhenE (holNot (holEq cap .NullCap)) (holThrowError ())) + (holKBind (holReturnOk [slot]))) + | _, none => holReturn [] + +theorem patched_getReceiveSlots_equiv (thread : ObjRef) (buf : Option ObjRef) : + MRel SR Eq (get_receive_slots_p thread buf) (Fl4Spec.getReceiveSlots thread buf) := by + cases buf with + | none => exact mrel_return rfl + | some buffer => + unfold get_receive_slots_p Fl4Spec.getReceiveSlots + refine mrel_bind (loadCapTransfer_equiv buffer) fun ctH ctL hct => ?_ + subst hct + have : Nonempty ExceptionTypes_A.lookup_failure := ⟨.InvalidRoot⟩ + have : Nonempty ExceptionTypes_A.syscall_error := ⟨.IllegalOperation⟩ + have hEOF : MRel SR (ListRel Eq) + (Exceptions_A.empty_on_failure + (holBindE (Exceptions_A.unify_failure (lookup_cap_p thread ctH.ct_receive_root)) fun cnode => + holBindE (Exceptions_A.unify_failure + (lookup_target_slot_p cnode ctH.ct_receive_index (holUnsigned ctH.ct_receive_depth))) fun slot => + holBindE (holLiftE (get_cap_p slot)) fun cap => + holBindE (holWhenE (holNot (holEq cap .NullCap)) (holThrowError ())) + (holKBind (holReturnOk [slot])))) + (Fl4Spec.emptyOnFailure (do + let cnode ← Fl4Spec.unifyFailure (Fl4Spec.lookupCap thread ctH.ct_receive_root) + let slot ← Fl4Spec.unifyFailure + (Fl4Spec.lookupTargetSlot cnode ctH.ct_receive_index (Fl4Spec.unat ctH.ct_receive_depth)) + let cap ← NonDetE.liftE (Fl4Spec.getCap slot) + NonDetE.whenE (cap ≠ Cap.nullCap) (NonDetE.throwError ()) + NonDetE.returnOk [slot])) := by + refine emptyOnFailure_equiv (FH := Unit) (FL := Unit) (αH := CslotPtr) (αL := CslotPtr) + (Rf := Eq) (Ra := Eq) ?_ + refine mrele_bindE (unifyFailure_equiv (FH := ExceptionTypes_A.lookup_failure) (FL := LookupFailure) + (patched_lookupCap_equiv thread ctH.ct_receive_root)) fun cnH cnL hcn => ?_ + subst hcn + refine mrele_bindE (unifyFailure_equiv (FH := ExceptionTypes_A.syscall_error) (FL := SyscallError) + (patched_lookupSlotForCnodeOp_equiv false cnH ctH.ct_receive_index ctH.ct_receive_depth.toNat)) + fun slH slL hsl => ?_ + subst hsl + refine mrele_bindE (mrele_liftE (patched_getCap_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) slH)) fun cH cL hc => ?_ + subst hc + refine mrele_kbindE (mrele_whenE (by cases cH <;> simp [holNot_eq_true, holEq_eq_true, embCap]) + fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk (ListRel.cons rfl ListRel.nil) + intro sH sL hs + have h := hEOF sH sL hs + have hlr : ∀ {xs ys : List CslotPtr}, ListRel Eq xs ys → xs = ys := by + intro xs ys hl + induction hl with + | nil => rfl + | cons h1 _ ih => subst h1; exact congrArg _ ih + exact ⟨h.1, + fun aH sH' hm => let ⟨aL, sL', hm', ha, hs'⟩ := h.2.1 aH sH' hm; ⟨aL, sL', hm', hlr ha, hs'⟩, + fun aL sL' hm => let ⟨aH, sH', hm', ha, hs'⟩ := h.2.2 aL sL' hm; ⟨aH, sH', hm', hlr ha, hs'⟩⟩ + +def set_untyped_cap_as_full_p (src_cap new_cap : Structures_A.cap) (src_slot : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + holIf (holConj (Structures_A.is_untyped_cap src_cap) + (holConj (Structures_A.is_untyped_cap new_cap) + (holConj (holEq (Structures_A.obj_ref_of src_cap) (Structures_A.obj_ref_of new_cap)) + (holEq (Structures_A.cap_bits_untyped src_cap) (Structures_A.cap_bits_untyped new_cap))))) + (set_cap_p (CSpace_A.max_free_index_update src_cap) src_slot) (holReturn ()) + +theorem patched_setUntypedCapAsFull_equiv (srcCap newCap : Structures_A.cap) (srcSlot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hslot : NonExtCapSlot srcSlot sH) : + MRelStep SR Eq + (set_untyped_cap_as_full_p srcCap newCap srcSlot sH) + (Fl4Spec.setUntypedCapAsFull (embCap srcCap) (embCap newCap) srcSlot sL) := by + unfold set_untyped_cap_as_full_p Fl4Spec.setUntypedCapAsFull + have hcond : holConj (Structures_A.is_untyped_cap srcCap) + (holConj (Structures_A.is_untyped_cap newCap) + (holConj (holEq (Structures_A.obj_ref_of srcCap) (Structures_A.obj_ref_of newCap)) + (holEq (Structures_A.cap_bits_untyped srcCap) (Structures_A.cap_bits_untyped newCap)))) = true ↔ + Fl4Spec.isUntypedCap (embCap srcCap) = true ∧ Fl4Spec.isUntypedCap (embCap newCap) = true ∧ + Fl4Spec.objRefOf (embCap srcCap) = Fl4Spec.objRefOf (embCap newCap) ∧ + Fl4Spec.capBitsUntyped (embCap srcCap) = Fl4Spec.capBitsUntyped (embCap newCap) := by + simp only [holConj_eq_true, holEq_eq_true, isUntypedCap_eq, objRefOf_eq] + refine and_congr_right fun hu1 => and_congr_right fun hu2 => and_congr_right fun _ => ?_ + cases srcCap <;> try simp [Structures_A.is_untyped_cap] at hu1 + cases newCap <;> try simp [Structures_A.is_untyped_cap] at hu2 + rfl + by_cases hL : Fl4Spec.isUntypedCap (embCap srcCap) = true ∧ Fl4Spec.isUntypedCap (embCap newCap) = true ∧ + Fl4Spec.objRefOf (embCap srcCap) = Fl4Spec.objRefOf (embCap newCap) ∧ + Fl4Spec.capBitsUntyped (embCap srcCap) = Fl4Spec.capBitsUntyped (embCap newCap) + · simp only [hcond.mpr hL, holIf_true, hL] + have hmfu := maxFreeIndexUpdate_eq srcCap + rw [hmfu] + exact patched_setCap_equiv_at (CSpace_A.max_free_index_update srcCap) srcSlot hs (Or.inl hslot) + · simp only [Bool.eq_false_iff.mpr (mt hcond.mp hL), holIf_false, hL, ↓reduceIte] + exact mrel_return rfl sH sL hs + +def cap_insert_p (new_cap : Structures_A.cap) (src_slot dest_slot : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (get_cap_p src_slot) fun src_cap => + holBind (holReturn (CSpace_A.is_cap_revocable new_cap src_cap)) fun dest_orig => + holBind (get_cap_p dest_slot) fun old_cap => + holBind (holAssert (holEq old_cap .NullCap)) (holKBind + (holBind (set_untyped_cap_as_full_p src_cap new_cap src_slot) (holKBind + (holBind (set_cap_p new_cap dest_slot) (holKBind + (holBind (holGets fun s => s.is_original_cap) fun is_orig => + holBind (holReturn (should_be_parent_of_p src_cap (is_orig src_slot) new_cap dest_orig)) fun src_parent => + holBind (holGets fun s => s.cdt src_slot) fun src_p => + holBind (holGets fun s => s.cdt dest_slot) fun dest_p => + holBind (CSpaceAcc_A.update_cdt fun cdt => + holFunUpd cdt dest_slot (holIf src_parent (some src_slot) (cdt src_slot))) + (holKBind (holBind (Deterministic_A.do_extended_op + (Deterministic_A.cap_insert_ext src_parent src_slot dest_slot src_p dest_p)) + (holKBind (CSpaceAcc_A.set_original dest_slot dest_orig)))))))))) + +/-- Cap insertion reads a valid source and checks slot admissibility at the actual writes. -/ +def CapInsertSafe (newCap : Structures_A.cap) (srcSlot destSlot : CslotPtr) + (s : Structures_A.state ZH) : Prop := + ∀ src s₁, (src, s₁) ∈ (get_cap_p srcSlot s).1 → + DeriveSrcValid newCap src ∧ + ∀ old s₂, (old, s₂) ∈ (get_cap_p destSlot s₁).1 → old = .NullCap → + NonExtCapSlot srcSlot s₂ ∧ + ∀ u s₃, (u, s₃) ∈ (set_untyped_cap_as_full_p src newCap srcSlot s₂).1 → + SetCapSafe newCap destSlot s₃ + +theorem patched_capInsert_equiv (newCap : Structures_A.cap) (srcSlot destSlot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : CapInsertSafe newCap srcSlot destSlot sH) : + MRelStep SR Eq + (cap_insert_p newCap srcSlot destSlot sH) + (Fl4Spec.capInsert (embCap newCap) srcSlot destSlot sL) := by + unfold cap_insert_p Fl4Spec.capInsert + refine mrelStep_bind_mem (patched_getCap_equiv srcSlot sH sL hs) + fun scH scL hsc s1H s1L hs1 hm1 => ?_ + subst hsc + obtain ⟨hvalid, hwrites⟩ := hsafe scH s1H hm1 + refine mrelStep_bind_mem (mrel_return (Ra := Eq) (by + apply Bool.eq_iff_iff.mpr + simp only [decide_eq_true_eq] + exact isCapRevocable_iff newCap scH hvalid) s1H s1L hs1) + fun doH doL hdo s2H s2L hs2 hm2 => ?_ + subst hdo + have hs2eq : s2H = s1H := congrArg Prod.snd (Set.mem_singleton_iff.mp hm2) + subst s2H + refine mrelStep_bind_mem (patched_getCap_equiv destSlot s1H s2L hs2) + fun oldH oldL hold s3H s3L hs3 hm3 => ?_ + subst hold + refine mrelStep_bind_mem (mrel_assert (by cases oldH <;> simp [holEq_eq_true, embCap]) s3H s3L hs3) + fun _ _ _ s4H s4L hs4 hm4 => ?_ + have ⟨hnull, hs4eq⟩ : oldH = .NullCap ∧ s4H = s3H := by + simpa [holAssert, holEq_eq_true] using hm4 + subst s4H + obtain ⟨hsrc, hdest⟩ := hwrites oldH s3H hm3 hnull + refine mrelStep_bind_mem (patched_setUntypedCapAsFull_equiv scH newCap srcSlot hs4 hsrc) + fun u _ _ s5H s5L hs5 hm5 => ?_ + refine mrelStep_bind_mem (patched_setCap_equiv_at newCap destSlot hs5 (hdest u s5H hm5)) + fun _ _ _ s6H s6L hs6 _ => ?_ + refine (mrel_bind (mrel_gets fun _ _ h => h.isOriginalCap_eq.symm) fun origH origL horig => ?_) s6H s6L hs6 + subst horig + refine mrel_bind (mrel_return (Ra := Eq) (by + apply Bool.eq_iff_iff.mpr + simp only [decide_eq_true_eq] + exact patched_shouldBeParentOf_iff scH (origH srcSlot) newCap doH)) fun spH spL hsp => ?_ + subst hsp + refine mrel_bind (mrel_gets fun _ _ h => congrFun h.cdt_eq.symm srcSlot) fun p1H p1L hp1 => ?_ + subst hp1 + refine mrel_bind (mrel_gets fun _ _ h => congrFun h.cdt_eq.symm destSlot) fun p2H p2L hp2 => ?_ + subst hp2 + refine mrel_kbind (by + have hfun : (fun cdt => Function.update cdt destSlot (if spH = true then some srcSlot else cdt srcSlot)) = + (fun cdt => holFunUpd cdt destSlot (holIf spH (some srcSlot) (cdt srcSlot))) := by + funext cdt k; simp only [holFunUpd, Function.update, holIf_eq] + rw [hfun]; exact updateCdt_equiv _) ?_ + refine mrel_kbind (doExtendedOp_equiv (capInsertExt_equiv spH srcSlot destSlot p1H p2H)) ?_ + exact setOriginal_equiv destSlot doH + + +omit [StateExt ZL] in +private theorem leanGetCap_state_eq {sL : State ZL} {slot : CslotPtr} {a : Cap} {st : State ZL} + (h : (a, st) ∈ (Fl4Spec.getCap slot sL).1) : st = sL := by + rcases slot with ⟨oref, cref⟩ + unfold Fl4Spec.getCap Fl4Spec.getObject Fl4Spec.readObject at h + cases hk : sL.kheap oref with + | none => simp [hk, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, NonDet.fail] at h + | some ko => + cases ko with + | cnode sz cn => + by_cases hw : Fl4Spec.wellFormedCnodeN sz cn + · cases hc : cn cref with + | none => + simp [hk, hw, hc, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, + NonDet.assert, NonDet.pure, NonDet.fail] at h + | some cap => + simp [hk, hw, hc, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, + NonDet.assert, NonDet.pure] at h + exact h.2 + · simp [hk, hw, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, + NonDet.assert, NonDet.pure] at h + | tcb tcb => + cases hc : Fl4Spec.tcbCnodeMap tcb cref with + | none => + simp [hk, hc, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, + NonDet.pure, NonDet.fail] at h + | some cap => + simp [hk, hc, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, + NonDet.pure] at h + exact h.2 + | _ => + simp [hk, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, + NonDet.pure, NonDet.fail] at h + + +private theorem refIntersection_ne_empty (cap other : Structures_A.cap) : + IpcCancel_A.gen_obj_refs cap ∩ IpcCancel_A.gen_obj_refs other ≠ ∅ ↔ + Fl4Spec.genObjRefs (embCap cap) ∩ Fl4Spec.genObjRefs (embCap other) ≠ ∅ := by + rw [genObjRefs_eq, genObjRefs_eq, ← Set.image_inter embGenObjRef_injective] + exact not_congr Set.image_eq_empty.symm + +private theorem capReferenceAt_iff {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (cap : Structures_A.cap) (slot : CslotPtr) : + (∃ other, (CSpaceAcc_A.get_cap slot sH).1 = {(other, sH)} ∧ + IpcCancel_A.gen_obj_refs cap ∩ IpcCancel_A.gen_obj_refs other ≠ ∅) ↔ + (∃ other, (Fl4Spec.getCap slot sL).1 = {(other, sL)} ∧ + Fl4Spec.genObjRefs (embCap cap) ∩ Fl4Spec.genObjRefs other ≠ ∅) := by + have transfer (hrel : MRelStep SR (FunRel embCap) (CSpaceAcc_A.get_cap slot sH) + (Fl4Spec.getCap slot sL)) : + (∃ other, (CSpaceAcc_A.get_cap slot sH).1 = {(other, sH)} ∧ + IpcCancel_A.gen_obj_refs cap ∩ IpcCancel_A.gen_obj_refs other ≠ ∅) ↔ + (∃ other, (Fl4Spec.getCap slot sL).1 = {(other, sL)} ∧ + Fl4Spec.genObjRefs (embCap cap) ∩ Fl4Spec.genObjRefs other ≠ ∅) := by + constructor + · rintro ⟨other, result, refs⟩ + have hmem : (other, sH) ∈ (CSpaceAcc_A.get_cap slot sH).1 := by rw [result]; rfl + obtain ⟨otherL, stateL, memL, related, _⟩ := hrel.2.1 _ _ hmem + have hst := leanGetCap_state_eq memL + subst stateL + subst related + refine ⟨embCap other, ?_, (refIntersection_ne_empty cap other).mp refs⟩ + ext ⟨c, st⟩ + simp only [Set.mem_singleton_iff, Prod.mk.injEq] + constructor + · intro hm + obtain ⟨ch, sh, hmH, hcap, _⟩ := hrel.2.2 _ _ hm + rw [result] at hmH + simp only [Set.mem_singleton_iff, Prod.mk.injEq] at hmH + exact ⟨hcap.trans (congrArg embCap hmH.1), leanGetCap_state_eq hm⟩ + · rintro ⟨rfl, rfl⟩ + exact memL + · rintro ⟨otherL, result, refs⟩ + have hmem : (otherL, sL) ∈ (Fl4Spec.getCap slot sL).1 := by rw [result]; rfl + obtain ⟨otherH, stateH, memH, related, _⟩ := hrel.2.2 _ _ hmem + have hst := getCap_state_eq memH + subst stateH + subst related + refine ⟨otherH, ?_, (refIntersection_ne_empty cap otherH).mpr refs⟩ + ext ⟨c, st⟩ + simp only [Set.mem_singleton_iff, Prod.mk.injEq] + constructor + · intro hm + obtain ⟨cl, sl, hmL, hcap, _⟩ := hrel.2.1 _ _ hm + rw [result] at hmL + simp only [Set.mem_singleton_iff, Prod.mk.injEq] at hmL + exact ⟨embCap_injective (hcap.symm.trans hmL.1), getCap_state_eq hm⟩ + · rintro ⟨rfl, rfl⟩ + exact memH + by_cases hidx : NonExtTcbSlot slot.2 + · exact transfer (getCap_equiv_nonExt slot hidx sH sL hs) + by_cases htcb : ∃ t, sH.kheap slot.1 = some (.TCB t) + · obtain ⟨t, ht⟩ := htcb + have htL : sL.kheap slot.1 = some (.tcb (embTcb t)) := by rw [hs.kheap_eq, ht]; rfl + have hslot : slot.2 = tcbCnodeIndex 5 := by + simpa [NonExtTcbSlot] using hidx + have hmapH : Structures_A.tcb_cnode_map t slot.2 = none := by + rw [hslot, tcbCnodeIndex_eq] + exact (Patched.tcbEptSlot_delta t).1 + have hmapL : Fl4Spec.tcbCnodeMap (embTcb t) slot.2 = some .nullCap := by + rw [hslot] + exact (Patched.tcbEptSlot_delta t).2 + have hH : (CSpaceAcc_A.get_cap slot sH).1 = ∅ := by + unfold CSpaceAcc_A.get_cap KHeap_A.get_object KHeap_A.read_object holSwp + simp [ht, hmapH, Structures_A.case_kernel_object, holBind, holGetsThe, holAssertOpt, + holReturn, holFail] + have hL : (Fl4Spec.getCap slot sL).1 = {(.nullCap, sL)} := by + unfold Fl4Spec.getCap Fl4Spec.getObject Fl4Spec.readObject + simp [htL, hmapL, Bind.bind, Pure.pure, NonDet.bind, NonDet.getsThe, + NonDet.assertOpt, NonDet.pure] + rw [hH, hL] + simp [genObjRefs_nullCap] + · apply transfer + have hnt : ∀ t, sH.kheap slot.1 ≠ some (.TCB t) := fun t h => htcb ⟨t, h⟩ + have heq := getCap_eq_patched_of_not_tcb hnt + have hrel := patched_getCap_equiv slot sH sL hs + rw [heq] + exact hrel + +private theorem insert_empty_singleton {α : Type} (a : α) : insert a (∅ : Set α) = {a} := by + ext x + simp + +theorem isFinalCap'_iff {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (cap : Structures_A.cap) : + IpcCancel_A.is_final_cap' cap sH = true ↔ Fl4Spec.isFinalCap' (embCap cap) sL := by + unfold IpcCancel_A.is_final_cap' Fl4Spec.isFinalCap' + simp only [holEx_eq_true, holEq_eq_true, holCollect_eq, holConj_eq_true, + holNot_eq_true, holInsert_eq, HolCompleteLattice.holBot, HolCompleteLattice.holInf, + insert_empty_singleton, ne_eq, holEq_eq_true] + have hset : {slot | ∃ other, (CSpaceAcc_A.get_cap slot sH).1 = {(other, sH)} ∧ + IpcCancel_A.gen_obj_refs cap ∩ IpcCancel_A.gen_obj_refs other ≠ ∅} = + {slot | ∃ other, (Fl4Spec.getCap slot sL).1 = {(other, sL)} ∧ + Fl4Spec.genObjRefs (embCap cap) ∩ Fl4Spec.genObjRefs other ≠ ∅} := by + ext slot + exact capReferenceAt_iff hs cap slot + rw [hset] + +theorem isFinalCap_equiv (cap : Structures_A.cap) : + MRel SR Eq (IpcCancel_A.is_final_cap cap) (Fl4Spec.isFinalCap (embCap cap)) := by + unfold IpcCancel_A.is_final_cap Fl4Spec.isFinalCap + refine mrel_gets fun _ _ hs => ?_ + apply Bool.eq_iff_iff.mpr + rw [isFinalCap'_iff hs cap, decide_eq_true_eq] + +def slot_cap_long_running_delete_p (slot : CslotPtr) : HolNonDet (Structures_A.state ZH) Bool := + holBind (get_cap_p slot) fun cap => + match cap with + | .NullCap => holReturn false + | _ => holBind (IpcCancel_A.is_final_cap cap) fun final => + holReturn (holConj final (CSpace_A.long_running_delete cap)) + +theorem patched_slotCapLongRunningDelete_equiv (slot : CslotPtr) : + MRel SR Eq + (slot_cap_long_running_delete_p slot) (Fl4Spec.slotCapLongRunningDelete slot) := by + unfold slot_cap_long_running_delete_p Fl4Spec.slotCapLongRunningDelete + refine mrel_bind (patched_getCap_equiv slot) fun cH cL hc => ?_ + subst hc + cases cH with + | NullCap => exact mrel_return rfl + | _ => + refine mrel_bind (isFinalCap_equiv (RestRel := RestRel) _) fun fH fL hf => ?_ + subst hf + exact mrel_return (by rw [longRunningDelete_eq]; rfl) + +/-- l4v: CSpace_A.cap_swap with X64 base-slot writes. -/ +def cap_swap_p (cap1 : Structures_A.cap) (slot1 : CslotPtr) + (cap2 : Structures_A.cap) (slot2 : CslotPtr) : HolNonDet (Structures_A.state ZH) Unit := + holBind (set_cap_p cap2 slot1) (holKBind (holBind (set_cap_p cap1 slot2) (holKBind + (holBind (holGets fun s => s.cdt slot1) fun p1 => + holBind (holGets fun s => s.cdt slot2) fun p2 => + holBind (holGets fun s => s.cdt) fun cdt => + holBind (holReturn fun n => holIf (holEq (cdt n) (some slot1)) (some slot2) + (holIf (holEq (cdt n) (some slot2)) (some slot1) (cdt n))) fun cdt' => + holBind (CSpaceAcc_A.set_cdt (holFunUpd (holFunUpd cdt' slot1 (cdt' slot2)) slot2 (cdt' slot1))) + (holKBind (holBind (Deterministic_A.do_extended_op (Deterministic_A.cap_swap_ext slot1 slot2 p1 p2)) + (holKBind (holBind (holGets fun s => s.is_original_cap) fun is_orig => + holBind (CSpaceAcc_A.set_original slot1 (is_orig slot2)) + (holKBind (CSpaceAcc_A.set_original slot2 (is_orig slot1))))))))))) + +/-- [P] The two actual writes must admit their destination slots. -/ +theorem patched_capSwap_equiv (cap1 : Structures_A.cap) (slot1 : CslotPtr) + (cap2 : Structures_A.cap) (slot2 : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (h1 : SetCapSafe cap2 slot1 sH) + (h2 : ∀ t, ((), t) ∈ (set_cap_p cap2 slot1 sH).1 → SetCapSafe cap1 slot2 t) : + MRelStep SR Eq + (cap_swap_p cap1 slot1 cap2 slot2 sH) + (Fl4Spec.capSwap (embCap cap1) slot1 (embCap cap2) slot2 sL) := by + unfold cap_swap_p Fl4Spec.capSwap + refine mrelStep_bind_mem (patched_setCap_equiv_at cap2 slot1 hs h1) + fun a _ _ s1H s1L hs1 hm1 => ?_ + cases a + refine mrelStep_bind_mem (patched_setCap_equiv_at cap1 slot2 hs1 (h2 s1H hm1)) + fun _ _ _ s2H s2L hs2 _ => ?_ + refine (mrel_bind (mrel_gets fun _ _ h => congrFun h.cdt_eq.symm slot1) fun p1H p1L hp1 => ?_) s2H s2L hs2 + subst hp1 + refine mrel_bind (mrel_gets fun _ _ h => congrFun h.cdt_eq.symm slot2) fun p2H p2L hp2 => ?_ + subst hp2 + refine mrel_bind (mrel_gets fun _ _ h => h.cdt_eq.symm) fun cdtH cdtL hcdt => ?_ + subst hcdt + refine mrel_bind (mrel_return (Ra := Eq) (by funext n; simp only [holIf_eq, holEq_eq_true])) fun cdt'H cdt'L hcdt' => ?_ + subst hcdt' + refine mrel_kbind (by + have hfun : Function.update (Function.update cdt'H slot1 (cdt'H slot2)) slot2 (cdt'H slot1) = + holFunUpd (holFunUpd cdt'H slot1 (cdt'H slot2)) slot2 (cdt'H slot1) := by + funext k; simp only [holFunUpd, Function.update]; split_ifs <;> rfl + rw [hfun]; exact setCdt_equiv _) ?_ + refine mrel_kbind (doExtendedOp_equiv (capSwapExt_equiv slot1 slot2 p1H p2H)) ?_ + refine mrel_bind (mrel_gets fun _ _ h => h.isOriginalCap_eq.symm) fun origH origL horig => ?_ + subst horig + refine mrel_kbind (setOriginal_equiv slot1 (origH slot2)) ?_ + exact setOriginal_equiv slot2 (origH slot1) + +/-- l4v: CSpace_A.cap_move with X64 base-slot writes. -/ +def cap_move_p (newCap : Structures_A.cap) (srcSlot destSlot : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (set_cap_p newCap destSlot) (holKBind (holBind (set_cap_p .NullCap srcSlot) (holKBind + (holBind (holGets fun s => s.cdt srcSlot) fun src_p => + holBind (holGets fun s => s.cdt destSlot) fun dest_p => + holBind (holGets fun s => s.cdt) fun cdt => + holBind (holReturn (cdt srcSlot)) fun parent => + holBind (holReturn (holFunUpd (holFunUpd cdt destSlot parent) srcSlot none)) fun cdt' => + holBind (CSpaceAcc_A.set_cdt fun r => holIf (holEq (cdt' r) (some srcSlot)) (some destSlot) (cdt' r)) + (holKBind (holBind (Deterministic_A.do_extended_op (Deterministic_A.cap_move_ext srcSlot destSlot src_p dest_p)) + (holKBind (holBind (holGets fun s => s.is_original_cap) fun is_orig => + holBind (CSpaceAcc_A.set_original destSlot (is_orig srcSlot)) + (holKBind (CSpaceAcc_A.set_original srcSlot false)))))))))) + +/-- [P] The moved capability must admit its destination slot. -/ +theorem patched_capMove_equiv (newCap : Structures_A.cap) (srcSlot destSlot : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hd : SetCapSafe newCap destSlot sH) : + MRelStep SR Eq + (cap_move_p newCap srcSlot destSlot sH) + (Fl4Spec.capMove (embCap newCap) srcSlot destSlot sL) := by + unfold cap_move_p Fl4Spec.capMove + refine mrelStep_bind_mem (patched_setCap_equiv_at newCap destSlot hs hd) + fun _ _ _ s1H s1L hs1 _ => ?_ + refine mrelStep_bind_mem (patched_setCap_equiv_at .NullCap srcSlot hs1 (Or.inr rfl)) + fun _ _ _ s2H s2L hs2 _ => ?_ + refine (mrel_bind (mrel_gets fun _ _ h => congrFun h.cdt_eq.symm srcSlot) + fun p1H p1L hp1 => ?_) s2H s2L hs2 + subst hp1 + refine mrel_bind (mrel_gets fun _ _ h => congrFun h.cdt_eq.symm destSlot) fun p2H p2L hp2 => ?_ + subst hp2 + refine mrel_bind (mrel_gets fun _ _ h => h.cdt_eq.symm) fun cdtH cdtL hcdt => ?_ + subst hcdt + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun parH parL hpar => ?_ + subst hpar + refine mrel_bind (mrel_return (Ra := Eq) (by + funext k; simp only [holFunUpd, Function.update]; split_ifs <;> rfl)) fun cdt'H cdt'L hcdt' => ?_ + subst hcdt' + refine mrel_kbind (by + have hfun : (fun r => if cdt'H r = some srcSlot then some destSlot else cdt'H r) = + (fun r => holIf (holEq (cdt'H r) (some srcSlot)) (some destSlot) (cdt'H r)) := by + funext r; simp only [holIf_eq, holEq_eq_true] + rw [hfun]; exact setCdt_equiv _) ?_ + refine mrel_kbind (doExtendedOp_equiv (capMoveExt_equiv srcSlot destSlot p1H p2H)) ?_ + refine mrel_bind (mrel_gets fun _ _ h => h.isOriginalCap_eq.symm) fun origH origL horig => ?_ + subst horig + refine mrel_kbind (setOriginal_equiv destSlot (origH srcSlot)) ?_ + exact setOriginal_equiv srcSlot false + + +theorem postCapDeletion_equiv (cap : Structures_A.cap) : + MRel SR Eq (IpcCancel_A.post_cap_deletion cap) (Fl4Spec.postCapDeletion (embCap cap)) := by + cases cap with + | IRQHandlerCap irq => exact setIrqState_equiv .IRQInactive irq + | ArchObjectCap arch => exact archPostCapDeletion_equiv arch + | _ => exact mrel_return rfl + +/-- l4v: IpcCancel_A.empty_slot with X64 capability-slot access. -/ +def empty_slot_p (slot : CslotPtr) (cleanup_info : Structures_A.cap) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (get_cap_p slot) fun cap => + holIf (holEq cap .NullCap) (holReturn ()) + (holBind (holGets fun s => s.cdt slot) fun slot_p => + holBind (holGets fun s => s.cdt) fun cdt => + holBind (holReturn (cdt slot)) fun parent => + holBind (CSpaceAcc_A.set_cdt (holFunUpd (fun p => holIf (holEq (cdt p) (some slot)) parent (cdt p)) slot none)) + (holKBind (holBind (Deterministic_A.do_extended_op (Deterministic_A.empty_slot_ext slot slot_p)) + (holKBind (holBind (CSpaceAcc_A.set_original slot false) + (holKBind (holBind (set_cap_p .NullCap slot) + (holKBind (IpcCancel_A.post_cap_deletion cleanup_info))))))))) + +theorem patched_setCap_equiv_null (slot : CslotPtr) : + MRel SR Eq (set_cap_p .NullCap slot) (Fl4Spec.setCap .nullCap slot) := + fun _ _ hs => patched_setCap_equiv_at .NullCap slot hs (Or.inr rfl) + +theorem patched_emptySlot_equiv (slot : CslotPtr) (cleanupInfo : Structures_A.cap) : + MRel SR Eq (empty_slot_p slot cleanupInfo) (Fl4Spec.emptySlot slot (embCap cleanupInfo)) := by + unfold empty_slot_p Fl4Spec.emptySlot + refine mrel_bind (patched_getCap_equiv slot) fun cH cL hc => ?_ + subst hc + refine mrel_if (by cases cH <;> simp [holEq, embCap]) (fun _ => mrel_return rfl) (fun _ => ?_) + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ hs => congrFun hs.cdt_eq.symm slot) fun spH spL hsp => ?_ + subst hsp + refine mrel_bind (mrel_gets fun _ _ hs => hs.cdt_eq.symm) fun cdtH cdtL hcdt => ?_ + subst hcdt + refine mrel_bind (mrel_return (aH := cdtH slot) rfl) fun pH pL hp => ?_ + subst hp + have hcdt' : Function.update (fun p => if cdtH p = some slot then pH else cdtH p) slot none = + holFunUpd (fun p => holIf (holEq (cdtH p) (some slot)) pH (cdtH p)) slot none := by + funext p + by_cases h1 : p = slot + · subst h1; simp [holFunUpd] + · simp [holFunUpd, h1, holIf_eq, holEq_eq_true] + refine mrel_kbind (by rw [hcdt']; exact setCdt_equiv _) ?_ + refine mrel_kbind (doExtendedOp_equiv (emptySlotExt_equiv slot spH)) ?_ + refine mrel_kbind (setOriginal_equiv slot false) ?_ + refine mrel_kbind (patched_setCap_equiv_null slot) ?_ + exact postCapDeletion_equiv cleanupInfo + +theorem fastFinalise_equiv (hop : OpaqueRel RestRel) (cap : Structures_A.cap) (final : Bool) : + MRel SR Eq + (CSpace_A.fast_finalise cap final) (Fl4Spec.fastFinalise (embCap cap) final) := by + cases cap with + | NullCap => exact mrel_return rfl + | ReplyCap r rs => + unfold CSpace_A.fast_finalise Fl4Spec.fastFinalise + refine mrel_when Iff.rfl fun _ => ?_ + refine mrel_bind (getReplyTcb_equiv r) fun tpH tpL htp => ?_ + subst htp + cases tpH with + | none => exact mrel_return rfl + | some tp => + refine mrel_bind (getThreadState_equiv tp) fun tsH tsL hts => ?_ + subst hts + cases tsH with + | BlockedOnReply r' => exact replyRemove_equiv hop tp r' + | _ => exact cancelIpc_equiv tp + | EndpointCap r b rs => + unfold CSpace_A.fast_finalise Fl4Spec.fastFinalise + exact mrel_when Iff.rfl fun _ => cancelAllIpc_equiv hop r + | NotificationCap r b rs => + unfold CSpace_A.fast_finalise Fl4Spec.fastFinalise + refine mrel_when Iff.rfl fun _ => ?_ + refine mrel_kbind (schedContextMaybeUnbindNtfn_equiv r) ?_ + refine mrel_kbind (unbindMaybeNotification_equiv r) ?_ + exact cancelAllSignals_equiv hop r + | _ => exact mrel_fail + +/-- l4v: CSpace_A.cap_delete_one with X64 capability-slot access. -/ +def cap_delete_one_p (slot : CslotPtr) : HolNonDet (Structures_A.state ZH) Unit := + holBind (get_cap_p slot) fun cap => + holUnless (holEq cap .NullCap) + (holBind (IpcCancel_A.is_final_cap cap) fun final => + holBind (CSpace_A.fast_finalise cap final) (holKBind (empty_slot_p slot .NullCap))) + +theorem patched_capDeleteOne_equiv (hop : OpaqueRel RestRel) (slot : CslotPtr) : + MRel SR Eq (cap_delete_one_p slot) (Fl4Spec.capDeleteOne slot) := by + unfold cap_delete_one_p Fl4Spec.capDeleteOne + refine mrel_bind (patched_getCap_equiv slot) fun cH cL hc => ?_ + subst hc + refine mrel_unless (by cases cH <;> simp [holEq_eq_true, embCap]) fun _ => ?_ + refine mrel_bind (isFinalCap_equiv cH) fun fH fL hf => ?_ + subst hf + refine mrel_kbind (fastFinalise_equiv hop cH fH) ?_ + exact patched_emptySlot_equiv slot .NullCap + +/-- l4v: CSpace_A.deleting_irq_handler with the related slot deletion. -/ +def deleting_irq_handler_p (irq : BitVec 8) : HolNonDet (Structures_A.state ZH) Unit := + holBind (KHeap_A.get_irq_slot irq) cap_delete_one_p + +theorem patched_deletingIrqHandler_equiv (hop : OpaqueRel RestRel) (irq : BitVec 8) : + MRel SR Eq (deleting_irq_handler_p irq) (Fl4Spec.deletingIrqHandler (embIrq irq)) := by + unfold deleting_irq_handler_p Fl4Spec.deletingIrqHandler + refine mrel_bind (getIrqSlot_equiv irq) fun slotH slotL hslot => ?_ + subst hslot + exact patched_capDeleteOne_equiv hop slotH + + + +/-- [P] Finalization that reaches an ASID or a native mapping admits the base address carrier. -/ +def ArchFinaliseSafe (a : Arch_Structs_A.arch_cap) (final : Bool) (s : Structures_A.state ZH) : Prop := + match a, final with + | .ASIDPoolCap ptr base, true => DeleteAsidPoolSafe base ptr s + | .PML4Cap ptr (some asid), true => DeleteAsidSafe asid ptr s + | .PDPointerTableCap _ (some (asid, _)), true + | .PageDirectoryCap _ (some (asid, _)), true + | .PageTableCap _ (some (asid, _)), true + | .PageCap _ _ _ _ _ (some (asid, _)), _ => BaseAsid asid + | _, _ => True + +private theorem archFinaliseReturn_equiv {mH : HolNonDet (Structures_A.state ZH) Unit} + {mL : SMonad ZL Unit} {sH : Structures_A.state ZH} {sL : State ZL} + (hm : MRelStep SR Eq (mH sH) (mL sL)) : + MRelStep SR (ProdRel (FunRel embCap) (FunRel embCap)) + (holBind mH (fun _ => holReturn (.NullCap, .NullCap)) sH) + ((do + mL + pure (Cap.nullCap, Cap.nullCap)) sL) := + mrelStep_bind_mem hm fun _ _ _ tH tL ht _ => mrel_return ⟨rfl, rfl⟩ tH tL ht + +private theorem nullFinalise_equiv : + MRel SR (ProdRel (FunRel embCap) (FunRel embCap)) (holReturn (.NullCap, .NullCap)) + (NonDet.pure (Cap.nullCap, Cap.nullCap)) := + mrel_return ⟨rfl, rfl⟩ + +private theorem ioportFinalise_equiv (first last : BitVec 16) : + MRel SR (ProdRel (FunRel embCap) (FunRel embCap)) + (holReturn (.NullCap, .ArchObjectCap (.IOPortCap first last))) + (NonDet.pure (Cap.nullCap, Cap.archObjectCap (.ioPortCap first last none))) := + mrel_return ⟨rfl, rfl⟩ + +theorem archFinaliseCap_equiv (hop : OpaqueRel RestRel) (a : Arch_Structs_A.arch_cap) (final : Bool) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (ha : ArchFinaliseSafe a final sH) : + MRelStep SR (ProdRel (FunRel embCap) (FunRel embCap)) + (ArchVSpace_A.arch_finalise_cap a final sH) (Fl4Spec.archFinaliseCap (embArchCap a) final sL) := by + cases a with + | ASIDPoolCap ptr base => + cases final + · exact nullFinalise_equiv sH sL hs + · exact archFinaliseReturn_equiv (deleteAsidPool_equiv hop base ptr hs hb ha) + | PML4Cap ptr mapping => + cases final + · cases mapping <;> exact nullFinalise_equiv sH sL hs + · cases mapping with + | none => exact nullFinalise_equiv sH sL hs + | some asid => exact archFinaliseReturn_equiv (deleteAsid_equiv hop asid ptr hs hb ha) + | PageCap dev ptr rights mt size mapping => + cases mapping with + | none => cases final <;> exact nullFinalise_equiv sH sL hs + | some pair => + obtain ⟨asid, addr⟩ := pair + cases final <;> exact archFinaliseReturn_equiv (unmapPage_equiv hop size asid addr ptr ha hs hb) + | PageTableCap ptr mapping => + cases final + · cases mapping <;> exact nullFinalise_equiv sH sL hs + · cases mapping with + | none => exact nullFinalise_equiv sH sL hs + | some pair => + obtain ⟨asid, addr⟩ := pair + exact archFinaliseReturn_equiv (unmapPageTable_equiv hop asid addr ptr ha hs hb) + | PageDirectoryCap ptr mapping => + cases final + · cases mapping <;> exact nullFinalise_equiv sH sL hs + · cases mapping with + | none => exact nullFinalise_equiv sH sL hs + | some pair => + obtain ⟨asid, addr⟩ := pair + exact archFinaliseReturn_equiv (unmapPd_equiv hop asid addr ptr ha hs hb) + | PDPointerTableCap ptr mapping => + cases final + · cases mapping <;> exact nullFinalise_equiv sH sL hs + · cases mapping with + | none => exact nullFinalise_equiv sH sL hs + | some pair => + obtain ⟨asid, addr⟩ := pair + exact archFinaliseReturn_equiv (unmapPdpt_equiv hop asid addr ptr ha hs hb) + | IOPortCap first last => + cases final + · exact nullFinalise_equiv sH sL hs + · exact ioportFinalise_equiv first last sH sL hs + | _ => cases final <;> exact nullFinalise_equiv sH sL hs + +/-- [P] The finalization of a base capability reaches only supported ASIDs or mappings. -/ +def FinaliseSafe (cap : Structures_A.cap) (final : Bool) (s : Structures_A.state ZH) : Prop := + match cap with + | .ArchObjectCap a => ArchFinaliseSafe a final s + | _ => True + +/-- l4v: CSpace_A.finalise_cap with guarded scheduler operations, IRQ slot access, and six TCB slots. -/ +def finalise_cap_p : Structures_A.cap → Bool → + HolNonDet (Structures_A.state ZH) (Structures_A.cap × Structures_A.cap) + | .ThreadCap r, final => + holBind (holWhen final (IpcCancel_A.unbind_notification r)) (holKBind + (holBind (holWhen final (unbind_from_sc_p r)) (holKBind + (holBind (holWhen final (SchedContext_A.suspend r)) (holKBind + (holBind (holWhen final (ArchVSpace_A.prepare_thread_delete r)) (holKBind + (holReturn (holIf final (.Zombie r none 6) .NullCap, .NullCap))))))))) + | .SchedContextCap sc _, final => + holBind (holWhen final (IpcCancel_A.sched_context_unbind_all_tcbs sc)) (holKBind + (holBind (holWhen final (IpcCancel_A.sched_context_unbind_ntfn sc)) (holKBind + (holBind (holWhen final (IpcCancel_A.sched_context_unbind_reply sc)) (holKBind + (holBind (holWhen final (sched_context_unbind_yield_from_p sc)) (holKBind + (holBind (holWhen final (SchedContext_A.sched_context_set_inactive sc)) (holKBind + (holReturn (.NullCap, .NullCap))))))))))) + | .IRQHandlerCap irq, final => + holIf final + (holBind (deleting_irq_handler_p irq) fun _ => holReturn (.NullCap, .IRQHandlerCap irq)) + (holReturn (.NullCap, .NullCap)) + | c, final => CSpace_A.finalise_cap c final + + +theorem patched_finaliseCap_equiv (hop : OpaqueRel RestRel) (cap : Structures_A.cap) (final : Bool) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) + (hf : FinaliseSafe cap final sH) : + MRelStep SR (ProdRel (FunRel embCap) (FunRel embCap)) + (finalise_cap_p cap final sH) (Fl4Spec.finaliseCap (embCap cap) final sL) := by + cases cap with + | ThreadCap r => + refine (show MRel SR (ProdRel (FunRel embCap) (FunRel embCap)) _ _ from ?_) sH sL hs + unfold finalise_cap_p Fl4Spec.finaliseCap + refine mrel_kbind (mrel_when Iff.rfl fun _ => unbindNotification_equiv r) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => patched_unbindFromSc_equiv hop r) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => suspend_equiv r) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => fpuRelease_equiv hop r) ?_ + exact mrel_return ⟨by cases final <;> rfl, rfl⟩ + | SchedContextCap sc bits => + refine (show MRel SR (ProdRel (FunRel embCap) (FunRel embCap)) _ _ from ?_) sH sL hs + unfold finalise_cap_p Fl4Spec.finaliseCap + refine mrel_kbind (mrel_when Iff.rfl fun _ => schedContextUnbindAllTcbs_equiv hop sc) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => schedContextUnbindNtfn_equiv sc) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => schedContextUnbindReply_equiv sc) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => patched_schedContextUnbindYieldFrom_equiv hop sc) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => schedContextSetInactive_equiv sc) ?_ + exact mrel_return ⟨rfl, rfl⟩ + | ReplyCap r rs => + refine (show MRel SR (ProdRel (FunRel embCap) (FunRel embCap)) _ _ from ?_) sH sL hs + unfold finalise_cap_p CSpace_A.finalise_cap Fl4Spec.finaliseCap + refine mrel_liftM (fun _ _ _ => ⟨rfl, rfl⟩) (mrel_when Iff.rfl fun _ => ?_) + refine mrel_bind (getReplyTcb_equiv r) fun tpH tpL htp => ?_ + subst htp + cases tpH with + | none => exact mrel_return rfl + | some tp => + refine mrel_bind (getThreadState_equiv tp) fun tsH tsL hts => ?_ + subst hts + cases tsH with + | BlockedOnReply r' => exact replyRemove_equiv hop tp r' + | _ => exact cancelIpc_equiv tp + | EndpointCap r b rs => + refine (show MRel SR (ProdRel (FunRel embCap) (FunRel embCap)) _ _ from ?_) sH sL hs + unfold finalise_cap_p CSpace_A.finalise_cap Fl4Spec.finaliseCap + exact mrel_liftM (fun _ _ _ => ⟨rfl, rfl⟩) (mrel_when Iff.rfl fun _ => cancelAllIpc_equiv hop r) + | NotificationCap r b rs => + refine (show MRel SR (ProdRel (FunRel embCap) (FunRel embCap)) _ _ from ?_) sH sL hs + unfold finalise_cap_p CSpace_A.finalise_cap Fl4Spec.finaliseCap + refine mrel_liftM (fun _ _ _ => ⟨rfl, rfl⟩) (mrel_when Iff.rfl fun _ => ?_) + refine mrel_kbind (schedContextMaybeUnbindNtfn_equiv r) ?_ + refine mrel_kbind (unbindMaybeNotification_equiv r) ?_ + exact cancelAllSignals_equiv hop r + | ArchObjectCap a => exact archFinaliseCap_equiv hop a final hs hb hf + | IRQHandlerCap irq => + cases final + · exact mrel_return (Ra := ProdRel (FunRel embCap) (FunRel embCap)) ⟨rfl, rfl⟩ sH sL hs + · simp only [finalise_cap_p, holIf_true, Fl4Spec.finaliseCap, embCap, ↓reduceIte] + refine mrelStep_bind_mem (patched_deletingIrqHandler_equiv hop irq sH sL hs) + fun _ _ _ tH tL ht _ => ?_ + exact mrel_return ⟨rfl, rfl⟩ tH tL ht + | Zombie ptr bits count => + exact mrel_kbind (mrel_assert Iff.rfl) (mrel_return ⟨rfl, rfl⟩) sH sL hs + | _ => cases final <;> exact mrel_return (Ra := ProdRel (FunRel embCap) (FunRel embCap)) ⟨rfl, rfl⟩ sH sL hs + +def cap_swap_for_delete_p (slot1 slot2 : CslotPtr) : HolNonDet (Structures_A.state ZH) Unit := + holWhen (holNot (holEq slot1 slot2)) + (holBind (get_cap_p slot1) fun cap1 => + holBind (get_cap_p slot2) fun cap2 => cap_swap_p cap1 slot1 cap2 slot2) + +/-- [P] Both reached writes of a deletion swap have admissible slots. -/ +def CapSwapForDeleteSafe (slot1 slot2 : CslotPtr) (s : Structures_A.state ZH) : Prop := + slot1 ≠ slot2 → + ∀ c1 t, (c1, t) ∈ (get_cap_p slot1 s).1 → + ∀ c2 u, (c2, u) ∈ (get_cap_p slot2 t).1 → + SetCapSafe c2 slot1 u ∧ + ∀ v, ((), v) ∈ (set_cap_p c2 slot1 u).1 → SetCapSafe c1 slot2 v + +theorem patched_capSwapForDelete_equiv (slot1 slot2 : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hw : CapSwapForDeleteSafe slot1 slot2 sH) : + MRelStep SR Eq (cap_swap_for_delete_p slot1 slot2 sH) (Fl4Spec.capSwapForDelete slot1 slot2 sL) := by + unfold cap_swap_for_delete_p Fl4Spec.capSwapForDelete + by_cases hslots : slot1 = slot2 + · subst slot2 + simp only [holNot, holEq, decide_true, Bool.not_true, holWhen, Bool.false_eq_true, ↓reduceIte, NonDet.when] + rw [ite_eq_right (not_not_intro rfl)] + exact mrel_return rfl sH sL hs + · have hh : holNot (holEq slot1 slot2) = true := by simp [holNot_eq_true, holEq_eq_true, hslots] + simp only [hh, holWhen, ↓reduceIte, NonDet.when] + rw [ite_eq_left hslots] + refine mrelStep_bind_mem (patched_getCap_equiv slot1 sH sL hs) fun c1H c1L hc1 tH tL ht hread1 => ?_ + subst hc1 + refine mrelStep_bind_mem (patched_getCap_equiv slot2 tH tL ht) fun c2H c2L hc2 uH uL hu hread2 => ?_ + subst hc2 + obtain ⟨hfirst, hsecond⟩ := hw hslots c1H tH hread1 c2H uH hread2 + exact patched_capSwap_equiv c1H slot1 c2H slot2 hu hfirst hsecond + +private theorem withoutPreemption_step_equiv {αH αL : Type} [Nonempty αH] + {Ra : αH → αL → Prop} + {mH : HolNonDet (Structures_A.state ZH) αH} {mL : SMonad ZL αL} + {sH : Structures_A.state ZH} {sL : State ZL} (hm : MRelStep SR Ra (mH sH) (mL sL)) : + MRelStep SR (SumExceptRel Eq Ra) + (Exceptions_A.without_preemption mH sH) ((Fl4Spec.withoutPreemption mL).run sL) := + mrelStep_liftE hm + +private theorem natToCref_eq (len n : Nat) : + Machine_A.nat_to_cref len n = Fl4Spec.natToCref len n := rfl + +private theorem isZombie_eq (c : Structures_A.cap) : Fl4Spec.isZombie (embCap c) = Structures_A.is_zombie c := by + cases c <;> rfl + +private theorem finaliseCap_p_rem_null_or_zombie (cap : Structures_A.cap) (final : Bool) + {sH sH' : Structures_A.state ZH} {rem info : Structures_A.cap} + (hm : ((rem, info), sH') ∈ (finalise_cap_p cap final sH).1) : + rem = .NullCap ∨ ∃ p b n, rem = .Zombie p b n := by + cases cap with + | NullCap => simp [finalise_cap_p, CSpace_A.finalise_cap, holReturn] at hm; exact Or.inl hm.1.1 + | UntypedCap _ _ _ _ => simp [finalise_cap_p, CSpace_A.finalise_cap, holReturn] at hm; exact Or.inl hm.1.1 + | ReplyCap _ _ => + unfold finalise_cap_p CSpace_A.finalise_cap at hm + simp only [holFunApp, holLiftM, holK, holBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨_, _, hm'⟩; cases hm'; exact Or.inl rfl + | EndpointCap _ _ _ => + unfold finalise_cap_p CSpace_A.finalise_cap at hm + simp only [holFunApp, holLiftM, holK, holBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨_, _, hm'⟩; cases hm'; exact Or.inl rfl + | NotificationCap _ _ _ => + unfold finalise_cap_p CSpace_A.finalise_cap at hm + simp only [holFunApp, holLiftM, holK, holBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨_, _, hm'⟩; cases hm'; exact Or.inl rfl + | CNodeCap r bits g => + simp [finalise_cap_p, CSpace_A.finalise_cap, holReturn] at hm + cases final <;> simp [hm.1.1] + | ThreadCap r => + unfold finalise_cap_p at hm + simp only [holBind, holKBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨_, _, _, _, _, _, _, _, hm'⟩; cases hm' + cases final <;> simp + | DomainCap => simp [finalise_cap_p, CSpace_A.finalise_cap, holReturn] at hm; exact Or.inl hm.1.1 + | SchedContextCap sc _ => + unfold finalise_cap_p at hm + simp only [holBind, holKBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨_, _, _, _, _, _, _, _, _, _, hm'⟩; cases hm'; exact Or.inl rfl + | SchedControlCap => simp [finalise_cap_p, CSpace_A.finalise_cap, holReturn] at hm; exact Or.inl hm.1.1 + | Zombie r b n => + unfold finalise_cap_p CSpace_A.finalise_cap at hm + simp only [holBind, holKBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨_, _, hm'⟩; cases hm'; exact Or.inr ⟨r, b, n, rfl⟩ + | IRQControlCap => simp [finalise_cap_p, CSpace_A.finalise_cap, holReturn] at hm; exact Or.inl hm.1.1 + | IRQHandlerCap irq => + unfold finalise_cap_p CSpace_A.finalise_cap at hm + cases final with + | true => + simp only [holIf_true, holBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨_, _, hm'⟩; cases hm'; exact Or.inl rfl + | false => + simp [holIf_false, holReturn] at hm; exact Or.inl hm.1.1 + | ArchObjectCap ac => + unfold finalise_cap_p CSpace_A.finalise_cap ArchVSpace_A.arch_finalise_cap at hm + cases ac <;> cases final + all_goals try (rename_i mapping; cases mapping) + all_goals + try simp only [holCaseProd_eq, Arch_Structs_A.case_arch_cap, holCaseOption_none, holCaseOption_some] at hm + try rename_i pair + first + | exact Or.inl (Prod.mk.inj (Prod.mk.inj (Set.mem_singleton_iff.mp hm)).1).1 + | rcases hm with ⟨_, _, hret⟩ + cases hret + exact Or.inl rfl + +/-- General Knaster–Tarski fixed-point equation for `Fl4Spec.NonDet.lfp`. -/ +theorem nonDet_lfp_unfold {ι σ α : Type} + (F : (ι → NonDet σ α) → ι → NonDet σ α) + (hmono : ∀ f g, (∀ i s, f i s ≤ g i s) → ∀ i s, F f i s ≤ F g i s) + (i : ι) (s : σ) : + NonDet.lfp F i s = F (NonDet.lfp F) i s := by + let S : Set (ι → σ → Set (α × σ) × Prop) := {f | ∀ j t, F f j t ≤ f j t} + have hlfp_le : ∀ f ∈ S, ∀ j t, NonDet.lfp F j t ≤ f j t := by + intro f hf j t + exact (sInf_le (s := S) hf) j t + have hFlfp_le : ∀ j t, F (NonDet.lfp F) j t ≤ NonDet.lfp F j t := by + intro j t + exact (le_sInf (s := S) (fun f hf j' t' => + le_trans (hmono (NonDet.lfp F) f (hlfp_le f hf) j' t') (hf j' t'))) j t + have hFlfp_mem : F (NonDet.lfp F) ∈ S := fun j t => hmono _ _ hFlfp_le j t + exact le_antisymm (hlfp_le _ hFlfp_mem i s) (hFlfp_le i s) + +private theorem nonDet_bind_mono {σ α β : Type} + {m₁ m₂ : NonDet σ α} {f₁ f₂ : α → NonDet σ β} + (hm : ∀ s, m₁ s ≤ m₂ s) (hf : ∀ a s, f₁ a s ≤ f₂ a s) (s : σ) : + NonDet.bind m₁ f₁ s ≤ NonDet.bind m₂ f₂ s := by + constructor + · rintro p ⟨x, hx, hp⟩ + exact ⟨x, (hm s).1 hx, (hf x.1 x.2).1 hp⟩ + · rintro (h | ⟨x, hx, hf'⟩) + · exact Or.inl ((hm s).2 h) + · exact Or.inr ⟨x, (hm s).1 hx, (hf x.1 x.2).2 hf'⟩ + +private theorem nonDetE_bind_mono {σ ε α β : Type} + {m₁ m₂ : NonDetE σ ε α} {f₁ f₂ : α → NonDetE σ ε β} + (hm : ∀ s, m₁ s ≤ m₂ s) (hf : ∀ a s, f₁ a s ≤ f₂ a s) (s : σ) : + (m₁ >>= f₁) s ≤ (m₂ >>= f₂) s := by + refine nonDet_bind_mono hm (fun r s' => ?_) s + cases r with + | error e => exact le_refl _ + | ok a => exact hf a s' + +theorem recDelF_mono : + ∀ (f g : RecDelCall → PMonad ZL (Bool × Cap)), + (∀ c s, f c s ≤ g c s) → ∀ c s, Fl4Spec.recDelF f c s ≤ Fl4Spec.recDelF g c s := by + intro f g hfg c s + cases c with + | cTEDeleteCall slot exposed => + unfold Fl4Spec.recDelF + exact nonDetE_bind_mono (hfg _) (fun _ _ => le_refl _) s + | finaliseSlotCall slot exposed => + unfold Fl4Spec.recDelF + refine nonDetE_bind_mono (fun _ => le_refl _) (fun cap s1 => ?_) s + by_cases hnull : cap = .nullCap + · simp only [hnull, ↓reduceIte]; exact le_refl _ + · simp only [hnull, ↓reduceIte] + refine nonDetE_bind_mono (fun _ => le_refl _) (fun isFinal s2 => ?_) s1 + refine nonDetE_bind_mono (fun _ => le_refl _) (fun p s3 => ?_) s2 + rcases p with ⟨rem, info⟩ + by_cases hrem : Fl4Spec.capRemoveable rem slot + · simp only [hrem, ↓reduceIte]; exact le_refl _ + · simp only [hrem, ↓reduceIte] + by_cases hcyc : Fl4Spec.capCyclicZombie rem slot ∧ ¬exposed = true + · simp only [hcyc]; exact le_refl _ + · simp only [hcyc, ↓reduceIte] + refine nonDetE_bind_mono (fun _ => le_refl _) (fun _ s4 => ?_) s3 + refine nonDetE_bind_mono (hfg _) (fun _ s5 => ?_) s4 + exact nonDetE_bind_mono (fun _ => le_refl _) (fun _ s6 => hfg _ s6) s5 + | reduceZombieCall cap slot exposed => + cases cap with + | zombie ptr bits n => + cases n with + | zero => exact le_refl _ + | succ k => + cases exposed with + | false => exact le_refl _ + | true => + unfold Fl4Spec.recDelF + refine nonDetE_bind_mono (fun _ => le_refl _) (fun endSlot s1 => ?_) s + exact nonDetE_bind_mono (hfg _) (fun _ _ => le_refl _) s1 + | _ => exact le_refl _ + +theorem recDel_unfold (c : RecDelCall) (s : State ZL) : + Fl4Spec.recDel c s = Fl4Spec.recDelF Fl4Spec.recDel c s := + nonDet_lfp_unfold (fun r c => Fl4Spec.recDelF r c) recDelF_mono c s + +theorem capRevokeF_mono : + ∀ (f g : CslotPtr → PMonad ZL Unit), + (∀ slot s, f slot s ≤ g slot s) → ∀ slot s, Fl4Spec.capRevokeF f slot s ≤ Fl4Spec.capRevokeF g slot s := by + intro f g hfg slot s + unfold Fl4Spec.capRevokeF + refine nonDetE_bind_mono (fun _ => le_refl _) (fun cap s1 => ?_) s + refine nonDetE_bind_mono (fun _ => le_refl _) (fun cdt s2 => ?_) s1 + refine nonDetE_bind_mono (fun _ => le_refl _) (fun desc s3 => ?_) s2 + unfold NonDetE.whenE + split_ifs + · refine nonDetE_bind_mono (fun _ => le_refl _) (fun child s4 => ?_) s3 + refine nonDetE_bind_mono (fun _ => le_refl _) (fun cap1 s5 => ?_) s4 + refine nonDetE_bind_mono (fun _ => le_refl _) (fun _ s6 => ?_) s5 + refine nonDetE_bind_mono (fun _ => le_refl _) (fun _ s7 => ?_) s6 + exact nonDetE_bind_mono (fun _ => le_refl _) (fun _ s8 => hfg slot s8) s7 + · exact le_refl _ + +theorem capRevoke_unfold (slot : CslotPtr) (s : State ZL) : + Fl4Spec.capRevoke slot s = Fl4Spec.capRevokeF Fl4Spec.capRevoke slot s := + nonDet_lfp_unfold (fun r c => Fl4Spec.capRevokeF r c) capRevokeF_mono slot s + +/-- Call-indexed return relation for `recDel`: exact on `FinaliseSlotCall` (where the returned +`(success, cleanupInfo)` is used), and `True` on `CTEDeleteCall`/`ReduceZombieCall` (where both +specs return their type-specific `undefined : Bool × Cap` and every caller discards it). -/ +def RecDelRetRel : CSpace_A.rec_del_call → (Bool × Structures_A.cap) → (Bool × Cap) → Prop + | .FinaliseSlotCall _ _, rH, rL => rL = (rH.1, embCap rH.2) + | .CTEDeleteCall _ _, _, _ => True + | .ReduceZombieCall _ _ _, _, _ => True + +/-- Single-step functional of patched `rec_del` (using `get_cap_p`, `set_cap_p`, `empty_slot_p`, +`finalise_cap_p`, `cap_swap_for_delete_p`), mirroring `CSpace_A.rec_del_graph` verbatim. -/ +def rec_del_step_p + (r : CSpace_A.rec_del_call × Structures_A.state ZH → + Set (Sum Unit (Bool × Structures_A.cap) × Structures_A.state ZH) × Bool) : + CSpace_A.rec_del_call → HolNonDet (Structures_A.state ZH) (Sum Unit (Bool × Structures_A.cap)) + | .CTEDeleteCall slot exposed => + holBindE (fun s => r (.FinaliseSlotCall slot exposed, s)) fun (success, cleanup_info) => + holBindE (Exceptions_A.without_preemption (holWhen (holDisj exposed success) (empty_slot_p slot cleanup_info))) + (holKBind (holReturnOk holUndefined)) + | .FinaliseSlotCall slot exposed => + holBindE (Exceptions_A.without_preemption (get_cap_p slot)) fun cap => + holIf (holEq cap .NullCap) + (holReturnOk (true, .NullCap)) + (holBindE (Exceptions_A.without_preemption (IpcCancel_A.is_final_cap cap)) fun is_final => + holBindE (Exceptions_A.without_preemption (finalise_cap_p cap is_final)) fun (rem, info) => + holIf (CSpace_A.cap_removeable rem slot) + (holReturnOk (true, info)) + (holIf (holConj (CSpace_A.cap_cyclic_zombie rem slot) (holNot exposed)) + (holBindE (Exceptions_A.without_preemption (set_cap_p rem slot)) + (holKBind (holReturnOk (false, .NullCap)))) + (holBindE (Exceptions_A.without_preemption (set_cap_p rem slot)) + (holKBind (holBindE (fun s => r (.ReduceZombieCall rem slot exposed, s)) + (holKBind (holBindE KHeap_A.preemption_point + (holKBind (fun s => r (.FinaliseSlotCall slot exposed, s)))))))))) + | .ReduceZombieCall (.Zombie ptr bits (n + 1)) slot false => + holBindE (holReturnOk (Structures_A.first_cslot_of (.Zombie ptr bits (n + 1)))) fun cn => + holBindE (holAssertE (holNot (holEq cn slot))) + (holKBind (holBindE (Exceptions_A.without_preemption (cap_swap_for_delete_p cn slot)) + (holKBind (holReturnOk holUndefined)))) + | .ReduceZombieCall (.Zombie ptr bits (n + 1)) slot true => + holBindE (holReturnOk (ptr, Machine_A.nat_to_cref (Structures_A.zombie_cte_bits bits) n)) fun end_slot => + holBindE (fun s => r (.CTEDeleteCall end_slot false, s)) + (holKBind (holBindE (Exceptions_A.without_preemption (get_cap_p slot)) fun new_cap => + holBindE (holIf (holEq new_cap (.Zombie ptr bits (n + 1))) + (Exceptions_A.without_preemption (set_cap_p (.Zombie ptr bits n) slot)) + (holAssertE (holDisj (holEq new_cap .NullCap) + (holConj (Structures_A.is_zombie new_cap) + (holConj (holEq (Structures_A.first_cslot_of new_cap) slot) + (holNot (holEq (Structures_A.first_cslot_of (.Zombie ptr bits (n + 1))) slot))))))) + (holKBind (holReturnOk holUndefined)))) + | .ReduceZombieCall _ _ _ => holFail + +/-- [P] The recursive deletion graph admits finalization and slot updates at their reached states. -/ +inductive RecDelPGraph : + (CSpace_A.rec_del_call × Structures_A.state ZH) → + (Set (Sum Unit (Bool × Structures_A.cap) × Structures_A.state ZH) × Bool) → Prop + | cteDelete {r slot exposed s} : + RecDelPGraph (.FinaliseSlotCall slot exposed, s) (r (.FinaliseSlotCall slot exposed, s)) → + RecDelPGraph (.CTEDeleteCall slot exposed, s) (rec_del_step_p r (.CTEDeleteCall slot exposed) s) + | finaliseSlot {r slot exposed s} : + (∀ cap st is_final sta, + (Sum.inr cap, st) ∈ (Exceptions_A.without_preemption (get_cap_p slot) s).1 → + cap ≠ .NullCap → + (Sum.inr is_final, sta) ∈ (Exceptions_A.without_preemption (IpcCancel_A.is_final_cap cap) st).1 → + ReferenceBaseCarriers sta ∧ FinaliseSafe cap is_final sta) → + (∀ cap st is_final sta rem info stb, + (Sum.inr cap, st) ∈ (Exceptions_A.without_preemption (get_cap_p slot) s).1 → + cap ≠ .NullCap → + (Sum.inr is_final, sta) ∈ (Exceptions_A.without_preemption (IpcCancel_A.is_final_cap cap) st).1 → + (Sum.inr (rem, info), stb) ∈ (Exceptions_A.without_preemption (finalise_cap_p cap is_final) sta).1 → + CSpace_A.cap_removeable rem slot = false → + NonExtCapSlot slot stb) → + (∀ cap st is_final sta rem info stb u stc, + (Sum.inr cap, st) ∈ (Exceptions_A.without_preemption (get_cap_p slot) s).1 → + cap ≠ .NullCap → + (Sum.inr is_final, sta) ∈ (Exceptions_A.without_preemption (IpcCancel_A.is_final_cap cap) st).1 → + (Sum.inr (rem, info), stb) ∈ (Exceptions_A.without_preemption (finalise_cap_p cap is_final) sta).1 → + CSpace_A.cap_removeable rem slot = false → + ¬(CSpace_A.cap_cyclic_zombie rem slot = true ∧ exposed = false) → + (Sum.inr u, stc) ∈ (Exceptions_A.without_preemption (set_cap_p rem slot) stb).1 → + RecDelPGraph (.ReduceZombieCall rem slot exposed, stc) (r (.ReduceZombieCall rem slot exposed, stc))) → + (∀ cap st is_final sta rem info stb u stc rvd std rve ste, + (Sum.inr cap, st) ∈ (Exceptions_A.without_preemption (get_cap_p slot) s).1 → + cap ≠ .NullCap → + (Sum.inr is_final, sta) ∈ (Exceptions_A.without_preemption (IpcCancel_A.is_final_cap cap) st).1 → + (Sum.inr (rem, info), stb) ∈ (Exceptions_A.without_preemption (finalise_cap_p cap is_final) sta).1 → + CSpace_A.cap_removeable rem slot = false → + ¬(CSpace_A.cap_cyclic_zombie rem slot = true ∧ exposed = false) → + (Sum.inr u, stc) ∈ (Exceptions_A.without_preemption (set_cap_p rem slot) stb).1 → + (Sum.inr rvd, std) ∈ (r (.ReduceZombieCall rem slot exposed, stc)).1 → + (Sum.inr rve, ste) ∈ (KHeap_A.preemption_point std).1 → + RecDelPGraph (.FinaliseSlotCall slot exposed, ste) (r (.FinaliseSlotCall slot exposed, ste))) → + RecDelPGraph (.FinaliseSlotCall slot exposed, s) (rec_del_step_p r (.FinaliseSlotCall slot exposed) s) + | reduceZombieFalse {r ptr bits n slot s} : + CapSwapForDeleteSafe (Structures_A.first_cslot_of (.Zombie ptr bits (n + 1))) slot s → + RecDelPGraph (.ReduceZombieCall (.Zombie ptr bits (n + 1)) slot false, s) + (rec_del_step_p r (.ReduceZombieCall (.Zombie ptr bits (n + 1)) slot false) s) + | reduceZombieTrue {r ptr bits n slot s} : + RecDelPGraph (.CTEDeleteCall (ptr, Machine_A.nat_to_cref (Structures_A.zombie_cte_bits bits) n) false, s) + (r (.CTEDeleteCall (ptr, Machine_A.nat_to_cref (Structures_A.zombie_cte_bits bits) n) false, s)) → + (∀ res t, (Sum.inr res, t) ∈ (r (.CTEDeleteCall + (ptr, Machine_A.nat_to_cref (Structures_A.zombie_cte_bits bits) n) false, s)).1 → + ∀ u, (Sum.inr (.Zombie ptr bits (n + 1)), u) ∈ + (Exceptions_A.without_preemption (get_cap_p slot) t).1 → + SetCapSafe (.Zombie ptr bits n) slot u) → + RecDelPGraph (.ReduceZombieCall (.Zombie ptr bits (n + 1)) slot true, s) + (rec_del_step_p r (.ReduceZombieCall (.Zombie ptr bits (n + 1)) slot true) s) + | reduceZombieFail {cap slot exposed s} : + (∀ ptr bits n, cap ≠ .Zombie ptr bits (n + 1)) → + RecDelPGraph (.ReduceZombieCall cap slot exposed, s) (holFail s) + +def rec_del_p (c : CSpace_A.rec_del_call) (s : Structures_A.state ZH) : + Set (Sum Unit (Bool × Structures_A.cap) × Structures_A.state ZH) × Bool := + holTheDefault holUndefined (fun y => decide (RecDelPGraph (c, s) y)) + +def cap_delete_p (slot : CslotPtr) : HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holBindE (rec_del_p (.CTEDeleteCall slot true)) (holKBind (holReturnOk ())) + +def finalise_slot_p (p : CslotPtr) (e : Bool) : + HolNonDet (Structures_A.state ZH) (Sum Unit (Bool × Structures_A.cap)) := + rec_del_p (.FinaliseSlotCall p e) + +/-- Helper: `first_cslot_of` equivalence. -/ +theorem firstCslotOf_eq (c : Structures_A.cap) + (hz : ∃ p b n, c = .Zombie p b n) : + Fl4Spec.firstCslotOf (embCap c) = Structures_A.first_cslot_of c := by + rcases hz with ⟨p, b, n, rfl⟩ + simp [Fl4Spec.firstCslotOf, Structures_A.first_cslot_of, embCap, + holListReplicate, zombieCteBits_eq] + +/-- Main graph-to-`NonDet.lfp` induction theorem for `RecDelPGraph`: +every `(call, sH, y)` in `RecDelPGraph` is bisimilar to `Fl4Spec.recDel (embRecDelCall call) sL`. -/ +theorem recDelPGraph_mrelStep (hop : OpaqueRel RestRel) (hc : ConfigRel) + {x : CSpace_A.rec_del_call × Structures_A.state ZH} + {y : Set (Sum Unit (Bool × Structures_A.cap) × Structures_A.state ZH) × Bool} + (hg : RecDelPGraph x y) : + ∀ sL, SR x.2 sL → + MRelStep SR (SumExceptRel Eq (RecDelRetRel x.1)) y + (Fl4Spec.recDel (embRecDelCall x.1) sL) := by + induction hg with + | @cteDelete r slot exposed s hsub ih => + intro sL hs + rw [recDel_unfold] + unfold rec_del_step_p Fl4Spec.recDelF embRecDelCall + refine mrelStep_bindE_mem (ih sL hs) fun pH pL hp s1H s1L hs1 _ => ?_ + rcases pH with ⟨sucH, ciH⟩ + simp only [RecDelRetRel] at hp + subst hp + refine mrelStep_bindE_mem + (withoutPreemption_equiv (mrel_when (by simp [holDisj_eq_true]) fun _ => + patched_emptySlot_equiv slot ciH) s1H s1L hs1) + fun _ _ _ s2H s2L hs2 _ => ?_ + exact mrele_returnOk (Ra := RecDelRetRel (.CTEDeleteCall slot exposed)) trivial s2H s2L hs2 + | @finaliseSlot r slot exposed s hfinalise hneSlot hred hfin ihred ihfin => + intro sL hs + rw [recDel_unfold] + unfold rec_del_step_p Fl4Spec.recDelF embRecDelCall + refine mrelStep_bindE_mem (withoutPreemption_equiv (patched_getCap_equiv slot) s sL hs) + fun capH capL hcap s1H s1L hs1 hm1 => ?_ + subst hcap + by_cases hnull : capH = .NullCap + · subst hnull + simp only [holEq, ↓reduceIte, embCap] + exact mrele_returnOk (Ra := RecDelRetRel (.FinaliseSlotCall slot exposed)) rfl s1H s1L hs1 + · have hneH : holEq capH .NullCap = false := by + cases h : holEq capH .NullCap + · rfl + · rw [holEq_eq_true] at h; exact absurd h hnull + have hneL : embCap capH ≠ .nullCap := by cases capH <;> simp [embCap] at hnull ⊢ + simp only [hneH, holIf_false, hneL, ↓reduceIte] + refine mrelStep_bindE_mem (withoutPreemption_equiv (isFinalCap_equiv capH) s1H s1L hs1) + fun finH finL hfin s2H s2L hs2 hm2 => ?_ + subst hfin + obtain ⟨hb, hf⟩ := hfinalise capH s1H finH s2H hm1 hnull hm2 + refine mrelStep_bindE_mem (withoutPreemption_step_equiv + (patched_finaliseCap_equiv hop capH finH hs2 (hs2.baseCarriers_iff.mpr hb) hf)) + fun pH pL hp s3H s3L hs3 hm3 => ?_ + rcases pH with ⟨remH, infoH⟩ + rcases pL with ⟨remL, infoL⟩ + rcases hp with ⟨hrem_eq, hinfo_eq⟩ + subst hrem_eq; subst hinfo_eq + have hremNZ : remH = .NullCap ∨ ∃ p b n, remH = .Zombie p b n := by + unfold Exceptions_A.without_preemption holLiftE holLiftM at hm3 + simp only [holBind, holReturn, Set.mem_singleton_iff] at hm3 + rcases hm3 with ⟨⟨⟨r', i'⟩, s'⟩, hf, hm_eq⟩ + cases hm_eq + exact finaliseCap_p_rem_null_or_zombie capH finH hf + have hremIff := capRemoveable_iff_nullOrZombie remH slot hremNZ + by_cases hrem : CSpace_A.cap_removeable remH slot = true + · simp only [hrem, holIf_true, hremIff.mp hrem, ↓reduceIte] + exact mrele_returnOk (Ra := RecDelRetRel (.FinaliseSlotCall slot exposed)) rfl s3H s3L hs3 + · have hremF : CSpace_A.cap_removeable remH slot = false := Bool.eq_false_iff.mpr hrem + have hremLF : ¬Fl4Spec.capRemoveable (embCap remH) slot := mt hremIff.mpr hrem + have hslot3 : NonExtCapSlot slot s3H := hneSlot capH s1H finH s2H remH infoH s3H hm1 hnull hm2 hm3 hremF + simp only [hremF, holIf_false, hremLF, ↓reduceIte] + have hcycIff : holConj (CSpace_A.cap_cyclic_zombie remH slot) (holNot exposed) = true ↔ + Fl4Spec.capCyclicZombie (embCap remH) slot ∧ ¬exposed = true := by + simp [holConj_eq_true, holNot_eq_true, capCyclicZombie_iff] + by_cases hcyc : holConj (CSpace_A.cap_cyclic_zombie remH slot) (holNot exposed) = true + · rw [hcyc, holIf_true, ite_eq_left (hcycIff.mp hcyc)] + refine mrelStep_bindE_mem (withoutPreemption_step_equiv (patched_setCap_equiv_at remH slot hs3 (Or.inl hslot3))) + fun _ _ _ s4H s4L hs4 _ => ?_ + exact mrele_returnOk (Ra := RecDelRetRel (.FinaliseSlotCall slot exposed)) rfl s4H s4L hs4 + · have hcycF : holConj (CSpace_A.cap_cyclic_zombie remH slot) (holNot exposed) = false := + Bool.eq_false_iff.mpr hcyc + have hcycLF : ¬(Fl4Spec.capCyclicZombie (embCap remH) slot ∧ ¬exposed = true) := + mt hcycIff.mpr hcyc + have hcycNeg : ¬(CSpace_A.cap_cyclic_zombie remH slot = true ∧ exposed = false) := by + rintro ⟨hc1, hc2⟩ + apply hcyc + simp [holConj_eq_true, holNot_eq_true, hc1, hc2] + rw [hcycF, holIf_false, ite_eq_right hcycLF] + refine mrelStep_bindE_mem (withoutPreemption_step_equiv (patched_setCap_equiv_at remH slot hs3 (Or.inl hslot3))) + fun uH uL _ s4H s4L hs4 hm4 => ?_ + refine mrelStep_bindE_mem + (ihred capH s1H finH s2H remH infoH s3H uH s4H hm1 hnull hm2 hm3 hremF hcycNeg hm4 s4L hs4) + fun rvdH rvdL _ s5H s5L hs5 hm5 => ?_ + refine mrelStep_bindE_mem (preemptionPoint_equiv hc hop s5H s5L hs5) + fun rveH rveL _ s6H s6L hs6 hm6 => ?_ + exact ihfin capH s1H finH s2H remH infoH s3H uH s4H rvdH s5H rveH s6H + hm1 hnull hm2 hm3 hremF hcycNeg hm4 hm5 hm6 s6L hs6 + | @reduceZombieFalse r ptr bits n slot s hslot => + intro sL hs + rw [recDel_unfold] + unfold rec_del_step_p Fl4Spec.recDelF embRecDelCall + simp only [embCap] + refine mrelStep_bindE_mem (mrele_returnOk (Ra := Eq) + (firstCslotOf_eq (.Zombie ptr bits (n + 1)) ⟨ptr, bits, n + 1, rfl⟩).symm s sL hs) + fun cnH cnL hcn s1H s1L hs1 hm1 => ?_ + subst hcn + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hm1 + obtain ⟨hcn_eq, hs1eq⟩ := hm1 + rw [hs1eq] at hs1 ⊢ + refine mrelStep_bindE_mem (mrele_assertE (by simp [holNot_eq_true, holEq_eq_true]) s s1L hs1) + fun _ _ _ s2H s2L hs2 hm2 => ?_ + have hs2eq : s2H = s := by + unfold holAssertE holLiftE holLiftM at hm2 + simp [holBind, holAssert, holReturn] at hm2 + exact hm2.2 + rw [hs2eq] at hs2 ⊢ + refine mrelStep_bindE_mem (withoutPreemption_step_equiv + (patched_capSwapForDelete_equiv cnH slot hs2 (hcn_eq ▸ hslot))) + fun _ _ _ s3H s3L hs3 _ => ?_ + exact mrele_returnOk (Ra := RecDelRetRel (.ReduceZombieCall (.Zombie ptr bits (n + 1)) slot false)) + trivial s3H s3L hs3 + | @reduceZombieTrue r ptr bits n slot s hsub hwrite ih => + intro sL hs + rw [recDel_unfold] + unfold rec_del_step_p Fl4Spec.recDelF embRecDelCall + simp only [embCap] + refine mrelStep_bindE_mem (mrele_returnOk (Ra := Eq) (by + rw [zombieCteBits_eq, natToCref_eq]) s sL hs) + fun esH esL hes s1H s1L hs1 hm1 => ?_ + subst hes + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hm1 + obtain ⟨hes_eq, hs1_eq⟩ := hm1 + subst hes_eq + rw [hs1_eq] at hs1 ⊢ + refine mrelStep_bindE_mem (ih s1L hs1) fun res _ _ s2H s2L hs2 hres => ?_ + refine mrelStep_bindE_mem (withoutPreemption_equiv (patched_getCap_equiv slot) s2H s2L hs2) + fun ncH ncL hnc s3H s3L hs3 hm3 => ?_ + subst hnc + by_cases hzeq : ncH = .Zombie ptr bits (n + 1) + · subst hzeq + have hslot3 := hwrite res s2H hres s3H hm3 + simp only [holEq, ↓reduceIte, embCap] + refine mrelStep_bindE_mem + (withoutPreemption_step_equiv (patched_setCap_equiv_at (.Zombie ptr bits n) slot hs3 hslot3)) + (fun _ _ _ s4H s4L hs4 _ => + mrele_returnOk (Ra := RecDelRetRel (.ReduceZombieCall (.Zombie ptr bits (n + 1)) slot true)) + trivial s4H s4L hs4) + · have hzeqH : holEq ncH (.Zombie ptr bits (n + 1)) = false := by + cases h : holEq ncH (.Zombie ptr bits (n + 1)) + · rfl + · rw [holEq_eq_true] at h; exact absurd h hzeq + have hzeqL : embCap ncH ≠ .zombie ptr bits (n + 1) := by + intro h; apply hzeq; exact embCap_injective h + simp only [hzeqH, holIf_false, hzeqL, ↓reduceIte] + refine mrelStep_bindE_mem (mrele_assertE (by + simp only [holDisj_eq_true, holConj_eq_true, holEq_eq_true, holNot_eq_true, ne_eq, isZombie_eq] + refine or_congr (by cases ncH <;> simp [embCap]) (and_congr_right fun hz => ?_) + cases ncH with + | Zombie p' b' n' => + have h1 := firstCslotOf_eq (.Zombie p' b' n') ⟨p', b', n', rfl⟩ + have h2 := firstCslotOf_eq (.Zombie ptr bits (n + 1)) ⟨ptr, bits, n + 1, rfl⟩ + simp only [embCap] at h1 h2 ⊢ + rw [h1, h2] + | _ => simp [Structures_A.is_zombie, Structures_A.case_cap] at hz) s3H s3L hs3) + (fun _ _ _ s4H s4L hs4 _ => + mrele_returnOk (Ra := RecDelRetRel (.ReduceZombieCall (.Zombie ptr bits (n + 1)) slot true)) + trivial s4H s4L hs4) + | @reduceZombieFail cap slot exposed s hnot => + intro sL hs + rw [recDel_unfold] + unfold Fl4Spec.recDelF embRecDelCall + cases cap with + | Zombie ptr bits n => + cases n with + | zero => exact mrele_fail_liftE s sL hs + | succ k => exact absurd rfl (hnot ptr bits k) + | _ => exact mrele_fail_liftE s sL hs + +/-- Domain predicate for `rec_del_p`: Isabelle's termination domain (`∃! y, RecDelPGraph (c, s) y`). -/ +def RecDelDom (c : CSpace_A.rec_del_call) (sH : Structures_A.state ZH) : Prop := + ∃! y, RecDelPGraph (c, sH) y + +theorem patched_recDel_equiv_on_dom (hop : OpaqueRel RestRel) (hc : ConfigRel) + {c : CSpace_A.rec_del_call} {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hdom : RecDelDom c sH) : + MRelStep SR (SumExceptRel Eq (RecDelRetRel c)) + (rec_del_p c sH) (Fl4Spec.recDel (embRecDelCall c) sL) := by + unfold rec_del_p + refine holTheDefault_of_existsUnique + (Q := fun y => MRelStep SR (SumExceptRel Eq (RecDelRetRel c)) y (Fl4Spec.recDel (embRecDelCall c) sL)) + ?_ (fun y hy => recDelPGraph_mrelStep hop hc (x := (c, sH)) (of_decide_eq_true hy) sL hs) + rcases hdom with ⟨y0, hy0, huniq⟩ + exact ⟨y0, decide_eq_true hy0, fun y hy => huniq y (of_decide_eq_true hy)⟩ + +theorem patched_capDelete_equiv_on_dom (hop : OpaqueRel RestRel) (hc : ConfigRel) + {slot : CslotPtr} {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hdom : RecDelDom (.CTEDeleteCall slot true) sH) : + MRelStep SR (SumExceptRel Eq Eq) + (cap_delete_p slot sH) (Fl4Spec.capDelete slot sL) := by + unfold cap_delete_p Fl4Spec.capDelete + refine mrelStep_bindE_mem (patched_recDel_equiv_on_dom hop hc hs hdom) + fun _ _ _ s1H s1L hs1 _ => mrele_returnOk rfl s1H s1L hs1 + +theorem patched_finaliseSlot_equiv_on_dom (hop : OpaqueRel RestRel) (hc : ConfigRel) + {slot : CslotPtr} {exposed : Bool} {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hdom : RecDelDom (.FinaliseSlotCall slot exposed) sH) : + MRelStep SR (SumExceptRel Eq (ProdRel Eq (FunRel embCap))) + (finalise_slot_p slot exposed sH) (Fl4Spec.finaliseSlot slot exposed sL) := by + have h := patched_recDel_equiv_on_dom hop hc hs hdom + refine ⟨h.1, ?_, ?_⟩ + · intro rH sH' hm + obtain ⟨rL, sL', hmL, hr, hs'⟩ := h.2.1 rH sH' hm + refine ⟨rL, sL', hmL, ?_, hs'⟩ + cases rH <;> cases rL <;> simp_all [SumExceptRel, RecDelRetRel, ProdRel] + · intro rL sL' hm + obtain ⟨rH, sH', hmH, hr, hs'⟩ := h.2.2 rL sL' hm + refine ⟨rH, sH', hmH, ?_, hs'⟩ + cases rH <;> cases rL <;> simp_all [SumExceptRel, RecDelRetRel, ProdRel] + + +def cap_revoke_step_p + (r : CslotPtr × Structures_A.state ZH → + Set (Sum Unit Unit × Structures_A.state ZH) × Bool) + (slot : CslotPtr) : HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holBindE (Exceptions_A.without_preemption (get_cap_p slot)) fun cap => + holBindE (Exceptions_A.without_preemption (holGets fun s => s.cdt)) fun cdt => + holBindE (holReturnOk (CSpaceAcc_A.descendants_of slot cdt)) fun desc => + holWhenE (holConj (holNot (holEq cap .NullCap)) (holNot (holEq desc ∅))) + (holBindE (Exceptions_A.without_preemption (Deterministic_A.select_ext (Deterministic_A.next_revoke_cap slot) desc)) fun child => + holBindE (Exceptions_A.without_preemption (get_cap_p child)) fun cap1 => + holBindE (holAssertE (holNot (holEq cap1 .NullCap))) + (holKBind (holBindE (cap_delete_p child) + (holKBind (holBindE KHeap_A.preemption_point + (holKBind (fun s => r (slot, s)))))))) + +/-- [P] Deterministic revocation selection has a next child when the selector is enabled. -/ +def NextRevokeSafe (slot : CslotPtr) (sH : Structures_A.state ZH) : Prop := + Deterministic_A.state_ext_class.select_switch sH.more.exst = true → + Deterministic_A.next_child slot + (Deterministic_A.cdt_list (Deterministic_A.state_ext_class.unwrap_ext sH)) ≠ none + +private theorem selectExt_nextRevokeCap_equiv (slot : CslotPtr) (d : Set CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : NextRevokeSafe slot sH) : + MRelStep SR Eq + (Deterministic_A.select_ext (Deterministic_A.next_revoke_cap slot) d sH) + (Fl4Spec.selectExt (Fl4Spec.nextRevokeCap slot) d sL) := by + unfold Deterministic_A.select_ext Fl4Spec.selectExt + refine mrelStep_bind_mem (mrel_get (Rs := SR) sH sL hs) fun s1H s1L hs1 s2H s2L hs2 hm1 => ?_ + have hs1eq : s1H = sH ∧ s2H = sH := by + simp only [holGet, Set.mem_singleton_iff, Prod.mk.injEq] at hm1; exact hm1 + obtain ⟨hs1_eq, hs2_eq⟩ := hs1eq + rw [hs1_eq] at hs1 ⊢ + rw [hs2_eq] at hs2 ⊢ + have hsw := ser.selectSwitch_eq sH.more.exst s1L.exst hs1.exst_rel + change MRelStep SR Eq + (holBind (holIf (Deterministic_A.state_ext_class.select_switch sH.more.exst) _ _) _ sH) _ + by_cases htrue : StateExt.selectSwitch s1L.exst = true + · have hH : Deterministic_A.state_ext_class.select_switch sH.more.exst = true := by rw [hsw, htrue] + rw [hH] + simp only [htrue, holIf_true, ↓reduceIte] + have hnr : Deterministic_A.next_revoke_cap slot (Deterministic_A.state_ext_class.unwrap_ext sH) = + Fl4Spec.nextRevokeCap slot (StateExt.unwrapExt s1L) := + (nextRevokeCap_eq_on_some slot (ser.unwrapExt_rel sH s1L hs1 htrue) (hsafe hH)).symm + refine mrelStep_bind_mem (mrel_return (Ra := Eq) hnr sH s2L hs2) fun xH xL hx s3H s3L hs3 _ => ?_ + subst hx + exact (mrel_kbind (mrel_assert (by simp [holMember_eq_true])) (mrel_return rfl)) s3H s3L hs3 + · have hH : Deterministic_A.state_ext_class.select_switch sH.more.exst = false := by + rw [hsw]; cases hb : StateExt.selectSwitch s1L.exst <;> simp_all + rw [hH] + simp only [htrue, holIf_false, Bool.false_eq_true, ↓reduceIte] + have hS : SetRel Eq d d := ⟨fun x hx => ⟨x, hx, rfl⟩, fun x hx => ⟨x, hx, rfl⟩⟩ + refine mrelStep_bind_mem (mrel_select hS sH s2L hs2) fun xH xL hx s3H s3L hs3 _ => ?_ + subst hx + exact (mrel_kbind (mrel_assert (by simp [holMember_eq_true])) (mrel_return rfl)) s3H s3L hs3 + +inductive CapRevokePGraph : + (CslotPtr × Structures_A.state ZH) → + (Set (Sum Unit Unit × Structures_A.state ZH) × Bool) → Prop + | step {r slot s} : + (∀ cap st cdt sta desc stb, + (Sum.inr cap, st) ∈ (Exceptions_A.without_preemption (get_cap_p slot) s).1 → + (Sum.inr cdt, sta) ∈ (Exceptions_A.without_preemption (holGets fun s => s.cdt) st).1 → + (Sum.inr desc, stb) ∈ (holReturnOk (ε := Unit) (CSpaceAcc_A.descendants_of slot cdt) sta).1 → + cap ≠ .NullCap → desc ≠ ∅ → + NextRevokeSafe slot stb) → + (∀ cap st cdt sta desc stb child stc cap1 std u ste, + (Sum.inr cap, st) ∈ (Exceptions_A.without_preemption (get_cap_p slot) s).1 → + (Sum.inr cdt, sta) ∈ (Exceptions_A.without_preemption (holGets fun s => s.cdt) st).1 → + (Sum.inr desc, stb) ∈ (holReturnOk (ε := Unit) (CSpaceAcc_A.descendants_of slot cdt) sta).1 → + cap ≠ .NullCap → desc ≠ ∅ → + (Sum.inr child, stc) ∈ (Exceptions_A.without_preemption (Deterministic_A.select_ext (Deterministic_A.next_revoke_cap slot) desc) stb).1 → + (Sum.inr cap1, std) ∈ (Exceptions_A.without_preemption (get_cap_p child) stc).1 → + (Sum.inr u, ste) ∈ (holAssertE (ε := Unit) (holNot (holEq cap1 .NullCap)) std).1 → + RecDelDom (.CTEDeleteCall child true) ste) → + (∀ cap st cdt sta desc stb child stc cap1 std u ste v stf w stg, + (Sum.inr cap, st) ∈ (Exceptions_A.without_preemption (get_cap_p slot) s).1 → + (Sum.inr cdt, sta) ∈ (Exceptions_A.without_preemption (holGets fun s => s.cdt) st).1 → + (Sum.inr desc, stb) ∈ (holReturnOk (ε := Unit) (CSpaceAcc_A.descendants_of slot cdt) sta).1 → + cap ≠ .NullCap → desc ≠ ∅ → + (Sum.inr child, stc) ∈ (Exceptions_A.without_preemption (Deterministic_A.select_ext (Deterministic_A.next_revoke_cap slot) desc) stb).1 → + (Sum.inr cap1, std) ∈ (Exceptions_A.without_preemption (get_cap_p child) stc).1 → + (Sum.inr u, ste) ∈ (holAssertE (ε := Unit) (holNot (holEq cap1 .NullCap)) std).1 → + (Sum.inr v, stf) ∈ (cap_delete_p child ste).1 → + (Sum.inr w, stg) ∈ (KHeap_A.preemption_point stf).1 → + CapRevokePGraph (slot, stg) (r (slot, stg))) → + CapRevokePGraph (slot, s) (cap_revoke_step_p r slot s) + +def cap_revoke_p (slot : CslotPtr) (s : Structures_A.state ZH) : + Set (Sum Unit Unit × Structures_A.state ZH) × Bool := + holTheDefault holUndefined (fun y => decide (CapRevokePGraph (slot, s) y)) + +def CapRevokeDom (slot : CslotPtr) (sH : Structures_A.state ZH) : Prop := + ∃! y, CapRevokePGraph (slot, sH) y + +theorem capRevokePGraph_mrelStep (hop : OpaqueRel RestRel) (hc : ConfigRel) + {x : CslotPtr × Structures_A.state ZH} + {y : Set (Sum Unit Unit × Structures_A.state ZH) × Bool} + (hg : CapRevokePGraph x y) : + ∀ sL, SR x.2 sL → + MRelStep SR (SumExceptRel Eq Eq) y (Fl4Spec.capRevoke x.1 sL) := by + induction hg with + | @step r slot s hnr hdel hrev ih => + intro sL hs + rw [capRevoke_unfold] + unfold cap_revoke_step_p Fl4Spec.capRevokeF + refine mrelStep_bindE_mem (withoutPreemption_equiv (patched_getCap_equiv slot) s sL hs) + fun capH capL hcap s1H s1L hs1 hm1 => ?_ + subst hcap + refine mrelStep_bindE_mem (withoutPreemption_equiv (mrel_gets fun _ _ h => h.cdt_eq.symm) s1H s1L hs1) + fun cdtH cdtL hcdt s2H s2L hs2 hm2 => ?_ + subst hcdt + refine mrelStep_bindE_mem (mrele_returnOk (Ra := Eq) (descendantsOf_eq slot cdtH).symm s2H s2L hs2) + fun dH dL hd s3H s3L hs3 hm3 => ?_ + subst hd + have hcondIff : holConj (holNot (holEq capH .NullCap)) (holNot (holEq dH ∅)) = true ↔ + embCap capH ≠ .nullCap ∧ dH ≠ ∅ := by + simp only [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true] + exact and_congr_left fun _ => by cases capH <;> simp [embCap] + unfold holWhenE NonDetE.whenE + by_cases hcond : holConj (holNot (holEq capH .NullCap)) (holNot (holEq dH ∅)) = true + · rw [ite_eq_left hcond, ite_eq_left (hcondIff.mp hcond)] + have ⟨hcapNe, hdNe⟩ : capH ≠ .NullCap ∧ dH ≠ ∅ := by + simpa [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true] using hcond + have hnr3 := hnr capH s1H cdtH s2H dH s3H hm1 hm2 hm3 hcapNe hdNe + refine mrelStep_bindE_mem (withoutPreemption_step_equiv (selectExt_nextRevokeCap_equiv slot dH hs3 hnr3)) + fun chH chL hch s4H s4L hs4 hm4 => ?_ + subst hch + refine mrelStep_bindE_mem (withoutPreemption_equiv (patched_getCap_equiv chH) s4H s4L hs4) + fun c1H c1L hc1 s5H s5L hs5 hm5 => ?_ + subst hc1 + refine mrelStep_bindE_mem (mrele_assertE (by cases c1H <;> simp [holNot_eq_true, holEq_eq_true, embCap]) s5H s5L hs5) + fun uH uL _ s6H s6L hs6 hm6 => ?_ + have hdomDel := hdel capH s1H cdtH s2H dH s3H chH s4H c1H s5H uH s6H + hm1 hm2 hm3 hcapNe hdNe hm4 hm5 hm6 + refine mrelStep_bindE_mem (patched_capDelete_equiv_on_dom hop hc hs6 hdomDel) + fun vH vL _ s7H s7L hs7 hm7 => ?_ + refine mrelStep_bindE_mem (preemptionPoint_equiv hc hop s7H s7L hs7) + fun wH wL _ s8H s8L hs8 hm8 => ?_ + exact ih capH s1H cdtH s2H dH s3H chH s4H c1H s5H uH s6H vH s7H wH s8H + hm1 hm2 hm3 hcapNe hdNe hm4 hm5 hm6 hm7 hm8 s8L hs8 + · rw [ite_eq_right hcond, ite_eq_right (mt hcondIff.mpr hcond)] + exact mrele_returnOk rfl s3H s3L hs3 + +theorem patched_capRevoke_equiv_on_dom (hop : OpaqueRel RestRel) (hc : ConfigRel) + {slot : CslotPtr} {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hdom : CapRevokeDom slot sH) : + MRelStep SR (SumExceptRel Eq Eq) + (cap_revoke_p slot sH) (Fl4Spec.capRevoke slot sL) := by + unfold cap_revoke_p + refine holTheDefault_of_existsUnique + (Q := fun y => MRelStep SR (SumExceptRel Eq Eq) y (Fl4Spec.capRevoke slot sL)) + ?_ (fun y hy => capRevokePGraph_mrelStep hop hc (x := (slot, sH)) (of_decide_eq_true hy) sL hs) + rcases hdom with ⟨y0, hy0, huniq⟩ + exact ⟨y0, decide_eq_true hy0, fun y hy => huniq y (of_decide_eq_true hy)⟩ + +/-! ### `invokeCnode` -/ + +/-- l4v: CSpace_A.invoke_cnode using the checked recursive deletion and slot operations. -/ +def invoke_cnode_p : Invocations_A.cnode_invocation → HolNonDet (Structures_A.state ZH) (Sum Unit Unit) + | .InsertCall cap src dest => Exceptions_A.without_preemption (cap_insert_p cap src dest) + | .MoveCall cap src dest => Exceptions_A.without_preemption (cap_move_p cap src dest) + | .RevokeCall dest => cap_revoke_p dest + | .DeleteCall dest => cap_delete_p dest + | .RotateCall c1 c2 s1 s2 s3 => + Exceptions_A.without_preemption (holIf (holEq s1 s3) (cap_swap_p c1 s1 c2 s2) + (holBind (cap_move_p c2 s2 s3) (holKBind (cap_move_p c1 s1 s2)))) + | .CancelBadgedSendsCall (.EndpointCap ep b _) => + Exceptions_A.without_preemption (holWhen (holNot (holEq b 0#64)) (IpcCancel_A.cancel_badged_sends ep b)) + | .CancelBadgedSendsCall _ => holFail + +/-- [P] The selected invocation admits its recursive domain and writes. -/ +def InvokeCnodeSafe (i : Invocations_A.cnode_invocation) (sH : Structures_A.state ZH) : Prop := + match i with + | .InsertCall cap src dest => CapInsertSafe cap src dest sH + | .MoveCall cap _ dest => SetCapSafe cap dest sH + | .RevokeCall dest => CapRevokeDom dest sH + | .DeleteCall dest => RecDelDom (.CTEDeleteCall dest true) sH + | .RotateCall c1 c2 s1 s2 s3 => + (s1 = s3 → SetCapSafe c2 s1 sH ∧ + ∀ t, ((), t) ∈ (set_cap_p c2 s1 sH).1 → SetCapSafe c1 s2 t) ∧ + (s1 ≠ s3 → SetCapSafe c2 s3 sH ∧ + ∀ t, ((), t) ∈ (cap_move_p c2 s2 s3 sH).1 → SetCapSafe c1 s2 t) + | _ => True + +theorem patched_invokeCnode_equiv (hop : OpaqueRel RestRel) (hc : ConfigRel) + (i : Invocations_A.cnode_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : InvokeCnodeSafe i sH) : + MRelStep SR (SumExceptRel Eq Eq) + (invoke_cnode_p i sH) (Fl4Spec.invokeCnode (embCnodeInv i) sL) := by + cases i with + | InsertCall cap src dest => + unfold invoke_cnode_p Fl4Spec.invokeCnode embCnodeInv + exact withoutPreemption_step_equiv (patched_capInsert_equiv cap src dest hs hsafe) + | MoveCall cap src dest => + exact withoutPreemption_step_equiv (patched_capMove_equiv cap src dest hs hsafe) + | RevokeCall dest => + exact patched_capRevoke_equiv_on_dom hop hc hs hsafe + | DeleteCall dest => + exact patched_capDelete_equiv_on_dom hop hc hs hsafe + | RotateCall c1 c2 s1 s2 s3 => + unfold invoke_cnode_p Fl4Spec.invokeCnode embCnodeInv + refine withoutPreemption_step_equiv ?_ + by_cases heq : s1 = s3 + · have ⟨hfirst, hsecond⟩ := hsafe.1 heq + rw [holIf_eq, ite_eq_left ((holEq_eq_true _ _).mpr heq), ite_eq_left heq] + exact patched_capSwap_equiv c1 s1 c2 s2 hs hfirst hsecond + · have hf : holEq s1 s3 = false := by simp [holEq, heq] + simp only [hf, holIf_false, heq, ↓reduceIte] + obtain ⟨hfirst, hsecond⟩ := hsafe.2 heq + refine mrelStep_bind_mem (patched_capMove_equiv c2 s2 s3 hs hfirst) + fun a _ _ s1H s1L hs1 hm1 => ?_ + cases a + exact patched_capMove_equiv c1 s1 s2 hs1 (hsecond s1H hm1) + | CancelBadgedSendsCall cap => + cases cap with + | EndpointCap ep b rs => + unfold invoke_cnode_p Fl4Spec.invokeCnode embCnodeInv embCap + exact withoutPreemption_equiv + (mrel_when (by simp [holNot_eq_true, holEq_eq_true]) fun _ => cancelBadgedSends_equiv hop ep b) sH sL hs + | _ => exact mrele_fail_liftE sH sL hs + + +end CSpaceMonad + +end + +end L4vRefX64.Equiv.CSpace diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/CSpaceAcc.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/CSpaceAcc.lean new file mode 100644 index 000000000..86581439d --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/CSpaceAcc.lean @@ -0,0 +1,807 @@ +import L4vRefX64.Equiv.KHeap +import L4vRefX64.Spec.Sporadic_A + +namespace L4vRefX64.Equiv.CSpaceAcc + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec +open L4vRefX64.Equiv.Machine +open L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.Deterministic +open L4vRefX64.Equiv.KHeap +open Fl4Spec +open Classical + +noncomputable section + +/-! ## CSpaceAcc_A: Pure CDT Predicates & Closures -/ + +theorem isCdtParent_iff (t : Cdt) (p c : CslotPtr) : + CSpaceAcc_A.is_cdt_parent t p c = true ↔ Fl4Spec.isCdtParent t p c := by + unfold CSpaceAcc_A.is_cdt_parent Fl4Spec.isCdtParent + simp [holEq_eq_true] + +theorem cdtParentRel_eq (t : Cdt) : + Fl4Spec.cdtParentRel t = CSpaceAcc_A.cdt_parent_rel t := by + unfold Fl4Spec.cdtParentRel CSpaceAcc_A.cdt_parent_rel + ext ⟨p, c⟩ + simp [holCollect_eq, holCaseProd_eq, isCdtParent_iff] + +theorem parentOf_iff (t : Cdt) (p c : CslotPtr) : + CSpaceAcc_A.parent_of t p c = true ↔ Fl4Spec.parentOf t p c := by + unfold CSpaceAcc_A.parent_of Fl4Spec.parentOf + rw [cdtParentRel_eq] + simp [holMember_eq_true] + +theorem parentOfTrancl_iff (t : Cdt) (x y : CslotPtr) : + CSpaceAcc_A.parent_of_trancl t x y = true ↔ Fl4Spec.parentOfTrancl t x y := by + unfold CSpaceAcc_A.parent_of_trancl Fl4Spec.parentOfTrancl + rw [← cdtParentRel_eq] + simp only [holMember_eq_true] + unfold holTrancl + change Relation.TransGen (fun a b => (a, b) ∈ Fl4Spec.cdtParentRel t) x y ↔ + Relation.TransGen (Fl4Spec.parentOf t) x y + rfl + +theorem parentOfRtrancl_iff (t : Cdt) (x y : CslotPtr) : + CSpaceAcc_A.parent_of_rtrancl t x y = true ↔ Fl4Spec.parentOfRtrancl t x y := by + unfold CSpaceAcc_A.parent_of_rtrancl Fl4Spec.parentOfRtrancl + rw [← cdtParentRel_eq] + simp only [holMember_eq_true] + unfold holRtrancl + change Relation.ReflTransGen (fun a b => (a, b) ∈ Fl4Spec.cdtParentRel t) x y ↔ + Relation.ReflTransGen (Fl4Spec.parentOf t) x y + rfl + +theorem descendantsOf_eq (p : CslotPtr) (t : Cdt) : + Fl4Spec.descendantsOf p t = CSpaceAcc_A.descendants_of p t := by + unfold Fl4Spec.descendantsOf CSpaceAcc_A.descendants_of + ext q + have h := parentOfTrancl_iff t p q + unfold CSpaceAcc_A.parent_of_trancl at h + simp only [holCollect_eq, Set.mem_ofPred_eq, h] + +/-! ## Sporadic_A: Pure Helpers -/ + +theorem canMergeRefill_iff (r1 r2 : Structures_A.refill) : + Sporadic_A.can_merge_refill r1 r2 = true ↔ + Fl4Spec.canMergeRefill (embRefill r1) (embRefill r2) := by + unfold Sporadic_A.can_merge_refill Fl4Spec.canMergeRefill + simp [embRefill, holLe_eq_true, HolOrd.leVal, HolAdd.addVal] + +theorem mergeRefill_eq (r1 r2 : Structures_A.refill) : + Fl4Spec.mergeRefill (embRefill r1) (embRefill r2) = + embRefill (Sporadic_A.merge_refill r1 r2) := rfl + +/-! ## CSpaceAcc_A & Sporadic_A: Monadic Operations -/ + +section CSpaceAccMonad + +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 + +/-- Slot 5 is the extra EPT root entry in the FL4 TCB. -/ +def NonExtTcbSlot (cref : CnodeIndex) : Prop := cref ≠ Fl4Spec.tcbCnodeIndex 5 + +theorem getCap_equiv_nonExt (slot : CslotPtr) (hslot : NonExtTcbSlot slot.2) : + MRel SR (FunRel embCap) + (CSpaceAcc_A.get_cap slot) (Fl4Spec.getCap slot) := by + rcases slot with ⟨oref, cref⟩ + simp only [NonExtTcbSlot] at hslot + unfold CSpaceAcc_A.get_cap Fl4Spec.getCap + simp only [holCaseProd_eq] + refine mrel_bind (getObject_equiv oref) fun koH koL hko => ?_ + subst hko + cases koH with + | CNode sz cn => + simp only [Structures_A.case_kernel_object, embKernelObject] + rw [holBind_assoc] + refine mrel_bind (mrel_assert (wellFormedCnodeN_iff sz cn)) fun _ _ _ => ?_ + simp only [holKBind_eq] + refine mrel_bind (Ra := fun (fH : List Bool → Option Structures_A.cap) (fL : CnodeIndex → Option Cap) => + OptRel (FunRel embCap) (fH cref) (fL cref)) + (mrel_return (by rw [optRel_funRel]; rfl)) + fun _ _ hf => mrel_assertOpt hf + | TCB tcb => + simp only [Structures_A.case_kernel_object, embKernelObject] + refine mrel_bind (Ra := fun (fH : List Bool → Option Structures_A.cap) (fL : CnodeIndex → Option Cap) => + OptRel (FunRel embCap) (fH cref) (fL cref)) + (mrel_return ((optRel_funRel embCap _ _).mpr (tcbCnodeMap_eq_nonExt tcb cref hslot))) + fun _ _ hf => mrel_assertOpt hf + | Endpoint _ | Notification _ | SchedContext _ _ | Reply _ | ArchObj _ => + simp only [Structures_A.case_kernel_object, embKernelObject] + exact mrel_bind mrel_fail fun _ _ h => (False.elim h) + +omit [StateExt ZL] in +theorem getCap_member_heap {s s' : Structures_A.state ZH} {slot : CslotPtr} + {cap : Structures_A.cap} (hm : (cap, s') ∈ (CSpaceAcc_A.get_cap slot s).1) : + s' = s ∧ (match s.kheap slot.1 with + | some (.CNode _ caps) => caps slot.2 + | some (.TCB tcb) => Structures_A.tcb_cnode_map tcb slot.2 + | _ => none) = some cap := by + rcases slot with ⟨ptr, index⟩ + unfold CSpaceAcc_A.get_cap at hm + simp only [holCaseProd_eq, holBind, Set.mem_ofPred_eq, Prod.exists] at hm + obtain ⟨obj, s0, hget, caps, s1, hcaps, hcap⟩ := hm + obtain ⟨hheap, heq⟩ := getObject_member hget + subst s0 + simp only [hheap] + cases obj with + | CNode size entries => + simp only [Structures_A.case_kernel_object, holKBind_eq, holBind, Set.mem_ofPred_eq, + Prod.exists] at hcaps + obtain ⟨u, st, ha, hr⟩ := hcaps + have hst : st = s := by + simp only [holAssert, Set.mem_ofPred_eq, Prod.mk.injEq] at ha + exact ha.2.2 + subst st + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hr + obtain ⟨hcaps, hs1⟩ := hr + subst caps + subst s1 + cases hc : entries index <;> simp_all [holAssertOpt, holReturn, holFail] + | TCB tcb => + simp only [Structures_A.case_kernel_object, holReturn, Set.mem_singleton_iff, + Prod.mk.injEq] at hcaps + obtain ⟨hcaps, hs1⟩ := hcaps + subst caps + subst s1 + cases hc : Structures_A.tcb_cnode_map tcb index <;> simp_all [holAssertOpt, holReturn, holFail] + | _ => simp only [Structures_A.case_kernel_object, holFail, Set.mem_empty_iff_false] at hcaps + +theorem setCap_equiv_nonExt (cap : Structures_A.cap) (slot : CslotPtr) + (hslot : NonExtTcbSlot slot.2) : + MRel SR Eq + (CSpaceAcc_A.set_cap cap slot) (Fl4Spec.setCap (embCap cap) slot) := by + rcases slot with ⟨oref, cref⟩ + simp only [NonExtTcbSlot] at hslot + unfold CSpaceAcc_A.set_cap Fl4Spec.setCap + simp only [holCaseProd_eq] + refine mrel_bind (getObject_equiv oref) fun koH koL hko => ?_ + subst hko + cases koH with + | CNode sz cn => + simp only [Structures_A.case_kernel_object, embKernelObject] + have hcond : holConj (holMember cref (holDom cn)) (Structures_A.well_formed_cnode_n sz cn) = true ↔ + cref ∈ Fl4Spec.dom (embCnodeContents cn) ∧ Fl4Spec.wellFormedCnodeN sz (embCnodeContents cn) := by + simp [holConj_eq_true, holMember_eq_true, Fl4Spec.dom, holDom, embCnodeContents, + wellFormedCnodeN_iff] + by_cases hL : cref ∈ Fl4Spec.dom (embCnodeContents cn) ∧ Fl4Spec.wellFormedCnodeN sz (embCnodeContents cn) + · have hH : holConj (holMember cref (holDom cn)) (Structures_A.well_formed_cnode_n sz cn) = true := hcond.mpr hL + simp only [hH, hL, holIf_true] + have hcn : Function.update (embCnodeContents cn) cref (some (embCap cap)) = + embCnodeContents (holFunUpd cn cref (some cap)) := by + funext k; unfold embCnodeContents holFunUpd Function.update + split_ifs <;> first | (subst ‹k = _›; rfl) | rfl + refine mrel_bind (Ra := FunRel embKernelObject) + (mrel_return (by simp [FunRel, embKernelObject, hcn])) fun ko'H ko'L hko' => ?_ + subst hko' + exact setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) oref ko'H + · have hH : holConj (holMember cref (holDom cn)) (Structures_A.well_formed_cnode_n sz cn) = false := by + cases hb : holConj (holMember cref (holDom cn)) (Structures_A.well_formed_cnode_n sz cn) + · rfl + · exact absurd (hcond.mp hb) hL + simp only [hH, hL, holIf_false] + exact mrel_bind mrel_fail fun _ _ h => (False.elim h) + | TCB tcb => + simp only [Structures_A.case_kernel_object, embKernelObject] + by_cases h0 : cref = Fl4Spec.tcbCnodeIndex 0 + · have h0H : holEq cref (Structures_A.tcb_cnode_index (HolZero.zeroVal (α := Nat))) = true := by + simp [holEq_eq_true, ← tcbCnodeIndex_eq 0, HolZero.zeroVal, h0] + rw [h0H, holIf_true]; simp only [h0, ↓reduceIte, holFunApp] + exact mrel_bind (Ra := FunRel embKernelObject) + (mrel_return (by simp [FunRel, embKernelObject, embTcb, Structures_A.tcb.tcb_ctable_update])) + fun ko'H ko'L hko' => by + subst hko'; exact setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) oref ko'H + · have h0H : holEq cref (Structures_A.tcb_cnode_index (HolZero.zeroVal (α := Nat))) = false := by + simp [holEq, ← tcbCnodeIndex_eq 0, HolZero.zeroVal, h0] + rw [h0H, holIf_false]; simp only [h0, ↓reduceIte] + by_cases h1 : cref = Fl4Spec.tcbCnodeIndex 1 + · have h1H : holEq cref (Structures_A.tcb_cnode_index (HolOne.oneVal (α := Nat))) = true := by + simp [holEq_eq_true, ← tcbCnodeIndex_eq 1, HolOne.oneVal, h1] + rw [h1H, holIf_true]; simp only [h1, ↓reduceIte, holFunApp] + exact mrel_bind (Ra := FunRel embKernelObject) + (mrel_return (by simp [FunRel, embKernelObject, embTcb, Structures_A.tcb.tcb_vtable_update])) + fun ko'H ko'L hko' => by + subst hko'; exact setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) oref ko'H + · have h1H : holEq cref (Structures_A.tcb_cnode_index (HolOne.oneVal (α := Nat))) = false := by + simp [holEq, ← tcbCnodeIndex_eq 1, HolOne.oneVal, h1] + rw [h1H, holIf_false]; simp only [h1, ↓reduceIte] + by_cases h2 : cref = Fl4Spec.tcbCnodeIndex 2 + · have h2H : holEq cref (Structures_A.tcb_cnode_index (HolNumeral.ofNatVal 2)) = true := by + simp [holEq_eq_true, ← tcbCnodeIndex_eq 2, HolNumeral.ofNatVal, h2] + rw [h2H, holIf_true]; simp only [h2, ↓reduceIte, holFunApp] + exact mrel_bind (Ra := FunRel embKernelObject) + (mrel_return (by simp [FunRel, embKernelObject, embTcb, Structures_A.tcb.tcb_ipcframe_update])) + fun ko'H ko'L hko' => by + subst hko'; exact setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) oref ko'H + · have h2H : holEq cref (Structures_A.tcb_cnode_index (HolNumeral.ofNatVal 2)) = false := by + simp [holEq, ← tcbCnodeIndex_eq 2, HolNumeral.ofNatVal, h2] + rw [h2H, holIf_false]; simp only [h2, ↓reduceIte] + by_cases h3 : cref = Fl4Spec.tcbCnodeIndex 3 + · have h3H : holEq cref (Structures_A.tcb_cnode_index (HolNumeral.ofNatVal 3)) = true := by + simp [holEq_eq_true, ← tcbCnodeIndex_eq 3, HolNumeral.ofNatVal, h3] + rw [h3H, holIf_true]; simp only [h3, ↓reduceIte, holFunApp] + exact mrel_bind (Ra := FunRel embKernelObject) + (mrel_return (by simp [FunRel, embKernelObject, embTcb, Structures_A.tcb.tcb_fault_handler_update])) + fun ko'H ko'L hko' => by + subst hko'; exact setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) oref ko'H + · have h3H : holEq cref (Structures_A.tcb_cnode_index (HolNumeral.ofNatVal 3)) = false := by + simp [holEq, ← tcbCnodeIndex_eq 3, HolNumeral.ofNatVal, h3] + rw [h3H, holIf_false]; simp only [h3, ↓reduceIte] + by_cases h4 : cref = Fl4Spec.tcbCnodeIndex 4 + · have h4H : holEq cref (Structures_A.tcb_cnode_index (HolNumeral.ofNatVal 4)) = true := by + simp [holEq_eq_true, ← tcbCnodeIndex_eq 4, HolNumeral.ofNatVal, h4] + rw [h4H, holIf_true]; simp only [h4, ↓reduceIte, holFunApp] + exact mrel_bind (Ra := FunRel embKernelObject) + (mrel_return (by simp [FunRel, embKernelObject, embTcb, Structures_A.tcb.tcb_timeout_handler_update])) + fun ko'H ko'L hko' => by + subst hko'; exact setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) oref ko'H + · have h4H : holEq cref (Structures_A.tcb_cnode_index (HolNumeral.ofNatVal 4)) = false := by + simp [holEq, ← tcbCnodeIndex_eq 4, HolNumeral.ofNatVal, h4] + rw [h4H, holIf_false]; simp only [h4, hslot, ↓reduceIte] + exact mrel_bind mrel_fail fun _ _ h => (False.elim h) + | Endpoint _ | Notification _ | SchedContext _ _ | Reply _ | ArchObj _ => + simp only [Structures_A.case_kernel_object, embKernelObject] + exact mrel_bind mrel_fail fun _ _ h => (False.elim h) + +theorem ensureEmpty_equiv_nonExt (slot : CslotPtr) (hslot : NonExtTcbSlot slot.2) : + MRelE SR (FunRel embSyscallError) Eq + (CSpaceAcc_A.ensure_empty slot) (Fl4Spec.ensureEmpty slot) := by + unfold CSpaceAcc_A.ensure_empty Fl4Spec.ensureEmpty + refine mrele_bindE (mrele_liftE (getCap_equiv_nonExt slot hslot)) fun cH cL hc => ?_ + subst hc + have hneq : holNot (holEq cH .NullCap) = true ↔ embCap cH ≠ .nullCap := by + cases cH <;> simp [embCap, holNot, holEq] + exact mrele_whenE hneq fun _ => mrele_throwError rfl + +theorem setCdt_equiv (t : Cdt) : + MRel SR Eq + (CSpaceAcc_A.set_cdt t) (Fl4Spec.setCdt t) := by + unfold CSpaceAcc_A.set_cdt Fl4Spec.setCdt + refine mrel_bind (mrel_get (Rs := SR)) fun sH sL hs => ?_ + exact mrel_put { hs with cdt_eq := rfl } + +theorem updateCdt_equiv (f : Cdt → Cdt) : + MRel SR Eq + (CSpaceAcc_A.update_cdt f) (Fl4Spec.updateCdt f) := by + unfold CSpaceAcc_A.update_cdt Fl4Spec.updateCdt + refine mrel_bind (mrel_gets fun _ _ hs => hs.cdt_eq.symm) fun tH tL ht => ?_ + subst ht + exact setCdt_equiv (f tH) + +theorem setOriginal_equiv (slot : CslotPtr) (v : Bool) : + MRel SR Eq + (CSpaceAcc_A.set_original slot v) (Fl4Spec.setOriginal slot v) := by + unfold CSpaceAcc_A.set_original Fl4Spec.setOriginal + refine mrel_bind (mrel_gets fun _ _ hs => hs.isOriginalCap_eq.symm) fun rH rL hr => ?_ + subst hr + refine mrel_modify fun _ _ hs => { hs with isOriginalCap_eq := ?_ } + dsimp only [Structures_A.abstract_state.is_original_cap_update] + funext k + unfold holFunUpd Function.update + split_ifs <;> first | (subst ‹k = _›; rfl) | rfl + +/-! ## Sporadic_A Monadic Operations -/ + +theorem isRoundRobin_equiv (scPtr : ObjRef) : + MRel SR Eq + (Sporadic_A.is_round_robin scPtr) (Fl4Spec.isRoundRobin scPtr) := by + unfold Sporadic_A.is_round_robin Fl4Spec.isRoundRobin + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + refine mrel_return ?_ + apply Bool.eq_iff_iff.mpr + simp only [embSchedContext, holEq_eq_true, HolZero.zeroVal] + by_cases h : scH.sc_period = 0#64 <;> simp [h] + +theorem refillPopHead_equiv (scPtr : ObjRef) : + MRel SR (FunRel embRefill) + (Sporadic_A.refill_pop_head scPtr) (Fl4Spec.refillPopHead scPtr) := by + unfold Sporadic_A.refill_pop_head Fl4Spec.refillPopHead + refine mrel_bind (getRefillHead_equiv scPtr) fun rH rL hr => ?_ + refine mrel_kbind (updateSchedContext_equiv (fun sc => by + simp only [embSchedContext, scRefillsUpdate, Structures_A.sched_context.sc_refills_update, holTl] + cases sc.sc_refills <;> rfl) scPtr) (mrel_return hr) + +theorem refillHeadOverlapping_equiv (scPtr : ObjRef) : + LookupRel SR Eq + (Sporadic_A.refill_head_overlapping scPtr) (Fl4Spec.refillHeadOverlapping scPtr) := by + unfold Sporadic_A.refill_head_overlapping Fl4Spec.refillHeadOverlapping + refine lookup_bind (readSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + refine lookup_oreturn ?_ + apply Bool.eq_iff_iff.mpr + simp only [holConj_eq_true, holLt_eq_true, holLe_eq_true, HolOrd.ltVal, HolOrd.leVal, + HolOne.oneVal, HolAdd.addVal, holSize_list, decide_eq_true_eq, embSchedContext, + List.length_map, gt_iff_lt] + constructor + · rintro ⟨hlen, hle⟩ + refine ⟨hlen, ?_⟩ + cases h : scH.sc_refills with + | nil => simp [h] at hlen + | cons r0 rs => + cases rs with + | nil => simp [h] at hlen + | cons r1 rs' => + simp only [h, holTl, holHd, List.map_cons, List.tail_cons, List.head?_cons, the, + Fl4Spec.refillHd, embRefill] at hle ⊢ + exact hle + · rintro ⟨hlen, hle⟩ + refine ⟨hlen, ?_⟩ + cases h : scH.sc_refills with + | nil => simp [h] at hlen + | cons r0 rs => + cases rs with + | nil => simp [h] at hlen + | cons r1 rs' => + simp only [h, holTl, holHd, List.map_cons, List.tail_cons, List.head?_cons, the, + Fl4Spec.refillHd, embRefill] at hle ⊢ + exact hle + +/-- State predicate: `scPtr` holds a `SchedContext` with a non-empty `sc_refills` list. -/ +def HasNonEmptyRefills (scPtr : ObjRef) (sH : Structures_A.state ZH) : Prop := + ∃ sc n, sH.kheap scPtr = some (.SchedContext sc n) ∧ sc.sc_refills ≠ [] + +/-- State predicate: `scPtr` holds a `SchedContext` with at least 2 refills. -/ +def HasTwoRefills (scPtr : ObjRef) (sH : Structures_A.state ZH) : Prop := + ∃ sc n, sH.kheap scPtr = some (.SchedContext sc n) ∧ sc.sc_refills.length > 1 + +theorem updateRefillHd_equiv_nonEmpty (scPtr : ObjRef) + {fH : Structures_A.refill → Structures_A.refill} {fL : Refill → Refill} + (hf : ∀ r, fL (embRefill r) = embRefill (fH r)) : + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (Sporadic_A.update_refill_hd scPtr fH) (Fl4Spec.updateRefillHd scPtr fL) := by + intro sH sL ⟨hs, sc, n, hkh, hne⟩ + have hkhL : sL.kheap scPtr = some (.schedContext (embSchedContext sc) n) := by + rw [hs.kheap_eq scPtr, hkh]; rfl + cases href : sc.sc_refills with + | nil => exact absurd href hne + | cons r rs => + let sc'H := Structures_A.sched_context.sc_refills_update + (fun refills => fH (holHd refills) :: holTl refills) sc + let sc'L := scRefillsUpdate (fun refills => fL (the refills.head?) :: refills.tail) + (embSchedContext sc) + have hsc' : sc'L = embSchedContext sc'H := by + simp [sc'L, sc'H, embSchedContext, scRefillsUpdate, + Structures_A.sched_context.sc_refills_update, href, holHd, holTl, the, hf] + have hne' : sc'H.sc_refills ≠ [] := by + simp [sc'H, Structures_A.sched_context.sc_refills_update] + have hstep := setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr (.SchedContext sc'H n) sH sL hs + have hH_eq : Sporadic_A.update_refill_hd scPtr fH sH = + KHeap_A.set_object scPtr (.SchedContext sc'H n) sH := by + unfold Sporadic_A.update_refill_hd KHeap_A.update_sched_context + KHeap_A.get_object KHeap_A.read_object holSwp + apply Prod.ext + · ext p + simp [holFunApp, holBind, holGetsThe, holAssertOpt, holReturn, hkh, + Structures_A.case_kernel_object, sc'H] + · simp [holFunApp, holBind, holGetsThe, holAssertOpt, holReturn, hkh, + Structures_A.case_kernel_object, sc'H] + have hL_eq : Fl4Spec.updateRefillHd scPtr fL sL = + Fl4Spec.setObject scPtr (.schedContext (embSchedContext sc'H) n) sL := by + unfold Fl4Spec.updateRefillHd Fl4Spec.updateSchedContext Fl4Spec.getObject + Fl4Spec.readObject Fl4Spec.setSchedContext + rw [← hsc'] + apply Prod.ext + · ext p + simp [Bind.bind, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, NonDet.pure, hkhL, sc'L] + · simp [Bind.bind, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, NonDet.pure, hkhL, sc'L] + rw [hH_eq, hL_eq] + refine ⟨hstep.1, ?_, ?_⟩ + · intro aH sH' hm + obtain ⟨aL, sL', hmL, ha, hs'⟩ := hstep.2.1 aH sH' hm + have hkh' : sH'.kheap scPtr = some (.SchedContext sc'H n) := by + unfold KHeap_A.set_object KHeap_A.get_object KHeap_A.read_object holSwp at hm + simp [holFunApp, holBind, holGetsThe, holAssertOpt, hkh, holAssert, holGet, holPut, + holReturn, Structures_A.a_type, holEq] at hm + rcases hm with ⟨_, _, _, rfl⟩ + simp [Structures_A.abstract_state.kheap_update] + exact ⟨aL, sL', hmL, ha, hs', sc'H, n, hkh', hne'⟩ + · intro aL sL' hm + obtain ⟨aH, sH', hmH, ha, hs'⟩ := hstep.2.2 aL sL' hm + have hkh' : sH'.kheap scPtr = some (.SchedContext sc'H n) := by + unfold KHeap_A.set_object KHeap_A.get_object KHeap_A.read_object holSwp at hmH + simp [holFunApp, holBind, holGetsThe, holAssertOpt, hkh, holAssert, holGet, holPut, + holReturn, Structures_A.a_type, holEq] at hmH + rcases hmH with ⟨_, _, _, rfl⟩ + simp [Structures_A.abstract_state.kheap_update] + exact ⟨aH, sH', hmH, ha, hs', sc'H, n, hkh', hne'⟩ + +private theorem mrel_whileLoop_guarded {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {CH : αH → σH → Bool} {CL : αL → σL → Prop} + {BH : αH → HolNonDet σH αH} {BL : αL → NonDet σL αL} + (hC : ∀ rH rL, Ra rH rL → ∀ sH sL, Rs sH sL → (CH rH sH = true ↔ CL rL sL)) + (hB : ∀ rH rL, Ra rH rL → ∀ sH sL, Rs sH sL → CH rH sH = true → + ((BH rH sH).2 = true ↔ (BL rL sL).2) ∧ + (∀ aH sH', (aH, sH') ∈ (BH rH sH).1 → ∃ aL sL', (aL, sL') ∈ (BL rL sL).1 ∧ Ra aH aL ∧ Rs sH' sL') ∧ + (∀ aL sL', (aL, sL') ∈ (BL rL sL).1 → ∃ aH sH', (aH, sH') ∈ (BH rH sH).1 ∧ Ra aH aL ∧ Rs sH' sL')) + {rH : αH} {rL : αL} (hr : Ra rH rL) : + MRel Rs Ra (holWhileLoop CH BH rH) (NonDet.whileLoop CL BL rL) := by + have hRes1 : ∀ {rH sH x}, HolWhileResults CH BH rH sH x → + ∀ rL sL, Ra rH rL → Rs sH sL → + ∃ rL' sL', NonDet.WhileResults CL BL rL sL (rL', sL') ∧ Ra x.1 rL' ∧ Rs x.2 sL' := by + intro rH sH x h + induction h with + | @done rH sH hcf => + intro rL sL hr hs + have hnc : ¬CL rL sL := fun hc => by have := (hC rH rL hr sH sL hs).mpr hc; simp [hcf] at this + exact ⟨rL, sL, .done hnc, hr, hs⟩ + | @step rH sH rH' sH' x hct hmem _ ih => + intro rL sL hr hs + have hcL : CL rL sL := (hC rH rL hr sH sL hs).mp hct + obtain ⟨rL', sL', hmemL, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.1 rH' sH' hmem + obtain ⟨rL'', sL'', hres, ha'', hs''⟩ := ih rL' sL' hr' hs' + exact ⟨rL'', sL'', .step hcL hmemL hres, ha'', hs''⟩ + have hRes2 : ∀ {rL sL x}, NonDet.WhileResults CL BL rL sL x → + ∀ rH sH, Ra rH rL → Rs sH sL → + ∃ rH' sH', HolWhileResults CH BH rH sH (rH', sH') ∧ Ra rH' x.1 ∧ Rs sH' x.2 := by + intro rL sL x h + induction h with + | @done rL sL hnc => + intro rH sH hr hs + have hcf : CH rH sH = false := by + cases hc : CH rH sH + · rfl + · exfalso; exact hnc ((hC rH rL hr sH sL hs).mp hc) + exact ⟨rH, sH, .done hcf, hr, hs⟩ + | @step rL sL rL' sL' x hcL hmem _ ih => + intro rH sH hr hs + have hct : CH rH sH = true := (hC rH rL hr sH sL hs).mpr hcL + obtain ⟨rH', sH', hmemH, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.2 rL' sL' hmem + obtain ⟨rH'', sH'', hres, ha'', hs''⟩ := ih rH' sH' hr' hs' + exact ⟨rH'', sH'', .step hct hmemH hres, ha'', hs''⟩ + have hReach1 : ∀ {r0H s0H rH sH}, HolWhileReach CH BH r0H s0H rH sH → + ∀ r0L s0L, Ra r0H r0L → Rs s0H s0L → + ∃ rL sL, NonDet.WhileReach CL BL r0L s0L rL sL ∧ Ra rH rL ∧ Rs sH sL := by + intro r0H s0H rH sH h + induction h with + | start => intro r0L s0L hr0 hs0; exact ⟨r0L, s0L, .start, hr0, hs0⟩ + | @step rH sH rH' sH' _ hct hmem ih => + intro r0L s0L hr0 hs0 + obtain ⟨rL, sL, hreach, hr, hs⟩ := ih r0L s0L hr0 hs0 + have hcL : CL rL sL := (hC rH rL hr sH sL hs).mp hct + obtain ⟨rL', sL', hmemL, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.1 rH' sH' hmem + exact ⟨rL', sL', .step hreach hcL hmemL, hr', hs'⟩ + have hReach2 : ∀ {r0L s0L rL sL}, NonDet.WhileReach CL BL r0L s0L rL sL → + ∀ r0H s0H, Ra r0H r0L → Rs s0H s0L → + ∃ rH sH, HolWhileReach CH BH r0H s0H rH sH ∧ Ra rH rL ∧ Rs sH sL := by + intro r0L s0L rL sL h + induction h with + | start => intro r0H s0H hr0 hs0; exact ⟨r0H, s0H, .start, hr0, hs0⟩ + | @step rL sL rL' sL' _ hcL hmem ih => + intro r0H s0H hr0 hs0 + obtain ⟨rH, sH, hreach, hr, hs⟩ := ih r0H s0H hr0 hs0 + have hct : CH rH sH = true := (hC rH rL hr sH sL hs).mpr hcL + obtain ⟨rH', sH', hmemH, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.2 rL' sL' hmem + exact ⟨rH', sH', .step hreach hct hmemH, hr', hs'⟩ + intro sH sL hs + refine ⟨?_, ?_, ?_⟩ + · simp only [holWhileLoop, NonDet.whileLoop, decide_eq_true_eq] + constructor + · rintro (⟨rH', sH', hreach, hct, hfail⟩ | ⟨fH, hf0, hfstep⟩) + · obtain ⟨rL', sL', hreachL, hr', hs'⟩ := hReach1 hreach rL sL hr hs + exact Or.inl ⟨rL', sL', hreachL, (hC rH' rL' hr' sH' sL' hs').mp hct, + (hB rH' rL' hr' sH' sL' hs' hct).1.mp hfail⟩ + · let stepL : ∀ n, {p : αL × σL // Ra (fH n).1 p.1 ∧ Rs (fH n).2 p.2} := + Nat.rec + ⟨(rL, sL), by rw [hf0]; exact ⟨hr, hs⟩⟩ + (fun n ih => + let h1 := hfstep n + let ex := (hB (fH n).1 ih.1.1 ih.2.1 (fH n).2 ih.1.2 ih.2.2 h1.1).2.1 + (fH (n + 1)).1 (fH (n + 1)).2 h1.2 + ⟨(Classical.choose ex, Classical.choose (Classical.choose_spec ex)), + (Classical.choose_spec (Classical.choose_spec ex)).2⟩) + refine Or.inr ⟨fun n => (stepL n).1, rfl, fun n => ?_⟩ + have h1 := hfstep n + refine ⟨(hC (fH n).1 (stepL n).1.1 (stepL n).2.1 (fH n).2 (stepL n).1.2 (stepL n).2.2).mp h1.1, ?_⟩ + exact (Classical.choose_spec (Classical.choose_spec + ((hB (fH n).1 (stepL n).1.1 (stepL n).2.1 (fH n).2 (stepL n).1.2 (stepL n).2.2 h1.1).2.1 + (fH (n + 1)).1 (fH (n + 1)).2 h1.2))).1 + · rintro (⟨rL', sL', hreach, hcL, hfail⟩ | ⟨fL, hf0, hfstep⟩) + · obtain ⟨rH', sH', hreachH, hr', hs'⟩ := hReach2 hreach rH sH hr hs + have hct := (hC rH' rL' hr' sH' sL' hs').mpr hcL + exact Or.inl ⟨rH', sH', hreachH, hct, + (hB rH' rL' hr' sH' sL' hs' hct).1.mpr hfail⟩ + · let stepH : ∀ n, {p : αH × σH // Ra p.1 (fL n).1 ∧ Rs p.2 (fL n).2} := + Nat.rec + ⟨(rH, sH), by rw [hf0]; exact ⟨hr, hs⟩⟩ + (fun n ih => + let h1 := hfstep n + let hct := (hC ih.1.1 (fL n).1 ih.2.1 ih.1.2 (fL n).2 ih.2.2).mpr h1.1 + let ex := (hB ih.1.1 (fL n).1 ih.2.1 ih.1.2 (fL n).2 ih.2.2 hct).2.2 + (fL (n + 1)).1 (fL (n + 1)).2 h1.2 + ⟨(Classical.choose ex, Classical.choose (Classical.choose_spec ex)), + (Classical.choose_spec (Classical.choose_spec ex)).2⟩) + refine Or.inr ⟨fun n => (stepH n).1, rfl, fun n => ?_⟩ + have h1 := hfstep n + have hct := (hC (stepH n).1.1 (fL n).1 (stepH n).2.1 (stepH n).1.2 (fL n).2 (stepH n).2.2).mpr h1.1 + refine ⟨hct, ?_⟩ + exact (Classical.choose_spec (Classical.choose_spec + ((hB (stepH n).1.1 (fL n).1 (stepH n).2.1 (stepH n).1.2 (fL n).2 (stepH n).2.2 hct).2.2 + (fL (n + 1)).1 (fL (n + 1)).2 h1.2))).1 + · intro aH sH' hmem; exact hRes1 hmem rL sL hr hs + · intro aL sL' hmem; exact hRes2 hmem rH sH hr hs + +theorem mergeOverlappingRefills_equiv_two (scPtr : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (htwo : HasTwoRefills scPtr sH) : + ((Sporadic_A.merge_overlapping_refills scPtr sH).2 = true ↔ + (Fl4Spec.mergeOverlappingRefills scPtr sL).2) ∧ + (∀ aH sH', (aH, sH') ∈ (Sporadic_A.merge_overlapping_refills scPtr sH).1 → + ∃ aL sL', (aL, sL') ∈ (Fl4Spec.mergeOverlappingRefills scPtr sL).1 ∧ + aH = aL ∧ SR sH' sL' ∧ HasNonEmptyRefills scPtr sH') ∧ + (∀ aL sL', (aL, sL') ∈ (Fl4Spec.mergeOverlappingRefills scPtr sL).1 → + ∃ aH sH', (aH, sH') ∈ (Sporadic_A.merge_overlapping_refills scPtr sH).1 ∧ + aH = aL ∧ SR sH' sL' ∧ HasNonEmptyRefills scPtr sH') := by + obtain ⟨sc, n, hkh, hlen⟩ := htwo + cases href : sc.sc_refills with + | nil => simp [href] at hlen + | cons r0 rs => + cases rs with + | nil => simp [href] at hlen + | cons r1 rs' => + -- Evaluate directly via `refillPopHead_equiv` + `updateRefillHd_equiv_nonEmpty` + have hp := refillPopHead_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr sH sL hs + have hp_ne : ∀ rH sH', (rH, sH') ∈ (Sporadic_A.refill_pop_head scPtr sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro rH sH' hm + have hgh : KHeap_A.get_refill_head scPtr sH = ({(r0, sH)}, false) := by + unfold KHeap_A.get_refill_head KHeap_A.read_refill_head KHeap_A.read_sched_context + KHeap_A.read_object holSwp + simp [holGetsThe, holAssertOpt, holOBind, holOAssert, holOReturn, + holReturn, hkh, href, Structures_A.case_kernel_object, holNot, holEq, holHd] + have hgo : KHeap_A.get_object scPtr sH = ({(.SchedContext sc n, sH)}, false) := by + unfold KHeap_A.get_object KHeap_A.read_object holSwp + simp [holFunApp, holGetsThe, holAssertOpt, hkh, holReturn] + unfold Sporadic_A.refill_pop_head KHeap_A.update_sched_context KHeap_A.set_object at hm + simp [holBind, holKBind, hgh, hgo, Structures_A.case_kernel_object, + holAssert, holGet, holPut, holReturn, Structures_A.a_type, holEq] at hm + rcases hm with ⟨_, rfl⟩ + refine ⟨Structures_A.sched_context.sc_refills_update holTl sc, n, ?_, ?_⟩ + · simp [Structures_A.abstract_state.kheap_update] + · simp [Structures_A.sched_context.sc_refills_update, holTl, href] + unfold Sporadic_A.merge_overlapping_refills Fl4Spec.mergeOverlappingRefills + refine ⟨?_, ?_, ?_⟩ + · simp only [holBind, Bind.bind, NonDet.bind, decide_eq_true_eq] + constructor + · rintro (hf | ⟨⟨rH, sH'⟩, hm, hf⟩) + · exact Or.inl (hp.1.mp hf) + · obtain ⟨rL, sL', hmL, hr, hs'⟩ := hp.2.1 rH sH' hm + subst hr + have hupd := updateRefillHd_equiv_nonEmpty (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr (fun r => mergeRefill_eq rH r) sH' sL' ⟨hs', hp_ne rH sH' hm⟩ + exact Or.inr ⟨(embRefill rH, sL'), hmL, hupd.1.mp hf⟩ + · rintro (hf | ⟨⟨rL, sL'⟩, hm, hf⟩) + · exact Or.inl (hp.1.mpr hf) + · obtain ⟨rH, sH', hmH, hr, hs'⟩ := hp.2.2 rL sL' hm + subst hr + have hupd := updateRefillHd_equiv_nonEmpty (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr (fun r => mergeRefill_eq rH r) sH' sL' ⟨hs', hp_ne rH sH' hmH⟩ + exact Or.inr ⟨(rH, sH'), hmH, hupd.1.mpr hf⟩ + · rintro aH sH'' ⟨⟨rH, sH'⟩, hm1, hm2⟩ + obtain ⟨rL, sL', hm1L, hr, hs'⟩ := hp.2.1 rH sH' hm1 + subst hr + have hupd := updateRefillHd_equiv_nonEmpty (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr (fun r => mergeRefill_eq rH r) sH' sL' ⟨hs', hp_ne rH sH' hm1⟩ + obtain ⟨aL, sL'', hm2L, ha, hs'', hne''⟩ := hupd.2.1 aH sH'' hm2 + exact ⟨aL, sL'', ⟨(embRefill rH, sL'), hm1L, hm2L⟩, ha, hs'', hne''⟩ + · rintro aL sL'' ⟨⟨rL, sL'⟩, hm1, hm2⟩ + obtain ⟨rH, sH', hm1H, hr, hs'⟩ := hp.2.2 rL sL' hm1 + subst hr + have hupd := updateRefillHd_equiv_nonEmpty (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr (fun r => mergeRefill_eq rH r) sH' sL' ⟨hs', hp_ne rH sH' hm1H⟩ + obtain ⟨aH, sH'', hm2H, ha, hs'', hne''⟩ := hupd.2.2 aL sL'' hm2 + exact ⟨aH, sH'', ⟨(rH, sH'), hm1H, hm2H⟩, ha, hs'', hne''⟩ + +theorem refillHeadOverlappingLoop_equiv_nonEmpty (scPtr : ObjRef) : + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (Sporadic_A.refill_head_overlapping_loop scPtr) + (Fl4Spec.refillHeadOverlappingLoop scPtr) := by + unfold Sporadic_A.refill_head_overlapping_loop Fl4Spec.refillHeadOverlappingLoop + refine mrel_whileLoop_guarded (Ra := Eq) ?_ ?_ rfl + · intro _ _ _ sH sL ⟨hs, sc, n, hkh, _⟩ + have ho := refillHeadOverlapping_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr sH sL hs + have hsome : ∃ b, Sporadic_A.refill_head_overlapping scPtr sH = some b := by + unfold Sporadic_A.refill_head_overlapping KHeap_A.read_sched_context KHeap_A.read_object holSwp + simp [holOBind, hkh, Structures_A.case_kernel_object, holOReturn] + obtain ⟨b, hb⟩ := hsome + rw [hb] at ho ⊢ + cases hL : Fl4Spec.refillHeadOverlapping scPtr sL with + | none => simp [hL, OptRel] at ho + | some bL => + simp only [hL, OptRel] at ho + subst ho + simp [holTheOpt, the] + · intro _ _ _ sH sL ⟨hs, sc, n, hkh, _⟩ hct + have htwo : HasTwoRefills scPtr sH := by + unfold Sporadic_A.refill_head_overlapping KHeap_A.read_sched_context KHeap_A.read_object holSwp at hct + simp [holOBind, hkh, Structures_A.case_kernel_object, holOReturn, holTheOpt, + holConj_eq_true, holLt_eq_true, HolOrd.ltVal, HolOne.oneVal, holSize_list] at hct + exact ⟨sc, n, hkh, hct.1⟩ + exact mergeOverlappingRefills_equiv_two scPtr hs htwo + +theorem refillUnblockCheck_equiv (scPtr : ObjRef) : + MRel SR Eq + (Sporadic_A.refill_unblock_check scPtr) (Fl4Spec.refillUnblockCheck scPtr) := by + unfold Sporadic_A.refill_unblock_check Fl4Spec.refillUnblockCheck + refine mrel_bind (isRoundRobin_equiv scPtr) fun robH robL hrob => ?_ + subst hrob + -- Track that after `getScRefillReady scPtr` succeeds, `HasNonEmptyRefills scPtr` holds! + have hready : MRel SR + (fun bH bL => bH = bL) + (KHeap_A.get_sc_refill_ready scPtr) (Fl4Spec.getScRefillReady scPtr) := + getScRefillReady_equiv scPtr + intro sH sL hs + obtain ⟨hf, h1, h2⟩ := hready sH sL hs + have hne_after : ∀ b sH', (b, sH') ∈ (KHeap_A.get_sc_refill_ready scPtr sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro b sH' hm + unfold KHeap_A.get_sc_refill_ready KHeap_A.read_sc_refill_ready KHeap_A.read_refill_head + KHeap_A.read_sched_context KHeap_A.read_object holSwp at hm + cases hkh : sH.kheap scPtr with + | none => simp [holGetsThe, holAssertOpt, holOBind, hkh, holFail] at hm + | some ko => + cases ko with + | SchedContext sc n => + by_cases hne : sc.sc_refills = [] + · have hnot : holNot (holEq sc.sc_refills []) = false := by + simp [hne, holNot, holEq] + simp [holGetsThe, holAssertOpt, holOBind, holOAssert, holOReturn, + hkh, hnot, Structures_A.case_kernel_object, holOFail, holFail] at hm + · have hnot : holNot (holEq sc.sc_refills []) = true := by + simp [holNot_eq_true, ne_eq, holEq_eq_true, hne] + simp [holFunApp, holGetsThe, holAssertOpt, holOBind, holOAssert, holAsks, holOReturn, + holReturn, hkh, hnot, Structures_A.case_kernel_object] at hm + rcases hm with ⟨_, rfl⟩ + exact ⟨sc, n, hkh, hne⟩ + | _ => simp [holGetsThe, holAssertOpt, holOBind, hkh, + Structures_A.case_kernel_object, holOFail, holFail] at hm + have hcont : ∀ (rd : Bool) (stH : Structures_A.state ZH) (stL : State ZL), + SR stH stL → HasNonEmptyRefills scPtr stH → + ((holWhen (holConj rd (holNot robH)) + (holBind (holGets Structures_A.abstract_state_ext.cur_time) fun ct => + holBind (Sporadic_A.update_refill_hd scPtr (Structures_A.refill.r_time_update fun _ => ct)) + (holKBind (holBind (holModify fun s => Structures_A.abstract_state.reprogram_timer_update (fun _ => true) s) + (holKBind (Sporadic_A.refill_head_overlapping_loop scPtr))))) stH).2 = true ↔ + (NonDet.when (rd = true ∧ ¬robH = true) (do + let ct ← NonDet.gets fun s : State ZL => s.curTime + Fl4Spec.updateRefillHd scPtr fun r => { r with rTime := ct } + NonDet.modify fun s => { s with reprogramTimer := true } + Fl4Spec.refillHeadOverlappingLoop scPtr) stL).2) ∧ + (∀ aH sH', (aH, sH') ∈ (holWhen (holConj rd (holNot robH)) + (holBind (holGets Structures_A.abstract_state_ext.cur_time) fun ct => + holBind (Sporadic_A.update_refill_hd scPtr (Structures_A.refill.r_time_update fun _ => ct)) + (holKBind (holBind (holModify fun s => Structures_A.abstract_state.reprogram_timer_update (fun _ => true) s) + (holKBind (Sporadic_A.refill_head_overlapping_loop scPtr))))) stH).1 → + ∃ aL sL', (aL, sL') ∈ (NonDet.when (rd = true ∧ ¬robH = true) (do + let ct ← NonDet.gets fun s : State ZL => s.curTime + Fl4Spec.updateRefillHd scPtr fun r => { r with rTime := ct } + NonDet.modify fun s => { s with reprogramTimer := true } + Fl4Spec.refillHeadOverlappingLoop scPtr) stL).1 ∧ aH = aL ∧ SR sH' sL') ∧ + (∀ aL sL', (aL, sL') ∈ (NonDet.when (rd = true ∧ ¬robH = true) (do + let ct ← NonDet.gets fun s : State ZL => s.curTime + Fl4Spec.updateRefillHd scPtr fun r => { r with rTime := ct } + NonDet.modify fun s => { s with reprogramTimer := true } + Fl4Spec.refillHeadOverlappingLoop scPtr) stL).1 → + ∃ aH sH', (aH, sH') ∈ (holWhen (holConj rd (holNot robH)) + (holBind (holGets Structures_A.abstract_state_ext.cur_time) fun ct => + holBind (Sporadic_A.update_refill_hd scPtr (Structures_A.refill.r_time_update fun _ => ct)) + (holKBind (holBind (holModify fun s => Structures_A.abstract_state.reprogram_timer_update (fun _ => true) s) + (holKBind (Sporadic_A.refill_head_overlapping_loop scPtr))))) stH).1 ∧ aH = aL ∧ SR sH' sL') := by + intro rd stH stL hst hne + have hm : MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (holWhen (holConj rd (holNot robH)) + (holBind (holGets Structures_A.abstract_state_ext.cur_time) fun ct => + holBind (Sporadic_A.update_refill_hd scPtr (Structures_A.refill.r_time_update fun _ => ct)) + (holKBind (holBind (holModify fun s => Structures_A.abstract_state.reprogram_timer_update (fun _ => true) s) + (holKBind (Sporadic_A.refill_head_overlapping_loop scPtr)))))) + (NonDet.when (rd = true ∧ ¬robH = true) (do + let ct ← NonDet.gets fun s : State ZL => s.curTime + Fl4Spec.updateRefillHd scPtr fun r => { r with rTime := ct } + NonDet.modify fun s => { s with reprogramTimer := true } + Fl4Spec.refillHeadOverlappingLoop scPtr)) := by + refine mrel_when (by simp [holConj_eq_true, holNot_eq_true]) fun _ => ?_ + refine mrel_bind (mrel_gets fun _ _ h => h.1.curTime_eq.symm) fun ctH ctL hct => ?_ + subst hct + refine mrel_kbind (updateRefillHd_equiv_nonEmpty scPtr (fun _ => rfl)) ?_ + refine mrel_kbind (mrel_modify fun _ _ h => ⟨{ h.1 with reprogramTimer_eq := rfl }, h.2⟩) ?_ + exact refillHeadOverlappingLoop_equiv_nonEmpty scPtr + obtain ⟨cf, c1, c2⟩ := hm stH stL ⟨hst, hne⟩ + exact ⟨cf, fun aH sH' m => by obtain ⟨aL, sL', mL, ha, hs', _⟩ := c1 aH sH' m; exact ⟨aL, sL', mL, ha, hs'⟩, + fun aL sL' m => by obtain ⟨aH, sH', mH, ha, hs', _⟩ := c2 aL sL' m; exact ⟨aH, sH', mH, ha, hs'⟩⟩ + refine ⟨?_, ?_, ?_⟩ + · simp only [holBind, Bind.bind, NonDet.bind, decide_eq_true_eq] + constructor + · rintro (h | ⟨⟨rd, sH'⟩, hm, h⟩) + · exact Or.inl (hf.mp h) + · obtain ⟨rdL, sL', hmL, hrd, hs'⟩ := h1 rd sH' hm + subst hrd + exact Or.inr ⟨(rd, sL'), hmL, (hcont rd sH' sL' hs' (hne_after rd sH' hm)).1.mp h⟩ + · rintro (h | ⟨⟨rdL, sL'⟩, hm, h⟩) + · exact Or.inl (hf.mpr h) + · obtain ⟨rd, sH', hmH, hrd, hs'⟩ := h2 rdL sL' hm + subst hrd + exact Or.inr ⟨(rd, sH'), hmH, (hcont rd sH' sL' hs' (hne_after rd sH' hmH)).1.mpr h⟩ + · rintro aH sH'' ⟨⟨rd, sH'⟩, hm1, hm2⟩ + obtain ⟨rdL, sL', hm1L, hrd, hs'⟩ := h1 rd sH' hm1 + subst hrd + obtain ⟨aL, sL'', hm2L, ha, hs''⟩ := (hcont rd sH' sL' hs' (hne_after rd sH' hm1)).2.1 aH sH'' hm2 + exact ⟨aL, sL'', ⟨(rd, sL'), hm1L, hm2L⟩, ha, hs''⟩ + · rintro aL sL'' ⟨⟨rdL, sL'⟩, hm1, hm2⟩ + obtain ⟨rd, sH', hm1H, hrd, hs'⟩ := h2 rdL sL' hm1 + subst hrd + obtain ⟨aH, sH'', hm2H, ha, hs''⟩ := (hcont rd sH' sL' hs' (hne_after rd sH' hm1H)).2.2 aL sL'' hm2 + exact ⟨aH, sH'', ⟨(rd, sH'), hm1H, hm2H⟩, ha, hs''⟩ + +theorem ifCondRefillUnblockCheck_equiv (scOpt : Option ObjRef) (active asst : Option Bool) : + MRel SR Eq + (Sporadic_A.if_cond_refill_unblock_check scOpt active asst) + (Fl4Spec.ifCondRefillUnblockCheck scOpt active asst) := by + unfold Sporadic_A.if_cond_refill_unblock_check Fl4Spec.ifCondRefillUnblockCheck + refine mrel_maybeM (Ra := Eq) (fun scpH scpL hscp => ?_) (by cases scOpt <;> simp [OptRel]) + subst hscp + refine mrel_bind (getSchedContext_equiv scpH) fun scH scL hsc => ?_ + subst hsc + refine mrel_bind (mrel_gets fun _ _ hs => hs.curSc_eq.symm) fun curH curL hcur => ?_ + subst hcur + refine mrel_bind (Ra := fun gH gL => gH = true ↔ gL) (mrel_return ?_) fun gH gL hg => ?_ + · cases active with + | none => simp [holNot_eq_true, embSchedContext] + | some b => + cases b with + | true => simp [holConj_eq_true, embSchedContext, Fl4Spec.scActive, activeSc_eq] + | false => simp [embSchedContext] + · refine mrel_when (by simp [holConj_eq_true, holImp_eq_true, holEq_eq_true, holNot_eq_true, + ne_eq, hg]) fun _ => ?_ + refine mrel_when (by simp [holImp_eq_true, holEq_eq_true, holNot_eq_true, ne_eq]) fun _ => ?_ + exact refillUnblockCheck_equiv scpH + +theorem ifSporadicCurScAssertRefillUnblockCheck_equiv (scOpt : Option ObjRef) : + MRel SR Eq + (Sporadic_A.if_sporadic_cur_sc_assert_refill_unblock_check scOpt) + (Fl4Spec.ifSporadicCurScAssertRefillUnblockCheck scOpt) := + ifCondRefillUnblockCheck_equiv scOpt (some false) (some true) + +theorem ifSporadicAndActiveRefillUnblockCheck_equiv (scOpt : Option ObjRef) : + MRel SR Eq + (Sporadic_A.if_sporadic_and_active_refill_unblock_check scOpt) + (Fl4Spec.ifSporadicAndActiveRefillUnblockCheck scOpt) := + ifCondRefillUnblockCheck_equiv scOpt (some true) none + +theorem ifSporadicCurScTestRefillUnblockCheck_equiv (scOpt : Option ObjRef) : + MRel SR Eq + (Sporadic_A.if_sporadic_cur_sc_test_refill_unblock_check scOpt) + (Fl4Spec.ifSporadicCurScTestRefillUnblockCheck scOpt) := + ifCondRefillUnblockCheck_equiv scOpt (some false) (some false) + +theorem ifSporadicActiveCurScTestRefillUnblockCheck_equiv (scOpt : Option ObjRef) : + MRel SR Eq + (Sporadic_A.if_sporadic_active_cur_sc_test_refill_unblock_check scOpt) + (Fl4Spec.ifSporadicActiveCurScTestRefillUnblockCheck scOpt) := + ifCondRefillUnblockCheck_equiv scOpt (some true) (some false) + +theorem ifSporadicActiveCurScAssertRefillUnblockCheck_equiv (scOpt : Option ObjRef) : + MRel SR Eq + (Sporadic_A.if_sporadic_active_cur_sc_assert_refill_unblock_check scOpt) + (Fl4Spec.ifSporadicActiveCurScAssertRefillUnblockCheck scOpt) := + ifCondRefillUnblockCheck_equiv scOpt (some true) (some true) + +theorem ifConstantBandwidthRefillUnblockCheck_equiv (scOpt : Option ObjRef) : + MRel SR Eq + (Sporadic_A.if_constant_bandwidth_refill_unblock_check scOpt) + (Fl4Spec.ifConstantBandwidthRefillUnblockCheck scOpt) := + ifCondRefillUnblockCheck_equiv scOpt none none + +end CSpaceAccMonad + + +end + +end L4vRefX64.Equiv.CSpaceAcc diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Decode.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Decode.lean new file mode 100644 index 000000000..bfe6e1d54 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Decode.lean @@ -0,0 +1,2087 @@ +import L4vRefX64.Equiv.CSpace +import L4vRefX64.Equiv.ArchVSpace +import L4vRefX64.Equiv.Schedule +import L4vRefX64.Rel.Invocation +import L4vRefX64.Spec.Decode_A + +namespace L4vRefX64.Equiv.Decode + +open L4vRefX64.Prim L4vRefX64.Rel L4vRefX64.Spec +open L4vRefX64.Equiv.CSpace L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.ArchVSpace +open L4vRefX64.Equiv.Schedule L4vRefX64.Equiv.SchedContext L4vRefX64.Equiv.Machine +open L4vRefX64.Equiv.Retype L4vRefX64.Equiv.Deterministic +open Fl4Spec Classical + +noncomputable section + +private theorem embGenInvocationLabels_injective : Function.Injective embGenInvocationLabels := + Function.LeftInverse.injective unembGenInvocationLabels_emb + +def gen_invocation_type (label : Data) : InvocationLabels_H.gen_invocation_labels := + match Patched.invocation_type label with + | .GenInvocationLabel gen => gen + | .ArchInvocationLabel _ => .InvalidInvocation + +theorem genInvocationType_eq (label : Data) : + Fl4Spec.genInvocationType label = embGenInvocationLabels (gen_invocation_type label) := by + unfold Fl4Spec.genInvocationType gen_invocation_type + rw [← Patched.invocationType_equiv] + cases Patched.invocation_type label <;> rfl + +private theorem allRights_eq : + Fl4Spec.allRights = embRightsSet CapRights_A.all_rights := + embRightsSet_univ.symm + +theorem the_getElem_map {α β : Type} [Nonempty α] [Nonempty β] + (f : α → β) (xs : List α) (i : Nat) (hi : i < xs.length) : + the ((xs.map f)[i]?) = f (holNth xs i) := by + simp only [List.getElem?_map, holNth, holTheOpt, List.getElem?_eq_getElem hi, Option.map_some, the] + +theorem genInvocationLabels_fromEnum_eq (l : InvocationLabels_H.gen_invocation_labels) : + Fl4Spec.GenInvocationLabels.fromEnum (embGenInvocationLabels l) = holFromEnum l := by + unfold Fl4Spec.GenInvocationLabels.fromEnum holFromEnum + change GenInvocationLabels.enum.idxOf (embGenInvocationLabels l) = + holTheIndex InvocationLabels_H.enum_gen_invocation_labels l + rw [← genInvocationLabels_enum_eq] + have hidx : ∀ (xs : List InvocationLabels_H.gen_invocation_labels) + (y : InvocationLabels_H.gen_invocation_labels), + y ∈ xs → (xs.map embGenInvocationLabels).idxOf (embGenInvocationLabels y) = holTheIndex xs y := by + intro xs y hy + induction xs with + | nil => cases hy + | cons x xs ih => + simp only [List.map_cons, List.idxOf_cons, holTheIndex] + by_cases hxy : x = y + · subst hxy; simp + · have hne : (embGenInvocationLabels x == embGenInvocationLabels y) = false := by + simp [embGenInvocationLabels_injective.eq_iff, hxy] + have hne' : x ≠ y := hxy + simp only [hne, show (x = y) ↔ False from by simp [hne'], + Bool.false_eq_true, ite_false] + have hy' : y ∈ xs := by + cases hy with + | head => exact absurd rfl hne' + | tail _ hm => exact hm + rw [ih hy'] + exact hidx _ l (by cases l <;> simp [InvocationLabels_H.enum_gen_invocation_labels]) + +private theorem map_holNth_range'_decode {α β : Type} [Nonempty α] [Nonempty β] (f : α → β) + (xs : List α) (s k : Nat) (h : s + k ≤ xs.length) : + (List.range' s k).map (fun i => the ((xs.map f)[i]?)) = + ((List.range' s k).map (fun i => holNth xs i)).map f := by + induction k generalizing s with + | zero => rfl + | succ k ih => + rw [List.range', List.map_cons, List.map_cons, List.map_cons] + congr 1 + · simp only [List.getElem?_map, holNth, holTheOpt] + have hlt : s < xs.length := by omega + rw [List.getElem?_eq_getElem hlt] + rfl + · exact ih (s + 1) (by omega) + +theorem genInvocationLabels_uptoEnum_eq (a b : InvocationLabels_H.gen_invocation_labels) : + Fl4Spec.GenInvocationLabels.uptoEnum (embGenInvocationLabels a) (embGenInvocationLabels b) = + (holUptoEnum a b).map embGenInvocationLabels := by + unfold Fl4Spec.GenInvocationLabels.uptoEnum Fl4Spec.GenInvocationLabels.toEnum + holUptoEnum holListUpt holToEnum + rw [genInvocationLabels_fromEnum_eq, genInvocationLabels_fromEnum_eq, ← genInvocationLabels_enum_eq] + change (List.range' (holFromEnum a) (holFromEnum b + 1 - holFromEnum a)).map + (fun i => the ((InvocationLabels_H.enum_gen_invocation_labels.map embGenInvocationLabels)[i]?)) = + ((List.range' (holFromEnum a) (holFromEnum b + 1 - holFromEnum a)).map + (fun i => holNth InvocationLabels_H.enum_gen_invocation_labels i)).map embGenInvocationLabels + have hlen : InvocationLabels_H.enum_gen_invocation_labels.length = 39 := by + simp [InvocationLabels_H.enum_gen_invocation_labels] + have hb : holFromEnum b < 39 := by + cases b <;> + simp [holFromEnum, HolEnum.enumList, InvocationLabels_H.enum_gen_invocation_labels, holTheIndex] + by_cases hle : holFromEnum a ≤ holFromEnum b + 1 + · exact map_holNth_range'_decode embGenInvocationLabels _ _ _ (by omega) + · have hsub : holFromEnum b + 1 - holFromEnum a = 0 := by omega + simp [hsub] + +theorem mem_uptoEnum_genInvocationLabels_iff (x a b : InvocationLabels_H.gen_invocation_labels) : + holMember x (holListSet (holUptoEnum a b)) = true ↔ + embGenInvocationLabels x ∈ + Fl4Spec.GenInvocationLabels.uptoEnum (embGenInvocationLabels a) (embGenInvocationLabels b) := by + rw [genInvocationLabels_uptoEnum_eq, holMember_eq_true, holListSet] + constructor + · intro hx; exact List.mem_map.mpr ⟨x, hx, rfl⟩ + · intro hx + rcases List.mem_map.mp hx with ⟨y, hy, heq⟩ + have := embGenInvocationLabels_injective heq + subst this; exact hy + +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 + +def ensure_empty_p (slot : CslotPtr) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Unit) := + holBindE (holLiftE (get_cap_p slot)) fun cap => + holWhenE (holNot (holEq cap .NullCap)) (holThrowError .DeleteFirst) + +theorem patched_ensureEmpty_equiv (slot : CslotPtr) : + MRelE SR (FunRel embSyscallError) Eq + (ensure_empty_p slot) (Fl4Spec.ensureEmpty slot) := by + unfold ensure_empty_p Fl4Spec.ensureEmpty + refine mrele_bindE (mrele_liftE (patched_getCap_equiv slot)) fun cH cL hc => ?_ + subst hc + have hneq : holNot (holEq cH .NullCap) = true ↔ embCap cH ≠ .nullCap := by + cases cH <;> simp [embCap, holNot, holEq] + exact mrele_whenE hneq fun _ => mrele_throwError rfl + +theorem patched_lookupTargetSlot_equiv (croot : Structures_A.cap) (ptr : CapRef) (depth : Nat) : + MRelE SR (FunRel embSyscallError) Eq + (lookup_target_slot_p croot ptr depth) + (Fl4Spec.lookupTargetSlot (embCap croot) ptr depth) := + patched_lookupSlotForCnodeOp_equiv false croot ptr depth + +theorem patched_lookupSourceSlot_equiv (croot : Structures_A.cap) (ptr : CapRef) (depth : Nat) : + MRelE SR (FunRel embSyscallError) Eq + (lookup_source_slot_p croot ptr depth) + (Fl4Spec.lookupSourceSlot (embCap croot) ptr depth) := + patched_lookupSlotForCnodeOp_equiv true croot ptr depth + +theorem patched_lookupPivotSlot_equiv (croot : Structures_A.cap) (ptr : CapRef) (depth : Nat) : + MRelE SR (FunRel embSyscallError) Eq + (lookup_pivot_slot_p croot ptr depth) + (Fl4Spec.lookupPivotSlot (embCap croot) ptr depth) := + patched_lookupSlotForCnodeOp_equiv true croot ptr depth + +def decode_cnode_invocation_p (label : Data) (args : List Data) (cap : Structures_A.cap) + (excaps : List Structures_A.cap) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.cnode_invocation) := + holBindE (holUnlessE (holMember (gen_invocation_type label) + (holListSet (holUptoEnum .CNodeRevoke .CNodeRotate))) (holThrowError .IllegalOperation)) (holKBind + (holBindE (holWhenE (holLt args.length 2) (holThrowError .TruncatedMessage)) (holKBind + (holBindE (holReturnOk (Machine_A.data_to_cptr (holNth args 0))) fun index => + holBindE (holReturnOk (Machine_A.data_to_nat (holNth args 1))) fun bits => + holBindE (holReturnOk (args.drop 2)) fun args1 => + holBindE (lookup_target_slot_p cap index bits) fun dest_slot => + if 2 ≤ args1.length ∧ 0 < excaps.length ∧ + holMember (gen_invocation_type label) + (holListSet (holUptoEnum .CNodeCopy .CNodeMutate)) = true then + holBindE (holReturnOk (Machine_A.data_to_cptr (holNth args1 0))) fun src_index => + holBindE (holReturnOk (Machine_A.data_to_nat (holNth args1 1))) fun src_depth => + holBindE (holReturnOk (args1.drop 2)) fun args2 => + holBindE (holReturnOk (holNth excaps 0)) fun src_root_cap => + holBindE (ensure_empty_p dest_slot) (holKBind + (holBindE (lookup_source_slot_p src_root_cap src_index src_depth) fun src_slot => + holBindE (holLiftE (get_cap_p src_slot)) fun src_cap => + holBindE (holWhenE (holEq src_cap .NullCap) + (holThrowError (.FailedLookup true (.MissingCapability src_depth)))) (holKBind + (holBindE (match gen_invocation_type label, args2 with + | .CNodeCopy, rw :: _ => + holBindE (holReturnOk (CSpace_A.data_to_rights rw)) fun rights => + holReturnOk (rights, none, false) + | .CNodeMint, rw :: cd :: _ => + holBindE (holReturnOk (CSpace_A.data_to_rights rw)) fun rights => + holReturnOk (rights, some cd, false) + | .CNodeMove, _ => holReturnOk (CapRights_A.all_rights, none, true) + | .CNodeMutate, cd :: _ => holReturnOk (CapRights_A.all_rights, some cd, true) + | _, _ => holThrowError .TruncatedMessage) fun (rights, cap_data, is_move) => + holBindE (holReturnOk (Structures_A.mask_cap rights src_cap)) fun src_cap1 => + holBindE ((if is_move then holReturnOk else CSpace_A.derive_cap src_slot) + (match cap_data with + | some w => CSpace_A.update_cap_data is_move w src_cap1 + | none => src_cap1)) fun new_cap => + holBindE (holWhenE (holEq new_cap .NullCap) (holThrowError .IllegalOperation)) (holKBind + (holReturnOk ((if is_move then Invocations_A.cnode_invocation.MoveCall else .InsertCall) + new_cap src_slot dest_slot))))))) + else if holEq (gen_invocation_type label) .CNodeRevoke = true then + holReturnOk (.RevokeCall dest_slot) + else if holEq (gen_invocation_type label) .CNodeDelete = true then + holReturnOk (.DeleteCall dest_slot) + else if holEq (gen_invocation_type label) .CNodeCancelBadgedSends = true then + holBindE (holLiftE (get_cap_p dest_slot)) fun cap1 => + holBindE (holUnlessE (CSpace_A.has_cancel_send_rights cap1) (holThrowError .IllegalOperation)) (holKBind + (holReturnOk (.CancelBadgedSendsCall cap1))) + else if holEq (gen_invocation_type label) .CNodeRotate = true ∧ + 5 < args1.length ∧ 1 < excaps.length then + holBindE (holReturnOk (holNth args1 0)) fun pivot_new_data => + holBindE (holReturnOk (Machine_A.data_to_cptr (holNth args1 1))) fun pivot_index => + holBindE (holReturnOk (Machine_A.data_to_nat (holNth args1 2))) fun pivot_depth => + holBindE (holReturnOk (holNth args1 3)) fun src_new_data => + holBindE (holReturnOk (Machine_A.data_to_cptr (holNth args1 4))) fun src_index => + holBindE (holReturnOk (Machine_A.data_to_nat (holNth args1 5))) fun src_depth => + holBindE (holReturnOk (holNth excaps 0)) fun pivot_root_cap => + holBindE (holReturnOk (holNth excaps 1)) fun src_root_cap => + holBindE (lookup_source_slot_p src_root_cap src_index src_depth) fun src_slot => + holBindE (lookup_pivot_slot_p pivot_root_cap pivot_index pivot_depth) fun pivot_slot => + holBindE (holWhenE (holDisj (holEq pivot_slot src_slot) (holEq pivot_slot dest_slot)) + (holThrowError .IllegalOperation)) (holKBind + (holBindE (holUnlessE (holEq src_slot dest_slot) (ensure_empty_p dest_slot)) (holKBind + (holBindE (holLiftE (get_cap_p src_slot)) fun src_cap => + holBindE (holWhenE (holEq src_cap .NullCap) + (holThrowError (.FailedLookup true (.MissingCapability src_depth)))) (holKBind + (holBindE (holLiftE (get_cap_p pivot_slot)) fun pivot_cap => + holBindE (holWhenE (holEq pivot_cap .NullCap) + (holThrowError (.FailedLookup false (.MissingCapability pivot_depth)))) (holKBind + (holBindE (holReturnOk (CSpace_A.update_cap_data true src_new_data src_cap)) fun new_src_cap => + holBindE (holReturnOk (CSpace_A.update_cap_data true pivot_new_data pivot_cap)) fun new_pivot_cap => + holBindE (holWhenE (holEq new_src_cap .NullCap) (holThrowError .IllegalOperation)) (holKBind + (holBindE (holWhenE (holEq new_pivot_cap .NullCap) (holThrowError .IllegalOperation)) (holKBind + (holReturnOk (.RotateCall new_src_cap new_pivot_cap src_slot pivot_slot dest_slot))))))))))))) + else holThrowError .TruncatedMessage)))) + +theorem patched_decodeCnodeInvocation_equiv (label : Data) (args : List Data) + (cap : Structures_A.cap) (excaps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embCnodeInv) + (decode_cnode_invocation_p label args cap excaps) + (Fl4Spec.decodeCnodeInvocation label args (embCap cap) (excaps.map embCap)) := by + unfold decode_cnode_invocation_p Fl4Spec.decodeCnodeInvocation + refine mrele_kbindE (mrele_unlessE + (by rw [genInvocationType_eq]; exact mem_uptoEnum_genInvocationLabels_iff _ .CNodeRevoke .CNodeRotate) + fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE (by rw [holLt_eq_true]; rfl) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun idxH idxL hidx => ?_ + subst hidx + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun bitsH bitsL hbits => ?_ + subst hbits + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun a1H a1L ha1 => ?_ + subst ha1 + refine mrele_bindE (patched_lookupTargetSlot_equiv cap idxH bitsH) fun dsH dsL hds => ?_ + subst hds + have hcond1 : (2 ≤ a1H.length ∧ 0 < excaps.length ∧ + holMember (gen_invocation_type label) + (holListSet (holUptoEnum .CNodeCopy .CNodeMutate)) = true) ↔ + (a1H.length ≥ 2 ∧ (excaps.map embCap).length > 0 ∧ + Fl4Spec.genInvocationType label ∈ + Fl4Spec.GenInvocationLabels.uptoEnum .cnodeCopy .cnodeMutate) := by + rw [genInvocationType_eq, mem_uptoEnum_genInvocationLabels_iff _ .CNodeCopy .CNodeMutate, + List.length_map] + rfl + by_cases h1 : 2 ≤ a1H.length ∧ 0 < excaps.length ∧ + holMember (gen_invocation_type label) + (holListSet (holUptoEnum .CNodeCopy .CNodeMutate)) = true + · rw [ite_eq_left h1, ite_eq_left (hcond1.mp h1)] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun siH siL hsi => ?_ + subst hsi + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun sdH sdL hsd => ?_ + subst hsd + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun a2H a2L ha2 => ?_ + subst ha2 + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (the_getElem_map embCap excaps 0 h1.2.1)) + fun srH srL hsr => ?_ + subst hsr + refine mrele_kbindE (patched_ensureEmpty_equiv dsH) ?_ + refine mrele_bindE (patched_lookupSourceSlot_equiv srH siH sdH) fun ssH ssL hss => ?_ + subst hss + refine mrele_bindE (mrele_liftE (patched_getCap_equiv ssH)) fun scH scL hsc => ?_ + subst hsc + have hnull : holEq scH .NullCap = true ↔ embCap scH = .nullCap := by + cases scH <;> simp [embCap, holEq] + refine mrele_kbindE (mrele_whenE hnull fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (Ra := ProdRel (FunRel embRightsSet) (ProdRel Eq Eq)) (by + rw [genInvocationType_eq] + cases gen_invocation_type label with + | CNodeCopy => + cases a2H with + | nil => exact mrele_throwError rfl + | cons rw tl => + refine mrele_bindE (mrele_returnOk (Ra := FunRel embRightsSet) (dataToRights_eq rw)) fun rH rL hr => ?_ + subst hr + exact mrele_returnOk ⟨rfl, rfl, rfl⟩ + | CNodeMint => + cases a2H with + | nil => exact mrele_throwError rfl + | cons rw tl => + cases tl with + | nil => exact mrele_throwError rfl + | cons cd tl2 => + refine mrele_bindE (mrele_returnOk (Ra := FunRel embRightsSet) (dataToRights_eq rw)) fun rH rL hr => ?_ + subst hr + exact mrele_returnOk ⟨rfl, rfl, rfl⟩ + | CNodeMove => + exact mrele_returnOk ⟨allRights_eq, rfl, rfl⟩ + | CNodeMutate => + cases a2H with + | nil => exact mrele_throwError rfl + | cons cd tl => exact mrele_returnOk ⟨allRights_eq, rfl, rfl⟩ + | _ => exact mrele_throwError rfl) ?_ + rintro ⟨rH, cdH, imH⟩ ⟨rL, cdL, imL⟩ ⟨hr, hcd, him⟩ + subst hr; subst hcd; subst him + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (maskCap_eq rH scH)) fun sc1H sc1L hsc1 => ?_ + subst hsc1 + refine mrele_bindE (Ra := FunRel embCap) ?_ fun ncH ncL hnc => ?_ + · cases imH with + | true => + cases cdH with + | none => exact mrele_returnOk rfl + | some w => exact mrele_returnOk (updateCapData_eq true w sc1H) + | false => + cases cdH with + | none => exact deriveCap_equiv ssH sc1H + | some w => + dsimp only + rw [updateCapData_eq false w sc1H] + exact deriveCap_equiv ssH _ + subst hnc + have hncNull : holEq ncH .NullCap = true ↔ embCap ncH = .nullCap := by + cases ncH <;> simp [embCap, holEq] + refine mrele_kbindE (mrele_whenE hncNull fun _ => mrele_throwError rfl) ?_ + cases imH <;> exact mrele_returnOk rfl + · rw [ite_eq_right h1, ite_eq_right (mt hcond1.mpr h1)] + have hmRev : holEq (gen_invocation_type label) .CNodeRevoke = true ↔ + Fl4Spec.genInvocationType label = .cnodeRevoke := by + rw [genInvocationType_eq, holEq_eq_true]; exact embGenInvocationLabels_injective.eq_iff.symm + by_cases h2 : holEq (gen_invocation_type label) .CNodeRevoke = true + · rw [ite_eq_left h2, ite_eq_left (hmRev.mp h2)]; exact mrele_returnOk rfl + · rw [ite_eq_right h2, ite_eq_right (mt hmRev.mpr h2)] + have hmDel : holEq (gen_invocation_type label) .CNodeDelete = true ↔ + Fl4Spec.genInvocationType label = .cnodeDelete := by + rw [genInvocationType_eq, holEq_eq_true]; exact embGenInvocationLabels_injective.eq_iff.symm + by_cases h3 : holEq (gen_invocation_type label) .CNodeDelete = true + · rw [ite_eq_left h3, ite_eq_left (hmDel.mp h3)]; exact mrele_returnOk rfl + · rw [ite_eq_right h3, ite_eq_right (mt hmDel.mpr h3)] + have hmCan : holEq (gen_invocation_type label) .CNodeCancelBadgedSends = true ↔ + Fl4Spec.genInvocationType label = .cnodeCancelBadgedSends := by + rw [genInvocationType_eq, holEq_eq_true]; exact embGenInvocationLabels_injective.eq_iff.symm + by_cases h4 : holEq (gen_invocation_type label) .CNodeCancelBadgedSends = true + · rw [ite_eq_left h4, ite_eq_left (hmCan.mp h4)] + refine mrele_bindE (mrele_liftE (patched_getCap_equiv dsH)) fun c1H c1L hc1 => ?_ + subst hc1 + refine mrele_kbindE (mrele_unlessE (hasCancelSendRights_iff c1H) fun _ => + mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + · rw [ite_eq_right h4, ite_eq_right (mt hmCan.mpr h4)] + have hmRot : (holEq (gen_invocation_type label) .CNodeRotate = true ∧ + 5 < a1H.length ∧ 1 < excaps.length) ↔ + (Fl4Spec.genInvocationType label = .cnodeRotate ∧ a1H.length > 5 ∧ + (excaps.map embCap).length > 1) := by + rw [genInvocationType_eq, holEq_eq_true, List.length_map, + embGenInvocationLabels_injective.eq_iff.symm] + rfl + by_cases h5 : holEq (gen_invocation_type label) .CNodeRotate = true ∧ + 5 < a1H.length ∧ 1 < excaps.length + · rw [ite_eq_left h5, ite_eq_left (hmRot.mp h5)] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pndH pndL hpnd => ?_ + subst hpnd + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun piH piL hpi => ?_ + subst hpi + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pdH pdL hpd => ?_ + subst hpd + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun sndH sndL hsnd => ?_ + subst hsnd + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun siH siL hsi => ?_ + subst hsi + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun sdH sdL hsd => ?_ + subst hsd + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (the_getElem_map embCap excaps 0 (by omega))) + fun prH prL hpr => ?_ + subst hpr + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (the_getElem_map embCap excaps 1 h5.2.2)) + fun srH srL hsr => ?_ + subst hsr + refine mrele_bindE (patched_lookupSourceSlot_equiv srH siH sdH) fun ssH ssL hss => ?_ + subst hss + refine mrele_bindE (patched_lookupPivotSlot_equiv prH piH pdH) fun psH psL hps => ?_ + subst hps + refine mrele_kbindE (mrele_whenE (by simp [holDisj_eq_true, holEq_eq_true]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_unlessE (by rw [holEq_eq_true]) fun _ => + patched_ensureEmpty_equiv dsH) ?_ + refine mrele_bindE (mrele_liftE (patched_getCap_equiv ssH)) fun scH scL hsc => ?_ + subst hsc + have hscNull : holEq scH .NullCap = true ↔ embCap scH = .nullCap := by + cases scH <;> simp [embCap, holEq] + refine mrele_kbindE (mrele_whenE hscNull fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (patched_getCap_equiv psH)) fun pcH pcL hpc => ?_ + subst hpc + have hpcNull : holEq pcH .NullCap = true ↔ embCap pcH = .nullCap := by + cases pcH <;> simp [embCap, holEq] + refine mrele_kbindE (mrele_whenE hpcNull fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (updateCapData_eq true sndH scH)) + fun nscH nscL hnsc => ?_ + subst hnsc + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (updateCapData_eq true pndH pcH)) + fun npcH npcL hnpc => ?_ + subst hnpc + have hnscNull : holEq nscH .NullCap = true ↔ embCap nscH = .nullCap := by + cases nscH <;> simp [embCap, holEq] + have hnpcNull : holEq npcH .NullCap = true ↔ embCap npcH = .nullCap := by + cases npcH <;> simp [embCap, holEq] + refine mrele_kbindE (mrele_whenE hnscNull fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE hnpcNull fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + · rw [ite_eq_right h5, ite_eq_right (mt hmRot.mpr h5)] + exact mrele_throwError rfl + +private theorem mrele_kbindE_throwError {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Rb : βH → βL → Prop} + {eH : εH} {eL : εL} (he : Re eH eL) + {gH : αH → HolNonDet σH (Sum εH βH)} {gL : αL → NonDetE σL εL βL} : + MRelE Rs Re Rb (holBindE (holThrowError eH) gH) + (NonDetE.throwError eL >>= gL) := + mrele_bindE (Ra := fun _ _ => False) (mrele_throwError he) (fun _ _ h => False.elim h) + +theorem mrele_kbindE_whenE_throw' {σH σL εH εL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Rb : βH → βL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {eH : εH} {eL : εL} (he : Re eH eL) + {gH : HolNonDet σH (Sum εH βH)} {gL : NonDetE σL εL βL} + (hg : ¬P → MRelE Rs Re Rb gH gL) : + MRelE Rs Re Rb (holBindE (holWhenE b (holThrowError eH)) (holKBind gH)) + (NonDetE.whenE P (NonDetE.throwError eL) >>= fun _ => gL) := by + by_cases hp : P + · have hb : b = true := h.mpr hp + unfold holWhenE NonDetE.whenE + simp only [hb, hp, ite_true] + exact mrele_kbindE_throwError he + · have hb : b = false := Bool.eq_false_iff.mpr (mt h.mp hp) + unfold holWhenE NonDetE.whenE + simp only [hb, hp, ite_false] + exact mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) (hg hp) + +private theorem the_head_map {α β : Type} [Nonempty α] [Nonempty β] + (f : α → β) (xs : List α) (hne : xs ≠ []) : + the ((xs.map f).head?) = f (holHd xs) := by + cases xs with + | nil => exact absurd rfl hne + | cons x _ => rfl + +theorem parseTimeArg_eq (i : Nat) (args : List Word) (hi : i < args.length) : + Fl4Spec.parseTimeArg i args = Arch_Structs_B.parseTimeArg i args := by + unfold Fl4Spec.parseTimeArg Arch_Structs_B.parseTimeArg + simp [holUcast, holNth, holTheOpt, Fl4Spec.the, List.getElem?_eq_getElem hi] + +theorem parseTimeArgA_eq (i : Nat) (args : List Word) (hi : i < args.length) : + Fl4Spec.parseTimeArgA i args = Arch_Structs_A.parse_time_arg i args := by + unfold Fl4Spec.parseTimeArgA Arch_Structs_A.parse_time_arg + simp [holUcast, holNth, holTheOpt, Fl4Spec.the, List.getElem?_eq_getElem hi] + +theorem decodeDomainSet_equiv (hc : ConfigRel) (args : List Data) + (excs : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embDomainInv) + (Decode_A.decode_domain_set args excs) + (Fl4Spec.decodeDomainSet args (excs.map fun p => (embCap p.1, p.2))) := by + unfold Decode_A.decode_domain_set Fl4Spec.decodeDomainSet + dsimp only [holFunApp] + refine mrele_bindE (Ra := Eq) ?_ fun domH domL hdom => ?_ + · cases args with + | nil => exact mrele_throwError rfl + | cons x xs => + simp only [holCaseList] + refine mrele_kbindE (mrele_whenE (by rw [Fl4Spec.numDomains, hc.numDomains_eq, holLe_eq_true]; rfl) fun _ => + mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + subst hdom + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hneE : excs ≠ [] := by intro h; simp [h] at hne + have hhd : (the ((excs.map fun p => (embCap p.1, p.2)).head?)).1 = + embCap (holHd excs).1 := by + rw [the_head_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) excs hneE] + rw [hhd] + cases (holHd excs).1 with + | ThreadCap ptr => exact mrele_returnOk rfl + | _ => exact mrele_throwError rfl + +theorem decodeDomainScheduleSetStart_equiv (args : List Data) : + MRelE SR (FunRel embSyscallError) (FunRel embDomainInv) + (Decode_A.decode_domain_schedule_set_start args) + (Fl4Spec.decodeDomainScheduleSetStart args) := by + unfold Decode_A.decode_domain_schedule_set_start Fl4Spec.decodeDomainScheduleSetStart + dsimp only [holFunApp] + refine mrele_kbindE (mrele_whenE (by simp [holEq_eq_true, holSize_list, HolZero.zeroVal]) fun _ => + mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun idxH idxL hidx => ?_ + subst hidx + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun sH sL hs => hs.domainList_eq.symm)) fun scH scL hsc => ?_ + subst hsc + refine mrele_kbindE (mrele_whenE (by rw [holLe_eq_true]; rfl) fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE (by rw [domainEndMarker_eq, holEq_eq_true]; rfl) fun _ => + mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + +theorem decodeDomainScheduleConfigure_equiv (hc : ConfigRel) (args : List Data) : + MRelE SR (FunRel embSyscallError) (FunRel embDomainInv) + (Decode_A.decode_domain_schedule_configure args) + (Fl4Spec.decodeDomainScheduleConfigure args) := by + unfold Decode_A.decode_domain_schedule_configure Fl4Spec.decodeDomainScheduleConfigure + dsimp only [holFunApp] + have htlen : Fl4Spec.timeArgLen = Structs_B.timeArgLen := rfl + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hge => ?_ + · rw [htlen, holLt_eq_true]; rfl + have h2lt : 2 < args.length := by + have h1 : Fl4Spec.timeArgLen = 1 := rfl + omega + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun idxH idxL hidx => ?_ + subst hidx + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun domH domL hdom => ?_ + subst hdom + refine mrele_bindE (mrele_returnOk (Ra := Eq) (parseTimeArg_eq 2 args h2lt).symm) fun durH durL hdur => ?_ + subst hdur + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun sH sL hs => hs.domainList_eq.symm)) fun scH scL hsc => ?_ + subst hsc + refine mrele_kbindE (mrele_whenE (by rw [holLe_eq_true]; rfl) fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE (by rw [Fl4Spec.numDomains, hc.numDomains_eq, holLe_eq_true]; rfl) fun _ => + mrele_throwError (by rw [Fl4Spec.numDomains, hc.numDomains_eq]; rfl)) ?_ + have hmaxd : Fl4Spec.maxDomainDuration = Structures_A.max_domain_duration := by + unfold Fl4Spec.maxDomainDuration Structures_A.max_domain_duration Fl4Spec.domainDurationLen + rfl + refine mrele_kbindE (mrele_whenE (by rw [hmaxd, holLt_eq_true]; rfl) fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE (by simp [holConj_eq_true, holNot_eq_true, holEq_eq_true, HolZero.zeroVal]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun sH sL hs => hs.domainStartIndex_eq.symm)) fun stH stL hst => ?_ + subst hst + refine mrele_kbindE (mrele_whenE (by simp [holConj_eq_true, holEq_eq_true, HolZero.zeroVal]) + fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + +def decode_domain_invocation_p {tv_z : Type} [Nonempty tv_z] [Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((List (Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((Structures_A.abstract_state_ext (Structures_A.state_ext tv_z Unit)) → ((Set ((Sum ExceptionTypes_A.syscall_error Invocations_A.domain_invocation) × (Structures_A.abstract_state_ext (Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (excs : (List (Structures_A.cap × ((BitVec 64) × (List Bool))))) => (InvocationLabels_H.case_gen_invocation_labels ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (Decode_A.decode_domain_set args excs) (Decode_A.decode_domain_schedule_configure args) (Decode_A.decode_domain_schedule_set_start args) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Invocations_A.domain_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (gen_invocation_type label))))) + +theorem decodeDomainInvocation_equiv (hc : ConfigRel) (label : Data) (args : List Data) + (excs : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embDomainInv) + (decode_domain_invocation_p label args excs) + (Fl4Spec.decodeDomainInvocation label args (excs.map fun p => (embCap p.1, p.2))) := by + unfold decode_domain_invocation_p Fl4Spec.decodeDomainInvocation + rw [genInvocationType_eq] + cases gen_invocation_type label + all_goals try exact mrele_throwError rfl + · exact decodeDomainSet_equiv hc args excs + · exact decodeDomainScheduleConfigure_equiv hc args + · exact decodeDomainScheduleSetStart_equiv args + +/-! ### `Decode_A`: scheduling contexts & sched control -/ + +theorem decodeSchedContextBind_equiv (scPtr : ObjRef) (excaps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embSchedContextInv) + (Decode_A.decode_sched_context_bind scPtr excaps) + (Fl4Spec.decodeSchedContextBind scPtr (excaps.map embCap)) := by + unfold Decode_A.decode_sched_context_bind Fl4Spec.decodeSchedContextBind + dsimp only [holFunApp] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hneE : excaps ≠ [] := by intro h; simp [h] at hne + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (the_head_map embCap excaps hneE)) fun cH cL hc => ?_ + subst hc + refine mrele_bindE (mrele_liftE (getSchedContext_equiv scPtr)) fun scH scL hsc => ?_ + subst hsc + cases cH with + | ThreadCap tcbPtr => + simp only [Structures_A.case_cap, embCap, holBindE_assoc, holKBind] + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true, embSchedContext]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (getTcbObjRef_equiv (fun _ => rfl) tcbPtr)) fun soH soL hso => ?_ + subst hso + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (getThreadState_equiv tcbPtr)) fun stH stL hst => ?_ + subst hst + refine mrele_bindE (mrele_liftE (getScReleased_equiv scPtr)) fun relH relL hrel => ?_ + subst hrel + refine mrele_kbindE (mrele_whenE (by rw [ipcQueuedThreadState_eq]; simp [holConj_eq_true, holNot_eq_true]) + fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + | NotificationCap ntfnPtr b r => + simp only [Structures_A.case_cap, embCap, holBindE_assoc, holKBind] + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true, embSchedContext]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (getNtfnObjRef_equiv (fun _ => rfl) ntfnPtr)) fun soH soL hso => ?_ + subst hso + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + | _ => + simp only [Structures_A.case_cap, embCap] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + +theorem decodeSchedContextUnbindObject_equiv (scPtr : ObjRef) (excaps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embSchedContextInv) + (Decode_A.decode_sched_context_unbind_object scPtr excaps) + (Fl4Spec.decodeSchedContextUnbindObject scPtr (excaps.map embCap)) := by + unfold Decode_A.decode_sched_context_unbind_object Fl4Spec.decodeSchedContextUnbindObject + dsimp only [holFunApp] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hneE : excaps ≠ [] := by intro h; simp [h] at hne + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (the_head_map embCap excaps hneE)) fun cH cL hc => ?_ + subst hc + cases cH with + | ThreadCap tcbPtr => + simp only [Structures_A.case_cap, embCap, holBindE_assoc, holKBind] + refine mrele_bindE (mrele_liftE (getScObjRef_equiv (fun _ => rfl) scPtr)) fun stH stL hst => ?_ + subst hst + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun sH sL hs => hs.curThread_eq.symm)) fun ctH ctL hct => ?_ + subst hct + refine mrele_kbindE (mrele_whenE (by rw [holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + | NotificationCap ntfnPtr b r => + simp only [Structures_A.case_cap, embCap, holBindE_assoc] + refine mrele_bindE (mrele_liftE (getScObjRef_equiv (fun _ => rfl) scPtr)) fun snH snL hsn => ?_ + subst hsn + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + | _ => + simp only [Structures_A.case_cap, embCap] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + +theorem decodeSchedContextYieldTo_equiv (scPtr : ObjRef) : + MRelE SR (FunRel embSyscallError) (FunRel embSchedContextInv) + (Decode_A.decode_sched_context_yield_to scPtr) + (Fl4Spec.decodeSchedContextYieldTo scPtr) := by + unfold Decode_A.decode_sched_context_yield_to Fl4Spec.decodeSchedContextYieldTo + dsimp only [holFunApp] + refine mrele_bindE (mrele_liftE (getScObjRef_equiv (fun _ => rfl) scPtr)) fun stH stL hst => ?_ + subst hst + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · rw [holEq_eq_true] + have hthe : the stH = holTheOpt stH := by + cases stH with + | none => exact absurd rfl hne + | some _ => rfl + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun sH sL hs => hs.curThread_eq.symm)) fun ctH ctL hct => ?_ + subst hct + refine mrele_kbindE (mrele_whenE (by rw [holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (by rw [hthe]; exact threadGet_equiv (Ra := Eq) (fun _ => rfl) _)) + fun prH prL hpr => ?_ + subst hpr + refine mrele_bindE (mrele_liftE (threadGet_equiv (Ra := Eq) (fun _ => rfl) ctH)) fun mcpH mcpL hmcp => ?_ + subst hmcp + refine mrele_kbindE (mrele_whenE (by rw [holLt_eq_true]; rfl) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (threadGet_equiv (Ra := Eq) (fun _ => rfl) ctH)) fun ytH ytL hyt => ?_ + subst hyt + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true, holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + +def decode_sched_context_invocation_p {tv_z : Type} [Nonempty tv_z] [Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((List Structures_A.cap) → ((Structures_A.abstract_state_ext (Structures_A.state_ext tv_z Unit)) → ((Set ((Sum ExceptionTypes_A.syscall_error Invocations_A.sched_context_invocation) × (Structures_A.abstract_state_ext (Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (sc_ptr : (BitVec 64)) => (fun (excaps : (List Structures_A.cap)) => (InvocationLabels_H.case_gen_invocation_labels (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := Invocations_A.sched_context_invocation)) ExceptionTypes_A.syscall_error.IllegalOperation) (Decode_A.decode_sched_context_bind sc_ptr excaps) (holBindE (holFunApp (holLiftE (ε := ExceptionTypes_A.syscall_error)) (KHeap_A.get_sched_context sc_ptr)) (fun (sc : (Structures_A.sched_context_ext Unit)) => (holBindE (holFunApp (holLiftE (ε := ExceptionTypes_A.syscall_error)) (holGets Structures_A.abstract_state_ext.cur_thread)) (fun (ct_ptr : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holEq (Structures_A.sched_context_ext.sc_tcb sc) (Option.some ct_ptr))) ((holThrowError (α := Unit)) ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (Invocations_A.sched_context_invocation.InvokeSchedContextUnbind sc_ptr)))))))) (Decode_A.decode_sched_context_unbind_object sc_ptr excaps) (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (Invocations_A.sched_context_invocation.InvokeSchedContextConsumed sc_ptr)) (Decode_A.decode_sched_context_yield_to sc_ptr) (gen_invocation_type label))))) + +theorem decodeSchedContextInvocation_equiv (label : Data) (scPtr : ObjRef) + (excaps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embSchedContextInv) + (decode_sched_context_invocation_p label scPtr excaps) + (Fl4Spec.decodeSchedContextInvocation label scPtr (excaps.map embCap)) := by + unfold decode_sched_context_invocation_p Fl4Spec.decodeSchedContextInvocation + dsimp only [holFunApp] + rw [genInvocationType_eq] + cases gen_invocation_type label + all_goals try exact mrele_throwError rfl + · exact decodeSchedContextBind_equiv scPtr excaps + · refine mrele_bindE (mrele_liftE (getSchedContext_equiv scPtr)) fun scH scL hsc => ?_ + subst hsc + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun sH sL hs => hs.curThread_eq.symm)) fun ctH ctL hct => ?_ + subst hct + refine mrele_kbindE (mrele_whenE (by simp [holEq_eq_true, embSchedContext]) fun _ => + mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + · exact decodeSchedContextUnbindObject_equiv scPtr excaps + · exact mrele_returnOk rfl + · exact decodeSchedContextYieldTo_equiv scPtr + +def decode_sched_control_invocation_flags_p {tv_z : Type} [Nonempty tv_z] [Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((List Structures_A.cap) → ((Structures_A.abstract_state_ext (Structures_A.state_ext tv_z Unit)) → ((Set ((Sum ExceptionTypes_A.syscall_error Invocations_A.sched_control_invocation) × (Structures_A.abstract_state_ext (Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (excaps : (List Structures_A.cap)) => (holBindE (holFunApp (holUnlessE (holEq (gen_invocation_type label) InvocationLabels_H.gen_invocation_labels.SchedControlConfigureFlags)) ((holThrowError (α := Unit)) ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holWhenE (holEq (holSize excaps) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolAdd.addVal (HolMul.mulVal Structs_B.timeArgLen (HolNumeral.ofNatVal (α := Nat) 2)) (HolNumeral.ofNatVal (α := Nat) 3)))) ((holThrowError (α := Unit)) ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (Arch_Structs_A.parse_time_arg (HolZero.zeroVal (α := Nat)) args)) (fun (budget_us : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt Time.MAX_PERIOD_US budget_us)) ((holThrowError (α := Unit)) (ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (Arch_Structs_A.parse_time_arg Structs_B.timeArgLen args)) (fun (period_us : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt Time.MAX_PERIOD_US period_us)) ((holThrowError (α := Unit)) (ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holWhenE (holLt budget_us Structures_A.MIN_BUDGET_US)) ((holThrowError (α := Unit)) (ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holWhenE (holLt period_us Structures_A.MIN_BUDGET_US)) ((holThrowError (α := Unit)) (ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holWhenE (holLt period_us budget_us)) ((holThrowError (α := Unit)) (ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) period_us)))) (holKBind (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (holHd excaps)) (fun (target_cap : Structures_A.cap) => (holBindE (holFunApp (holWhenE (holNot (Structures_A.is_sched_context_cap target_cap))) ((holThrowError (α := Unit)) (ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (Structures_A.obj_ref_of target_cap)) (fun (sc_ptr : (BitVec 64)) => (holBindE ((holAssertE (ε := ExceptionTypes_A.syscall_error)) (holLe (Structures_A.MIN_REFILLS : Nat) (SchedContext_A.max_refills_cap target_cap))) (holKBind (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (holNth args (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) Structs_B.timeArgLen))) (fun (extra_refills : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt (HolSub.subVal (SchedContext_A.max_refills_cap target_cap) (Structures_A.MIN_REFILLS : Nat)) (holUnsigned extra_refills))) ((holThrowError (α := Unit)) (ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) (HolSub.subVal (SchedContext_A.max_refills_cap target_cap) (Structures_A.MIN_REFILLS : Nat)))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (holNth args (HolAdd.addVal (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) Structs_B.timeArgLen) (HolOne.oneVal (α := Nat))))) (fun (badge : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (holNth args (HolAdd.addVal (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) Structs_B.timeArgLen) (HolNumeral.ofNatVal (α := Nat) 2)))) (fun (flags : (BitVec 64)) => (holFunApp (holReturnOk (ε := ExceptionTypes_A.syscall_error)) (Invocations_A.sched_control_invocation.InvokeSchedControlConfigureFlags sc_ptr (Time.us_to_ticks budget_us) (Time.us_to_ticks period_us) (HolAdd.addVal (holUnsigned extra_refills) (Structures_A.MIN_REFILLS : Nat)) badge flags))))))))))))))))))))))))))))))))))))))))) + +theorem decodeSchedControlInvocationFlags_equiv (ho : OpaqueRel RestRel) + (label : Data) (args : List Data) (excaps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embSchedControlInv) + (decode_sched_control_invocation_flags_p label args excaps) + (Fl4Spec.decodeSchedControlInvocationFlags label args (excaps.map embCap)) := by + unfold decode_sched_control_invocation_flags_p Fl4Spec.decodeSchedControlInvocationFlags + dsimp only [holFunApp] + refine mrele_kbindE (mrele_unlessE + (by rw [genInvocationType_eq, holEq_eq_true]; exact embGenInvocationLabels_injective.eq_iff.symm) + fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hneE => ?_ + · simp [holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hne : excaps ≠ [] := by intro h; simp [h] at hneE + have htlen : Fl4Spec.timeArgLen = Structs_B.timeArgLen := rfl + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hgeA => ?_ + · rw [htlen, holLt_eq_true]; rfl + have h0lt : 0 < args.length := by have : Fl4Spec.timeArgLen = 1 := rfl; omega + have htlt : Structs_B.timeArgLen < args.length := by + have : Fl4Spec.timeArgLen = 1 := rfl + have : Structs_B.timeArgLen = 1 := rfl + omega + refine mrele_bindE (mrele_returnOk (Ra := Eq) (parseTimeArgA_eq 0 args h0lt).symm) fun budH budL hbud => ?_ + subst hbud + have hminb := MIN_BUDGET_US_eq ho + refine mrele_kbindE (mrele_whenE (by rw [ho.maxPeriodUs_eq, holLt_eq_true]; rfl) fun _ => + mrele_throwError (by rw [hminb, ho.maxPeriodUs_eq]; rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) (by rw [htlen]; exact (parseTimeArgA_eq _ args htlt).symm)) + fun perH perL hper => ?_ + subst hper + refine mrele_kbindE (mrele_whenE (by rw [ho.maxPeriodUs_eq, holLt_eq_true]; rfl) fun _ => + mrele_throwError (by rw [hminb, ho.maxPeriodUs_eq]; rfl)) ?_ + refine mrele_kbindE (mrele_whenE (by rw [hminb, holLt_eq_true]; rfl) fun _ => + mrele_throwError (by rw [hminb, ho.maxPeriodUs_eq]; rfl)) ?_ + refine mrele_kbindE (mrele_whenE (by rw [hminb, holLt_eq_true]; rfl) fun _ => + mrele_throwError (by rw [hminb, ho.maxPeriodUs_eq]; rfl)) ?_ + refine mrele_kbindE (mrele_whenE (by rw [holLt_eq_true]; rfl) fun _ => + mrele_throwError (by rw [hminb]; rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (the_head_map embCap excaps hne)) fun tcH tcL htc => ?_ + subst htc + refine mrele_kbindE (mrele_whenE (by rw [isSchedContextCap_eq, holNot_eq_true]) fun _ => + mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) (objRefOf_eq tcH).symm) fun spH spL hsp => ?_ + subst hsp + refine mrele_kbindE (mrele_assertE (by rw [MIN_REFILLS_eq, maxRefillsCap_eq, holLe_eq_true]; rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) (by rw [htlen]; rfl)) fun erH erL her => ?_ + subst her + refine mrele_kbindE (mrele_whenE (by rw [MIN_REFILLS_eq, maxRefillsCap_eq, holLt_eq_true]; rfl) fun _ => + mrele_throwError (by rw [MIN_REFILLS_eq, maxRefillsCap_eq]; rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) (by rw [htlen]; rfl)) fun bdgH bdgL hbdg => ?_ + subst hbdg + refine mrele_bindE (mrele_returnOk (Ra := Eq) (by rw [htlen]; rfl)) fun flH flL hfl => ?_ + subst hfl + exact mrele_returnOk (by rw [usToTicks_eq ho, usToTicks_eq ho, MIN_REFILLS_eq]; rfl) + + +theorem alignUp_eq {w : Nat} (x : BitVec w) (n : Nat) : + Fl4Spec.alignUp x n = More_Word_Operations.alignUp x n := by + unfold Fl4Spec.alignUp More_Word_Operations.alignUp + simp only [holWordAnd, holWordNot, HolAdd.addVal, HolSub.subVal, HolPow.powVal, + HolNumeral.ofNatVal, HolOne.oneVal] + have hbv : BitVec.ofNat w ((BitVec.ofNat w 2).toNat ^ n) = BitVec.ofNat w (2 ^ n) := by + apply BitVec.eq_of_toNat_eq + simp only [BitVec.toNat_ofNat] + exact (Nat.pow_mod 2 n (2 ^ w)).symm + rw [hbv]; rfl + +private theorem bitsOf_cnode_eq (r b g) : + Fl4Spec.bitsOf (embCap (.CNodeCap r b g)) = Structures_A.bits_of (.CNodeCap r b g) := rfl + +private theorem untypedMinBits_eq : + Fl4Spec.untypedMinBits = Arch_Structs_A.untyped_min_bits := rfl + +private theorem isFrameType_eq (t : Structures_A.apiobject_type) : + Fl4Spec.isFrameType (embApiObjectType t) = Structures_A.is_frame_type t := by + cases t with + | ArchObject a => cases a <;> rfl + | _ => rfl + +theorem archDataToObjType_equiv_base (n : Nat) (hbase : n < 7 ∨ 11 < n) : + Fl4Spec.archDataToObjType n = (ArchDecode_A.arch_data_to_obj_type n).map embAObjectType := by + rcases hbase with h | h + · exact (Patched.decodeObjectType_common n (by omega)).1.symm + · simp [Fl4Spec.archDataToObjType, ArchDecode_A.arch_data_to_obj_type, holIf_eq, holEq_eq_true, + HolZero.zeroVal, HolOne.oneVal, HolNumeral.ofNatVal, + show n ≠ 0 by omega, show n ≠ 1 by omega, show n ≠ 2 by omega, + show n ≠ 3 by omega, show n ≠ 4 by omega, show n ≠ 5 by omega, + show n ≠ 6 by omega, show n ≠ 7 by omega, show n ≠ 8 by omega, + show n ≠ 9 by omega, show n ≠ 10 by omega, show n ≠ 11 by omega] + +theorem dataToObjType_equiv (ty : Data) (hbase : ty.toNat < 14 ∨ 18 < ty.toNat) : + MRelE SR (FunRel embSyscallError) (FunRel embApiObjectType) + (Decode_A.data_to_obj_type ty) + (Fl4Spec.dataToObjType ty) := by + unfold Decode_A.data_to_obj_type Fl4Spec.dataToObjType + refine mrele_bindE + (mrele_returnOk (Ra := fun nH nL => nH = ty.toNat ∧ nL = ty.toNat) ⟨rfl, rfl⟩) + fun nH nL ⟨hnH, hnL⟩ => ?_ + subst nH + subst nL + refine mrele_if (by simp [holEq_eq_true, HolZero.zeroVal]) (fun _ => mrele_returnOk rfl) fun _ => ?_ + refine mrele_if (by simp [holEq_eq_true, HolOne.oneVal]) (fun _ => mrele_returnOk rfl) fun _ => ?_ + refine mrele_if (by simp [holEq_eq_true, HolNumeral.ofNatVal]) (fun _ => mrele_returnOk rfl) fun _ => ?_ + refine mrele_if (by simp [holEq_eq_true, HolNumeral.ofNatVal]) (fun _ => mrele_returnOk rfl) fun _ => ?_ + refine mrele_if (by simp [holEq_eq_true, HolNumeral.ofNatVal]) (fun _ => mrele_returnOk rfl) fun _ => ?_ + refine mrele_if (by simp [holEq_eq_true, HolNumeral.ofNatVal]) (fun _ => mrele_returnOk rfl) fun _ => ?_ + refine mrele_if (by simp [holEq_eq_true, HolNumeral.ofNatVal]) (fun _ => mrele_returnOk rfl) fun _ => ?_ + have hbase' : ty.toNat - 7 < 7 ∨ 11 < ty.toNat - 7 := by omega + rw [archDataToObjType_equiv_base _ hbase'] + cases ArchDecode_A.arch_data_to_obj_type (ty.toNat - 7) with + | none => exact mrele_throwError rfl + | some tp => exact mrele_returnOk rfl + +def decode_untyped_invocation_p (label : Data) (args : List Data) (slot : CslotPtr) + (cap : Structures_A.cap) (excaps : List Structures_A.cap) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.untyped_invocation) := + holBindE (holUnlessE (holEq (gen_invocation_type label) .UntypedRetype) + (holThrowError .IllegalOperation)) (holKBind + (holBindE (holWhenE (holLt args.length 6) (holThrowError .TruncatedMessage)) (holKBind + (holBindE (holWhenE (holEq excaps.length 0) (holThrowError .TruncatedMessage)) (holKBind + (holBindE (holReturnOk (holNth excaps 0)) fun root_cap => + holBindE (Decode_A.data_to_obj_type (holNth args 0)) fun new_type => + holBindE (holReturnOk (Machine_A.data_to_nat (holNth args 1))) fun user_obj_size => + holBindE (holReturnOk (Patched.obj_bits_api new_type user_obj_size)) fun object_size => + holBindE (holUnlessE (holConj (holLt user_obj_size Machine_Word_64_Basics.word_bits) + (holLe object_size Arch_Structs_A.untyped_max_bits)) + (holThrowError (.RangeError 0 (holOfNat Arch_Structs_A.untyped_max_bits)))) (holKBind + (holBindE (holWhenE (holConj (holEq new_type .CapTableObject) (holEq user_obj_size 0)) + (holThrowError (.InvalidArgument 1))) (holKBind + (holBindE (holWhenE (holConj (holEq new_type .Untyped) (holLt user_obj_size Arch_Structs_A.untyped_min_bits)) + (holThrowError (.InvalidArgument 1))) (holKBind + (holBindE (holWhenE (holConj (holEq new_type .SchedContextObject) (holLt user_obj_size Structures_A.min_sched_context_bits)) + (holThrowError (.InvalidArgument 1))) (holKBind + (holBindE (holReturnOk (Machine_A.data_to_cptr (holNth args 2))) fun node_index => + holBindE (holReturnOk (Machine_A.data_to_nat (holNth args 3))) fun node_depth => + holBindE (if holEq node_depth 0 = true then holReturnOk root_cap + else holBindE (lookup_target_slot_p root_cap node_index node_depth) fun node_slot => + holLiftE (get_cap_p node_slot)) fun node_cap => + holBindE (if Structures_A.is_cnode_cap node_cap = true then holReturnOk () + else holThrowError (.FailedLookup false (.MissingCapability node_depth))) (holKBind + (holBindE (holReturnOk (Machine_A.data_to_nat (holNth args 4))) fun node_offset => + holBindE (holReturnOk (Machine_A.data_to_nat (holNth args 5))) fun node_window => + holBindE (holReturnOk (Structures_A.bits_of node_cap)) fun radix_bits => + holBindE (holReturnOk (2 ^ radix_bits)) fun node_size => + holBindE (holWhenE (holDisj (holLt node_offset 0) (holLt (node_size - 1) node_offset)) + (holThrowError (.RangeError 0 (holOfNat (node_size - 1))))) (holKBind + (holBindE (holWhenE (holDisj (holLt node_window 1) (holLt (holUnsigned Kernel_Config.retypeFanOutLimit) node_window)) + (holThrowError (.RangeError 1 Kernel_Config.retypeFanOutLimit))) (holKBind + (holBindE (holWhenE (holDisj (holLt node_window 1) (holLt (node_size - node_offset) node_window)) + (holThrowError (.RangeError 1 (holOfNat (node_size - node_offset))))) (holKBind + (holBindE (holReturnOk (Structures_A.obj_ref_of node_cap)) fun oref => + holBindE (holReturnOk ((holListUpt node_offset (node_offset + node_window)).map (Machine_A.nat_to_cref radix_bits))) fun offsets => + holBindE (holReturnOk (offsets.map fun cref => (oref, cref))) fun slots => + holBindE (holMapMEx ensure_empty_p slots) (holKBind + (holBindE (holLiftE (Exceptions_A.const_on_failure false + (holBindE (CSpace_A.ensure_no_children slot) (holKBind (holReturnOk true))))) fun reset => + holBindE (holReturnOk (if reset then 0 else Structures_A.free_index_of cap)) fun free_index => + holBindE (holReturnOk (Retype_A.get_free_ref (Structures_A.obj_ref_of cap) free_index)) fun free_ref => + holBindE (holReturnOk (More_Word_Operations.alignUp free_ref object_size)) fun aligned_free_ref => + holBindE (holReturnOk (HolSub.subVal (Structures_A.obj_size cap) (holOfNat free_index))) fun untyped_free_bytes => + holBindE (holReturnOk (holWordShiftr untyped_free_bytes object_size)) fun max_count => + holBindE (holWhenE (holLt (holUnsigned max_count) node_window) + (holThrowError (.NotEnoughMemory untyped_free_bytes))) (holKBind + (holBindE (holReturnOk (holNot (Structures_A.is_frame_type new_type))) fun not_frame => + holBindE (match cap with + | .UntypedCap dev p _n _f => holReturnOk (p, dev) + | _ => holFail) fun (ptr, is_device) => + holBindE (holWhenE (holConj is_device (holConj not_frame (holNot (holEq new_type .Untyped)))) + (holThrowError (.InvalidArgument 1))) (holKBind + (holReturnOk (.Retype slot reset ptr aligned_free_ref new_type user_obj_size slots is_device))))))))))))))))))))))))))))) + +theorem patched_decodeUntypedInvocation_equiv (hc : ConfigRel) + (label : Data) (args : List Data) (slot : CslotPtr) + (dev : Bool) (uptr : ObjRef) (usz ufi : Nat) + (excaps : List Structures_A.cap) + (hbase : 6 ≤ args.length → (holNth args 0 : Data).toNat < 14 ∨ 18 < (holNth args 0 : Data).toNat) : + MRelE SR (FunRel embSyscallError) (FunRel embUntypedInv) + (decode_untyped_invocation_p label args slot (.UntypedCap dev uptr usz ufi) excaps) + (Fl4Spec.decodeUntypedInvocation label args slot + (embCap (.UntypedCap dev uptr usz ufi)) (excaps.map embCap)) := by + unfold decode_untyped_invocation_p Fl4Spec.decodeUntypedInvocation + refine mrele_kbindE (mrele_unlessE + (by rw [genInvocationType_eq, holEq_eq_true]; exact embGenInvocationLabels_injective.eq_iff.symm) + fun _ => mrele_throwError rfl) ?_ + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hlen => ?_ + · rw [holLt_eq_true]; rfl + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holEq_eq_true, List.length_map] + have h0lt : 0 < excaps.length := by simp only [List.length_map] at hne; omega + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) (the_getElem_map embCap excaps 0 h0lt)) + fun rcH rcL hrc => ?_ + subst hrc + refine mrele_bindE (dataToObjType_equiv _ (hbase (by omega))) fun ntH ntL hnt => ?_ + subst hnt + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun usH usL hus => ?_ + subst hus + refine mrele_bindE (mrele_returnOk (Ra := Eq) (patched_objBitsApi_equiv ntH usH).symm) fun osH osL hos => ?_ + subst hos + refine mrele_kbindE (mrele_unlessE + (by rw [wordBits_eq, untypedMaxBits_eq, holConj_eq_true, holLt_eq_true, holLe_eq_true]; rfl) + fun _ => mrele_throwError (by rw [untypedMaxBits_eq]; rfl)) ?_ + have hct : holConj (holEq ntH .CapTableObject) (holEq usH 0) = true ↔ + embApiObjectType ntH = .capTableObject ∧ usH = 0 := by + rw [holConj_eq_true, holEq_eq_true, holEq_eq_true] + cases ntH <;> simp [embApiObjectType] + refine mrele_kbindE (mrele_whenE hct fun _ => mrele_throwError rfl) ?_ + have hunt : holConj (holEq ntH .Untyped) (holLt usH Arch_Structs_A.untyped_min_bits) = true ↔ + embApiObjectType ntH = .untyped ∧ usH < Fl4Spec.untypedMinBits := by + rw [untypedMinBits_eq, holConj_eq_true, holEq_eq_true, holLt_eq_true] + cases ntH <;> simp [embApiObjectType] + rfl + refine mrele_kbindE (mrele_whenE hunt fun _ => mrele_throwError rfl) ?_ + have hsc : holConj (holEq ntH .SchedContextObject) (holLt usH Structures_A.min_sched_context_bits) = true ↔ + embApiObjectType ntH = .schedContextObject ∧ usH < Fl4Spec.minSchedContextBits := by + rw [minSchedContextBits_eq, holConj_eq_true, holEq_eq_true, holLt_eq_true] + cases ntH <;> simp [embApiObjectType] + rfl + refine mrele_kbindE (mrele_whenE hsc fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun niH niL hni => ?_ + subst hni + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun ndH ndL hnd => ?_ + subst hnd + refine mrele_bindE (Ra := FunRel embCap) ?_ fun ncH ncL hnc => ?_ + · by_cases h0 : ndH = 0 + · have h0H : holEq ndH 0 = true := (holEq_eq_true ndH 0).mpr h0 + rw [ite_eq_left h0, ite_eq_left h0H] + exact mrele_returnOk rfl + · have h0H : holEq ndH 0 ≠ true := mt (holEq_eq_true ndH 0).mp h0 + rw [ite_eq_right h0, ite_eq_right h0H] + refine mrele_bindE (patched_lookupTargetSlot_equiv rcH niH ndH) fun nsH nsL hns => ?_ + subst hns + exact mrele_liftE (patched_getCap_equiv nsH) + subst hnc + by_cases hcnode : Structures_A.is_cnode_cap ncH = true + · have hcnodeL : Fl4Spec.isCnodeCap (embCap ncH) = true := by rw [isCnodeCap_eq]; exact hcnode + rw [ite_eq_left hcnode, ite_eq_left hcnodeL] + refine mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) ?_ + obtain ⟨cnPtr, cnBits, cnGuard, rfl⟩ : ∃ p b g, ncH = .CNodeCap p b g := by + cases ncH <;> simp [Structures_A.is_cnode_cap] at hcnode + exact ⟨_, _, _, rfl⟩ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun noH noL hno => ?_ + subst hno + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun nwH nwL hnw => ?_ + subst hnw + refine mrele_bindE (mrele_returnOk (Ra := Eq) (bitsOf_cnode_eq cnPtr cnBits cnGuard).symm) fun rbH rbL hrb => ?_ + subst hrb + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun nszH nszL hnsz => ?_ + subst hnsz + refine mrele_kbindE (mrele_whenE (by simp [holDisj_eq_true, holLt_eq_true, HolOrd.ltVal]) fun _ => + mrele_throwError rfl) ?_ + refine mrele_kbindE (mrele_whenE (by + unfold Fl4Spec.retypeFanOutLimit + rw [hc.retypeFanOutLimit_eq, holDisj_eq_true, holLt_eq_true, holLt_eq_true]; rfl) + fun _ => mrele_throwError (by unfold Fl4Spec.retypeFanOutLimit; rw [hc.retypeFanOutLimit_eq]; rfl)) ?_ + refine mrele_kbindE (mrele_whenE (by simp [holDisj_eq_true, holLt_eq_true, HolOrd.ltVal]) fun _ => + mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) (objRefOf_eq _).symm) fun orefH orefL horef => ?_ + subst horef + have hoff : (holListUpt noH (noH + nwH)).map (Machine_A.nat_to_cref rbH) = + (List.range' noH (noH + nwH - noH)).map (Fl4Spec.natToCref rbH) := by + unfold holListUpt + congr 1 + refine mrele_bindE (mrele_returnOk (Ra := Eq) hoff) fun offsH offsL hoffs => ?_ + subst hoffs + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun slsH slsL hsls => ?_ + subst hsls + refine mrele_kbindE (mrele_mapMEx (fun sH sL hs => by subst hs; exact patched_ensureEmpty_equiv sH) + (listRel_eq slsH)) ?_ + refine mrele_bindE (mrele_liftE (constOnFailure_equiv (Ra := Eq) rfl + (mrele_kbindE (ensureNoChildren_equiv slot) (mrele_returnOk rfl)))) fun rstH rstL hrst => ?_ + subst hrst + have hfi : (if rstH = true then 0 else Structures_A.free_index_of (.UntypedCap dev uptr usz ufi)) = + (if rstH = true then 0 else Fl4Spec.freeIndexOf (embCap (.UntypedCap dev uptr usz ufi))) := by + rw [freeIndexOf_eq'] + refine mrele_bindE (mrele_returnOk (Ra := Eq) hfi) fun fiH fiL hfi' => ?_ + subst hfi' + refine mrele_bindE (mrele_returnOk (Ra := Eq) (by rw [objRefOf_eq, getFreeRef_eq])) fun frH frL hfr => ?_ + subst hfr + refine mrele_bindE (mrele_returnOk (Ra := Eq) (alignUp_eq frH osH).symm) fun afrH afrL hafr => ?_ + subst hafr + have hosz : Fl4Spec.objSize (embCap (.UntypedCap dev uptr usz ufi)) = + Structures_A.obj_size (.UntypedCap dev uptr usz ufi) := + objSize_eq_nonNtfn (.UntypedCap dev uptr usz ufi) (by intro r b rs h; cases h) + ⟨(by intro h; cases h), (by intro h; cases h), (by intro h; cases h), (by intro i h; cases h)⟩ + refine mrele_bindE (mrele_returnOk (Ra := Eq) (by rw [hosz]; rfl)) fun ufbH ufbL hufb => ?_ + subst hufb + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun mcH mcL hmc => ?_ + subst hmc + refine mrele_kbindE (mrele_whenE (by rw [holLt_eq_true]; rfl) fun _ => mrele_throwError rfl) ?_ + have hnfIff : (holNot (Structures_A.is_frame_type ntH) = true) ↔ + ¬(Fl4Spec.isFrameType (embApiObjectType ntH) = true) := by + rw [holNot_eq_true, isFrameType_eq] + refine mrele_bindE (Ra := fun b p => (b = true) ↔ p) (mrele_returnOk hnfIff) fun nfH nfL hnf => ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) (aH := (uptr, dev)) (aL := (uptr, dev)) rfl) ?_ + rintro ⟨pH, dH⟩ ⟨pL, dL⟩ hpd + cases hpd + have hdev : holConj dH (holConj nfH (holNot (holEq ntH .Untyped))) = true ↔ + dH = true ∧ nfL ∧ embApiObjectType ntH ≠ .untyped := by + simp only [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true, hnf] + cases ntH <;> simp [embApiObjectType] + refine mrele_kbindE (mrele_whenE hdev fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + · have hcnodeL : ¬(Fl4Spec.isCnodeCap (embCap ncH) = true) := by rw [isCnodeCap_eq]; exact hcnode + rw [ite_eq_right hcnode, ite_eq_right hcnodeL] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + +/-- l4v: ArchDecode_A.arch_decode_irq_control_invocation, with the FL4 label ABI +and the related CSpace operations. -/ +def arch_decode_irq_control_invocation_p (label : Data) (args : List Data) (slot : CslotPtr) + (caps : List Structures_A.cap) : + HolNonDet (Structures_A.state ZH) + (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_irq_control_invocation) := + let available := holConj (holLe 7 args.length) (holLe 1 caps.length) + let preIrq := holNth args 6 + let irq := holUcast (w := 8) preIrq + Platform.minUserIRQ + let maximum := holUcast (w := 64) (Platform.maxUserIRQ - Platform.minUserIRQ) + let cnode := holNth caps 0 + let index := Machine_A.data_to_cptr (holNth args 0) + let depth := holUnsigned (holNth args 1) + let checkBound := fun (value limit : Data) => + holWhenE (holLt limit value) (holThrowError (.RangeError 0 limit)) + let findSlot := fun next => + holBindE (checkBound preIrq maximum) (holKBind + (holBindE (holLiftE (KHeap_A.is_irq_active irq)) fun active => + holBindE (holWhenE active (holThrowError .RevokeFirst)) (holKBind + (holBindE (lookup_target_slot_p cnode index depth) fun dst => + holBindE (ensure_empty_p dst) (holKBind (next dst)))))) + holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64IRQIssueIRQHandlerIOAPIC)) + (holIf available + (findSlot fun dst => + let ioapic := holNth args 2 + let pin := holNth args 3 + let level := holNth args 4 + let polarity := holNth args 5 + let vector := holUcast (w := 64) irq + MachineOps.irqIntOffset + holBindE (holLiftE (holGets fun s => s.arch_state.x64_num_ioapics)) fun n => + holBindE (holLiftE (holGets fun s => s.arch_state.x64_ioapic_nirqs)) fun nirqs => + holBindE (holWhenE (holEq n 0) (holThrowError .IllegalOperation)) (holKBind + (holBindE (checkBound ioapic (n - 1)) (holKBind + (holBindE (checkBound pin (holUcast (w := 64) (nirqs ioapic - 1))) (holKBind + (holBindE (checkBound level 1) (holKBind + (holBindE (checkBound polarity 1) (holKBind + (holReturnOk (.IssueIRQHandlerIOAPIC irq dst slot ioapic pin level polarity vector)))))))))))) + (holThrowError .TruncatedMessage)) + (holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64IRQIssueIRQHandlerMSI)) + (holIf available + (findSlot fun dst => + let bus := holNth args 2 + let dev := holNth args 3 + let fn := holNth args 4 + let handle := holNth args 5 + holBindE (checkBound bus MachineOps.maxPCIBus) (holKBind + (holBindE (checkBound dev MachineOps.maxPCIDev) (holKBind + (holBindE (checkBound fn MachineOps.maxPCIFunc) (holKBind + (holReturnOk (.IssueIRQHandlerMSI irq dst slot bus dev fn handle)))))))) + (holThrowError .TruncatedMessage)) + (holThrowError .IllegalOperation)) + +private theorem irqArgsAvailable (n : Nat) (args : List Data) (caps : List Structures_A.cap) : + holConj (holLe n args.length) (holLe 1 caps.length) = true ↔ + n ≤ args.length ∧ 1 ≤ (caps.map embCap).length := by + rw [holConj_eq_true, holLe_eq_true, holLe_eq_true, List.length_map] + rfl + +theorem archInvocationLabel_iff (label : Data) + (l : InvocationLabels_H.invocation_label) : + holEq (Patched.invocation_type label) l = true ↔ + Fl4Spec.invocationType label = embInvocationLabel l := by + rw [← Patched.invocationType_equiv, holEq_eq_true, embInvocationLabel_eq_iff] + +private theorem irqGuard (limit v : Data) : holLt limit v = true ↔ limit < v := by + rw [holLt_eq_true] + rfl + +theorem patched_archDecodeIrqControlInvocation_equiv (label : Data) (args : List Data) + (slot : CslotPtr) (caps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embArchIrqControlInv) + (arch_decode_irq_control_invocation_p label args slot caps) + (Fl4Spec.archDecodeIrqControlInvocation label args slot (caps.map embCap)) := by + unfold arch_decode_irq_control_invocation_p Fl4Spec.archDecodeIrqControlInvocation + refine mrele_if (archInvocationLabel_iff label (.ArchInvocationLabel .X64IRQIssueIRQHandlerIOAPIC)) ?_ ?_ + · intro _ + refine mrele_if (irqArgsAvailable 7 args caps) ?_ (fun _ => mrele_throwError rfl) + intro hlen + have hcap := hlen.2 + rw [List.length_map] at hcap + rw [the_getElem_map embCap caps 0 (by omega)] + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_liftE (isIrqActive_equiv _)) fun aH aL ha => ?_ + subst ha + refine mrele_kbindE (mrele_whenE Iff.rfl (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (patched_lookupTargetSlot_equiv _ _ _) fun dH dL hd => ?_ + subst hd + refine mrele_kbindE (patched_ensureEmpty_equiv dH) ?_ + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) (fun _ _ hs => by rw [hs.archState_eq]; rfl))) + fun nH nL hn => ?_ + subst hn + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) (fun _ _ hs => by rw [hs.archState_eq]; rfl))) + fun pH pL hp => ?_ + subst hp + refine mrele_kbindE (mrele_whenE (holEq_eq_true nH 0) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + exact mrele_returnOk rfl + · intro _ + refine mrele_if (archInvocationLabel_iff label (.ArchInvocationLabel .X64IRQIssueIRQHandlerMSI)) + ?_ (fun _ => mrele_throwError rfl) + intro _ + refine mrele_if (irqArgsAvailable 7 args caps) ?_ (fun _ => mrele_throwError rfl) + intro hlen + have hcap := hlen.2 + rw [List.length_map] at hcap + rw [the_getElem_map embCap caps 0 (by omega)] + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_liftE (isIrqActive_equiv _)) fun aH aL ha => ?_ + subst ha + refine mrele_kbindE (mrele_whenE Iff.rfl (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (patched_lookupTargetSlot_equiv _ _ _) fun dH dL hd => ?_ + subst hd + refine mrele_kbindE (patched_ensureEmpty_equiv dH) ?_ + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_kbindE (mrele_whenE (irqGuard _ _) (fun _ => mrele_throwError rfl)) ?_ + exact mrele_returnOk rfl + +/-- l4v: Decode_A.decode_irq_control_invocation, with the FL4 labels and +the X64-specific patched decoder. The generic issue call fails at arch_check_irq on X64. -/ +def decode_irq_control_invocation_p (label : Data) (args : List Data) (slot : CslotPtr) + (caps : List Structures_A.cap) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.irq_control_invocation) := + holIf (holEq (gen_invocation_type label) .IRQIssueIRQHandler) + (holIf (holConj (holLe 3 args.length) (holLe 1 caps.length)) + (holBindE (ArchDecode_A.arch_check_irq (holNth args 0)) (holKBind + (let irq := holUcast (w := 8) (holNth args 0) + holBindE (holLiftE (KHeap_A.is_irq_active irq)) fun active => + holBindE (holWhenE active (holThrowError .RevokeFirst)) (holKBind + (holBindE (lookup_target_slot_p (holNth caps 0) (Machine_A.data_to_cptr (holNth args 1)) + (holUnsigned (holNth args 2))) fun dst => + holBindE (ensure_empty_p dst) (holKBind (holReturnOk (.IRQControl irq dst slot)))))))) + (holThrowError .TruncatedMessage)) + (holLiftME Invocations_A.irq_control_invocation.ArchIRQControl + (arch_decode_irq_control_invocation_p label args slot caps)) + +private theorem irqGenLabel_true (label : Data) (l : InvocationLabels_H.gen_invocation_labels) : + holEq (gen_invocation_type label) l = true ↔ + Fl4Spec.genInvocationType label = embGenInvocationLabels l := by + rw [genInvocationType_eq, holEq_eq_true] + exact embGenInvocationLabels_injective.eq_iff.symm + +theorem patched_decodeIrqControlInvocation_equiv (label : Data) (args : List Data) (slot : CslotPtr) + (caps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embIrqControlInv) + (decode_irq_control_invocation_p label args slot caps) + (Fl4Spec.decodeIrqControlInvocation label args slot (caps.map embCap)) := by + unfold decode_irq_control_invocation_p Fl4Spec.decodeIrqControlInvocation + refine mrele_if (irqGenLabel_true label .IRQIssueIRQHandler) ?_ ?_ + · intro _ + refine mrele_if (irqArgsAvailable 3 args caps) ?_ (fun _ => mrele_throwError rfl) + intro _ + unfold ArchDecode_A.arch_check_irq Fl4Spec.archCheckIrq + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + · intro _ + refine mrele_liftME (Ra := FunRel embArchIrqControlInv) ?_ + (patched_archDecodeIrqControlInvocation_equiv label args slot caps) + intro aH aL ha + subst ha + rfl + +/-- l4v: Decode_A.decode_irq_handler_invocation, with the FL4 label ABI. -/ +def decode_irq_handler_invocation_p (label : Data) (irq : Irq) + (caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.irq_handler_invocation) := + holIf (holEq (gen_invocation_type label) .IRQAckIRQ) (holReturnOk (.ACKIrq irq)) + (holIf (holEq (gen_invocation_type label) .IRQSetIRQHandler) + (holIf (holNot (holEq caps [])) + (let (cap, slot) := holHd caps + holIf (holConj (Structures_A.is_ntfn_cap cap) (holMember CapRights_A.AllowSend (Structures_A.cap_rights cap))) + (holReturnOk (.SetIRQHandler irq cap slot)) (holThrowError (.InvalidCapability 0))) + (holThrowError .TruncatedMessage)) + (holIf (holEq (gen_invocation_type label) .IRQClearIRQHandler) + (holReturnOk (.ClearIRQHandler irq)) (holThrowError .IllegalOperation))) + +theorem patched_decodeIrqHandlerInvocation_equiv (label : Data) (irq : Irq) + (caps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embIrqHandlerInv) + (decode_irq_handler_invocation_p label irq caps) + (Fl4Spec.decodeIrqHandlerInvocation label irq (caps.map fun (cap, slot) => (embCap cap, slot))) := by + unfold decode_irq_handler_invocation_p Fl4Spec.decodeIrqHandlerInvocation + refine mrele_if (irqGenLabel_true label .IRQAckIRQ) (fun _ => mrele_returnOk rfl) ?_ + intro _ + refine mrele_if (irqGenLabel_true label .IRQSetIRQHandler) ?_ ?_ + · intro _ + cases caps with + | nil => + simp only [holNot, holEq, decide_true, Bool.not_true, holIf, Bool.false_eq_true, ite_false, + List.map_nil, ne_eq, not_true_eq_false] + exact mrele_throwError rfl + | cons head tail => + obtain ⟨cap, slot⟩ := head + have hne : holNot (holEq ((cap, slot) :: tail) []) = true := by + rw [holNot_eq_true] + exact fun h => List.cons_ne_nil _ _ ((holEq_eq_true _ _).mp h) + simp only [holIf_eq, hne, ite_true, List.map_cons] + change MRelE SR (FunRel embSyscallError) (FunRel embIrqHandlerInv) + (holIf (holConj (Structures_A.is_ntfn_cap cap) (holMember CapRights_A.AllowSend (Structures_A.cap_rights cap))) + (holReturnOk (.SetIRQHandler irq cap slot)) (holThrowError (.InvalidCapability 0))) + (if Fl4Spec.isNtfnCap (embCap cap) ∧ AllowSend ∈ Fl4Spec.capRights (embCap cap) + then NonDetE.returnOk (.setIRQHandler irq (embCap cap) slot) else NonDetE.throwError (.invalidCapability 0)) + refine mrele_if ?_ (fun _ => mrele_returnOk rfl) (fun _ => mrele_throwError rfl) + rw [holConj_eq_true, ← isNtfnCap_eq, holMember_eq_true] + refine and_congr_right fun h => ?_ + cases cap <;> simp [Fl4Spec.isNtfnCap, embCap] at h + exact (embRightsSet_mem CapRights_A.AllowSend _).symm + · intro _ + exact mrele_if (irqGenLabel_true label .IRQClearIRQHandler) + (fun _ => mrele_returnOk rfl) (fun _ => mrele_throwError rfl) + + +/-! ### TCB registers and priorities -/ + +theorem decodeReadRegisters_equiv (data : List Data) (ptr : ObjRef) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_read_registers data (.ThreadCap ptr)) + (Fl4Spec.decodeReadRegisters data (embCap (.ThreadCap ptr))) := by + unfold Decode_A.decode_read_registers Fl4Spec.decodeReadRegisters + cases data with + | nil => exact mrele_throwError rfl + | cons flags tl => + cases tl with + | nil => exact mrele_throwError rfl + | cons n rest => + simp only [holCaseList, Structures_A.case_cap, embCap] + have hlen : (Fl4Spec.frameRegisters.length + Fl4Spec.gpRegisters.length) = + HolAdd.addVal (holSize MachineTypes.frameRegisters) (holSize MachineTypes.gpRegisters) := by + have hstart : holFromEnum MachineTypes.register.RAX = 0 := by + simp [holFromEnum, HolEnum.enumList, MachineTypes.enum_register, holTheIndex] + have hend : holFromEnum MachineTypes.register.R15 = 14 := by + simp [holFromEnum, HolEnum.enumList, MachineTypes.enum_register, holTheIndex] + rw [MachineTypes.frameRegisters, holUptoEnum, hstart, hend] + rfl + refine mrele_kbindE (by rw [hlen]; exact rangeCheck_equiv n 1 _) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pH pL hp => ?_ + subst hp + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun _ _ hs => hs.curThread_eq.symm)) fun selfH selfL hself => ?_ + subst hself + refine mrele_kbindE (mrele_whenE (by rw [holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + +theorem decodeCopyRegisters_equiv (data : List Data) (ptr : ObjRef) + (extraCaps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_copy_registers data (.ThreadCap ptr) extraCaps) + (Fl4Spec.decodeCopyRegisters data (embCap (.ThreadCap ptr)) (extraCaps.map embCap)) := by + unfold Decode_A.decode_copy_registers Fl4Spec.decodeCopyRegisters + cases data with + | nil => exact mrele_throwError rfl + | cons flags rest => + simp only [holCaseList, embCap] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun s0H s0L hs0 => ?_ + subst hs0 + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun s1H s1L hs1 => ?_ + subst hs1 + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun s2H s2L hs2 => ?_ + subst hs2 + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun s3H s3L hs3 => ?_ + subst hs3 + have hnil : holEq extraCaps [] = true ↔ extraCaps.map embCap = [] := by + cases extraCaps <;> simp [holEq] + refine mrele_kbindE (mrele_whenE hnil fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (by + cases extraCaps with + | nil => exact mrele_throwError rfl + | cons c cs => + cases c with + | ThreadCap p => exact mrele_returnOk (Ra := Eq) rfl + | _ => exact mrele_throwError rfl) fun stH stL hst => ?_ + subst hst + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pH pL hp => ?_ + subst hp + exact mrele_returnOk rfl + +theorem decodeWriteRegisters_equiv (data : List Data) (ptr : ObjRef) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_write_registers data (.ThreadCap ptr)) + (Fl4Spec.decodeWriteRegisters data (embCap (.ThreadCap ptr))) := by + unfold Decode_A.decode_write_registers Fl4Spec.decodeWriteRegisters + cases data with + | nil => exact mrele_throwError rfl + | cons flags tl => + cases tl with + | nil => exact mrele_throwError rfl + | cons n values => + simp only [holCaseList, Structures_A.case_cap, embCap] + refine mrele_kbindE (mrele_whenE (by rw [holLt_eq_true]; rfl) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pH pL hp => ?_ + subst hp + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun _ _ hs => hs.curThread_eq.symm)) fun selfH selfL hself => ?_ + subst hself + refine mrele_kbindE (mrele_whenE (by rw [holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk rfl + +theorem checkPrio_equiv (newPrio : Data) (authTcb : ObjRef) : + MRelE SR (FunRel embSyscallError) Eq + (Decode_A.check_prio newPrio authTcb) + (Fl4Spec.checkPrio newPrio authTcb) := by + unfold Decode_A.check_prio Fl4Spec.checkPrio + refine mrele_bindE (mrele_liftE (threadGet_equiv (Ra := Eq) (fun _ => rfl) authTcb)) fun mH mL hm => ?_ + subst hm + exact mrele_whenE (by rw [holLt_eq_true]; rfl) fun _ => mrele_throwError rfl + +theorem decodeSetPriority_equiv (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (extraCaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_set_priority args cap slot extraCaps) + (Fl4Spec.decodeSetPriority args (embCap cap) slot + (extraCaps.map fun p => (embCap p.1, p.2))) := by + unfold Decode_A.decode_set_priority Fl4Spec.decodeSetPriority + dsimp only [holFunApp] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holDisj_eq_true, holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hec0 : (the ((extraCaps.map fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2))[0]?)).1 = + embCap (holNth extraCaps 0).1 := by + rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps 0 (by simp only [List.length_map] at hne; omega)] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun prH prL hpr => ?_ + subst hpr + rw [hec0] + cases (holNth extraCaps 0).1 with + | ThreadCap tcbPtr => + simp only [Structures_A.case_cap] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun authH authL hauth => ?_ + subst hauth + refine mrele_kbindE (checkPrio_equiv _ authH) ?_ + exact mrele_returnOk (by rw [objRefOf_eq]; rfl) + | _ => + simp only [Structures_A.case_cap] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + +theorem decodeSetMcpriority_equiv (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (extraCaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_set_mcpriority args cap slot extraCaps) + (Fl4Spec.decodeSetMcpriority args (embCap cap) slot + (extraCaps.map fun p => (embCap p.1, p.2))) := by + unfold Decode_A.decode_set_mcpriority Fl4Spec.decodeSetMcpriority + dsimp only [holFunApp] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holDisj_eq_true, holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hec0 : (the ((extraCaps.map fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2))[0]?)).1 = + embCap (holNth extraCaps 0).1 := by + rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps 0 (by simp only [List.length_map] at hne; omega)] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun mH mL hm => ?_ + subst hm + rw [hec0] + cases (holNth extraCaps 0).1 with + | ThreadCap tcbPtr => + simp only [Structures_A.case_cap] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun authH authL hauth => ?_ + subst hauth + refine mrele_kbindE (checkPrio_equiv _ authH) ?_ + exact mrele_returnOk (by rw [objRefOf_eq]; rfl) + | _ => + simp only [Structures_A.case_cap] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + +theorem hasHandlerRights_iff (cap : Structures_A.cap) + (hep : Structures_A.is_ep_cap cap = true) : + Fl4Spec.hasHandlerRights (embCap cap) ↔ Decode_A.has_handler_rights cap = true := by + cases cap with + | EndpointCap ptr badge R => + unfold Fl4Spec.hasHandlerRights Decode_A.has_handler_rights + simp only [embCap, Fl4Spec.capRights, Structures_A.cap_rights, + holConj_eq_true, holMember_eq_true, holNot_eq_true, ne_eq, holEq_eq_true] + have hsend : Fl4Spec.AllowSend ∈ embRightsSet R ↔ CapRights_A.AllowSend ∈ R := by + change embRights CapRights_A.AllowSend ∈ embRightsSet R ↔ _ + exact embRightsSet_mem CapRights_A.AllowSend R + have hinter : ({Rights.allowGrant, Rights.allowGrantReply} ∩ embRightsSet R ≠ ∅) ↔ + (HolCompleteLattice.holInf + (holInsert CapRights_A.rights.AllowGrant + (holInsert CapRights_A.rights.AllowGrantReply HolCompleteLattice.holBot)) R ≠ + HolCompleteLattice.holBot) := by + have hiff : ({Rights.allowGrant, Rights.allowGrantReply} ∩ embRightsSet R = ∅) ↔ + (HolCompleteLattice.holInf + (holInsert CapRights_A.rights.AllowGrant + (holInsert CapRights_A.rights.AllowGrantReply HolCompleteLattice.holBot)) R = + HolCompleteLattice.holBot) := by + constructor + · intro hempty + ext rH + have hmem : embRights rH ∉ ({Rights.allowGrant, Rights.allowGrantReply} ∩ embRightsSet R) := by + rw [hempty]; exact Set.notMem_empty _ + simp only [HolCompleteLattice.holInf, HolCompleteLattice.holBot, holInsert, + Set.mem_inter_iff, Set.mem_empty_iff_false, iff_false] + intro ⟨h1, h2⟩ + apply hmem + refine ⟨?_, (embRightsSet_mem rH R).mpr h2⟩ + cases rH <;> simp [embRights, Set.insert] at h1 ⊢ + · intro hempty + ext r + obtain ⟨rH, rfl⟩ : ∃ rH, r = embRights rH := ⟨unembRights r, (embRights_unemb r).symm⟩ + have hmem : rH ∉ HolCompleteLattice.holInf + (holInsert CapRights_A.rights.AllowGrant + (holInsert CapRights_A.rights.AllowGrantReply HolCompleteLattice.holBot)) R := by + rw [hempty]; exact Set.notMem_empty _ + simp only [Set.mem_inter_iff, Set.mem_empty_iff_false, iff_false] + intro ⟨h1, h2⟩ + apply hmem + refine ⟨?_, (embRightsSet_mem rH R).mp h2⟩ + cases rH <;> simp [embRights, holInsert, HolCompleteLattice.holBot, Set.insert] at h1 ⊢ + exact not_congr hiff + simp only [ne_eq] at hinter + rw [hsend, hinter] + | _ => simp [Structures_A.is_ep_cap] at hep + +theorem validFaultHandler_iff (cap : Structures_A.cap) : + Fl4Spec.validFaultHandler (embCap cap) ↔ Decode_A.valid_fault_handler cap = true := by + unfold Fl4Spec.validFaultHandler Decode_A.valid_fault_handler + simp only [HolCompleteLattice.holSup, HolCompleteLattice.holInf, Bool.or_eq_true, Bool.and_eq_true, + holEq_eq_true] + rw [isEpCap_eq] + have hnull : Cap.nullCap = embCap cap ↔ Structures_A.cap.NullCap = cap := by + cases cap <;> simp [embCap] + rw [hnull] + by_cases hep : Structures_A.is_ep_cap cap = true + · rw [hasHandlerRights_iff cap hep] + · simp [hep] + +private def IsThreadControlCaps : Invocations_A.tcb_invocation → Prop + | .ThreadControlCaps _ _ _ _ _ _ _ => True + | _ => False + +private theorem decodeSetIpcBuffer_equiv_strong (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (excs : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (fun iH iL => iL = embTcbInv iH ∧ IsThreadControlCaps iH) + (Decode_A.decode_set_ipc_buffer args cap slot excs) + (Fl4Spec.decodeSetIpcBuffer args (embCap cap) slot + (excs.map fun p => (embCap p.1, p.2))) := by + unfold Decode_A.decode_set_ipc_buffer Fl4Spec.decodeSetIpcBuffer + dsimp only [holFunApp] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun _ => ?_ + · simp [holEq_eq_true, holSize_list, HolZero.zeroVal] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hec0 : the ((excs.map fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2))[0]?) = + (embCap (holNth excs 0).1, (holNth excs 0).2) := + the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) excs 0 + (by simp only [List.length_map] at hne; omega) + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun bufH bufL hbuf => ?_ + subst hbuf + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) (by rw [hec0]; exact ⟨rfl, rfl⟩)) ?_ + rintro ⟨bcH, bsH⟩ ⟨bcL, bsL⟩ ⟨hbc, hbs⟩ + subst hbc; subst hbs + simp only [holCaseProd_eq] + refine mrele_bindE (Ra := OptRel (ProdRel (FunRel embCap) Eq)) ?_ fun nbH nbL hnb => ?_ + · refine mrele_if (by rw [holEq_eq_true]; rfl) (fun _ => mrele_returnOk trivial) fun _ => ?_ + refine mrele_bindE (deriveCap_equiv bsH bcH) fun bcapH bcapL hbcap => ?_ + subst hbcap + refine mrele_kbindE (checkValidIpcBuffer_equiv bufH bcapH) ?_ + exact mrele_returnOk ⟨rfl, rfl⟩ + · refine mrele_returnOk ⟨?_, trivial⟩ + rw [objRefOf_eq] + simp only [embTcbInv] + congr 1; congr 1; congr 1 + cases nbH <;> cases nbL <;> simp [OptRel, ProdRel, FunRel] at hnb ⊢ + exact Prod.ext hnb.1 hnb.2.symm + +theorem decodeSetIpcBuffer_equiv (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (excs : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_set_ipc_buffer args cap slot excs) + (Fl4Spec.decodeSetIpcBuffer args (embCap cap) slot + (excs.map fun p => (embCap p.1, p.2))) := + mrel_conseq_res (decodeSetIpcBuffer_equiv_strong args cap slot excs) fun xH xL hx => by + cases xH <;> cases xL <;> simp [SumExceptRel] at hx ⊢ + · exact hx + · exact hx.1 + +theorem checkHandlerEp_equiv (pos : Nat) (hCap : Structures_A.cap) (hSlot : CslotPtr) : + MRelE SR (FunRel embSyscallError) (ProdRel (FunRel embCap) Eq) + (Decode_A.check_handler_ep pos (hCap, hSlot)) + (Fl4Spec.checkHandlerEp pos (embCap hCap, hSlot)) := by + unfold Decode_A.check_handler_ep Fl4Spec.checkHandlerEp + refine mrele_kbindE (mrele_unlessE (validFaultHandler_iff hCap).symm fun _ => + mrele_throwError rfl) ?_ + exact mrele_returnOk ⟨rfl, rfl⟩ + +private theorem getTcbCtablePtr_eq (p : ObjRef) : + Fl4Spec.getTcbCtablePtr p = Tcb_A.get_tcb_ctable_ptr p := rfl + +private theorem getTcbVtablePtr_eq (p : ObjRef) : + Fl4Spec.getTcbVtablePtr p = Tcb_A.get_tcb_vtable_ptr p := rfl + +private theorem isValidVtableRoot_iff (cap : Structures_A.cap) : + ArchVSpace_A.is_valid_vtable_root cap = true ↔ Fl4Spec.isValidVtableRoot (embCap cap) := by + unfold ArchVSpace_A.is_valid_vtable_root Fl4Spec.isValidVtableRoot + simp only [holEx_eq_true, holEq_eq_true] + constructor + · rintro ⟨r, a, rfl⟩ + exact ⟨r, a, rfl⟩ + · rintro ⟨r, a, h⟩ + exact ⟨r, a, embCap_injective h⟩ + +private theorem AllowRecv_eq : Fl4Spec.AllowRecv = embRights CapRights_A.AllowRecv := rfl + +theorem wordToTcbFlags_eq (w : Word) : + Fl4Spec.wordToTcbFlags w = embTcbFlags (Structures_A.word_to_tcb_flags w) := by + ext f + cases f + change Fl4Spec.TcbFlag.fpuDisabled ∈ Fl4Spec.wordToTcbFlags w ↔ + embTcbFlag .FpuDisabled ∈ embTcbFlags (Structures_A.word_to_tcb_flags w) + rw [embTcbFlags_mem] + simp only [Fl4Spec.wordToTcbFlags, Structures_A.word_to_tcb_flags, holCollect_eq, + Set.mem_ofPred_eq, holNot_eq_true, ne_eq, holEq_eq_true, holWordAnd] + rw [BitVec.and_assoc] + rfl + +def decode_cv_space_p (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (excaps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.tcb_invocation) := + holBindE (holWhenE (holDisj (holLt args.length 2) (holLt excaps.length 2)) (holThrowError .TruncatedMessage)) (holKBind + (holBindE (holReturnOk (holNth args 0)) fun croot_data => + holBindE (holReturnOk (holNth args 1)) fun vroot_data => + holBindE (holReturnOk (holNth excaps 0)) fun croot_arg => + holBindE (holReturnOk (holNth excaps 1)) fun vroot_arg => + holBindE (holLiftE (holLiftM holNot (slot_cap_long_running_delete_p (Tcb_A.get_tcb_ctable_ptr (Structures_A.obj_ref_of cap))))) fun can_chg_cr => + holBindE (holLiftE (holLiftM holNot (slot_cap_long_running_delete_p (Tcb_A.get_tcb_vtable_ptr (Structures_A.obj_ref_of cap))))) fun can_chg_vr => + holBindE (holUnlessE (holConj can_chg_cr can_chg_vr) (holThrowError .IllegalOperation)) (holKBind + (holBindE (holReturnOk croot_arg.1) fun croot_cap => + holBindE (holReturnOk croot_arg.2) fun croot_slot => + holBindE (CSpace_A.derive_cap croot_slot + ((if holEq croot_data 0 = true then id else CSpace_A.update_cap_data false croot_data) croot_cap)) fun croot_cap' => + holBindE (holUnlessE (Structures_A.is_cnode_cap croot_cap') (holThrowError .IllegalOperation)) (holKBind + (holBindE (holReturnOk (croot_cap', croot_slot)) fun croot => + holBindE (holReturnOk vroot_arg.1) fun vroot_cap => + holBindE (holReturnOk vroot_arg.2) fun vroot_slot => + holBindE (CSpace_A.derive_cap vroot_slot + ((if holEq vroot_data 0 = true then id else CSpace_A.update_cap_data false vroot_data) vroot_cap)) fun vroot_cap' => + holBindE (holUnlessE (ArchVSpace_A.is_valid_vtable_root vroot_cap') (holThrowError .IllegalOperation)) (holKBind + (holBindE (holReturnOk (vroot_cap', vroot_slot)) fun vroot => + holReturnOk (.ThreadControlCaps (Structures_A.obj_ref_of cap) slot none none (some croot) (some vroot) none))))))))) + +private theorem patched_decodeCvSpace_equiv_strong (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (excaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (fun iH iL => iL = embTcbInv iH ∧ IsThreadControlCaps iH) + (decode_cv_space_p args cap slot excaps) + (Fl4Spec.decodeCvSpace args (embCap cap) slot + (excaps.map fun p => (embCap p.1, p.2))) := by + unfold decode_cv_space_p Fl4Spec.decodeCvSpace + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hge => ?_ + · simp [holDisj_eq_true, holLt_eq_true, HolOrd.ltVal, List.length_map] + have hgeE : 2 ≤ excaps.length := by simp only [List.length_map] at hge; omega + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun cdH cdL hcd => ?_ + subst hcd + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun vdH vdL hvd => ?_ + subst hvd + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) excaps 0 (by omega)]; exact ⟨rfl, rfl⟩)) fun crH crL hcr => ?_ + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) excaps 1 (by omega)]; exact ⟨rfl, rfl⟩)) fun vrH vrL hvr => ?_ + have hnotL : ∀ mH mL, MRel SR Eq mH mL → + MRel SR Eq (holLiftM holNot mH) (NonDet.liftM not mL) := by + intro mH mL hm + unfold holLiftM NonDet.liftM + exact mrel_bind hm fun bH bL hb => by subst hb; exact mrel_return (by cases bH <;> rfl) + refine mrele_bindE (mrele_liftE (hnotL _ _ (by + rw [objRefOf_eq, getTcbCtablePtr_eq] + exact patched_slotCapLongRunningDelete_equiv _))) fun ccrH ccrL hccr => ?_ + subst hccr + refine mrele_bindE (mrele_liftE (hnotL _ _ (by + rw [objRefOf_eq, getTcbVtablePtr_eq] + exact patched_slotCapLongRunningDelete_equiv _))) fun cvrH cvrL hcvr => ?_ + subst hcvr + refine mrele_kbindE (mrele_unlessE (by simp [holConj_eq_true]) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) hcr.1) fun crcH crcL hcrc => ?_ + subst hcrc + refine mrele_bindE (mrele_returnOk (Ra := Eq) hcr.2) fun crsH crsL hcrs => ?_ + subst hcrs + have hcrUpd : (if cdH = 0 then id else Fl4Spec.updateCapData false cdH) (embCap crcH) = + embCap ((if holEq cdH 0 = true then id else CSpace_A.update_cap_data false cdH) crcH) := by + by_cases h0 : cdH = 0 + · have h0H : holEq cdH 0 = true := (holEq_eq_true cdH 0).mpr h0 + rw [ite_eq_left h0, ite_eq_left h0H]; rfl + · have h0H : holEq cdH 0 ≠ true := mt (holEq_eq_true cdH 0).mp h0 + rw [ite_eq_right h0, ite_eq_right h0H] + exact updateCapData_eq false cdH crcH + refine mrele_bindE (by rw [hcrUpd]; exact deriveCap_equiv crsH _) fun crc'H crc'L hcrc' => ?_ + subst hcrc' + refine mrele_kbindE (mrele_unlessE (by rw [isCnodeCap_eq]) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) ⟨rfl, rfl⟩) fun crootH crootL hcroot => ?_ + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) hvr.1) fun vrcH vrcL hvrc => ?_ + subst hvrc + refine mrele_bindE (mrele_returnOk (Ra := Eq) hvr.2) fun vrsH vrsL hvrs => ?_ + subst hvrs + have hvrUpd : (if vdH = 0 then id else Fl4Spec.updateCapData false vdH) (embCap vrcH) = + embCap ((if holEq vdH 0 = true then id else CSpace_A.update_cap_data false vdH) vrcH) := by + by_cases h0 : vdH = 0 + · have h0H : holEq vdH 0 = true := (holEq_eq_true vdH 0).mpr h0 + rw [ite_eq_left h0, ite_eq_left h0H]; rfl + · have h0H : holEq vdH 0 ≠ true := mt (holEq_eq_true vdH 0).mp h0 + rw [ite_eq_right h0, ite_eq_right h0H] + exact updateCapData_eq false vdH vrcH + refine mrele_bindE (by rw [hvrUpd]; exact deriveCap_equiv vrsH _) fun vrc'H vrc'L hvrc' => ?_ + subst hvrc' + refine mrele_kbindE (mrele_unlessE (by rw [isValidVtableRoot_iff]) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) ⟨rfl, rfl⟩) fun vrootH vrootL hvroot => ?_ + refine mrele_returnOk ?_ + rw [objRefOf_eq] + rcases crootH with ⟨c1, c2⟩; rcases crootL with ⟨c1L, c2L⟩ + rcases vrootH with ⟨v1, v2⟩; rcases vrootL with ⟨v1L, v2L⟩ + rcases hcroot with ⟨hc1, hc2⟩; rcases hvroot with ⟨hv1, hv2⟩ + subst hc1; subst hc2; subst hv1; subst hv2 + exact ⟨rfl, trivial⟩ + +theorem patched_decodeCvSpace_equiv (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (excaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (decode_cv_space_p args cap slot excaps) + (Fl4Spec.decodeCvSpace args (embCap cap) slot + (excaps.map fun p => (embCap p.1, p.2))) := + mrel_conseq_res (patched_decodeCvSpace_equiv_strong args cap slot excaps) fun xH xL hx => by + cases xH <;> cases xL <;> simp [SumExceptRel] at hx ⊢ + · exact hx + · exact hx.1 + +def decode_set_space_p (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (excaps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.tcb_invocation) := + holBindE (holWhenE (holDisj (holLt args.length 2) (holLt excaps.length 3)) (holThrowError .TruncatedMessage)) (holKBind + (holBindE (decode_cv_space_p (args.take 2) cap slot ((excaps.drop 1).take 2)) fun space => + holBindE (holReturnOk (holNth excaps 0)) fun fh_arg => + holBindE (Decode_A.check_handler_ep 1 fh_arg) fun fault_handler => + holReturnOk (.ThreadControlCaps (Structures_A.obj_ref_of cap) slot (some fault_handler) none + space.tc_new_croot space.tc_new_vroot none))) + +theorem patched_decodeSetSpace_equiv (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (excaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (decode_set_space_p args cap slot excaps) + (Fl4Spec.decodeSetSpace args (embCap cap) slot + (excaps.map fun p => (embCap p.1, p.2))) := by + unfold decode_set_space_p Fl4Spec.decodeSetSpace + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hge => ?_ + · simp [holDisj_eq_true, holLt_eq_true, HolOrd.ltVal, List.length_map] + have hgeE : 3 ≤ excaps.length := by simp only [List.length_map] at hge; omega + have hmapDT : ((excaps.map fun p => (embCap p.1, p.2)).drop 1).take 2 = + ((excaps.drop 1).take 2).map fun p => (embCap p.1, p.2) := by + rw [List.map_take, List.map_drop] + refine mrele_bindE (by rw [hmapDT]; exact patched_decodeCvSpace_equiv_strong (args.take 2) cap slot ((excaps.drop 1).take 2)) + fun spH spL hsp => ?_ + rcases hsp with ⟨rfl, htc⟩ + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) excaps 0 (by omega)]; exact ⟨rfl, rfl⟩)) fun fhH fhL hfh => ?_ + rcases fhH with ⟨fcH, fsH⟩; rcases fhL with ⟨fcL, fsL⟩ + rcases hfh with ⟨hfc, hfs⟩; subst hfc; subst hfs + refine mrele_bindE (checkHandlerEp_equiv 1 fcH fsH) fun resH resL hres => ?_ + rcases resH with ⟨rcH, rsH⟩; rcases resL with ⟨rcL, rsL⟩ + rcases hres with ⟨hrc, hrs⟩; subst hrc; subst hrs + refine mrele_returnOk ?_ + rw [objRefOf_eq] + cases spH <;> simp [IsThreadControlCaps] at htc + rfl + +theorem decodeUpdateSc_equiv (cap : Structures_A.cap) (slot : CslotPtr) (scCap : Structures_A.cap) : + MRelE SR (FunRel embSyscallError) Eq + (Decode_A.decode_update_sc cap slot scCap) + (Fl4Spec.decodeUpdateSc (embCap cap) slot (embCap scCap)) := by + unfold Decode_A.decode_update_sc Fl4Spec.decodeUpdateSc + dsimp only [holFunApp] + refine mrele_bindE (mrele_returnOk (Ra := Eq) (objRefOf_eq cap).symm) fun tpH tpL htp => ?_ + subst htp + refine mrele_bindE (mrele_liftE (getTcbObjRef_equiv (fun _ => rfl) tpH)) fun tscH tscL htsc => ?_ + subst htsc + have hfin : ∀ (scoH : Option ObjRef), + MRelE SR (FunRel embSyscallError) Eq + (holReturnOk (holIf (holNot (holEq tscH scoH)) (some scoH) none)) + (NonDetE.returnOk (if tscH ≠ scoH then some scoH else none)) := by + intro scoH + refine mrele_returnOk ?_ + by_cases h : tscH ≠ scoH + · have hH : holNot (holEq tscH scoH) = true := by simp [holNot_eq_true, holEq_eq_true, h] + rw [ite_eq_left h, hH, holIf_true] + · have hH : holNot (holEq tscH scoH) = false := Bool.eq_false_iff.mpr (by simp [holNot_eq_true, holEq_eq_true, h]) + rw [ite_eq_right h, hH, holIf_false] + cases scCap with + | NullCap => + simp only [Structures_A.case_cap, embCap, holBindE_assoc, holKBind] + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun _ _ hs => hs.curThread_eq.symm)) fun ctH ctL hct => ?_ + subst hct + refine mrele_kbindE (mrele_whenE (by rw [holEq_eq_true]) fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun scoH scoL hsco => ?_ + subst hsco + exact hfin scoH + | SchedContextCap scPtr scSz => + simp only [Structures_A.case_cap, embCap, holBindE_assoc, holKBind] + refine mrele_bindE (mrele_returnOk (Ra := Eq) (objRefOf_eq (.SchedContextCap scPtr scSz)).symm) fun spH spL hsp => ?_ + subst hsp + refine mrele_bindE (mrele_liftE (getScObjRef_equiv (fun _ => rfl) spH)) fun stH stL hst => ?_ + subst hst + refine mrele_kbindE (mrele_whenE + (by simp [holConj_eq_true, holDisj_eq_true, holNot_eq_true, holEq_eq_true]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (isBlocked_equiv tpH)) fun bH bL hb => ?_ + subst hb + refine mrele_bindE (mrele_liftE (getScReleased_equiv spH)) fun rH rL hr => ?_ + subst hr + refine mrele_kbindE (mrele_whenE (by simp [holConj_eq_true, holNot_eq_true]) + fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun scoH scoL hsco => ?_ + subst hsco + exact hfin scoH + | _ => + simp only [Structures_A.case_cap, embCap] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + +def decode_tcb_configure_p (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (extra_caps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.tcb_invocation) := + holBindE (holWhenE (holLt args.length 3) (holThrowError .TruncatedMessage)) (holKBind + (holBindE (holWhenE (holLt extra_caps.length 3) (holThrowError .TruncatedMessage)) (holKBind + (holBindE (holReturnOk (holNth args 2)) fun buffer => + holBindE (holReturnOk (holNth extra_caps 2)) fun buffer_cap => + holBindE (Decode_A.decode_set_ipc_buffer [buffer] cap slot [buffer_cap]) fun set_params => + holBindE (decode_cv_space_p (args.take 2) cap slot (extra_caps.take 2)) fun set_space => + holReturnOk (.ThreadControlCaps (Structures_A.obj_ref_of cap) slot none none + set_space.tc_new_croot set_space.tc_new_vroot set_params.tc_new_buffer))))) + +theorem patched_decodeTcbConfigure_equiv (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (extraCaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (decode_tcb_configure_p args cap slot extraCaps) + (Fl4Spec.decodeTcbConfigure args (embCap cap) slot + (extraCaps.map fun p => (embCap p.1, p.2))) := by + unfold decode_tcb_configure_p Fl4Spec.decodeTcbConfigure + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun _ => ?_ + · simp [holLt_eq_true, HolOrd.ltVal] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hge => ?_ + · simp [holLt_eq_true, HolOrd.ltVal, List.length_map] + have hgeE : 3 ≤ extraCaps.length := by simp only [List.length_map] at hge; omega + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun bufH bufL hbuf => ?_ + subst hbuf + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps 2 (by omega)]; exact ⟨rfl, rfl⟩)) fun bcH bcL hbc => ?_ + rcases bcH with ⟨cH, sH⟩; rcases bcL with ⟨cL, sL⟩ + rcases hbc with ⟨hc, hs⟩; subst hc; subst hs + refine mrele_bindE (by + have h1 := decodeSetIpcBuffer_equiv_strong (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + [bufH] cap slot [(cH, sH)] + simpa using h1) fun spH spL hsp => ?_ + rcases hsp with ⟨rfl, htc1⟩ + have hmapT : (extraCaps.map fun p => (embCap p.1, p.2)).take 2 = + (extraCaps.take 2).map fun p => (embCap p.1, p.2) := by + rw [List.map_take] + refine mrele_bindE (by rw [hmapT]; exact patched_decodeCvSpace_equiv_strong (args.take 2) cap slot (extraCaps.take 2)) + fun ssH ssL hss => ?_ + rcases hss with ⟨rfl, htc2⟩ + refine mrele_returnOk ?_ + rw [objRefOf_eq] + cases ssH <;> simp [IsThreadControlCaps] at htc2 + cases spH <;> simp [IsThreadControlCaps] at htc1 + rfl + +theorem decodeSetTimeoutEp_equiv (cap : Structures_A.cap) (slot : CslotPtr) + (extraCaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_set_timeout_ep cap slot extraCaps) + (Fl4Spec.decodeSetTimeoutEp (embCap cap) slot + (extraCaps.map fun p => (embCap p.1, p.2))) := by + unfold Decode_A.decode_set_timeout_ep Fl4Spec.decodeSetTimeoutEp + dsimp only [holFunApp] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hge => ?_ + · simp [holLt_eq_true, HolOrd.ltVal, holSize_list, HolOne.oneVal, List.length_map] + have hgeE : 1 ≤ extraCaps.length := by simp only [List.length_map] at hge; omega + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps 0 (by omega)]; exact ⟨rfl, rfl⟩)) fun thH thL hth => ?_ + rcases thH with ⟨cH, sH⟩; rcases thL with ⟨cL, sL⟩ + rcases hth with ⟨hc, hs⟩; subst hc; subst hs + refine mrele_bindE (checkHandlerEp_equiv 1 cH sH) fun resH resL hres => ?_ + rcases resH with ⟨rcH, rsH⟩; rcases resL with ⟨rcL, rsL⟩ + rcases hres with ⟨hrc, hrs⟩; subst hrc; subst hrs + exact mrele_returnOk (by rw [objRefOf_eq]; rfl) + +theorem decodeBindNotification_equiv (cap : Structures_A.cap) + (extraCaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_bind_notification cap extraCaps) + (Fl4Spec.decodeBindNotification (embCap cap) + (extraCaps.map fun p => (embCap p.1, p.2))) := by + cases cap with + | ThreadCap tcb => + unfold Decode_A.decode_bind_notification Fl4Spec.decodeBindNotification + dsimp only [holFunApp, Structures_A.case_cap] + change MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) _ + (do + NonDetE.whenE ((extraCaps.map fun p => (embCap p.1, p.2)).length = 0) (NonDetE.throwError .truncatedMessage) + let nTFN ← NonDetE.liftE (Fl4Spec.getTcbObjRef Fl4Spec.Tcb.tcbBoundNotification tcb) + match nTFN with + | some _ => NonDetE.throwError .illegalOperation + | none => NonDetE.returnOk () + let (ntfnptr, rights) ← match (the ((extraCaps.map fun p => (embCap p.1, p.2)).head?)).1 with + | .notificationCap ptr _ r => NonDetE.returnOk (ptr, r) + | _ => NonDetE.throwError .illegalOperation + NonDetE.whenE (Fl4Spec.AllowRecv ∉ rights) (NonDetE.throwError .illegalOperation) + let ntfn ← NonDetE.liftE (Fl4Spec.getNotification ntfnptr) + match ntfn.ntfnObj, ntfn.ntfnBoundTcb with + | .idleNtfn, none => NonDetE.returnOk () + | .activeNtfn _, none => NonDetE.returnOk () + | _, _ => NonDetE.throwError .illegalOperation + NonDetE.returnOk (.notificationControl tcb (some ntfnptr))) + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hne => ?_ + · simp [holEq_eq_true, holSize_list, HolZero.zeroVal, List.length_map] + have hneE : extraCaps ≠ [] := by intro h; simp [h] at hne + refine mrele_bindE (mrele_liftE (getTcbObjRef_equiv (fun _ => rfl) tcb)) fun nH nL hn => ?_ + subst hn + cases nH with + | some _ => + simp only [holCaseOption] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + | none => + simp only [holCaseOption] + refine mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) ?_ + have hhd : (the ((extraCaps.map fun p => (embCap p.1, p.2)).head?)).1 = + embCap (holHd extraCaps).1 := by + rw [the_head_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps hneE] + rw [hhd] + cases (holHd extraCaps).1 with + | NotificationCap ptr b r => + refine mrele_bindE (mrele_returnOk (Ra := ProdRel Eq (FunRel embRightsSet)) ⟨rfl, rfl⟩) ?_ + rintro ⟨npH, rH⟩ ⟨npL, rL⟩ ⟨hnp, hr⟩ + subst hnp; subst hr + simp only [holCaseProd_eq] + have hnr : holNot (holMember CapRights_A.AllowRecv rH) = true ↔ + Fl4Spec.AllowRecv ∉ embRightsSet rH := by + simp only [holNot_eq_true, ne_eq, holMember_eq_true, AllowRecv_eq, embRightsSet_mem] + refine mrele_kbindE (mrele_whenE hnr fun _ => mrele_throwError rfl) ?_ + refine mrele_bindE (mrele_liftE (getNotification_equiv npH)) fun ntH ntL hnt => ?_ + subst hnt + rcases ntH with ⟨obj, bt, sc⟩ + cases obj <;> cases bt <;> + simp only [Structures_A.case_ntfn, embNotification, embNtfn] + all_goals try exact mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) (mrele_returnOk rfl) + all_goals exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + | _ => + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + | _ => + unfold Decode_A.decode_bind_notification Fl4Spec.decodeBindNotification + simp only [Structures_A.case_cap, embCap] + exact mrele_throwError rfl + +theorem decodeUnbindNotification_equiv (cap : Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_unbind_notification cap) + (Fl4Spec.decodeUnbindNotification (embCap cap)) := by + cases cap with + | ThreadCap tcb => + unfold Decode_A.decode_unbind_notification Fl4Spec.decodeUnbindNotification + dsimp only [holFunApp] + simp only [Structures_A.case_cap, embCap] + refine mrele_bindE (mrele_liftE (getTcbObjRef_equiv (fun _ => rfl) tcb)) fun nH nL hn => ?_ + subst hn + cases nH with + | none => + simp only [holCaseOption] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + | some _ => + simp only [holCaseOption] + exact mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) (mrele_returnOk rfl) + | _ => + unfold Decode_A.decode_unbind_notification Fl4Spec.decodeUnbindNotification + simp only [Structures_A.case_cap, embCap] + exact mrele_throwError rfl + +theorem decodeSetTlsBase_equiv (args : List Data) (cap : Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_set_tls_base args cap) + (Fl4Spec.decodeSetTlsBase args (embCap cap)) := by + unfold Decode_A.decode_set_tls_base Fl4Spec.decodeSetTlsBase + refine mrele_kbindE (mrele_whenE (by simp [holEq_eq_true, HolZero.zeroVal]) fun _ => + mrele_throwError rfl) ?_ + exact mrele_returnOk (by rw [objRefOf_eq]; rfl) + +theorem decodeSetFlags_equiv (args : List Data) (cap : Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_set_flags args cap) + (Fl4Spec.decodeSetFlags args (embCap cap)) := by + unfold Decode_A.decode_set_flags Fl4Spec.decodeSetFlags + refine mrele_kbindE (mrele_whenE (by simp [holLt_eq_true, HolOrd.ltVal, holSize_list, HolNumeral.ofNatVal]) fun _ => mrele_throwError rfl) ?_ + exact mrele_returnOk (by rw [objRefOf_eq, wordToTcbFlags_eq, wordToTcbFlags_eq]; rfl) + +theorem decodeSetSchedParams_equiv (args : List Data) (cap : Structures_A.cap) (slot : CslotPtr) + (extraCaps : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (Decode_A.decode_set_sched_params args cap slot extraCaps) + (Fl4Spec.decodeSetSchedParams args (embCap cap) slot + (extraCaps.map fun p => (embCap p.1, p.2))) := by + unfold Decode_A.decode_set_sched_params Fl4Spec.decodeSetSchedParams + dsimp only [holFunApp] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun _ => ?_ + · simp [holLt_eq_true, HolOrd.ltVal, holSize_list, HolNumeral.ofNatVal] + refine mrele_kbindE_whenE_throw' (Re := FunRel embSyscallError) ?_ rfl fun hge => ?_ + · simp [holLt_eq_true, HolOrd.ltVal, holSize_list, HolNumeral.ofNatVal, List.length_map] + have hgeE : 3 ≤ extraCaps.length := by simp only [List.length_map] at hge; omega + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun mH mL hm => ?_ + subst hm + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pH pL hp => ?_ + subst hp + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps 0 (by omega)]; rfl)) fun acH acL hac => ?_ + subst hac + refine mrele_bindE (mrele_returnOk (Ra := FunRel embCap) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps 1 (by omega)]; rfl)) fun scH scL hsc => ?_ + subst hsc + refine mrele_bindE (mrele_returnOk (Ra := ProdRel (FunRel embCap) Eq) + (by rw [the_getElem_map (fun p : Structures_A.cap × CslotPtr => (embCap p.1, p.2)) extraCaps 2 (by omega)]; exact ⟨rfl, rfl⟩)) fun fhH fhL hfh => ?_ + rcases fhH with ⟨fcH, fsH⟩; rcases fhL with ⟨fcL, fsL⟩ + rcases hfh with ⟨hfc, hfs⟩; subst hfc; subst hfs + cases acH with + | ThreadCap tcbPtr => + simp only [Structures_A.case_cap] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun authH authL hauth => ?_ + subst hauth + refine mrele_kbindE (checkPrio_equiv _ authH) ?_ + refine mrele_kbindE (checkPrio_equiv _ authH) ?_ + refine mrele_bindE (decodeUpdateSc_equiv cap slot scH) fun scooH scooL hscoo => ?_ + subst hscoo + refine mrele_bindE (checkHandlerEp_equiv 3 fcH fsH) fun resH resL hres => ?_ + rcases resH with ⟨rcH, rsH⟩; rcases resL with ⟨rcL, rsL⟩ + rcases hres with ⟨hrc, hrs⟩; subst hrc; subst hrs + exact mrele_returnOk (by rw [objRefOf_eq]; rfl) + | _ => + simp only [Structures_A.case_cap] + exact mrele_kbindE_throwError (Re := FunRel embSyscallError) rfl + +def decode_tcb_invocation_p (label : Data) (args : List Data) (cap : Structures_A.cap) + (slot : CslotPtr) (excs : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.tcb_invocation) := + match gen_invocation_type label with + | .TCBReadRegisters => Decode_A.decode_read_registers args cap + | .TCBWriteRegisters => Decode_A.decode_write_registers args cap + | .TCBCopyRegisters => Decode_A.decode_copy_registers args cap (excs.map Prod.fst) + | .TCBConfigure => decode_tcb_configure_p args cap slot excs + | .TCBSetPriority => Decode_A.decode_set_priority args cap slot excs + | .TCBSetMCPriority => Decode_A.decode_set_mcpriority args cap slot excs + | .TCBSetSchedParams => Decode_A.decode_set_sched_params args cap slot excs + | .TCBSetTimeoutEndpoint => Decode_A.decode_set_timeout_ep cap slot excs + | .TCBSetIPCBuffer => Decode_A.decode_set_ipc_buffer args cap slot excs + | .TCBSetSpace => decode_set_space_p args cap slot excs + | .TCBSuspend => holReturnOk (.Suspend (Structures_A.obj_ref_of cap)) + | .TCBResume => holReturnOk (.Resume (Structures_A.obj_ref_of cap)) + | .TCBBindNotification => Decode_A.decode_bind_notification cap excs + | .TCBUnbindNotification => Decode_A.decode_unbind_notification cap + | .TCBSetTLSBase => Decode_A.decode_set_tls_base args cap + | .TCBSetFlags => Decode_A.decode_set_flags args cap + | _ => holThrowError .IllegalOperation + +theorem patched_decodeTcbInvocation_equiv (label : Data) (args : List Data) (ptr : ObjRef) + (slot : CslotPtr) (excs : List (Structures_A.cap × CslotPtr)) : + MRelE SR (FunRel embSyscallError) (FunRel embTcbInv) + (decode_tcb_invocation_p label args (.ThreadCap ptr) slot excs) + (Fl4Spec.decodeTcbInvocation label args (embCap (.ThreadCap ptr)) slot + (excs.map fun p => (embCap p.1, p.2))) := by + unfold decode_tcb_invocation_p Fl4Spec.decodeTcbInvocation + rw [genInvocationType_eq] + cases gen_invocation_type label + all_goals try exact mrele_throwError rfl + · exact decodeReadRegisters_equiv args ptr + · exact decodeWriteRegisters_equiv args ptr + · have hmap : (excs.map fun p => (embCap p.1, p.2)).map Prod.fst = + (excs.map Prod.fst).map embCap := by + simp [List.map_map, Function.comp_def] + rw [hmap] + exact decodeCopyRegisters_equiv args ptr (excs.map Prod.fst) + · exact patched_decodeTcbConfigure_equiv args (.ThreadCap ptr) slot excs + · exact decodeSetPriority_equiv args (.ThreadCap ptr) slot excs + · exact decodeSetMcpriority_equiv args (.ThreadCap ptr) slot excs + · exact decodeSetSchedParams_equiv args (.ThreadCap ptr) slot excs + · exact decodeSetTimeoutEp_equiv (.ThreadCap ptr) slot excs + · exact decodeSetIpcBuffer_equiv args (.ThreadCap ptr) slot excs + · exact patched_decodeSetSpace_equiv args (.ThreadCap ptr) slot excs + · exact mrele_returnOk (by rw [objRefOf_eq]; rfl) + · exact mrele_returnOk (by rw [objRefOf_eq]; rfl) + · exact decodeBindNotification_equiv (.ThreadCap ptr) excs + · exact decodeUnbindNotification_equiv (.ThreadCap ptr) + · exact decodeSetTlsBase_equiv args (.ThreadCap ptr) + · exact decodeSetFlags_equiv args (.ThreadCap ptr) + +/-! ### X64 I/O port invocations -/ + +theorem ensurePortOperationAllowed_equiv (cap : Arch_Structs_A.arch_cap) + (start : BitVec 32) (size : Nat) : + MRelE SR (FunRel embSyscallError) Eq + (ArchDecode_A.ensure_port_operation_allowed cap start size) + (Fl4Spec.ensurePortOperationAllowed (embArchCap cap) start size) := by + cases cap with + | IOPortCap first last => + unfold ArchDecode_A.ensure_port_operation_allowed Fl4Spec.ensurePortOperationAllowed + simp only [Arch_Structs_A.case_arch_cap, embArchCap, holFunApp] + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun eH eL he => ?_ + subst he + refine mrele_kbindE (mrele_assertE (by rw [holLe_eq_true]; rfl)) ?_ + refine mrele_kbindE (mrele_assertE (by rw [holLe_eq_true]; rfl)) ?_ + exact mrele_whenE (by rw [holDisj_eq_true, holLt_eq_true, holLt_eq_true]; rfl) + fun _ => mrele_throwError rfl + | _ => exact mrele_fail_liftE + +/-- l4v: ArchDecode_A.decode_port_invocation, using the FL4 label ABI. -/ +def decode_port_invocation_p (label : Data) (args : List Data) (cap : Arch_Structs_A.arch_cap) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + let check := fun n => holWhenE (holLt args.length n) (holThrowError .TruncatedMessage) + let readPort := fun size op => holBindE (check 1) (holKBind + (holBindE (holReturnOk (holUcast (w := 16) (holNth args 0))) fun port => + holBindE (ArchDecode_A.ensure_port_operation_allowed cap (holUcast (w := 32) port) size) (holKBind + (holReturnOk (.InvokeIOPort (.IOPortInvocation port op)))))) + let writePort := fun {width : Nat} size (op : BitVec width → ArchInvocation_A.io_port_invocation_data) => + holBindE (check 2) (holKBind + (holBindE (holReturnOk (holUcast (w := 16) (holNth args 0))) fun port => + holBindE (ArchDecode_A.ensure_port_operation_allowed cap (holUcast (w := 32) port) size) (holKBind + (holBindE (holReturnOk (holUcast (w := width) (holNth args 1))) fun value => + holReturnOk (.InvokeIOPort (.IOPortInvocation port (op value))))))) + match Patched.invocation_type label with + | .ArchInvocationLabel .X64IOPortIn8 => readPort 1 .IOPortIn8 + | .ArchInvocationLabel .X64IOPortIn16 => readPort 2 .IOPortIn16 + | .ArchInvocationLabel .X64IOPortIn32 => readPort 4 .IOPortIn32 + | .ArchInvocationLabel .X64IOPortOut8 => writePort 1 .IOPortOut8 + | .ArchInvocationLabel .X64IOPortOut16 => writePort 2 .IOPortOut16 + | .ArchInvocationLabel .X64IOPortOut32 => writePort 4 .IOPortOut32 + | _ => holThrowError .IllegalOperation + +theorem patched_decodePortInvocation_equiv (label : Data) (args : List Data) + (cap : Arch_Structs_A.arch_cap) : + MRelE SR (FunRel embSyscallError) (FunRel embArchInv) + (decode_port_invocation_p label args cap) + (Fl4Spec.decodePortInvocation label args (embArchCap cap)) := by + unfold decode_port_invocation_p Fl4Spec.decodePortInvocation + rw [← Patched.invocationType_equiv] + rcases Patched.invocation_type label with _ | arch + · exact mrele_throwError rfl + cases arch + all_goals try exact mrele_throwError rfl + all_goals + refine mrele_kbindE (mrele_whenE (by rw [holLt_eq_true]; rfl) + (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun pH pL hp => ?_ + subst hp + refine mrele_kbindE (ensurePortOperationAllowed_equiv cap _ _) ?_ + all_goals first + | exact mrele_returnOk rfl + | exact mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun _ _ h => by + subst h + exact mrele_returnOk rfl + +theorem isIoportRangeFree_equiv (first last : IoPort) : + MRel SR Eq (ArchDecode_A.is_ioport_range_free first last) + (Fl4Spec.isIoportRangeFree first last) := by + unfold ArchDecode_A.is_ioport_range_free Fl4Spec.isIoportRangeFree + refine mrel_bind (mrel_gets (Ra := Eq) (fun _ _ hs => by rw [hs.archState_eq]; rfl)) + fun fH fL hf => ?_ + subst hf + refine mrel_return (Bool.eq_iff_iff.mpr ?_) + rw [holEq_eq_true, decide_eq_true_eq] + rfl + +/-- l4v: ArchDecode_A.decode_ioport_control_invocation, with the FL4 labels +and the related CSpace operations. -/ +def decode_ioport_control_invocation_p (label : Data) (args : List Data) (slot : CslotPtr) + (caps : List Structures_A.cap) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error ArchInvocation_A.arch_invocation) := + holIf (holEq (Patched.invocation_type label) (.ArchInvocationLabel .X64IOPortControlIssue)) + (holIf (holConj (holLe 4 args.length) (holLe 1 caps.length)) + (let first := holUcast (w := 16) (holNth args 0) + let last := holUcast (w := 16) (holNth args 1) + holBindE (holWhenE (holLt last first) (holThrowError (.InvalidArgument 1))) (holKBind + (holBindE (holLiftE (ArchDecode_A.is_ioport_range_free first last)) fun free => + holBindE (holWhenE (holNot free) (holThrowError .RevokeFirst)) (holKBind + (holBindE (lookup_target_slot_p (holNth caps 0) + (Machine_A.data_to_cptr (holNth args 2)) (holUnsigned (holNth args 3))) fun dst => + holBindE (ensure_empty_p dst) (holKBind + (holReturnOk (.InvokeIOPortControl (.IOPortControlInvocation first last dst slot))))))))) + (holThrowError .TruncatedMessage)) + (holThrowError .IllegalOperation) + +theorem patched_decodeIoportControlInvocation_equiv (label : Data) (args : List Data) + (slot : CslotPtr) (cap : Arch_Structs_A.arch_cap) (caps : List Structures_A.cap) : + MRelE SR (FunRel embSyscallError) (FunRel embArchInv) + (decode_ioport_control_invocation_p label args slot caps) + (Fl4Spec.decodeIoportControlInvocation label args slot (embArchCap cap) (caps.map embCap)) := by + unfold decode_ioport_control_invocation_p Fl4Spec.decodeIoportControlInvocation + refine mrele_if (archInvocationLabel_iff label (.ArchInvocationLabel .X64IOPortControlIssue)) + ?_ (fun _ => mrele_throwError rfl) + intro _ + refine mrele_if (irqArgsAvailable 4 args caps) ?_ (fun _ => mrele_throwError rfl) + intro hlen + have hcap := hlen.2 + rw [List.length_map] at hcap + rw [the_getElem_map embCap caps 0 (by omega)] + refine mrele_kbindE (mrele_whenE (by rw [holLt_eq_true]; rfl) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (mrele_liftE (isIoportRangeFree_equiv _ _)) fun fH fL hf => ?_ + subst hf + refine mrele_kbindE (mrele_whenE (by simp [holNot_eq_true]) (fun _ => mrele_throwError rfl)) ?_ + refine mrele_bindE (patched_lookupTargetSlot_equiv _ _ _) fun dH dL hd => ?_ + subst hd + exact mrele_kbindE (patched_ensureEmpty_equiv dH) (mrele_returnOk rfl) + + +end +end L4vRefX64.Equiv.Decode diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Deterministic.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Deterministic.lean new file mode 100644 index 000000000..bec129501 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Deterministic.lean @@ -0,0 +1,697 @@ +import L4vRefX64.Rel.Extension +import L4vRefX64.Spec.Exceptions_A + +namespace L4vRefX64.Equiv.Deterministic + +open L4vRefX64.Prim +open L4vRefX64.Spec +open L4vRefX64.Rel +open Fl4Spec +open Classical + +noncomputable section + +/-! ## List_Lib -/ + +theorem listReplace_eq {α : Type} [Nonempty α] [DecidableEq α] (xs : List α) (a b : α) : + Fl4Spec.listReplace xs a b = List_Lib.list_replace xs a b := by + unfold Fl4Spec.listReplace List_Lib.list_replace + simp only [holListMap, holIf_eq, holEq_eq_true] + +theorem listReplaceList_eq {α : Type} [Nonempty α] [DecidableEq α] (xs : List α) (a : α) (ys : List α) : + Fl4Spec.listReplaceList xs a ys = List_Lib.list_replace_list xs a ys := by + induction xs with + | nil => rfl + | cons x xs ih => + simp only [Fl4Spec.listReplaceList, List_Lib.list_replace_list, + holIf_eq, holEq_eq_true, holListAppend_eq, ih] + +theorem listSwap_eq {α : Type} [Nonempty α] [DecidableEq α] (xs : List α) (a b : α) : + Fl4Spec.listSwap xs a b = List_Lib.list_swap xs a b := by + unfold Fl4Spec.listSwap List_Lib.list_swap + simp only [holListMap, holIf_eq, holEq_eq_true] + +theorem listInsertAfter_eq {α : Type} [Nonempty α] [DecidableEq α] (xs : List α) (a b : α) : + Fl4Spec.listInsertAfter xs a b = List_Lib.list_insert_after xs a b := by + induction xs with + | nil => rfl + | cons x xs ih => + simp only [Fl4Spec.listInsertAfter, List_Lib.list_insert_after, + holIf_eq, holEq_eq_true, ih] + +theorem listRemove_eq {α : Type} [Nonempty α] [DecidableEq α] (xs : List α) (a : α) : + Fl4Spec.listRemove xs a = List_Lib.list_remove xs a := by + induction xs with + | nil => rfl + | cons x xs ih => + simp only [Fl4Spec.listRemove, List_Lib.list_remove, + holIf_eq, holEq_eq_true, ih] + +theorem afterInList_eq {α : Type} [Nonempty α] [DecidableEq α] (xs : List α) (a : α) : + Fl4Spec.afterInList xs a = List_Lib.after_in_list xs a := by + induction xs with + | nil => rfl + | cons x xs ih => + cases xs with + | nil => rfl + | cons y ys => + simp only [Fl4Spec.afterInList, List_Lib.after_in_list, + holIf_eq, holEq_eq_true, ih] + +/-! ## Deterministic_A Pure Helpers & `next_not_child` -/ + +theorem workUnitsLimit_eq : Fl4Spec.workUnitsLimit = Deterministic_A.work_units_limit := rfl + +theorem transState_rel + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {AH AL BH BL : Type} [Nonempty AH] [Nonempty BH] + {RA : AH → AL → Prop} {RB : BH → BL → Prop} + (tH : AH → BH) (tL : AL → BL) (ht : ∀ aH aL, RA aH aL → RB (tH aH) (tL aL)) + {sH : Structures_A.state AH} {sL : State AL} + (hs : StateRel RestRel RA sH sL) : + StateRel RestRel RB (Deterministic_A.trans_state tH sH) (Fl4Spec.transState tL sL) := + { kheap_eq := hs.kheap_eq + cdt_eq := hs.cdt_eq + isOriginalCap_eq := hs.isOriginalCap_eq + curThread_eq := hs.curThread_eq + idleThread_eq := hs.idleThread_eq + idleSc_eq := hs.idleSc_eq + consumedTime_eq := hs.consumedTime_eq + curTime_eq := hs.curTime_eq + curSc_eq := hs.curSc_eq + reprogramTimer_eq := hs.reprogramTimer_eq + schedulerAction_eq := hs.schedulerAction_eq + domainList_eq := hs.domainList_eq + domainIndex_eq := hs.domainIndex_eq + domainStartIndex_eq := hs.domainStartIndex_eq + curDomain_eq := hs.curDomain_eq + domainTime_eq := hs.domainTime_eq + readyQueues_eq := hs.readyQueues_eq + releaseQueue_eq := hs.releaseQueue_eq + machineState_rel := hs.machineState_rel + interruptIrqNode_eq := hs.interruptIrqNode_eq + interruptStates_eq := hs.interruptStates_eq + archState_eq := hs.archState_eq + exst_rel := ht _ _ hs.exst_rel } + +theorem truncateState_rel + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {AH AL : Type} [Nonempty AH] {RA : AH → AL → Prop} + {sH : Structures_A.state AH} {sL : State AL} + (hs : StateRel RestRel RA sH sL) : + StateRel RestRel Eq (Deterministic_A.truncate_state sH) (Fl4Spec.truncateState sL) := + transState_rel _ _ (fun _ _ _ => rfl) hs + +theorem workUnitsCompleted_eq + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {sH : Structures_A.state Deterministic_A.det_ext} {sL : DetState} + (hs : StateRel RestRel (FunRel embDetExt) sH sL) : + Fl4Spec.workUnitsCompleted sL = Deterministic_A.work_units_completed sH := by + simp [Fl4Spec.workUnitsCompleted, Deterministic_A.work_units_completed, + Structures_A.state.exst, hs.exst_rel, embDetExt] + +theorem cdtList_eq + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {sH : Structures_A.state Deterministic_A.det_ext} {sL : DetState} + (hs : StateRel RestRel (FunRel embDetExt) sH sL) : + Fl4Spec.cdtList sL = Deterministic_A.cdt_list sH := by + simp [Fl4Spec.cdtList, Deterministic_A.cdt_list, Structures_A.state.exst, hs.exst_rel, embDetExt] + +theorem nextChild_eq (slot : CslotPtr) (t : CdtList) : + Fl4Spec.nextChild slot t = Deterministic_A.next_child slot t := by + unfold Fl4Spec.nextChild Deterministic_A.next_child + cases t slot <;> rfl + +theorem nextSib_eq (slot : CslotPtr) (t : CdtList) (m : Cdt) : + Fl4Spec.nextSib slot t m = Deterministic_A.next_sib slot t m := by + unfold Fl4Spec.nextSib Deterministic_A.next_sib + cases m slot with + | none => rfl + | some p => exact afterInList_eq (t p) slot + +/-- Universal Tarski `lfp` unfolding for binary Bool-valued relations (used by all `*_graph` defs). -/ +theorem holLfp_rel_eq_true {α β : Type} (F : (α → β → Bool) → α → β → Bool) (x : α) (y : β) : + HolCompleteLattice.holLfp F x y = true ↔ + ∀ P : α → β → Bool, (∀ a b, F P a b = true → P a b = true) → P x y = true := by + simp only [HolCompleteLattice.holLfp, HolCompleteLattice.holInfSet, HolCompleteLattice.holLe, + decide_eq_true_eq, Set.mem_ofPred_eq] + constructor + · intro h P hP + exact h (P x y) ⟨P x, ⟨P, hP, rfl⟩, rfl⟩ + · rintro h b ⟨g, ⟨P, hP, rfl⟩, rfl⟩ + exact h P hP + +/-- Exact graph equivalence between Isabelle's `function (domintros)` `next_not_child_graph` +and Lean's inductive `NextNotChildGraph`. -/ +theorem next_not_child_graph_iff (slot : CslotPtr) (t : CdtList) (m : Cdt) (r : Option CslotPtr) : + Deterministic_A.next_not_child_graph (slot, t, m) r = true ↔ + Fl4Spec.NextNotChildGraph t m slot r := by + unfold Deterministic_A.next_not_child_graph + rw [holLfp_rel_eq_true] + constructor + · intro h + let P0 : (CslotPtr × CdtList × Cdt) → Option CslotPtr → Bool := + fun x y => decide (Fl4Spec.NextNotChildGraph x.2.1 x.2.2 x.1 y) + have hP0 := h P0 (by + rintro ⟨s', t', m'⟩ r' hF + simp only [holEx_eq_true, holConj_eq_true, holEq_eq_true, holAll_eq_true, holImp_eq_true] at hF + rcases hF with ⟨f, s0, t0, m0, hpair, hr', hrec⟩ + have hs0 : s' = s0 := congrArg Prod.fst hpair + have ht0 : t' = t0 := congrArg (fun p => p.2.1) hpair + have hm0 : m' = m0 := congrArg (fun p => p.2.2) hpair + subst hs0; subst ht0; subst hm0 + simp only [P0, decide_eq_true_eq] + rw [hr'] + by_cases hns : Deterministic_A.next_sib s' t' m' = none + · have hnsL : Fl4Spec.nextSib s' t' m' = none := by rw [nextSib_eq]; exact hns + simp only [holIf_eq, holEq_eq_true, hns, ↓reduceIte] + cases hm : m' s' with + | none => + simp only [holCaseOption] + exact Fl4Spec.NextNotChildGraph.noSibNoParent hnsL hm + | some p => + simp only [holCaseOption] + have hp := hrec p hns hm + simp only [P0, decide_eq_true_eq] at hp + exact Fl4Spec.NextNotChildGraph.noSibParent hnsL hm hp + · have hnsL : Fl4Spec.nextSib s' t' m' ≠ none := by rw [nextSib_eq]; exact hns + simp only [holIf_eq, holEq_eq_true, ← nextSib_eq, hnsL, ↓reduceIte] + exact Fl4Spec.NextNotChildGraph.sib hnsL) + simpa [P0] using hP0 + · intro hG P hclosed + induction hG with + | @noSibNoParent s hns hm => + apply hclosed + simp only [holEx_eq_true, holConj_eq_true, holEq_eq_true, holAll_eq_true, holImp_eq_true] + refine ⟨fun _ => none, s, t, m, rfl, ?_, ?_⟩ + · have hnsH : Deterministic_A.next_sib s t m = none := by rw [← nextSib_eq]; exact hns + simp [holIf_eq, holEq_eq_true, hnsH, hm, holCaseOption] + · intro p _ hmp; rw [hm] at hmp; cases hmp + | @noSibParent s p r hns hm _ ih => + apply hclosed + simp only [holEx_eq_true, holConj_eq_true, holEq_eq_true, holAll_eq_true, holImp_eq_true] + refine ⟨fun _ => r, s, t, m, rfl, ?_, ?_⟩ + · have hnsH : Deterministic_A.next_sib s t m = none := by rw [← nextSib_eq]; exact hns + simp [holIf_eq, holEq_eq_true, hnsH, hm, holCaseOption] + · intro p' _ hmp' + rw [hm] at hmp'; cases hmp' + exact ih + | @sib s hns => + apply hclosed + simp only [holEx_eq_true, holConj_eq_true, holEq_eq_true, holAll_eq_true, holImp_eq_true] + refine ⟨fun _ => none, s, t, m, rfl, ?_, ?_⟩ + · have hnsH : Deterministic_A.next_sib s t m ≠ none := by rw [← nextSib_eq]; exact hns + simp [holIf_eq, holEq_eq_true, hnsH, nextSib_eq] + · intro p hnsH _; exact absurd (by rw [nextSib_eq]; exact hnsH) hns + +theorem nextNotChildGraph_unique {t : CdtList} {m : Cdt} {slot : CslotPtr} {r₁ r₂ : Option CslotPtr} + (h₁ : Fl4Spec.NextNotChildGraph t m slot r₁) + (h₂ : Fl4Spec.NextNotChildGraph t m slot r₂) : r₁ = r₂ := by + induction h₁ generalizing r₂ with + | noSibNoParent hns hm => + cases h₂ with + | noSibNoParent => rfl + | noSibParent _ hm2 => rw [hm] at hm2; cases hm2 + | sib hns2 => exact absurd hns hns2 + | noSibParent hns hm _ ih => + cases h₂ with + | noSibNoParent _ hm2 => rw [hm] at hm2; cases hm2 + | noSibParent _ hm2 h2' => rw [hm] at hm2; cases hm2; exact ih h2' + | sib hns2 => exact absurd hns hns2 + | sib hns => + cases h₂ with + | noSibNoParent hns2 => exact absurd hns2 hns + | noSibParent hns2 => exact absurd hns2 hns + | sib => rfl + +/-- On its domain (`∃ r, NextNotChildGraph t m slot r`, equivalent to Isabelle's +`next_not_child_dom`), `Fl4Spec.nextNotChild` equals `Deterministic_A.next_not_child`. -/ +theorem nextNotChild_eq_on_dom (slot : CslotPtr) (t : CdtList) (m : Cdt) + (hdom : ∃ r, Fl4Spec.NextNotChildGraph t m slot r) : + Fl4Spec.nextNotChild slot t m = Deterministic_A.next_not_child slot t m := by + obtain ⟨r, hr⟩ := hdom + have huniq : ∀ y, Fl4Spec.NextNotChildGraph t m slot y ↔ y = r := fun y => + ⟨fun hy => nextNotChildGraph_unique hy hr, fun hy => hy ▸ hr⟩ + have huniqH : ∃! y, Deterministic_A.next_not_child_graph (slot, t, m) y = true := + ⟨r, (next_not_child_graph_iff slot t m r).mpr hr, + fun y hy => (huniq y).mp ((next_not_child_graph_iff slot t m y).mp hy)⟩ + have hL : Fl4Spec.nextNotChild slot t m = r := by + unfold Fl4Spec.nextNotChild Fl4Spec.The + have huniqL : ∃! y, Fl4Spec.NextNotChildGraph t m slot y := + ⟨r, hr, fun y hy => nextNotChildGraph_unique hy hr⟩ + simp only [huniqL, ↓reduceDIte] + exact nextNotChildGraph_unique (Classical.choose_spec huniqL).1 hr + have hH : Deterministic_A.next_not_child slot t m = r := by + unfold Deterministic_A.next_not_child Deterministic_A.next_not_child_sumC holTheDefault + simp only [huniqH, ↓reduceDIte] + exact (huniq _).mp ((next_not_child_graph_iff slot t m _).mp (Classical.choose_spec huniqH).1) + rw [hL, hH] + +theorem nextSlot_eq_on_dom (slot : CslotPtr) (t : CdtList) (m : Cdt) + (hdom : t slot ≠ [] ∨ ∃ r, Fl4Spec.NextNotChildGraph t m slot r) : + Fl4Spec.nextSlot slot t m = Deterministic_A.next_slot slot t m := by + unfold Fl4Spec.nextSlot Deterministic_A.next_slot + simp only [holIf_eq, holNot_eq_true, ne_eq, holEq_eq_true] + by_cases h : t slot ≠ [] + · simp [h, nextChild_eq] + · simp only [h, ↓reduceIte] + exact nextNotChild_eq_on_dom slot t m (hdom.resolve_left h) + +theorem nextRevokeCap_eq_on_some + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (slot : CslotPtr) {sH : Structures_A.state Deterministic_A.det_ext} {sL : DetState} + (hs : StateRel RestRel (FunRel embDetExt) sH sL) + (hchild : Deterministic_A.next_child slot (Deterministic_A.cdt_list sH) ≠ none) : + Fl4Spec.nextRevokeCap slot sL = Deterministic_A.next_revoke_cap slot sH := by + unfold Fl4Spec.nextRevokeCap Deterministic_A.next_revoke_cap + rw [cdtList_eq hs, nextChild_eq] + unfold Deterministic_A.cdt_list at hchild ⊢ + cases h : Deterministic_A.next_child slot (Structures_A.state.exst sH).cdt_list_internal with + | some v => rfl + | none => exact absurd h hchild + +theorem validList2_iff (t : CdtList) (m : Cdt) : + Deterministic_A.valid_list_2 t m = true ↔ Fl4Spec.validList2 t m := by + unfold Deterministic_A.valid_list_2 Fl4Spec.validList2 + have hdist : ∀ xs : List CslotPtr, holListDistinct xs = true ↔ xs.Nodup := by + intro xs + induction xs with + | nil => simp [holListDistinct] + | cons x xs ih => simp [holListDistinct, ih] + simp only [holConj_eq_true, holAll_eq_true, holEq_eq_true, hdist, holListSet_eq, holCollect_eq] + +theorem validList_iff + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {sH : Structures_A.state Deterministic_A.det_ext} {sL : DetState} + (hs : StateRel RestRel (FunRel embDetExt) sH sL) : + Deterministic_A.valid_list sH = true ↔ Fl4Spec.validList sL := by + unfold Deterministic_A.valid_list Fl4Spec.validList + rw [cdtList_eq hs, hs.cdt_eq] + exact validList2_iff _ _ + +/-! ## Deterministic_A Monadic Operations -/ + +section DetMonadEquiv +variable {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + +theorem setCdtList_equiv (t : CdtList) : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + (Deterministic_A.set_cdt_list t) (Fl4Spec.setCdtList t) := by + unfold Deterministic_A.set_cdt_list Fl4Spec.setCdtList + refine mrel_bind (mrel_get (Rs := StateRel RestRel (FunRel embDetExt))) ?_ + intro sH sL hs + refine mrel_put (transState_rel _ _ (fun dH dL hd => ?_) hs) + subst hd; rfl + +theorem updateCdtList_equiv (f : CdtList → CdtList) : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + (Deterministic_A.update_cdt_list f) (Fl4Spec.updateCdtList f) := by + unfold Deterministic_A.update_cdt_list Fl4Spec.updateCdtList + refine mrel_bind (mrel_gets (Ra := Eq) fun sH sL hs => (cdtList_eq hs).symm) ?_ + rintro tH tL rfl + exact setCdtList_equiv (f tH) + +theorem capSwapExt_equiv (slot1 slot2 : CslotPtr) (slot1Op slot2Op : Option CslotPtr) : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + (Deterministic_A.cap_swap_ext slot1 slot2 slot1Op slot2Op) + (Fl4Spec.capSwapExt slot1 slot2 slot1Op slot2Op) := by + unfold Deterministic_A.cap_swap_ext Fl4Spec.capSwapExt + have h1 : (fun list : CdtList => + holFunUpd (holFunUpd list slot1 (list slot2)) slot2 (list slot1)) = + (fun list : CdtList => + Function.update (Function.update list slot1 (list slot2)) slot2 (list slot1)) := by + funext list k; simp [holFunUpd_eq, Function.update] + have h2 : (fun list : CdtList => + holCaseOption + (holCaseOption list (fun slot2_p => holFunUpd list slot2_p (List_Lib.list_replace (list slot2_p) slot1 slot2)) + (holIf (holEq slot1Op (some slot1)) (some slot2) (holIf (holEq slot1Op (some slot2)) (some slot1) slot1Op))) + (fun slot1_p => holCaseOption + (holFunUpd list slot1_p (List_Lib.list_replace (list slot1_p) slot2 slot1)) + (fun slot2_p => holIf (holEq slot1_p slot2_p) + (holFunUpd list slot1_p (List_Lib.list_swap (list slot1_p) slot1 slot2)) + (holFunUpd (holFunUpd list slot1_p (List_Lib.list_replace (list slot1_p) slot2 slot1)) + slot2_p (List_Lib.list_replace (list slot2_p) slot1 slot2))) + (holIf (holEq slot1Op (some slot1)) (some slot2) (holIf (holEq slot1Op (some slot2)) (some slot1) slot1Op))) + (holIf (holEq slot2Op (some slot1)) (some slot2) (holIf (holEq slot2Op (some slot2)) (some slot1) slot2Op))) = + (fun list : CdtList => + match (if slot2Op = some slot1 then some slot2 else if slot2Op = some slot2 then some slot1 else slot2Op) with + | none => + match (if slot1Op = some slot1 then some slot2 else if slot1Op = some slot2 then some slot1 else slot1Op) with + | none => list + | some slot2P => Function.update list slot2P (Fl4Spec.listReplace (list slot2P) slot1 slot2) + | some slot1P => + match (if slot1Op = some slot1 then some slot2 else if slot1Op = some slot2 then some slot1 else slot1Op) with + | none => Function.update list slot1P (Fl4Spec.listReplace (list slot1P) slot2 slot1) + | some slot2P => + if slot1P = slot2P + then Function.update list slot1P (Fl4Spec.listSwap (list slot1P) slot1 slot2) + else Function.update (Function.update list slot1P (Fl4Spec.listReplace (list slot1P) slot2 slot1)) + slot2P (Fl4Spec.listReplace (list slot2P) slot1 slot2)) := by + funext list k + simp only [holIf_eq, holEq_eq_true, holFunUpd_eq, ← listReplace_eq, ← listSwap_eq] + cases (if slot2Op = some slot1 then some slot2 else if slot2Op = some slot2 then some slot1 else slot2Op) <;> + cases (if slot1Op = some slot1 then some slot2 else if slot1Op = some slot2 then some slot1 else slot1Op) <;> + simp [holCaseOption, Function.update] + split_ifs <;> simp [Function.update] + rw [h1, h2] + exact mrel_kbind (updateCdtList_equiv _) (updateCdtList_equiv _) + +theorem capMoveExt_equiv (srcSlot destSlot : CslotPtr) (srcP destP : Option CslotPtr) : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + (Deterministic_A.cap_move_ext srcSlot destSlot srcP destP) + (Fl4Spec.capMoveExt srcSlot destSlot srcP destP) := by + unfold Deterministic_A.cap_move_ext Fl4Spec.capMoveExt + have h1 : (fun list : CdtList => + holCaseOption list (fun p => holFunUpd list p (List_Lib.list_remove (list p) destSlot)) destP) = + (fun list : CdtList => match destP with + | none => list + | some p => Function.update list p (Fl4Spec.listRemove (list p) destSlot)) := by + funext list k; cases destP <;> simp [holCaseOption, holFunUpd_eq, ← listRemove_eq, Function.update] + have h2 : (fun list : CdtList => + holCaseOption list (fun p => holFunUpd list p (List_Lib.list_replace (list p) srcSlot destSlot)) srcP) = + (fun list : CdtList => match srcP with + | none => list + | some p => Function.update list p (Fl4Spec.listReplace (list p) srcSlot destSlot)) := by + funext list k; cases srcP <;> simp [holCaseOption, holFunUpd_eq, ← listReplace_eq, Function.update] + have h3 : (fun list : CdtList => + holFunUpd (holFunUpd list srcSlot []) destSlot (holListAppend (list srcSlot) (list destSlot))) = + (fun list : CdtList => + Function.update (Function.update list srcSlot []) destSlot (list srcSlot ++ list destSlot)) := by + funext list k; simp [holFunUpd_eq, holListAppend_eq, Function.update] + rw [h1, h2, h3] + refine mrel_kbind (updateCdtList_equiv _) (mrel_if (by simp [holEq_eq_true]) (fun _ => mrel_return rfl) fun _ => ?_) + exact mrel_kbind (updateCdtList_equiv _) (updateCdtList_equiv _) + +theorem capInsertExt_equiv (srcParent : Bool) (srcSlot destSlot : CslotPtr) (srcP destP : Option CslotPtr) : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + (Deterministic_A.cap_insert_ext srcParent srcSlot destSlot srcP destP) + (Fl4Spec.capInsertExt srcParent srcSlot destSlot srcP destP) := by + unfold Deterministic_A.cap_insert_ext Fl4Spec.capInsertExt + have h1 : (fun list : CdtList => + holCaseOption list (fun p => holFunUpd list p (List_Lib.list_remove (list p) destSlot)) destP) = + (fun list : CdtList => match destP with + | none => list + | some p => Function.update list p (Fl4Spec.listRemove (list p) destSlot)) := by + funext list k; cases destP <;> simp [holCaseOption, holFunUpd_eq, ← listRemove_eq, Function.update] + have h2 : (fun list : CdtList => + holCaseOption + (holFunUpd list srcSlot (holIf srcParent (holListAppend [destSlot] (list srcSlot)) (list srcSlot))) + (fun p => holFunUpd + (holFunUpd list srcSlot (holIf srcParent (holListAppend [destSlot] (list srcSlot)) (list srcSlot))) + p (holIf (holConj srcParent (holNot (holEq p srcSlot))) (list p) + (holIf (holNot (holEq srcSlot destSlot)) (List_Lib.list_insert_after (list p) srcSlot destSlot) + (destSlot :: list p)))) + srcP) = + (fun list : CdtList => match srcP with + | none => Function.update list srcSlot (if srcParent then [destSlot] ++ list srcSlot else list srcSlot) + | some p => Function.update + (Function.update list srcSlot (if srcParent then [destSlot] ++ list srcSlot else list srcSlot)) + p (if srcParent ∧ p ≠ srcSlot then list p + else if srcSlot ≠ destSlot then Fl4Spec.listInsertAfter (list p) srcSlot destSlot + else destSlot :: list p)) := by + funext list k + cases srcP <;> + simp [holCaseOption, holFunUpd_eq, holIf_eq, holConj_eq_true, holNot_eq_true, + holEq_eq_true, holListAppend_eq, ← listInsertAfter_eq, Function.update] + rw [h1, h2] + exact mrel_kbind (updateCdtList_equiv _) (updateCdtList_equiv _) + +theorem emptySlotExt_equiv (slot : CslotPtr) (slotP : Option CslotPtr) : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + (Deterministic_A.empty_slot_ext slot slotP) + (Fl4Spec.emptySlotExt slot slotP) := by + unfold Deterministic_A.empty_slot_ext Fl4Spec.emptySlotExt + have h1 : (fun list : CdtList => + holCaseOption (holFunUpd list slot []) + (fun p => holIf (holEq p slot) + (holFunUpd list p (List_Lib.list_remove (list p) slot)) + (holFunUpd (holFunUpd list p (List_Lib.list_replace_list (list p) slot (list slot))) slot [])) + slotP) = + (fun list : CdtList => match slotP with + | none => Function.update list slot [] + | some p => + if p = slot then Function.update list p (Fl4Spec.listRemove (list p) slot) + else Function.update (Function.update list p (Fl4Spec.listReplaceList (list p) slot (list slot))) slot []) := by + funext list k + cases slotP with + | none => simp [holCaseOption, holFunUpd_eq, Function.update] + | some p => + simp only [holCaseOption, holIf_eq, holEq_eq_true, holFunUpd_eq, ← listRemove_eq, ← listReplaceList_eq] + split_ifs <;> simp [Function.update] + rw [h1] + exact updateCdtList_equiv _ + +theorem createCapExt_equiv (untyped dest : CslotPtr) (destP : Option CslotPtr) : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + (Deterministic_A.create_cap_ext untyped dest destP) + (Fl4Spec.createCapExt untyped dest destP) := by + unfold Deterministic_A.create_cap_ext Fl4Spec.createCapExt + have h1 : (fun list : CdtList => + holCaseOption list (fun p => holFunUpd list p (List_Lib.list_remove (list p) dest)) destP) = + (fun list : CdtList => match destP with + | none => list + | some p => Function.update list p (Fl4Spec.listRemove (list p) dest)) := by + funext list k; cases destP <;> simp [holCaseOption, holFunUpd_eq, ← listRemove_eq, Function.update] + have h2 : (fun list : CdtList => holFunUpd list untyped (holListAppend [dest] (list untyped))) = + (fun list : CdtList => Function.update list untyped ([dest] ++ list untyped)) := by + funext list k; simp [holFunUpd_eq, holListAppend_eq, Function.update] + rw [h1, h2] + exact mrel_kbind (updateCdtList_equiv _) (updateCdtList_equiv _) + +theorem updateWorkUnits_equiv : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + Deterministic_A.update_work_units Fl4Spec.updateWorkUnits := by + unfold Deterministic_A.update_work_units Fl4Spec.updateWorkUnits + refine mrel_modify fun sH sL hs => transState_rel _ _ (fun dH dL hd => ?_) hs + subst hd + simp only [FunRel, embDetExt, Deterministic_A.det_ext.work_units_completed_internal_update, + HolAdd.addVal, HolOne.oneVal] + congr 1 + rw [workUnitsCompleted_eq hs] + rfl + +theorem resetWorkUnits_equiv : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + Deterministic_A.reset_work_units Fl4Spec.resetWorkUnits := by + unfold Deterministic_A.reset_work_units Fl4Spec.resetWorkUnits + refine mrel_modify fun sH sL hs => transState_rel _ _ (fun dH dL hd => ?_) hs + subst hd + simp [FunRel, embDetExt, Deterministic_A.det_ext.work_units_completed_internal_update, + HolZero.zeroVal] + +theorem workUnitsLimitReached_equiv : + MRel (StateRel RestRel (FunRel embDetExt)) Eq + Deterministic_A.work_units_limit_reached Fl4Spec.workUnitsLimitReached := by + unfold Deterministic_A.work_units_limit_reached Fl4Spec.workUnitsLimitReached + refine mrel_bind (mrel_gets (Ra := Eq) fun sH sL hs => (workUnitsCompleted_eq hs).symm) ?_ + rintro wH wL rfl + refine mrel_return ?_ + apply Bool.eq_iff_iff.mpr + rw [holLe_eq_true, workUnitsLimit_eq] + change Deterministic_A.work_units_limit ≤ wH ↔ decide (Deterministic_A.work_units_limit ≤ wH) = true + by_cases h : Deterministic_A.work_units_limit ≤ wH <;> simp [h] + +/-! ## `OR_choice`, `OR_choiceE`, `do_extended_op`, `select_ext` -/ + +section ExtOps +variable {ZH ZL : Type} [Nonempty ZH] [Deterministic_A.state_ext_class ZH] [StateExt ZL] +variable [ser : StateExtRel RestRel ZH ZL] + +theorem mrel_selectF_mkEf {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {mH : Set (αH × σH) × Bool} {mL : Set (αL × σL) × Prop} + (hfail : mH.2 = true ↔ mL.2) + (h1 : ∀ aH sH', (aH, sH') ∈ mH.1 → ∃ aL sL', (aL, sL') ∈ mL.1 ∧ Ra aH aL ∧ Rs sH' sL') + (h2 : ∀ aL sL', (aL, sL') ∈ mL.1 → ∃ aH sH', (aH, sH') ∈ mH.1 ∧ Ra aH aL ∧ Rs sH' sL') : + MRel Rs (ProdRel Ra Rs) (holSelectF (holMkEf mH)) (NonDet.selectF (NonDet.mkEf mL)) := by + refine mrel_selectF (Ra := ProdRel Ra Rs) ?_ ⟨?_, ?_⟩ + · unfold holMkEf NonDet.mkEf + simp only [decide_eq_true_eq] + constructor + · rintro (h | h) + · exact Or.inl (by + ext ⟨aL, sL'⟩; simp only [Set.mem_empty_iff_false, iff_false] + intro hm; obtain ⟨aH, sH', hmH, _, _⟩ := h2 aL sL' hm; rw [h] at hmH; exact hmH) + · exact Or.inr (hfail.mp h) + · rintro (h | h) + · exact Or.inl (by + ext ⟨aH, sH'⟩; simp only [Set.mem_empty_iff_false, iff_false] + intro hm; obtain ⟨aL, sL', hmL, _, _⟩ := h1 aH sH' hm; rw [h] at hmL; exact hmL) + · exact Or.inr (hfail.mpr h) + · rintro ⟨aH, sH'⟩ hmH + obtain ⟨aL, sL', hmL, ha, hs'⟩ := h1 aH sH' hmH + exact ⟨(aL, sL'), hmL, ha, hs'⟩ + · rintro ⟨aL, sL'⟩ hmL + obtain ⟨aH, sH', hmH, ha, hs'⟩ := h2 aL sL' hmL + exact ⟨(aH, sH'), hmH, ha, hs'⟩ + +theorem orChoice_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + {cH : HolNonDet (Structures_A.state Deterministic_A.det_ext) Bool} + {cL : DetExtMonad Bool} + {fH gH : HolNonDet (Structures_A.state ZH) αH} + {fL gL : NonDet (State ZL) αL} + (hc : MRel (StateRel RestRel (FunRel embDetExt)) Eq cH cL) + (hf : MRel (StateRel RestRel ser.exstRel) Ra fH fL) + (hg : MRel (StateRel RestRel ser.exstRel) Ra gH gL) : + MRel (StateRel RestRel ser.exstRel) Ra + (Deterministic_A.OR_choice cH fH gH) (Fl4Spec.orChoice cL fL gL) := by + unfold Deterministic_A.OR_choice Fl4Spec.orChoice + refine mrel_bind (mrel_get (Rs := StateRel RestRel ser.exstRel)) ?_ + intro exH exL hex + obtain ⟨hfail, h1, h2⟩ := ser.wrapExtBool_rel cH cL hc exH exL hex + refine mrel_bind (mrel_selectF_mkEf hfail h1 h2) ?_ + rintro ⟨rvH, _⟩ ⟨rvL, _⟩ ⟨hrv, _⟩ + subst hrv + simp only [holCaseProd_eq] + exact mrel_if Iff.rfl (fun _ => hf) (fun _ => hg) + +theorem orChoiceE_equiv {εH εL αH αL : Type} [Nonempty εH] [Nonempty αH] + {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {cH : HolNonDet (Structures_A.state Deterministic_A.det_ext) Bool} + {cL : DetExtMonad Bool} + {fH gH : HolNonDet (Structures_A.state ZH) (Sum εH αH)} + {fL gL : NonDetE (State ZL) εL αL} + (hc : MRel (StateRel RestRel (FunRel embDetExt)) Eq cH cL) + (hf : MRelE (StateRel RestRel ser.exstRel) Re Ra fH fL) + (hg : MRelE (StateRel RestRel ser.exstRel) Re Ra gH gL) : + MRelE (StateRel RestRel ser.exstRel) Re Ra + (Deterministic_A.OR_choiceE cH fH gH) (Fl4Spec.orChoiceE cL fL gL) := by + unfold Deterministic_A.OR_choiceE Fl4Spec.orChoiceE + refine mrele_bindE (mrele_liftE (mrel_get (Rs := StateRel RestRel ser.exstRel))) ?_ + intro exH exL hex + obtain ⟨hfail, h1, h2⟩ := ser.wrapExtBool_rel cH cL hc exH exL hex + refine mrele_bindE (mrele_liftE (mrel_selectF_mkEf hfail h1 h2)) ?_ + rintro ⟨rvH, _⟩ ⟨rvL, _⟩ ⟨hrv, _⟩ + subst hrv + simp only [holCaseProd_eq] + exact mrel_if Iff.rfl (fun _ => hf) (fun _ => hg) + +theorem doExtendedOp_equiv + {eopH : HolNonDet (Structures_A.state Deterministic_A.det_ext) Unit} + {eopL : DetExtMonad Unit} + (heop : MRel (StateRel RestRel (FunRel embDetExt)) Eq eopH eopL) : + MRel (StateRel RestRel ser.exstRel) Eq + (Deterministic_A.do_extended_op eopH) (Fl4Spec.doExtendedOp eopL) := by + unfold Deterministic_A.do_extended_op Fl4Spec.doExtendedOp + refine mrel_bind (mrel_get (Rs := StateRel RestRel ser.exstRel)) ?_ + intro exH exL hex + obtain ⟨hfail, h1, h2⟩ := ser.wrapExtOp_rel eopH eopL heop exH exL hex + refine mrel_bind (mrel_selectF_mkEf hfail h1 h2) ?_ + rintro ⟨_, esH'⟩ ⟨_, esL'⟩ ⟨_, hes'⟩ + simp only [holCaseProd_eq] + exact mrel_modify fun sH sL hs => { hs with exst_rel := hes'.exst_rel } + +theorem selectExt_equiv {DH DL : Type} [Nonempty DH] {Rd : DH → DL → Prop} + {aH : Structures_A.state Deterministic_A.det_ext → DH} + {aL : DetState → DL} + {SH : Set DH} {SL : Set DL} + (ha : ∀ sH sL, StateRel RestRel (FunRel embDetExt) sH sL → Rd (aH sH) (aL sL)) + (hS : SetRel Rd SH SL) + (hSmem : ∀ xH xL, Rd xH xL → (xH ∈ SH ↔ xL ∈ SL)) : + MRel (StateRel RestRel ser.exstRel) Rd + (Deterministic_A.select_ext aH SH) (Fl4Spec.selectExt aL SL) := by + unfold Deterministic_A.select_ext Fl4Spec.selectExt + refine mrel_bind (mrel_get (Rs := StateRel RestRel ser.exstRel)) ?_ + intro sH sL hs + have hsw := ser.selectSwitch_eq sH.more.exst sL.exst hs.exst_rel + change MRel _ _ (holBind (holIf (Deterministic_A.state_ext_class.select_switch sH.more.exst) _ _) _) _ + by_cases htrue : StateExt.selectSwitch sL.exst = true + · have hH : Deterministic_A.state_ext_class.select_switch sH.more.exst = true := by + rw [hsw, htrue] + rw [hH] + simp only [htrue, holIf_true, ↓reduceIte] + refine mrel_bind (mrel_return (ha _ _ (ser.unwrapExt_rel sH sL hs htrue))) fun xH xL hx => ?_ + exact mrel_kbind (mrel_assert (by simp [holMember_eq_true, hSmem xH xL hx])) (mrel_return hx) + · have hH : Deterministic_A.state_ext_class.select_switch sH.more.exst = false := by + rw [hsw]; cases hb : StateExt.selectSwitch sL.exst <;> simp_all + rw [hH] + simp only [htrue, holIf_false, Bool.false_eq_true, ↓reduceIte] + refine mrel_bind (mrel_select hS) fun xH xL hx => ?_ + exact mrel_kbind (mrel_assert (by simp [holMember_eq_true, hSmem xH xL hx])) (mrel_return hx) + +/-! ## Exceptions_A -/ + +theorem withoutPreemption_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + {mH : HolNonDet (Structures_A.state ZH) αH} {mL : SMonad ZL αL} + (hm : MRel (StateRel RestRel ser.exstRel) Ra mH mL) : + MRelE (StateRel RestRel ser.exstRel) Eq Ra + (Exceptions_A.without_preemption mH) (Fl4Spec.withoutPreemption mL) := + mrele_liftE hm + +theorem capFaultOnFailure_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + (cptr : ObjRef) (rp : Bool) + {mH : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure αH)} + {mL : LFMonad ZL αL} + (hm : MRelE (StateRel RestRel ser.exstRel) (FunRel embLookupFailure) Ra mH mL) : + MRelE (StateRel RestRel ser.exstRel) (FunRel embFault) Ra + (Exceptions_A.cap_fault_on_failure cptr rp mH) (Fl4Spec.capFaultOnFailure cptr rp mL) := by + unfold Exceptions_A.cap_fault_on_failure Fl4Spec.capFaultOnFailure + refine mrele_handleE' hm fun eH eL he => ?_ + subst he + exact mrele_throwError (by simp [FunRel, embFault]) + +theorem lookupErrorOnFailure_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + (s : Bool) + {mH : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure αH)} + {mL : LFMonad ZL αL} + (hm : MRelE (StateRel RestRel ser.exstRel) (FunRel embLookupFailure) Ra mH mL) : + MRelE (StateRel RestRel ser.exstRel) (FunRel embSyscallError) Ra + (Exceptions_A.lookup_error_on_failure s mH) (Fl4Spec.lookupErrorOnFailure s mL) := by + unfold Exceptions_A.lookup_error_on_failure Fl4Spec.lookupErrorOnFailure + refine mrele_handleE' hm fun eH eL he => ?_ + subst he + exact mrele_throwError (by simp [FunRel, embSyscallError]) + +theorem nullCapOnFailure_equiv + {mH : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.lookup_failure Structures_A.cap)} + {mL : LFMonad ZL Cap} + (hm : MRelE (StateRel RestRel ser.exstRel) (FunRel embLookupFailure) (FunRel embCap) mH mL) : + MRel (StateRel RestRel ser.exstRel) (FunRel embCap) + (Exceptions_A.null_cap_on_failure mH) (Fl4Spec.nullCapOnFailure mL) := by + unfold Exceptions_A.null_cap_on_failure Fl4Spec.nullCapOnFailure + refine mrel_liftM (fun aH aL ha => ?_) hm + cases aH <;> cases aL <;> simp [SumExceptRel] at ha + · rfl + · exact ha + +theorem unifyFailure_equiv {FH FL αH αL : Type} [Nonempty FH] [Nonempty αH] + {Rf : FH → FL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet (Structures_A.state ZH) (Sum FH αH)} + {mL : NonDetE (State ZL) FL αL} + (hm : MRelE (StateRel RestRel ser.exstRel) Rf Ra mH mL) : + MRelE (StateRel RestRel ser.exstRel) Eq Ra + (Exceptions_A.unify_failure mH) (Fl4Spec.unifyFailure mL) := + mrele_handleE' hm fun _ _ _ => mrele_throwError rfl + +theorem emptyOnFailure_equiv {FH FL αH αL : Type} [Nonempty FH] [Nonempty αH] + {Rf : FH → FL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet (Structures_A.state ZH) (Sum FH (List αH))} + {mL : NonDetE (State ZL) FL (List αL)} + (hm : MRelE (StateRel RestRel ser.exstRel) Rf (ListRel Ra) mH mL) : + MRel (StateRel RestRel ser.exstRel) (ListRel Ra) + (Exceptions_A.empty_on_failure mH) (Fl4Spec.emptyOnFailure mL) := + mrele_catch hm fun _ _ _ => mrel_return ListRel.nil + +theorem constOnFailure_equiv {FH FL αH αL : Type} [Nonempty FH] [Nonempty αH] + {Rf : FH → FL → Prop} {Ra : αH → αL → Prop} + {cH : αH} {cL : αL} (hc : Ra cH cL) + {mH : HolNonDet (Structures_A.state ZH) (Sum FH αH)} + {mL : NonDetE (State ZL) FL αL} + (hm : MRelE (StateRel RestRel ser.exstRel) Rf Ra mH mL) : + MRel (StateRel RestRel ser.exstRel) Ra + (Exceptions_A.const_on_failure cH mH) (Fl4Spec.constOnFailure cL mL) := + mrele_catch hm fun _ _ _ => mrel_return hc + +theorem rangeCheck_equiv (v minV maxV : Word) : + MRelE (StateRel RestRel ser.exstRel) (FunRel embSyscallError) Eq + (Exceptions_A.range_check v minV maxV) (Fl4Spec.rangeCheck v minV maxV) := by + unfold Exceptions_A.range_check Fl4Spec.rangeCheck + refine mrele_unlessE ?_ (fun _ => mrele_throwError (by simp [FunRel, embSyscallError])) + simp [holConj_eq_true, holLe_eq_true, HolOrd.leVal] + +end ExtOps +end DetMonadEquiv + + +end + +end L4vRefX64.Equiv.Deterministic diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Fpu.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Fpu.lean new file mode 100644 index 000000000..c9a4a409a --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Fpu.lean @@ -0,0 +1,101 @@ +import L4vRefX64.Equiv.Hardware +import L4vRefX64.Equiv.KHeap +import L4vRefX64.Spec.FPU_A + +namespace L4vRefX64.Equiv.Fpu + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Hardware L4vRefX64.Equiv.KHeap +open Fl4Spec Classical + +noncomputable section + +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 + +private theorem currentFpuOwner_equiv : + MRel SR Eq + (holGets (holComp Arch_Structs_A.arch_state_ext.x64_current_fpu_owner + Structures_A.abstract_state_ext.arch_state)) + (NonDet.gets fun s : State ZL => s.archState.x64CurrentFpuOwner) := + mrel_gets fun sH sL hs => by rw [hs.archState_eq]; rfl + +theorem saveFpuState_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) : + MRel SR Eq (FPU_A.save_fpu_state thread) (Fl4Spec.saveFpuState thread) := by + unfold FPU_A.save_fpu_state Fl4Spec.saveFpuState + refine mrel_bind (mrel_doMachineOp (readFpuState_equiv hop)) fun fH fL hf => ?_ + subst hf + refine asUser_equiv (mrel_modify ?_) thread + intro sH sL hs + subst sL + cases sH + rfl + +theorem loadFpuState_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) : + MRel SR Eq (FPU_A.load_fpu_state thread) (Fl4Spec.loadFpuState thread) := by + unfold FPU_A.load_fpu_state Fl4Spec.loadFpuState + have hget : MRel (FunRel embUserContext) Eq MachineOps.getFPUState Fl4Spec.getFPUState := + mrel_gets fun sH sL hs => by subst sL; cases sH; rfl + refine mrel_bind (asUser_equiv hget thread) fun fH fL hf => ?_ + subst hf + exact mrel_doMachineOp (writeFpuState_equiv hop fH) + +private theorem setCurFpu_equiv (owner : Bool) (thread : ObjRef) : + MRel SR Eq + (KHeap_A.arch_thread_set (Arch_Structs_A.arch_tcb.tcb_cur_fpu_update fun _ => owner) thread) + (Fl4Spec.archThreadSet (fun t => { t with tcbCurFpu := owner }) thread) := + archThreadSet_equiv (fun _ => rfl) thread + +theorem setX64CurrentFpuOwner_equiv (owner : Option ObjRef) : + MRel SR Eq (FPU_A.set_x64_current_fpu_owner owner) (Fl4Spec.setX64CurrentFpuOwner owner) := by + unfold FPU_A.set_x64_current_fpu_owner Fl4Spec.setX64CurrentFpuOwner + refine mrel_bind (currentFpuOwner_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL)) fun oldH oldL h => ?_ + subst h + refine mrel_kbind (mrel_maybeM (Ra := Eq) (fun tH tL ht => by subst ht; exact setCurFpu_equiv false tH) + (by cases oldH <;> simp [OptRel])) ?_ + refine mrel_kbind (mrel_modify ?_) ?_ + · intro sH sL hs + have harch := congrArg (fun ar : ArchState => { ar with x64CurrentFpuOwner := owner }) hs.archState_eq + exact { hs with archState_eq := harch } + · exact mrel_maybeM (Ra := Eq) (fun tH tL ht => by subst ht; exact setCurFpu_equiv true tH) + (by cases owner <;> simp [OptRel]) + +theorem switchLocalFpuOwner_equiv (hop : OpaqueRel RestRel) (owner : Option ObjRef) : + MRel SR Eq (FPU_A.switch_local_fpu_owner owner) (Fl4Spec.switchLocalFpuOwner owner) := by + unfold FPU_A.switch_local_fpu_owner Fl4Spec.switchLocalFpuOwner + refine mrel_bind (currentFpuOwner_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL)) fun oldH oldL h => ?_ + subst h + refine mrel_kbind (mrel_doMachineOp (enableFpu_equiv hop)) ?_ + refine mrel_kbind (mrel_maybeM (Ra := Eq) (fun tH tL ht => by subst ht; exact saveFpuState_equiv hop tH) + (by cases oldH <;> simp [OptRel])) ?_ + have hset := setX64CurrentFpuOwner_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) owner + cases owner with + | none => exact mrel_kbind (mrel_doMachineOp (disableFpu_equiv hop)) hset + | some thread => exact mrel_kbind (loadFpuState_equiv hop thread) hset + +theorem fpuRelease_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) : + MRel SR Eq (FPU_A.fpu_release thread) (Fl4Spec.fpuRelease thread) := by + unfold FPU_A.fpu_release Fl4Spec.fpuRelease + refine mrel_bind (currentFpuOwner_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL)) fun oldH oldL h => ?_ + subst h + exact mrel_when (holEq_eq_true ..) fun _ => switchLocalFpuOwner_equiv hop none + +theorem lazyFpuRestore_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) : + MRel SR Eq (FPU_A.lazy_fpu_restore thread) (Fl4Spec.lazyFpuRestore thread) := by + unfold FPU_A.lazy_fpu_restore Fl4Spec.lazyFpuRestore + refine mrel_bind (threadGet_equiv (Ra := FunRel embTcbFlags) (fun _ => rfl) thread) fun flagsH flagsL hf => ?_ + subst hf + refine mrel_if ?_ (fun _ => mrel_doMachineOp (disableFpu_equiv hop)) fun _ => ?_ + · change holMember .FpuDisabled flagsH = true ↔ embTcbFlag .FpuDisabled ∈ embTcbFlags flagsH + simp + · refine mrel_bind (currentFpuOwner_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL)) fun oldH oldL h => ?_ + subst h + exact mrel_if (holEq_eq_true ..) (fun _ => mrel_doMachineOp (enableFpu_equiv hop)) + fun _ => switchLocalFpuOwner_equiv hop (some thread) + +end + +end L4vRefX64.Equiv.Fpu diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Hardware.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Hardware.lean new file mode 100644 index 000000000..74ae36361 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Hardware.lean @@ -0,0 +1,104 @@ +import L4vRefX64.Equiv.Machine +import L4vRefX64.Rel.Lift + +namespace L4vRefX64.Equiv.Hardware + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec +open Fl4Spec + +noncomputable section + +variable {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + +theorem setDeadline_equiv (hop : OpaqueRel RestRel) (time : Ticks) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.setDeadline time) (Fl4Spec.setDeadline time) := + mrel_machineOpLift (hop.setDeadline_rel time) + +theorem invalidateASID_equiv (hop : OpaqueRel RestRel) (root asid : Word) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.invalidateASID root asid) (Fl4Spec.invalidateASID root asid) := + mrel_machineOpLift (hop.invalidateAsid_rel root asid) + +theorem invalidateLocalPageStructureCacheASID_equiv (hop : OpaqueRel RestRel) (root asid : Word) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.invalidateLocalPageStructureCacheASID root asid) (Fl4Spec.invalidateLocalPageStructureCacheASID root asid) := + mrel_machineOpLift (hop.invalidateLocalCacheAsid_rel root asid) + +theorem invalidateTranslationSingleASID_equiv (hop : OpaqueRel RestRel) (vaddr asid : Word) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.invalidateTranslationSingleASID vaddr asid) (Fl4Spec.invalidateTranslationSingleASID vaddr asid) := + mrel_machineOpLift (hop.invalidateSingleAsid_rel vaddr asid) + +theorem ioapicMapPinToVector_equiv (hop : OpaqueRel RestRel) (apic pin level polarity vector : Word) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.ioapicMapPinToVector apic pin level polarity vector) (Fl4Spec.ioapicMapPinToVector apic pin level polarity vector) := + mrel_machineOpLift (hop.ioapicMapPin_rel apic pin level polarity vector) + +theorem out8_equiv (hop : OpaqueRel RestRel) (port : Word16) (value : BitVec 8) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.out8 port value) (Fl4Spec.out8 port value) := + mrel_machineOpLift (hop.out8_rel port value) + +theorem out16_equiv (hop : OpaqueRel RestRel) (port : Word16) (value : BitVec 16) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.out16 port value) (Fl4Spec.out16 port value) := + mrel_machineOpLift (hop.out16_rel port value) + +theorem out32_equiv (hop : OpaqueRel RestRel) (port : Word16) (value : BitVec 32) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.out32 port value) (Fl4Spec.out32 port value) := + mrel_machineOpLift (hop.out32_rel port value) + +theorem in8_equiv (hop : OpaqueRel RestRel) (port : Word16) : + MRel (MachineStateRel RestRel) Eq (MachineOps.in8 port) (Fl4Spec.in8 port) := by + unfold MachineOps.in8 Fl4Spec.in8 + exact mrel_kbind (mrel_machineOpLift (hop.in8_rel port)) + (mrel_gets fun sH sL h => (hop.in8Val_eq sH sL h).symm) + +theorem in16_equiv (hop : OpaqueRel RestRel) (port : Word16) : + MRel (MachineStateRel RestRel) Eq (MachineOps.in16 port) (Fl4Spec.in16 port) := by + unfold MachineOps.in16 Fl4Spec.in16 + exact mrel_kbind (mrel_machineOpLift (hop.in16_rel port)) + (mrel_gets fun sH sL h => (hop.in16Val_eq sH sL h).symm) + +theorem in32_equiv (hop : OpaqueRel RestRel) (port : Word16) : + MRel (MachineStateRel RestRel) Eq (MachineOps.in32 port) (Fl4Spec.in32 port) := by + unfold MachineOps.in32 Fl4Spec.in32 + exact mrel_kbind (mrel_machineOpLift (hop.in32_rel port)) + (mrel_gets fun sH sL h => (hop.in32Val_eq sH sL h).symm) + +theorem getFaultAddress_equiv (hop : OpaqueRel RestRel) : + MRel (MachineStateRel RestRel) Eq MachineOps.getFaultAddress Fl4Spec.getFaultAddress := + mrel_gets fun sH sL h => (hop.faultAddress_eq sH sL h).symm + +theorem enableFpu_equiv (hop : OpaqueRel RestRel) : + MRel (MachineStateRel RestRel) Eq MachineOps.enableFpu Fl4Spec.enableFpu := by + unfold MachineOps.enableFpu Fl4Spec.enableFpu + exact mrel_kbind (mrel_machineOpLift hop.enableFpu_rel) + (mrel_modify fun _ _ h => { h with fpuEnabled_eq := rfl }) + +theorem disableFpu_equiv (hop : OpaqueRel RestRel) : + MRel (MachineStateRel RestRel) Eq MachineOps.disableFpu Fl4Spec.disableFpu := by + unfold MachineOps.disableFpu Fl4Spec.disableFpu + exact mrel_kbind (mrel_machineOpLift hop.disableFpu_rel) + (mrel_modify fun _ _ h => { h with fpuEnabled_eq := rfl }) + +theorem readFpuState_equiv (hop : OpaqueRel RestRel) : + MRel (MachineStateRel RestRel) Eq MachineOps.readFpuState Fl4Spec.readFpuState := by + unfold MachineOps.readFpuState Fl4Spec.readFpuState + refine mrel_kbind (mrel_stateAssert fun _ _ h => by rw [h.fpuEnabled_eq]) ?_ + exact mrel_machineRestLift (mrel_gets fun rH rL hr => (hop.readFpuState_eq rH rL hr).symm) + +theorem writeFpuState_equiv (hop : OpaqueRel RestRel) (fpu : FpuState) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.writeFpuState fpu) (Fl4Spec.writeFpuState fpu) := by + unfold MachineOps.writeFpuState Fl4Spec.writeFpuState + exact mrel_kbind (mrel_stateAssert fun _ _ h => by rw [h.fpuEnabled_eq]) + (mrel_machineOpLift (hop.writeFpuState_rel fpu)) + +end + +end L4vRefX64.Equiv.Hardware diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Interrupt.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Interrupt.lean new file mode 100644 index 000000000..835466851 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Interrupt.lean @@ -0,0 +1,268 @@ +import L4vRefX64.Equiv.Ipc +import L4vRefX64.Equiv.Hardware +import L4vRefX64.Spec.Interrupt_A + +namespace L4vRefX64.Equiv.Interrupt + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.CSpaceAcc +open L4vRefX64.Equiv.Ipc L4vRefX64.Equiv.CSpace L4vRefX64.Equiv.Hardware +open Fl4Spec Classical + +noncomputable section + +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 ackInterrupt_equiv (irq : BitVec 8) : + MRel (MachineStateRel RestRel) Eq (MachineOps.ackInterrupt irq) (Fl4Spec.ackInterrupt irq) := + mrel_return rfl + +theorem ackDeadlineIRQ_equiv : + MRel (MachineStateRel RestRel) Eq MachineOps.ackDeadlineIRQ Fl4Spec.ackDeadlineIRQ := + mrel_return rfl + +theorem archMaskIrqSignal_equiv (irq : BitVec 8) : + MRel SR Eq (ArchInterrupt_A.arch_mask_irq_signal irq) (Fl4Spec.archMaskIrqSignal irq) := + mrel_doMachineOp (maskInterrupt_equiv true irq) + +theorem handleReservedIrq_equiv (irq : BitVec 8) : + MRel SR Eq (ArchInterrupt_A.handle_reserved_irq irq) (Fl4Spec.handleReservedIrq irq) := + mrel_return rfl + +theorem handleSpuriousIrq_equiv : + MRel SR Eq ArchInterrupt_A.handle_spurious_irq Fl4Spec.handleSpuriousIrq := + mrel_return rfl + +private theorem getIrqSlot_valid (irq : BitVec 8) : + MRel SR (fun slH slL => slL = slH ∧ slH.2 = []) + (KHeap_A.get_irq_slot irq) (Fl4Spec.getIrqSlot irq) := by + unfold KHeap_A.get_irq_slot Fl4Spec.getIrqSlot + exact mrel_gets fun _ _ hs => by simp [hs.interruptIrqNode_eq] + +private theorem signalCap_condition (cH : Structures_A.cap) : + holConj (Structures_A.is_ntfn_cap cH) + (holMember CapRights_A.AllowSend (Structures_A.cap_rights cH)) = true ↔ + Fl4Spec.isNtfnCap (embCap cH) = true ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights (embCap cH) := by + cases cH with + | NotificationCap _ _ rights => + simp only [holConj_eq_true, holMember_eq_true, Structures_A.is_ntfn_cap, Fl4Spec.isNtfnCap, + embCap, Structures_A.cap_rights, Fl4Spec.capRights, CapRights_A.AllowSend, Fl4Spec.AllowSend, + true_and] + exact (embRightsSet_mem .AllowWrite rights).symm + | _ => simp [holConj_eq_true, Structures_A.is_ntfn_cap, Fl4Spec.isNtfnCap, embCap] + +theorem handleInterrupt_equiv (hop : OpaqueRel RestRel) (irq : BitVec 8) : + MRel SR Eq (Interrupt_A.handle_interrupt irq) (Fl4Spec.handleInterrupt irq) := by + unfold Interrupt_A.handle_interrupt Fl4Spec.handleInterrupt + refine mrel_if (P := Fl4Spec.maxIRQ < irq) ?_ ?_ ?_ + · have hmax : Fl4Spec.maxIRQ = Platform.maxIRQ := rfl + rw [hmax] + exact holLt_eq_true _ _ + · intro _ + exact mrel_doMachineOp (mrel_kbind (maskInterrupt_equiv true irq) (ackInterrupt_equiv irq)) + · intro _ + refine mrel_bind (getIrqState_equiv irq) fun stH stL hst => ?_ + subst hst + have hack : MRel SR Eq + (Structures_A.do_machine_op (MachineOps.ackInterrupt irq)) + (Fl4Spec.doMachineOp (Fl4Spec.ackInterrupt irq)) := + mrel_doMachineOp (ackInterrupt_equiv irq) + cases stH <;> simp only [Structures_A.case_irq_state, embIrqState] + case IRQInactive => exact mrel_kbind (mrel_fail (Ra := Eq)) hack + case IRQTimer => + rw [KHeap.holBind_assoc] + refine mrel_bind (mrel_doMachineOp (ackDeadlineIRQ_equiv (RestRel := RestRel))) fun _ _ _ => ?_ + dsimp only [holKBind] + exact mrel_kbind (mrel_modify fun _ _ h => { h with reprogramTimer_eq := rfl }) hack + case IRQReserved => exact mrel_kbind (handleReservedIrq_equiv irq) hack + case IRQSignal => + rw [KHeap.holBind_assoc] + refine mrel_bind (getIrqSlot_valid irq) fun slH slL ⟨hslot, hindex⟩ => ?_ + subst slL + rw [KHeap.holBind_assoc] + have hbase : NonExtTcbSlot slH.2 := by + rw [hindex] + intro hempty + cases hempty + refine mrel_bind (getCap_equiv_nonExt slH hbase) fun cH cL hc => ?_ + subst hc + rw [KHeap.holBind_assoc] + refine mrel_bind (mrel_when (signalCap_condition cH) fun h => ?_) fun _ _ _ => ?_ + · cases cH with + | NotificationCap ptr badge _ => exact sendSignal_equiv hop ptr badge + | _ => simp [Fl4Spec.isNtfnCap, embCap] at h + · dsimp only [holKBind] + exact mrel_kbind (archMaskIrqSignal_equiv irq) hack + +theorem maybeHandleInterrupt_equiv (hop : OpaqueRel RestRel) (inKernel : Bool) : + MRel SR Eq (Interrupt_A.maybe_handle_interrupt inKernel) (Fl4Spec.maybeHandleInterrupt inKernel) := by + unfold Interrupt_A.maybe_handle_interrupt Fl4Spec.maybeHandleInterrupt + refine mrel_bind (mrel_doMachineOp (getActiveIRQ_equiv hop inKernel)) fun oH oL ho => ?_ + subst ho + cases oH with + | none => exact handleSpuriousIrq_equiv + | some irq => exact handleInterrupt_equiv hop irq + +/-- l4v: Interrupt_A.invoke_irq_handler with base-slot deletion and insertion. -/ +def invoke_irq_handler_p : Invocations_A.irq_handler_invocation → + HolNonDet (Structures_A.state ZH) Unit + | .ACKIrq irq => ArchInterrupt_A.arch_invoke_irq_handler (.ACKIrq irq) + | .SetIRQHandler irq cap slot => + holBind (KHeap_A.get_irq_slot irq) fun irqSlot => + holBind (cap_delete_one_p irqSlot) fun _ => cap_insert_p cap slot irqSlot + | .ClearIRQHandler irq => holBind (KHeap_A.get_irq_slot irq) cap_delete_one_p + +/-- [P] Setting an IRQ handler admits insertion after the actual slot lookup and deletion. -/ +def InvokeIrqHandlerSafe (i : Invocations_A.irq_handler_invocation) (s : Structures_A.state ZH) : Prop := + match i with + | .SetIRQHandler irq cap slot => + ∀ irqSlot t, (irqSlot, t) ∈ (KHeap_A.get_irq_slot irq s).1 → + ∀ u, ((), u) ∈ (cap_delete_one_p irqSlot t).1 → CapInsertSafe cap slot irqSlot u + | _ => True + +theorem patched_invokeIrqHandler_equiv (hop : OpaqueRel RestRel) + (i : Invocations_A.irq_handler_invocation) {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hi : InvokeIrqHandlerSafe i sH) : + MRelStep SR Eq (invoke_irq_handler_p i sH) (Fl4Spec.invokeIrqHandler (embIrqHandlerInv i) sL) := by + cases i with + | ACKIrq irq => exact mrel_doMachineOp (maskInterrupt_equiv false irq) sH sL hs + | SetIRQHandler irq cap slot => + refine mrelStep_bind_mem (getIrqSlot_equiv irq sH sL hs) fun slotH slotL hslot tH tL ht hr => ?_ + subst hslot + refine mrelStep_bind_mem (patched_capDeleteOne_equiv hop slotH tH tL ht) fun a _ _ uH uL hu hd => ?_ + cases a + exact patched_capInsert_equiv cap slot slotH hu (hi slotH tH hr uH hd) + | ClearIRQHandler irq => + refine mrelStep_bind_mem (getIrqSlot_equiv irq sH sL hs) fun slotH slotL hslot tH tL ht _ => ?_ + subst hslot + exact patched_capDeleteOne_equiv hop slotH tH tL ht + +private theorem updateIrqState_equiv (irq : Irq) (st : Arch_Structs_A.X64IRQState) : + MRel SR Eq (Arch_A.update_irq_state irq st) (Fl4Spec.updateIrqState irq (embX64IrqState st)) := by + unfold Arch_A.update_irq_state Fl4Spec.updateIrqState + refine mrel_bind (Ra := fun f g => g = embX64IrqState ∘ f) + (mrel_gets fun sH sL hs => congrArg ArchState.x64IrqState hs.archState_eq) fun f g hfg => ?_ + subst g + apply mrel_modify + intro sH sL hs + have harch : ({sL.archState with x64IrqState := Function.update (embX64IrqState ∘ f) irq (embX64IrqState st)} : ArchState) = + embArchState sL.archState.x64Plat + (Arch_Structs_A.arch_state.x64_irq_state_update (fun _ => holFunUpd f irq st) sH.arch_state) := by + conv => lhs; rw [hs.archState_eq] + have hupdate : Function.update (embX64IrqState ∘ f) irq (embX64IrqState st) = + embX64IrqState ∘ holFunUpd f irq st := by + funext j + by_cases he : j = irq <;> simp [Function.update, holFunUpd, he] + rw [hupdate] + rfl + exact { hs with archState_eq := harch } + +private def install_irq_handler_p (irq : Irq) (src dest : CslotPtr) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (KHeap_A.set_irq_state .IRQSignal irq) fun _ => cap_insert_p (.IRQHandlerCap irq) src dest + +private def InstallIrqHandlerSafe (irq : Irq) (src dest : CslotPtr) (s : Structures_A.state ZH) : Prop := + ∀ t, ((), t) ∈ (KHeap_A.set_irq_state .IRQSignal irq s).1 → + CapInsertSafe (.IRQHandlerCap irq) src dest t + +private theorem installIrqHandler_equiv (irq : Irq) (src dest : CslotPtr) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hi : InstallIrqHandlerSafe irq src dest sH) : + MRelStep SR Eq (install_irq_handler_p irq src dest sH) + ((do + Fl4Spec.setIrqState .irqSignal irq + Fl4Spec.capInsert (.irqHandlerCap irq) src dest) sL) := by + unfold install_irq_handler_p + refine mrelStep_bind_mem (setIrqState_equiv .IRQSignal irq sH sL hs) fun a _ _ tH tL ht hr => ?_ + cases a + exact patched_capInsert_equiv (.IRQHandlerCap irq) src dest ht (hi tH hr) + +private def ioapic_irq_state (apic pin level polarity : Word) : Arch_Structs_A.X64IRQState := + .IRQIOAPIC (apic &&& mask 5) (pin &&& mask 5) (level &&& 1) (polarity &&& 1) true + +private def msi_irq_state (bus dev fn handle : Word) : Arch_Structs_A.X64IRQState := + .IRQMSI (bus &&& mask 8) (dev &&& mask 5) (fn &&& mask 3) (handle &&& mask 32) + +private def arch_invoke_irq_control_p : ArchInvocation_A.arch_irq_control_invocation → + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) + | .IssueIRQHandlerIOAPIC irq dest src apic pin level polarity vector => + holLiftE <| holBind (Structures_A.do_machine_op (MachineOps.ioapicMapPinToVector apic pin level polarity vector)) fun _ => + holBind (holReturn (ioapic_irq_state apic pin level polarity)) fun st => + holBind (Arch_A.update_irq_state irq st) fun _ => install_irq_handler_p irq src dest + | .IssueIRQHandlerMSI irq dest src bus dev fn handle => + holLiftE <| holBind (holReturn (msi_irq_state bus dev fn handle)) fun st => + holBind (Arch_A.update_irq_state irq st) fun _ => install_irq_handler_p irq src dest + +private def ArchInvokeIrqControlSafe (i : ArchInvocation_A.arch_irq_control_invocation) + (s : Structures_A.state ZH) : Prop := + match i with + | .IssueIRQHandlerIOAPIC irq dest src apic pin level polarity vector => + ∀ t, ((), t) ∈ (Structures_A.do_machine_op (MachineOps.ioapicMapPinToVector apic pin level polarity vector) s).1 → + ∀ u, ((), u) ∈ (Arch_A.update_irq_state irq (ioapic_irq_state apic pin level polarity) t).1 → + InstallIrqHandlerSafe irq src dest u + | .IssueIRQHandlerMSI irq dest src bus dev fn handle => + ∀ u, ((), u) ∈ (Arch_A.update_irq_state irq (msi_irq_state bus dev fn handle) s).1 → + InstallIrqHandlerSafe irq src dest u + +private theorem patched_archInvokeIrqControl_equiv (hop : OpaqueRel RestRel) + (i : ArchInvocation_A.arch_irq_control_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hi : ArchInvokeIrqControlSafe i sH) : + MRelStep SR (SumExceptRel Eq Eq) (arch_invoke_irq_control_p i sH) + ((Fl4Spec.archInvokeIrqControl (embArchIrqControlInv i)).run sL) := by + cases i with + | IssueIRQHandlerIOAPIC irq dest src apic pin level polarity vector => + unfold arch_invoke_irq_control_p Fl4Spec.archInvokeIrqControl embArchIrqControlInv Fl4Spec.withoutPreemption + apply mrelStep_liftE + refine mrelStep_bind_mem (mrel_doMachineOp (ioapicMapPinToVector_equiv hop apic pin level polarity vector) sH sL hs) + fun a _ _ tH tL ht hm => ?_ + cases a + refine mrelStep_bind_mem (mrel_return (Ra := FunRel embX64IrqState) (aH := ioapic_irq_state apic pin level polarity) rfl tH tL ht) + fun stH stL hst uH uL hu hp => ?_ + subst hst + have ⟨hstate, hsource⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hp) + subst stH + subst uH + refine mrelStep_bind_mem (updateIrqState_equiv irq _ tH uL hu) fun b _ _ vH vL hv hr => ?_ + cases b + exact installIrqHandler_equiv irq src dest hv (hi tH hm vH hr) + | IssueIRQHandlerMSI irq dest src bus dev fn handle => + unfold arch_invoke_irq_control_p Fl4Spec.archInvokeIrqControl embArchIrqControlInv Fl4Spec.withoutPreemption + apply mrelStep_liftE + refine mrelStep_bind_mem (mrel_return (Ra := FunRel embX64IrqState) (aH := msi_irq_state bus dev fn handle) rfl sH sL hs) + fun stH stL hst tH tL ht hp => ?_ + subst hst + have ⟨hstate, hsource⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hp) + subst stH + subst tH + refine mrelStep_bind_mem (updateIrqState_equiv irq _ sH tL ht) fun b _ _ vH vL hv hr => ?_ + cases b + exact installIrqHandler_equiv irq src dest hv (hi vH hr) + +/-- l4v: Interrupt_A.invoke_irq_control, including native IOAPIC and MSI routes. -/ +def invoke_irq_control_p : Invocations_A.irq_control_invocation → + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) + | .IRQControl irq dest src => holLiftE (install_irq_handler_p irq src dest) + | .ArchIRQControl i => arch_invoke_irq_control_p i + +/-- [P] Successful IRQ setup leaves a state admitting the handler-cap insertion. -/ +def InvokeIrqControlSafe (i : Invocations_A.irq_control_invocation) (s : Structures_A.state ZH) : Prop := + match i with + | .IRQControl irq dest src => InstallIrqHandlerSafe irq src dest s + | .ArchIRQControl a => ArchInvokeIrqControlSafe a s + +theorem patched_invokeIrqControl_equiv (hop : OpaqueRel RestRel) + (i : Invocations_A.irq_control_invocation) {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hi : InvokeIrqControlSafe i sH) : + MRelStep SR (SumExceptRel Eq Eq) (invoke_irq_control_p i sH) + ((Fl4Spec.invokeIrqControl (embIrqControlInv i)).run sL) := by + cases i with + | IRQControl irq dest src => exact mrelStep_liftE (installIrqHandler_equiv irq src dest hs hi) + | ArchIRQControl a => exact patched_archInvokeIrqControl_equiv hop a hs hi + +end + +end L4vRefX64.Equiv.Interrupt diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/InvocationDecode.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/InvocationDecode.lean new file mode 100644 index 000000000..ac8c603dd --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/InvocationDecode.lean @@ -0,0 +1,153 @@ +import L4vRefX64.Equiv.ArchDecode + +namespace L4vRefX64.Equiv.InvocationDecode + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Decode L4vRefX64.Equiv.ArchDecode L4vRefX64.Equiv.Machine +open Fl4Spec Classical + +noncomputable section + +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 + +/-- l4v: Decode_A.decode_invocation, with the checked FL4 decoder deltas. -/ +def decode_invocation_p (huge firstPhase : Bool) (label : Data) (args : List Data) + (slot : CslotPtr) (cap : Structures_A.cap) (excaps : List (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.invocation) := + let extra := excaps.map Prod.fst + let invalid := holThrowError (.InvalidCapability 0) + match cap with + | .EndpointCap ptr badge rights => + holIf (holMember CapRights_A.AllowSend rights) + (holReturnOk (.InvokeEndpoint ptr badge (holMember .AllowGrant rights) (holMember .AllowGrantReply rights))) + invalid + | .NotificationCap ptr badge rights => + holIf (holMember CapRights_A.AllowSend rights) (holReturnOk (.InvokeNotification ptr badge)) invalid + | .ReplyCap ptr rights => + holReturnOk (.InvokeReply ptr (holMember .AllowGrant rights)) + | .IRQControlCap => holLiftME .InvokeIRQControl (decode_irq_control_invocation_p label args slot extra) + | .IRQHandlerCap irq => holLiftME .InvokeIRQHandler (decode_irq_handler_invocation_p label irq excaps) + | .ThreadCap _ => + holIf firstPhase invalid (holLiftME .InvokeTCB (decode_tcb_invocation_p label args cap slot excaps)) + | .DomainCap => holIf firstPhase invalid (holLiftME .InvokeDomain (decode_domain_invocation_p label args excaps)) + | .SchedContextCap sc _ => + holIf firstPhase invalid (holLiftME .InvokeSchedContext (decode_sched_context_invocation_p label sc extra)) + | .SchedControlCap => + holIf firstPhase invalid (holLiftME .InvokeSchedControl (decode_sched_control_invocation_flags_p label args extra)) + | .CNodeCap .. => + holIf firstPhase invalid (holLiftME .InvokeCNode (decode_cnode_invocation_p label args cap extra)) + | .UntypedCap .. => holLiftME .InvokeUntyped (decode_untyped_invocation_p label args slot cap extra) + | .ArchObjectCap arch => holLiftME .InvokeArchObject (arch_decode_invocation_p huge label args slot arch excaps) + | _ => invalid + +/-- [P] Retype uses shared object numbers and ASID-bearing decoder arguments use the common width. -/ +structure BaseDecodeInputs (cap : Structures_A.cap) (args : List Data) + (caps : List (Structures_A.cap × CslotPtr)) : Prop where + rootCaps : RootCapsInBaseRange caps + poolCap : ∀ ptr base, cap = .ArchObjectCap (.ASIDPoolCap ptr base) → BaseAsid base + objectCode : ∀ dev ptr size free, cap = .UntypedCap dev ptr size free → 6 ≤ args.length → + (holNth args 0 : Data).toNat < 14 ∨ 18 < (holNth args 0 : Data).toNat + +private theorem rightMember_eq (right : CapRights_A.rights) (rights : Set CapRights_A.rights) : + holMember right rights = decide (embRights right ∈ embRightsSet rights) := by + apply Bool.eq_iff_iff.mpr + rw [holMember_eq_true, decide_eq_true_eq, embRightsSet_mem] + +private theorem decide_irrel {p : Prop} (a b : Decidable p) : @decide p a = @decide p b := + congrArg (fun d => @decide p d) (Subsingleton.elim a b) + +private theorem liftInvocation_step {αH αL : Type} {embed : αH → αL} + {ctorH : αH → Invocations_A.invocation} {ctorL : αL → Invocation} + {mH : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error αH)} + {mL : SEMonad ZL αL} {sH : Structures_A.state ZH} {sL : State ZL} + (heq : ∀ x, embInvocation (ctorH x) = ctorL (embed x)) + (hm : MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embed)) (mH sH) (mL.run sL)) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embInvocation)) + (holLiftME ctorH mH sH) ((NonDetE.liftME ctorL mL).run sL) := by + unfold holLiftME NonDetE.liftME + refine mrelStep_bindE_mem hm fun aH aL ha tH tL ht _ => ?_ + subst ha + exact mrele_returnOk (Ra := FunRel embInvocation) (heq aH).symm tH tL ht + +/-- [P] The decoder admits native base carriers and the guarded invocation inputs. -/ +theorem patched_decodeInvocation_equiv (hc : ConfigRel) (ho : OpaqueRel RestRel) + (firstPhase : Bool) (label : Data) (args : List Data) (capIndex : CapRef) + (slot : CslotPtr) (cap : Structures_A.cap) (caps : List (Structures_A.cap × CslotPtr)) + (buffer : Option ObjRef) {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (hi : BaseDecodeInputs cap args caps) : + MRelStep SR (SumExceptRel (FunRel embSyscallError) (FunRel embInvocation)) + (decode_invocation_p sL.archState.x64Plat.hugePages firstPhase label args slot cap caps sH) + ((Fl4Spec.decodeInvocation firstPhase label args capIndex slot (embCap cap) + (caps.map fun (c, s) => (embCap c, s)) buffer).run sL) := by + have hmap : ((caps.map Prod.fst).map embCap) = + (caps.map fun p => (embCap p.1, p.2)).map Prod.fst := by simp [List.map_map, Function.comp_def] + cases cap with + | EndpointCap ptr badge rights => + exact (mrele_if (Re := FunRel embSyscallError) (Ra := FunRel embInvocation) + (by rw [rightMember_eq, decide_eq_true_eq]; rfl) (fun _ => + mrele_returnOk (by + simp [FunRel, embInvocation, rightMember_eq, embRights] + exact ⟨decide_irrel _ _, decide_irrel _ _⟩)) + (fun _ => mrele_throwError rfl)) sH sL hs + | NotificationCap ptr badge rights => + exact (mrele_if (Re := FunRel embSyscallError) (Ra := FunRel embInvocation) + (by rw [rightMember_eq, decide_eq_true_eq]; rfl) (fun _ => mrele_returnOk rfl) + (fun _ => mrele_throwError rfl)) sH sL hs + | ReplyCap ptr rights => + exact mrele_returnOk (Re := FunRel embSyscallError) (Ra := FunRel embInvocation) + (by + simp [FunRel, embInvocation, rightMember_eq, embRights] + exact decide_irrel _ _) sH sL hs + | IRQControlCap => + have hd := patched_decodeIrqControlInvocation_equiv label args slot (caps.map Prod.fst) sH sL hs + rw [hmap] at hd + exact liftInvocation_step (fun _ => rfl) hd + | IRQHandlerCap irq => + exact liftInvocation_step (fun _ => rfl) + (patched_decodeIrqHandlerInvocation_equiv label irq caps sH sL hs) + | ThreadCap ptr => + cases firstPhase + · exact liftInvocation_step (fun _ => rfl) + (patched_decodeTcbInvocation_equiv label args ptr slot caps sH sL hs) + · exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + | DomainCap => + cases firstPhase + · exact liftInvocation_step (fun _ => rfl) (decodeDomainInvocation_equiv hc label args caps sH sL hs) + · exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + | SchedContextCap ptr size => + cases firstPhase + · have hd := decodeSchedContextInvocation_equiv label ptr (caps.map Prod.fst) sH sL hs + rw [hmap] at hd + exact liftInvocation_step (fun _ => rfl) hd + · exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + | SchedControlCap => + cases firstPhase + · have hd := decodeSchedControlInvocationFlags_equiv ho label args (caps.map Prod.fst) sH sL hs + rw [hmap] at hd + exact liftInvocation_step (fun _ => rfl) hd + · exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + | CNodeCap ptr bits guard => + cases firstPhase + · have hd := patched_decodeCnodeInvocation_equiv label args (.CNodeCap ptr bits guard) + (caps.map Prod.fst) sH sL hs + rw [hmap] at hd + exact liftInvocation_step (fun _ => rfl) hd + · exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + | UntypedCap dev ptr size free => + have hd := patched_decodeUntypedInvocation_equiv hc label args slot dev ptr size free + (caps.map Prod.fst) (hi.objectCode dev ptr size free rfl) sH sL hs + rw [hmap] at hd + exact liftInvocation_step (fun _ => rfl) hd + | ArchObjectCap arch => + exact liftInvocation_step (fun _ => rfl) + (patched_archDecodeInvocation_equiv label args capIndex slot arch caps hs hb hi.rootCaps + (fun ptr base h => hi.poolCap ptr base (congrArg Structures_A.cap.ArchObjectCap h))) + | _ => exact mrele_throwError (Re := FunRel embSyscallError) rfl sH sL hs + +end + +end L4vRefX64.Equiv.InvocationDecode diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Ipc.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Ipc.lean new file mode 100644 index 000000000..16ba75c79 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Ipc.lean @@ -0,0 +1,2460 @@ +import L4vRefX64.Equiv.SchedContext +import L4vRefX64.Equiv.CSpace +import L4vRefX64.Equiv.TcbAcc +import L4vRefX64.Spec.Ipc_A + +namespace L4vRefX64.Equiv.Ipc + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.CSpaceAcc +open L4vRefX64.Equiv.IpcCancel L4vRefX64.Equiv.SchedContext +open L4vRefX64.Equiv.Structures L4vRefX64.Equiv.TcbAcc +open L4vRefX64.Equiv.CSpace L4vRefX64.Equiv.Deterministic L4vRefX64.Equiv.ArchVSpace +open Fl4Spec Classical + +noncomputable section + +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 + +private theorem holAssert_false {σ : Type} : holAssert (σ := σ) false = holFail := by + funext s + apply Prod.ext + · ext x; simp [holAssert, holFail] + · rfl + +private theorem assert_false {σ : Type} : NonDet.assert (σ := σ) False = NonDet.fail := by + funext s + apply Prod.ext + · ext x; simp [NonDet.assert, NonDet.fail] + · simp [NonDet.assert, NonDet.fail] + +private theorem mrel_bind_fail {αH αL βH βL : Type} {Rb : βH → βL → Prop} + {fH : αH → HolNonDet (Structures_A.state ZH) βH} {fL : αL → SMonad ZL βL} : + MRel SR Rb (holBind holFail fH) (NonDet.bind NonDet.fail fL) := by + intro _ _ _ + exact ⟨by simp [holBind, NonDet.bind, holFail, NonDet.fail], + fun _ _ h => by simp [holBind, holFail] at h, + fun _ _ h => by simp [NonDet.bind, NonDet.fail] at h⟩ + +theorem bufferCptrIndex_eq : Fl4Spec.bufferCptrIndex = Ipc_A.buffer_cptr_index := rfl + +theorem isActive_eq (n : Structures_A.notification) : + Fl4Spec.isActive (embNotification n) = Ipc_A.isActive n := by + unfold Fl4Spec.isActive Ipc_A.isActive embNotification + cases n.ntfn_obj <;> rfl + +theorem isTimeoutFault_eq (f : ExceptionTypes_A.fault) : + Fl4Spec.isTimeoutFault (embFault f) = Ipc_A.is_timeout_fault f := by + unfold Fl4Spec.isTimeoutFault Ipc_A.is_timeout_fault embFault + cases f <;> rfl + +theorem receiveBlocked_eq (st : Structures_A.thread_state) : + Fl4Spec.receiveBlocked (embThreadState st) = Ipc_A.receive_blocked st := by + unfold Fl4Spec.receiveBlocked Ipc_A.receive_blocked embThreadState + cases st <;> rfl + +theorem sendIpcBlocked_equiv (thread epptr badge : Word) + (canGrant canGrantReply call : Bool) : + MRel SR Eq + (Ipc_A.send_ipc_blocked thread epptr badge canGrant canGrantReply call) + (Fl4Spec.sendIpcBlocked thread epptr badge canGrant canGrantReply call) := by + unfold Ipc_A.send_ipc_blocked Fl4Spec.sendIpcBlocked + exact mrel_kbind (setThreadState_equiv thread (.BlockedOnSend epptr ⟨badge, canGrant, canGrantReply, call, ()⟩)) + (tcbEpAppend_equiv thread epptr false) + +theorem completeSignal_equiv (hop : OpaqueRel RestRel) (ntfnptr tptr : ObjRef) : + MRel SR Eq + (Ipc_A.complete_signal ntfnptr tptr) (Fl4Spec.completeSignal ntfnptr tptr) := by + unfold Ipc_A.complete_signal Fl4Spec.completeSignal + refine mrel_bind (getNotification_equiv ntfnptr) fun nH nL hn => ?_; subst hn + cases hobj : nH.ntfn_obj with + | IdleNtfn => simp only [Structures_A.case_ntfn, embNotification, hobj]; exact mrel_fail + | WaitingNtfn _ => simp only [Structures_A.case_ntfn, embNotification, hobj]; exact mrel_fail + | ActiveNtfn badge => + simp only [Structures_A.case_ntfn, embNotification, hobj, holFunApp] + refine mrel_kbind (asUser_equiv (setRegister_equiv Machine_A.badge_register badge) tptr) ?_ + refine mrel_kbind (setNotification_equiv ntfnptr + (Structures_A.notification.ntfn_obj_update (holK .IdleNtfn) nH)) ?_ + refine mrel_kbind (maybeDonateSc_equiv hop tptr ntfnptr) ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) tptr) fun scH scL hsc => ?_; subst hsc + cases scH with + | none => exact mrel_return rfl + | some scp => + simp only [holMaybeM, NonDet.maybeM] + refine mrel_bind (getSchedContext_equiv scp) fun sH' sL' hs' => ?_; subst hs' + refine mrel_when (by simp [embSchedContext]) fun _ => ?_ + refine mrel_bind (getNtfnObjRef_equiv (fun _ => rfl) ntfnptr) fun nsH nsL hns => ?_; subst hns + refine mrel_bind (mrel_gets fun _ _ hs => hs.curSc_eq.symm) fun csH csL hcs => ?_; subst hcs + exact mrel_when (by simp [holConj_eq_true, holEq_eq_true, holNot_eq_true]) + fun _ => refillUnblockCheck_equiv scp + +theorem doNbrecvFailedTransfer_equiv (thread : ObjRef) : + MRel SR Eq + (Ipc_A.do_nbrecv_failed_transfer thread) (Fl4Spec.doNbrecvFailedTransfer thread) := by + unfold Ipc_A.do_nbrecv_failed_transfer Fl4Spec.doNbrecvFailedTransfer + exact mrel_kbind (asUser_equiv (setRegister_equiv Machine_A.badge_register 0) thread) (mrel_return rfl) + +theorem receiveIpcBlocked_equiv (isBlocking : Bool) (thread epptr : ObjRef) + (reply : Option ObjRef) : + MRel SR Eq + (Ipc_A.receive_ipc_blocked isBlocking thread epptr reply) + (Fl4Spec.receiveIpcBlocked isBlocking thread epptr reply) := by + unfold Ipc_A.receive_ipc_blocked Fl4Spec.receiveIpcBlocked + cases isBlocking with + | false => exact doNbrecvFailedTransfer_equiv thread + | true => + simp only [holIf_true, ↓reduceIte] + refine mrel_kbind (setThreadState_equiv thread (.BlockedOnReceive epptr reply ⟨false, ()⟩)) ?_ + refine mrel_kbind (Ra := Eq) ?_ (tcbEpAppend_equiv thread epptr true) + cases reply with + | none => exact mrel_return rfl + | some r => exact setReplyObjRef_equiv (fun _ _ => rfl) r (some thread) + +theorem updateWaitingNtfn_equiv (hop : OpaqueRel RestRel) + (ntfnptr : ObjRef) (queue : List ObjRef) (badge : Badge) : + MRel SR Eq + (Ipc_A.update_waiting_ntfn ntfnptr queue badge) + (Fl4Spec.updateWaitingNtfn ntfnptr queue badge) := by + cases queue with + | nil => + unfold Ipc_A.update_waiting_ntfn Fl4Spec.updateWaitingNtfn + simp only [holNot, holEq, decide_true, Bool.not_true, holAssert_false, + ne_eq, not_true_eq_false, assert_false] + exact mrel_bind_fail (αH := Unit) (αL := Unit) (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + | cons dest rest => + unfold Ipc_A.update_waiting_ntfn Fl4Spec.updateWaitingNtfn + refine mrel_kbind (mrel_assert (by simp [holNot_eq_true, holEq_eq_true])) ?_ + simp only [holHd, List.head?, the, holFunApp] + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun dH dL hd => ?_; subst hd + refine mrel_kbind (tcbNtfnDequeue_equiv dH ntfnptr) ?_ + refine mrel_kbind (setThreadState_equiv dH .Running) ?_ + refine mrel_kbind (asUser_equiv (setRegister_equiv Machine_A.badge_register badge) dH) ?_ + refine mrel_kbind (maybeDonateSc_equiv hop dH ntfnptr) ?_ + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs dH).symm) fun scH scL hsc => ?_; subst hsc + refine mrel_kbind (mrel_when (by simp) fun _ => possibleSwitchTo_equiv hop dH) ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) dH) fun soH soL hso => ?_; subst hso + exact ifSporadicCurScTestRefillUnblockCheck_equiv soH + +theorem sendSignal_equiv (hop : OpaqueRel RestRel) (ntfnptr : ObjRef) (badge : Badge) : + MRel SR Eq + (Ipc_A.send_signal ntfnptr badge) (Fl4Spec.sendSignal ntfnptr badge) := by + unfold Ipc_A.send_signal Fl4Spec.sendSignal + refine mrel_bind (getNotification_equiv ntfnptr) fun nH nL hn => ?_; subst hn + simp only [holCaseProd_eq, embNotification] + cases hobj : nH.ntfn_obj with + | IdleNtfn => + simp only [Structures_A.case_ntfn, embNtfn, holFunApp] + cases hbt : nH.ntfn_bound_tcb with + | none => + simp only [holCaseOption] + have hn' : Fl4Spec.ntfnObjUpdate (fun _ => .activeNtfn badge) + { ntfnObj := .idleNtfn, ntfnBoundTcb := none, ntfnSc := nH.ntfn_sc } = + embNotification (Structures_A.notification.ntfn_obj_update (holK (.ActiveNtfn badge)) nH) := by + simp [Fl4Spec.ntfnObjUpdate, embNotification, embNtfn, Structures_A.notification.ntfn_obj_update, holK, hbt] + rw [hn'] + exact setNotification_equiv ntfnptr + (Structures_A.notification.ntfn_obj_update (holK (.ActiveNtfn badge)) nH) + | some tcb => + simp only [holCaseOption] + refine mrel_bind (getThreadState_equiv tcb) fun stH stL hst => ?_; subst hst + refine mrel_if (by rw [receiveBlocked_eq]) (fun _ => ?_) (fun _ => by + have hn' : Fl4Spec.ntfnObjUpdate (fun _ => .activeNtfn badge) + { ntfnObj := .idleNtfn, ntfnBoundTcb := some tcb, ntfnSc := nH.ntfn_sc } = + embNotification (Structures_A.notification.ntfn_obj_update (holK (.ActiveNtfn badge)) nH) := by + simp [Fl4Spec.ntfnObjUpdate, embNotification, embNtfn, Structures_A.notification.ntfn_obj_update, holK, hbt] + rw [hn'] + exact setNotification_equiv ntfnptr + (Structures_A.notification.ntfn_obj_update (holK (.ActiveNtfn badge)) nH)) + refine mrel_kbind (cancelIpc_equiv tcb) ?_ + refine mrel_kbind (setThreadState_equiv tcb .Running) ?_ + refine mrel_kbind (asUser_equiv (setRegister_equiv Machine_A.badge_register badge) tcb) ?_ + refine mrel_kbind (maybeDonateSc_equiv hop tcb ntfnptr) ?_ + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs tcb).symm) fun scH scL hsc => ?_; subst hsc + refine mrel_kbind (mrel_when (by simp) fun _ => possibleSwitchTo_equiv hop tcb) ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) tcb) fun soH soL hso => ?_; subst hso + exact ifSporadicCurScTestRefillUnblockCheck_equiv soH + | WaitingNtfn queue => + simp only [Structures_A.case_ntfn, embNtfn] + exact updateWaitingNtfn_equiv hop ntfnptr queue badge + | ActiveNtfn badge' => + simp only [Structures_A.case_ntfn, embNtfn, holFunApp] + have hcomb : Fl4Spec.combineNtfnBadges badge badge' = Machine_A.combine_ntfn_badges badge badge' := rfl + have hn' : Fl4Spec.ntfnObjUpdate (fun _ => .activeNtfn (Fl4Spec.combineNtfnBadges badge badge')) + { ntfnObj := .activeNtfn badge', ntfnBoundTcb := nH.ntfn_bound_tcb, ntfnSc := nH.ntfn_sc } = + embNotification (Structures_A.notification.ntfn_obj_update + (holK (.ActiveNtfn (Machine_A.combine_ntfn_badges badge badge'))) nH) := by + simp [Fl4Spec.ntfnObjUpdate, embNotification, embNtfn, Structures_A.notification.ntfn_obj_update, holK, hcomb] + rw [hn'] + exact setNotification_equiv ntfnptr + (Structures_A.notification.ntfn_obj_update (holK (.ActiveNtfn (Machine_A.combine_ntfn_badges badge badge'))) nH) + +theorem receiveSignalBlocked_equiv (hop : OpaqueRel RestRel) + (thread ntfnptr : ObjRef) (isBlocking : Bool) : + MRel SR Eq + (Ipc_A.receive_signal_blocked thread ntfnptr isBlocking) + (Fl4Spec.receiveSignalBlocked thread ntfnptr isBlocking) := by + unfold Ipc_A.receive_signal_blocked Fl4Spec.receiveSignalBlocked + cases isBlocking with + | false => exact doNbrecvFailedTransfer_equiv thread + | true => + simp only [holIf_true, ↓reduceIte] + refine mrel_kbind (setThreadState_equiv thread (.BlockedOnNotification ntfnptr)) ?_ + exact mrel_kbind (tcbNtfnAppend_equiv thread ntfnptr) (maybeReturnSc_equiv hop ntfnptr thread) + +theorem receiveSignal_equiv (hop : OpaqueRel RestRel) + (thread : ObjRef) (cap : Structures_A.cap) (isBlocking : Bool) : + MRel SR Eq + (Ipc_A.receive_signal thread cap isBlocking) + (Fl4Spec.receiveSignal thread (embCap cap) isBlocking) := by + unfold Ipc_A.receive_signal Fl4Spec.receiveSignal + cases cap with + | NotificationCap np _ _ => + simp only [Structures_A.case_cap, embCap] + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun npH npL hnp => ?_; subst hnp + refine mrel_bind (getNotification_equiv npH) fun nH nL hn => ?_; subst hn + cases hobj : nH.ntfn_obj with + | ActiveNtfn badge => + simp only [Structures_A.case_ntfn, embNotification, hobj, holFunApp] + refine mrel_kbind (asUser_equiv (setRegister_equiv Machine_A.badge_register badge) thread) ?_ + refine mrel_kbind (setNotification_equiv npH + (Structures_A.notification.ntfn_obj_update (holK .IdleNtfn) nH)) ?_ + refine mrel_kbind (maybeDonateSc_equiv hop thread npH) ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) thread) fun soH soL hso => ?_; subst hso + exact ifSporadicCurScTestRefillUnblockCheck_equiv soH + | IdleNtfn => + simp only [Structures_A.case_ntfn, embNotification, hobj] + exact receiveSignalBlocked_equiv hop thread npH isBlocking + | WaitingNtfn _ => + simp only [Structures_A.case_ntfn, embNotification, hobj] + exact receiveSignalBlocked_equiv hop thread npH isBlocking + | _ => + simp only [Structures_A.case_cap, embCap] + exact mrel_bind_fail + +theorem refillResetRr_equiv (cscPtr : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hne : HasNonEmptyRefills cscPtr sH) : + MRelStep SR Eq + (Ipc_A.refill_reset_rr cscPtr sH) (Fl4Spec.refillResetRr cscPtr sL) := by + unfold Ipc_A.refill_reset_rr Fl4Spec.refillResetRr + refine mrelStep_bind_mem (getRefillHead_equiv cscPtr sH sL hs) fun hdH hdL hhd s1H s1L hs1 hm1 => ?_ + subst hhd + have hs1eq : s1H = sH := holGetsThe_state_eq hm1 + subst s1H + refine mrelStep_bind_mem (getRefillTail_equiv cscPtr sH s1L hs1) fun tlH tlL htl s2H s2L hs2 hm2 => ?_ + subst htl + have hs2eq : s2H = sH := holGetsThe_state_eq hm2 + subst s2H + have hhd_upd := updateRefillHd_equiv_nonEmpty (RestRel := RestRel) (ZH := ZH) (ZL := ZL) cscPtr + (fH := Structures_A.refill.r_amount_update fun _ => HolAdd.addVal hdH.r_amount tlH.r_amount) + (fL := fun hd => { hd with rAmount := hdH.r_amount + tlH.r_amount }) + (fun _ => rfl) sH s2L ⟨hs2, hne⟩ + have hfull : MRelStep (fun sH sL => SR sH sL ∧ HasNonEmptyRefills cscPtr sH) Eq + (holBind (Sporadic_A.update_refill_hd cscPtr (Structures_A.refill.r_amount_update fun _ => HolAdd.addVal hdH.r_amount tlH.r_amount)) + (holKBind (SchedContext_A.update_refill_tl cscPtr (Structures_A.refill.r_amount_update fun _ => 0))) sH) + ((do + Fl4Spec.updateRefillHd cscPtr fun hd => { hd with rAmount := hdH.r_amount + tlH.r_amount } + Fl4Spec.updateRefillTl cscPtr fun r => { r with rAmount := 0 }) s2L) := + mrelStep_bind_mem hhd_upd fun _ _ _ s3H s3L ⟨hs3, hne3⟩ _ => + updateRefillTl_equiv_nonEmpty (RestRel := RestRel) (ZH := ZH) (ZL := ZL) cscPtr + (fH := Structures_A.refill.r_amount_update fun _ => 0) + (fL := fun r => { r with rAmount := 0 }) + (fun _ => rfl) s3H s3L ⟨hs3, hne3⟩ + exact ⟨hfull.1, + fun aH sH' hm => let ⟨aL, sL', hm', ha, hs'⟩ := hfull.2.1 aH sH' hm; ⟨aL, sL', hm', ha, hs'.1⟩, + fun aL sL' hm => let ⟨aH, sH', hm', ha, hs'⟩ := hfull.2.2 aL sL' hm; ⟨aH, sH', hm', ha, hs'.1⟩⟩ + +theorem schedulable_implies_tcb (t : ObjRef) (sH : Structures_A.state ZH) + (h : KHeap_A.schedulable t sH = true) : + ∃ tcb, sH.kheap t = some (.TCB tcb) := by + unfold KHeap_A.schedulable at h + simp only [holConj_eq_true] at h + have h1 := h.1 + cases hkh : sH.kheap t with + | none => + simp [holOptPred, holOptMap, KHeap_A.tcbs_of_kh, hkh] at h1 + | some ko => + cases ko with + | TCB tcb => exact ⟨tcb, rfl⟩ + | _ => + simp [holOptPred, holOptMap, KHeap_A.tcbs_of_kh, KHeap_A.tcb_of, hkh, + Structures_A.case_kernel_object] at h1 + +/-- A successful sufficient-refill read leaves the budget and heap unchanged. +The domain countdown determines whether the entry proceeds. -/ +theorem checkBudget_run_sufficient + (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) + (hread : KHeap_A.read_sc_refill_sufficient sH.cur_sc sH.consumed_time sH = some true) : + Ipc_A.check_budget sH = ({(!KHeap_A.is_cur_domain_expired sH, sH)}, false) ∧ + Fl4Spec.checkBudget sL = ({(!KHeap_A.is_cur_domain_expired sH, sL)}, False) := by + have hlookup := readScRefillSufficient_equiv hop sH.cur_sc sH.consumed_time sH sL hs + rw [hread] at hlookup + have hreadL : Fl4Spec.readScRefillSufficient sL.curSc sL.consumedTime sL = some true := by + rw [hs.curSc_eq, hs.consumedTime_eq] + cases h : Fl4Spec.readScRefillSufficient sH.cur_sc sH.consumed_time sL with + | none => simp [OptRel, h] at hlookup + | some b => + have hb : true = b := by simpa [OptRel, h] using (show OptRel Eq (some true) + (Fl4Spec.readScRefillSufficient sH.cur_sc sH.consumed_time sL) from hlookup) + exact congrArg some hb.symm + constructor + · simp [Ipc_A.check_budget, KHeap_A.get_sc_refill_sufficient, holGetsThe, holAssertOpt, + holBind, holGets, holReturn, holIf, holNot, hread] + · simp [Fl4Spec.checkBudget, Fl4Spec.getScRefillSufficient, NonDet.getsThe, NonDet.assertOpt, + NonDet.bind, NonDet.gets, NonDet.pure, Bind.bind, Pure.pure, hreadL, isCurDomainExpired_eq hc hs] + + +theorem checkBudgetRestart_equiv_sufficient + (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hread : KHeap_A.read_sc_refill_sufficient sH.cur_sc sH.consumed_time sH = some true) : + MRelStep SR Eq (Ipc_A.check_budget_restart sH) (Fl4Spec.checkBudgetRestart sL) := by + obtain ⟨hH, hL⟩ := checkBudget_run_sufficient hc hop hs hread + have hr : MRelStep SR Eq (Ipc_A.check_budget sH) (Fl4Spec.checkBudget sL) := by + rw [hH, hL] + exact mrel_return rfl sH sL hs + unfold Ipc_A.check_budget_restart Fl4Spec.checkBudgetRestart + refine mrelStep_bind_mem hr fun resH resL hres s1H s1L hs1 _ => ?_ + subst hres + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) s1H s1L hs1) + fun tH tL ht s2H s2L hs2 _ => ?_ + subst ht + refine mrelStep_bind_mem (getThreadState_equiv tH s2H s2L hs2) fun stH stL hst s3H s3L hs3 _ => ?_ + subst hst + refine mrelStep_bind_mem (mrel_when (by simp [holConj_eq_true, holNot_eq_true, L4vRefX64.Equiv.Structures.runnable_eq]) + (fun _ => setThreadState_equiv tH .Restart) s3H s3L hs3) fun _ _ _ s4H s4L hs4 _ => ?_ + exact mrel_return rfl s4H s4L hs4 + + +theorem isValidTimeoutHandler_equiv (tptr : ObjRef) : + MRel SR Eq (Ipc_A.is_valid_timeout_handler tptr) (Fl4Spec.isValidTimeoutHandler tptr) := by + unfold Ipc_A.is_valid_timeout_handler Fl4Spec.isValidTimeoutHandler + refine mrel_bind (mrel_return (Ra := fun a b => a = Tcb_A.get_tcb_timeout_handler_ptr tptr ∧ b = a) + ⟨rfl, rfl⟩) fun slH slL ⟨hh, hl⟩ => ?_ + subst slH slL + have hslot : NonExtTcbSlot (Tcb_A.get_tcb_timeout_handler_ptr tptr).2 := by + change Fl4Spec.tcbCnodeIndex 4 ≠ Fl4Spec.tcbCnodeIndex 5 + decide + refine mrel_bind (getCap_equiv_nonExt _ hslot) fun cH cL hc => ?_ + subst hc + apply mrel_return + cases cH <;> rfl + +private theorem isRoundRobin_state_eq {s t : Structures_A.state ZH} + {sc : ObjRef} {rr : Bool} (h : (rr, t) ∈ (Sporadic_A.is_round_robin sc s).1) : t = s := by + rcases h with ⟨⟨obj, st⟩, hread, hret⟩ + have hst : st = s := by + rcases hread with ⟨⟨ko, u⟩, hget, hcont⟩ + have hu := (getObject_member hget).2 + subst u + cases ko <;> simp [Structures_A.case_kernel_object, holFail, holReturn] at hcont + exact hcont.2 + subst st + exact (Prod.mk.inj (Set.mem_singleton_iff.mp hret)).2 + +/-- Yield-time charging uses the ordinary timeslice endpoint with timeout +disabled. The current TCB premise discharges FL4's additional state read. -/ +theorem endTimeslice_equiv_without_timeout (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hcur : ∃ tcb, sH.kheap sH.cur_thread = some (.TCB tcb)) : + MRelStep SR Eq (Ipc_A.end_timeslice false sH) (Fl4Spec.endTimeslice false sL) := by + unfold Ipc_A.end_timeslice Fl4Spec.endTimeslice + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun scH scL hsc s1H s1L hs1 hm1 => ?_ + subst hsc + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + obtain ⟨hrsc, hrst⟩ := hm1 + subst scH s1H + refine mrelStep_bind_mem (isRoundRobin_equiv sH.cur_sc sH s1L hs1) + fun rrH rrL hrr s2H s2L hs2 hm2 => ?_ + subst hrr + have hs2eq := isRoundRobin_state_eq hm2 + subst s2H + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH s2L hs2) + fun ctH ctL hct s3H s3L hs3 hm3 => ?_ + subst hct + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm3 + obtain ⟨hcurThread, hcurState⟩ := hm3 + subst ctH s3H + obtain ⟨tcb, htcb⟩ := hcur + have hkh := hs3.kheap_eq sH.cur_thread + rw [htcb] at hkh + have hts : Fl4Spec.getThreadState sH.cur_thread s3L = + ({(embThreadState tcb.tcb_state, s3L)}, False) := by + simp [Fl4Spec.getThreadState, Fl4Spec.threadGet, Fl4Spec.getTcb, Fl4Spec.readObject, NonDet.bind, + NonDet.getsThe, NonDet.assertOpt, NonDet.pure, Bind.bind, Pure.pure, hkh, embKernelObject, embTcb] + have hnative : embThreadState tcb.tcb_state ≠ .runningVM := by + cases tcb.tcb_state <;> simp [embThreadState] + simp only [Bind.bind] + rw [nonDet_bind_singleton_at _ hts] + simp only [hnative, ↓reduceIte, holConj, Bool.false_and, holIf_false, Bool.false_eq_true, false_and] + refine mrelStep_bind_mem (isValidTimeoutHandler_equiv sH.cur_thread sH s3L hs3) + fun _ _ _ s4H s4L hs4 _ => ?_ + refine mrelStep_bind_mem (getScRefillReady_equiv sH.cur_sc s4H s4L hs4) + fun rH rL hr s5H s5L hs5 _ => ?_ + subst hr + refine mrelStep_bind_mem (getScRefillSufficient_equiv hop sH.cur_sc 0 s5H s5L hs5) + fun suH suL hsu s6H s6L hs6 _ => ?_ + subst hsu + by_cases hready : rH = true ∧ suH = true + · simp only [hready] + exact tcbSchedAction_equiv tcbSchedAppend_eq sH.cur_thread s6H s6L hs6 + · have hhol : (rH && suH) = false := + Bool.eq_false_iff.mpr (mt (holConj_eq_true _ _).mp hready) + simp only [hhol, holIf_false, hready, ↓reduceIte] + exact postpone_equiv sH.cur_sc s6H s6L hs6 + + +/-- The live scheduling context must support both possible budget-check updates. -/ +def ChargeBudgetSafe (consumed : Ticks) (s : Structures_A.state ZH) : Prop := + s.cur_sc ≠ Machine_A.idle_sc_ptr → + HasNonEmptyRefills s.cur_sc s ∧ RefillBudgetCheckSafe consumed s + +theorem chargeBudget_equiv_without_timeout (hop : OpaqueRel RestRel) (consumed : Ticks) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : ChargeBudgetSafe consumed sH) : + MRelStep SR Eq (Ipc_A.charge_budget consumed false sH) (Fl4Spec.chargeBudget consumed false sL) := by + unfold Ipc_A.charge_budget Fl4Spec.chargeBudget + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun cH cL hc s1H s1L hs1 hm1 => ?_ + subst hc + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + obtain ⟨hsc, hstate⟩ := hm1 + subst cH s1H + simp only [Bind.bind, nonDet_bind_gets_at] + refine mrelStep_bind_mem (Rs' := SR) (Ra := Eq) (Rb := Eq) ?_ fun _ _ _ s2H s2L hs2 _ => ?_ + · by_cases hne : sH.cur_sc ≠ Machine_A.idle_sc_ptr + · have hc : holNot (holEq sH.cur_sc Machine_A.idle_sc_ptr) = true := by + simp [holNot_eq_true, holEq_eq_true, hne] + have hneL : sH.cur_sc ≠ s1L.idleSc := by simpa only [hs1.idleSc_eq] using hne + simp only [holFunApp, holWhen, NonDet.when, hc, ↓reduceIte] + rw [ite_eq_left hneL] + obtain ⟨hnonempty, hbudget⟩ := hsafe hne + refine mrelStep_bind_mem (isRoundRobin_equiv sH.cur_sc sH s1L hs1) + fun rrH rrL hrr s3H s3L hs3 hm3 => ?_ + subst hrr + have hsame := isRoundRobin_state_eq hm3 + subst s3H + cases rrH with + | true => + simp only [holIf_true, ↓reduceIte] + exact mrelStep_bind_mem (refillResetRr_equiv sH.cur_sc hs3 hnonempty) + fun _ _ _ tH tL ht _ => updateSchedContext_equiv (fun _ => rfl) sH.cur_sc tH tL ht + | false => + simp only [holIf_false, Bool.false_eq_true, ↓reduceIte] + exact mrelStep_bind_mem (refillBudgetCheck_equiv hop consumed hs3 hbudget) + fun _ _ _ tH tL ht _ => updateSchedContext_equiv (fun _ => rfl) sH.cur_sc tH tL ht + · have hc : holNot (holEq sH.cur_sc Machine_A.idle_sc_ptr) = false := by + apply Bool.eq_false_iff.mpr + simpa [holNot_eq_true, holEq_eq_true] using hne + have hneL : ¬sH.cur_sc ≠ s1L.idleSc := by simpa only [hs1.idleSc_eq] using hne + simp only [holFunApp, holWhen, NonDet.when, hc, Bool.false_eq_true, ↓reduceIte] + rw [ite_eq_right hneL] + exact mrel_return rfl sH s1L hs1 + · refine mrelStep_bind_mem (mrel_modify (fun _ _ h => { h with consumedTime_eq := rfl }) s2H s2L hs2) + fun _ _ _ s3H s3L hs3 _ => ?_ + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) s3H s3L hs3) + fun tH tL ht s4H s4L hs4 hm4 => ?_ + subst ht + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm4 + obtain ⟨hthread, hstate⟩ := hm4 + subst tH s4H + refine mrelStep_bind_mem (mrel_gets (fH := KHeap_A.schedulable s3H.cur_thread) + (fL := Fl4Spec.schedulable s3H.cur_thread) (Ra := Eq) + (fun _ _ h => (schedulable_eq h s3H.cur_thread).symm) s3H s4L hs4) + fun shouldH shouldL hshould s5H s5L hs5 hm5 => ?_ + subst hshould + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm5 + obtain ⟨hshould, hstate⟩ := hm5 + subst shouldH s5H + by_cases htrue : KHeap_A.schedulable s3H.cur_thread s3H = true + · simp only [holWhen, NonDet.when, holFunApp, htrue, ↓reduceIte] + refine mrelStep_bind_mem + (endTimeslice_equiv_without_timeout hop hs5 (schedulable_implies_tcb _ _ htrue)) + fun _ _ _ tH tL ht _ => ?_ + refine mrelStep_bind_mem (rescheduleRequired_equiv hop tH tL ht) fun _ _ _ uH uL hu _ => ?_ + exact mrel_modify (fun _ _ h => { h with reprogramTimer_eq := rfl }) uH uL hu + · have hfalse : KHeap_A.schedulable s3H.cur_thread s3H = false := Bool.eq_false_iff.mpr htrue + simp only [holWhen, NonDet.when, holFunApp, hfalse, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl s3H s5L hs5 + + +private theorem listRel_eq_refl {α : Type} : ∀ xs : List α, ListRel Eq xs xs + | [] => ListRel.nil + | _ :: tl => ListRel.cons rfl (listRel_eq_refl tl) + +private theorem listRel_eq_eq {α : Type} {xs ys : List α} (h : ListRel Eq xs ys) : xs = ys := by + induction h with + | nil => rfl + | cons h1 _ ih => subst h1; exact congrArg _ ih + +/-! ## Unconditional IPC helpers -/ + +theorem getMessageInfo_equiv (thread : ObjRef) : + MRel SR (FunRel embMessageInfo) + (Ipc_A.get_message_info thread) (Fl4Spec.getMessageInfo thread) := by + unfold Ipc_A.get_message_info Fl4Spec.getMessageInfo + refine mrel_bind (asUser_equiv (getRegister_equiv Machine_A.msg_info_register) thread) + fun xH xL hx => ?_ + subst hx + exact mrel_return (dataToMessageInfo_eq xH) + +theorem getExtraCptrs_equiv (buf : Option ObjRef) (mi : Structures_A.message_info) : + MRel SR (ListRel Eq) + (Ipc_A.get_extra_cptrs buf mi) (Fl4Spec.getExtraCptrs buf (embMessageInfo mi)) := by + cases buf with + | none => exact mrel_return ListRel.nil + | some b => + unfold Ipc_A.get_extra_cptrs Fl4Spec.getExtraCptrs + simp only [holFunApp, embMessageInfo, bufferCptrIndex_eq] + have hrange : holListUpt Ipc_A.buffer_cptr_index + (HolAdd.addVal Ipc_A.buffer_cptr_index (holUnsigned mi.mi_extra_caps)) = + List.range' Ipc_A.buffer_cptr_index + (Ipc_A.buffer_cptr_index + Fl4Spec.unat mi.mi_extra_caps - Ipc_A.buffer_cptr_index) := by + rfl + rw [hrange] + refine mrel_liftM (Ra := ListRel Eq) (Rb := ListRel Eq) ?_ + (mrel_mapM (fun nH nL hn => by subst hn; exact loadWordOffs_equiv b nH) (listRel_eq_refl _)) + intro wsH wsL hws + rw [listRel_eq_eq hws] + unfold holListMap + have hmap : List.map Machine_A.data_to_cptr wsL = List.map Fl4Spec.dataToCptr wsL := by + congr 1 + rw [hmap] + exact listRel_eq_refl _ + +theorem getExtraCptr_equiv (buffer : ObjRef) (n : Nat) : + MRel SR Eq + (Ipc_A.get_extra_cptr buffer n) (Fl4Spec.getExtraCptr buffer n) := by + unfold Ipc_A.get_extra_cptr Fl4Spec.getExtraCptr + exact mrel_liftM (fun wH wL hw => by subst hw; exact (dataToCptr_eq wH).symm) + (loadWordOffs_equiv buffer (n + Ipc_A.buffer_cptr_index)) + +theorem setExtraBadge_equiv (buffer badge : Word) (n : Nat) : + MRel SR Eq + (Ipc_A.set_extra_badge buffer badge n) (Fl4Spec.setExtraBadge buffer badge n) := + storeWordOffs_equiv buffer (Ipc_A.buffer_cptr_index + n) badge + +def lookup_extra_caps_p (thread : ObjRef) (buffer : Option Word) + (mi : Structures_A.message_info) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.fault (List (Structures_A.cap × CslotPtr))) := + holBindE (holLiftE (Ipc_A.get_extra_cptrs buffer mi)) fun cptrs => + holMapME (fun cptr => + Exceptions_A.cap_fault_on_failure (holOfBl (w := 64) cptr) false + (lookup_cap_and_slot_p thread cptr)) cptrs + +theorem patched_lookupExtraCaps_equiv (thread : ObjRef) (buffer : Option Word) + (mi : Structures_A.message_info) : + MRelE SR (FunRel embFault) (ListRel (ProdRel (FunRel embCap) Eq)) + (lookup_extra_caps_p thread buffer mi) + (Fl4Spec.lookupExtraCaps thread buffer (embMessageInfo mi)) := by + unfold lookup_extra_caps_p Fl4Spec.lookupExtraCaps + refine mrele_bindE (mrele_liftE (getExtraCptrs_equiv buffer mi)) fun csH csL hcs => ?_ + rw [listRel_eq_eq hcs] + exact mrele_mapME (fun cH cL hc => by + subst hc + exact capFaultOnFailure_equiv _ false (patched_lookupCapAndSlot_equiv thread cH)) (listRel_eq_refl _) + +def transfer_caps_loop_p (ep : Option ObjRef) (rcv_buffer : ObjRef) : + Nat → List (Structures_A.cap × CslotPtr) → List CslotPtr → Structures_A.message_info → + HolNonDet (Structures_A.state ZH) Structures_A.message_info + | n, [], _slots, mi => + holReturn (.MI mi.mi_length (holOfNat n) mi.mi_caps_unwrapped mi.mi_label) + | n, (cap, slot) :: morecaps, slots, mi => + Exceptions_A.const_on_failure (.MI mi.mi_length (holOfNat n) mi.mi_caps_unwrapped mi.mi_label) + (holBindE (holReturnOk (ε := ExceptionTypes_A.syscall_error) + (transfer_caps_loop_p ep rcv_buffer (n + 1) morecaps)) fun transfer_rest => + holIf (holConj (Structures_A.is_ep_cap cap) (holEq ep (some (Structures_A.obj_ref_of cap)))) + (holBindE (holLiftE (Ipc_A.set_extra_badge rcv_buffer (Structures_A.cap_ep_badge cap) n)) (holKBind + (holLiftE (transfer_rest slots + (.MI mi.mi_length mi.mi_extra_caps (holWordOr mi.mi_caps_unwrapped (holWordShiftl (1 : Word) n)) mi.mi_label))))) + (holIf (holNot (holEq slots [])) + (holBindE (CSpace_A.derive_cap slot cap) fun cap' => + holBindE (holWhenE (holEq cap' .NullCap) (holThrowError (holUndefined (α := ExceptionTypes_A.syscall_error)))) (holKBind + (holBindE (holLiftE (cap_insert_p cap' slot (holHd slots))) (holKBind + (holLiftE (transfer_rest (holTl slots) mi)))))) + (holReturnOk (.MI mi.mi_length (holOfNat n) mi.mi_caps_unwrapped mi.mi_label)))) + +/-- State-indexed, run-guarded safety predicate for `transfer_caps_loop_p` (structural recursion on `caps`). -/ +def TransferCapsLoopSafe (ep : Option ObjRef) (rcvBuffer : ObjRef) (n : Nat) + (caps : List (Structures_A.cap × CslotPtr)) (slots : List CslotPtr) + (mi : Structures_A.message_info) (sH : Structures_A.state ZH) : Prop := + match caps with + | [] => True + | (cap, slot) :: rest => + if Structures_A.is_ep_cap cap = true ∧ ep = some (Structures_A.obj_ref_of cap) then + ∀ s1, ((), s1) ∈ (Ipc_A.set_extra_badge rcvBuffer (Structures_A.cap_ep_badge cap) n sH).1 → + TransferCapsLoopSafe ep rcvBuffer (n + 1) rest slots + (.MI mi.mi_length mi.mi_extra_caps + (holWordOr mi.mi_caps_unwrapped (holWordShiftl (1 : Word) n)) mi.mi_label) s1 + else + match slots with + | [] => True + | dst :: dsts => + ∀ c' s1, (Sum.inr c', s1) ∈ (CSpace_A.derive_cap slot cap sH).1 → + c' ≠ .NullCap → + CapInsertSafe c' slot dst s1 ∧ + ∀ s2, ((), s2) ∈ (cap_insert_p c' slot dst s1).1 → + TransferCapsLoopSafe ep rcvBuffer (n + 1) rest dsts mi s2 + +private theorem constOnFailure_step_equiv {FH FL αH αL : Type} [Nonempty FH] [Nonempty αH] + {Rf : FH → FL → Prop} {Ra : αH → αL → Prop} + {cH : αH} {cL : αL} (hc : Ra cH cL) + {mH : HolNonDet (Structures_A.state ZH) (Sum FH αH)} + {mL : NonDetE (State ZL) FL αL} + {sH : Structures_A.state ZH} {sL : State ZL} + (hm : MRelStep SR (SumExceptRel Rf Ra) (mH sH) (ExceptT.run mL sL)) : + MRelStep SR Ra + (Exceptions_A.const_on_failure cH mH sH) (Fl4Spec.constOnFailure cL mL sL) := by + unfold Exceptions_A.const_on_failure Fl4Spec.constOnFailure holCatch NonDetE.catch + refine mrelStep_bind_mem hm fun rH rL hr s1H s1L hs1 _ => ?_ + cases rH <;> cases rL <;> simp only [SumExceptRel] at hr + · exact mrel_return hc s1H s1L hs1 + · exact mrel_return hr s1H s1L hs1 + +theorem patched_transferCapsLoop_equiv (ep : Option ObjRef) (rcvBuffer : ObjRef) + (n : Nat) (caps : List (Structures_A.cap × CslotPtr)) (slots : List CslotPtr) + (mi : Structures_A.message_info) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : TransferCapsLoopSafe ep rcvBuffer n caps slots mi sH) : + MRelStep SR (FunRel embMessageInfo) + (transfer_caps_loop_p ep rcvBuffer n caps slots mi sH) + (Fl4Spec.transferCapsLoop ep rcvBuffer n (caps.map fun p => (embCap p.1, p.2)) slots (embMessageInfo mi) sL) := by + induction caps generalizing n slots mi sH sL with + | nil => exact mrel_return (by cases mi; simp [embMessageInfo, holOfNat, HolNumeral.ofNatVal]; rfl) sH sL hs + | cons hd tl ih => + rcases hd with ⟨cap, slot⟩ + unfold transfer_caps_loop_p Fl4Spec.transferCapsLoop + simp only [List.map] + refine constOnFailure_step_equiv (Rf := fun _ _ => True) (Ra := FunRel embMessageInfo) + (by cases mi; simp [embMessageInfo, holOfNat, HolNumeral.ofNatVal]; rfl) ?_ + -- Peel the `returnOk transfer_rest` binding at state `sH`, `sL` + have hcondIff : (Structures_A.is_ep_cap cap = true ∧ ep = some (Structures_A.obj_ref_of cap)) ↔ + (Fl4Spec.isEpCap (embCap cap) = true ∧ ep = some (Fl4Spec.objRefOf (embCap cap))) := by + rw [isEpCap_eq] + constructor + · rintro ⟨hep, hobj⟩ + refine ⟨hep, ?_⟩ + cases cap with + | EndpointCap r _ _ => exact hobj + | _ => simp [Structures_A.is_ep_cap] at hep + · rintro ⟨hep, hobj⟩ + refine ⟨hep, ?_⟩ + cases cap with + | EndpointCap r _ _ => exact hobj + | _ => simp [Structures_A.is_ep_cap] at hep + refine mrelStep_bindE_mem + (mrele_returnOk (Re := fun _ _ => True) + (Ra := fun (fH : List CslotPtr → Structures_A.message_info → HolNonDet (Structures_A.state ZH) Structures_A.message_info) + (fL : List CslotPtr → MessageInfo → SMonad ZL MessageInfo) => + ∀ sls mi' sH' sL', SR sH' sL' → + TransferCapsLoopSafe ep rcvBuffer (n + 1) tl sls mi' sH' → + MRelStep SR (FunRel embMessageInfo) (fH sls mi' sH') (fL sls (embMessageInfo mi') sL')) + (fun sls mi' _ _ hs' hsf => ih (n + 1) sls mi' hs' hsf) sH sL hs) + fun trH trL htr s0H s0L hs0 hm0 => ?_ + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm0 + obtain ⟨_, hs0eq⟩ := hm0 + subst s0H + by_cases hcond : Structures_A.is_ep_cap cap = true ∧ ep = some (Structures_A.obj_ref_of cap) + · have hcondH : holConj (Structures_A.is_ep_cap cap) (holEq ep (some (Structures_A.obj_ref_of cap))) = true := by + simp [holConj_eq_true, holEq_eq_true, hcond] + have hcondL := hcondIff.mp hcond + unfold TransferCapsLoopSafe at hsafe + rw [ite_eq_left hcond] at hsafe + rw [hcondH, holIf_true, ite_eq_left hcondL] + have hbg : Fl4Spec.capEpBadge (embCap cap) = Structures_A.cap_ep_badge cap := by + have h1 := hcond.1 + cases cap with + | EndpointCap _ _ _ => rfl + | _ => simp [Structures_A.is_ep_cap] at h1 + rw [hbg] + have hbadge : MRelStep SR (SumExceptRel (εH := ExceptionTypes_A.syscall_error) (εL := SyscallError) (fun _ _ => True) Eq) + (holLiftE (Ipc_A.set_extra_badge rcvBuffer (Structures_A.cap_ep_badge cap) n) sH) + (NonDetE.liftE (Fl4Spec.setExtraBadge rcvBuffer (Structures_A.cap_ep_badge cap) n) s0L) := + mrele_liftE (setExtraBadge_equiv rcvBuffer _ n) sH s0L hs0 + refine mrelStep_bindE_mem hbadge fun _ _ _ s1H s1L hs1 hm1 => ?_ + have hm1' : ((), s1H) ∈ (Ipc_A.set_extra_badge rcvBuffer (Structures_A.cap_ep_badge cap) n sH).1 := by + simp only [holLiftE, holLiftM, holBind, holReturn, Set.mem_ofPred_eq, + Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + rcases hm1 with ⟨⟨r0, s0⟩, hm, _, hs0e⟩ + cases r0; subst hs0e; exact hm + have hstep := htr slots + (.MI mi.mi_length mi.mi_extra_caps + (holWordOr mi.mi_caps_unwrapped (holWordShiftl (1 : Word) n)) mi.mi_label) + s1H s1L hs1 (hsafe s1H hm1') + unfold holLiftE holLiftM NonDetE.liftE ExceptT.lift ExceptT.mk + exact mrelStep_bind_mem hstep fun aH aL ha sA sB hsA _ => + mrel_return (aH := Sum.inr aH) (aL := Except.ok aL) + (Ra := SumExceptRel (fun _ _ => True) (FunRel embMessageInfo)) ha sA sB hsA + · have hcondH : holConj (Structures_A.is_ep_cap cap) (holEq ep (some (Structures_A.obj_ref_of cap))) = false := + Bool.eq_false_iff.mpr (by simpa [holConj_eq_true, holEq_eq_true] using hcond) + have hcondL : ¬(Fl4Spec.isEpCap (embCap cap) = true ∧ ep = some (Fl4Spec.objRefOf (embCap cap))) := + mt hcondIff.mpr hcond + simp only [TransferCapsLoopSafe, hcond, ↓reduceIte] at hsafe + rw [hcondH, holIf_false, ite_eq_right hcondL] + cases slots with + | nil => + simp only [holNot, holEq, decide_true, Bool.not_true, holIf_false, ne_eq, not_true_eq_false, ↓reduceIte] + exact mrele_returnOk (by cases mi; simp [embMessageInfo, holOfNat, HolNumeral.ofNatVal]; rfl) sH s0L hs0 + | cons dst dsts => + simp only [holNot, holEq, List.cons_ne_nil, decide_false, Bool.not_false, holIf_true, + ne_eq, not_false_eq_true, ↓reduceIte, holHd, holTl, List.head?, the, List.tail] + have hder : MRelStep SR (SumExceptRel (fun _ _ => True) (FunRel embCap)) + (CSpace_A.derive_cap slot cap sH) (Fl4Spec.deriveCap slot (embCap cap) s0L) := by + have hd := deriveCap_equiv slot cap sH s0L hs0 + refine ⟨hd.1, ?_, ?_⟩ + · intro aH sH' hm + obtain ⟨aL, sL', hm', ha, hs'⟩ := hd.2.1 aH sH' hm + exact ⟨aL, sL', hm', by cases aH <;> cases aL <;> simp [SumExceptRel] at ha ⊢; exact ha, hs'⟩ + · intro aL sL' hm + obtain ⟨aH, sH', hm', ha, hs'⟩ := hd.2.2 aL sL' hm + exact ⟨aH, sH', hm', by cases aH <;> cases aL <;> simp [SumExceptRel] at ha ⊢; exact ha, hs'⟩ + refine mrelStep_bindE_mem hder fun c'H c'L hc' s1H s1L hs1 hm1 => ?_ + subst hc' + by_cases hN : c'H = .NullCap + · subst hN + simp only [holWhenE, NonDetE.whenE, decide_true, ↓reduceIte, embCap] + exact mrelStep_bindE_mem (mrele_throwError (Re := fun _ _ => True) (Ra := Eq) trivial s1H s1L hs1) + (fun _ _ _ _ _ _ hm => by simp [holThrowError, holReturn] at hm) + · have hNLF : embCap c'H ≠ .nullCap := by intro h; exact hN (by cases c'H <;> simp [embCap] at h; rfl) + simp only [holWhenE, NonDetE.whenE, hN, decide_false, hNLF, Bool.false_eq_true, ↓reduceIte] + refine mrelStep_bindE_mem (mrele_returnOk (Re := fun _ _ => True) (Ra := Eq) rfl s1H s1L hs1) + fun _ _ _ s2H s2L hs2 hm2 => ?_ + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm2 + obtain ⟨_, hs2eq⟩ := hm2 + subst s2H + obtain ⟨hsrcV, hrestSafe⟩ := hsafe c'H s1H hm1 hN + have hinsStep : MRelStep SR (SumExceptRel (εH := ExceptionTypes_A.syscall_error) (εL := SyscallError) (fun _ _ => True) Eq) + (holLiftE (ε := ExceptionTypes_A.syscall_error) (cap_insert_p c'H slot dst) s1H) + (NonDetE.liftE (ε := SyscallError) (Fl4Spec.capInsert (embCap c'H) slot dst) s2L) := by + have hci := patched_capInsert_equiv c'H slot dst hs2 hsrcV + unfold holLiftE holLiftM NonDetE.liftE ExceptT.lift ExceptT.mk + exact mrelStep_bind_mem hci fun aH aL ha sA sB hsA _ => + mrel_return (aH := Sum.inr aH) (aL := Except.ok aL) + (Ra := SumExceptRel (fun _ _ => True) Eq) ha sA sB hsA + refine mrelStep_bindE_mem hinsStep fun _ _ _ s3H s3L hs3 hm3 => ?_ + have hm3' : ((), s3H) ∈ (cap_insert_p c'H slot dst s1H).1 := by + simp only [holLiftE, holLiftM, holBind, holReturn, Set.mem_ofPred_eq, + Set.mem_singleton_iff, Prod.mk.injEq] at hm3 + rcases hm3 with ⟨⟨r0, s0⟩, hm, _, hs0e⟩ + cases r0; subst hs0e; exact hm + have hstep := htr dsts mi s3H s3L hs3 (hrestSafe s3H hm3') + unfold holLiftE holLiftM NonDetE.liftE ExceptT.lift ExceptT.mk + exact mrelStep_bind_mem hstep fun aH aL ha sA sB hsA _ => + mrel_return (aH := Sum.inr aH) (aL := Except.ok aL) + (Ra := SumExceptRel (fun _ _ => True) (FunRel embMessageInfo)) ha sA sB hsA + +def transfer_caps_p (info : Structures_A.message_info) (caps : List (Structures_A.cap × CslotPtr)) + (endpoint : Option ObjRef) (receiver : ObjRef) (recv_buffer : Option ObjRef) : + HolNonDet (Structures_A.state ZH) Structures_A.message_info := + holBind (get_receive_slots_p receiver recv_buffer) fun dest_slots => + holBind (holReturn (.MI info.mi_length 0 0 info.mi_label)) fun mi' => + match recv_buffer with + | none => holReturn mi' + | some receive_buffer => transfer_caps_loop_p endpoint receive_buffer 0 caps dest_slots mi' + +/-- State-indexed, run-guarded safety predicate for `transfer_caps_p`. -/ +def TransferCapsSafe (info : Structures_A.message_info) (caps : List (Structures_A.cap × CslotPtr)) + (endpoint : Option ObjRef) (receiver : ObjRef) (recvBuffer : Option ObjRef) + (sH : Structures_A.state ZH) : Prop := + match recvBuffer with + | none => True + | some rb => + ∀ ds s1, (ds, s1) ∈ (get_receive_slots_p receiver (some rb) sH).1 → + TransferCapsLoopSafe endpoint rb 0 caps ds (.MI info.mi_length 0 0 info.mi_label) s1 + +theorem patched_transferCaps_equiv (info : Structures_A.message_info) + (caps : List (Structures_A.cap × CslotPtr)) + (endpoint : Option ObjRef) (receiver : ObjRef) (recvBuffer : Option ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : TransferCapsSafe info caps endpoint receiver recvBuffer sH) : + MRelStep SR (FunRel embMessageInfo) + (transfer_caps_p info caps endpoint receiver recvBuffer sH) + (Fl4Spec.transferCaps (embMessageInfo info) (caps.map fun p => (embCap p.1, p.2)) + endpoint receiver recvBuffer sL) := by + unfold transfer_caps_p Fl4Spec.transferCaps + refine mrelStep_bind_mem (patched_getReceiveSlots_equiv receiver recvBuffer sH sL hs) + fun dsH dsL hds s1H s1L hs1 hm1 => ?_ + subst hds + refine mrelStep_bind_mem (mrel_return (Ra := FunRel embMessageInfo) (by cases info; simp [embMessageInfo]; rfl) s1H s1L hs1) + fun mi'H mi'L hmi' s2H s2L hs2 hm2 => ?_ + subst hmi' + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm2 + obtain ⟨hmiEq, hs2eq⟩ := hm2 + subst hmiEq; subst s2H + cases recvBuffer with + | none => exact mrel_return (Ra := FunRel embMessageInfo) rfl s1H s2L hs2 + | some rb => + exact patched_transferCapsLoop_equiv endpoint rb 0 caps dsH _ hs2 (hsafe dsH s1H hm1) + + +private theorem msgFromLookupFailure_eq (lf : ExceptionTypes_A.lookup_failure) : + Fl4Spec.msgFromLookupFailure (embLookupFailure lf) = + ExceptionTypes_A.msg_from_lookup_failure lf := by + cases lf <;> rfl + +theorem msgFromSyscallError_eq (e : ExceptionTypes_A.syscall_error) : + Fl4Spec.msgFromSyscallError (embSyscallError e) = + ExceptionTypes_A.msg_from_syscall_error e := by + cases e with + | FailedLookup b lf => + cases b <;> simp [Fl4Spec.msgFromSyscallError, ExceptionTypes_A.msg_from_syscall_error, + embSyscallError, msgFromLookupFailure_eq, holListAppend_eq, + HolNumeral.ofNatVal, HolZero.zeroVal, HolOne.oneVal] + | _ => rfl + +private theorem syscallMessage_eq : + Fl4Spec.syscallMessage = MachineTypes.syscallMessage.map embRegister := by + have hstart : holFromEnum MachineTypes.register.RAX = 0 := by + simp [holFromEnum, HolEnum.enumList, MachineTypes.enum_register, holTheIndex] + have hend : holFromEnum MachineTypes.register.R15 = 14 := by + simp [holFromEnum, HolEnum.enumList, MachineTypes.enum_register, holTheIndex] + rw [MachineTypes.syscallMessage, holUptoEnum, hstart, hend] + rfl + +private theorem exceptionMessage_eq : + Fl4Spec.exceptionMessage = MachineTypes.exceptionMessage.map embRegister := rfl + +theorem sanitiseRegister_eq (info : Bool) (reg : MachineTypes.register) (value : Word) : + ArchTcb_A.sanitise_register info reg value = Fl4Spec.sanitiseRegister info (embRegister reg) value := by + have hor : ArchTcb_A.sanitise_or_flags = Fl4Spec.sanitiseOrFlags := by decide + have hand : ArchTcb_A.sanitise_and_flags = Fl4Spec.sanitiseAndFlags := by decide + cases reg <;> + simp [ArchTcb_A.sanitise_register, Fl4Spec.sanitiseRegister, embRegister, holLet_eq, holIf_eq, + holEq_eq_true, holDisj_eq_true, holConj_eq_true, holLt_eq_true, HolNumeral.ofNatVal, + HolZero.zeroVal, HolOrd.ltVal, hor, hand, holWordOr, holWordAnd] + +theorem archGetSanitiseRegisterInfo_equiv (thread : ObjRef) : + MRel SR Eq (ArchTcb_A.arch_get_sanitise_register_info thread) + (Fl4Spec.archGetSanitiseRegisterInfo thread) := + mrel_return rfl + +private theorem timeoutMessage_eq : + Fl4Spec.timeoutMessage = MachineTypes.timeoutMessage.map embRegister := rfl + +private theorem restoreFaultRegisters_equiv (thread label : Word) (msg : List Word) + (registers : List MachineTypes.register) : + MRel SR Eq + (holBind (ArchTcb_A.arch_get_sanitise_register_info thread) fun info => + holBind (KHeap_A.as_user thread + (holZipWithMx (fun reg v => MachineOps.setRegister reg (ArchTcb_A.sanitise_register info reg v)) + registers msg)) (holKBind (holReturn (holEq label 0)))) + (do + let info ← Fl4Spec.archGetSanitiseRegisterInfo thread + Fl4Spec.asUser thread (NonDet.zipWithMx + (fun reg v => Fl4Spec.setRegister reg (Fl4Spec.sanitiseRegister info reg v)) + (registers.map embRegister) msg) + return decide (label = 0)) := by + refine mrel_bind (archGetSanitiseRegisterInfo_equiv thread) fun tH tL ht => ?_ + subst ht + have hregs : ListRel (FunRel embRegister) registers (registers.map embRegister) := by + induction registers with + | nil => exact ListRel.nil + | cons _ _ ih => exact ListRel.cons rfl ih + refine mrel_kbind (asUser_equiv (mrel_zipWithMx (Ra := FunRel embRegister) (Rb := Eq) + (fun rH rL hr vH vL hv => by + subst hr + subst hv + rw [← sanitiseRegister_eq] + exact setRegister_equiv rH _) hregs (listRel_eq_refl msg)) thread) ?_ + exact mrel_return (by simp [holEq]) + +theorem handleFaultReply_equiv (f : ExceptionTypes_A.fault) (thread label : Word) + (msg : List Word) : + MRel SR Eq (Ipc_A.handle_fault_reply f thread label msg) + (Fl4Spec.handleFaultReply (embFault f) thread label msg) := by + cases f with + | CapFault _ _ _ => exact mrel_return rfl + | UnknownSyscallException _ => + unfold Ipc_A.handle_fault_reply Fl4Spec.handleFaultReply embFault + simp only [syscallMessage_eq] + exact restoreFaultRegisters_equiv thread label msg _ + | UserException _ _ => + unfold Ipc_A.handle_fault_reply Fl4Spec.handleFaultReply embFault + simp only [exceptionMessage_eq] + exact restoreFaultRegisters_equiv thread label msg _ + | Timeout _ => + unfold Ipc_A.handle_fault_reply Fl4Spec.handleFaultReply embFault + simp only [timeoutMessage_eq] + exact restoreFaultRegisters_equiv thread label msg _ + | ArchFault af => exact mrel_return rfl + +theorem patched_makeArchFaultMsg_equiv (f : Machine_A.arch_fault) (thread : ObjRef) : + MRel SR Eq (Patched.makeArchFaultMsg f thread) (Fl4Spec.makeArchFaultMsg (embArchFault f) thread) := by + cases f with + | VMFault addr words => + rw [(Patched.makeArchFaultMsg_delta (Z := ZH) addr thread words).2] + exact mrel_bind (asUser_equiv getRestartPC_equiv thread) fun _ _ h => by + subst h + exact mrel_return rfl + +def make_fault_msg_p : ExceptionTypes_A.fault → ObjRef → + HolNonDet (Structures_A.state ZH) (Word × List Word) + | .CapFault cptr rp lf, thread => + holBind (KHeap_A.as_user thread MachineOps.getRestartPC) fun pc => + holReturn (1, pc :: cptr :: (if rp then 1 else 0) :: ExceptionTypes_A.msg_from_lookup_failure lf) + | .UnknownSyscallException n, thread => + holBind (KHeap_A.as_user thread (holMapM MachineOps.getRegister MachineTypes.syscallMessage)) fun msg => + holReturn (2, msg ++ [n]) + | .UserException exception code, thread => + holBind (KHeap_A.as_user thread (holMapM MachineOps.getRegister MachineTypes.exceptionMessage)) fun msg => + holReturn (3, msg ++ [exception, code]) + | .Timeout badge, thread => + holBind (holGetsThe (KHeap_A.get_tcb thread)) fun tcb => + match tcb.tcb_sched_context with + | none => holReturn (5, [badge]) + | some sc => + holBind (SchedContext_A.sched_context_update_consumed sc) fun consumed => + holReturn (5, badge :: Arch_Structs_A.words_from_time consumed) + | .ArchFault af, thread => Patched.makeArchFaultMsg af thread + +theorem patched_makeFaultMsg_equiv (hop : OpaqueRel RestRel) + (f : ExceptionTypes_A.fault) (thread : ObjRef) : + MRel SR Eq + (make_fault_msg_p f thread) (Fl4Spec.makeFaultMsg (embFault f) thread) := by + cases f with + | CapFault cptr rp lf => + unfold make_fault_msg_p Fl4Spec.makeFaultMsg embFault + refine mrel_bind (asUser_equiv getRestartPC_equiv thread) fun pcH pcL hpc => ?_; subst hpc + exact mrel_return (by rw [msgFromLookupFailure_eq]) + | UnknownSyscallException n => + unfold make_fault_msg_p Fl4Spec.makeFaultMsg embFault + have hregs : ListRel (FunRel embRegister) MachineTypes.syscallMessage Fl4Spec.syscallMessage := by + rw [syscallMessage_eq] + induction MachineTypes.syscallMessage with + | nil => exact ListRel.nil + | cons _ _ ih => exact ListRel.cons rfl ih + refine mrel_bind (asUser_equiv (mrel_mapM (fun rH rL hr => by subst hr; exact getRegister_equiv rH) hregs) thread) + fun mH mL hm => ?_ + rw [listRel_eq_eq hm] + exact mrel_return rfl + | UserException exception code => + unfold make_fault_msg_p Fl4Spec.makeFaultMsg embFault + have hregs : ListRel (FunRel embRegister) MachineTypes.exceptionMessage Fl4Spec.exceptionMessage := by + rw [exceptionMessage_eq] + induction MachineTypes.exceptionMessage with + | nil => exact ListRel.nil + | cons _ _ ih => exact ListRel.cons rfl ih + refine mrel_bind (asUser_equiv (mrel_mapM (fun rH rL hr => by subst hr; exact getRegister_equiv rH) hregs) thread) + fun mH mL hm => ?_ + rw [listRel_eq_eq hm] + exact mrel_return rfl + | Timeout badge => + unfold make_fault_msg_p Fl4Spec.makeFaultMsg embFault + refine mrel_bind (mrel_getsThe (getTcb_equiv thread)) fun tH tL ht => ?_; subst ht + cases hsc : tH.tcb_sched_context with + | none => simp [embTcb, hsc]; exact mrel_return rfl + | some sc => + simp only [embTcb, hsc] + refine mrel_bind (schedContextUpdateConsumed_equiv hop sc) fun cH cL hc => ?_; subst hc + exact mrel_return (by rw [wordsFromTime_eq]) + | ArchFault af => exact patched_makeArchFaultMsg_equiv af thread + +def do_fault_transfer_p (badge sender receiver : ObjRef) (buf : Option ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault sender) fun fault => + holBind (match fault with | some f => holReturn f | none => holFail) fun f => + holBind (make_fault_msg_p f sender) fun (label, msg) => + holBind (TcbAcc_A.set_mrs receiver buf msg) fun sent => + holBind (TcbAcc_A.set_message_info receiver (.MI sent 0 0 label)) (holKBind + (KHeap_A.as_user receiver (MachineOps.setRegister Machine_A.badge_register badge))) + +theorem patched_doFaultTransfer_equiv (hop : OpaqueRel RestRel) + (badge sender receiver : ObjRef) (buf : Option ObjRef) : + MRel SR Eq + (do_fault_transfer_p badge sender receiver buf) + (Fl4Spec.doFaultTransfer badge sender receiver buf) := by + unfold do_fault_transfer_p Fl4Spec.doFaultTransfer + refine mrel_bind (threadGet_equiv (Ra := OptRel (FunRel embFault)) + (fun t => by cases hf' : t.tcb_fault <;> simp [OptRel, embTcb, hf']) sender) fun fH fL hf => ?_ + cases fH with + | none => + cases fL with + | none => exact mrel_bind_fail + | some _ => simp [OptRel] at hf + | some fH' => + cases fL with + | none => simp [OptRel] at hf + | some fL' => + simp only [OptRel, FunRel] at hf + subst hf + refine mrel_bind (mrel_return (Ra := FunRel embFault) rfl) fun xH xL hx => ?_; subst hx + refine mrel_bind (patched_makeFaultMsg_equiv hop xH sender) fun pH pL hp => ?_; subst hp + rcases pH with ⟨label, msg⟩ + refine mrel_bind (setMrs_equiv receiver buf msg) fun sH' sL' hs' => ?_; subst hs' + refine mrel_kbind (setMessageInfo_equiv receiver (.MI sH' 0 0 label)) ?_ + exact asUser_equiv (setRegister_equiv Machine_A.badge_register badge) receiver + +def do_normal_transfer_p (sender : ObjRef) (sbuf endpoint : Option ObjRef) (badge : Word) + (grant : Bool) (receiver : ObjRef) (rbuf : Option ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (Ipc_A.get_message_info sender) fun mi => + holBind (if grant then holCatch (lookup_extra_caps_p sender sbuf mi) (fun _ => holReturn []) + else holReturn []) fun caps => + holBind (Tcb_A.copy_mrs sender sbuf receiver rbuf mi.mi_length) fun mrs_transferred => + holBind (transfer_caps_p mi caps endpoint receiver rbuf) fun mi' => + holBind (TcbAcc_A.set_message_info receiver (.MI mrs_transferred mi'.mi_extra_caps mi'.mi_caps_unwrapped mi.mi_label)) + (holKBind (KHeap_A.as_user receiver (MachineOps.setRegister Machine_A.badge_register badge))) + +/-- State-indexed, run-guarded safety predicate for `do_normal_transfer_p` (trivially `True` when `grant = false`). -/ +def DoNormalTransferSafe (sender : ObjRef) (sbuf endpoint : Option ObjRef) + (grant : Bool) (receiver : ObjRef) (rbuf : Option ObjRef) + (sH : Structures_A.state ZH) : Prop := + grant = true → + ∀ mi s1, (mi, s1) ∈ (Ipc_A.get_message_info sender sH).1 → + ∀ caps s2, (caps, s2) ∈ (holCatch (lookup_extra_caps_p sender sbuf mi) (fun _ => holReturn []) s1).1 → + ∀ mrs s3, (mrs, s3) ∈ (Tcb_A.copy_mrs sender sbuf receiver rbuf mi.mi_length s2).1 → + TransferCapsSafe mi caps endpoint receiver rbuf s3 + +theorem patched_doNormalTransfer_equiv + (sender : ObjRef) (sbuf endpoint : Option ObjRef) (badge : Word) + (grant : Bool) (receiver : ObjRef) (rbuf : Option ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : DoNormalTransferSafe sender sbuf endpoint grant receiver rbuf sH) : + MRelStep SR Eq + (do_normal_transfer_p sender sbuf endpoint badge grant receiver rbuf sH) + (Fl4Spec.doNormalTransfer sender sbuf endpoint badge grant receiver rbuf sL) := by + unfold do_normal_transfer_p Fl4Spec.doNormalTransfer + refine mrelStep_bind_mem (getMessageInfo_equiv sender sH sL hs) fun miH miL hmi s1H s1L hs1 hm1 => ?_ + subst hmi + have hcont : ∀ cH cL, ListRel (ProdRel (FunRel embCap) Eq) cH cL → + ∀ s2H s2L, SR s2H s2L → + (∀ mrs s3, (mrs, s3) ∈ (Tcb_A.copy_mrs sender sbuf receiver rbuf miH.mi_length s2H).1 → + TransferCapsSafe miH cH endpoint receiver rbuf s3) → + MRelStep SR Eq + ((holBind (Tcb_A.copy_mrs sender sbuf receiver rbuf miH.mi_length) fun mrs_transferred => + holBind (transfer_caps_p miH cH endpoint receiver rbuf) fun mi' => + holBind (TcbAcc_A.set_message_info receiver (.MI mrs_transferred mi'.mi_extra_caps mi'.mi_caps_unwrapped miH.mi_label)) + (holKBind (KHeap_A.as_user receiver (MachineOps.setRegister Machine_A.badge_register badge)))) s2H) + ((do + let mrsTransferred ← Fl4Spec.copyMrs sender sbuf receiver rbuf (embMessageInfo miH).miLength + let mi' ← Fl4Spec.transferCaps (embMessageInfo miH) cL endpoint receiver rbuf + Fl4Spec.setMessageInfo receiver + { miLength := mrsTransferred, miExtraCaps := mi'.miExtraCaps, + miCapsUnwrapped := mi'.miCapsUnwrapped, miLabel := (embMessageInfo miH).miLabel } + Fl4Spec.asUser receiver (Fl4Spec.setRegister Fl4Spec.badgeRegister badge)) s2L) := by + intro cH cL hc s2H s2L hs2 hcapsSafe + have hcEq : cL = cH.map (fun p => (embCap p.1, p.2)) := by + have aux : ∀ {lH : List (Structures_A.cap × CslotPtr)} {lL : List (Cap × CslotPtr)}, + ListRel (ProdRel (FunRel embCap) Eq) lH lL → lL = lH.map (fun p => (embCap p.1, p.2)) := by + intro lH lL h + induction h with + | nil => rfl + | cons hd _ ih => + rcases hd with ⟨ha, hb⟩; dsimp only [FunRel] at ha + exact congrArg₂ List.cons (Prod.ext ha hb.symm) ih + exact aux hc + subst hcEq + refine mrelStep_bind_mem (copyMrs_equiv sender sbuf receiver rbuf miH.mi_length s2H s2L hs2) + fun mtH mtL hmt s3H s3L hs3 hm3 => ?_; subst hmt + refine mrelStep_bind_mem (patched_transferCaps_equiv miH cH endpoint receiver rbuf hs3 (hcapsSafe mtH s3H hm3)) + fun mi'H mi'L hmi' s4H s4L hs4 _ => ?_; subst hmi' + refine mrelStep_bind_mem (setMessageInfo_equiv receiver + (.MI mtH mi'H.mi_extra_caps mi'H.mi_caps_unwrapped miH.mi_label) s4H s4L hs4) + fun _ _ _ s5H s5L hs5 _ => ?_ + exact asUser_equiv (setRegister_equiv Machine_A.badge_register badge) receiver s5H s5L hs5 + cases grant with + | false => + simp only [Bool.false_eq_true, ↓reduceIte] + refine mrelStep_bind_mem (mrel_return (Ra := ListRel (ProdRel (FunRel embCap) Eq)) (aH := []) (aL := []) ListRel.nil s1H s1L hs1) + fun cH cL hc s2H s2L hs2 hm2 => ?_ + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm2 + obtain ⟨rfl, _⟩ := hm2 + exact hcont [] cL hc s2H s2L hs2 (fun _ _ _ => by + cases rbuf with + | none => trivial + | some rb => intro _ _ _; trivial) + | true => + simp only [↓reduceIte] + refine mrelStep_bind_mem (mrele_catch (patched_lookupExtraCaps_equiv sender sbuf miH) + (fun _ _ _ => mrel_return (aH := []) (aL := []) ListRel.nil) s1H s1L hs1) fun cH cL hc s2H s2L hs2 hm2 => ?_ + exact hcont cH cL hc s2H s2L hs2 (hsafe rfl miH s1H hm1 cH s2H hm2) + +def do_ipc_transfer_p (sender : ObjRef) (ep : Option ObjRef) (badge : Badge) (grant : Bool) + (receiver : ObjRef) : HolNonDet (Structures_A.state ZH) Unit := + holBind (Patched.lookupIpcBuffer true receiver) fun recv_buffer => + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault sender) fun fault => + match fault with + | none => + holBind (Patched.lookupIpcBuffer false sender) fun send_buffer => + do_normal_transfer_p sender send_buffer ep badge grant receiver recv_buffer + | some _ => do_fault_transfer_p badge sender receiver recv_buffer + +/-- State-indexed, run-guarded safety predicate for `do_ipc_transfer_p`. -/ +def DoIpcTransferSafe (sender : ObjRef) (ep : Option ObjRef) (grant : Bool) + (receiver : ObjRef) (sH : Structures_A.state ZH) : Prop := + grant = true → + ∀ rbuf s1, (rbuf, s1) ∈ (Patched.lookupIpcBuffer true receiver sH).1 → + ∀ s2, (none, s2) ∈ (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault sender s1).1 → + ∀ sbuf s3, (sbuf, s3) ∈ (Patched.lookupIpcBuffer false sender s2).1 → + DoNormalTransferSafe sender sbuf ep true receiver rbuf s3 + +theorem patched_doIpcTransfer_equiv (hop : OpaqueRel RestRel) + (sender : ObjRef) (ep : Option ObjRef) (badge : Badge) (grant : Bool) + (receiver : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : DoIpcTransferSafe sender ep grant receiver sH) : + MRelStep SR Eq + (do_ipc_transfer_p sender ep badge grant receiver sH) + (Fl4Spec.doIpcTransfer sender ep badge grant receiver sL) := by + unfold do_ipc_transfer_p Fl4Spec.doIpcTransfer + refine mrelStep_bind_mem (patched_lookupIpcBuffer_equiv true receiver sH sL hs) + fun rbH rbL hrb s1H s1L hs1 hm1 => ?_; subst hrb + refine mrelStep_bind_mem (threadGet_equiv (Ra := OptRel (FunRel embFault)) + (fun t => by cases hf' : t.tcb_fault <;> simp [OptRel, embTcb, hf']) sender s1H s1L hs1) + fun fH fL hf s2H s2L hs2 hm2 => ?_ + cases fH <;> cases fL <;> simp only [OptRel] at hf + · refine mrelStep_bind_mem (patched_lookupIpcBuffer_equiv false sender s2H s2L hs2) + fun sbH sbL hsb s3H s3L hs3 hm3 => ?_; subst hsb + exact patched_doNormalTransfer_equiv sender sbH ep badge grant receiver rbH hs3 + (fun hg => by subst hg; exact hsafe rfl rbH s1H hm1 s2H hm2 sbH s3H hm3 rfl) + · exact patched_doFaultTransfer_equiv hop badge sender receiver rbH s2H s2L hs2 + + +def send_ipc_p (block call : Bool) (badge : Badge) + (can_grant can_grant_reply can_donate : Bool) (thread epptr : ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (KHeap_A.get_simple_ko Structures_A.kernel_object.Endpoint epptr) fun ep => + match ep, block with + | .IdleEP, true => Ipc_A.send_ipc_blocked thread epptr badge can_grant can_grant_reply call + | .SendEP _, true => Ipc_A.send_ipc_blocked thread epptr badge can_grant can_grant_reply call + | .IdleEP, false => holReturn () + | .SendEP _, false => holReturn () + | .RecvEP (dest :: _), _ => + holBind (IpcCancel_A.tcb_ep_dequeue dest epptr) (holKBind + (holBind (KHeap_A.get_thread_state dest) fun recv_state => + holBind (match recv_state with | .BlockedOnReceive _ reply _ => holReturn reply | _ => holFail) fun reply => + holBind (do_ipc_transfer_p thread (some epptr) badge can_grant dest) (holKBind + (holBind (holMaybeM (IpcCancel_A.reply_unlink_tcb dest) reply) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context dest) fun sc_opt => + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault thread) fun fault => + holBind (if call ∨ fault ≠ none then + if (can_grant ∨ can_grant_reply) ∧ reply ≠ none then + IpcCancel_A.reply_push thread dest (holTheOpt reply) can_donate + else KHeap_A.set_thread_state thread .Inactive + else holWhen (holConj can_donate (holEq sc_opt none)) + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context thread) fun thread_sc => + IpcCancel_A.sched_context_donate (holTheOpt thread_sc) dest)) (holKBind + (holBind (KHeap_A.set_thread_state dest .Running) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context dest) fun dest_sc => + holBind (Sporadic_A.if_cond_refill_unblock_check dest_sc (some false) (some false)) (holKBind + (KHeap_A.possible_switch_to dest)))))))))))) + | .RecvEP [], _ => holFail + +/-- State-indexed, run-guarded safety predicate for `send_ipc_p`. -/ +def SendIpcSafe (canGrant : Bool) (thread epptr : ObjRef) (sH : Structures_A.state ZH) : Prop := + canGrant = true → + ∀ dest rest s1, (.RecvEP (dest :: rest), s1) ∈ (KHeap_A.get_simple_ko Structures_A.kernel_object.Endpoint epptr sH).1 → + ∀ s2, ((), s2) ∈ (IpcCancel_A.tcb_ep_dequeue dest epptr s1).1 → + ∀ b rep d s3, (.BlockedOnReceive b rep d, s3) ∈ (KHeap_A.get_thread_state dest s2).1 → + DoIpcTransferSafe thread (some epptr) true dest s3 + +theorem patched_sendIpc_equiv (hop : OpaqueRel RestRel) + (block call : Bool) (badge : Badge) + (canGrant canGrantReply canDonate : Bool) (thread epptr : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : SendIpcSafe canGrant thread epptr sH) : + MRelStep SR Eq + (send_ipc_p block call badge canGrant canGrantReply canDonate thread epptr sH) + (Fl4Spec.sendIpc block call badge canGrant canGrantReply canDonate thread epptr sL) := by + unfold send_ipc_p Fl4Spec.sendIpc + refine mrelStep_bind_mem (getEndpoint_equiv epptr sH sL hs) fun epH epL hep s1H s1L hs1 hm1 => ?_; subst hep + cases epH with + | IdleEP => cases block <;> first | exact mrel_return rfl s1H s1L hs1 | exact sendIpcBlocked_equiv thread epptr badge canGrant canGrantReply call s1H s1L hs1 + | SendEP q => cases block <;> first | exact mrel_return rfl s1H s1L hs1 | exact sendIpcBlocked_equiv thread epptr badge canGrant canGrantReply call s1H s1L hs1 + | RecvEP q => + cases q with + | nil => exact mrel_fail s1H s1L hs1 + | cons dest rest => + simp only [embEndpoint] + refine mrelStep_bind_mem (tcbEpDequeue_equiv dest epptr s1H s1L hs1) fun u2 _ _ s2H s2L hs2 hm2 => ?_ + cases u2 + refine mrelStep_bind_mem (getThreadState_equiv dest s2H s2L hs2) fun rsH rsL hrs s3H s3L hs3 hm3 => ?_; subst hrs + cases rsH with + | BlockedOnReceive b rep d => + simp only [embThreadState] + refine mrelStep_bind_mem (mrel_return (Ra := Eq) rfl s3H s3L hs3) fun repH repL hrep' s4H s4L hs4 hm4 => ?_; subst hrep' + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm4 + obtain ⟨hreq, hs4eq⟩ := hm4; subst repH; subst s4H + refine mrelStep_bind_mem (patched_doIpcTransfer_equiv hop thread (some epptr) badge canGrant dest hs4 + (fun hg => by subst hg; exact hsafe rfl dest rest s1H hm1 s2H hm2 b rep d s3H hm3 rfl)) + fun _ _ _ s5H s5L hs5 _ => ?_ + have hunlink : MRel SR Eq (holMaybeM (IpcCancel_A.reply_unlink_tcb dest) rep) + (NonDet.maybeM (Fl4Spec.replyUnlinkTcb dest) rep) := + mrel_maybeM (Ra := Eq) (fun rH rL hr => by subst hr; exact replyUnlinkTcb_equiv dest rH) + (by cases rep <;> simp [OptRel]) + refine mrelStep_bind_mem (hunlink s5H s5L hs5) + fun _ _ _ s6H s6L hs6 _ => ?_ + refine mrelStep_bind_mem (getTcbObjRef_equiv (fun _ => rfl) dest s6H s6L hs6) fun soH soL hso s7H s7L hs7 _ => ?_; subst hso + refine mrelStep_bind_mem (threadGet_equiv (Ra := OptRel (FunRel embFault)) + (fun t => by cases hf' : t.tcb_fault <;> simp [OptRel, embTcb, hf']) thread s7H s7L hs7) + fun fH fL hf s8H s8L hs8 _ => ?_ + have hfNone : fH ≠ none ↔ fL ≠ none := by cases fH <;> cases fL <;> simp [OptRel] at hf ⊢ + have htail : MRel SR Eq + (holBind (KHeap_A.set_thread_state dest .Running) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context dest) fun dest_sc => + holBind (Sporadic_A.if_cond_refill_unblock_check dest_sc (some false) (some false)) (holKBind + (KHeap_A.possible_switch_to dest))))) + (do + Fl4Spec.setThreadState dest .running + let destSc ← Fl4Spec.getTcbObjRef Tcb.tcbSchedContext dest + Fl4Spec.ifSporadicCurScTestRefillUnblockCheck destSc + Fl4Spec.possibleSwitchTo dest) := by + refine mrel_kbind (setThreadState_equiv dest .Running) ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) dest) fun dsH dsL hds => ?_; subst hds + exact mrel_kbind (ifSporadicCurScTestRefillUnblockCheck_equiv dsH) (possibleSwitchTo_equiv hop dest) + by_cases hcf : call = true ∨ fH ≠ none + · have hcfL : call = true ∨ fL ≠ none := by rwa [← hfNone] + simp only [hcf, hcfL, ↓reduceIte] + by_cases hgr : (canGrant = true ∨ canGrantReply = true) ∧ rep ≠ none + · simp only [hgr] + cases rep with + | none => exact absurd rfl hgr.2 + | some r => exact (mrel_kbind (replyPush_equiv hop thread dest r canDonate) htail) s8H s8L hs8 + · simp only [hgr, ↓reduceIte] + exact (mrel_kbind (setThreadState_equiv thread .Inactive) htail) s8H s8L hs8 + · have hcfL : ¬(call = true ∨ fL ≠ none) := by rwa [← hfNone] + simp only [hcf, hcfL, ↓reduceIte] + refine (mrel_kbind (Ra := Eq) ?_ htail) s8H s8L hs8 + refine mrel_when (by simp [holConj_eq_true, holEq_eq_true]) fun _ => ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) thread) fun tsH tsL hts => ?_; subst hts + exact schedContextDonate_equiv hop (holTheOpt tsH) dest + | _ => simp only [embThreadState]; exact mrel_bind_fail s3H s3L hs3 + +def receive_ipc_p (thread : ObjRef) (cap : Structures_A.cap) (is_blocking : Bool) + (reply_cap : Structures_A.cap) : HolNonDet (Structures_A.state ZH) Unit := + holBind (match cap with | .EndpointCap ref _ rights => holReturn (ref, rights) | _ => holFail) fun (epptr, _rights) => + holBind (match reply_cap with + | .ReplyCap r _ => + holBind (holLiftM Structures_A.reply_ext.reply_tcb (KHeap_A.get_simple_ko Structures_A.kernel_object.Reply r)) fun tptr => + holBind (holWhen (holConj (holNot (holEq tptr none)) (holNot (holEq (holTheOpt tptr) thread))) + (IpcCancel_A.cancel_ipc (holTheOpt tptr))) (holKBind (holReturn (some r))) + | .NullCap => holReturn none + | _ => holFail) fun reply => + holBind (KHeap_A.get_simple_ko Structures_A.kernel_object.Endpoint epptr) fun ep => + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_bound_notification thread) fun ntfnptr => + holBind (match ntfnptr with | none => holReturn Structures_A.default_notification | some p => KHeap_A.get_simple_ko Structures_A.kernel_object.Notification p) fun ntfn => + if ntfnptr ≠ none ∧ Ipc_A.isActive ntfn = true then + Ipc_A.complete_signal (holTheOpt ntfnptr) thread + else + holBind (holWhen (holConj (holNot (holEq ntfnptr none)) is_blocking) + (SchedContext_A.maybe_return_sc (holTheOpt ntfnptr) thread)) (holKBind + (match ep with + | .SendEP q => + holBind (holAssert (holNot (holEq q []))) (holKBind + (holBind (holReturn (holHd q)) fun sender => + holBind (IpcCancel_A.tcb_ep_dequeue sender epptr) (holKBind + (holBind (KHeap_A.get_thread_state sender) fun sender_state => + holBind (match sender_state with | .BlockedOnSend _ data => holReturn data | _ => holFail) fun data => + holBind (do_ipc_transfer_p sender (some epptr) data.sender_badge data.sender_can_grant thread) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context sender) fun sc_ptr => + holBind (Sporadic_A.if_cond_refill_unblock_check sc_ptr (some false) (some true)) (holKBind + (holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault sender) fun fault => + if data.sender_is_call = true ∨ fault ≠ none then + if (data.sender_can_grant = true ∨ data.sender_can_grant_reply = true) ∧ reply ≠ none then + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context sender) fun sender_sc => + holBind (holReturn (decide (sender_sc ≠ none ∧ ¬(fault.elim false Ipc_A.is_timeout_fault = true)))) fun donate => + IpcCancel_A.reply_push sender thread (holTheOpt reply) donate + else KHeap_A.set_thread_state sender .Inactive + else + holBind (KHeap_A.set_thread_state sender .Running) (holKBind + (KHeap_A.possible_switch_to sender)))))))))) + | _ => Ipc_A.receive_ipc_blocked is_blocking thread epptr reply)) + +/-- State-indexed, run-guarded safety predicate for `receive_ipc_p`. -/ +def ReceiveIpcSafe (thread : ObjRef) (cap : Structures_A.cap) (isBlocking : Bool) + (replyCap : Structures_A.cap) (sH : Structures_A.state ZH) : Prop := + match cap with + | .EndpointCap epptr _ _ => + ∀ (rep : Option ObjRef) s1, (rep, s1) ∈ ((match replyCap with + | .ReplyCap r _ => + holBind (holLiftM Structures_A.reply_ext.reply_tcb (KHeap_A.get_simple_ko Structures_A.kernel_object.Reply r)) fun tptr => + holBind (holWhen (holConj (holNot (holEq tptr none)) (holNot (holEq (holTheOpt tptr) thread))) + (IpcCancel_A.cancel_ipc (holTheOpt tptr))) (holKBind (holReturn (some r))) + | .NullCap => holReturn none + | _ => holFail : HolNonDet (Structures_A.state ZH) (Option ObjRef)) sH).1 → + ∀ ep s2, (ep, s2) ∈ (KHeap_A.get_simple_ko Structures_A.kernel_object.Endpoint epptr s1).1 → + ∀ ntfnptr s3, (ntfnptr, s3) ∈ (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_bound_notification thread s2).1 → + ∀ ntfn s4, (ntfn, s4) ∈ ((match ntfnptr with + | none => holReturn Structures_A.default_notification + | some p => KHeap_A.get_simple_ko Structures_A.kernel_object.Notification p : + HolNonDet (Structures_A.state ZH) Structures_A.notification) s3).1 → + ¬(ntfnptr ≠ none ∧ Ipc_A.isActive ntfn = true) → + ∀ s5, ((), s5) ∈ (holWhen (holConj (holNot (holEq ntfnptr none)) isBlocking) + (SchedContext_A.maybe_return_sc (holTheOpt ntfnptr) thread) s4).1 → + match ep with + | .SendEP (sender :: _) => + ∀ s6, ((), s6) ∈ (IpcCancel_A.tcb_ep_dequeue sender epptr s5).1 → + ∀ ptr data s7, (.BlockedOnSend ptr data, s7) ∈ (KHeap_A.get_thread_state sender s6).1 → + DoIpcTransferSafe sender (some epptr) data.sender_can_grant thread s7 + | _ => True + | _ => True + +theorem patched_receiveIpc_equiv (hop : OpaqueRel RestRel) + (thread : ObjRef) (cap : Structures_A.cap) (isBlocking : Bool) + (replyCap : Structures_A.cap) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : ReceiveIpcSafe thread cap isBlocking replyCap sH) : + MRelStep SR Eq + (receive_ipc_p thread cap isBlocking replyCap sH) + (Fl4Spec.receiveIpc thread (embCap cap) isBlocking (embCap replyCap) sL) := by + unfold receive_ipc_p Fl4Spec.receiveIpc + cases cap with + | EndpointCap epptr _ rights => + simp only [embCap] + refine mrelStep_bind_mem (mrel_return (Ra := ProdRel Eq (FunRel embRightsSet)) ⟨rfl, rfl⟩ sH sL hs) + fun pH pL hp s0H s0L hs0 hm0 => ?_ + rcases pH with ⟨epptrH, _⟩; rcases pL with ⟨epptrL, _⟩; rcases hp with ⟨hep, _⟩; subst hep + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm0 + obtain ⟨⟨hepp, _⟩, hs0eq⟩ := hm0 + subst epptrH; subst s0H + have hcontRep : ∀ repH repL, repH = repL → ∀ s1H s1L, SR s1H s1L → + (∀ ep s2, (ep, s2) ∈ (KHeap_A.get_simple_ko Structures_A.kernel_object.Endpoint epptr s1H).1 → + ∀ ntfnptr s3, (ntfnptr, s3) ∈ (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_bound_notification thread s2).1 → + ∀ ntfn s4, (ntfn, s4) ∈ ((match ntfnptr with + | none => holReturn Structures_A.default_notification + | some p => KHeap_A.get_simple_ko Structures_A.kernel_object.Notification p : + HolNonDet (Structures_A.state ZH) Structures_A.notification) s3).1 → + ¬(ntfnptr ≠ none ∧ Ipc_A.isActive ntfn = true) → + ∀ s5, ((), s5) ∈ (holWhen (holConj (holNot (holEq ntfnptr none)) isBlocking) + (SchedContext_A.maybe_return_sc (holTheOpt ntfnptr) thread) s4).1 → + match ep with + | .SendEP (sender :: _) => + ∀ s6, ((), s6) ∈ (IpcCancel_A.tcb_ep_dequeue sender epptr s5).1 → + ∀ ptr data s7, (.BlockedOnSend ptr data, s7) ∈ (KHeap_A.get_thread_state sender s6).1 → + DoIpcTransferSafe sender (some epptr) data.sender_can_grant thread s7 + | _ => True) → + MRelStep SR Eq + ((holBind (KHeap_A.get_simple_ko Structures_A.kernel_object.Endpoint epptr) fun ep => + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_bound_notification thread) fun ntfnptr => + holBind (match ntfnptr with | none => holReturn Structures_A.default_notification | some p => KHeap_A.get_simple_ko Structures_A.kernel_object.Notification p) fun ntfn => + if ntfnptr ≠ none ∧ Ipc_A.isActive ntfn = true then + Ipc_A.complete_signal (holTheOpt ntfnptr) thread + else + holBind (holWhen (holConj (holNot (holEq ntfnptr none)) isBlocking) + (SchedContext_A.maybe_return_sc (holTheOpt ntfnptr) thread)) (holKBind + (match ep with + | .SendEP q => + holBind (holAssert (holNot (holEq q []))) (holKBind + (holBind (holReturn (holHd q)) fun sender => + holBind (IpcCancel_A.tcb_ep_dequeue sender epptr) (holKBind + (holBind (KHeap_A.get_thread_state sender) fun sender_state => + holBind (match sender_state with | .BlockedOnSend _ data => holReturn data | _ => holFail) fun data => + holBind (do_ipc_transfer_p sender (some epptr) data.sender_badge data.sender_can_grant thread) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context sender) fun sc_ptr => + holBind (Sporadic_A.if_cond_refill_unblock_check sc_ptr (some false) (some true)) (holKBind + (holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault sender) fun fault => + if data.sender_is_call = true ∨ fault ≠ none then + if (data.sender_can_grant = true ∨ data.sender_can_grant_reply = true) ∧ repH ≠ none then + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context sender) fun sender_sc => + holBind (holReturn (decide (sender_sc ≠ none ∧ ¬(fault.elim false Ipc_A.is_timeout_fault = true)))) fun donate => + IpcCancel_A.reply_push sender thread (holTheOpt repH) donate + else KHeap_A.set_thread_state sender .Inactive + else + holBind (KHeap_A.set_thread_state sender .Running) (holKBind + (KHeap_A.possible_switch_to sender)))))))))) + | _ => Ipc_A.receive_ipc_blocked isBlocking thread epptr repH))) s1H) + ((do + let ep ← Fl4Spec.getEndpoint epptr + let ntfnptr ← Fl4Spec.getTcbObjRef Tcb.tcbBoundNotification thread + let ntfn ← match ntfnptr with + | none => pure Fl4Spec.defaultNotification + | some p => Fl4Spec.getNotification p + if ntfnptr ≠ none ∧ Fl4Spec.isActive ntfn then + Fl4Spec.completeSignal (the ntfnptr) thread + else do + NonDet.when (ntfnptr ≠ none ∧ isBlocking) (Fl4Spec.maybeReturnSc (the ntfnptr) thread) + match ep with + | .sendEP q => do + NonDet.assert (q ≠ []) + let sender ← pure (the q.head?) + Fl4Spec.tcbEpDequeue sender epptr + let senderState ← Fl4Spec.getThreadState sender + let data ← match senderState with | .blockedOnSend _ data => pure data | _ => NonDet.fail + Fl4Spec.doIpcTransfer sender (some epptr) data.senderBadge data.senderCanGrant thread + let scPtr ← Fl4Spec.getTcbObjRef Tcb.tcbSchedContext sender + Fl4Spec.ifSporadicCurScAssertRefillUnblockCheck scPtr + let fault ← Fl4Spec.threadGet Tcb.tcbFault sender + if data.senderIsCall ∨ fault ≠ none then + if (data.senderCanGrant ∨ data.senderCanGrantReply) ∧ repL ≠ none then do + let senderSc ← Fl4Spec.getTcbObjRef Tcb.tcbSchedContext sender + let donate ← pure (decide (senderSc ≠ none ∧ ¬(fault.elim false Fl4Spec.isTimeoutFault = true))) + Fl4Spec.replyPush sender thread (the repL) donate + else Fl4Spec.setThreadState sender .inactive + else do + Fl4Spec.setThreadState sender .running + Fl4Spec.possibleSwitchTo sender + | _ => Fl4Spec.receiveIpcBlocked isBlocking thread epptr repL) s1L) := by + intro repH repL hrep s1H s1L hs1 hsafe1; subst hrep + refine mrelStep_bind_mem (getEndpoint_equiv epptr s1H s1L hs1) fun epH epL hep s2H s2L hs2 hm2 => ?_; subst hep + refine mrelStep_bind_mem (getTcbObjRef_equiv (fun _ => rfl) thread s2H s2L hs2) fun npH npL hnp s3H s3L hs3 hm3 => ?_; subst hnp + have hcontNtfn : ∀ nH nL, FunRel embNotification nH nL → ∀ s4H s4L, SR s4H s4L → + (nH, s4H) ∈ ((match npH with + | none => holReturn Structures_A.default_notification + | some p => KHeap_A.get_simple_ko Structures_A.kernel_object.Notification p) s3H).1 → + MRelStep SR Eq + ((if npH ≠ none ∧ Ipc_A.isActive nH = true then + Ipc_A.complete_signal (holTheOpt npH) thread + else + holBind (holWhen (holConj (holNot (holEq npH none)) isBlocking) + (SchedContext_A.maybe_return_sc (holTheOpt npH) thread)) (holKBind + (match epH with + | .SendEP q => + holBind (holAssert (holNot (holEq q []))) (holKBind + (holBind (holReturn (holHd q)) fun sender => + holBind (IpcCancel_A.tcb_ep_dequeue sender epptr) (holKBind + (holBind (KHeap_A.get_thread_state sender) fun sender_state => + holBind (match sender_state with | .BlockedOnSend _ data => holReturn data | _ => holFail) fun data => + holBind (do_ipc_transfer_p sender (some epptr) data.sender_badge data.sender_can_grant thread) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context sender) fun sc_ptr => + holBind (Sporadic_A.if_cond_refill_unblock_check sc_ptr (some false) (some true)) (holKBind + (holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault sender) fun fault => + if data.sender_is_call = true ∨ fault ≠ none then + if (data.sender_can_grant = true ∨ data.sender_can_grant_reply = true) ∧ repH ≠ none then + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context sender) fun sender_sc => + holBind (holReturn (decide (sender_sc ≠ none ∧ ¬(fault.elim false Ipc_A.is_timeout_fault = true)))) fun donate => + IpcCancel_A.reply_push sender thread (holTheOpt repH) donate + else KHeap_A.set_thread_state sender .Inactive + else + holBind (KHeap_A.set_thread_state sender .Running) (holKBind + (KHeap_A.possible_switch_to sender)))))))))) + | _ => Ipc_A.receive_ipc_blocked isBlocking thread epptr repH))) s4H) + ((if npH ≠ none ∧ Fl4Spec.isActive nL then + Fl4Spec.completeSignal (the npH) thread + else do + NonDet.when (npH ≠ none ∧ isBlocking) (Fl4Spec.maybeReturnSc (the npH) thread) + match embEndpoint epH with + | .sendEP q => do + NonDet.assert (q ≠ []) + let sender ← pure (the q.head?) + Fl4Spec.tcbEpDequeue sender epptr + let senderState ← Fl4Spec.getThreadState sender + let data ← match senderState with | .blockedOnSend _ data => pure data | _ => NonDet.fail + Fl4Spec.doIpcTransfer sender (some epptr) data.senderBadge data.senderCanGrant thread + let scPtr ← Fl4Spec.getTcbObjRef Tcb.tcbSchedContext sender + Fl4Spec.ifSporadicCurScAssertRefillUnblockCheck scPtr + let fault ← Fl4Spec.threadGet Tcb.tcbFault sender + if data.senderIsCall ∨ fault ≠ none then + if (data.senderCanGrant ∨ data.senderCanGrantReply) ∧ repH ≠ none then do + let senderSc ← Fl4Spec.getTcbObjRef Tcb.tcbSchedContext sender + let donate ← pure (decide (senderSc ≠ none ∧ ¬(fault.elim false Fl4Spec.isTimeoutFault = true))) + Fl4Spec.replyPush sender thread (the repH) donate + else Fl4Spec.setThreadState sender .inactive + else do + Fl4Spec.setThreadState sender .running + Fl4Spec.possibleSwitchTo sender + | _ => Fl4Spec.receiveIpcBlocked isBlocking thread epptr repH) s4L) := by + intro nH nL hn s4H s4L hs4 hm4; subst hn + rw [isActive_eq nH] + by_cases hact : npH ≠ none ∧ Ipc_A.isActive nH = true + · simp only [hact] + cases npH with + | none => exact absurd rfl hact.1 + | some p => exact completeSignal_equiv hop p thread s4H s4L hs4 + · simp only [hact, ↓reduceIte] + refine mrelStep_bind_mem (mrel_when (by simp [holConj_eq_true, holNot_eq_true, holEq_eq_true]) + (fun h => by + cases npH with + | none => simp at h + | some p => exact maybeReturnSc_equiv hop p thread) s4H s4L hs4) + fun u5 _ _ s5H s5L hs5 hm5 => ?_ + cases u5 + cases epH with + | IdleEP => exact receiveIpcBlocked_equiv isBlocking thread epptr repH s5H s5L hs5 + | RecvEP _ => exact receiveIpcBlocked_equiv isBlocking thread epptr repH s5H s5L hs5 + | SendEP q => + cases q with + | nil => + simp only [embEndpoint, holNot, holEq, decide_true, Bool.not_true, + holAssert_false, ne_eq, not_true_eq_false, assert_false] + exact mrel_bind_fail (αH := Unit) (αL := Unit) (RestRel := RestRel) (ZH := ZH) (ZL := ZL) s5H s5L hs5 + | cons sender rest => + simp only [embEndpoint, holHd, List.head?, the] + refine mrelStep_bind_mem (mrel_assert (by simp [holNot_eq_true, holEq_eq_true]) s5H s5L hs5) + fun u5a _ _ s5aH s5aL hs5a hm5a => ?_ + have hs5aeq : s5aH = s5H := by + simp only [holAssert, holNot, holEq, List.cons_ne_nil, decide_false, Bool.not_false, + Set.mem_ofPred_eq, Prod.mk.injEq] at hm5a + exact hm5a.2.2 + subst s5aH + refine mrelStep_bind_mem (mrel_return (Ra := Eq) rfl s5H s5aL hs5a) + fun sH' sL' hs' s5bH s5bL hs5b hm5b => ?_; subst hs' + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm5b + obtain ⟨hseq, hs5beq⟩ := hm5b; subst sH'; subst s5bH + refine mrelStep_bind_mem (tcbEpDequeue_equiv sender epptr s5H s5bL hs5b) + fun u6 _ _ s6H s6L hs6 hm6 => ?_; cases u6 + refine mrelStep_bind_mem (getThreadState_equiv sender s6H s6L hs6) + fun ssH ssL hss s7H s7L hs7 hm7 => ?_; subst hss + cases ssH with + | BlockedOnSend ptr data => + simp only [embThreadState] + refine mrelStep_bind_mem (mrel_return (Ra := FunRel embSenderPayload) rfl s7H s7L hs7) + fun dH dL hd s7aH s7aL hs7a hm7a => ?_; subst hd + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm7a + obtain ⟨hdeq, hs7aeq⟩ := hm7a; subst dH; subst s7aH + have hdit := hsafe1 (.SendEP (sender :: rest)) s2H hm2 npH s3H hm3 nH s4H hm4 hact s5H hm5 + s6H hm6 ptr data s7H hm7 + refine mrelStep_bind_mem (patched_doIpcTransfer_equiv hop sender (some epptr) data.sender_badge data.sender_can_grant thread hs7a hdit) + fun _ _ _ s8H s8L hs8 _ => ?_ + refine mrelStep_bind_mem (getTcbObjRef_equiv (fun _ => rfl) sender s8H s8L hs8) fun spH spL hsp s9H s9L hs9 _ => ?_; subst hsp + refine mrelStep_bind_mem (ifSporadicCurScAssertRefillUnblockCheck_equiv spH s9H s9L hs9) fun _ _ _ s10H s10L hs10 _ => ?_ + refine mrelStep_bind_mem (threadGet_equiv (Ra := OptRel (FunRel embFault)) + (fun t => by cases hf' : t.tcb_fault <;> simp [OptRel, embTcb, hf']) sender s10H s10L hs10) + fun fH fL hf s11H s11L hs11 _ => ?_ + have hfNone : fH ≠ none ↔ fL ≠ none := by cases fH <;> cases fL <;> simp [OptRel] at hf ⊢ + have hto : fH.elim false Ipc_A.is_timeout_fault = fL.elim false Fl4Spec.isTimeoutFault := by + cases fH <;> cases fL <;> simp only [OptRel, FunRel] at hf + · rfl + · subst hf; exact (isTimeoutFault_eq _).symm + by_cases hcf : data.sender_is_call = true ∨ fH ≠ none + · have hcfL : data.sender_is_call = true ∨ fL ≠ none := by rwa [← hfNone] + simp only [embSenderPayload, hcf, hcfL, ↓reduceIte] + by_cases hgr : (data.sender_can_grant = true ∨ data.sender_can_grant_reply = true) ∧ repH ≠ none + · simp only [hgr, true_and, ne_eq, not_false_eq_true, ↓reduceIte] + refine mrelStep_bind_mem (getTcbObjRef_equiv (fun _ => rfl) sender s11H s11L hs11) fun sscH sscL hssc s12H s12L hs12 _ => ?_; subst hssc + refine mrelStep_bind_mem (mrel_return (Ra := Eq) (by rw [hto]) s12H s12L hs12) fun dnH dnL hdn s13H s13L hs13 _ => ?_; subst hdn + cases repH with + | none => exact absurd rfl hgr.2 + | some r => exact replyPush_equiv hop sender thread r dnH s13H s13L hs13 + · simp only [hgr, ↓reduceIte]; exact setThreadState_equiv sender .Inactive s11H s11L hs11 + · have hcfL : ¬(data.sender_is_call = true ∨ fL ≠ none) := by rwa [← hfNone] + simp only [embSenderPayload, hcf, hcfL, ↓reduceIte] + exact (mrel_kbind (setThreadState_equiv sender .Running) (possibleSwitchTo_equiv hop sender)) s11H s11L hs11 + | _ => + simp only [embThreadState] + exact mrel_bind_fail (αH := Structures_A.sender_payload) (αL := SenderPayload) + (RestRel := RestRel) (ZH := ZH) (ZL := ZL) s7H s7L hs7 + cases npH with + | none => + exact mrelStep_bind_mem (mrel_return (Ra := FunRel embNotification) rfl s3H s3L hs3) + fun nH nL hn s4H s4L hs4 hm4 => hcontNtfn nH nL hn s4H s4L hs4 hm4 + | some p => + exact mrelStep_bind_mem (getNotification_equiv p s3H s3L hs3) + fun nH nL hn s4H s4L hs4 hm4 => hcontNtfn nH nL hn s4H s4L hs4 hm4 + cases replyCap with + | NullCap => + exact mrelStep_bind_mem (mrel_return (Ra := Eq) rfl sH s0L hs0) + fun rH rL hr s1H s1L hs1 hm1 => hcontRep rH rL hr s1H s1L hs1 (hsafe rH s1H hm1) + | ReplyCap r b => + simp only [] + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (getReplyTcb_equiv r sH s0L hs0) fun tpH tpL htp sA1H sA1L hsA1 hmA1 => ?_; subst htp + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (mrel_when + (by cases tpH <;> simp [holConj_eq_true, holNot_eq_true, holEq_eq_true, holTheOpt, the]) + (fun h => by + cases tpH with + | none => simp at h + | some t => + simp only [holTheOpt, the] + exact cancelIpc_equiv t) sA1H sA1L hsA1) + fun uA2 _ _ sA2H sA2L hsA2 hmA2 => ?_ + cases uA2 + dsimp only [holKBind] + refine mrelStep_bind_mem (mrel_return (Ra := Eq) rfl sA2H sA2L hsA2) fun rH rL hr s1H s1L hs1 hm1 => ?_ + have hrepMem : (rH, s1H) ∈ ((holBind (holLiftM Structures_A.reply_ext.reply_tcb + (KHeap_A.get_simple_ko Structures_A.kernel_object.Reply r)) fun tptr => + holBind (holWhen (holConj (holNot (holEq tptr none)) (holNot (holEq (holTheOpt tptr) thread))) + (IpcCancel_A.cancel_ipc (holTheOpt tptr))) (holKBind (holReturn (some r)))) sH).1 := by + simp only [holBind, holKBind, Set.mem_ofPred_eq] + exact ⟨(tpH, sA1H), hmA1, ((), sA2H), hmA2, hm1⟩ + exact hcontRep rH rL hr s1H s1L hs1 (hsafe rH s1H hrepMem) + | _ => + simp only [] + exact mrel_bind_fail (αH := Option ObjRef) (αL := Option ObjRef) (RestRel := RestRel) (ZH := ZH) (ZL := ZL) sH s0L hs0 + | _ => + simp only [embCap] + exact mrel_bind_fail (αH := ObjRef × Set CapRights_A.rights) (αL := ObjRef × CapRights) + (RestRel := RestRel) (ZH := ZH) (ZL := ZL) sH sL hs + + +private theorem holAssert_mem {σ : Type} {b : Bool} {s s1 : σ} {u : Unit} + (h : (u, s1) ∈ (holAssert b s).1) : b = true ∧ s1 = s := by + simp only [holAssert, Set.mem_ofPred_eq, Prod.mk.injEq] at h + exact ⟨h.1, h.2.2⟩ + +private theorem getObject_mem {ptr : ObjRef} {ko : Structures_A.kernel_object} + {s s1 : Structures_A.state ZH} + (hm : (ko, s1) ∈ (KHeap_A.get_object ptr s).1) : + s1 = s ∧ s.kheap ptr = some ko := + (getObject_member hm).symm + +private theorem setObject_mem {ptr : ObjRef} {obj : Structures_A.kernel_object} + {s s1 : Structures_A.state ZH} + (hm : ((), s1) ∈ (KHeap_A.set_object ptr obj s).1) : + s1 = Structures_A.abstract_state.kheap_update (fun _ => holFunUpd s.kheap ptr (some obj)) s := by + unfold KHeap_A.set_object at hm + simp only [holBind, holKBind, holGet, holPut, Set.mem_ofPred_eq, Set.mem_singleton_iff, Prod.mk.injEq] at hm + rcases hm with ⟨⟨kobj, s0⟩, h0, ⟨_, sa⟩, ha, ⟨st, sb⟩, ⟨rfl, rfl⟩, _, hs1⟩ + have hs0 : s0 = s := (getObject_mem h0).1; subst s0 + have hsa : sa = s := (holAssert_mem ha).2; subst sa + exact hs1 + +private theorem getSimpleKo_ep_mem {epptr : ObjRef} {ep : Structures_A.endpoint} + {s s1 : Structures_A.state ZH} + (hm : (ep, s1) ∈ (KHeap_A.get_simple_ko Structures_A.kernel_object.Endpoint epptr s).1) : + s1 = s ∧ s.kheap epptr = some (.Endpoint ep) := by + unfold KHeap_A.get_simple_ko at hm + simp only [holBind, holKBind, Set.mem_ofPred_eq] at hm + rcases hm with ⟨⟨ko, s0⟩, h0, ⟨_, sa⟩, ha, h1⟩ + have ⟨hs0, hkh⟩ := getObject_mem h0; subst s0 + have hsa : sa = s := (holAssert_mem ha).2; subst sa + dsimp only at h1 + cases hko : ko with + | Endpoint ep' => + have hpinv : Lib.partial_inv Structures_A.kernel_object.Endpoint (.Endpoint ep') = some ep' := by + unfold Lib.partial_inv + have hex1' : ∃! y, holEq (Structures_A.kernel_object.Endpoint y) (.Endpoint ep') = true := + ⟨ep', by simp [holEq], fun y hy => by simp only [holEq, decide_eq_true_eq] at hy; injection hy⟩ + have hex1 : holEx1 (fun y => holEq (Structures_A.kernel_object.Endpoint y) (.Endpoint ep')) = true := by + simp [holEx1, holEq] + have hthe : holThe (fun y => holEq (Structures_A.kernel_object.Endpoint y) (.Endpoint ep')) = ep' := by + unfold holThe + rw [dite_eq_left hex1'] + exact ((Classical.choose_spec hex1').2 ep' (by simp [holEq])).symm + simp [hex1, hthe, holIf_true] + rw [hko, hpinv] at h1 + simp only [holCaseOption, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at h1 + exact ⟨h1.2, by rw [hkh, hko, h1.1]⟩ + | _ => + have hpinv : Lib.partial_inv Structures_A.kernel_object.Endpoint ko = none := by + unfold Lib.partial_inv + have hex1 : holEx1 (fun y => holEq (Structures_A.kernel_object.Endpoint y) ko) = false := by + simp only [holEx1, decide_eq_false_iff_not] + rintro ⟨y, hy, _⟩; subst hko; simp [holEq] at hy + simp [hex1, holIf_false] + rw [hpinv] at h1 + simp [holCaseOption, holFail] at h1 + +private theorem tcbEpDequeue_kheap_ne {dest epptr q : ObjRef} {s s1 : Structures_A.state ZH} + (hm : ((), s1) ∈ (IpcCancel_A.tcb_ep_dequeue dest epptr s).1) (hne : q ≠ epptr) : + s1.kheap q = s.kheap q := by + unfold IpcCancel_A.tcb_ep_dequeue at hm + simp only [holBind, holKBind, holFunApp, holReturn, Set.mem_ofPred_eq, Set.mem_singleton_iff] at hm + rcases hm with ⟨⟨ep, s0⟩, h0, ⟨_, sa⟩, ⟨rfl, rfl⟩, ⟨_, sb⟩, hassert, ⟨_, sc⟩, ⟨rfl, rfl⟩, ⟨ep', sd⟩, ⟨rfl, rfl⟩, hset⟩ + have hs0 := (getSimpleKo_ep_mem h0).1; subst s0 + have hsb : sb = s := (holAssert_mem hassert).2; subst sb + unfold KHeap_A.set_simple_ko at hset + simp only [holBind, holKBind, Set.mem_ofPred_eq] at hset + rcases hset with ⟨⟨obj, se⟩, hget, ⟨_, sf⟩, ha1, ⟨_, sg⟩, ha2, hso⟩ + have hse : se = s := (getObject_mem hget).1; subst se + have hsf : sf = s := (holAssert_mem ha1).2; subst sf + have hsg : sg = s := (holAssert_mem ha2).2; subst sg + rw [setObject_mem hso] + simp [Structures_A.abstract_state.kheap_update, holFunUpd, hne] + +private theorem threadGet_mem {α : Type} [Nonempty α] (f : Structures_A.tcb_ext Unit → α) + {t : ObjRef} {v : α} {s s1 : Structures_A.state ZH} + (hm : (v, s1) ∈ (KHeap_A.thread_get f t s).1) : + s1 = s ∧ ∃ tcb, s.kheap t = some (.TCB tcb) ∧ f tcb = v := by + unfold KHeap_A.thread_get KHeap_A.get_tcb KHeap_A.read_object at hm + simp only [holBind, holFunApp, holGetsThe, holSwp, holReturn, Set.mem_ofPred_eq, Set.mem_singleton_iff, Prod.mk.injEq] at hm + rcases hm with ⟨⟨tcb, s0⟩, h0, hv, hs1⟩ + subst s1 + cases hkh : s.kheap t with + | none => simp [hkh, holCaseOption, holAssertOpt, holFail] at h0 + | some ko => + cases ko with + | TCB tcb' => + simp only [hkh, holCaseOption, Structures_A.case_kernel_object, holAssertOpt, holReturn, + Set.mem_singleton_iff, Prod.mk.injEq] at h0 + rcases h0 with ⟨rfl, rfl⟩ + exact ⟨rfl, tcb, rfl, hv.symm⟩ + | _ => + simp [hkh, holCaseOption, Structures_A.case_kernel_object, holAssertOpt, holFail] at h0 + +private theorem lookupIpcBuffer_state_eq {isRcv : Bool} {t : ObjRef} {rbuf : Option ObjRef} + {s s1 : Structures_A.state ZH} + (hm : (rbuf, s1) ∈ (Patched.lookupIpcBuffer isRcv t s).1) : s1 = s := by + unfold Patched.lookupIpcBuffer Patched.lookupIpcBufferAt at hm + simp only [holBind, holReturn, Set.mem_ofPred_eq, Set.mem_singleton_iff] at hm + rcases hm with ⟨⟨bp, sa⟩, ha, ⟨sl, sb⟩, hsb, ⟨cap, sc⟩, hc, hret⟩ + have hsa := (threadGet_mem _ ha).1 + subst sa + obtain ⟨rfl, rfl⟩ := Prod.mk.inj hsb + have hs := getCap_state_eq hc + subst sc + exact (Prod.mk.inj hret).2 + +private theorem sendIpcSafe_of_fault {tptr epptr : ObjRef} {f : ExceptionTypes_A.fault} + {s : Structures_A.state ZH} + (hfault : ∃ tcb, s.kheap tptr = some (.TCB tcb) ∧ tcb.tcb_fault = some f) : + ∀ canGrant, SendIpcSafe canGrant tptr epptr s := by + rcases hfault with ⟨tcb, htcb, htf⟩ + intro canGrant _ dest rest s1 hm1 s2 hm2 b rep d s3 hm3 _ rbuf s4 hm4 s5 hm5 + have ⟨hs1, hep⟩ := getSimpleKo_ep_mem hm1; subst s1 + have hne : tptr ≠ epptr := by intro h; subst h; rw [htcb] at hep; cases hep + have hk2 : s2.kheap tptr = some (.TCB tcb) := by rw [tcbEpDequeue_kheap_ne hm2 hne, htcb] + have hs3 : s3 = s2 := (threadGet_mem _ hm3).1; subst s3 + have hs4 : s4 = s2 := lookupIpcBuffer_state_eq hm4; subst s4 + have ⟨_, tcb', htcb', hnone⟩ := threadGet_mem _ hm5 + rw [hk2] at htcb'; injection htcb' with h1; injection h1 with h2; subst h2 + rw [htf] at hnone; cases hnone + +def send_fault_ipc_p (tptr : ObjRef) (handler_cap : Structures_A.cap) + (fault : ExceptionTypes_A.fault) (can_donate : Bool) : + HolNonDet (Structures_A.state ZH) Bool := + match handler_cap with + | .EndpointCap _ref _badge rights => + holBind (KHeap_A.thread_set (fun tcb => Structures_A.tcb.tcb_fault_update (fun _ => some fault) tcb) tptr) (holKBind + (holBind (send_ipc_p true false (Structures_A.cap_ep_badge handler_cap) + (holMember .AllowGrant rights) (holMember .AllowGrantReply rights) can_donate tptr + (Structures_A.cap_ep_ptr handler_cap)) (holKBind (holReturn true)))) + | .NullCap => holReturn false + | _ => holFail + +theorem patched_sendFaultIpc_equiv (hop : OpaqueRel RestRel) + (tptr : ObjRef) (handlerCap : Structures_A.cap) + (fault : ExceptionTypes_A.fault) (canDonate : Bool) : + MRel SR Eq + (send_fault_ipc_p tptr handlerCap fault canDonate) + (Fl4Spec.sendFaultIpc tptr (embCap handlerCap) (embFault fault) canDonate) := by + intro sH sL hs + cases handlerCap with + | NullCap => exact mrel_return rfl sH sL hs + | EndpointCap ref badge rights => + unfold send_fault_ipc_p Fl4Spec.sendFaultIpc + simp only [embCap, Structures_A.cap_ep_badge, Structures_A.cap_ep_ptr, + Fl4Spec.capEpBadge, Fl4Spec.capEpPtr] + refine mrelStep_bind_mem (threadSet_equiv (fun t => by simp [embTcb, Structures_A.tcb.tcb_fault_update]) tptr sH sL hs) + fun u1 _ _ s1H s1L hs1 hm1 => ?_ + cases u1 + have hfault : ∃ tcb, s1H.kheap tptr = some (.TCB tcb) ∧ tcb.tcb_fault = some fault := by + unfold KHeap_A.thread_set at hm1 + simp only [holBind, holFunApp, Set.mem_ofPred_eq] at hm1 + rcases hm1 with ⟨⟨tcb, s0⟩, _, hso⟩ + rw [setObject_mem hso] + exact ⟨Structures_A.tcb.tcb_fault_update (fun _ => some fault) tcb, + by simp [Structures_A.abstract_state.kheap_update, holFunUpd], + by simp [Structures_A.tcb.tcb_fault_update]⟩ + have hG : holMember CapRights_A.rights.AllowGrant rights = decide (Rights.allowGrant ∈ embRightsSet rights) := by + apply Bool.eq_iff_iff.mpr + rw [holMember_eq_true, decide_eq_true_eq] + exact (embRightsSet_mem .AllowGrant rights).symm + have hGR : holMember CapRights_A.rights.AllowGrantReply rights = decide (Rights.allowGrantReply ∈ embRightsSet rights) := by + apply Bool.eq_iff_iff.mpr + rw [holMember_eq_true, decide_eq_true_eq] + exact (embRightsSet_mem .AllowGrantReply rights).symm + rw [hG, hGR] + refine mrelStep_bind_mem (patched_sendIpc_equiv hop true false badge _ _ canDonate tptr ref hs1 + (sendIpcSafe_of_fault hfault _)) + fun _ _ _ s2H s2L hs2 _ => mrel_return rfl s2H s2L hs2 + | _ => exact mrel_fail sH sL hs + +def handle_timeout_p (tptr : ObjRef) (ex : ExceptionTypes_A.fault) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (Ipc_A.is_valid_timeout_handler tptr) fun valid => + holBind (holAssert valid) (holKBind + (holBind (holReturn (Tcb_A.get_tcb_timeout_handler_ptr tptr)) fun slot => + holBind (CSpaceAcc_A.get_cap slot) fun cap => + holBind (send_fault_ipc_p tptr cap ex false) (holKBind (holReturn ())))) + +theorem patched_handleTimeout_equiv (hop : OpaqueRel RestRel) + (tptr : ObjRef) (ex : ExceptionTypes_A.fault) : + MRel SR Eq + (handle_timeout_p tptr ex) (Fl4Spec.handleTimeout tptr (embFault ex)) := by + unfold handle_timeout_p Fl4Spec.handleTimeout + refine mrel_bind (isValidTimeoutHandler_equiv tptr) fun vH vL hv => ?_; subst hv + refine mrel_kbind (mrel_assert (by simp)) ?_ + refine mrel_bind (mrel_return (Ra := fun x y => x = Tcb_A.get_tcb_timeout_handler_ptr tptr ∧ y = x) + ⟨rfl, rfl⟩) fun slH slL ⟨h1, h2⟩ => ?_; subst h1; subst h2 + have hnonExt : NonExtTcbSlot (Tcb_A.get_tcb_timeout_handler_ptr tptr).2 := by + change Fl4Spec.tcbCnodeIndex 4 ≠ Fl4Spec.tcbCnodeIndex 5 + decide + refine mrel_bind (getCap_equiv_nonExt _ hnonExt) fun cH cL hc => ?_; subst hc + exact mrel_kbind (patched_sendFaultIpc_equiv hop tptr cH ex false) (mrel_return rfl) + +def handle_fault_p (thread : ObjRef) (ex : ExceptionTypes_A.fault) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (holReturn (Tcb_A.get_tcb_fault_handler_ptr thread)) fun slot => + holBind (CSpaceAcc_A.get_cap slot) fun cap => + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_sched_context thread) fun sc_opt => + holBind (send_fault_ipc_p thread cap ex (holNot (holEq sc_opt none))) fun has_fh => + holBind (holUnless has_fh (Ipc_A.handle_no_fault thread)) (holKBind (holReturn ())) + +theorem patched_handleFault_equiv (hop : OpaqueRel RestRel) + (thread : ObjRef) (ex : ExceptionTypes_A.fault) : + MRel SR Eq + (handle_fault_p thread ex) (Fl4Spec.handleFault thread (embFault ex)) := by + unfold handle_fault_p Fl4Spec.handleFault + refine mrel_bind (mrel_return (Ra := fun x y => x = Tcb_A.get_tcb_fault_handler_ptr thread ∧ y = x) + ⟨rfl, rfl⟩) fun slH slL ⟨h1, h2⟩ => ?_; subst h1; subst h2 + have hnonExt : NonExtTcbSlot (Tcb_A.get_tcb_fault_handler_ptr thread).2 := by + change Fl4Spec.tcbCnodeIndex 3 ≠ Fl4Spec.tcbCnodeIndex 5 + decide + refine mrel_bind (getCap_equiv_nonExt _ hnonExt) fun cH cL hc => ?_; subst hc + refine mrel_bind (threadGet_equiv (fun _ => rfl) thread) fun soH soL hso => ?_; subst hso + have hdon : holNot (holEq soH none) = decide (soH ≠ none) := by cases soH <;> simp [holNot, holEq] + rw [hdon] + refine mrel_bind (patched_sendFaultIpc_equiv hop thread cH ex _) fun fhH fhL hfh => ?_; subst hfh + exact mrel_kbind (mrel_unless (by simp) fun _ => setThreadState_equiv thread .Inactive) (mrel_return rfl) + + +/-- l4v: Ipc_A.do_reply_transfer with patched IPC buffer and timeout delivery. -/ +def do_reply_transfer_p (sender reply : ObjRef) (grant : Bool) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (holLiftM Structures_A.reply_ext.reply_tcb (KHeap_A.get_simple_ko Structures_A.kernel_object.Reply reply)) fun recv_opt => + holMaybeM (fun receiver => + holBind (KHeap_A.get_thread_state receiver) fun state => + match state with + | .BlockedOnReply r => + holBind (holAssert (holEq r reply)) (holKBind + (holBind (IpcCancel_A.reply_remove receiver reply) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context receiver) fun sc_opt => + holBind (Sporadic_A.if_cond_refill_unblock_check sc_opt (some false) (some false)) (holKBind + (holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault receiver) fun fault => + holBind (match fault with + | none => + holBind (do_ipc_transfer_p sender none 0 grant receiver) (holKBind + (KHeap_A.set_thread_state receiver .Running)) + | some f => + holBind (Ipc_A.get_message_info sender) fun mi => + holBind (Patched.lookupIpcBuffer false sender) fun buf => + holBind (Tcb_A.get_mrs sender buf mi) fun mrs => + holBind (Ipc_A.handle_fault_reply f receiver mi.mi_label mrs) fun restart => + holBind (KHeap_A.thread_set (fun tcb => Structures_A.tcb.tcb_fault_update (fun _ => none) tcb) receiver) (holKBind + (KHeap_A.set_thread_state receiver (if restart then .Restart else .Inactive)))) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context receiver) fun sc_opt1 => + holBind (KHeap_A.get_thread_state receiver) fun state1 => + holWhen (holConj (holNot (holEq sc_opt1 none)) (Structures_A.runnable state1)) + (holBind (holAssertOpt sc_opt1) fun sc_ptr => + holBind (KHeap_A.get_sched_context sc_ptr) fun sc => + holBind (holGets fun s => s.cur_time) fun curtime => + if KHeap_A.refill_ready' 0 curtime (holHd sc.sc_refills) = true ∧ + KHeap_A.refill_sufficient 0 (holHd sc.sc_refills) = true then + KHeap_A.possible_switch_to receiver + else + holBind (holGetsThe (KHeap_A.get_tcb receiver)) fun tcb => + if Structures_A.is_ep_cap tcb.tcb_timeout_handler = true ∧ + ¬(fault.elim false Ipc_A.is_timeout_fault = true) then + handle_timeout_p receiver (.Timeout sc.sc_badge) + else SchedContext_A.postpone sc_ptr))))))))) + | _ => holReturn ()) recv_opt + +/-- State-indexed, run-guarded safety predicate for `do_reply_transfer_p`. -/ +def DoReplyTransferSafe (sender reply : ObjRef) (grant : Bool) + (sH : Structures_A.state ZH) : Prop := + ∀ receiver s1, (some receiver, s1) ∈ (holLiftM Structures_A.reply_ext.reply_tcb + (KHeap_A.get_simple_ko Structures_A.kernel_object.Reply reply) sH).1 → + ∀ s2, (.BlockedOnReply reply, s2) ∈ (KHeap_A.get_thread_state receiver s1).1 → + ∀ s4, ((), s4) ∈ (IpcCancel_A.reply_remove receiver reply s2).1 → + ∀ scOpt s5, (scOpt, s5) ∈ (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context receiver s4).1 → + ∀ s6, ((), s6) ∈ (Sporadic_A.if_cond_refill_unblock_check scOpt (some false) (some false) s5).1 → + ∀ (fault : Option ExceptionTypes_A.fault) s7, + (fault, s7) ∈ (KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault receiver s6).1 → + (fault = none → DoIpcTransferSafe sender none grant receiver s7) ∧ + ∀ s8, ((), s8) ∈ ((match fault with + | none => + holBind (do_ipc_transfer_p sender none 0 grant receiver) (holKBind + (KHeap_A.set_thread_state receiver .Running)) + | some f => + holBind (Ipc_A.get_message_info sender) fun mi => + holBind (Patched.lookupIpcBuffer false sender) fun buf => + holBind (Tcb_A.get_mrs sender buf mi) fun mrs => + holBind (Ipc_A.handle_fault_reply f receiver mi.mi_label mrs) fun restart => + holBind (KHeap_A.thread_set (fun tcb => Structures_A.tcb.tcb_fault_update (fun _ => none) tcb) receiver) (holKBind + (KHeap_A.set_thread_state receiver (if restart then .Restart else .Inactive))) : + HolNonDet (Structures_A.state ZH) Unit) s7).1 → + ∀ scPtr s9, (some scPtr, s9) ∈ (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context receiver s8).1 → + ∀ st1 s10, (st1, s10) ∈ (KHeap_A.get_thread_state receiver s9).1 → + Structures_A.runnable st1 = true → + ∀ sc s11, (sc, s11) ∈ (KHeap_A.get_sched_context scPtr s10).1 → + sc.sc_refills ≠ [] + +/-- [P] Reached transfer states have admissible capability slots and reached scheduling contexts have a head refill. -/ +theorem patched_doReplyTransfer_equiv (hop : OpaqueRel RestRel) + (sender reply : ObjRef) (grant : Bool) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : DoReplyTransferSafe sender reply grant sH) : + MRelStep SR Eq + (do_reply_transfer_p sender reply grant sH) (Fl4Spec.doReplyTransfer sender reply grant sL) := by + unfold do_reply_transfer_p Fl4Spec.doReplyTransfer + refine mrelStep_bind_mem (getReplyTcb_equiv reply sH sL hs) fun roH roL hro s1H s1L hs1 hm1 => ?_; subst hro + cases roH with + | none => exact mrel_return rfl s1H s1L hs1 + | some receiver => + simp only [holMaybeM, NonDet.maybeM] + refine mrelStep_bind_mem (getThreadState_equiv receiver s1H s1L hs1) fun stH stL hst s2H s2L hs2 hm2 => ?_; subst hst + cases stH with + | BlockedOnReply r => + simp only [embThreadState] + refine mrelStep_bind_mem (mrel_assert (by simp [holEq_eq_true]) s2H s2L hs2) fun u3 _ _ s3H s3L hs3 hm3 => ?_ + have hreq : r = reply ∧ s3H = s2H := by + by_cases he : r = reply + · simp only [holAssert, holEq, he, decide_true, Set.mem_ofPred_eq, Prod.mk.injEq] at hm3 + exact ⟨he, hm3.2.2⟩ + · simp [holAssert, holEq, he] at hm3 + rcases hreq with ⟨rfl, rfl⟩ + refine mrelStep_bind_mem (replyRemove_equiv hop receiver r s3H s3L hs3) fun u4 _ _ s4H s4L hs4 hm4 => ?_; cases u4 + refine mrelStep_bind_mem (getTcbObjRef_equiv (fun _ => rfl) receiver s4H s4L hs4) fun soH soL hso s5H s5L hs5 hm5 => ?_; subst hso + refine mrelStep_bind_mem (ifSporadicCurScTestRefillUnblockCheck_equiv soH s5H s5L hs5) fun u6 _ _ s6H s6L hs6 hm6 => ?_; cases u6 + refine mrelStep_bind_mem (threadGet_equiv (Ra := OptRel (FunRel embFault)) + (fun t => by cases hf' : t.tcb_fault <;> simp [OptRel, embTcb, hf']) receiver s6H s6L hs6) fun fH fL hf s7H s7L hs7 hm7 => ?_ + obtain ⟨hditSafe, htailRefills⟩ := hsafe receiver s1H hm1 s3H hm2 s4H hm4 soH s5H hm5 s6H hm6 fH s7H hm7 + have htail : ∀ s8H s8L, SR s8H s8L → + (∀ scPtr s9, (some scPtr, s9) ∈ (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context receiver s8H).1 → + ∀ st1 s10, (st1, s10) ∈ (KHeap_A.get_thread_state receiver s9).1 → + Structures_A.runnable st1 = true → + ∀ sc s11, (sc, s11) ∈ (KHeap_A.get_sched_context scPtr s10).1 → + sc.sc_refills ≠ []) → + MRelStep SR Eq + ((holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context receiver) fun sc_opt1 => + holBind (KHeap_A.get_thread_state receiver) fun state1 => + holWhen (holConj (holNot (holEq sc_opt1 none)) (Structures_A.runnable state1)) + (holBind (holAssertOpt sc_opt1) fun sc_ptr => + holBind (KHeap_A.get_sched_context sc_ptr) fun sc => + holBind (holGets fun s => s.cur_time) fun curtime => + if KHeap_A.refill_ready' 0 curtime (holHd sc.sc_refills) = true ∧ + KHeap_A.refill_sufficient 0 (holHd sc.sc_refills) = true then + KHeap_A.possible_switch_to receiver + else + holBind (holGetsThe (KHeap_A.get_tcb receiver)) fun tcb => + if Structures_A.is_ep_cap tcb.tcb_timeout_handler = true ∧ + ¬(fH.elim false Ipc_A.is_timeout_fault = true) then + handle_timeout_p receiver (.Timeout sc.sc_badge) + else SchedContext_A.postpone sc_ptr)) s8H) + ((do + let scOpt1 ← Fl4Spec.getTcbObjRef Tcb.tcbSchedContext receiver + let state1 ← Fl4Spec.getThreadState receiver + NonDet.when (scOpt1 ≠ none ∧ Fl4Spec.runnable state1) do + let scPtr ← NonDet.assertOpt scOpt1 + let sc ← Fl4Spec.getSchedContext scPtr + let curtime ← NonDet.gets fun s : State ZL => s.curTime + if Fl4Spec.refillReady curtime (Fl4Spec.refillHd sc) ∧ + Fl4Spec.refillSufficient 0 (Fl4Spec.refillHd sc) then + Fl4Spec.possibleSwitchTo receiver + else do + let tcb ← NonDet.getsThe (Fl4Spec.getTcb receiver) + if Fl4Spec.isEpCap tcb.tcbTimeoutHandler ∧ + ¬(fL.elim false Fl4Spec.isTimeoutFault = true) then + Fl4Spec.handleTimeout receiver (.timeout sc.scBadge) + else Fl4Spec.postpone scPtr) s8L) := by + intro s8H s8L hs8 href8 + refine mrelStep_bind_mem (getTcbObjRef_equiv (fun _ => rfl) receiver s8H s8L hs8) fun so1H so1L hso1 s9H s9L hs9 hm9 => ?_; subst hso1 + refine mrelStep_bind_mem (getThreadState_equiv receiver s9H s9L hs9) fun st1H st1L hst1 s10H s10L hs10 hm10 => ?_; subst hst1 + by_cases hcondW : so1H ≠ none ∧ Structures_A.runnable st1H = true + · have hcondH : holConj (holNot (holEq so1H none)) (Structures_A.runnable st1H) = true := by + simp [holConj_eq_true, holNot_eq_true, holEq_eq_true, hcondW] + have hcondL : so1H ≠ none ∧ Fl4Spec.runnable (embThreadState st1H) = true := by + rw [runnable_eq]; exact hcondW + simp only [holWhen, NonDet.when, hcondH, ite_true, ite_eq_left hcondL] + obtain ⟨hneOpt, hrun1⟩ := hcondW + cases so1H with + | none => exact absurd rfl hneOpt + | some sp0 => + refine mrelStep_bind_mem (mrel_assertOpt (Ra := Eq) (by simp [OptRel]) s10H s10L hs10) + fun spH spL hsp s12H s12L hs12 hm12 => ?_; subst hsp + simp only [holAssertOpt, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm12 + obtain ⟨hspEq, hs12eq⟩ := hm12; subst spH; subst s12H + refine mrelStep_bind_mem (getSchedContext_equiv sp0 s10H s12L hs12) + fun scH scL hsc s13H s13L hs13 hm13 => ?_; subst hsc + have hne : scH.sc_refills ≠ [] := href8 sp0 s9H hm9 st1H s10H hm10 hrun1 scH s13H hm13 + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ hs => hs.curTime_eq.symm) s13H s13L hs13) + fun ctH ctL hct s14H s14L hs14 _ => ?_; subst hct + have hrhd : Fl4Spec.refillHd (embSchedContext scH) = embRefill (holHd scH.sc_refills) := by + cases hrf : scH.sc_refills with + | nil => exact absurd hrf hne + | cons r rs => + simp [Fl4Spec.refillHd, embSchedContext, hrf, holHd, the] + have hcond : (KHeap_A.refill_ready' 0 ctH (holHd scH.sc_refills) = true ∧ + KHeap_A.refill_sufficient 0 (holHd scH.sc_refills) = true) ↔ + (Fl4Spec.refillReady ctH (Fl4Spec.refillHd (embSchedContext scH)) = true ∧ + Fl4Spec.refillSufficient 0 (Fl4Spec.refillHd (embSchedContext scH)) = true) := by + rw [hrhd, Fl4Spec.refillReady, refillReady'_eq, refillSufficient_eq hop] + by_cases hrr : KHeap_A.refill_ready' 0 ctH (holHd scH.sc_refills) = true ∧ + KHeap_A.refill_sufficient 0 (holHd scH.sc_refills) = true + · have hrrL := hcond.mp hrr + simp only [hrr, hrrL] + exact possibleSwitchTo_equiv hop receiver s14H s14L hs14 + · have hrrL := mt hcond.mpr hrr + simp only [hrr, hrrL, ↓reduceIte] + refine mrelStep_bind_mem (mrel_getsThe (getTcb_equiv receiver) s14H s14L hs14) fun tH tL ht s15H s15L hs15 _ => ?_; subst ht + have hto : fH.elim false Ipc_A.is_timeout_fault = fL.elim false Fl4Spec.isTimeoutFault := by + cases fH <;> cases fL <;> simp only [OptRel, FunRel] at hf + · rfl + · subst hf; exact (isTimeoutFault_eq _).symm + have hth : Structures_A.is_ep_cap tH.tcb_timeout_handler = Fl4Spec.isEpCap (embTcb tH).tcbTimeoutHandler := + (isEpCap_eq tH.tcb_timeout_handler).symm + rw [hth, hto] + by_cases hthc : Fl4Spec.isEpCap (embTcb tH).tcbTimeoutHandler = true ∧ + ¬(fL.elim false Fl4Spec.isTimeoutFault = true) + · simp only [hthc] + exact patched_handleTimeout_equiv hop receiver (.Timeout scH.sc_badge) s15H s15L hs15 + · simp only [hthc, ↓reduceIte] + exact postpone_equiv sp0 s15H s15L hs15 + · have hcondH : holConj (holNot (holEq so1H none)) (Structures_A.runnable st1H) = false := + Bool.eq_false_iff.mpr (by simpa [holConj_eq_true, holNot_eq_true, holEq_eq_true] using hcondW) + have hcondL : ¬(so1H ≠ none ∧ Fl4Spec.runnable (embThreadState st1H) = true) := by + rw [runnable_eq]; exact hcondW + simp only [holWhen, NonDet.when, hcondH, Bool.false_eq_true, ite_false, ite_eq_right hcondL] + exact mrel_return rfl s10H s10L hs10 + cases fH with + | none => + cases fL with + | none => + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (patched_doIpcTransfer_equiv hop sender none 0 grant receiver hs7 (hditSafe rfl)) + fun u8 _ _ s8H s8L hs8 hm8 => ?_; cases u8 + refine mrelStep_bind_mem (setThreadState_equiv receiver .Running s8H s8L hs8) + fun u9 _ _ s9H s9L hs9 hm9 => ?_; cases u9 + exact htail s9H s9L hs9 (htailRefills s9H ⟨((), s8H), hm8, hm9⟩) + | some _ => simp [OptRel] at hf + | some fH' => + cases fL with + | none => simp [OptRel] at hf + | some fL' => + simp only [OptRel, FunRel] at hf + subst hf + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (getMessageInfo_equiv sender s7H s7L hs7) fun miH miL hmi s8H s8L hs8 hm8 => ?_; subst hmi + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (patched_lookupIpcBuffer_equiv false sender s8H s8L hs8) fun bH bL hb s9H s9L hs9 hm9 => ?_; subst hb + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (getMrs_equiv sender bH miH s9H s9L hs9) fun mH mL hm s10H s10L hs10 hm10 => ?_; subst hm + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (handleFaultReply_equiv fH' receiver miH.mi_label mH s10H s10L hs10) fun rH rL hr s11H s11L hs11 hm11 => ?_; subst hr + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (threadSet_equiv (fun t => by simp [embTcb, Structures_A.tcb.tcb_fault_update]) receiver s11H s11L hs11) + fun u12 _ _ s12H s12L hs12 hm12 => ?_; cases u12 + cases rH with + | true => + refine mrelStep_bind_mem (setThreadState_equiv receiver .Restart s12H s12L hs12) + fun u13 _ _ s13H s13L hs13 hm13 => ?_; cases u13 + exact htail s13H s13L hs13 (htailRefills s13H + ⟨(miH, s8H), hm8, (bH, s9H), hm9, (mH, s10H), hm10, (true, s11H), hm11, ((), s12H), hm12, hm13⟩) + | false => + refine mrelStep_bind_mem (setThreadState_equiv receiver .Inactive s12H s12L hs12) + fun u13 _ _ s13H s13L hs13 hm13 => ?_; cases u13 + exact htail s13H s13L hs13 (htailRefills s13H + ⟨(miH, s8H), hm8, (bH, s9H), hm9, (mH, s10H), hm10, (false, s11H), hm11, ((), s12H), hm12, hm13⟩) + | _ => exact mrel_return rfl s2H s2L hs2 + +/-- State-indexed, run-guarded safety predicate for `invoke_sched_control_configure_flags`. -/ +def InvokeSchedControlSafe (iv : Invocations_A.sched_control_invocation) + (sH : Structures_A.state ZH) : Prop := + match iv with + | .InvokeSchedControlConfigureFlags scPtr budget period _ _ _ => + ∀ sc s1, (sc, s1) ∈ (KHeap_A.get_sched_context scPtr sH).1 → + (sc.sc_tcb ≠ none → + ∀ tp s3, (tp, s3) ∈ (holAssertOpt sc.sc_tcb s1).1 → + ∀ s4, ((), s4) ∈ (KHeap_A.tcb_release_remove tp s3).1 → + ∀ s5, ((), s5) ∈ (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_dequeue tp s4).1 → + s5.cur_sc = scPtr → CommitTimeSafe s5) ∧ + (period ≠ budget → + ∀ s2, ((), s2) ∈ (holWhen (holNot (holEq sc.sc_tcb none)) + (holBind (holAssertOpt sc.sc_tcb) fun tcb_ptr => + holBind (KHeap_A.tcb_release_remove tcb_ptr) (holKBind + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind + (holBind (holGets fun s => s.cur_sc) fun cur_sc => + holWhen (holEq cur_sc scPtr) SchedContext_A.commit_time))))) s1).1 → + ∀ sc2 n, s2.kheap scPtr = some (.SchedContext sc2 n) → sc2.sc_refills ≠ []) + +theorem invokeSchedControlConfigureFlags_equiv (hop : OpaqueRel RestRel) + (iv : Invocations_A.sched_control_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : InvokeSchedControlSafe iv sH) : + MRelStep SR Eq + (Ipc_A.invoke_sched_control_configure_flags iv sH) + (Fl4Spec.invokeSchedControlConfigureFlags (embSchedControlInv iv) sL) := by + cases iv with + | InvokeSchedControlConfigureFlags scPtr budget period mrefills badge flag => + unfold Ipc_A.invoke_sched_control_configure_flags Fl4Spec.invokeSchedControlConfigureFlags + simp only [Invocations_A.case_sched_control_invocation, embSchedControlInv] + refine mrelStep_bind_mem (getSchedContext_equiv scPtr sH sL hs) fun scH scL hsc s1H s1L hs1 hm1 => ?_ + subst hsc + obtain ⟨hcommit1, hrefills1⟩ := hsafe scH s1H hm1 + have hstep1 : MRelStep SR Eq + (holFunApp (holWhen (holNot (holEq scH.sc_tcb none))) + (holBind (holFunApp holAssertOpt scH.sc_tcb) fun tcb_ptr => + holBind (KHeap_A.tcb_release_remove tcb_ptr) (holKBind + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind + (holBind (holGets fun s => s.cur_sc) fun cur_sc => + holFunApp (holWhen (holEq cur_sc scPtr)) SchedContext_A.commit_time))))) s1H) + ((NonDet.when (scH.sc_tcb ≠ none) do + let tcbPtr ← NonDet.assertOpt scH.sc_tcb + Fl4Spec.tcbReleaseRemove tcbPtr + Fl4Spec.tcbSchedAction Fl4Spec.tcbSchedDequeue tcbPtr + let curSc ← NonDet.gets fun s : State ZL => s.curSc + NonDet.when (curSc = scPtr) Fl4Spec.commitTime) s1L) := by + by_cases hnt : scH.sc_tcb ≠ none + · have hntH : holNot (holEq scH.sc_tcb none) = true := by simp [holNot_eq_true, holEq_eq_true, hnt] + simp only [holFunApp, holWhen, NonDet.when, hntH, ite_true, ite_eq_left hnt] + have haOpt : MRel SR Eq (holAssertOpt scH.sc_tcb) (NonDet.assertOpt scH.sc_tcb) := + mrel_assertOpt (by cases scH.sc_tcb <;> simp [OptRel]) + refine mrelStep_bind_mem (haOpt s1H s1L hs1) + fun tpH tpL htp s3H s3L hs3 hm3 => ?_; subst htp + refine mrelStep_bind_mem (tcbReleaseRemove_equiv tpH s3H s3L hs3) + fun u4 _ _ s4H s4L hs4 hm4 => ?_; cases u4 + refine mrelStep_bind_mem (tcbSchedAction_equiv tcbSchedDequeue_eq tpH s4H s4L hs4) + fun u5 _ _ s5H s5L hs5 hm5 => ?_; cases u5 + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) s5H s5L hs5) + fun csH csL hcs s6H s6L hs6 hm6 => ?_; subst hcs + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm6 + obtain ⟨hcs0, hs6eq⟩ := hm6 + subst s6H + subst csH + by_cases hcsEq : s5H.cur_sc = scPtr + · simp only [hcsEq, holEq, decide_true, ↓reduceIte] + exact commitTime_equiv hop hs6 (hcommit1 hnt tpH s3H hm3 s4H hm4 s5H hm5 hcsEq) + · simp only [hcsEq, holEq, decide_false, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl s5H s6L hs6 + · have hntH : holNot (holEq scH.sc_tcb none) = false := by + cases h : scH.sc_tcb + · simp [holNot, holEq] + · exact absurd (by simp [h]) hnt + simp only [holFunApp, holWhen, NonDet.when, hntH, hnt, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl s1H s1L hs1 + refine mrelStep_bind_mem hstep1 fun u2 _ _ s2H s2L hs2 hm2 => ?_ + cases u2 + have htail : ∀ s3H s3L, SR s3H s3L → MRelStep SR Eq + ((holBind (holFunApp (holWhen (holNot (holEq scH.sc_tcb none))) + (holBind (SchedContext_A.sched_context_resume scPtr) (holKBind + (holBind (holFunApp holAssertOpt scH.sc_tcb) fun tcb_ptr => + holBind (KHeap_A.get_thread_state tcb_ptr) fun st => + holBind (holGets fun s => s.cur_thread) fun ct => + holIf (holEq tcb_ptr ct) KHeap_A.reschedule_required + (holFunApp (holWhen (Structures_A.runnable st)) (KHeap_A.possible_switch_to tcb_ptr)))))) (holKBind + (holBind (KHeap_A.set_sc_obj_ref Structures_A.sched_context.sc_badge_update scPtr badge) (holKBind + (KHeap_A.set_sc_obj_ref Structures_A.sched_context.sc_sporadic_update scPtr + (holWordBit flag Structures_A.sc_sporadic_flag)))))) s3H) + ((do + NonDet.when (scH.sc_tcb ≠ none) do + Fl4Spec.schedContextResume scPtr + let tcbPtr ← NonDet.assertOpt scH.sc_tcb + let st ← Fl4Spec.getThreadState tcbPtr + let ct ← NonDet.gets fun s : State ZL => s.curThread + if tcbPtr = ct then Fl4Spec.rescheduleRequired + else NonDet.when (Fl4Spec.runnable st) (Fl4Spec.possibleSwitchTo tcbPtr) + Fl4Spec.setScObjRef Fl4Spec.scBadgeUpdate scPtr badge + Fl4Spec.setScObjRef Fl4Spec.scSporadicUpdate scPtr + (Fl4Spec.testBit flag Fl4Spec.scSporadicFlag)) s3L) := by + intro s3H s3L hs3 + refine mrelStep_bind_mem (mrel_when (by simp [holNot_eq_true, holEq_eq_true]) (fun _ => by + refine mrel_kbind (schedContextResume_equiv hop scPtr) ?_ + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases scH.sc_tcb <;> simp [OptRel])) fun tpH tpL htp => ?_; subst htp + refine mrel_bind (getThreadState_equiv tpH) fun stH stL hst => ?_; subst hst + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun ctH ctL hct => ?_; subst hct + exact mrel_if (by simp [holEq_eq_true]) (fun _ => rescheduleRequired_equiv hop) + (fun _ => mrel_when (by rw [runnable_eq]) fun _ => possibleSwitchTo_equiv hop tpH)) s3H s3L hs3) + fun _ _ _ s4H s4L hs4 _ => ?_ + refine mrelStep_bind_mem (setScObjRef_equiv (fun _ _ => rfl) scPtr badge s4H s4L hs4) + fun _ _ _ s5H s5L hs5 _ => ?_ + have hbit : Fl4Spec.testBit flag Fl4Spec.scSporadicFlag = + holWordBit flag Structures_A.sc_sporadic_flag := rfl + rw [hbit] + exact setScObjRef_equiv (fun _ _ => rfl) scPtr _ s5H s5L hs5 + by_cases hpb : period = budget + · have hpbH : holEq period budget = true := by simp [holEq_eq_true, hpb] + rw [hpbH, holIf_true] + simp only [hpb, ↓reduceIte] + exact mrelStep_bind_mem (refillNew_equiv scPtr Structures_A.MIN_REFILLS budget 0 s2H s2L hs2) + fun _ _ _ s3H s3L hs3 _ => htail s3H s3L hs3 + · have hpbH : holEq period budget = false := Bool.eq_false_iff.mpr (by simpa [holEq_eq_true]) + rw [hpbH, holIf_false] + simp only [hpb, ↓reduceIte] + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (getScActive_equiv scPtr s2H s2L hs2) fun aH aL ha s3H s3L hs3 hm3 => ?_; subst ha + have hs3eq : s3H = s2H := holGetsThe_state_eq hm3 + subst s3H + have hsc3 : ∃ sc n, s2H.kheap scPtr = some (.SchedContext sc n) := by + unfold KHeap_A.get_sc_active holGetsThe KHeap_A.read_sc_active + KHeap_A.read_sched_context KHeap_A.read_object at hm3 + cases hkh : s2H.kheap scPtr with + | none => simp [hkh, holSwp, holOBind, holAssertOpt, holFail] at hm3 + | some k => + cases k with + | SchedContext sc n => exact ⟨sc, n, rfl⟩ + | _ => simp [hkh, holSwp, holOBind, holOFail, Structures_A.case_kernel_object, holAssertOpt, holFail] at hm3 + by_cases hat : aH = true ∧ scH.sc_tcb ≠ none + · have hatH : holConj aH (holNot (holEq scH.sc_tcb none)) = true := by + simp [holConj_eq_true, holNot_eq_true, holEq_eq_true, hat] + have hatL : aH = true ∧ (embSchedContext scH).scTcb ≠ none := hat + rw [hatH, holIf_true, ite_eq_left hatL] + simp only [holFunApp] + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (mrel_assertOpt (Ra := Eq) (oH := scH.sc_tcb) (oL := (embSchedContext scH).scTcb) + (by dsimp only [embSchedContext]; cases scH.sc_tcb <;> simp [OptRel]) s2H s3L hs3) + fun tpH tpL htp s4H s4L hs4 hm4 => ?_; subst htp + have hs4eq : s4H = s2H := by + cases hopt : scH.sc_tcb with + | none => simp [hopt, holAssertOpt, holFail] at hm4 + | some _ => simp [hopt, holAssertOpt, holReturn] at hm4; exact hm4.2 + subst s4H + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (getThreadState_equiv tpH s2H s4L hs4) fun stH stL hst s5H s5L hs5 hm5 => ?_; subst hst + have hs5eq : s5H = s2H := by + unfold KHeap_A.get_thread_state KHeap_A.thread_get KHeap_A.get_tcb at hm5 + simp only [holBind, holReturn, holFunApp, Set.mem_ofPred_eq, Set.mem_singleton_iff, Prod.mk.injEq] at hm5 + rcases hm5 with ⟨⟨_, sA⟩, hgt, _, hsA⟩ + rw [hsA] + exact holGetsThe_state_eq hgt + subst s5H + by_cases hrun : Structures_A.runnable stH = true + · have hrunL : Fl4Spec.runnable (embThreadState stH) = true := by rw [runnable_eq, hrun] + rw [hrun, holIf_true] + simp only [hrunL, ↓reduceIte] + have hne5 : HasNonEmptyRefills scPtr s2H := by + rcases hsc3 with ⟨sc, n, hkh⟩ + exact ⟨sc, n, hkh, hrefills1 hpb s2H hm2 sc n hkh⟩ + refine mrelStep_bind_mem + (mrel_drop_post (refillUpdate_equiv_nonEmpty scPtr period budget mrefills) s2H s5L ⟨hs5, hne5⟩) + fun _ _ _ s6H s6L hs6 _ => htail s6H s6L hs6 + · have hrunF : Structures_A.runnable stH = false := Bool.eq_false_iff.mpr hrun + have hrunLF : Fl4Spec.runnable (embThreadState stH) = false := by rw [runnable_eq, hrunF] + rw [hrunF, holIf_false] + simp only [hrunLF, Bool.false_eq_true, ↓reduceIte] + exact mrelStep_bind_mem (refillNew_equiv scPtr mrefills budget period s2H s5L hs5) + fun _ _ _ s6H s6L hs6 _ => htail s6H s6L hs6 + · have hatH : holConj aH (holNot (holEq scH.sc_tcb none)) = false := + Bool.eq_false_iff.mpr (by simpa [holConj_eq_true, holNot_eq_true, holEq_eq_true] using hat) + have hatL : ¬(aH = true ∧ (embSchedContext scH).scTcb ≠ none) := hat + rw [hatH, holIf_false, ite_eq_right hatL] + exact mrelStep_bind_mem (refillNew_equiv scPtr mrefills budget period s2H s3L hs3) + fun _ _ _ s4H s4L hs4 _ => htail s4H s4L hs4 + +def end_timeslice_p (canTimeout : Bool) : HolNonDet (Structures_A.state ZH) Unit := + holBind (holGets fun s => s.cur_sc) fun sc_ptr => + holBind (Sporadic_A.is_round_robin sc_ptr) fun round_robin => + holBind (holGets fun s => s.cur_thread) fun ct => + holBind (Ipc_A.is_valid_timeout_handler ct) fun valid => + holIf (holConj canTimeout (holConj (holNot round_robin) valid)) + ( + holBind (KHeap_A.get_sched_context sc_ptr) fun sc => + handle_timeout_p ct (.Timeout sc.sc_badge)) + ( + holBind (KHeap_A.get_sc_refill_ready sc_ptr) fun ready => + holBind (KHeap_A.get_sc_refill_sufficient sc_ptr 0) fun sufficient => + holIf (holConj ready sufficient) + (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_append ct) + (SchedContext_A.postpone sc_ptr)) + +theorem patched_endTimeslice_equiv (hop : OpaqueRel RestRel) (canTimeout : Bool) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hcur : ∃ tcb, sH.kheap sH.cur_thread = some (.TCB tcb)) : + MRelStep SR Eq (end_timeslice_p canTimeout sH) (Fl4Spec.endTimeslice canTimeout sL) := by + unfold end_timeslice_p Fl4Spec.endTimeslice + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun scH scL hsc s1H s1L hs1 hm1 => ?_ + subst hsc + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + obtain ⟨hrsc, hrst⟩ := hm1 + subst scH s1H + refine mrelStep_bind_mem (isRoundRobin_equiv sH.cur_sc sH s1L hs1) + fun rrH rrL hrr s2H s2L hs2 hm2 => ?_ + subst hrr + have hs2eq := isRoundRobin_state_eq hm2 + subst s2H + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH s2L hs2) + fun ctH ctL hct s3H s3L hs3 hm3 => ?_ + subst hct + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm3 + obtain ⟨hcurThread, hcurState⟩ := hm3 + subst ctH s3H + obtain ⟨tcb, htcb⟩ := hcur + have hkh := hs3.kheap_eq sH.cur_thread + rw [htcb] at hkh + have hts : Fl4Spec.getThreadState sH.cur_thread s3L = + ({(embThreadState tcb.tcb_state, s3L)}, False) := by + simp [Fl4Spec.getThreadState, Fl4Spec.threadGet, Fl4Spec.getTcb, Fl4Spec.readObject, NonDet.bind, + NonDet.getsThe, NonDet.assertOpt, NonDet.pure, Bind.bind, Pure.pure, hkh, embKernelObject, embTcb] + have hnative : embThreadState tcb.tcb_state ≠ .runningVM := by + cases tcb.tcb_state <;> simp [embThreadState] + simp only [Bind.bind] + rw [nonDet_bind_singleton_at _ hts] + simp only [hnative, ↓reduceIte] + refine mrelStep_bind_mem (isValidTimeoutHandler_equiv sH.cur_thread sH s3L hs3) + fun validH validL hv s4H s4L hs4 _ => ?_ + subst hv + have hguard : holConj canTimeout (holConj (holNot rrH) validH) = true ↔ + canTimeout = true ∧ ¬rrH = true ∧ validH = true := by + cases rrH <;> simp [holConj_eq_true, holNot] + by_cases htimeout : canTimeout = true ∧ ¬rrH = true ∧ validH = true + · rw [hguard.mpr htimeout, holIf_true, ite_eq_left htimeout] + refine mrelStep_bind_mem (getSchedContext_equiv sH.cur_sc s4H s4L hs4) + fun scH scL hsc s5H s5L hs5 _ => ?_ + subst hsc + exact patched_handleTimeout_equiv hop sH.cur_thread (.Timeout scH.sc_badge) s5H s5L hs5 + · rw [Bool.eq_false_iff.mpr (mt hguard.mp htimeout), holIf_false, ite_eq_right htimeout] + refine mrelStep_bind_mem (getScRefillReady_equiv sH.cur_sc s4H s4L hs4) + fun rH rL hr s5H s5L hs5 _ => ?_ + subst hr + refine mrelStep_bind_mem (getScRefillSufficient_equiv hop sH.cur_sc 0 s5H s5L hs5) + fun suH suL hsu s6H s6L hs6 _ => ?_ + subst hsu + by_cases hready : rH = true ∧ suH = true + · rw [(holConj_eq_true _ _).mpr hready, holIf_true, ite_eq_left hready] + exact tcbSchedAction_equiv tcbSchedAppend_eq sH.cur_thread s6H s6L hs6 + · rw [Bool.eq_false_iff.mpr (mt (holConj_eq_true _ _).mp hready), holIf_false, ite_eq_right hready] + exact postpone_equiv sH.cur_sc s6H s6L hs6 + +def charge_budget_p (consumed : Ticks) (canTimeout : Bool) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (holGets fun s => s.cur_sc) fun csc_ptr => + holBind (holWhen (holNot (holEq csc_ptr Machine_A.idle_sc_ptr)) + (holBind (Sporadic_A.is_round_robin csc_ptr) fun robin => + holBind (holIf robin (Ipc_A.refill_reset_rr csc_ptr) (SchedContext_A.refill_budget_check consumed)) (holKBind + (KHeap_A.update_sched_context csc_ptr fun sc => + Structures_A.sched_context.sc_consumed_update (fun _ => HolAdd.addVal sc.sc_consumed consumed) sc)))) (holKBind + (holBind (holModify (Structures_A.abstract_state.consumed_time_update (holK 0))) (holKBind + (holBind (holGets fun s => s.cur_thread) fun ct => + holBind (holGets (KHeap_A.schedulable ct)) fun sched => + holWhen sched + (holBind (end_timeslice_p canTimeout) (holKBind + (holBind KHeap_A.reschedule_required (holKBind + (holModify (Structures_A.abstract_state.reprogram_timer_update (fun _ => true))))))))))) + +theorem patched_chargeBudget_equiv (hop : OpaqueRel RestRel) (consumed : Ticks) (canTimeout : Bool) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : ChargeBudgetSafe consumed sH) : + MRelStep SR Eq (charge_budget_p consumed canTimeout sH) (Fl4Spec.chargeBudget consumed canTimeout sL) := by + unfold charge_budget_p Fl4Spec.chargeBudget + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun cH cL hc s1H s1L hs1 hm1 => ?_ + subst hc + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + obtain ⟨hsc, hstate⟩ := hm1 + subst cH s1H + simp only [Bind.bind, nonDet_bind_gets_at] + refine mrelStep_bind_mem (Rs' := SR) (Ra := Eq) (Rb := Eq) ?_ fun _ _ _ s2H s2L hs2 _ => ?_ + · by_cases hne : sH.cur_sc ≠ Machine_A.idle_sc_ptr + · have hc : holNot (holEq sH.cur_sc Machine_A.idle_sc_ptr) = true := by + simp [holNot_eq_true, holEq_eq_true, hne] + have hneL : sH.cur_sc ≠ s1L.idleSc := by simpa only [hs1.idleSc_eq] using hne + simp only [holWhen, NonDet.when, hc, ↓reduceIte] + rw [ite_eq_left hneL] + obtain ⟨hnonempty, hbudget⟩ := hsafe hne + refine mrelStep_bind_mem (isRoundRobin_equiv sH.cur_sc sH s1L hs1) + fun rrH rrL hrr s3H s3L hs3 hm3 => ?_ + subst hrr + have hsame := isRoundRobin_state_eq hm3 + subst s3H + cases rrH with + | true => + simp only [holIf_true, ↓reduceIte] + exact mrelStep_bind_mem (refillResetRr_equiv sH.cur_sc hs3 hnonempty) + fun _ _ _ tH tL ht _ => updateSchedContext_equiv (fun _ => rfl) sH.cur_sc tH tL ht + | false => + simp only [holIf_false, Bool.false_eq_true, ↓reduceIte] + exact mrelStep_bind_mem (refillBudgetCheck_equiv hop consumed hs3 hbudget) + fun _ _ _ tH tL ht _ => updateSchedContext_equiv (fun _ => rfl) sH.cur_sc tH tL ht + · have hc : holNot (holEq sH.cur_sc Machine_A.idle_sc_ptr) = false := by + apply Bool.eq_false_iff.mpr + simpa [holNot_eq_true, holEq_eq_true] using hne + have hneL : ¬sH.cur_sc ≠ s1L.idleSc := by simpa only [hs1.idleSc_eq] using hne + simp only [holWhen, NonDet.when, hc, Bool.false_eq_true, ↓reduceIte] + rw [ite_eq_right hneL] + exact mrel_return rfl sH s1L hs1 + · refine mrelStep_bind_mem (mrel_modify (fun _ _ h => { h with consumedTime_eq := rfl }) s2H s2L hs2) + fun _ _ _ s3H s3L hs3 _ => ?_ + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) s3H s3L hs3) + fun tH tL ht s4H s4L hs4 hm4 => ?_ + subst ht + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm4 + obtain ⟨hthread, hstate⟩ := hm4 + subst tH s4H + refine mrelStep_bind_mem (mrel_gets (fH := KHeap_A.schedulable s3H.cur_thread) + (fL := Fl4Spec.schedulable s3H.cur_thread) (Ra := Eq) + (fun _ _ h => (schedulable_eq h s3H.cur_thread).symm) s3H s4L hs4) + fun shouldH shouldL hshould s5H s5L hs5 hm5 => ?_ + subst hshould + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm5 + obtain ⟨hshould, hstate⟩ := hm5 + subst shouldH s5H + by_cases htrue : KHeap_A.schedulable s3H.cur_thread s3H = true + · simp only [holWhen, NonDet.when, htrue, ↓reduceIte] + refine mrelStep_bind_mem + (patched_endTimeslice_equiv hop canTimeout hs5 (schedulable_implies_tcb _ _ htrue)) + fun _ _ _ tH tL ht _ => ?_ + refine mrelStep_bind_mem (rescheduleRequired_equiv hop tH tL ht) fun _ _ _ uH uL hu _ => ?_ + exact mrel_modify (fun _ _ h => { h with reprogramTimer_eq := rfl }) uH uL hu + · have hfalse : KHeap_A.schedulable s3H.cur_thread s3H = false := Bool.eq_false_iff.mpr htrue + simp only [holWhen, NonDet.when, hfalse, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl s3H s5L hs5 + + +def check_budget_p : HolNonDet (Structures_A.state ZH) Bool := + holBind (holGets fun s => s.cur_sc) fun csc => + holBind (holGets fun s => s.consumed_time) fun consumed => + holBind (KHeap_A.get_sc_refill_sufficient csc consumed) fun sufficient => + holIf sufficient + (holBind (holGets KHeap_A.is_cur_domain_expired) fun expired => holReturn (holNot expired)) + (holBind (holGets fun s => s.consumed_time) fun elapsed => + holBind (charge_budget_p elapsed true) (holKBind (holReturn false))) + +/-- Only a reached budget-exhaustion branch requires a charging premise. -/ +def CheckBudgetSafe (s : Structures_A.state ZH) : Prop := + ∀ t, (false, t) ∈ (KHeap_A.get_sc_refill_sufficient s.cur_sc s.consumed_time s).1 → + ChargeBudgetSafe t.consumed_time t + +theorem patched_checkBudget_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : CheckBudgetSafe sH) : + MRelStep SR Eq (check_budget_p sH) (Fl4Spec.checkBudget sL) := by + unfold check_budget_p Fl4Spec.checkBudget + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun scH scL hsc s1H s1L hs1 hm1 => ?_ + subst hsc + obtain ⟨hvalue, hstate⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm1) + subst scH s1H + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.consumedTime_eq.symm) sH s1L hs1) + fun cH cL hcon s2H s2L hs2 hm2 => ?_ + subst hcon + obtain ⟨hvalue, hstate⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm2) + subst cH s2H + refine mrelStep_bind_mem (getScRefillSufficient_equiv hop sH.cur_sc sH.consumed_time sH s2L hs2) + fun suH suL hsu s3H s3L hs3 hm3 => ?_ + subst hsu + cases suH with + | true => + simp only [holIf_true, ↓reduceIte] + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) + (fH := KHeap_A.is_cur_domain_expired) (fL := Fl4Spec.isCurDomainExpired) + (fun _ _ h => (isCurDomainExpired_eq hc h).symm) s3H s3L hs3) + fun dH dL hd s4H s4L hs4 _ => ?_ + subst hd + exact mrel_return rfl s4H s4L hs4 + | false => + simp only [holIf_false, Bool.false_eq_true, ↓reduceIte] + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.consumedTime_eq.symm) s3H s3L hs3) + fun elH elL hel s4H s4L hs4 hm4 => ?_ + subst hel + obtain ⟨hvalue, hstate⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm4) + subst elH s4H + exact mrelStep_bind_mem (patched_chargeBudget_equiv hop s3H.consumed_time true hs4 (hsafe s3H hm3)) + fun _ _ _ s5H s5L hs5 _ => mrel_return rfl s5H s5L hs5 + +def check_budget_restart_p : HolNonDet (Structures_A.state ZH) Bool := + holBind check_budget_p fun result => + holBind (holGets fun s => s.cur_thread) fun cur => + holBind (KHeap_A.get_thread_state cur) fun st => + holBind (holWhen (holConj (holNot result) (Structures_A.runnable st)) + (KHeap_A.set_thread_state cur .Restart)) (holKBind (holReturn result)) + +theorem patched_checkBudgetRestart_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : CheckBudgetSafe sH) : + MRelStep SR Eq (check_budget_restart_p sH) (Fl4Spec.checkBudgetRestart sL) := by + unfold check_budget_restart_p Fl4Spec.checkBudgetRestart + refine mrelStep_bind_mem (patched_checkBudget_equiv hc hop hs hsafe) + fun rH rL hr s1H s1L hs1 _ => ?_ + subst hr + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) s1H s1L hs1) + fun ctH ctL hct s2H s2L hs2 _ => ?_ + subst hct + refine mrelStep_bind_mem (getThreadState_equiv ctH s2H s2L hs2) + fun stH stL hst s3H s3L hs3 _ => ?_ + subst hst + refine mrelStep_bind_mem (mrel_when (by simp [holConj_eq_true, holNot_eq_true, runnable_eq]) + (fun _ => setThreadState_equiv ctH .Restart) s3H s3L hs3) + fun _ _ _ s4H s4L hs4 _ => ?_ + exact mrel_return rfl s4H s4L hs4 + +end + +end L4vRefX64.Equiv.Ipc diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/IpcCancel.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/IpcCancel.lean new file mode 100644 index 000000000..2061221e9 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/IpcCancel.lean @@ -0,0 +1,810 @@ +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Equiv.CSpaceAcc + +namespace L4vRefX64.Equiv.IpcCancel + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec +open L4vRefX64.Equiv.Machine +open L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.Deterministic +open L4vRefX64.Equiv.KHeap +open L4vRefX64.Equiv.CSpaceAcc +open Fl4Spec +open Classical + +noncomputable section + +theorem holBind_kbind_return_left {σ β : Type} (a : Unit) (m : HolNonDet σ β) : + holBind (holReturn a) (holKBind m) = m := + holBind_return_left a (holKBind m) + +theorem holBind_kbind_assoc {σ α β γ : Type} (m : HolNonDet σ α) (n : HolNonDet σ β) + (g : β → HolNonDet σ γ) : + holBind (holBind m (holKBind n)) g = holBind m (holKBind (holBind n g)) := by + rw [KHeap.holBind_assoc]; rfl + +theorem nonDet_bind_pure_left {σ α β : Type} (a : α) (f : α → NonDet σ β) : + NonDet.bind (NonDet.pure a) f = f a := by + funext s + apply Prod.ext + · ext ⟨b, s'⟩ + simp [NonDet.bind, NonDet.pure] + · simp [NonDet.bind, NonDet.pure] + +private theorem set_insert_empty {α : Type} (x : α) : insert x (∅ : Set α) = {x} := by + ext y + simp + +theorem updateEpQueue_eq (ep : Structures_A.endpoint) (q : List ObjRef) (isRecv : Bool) : + Fl4Spec.updateEpQueue (embEndpoint ep) q isRecv = + embEndpoint (IpcCancel_A.update_ep_queue ep q isRecv) := by + cases ep with + | IdleEP => cases isRecv <;> rfl + | SendEP _ => rfl + | RecvEP _ => rfl + +theorem ntfnQueueOf_eq (n : Structures_A.notification) : + Fl4Spec.ntfnQueueOf (embNotification n) = IpcCancel_A.ntfn_queue_of n := by + unfold Fl4Spec.ntfnQueueOf IpcCancel_A.ntfn_queue_of + exact ntfnQueue_eq n.ntfn_obj + +theorem updateNtfnQueue_waiting_eq (q0 q : List ObjRef) : + Fl4Spec.updateNtfnQueue (embNtfn (.WaitingNtfn q0)) q = + embNtfn (IpcCancel_A.update_ntfn_queue (.WaitingNtfn q0) q) := rfl + +theorem epBlocked_eq (ts : Structures_A.thread_state) : + Fl4Spec.epBlocked (embThreadState ts) = IpcCancel_A.ep_blocked ts := by + cases ts <;> rfl + +theorem ntfnBlocked_eq (ts : Structures_A.thread_state) : + Fl4Spec.ntfnBlocked (embThreadState ts) = IpcCancel_A.ntfn_blocked ts := by + cases ts <;> rfl + +theorem removeAll_eq {α : Type} [DecidableEq α] (x : α) (xs : List α) : + Fl4Spec.removeAll x xs = holListRemoveAll x xs := by + unfold Fl4Spec.removeAll holListRemoveAll + congr 1; funext y + by_cases h : x = y <;> simp [h, eq_comm] + +theorem ntfn_isWaitingNtfn_eq (n : Structures_A.ntfn) : + (embNtfn n).isWaitingNtfn = n.is_WaitingNtfn := by + cases n <;> apply Bool.eq_iff_iff.mpr <;> + simp [Ntfn.isWaitingNtfn, Structures_A.ntfn.is_WaitingNtfn, embNtfn, holEx_eq_true, holEq_eq_true] + +theorem blockingIpcBadge_eq (ts : Structures_A.thread_state) : + Fl4Spec.blockingIpcBadge (embThreadState ts) = IpcCancel_A.blocking_ipc_badge ts := by + cases ts <;> rfl + +theorem capIrqOpt_eq (c : Structures_A.cap) : + Fl4Spec.capIrqOpt (embCap c) = (IpcCancel_A.cap_irq_opt c).map embIrq := by + cases c <;> rfl + +theorem capIrqs_eq (c : Structures_A.cap) : + Fl4Spec.capIrqs (embCap c) = embIrq '' IpcCancel_A.cap_irqs c := by + unfold Fl4Spec.capIrqs IpcCancel_A.cap_irqs holSetOption + ext irq + simp only [Set.mem_ofPred_eq, Set.mem_image, capIrqOpt_eq] + cases IpcCancel_A.cap_irq_opt c with + | none => simp + | some i => + simp [Option.map, eq_comm] + +section IpcCancelMonad + +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 schedContextBindNtfn_equiv (sc ntfn : ObjRef) : + MRel SR Eq + (IpcCancel_A.sched_context_bind_ntfn sc ntfn) + (Fl4Spec.schedContextBindNtfn sc ntfn) := by + unfold IpcCancel_A.sched_context_bind_ntfn Fl4Spec.schedContextBindNtfn + exact mrel_kbind + (setNtfnObjRef_equiv (fun _ _ => rfl) ntfn (some sc)) + (setScObjRef_equiv (fun _ _ => rfl) sc (some ntfn)) + +theorem doUnbindNtfnSc_equiv (ntfnptr scptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.do_unbind_ntfn_sc ntfnptr scptr) + (Fl4Spec.doUnbindNtfnSc ntfnptr scptr) := by + unfold IpcCancel_A.do_unbind_ntfn_sc Fl4Spec.doUnbindNtfnSc + exact mrel_kbind + (setNtfnObjRef_equiv (fun _ _ => rfl) ntfnptr none) + (setScObjRef_equiv (fun _ _ => rfl) scptr none) + +theorem schedContextUnbindNtfn_equiv (scPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.sched_context_unbind_ntfn scPtr) + (Fl4Spec.schedContextUnbindNtfn scPtr) := by + unfold IpcCancel_A.sched_context_unbind_ntfn Fl4Spec.schedContextUnbindNtfn + refine mrel_bind (getScObjRef_equiv (fun _ => rfl) scPtr) fun oH oL ho => ?_ + subst ho + cases oH with + | none => exact mrel_return rfl + | some ntfn => exact doUnbindNtfnSc_equiv ntfn scPtr + +theorem schedContextMaybeUnbindNtfn_equiv (ntfnPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.sched_context_maybe_unbind_ntfn ntfnPtr) + (Fl4Spec.schedContextMaybeUnbindNtfn ntfnPtr) := by + unfold IpcCancel_A.sched_context_maybe_unbind_ntfn Fl4Spec.schedContextMaybeUnbindNtfn + refine mrel_bind (getNtfnObjRef_equiv (fun _ => rfl) ntfnPtr) fun oH oL ho => ?_ + subst ho + cases oH with + | none => exact mrel_return rfl + | some sc => exact doUnbindNtfnSc_equiv ntfnPtr sc + +theorem schedContextUnbindReply_equiv (scPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.sched_context_unbind_reply scPtr) + (Fl4Spec.schedContextUnbindReply scPtr) := by + unfold IpcCancel_A.sched_context_unbind_reply Fl4Spec.schedContextUnbindReply + refine mrel_bind (mrel_liftM (Rb := Eq) (fun scH scL hsc => by subst hsc; rfl) (getSchedContext_equiv scPtr)) + fun rH rL hr => ?_ + subst hr + cases rH with + | nil => + have hnil : holEq ([] : List ObjRef) [] = true := by simp [holEq] + simp only [holFunApp, holUnless, hnil, NonDet.unless, ↓reduceIte] + exact mrel_return rfl + | cons hd tl => + have hne : holEq (hd :: tl) [] = false := by simp [holEq] + simp only [holFunApp, holUnless, hne, NonDet.unless, reduceCtorEq, ↓reduceIte, holHd, the] + exact mrel_kbind + (setReplyObjRef_equiv (fun _ _ => rfl) hd none) + (setScObjRef_equiv (fun _ _ => rfl) scPtr []) + +theorem schedContextUnbindTcb_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.sched_context_unbind_tcb scPtr) + (Fl4Spec.schedContextUnbindTcb scPtr) := by + unfold IpcCancel_A.sched_context_unbind_tcb Fl4Spec.schedContextUnbindTcb + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + simp only [holFunApp] + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by simp only [embSchedContext]; cases scH.sc_tcb <;> simp [OptRel])) fun tH tL ht => ?_ + subst ht + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun cH cL hc => ?_ + subst hc + refine mrel_kbind (mrel_when (by simp [holEq_eq_true]) fun _ => rescheduleRequired_equiv hop) ?_ + refine mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq tH) ?_ + refine mrel_kbind (tcbReleaseRemove_equiv tH) ?_ + refine mrel_kbind (setTcbObjRef_equiv (fun _ _ => rfl) tH none) ?_ + exact setScObjRef_equiv (fun _ _ => rfl) scPtr none + +theorem testReschedule_equiv (hop : OpaqueRel RestRel) (fromTptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.test_reschedule fromTptr) + (Fl4Spec.testReschedule fromTptr) := by + unfold IpcCancel_A.test_reschedule Fl4Spec.testReschedule + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun cH cL hc => ?_ + subst hc + refine mrel_bind (mrel_gets (Ra := FunRel embSchedulerAction) fun _ _ hs => hs.schedulerAction_eq) + fun aH aL ha => ?_ + subst ha + have hflag : ∀ (bH : Bool) (P : Prop), + (bH = true ↔ P) → + MRel SR Eq + (holBind (holReturn bH) fun flag => + holWhen (holDisj (holEq fromTptr cH) flag) KHeap_A.reschedule_required) + (do let flag ← pure P; NonDet.when (fromTptr = cH ∨ flag) Fl4Spec.rescheduleRequired) := by + intro bH P hbp + refine mrel_bind (Ra := fun x y => x = true ↔ y) (mrel_return hbp) fun fH fL hf => ?_ + exact mrel_when (by simp [holDisj_eq_true, holEq_eq_true, hf]) fun _ => + rescheduleRequired_equiv hop + cases aH with + | resume_cur_thread => + simp only [Structures_A.case_scheduler_action, embSchedulerAction, holFunApp] + exact hflag _ _ (by simp) + | choose_new_thread => + simp only [Structures_A.case_scheduler_action, embSchedulerAction, holFunApp] + exact hflag _ _ (by simp) + | switch_thread p => + simp only [Structures_A.case_scheduler_action, embSchedulerAction, holFunApp] + exact hflag _ _ (by simp [holEq_eq_true]) + +theorem schedContextDonate_equiv (hop : OpaqueRel RestRel) (scPtr tcbPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.sched_context_donate scPtr tcbPtr) + (Fl4Spec.schedContextDonate scPtr tcbPtr) := by + unfold IpcCancel_A.sched_context_donate Fl4Spec.schedContextDonate + refine mrel_bind (getScObjRef_equiv (fun _ => rfl) scPtr) fun oH oL ho => ?_ + subst ho + refine mrel_kbind (mrel_when (by simp [holNot_eq_true, ne_eq, holEq_eq_true]) fun _ => ?_) ?_ + · refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases oH <;> simp [OptRel])) fun fH fL hf => ?_ + subst hf + refine mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq fH) ?_ + refine mrel_kbind (tcbReleaseRemove_equiv fH) ?_ + refine mrel_kbind (setTcbObjRef_equiv (fun _ _ => rfl) fH none) ?_ + exact testReschedule_equiv hop fH + · refine mrel_kbind (setScObjRef_equiv (fun _ _ => rfl) scPtr (some tcbPtr)) ?_ + exact setTcbObjRef_equiv (fun _ _ => rfl) tcbPtr (some scPtr) + +theorem replyUnlinkSc_equiv (scPtr replyPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.reply_unlink_sc scPtr replyPtr) + (Fl4Spec.replyUnlinkSc scPtr replyPtr) := by + unfold IpcCancel_A.reply_unlink_sc Fl4Spec.replyUnlinkSc + refine mrel_bind (mrel_liftM (Rb := Eq) (fun scH scL hsc => by subst hsc; rfl) (getSchedContext_equiv scPtr)) + fun rsH rsL hrs => ?_ + subst hrs + refine mrel_bind (getReply_equiv replyPtr) fun rH rL hr => ?_ + subst hr + have hhd : holHd rsH = the rsH.head? := by cases rsH <;> rfl + refine mrel_if (by simp [holEq_eq_true, hhd]) (fun _ => ?_) (fun _ => ?_) + · refine mrel_kbind (mrel_assert (by simp [holEq_eq_true, embReply])) ?_ + refine mrel_kbind (updateSchedContext_equiv (fun sc => by + cases sc; simp only [embSchedContext, Structures_A.sched_context.sc_replies_update, + Fl4Spec.scRepliesUpdate] + congr 1; cases ‹List (BitVec 64)› <;> rfl) scPtr) ?_ + cases rsH with + | nil => + simp only [holTl, holCaseList, List.tail_nil, holBind_kbind_return_left] + exact setReplyObjRef_equiv (fun _ _ => rfl) replyPtr none + | cons _ tl => + cases tl with + | nil => + simp only [holTl, holCaseList, List.tail_cons, holBind_kbind_return_left] + exact setReplyObjRef_equiv (fun _ _ => rfl) replyPtr none + | cons r' _ => + simp only [holTl, holCaseList, List.tail_cons] + exact mrel_kbind (setReplyObjRef_equiv (fun _ _ => rfl) r' (some scPtr)) + (setReplyObjRef_equiv (fun _ _ => rfl) replyPtr none) + · refine mrel_kbind (mrel_assert (by simp [holEq_eq_true, embReply])) ?_ + exact updateSchedContext_equiv (fun sc => by + simp only [embSchedContext, Structures_A.sched_context.sc_replies_update, + Fl4Spec.scRepliesUpdate, holListTakeWhile] + congr 1; congr 1; funext r + by_cases h : r = replyPtr <;> simp [h, holNot, holEq]) scPtr + +theorem replyUnlinkTcb_equiv (t r : ObjRef) : + MRel SR Eq + (IpcCancel_A.reply_unlink_tcb t r) (Fl4Spec.replyUnlinkTcb t r) := by + unfold IpcCancel_A.reply_unlink_tcb Fl4Spec.replyUnlinkTcb + refine mrel_bind (getReply_equiv r) fun rH rL hr => ?_ + subst hr + refine mrel_kbind (mrel_assert (by simp [holEq_eq_true, embReply])) ?_ + refine mrel_bind (getThreadState_equiv t) fun tsH tsL hts => ?_ + subst hts + have hcond : holDisj (holEq tsH (.BlockedOnReply r)) + (holEx fun ep => holEx fun d => holEq tsH (.BlockedOnReceive ep (some r) d)) = true ↔ + (embThreadState tsH = .blockedOnReply r ∨ + ∃ ep d, embThreadState tsH = .blockedOnReceive ep (some r) d) := by + simp only [holDisj_eq_true, holEx_eq_true, holEq_eq_true] + cases tsH with + | BlockedOnReply r' => simp [embThreadState] + | BlockedOnReceive ep ro d => + simp only [embThreadState, reduceCtorEq, false_or, ThreadState.blockedOnReceive.injEq, + Structures_A.thread_state.BlockedOnReceive.injEq] + constructor + · rintro ⟨ep', d', rfl, rfl, rfl⟩; exact ⟨ep, embReceiverPayload d, rfl, rfl, rfl⟩ + · rintro ⟨ep', d', rfl, rfl, h⟩; exact ⟨ep, d, rfl, rfl, rfl⟩ + | _ => simp [embThreadState] + refine mrel_kbind (mrel_assert hcond) ?_ + refine mrel_kbind (setReplyObjRef_equiv (fun _ _ => rfl) r none) ?_ + exact setThreadState_equiv t .Inactive + +theorem scWithReply_eq {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (r : ObjRef) : + Fl4Spec.scWithReply r sL = IpcCancel_A.sc_with_reply r sH := by + unfold Fl4Spec.scWithReply IpcCancel_A.sc_with_reply + have hrel := partialInv_rel (e := id) (bH := true) (bL := true) + (fH := fun sc_ptr => holEx fun sc => holEx fun n => + holConj (holEq (sH.kheap sc_ptr) (some (.SchedContext sc n))) + (holMember r (holListSet sc.sc_replies))) + (fL := fun scPtr => decide (∃ sc n, sL.kheap scPtr = some (.schedContext sc n) ∧ r ∈ sc.scReplies)) + (fun scPtr => by + simp only [id_eq, holEx_eq_true, holConj_eq_true, holEq_eq_true, holMember_eq_true, + holListSet_eq, decide_eq_true_eq, hs.kheap_eq scPtr] + constructor + · rintro ⟨sc, n, hkh, hmem⟩ + exact ⟨embSchedContext sc, n, by simp [hkh, embKernelObject], hmem⟩ + · rintro ⟨scL, n, hkh, hmem⟩ + cases h0 : sH.kheap scPtr with + | none => simp [h0] at hkh + | some ko => + cases ko with + | SchedContext scH nH => + simp only [h0, Option.map_some, Option.some.injEq, embKernelObject, + KernelObject.schedContext.injEq] at hkh + rcases hkh with ⟨rfl, rfl⟩ + exact ⟨scH, nH, rfl, hmem⟩ + | _ => simp [h0, embKernelObject] at hkh) + (fun _ _ _ _ h => h) + (fun aL _ => ⟨aL, rfl⟩) + rw [optRel_funRel] at hrel + simpa using hrel + +theorem replyRemove_equiv (hop : OpaqueRel RestRel) (caller r : ObjRef) : + MRel SR Eq + (IpcCancel_A.reply_remove caller r) (Fl4Spec.replyRemove caller r) := by + unfold IpcCancel_A.reply_remove Fl4Spec.replyRemove + refine mrel_bind (getReply_equiv r) fun rH rL hr => ?_ + subst hr + refine mrel_kbind (mrel_assert (by simp [holEq_eq_true, embReply])) ?_ + refine mrel_bind (mrel_gets fun _ _ hs => (scWithReply_eq hs r).symm) fun oH oL ho => ?_ + subst ho + cases oH with + | none => + simp only [holCaseOption_none, holBind_kbind_return_left] + exact replyUnlinkTcb_equiv caller r + | some scPtr => + simp only [holCaseOption_some, KHeap.holBind_assoc, holKBind_eq] + refine mrel_bind (mrel_liftM (Rb := Eq) (fun scH scL hsc => by subst hsc; rfl) (getSchedContext_equiv scPtr)) + fun rsH rsL hrs => ?_ + subst hrs + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) caller) fun csH csL hcs => ?_ + subst hcs + refine mrel_bind (replyUnlinkSc_equiv scPtr r) fun _ _ _ => ?_ + have hhd : holHd rsH = the rsH.head? := by cases rsH <;> rfl + refine mrel_bind (mrel_when (by simp [holConj_eq_true, holEq_eq_true, hhd]) fun _ => + schedContextDonate_equiv hop scPtr caller) fun _ _ _ => ?_ + exact replyUnlinkTcb_equiv caller r + +theorem replyRemoveTcb_equiv (tptr rptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.reply_remove_tcb tptr rptr) (Fl4Spec.replyRemoveTcb tptr rptr) := by + unfold IpcCancel_A.reply_remove_tcb Fl4Spec.replyRemoveTcb + refine mrel_bind (getThreadState_equiv tptr) fun tsH tsL hts => ?_ + subst hts + refine mrel_kbind (mrel_assert (by + cases tsH <;> simp [holEq_eq_true, embThreadState])) ?_ + refine mrel_bind (mrel_gets fun _ _ hs => (scWithReply_eq hs rptr).symm) fun oH oL ho => ?_ + subst ho + cases oH with + | none => + simp only [holCaseOption_none, holBind_kbind_return_left] + exact replyUnlinkTcb_equiv tptr rptr + | some scPtr => + simp only [holCaseOption_some, KHeap.holBind_assoc, holKBind_eq] + refine mrel_bind (mrel_liftM (Rb := Eq) (fun scH scL hsc => by subst hsc; rfl) (getSchedContext_equiv scPtr)) + fun rsH rsL hrs => ?_ + subst hrs + refine mrel_bind (getReplyObjRef_equiv (fun _ => rfl) rptr) fun rscH rscL hrsc => ?_ + subst hrsc + have hhd : holHd rsH = the rsH.head? := by cases rsH <;> rfl + have ha : holIf (holEq (holHd rsH) rptr) (holEq rscH (some scPtr)) (holEq rscH none) = true ↔ + (if the rsH.head? = rptr then rscH = some scPtr else rscH = none) := by + rw [← hhd] + by_cases h : holHd rsH = rptr <;> simp [h, holIf_eq, holEq_eq_true] + refine mrel_bind (mrel_assert ha) fun _ _ _ => ?_ + refine mrel_bind (updateSchedContext_equiv (fun sc => by + simp only [embSchedContext, Structures_A.sched_context.sc_replies_update, + Fl4Spec.scRepliesUpdate, holListTakeWhile] + congr 1; congr 1; funext r + by_cases h : r = rptr <;> simp [h, holNot, holEq]) scPtr) fun _ _ _ => ?_ + refine mrel_bind (setReplyObjRef_equiv (fun _ _ => rfl) rptr none) fun _ _ _ => ?_ + exact replyUnlinkTcb_equiv tptr rptr + +theorem noReplyInTs_equiv (tptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.no_reply_in_ts tptr) (Fl4Spec.noReplyInTs tptr) := by + unfold IpcCancel_A.no_reply_in_ts Fl4Spec.noReplyInTs + refine mrel_bind (getThreadState_equiv tptr) fun tsH tsL hts => ?_ + subst hts + cases tsH with + | BlockedOnReceive _ r _ => + exact mrel_return (by cases r <;> simp [holEq]) + | _ => exact mrel_return rfl + +theorem bindScReply_equiv (scPtr replyPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.bind_sc_reply scPtr replyPtr) (Fl4Spec.bindScReply scPtr replyPtr) := by + unfold IpcCancel_A.bind_sc_reply Fl4Spec.bindScReply + refine mrel_bind (mrel_liftM (Rb := Eq) (fun scH scL hsc => by subst hsc; rfl) (getSchedContext_equiv scPtr)) + fun rsH rsL hrs => ?_ + subst hrs + cases rsH with + | nil => + simp only [holCaseList, holBind_kbind_return_left] + refine mrel_kbind (setScObjRef_equiv (fun _ _ => rfl) scPtr [replyPtr]) ?_ + exact setReplyObjRef_equiv (fun _ _ => rfl) replyPtr (some scPtr) + | cons r tl => + simp only [holCaseList] + refine mrel_kbind (setReplyObjRef_equiv (fun _ _ => rfl) r none) ?_ + refine mrel_kbind (setScObjRef_equiv (fun _ _ => rfl) scPtr (replyPtr :: r :: tl)) ?_ + exact setReplyObjRef_equiv (fun _ _ => rfl) replyPtr (some scPtr) + +theorem replyPush_equiv (hop : OpaqueRel RestRel) (caller callee replyPtr : ObjRef) + (canDonate : Bool) : + MRel SR Eq + (IpcCancel_A.reply_push caller callee replyPtr canDonate) + (Fl4Spec.replyPush caller callee replyPtr canDonate) := by + unfold IpcCancel_A.reply_push Fl4Spec.replyPush + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) caller) fun scH scL hsc => ?_ + subst hsc + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) callee) fun ccH ccL hcc => ?_ + subst hcc + refine mrel_kbind (setReplyObjRef_equiv (fun _ _ => rfl) replyPtr (some caller)) ?_ + refine mrel_kbind (setThreadState_equiv caller (.BlockedOnReply replyPtr)) ?_ + refine mrel_when (by simp [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true]) fun _ => ?_ + have hthe : holTheOpt scH = the scH := by cases scH <;> rfl + rw [hthe] + exact mrel_kbind (bindScReply_equiv (the scH) replyPtr) + (schedContextDonate_equiv hop (the scH) callee) + +theorem tcbEpDequeue_equiv (tptr epPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.tcb_ep_dequeue tptr epPtr) (Fl4Spec.tcbEpDequeue tptr epPtr) := by + unfold IpcCancel_A.tcb_ep_dequeue Fl4Spec.tcbEpDequeue + refine mrel_bind (getEndpoint_equiv epPtr) fun epH epL hep => ?_ + subst hep + refine mrel_bind (mrel_return (epQueue_eq epH).symm) fun qH qL hq => ?_ + subst hq + refine mrel_kbind (mrel_assert (by simp [holMember_eq_true, holListSet_eq])) ?_ + refine mrel_bind (mrel_return (removeAll_eq tptr qH).symm) fun q'H q'L hq' => ?_ + subst hq' + refine mrel_bind (Ra := FunRel embEndpoint) ?_ fun ep'H ep'L hep' => by + subst hep'; exact setEndpoint_equiv epPtr ep'H + cases q'H with + | nil => exact mrel_return rfl + | cons a as => exact mrel_return (updateEpQueue_eq epH (a :: as) true) + +theorem tcbNtfnDequeue_equiv (tptr ntfnPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.tcb_ntfn_dequeue tptr ntfnPtr) (Fl4Spec.tcbNtfnDequeue tptr ntfnPtr) := by + unfold IpcCancel_A.tcb_ntfn_dequeue Fl4Spec.tcbNtfnDequeue + refine mrel_bind (getNotification_equiv ntfnPtr) fun nH nL hn => ?_ + subst hn + refine mrel_bind (mrel_return (ntfnQueueOf_eq nH).symm) fun qH qL hq => ?_ + subst hq + refine mrel_kbind (mrel_assert (by simp [holMember_eq_true, holListSet_eq])) ?_ + refine mrel_bind (mrel_return (removeAll_eq tptr qH).symm) fun q'H q'L hq' => ?_ + subst hq' + refine mrel_bind (Ra := FunRel embNotification) ?_ fun n'H n'L hn' => by + subst hn'; exact setNotification_equiv ntfnPtr n'H + cases q'H <;> exact mrel_return rfl + +theorem orderedInsert_equiv {α β : Type} [Nonempty α] [Nonempty β] + (t : α) (ts : List α) + {fH : α → HolLookup (Structures_A.state ZH) β} + {fL : α → Lookup (State ZL) β} + (hf : ∀ x, LookupRel SR Eq (fH x) (fL x)) + {RH : β → β → Bool} {RL : β → β → Prop} + (hR : ∀ x y, RH x y = decide (RL x y)) : + MRel SR Eq + (IpcCancel_A.ordered_insert t ts fH RH) + (Fl4Spec.orderedInsert t ts fL RL) := by + unfold IpcCancel_A.ordered_insert Fl4Spec.orderedInsert + refine mrel_bind (mrel_getsThe (hf t)) fun vH vL hv => ?_ + subst hv + refine mrel_bind (mrel_mapM (fun xH xL hx => by subst hx; exact mrel_getsThe (hf xH)) + (listRel_eq ts)) fun vsH vsL hvs => ?_ + have hvs' : vsH = vsL := by + induction hvs with + | nil => rfl + | cons h _ ih => subst h; rw [ih] + cases hvs' + refine mrel_bind (mrel_return (aH := holListZip ts vsH) rfl) fun zH zL hz => ?_ + subst hz + have htw : (zH.takeWhile (fun (_, val') => decide (RL val' vH)) ++ [(t, vH)] ++ + zH.dropWhile (fun (_, val') => decide (RL val' vH))) = + holListAppend (holListTakeWhile (holCaseProd fun _ val' => RH val' vH) zH) + (holListAppend [(t, vH)] (holListDropWhile (holCaseProd fun _ val' => RH val' vH) zH)) := by + have hpred : (fun p : α × β => decide (RL p.2 vH)) = + (holCaseProd fun (_ : α) (val' : β) => RH val' vH) := by + funext ⟨_, val'⟩; simp [holCaseProd_eq, hR] + simp [holListAppend, holListTakeWhile, holListDropWhile, hpred, List.append_assoc] + refine mrel_bind (mrel_return htw.symm) fun z'H z'L hz' => ?_ + subst hz' + exact mrel_return (by simp [holListMap_eq]) + +theorem tcbAppend_equiv (tptr : ObjRef) (qs : List ObjRef) : + MRel SR Eq + (IpcCancel_A.tcb_append tptr qs) (Fl4Spec.tcbAppend tptr qs) := by + unfold IpcCancel_A.tcb_append Fl4Spec.tcbAppend + refine orderedInsert_equiv (β := BitVec 8) tptr qs ?_ (fun x y => by + unfold holLe HolOrd.leVal instHolOrdBitVec + by_cases h : y ≤ x <;> simp [h]) + intro x + have h := threadRead_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + (fH := Structures_A.tcb_ext.tcb_priority) (fL := Tcb.tcbPriority) (fun _ => rfl) x + exact h + +theorem tcbEpAppend_equiv (tptr epPtr : ObjRef) (isRecv : Bool) : + MRel SR Eq + (IpcCancel_A.tcb_ep_append tptr epPtr isRecv) + (Fl4Spec.tcbEpAppend tptr epPtr isRecv) := by + unfold IpcCancel_A.tcb_ep_append Fl4Spec.tcbEpAppend + refine mrel_bind (getEndpoint_equiv epPtr) fun epH epL hep => ?_ + subst hep + refine mrel_bind (mrel_return (epQueue_eq epH).symm) fun qH qL hq => ?_ + subst hq + refine mrel_bind (tcbAppend_equiv tptr qH) fun q'H q'L hq' => ?_ + subst hq' + rw [updateEpQueue_eq] + exact setEndpoint_equiv epPtr _ + +theorem tcbNtfnAppend_equiv (tptr ntfnPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.tcb_ntfn_append tptr ntfnPtr) + (Fl4Spec.tcbNtfnAppend tptr ntfnPtr) := by + unfold IpcCancel_A.tcb_ntfn_append Fl4Spec.tcbNtfnAppend + refine mrel_bind (getNotification_equiv ntfnPtr) fun nH nL hn => ?_ + subst hn + refine mrel_bind (mrel_return (ntfnQueueOf_eq nH).symm) fun qH qL hq => ?_ + subst hq + refine mrel_bind (tcbAppend_equiv tptr qH) fun q'H q'L hq' => ?_ + subst hq' + exact setNotification_equiv ntfnPtr _ + +theorem reorderEp_equiv (epPtr tptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.reorder_ep epPtr tptr) (Fl4Spec.reorderEp epPtr tptr) := by + unfold IpcCancel_A.reorder_ep Fl4Spec.reorderEp + refine mrel_bind (getEndpoint_equiv epPtr) fun epH epL hep => ?_ + subst hep + refine mrel_kbind (mrel_assert (by cases epH <;> simp [holNot, holEq, embEndpoint])) ?_ + refine mrel_bind (mrel_return (epQueue_eq epH).symm) fun qH qL hq => ?_ + subst hq + refine mrel_kbind (mrel_assert (by simp [holNot_eq_true, ne_eq, holEq_eq_true])) ?_ + refine mrel_bind (mrel_return (removeAll_eq tptr qH).symm) fun q'H q'L hq' => ?_ + subst hq' + refine mrel_bind (tcbAppend_equiv tptr q'H) fun q''H q''L hq'' => ?_ + subst hq'' + rw [updateEpQueue_eq] + exact setEndpoint_equiv epPtr _ + +theorem reorderNtfn_equiv (ntfnPtr tptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.reorder_ntfn ntfnPtr tptr) (Fl4Spec.reorderNtfn ntfnPtr tptr) := by + unfold IpcCancel_A.reorder_ntfn Fl4Spec.reorderNtfn + refine mrel_bind (getNotification_equiv ntfnPtr) fun nH nL hn => ?_ + subst hn + refine mrel_kbind (mrel_assert (by simp [embNotification, ntfn_isWaitingNtfn_eq])) ?_ + refine mrel_bind (mrel_return (ntfnQueueOf_eq nH).symm) fun qH qL hq => ?_ + subst hq + refine mrel_kbind (mrel_assert (by simp [holNot_eq_true, ne_eq, holEq_eq_true])) ?_ + refine mrel_bind (mrel_return (removeAll_eq tptr qH).symm) fun q'H q'L hq' => ?_ + subst hq' + refine mrel_bind (tcbAppend_equiv tptr q'H) fun q''H q''L hq'' => ?_ + subst hq'' + exact setNotification_equiv ntfnPtr _ + +theorem setPriority_equiv (hop : OpaqueRel RestRel) (tptr : ObjRef) (prio : Priority) : + MRel SR Eq + (IpcCancel_A.set_priority tptr prio) (Fl4Spec.setPriority tptr prio) := by + unfold IpcCancel_A.set_priority Fl4Spec.setPriority + refine mrel_bind (getThreadState_equiv tptr) fun tsH tsL hts => ?_ + subst hts + refine mrel_if (by simp [runnable_eq]) (fun _ => ?_) (fun _ => ?_) + · refine mrel_bind (threadGet_equiv (fun _ => rfl) tptr) fun dH dL hd => ?_ + subst hd + refine mrel_bind (threadGet_equiv (fun _ => rfl) tptr) fun pH pL hp => ?_ + subst hp + refine mrel_bind (getTcbQueue_equiv dH pH) fun qH qL hq => ?_ + subst hq + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun cH cL hc => ?_ + subst hc + refine mrel_if (by simp [holDisj_eq_true, holMember_eq_true, holListSet_eq, holEq_eq_true]) + (fun _ => ?_) (fun _ => threadSetPriority_equiv tptr prio) + refine mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq tptr) ?_ + refine mrel_kbind (threadSetPriority_equiv tptr prio) ?_ + refine mrel_kbind (tcbSchedAction_equiv tcbSchedEnqueue_eq tptr) ?_ + exact rescheduleRequired_equiv hop + · refine mrel_kbind (threadSetPriority_equiv tptr prio) ?_ + refine mrel_kbind (Ra := Eq) ?_ ?_ + · rw [epBlocked_eq] + cases IpcCancel_A.ep_blocked tsH with + | none => exact mrel_return rfl + | some ep => exact reorderEp_equiv ep tptr + · rw [ntfnBlocked_eq] + cases IpcCancel_A.ntfn_blocked tsH with + | none => exact mrel_return rfl + | some ntfn => exact reorderNtfn_equiv ntfn tptr + +theorem restartThreadIfNoFault_equiv (hop : OpaqueRel RestRel) (t : ObjRef) : + MRel SR Eq + (IpcCancel_A.restart_thread_if_no_fault t) + (Fl4Spec.restartThreadIfNoFault t) := by + unfold IpcCancel_A.restart_thread_if_no_fault Fl4Spec.restartThreadIfNoFault + refine mrel_bind (threadGet_equiv (Ra := OptRel (FunRel embFault)) + (fun tcb => by rw [optRel_funRel]; rfl) t) fun fH fL hf => ?_ + have hnone : holEq fH none = true ↔ fL = none := by + rw [optRel_funRel] at hf; rw [hf]; cases fH <;> simp [holEq] + refine mrel_if hnone (fun _ => ?_) (fun _ => setThreadState_equiv t .Inactive) + refine mrel_kbind (setThreadState_equiv t .Restart) ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) t) fun scH scL hsc => ?_ + subst hsc + refine mrel_kbind (ifSporadicCurScAssertRefillUnblockCheck_equiv scH) ?_ + exact possibleSwitchTo_equiv hop t + +theorem removeAndRestartEpQueuedThread_equiv (hop : OpaqueRel RestRel) (t epptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.remove_and_restart_ep_queued_thread t epptr) + (Fl4Spec.removeAndRestartEpQueuedThread t epptr) := by + unfold IpcCancel_A.remove_and_restart_ep_queued_thread Fl4Spec.removeAndRestartEpQueuedThread + refine mrel_kbind (tcbEpDequeue_equiv t epptr) ?_ + refine mrel_bind (getThreadState_equiv t) fun tsH tsL hts => ?_ + subst hts + have hro : (if Fl4Spec.isBlockedOnReceive (embThreadState tsH) then + Fl4Spec.replyObject (embThreadState tsH) else none) = + holIf (Structures_A.is_blocked_on_receive tsH) (Structures_A.reply_object tsH) none := by + cases tsH <;> simp [Fl4Spec.isBlockedOnReceive, Structures_A.is_blocked_on_receive, + Fl4Spec.replyObject, Structures_A.reply_object, embThreadState, holIf_eq, + holEx_eq_true, holEq_eq_true] + refine mrel_bind (mrel_return hro.symm) fun rH rL hr => ?_ + subst hr + refine mrel_kbind (mrel_maybeM (Ra := Eq) (fun rH rL hr => by + subst hr; exact replyUnlinkTcb_equiv t rH) (by cases rH <;> simp [OptRel])) + (restartThreadIfNoFault_equiv hop t) + +theorem cancelAllIpc_equiv (hop : OpaqueRel RestRel) (epptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.cancel_all_ipc epptr) (Fl4Spec.cancelAllIpc epptr) := by + unfold IpcCancel_A.cancel_all_ipc Fl4Spec.cancelAllIpc + refine mrel_bind (getEndpoint_equiv epptr) fun epH epL hep => ?_ + subst hep + cases epH with + | IdleEP => exact mrel_return rfl + | SendEP q => + simp only [Structures_A.case_endpoint, embEndpoint] + refine mrel_bind (Ra := Eq) (mrel_return rfl) fun qH qL hq => ?_ + subst hq + exact mrel_kbind + (mrel_mapMx (Ra := Eq) (Rb := Eq) (fun tH tL ht => by subst ht; exact removeAndRestartEpQueuedThread_equiv hop tH epptr) + (listRel_eq qH)) + (rescheduleRequired_equiv hop) + | RecvEP q => + simp only [Structures_A.case_endpoint, embEndpoint] + refine mrel_bind (Ra := Eq) (mrel_return rfl) fun qH qL hq => ?_ + subst hq + exact mrel_kbind + (mrel_mapMx (Ra := Eq) (Rb := Eq) (fun tH tL ht => by subst ht; exact removeAndRestartEpQueuedThread_equiv hop tH epptr) + (listRel_eq qH)) + (rescheduleRequired_equiv hop) + +theorem removeAndRestartBadgedThread_equiv (hop : OpaqueRel RestRel) (t epptr : ObjRef) + (badge : Badge) : + MRel SR Eq + (IpcCancel_A.remove_and_restart_badged_thread t epptr badge) + (Fl4Spec.removeAndRestartBadgedThread t epptr badge) := by + unfold IpcCancel_A.remove_and_restart_badged_thread Fl4Spec.removeAndRestartBadgedThread + refine mrel_bind (getThreadState_equiv t) fun tsH tsL hts => ?_ + subst hts + refine mrel_when (by simp [holEq_eq_true, blockingIpcBadge_eq]) fun _ => ?_ + exact mrel_kbind (tcbEpDequeue_equiv t epptr) (restartThreadIfNoFault_equiv hop t) + +theorem cancelBadgedSends_equiv (hop : OpaqueRel RestRel) (epptr : ObjRef) (badge : Badge) : + MRel SR Eq + (IpcCancel_A.cancel_badged_sends epptr badge) + (Fl4Spec.cancelBadgedSends epptr badge) := by + unfold IpcCancel_A.cancel_badged_sends Fl4Spec.cancelBadgedSends + refine mrel_bind (getEndpoint_equiv epptr) fun epH epL hep => ?_ + subst hep + cases epH with + | SendEP q => + exact mrel_kbind + (mrel_mapMx (fun tH tL ht => by + subst ht; exact removeAndRestartBadgedThread_equiv hop tH epptr badge) (listRel_eq q)) + (rescheduleRequired_equiv hop) + | _ => exact mrel_return rfl + +theorem doUnbindNotification_equiv (ntfnptr tcbptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.do_unbind_notification ntfnptr tcbptr) + (Fl4Spec.doUnbindNotification ntfnptr tcbptr) := by + unfold IpcCancel_A.do_unbind_notification Fl4Spec.doUnbindNotification + exact mrel_kbind + (setNtfnObjRef_equiv (fun _ _ => rfl) ntfnptr none) + (setTcbObjRef_equiv (fun _ _ => rfl) tcbptr none) + +theorem unbindNotification_equiv (tcb : ObjRef) : + MRel SR Eq + (IpcCancel_A.unbind_notification tcb) (Fl4Spec.unbindNotification tcb) := by + unfold IpcCancel_A.unbind_notification Fl4Spec.unbindNotification + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) tcb) fun oH oL ho => ?_ + subst ho + cases oH with + | none => exact mrel_return rfl + | some nptr => exact doUnbindNotification_equiv nptr tcb + +theorem unbindMaybeNotification_equiv (ntfnptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.unbind_maybe_notification ntfnptr) + (Fl4Spec.unbindMaybeNotification ntfnptr) := by + unfold IpcCancel_A.unbind_maybe_notification Fl4Spec.unbindMaybeNotification + refine mrel_bind (getNtfnObjRef_equiv (fun _ => rfl) ntfnptr) fun oH oL ho => ?_ + subst ho + cases oH with + | none => exact mrel_return rfl + | some t => exact doUnbindNotification_equiv ntfnptr t + +theorem removeAndRestartNtfnQueuedThread_equiv (hop : OpaqueRel RestRel) (t ntfnptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.remove_and_restart_ntfn_queued_thread t ntfnptr) + (Fl4Spec.removeAndRestartNtfnQueuedThread t ntfnptr) := by + unfold IpcCancel_A.remove_and_restart_ntfn_queued_thread Fl4Spec.removeAndRestartNtfnQueuedThread + refine mrel_kbind (tcbNtfnDequeue_equiv t ntfnptr) ?_ + refine mrel_kbind (setThreadState_equiv t .Restart) ?_ + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) t) fun scH scL hsc => ?_ + subst hsc + refine mrel_kbind (ifSporadicCurScAssertRefillUnblockCheck_equiv scH) ?_ + exact possibleSwitchTo_equiv hop t + +theorem cancelAllSignals_equiv (hop : OpaqueRel RestRel) (ntfnptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.cancel_all_signals ntfnptr) (Fl4Spec.cancelAllSignals ntfnptr) := by + unfold IpcCancel_A.cancel_all_signals Fl4Spec.cancelAllSignals + refine mrel_bind (getNotification_equiv ntfnptr) fun nH nL hn => ?_ + subst hn + rcases nH with ⟨nobj, nbound, nsc, nmore⟩ + cases nobj with + | WaitingNtfn q => + exact mrel_kbind + (mrel_mapMx (Ra := Eq) (Rb := Eq) (fun tH tL ht => by + subst ht; exact removeAndRestartNtfnQueuedThread_equiv hop tH ntfnptr) (listRel_eq q)) + (rescheduleRequired_equiv hop) + | _ => exact mrel_return rfl + +theorem getBlockingObject_equiv (state : Structures_A.thread_state) : + MRel SR Eq + (IpcCancel_A.get_blocking_object state) + (Fl4Spec.getBlockingObject (embThreadState state)) := by + unfold IpcCancel_A.get_blocking_object Fl4Spec.getBlockingObject + rw [epBlocked_eq] + exact mrel_assertOpt (Ra := Eq) (by cases IpcCancel_A.ep_blocked state <;> simp [OptRel]) + +theorem blockedCancelIpc_equiv (state : Structures_A.thread_state) (tptr : ObjRef) + (replyOpt : Option ObjRef) : + MRel SR Eq + (IpcCancel_A.blocked_cancel_ipc state tptr replyOpt) + (Fl4Spec.blockedCancelIpc (embThreadState state) tptr replyOpt) := by + unfold IpcCancel_A.blocked_cancel_ipc Fl4Spec.blockedCancelIpc + refine mrel_bind (getBlockingObject_equiv state) fun epH epL hep => ?_ + subst hep + refine mrel_kbind (tcbEpDequeue_equiv tptr epH) ?_ + cases replyOpt with + | none => + simp only [holCaseOption_none, holBind_kbind_return_left] + exact setThreadState_equiv tptr .Inactive + | some r => + simp only [holCaseOption_some] + exact mrel_kbind (replyUnlinkTcb_equiv tptr r) (setThreadState_equiv tptr .Inactive) + + +theorem schedContextUnbindAllTcbs_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel SR Eq + (IpcCancel_A.sched_context_unbind_all_tcbs scPtr) + (Fl4Spec.schedContextUnbindAllTcbs scPtr) := by + unfold IpcCancel_A.sched_context_unbind_all_tcbs Fl4Spec.schedContextUnbindAllTcbs + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + intro sH sL hs + change MRelStep SR Eq _ (NonDet.bind (NonDet.gets (fun s : State ZL => s.idleSc)) _ sL) + rw [nonDet_bind_gets_at] + exact (mrel_when (by simp [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true, + embSchedContext, hs.idleSc_eq]) fun _ => schedContextUnbindTcb_equiv hop scPtr) sH sL hs + +theorem cancelSignal_equiv (threadptr ntfnptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.cancel_signal threadptr ntfnptr) + (Fl4Spec.cancelSignal threadptr ntfnptr) := by + unfold IpcCancel_A.cancel_signal Fl4Spec.cancelSignal + exact mrel_kbind (tcbNtfnDequeue_equiv threadptr ntfnptr) + (setThreadState_equiv threadptr .Inactive) + +theorem cancelIpc_equiv (tptr : ObjRef) : + MRel SR Eq + (IpcCancel_A.cancel_ipc tptr) (Fl4Spec.cancelIpc tptr) := by + unfold IpcCancel_A.cancel_ipc Fl4Spec.cancelIpc + refine mrel_bind (getThreadState_equiv tptr) fun tsH tsL hts => ?_ + subst hts + refine mrel_kbind (threadSet_equiv (fun _ => rfl) tptr) ?_ + cases tsH with + | BlockedOnSend _ _ => exact blockedCancelIpc_equiv _ tptr none + | BlockedOnReceive _ reply _ => exact blockedCancelIpc_equiv _ tptr reply + | BlockedOnNotification event => exact cancelSignal_equiv tptr event + | BlockedOnReply reply => exact replyRemoveTcb_equiv tptr reply + | _ => exact mrel_return rfl + +end IpcCancelMonad + +end + +end L4vRefX64.Equiv.IpcCancel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/KHeap.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/KHeap.lean new file mode 100644 index 000000000..3836c233e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/KHeap.lean @@ -0,0 +1,1270 @@ +import L4vRefX64.Rel.Lift +import L4vRefX64.Equiv.Machine +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Equiv.Structures +import L4vRefX64.Equiv.Deterministic + +namespace L4vRefX64.Equiv.KHeap + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec +open L4vRefX64.Equiv.Machine +open L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.Deterministic +open Fl4Spec +open Classical + +noncomputable section + +theorem minBudget_eq {RestRel} (hop : OpaqueRel RestRel) : Fl4Spec.MIN_BUDGET = Structures_A.MIN_BUDGET := by + unfold Fl4Spec.MIN_BUDGET Structures_A.MIN_BUDGET Fl4Spec.kernelWCETTicks Time.kernelWCET_ticks + rw [hop.kernelWCETUs_eq, usToTicks_eq hop] + rfl + +/-! ## KHeap_A: Pure Projections & Helpers -/ + +theorem tcbOf_eq (ko : Structures_A.kernel_object) : + Fl4Spec.tcbOf (embKernelObject ko) = (KHeap_A.tcb_of ko).map embTcb := by + cases ko <;> rfl + +theorem scFieldsOf_eq (ko : Structures_A.kernel_object) : + Fl4Spec.scFieldsOf (embKernelObject ko) = + (KHeap_A.sc_fields_of ko).map (fun (sc, n) => (embSchedContext sc, n)) := by + cases ko <;> rfl + +theorem scOf_eq (ko : Structures_A.kernel_object) : + Fl4Spec.scOf (embKernelObject ko) = (KHeap_A.sc_of ko).map embSchedContext := by + cases ko <;> rfl + +theorem cnodeOf_eq (ko : Structures_A.kernel_object) : + Fl4Spec.cnodeOf (embKernelObject ko) = + (KHeap_A.cnode_of ko).map (fun (sz, cn) => (sz, embCnodeContents cn)) := by + cases ko <;> rfl + +theorem isSimpleType_iff (ko : Structures_A.kernel_object) : + KHeap_A.is_simple_type ko = true ↔ Fl4Spec.isSimpleType (embKernelObject ko) := by + unfold KHeap_A.is_simple_type Fl4Spec.isSimpleType + rw [aType_eq] + cases Structures_A.a_type ko <;> simp [embAType, holInsert_eq] + +theorem ntfnSetBoundTcb_eq (n : Structures_A.notification) (t : Option ObjRef) : + Fl4Spec.ntfnSetBoundTcb (embNotification n) t = + embNotification (KHeap_A.ntfn_set_bound_tcb n t) := rfl + +theorem ntfnSetObj_eq (n : Structures_A.notification) (a : Structures_A.ntfn) : + Fl4Spec.ntfnSetObj (embNotification n) (embNtfn a) = + embNotification (KHeap_A.ntfn_set_obj n a) := rfl + +theorem activeSc_eq (n : Nat) : Fl4Spec.activeSc n = KHeap_A.active_sc n := by + unfold Fl4Spec.activeSc KHeap_A.active_sc + apply Bool.eq_iff_iff.mpr + rw [holLt_eq_true] + change decide (0 < n) = true ↔ 0 < n + by_cases h : 0 < n <;> simp [h] + +theorem scActive_eq (sc : Structures_A.sched_context) : + Fl4Spec.scActive (embSchedContext sc) = KHeap_A.sc_active sc := + activeSc_eq sc.sc_refill_max + +theorem refillHd_eq (sc : Structures_A.sched_context) (hne : sc.sc_refills ≠ []) : + Fl4Spec.refillHd (embSchedContext sc) = embRefill (KHeap_A.refill_hd sc) := by + cases h : sc.sc_refills with + | nil => exact absurd h hne + | cons r rs => simp [Fl4Spec.refillHd, KHeap_A.refill_hd, embSchedContext, h, holHd, the] + +theorem refillTl_eq (sc : Structures_A.sched_context) (hne : sc.sc_refills ≠ []) : + Fl4Spec.refillTl (embSchedContext sc) = embRefill (KHeap_A.refill_tl sc) := by + unfold Fl4Spec.refillTl KHeap_A.refill_tl + simp only [embSchedContext] + generalize sc.sc_refills = rs at hne ⊢ + induction rs with + | nil => exact absurd rfl hne + | cons x xs ih => + cases xs with + | nil => simp [holLast, holTheOpt, the] + | cons y ys => + have hne' : y :: ys ≠ [] := List.cons_ne_nil y ys + simpa [holLast, List.getLast?_cons_cons] using ih hne' + +theorem refillCapacity_eq (usage : Time) (r : Structures_A.refill) : + Fl4Spec.refillCapacity usage (embRefill r) = KHeap_A.refill_capacity usage r := by + unfold Fl4Spec.refillCapacity KHeap_A.refill_capacity + simp only [embRefill, holIf_eq, holLt_eq_true, HolOrd.ltVal, HolZero.zeroVal, HolSub.subVal] + rfl + +theorem refillSufficient_eq {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (usage : Time) (r : Structures_A.refill) : + Fl4Spec.refillSufficient usage (embRefill r) = KHeap_A.refill_sufficient usage r := by + unfold Fl4Spec.refillSufficient KHeap_A.refill_sufficient + rw [refillCapacity_eq, minBudget_eq hop] + apply Bool.eq_iff_iff.mpr + rw [holLe_eq_true] + change decide (Structures_A.MIN_BUDGET ≤ KHeap_A.refill_capacity usage r) = true ↔ + Structures_A.MIN_BUDGET ≤ KHeap_A.refill_capacity usage r + by_cases h : Structures_A.MIN_BUDGET ≤ KHeap_A.refill_capacity usage r <;> simp [h] + +theorem refillReady'_eq (usage curtime : Time) (r : Structures_A.refill) : + Fl4Spec.refillReady' usage curtime (embRefill r) = KHeap_A.refill_ready' usage curtime r := by + unfold Fl4Spec.refillReady' KHeap_A.refill_ready' + apply Bool.eq_iff_iff.mpr + rw [holLe_eq_true] + change decide (r.r_time + usage ≤ curtime) = true ↔ r.r_time + usage ≤ curtime + by_cases h : r.r_time + usage ≤ curtime <;> simp [h] + +theorem refillReady_eq (curtime : Time) (r : Structures_A.refill) : + Fl4Spec.refillReady curtime (embRefill r) = KHeap_A.refill_ready curtime r := by + unfold Fl4Spec.refillReady KHeap_A.refill_ready + exact refillReady'_eq 0 curtime r + +theorem scReleased_eq (curtime : Time) (sc : Structures_A.sched_context) + (hne : sc.sc_refills ≠ []) : + Fl4Spec.scReleased curtime (embSchedContext sc) = KHeap_A.sc_released curtime sc := by + unfold Fl4Spec.scReleased KHeap_A.sc_released + rw [scActive_eq, KHeap_A.sc_active, refillHd_eq sc hne, KHeap_A.refill_hd, refillReady_eq, + KHeap_A.refill_ready] + cases KHeap_A.active_sc sc.sc_refill_max <;> simp [holConj] + +theorem tcbSchedEnqueue_eq (t : ObjRef) (q : List ObjRef) : + Fl4Spec.tcbSchedEnqueue t q = KHeap_A.tcb_sched_enqueue t q := by + unfold Fl4Spec.tcbSchedEnqueue KHeap_A.tcb_sched_enqueue + simp only [holIf_eq, holNot_eq_true, ne_eq, holMember_eq_true, holListSet_eq, Set.mem_ofPred_eq] + +theorem tcbSchedAppend_eq (t : ObjRef) (q : List ObjRef) : + Fl4Spec.tcbSchedAppend t q = KHeap_A.tcb_sched_append t q := by + unfold Fl4Spec.tcbSchedAppend KHeap_A.tcb_sched_append + simp only [holIf_eq, holNot_eq_true, ne_eq, holMember_eq_true, holListSet_eq, Set.mem_ofPred_eq, + holListAppend_eq] + +theorem tcbSchedDequeue_eq (t : ObjRef) (q : List ObjRef) : + Fl4Spec.tcbSchedDequeue t q = KHeap_A.tcb_sched_dequeue t q := by + unfold Fl4Spec.tcbSchedDequeue KHeap_A.tcb_sched_dequeue + simp only [holListFilter_eq] + congr 1; funext x + by_cases h : t = x <;> simp [h, holNot, holEq] + +/-! ## KHeap_A: State Projections & Monadic Operations -/ + +section KHeapMonad + +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 tcbsOf_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (p : ObjRef) : + Fl4Spec.tcbsOf sL p = (KHeap_A.tcbs_of sH p).map embTcb := by + unfold Fl4Spec.tcbsOf Fl4Spec.tcbsOfKh KHeap_A.tcbs_of KHeap_A.tcbs_of_kh + unfold Fl4Spec.optMap holOptMap + rw [hs.kheap_eq p] + cases sH.kheap p with + | none => rfl + | some ko => simp [tcbOf_eq] + +theorem scsFieldsOf_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (p : ObjRef) : + Fl4Spec.scsFieldsOf sL p = + (KHeap_A.scs_fields_of sH p).map (fun (sc, n) => (embSchedContext sc, n)) := by + unfold Fl4Spec.scsFieldsOf KHeap_A.scs_fields_of Fl4Spec.optMap holOptMap + rw [hs.kheap_eq p] + cases sH.kheap p with + | none => rfl + | some ko => simp [scFieldsOf_eq] + +theorem scsOf_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (p : ObjRef) : + Fl4Spec.scsOf sL p = (KHeap_A.scs_of sH p).map embSchedContext := by + unfold Fl4Spec.scsOf Fl4Spec.scsOfKh KHeap_A.scs_of KHeap_A.scs_of_kh + unfold Fl4Spec.optMap holOptMap + rw [hs.kheap_eq p] + cases sH.kheap p with + | none => rfl + | some ko => simp [scOf_eq] + +theorem holBind_return_left {σ α β : Type} (a : α) (f : α → HolNonDet σ β) : + holBind (holReturn a) f = f a := by + funext s + apply Prod.ext + · ext p + simp [holBind, holReturn] + · simp [holBind, holReturn] + +theorem holBind_assoc {σ α β γ : Type} + (m : HolNonDet σ α) (f : α → HolNonDet σ β) (g : β → HolNonDet σ γ) : + holBind (holBind m f) g = holBind m (fun a => holBind (f a) g) := by + funext s + apply Prod.ext + · ext p + simp only [holBind, Set.mem_ofPred_eq, Prod.exists] + constructor + · rintro ⟨b, s'', ⟨a, s', ha, hb⟩, hg⟩ + exact ⟨a, s', ha, b, s'', hb, hg⟩ + · rintro ⟨a, s', ha, b, s'', hb, hg⟩ + exact ⟨b, s'', ⟨a, s', ha, hb⟩, hg⟩ + · apply Bool.eq_iff_iff.mpr + simp only [holBind, decide_eq_true_eq, Prod.exists] + constructor + · rintro ((hm | ⟨a, s', ha, hf⟩) | ⟨b, s'', ⟨a, s', ha, hb⟩, hg⟩) + · exact Or.inl hm + · exact Or.inr ⟨a, s', ha, Or.inl hf⟩ + · exact Or.inr ⟨a, s', ha, Or.inr ⟨b, s'', hb, hg⟩⟩ + · rintro (hm | ⟨a, s', ha, (hf | ⟨b, s'', hb, hg⟩)⟩) + · exact Or.inl (Or.inl hm) + · exact Or.inl (Or.inr ⟨a, s', ha, hf⟩) + · exact Or.inr ⟨b, s'', ⟨a, s', ha, hb⟩, hg⟩ + +theorem lookup_bind {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : HolLookup σH αH} {fL : Lookup σL αL} + {gH : αH → HolLookup σH βH} {gL : αL → Lookup σL βL} + (hf : LookupRel Rs Ra fH fL) + (hg : ∀ aH aL, Ra aH aL → LookupRel Rs Rb (gH aH) (gL aL)) : + LookupRel Rs Rb (holOBind fH gH) (Bind.bind fL gL) := by + intro sH sL hs + have h := hf sH sL hs + change OptRel Rb (match fH sH with | none => none | some a => gH a sH) + (Option.bind (fL sL) (fun a => gL a sL)) + cases h1 : fH sH <;> cases h2 : fL sL <;> simp [h1, h2, OptRel] at h ⊢ + exact hg _ _ h sH sL hs + +theorem lookup_oassert' {σH σL : Type} {Rs : σH → σL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) : + LookupRel Rs Eq (holOAssert b) (Lookup.oassert P) := by + intro _ _ _ + unfold holOAssert holOReturn holOFail Lookup.oassert Lookup.oreturn Lookup.ofail + by_cases hp : P + · have hb : b = true := h.mpr hp; simp [hp, hb, OptRel] + · have hb : b ≠ true := fun h1 => hp (h.mp h1); simp [hp, hb, OptRel] + +theorem mask_eq {w : Nat} (n : Nat) : + Fl4Spec.mask (w := w) n = holWordMask (w := w) n := rfl + +theorem scSizesOf_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (p : ObjRef) : + Fl4Spec.scSizesOf sL p = KHeap_A.sc_sizes_of sH p := by + unfold Fl4Spec.scSizesOf KHeap_A.sc_sizes_of Fl4Spec.optMapSome Fl4Spec.optMap holOptMapSome + rw [scsFieldsOf_eq hs p] + cases KHeap_A.scs_fields_of sH p <;> rfl + +theorem cnodesOf_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (p : ObjRef) : + Fl4Spec.cnodesOf sL p = + (KHeap_A.cnodes_of sH p).map (fun (sz, cn) => (sz, embCnodeContents cn)) := by + unfold Fl4Spec.cnodesOf KHeap_A.cnodes_of Fl4Spec.optMap holOptMap + rw [hs.kheap_eq p] + cases sH.kheap p with + | none => rfl + | some ko => simp [cnodeOf_eq] + +theorem cnodeSizesOf_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (p : ObjRef) : + Fl4Spec.cnodeSizesOf sL p = KHeap_A.cnode_sizes_of sH p := by + unfold Fl4Spec.cnodeSizesOf KHeap_A.cnode_sizes_of Fl4Spec.optMapSome Fl4Spec.optMap holOptMapSome + rw [cnodesOf_eq hs p] + cases KHeap_A.cnodes_of sH p <;> rfl + +theorem cnodeContentsOf_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (p : ObjRef) : + Fl4Spec.cnodeContentsOf sL p = (KHeap_A.cnode_contents_of sH p).map embCnodeContents := by + unfold Fl4Spec.cnodeContentsOf KHeap_A.cnode_contents_of Fl4Spec.optMapSome Fl4Spec.optMap holOptMapSome + rw [cnodesOf_eq hs p] + cases KHeap_A.cnodes_of sH p <;> rfl + +theorem readObject_equiv (ptr : ObjRef) : + LookupRel SR (FunRel embKernelObject) + (KHeap_A.read_object ptr) (Fl4Spec.readObject ptr) := by + intro sH sL hs + rw [optRel_funRel] + exact hs.kheap_eq ptr + +theorem getObject_equiv (ptr : ObjRef) : + MRel SR (FunRel embKernelObject) + (KHeap_A.get_object ptr) (Fl4Spec.getObject ptr) := + mrel_getsThe (readObject_equiv ptr) + +omit [StateExt ZL] in +theorem getObject_member {s s' : Structures_A.state ZH} {ptr : ObjRef} + {obj : Structures_A.kernel_object} + (hm : (obj, s') ∈ (KHeap_A.get_object ptr s).1) : + s.kheap ptr = some obj ∧ s' = s := by + unfold KHeap_A.get_object KHeap_A.read_object holSwp at hm + cases hk : s.kheap ptr <;> simp_all [holGetsThe, holAssertOpt, holReturn, holFail] + +private theorem embAType_eq_iff (a b : Structures_A.a_type_T) : + embAType a = embAType b ↔ a = b := by + constructor + · intro h; cases a <;> cases b <;> simp [embAType] at h ⊢ <;> + first | exact h | exact embAAType_injective h + · rintro rfl; rfl + +theorem setObject_equiv (ptr : ObjRef) (obj : Structures_A.kernel_object) : + MRel SR Eq + (KHeap_A.set_object ptr obj) (Fl4Spec.setObject ptr (embKernelObject obj)) := by + unfold KHeap_A.set_object Fl4Spec.setObject + refine mrel_bind (getObject_equiv ptr) fun koH koL hko => ?_ + subst hko + refine mrel_kbind (mrel_assert (by simp [holEq_eq_true, aType_eq, embAType_eq_iff])) ?_ + refine mrel_bind (mrel_get (Rs := SR)) fun sH sL hs => ?_ + refine mrel_put ?_ + refine { hs with kheap_eq := fun p => ?_ } + by_cases hp : p = ptr + · subst hp; simp [Structures_A.abstract_state.kheap_update, Function.update, holFunUpd_eq] + · simp [Structures_A.abstract_state.kheap_update, Function.update, holFunUpd_eq, hp, hs.kheap_eq p] + +theorem getTcb_equiv (tcbRef : ObjRef) : + LookupRel SR (FunRel embTcb) + (KHeap_A.get_tcb tcbRef) (Fl4Spec.getTcb tcbRef) := by + intro sH sL hs + rw [optRel_funRel] + unfold Fl4Spec.getTcb KHeap_A.get_tcb Fl4Spec.readObject KHeap_A.read_object holSwp + rw [hs.kheap_eq tcbRef] + cases sH.kheap tcbRef with + | none => rfl + | some ko => cases ko <;> rfl + +theorem threadRead_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + {fH : Structures_A.tcb → αH} {fL : Tcb → αL} + (hf : ∀ t, Ra (fH t) (fL (embTcb t))) (tptr : ObjRef) : + LookupRel SR Ra + (KHeap_A.thread_read fH tptr) (Fl4Spec.threadRead fL tptr) := by + unfold KHeap_A.thread_read Fl4Spec.threadRead holOLiftM Lookup.oliftM + exact lookup_bind (getTcb_equiv tptr) fun tH tL ht => by + subst ht; exact lookup_oreturn (hf tH) + +theorem threadGet_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + {fH : Structures_A.tcb → αH} {fL : Tcb → αL} + (hf : ∀ t, Ra (fH t) (fL (embTcb t))) (tptr : ObjRef) : + MRel SR Ra + (KHeap_A.thread_get fH tptr) (Fl4Spec.threadGet fL tptr) := by + unfold KHeap_A.thread_get Fl4Spec.threadGet + exact mrel_bind (mrel_getsThe (getTcb_equiv tptr)) fun tH tL ht => by + subst ht; exact mrel_return (hf tH) + +theorem threadSet_equiv + {fH : Structures_A.tcb → Structures_A.tcb} {fL : Tcb → Tcb} + (hf : ∀ t, fL (embTcb t) = embTcb (fH t)) (tptr : ObjRef) : + MRel SR Eq + (KHeap_A.thread_set fH tptr) (Fl4Spec.threadSet fL tptr) := by + unfold KHeap_A.thread_set Fl4Spec.threadSet + refine mrel_bind (mrel_getsThe (getTcb_equiv tptr)) fun tH tL ht => ?_ + subst ht + have heq : KernelObject.tcb (fL (embTcb tH)) = embKernelObject (.TCB (fH tH)) := by + simp [embKernelObject, hf tH] + rw [heq] + exact setObject_equiv tptr (.TCB (fH tH)) + +theorem archThreadGet_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + {fH : Arch_Structs_A.arch_tcb → αH} {fL : ArchTcb → αL} + (hf : ∀ a, Ra (fH a) (fL (embArchTcb a))) (tptr : ObjRef) : + MRel SR Ra + (KHeap_A.arch_thread_get fH tptr) (Fl4Spec.archThreadGet fL tptr) := by + unfold KHeap_A.arch_thread_get Fl4Spec.archThreadGet + exact mrel_bind (mrel_getsThe (getTcb_equiv tptr)) fun tH tL ht => by + subst ht; exact mrel_return (hf tH.tcb_arch) + +theorem archThreadSet_equiv + {fH : Arch_Structs_A.arch_tcb → Arch_Structs_A.arch_tcb} {fL : ArchTcb → ArchTcb} + (hf : ∀ a, fL (embArchTcb a) = embArchTcb (fH a)) (tptr : ObjRef) : + MRel SR Eq + (KHeap_A.arch_thread_set fH tptr) (Fl4Spec.archThreadSet fL tptr) := by + unfold KHeap_A.arch_thread_set Fl4Spec.archThreadSet + refine mrel_bind (mrel_getsThe (getTcb_equiv tptr)) fun tH tL ht => ?_ + subst ht + have heq : KernelObject.tcb { embTcb tH with tcbArch := fL (embTcb tH).tcbArch } = + embKernelObject (.TCB (Structures_A.tcb.tcb_arch_update (fun _ => fH tH.tcb_arch) tH)) := by + simp [embKernelObject, embTcb, Structures_A.tcb.tcb_arch_update, hf tH.tcb_arch] + rw [heq] + exact setObject_equiv tptr _ + +theorem readThreadState_equiv (ref : ObjRef) : + LookupRel SR (FunRel embThreadState) + (KHeap_A.read_thread_state ref) (Fl4Spec.readThreadState ref) := + threadRead_equiv (Ra := FunRel embThreadState) (fun _ => rfl) ref + +theorem getThreadState_equiv (ref : ObjRef) : + MRel SR (FunRel embThreadState) + (KHeap_A.get_thread_state ref) (Fl4Spec.getThreadState ref) := + threadGet_equiv (Ra := FunRel embThreadState) (fun _ => rfl) ref + +theorem readTcbObjRef_equiv + {fH : Structures_A.tcb → Option ObjRef} {fL : Tcb → Option ObjRef} + (hf : ∀ t, fL (embTcb t) = fH t) (ref : ObjRef) : + LookupRel SR Eq + (KHeap_A.read_tcb_obj_ref fH ref) (Fl4Spec.readTcbObjRef fL ref) := + threadRead_equiv (fun t => (hf t).symm) ref + +theorem getTcbObjRef_equiv + {fH : Structures_A.tcb → Option ObjRef} {fL : Tcb → Option ObjRef} + (hf : ∀ t, fL (embTcb t) = fH t) (ref : ObjRef) : + MRel SR Eq + (KHeap_A.get_tcb_obj_ref fH ref) (Fl4Spec.getTcbObjRef fL ref) := + threadGet_equiv (fun t => (hf t).symm) ref + +theorem setTcbObjRef_equiv + {fH : (Option ObjRef → Option ObjRef) → Structures_A.tcb → Structures_A.tcb} + {fL : (Option ObjRef → Option ObjRef) → Tcb → Tcb} + (hf : ∀ g t, fL g (embTcb t) = embTcb (fH g t)) + (ref : ObjRef) (new : Option ObjRef) : + MRel SR Eq + (KHeap_A.set_tcb_obj_ref fH ref new) (Fl4Spec.setTcbObjRef fL ref new) := + threadSet_equiv (fun t => hf (fun _ => new) t) ref + +theorem partialInv_rel {αH αL βH βL : Type} [Nonempty αH] [Nonempty αL] [Nonempty βH] + {e : αH → αL} {fH : αH → βH} {fL : αL → βL} {bH : βH} {bL : βL} + (hiff : ∀ aH, fH aH = bH ↔ fL (e aH) = bL) + (he_inj : ∀ a1 a2, fH a1 = bH → fH a2 = bH → e a1 = e a2 → a1 = a2) + (hsurj : ∀ aL, fL aL = bL → ∃ aH, aL = e aH) : + OptRel (FunRel e) (Lib.partial_inv fH bH) (Fl4Spec.partialInv fL bL) := by + rw [optRel_funRel] + unfold Lib.partial_inv Fl4Spec.partialInv + have hex : (∃! aH, fH aH = bH) ↔ (∃! aL, fL aL = bL) := by + constructor + · rintro ⟨a0, ha0, hu0⟩ + refine ⟨e a0, (hiff a0).mp ha0, fun aL haL => ?_⟩ + obtain ⟨aH, rfl⟩ := hsurj aL haL + rw [hu0 aH ((hiff aH).mpr haL)] + · rintro ⟨aL0, haL0, huL0⟩ + obtain ⟨a0, rfl⟩ := hsurj aL0 haL0 + refine ⟨a0, (hiff a0).mpr haL0, fun aH haH => ?_⟩ + exact he_inj aH a0 haH ((hiff a0).mpr haL0) (huL0 (e aH) ((hiff aH).mp haH)) + by_cases h1 : ∃! aH, fH aH = bH + · have h2 : ∃! aL, fL aL = bL := hex.mp h1 + have hhH : (holEx1 fun x => holEq (fH x) bH) = true := by + unfold holEx1; rw [decide_eq_true_eq] + rcases h1 with ⟨a0, ha0, hu0⟩ + exact ⟨a0, by simp [holEq_eq_true, ha0], fun y hy => hu0 y (by simpa [holEq_eq_true] using hy)⟩ + simp only [hhH, holIf_true, h2, ↓reduceIte, Option.map_some] + congr 1 + unfold Fl4Spec.The holThe + split_ifs with hL hH + · have hspecL : fL (Classical.choose hL) = bL := (Classical.choose_spec hL).1 + have hspecH : fH (Classical.choose hH) = bH := by + simpa [holEq_eq_true] using (Classical.choose_spec hH).1 + exact (Classical.choose_spec hL).2 (e (Classical.choose hH)) ((hiff _).mp hspecH) |>.symm + · exfalso; apply hH + rcases h1 with ⟨a0, ha0, hu0⟩ + exact ⟨a0, by simp [holEq_eq_true, ha0], fun y hy => hu0 y (by simpa [holEq_eq_true] using hy)⟩ + · exact absurd h2 hL + · exact absurd h2 hL + · have h2 : ¬∃! aL, fL aL = bL := fun h => h1 (hex.mpr h) + have hhH : (holEx1 fun x => holEq (fH x) bH) = false := by + cases hh : (holEx1 fun x => holEq (fH x) bH) + · rfl + · exfalso; unfold holEx1 at hh; rw [decide_eq_true_eq] at hh + rcases hh with ⟨a0, ha0, hu0⟩ + exact h1 ⟨a0, by simpa [holEq_eq_true] using ha0, + fun y hy => hu0 y (by simp [holEq_eq_true, hy])⟩ + simp only [hhH, holIf_false, h2, ↓reduceIte, Option.map_none] + +private theorem partialInv_ko_rel {αH αL : Type} [Nonempty αH] [Nonempty αL] + {e : αH → αL} + (he_inj : Function.Injective e) + {fH : αH → Structures_A.kernel_object} {fL : αL → KernelObject} + (hfH_inj : Function.Injective fH) + (hf : ∀ a, fL (e a) = embKernelObject (fH a)) + (hsurj : ∀ ko aL, fL aL = embKernelObject ko → ∃ aH, aL = e aH ∧ fH aH = ko) + (koH : Structures_A.kernel_object) : + OptRel (FunRel e) (Lib.partial_inv fH koH) (Fl4Spec.partialInv fL (embKernelObject koH)) := + partialInv_rel + (fun aH => ⟨fun h => by rw [hf, h], fun h => by + obtain ⟨aH', he, hfa⟩ := hsurj koH (e aH) h + rw [he_inj he]; exact hfa⟩) + (fun a1 a2 h1 h2 _ => hfH_inj (h1.trans h2.symm)) + (fun aL h => let ⟨aH, he, _⟩ := hsurj koH aL h; ⟨aH, he⟩) + +theorem getSimpleKo_equiv {αH αL : Type} [Nonempty αH] [Nonempty αL] + {e : αH → αL} + (he_inj : Function.Injective e) + {fH : αH → Structures_A.kernel_object} {fL : αL → KernelObject} + (hfH_inj : Function.Injective fH) + (hf : ∀ a, fL (e a) = embKernelObject (fH a)) + (hsurj : ∀ ko aL, fL aL = embKernelObject ko → ∃ aH, aL = e aH ∧ fH aH = ko) + (ptr : ObjRef) : + MRel SR (FunRel e) + (KHeap_A.get_simple_ko fH ptr) (Fl4Spec.getSimpleKo fL ptr) := by + unfold KHeap_A.get_simple_ko Fl4Spec.getSimpleKo + refine mrel_bind (getObject_equiv ptr) fun koH koL hko => ?_ + subst hko + have hst : holMember (Structures_A.a_type koH) + (holInsert Structures_A.a_type_T.AEndpoint + (holInsert Structures_A.a_type_T.ANTFN + (holInsert Structures_A.a_type_T.AReply HolCompleteLattice.holBot))) = true ↔ + Fl4Spec.isSimpleType (embKernelObject koH) := by + simpa [KHeap_A.is_simple_type, HolCompleteLattice.holBot] using isSimpleType_iff koH + refine mrel_kbind (mrel_assert hst) ?_ + have hpi := partialInv_ko_rel he_inj hfH_inj hf hsurj koH + cases hH : Lib.partial_inv fH koH <;> + cases hL : Fl4Spec.partialInv fL (embKernelObject koH) <;> + simp [hH, hL, OptRel] at hpi ⊢ + · exact mrel_fail + · exact mrel_return hpi + +theorem setSimpleKo_equiv {αH αL : Type} [Nonempty αH] [Nonempty αL] + {e : αH → αL} + (he_inj : Function.Injective e) + {fH : αH → Structures_A.kernel_object} {fL : αL → KernelObject} + (hfH_inj : Function.Injective fH) + (hf : ∀ a, fL (e a) = embKernelObject (fH a)) + (hsurj : ∀ ko aL, fL aL = embKernelObject ko → ∃ aH, aL = e aH ∧ fH aH = ko) + (ptr : ObjRef) (v : αH) : + MRel SR Eq + (KHeap_A.set_simple_ko fH ptr v) (Fl4Spec.setSimpleKo fL ptr (e v)) := by + unfold KHeap_A.set_simple_ko Fl4Spec.setSimpleKo + refine mrel_bind (getObject_equiv ptr) fun koH koL hko => ?_ + subst hko + have hst : holMember (Structures_A.a_type koH) + (holInsert Structures_A.a_type_T.AEndpoint + (holInsert Structures_A.a_type_T.ANTFN + (holInsert Structures_A.a_type_T.AReply HolCompleteLattice.holBot))) = true ↔ + Fl4Spec.isSimpleType (embKernelObject koH) := by + simpa [KHeap_A.is_simple_type, HolCompleteLattice.holBot] using isSimpleType_iff koH + refine mrel_kbind (mrel_assert hst) ?_ + have hne : holNot (holEq (Lib.partial_inv fH koH) none) = true ↔ + Fl4Spec.partialInv fL (embKernelObject koH) ≠ none := by + have hpi := partialInv_ko_rel he_inj hfH_inj hf hsurj koH + rw [optRel_funRel] at hpi + rw [hpi] + simp [holNot_eq_true, ne_eq, holEq_eq_true] + refine mrel_kbind (mrel_assert hne) ?_ + rw [hf v] + exact setObject_equiv ptr (fH v) + +theorem embEndpoint_injective : Function.Injective embEndpoint := by + intro a b h; cases a <;> cases b <;> simp [embEndpoint] at h <;> try rfl + · subst h; rfl + · subst h; rfl + +theorem embNotification_injective : Function.Injective embNotification := by + intro ⟨o1, t1, s1, m1⟩ ⟨o2, t2, s2, m2⟩ h + cases m1; cases m2 + simp only [embNotification, Notification.mk.injEq] at h + rcases h with ⟨ho, ht, hs⟩ + have ho' : o1 = o2 := by + cases o1 <;> cases o2 <;> simp [embNtfn] at ho <;> try rfl + · subst ho; rfl + · subst ho; rfl + subst ho'; subst ht; subst hs; rfl + +theorem embReply_injective : Function.Injective embReply := by + intro ⟨t1, s1, m1⟩ ⟨t2, s2, m2⟩ h + cases m1; cases m2 + simp only [embReply, Reply.mk.injEq] at h + rcases h with ⟨ht, hs⟩; subst ht; subst hs; rfl + +theorem getEndpoint_equiv (ptr : ObjRef) : + MRel SR (FunRel embEndpoint) + (KHeap_A.get_endpoint ptr) (Fl4Spec.getEndpoint ptr) := by + unfold KHeap_A.get_endpoint Fl4Spec.getEndpoint + exact getSimpleKo_equiv embEndpoint_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) ptr + +theorem setEndpoint_equiv (ptr : ObjRef) (ep : Structures_A.endpoint) : + MRel SR Eq + (KHeap_A.set_endpoint ptr ep) (Fl4Spec.setEndpoint ptr (embEndpoint ep)) := by + unfold KHeap_A.set_endpoint Fl4Spec.setEndpoint + exact setSimpleKo_equiv embEndpoint_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) ptr ep + +theorem getNotification_equiv (ptr : ObjRef) : + MRel SR (FunRel embNotification) + (KHeap_A.get_notification ptr) (Fl4Spec.getNotification ptr) := by + unfold KHeap_A.get_notification Fl4Spec.getNotification + exact getSimpleKo_equiv embNotification_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) ptr + +theorem setNotification_equiv (ptr : ObjRef) (ntfn : Structures_A.notification) : + MRel SR Eq + (KHeap_A.set_notification ptr ntfn) (Fl4Spec.setNotification ptr (embNotification ntfn)) := by + unfold KHeap_A.set_notification Fl4Spec.setNotification + exact setSimpleKo_equiv embNotification_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) ptr ntfn + +theorem getReply_equiv (ptr : ObjRef) : + MRel SR (FunRel embReply) + (KHeap_A.get_reply ptr) (Fl4Spec.getReply ptr) := by + unfold KHeap_A.get_reply Fl4Spec.getReply + exact getSimpleKo_equiv embReply_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) ptr + +theorem setReply_equiv (ptr : ObjRef) (r : Structures_A.reply) : + MRel SR Eq + (KHeap_A.set_reply ptr r) (Fl4Spec.setReply ptr (embReply r)) := by + unfold KHeap_A.set_reply Fl4Spec.setReply + exact setSimpleKo_equiv embReply_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) ptr r + +theorem getReplyTcb_equiv (ptr : ObjRef) : + MRel SR Eq + (KHeap_A.get_reply_tcb ptr) (Fl4Spec.getReplyTcb ptr) := by + unfold KHeap_A.get_reply_tcb Fl4Spec.getReplyTcb + exact mrel_liftM (fun rH rL hr => by subst hr; rfl) (getReply_equiv ptr) + +theorem getIrqState_equiv (irq : BitVec 8) : + MRel SR (FunRel embIrqState) + (KHeap_A.get_irq_state irq) (Fl4Spec.getIrqState (embIrq irq)) := by + unfold KHeap_A.get_irq_state Fl4Spec.getIrqState + exact mrel_gets fun sH sL hs => hs.interruptStates_eq irq + +theorem setIrqState_equiv (st : Structures_A.irq_state) (irq : BitVec 8) : + MRel SR Eq + (KHeap_A.set_irq_state st irq) (Fl4Spec.setIrqState (embIrqState st) (embIrq irq)) := by + unfold KHeap_A.set_irq_state Fl4Spec.setIrqState + refine mrel_kbind (mrel_modify fun sH sL hs => ?_) ?_ + · refine { hs with interruptStates_eq := fun i => ?_ } + by_cases hi : i = irq + · subst hi; simp [Structures_A.abstract_state.interrupt_states_update, Function.update, holFunUpd_eq] + · simp [Structures_A.abstract_state.interrupt_states_update, Function.update, holFunUpd_eq, embIrq, hi, hs.interruptStates_eq i] + · have hdec : holEq st Structures_A.irq_state.IRQInactive = + decide (embIrqState st = IrqState.irqInactive) := by + cases st <;> simp [embIrqState, holEq] + rw [hdec] + exact mrel_doMachineOp (maskInterrupt_equiv _ irq) + +theorem getIrqSlot_equiv (irq : BitVec 8) : + MRel SR Eq + (KHeap_A.get_irq_slot irq) (Fl4Spec.getIrqSlot (embIrq irq)) := by + unfold KHeap_A.get_irq_slot Fl4Spec.getIrqSlot + exact mrel_gets fun sH sL hs => by simp [hs.interruptIrqNode_eq] + +theorem readSchedContext_equiv (ptr : ObjRef) : + LookupRel SR (FunRel embSchedContext) + (KHeap_A.read_sched_context ptr) (Fl4Spec.readSchedContext ptr) := by + unfold KHeap_A.read_sched_context Fl4Spec.readSchedContext + refine lookup_bind (readObject_equiv ptr) fun koH koL hko => ?_ + subst hko + cases koH with + | SchedContext sc n => exact lookup_oreturn rfl + | _ => exact lookup_ofail + +theorem getSchedContext_equiv (ptr : ObjRef) : + MRel SR (FunRel embSchedContext) + (KHeap_A.get_sched_context ptr) (Fl4Spec.getSchedContext ptr) := by + unfold KHeap_A.get_sched_context Fl4Spec.getSchedContext + refine mrel_bind (getObject_equiv ptr) fun koH koL hko => ?_ + subst hko + cases koH with + | SchedContext sc n => exact mrel_return rfl + | _ => exact mrel_fail + +theorem readScObjRef_equiv + {fH : Structures_A.sched_context → Option ObjRef} {fL : SchedContext → Option ObjRef} + (hf : ∀ sc, fL (embSchedContext sc) = fH sc) (ref : ObjRef) : + LookupRel SR Eq + (KHeap_A.read_sc_obj_ref fH ref) (Fl4Spec.readScObjRef fL ref) := by + unfold KHeap_A.read_sc_obj_ref Fl4Spec.readScObjRef holOLiftM Lookup.oliftM + exact lookup_bind (readSchedContext_equiv ref) fun scH scL hsc => by + subst hsc; exact lookup_oreturn (hf scH).symm + +theorem getScObjRef_equiv + {fH : Structures_A.sched_context → Option ObjRef} {fL : SchedContext → Option ObjRef} + (hf : ∀ sc, fL (embSchedContext sc) = fH sc) (ref : ObjRef) : + MRel SR Eq + (KHeap_A.get_sc_obj_ref fH ref) (Fl4Spec.getScObjRef fL ref) := by + unfold KHeap_A.get_sc_obj_ref Fl4Spec.getScObjRef + exact mrel_bind (getSchedContext_equiv ref) fun scH scL hsc => by + subst hsc; exact mrel_return (hf scH).symm + +theorem setSchedContext_equiv (ptr : ObjRef) (sc : Structures_A.sched_context) (n : Nat) : + MRel SR Eq + (KHeap_A.set_sched_context ptr sc n) + (Fl4Spec.setSchedContext ptr (embSchedContext sc) n) := + setObject_equiv ptr (.SchedContext sc n) + +theorem updateSchedContext_equiv + {fH : Structures_A.sched_context → Structures_A.sched_context} + {fL : SchedContext → SchedContext} + (hf : ∀ sc, fL (embSchedContext sc) = embSchedContext (fH sc)) (ptr : ObjRef) : + MRel SR Eq + (KHeap_A.update_sched_context ptr fH) (Fl4Spec.updateSchedContext ptr fL) := by + unfold KHeap_A.update_sched_context Fl4Spec.updateSchedContext + refine mrel_bind (getObject_equiv ptr) fun koH koL hko => ?_ + subst hko + cases koH with + | SchedContext sc n => + simp only [Structures_A.case_kernel_object, embKernelObject] + rw [hf sc] + exact setSchedContext_equiv ptr (fH sc) n + | _ => exact mrel_fail + +theorem setScObjRef_equiv {α : Type} [Nonempty α] + {fH : (α → α) → Structures_A.sched_context → Structures_A.sched_context} + {fL : (α → α) → SchedContext → SchedContext} + (hf : ∀ g sc, fL g (embSchedContext sc) = embSchedContext (fH g sc)) + (ref : ObjRef) (new : α) : + MRel SR Eq + (KHeap_A.set_sc_obj_ref fH ref new) (Fl4Spec.setScObjRef fL ref new) := + updateSchedContext_equiv (fun sc => hf (fun _ => new) sc) ref + +theorem readScActive_equiv (scPtr : ObjRef) : + LookupRel SR Eq + (KHeap_A.read_sc_active scPtr) (Fl4Spec.readScActive scPtr) := by + unfold KHeap_A.read_sc_active Fl4Spec.readScActive + exact lookup_bind (readSchedContext_equiv scPtr) fun scH scL hsc => by + subst hsc; exact lookup_oreturn (scActive_eq scH).symm + +theorem getScActive_equiv (scPtr : ObjRef) : + MRel SR Eq + (KHeap_A.get_sc_active scPtr) (Fl4Spec.getScActive scPtr) := + mrel_getsThe (readScActive_equiv scPtr) + +theorem inReleaseQueue_eq {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (t : ObjRef) : + Fl4Spec.inReleaseQueue t sL = KHeap_A.in_release_queue t sH := by + unfold Fl4Spec.inReleaseQueue KHeap_A.in_release_queue + rw [hs.releaseQueue_eq] + apply Bool.eq_iff_iff.mpr + rw [holMember_eq_true, holListSet_eq] + change decide (t ∈ sH.release_queue) = true ↔ t ∈ sH.release_queue + by_cases h : t ∈ sH.release_queue <;> simp [h] + +theorem schedulable_eq {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (t : ObjRef) : + Fl4Spec.schedulable t sL = KHeap_A.schedulable t sH := by + unfold Fl4Spec.schedulable KHeap_A.schedulable + have h1 : Fl4Spec.optPred (fun st => Fl4Spec.runnable st = true) + (Fl4Spec.optMapSome (Fl4Spec.tcbsOf sL) Tcb.tcbState) t ↔ + holOptPred Structures_A.runnable + (holOptMap (KHeap_A.tcbs_of_kh sH.kheap) (fun tcb => some tcb.tcb_state)) t = true := by + have htc := tcbsOf_eq hs t + unfold KHeap_A.tcbs_of at htc + unfold Fl4Spec.optPred holOptPred Fl4Spec.optMapSome Fl4Spec.optMap holOptMap + rw [htc] + cases KHeap_A.tcbs_of_kh sH.kheap t with + | none => simp + | some tcb => simp [embTcb, runnable_eq] + have h2 : Fl4Spec.optPred (fun sc => Fl4Spec.scActive sc = true) + (Fl4Spec.optMap (Fl4Spec.optMap (Fl4Spec.tcbsOf sL) Tcb.tcbSchedContext) + (Fl4Spec.scsOf sL)) t ↔ + holOptPred (fun sc => KHeap_A.active_sc sc.sc_refill_max) + (holOptMap (holOptMap (KHeap_A.tcbs_of_kh sH.kheap) Structures_A.tcb_ext.tcb_sched_context) + (KHeap_A.scs_of_kh sH.kheap)) t = true := by + have htc := tcbsOf_eq hs t + unfold KHeap_A.tcbs_of at htc + unfold Fl4Spec.optPred holOptPred Fl4Spec.optMap holOptMap + rw [htc] + cases KHeap_A.tcbs_of_kh sH.kheap t with + | none => simp + | some tcb => + simp only [Option.map_some, embTcb] + cases hscref : tcb.tcb_sched_context with + | none => simp + | some scPtr => + have hsc := scsOf_eq hs scPtr + unfold KHeap_A.scs_of at hsc + simp only [hsc] + cases KHeap_A.scs_of_kh sH.kheap scPtr with + | none => simp + | some sc => simp [scActive_eq, KHeap_A.sc_active] + have h3 : t ∉ sL.releaseQueue ↔ + holNot (holMember t (holListSet sH.release_queue)) = true := by + rw [hs.releaseQueue_eq] + simp [holNot_eq_true, ne_eq, holMember_eq_true, holListSet_eq] + apply Bool.eq_iff_iff.mpr + simp only [decide_eq_true_eq, holConj_eq_true, h1, h2, h3] + +theorem ctSchedulable_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) : + Fl4Spec.ctSchedulable sL = KHeap_A.ct_schedulable sH := by + unfold Fl4Spec.ctSchedulable KHeap_A.ct_schedulable + rw [hs.curThread_eq] + exact schedulable_eq hs sH.cur_thread + +theorem getRefills_equiv (scPtr : ObjRef) : + MRel SR (ListRel (FunRel embRefill)) + (KHeap_A.get_refills scPtr) (Fl4Spec.getRefills scPtr) := by + unfold KHeap_A.get_refills Fl4Spec.getRefills + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + exact mrel_return ((listRel_funRel embRefill _ _).mpr rfl) + +theorem readRefillHead_equiv (scPtr : ObjRef) : + LookupRel SR (FunRel embRefill) + (KHeap_A.read_refill_head scPtr) (Fl4Spec.readRefillHead scPtr) := by + unfold KHeap_A.read_refill_head Fl4Spec.readRefillHead + refine lookup_bind (readSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + by_cases hne : scH.sc_refills = [] + · intro _ _ _; simp [hne, embSchedContext, holOBind, Bind.bind, ReaderT.bind, Option.bind, + holOAssert, Lookup.oassert, holOFail, Lookup.ofail, holNot, holEq, OptRel] + · have hneL : (embSchedContext scH).scRefills ≠ [] := by + simp [embSchedContext, hne] + have hnot : holNot (holEq scH.sc_refills []) = true := by + simp [holNot_eq_true, ne_eq, holEq_eq_true, hne] + intro _ _ _ + simp [hneL, hnot, holOBind, Bind.bind, ReaderT.bind, Option.bind, holOAssert, Lookup.oassert, + holOReturn, Lookup.oreturn, OptRel, FunRel, refillHd_eq scH hne, KHeap_A.refill_hd] + +theorem getRefillHead_equiv (scPtr : ObjRef) : + MRel SR (FunRel embRefill) + (KHeap_A.get_refill_head scPtr) (Fl4Spec.getRefillHead scPtr) := + mrel_getsThe (readRefillHead_equiv scPtr) + +theorem readRefillTail_equiv (scPtr : ObjRef) : + LookupRel SR (FunRel embRefill) + (KHeap_A.read_refill_tail scPtr) (Fl4Spec.readRefillTail scPtr) := by + unfold KHeap_A.read_refill_tail Fl4Spec.readRefillTail + refine lookup_bind (readSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + by_cases hne : scH.sc_refills = [] + · intro _ _ _; simp [hne, embSchedContext, holOBind, Bind.bind, ReaderT.bind, Option.bind, + holOAssert, Lookup.oassert, holOFail, Lookup.ofail, holNot, holEq, OptRel] + · have hneL : (embSchedContext scH).scRefills ≠ [] := by + simp [embSchedContext, hne] + have hnot : holNot (holEq scH.sc_refills []) = true := by + simp [holNot_eq_true, ne_eq, holEq_eq_true, hne] + intro _ _ _ + simp [hneL, hnot, holOBind, Bind.bind, ReaderT.bind, Option.bind, holOAssert, Lookup.oassert, + holOReturn, Lookup.oreturn, OptRel, FunRel, refillTl_eq scH hne, KHeap_A.refill_tl] + +theorem getRefillTail_equiv (scPtr : ObjRef) : + MRel SR (FunRel embRefill) + (KHeap_A.get_refill_tail scPtr) (Fl4Spec.getRefillTail scPtr) := + mrel_getsThe (readRefillTail_equiv scPtr) + +theorem readScRefillCapacity_equiv (scPtr : ObjRef) (usage : Ticks) : + LookupRel SR Eq + (KHeap_A.read_sc_refill_capacity scPtr usage) + (Fl4Spec.readScRefillCapacity scPtr usage) := by + unfold KHeap_A.read_sc_refill_capacity Fl4Spec.readScRefillCapacity + exact lookup_bind (readRefillHead_equiv scPtr) fun rH rL hr => by + subst hr; exact lookup_oreturn (refillCapacity_eq usage rH).symm + +theorem getScRefillCapacity_equiv (scPtr : ObjRef) (usage : Ticks) : + MRel SR Eq + (KHeap_A.get_sc_refill_capacity scPtr usage) + (Fl4Spec.getScRefillCapacity scPtr usage) := + mrel_getsThe (readScRefillCapacity_equiv scPtr usage) + +theorem readScRefillSufficient_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) (usage : Ticks) : + LookupRel SR Eq + (KHeap_A.read_sc_refill_sufficient scPtr usage) + (Fl4Spec.readScRefillSufficient scPtr usage) := by + unfold KHeap_A.read_sc_refill_sufficient Fl4Spec.readScRefillSufficient + exact lookup_bind (readRefillHead_equiv scPtr) fun rH rL hr => by + subst hr; exact lookup_oreturn (refillSufficient_eq hop usage rH).symm + +theorem getScRefillSufficient_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) (usage : Ticks) : + MRel SR Eq + (KHeap_A.get_sc_refill_sufficient scPtr usage) + (Fl4Spec.getScRefillSufficient scPtr usage) := + mrel_getsThe (readScRefillSufficient_equiv hop scPtr usage) + +theorem readScRefillReady_equiv (scPtr : ObjRef) : + LookupRel SR Eq + (KHeap_A.read_sc_refill_ready scPtr) (Fl4Spec.readScRefillReady scPtr) := by + unfold KHeap_A.read_sc_refill_ready Fl4Spec.readScRefillReady + refine lookup_bind (readRefillHead_equiv scPtr) fun rH rL hr => ?_ + subst hr + refine lookup_bind (Ra := Eq) (fun sH sL hs => by simp [holAsks, Lookup.asks, OptRel, hs.curTime_eq]) ?_ + intro ctH ctL hct + subst hct + exact lookup_oreturn (refillReady'_eq 0 ctH rH).symm + +theorem getScRefillReady_equiv (scPtr : ObjRef) : + MRel SR Eq + (KHeap_A.get_sc_refill_ready scPtr) (Fl4Spec.getScRefillReady scPtr) := + mrel_getsThe (readScRefillReady_equiv scPtr) + +theorem readScReleased_equiv (scPtr : ObjRef) : + LookupRel SR Eq + (KHeap_A.read_sc_released scPtr) (Fl4Spec.readScReleased scPtr) := by + unfold KHeap_A.read_sc_released Fl4Spec.readScReleased + refine lookup_bind (readScActive_equiv scPtr) fun aH aL ha => ?_ + subst ha + cases aH with + | true => exact readScRefillReady_equiv scPtr + | false => exact lookup_oreturn rfl + +theorem getScReleased_equiv (scPtr : ObjRef) : + MRel SR Eq + (KHeap_A.get_sc_released scPtr) (Fl4Spec.getScReleased scPtr) := + mrel_getsThe (readScReleased_equiv scPtr) + +theorem getTcbQueue_equiv (d : Domain) (prio : Priority) : + MRel SR Eq + (KHeap_A.get_tcb_queue d prio) (Fl4Spec.getTcbQueue d prio) := by + unfold KHeap_A.get_tcb_queue Fl4Spec.getTcbQueue + exact mrel_bind (mrel_gets fun _ _ hs => hs.readyQueues_eq.symm) fun qH qL hq => by + subst hq; exact mrel_return rfl + +theorem setTcbQueue_equiv (d : Domain) (prio : Priority) (q : ReadyQueue) : + MRel SR Eq + (KHeap_A.set_tcb_queue d prio q) (Fl4Spec.setTcbQueue d prio q) := by + unfold KHeap_A.set_tcb_queue Fl4Spec.setTcbQueue + refine mrel_modify fun sH sL hs => { hs with readyQueues_eq := ?_ } + funext d' p + show (if d' = d ∧ p = prio then q else sL.readyQueues d' p) = + holIf (holConj (holEq d' d) (holEq p prio)) q (sH.ready_queues d' p) + rw [holIf_eq] + split_ifs with h1 h2 h3 + · rfl + · exfalso; apply h2; simp [holConj_eq_true, holEq_eq_true, h1.1, h1.2] + · exfalso; apply h1; simp [holConj_eq_true, holEq_eq_true] at h3; exact h3 + · exact congrFun (congrFun hs.readyQueues_eq d') p + +theorem tcbSchedAction_equiv + {actH actL : ObjRef → List ObjRef → List ObjRef} + (hact : ∀ t q, actL t q = actH t q) (thread : ObjRef) : + MRel SR Eq + (KHeap_A.tcb_sched_action actH thread) (Fl4Spec.tcbSchedAction actL thread) := by + unfold KHeap_A.tcb_sched_action Fl4Spec.tcbSchedAction + refine mrel_bind (threadGet_equiv (fun _ => rfl) thread) fun dH dL hd => ?_ + subst hd + refine mrel_bind (threadGet_equiv (fun _ => rfl) thread) fun pH pL hp => ?_ + subst hp + refine mrel_bind (getTcbQueue_equiv dH pH) fun qH qL hq => ?_ + subst hq + refine mrel_bind (mrel_return (hact thread qH).symm) fun qH' qL' hq' => ?_ + subst hq' + exact setTcbQueue_equiv dH pH qH' + +theorem isBlocked_equiv (thread : ObjRef) : + MRel SR Eq + (KHeap_A.is_blocked thread) (Fl4Spec.isBlocked thread) := by + unfold KHeap_A.is_blocked Fl4Spec.isBlocked + exact mrel_liftM (fun tsH tsL hts => by subst hts; exact (ipcQueuedThreadState_eq tsH).symm) + (getThreadState_equiv thread) + +theorem setReleaseQueue_equiv (q : List ObjRef) : + MRel SR Eq + (KHeap_A.set_release_queue q) (Fl4Spec.setReleaseQueue q) := by + unfold KHeap_A.set_release_queue Fl4Spec.setReleaseQueue + exact mrel_modify fun _ _ hs => { hs with releaseQueue_eq := rfl } + +theorem tcbReleaseRemove_equiv (tcbPtr : ObjRef) : + MRel SR Eq + (KHeap_A.tcb_release_remove tcbPtr) (Fl4Spec.tcbReleaseRemove tcbPtr) := by + unfold KHeap_A.tcb_release_remove Fl4Spec.tcbReleaseRemove + refine mrel_bind (mrel_gets fun _ _ hs => hs.releaseQueue_eq.symm) fun qsH qsL hqs => ?_ + subst hqs + have hcond : holConj (holNot (holEq qsH [])) (holEq (holHd qsH) tcbPtr) = true ↔ + (qsH ≠ [] ∧ the qsH.head? = tcbPtr) := by + cases qsH with + | nil => simp [holConj_eq_true, holNot_eq_true, holEq_eq_true] + | cons x xs => simp [holConj_eq_true, holNot_eq_true, holEq_eq_true, holHd, the] + refine mrel_kbind (mrel_when hcond fun _ => + mrel_modify fun _ _ hs => { hs with reprogramTimer_eq := rfl }) ?_ + refine mrel_bind (mrel_return (tcbSchedDequeue_eq tcbPtr qsH).symm) fun q'H q'L hq' => ?_ + subst hq' + exact setReleaseQueue_equiv q'H + +theorem setSchedulerAction_equiv (act : Structures_A.scheduler_action) : + MRel SR Eq + (KHeap_A.set_scheduler_action act) + (Fl4Spec.setSchedulerAction (embSchedulerAction act)) := by + unfold KHeap_A.set_scheduler_action Fl4Spec.setSchedulerAction + exact mrel_modify fun _ _ hs => { hs with schedulerAction_eq := rfl } + +theorem threadSetPriority_equiv (tptr : ObjRef) (prio : Priority) : + MRel SR Eq + (KHeap_A.thread_set_priority tptr prio) (Fl4Spec.threadSetPriority tptr prio) := + threadSet_equiv (fun _ => rfl) tptr + +theorem threadSetDomain_equiv (tptr : ObjRef) (d : Domain) : + MRel SR Eq + (KHeap_A.thread_set_domain tptr d) (Fl4Spec.threadSetDomain tptr d) := + threadSet_equiv (fun _ => rfl) tptr + +theorem rescheduleRequired_equiv (hop : OpaqueRel RestRel) : + MRel SR Eq + KHeap_A.reschedule_required Fl4Spec.rescheduleRequired := by + unfold KHeap_A.reschedule_required Fl4Spec.rescheduleRequired + refine mrel_bind (mrel_gets (Ra := FunRel embSchedulerAction) fun _ _ hs => hs.schedulerAction_eq) fun aH aL ha => ?_ + subst ha + cases aH with + | switch_thread t => + dsimp only [Structures_A.case_scheduler_action, embSchedulerAction] + rw [holBind_assoc] + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs t).symm) fun scH scL hsc => ?_ + subst hsc + refine mrel_kbind (Ra := Eq) ?_ + (setSchedulerAction_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) .choose_new_thread) + refine mrel_when Iff.rfl fun _ => ?_ + refine mrel_bind (threadGet_equiv (fun _ => rfl) t) fun oH oL ho => ?_ + subst ho + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases oH <;> simp [OptRel])) fun pH pL hp => ?_ + subst hp + refine mrel_bind (getScRefillSufficient_equiv hop pH 0) fun sfH sfL hsf => ?_ + subst hsf + refine mrel_bind (getScRefillReady_equiv pH) fun rdH rdL hrd => ?_ + subst hrd + refine mrel_kbind (mrel_assert (by simp [holConj_eq_true])) ?_ + exact tcbSchedAction_equiv tcbSchedEnqueue_eq t + | resume_cur_thread => + dsimp only [Structures_A.case_scheduler_action, embSchedulerAction] + rw [holBind_return_left, holKBind_eq] + exact setSchedulerAction_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) .choose_new_thread + | choose_new_thread => + dsimp only [Structures_A.case_scheduler_action, embSchedulerAction] + rw [holBind_return_left, holKBind_eq] + exact setSchedulerAction_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) .choose_new_thread + +theorem possibleSwitchTo_equiv (hop : OpaqueRel RestRel) (target : ObjRef) : + MRel SR Eq + (KHeap_A.possible_switch_to target) (Fl4Spec.possibleSwitchTo target) := by + unfold KHeap_A.possible_switch_to Fl4Spec.possibleSwitchTo + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) target) fun oH oL ho => ?_ + subst ho + refine mrel_bind (mrel_gets fun _ _ hs => (inReleaseQueue_eq hs target).symm) fun iH iL hi => ?_ + subst hi + refine mrel_when (by simp [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true]) fun _ => ?_ + refine mrel_bind (mrel_gets fun _ _ hs => hs.curDomain_eq.symm) fun cdH cdL hcd => ?_ + subst hcd + refine mrel_bind (threadGet_equiv (fun _ => rfl) target) fun tdH tdL htd => ?_ + subst htd + refine mrel_bind (mrel_gets (Ra := FunRel embSchedulerAction) fun _ _ hs => hs.schedulerAction_eq) fun aH aL ha => ?_ + subst ha + split_ifs with hdom hact + · have hT : holNot (holEq tdH cdH) = true := by + rw [holNot_eq_true] + intro h1; exact hdom ((holEq_eq_true tdH cdH).mp h1) + rw [hT, holIf_true] + exact tcbSchedAction_equiv tcbSchedEnqueue_eq target + · have hdom' : tdH = cdH := not_not.mp hdom + have hF : holNot (holEq tdH cdH) = false := by simp [holNot, holEq, hdom'] + have hAT : holNot (holEq aH Structures_A.scheduler_action.resume_cur_thread) = true := by + simp only [holNot_eq_true, ne_eq, holEq_eq_true] + intro heq; apply hact; rw [heq]; rfl + rw [hF, holIf_false, hAT, holIf_true] + exact mrel_kbind (rescheduleRequired_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) hop) + (tcbSchedAction_equiv tcbSchedEnqueue_eq target) + · have hdom' : tdH = cdH := not_not.mp hdom + have hF : holNot (holEq tdH cdH) = false := by simp [holNot, holEq, hdom'] + have ha' : aH = .resume_cur_thread := by + have h1 := not_not.mp hact + cases aH <;> simp [embSchedulerAction] at h1 ⊢ + have hAF : holNot (holEq aH Structures_A.scheduler_action.resume_cur_thread) = false := by + simp [holNot, holEq, ha'] + rw [hF, holIf_false, hAF, holIf_false] + exact setSchedulerAction_equiv (.switch_thread target) + +theorem scheduleTcb_equiv (hop : OpaqueRel RestRel) (tcbPtr : ObjRef) : + MRel SR Eq + (KHeap_A.schedule_tcb tcbPtr) (Fl4Spec.scheduleTcb tcbPtr) := by + unfold KHeap_A.schedule_tcb Fl4Spec.scheduleTcb + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun cH cL hc => ?_ + subst hc + refine mrel_bind (mrel_gets (Ra := FunRel embSchedulerAction) fun _ _ hs => hs.schedulerAction_eq) fun aH aL ha => ?_ + subst ha + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs tcbPtr).symm) fun sH sL hs => ?_ + subst hs + have haeq : aH = .resume_cur_thread ↔ embSchedulerAction aH = .resumeCurThread := by + cases aH <;> simp [embSchedulerAction] + refine mrel_when (by simp [holConj_eq_true, holEq_eq_true, holNot_eq_true, haeq]) fun _ => ?_ + exact rescheduleRequired_equiv hop + +theorem setThreadStateAct_equiv (tcbPtr : ObjRef) : + MRel SR Eq + (KHeap_A.set_thread_state_act tcbPtr) (Fl4Spec.setThreadStateAct tcbPtr) := by + unfold KHeap_A.set_thread_state_act Fl4Spec.setThreadStateAct + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun cH cL hc => ?_ + subst hc + refine mrel_bind (mrel_gets (Ra := FunRel embSchedulerAction) fun _ _ hs => hs.schedulerAction_eq) fun aH aL ha => ?_ + subst ha + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs tcbPtr).symm) fun sH sL hs => ?_ + subst hs + have haeq : aH = .resume_cur_thread ↔ embSchedulerAction aH = .resumeCurThread := by + cases aH <;> simp [embSchedulerAction] + refine mrel_when (by simp [holConj_eq_true, holEq_eq_true, holNot_eq_true, haeq]) fun _ => ?_ + exact setSchedulerAction_equiv .choose_new_thread + +theorem setThreadState_equiv (ref : ObjRef) (ts : Structures_A.thread_state) : + MRel SR Eq + (KHeap_A.set_thread_state ref ts) (Fl4Spec.setThreadState ref (embThreadState ts)) := by + unfold KHeap_A.set_thread_state Fl4Spec.setThreadState + exact mrel_kbind (threadSet_equiv (fun _ => rfl) ref) (setThreadStateAct_equiv ref) + +theorem setMcpriority_equiv (ref : ObjRef) (mcp : Priority) : + MRel SR Eq + (KHeap_A.set_mcpriority ref mcp) (Fl4Spec.setMcpriority ref mcp) := + threadSet_equiv (fun _ => rfl) ref + +theorem getSkObjRef_equiv {αH αL : Type} [Nonempty αH] [Nonempty αL] + {e : αH → αL} + (he_inj : Function.Injective e) + {CH : αH → Structures_A.kernel_object} {CL : αL → KernelObject} + (hC_inj : Function.Injective CH) + (hC : ∀ a, CL (e a) = embKernelObject (CH a)) + (hsurj : ∀ ko aL, CL aL = embKernelObject ko → ∃ aH, aL = e aH ∧ CH aH = ko) + {fH : αH → Option ObjRef} {fL : αL → Option ObjRef} + (hf : ∀ a, fL (e a) = fH a) (ref : ObjRef) : + MRel SR Eq + (KHeap_A.get_sk_obj_ref CH fH ref) (Fl4Spec.getSkObjRef CL fL ref) := by + unfold KHeap_A.get_sk_obj_ref Fl4Spec.getSkObjRef + exact mrel_bind (getSimpleKo_equiv he_inj hC_inj hC hsurj ref) fun aH aL ha => by + subst ha; exact mrel_return (hf aH).symm + +theorem updateSkObjRef_equiv {αH αL : Type} [Nonempty αH] [Nonempty αL] + {e : αH → αL} + (he_inj : Function.Injective e) + {CH : αH → Structures_A.kernel_object} {CL : αL → KernelObject} + (hC_inj : Function.Injective CH) + (hC : ∀ a, CL (e a) = embKernelObject (CH a)) + (hsurj : ∀ ko aL, CL aL = embKernelObject ko → ∃ aH, aL = e aH ∧ CH aH = ko) + {fH : (Option ObjRef → Option ObjRef) → αH → αH} + {fL : (Option ObjRef → Option ObjRef) → αL → αL} + (hf : ∀ g a, fL g (e a) = e (fH g a)) (ref : ObjRef) (new : Option ObjRef) : + MRel SR Eq + (KHeap_A.update_sk_obj_ref CH fH ref new) (Fl4Spec.updateSkObjRef CL fL ref new) := by + unfold KHeap_A.update_sk_obj_ref Fl4Spec.updateSkObjRef + refine mrel_bind (getSimpleKo_equiv he_inj hC_inj hC hsurj ref) fun aH aL ha => ?_ + subst ha + rw [hf (fun _ => new) aH] + exact setSimpleKo_equiv he_inj hC_inj hC hsurj ref (fH (fun _ => new) aH) + +theorem getNtfnObjRef_equiv + {fH : Structures_A.notification → Option ObjRef} {fL : Notification → Option ObjRef} + (hf : ∀ n, fL (embNotification n) = fH n) (ref : ObjRef) : + MRel SR Eq + (KHeap_A.get_sk_obj_ref .Notification fH ref) (Fl4Spec.getNtfnObjRef fL ref) := + getSkObjRef_equiv embNotification_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) hf ref + +theorem setNtfnObjRef_equiv + {fH : (Option ObjRef → Option ObjRef) → Structures_A.notification → Structures_A.notification} + {fL : (Option ObjRef → Option ObjRef) → Notification → Notification} + (hf : ∀ g n, fL g (embNotification n) = embNotification (fH g n)) + (ref : ObjRef) (new : Option ObjRef) : + MRel SR Eq + (KHeap_A.update_sk_obj_ref .Notification fH ref new) + (Fl4Spec.setNtfnObjRef fL ref new) := + updateSkObjRef_equiv embNotification_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) hf ref new + +theorem getReplyObjRef_equiv + {fH : Structures_A.reply → Option ObjRef} {fL : Reply → Option ObjRef} + (hf : ∀ r, fL (embReply r) = fH r) (ref : ObjRef) : + MRel SR Eq + (KHeap_A.get_sk_obj_ref .Reply fH ref) (Fl4Spec.getReplyObjRef fL ref) := + getSkObjRef_equiv embReply_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) hf ref + +theorem setReplyObjRef_equiv + {fH : (Option ObjRef → Option ObjRef) → Structures_A.reply → Structures_A.reply} + {fL : (Option ObjRef → Option ObjRef) → Reply → Reply} + (hf : ∀ g r, fL g (embReply r) = embReply (fH g r)) + (ref : ObjRef) (new : Option ObjRef) : + MRel SR Eq + (KHeap_A.update_sk_obj_ref .Reply fH ref new) + (Fl4Spec.setReplyObjRef fL ref new) := + updateSkObjRef_equiv embReply_injective (fun _ _ h => by injection h) (fun _ => rfl) + (fun ko aL h => by cases ko <;> simp [embKernelObject] at h; exact ⟨_, h, rfl⟩) hf ref new + +theorem isIrqActive_equiv (irq : BitVec 8) : + MRel SR Eq + (KHeap_A.is_irq_active irq) (Fl4Spec.isIrqActive (embIrq irq)) := by + unfold KHeap_A.is_irq_active Fl4Spec.isIrqActive + refine mrel_liftM (fun sH sL hs => ?_) (getIrqState_equiv irq) + subst hs + cases sH <;> simp [embIrqState, holNot, holEq] + +theorem setFlags_equiv (ref : ObjRef) (flags : Set Structs_B.tcb_flag) : + MRel SR Eq + (KHeap_A.set_flags ref flags) (Fl4Spec.setFlags ref (embTcbFlags flags)) := + threadSet_equiv (fun _ => rfl) ref + +theorem asUser_equiv {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + {fH : HolNonDet MachineOps.user_context αH} {fL : UserMonad αL} + (hf : MRel (FunRel embUserContext) Ra fH fL) (tptr : ObjRef) : + MRel SR Ra + (KHeap_A.as_user tptr fH) (Fl4Spec.asUser tptr fL) := by + unfold KHeap_A.as_user Fl4Spec.asUser + refine mrel_bind (mrel_getsThe (getTcb_equiv tptr)) fun tH tL ht => ?_ + subst ht + refine mrel_bind (mrel_return (Ra := FunRel embUserContext) + (by simp [FunRel, embTcb, archTcbContextGet_eq])) fun ucH ucL huc => ?_ + obtain ⟨hfail, h1, h2⟩ := hf ucH ucL huc + refine mrel_bind (mrel_selectF (Ra := ProdRel Ra (FunRel embUserContext)) hfail ⟨?_, ?_⟩) ?_ + · rintro ⟨aH, ucH'⟩ hmH; obtain ⟨aL, ucL', hmL, ha, huc'⟩ := h1 aH ucH' hmH + exact ⟨(aL, ucL'), hmL, ha, huc'⟩ + · rintro ⟨aL, ucL'⟩ hmL; obtain ⟨aH, ucH', hmH, ha, huc'⟩ := h2 aL ucL' hmL + exact ⟨(aH, ucH'), hmH, ha, huc'⟩ + · rintro ⟨aH, ucH'⟩ ⟨aL, ucL'⟩ ⟨ha, huc'⟩ + subst huc' + simp only [holCaseProd_eq] + refine mrel_bind (mrel_return (Ra := FunRel embTcb) (by + simp [FunRel, embTcb, Structures_A.tcb.tcb_arch_update, archTcbContextSet_eq])) + fun ntH ntL hnt => ?_ + subst hnt + exact mrel_kbind (setObject_equiv tptr (.TCB ntH)) (mrel_return ha) + +theorem throwOnFalse_equiv {εH εL : Type} [Nonempty εH] {Re : εH → εL → Prop} + {eH : εH} {eL : εL} (he : Re eH eL) + {fH : HolNonDet (Structures_A.state ZH) Bool} {fL : SMonad ZL Bool} + (hf : MRel SR Eq fH fL) : + MRelE SR Re Eq + (KHeap_A.throw_on_false eH fH) (Fl4Spec.throwOnFalse eL fL) := by + unfold KHeap_A.throw_on_false Fl4Spec.throwOnFalse + exact mrele_bindE (mrele_liftE hf) fun vH vL hv => by + subst hv; exact mrele_unlessE Iff.rfl fun _ => mrele_throwError he + +end KHeapMonad + +variable {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} +variable {ZH ZL : Type} [Nonempty ZH] [Deterministic_A.state_ext_class ZH] +variable {ExstRel : ZH → ZL → Prop} + +theorem isCurDomainExpired_eq (hc : ConfigRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : StateRel RestRel ExstRel sH sL) : + Fl4Spec.isCurDomainExpired sL = KHeap_A.is_cur_domain_expired sH := by + unfold Fl4Spec.isCurDomainExpired KHeap_A.is_cur_domain_expired + rw [show Fl4Spec.numDomains = Kernel_Config.numDomains from hc.numDomains_eq, hs.domainTime_eq] + apply Bool.eq_iff_iff.mpr + simp [holLt_eq_true, HolOrd.ltVal, HolOne.oneVal, HolZero.zeroVal] + +theorem updateTimeStamp_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) : + MRel (StateRel RestRel ExstRel) Eq + KHeap_A.update_time_stamp Fl4Spec.updateTimeStamp := by + unfold KHeap_A.update_time_stamp Fl4Spec.updateTimeStamp + refine mrel_bind (mrel_gets fun _ _ hs => hs.curTime_eq.symm) fun ptH ptL hpt => ?_ + subst hpt + refine mrel_bind (mrel_doMachineOp (getCurrentTime_equiv hop)) fun ctH ctL hct => ?_ + subst hct + refine mrel_bind (mrel_return (aH := ctH - ptH) rfl) fun cH cL hcost => ?_ + subst hcost + refine mrel_kbind (mrel_modify fun _ _ hs => { hs with curTime_eq := rfl }) ?_ + refine mrel_kbind (mrel_modify fun _ _ hs => { hs with consumedTime_eq := ?_ }) ?_ + · simp [Structures_A.abstract_state.consumed_time_update, hs.consumedTime_eq, HolAdd.addVal] + refine mrel_bind (mrel_gets fun _ _ hs => hs.domainTime_eq.symm) fun dtH dtL hdt => ?_ + subst hdt + refine mrel_when (by + simp [show Fl4Spec.numDomains = Kernel_Config.numDomains from hc.numDomains_eq, + holLt_eq_true, HolOrd.ltVal, HolOne.oneVal]) fun _ => ?_ + refine mrel_if (by simp [holLe_eq_true, HolOrd.leVal, HolAdd.addVal, minBudget_eq hop]) + (fun _ => mrel_modify fun _ _ hs => { hs with domainTime_eq := rfl }) + (fun _ => mrel_modify fun _ _ hs => { hs with domainTime_eq := rfl }) + +variable [StateExt ZL] [ser : StateExtRel RestRel ZH ZL] + +local notation "SR" => StateRel RestRel ser.exstRel + +theorem preemptionPoint_equiv (hcfg : ConfigRel) (hop : OpaqueRel RestRel) : + MRelE SR Eq Eq + KHeap_A.preemption_point Fl4Spec.preemptionPoint := by + unfold KHeap_A.preemption_point Fl4Spec.preemptionPoint + refine mrele_kbindE (mrele_liftE (doExtendedOp_equiv updateWorkUnits_equiv)) ?_ + refine orChoiceE_equiv workUnitsLimitReached_equiv ?_ (mrele_returnOk rfl) + refine mrele_kbindE (mrele_liftE (doExtendedOp_equiv resetWorkUnits_equiv)) ?_ + refine mrele_kbindE (mrele_liftE (updateTimeStamp_equiv hcfg hop)) ?_ + refine mrele_bindE (mrele_liftE (mrel_doMachineOp (getActiveIRQ_equiv hop true))) + fun oH oL ho => ?_ + refine mrele_bindE (mrele_liftE (mrel_gets fun _ _ hs => (isCurDomainExpired_eq hcfg hs).symm)) + fun expH expL hexp => ?_ + subst hexp + refine mrele_bindE (mrele_liftE (mrel_gets fun _ _ hs => hs.curSc_eq.symm)) + fun scH scL hsc => ?_ + subst hsc + refine mrele_bindE (mrele_liftE (mrel_gets fun _ _ hs => hs.consumedTime_eq.symm)) + fun cH cL hc => ?_ + subst hc + refine mrele_bindE (mrele_liftE (getScActive_equiv scH)) fun actH actL hact => ?_ + subst hact + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun sH sL hs => ?_)) fun sfH sfL hsf => ?_ + · have h := readScRefillSufficient_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) hop scH cH sH sL hs + cases h1 : KHeap_A.read_sc_refill_sufficient scH cH sH <;> + cases h2 : Fl4Spec.readScRefillSufficient scH cH sL <;> + simp [h1, h2, OptRel] at h ⊢ + exact h + subst hsf + subst ho + exact mrele_whenE (by simp [holDisj_eq_true, holNot_eq_true, holConj_eq_true, holEq_eq_true]) + fun _ => mrele_throwError rfl + + +end + +end L4vRefX64.Equiv.KHeap diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Machine.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Machine.lean new file mode 100644 index 000000000..5298f9d90 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Machine.lean @@ -0,0 +1,295 @@ +import L4vRefX64.Spec.Aligned +import L4vRefX64.Spec.More_Word_Operations +import L4vRefX64.Rel.State + +namespace L4vRefX64.Equiv.Machine + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec +open Fl4Spec +open Classical + +noncomputable section + +variable {RestRel : MachineTypes.machine_state_rest → Fl4Spec.MachineStateRest → Prop} + +theorem usToTicks_eq (hop : OpaqueRel RestRel) (us : Fl4Spec.Ticks) : + Fl4Spec.usToTicks us = Time.us_to_ticks us := by + unfold Fl4Spec.usToTicks Time.us_to_ticks + rw [hop.ticksPerTimerUnit_eq, hop.timerUnit_eq] + rfl + +theorem ticksToUs_eq (hop : OpaqueRel RestRel) (t : Fl4Spec.Ticks) : + Fl4Spec.ticksToUs t = Time.ticks_to_us t := by + unfold Fl4Spec.ticksToUs Time.ticks_to_us + rw [hop.ticksPerTimerUnit_eq, hop.timerUnit_eq] + rfl + +theorem MAX_PERIOD_eq (hop : OpaqueRel RestRel) : + Fl4Spec.MAX_PERIOD = Time.MAX_PERIOD := by + unfold Fl4Spec.MAX_PERIOD Time.MAX_PERIOD + rw [hop.maxPeriodUs_eq] + exact usToTicks_eq hop _ + +theorem MAX_RELEASE_TIME_eq (hop : OpaqueRel RestRel) : + Fl4Spec.MAX_RELEASE_TIME = Time.MAX_RELEASE_TIME := by + unfold Fl4Spec.MAX_RELEASE_TIME Time.MAX_RELEASE_TIME + rw [MAX_PERIOD_eq hop] + rfl + +theorem getCurrentTime_equiv (hop : OpaqueRel RestRel) : + MRel (MachineStateRel RestRel) Eq MachineOps.getCurrentTime Fl4Spec.getCurrentTime := by + unfold MachineOps.getCurrentTime Fl4Spec.getCurrentTime + refine mrel_kbind (mrel_modify fun msH msL hms => ?_) ?_ + · refine { hms with timeState_eq := ?_ } + simp [MachineTypes.machine_state.time_state_update, HolAdd.addVal, HolOne.oneVal, + hms.timeState_eq] + refine mrel_bind (mrel_gets (Ra := Eq) fun msH msL hms => ?_) ?_ + · simp [holComp, hms.timeState_eq, hop.timeOracle_eq] + rintro _ _ rfl + refine mrel_bind (mrel_gets fun _ _ hms => hms.lastMachineTime_eq.symm) ?_ + rintro _ _ rfl + refine mrel_bind (mrel_return (Ra := Eq) rfl) ?_ + rintro _ _ rfl + refine mrel_bind (mrel_return (Ra := Eq) ?_) ?_ + · simp [holMin, HolOrd.leVal, holUnsigned, HolNeg.negVal, HolAdd.addVal, HolOne.oneVal, + HolMul.mulVal, HolNumeral.ofNatVal, Fl4Spec.timeBufferConst, MAX_PERIOD_eq hop] + rfl + rintro _ _ rfl + refine mrel_kbind (mrel_modify fun msH msL hms => { hms with lastMachineTime_eq := rfl }) ?_ + exact mrel_return rfl + +theorem getActiveIRQ_equiv (hop : OpaqueRel RestRel) (inKernel : Bool) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.getActiveIRQ inKernel) (Fl4Spec.getActiveIRQ inKernel) := by + unfold MachineOps.getActiveIRQ Fl4Spec.getActiveIRQ + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ hms => hms.irqMasks_eq.symm) ?_ + rintro mask _ rfl + refine mrel_kbind (mrel_modify fun msH msL hms => ?_) ?_ + · refine { hms with irqState_eq := ?_ } + simp [MachineTypes.machine_state.irq_state_update, HolAdd.addVal, HolOne.oneVal, + hms.irqState_eq] + refine mrel_bind (mrel_gets (Ra := Eq) fun msH msL hms => ?_) ?_ + · simp [holComp, hms.irqState_eq, hop.irqOracle_eq] + rintro irq _ rfl + refine mrel_if ?_ (fun _ => mrel_return rfl) (fun _ => mrel_return rfl) + simp [holDisj_eq_true, holConj_eq_true, holMember_eq_true, + MachineOps.non_kernel_IRQs, Fl4Spec.nonKernelIRQs, HolCompleteLattice.holBot, + HolNumeral.ofNatVal] + +theorem maskInterrupt_equiv (masked : Bool) (irq : BitVec 8) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.maskInterrupt masked irq) (Fl4Spec.maskInterrupt masked irq) := by + unfold MachineOps.maskInterrupt Fl4Spec.maskInterrupt + refine mrel_modify fun msH msL hms => { hms with irqMasks_eq := ?_ } + simp only [MachineTypes.machine_state.irq_masks_update, holFunUpd_eq, hms.irqMasks_eq] + funext i + by_cases h : i = irq + · subst i + simp + · simp [Function.update, h] + +theorem getRegister_equiv (reg : MachineTypes.register) : + MRel (FunRel embUserContext) Eq (MachineOps.getRegister reg) (Fl4Spec.getRegister (embRegister reg)) := by + unfold MachineOps.getRegister Fl4Spec.getRegister + refine mrel_gets fun ctxH ctxL hctx => ?_ + subst ctxL + cases ctxH + simp [embUserContext, MachineOps.user_context.user_regs, MachineOps.case_user_context] + +theorem setRegister_equiv (reg : MachineTypes.register) (value : Fl4Spec.Word) : + MRel (FunRel embUserContext) Eq + (MachineOps.setRegister reg value) (Fl4Spec.setRegister (embRegister reg) value) := by + unfold MachineOps.setRegister Fl4Spec.setRegister + refine mrel_modify fun ctxH ctxL hctx => ?_ + subst ctxL + cases ctxH + simp [FunRel, embUserContext, holFunUpd_eq, + MachineOps.user_context.user_regs, MachineOps.user_context.user_fpu_state, + MachineOps.case_user_context] + symm + exact fun_update_comp unembRegister_emb embRegister_unemb _ _ _ + +theorem wordSize_eq : Fl4Spec.wordSize = Machine_Word_64_Basics.word_size := rfl + +theorem pageBitsForSize_eq (sz : MachineTypes.vmpage_size) : + Fl4Spec.pageBitsForSize (embVMPageSize sz) = MachineTypes.pageBitsForSize sz := by + cases sz <;> rfl + +theorem ptrAdd_eq {w : Nat} (ptr : BitVec w) (n : Nat) : + Fl4Spec.ptrAdd ptr n = More_Word_Operations.ptr_add ptr n := rfl + +theorem holUptoEnum_bv_eq {w : Nat} (a b : BitVec w) : + holUptoEnum a b = Fl4Spec.uptoEnum a b := by + have hfrom : ∀ x : BitVec w, holFromEnum x = x.toNat := by + intro x + unfold holFromEnum + change holTheIndex ((List.range (2 ^ w)).map (BitVec.ofNat w)) x = x.toNat + have hgen : ∀ (k n : Nat) (x : BitVec w), x.toNat < k + n → k ≤ x.toNat → + holTheIndex ((List.range' k n).map (BitVec.ofNat w)) x = x.toNat - k := by + intro k n + induction n generalizing k with + | zero => intro x h1 h2; omega + | succ n ih => + intro x h1 h2 + simp only [List.range'_succ, List.map_cons, holTheIndex] + have hlt : k < 2 ^ w := by have := x.isLt; omega + by_cases hkx : BitVec.ofNat w k = x + · have heq : k = x.toNat := by + have := congrArg BitVec.toNat hkx + rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt hlt] at this + exact this + simp [heq] + · have hne : k ≠ x.toNat := fun he => hkx (by + apply BitVec.eq_of_toNat_eq; rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt hlt, he]) + simp only [hkx, ↓reduceIte] + rw [ih (k + 1) x (by omega) (by omega)] + omega + have := hgen 0 (2 ^ w) x (by simpa using x.isLt) (Nat.zero_le _) + simpa [List.range_eq_range'] using this + unfold holUptoEnum Fl4Spec.uptoEnum holListUpt + rw [hfrom a, hfrom b] + apply List.map_congr_left + intro k hk + simp only [List.mem_range'] at hk + have hlt : k < 2 ^ w := by have := b.isLt; omega + unfold holToEnum holNth holTheOpt + simp [HolEnum.enumList, hlt] + +theorem holUptoEnumStep_eq {w : Nat} (a b c : BitVec w) : + holUptoEnumStep a b c = Fl4Spec.uptoEnumStep a b c := by + unfold holUptoEnumStep Fl4Spec.uptoEnumStep + rw [holUptoEnum_bv_eq] + +theorem wordBits_eq : Fl4Spec.wordBits = Machine_Word_64_Basics.word_bits := rfl + +theorem dataToCptr_eq (x : Word) : Fl4Spec.dataToCptr x = Machine_A.data_to_cptr x := rfl + +theorem natToLen_eq (n : Nat) : Fl4Spec.natToLen n = Machine_A.nat_to_len n := rfl + +theorem msg_info_register_eq : + Fl4Spec.msg_info_register = embRegister Machine_A.msg_info_register := rfl + +theorem msg_registers_eq : + Fl4Spec.msg_registers = Machine_A.msg_registers.map embRegister := rfl + +theorem badge_register_eq : Fl4Spec.badge_register = embRegister Machine_A.badge_register := rfl + +theorem nextInstructionRegister_eq : + Fl4Spec.nextInstructionRegister = embRegister MachineTypes.nextInstructionRegister := rfl + +theorem faultRegister_eq : Fl4Spec.faultRegister = embRegister MachineTypes.faultRegister := rfl + +theorem getRestartPC_equiv : + MRel (FunRel embUserContext) Eq MachineOps.getRestartPC Fl4Spec.getRestartPC := + getRegister_equiv .FaultIP + +theorem setNextPC_equiv (value : Word) : + MRel (FunRel embUserContext) Eq (MachineOps.setNextPC value) (Fl4Spec.setNextPC value) := + setRegister_equiv .NextIP value + +theorem loadWord_equiv (p : Word) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.loadWord p) (Fl4Spec.loadWord p) := by + unfold MachineOps.loadWord Fl4Spec.loadWord + refine mrel_bind (mrel_gets fun msH msL hms => hms.underlyingMemory_eq.symm) ?_ + rintro mH mL rfl + refine mrel_kbind (mrel_assert ?_) (mrel_return ?_) + · have hm : Fl4Spec.mask (w := 64) 3 = 7#64 := by decide + simp [holEq_eq_true, holWordAnd, holWordMask, hm, HolZero.zeroVal, HolNumeral.ofNatVal] + · rfl + +theorem storeWord_equiv (p w : Word) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.storeWord p w) (Fl4Spec.storeWord p w) := by + unfold MachineOps.storeWord Fl4Spec.storeWord + refine mrel_kbind (mrel_assert ?_) (mrel_modify ?_) + · have hm : Fl4Spec.mask (w := 64) 3 = 7#64 := by decide + simp [holEq_eq_true, holWordAnd, holWordMask, hm, HolZero.zeroVal, HolNumeral.ofNatVal] + · intro msH msL hms + refine { hms with underlyingMemory_eq := ?_ } + simp only [MachineTypes.machine_state.underlying_memory_update, holListFold, + holFunUpd_eq, holOfInt, holIntToNat, + holNth, holTheOpt, HolZero.zeroVal, HolNumeral.ofNatVal, HolAdd.addVal, HolSub.subVal] + rw [hms.underlyingMemory_eq] + have hupto : holListUpto (0 : Int) (Int.ofNat 7) = Fl4Spec.intUpto 0 7 := by + simp [holListUpto, Fl4Spec.intUpto] + have hwr : holWordRsplit (m := 8) w = Fl4Spec.wordRsplit (m := 8) w := rfl + rw [hupto, hwr] + have hlen : (Fl4Spec.wordRsplit (m := 8) w).length = 8 := by + simp [Fl4Spec.wordRsplit] + have hstep : ∀ (m : Word → Word8) (a : Int), + Function.update m (p + BitVec.ofInt 64 a) + ((Fl4Spec.wordRsplit (m := 8) w).getD (7 - a.toNat) 0) = + @Function.update Word (fun _ => Word8) (Classical.decEq Word) m + (BitVec.add p (BitVec.ofInt 64 a)) + (match (Fl4Spec.wordRsplit (m := 8) w)[Nat.sub 7 a.toNat]? with + | some v => v | none => holUndefined) := by + intro m a + have hx : 7 - a.toNat < (Fl4Spec.wordRsplit (m := 8) w).length := by rw [hlen]; omega + have hget : (Fl4Spec.wordRsplit (m := 8) w).getD (7 - a.toNat) 0 = + match (Fl4Spec.wordRsplit (m := 8) w)[Nat.sub 7 a.toNat]? with + | some v => v | none => holUndefined := by + simp [List.getD, List.getElem?_eq_getElem hx] + rw [hget]; funext k; simp [Function.update] + have hfold : ∀ (is : List Int) (m : Word → Word8), + List.foldl (fun m a => Function.update m (p + BitVec.ofInt 64 a) + ((Fl4Spec.wordRsplit (m := 8) w).getD (7 - a.toNat) 0)) m is = + List.foldl (fun m a => @Function.update Word (fun _ => Word8) (Classical.decEq Word) m + (BitVec.add p (BitVec.ofInt 64 a)) + (match (Fl4Spec.wordRsplit (m := 8) w)[Nat.sub 7 a.toNat]? with + | some v => v | none => holUndefined)) m is := by + intro is m; simp only [hstep] + exact hfold (Fl4Spec.intUpto 0 7) msH.underlying_memory + +theorem clearMemory_equiv (ptr : Word) (bytelength : Nat) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.clearMemory ptr bytelength) (Fl4Spec.clearMemory ptr bytelength) := by + unfold MachineOps.clearMemory Fl4Spec.clearMemory + rw [holUptoEnumStep_eq] + refine mrel_mapMx (fun a b hab => by subst hab; exact storeWord_equiv a 0) (listRel_eq _) + +theorem clearMemoryVM_equiv (ptr : Word) (bits : Nat) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.clearMemoryVM ptr bits) (Fl4Spec.clearMemoryVM ptr bits) := mrel_return rfl + +theorem initMemory_equiv (ptr : Word) (bytelength : Nat) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.initMemory ptr bytelength) (Fl4Spec.initMemory ptr bytelength) := + clearMemory_equiv ptr bytelength + +theorem freeMemory_equiv (ptr : Word) (bits : Nat) : + MRel (MachineStateRel RestRel) Eq + (MachineOps.freeMemory ptr bits) (Fl4Spec.freeMemory ptr bits) := by + unfold MachineOps.freeMemory Fl4Spec.freeMemory + rw [holUptoEnumStep_eq] + have hpow : HolPow.powVal (HolNumeral.ofNatVal (α := BitVec 64) 2) bits = (2 : Word) ^ bits := by + apply BitVec.eq_of_toNat_eq + simp [HolPow.powVal, HolNumeral.ofNatVal, BitVec.toNat_pow] + have harg : + Fl4Spec.uptoEnumStep ptr (HolAdd.addVal ptr Machine_Word_64_Basics.word_size) + (HolSub.subVal (HolAdd.addVal ptr (HolPow.powVal (HolNumeral.ofNatVal (α := BitVec 64) 2) bits)) + (HolOne.oneVal (α := BitVec 64))) = + Fl4Spec.uptoEnumStep ptr (ptr + BitVec.ofNat 64 wordSize) (ptr + 2 ^ bits - 1) := by + rw [hpow]; rfl + rw [harg] + exact mrel_mapMx (fun a b hab => by subst hab; exact storeWord_equiv a 0) (listRel_eq _) + +theorem isAligned_iff {w : Nat} (x : BitVec w) (n : Nat) : + Aligned.is_aligned x n = true ↔ Fl4Spec.isAligned x n := by + have hdvd : ∀ a b : Int, holDvd a b = true ↔ a ∣ b := fun _ _ => by + simp [holDvd, HolDvd.dvdVal] + unfold Aligned.is_aligned Fl4Spec.isAligned + simp only [holMapFun, hdvd, holWordRep, holId, HolPow.powVal, HolNumeral.ofNatVal, + holWordTakeBit, HolTakeBit.takeBitVal] + have hlt : x.toNat < 2 ^ w := x.isLt + have hmod : (Int.ofNat x.toNat) % ((2 : Int) ^ w) = Int.ofNat x.toNat := by + have : (Int.ofNat x.toNat) % Int.ofNat (2 ^ w) = Int.ofNat (x.toNat % 2 ^ w) := rfl + rw [show ((2 : Int) ^ w) = Int.ofNat (2 ^ w) by norm_cast, this, Nat.mod_eq_of_lt hlt] + rw [hmod, show (Int.ofNat 2) ^ n = Int.ofNat (2 ^ n) by norm_cast] + exact Int.ofNat_dvd + +end + +end L4vRefX64.Equiv.Machine diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Retype.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Retype.lean new file mode 100644 index 000000000..6f36634f4 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Retype.lean @@ -0,0 +1,417 @@ +import L4vRefX64.Patched +import L4vRefX64.Equiv.ArchCap +import L4vRefX64.Equiv.CSpaceAcc +import L4vRefX64.Spec.ArchRetype_A +import L4vRefX64.Equiv.VSpaceAccess + +namespace L4vRefX64.Equiv.Retype + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.Types L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Deterministic L4vRefX64.Equiv.CSpaceAcc +open L4vRefX64.Equiv.VSpaceAccess +open Fl4Spec Classical + +noncomputable section + +theorem archDefaultCap_eq (type : Arch_Structs_A.aobject_type) (ref : ObjRef) + (bits : Nat) (device : Bool) : + Fl4Spec.archDefaultCap (embAObjectType type) ref bits device = + embArchCap (Arch_Structs_A.arch_default_cap type ref bits device) := by + cases type <;> simp [Fl4Spec.archDefaultCap, embAObjectType, Arch_Structs_A.arch_default_cap, + Arch_Structs_A.case_aobject_type, embArchCap, embVMPageSize, embVMMapType, vmReadWrite_eq, HolZero.zeroVal] + +theorem defaultArchObject_eq (type : Arch_Structs_A.aobject_type) (device : Bool) (bits : Nat) : + Fl4Spec.defaultArchObject (embAObjectType type) device bits = + embArchKobj (Arch_Structs_A.default_arch_object type device bits) := by + cases type <;> rfl + +theorem emptyContext_eq : + Fl4Spec.emptyContext = embUserContext ArchRetype_A.empty_context := by + rfl + +theorem initArchTcb_eq : + Fl4Spec.initArchTcb = embArchTcb ArchRetype_A.init_arch_tcb := by + rfl + +theorem defaultCap_eq (ty : Structures_A.apiobject_type) (oref : ObjRef) (s : Nat) (dev : Bool) : + Fl4Spec.defaultCap (embApiObjectType ty) oref s dev = + embCap (Retype_A.default_cap ty oref s dev) := by + cases ty with + | Untyped => rfl + | TCBObject => rfl + | EndpointObject => + simp only [Fl4Spec.defaultCap, Retype_A.default_cap, embApiObjectType, embCap, + HolCompleteLattice.holTop, HolZero.zeroVal] + rw [embRightsSet_univ] + | NotificationObject => + simp only [Fl4Spec.defaultCap, Retype_A.default_cap, embApiObjectType, embCap, + holInsert_eq, HolCompleteLattice.holBot, HolZero.zeroVal] + congr 1; ext x; rw [← embRights_unemb x] + simp only [Set.mem_insert_iff, Set.mem_singleton_iff, Set.mem_empty_iff_false, + embRightsSet_mem, or_false] + cases unembRights x <;> simp [embRights] + | CapTableObject => rfl + | SchedContextObject => + simp [Fl4Spec.defaultCap, Retype_A.default_cap, embApiObjectType, embCap, + minSchedContextBits_eq, HolSub.subVal] + | ReplyObject => + simp only [Fl4Spec.defaultCap, Retype_A.default_cap, embApiObjectType, embCap, + holInsert_eq, HolCompleteLattice.holBot] + congr 1; ext x; rw [← embRights_unemb x] + simp only [Set.mem_insert_iff, Set.mem_singleton_iff, Set.mem_empty_iff_false, + embRightsSet_mem, or_false] + cases unembRights x <;> simp [embRights] + | ArchObject a => + simp [Fl4Spec.defaultCap, Retype_A.default_cap, embApiObjectType, embCap, + archDefaultCap_eq] + +theorem emptyCnode_eq (bits : Nat) : + Fl4Spec.emptyCnode bits = embCnodeContents (Retype_A.empty_cnode bits) := by + funext x + unfold Fl4Spec.emptyCnode embCnodeContents Retype_A.empty_cnode + simp only [holIf_eq, holEq_eq_true, holSize_list] + split_ifs <;> rfl + +theorem patched_defaultTcb_equiv {RestRel} (hop : OpaqueRel RestRel) (domain : BitVec 8) : + Fl4Spec.defaultTcb domain = + embTcb { Structures_A.default_tcb domain with tcb_arch := ⟨Patched.newContext, false, ()⟩ } := by + simp [Fl4Spec.defaultTcb, Fl4Spec.defaultArchTcb, Structures_A.default_tcb, embTcb, + embArchTcb, Patched.newContext_equiv hop, embTcbFlags, HolCompleteLattice.holBot, + embThreadState, embCap, HolZero.zeroVal, Fl4Spec.defaultPriority, Structures_A.default_priority] + rfl + +theorem patched_defaultObject_eq {RestRel} (hop : OpaqueRel RestRel) (api : Structures_A.apiobject_type) (dev : Bool) (n : Nat) (d : Domain) + (h : api ≠ .Untyped) : + Fl4Spec.defaultObject (embApiObjectType api) dev n d = + embKernelObject (Patched.default_object api dev n d) := by + cases api with + | Untyped => exact absurd rfl h + | TCBObject => + exact congrArg Fl4Spec.KernelObject.tcb (patched_defaultTcb_equiv hop d) + | EndpointObject => rfl + | NotificationObject => rfl + | CapTableObject => + simp [Fl4Spec.defaultObject, Patched.default_object, Structures_A.case_apiobject_type, + embApiObjectType, embKernelObject, Retype_A.default_object, emptyCnode_eq] + | SchedContextObject => + simp [Fl4Spec.defaultObject, Patched.default_object, Structures_A.case_apiobject_type, + embApiObjectType, embKernelObject, Retype_A.default_object, defaultSchedContext_eq, minSchedContextBits_eq, + HolSub.subVal] + | ReplyObject => rfl + | ArchObject a => + simp [Fl4Spec.defaultObject, Patched.default_object, Structures_A.case_apiobject_type, + embApiObjectType, embKernelObject, Retype_A.default_object, defaultArchObject_eq] + +theorem patched_objBitsApi_equiv (type : Structures_A.apiobject_type) (bits : Nat) : + Fl4Spec.objBitsApi (embApiObjectType type) bits = Patched.obj_bits_api type bits := by + cases type with + | ArchObject type => cases type <;> rfl + | _ => rfl + +theorem objBitsApi_ntfn_delta (sz : Nat) : + Retype_A.obj_bits_api .NotificationObject sz = 5 ∧ + Fl4Spec.objBitsApi .notificationObject sz = 6 := by + constructor + · simp [Retype_A.obj_bits_api, Structures_A.case_apiobject_type, Structures_A.obj_bits, + Arch_Structs_A.ntfn_bits, HolNumeral.ofNatVal] + · simp [Fl4Spec.objBitsApi, Fl4Spec.objBits, Fl4Spec.ntfnBits] + +theorem getFreeRef_eq (base : ObjRef) (idx : Nat) : + Fl4Spec.getFreeRef base idx = Retype_A.get_free_ref base idx := rfl + +theorem getFreeIndex_eq (base free : ObjRef) : + Fl4Spec.getFreeIndex base free = Retype_A.get_free_index base free := rfl + +theorem isDeviceUntypedCap_eq (c : Structures_A.cap) : + Fl4Spec.isDeviceUntypedCap (embCap c) = Retype_A.is_device_untyped_cap c := by + cases c <;> rfl + +theorem bitsOf_eq (c : Structures_A.cap) : + Fl4Spec.bitsOf (embCap c) = Structures_A.bits_of c := by + cases c <;> rfl + +theorem freeIndexOf_eq' (c : Structures_A.cap) : + Fl4Spec.freeIndexOf (embCap c) = Structures_A.free_index_of c := by + cases c <;> 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 objRefOf_eq (cap : Structures_A.cap) : + Fl4Spec.objRefOf (embCap cap) = Structures_A.obj_ref_of cap := by + cases cap with + | ArchObjectCap arch => cases arch <;> rfl + | _ => rfl + +theorem reserveRegion_equiv (ptr : ObjRef) (len : Nat) (kernel : Bool) : + MRel SR Eq (ArchRetype_A.reserve_region ptr len kernel) (Fl4Spec.reserveRegion ptr len kernel) := + mrel_return rfl + +theorem archPostResetUntyped_equiv (device : Bool) (bits : Nat) : + MRel SR Eq (ArchRetype_A.arch_post_reset_untyped device bits) (Fl4Spec.archPostResetUntyped device bits) := + mrel_return rfl + +theorem detype_rel (S : Set ObjRef) {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) : + SR (Retype_A.detype S sH) (Fl4Spec.detype S sL) := by + refine { hs with kheap_eq := fun p => ?_ } + unfold Retype_A.detype Fl4Spec.detype + simp only [Structures_A.abstract_state.kheap_update, holIf_eq, holMember_eq_true] + by_cases hp : p ∈ S + · simp [hp] + · simp [hp, hs.kheap_eq p] + +theorem deleteObjects_equiv (ptr : Word) (bits : Nat) : + MRel SR Eq + (Retype_A.delete_objects ptr bits) (Fl4Spec.deleteObjects ptr bits) := by + unfold Retype_A.delete_objects Fl4Spec.deleteObjects + refine mrel_kbind (mrel_doMachineOp (freeMemory_equiv ptr bits)) ?_ + have hset : holAtLeastAtMost ptr + (HolSub.subVal (HolAdd.addVal ptr (HolPow.powVal (HolNumeral.ofNatVal (α := BitVec 64) 2) bits)) + (HolOne.oneVal (α := BitVec 64))) = + {x : Word | ptr ≤ x ∧ x ≤ ptr + 2 ^ bits - 1} := by + have hpow : BitVec.ofNat 64 ((2#64).toNat ^ bits) = (2 : Word) ^ bits := by + apply BitVec.eq_of_toNat_eq + simp [BitVec.toNat_pow] + ext x + simp only [holAtLeastAtMost, Set.mem_ofPred_eq, HolOrd.leVal, HolSub.subVal, + HolAdd.addVal, HolPow.powVal, HolNumeral.ofNatVal, HolOne.oneVal, hpow] + rfl + rw [hset] + exact mrel_modify fun _ _ hs => detype_rel _ hs + +theorem createCap_equiv_nonExt (ty : Structures_A.apiobject_type) (bits : Nat) + (untyped : CslotPtr) (isDevice : Bool) (p : CslotPtr × ObjRef) + (hslot : NonExtTcbSlot p.1.2) : + MRel SR Eq + (Retype_A.create_cap ty bits untyped isDevice p) + (Fl4Spec.createCap (embApiObjectType ty) bits untyped isDevice p) := by + rcases p with ⟨dest, oref⟩ + unfold Retype_A.create_cap Fl4Spec.createCap + simp only [holCaseProd_eq] + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ hs => by simp [hs.cdt_eq]) fun dpH dpL hdp => ?_ + subst hdp + refine mrel_bind (mrel_gets fun _ _ hs => hs.cdt_eq.symm) fun cH cL hc => ?_ + subst hc + have hupd : holFunUpd cH dest (some untyped) = Function.update cH dest (some untyped) := by + funext x; unfold holFunUpd Function.update; split_ifs <;> rfl + refine mrel_kbind (Ra := Eq) (by rw [hupd]; exact setCdt_equiv _) ?_ + refine mrel_kbind (doExtendedOp_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) (createCapExt_equiv untyped dest dpH)) ?_ + refine mrel_kbind (setOriginal_equiv dest true) ?_ + rw [defaultCap_eq] + exact setCap_equiv_nonExt _ dest hslot + +def retype_region_p (ptr : ObjRef) (numObjects o_bits : Nat) + (v_type : Structures_A.apiobject_type) (dev : Bool) : + HolNonDet (Structures_A.state ZH) (List ObjRef) := + holBind (holReturn (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) + (Patched.obj_bits_api v_type o_bits))) fun obj_size => + holBind (holReturn (holListMap (fun p => More_Word_Operations.ptr_add ptr (HolMul.mulVal p obj_size)) + (holListUpt (HolZero.zeroVal (α := Nat)) numObjects))) fun ptrs => + holBind (holWhen (holNot (holEq v_type .Untyped)) + (holBind (holGets fun s => s.kheap) fun heap => + holBind (holGets fun s => s.cur_domain) fun domain => + holBind (holReturn (holListFoldr (fun p ks => holFunUpd ks p + (some (Patched.default_object v_type dev o_bits domain))) ptrs heap)) fun heap' => + holModify (Structures_A.abstract_state.kheap_update (fun _ => heap')))) + (holKBind (holReturn ptrs)) + +theorem patched_retypeRegion_equiv (hop : OpaqueRel RestRel) (ptr : ObjRef) (numObjects oBits : Nat) + (ty : Structures_A.apiobject_type) (dev : Bool) : + MRel SR Eq + (retype_region_p ptr numObjects oBits ty dev) + (Fl4Spec.retypeRegion ptr numObjects oBits (embApiObjectType ty) dev) := by + unfold retype_region_p Fl4Spec.retypeRegion + have hsz : 2 ^ Fl4Spec.objBitsApi (embApiObjectType ty) oBits = + HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) (Patched.obj_bits_api ty oBits) := by + rw [patched_objBitsApi_equiv ty oBits]; rfl + refine mrel_bind (mrel_return hsz.symm) fun osH osL hos => ?_ + subst hos + have hptrs : (List.range numObjects).map (fun p => Fl4Spec.ptrAdd ptr (p * osH)) = + holListMap (fun p => More_Word_Operations.ptr_add ptr (HolMul.mulVal p osH)) + (holListUpt (HolZero.zeroVal (α := Nat)) numObjects) := by + simp [holListMap_eq, holListUpt, HolZero.zeroVal, List.range_eq_range', ptrAdd_eq, HolMul.mulVal] + refine mrel_bind (mrel_return hptrs.symm) fun psH psL hps => ?_ + subst hps + have hnotU : holNot (holEq ty .Untyped) = true ↔ embApiObjectType ty ≠ .untyped := by + cases ty <;> simp [embApiObjectType, holNot, holEq] + refine mrel_kbind (mrel_when hnotU fun hneL => ?_) (mrel_return rfl) + have hneH : ty ≠ .Untyped := fun he => hneL (by rw [he]; rfl) + refine mrel_bind (mrel_gets (Ra := fun khH khL => ∀ q, khL q = (khH q).map embKernelObject) + fun _ _ hs => hs.kheap_eq) fun khH khL hkh => ?_ + refine mrel_bind (mrel_gets fun _ _ hs => hs.curDomain_eq.symm) fun cdH cdL hcd => ?_ + subst hcd + have hfold : ∀ q, + (psH.foldr (fun p kh => Function.update kh p + (some (Fl4Spec.defaultObject (embApiObjectType ty) dev oBits cdH))) khL) q = + ((holListFoldr (fun p kh => holFunUpd kh p + (some (Patched.default_object ty dev oBits cdH))) psH khH) q).map embKernelObject := by + induction psH with + | nil => exact hkh + | cons p ps ih => + intro q + simp only [List.foldr_cons, holListFoldr] + by_cases hqp : q = p + · subst hqp + simp [Function.update, holFunUpd_eq, patched_defaultObject_eq hop ty dev oBits cdH hneH] + · simp only [Function.update, holFunUpd_eq, hqp] + exact ih q + refine mrel_bind (mrel_return (Ra := fun kH kL => ∀ q, kL q = (kH q).map embKernelObject) hfold) + fun kH kL hk => ?_ + exact mrel_modify fun _ _ hs => { hs with kheap_eq := hk } + +theorem resetUntypedCap_equiv (hop : OpaqueRel RestRel) (hc : ConfigRel) + (srcSlot : CslotPtr) (hslot : NonExtTcbSlot srcSlot.2) : + MRelE SR Eq Eq + (Retype_A.reset_untyped_cap srcSlot) (Fl4Spec.resetUntypedCap srcSlot) := by + unfold Retype_A.reset_untyped_cap Fl4Spec.resetUntypedCap + refine mrele_bindE (mrele_liftE (getCap_equiv_nonExt srcSlot hslot)) fun cH cL hc' => ?_ + subst hc' + refine mrele_bindE (mrele_returnOk (bitsOf_eq cH).symm) fun szH szL hsz => ?_ + subst hsz + refine mrele_bindE (mrele_returnOk (objRefOf_eq cH).symm) fun baseH baseL hbase => ?_ + subst hbase + refine mrele_if (by simp [holEq_eq_true, freeIndexOf_eq', HolZero.zeroVal]) + (fun _ => mrele_returnOk rfl) fun _ => ?_ + refine mrele_kbindE (mrele_liftE (deleteObjects_equiv baseH szH)) ?_ + refine mrele_bindE (mrele_returnOk (isDeviceUntypedCap_eq cH).symm) fun devH devL hdev => ?_ + subst hdev + simp only [holFunApp] + have hchunk : Fl4Spec.resetChunkBits = Kernel_Config.resetChunkBits := hc.resetChunkBits_eq + have hcond : holDisj devH (holLt szH Kernel_Config.resetChunkBits) = true ↔ + devH = true ∨ szH < Fl4Spec.resetChunkBits := by + simp [holDisj_eq_true, holLt_eq_true, HolOrd.ltVal, hchunk] + by_cases hcL : devH = true ∨ szH < Fl4Spec.resetChunkBits + · have hcH : holDisj devH (holLt szH Kernel_Config.resetChunkBits) = true := hcond.mpr hcL + simp only [hcH, holIf_true, hcL, ↓reduceIte] + refine mrele_kbindE (Ra := Eq) (mrele_liftE (Re := Eq) <| + mrel_kbind (mrel_unless Iff.rfl fun _ => + mrel_doMachineOp (clearMemory_equiv baseH (2 ^ szH))) + (setCap_equiv_nonExt (.UntypedCap devH baseH szH 0) srcSlot hslot)) + (mrele_liftE (Re := Eq) (archPostResetUntyped_equiv devH szH)) + · have hcH : holDisj devH (holLt szH Kernel_Config.resetChunkBits) = false := by + cases hb : holDisj devH (holLt szH Kernel_Config.resetChunkBits) + · rfl + · exact absurd (hcond.mp hb) hcL + simp only [hcH, holIf_false, hcL, ↓reduceIte] + refine mrele_kbindE (Ra := Eq) ?_ (mrele_liftE (Re := Eq) (archPostResetUntyped_equiv devH szH)) + have hlist : + ((List.range (2 ^ (szH - Fl4Spec.resetChunkBits))).filter + (fun i => decide (i * 2 ^ Fl4Spec.resetChunkBits < Fl4Spec.freeIndexOf (embCap cH)))).reverse = + holListRev (holListFilter (fun i => + holLt (HolMul.mulVal i (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) Kernel_Config.resetChunkBits)) + (Structures_A.free_index_of cH)) + (holListUpt (HolZero.zeroVal (α := Nat)) + (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) (HolSub.subVal szH Kernel_Config.resetChunkBits)))) := by + simp only [holListRev, holListFilter, holListUpt, HolZero.zeroVal, HolPow.powVal, + HolNumeral.ofNatVal, HolSub.subVal, HolMul.mulVal, List.range_eq_range', + hchunk, freeIndexOf_eq', Nat.sub_zero] + congr 1 + apply List.filter_congr + intro i _ + apply Bool.eq_iff_iff.mpr + simp [holLt_eq_true, HolOrd.ltVal] + refine mrele_mapMEx (Rb := Eq) (fun iH iL hi => ?_) (by rw [hlist]; exact listRel_eq _) + subst hi + refine mrele_kbindE (mrele_liftE (mrel_doMachineOp (by + rw [hchunk] + exact clearMemory_equiv _ _))) ?_ + refine mrele_kbindE (mrele_liftE (by + rw [hchunk] + exact setCap_equiv_nonExt (.UntypedCap devH baseH szH (iH * 2 ^ Kernel_Config.resetChunkBits)) + srcSlot hslot)) ?_ + exact preemptionPoint_equiv hc hop + +theorem initArchObjects_equiv (ty : Structures_A.apiobject_type) (device : Bool) + (ptr : ObjRef) (count bits : Nat) (refs : List ObjRef) : + MRel SR Eq (ArchRetype_A.init_arch_objects ty device ptr count bits refs) + (Fl4Spec.initArchObjects (embApiObjectType ty) device ptr count bits refs) := by + unfold ArchRetype_A.init_arch_objects Fl4Spec.initArchObjects + refine mrel_when (by + rw [holEq_eq_true] + cases ty <;> simp [embApiObjectType] + rename_i arch + cases arch <;> simp [embAObjectType]) fun _ => ?_ + exact mrel_mapMx (Rb := Eq) (fun a _ hab => hab ▸ copyGlobalMappings_equiv a) (listRel_eq refs) + +/-- l4v: Retype_A.invoke_untyped with the X64 object-size and initializer choices. -/ +def invoke_untyped_p : Invocations_A.untyped_invocation → + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) + | .Retype src reset base retypeBase ty bits slots device => + holBindE (holWhenE reset (Retype_A.reset_untyped_cap src)) fun _ => + holLiftE <| holBind (CSpaceAcc_A.get_cap src) fun cap => + holBind (holReturn ((BitVec.ofNat 64 slots.length) <<< Patched.obj_bits_api ty bits)) fun size => + holBind (holReturn (retypeBase + size)) fun free => + holBind (CSpaceAcc_A.set_cap (.UntypedCap device base (Structures_A.bits_of cap) + (holUnsigned (free - base))) src) fun _ => + holBind (retype_region_p retypeBase slots.length bits ty device) fun refs => + holBind (ArchRetype_A.init_arch_objects ty device retypeBase slots.length bits refs) fun _ => + holMapMx (Retype_A.create_cap ty bits src device) (holListZip slots refs) + +/-- [P] The source and requested destination slots use the shared capability layout. -/ +theorem patched_invokeUntyped_equiv (hop : OpaqueRel RestRel) (hc : ConfigRel) + (ui : Invocations_A.untyped_invocation) + (hsrc : match ui with | .Retype src _ _ _ _ _ _ _ => NonExtTcbSlot src.2) + (hslots : match ui with | .Retype _ _ _ _ _ _ slots _ => ∀ s ∈ slots, NonExtTcbSlot s.2) + : + MRelE SR Eq Eq + (invoke_untyped_p ui) (Fl4Spec.invokeUntyped (embUntypedInv ui)) := by + cases ui with + | Retype srcSlot reset base retypeBase newType objSz slots isDevice => + unfold invoke_untyped_p Fl4Spec.invokeUntyped + simp only [embUntypedInv] + refine mrele_kbindE (mrele_whenE Iff.rfl fun _ => resetUntypedCap_equiv hop hc srcSlot hsrc) ?_ + refine mrele_liftE ?_ + refine mrel_bind (getCap_equiv_nonExt srcSlot hsrc) fun cH cL hc' => ?_ + subst hc' + have htot : (BitVec.ofNat 64 slots.length <<< Fl4Spec.objBitsApi (embApiObjectType newType) objSz) = + holWordShiftl ((holOfNat (α := BitVec 64)) (holSize slots)) + (Patched.obj_bits_api newType objSz) := by + rw [patched_objBitsApi_equiv newType objSz] + simp [holWordShiftl, holOfNat, holSize_list, HolNumeral.ofNatVal] + refine mrel_bind (mrel_return htot.symm) fun totH totL htot' => ?_ + subst htot' + refine mrel_bind (mrel_return rfl) fun frH frL hfr => ?_ + subst hfr + refine mrel_kbind (by + rw [bitsOf_eq cH] + exact setCap_equiv_nonExt + (.UntypedCap isDevice base (Structures_A.bits_of cH) (holUnsigned (HolSub.subVal frH base))) + srcSlot hsrc) ?_ + refine mrel_bind (Rb := Eq) + (fH := fun refs => holBind (ArchRetype_A.init_arch_objects newType isDevice retypeBase slots.length objSz refs) + fun _ => holMapMx (Retype_A.create_cap newType objSz srcSlot isDevice) (holListZip slots refs)) + (fL := fun refs => do + Fl4Spec.initArchObjects (embApiObjectType newType) isDevice retypeBase slots.length objSz refs + NonDet.mapMx (Fl4Spec.createCap (embApiObjectType newType) objSz srcSlot isDevice) (slots.zip refs)) + (patched_retypeRegion_equiv (ZH := ZH) (ZL := ZL) hop retypeBase slots.length objSz newType isDevice) + fun orefsH orefsL horefs => ?_ + subst horefs + refine mrel_kbind (initArchObjects_equiv (ZH := ZH) (ZL := ZL) newType isDevice retypeBase slots.length objSz orefsH) ?_ + have hzip : ListRel (fun pH pL : CslotPtr × ObjRef => pH = pL ∧ pH.1 ∈ slots) + (holListZip slots orefsH) (slots.zip orefsH) := by + have haux : ∀ (xs : List CslotPtr) (ys : List ObjRef), + (∀ x ∈ xs, x ∈ slots) → + ListRel (fun pH pL : CslotPtr × ObjRef => pH = pL ∧ pH.1 ∈ slots) + (holListZip xs ys) (xs.zip ys) := by + intro xs + induction xs with + | nil => intro ys _; cases ys <;> exact ListRel.nil + | cons x xs ih => + intro ys hsub + cases ys with + | nil => exact ListRel.nil + | cons y ys => + exact ListRel.cons ⟨rfl, hsub x List.mem_cons_self⟩ + (ih ys fun z hz => hsub z (List.mem_cons_of_mem x hz)) + exact haux slots orefsH (fun _ h => h) + exact mrel_mapMx (fun pH pL ⟨hp, hmem⟩ => by + subst hp + exact createCap_equiv_nonExt newType objSz srcSlot isDevice pH (hslots pH.1 hmem)) hzip + +end + +end L4vRefX64.Equiv.Retype diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/SchedContext.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/SchedContext.lean new file mode 100644 index 000000000..5ccf890a5 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/SchedContext.lean @@ -0,0 +1,1410 @@ +import L4vRefX64.Spec.SchedContext_A +import L4vRefX64.Equiv.IpcCancel +import L4vRefX64.Equiv.TcbAcc + +namespace L4vRefX64.Equiv.SchedContext + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec +open L4vRefX64.Equiv.Machine +open L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.Deterministic +open L4vRefX64.Equiv.KHeap +open L4vRefX64.Equiv.CSpaceAcc +open L4vRefX64.Equiv.IpcCancel +open L4vRefX64.Equiv.TcbAcc +open Fl4Spec +open Classical + +noncomputable section + +theorem wordsFromTime_eq (t : Time) : + Fl4Spec.wordsFromTime t = Arch_Structs_A.words_from_time t := rfl + +/-! ## Pure Helpers -/ + +theorem refillsSum_eq (rf : List Structures_A.refill) : + Fl4Spec.refillsSum (rf.map embRefill) = SchedContext_A.refills_sum rf := by + unfold Fl4Spec.refillsSum SchedContext_A.refills_sum + induction rf with + | nil => rfl + | cons r rs ih => + simp only [List.map_cons, List.sum_cons, holListMap, holSumList] at ih ⊢ + change r.r_amount + (List.map Refill.rAmount (List.map embRefill rs)).sum = + HolAdd.addVal r.r_amount (holSumList (List.map Structures_A.refill_ext.r_amount rs)) + rw [ih]; rfl + +theorem maxRefillsCap_eq (cap : Structures_A.cap) : + Fl4Spec.maxRefillsCap (embCap cap) = SchedContext_A.max_refills_cap cap := by + cases cap with + | SchedContextCap sc sz => + unfold Fl4Spec.maxRefillsCap SchedContext_A.max_refills_cap + simp only [embCap, Structures_A.case_cap] + rw [minSchedContextBits_eq, maxNumRefills_eq] + rfl + | _ => rfl + +/-! ## Monadic `SchedContext_A` Operations -/ + +section SchedContextMonad + +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 readReadyTime_equiv (scPtr : ObjRef) : + LookupRel SR Eq + (SchedContext_A.read_ready_time scPtr) (Fl4Spec.readReadyTime scPtr) := by + unfold SchedContext_A.read_ready_time Fl4Spec.readReadyTime + refine lookup_bind (readRefillHead_equiv scPtr) fun hH hL hh => ?_ + subst hh + exact lookup_oreturn (by cases hH; rfl) + +theorem readTcbReadyTime_equiv (tcbPtr : ObjRef) : + LookupRel SR Eq + (SchedContext_A.read_tcb_ready_time tcbPtr) (Fl4Spec.readTcbReadyTime tcbPtr) := by + unfold SchedContext_A.read_tcb_ready_time Fl4Spec.readTcbReadyTime + refine lookup_bind + (threadRead_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + (fH := Structures_A.tcb_ext.tcb_sched_context) (fL := Tcb.tcbSchedContext) (fun _ => rfl) tcbPtr) + fun oH oL ho => ?_ + subst ho + refine lookup_bind (lookup_oassert' (by simp [holNot_eq_true, ne_eq, holEq_eq_true])) + fun _ _ _ => ?_ + have hthe : holTheOpt oH = the oH := by cases oH <;> rfl + rw [hthe] + exact readReadyTime_equiv (the oH) + +theorem readyTimesAppend_equiv (tptr : ObjRef) (qs : List ObjRef) : + MRel SR Eq + (SchedContext_A.ready_times_append tptr qs) (Fl4Spec.readyTimesAppend tptr qs) := by + unfold SchedContext_A.ready_times_append Fl4Spec.readyTimesAppend + exact orderedInsert_equiv (β := BitVec 64) tptr qs + (fun x => readTcbReadyTime_equiv x) + (fun x y => by unfold holLe HolOrd.leVal; rfl) + +theorem tcbReleaseEnqueue_equiv (tcbPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.tcb_release_enqueue tcbPtr) (Fl4Spec.tcbReleaseEnqueue tcbPtr) := by + unfold SchedContext_A.tcb_release_enqueue Fl4Spec.tcbReleaseEnqueue + refine mrel_bind (mrel_gets fun _ _ hs => hs.releaseQueue_eq.symm) fun qH qL hq => ?_ + subst hq + refine mrel_bind (readyTimesAppend_equiv tcbPtr qH) fun q'H q'L hq' => ?_ + subst hq' + refine mrel_kbind (setReleaseQueue_equiv q'H) ?_ + have hhd1 : holHd q'H = the q'H.head? := by cases q'H <;> rfl + have hhd2 : holHd qH = the qH.head? := by cases qH <;> rfl + refine mrel_when (by simp [holDisj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true, hhd1, hhd2]) + fun _ => mrel_modify fun _ _ hs => { hs with reprogramTimer_eq := rfl } + +theorem refillSize_equiv (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.refill_size scPtr) (Fl4Spec.refillSize scPtr) := by + unfold SchedContext_A.refill_size Fl4Spec.refillSize + refine mrel_bind (getRefills_equiv scPtr) fun rH rL hr => ?_ + rw [listRel_funRel] at hr; subst hr + exact mrel_return (by simp [holSize_list]) + +theorem refillFull_equiv (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.refill_full scPtr) (Fl4Spec.refillFull scPtr) := by + unfold SchedContext_A.refill_full Fl4Spec.refillFull + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + exact mrel_return (by + apply Bool.eq_iff_iff.mpr + simp [holEq_eq_true, holSize_list, embSchedContext]) + +theorem refillSingle_equiv (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.refill_single scPtr) (Fl4Spec.refillSingle scPtr) := by + unfold SchedContext_A.refill_single Fl4Spec.refillSingle + refine mrel_bind (refillSize_equiv scPtr) fun szH szL hsz => ?_ + subst hsz + exact mrel_return (by + apply Bool.eq_iff_iff.mpr + simp [holEq_eq_true, HolOne.oneVal]) + +theorem refillSum_equiv (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.refill_sum scPtr) (Fl4Spec.refillSum scPtr) := by + unfold SchedContext_A.refill_sum Fl4Spec.refillSum + refine mrel_bind (getRefills_equiv scPtr) fun rH rL hr => ?_ + rw [listRel_funRel] at hr; subst hr + exact mrel_return (by simp only [refillsSum_eq]) + +theorem setRefills_equiv (scPtr : ObjRef) (refills : List Structures_A.refill) : + MRel SR Eq + (SchedContext_A.set_refills scPtr refills) + (Fl4Spec.setRefills scPtr (refills.map embRefill)) := by + unfold SchedContext_A.set_refills Fl4Spec.setRefills Fl4Spec.setScObjRef + exact updateSchedContext_equiv (fun _ => rfl) scPtr + +theorem refillAddTail_equiv (scPtr : ObjRef) (newRefill : Structures_A.refill) : + MRel SR Eq + (SchedContext_A.refill_add_tail scPtr newRefill) + (Fl4Spec.refillAddTail scPtr (embRefill newRefill)) := by + unfold SchedContext_A.refill_add_tail Fl4Spec.refillAddTail + exact updateSchedContext_equiv (fun sc => by + simp [embSchedContext, Structures_A.sched_context.sc_refills_update, + Fl4Spec.scRefillsUpdate, holListAppend]) scPtr + +private theorem setObject_kheap {p : ObjRef} {obj : Structures_A.kernel_object} + {sH sH' : Structures_A.state ZH} {a : Unit} + (hm : (a, sH') ∈ (KHeap_A.set_object p obj sH).1) : + sH' = Structures_A.abstract_state.kheap_update (fun _ => holFunUpd sH.kheap p (some obj)) sH := by + unfold KHeap_A.set_object KHeap_A.get_object KHeap_A.read_object holSwp at hm + cases hk : sH.kheap p with + | none => simp [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holFail] at hm + | some kobj => + cases ha : holEq (Structures_A.a_type kobj) (Structures_A.a_type obj) with + | false => + simp only [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holAssert, holReturn] at hm + rcases hm with ⟨⟨k1, s1⟩, hm1, _, ⟨hfalse, _⟩, _⟩ + simp only [Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + rcases hm1 with ⟨rfl, rfl⟩ + rw [ha] at hfalse + exact absurd hfalse Bool.false_ne_true + | true => + simp [hk, ha, holFunApp, holBind, holGetsThe, holAssertOpt, holAssert, holGet, holPut, + holReturn, holKBind] at hm + exact hm.2 + +private theorem updateSchedContext_kheap {p : ObjRef} + {f : Structures_A.sched_context → Structures_A.sched_context} + {sH sH' : Structures_A.state ZH} {a : Unit} + (hm : (a, sH') ∈ (KHeap_A.update_sched_context p f sH).1) : + ∃ sc n, sH.kheap p = some (.SchedContext sc n) ∧ + sH' = Structures_A.abstract_state.kheap_update + (fun _ => holFunUpd sH.kheap p (some (.SchedContext (f sc) n))) sH := by + unfold KHeap_A.update_sched_context KHeap_A.get_object KHeap_A.read_object holSwp at hm + cases hk : sH.kheap p with + | none => simp [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holFail] at hm + | some ko => + cases ko with + | SchedContext sc n => + simp only [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holReturn, + Structures_A.case_kernel_object, Set.mem_singleton_iff] at hm + rcases hm with ⟨⟨_, _⟩, hm1, hset⟩ + cases hm1 + exact ⟨sc, n, rfl, setObject_kheap hset⟩ + | _ => simp [hk, holFunApp, holBind, holGetsThe, holAssertOpt, holReturn, holFail, + Structures_A.case_kernel_object] at hm + +theorem updateRefillTl_equiv_nonEmpty (scPtr : ObjRef) + {fH : Structures_A.refill → Structures_A.refill} {fL : Refill → Refill} + (hf : ∀ r, fL (embRefill r) = embRefill (fH r)) : + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (SchedContext_A.update_refill_tl scPtr fH) (Fl4Spec.updateRefillTl scPtr fL) := by + intro sH sL ⟨hs, sc, n, hkh, hne⟩ + have hkhL : sL.kheap scPtr = some (.schedContext (embSchedContext sc) n) := by + rw [hs.kheap_eq scPtr, hkh]; rfl + have hlast : ∀ (l : List Structures_A.refill), l ≠ [] → + (l.map embRefill).dropLast ++ [fL (the (l.map embRefill).getLast?)] = + (l.dropLast ++ [fH (holLast l)]).map embRefill := by + intro l hl + have hgl : (l.map embRefill).getLast? = (l.getLast?).map embRefill := by + induction l with + | nil => exact absurd rfl hl + | cons a as ih => + cases as with + | nil => rfl + | cons b bs => + simp only [List.map_cons, List.getLast?_cons_cons] + exact ih (by simp) + have hdl : (l.map embRefill).dropLast = l.dropLast.map embRefill := by + rw [List.map_dropLast] + rw [hdl, hgl, List.map_append, List.map_cons, List.map_nil] + congr 1; congr 1 + cases hg : l.getLast? with + | none => + exfalso; apply hl + exact List.getLast?_eq_none_iff.mp hg + | some r => + simp [holLast, holTheOpt, the, hg, hf] + let sc'H := Structures_A.sched_context.sc_refills_update + (fun refills => holListAppend (holButlast refills) [fH (holLast refills)]) sc + let sc'L := scRefillsUpdate + (fun refills => refills.dropLast ++ [fL (the refills.getLast?)]) (embSchedContext sc) + have hsc' : sc'L = embSchedContext sc'H := by + simp only [sc'L, sc'H, embSchedContext, scRefillsUpdate, + Structures_A.sched_context.sc_refills_update, holListAppend, holButlast] + congr 1 + exact hlast sc.sc_refills hne + have hne' : sc'H.sc_refills ≠ [] := by + simp [sc'H, Structures_A.sched_context.sc_refills_update, holListAppend] + have hstep := setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr (.SchedContext sc'H n) sH sL hs + have hH_eq : SchedContext_A.update_refill_tl scPtr fH sH = + KHeap_A.set_object scPtr (.SchedContext sc'H n) sH := by + unfold SchedContext_A.update_refill_tl KHeap_A.update_sched_context + KHeap_A.get_object KHeap_A.read_object holSwp + simp [holFunApp, holBind, holGetsThe, holAssertOpt, holReturn, hkh, + Structures_A.case_kernel_object, sc'H] + have hL_eq : Fl4Spec.updateRefillTl scPtr fL sL = + Fl4Spec.setObject scPtr (.schedContext sc'L n) sL := by + unfold Fl4Spec.updateRefillTl Fl4Spec.updateSchedContext + Fl4Spec.getObject Fl4Spec.readObject + simp [Bind.bind, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, NonDet.pure, hkhL, sc'L] + rw [hH_eq, hL_eq, hsc'] + refine ⟨hstep.1, ?_, ?_⟩ + · intro aH sH' hmH + obtain ⟨aL, sL', hmL, ha, hs'⟩ := hstep.2.1 aH sH' hmH + have heq := setObject_kheap hmH + have hkh' : sH'.kheap scPtr = some (.SchedContext sc'H n) := by + rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq] + exact ⟨aL, sL', hmL, ha, hs', ⟨sc'H, n, hkh', hne'⟩⟩ + · intro aL sL' hmL + obtain ⟨aH, sH', hmH, ha, hs'⟩ := hstep.2.2 aL sL' hmL + have heq := setObject_kheap hmH + have hkh' : sH'.kheap scPtr = some (.SchedContext sc'H n) := by + rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq] + exact ⟨aH, sH', hmH, ha, hs', ⟨sc'H, n, hkh', hne'⟩⟩ + +theorem setRefillHd_equiv_nonEmpty (scPtr : ObjRef) (new : Structures_A.refill) : + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (SchedContext_A.set_refill_hd scPtr new) + (Fl4Spec.setRefillHd scPtr (embRefill new)) := + updateRefillHd_equiv_nonEmpty scPtr (fun _ => rfl) + +theorem setRefillTl_equiv_nonEmpty (scPtr : ObjRef) (new : Structures_A.refill) : + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (SchedContext_A.set_refill_tl scPtr new) + (Fl4Spec.setRefillTl scPtr (embRefill new)) := + updateRefillTl_equiv_nonEmpty scPtr (fun _ => rfl) + +theorem maybeAddEmptyTail_equiv (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.maybe_add_empty_tail scPtr) (Fl4Spec.maybeAddEmptyTail scPtr) := by + unfold SchedContext_A.maybe_add_empty_tail Fl4Spec.maybeAddEmptyTail + refine mrel_bind (isRoundRobin_equiv scPtr) fun rH rL hr => ?_ + subst hr + simp only [holFunApp] + refine mrel_when (by simp) fun _ => ?_ + refine mrel_bind (getRefillHead_equiv scPtr) fun hH hL hh => ?_ + subst hh + refine mrel_bind (mrel_return (Ra := FunRel embRefill) (by rfl)) fun eH eL he => ?_ + subst he + exact refillAddTail_equiv scPtr eH + +theorem refillNew_equiv (scPtr : ObjRef) (maxRefills : Nat) (budget period : Ticks) : + MRel SR Eq + (SchedContext_A.refill_new scPtr maxRefills budget period) + (Fl4Spec.refillNew scPtr maxRefills budget period) := by + unfold SchedContext_A.refill_new Fl4Spec.refillNew Fl4Spec.setScObjRef + refine mrel_bind (mrel_gets fun _ _ hs => hs.curTime_eq.symm) fun tH tL ht => ?_ + subst ht + refine mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) ?_ + refine mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) ?_ + refine mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) ?_ + refine mrel_bind (mrel_return (Ra := FunRel embRefill) (by rfl)) fun rH rL hr => ?_ + subst hr + refine mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) ?_ + exact maybeAddEmptyTail_equiv scPtr + +theorem mrelStep_when {σH σL : Type} {Rs : σH → σL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {mH : HolNonDet σH Unit} {mL : NonDet σL Unit} + {sH : σH} {sL : σL} (hs : Rs sH sL) + (hm : P → MRelStep Rs Eq (mH sH) (mL sL)) : + MRelStep Rs Eq (holWhen b mH sH) (NonDet.when P mL sL) := by + unfold holWhen NonDet.when + by_cases hp : P + · have hb : b = true := h.mpr hp; simp [hp, hb]; exact hm hp + · have hb : b ≠ true := fun h1 => hp (h.mp h1); simp [hp, hb]; exact mrel_return rfl sH sL hs + +theorem mrel_bind_post {σH σL αH αL βH βL : Type} + {Rs Rs' : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + {fH : αH → HolNonDet σH βH} {fL : αL → NonDet σL βL} + (hm : ∀ sH sL, Rs sH sL → MRelStep Rs' Ra (mH sH) (mL sL)) + (hf : ∀ s0H aH aL, Ra aH aL → ∀ sH sL, Rs' sH sL → (aH, sH) ∈ (mH s0H).1 → + MRelStep Rs Rb (fH aH sH) (fL aL sL)) : + MRel Rs Rb (holBind mH fH) (NonDet.bind mL fL) := + fun sH sL hs => mrelStep_bind_mem (hm sH sL hs) (hf sH) + +theorem mrel_strengthen_post {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {P : σH → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (hm : MRel Rs Ra mH mL) + (hP : ∀ sH aH sH', (aH, sH') ∈ (mH sH).1 → P sH') : + ∀ sH sL, Rs sH sL → MRelStep (fun sH sL => Rs sH sL ∧ P sH) Ra (mH sH) (mL sL) := by + intro sH sL hs + obtain ⟨hf, h1, h2⟩ := hm sH sL hs + exact ⟨hf, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs'⟩ := h1 aH sH' m; ⟨aL, sL', mL, ha, hs', hP sH aH sH' m⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs'⟩ := h2 aL sL' m; ⟨aH, sH', mH, ha, hs', hP sH aH sH' mH⟩⟩ + +theorem mrel_drop_post {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {P : σH → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (hm : MRel (fun sH sL => Rs sH sL ∧ P sH) Ra mH mL) : + ∀ sH sL, Rs sH sL ∧ P sH → MRelStep Rs Ra (mH sH) (mL sL) := by + intro sH sL hs + obtain ⟨hf, h1, h2⟩ := hm sH sL hs + exact ⟨hf, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs', _⟩ := h1 aH sH' m; ⟨aL, sL', mL, ha, hs'⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs', _⟩ := h2 aL sL' m; ⟨aH, sH', mH, ha, hs'⟩⟩ + +theorem mrel_lift_preserves_state {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {P : σH → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (hm : MRel Rs Ra mH mL) + (hstay : ∀ sH aH sH', (aH, sH') ∈ (mH sH).1 → sH' = sH) : + MRel (fun sH sL => Rs sH sL ∧ P sH) Ra mH mL := by + intro sH sL ⟨hs, hp⟩ + obtain ⟨hf, h1, h2⟩ := hm sH sL hs + exact ⟨hf, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs'⟩ := h1 aH sH' m; ⟨aL, sL', mL, ha, hs', hstay sH aH sH' m ▸ hp⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs'⟩ := h2 aL sL' m; ⟨aH, sH', mH, ha, hs', hstay sH aH sH' mH ▸ hp⟩⟩ + +omit [Nonempty ZH] [Deterministic_A.state_ext_class ZH] in +theorem holGetsThe_state_eq {α : Type} + {f : Structures_A.state ZH → Option α} {sH sH' : Structures_A.state ZH} {a : α} + (hm : (a, sH') ∈ (holGetsThe f sH).1) : sH' = sH := by + unfold holGetsThe at hm + cases h : f sH with + | none => simp [h, holAssertOpt, holFail] at hm + | some v => simp [h, holAssertOpt, holReturn] at hm; exact hm.2 + +private theorem getRefillTail_preserves_nonEmpty {scPtr : ObjRef} + {sH : Structures_A.state ZH} {r : Structures_A.refill} {sH' : Structures_A.state ZH} + (hm : (r, sH') ∈ (KHeap_A.get_refill_tail scPtr sH).1) : + HasNonEmptyRefills scPtr sH' := by + unfold KHeap_A.get_refill_tail KHeap_A.read_refill_tail KHeap_A.read_sched_context + KHeap_A.read_object holSwp at hm + cases hk : sH.kheap scPtr with + | none => simp [hk, holGetsThe, holAssertOpt, holOBind, holFail] at hm + | some ko => + cases ko with + | SchedContext sc n => + cases hne : sc.sc_refills with + | nil => + simp [hk, hne, holNot, holEq, holGetsThe, holAssertOpt, holOBind, holOAssert, holOReturn, holOFail, holFail, + Structures_A.case_kernel_object] at hm + | cons x xs => + have hnot : holNot (holEq (x :: xs) []) = true := by simp [holNot, holEq] + simp [hk, hne, hnot, holGetsThe, holAssertOpt, holOBind, holOAssert, holOReturn, holReturn, + Structures_A.case_kernel_object] at hm + rcases hm with ⟨_, rfl⟩ + exact ⟨sc, n, hk, by simp [hne]⟩ + | _ => simp [hk, holGetsThe, holAssertOpt, holOBind, holOFail, holFail, + Structures_A.case_kernel_object] at hm + +private theorem getRefillHead_preserves_nonEmpty {scPtr : ObjRef} + {sH : Structures_A.state ZH} {r : Structures_A.refill} {sH' : Structures_A.state ZH} + (hm : (r, sH') ∈ (KHeap_A.get_refill_head scPtr sH).1) : + HasNonEmptyRefills scPtr sH' := by + unfold KHeap_A.get_refill_head KHeap_A.read_refill_head KHeap_A.read_sched_context + KHeap_A.read_object holSwp at hm + cases hk : sH.kheap scPtr with + | none => simp [hk, holGetsThe, holAssertOpt, holOBind, holFail] at hm + | some ko => + cases ko with + | SchedContext sc n => + cases hne : sc.sc_refills with + | nil => + simp [hk, hne, holNot, holEq, holGetsThe, holAssertOpt, holOBind, holOAssert, holOReturn, holOFail, holFail, + Structures_A.case_kernel_object] at hm + | cons x xs => + have hnot : holNot (holEq (x :: xs) []) = true := by simp [holNot, holEq] + simp [hk, hne, hnot, holGetsThe, holAssertOpt, holOBind, holOAssert, holOReturn, holReturn, + Structures_A.case_kernel_object] at hm + rcases hm with ⟨_, rfl⟩ + exact ⟨sc, n, hk, by simp [hne]⟩ + | _ => simp [hk, holGetsThe, holAssertOpt, holOBind, holOFail, holFail, + Structures_A.case_kernel_object] at hm + +private theorem getSchedContext_state_eq {scPtr : ObjRef} + {sH : Structures_A.state ZH} {sc : Structures_A.sched_context} {sH' : Structures_A.state ZH} + (hm : (sc, sH') ∈ (KHeap_A.get_sched_context scPtr sH).1) : sH' = sH := by + unfold KHeap_A.get_sched_context KHeap_A.get_object KHeap_A.read_object holSwp at hm + cases hk : sH.kheap scPtr with + | none => simp [hk, holBind, holGetsThe, holAssertOpt, holFail] at hm + | some ko => + cases ko with + | SchedContext sc0 n => + simp [hk, holBind, holGetsThe, holAssertOpt, holReturn, Structures_A.case_kernel_object] at hm + exact hm.2 + | _ => simp [hk, holBind, holGetsThe, holAssertOpt, holReturn, holFail, + Structures_A.case_kernel_object] at hm + +private theorem refillFull_state_eq {scPtr : ObjRef} + {sH : Structures_A.state ZH} {b : Bool} {sH' : Structures_A.state ZH} + (hm : (b, sH') ∈ (SchedContext_A.refill_full scPtr sH).1) : sH' = sH := by + unfold SchedContext_A.refill_full at hm + simp only [holBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨⟨sc, st⟩, hsc, hm_eq⟩ + cases hm_eq + exact getSchedContext_state_eq hsc + +private theorem refillSingle_state_eq {scPtr : ObjRef} + {sH : Structures_A.state ZH} {b : Bool} {sH' : Structures_A.state ZH} + (hm : (b, sH') ∈ (SchedContext_A.refill_single scPtr sH).1) : sH' = sH := by + unfold SchedContext_A.refill_single SchedContext_A.refill_size KHeap_A.get_refills at hm + simp only [holBind, holFunApp, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨⟨sz, s1⟩, ⟨⟨rfs, s2⟩, ⟨⟨sc, s3⟩, hsc, hm3⟩, hm2⟩, hm1⟩ + cases hm3; cases hm2; cases hm1 + exact getSchedContext_state_eq hsc + +theorem scheduleUsed_equiv (scPtr : ObjRef) (new : Structures_A.refill) : + MRel SR Eq + (SchedContext_A.schedule_used scPtr new) + (Fl4Spec.scheduleUsed scPtr (embRefill new)) := by + unfold SchedContext_A.schedule_used Fl4Spec.scheduleUsed + refine mrel_bind (getRefills_equiv scPtr) fun rH rL hr => ?_ + rw [listRel_funRel] at hr; subst hr + refine mrel_kbind (mrel_assert (by simp [holNot_eq_true, ne_eq, holEq_eq_true])) ?_ + refine mrel_bind_post + (mrel_strengthen_post (getRefillTail_equiv scPtr) (fun _ _ _ hm => getRefillTail_preserves_nonEmpty hm)) + fun _ tH tL ht stH stL hst _ => ?_ + subst ht + refine mrel_drop_post (P := HasNonEmptyRefills scPtr) ?_ stH stL hst + refine mrel_if (canMergeRefill_iff tH new) + (fun _ => updateRefillTl_equiv_nonEmpty scPtr (fun r => by + cases r; cases tH; cases new + simp [embRefill, Structures_A.refill.r_amount_update, HolAdd.addVal])) + (fun _ => ?_) + refine mrel_bind (mrel_lift_preserves_state (refillFull_equiv scPtr) (fun _ _ _ hm => refillFull_state_eq hm)) + fun fH fL hf => ?_ + subst hf + refine mrel_if (by simp [holNot_eq_true]) (fun _ => ?_) (fun _ => ?_) + · intro sH sL ⟨hs, _⟩ + have hstep := refillAddTail_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr new sH sL hs + have hpres : ∀ aH sH', (aH, sH') ∈ (SchedContext_A.refill_add_tail scPtr new sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro aH sH' hmH + obtain ⟨sc0, n0, _, heq⟩ := updateSchedContext_kheap hmH + refine ⟨Structures_A.sched_context.sc_refills_update + (fun refills => holListAppend refills [new]) sc0, n0, ?_, ?_⟩ + · rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq] + · simp [Structures_A.sched_context.sc_refills_update, holListAppend] + exact ⟨hstep.1, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs'⟩ := hstep.2.1 aH sH' m; ⟨aL, sL', mL, ha, hs', hpres aH sH' m⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs'⟩ := hstep.2.2 aL sL' m; ⟨aH, sH', mH, ha, hs', hpres aH sH' mH⟩⟩ + · refine mrel_kbind (updateRefillTl_equiv_nonEmpty scPtr (fun r => by + cases r; cases tH; cases new + simp [embRefill, Structures_A.refill.r_time_update, HolSub.subVal])) ?_ + exact updateRefillTl_equiv_nonEmpty scPtr (fun r => by + cases r; cases tH; cases new + simp [embRefill, Structures_A.refill.r_amount_update, HolAdd.addVal]) + +theorem refillBudgetCheckRoundRobin_equiv (usage : Ticks) : + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills sH.cur_sc sH) Eq + (SchedContext_A.refill_budget_check_round_robin usage) + (Fl4Spec.refillBudgetCheckRoundRobin usage) := by + unfold SchedContext_A.refill_budget_check_round_robin Fl4Spec.refillBudgetCheckRoundRobin + intro sH sL ⟨hs, hne⟩ + have hm : MRel (fun stH stL => SR stH stL ∧ HasNonEmptyRefills sH.cur_sc stH) Eq + (holBind (Sporadic_A.update_refill_hd sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolSub.subVal r.r_amount usage) r) + (holKBind (SchedContext_A.update_refill_tl sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolAdd.addVal r.r_amount usage) r))) + (do + Fl4Spec.updateRefillHd sH.cur_sc fun r => { r with rAmount := r.rAmount - usage } + Fl4Spec.updateRefillTl sH.cur_sc fun r => { r with rAmount := r.rAmount + usage }) := by + refine mrel_kbind (updateRefillHd_equiv_nonEmpty sH.cur_sc (fun r => by + cases r; simp [embRefill, Structures_A.refill.r_amount_update, HolSub.subVal])) ?_ + exact updateRefillTl_equiv_nonEmpty sH.cur_sc (fun r => by + cases r; simp [embRefill, Structures_A.refill.r_amount_update, HolAdd.addVal]) + have hcur : sL.curSc = sH.cur_sc := hs.curSc_eq + have hH : SchedContext_A.refill_budget_check_round_robin usage sH = + (holBind (Sporadic_A.update_refill_hd sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolSub.subVal r.r_amount usage) r) + (holKBind (SchedContext_A.update_refill_tl sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolAdd.addVal r.r_amount usage) r))) sH := by + unfold SchedContext_A.refill_budget_check_round_robin + simp [holBind, holGets] + have hL : Fl4Spec.refillBudgetCheckRoundRobin usage sL = + (do + Fl4Spec.updateRefillHd sH.cur_sc fun r => { r with rAmount := r.rAmount - usage } + Fl4Spec.updateRefillTl sH.cur_sc fun r => { r with rAmount := r.rAmount + usage }) sL := by + unfold Fl4Spec.refillBudgetCheckRoundRobin + simp [Bind.bind, NonDet.bind, NonDet.gets, hcur] + unfold SchedContext_A.refill_budget_check_round_robin at hH + unfold Fl4Spec.refillBudgetCheckRoundRobin at hL + rw [hH, hL] + have hstep := hm sH sL ⟨hs, hne⟩ + have hcurPres : ∀ sH' aH, (aH, sH') ∈ + (holBind (Sporadic_A.update_refill_hd sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolSub.subVal r.r_amount usage) r) + (holKBind (SchedContext_A.update_refill_tl sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolAdd.addVal r.r_amount usage) r)) sH).1 → + sH'.cur_sc = sH.cur_sc := by + intro sH' aH m + simp only [holBind, holKBind] at m + rcases m with ⟨⟨_, s1⟩, m1, m2⟩ + obtain ⟨_, _, _, hs1⟩ := updateSchedContext_kheap m1 + obtain ⟨_, _, _, hs2⟩ := updateSchedContext_kheap m2 + rw [hs2, hs1]; rfl + refine ⟨hstep.1, ?_, ?_⟩ + · intro aH sH' mH + obtain ⟨aL, sL', mL, ha, hs', hne'⟩ := hstep.2.1 aH sH' mH + exact ⟨aL, sL', mL, ha, hs', hcurPres sH' aH mH ▸ hne'⟩ + · intro aL sL' mL + obtain ⟨aH, sH', mH, ha, hs', hne'⟩ := hstep.2.2 aL sL' mL + exact ⟨aH, sH', mH, ha, hs', hcurPres sH' aH mH ▸ hne'⟩ + +theorem refillHeadInsufficient_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + LookupRel SR Eq + (SchedContext_A.refill_head_insufficient scPtr) + (Fl4Spec.refillHeadInsufficient scPtr) := by + unfold SchedContext_A.refill_head_insufficient Fl4Spec.refillHeadInsufficient + refine lookup_bind (readRefillHead_equiv scPtr) fun hH hL hh => ?_ + subst hh + exact lookup_oreturn (by + rw [minBudget_eq hop] + cases hH + simp only [embRefill, holLt, HolOrd.ltVal] + exact decide_eq_decide.mpr Iff.rfl) + +private theorem holTheOpt_bool_eq (o : Option Bool) : holTheOpt o = the o := by + cases o with + | none => + unfold holTheOpt holUndefined the Fl4Spec.undefined + congr 1 + | some b => rfl + +/-- Side condition ruling out the vacuous singleton-refill case where +`merge_nonoverlapping_head_refill` would call `update_refill_hd` on an empty refill list +(`holHd []` vs `the [].head?`). In seL4, `valid_sched_context` ensures a singleton refill +has `r_amount = refills_sum ≥ MIN_BUDGET`, so the loop never enters on a singleton refill. -/ +def NotSingletonRefill (scPtr : ObjRef) (sH : Structures_A.state ZH) : Prop := + ¬ ∃ sc n r, sH.kheap scPtr = some (.SchedContext sc n) ∧ sc.sc_refills = [r] + +theorem mergeNonoverlappingHeadRefill_equiv_safe (scPtr : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hns : NotSingletonRefill scPtr sH) : + MRelStep SR Eq + (SchedContext_A.merge_nonoverlapping_head_refill scPtr sH) + (Fl4Spec.mergeNonoverlappingHeadRefill scPtr sL) := by + unfold SchedContext_A.merge_nonoverlapping_head_refill Fl4Spec.mergeNonoverlappingHeadRefill + have hpop_ne : ∀ r sH', (r, sH') ∈ (Sporadic_A.refill_pop_head scPtr sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro r sH' hm + unfold Sporadic_A.refill_pop_head at hm + simp only [holBind, holKBind, holReturn, Set.mem_singleton_iff] at hm + rcases hm with ⟨⟨hd, s1⟩, mhd, ⟨_, s2⟩, mupd, _, rfl⟩ + have hs1 : s1 = sH := holGetsThe_state_eq mhd + subst hs1 + obtain ⟨sc, n, hkh, heq⟩ := updateSchedContext_kheap mupd + have hne : sc.sc_refills ≠ [] := by + obtain ⟨sc1, n1, hkh1, hne1⟩ := getRefillHead_preserves_nonEmpty mhd + rw [hkh] at hkh1; cases hkh1; exact hne1 + cases hrf : sc.sc_refills with + | nil => exact absurd hrf hne + | cons r0 rs => + cases rs with + | nil => exact absurd ⟨sc, n, r0, hkh, hrf⟩ hns + | cons r1 rs' => + refine ⟨Structures_A.sched_context.sc_refills_update holTl sc, n, ?_, ?_⟩ + · rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq] + · simp [Structures_A.sched_context.sc_refills_update, holTl, hrf] + refine mrelStep_bind_mem (refillPopHead_equiv scPtr sH sL hs) + fun oldH oldL hold s1H s1L hs1 hm1 => ?_ + subst hold + have hcont : MRel (fun stH stL => SR stH stL ∧ HasNonEmptyRefills scPtr stH) Eq + (holBind (Sporadic_A.update_refill_hd scPtr fun head => + Structures_A.refill.r_amount_update (fun _ => HolAdd.addVal head.r_amount oldH.r_amount) head) + (holKBind (Sporadic_A.update_refill_hd scPtr fun head => + Structures_A.refill.r_time_update (fun _ => HolSub.subVal head.r_time oldH.r_amount) head))) + (do + Fl4Spec.updateRefillHd scPtr fun head => { head with rAmount := head.rAmount + (embRefill oldH).rAmount } + Fl4Spec.updateRefillHd scPtr fun head => { head with rTime := head.rTime - (embRefill oldH).rAmount }) := by + refine mrel_kbind (updateRefillHd_equiv_nonEmpty scPtr (fun r => by + cases r; cases oldH; simp [embRefill, Structures_A.refill.r_amount_update, HolAdd.addVal])) ?_ + exact updateRefillHd_equiv_nonEmpty scPtr (fun r => by + cases r; cases oldH; simp [embRefill, Structures_A.refill.r_time_update, HolSub.subVal]) + exact mrel_drop_post hcont s1H s1L ⟨hs1, hpop_ne oldH s1H hm1⟩ + +/-- Every reachable state of `head_insufficient_loop` where the loop guard holds has +`NotSingletonRefill scPtr` (holds automatically under seL4's `valid_sched_context`). -/ +def HeadInsuffLoopSafe (scPtr : ObjRef) (sH : Structures_A.state ZH) : Prop := + ∀ sH', HolWhileReach + (fun _ s => holTheOpt (SchedContext_A.refill_head_insufficient scPtr s)) + (fun _ => SchedContext_A.merge_nonoverlapping_head_refill scPtr) () sH () sH' → + holTheOpt (SchedContext_A.refill_head_insufficient scPtr sH') = true → + NotSingletonRefill scPtr sH' + +/-- Guarded `whileLoop` bisimulation: only requires the loop body to agree when the loop guard holds. -/ +theorem mrel_whileLoop_guarded {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {CH : αH → σH → Bool} {CL : αL → σL → Prop} + {BH : αH → HolNonDet σH αH} {BL : αL → NonDet σL αL} + (hC : ∀ rH rL, Ra rH rL → ∀ sH sL, Rs sH sL → (CH rH sH = true ↔ CL rL sL)) + (hB : ∀ rH rL, Ra rH rL → ∀ sH sL, Rs sH sL → CH rH sH = true → + MRelStep Rs Ra (BH rH sH) (BL rL sL)) + {rH : αH} {rL : αL} (hr : Ra rH rL) : + MRel Rs Ra (holWhileLoop CH BH rH) (NonDet.whileLoop CL BL rL) := by + have hRes1 : ∀ {rH sH x}, HolWhileResults CH BH rH sH x → + ∀ rL sL, Ra rH rL → Rs sH sL → + ∃ rL' sL', NonDet.WhileResults CL BL rL sL (rL', sL') ∧ Ra x.1 rL' ∧ Rs x.2 sL' := by + intro rH sH x h + induction h with + | @done rH sH hcf => + intro rL sL hr hs + have hnc : ¬CL rL sL := fun hc => by have := (hC rH rL hr sH sL hs).mpr hc; simp [hcf] at this + exact ⟨rL, sL, .done hnc, hr, hs⟩ + | @step rH sH rH' sH' x hct hmem _ ih => + intro rL sL hr hs + have hcL : CL rL sL := (hC rH rL hr sH sL hs).mp hct + obtain ⟨rL', sL', hmemL, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.1 rH' sH' hmem + obtain ⟨rL'', sL'', hres, ha'', hs''⟩ := ih rL' sL' hr' hs' + exact ⟨rL'', sL'', .step hcL hmemL hres, ha'', hs''⟩ + have hRes2 : ∀ {rL sL x}, NonDet.WhileResults CL BL rL sL x → + ∀ rH sH, Ra rH rL → Rs sH sL → + ∃ rH' sH', HolWhileResults CH BH rH sH (rH', sH') ∧ Ra rH' x.1 ∧ Rs sH' x.2 := by + intro rL sL x h + induction h with + | @done rL sL hnc => + intro rH sH hr hs + have hcf : CH rH sH = false := by + cases hc : CH rH sH + · rfl + · exfalso; exact hnc ((hC rH rL hr sH sL hs).mp hc) + exact ⟨rH, sH, .done hcf, hr, hs⟩ + | @step rL sL rL' sL' x hcL hmem _ ih => + intro rH sH hr hs + have hct : CH rH sH = true := (hC rH rL hr sH sL hs).mpr hcL + obtain ⟨rH', sH', hmemH, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.2 rL' sL' hmem + obtain ⟨rH'', sH'', hres, ha'', hs''⟩ := ih rH' sH' hr' hs' + exact ⟨rH'', sH'', .step hct hmemH hres, ha'', hs''⟩ + have hReach1 : ∀ {r0H s0H rH sH}, HolWhileReach CH BH r0H s0H rH sH → + ∀ r0L s0L, Ra r0H r0L → Rs s0H s0L → + ∃ rL sL, NonDet.WhileReach CL BL r0L s0L rL sL ∧ Ra rH rL ∧ Rs sH sL := by + intro r0H s0H rH sH h + induction h with + | start => intro r0L s0L hr0 hs0; exact ⟨r0L, s0L, .start, hr0, hs0⟩ + | @step rH sH rH' sH' _ hct hmem ih => + intro r0L s0L hr0 hs0 + obtain ⟨rL, sL, hreach, hr, hs⟩ := ih r0L s0L hr0 hs0 + have hcL : CL rL sL := (hC rH rL hr sH sL hs).mp hct + obtain ⟨rL', sL', hmemL, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.1 rH' sH' hmem + exact ⟨rL', sL', .step hreach hcL hmemL, hr', hs'⟩ + have hReach2 : ∀ {r0L s0L rL sL}, NonDet.WhileReach CL BL r0L s0L rL sL → + ∀ r0H s0H, Ra r0H r0L → Rs s0H s0L → + ∃ rH sH, HolWhileReach CH BH r0H s0H rH sH ∧ Ra rH rL ∧ Rs sH sL := by + intro r0L s0L rL sL h + induction h with + | start => intro r0H s0H hr0 hs0; exact ⟨r0H, s0H, .start, hr0, hs0⟩ + | @step rL sL rL' sL' _ hcL hmem ih => + intro r0H s0H hr0 hs0 + obtain ⟨rH, sH, hreach, hr, hs⟩ := ih r0H s0H hr0 hs0 + have hct : CH rH sH = true := (hC rH rL hr sH sL hs).mpr hcL + obtain ⟨rH', sH', hmemH, hr', hs'⟩ := (hB rH rL hr sH sL hs hct).2.2 rL' sL' hmem + exact ⟨rH', sH', .step hreach hct hmemH, hr', hs'⟩ + intro sH sL hs + refine ⟨?_, fun aH sH' hmem => hRes1 hmem rL sL hr hs, fun aL sL' hmem => hRes2 hmem rH sH hr hs⟩ + simp only [holWhileLoop, NonDet.whileLoop, decide_eq_true_eq] + constructor + · rintro (⟨rH', sH', hreach, hct, hfail⟩ | ⟨fH, hf0, hfstep⟩) + · obtain ⟨rL', sL', hreachL, hr', hs'⟩ := hReach1 hreach rL sL hr hs + exact Or.inl ⟨rL', sL', hreachL, (hC rH' rL' hr' sH' sL' hs').mp hct, + (hB rH' rL' hr' sH' sL' hs' hct).1.mp hfail⟩ + · let stepL : ∀ n, {p : αL × σL // Ra (fH n).1 p.1 ∧ Rs (fH n).2 p.2} := + Nat.rec + ⟨(rL, sL), by rw [hf0]; exact ⟨hr, hs⟩⟩ + (fun n ih => + let h1 := hfstep n + let ex := (hB (fH n).1 ih.1.1 ih.2.1 (fH n).2 ih.1.2 ih.2.2 h1.1).2.1 + (fH (n + 1)).1 (fH (n + 1)).2 h1.2 + ⟨(Classical.choose ex, Classical.choose (Classical.choose_spec ex)), + (Classical.choose_spec (Classical.choose_spec ex)).2⟩) + refine Or.inr ⟨fun n => (stepL n).1, rfl, fun n => ?_⟩ + have h1 := hfstep n + refine ⟨(hC (fH n).1 (stepL n).1.1 (stepL n).2.1 (fH n).2 (stepL n).1.2 (stepL n).2.2).mp h1.1, ?_⟩ + exact (Classical.choose_spec (Classical.choose_spec + ((hB (fH n).1 (stepL n).1.1 (stepL n).2.1 (fH n).2 (stepL n).1.2 (stepL n).2.2 h1.1).2.1 + (fH (n + 1)).1 (fH (n + 1)).2 h1.2))).1 + · rintro (⟨rL', sL', hreach, hcL, hfail⟩ | ⟨fL, hf0, hfstep⟩) + · obtain ⟨rH', sH', hreachH, hr', hs'⟩ := hReach2 hreach rH sH hr hs + have hct : CH rH' sH' = true := (hC rH' rL' hr' sH' sL' hs').mpr hcL + exact Or.inl ⟨rH', sH', hreachH, hct, (hB rH' rL' hr' sH' sL' hs' hct).1.mpr hfail⟩ + · let stepH : ∀ n, {p : αH × σH // Ra p.1 (fL n).1 ∧ Rs p.2 (fL n).2} := + Nat.rec + ⟨(rH, sH), by rw [hf0]; exact ⟨hr, hs⟩⟩ + (fun n ih => + let h1 := hfstep n + let hct := (hC ih.1.1 (fL n).1 ih.2.1 ih.1.2 (fL n).2 ih.2.2).mpr h1.1 + let ex := (hB ih.1.1 (fL n).1 ih.2.1 ih.1.2 (fL n).2 ih.2.2 hct).2.2 + (fL (n + 1)).1 (fL (n + 1)).2 h1.2 + ⟨(Classical.choose ex, Classical.choose (Classical.choose_spec ex)), + (Classical.choose_spec (Classical.choose_spec ex)).2⟩) + refine Or.inr ⟨fun n => (stepH n).1, rfl, fun n => ?_⟩ + have h1 := hfstep n + have hct : CH (stepH n).1.1 (stepH n).1.2 = true := + (hC (stepH n).1.1 (fL n).1 (stepH n).2.1 (stepH n).1.2 (fL n).2 (stepH n).2.2).mpr h1.1 + refine ⟨hct, ?_⟩ + exact (Classical.choose_spec (Classical.choose_spec + ((hB (stepH n).1.1 (fL n).1 (stepH n).2.1 (stepH n).1.2 (fL n).2 (stepH n).2.2 hct).2.2 + (fL (n + 1)).1 (fL (n + 1)).2 h1.2))).1 + +private theorem holWhileReach_trans {σ α : Type} + {C : α → σ → Bool} {B : α → HolNonDet σ α} + {r0 r1 r2 : α} {s0 s1 s2 : σ} + (h01 : HolWhileReach C B r0 s0 r1 s1) + (h12 : HolWhileReach C B r1 s1 r2 s2) : + HolWhileReach C B r0 s0 r2 s2 := by + induction h12 with + | start => exact h01 + | step _ hc hm ih => exact .step ih hc hm + +theorem headInsufficientLoop_equiv_safe (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel (fun sH sL => SR sH sL ∧ HeadInsuffLoopSafe scPtr sH) Eq + (SchedContext_A.head_insufficient_loop scPtr) + (Fl4Spec.headInsufficientLoop scPtr) := by + unfold SchedContext_A.head_insufficient_loop Fl4Spec.headInsufficientLoop + refine mrel_whileLoop_guarded (Ra := Eq) + (Rs := fun sH sL => SR sH sL ∧ HeadInsuffLoopSafe scPtr sH) + (fun _ _ _ sH sL ⟨hs, _⟩ => by + have h := refillHeadInsufficient_equiv hop scPtr sH sL hs + have h' : Fl4Spec.refillHeadInsufficient scPtr sL = + SchedContext_A.refill_head_insufficient scPtr sH := by + cases h1 : SchedContext_A.refill_head_insufficient scPtr sH <;> + cases h2 : Fl4Spec.refillHeadInsufficient scPtr sL <;> + simp [h1, h2, OptRel] at h ⊢ + exact h.symm + rw [h', holTheOpt_bool_eq]) + (fun _ _ _ sH sL ⟨hs, hsafe⟩ hct => ?_) rfl + have hns : NotSingletonRefill scPtr sH := hsafe sH .start hct + have hstep := mergeNonoverlappingHeadRefill_equiv_safe (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr hs hns + have hpres : ∀ aH sH', (aH, sH') ∈ (SchedContext_A.merge_nonoverlapping_head_refill scPtr sH).1 → + HeadInsuffLoopSafe scPtr sH' := by + intro aH sH' hm sH'' hreach hct' + exact hsafe sH'' (holWhileReach_trans (.step .start hct hm) hreach) hct' + exact ⟨hstep.1, + fun aH sH' hm => let ⟨aL, sL', hmL, ha, hs'⟩ := hstep.2.1 aH sH' hm; ⟨aL, sL', hmL, ha, hs', hpres aH sH' hm⟩, + fun aL sL' hm => let ⟨aH, sH', hmH, ha, hs'⟩ := hstep.2.2 aL sL' hm; ⟨aH, sH', hmH, ha, hs', hpres aH sH' hmH⟩⟩ + +theorem headRefillOverrun_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) (usage : Ticks) : + LookupRel SR Eq + (SchedContext_A.head_refill_overrun scPtr usage) + (Fl4Spec.headRefillOverrun scPtr usage) := by + unfold SchedContext_A.head_refill_overrun Fl4Spec.headRefillOverrun + refine lookup_bind (readRefillHead_equiv scPtr) fun hH hL hh => ?_ + subst hh + exact lookup_oreturn (by + rw [MAX_RELEASE_TIME_eq hop] + unfold holConj holLe holLt HolOrd.leVal HolOrd.ltVal instHolOrdBitVec + cases hH with + | mk rt ra _ => + by_cases h1 : ra ≤ usage <;> by_cases h2 : rt < Time.MAX_RELEASE_TIME <;> + simp [embRefill, h1, h2]) + +theorem chargeEntireHeadRefill_equiv (scPtr : ObjRef) (usage : Ticks) : + MRel SR Eq + (SchedContext_A.charge_entire_head_refill scPtr usage) + (Fl4Spec.chargeEntireHeadRefill scPtr usage) := by + unfold SchedContext_A.charge_entire_head_refill Fl4Spec.chargeEntireHeadRefill + refine mrel_bind_post + (mrel_strengthen_post (getRefillHead_equiv scPtr) (fun _ _ _ hm => getRefillHead_preserves_nonEmpty hm)) + fun _ hH hL hh sH sL ⟨hs, hne⟩ _ => ?_ + subst hh + refine mrelStep_bind_mem + (mrel_lift_preserves_state (getSchedContext_equiv scPtr) (fun _ _ _ hm => getSchedContext_state_eq hm) sH sL ⟨hs, hne⟩) + fun scH scL hsc s1H s1L ⟨hs1, hne1⟩ _ => ?_ + subst hsc + refine mrelStep_bind_mem + (mrel_lift_preserves_state (refillSingle_equiv scPtr) (fun _ _ _ hm => refillSingle_state_eq hm) s1H s1L ⟨hs1, hne1⟩) + fun sgH sgL hsg s2H s2L ⟨hs2, hne2⟩ _ => ?_ + subst hsg + cases sgH with + | true => + simp only [holIf_true, ↓reduceIte] + refine mrelStep_bind_mem (Rs' := SR) (Ra := Eq) + (mrel_drop_post (updateRefillHd_equiv_nonEmpty scPtr (fun r => by + cases r; cases hH; cases scH + simp [embRefill, embSchedContext, Structures_A.refill.r_time_update, HolAdd.addVal])) s2H s2L ⟨hs2, hne2⟩) + (fun _ _ _ s3H s3L hs3 _ => mrel_return (Ra := Eq) (by cases hH; rfl) s3H s3L hs3) + | false => + simp only [holIf_false, Bool.false_eq_true, ↓reduceIte] + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (Rs' := SR) (Ra := FunRel embRefill) + (refillPopHead_equiv scPtr s2H s2L hs2) + (fun oldH oldL hold s2'H s2'L hs2' _ => by + subst hold + refine mrelStep_bind_mem (Rs' := SR) (Ra := Eq) + (scheduleUsed_equiv scPtr + (Structures_A.refill.r_time_update (fun _ => HolAdd.addVal oldH.r_time scH.sc_period) oldH) s2'H s2'L hs2') + (fun _ _ _ s3H s3L hs3 _ => mrel_return (Ra := Eq) (by cases hH; rfl) s3H s3L hs3)) + +theorem handleOverrun_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) (usage : Ticks) : + MRel SR Eq + (SchedContext_A.handle_overrun scPtr usage) + (Fl4Spec.handleOverrun scPtr usage) := by + unfold SchedContext_A.handle_overrun Fl4Spec.handleOverrun + exact mrel_whileLoop (Ra := Eq) + (fun uH uL hu sH sL hs => by + subst hu + have h := headRefillOverrun_equiv hop scPtr uH sH sL hs + have h' : Fl4Spec.headRefillOverrun scPtr uH sL = + SchedContext_A.head_refill_overrun scPtr uH sH := by + cases h1 : SchedContext_A.head_refill_overrun scPtr uH sH <;> + cases h2 : Fl4Spec.headRefillOverrun scPtr uH sL <;> + simp [h1, h2, OptRel] at h ⊢ + exact h.symm + rw [h', holTheOpt_bool_eq]) + (fun uH uL hu => by subst hu; exact chargeEntireHeadRefill_equiv scPtr uH) rfl + +/-- Side condition for `refill_budget_check`: every state reaching `head_insufficient_loop` +satisfies `HeadInsuffLoopSafe sH.cur_sc`. -/ +def RefillBudgetCheckSafe (usage : Ticks) (sH : Structures_A.state ZH) : Prop := + ∀ robin s1 u' s2 head s3 a s4, + (robin, s1) ∈ (Sporadic_A.is_round_robin sH.cur_sc sH).1 → + robin = false → + (u', s2) ∈ (SchedContext_A.handle_overrun sH.cur_sc usage s1).1 → + (head, s3) ∈ (KHeap_A.get_refill_head sH.cur_sc s2).1 → + (a, s4) ∈ (holWhen (holConj (holLt (HolZero.zeroVal (α := BitVec 64)) u') + (holLt head.r_time Time.MAX_RELEASE_TIME)) + (holBind (KHeap_A.get_sched_context sH.cur_sc) fun sc => + holBind (holReturn (Structures_A.refill_ext.mk (HolAdd.addVal head.r_time sc.sc_period) u' ())) fun used => + holBind (Sporadic_A.update_refill_hd sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolSub.subVal head.r_amount u') r) + (holKBind (holBind (Sporadic_A.update_refill_hd sH.cur_sc fun r => + Structures_A.refill.r_time_update (fun _ => HolAdd.addVal head.r_time u') r) + (holKBind (SchedContext_A.schedule_used sH.cur_sc used))))) s3).1 → + HeadInsuffLoopSafe sH.cur_sc s4 + +theorem refillBudgetCheck_equiv (hop : OpaqueRel RestRel) (usage : Ticks) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : RefillBudgetCheckSafe usage sH) : + MRelStep SR Eq + (SchedContext_A.refill_budget_check usage sH) + (Fl4Spec.refillBudgetCheck usage sL) := by + unfold SchedContext_A.refill_budget_check Fl4Spec.refillBudgetCheck + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun scH scL hsc s0H s0L hs0 hm0 => ?_ + subst hsc + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm0 + obtain ⟨hsc0, hs0eq⟩ := hm0 + subst hsc0 + rw [hs0eq] at hs0 ⊢ + refine mrelStep_bind_mem (isRoundRobin_equiv sH.cur_sc sH s0L hs0) + fun robH robL hrob s1H s1L hs1 hm1 => ?_ + subst hrob + refine mrelStep_bind_mem (mrel_assert (by simp [holNot_eq_true]) s1H s1L hs1) + fun _ _ _ s1'H s1'L hs1' hm1' => ?_ + have hrf : robH = false ∧ s1'H = s1H := by + cases robH with + | true => simp [holAssert, holNot] at hm1' + | false => simp [holAssert, holNot] at hm1'; exact ⟨rfl, hm1'⟩ + rcases hrf with ⟨rfl, hs1eq⟩ + rw [hs1eq] at hs1' ⊢ + refine mrelStep_bind_mem (handleOverrun_equiv hop sH.cur_sc usage s1H s1'L hs1') + fun u'H u'L hu' s2H s2L hs2 hm2 => ?_ + subst hu' + refine mrelStep_bind_mem (getRefillHead_equiv sH.cur_sc s2H s2L hs2) + fun headH headL hhead s3H s3L hs3 hm3 => ?_ + subst hhead + have hne3 : HasNonEmptyRefills sH.cur_sc s3H := getRefillHead_preserves_nonEmpty hm3 + have hwhenStep : MRelStep SR Eq + (holFunApp (holWhen (holConj (holLt (HolZero.zeroVal (α := BitVec 64)) u'H) + (holLt headH.r_time Time.MAX_RELEASE_TIME))) + (holBind (KHeap_A.get_sched_context sH.cur_sc) fun sc => + holBind (holReturn (Structures_A.refill_ext.mk (HolAdd.addVal headH.r_time sc.sc_period) u'H ())) fun used => + holBind (Sporadic_A.update_refill_hd sH.cur_sc fun r => + Structures_A.refill.r_amount_update (fun _ => HolSub.subVal headH.r_amount u'H) r) + (holKBind (holBind (Sporadic_A.update_refill_hd sH.cur_sc fun r => + Structures_A.refill.r_time_update (fun _ => HolAdd.addVal headH.r_time u'H) r) + (holKBind (SchedContext_A.schedule_used sH.cur_sc used))))) s3H) + ((NonDet.when (u'H > 0 ∧ (embRefill headH).rTime < Fl4Spec.MAX_RELEASE_TIME) <| do + let sc ← Fl4Spec.getSchedContext sH.cur_sc + let used ← pure { rTime := (embRefill headH).rTime + sc.scPeriod, rAmount := u'H : Refill } + Fl4Spec.updateRefillHd sH.cur_sc fun r => { r with rAmount := (embRefill headH).rAmount - u'H } + Fl4Spec.updateRefillHd sH.cur_sc fun r => { r with rTime := (embRefill headH).rTime + u'H } + Fl4Spec.scheduleUsed sH.cur_sc used) s3L) := by + simp only [holFunApp] + have hcond : holConj (holLt (HolZero.zeroVal (α := BitVec 64)) u'H) + (holLt headH.r_time Time.MAX_RELEASE_TIME) = true ↔ + (u'H > 0 ∧ (embRefill headH).rTime < Fl4Spec.MAX_RELEASE_TIME) := by + rw [MAX_RELEASE_TIME_eq hop] + simp [holConj_eq_true, holLt_eq_true, HolOrd.ltVal, HolZero.zeroVal, embRefill] + refine mrelStep_when hcond hs3 fun _ => ?_ + refine mrelStep_bind_mem + (mrel_lift_preserves_state (getSchedContext_equiv sH.cur_sc) (fun _ _ _ hm => getSchedContext_state_eq hm) s3H s3L ⟨hs3, hne3⟩) + fun scH scL hsc s3aH s3aL ⟨hs3a, hne3a⟩ _ => ?_ + subst hsc + refine mrelStep_bind_mem (Rs' := fun stH stL => SR stH stL ∧ HasNonEmptyRefills sH.cur_sc stH) + (mrel_return (Ra := FunRel embRefill) (by cases headH; cases scH; rfl) s3aH s3aL ⟨hs3a, hne3a⟩) + fun usedH usedL hused s3bH s3bL ⟨hs3b, hne3b⟩ _ => ?_ + subst hused + refine mrelStep_bind_mem + (updateRefillHd_equiv_nonEmpty sH.cur_sc (fun r => by + cases r; cases headH; simp [embRefill, Structures_A.refill.r_amount_update, HolSub.subVal]) s3bH s3bL ⟨hs3b, hne3b⟩) + fun _ _ _ s3cH s3cL ⟨hs3c, hne3c⟩ _ => ?_ + refine mrelStep_bind_mem + (updateRefillHd_equiv_nonEmpty sH.cur_sc (fun r => by + cases r; cases headH; simp [embRefill, Structures_A.refill.r_time_update, HolAdd.addVal]) s3cH s3cL ⟨hs3c, hne3c⟩) + fun _ _ _ s3dH s3dL ⟨hs3d, _⟩ _ => ?_ + exact scheduleUsed_equiv sH.cur_sc usedH s3dH s3dL hs3d + refine mrelStep_bind_mem hwhenStep fun aH aL ha s4H s4L hs4 hm4 => ?_ + exact mrel_drop_post (headInsufficientLoop_equiv_safe hop sH.cur_sc) s4H s4L + ⟨hs4, hsafe false s1H u'H s2H headH s3H aH s4H hm1 rfl hm2 hm3 hm4⟩ + +theorem refillUpdate_equiv_nonEmpty (scPtr : ObjRef) (newPeriod newBudget : Ticks) (newMaxRefills : Nat) : + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (SchedContext_A.refill_update scPtr newPeriod newBudget newMaxRefills) + (Fl4Spec.refillUpdate scPtr newPeriod newBudget newMaxRefills) := by + unfold SchedContext_A.refill_update Fl4Spec.refillUpdate + have h1 : MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (KHeap_A.update_sched_context scPtr (Structures_A.sched_context.sc_refills_update fun rfs => [holHd rfs])) + (Fl4Spec.updateSchedContext scPtr (Fl4Spec.scRefillsUpdate fun rfs => [the rfs.head?])) := by + intro sH sL ⟨hs, sc, n, hkh, hne⟩ + have hkhL : sL.kheap scPtr = some (.schedContext (embSchedContext sc) n) := by + rw [hs.kheap_eq scPtr, hkh]; rfl + have hhd : [the ((sc.sc_refills.map embRefill).head?)] = [holHd sc.sc_refills].map embRefill := by + cases hrf : sc.sc_refills with + | nil => exact absurd hrf hne + | cons r rs => simp [holHd, the] + let sc'H := Structures_A.sched_context.sc_refills_update (fun rfs => [holHd rfs]) sc + let sc'L := scRefillsUpdate (fun rfs => [the rfs.head?]) (embSchedContext sc) + have hsc' : sc'L = embSchedContext sc'H := by + simp only [sc'L, sc'H, embSchedContext, scRefillsUpdate, + Structures_A.sched_context.sc_refills_update] + rw [hhd] + have hne' : sc'H.sc_refills ≠ [] := by + simp [sc'H, Structures_A.sched_context.sc_refills_update] + have hstep := setObject_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + scPtr (.SchedContext sc'H n) sH sL hs + have hH_eq : KHeap_A.update_sched_context scPtr + (Structures_A.sched_context.sc_refills_update fun rfs => [holHd rfs]) sH = + KHeap_A.set_object scPtr (.SchedContext sc'H n) sH := by + unfold KHeap_A.update_sched_context KHeap_A.get_object KHeap_A.read_object holSwp + simp [holFunApp, holBind, holGetsThe, holAssertOpt, holReturn, hkh, + Structures_A.case_kernel_object, sc'H] + have hL_eq : Fl4Spec.updateSchedContext scPtr + (Fl4Spec.scRefillsUpdate fun rfs => [the rfs.head?]) sL = + Fl4Spec.setObject scPtr (.schedContext sc'L n) sL := by + unfold Fl4Spec.updateSchedContext Fl4Spec.getObject Fl4Spec.readObject + simp [Bind.bind, NonDet.bind, NonDet.getsThe, NonDet.assertOpt, NonDet.pure, hkhL, sc'L] + rw [hH_eq, hL_eq, hsc'] + have hkh' : ∀ aH sH', (aH, sH') ∈ (KHeap_A.set_object scPtr (.SchedContext sc'H n) sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro aH sH' hmH + have heq := setObject_kheap hmH + exact ⟨sc'H, n, by rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq], hne'⟩ + exact ⟨hstep.1, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs'⟩ := hstep.2.1 aH sH' m; ⟨aL, sL', mL, ha, hs', hkh' aH sH' m⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs'⟩ := hstep.2.2 aL sL' m; ⟨aH, sH', mH, ha, hs', hkh' aH sH' mH⟩⟩ + have hupdPres : ∀ (fH : Structures_A.sched_context → Structures_A.sched_context) + (fL : SchedContext → SchedContext), + (∀ sc, fL (embSchedContext sc) = embSchedContext (fH sc)) → + (∀ sc, (fH sc).sc_refills = sc.sc_refills) → + MRel (fun sH sL => SR sH sL ∧ HasNonEmptyRefills scPtr sH) Eq + (KHeap_A.update_sched_context scPtr fH) (Fl4Spec.updateSchedContext scPtr fL) := by + intro fH fL hf href sH sL ⟨hs, sc, n, hkh, hne⟩ + have hstep := updateSchedContext_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) hf scPtr sH sL hs + have hkh' : ∀ aH sH', (aH, sH') ∈ (KHeap_A.update_sched_context scPtr fH sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro aH sH' hmH + obtain ⟨sc0, n0, hkh0, heq⟩ := updateSchedContext_kheap hmH + rw [hkh] at hkh0; cases hkh0 + exact ⟨fH sc, n, by rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq], + by rw [href]; exact hne⟩ + exact ⟨hstep.1, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs'⟩ := hstep.2.1 aH sH' m; ⟨aL, sL', mL, ha, hs', hkh' aH sH' m⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs'⟩ := hstep.2.2 aL sL' m; ⟨aH, sH', mH, ha, hs', hkh' aH sH' mH⟩⟩ + have hready_stay : ∀ (sH : Structures_A.state ZH) b sH', + (b, sH') ∈ (KHeap_A.get_sc_refill_ready scPtr sH).1 → sH' = sH := + fun _ _ _ hm => holGetsThe_state_eq hm + have hhead_stay : ∀ (sH : Structures_A.state ZH) r sH', + (r, sH') ∈ (KHeap_A.get_refill_head scPtr sH).1 → sH' = sH := + fun _ _ _ hm => holGetsThe_state_eq hm + refine mrel_kbind h1 ?_ + refine mrel_kbind (hupdPres _ _ (fun _ => rfl) (fun _ => rfl)) ?_ + refine mrel_kbind (hupdPres _ _ (fun _ => rfl) (fun _ => rfl)) ?_ + refine mrel_kbind (hupdPres _ _ (fun _ => rfl) (fun _ => rfl)) ?_ + refine mrel_bind (mrel_lift_preserves_state (getScRefillReady_equiv scPtr) hready_stay) fun rdH rdL hrd => ?_ + subst hrd + refine mrel_kbind (mrel_when Iff.rfl fun _ => + mrel_bind (mrel_gets fun _ _ h => h.1.curTime_eq.symm) fun ctH ctL hct => by + subst hct + exact updateRefillHd_equiv_nonEmpty scPtr (fun r => by + cases r; simp [embRefill, Structures_A.refill.r_time_update])) ?_ + refine mrel_bind (mrel_lift_preserves_state (getRefillHead_equiv scPtr) hhead_stay) fun hH hL hh => ?_ + subst hh + refine mrel_if (by cases hH; simp [embRefill, holLe_eq_true, HolOrd.leVal]) (fun _ => ?_) (fun _ => ?_) + · refine mrel_kbind (updateRefillHd_equiv_nonEmpty scPtr (fun r => by + cases r; simp [embRefill, Structures_A.refill.r_amount_update])) ?_ + -- `maybeAddEmptyTail` preserves `HasNonEmptyRefills`! + intro sH sL ⟨hs, sc, n, hkh, hne⟩ + have hstep := maybeAddEmptyTail_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr sH sL hs + have hpres : ∀ aH sH', (aH, sH') ∈ (SchedContext_A.maybe_add_empty_tail scPtr sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro aH sH' hm + unfold SchedContext_A.maybe_add_empty_tail at hm + simp only [holBind, holFunApp] at hm + rcases hm with ⟨⟨rob, s1⟩, m1, m2⟩ + have hs1 : s1 = sH := by + unfold Sporadic_A.is_round_robin at m1 + simp only [holBind, holReturn, Set.mem_singleton_iff] at m1 + rcases m1 with ⟨⟨sc1, s1'⟩, msc, hm_eq⟩ + cases hm_eq + exact getSchedContext_state_eq msc + rw [hs1] at m2 + cases rob with + | false => + simp [holWhen, holReturn] at m2; rcases m2 with ⟨_, rfl⟩; exact ⟨sc, n, hkh, hne⟩ + | true => + simp only [holWhen, ↓reduceIte, holBind] at m2 + rcases m2 with ⟨⟨hd, s2⟩, mhd, ⟨_, s3⟩, hm3, madd⟩ + simp only [holReturn, Set.mem_singleton_iff] at hm3 + cases hm3 + have hs2 : s2 = sH := hhead_stay sH hd s2 mhd + rw [hs2] at madd + obtain ⟨sc0, n0, _, heq⟩ := updateSchedContext_kheap madd + refine ⟨Structures_A.sched_context.sc_refills_update + (fun refills => holListAppend refills [Structures_A.refill_ext.mk hd.r_time 0 ()]) sc0, n0, ?_, ?_⟩ + · rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq, HolZero.zeroVal] + · cases sc0.sc_refills <;> simp [Structures_A.sched_context.sc_refills_update, holListAppend] + exact ⟨hstep.1, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs'⟩ := hstep.2.1 aH sH' m; ⟨aL, sL', mL, ha, hs', hpres aH sH' m⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs'⟩ := hstep.2.2 aL sL' m; ⟨aH, sH', mH, ha, hs', hpres aH sH' mH⟩⟩ + · refine mrel_bind (mrel_return (Ra := Eq) (aH := HolSub.subVal newBudget hH.r_amount) (by cases hH; rfl)) + fun uH uL hu => ?_ + subst hu + refine mrel_bind (mrel_return (Ra := FunRel embRefill) (by cases hH; rfl)) fun nH nL hn => ?_ + subst hn + intro sH sL ⟨hs, _⟩ + have hstep := refillAddTail_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr nH sH sL hs + have hpres : ∀ aH sH', (aH, sH') ∈ (SchedContext_A.refill_add_tail scPtr nH sH).1 → + HasNonEmptyRefills scPtr sH' := by + intro aH sH' madd + obtain ⟨sc0, n0, _, heq⟩ := updateSchedContext_kheap madd + refine ⟨Structures_A.sched_context.sc_refills_update + (fun refills => holListAppend refills [nH]) sc0, n0, ?_, ?_⟩ + · rw [heq]; simp [Structures_A.abstract_state.kheap_update, holFunUpd_eq] + · simp [Structures_A.sched_context.sc_refills_update, holListAppend] + exact ⟨hstep.1, + fun aH sH' m => let ⟨aL, sL', mL, ha, hs'⟩ := hstep.2.1 aH sH' m; ⟨aL, sL', mL, ha, hs', hpres aH sH' m⟩, + fun aL sL' m => let ⟨aH, sH', mH, ha, hs'⟩ := hstep.2.2 aL sL' m; ⟨aH, sH', mH, ha, hs', hpres aH sH' mH⟩⟩ + +theorem postpone_equiv (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.postpone scPtr) (Fl4Spec.postpone scPtr) := by + unfold SchedContext_A.postpone Fl4Spec.postpone + refine mrel_bind (getScObjRef_equiv (fun _ => rfl) scPtr) fun oH oL ho => ?_ + subst ho + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases oH <;> simp [OptRel])) fun tH tL ht => ?_ + subst ht + refine mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq tH) ?_ + refine mrel_kbind (tcbReleaseEnqueue_equiv tH) ?_ + exact mrel_modify fun _ _ hs => { hs with reprogramTimer_eq := rfl } + +theorem schedContextResume_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.sched_context_resume scPtr) (Fl4Spec.schedContextResume scPtr) := by + unfold SchedContext_A.sched_context_resume Fl4Spec.schedContextResume + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by + cases h : scH.sc_tcb <;> simp [h, OptRel, embSchedContext])) fun tH tL ht => ?_ + subst ht + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs tH).symm) fun schH schL hsch => ?_ + subst hsch + refine mrel_when Iff.rfl fun _ => ?_ + refine mrel_bind (threadGet_equiv (Ra := FunRel embThreadState) (fun _ => rfl) tH) fun tsH tsL hts => ?_ + subst hts + refine mrel_bind (getScRefillReady_equiv scPtr) fun rdH rdL hrd => ?_ + subst hrd + refine mrel_bind (getScRefillSufficient_equiv hop scPtr 0) fun sfH sfL hsf => ?_ + subst hsf + refine mrel_when (by + simp [holConj_eq_true, holNot_eq_true, runnable_eq, Fl4Spec.scActive, + embSchedContext, activeSc_eq]) fun _ => ?_ + refine mrel_bind (threadGet_equiv (fun _ => rfl) tH) fun dH dL hd => ?_ + subst hd + refine mrel_bind (threadGet_equiv (fun _ => rfl) tH) fun pH pL hp => ?_ + subst hp + refine mrel_bind (getTcbQueue_equiv dH pH) fun qH qL hq => ?_ + subst hq + refine mrel_kbind (mrel_assert (by simp [holNot_eq_true, holMember_eq_true, holListSet_eq])) ?_ + exact postpone_equiv scPtr + +theorem schedContextUpdateConsumed_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.sched_context_update_consumed scPtr) + (Fl4Spec.schedContextUpdateConsumed scPtr) := by + unfold SchedContext_A.sched_context_update_consumed Fl4Spec.schedContextUpdateConsumed + Fl4Spec.setScObjRef + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + refine mrel_bind (mrel_return (aH := scH.sc_consumed) rfl) fun cH cL hc => ?_ + subst hc + refine mrel_if (by simp [holLe_eq_true, HolOrd.leVal, hop.maxTicksToUs_eq]) + (fun _ => mrel_kbind (updateSchedContext_equiv (fun sc => by + cases sc; simp [embSchedContext, Structures_A.sched_context.sc_consumed_update, + Fl4Spec.scConsumedUpdate, hop.maxTicksToUs_eq, HolSub.subVal]) scPtr) + (mrel_return (by rw [hop.maxTicksToUs_eq, ticksToUs_eq hop]))) + (fun _ => mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) + (mrel_return (by rw [ticksToUs_eq hop]; rfl))) + +theorem returnConsumed_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.return_consumed scPtr) (Fl4Spec.returnConsumed scPtr) := by + unfold SchedContext_A.return_consumed Fl4Spec.returnConsumed + refine mrel_bind (schedContextUpdateConsumed_equiv hop scPtr) fun cH cL hc => ?_ + subst hc + exact mrel_return (by simp [wordsFromTime_eq]) + +theorem schedContextCancelYieldTo_equiv (thread : ObjRef) : + MRel SR Eq + (SchedContext_A.sched_context_cancel_yield_to thread) + (Fl4Spec.schedContextCancelYieldTo thread) := by + unfold SchedContext_A.sched_context_cancel_yield_to Fl4Spec.schedContextCancelYieldTo + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) thread) fun oH oL ho => ?_ + subst ho + refine mrel_maybeM (Ra := Eq) (fun scH scL hsc => by + subst hsc + exact mrel_kbind (setScObjRef_equiv (fun _ _ => rfl) scH none) + (setTcbObjRef_equiv (fun _ _ => rfl) thread none)) (by cases oH <;> simp [OptRel]) + +/-- Parameterized `set_consumed` (downstream of Delta #2 `reply_from_kernel`). -/ +def set_consumed_p (sc_ptr tcb_ptr : ObjRef) : HolNonDet (Structures_A.state ZH) Unit := + holBind (SchedContext_A.sched_context_update_consumed sc_ptr) fun consumed => + Patched.reply_from_kernel tcb_ptr (HolZero.zeroVal, Arch_Structs_A.words_from_time consumed) + +theorem patched_setConsumed_equiv (hop : OpaqueRel RestRel) (scPtr tcbPtr : ObjRef) : + MRel SR Eq + (set_consumed_p scPtr tcbPtr) (Fl4Spec.setConsumed scPtr tcbPtr) := by + unfold set_consumed_p Fl4Spec.setConsumed + refine mrel_bind (schedContextUpdateConsumed_equiv hop scPtr) fun cH cL hc => ?_ + subst hc + rw [wordsFromTime_eq] + exact patched_replyFromKernel_equiv tcbPtr (0, Arch_Structs_A.words_from_time cH) + +/-- Parameterized `complete_yield_to` (downstream of Delta #2 `reply_from_kernel`). -/ +def complete_yield_to_p (tcb_ptr : ObjRef) : HolNonDet (Structures_A.state ZH) Unit := + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_yield_to tcb_ptr) fun yt_opt => + holMaybeM (fun sc_ptr => + holBind (set_consumed_p sc_ptr tcb_ptr) + (holKBind (SchedContext_A.sched_context_cancel_yield_to tcb_ptr))) yt_opt + +theorem patched_completeYieldTo_equiv (hop : OpaqueRel RestRel) (tcbPtr : ObjRef) : + MRel SR Eq + (complete_yield_to_p tcbPtr) (Fl4Spec.completeYieldTo tcbPtr) := by + unfold complete_yield_to_p Fl4Spec.completeYieldTo + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) tcbPtr) fun oH oL ho => ?_ + subst ho + refine mrel_maybeM (Ra := Eq) (fun scH scL hsc => by + subst hsc + exact mrel_kbind (patched_setConsumed_equiv hop scH tcbPtr) + (schedContextCancelYieldTo_equiv tcbPtr)) (by cases oH <;> simp [OptRel]) + +/-- Parameterized `sched_context_unbind_yield_from` (downstream of Delta #2 `reply_from_kernel`). -/ +def sched_context_unbind_yield_from_p (sc_ptr : ObjRef) : HolNonDet (Structures_A.state ZH) Unit := + holBind (KHeap_A.get_sched_context sc_ptr) fun sc => + holMaybeM complete_yield_to_p sc.sc_yield_from + +theorem patched_schedContextUnbindYieldFrom_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel SR Eq + (sched_context_unbind_yield_from_p scPtr) (Fl4Spec.schedContextUnbindYieldFrom scPtr) := by + unfold sched_context_unbind_yield_from_p Fl4Spec.schedContextUnbindYieldFrom + refine mrel_bind (getSchedContext_equiv scPtr) fun scH scL hsc => ?_ + subst hsc + refine mrel_maybeM (Ra := Eq) (fun tH tL ht => by subst ht; exact patched_completeYieldTo_equiv hop tH) + (by cases h : scH.sc_yield_from <;> simp [h, OptRel, embSchedContext]) + +def unbind_from_sc_p (tcb_ptr : ObjRef) : HolNonDet (Structures_A.state ZH) Unit := + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context tcb_ptr) fun sc_ptr_opt => + holBind (holMaybeM IpcCancel_A.sched_context_unbind_tcb sc_ptr_opt) + (holKBind (holMaybeM (fun scptr => + holBind (KHeap_A.get_sched_context scptr) fun sc => + holMaybeM complete_yield_to_p sc.sc_yield_from) sc_ptr_opt)) + +theorem patched_unbindFromSc_equiv (hop : OpaqueRel RestRel) (tcbPtr : ObjRef) : + MRel SR Eq + (unbind_from_sc_p tcbPtr) (Fl4Spec.unbindFromSc tcbPtr) := by + unfold unbind_from_sc_p Fl4Spec.unbindFromSc + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) tcbPtr) fun oH oL ho => ?_ + subst ho + refine mrel_kbind (mrel_maybeM (Ra := Eq) (fun scH scL hsc => by subst hsc; exact schedContextUnbindTcb_equiv hop scH) + (by cases oH <;> simp [OptRel])) ?_ + refine mrel_maybeM (Ra := Eq) (fun scH scL hsc => by + subst hsc + refine mrel_bind (getSchedContext_equiv scH) fun sc0H sc0L hsc0 => ?_ + subst hsc0 + exact mrel_maybeM (Ra := Eq) (fun tH tL ht => by subst ht; exact patched_completeYieldTo_equiv hop tH) + (by cases h : sc0H.sc_yield_from <;> simp [h, OptRel, embSchedContext])) + (by cases oH <;> simp [OptRel]) + +theorem testPossibleSwitchTo_equiv (hop : OpaqueRel RestRel) (tcbPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.test_possible_switch_to tcbPtr) (Fl4Spec.testPossibleSwitchTo tcbPtr) := by + unfold SchedContext_A.test_possible_switch_to Fl4Spec.testPossibleSwitchTo + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs tcbPtr).symm) fun bH bL hb => ?_ + subst hb + exact mrel_when Iff.rfl fun _ => possibleSwitchTo_equiv hop tcbPtr + +theorem schedContextBindTcb_equiv (hop : OpaqueRel RestRel) (scPtr tcbPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.sched_context_bind_tcb scPtr tcbPtr) + (Fl4Spec.schedContextBindTcb scPtr tcbPtr) := by + unfold SchedContext_A.sched_context_bind_tcb Fl4Spec.schedContextBindTcb + refine mrel_kbind (setTcbObjRef_equiv (fun _ _ => rfl) tcbPtr (some scPtr)) ?_ + refine mrel_kbind (setScObjRef_equiv (fun _ _ => rfl) scPtr (some tcbPtr)) ?_ + refine mrel_kbind (ifSporadicActiveCurScTestRefillUnblockCheck_equiv (some scPtr)) ?_ + refine mrel_kbind (schedContextResume_equiv hop scPtr) ?_ + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs tcbPtr).symm) fun bH bL hb => ?_ + subst hb + exact mrel_when Iff.rfl fun _ => + mrel_kbind (tcbSchedAction_equiv tcbSchedEnqueue_eq tcbPtr) (rescheduleRequired_equiv hop) + +theorem schedContextSetInactive_equiv (scPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.sched_context_set_inactive scPtr) + (Fl4Spec.schedContextSetInactive scPtr) := by + unfold SchedContext_A.sched_context_set_inactive Fl4Spec.schedContextSetInactive + refine mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) ?_ + refine mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) ?_ + refine mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) ?_ + exact updateSchedContext_equiv (fun _ => rfl) scPtr + +theorem maybeDonateSc_equiv (hop : OpaqueRel RestRel) (tcbPtr ntfnPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.maybe_donate_sc tcbPtr ntfnPtr) + (Fl4Spec.maybeDonateSc tcbPtr ntfnPtr) := by + unfold SchedContext_A.maybe_donate_sc Fl4Spec.maybeDonateSc + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) tcbPtr) fun oH oL ho => ?_ + subst ho + refine mrel_when (by simp [holEq_eq_true]) fun _ => ?_ + refine mrel_bind (getNtfnObjRef_equiv (fun _ => rfl) ntfnPtr) fun noH noL hno => ?_ + subst hno + refine mrel_maybeM (Ra := Eq) (fun scH scL hsc => ?_) (by cases noH <;> simp [OptRel]) + subst hsc + refine mrel_bind (getScObjRef_equiv (fun _ => rfl) scH) fun toH toL hto => ?_ + subst hto + refine mrel_when (by simp [holEq_eq_true]) fun _ => ?_ + exact mrel_kbind (schedContextDonate_equiv hop scH tcbPtr) (schedContextResume_equiv hop scH) + +theorem maybeReturnSc_equiv (hop : OpaqueRel RestRel) (ntfnPtr tcbPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.maybe_return_sc ntfnPtr tcbPtr) + (Fl4Spec.maybeReturnSc ntfnPtr tcbPtr) := by + unfold SchedContext_A.maybe_return_sc Fl4Spec.maybeReturnSc + refine mrel_bind (getNtfnObjRef_equiv (fun _ => rfl) ntfnPtr) fun nH nL hn => ?_ + subst hn + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) tcbPtr) fun tH tL ht => ?_ + subst ht + refine mrel_when (by simp [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true]) fun _ => ?_ + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases nH <;> simp [OptRel])) fun scH scL hsc => ?_ + subst hsc + refine mrel_kbind (setTcbObjRef_equiv (fun _ _ => rfl) tcbPtr none) ?_ + refine mrel_kbind (setScObjRef_equiv (fun _ _ => rfl) scH none) ?_ + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun ctH ctL hct => ?_ + subst hct + exact mrel_when (by simp [holEq_eq_true]) fun _ => rescheduleRequired_equiv hop + +def CommitTimeSafe (sH : Structures_A.state ZH) : Prop := + (∃ sc n, sH.kheap sH.cur_sc = some (.SchedContext sc n) ∧ KHeap_A.active_sc sc.sc_refill_max = true) → + sH.cur_sc ≠ Machine_A.idle_sc_ptr → + (0 : BitVec 64) < sH.consumed_time → + (HasNonEmptyRefills sH.cur_sc sH ∧ RefillBudgetCheckSafe sH.consumed_time sH) + +theorem commitTime_equiv (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : CommitTimeSafe sH) : + MRelStep SR Eq + (SchedContext_A.commit_time sH) (Fl4Spec.commitTime sL) := by + unfold SchedContext_A.commit_time Fl4Spec.commitTime + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun cscH cscL hcsc s0H s0L hs0 hm0 => ?_ + subst hcsc + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm0 + obtain ⟨hcsc0, hs0eq⟩ := hm0 + subst hcsc0 + rw [hs0eq] at hs0 ⊢ + refine mrelStep_bind_mem (getScActive_equiv sH.cur_sc sH s0L hs0) + fun actH actL hact s1H s1L hs1 hm1 => ?_ + subst hact + have hact_witness : s1H = sH ∧ (actH = true → + ∃ sc n, sH.kheap sH.cur_sc = some (.SchedContext sc n) ∧ KHeap_A.active_sc sc.sc_refill_max = true) := by + unfold KHeap_A.get_sc_active KHeap_A.read_sc_active KHeap_A.read_sched_context + KHeap_A.read_object holSwp at hm1 + cases hk : sH.kheap sH.cur_sc with + | none => simp [hk, holGetsThe, holAssertOpt, holOBind, holFail] at hm1 + | some ko => + cases ko with + | SchedContext sc n => + simp [hk, holFunApp, holGetsThe, holAssertOpt, holOBind, holOReturn, holReturn, + Structures_A.case_kernel_object] at hm1 + rcases hm1 with ⟨rfl, rfl⟩ + exact ⟨rfl, fun h => ⟨sc, n, rfl, h⟩⟩ + | _ => simp [hk, holGetsThe, holAssertOpt, holOBind, holOFail, holFail, + Structures_A.case_kernel_object] at hm1 + obtain ⟨hs1eq, hactW⟩ := hact_witness + rw [hs1eq] at hs1 ⊢ + change MRelStep SR Eq _ (NonDet.bind (NonDet.gets (fun s : State ZL => s.idleSc)) _ s1L) + rw [nonDet_bind_gets_at] + change MRelStep SR Eq (holBind _ _ sH) (NonDet.bind _ _ s1L) + refine mrelStep_bind_mem (Rs' := SR) (Ra := Eq) ?_ (fun _ _ _ s2H s2L hs2 _ => + mrel_modify (fun _ _ h => { h with consumedTime_eq := rfl }) s2H s2L hs2) + dsimp only [holFunApp] + refine mrelStep_when (by simp [holConj_eq_true, holNot_eq_true, ne_eq, holEq_eq_true, hs1.idleSc_eq]) hs1 + fun ⟨hactTrue, hneIdle⟩ => ?_ + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.consumedTime_eq.symm) sH s1L hs1) + fun ctH ctL hct s1aH s1aL hs1a hm1a => ?_ + subst hct + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm1a + obtain ⟨hct0, hs1aeq⟩ := hm1a + subst hct0 + rw [hs1aeq] at hs1a ⊢ + change MRelStep SR Eq (holBind _ _ sH) (NonDet.bind _ _ s1aL) + refine mrelStep_bind_mem (Rs' := SR) (Ra := Eq) ?_ (fun _ _ _ s1bH s1bL hs1b _ => + updateSchedContext_equiv (fun sc => by + cases sc; simp [embSchedContext, Structures_A.sched_context.sc_consumed_update, HolAdd.addVal]) + sH.cur_sc s1bH s1bL hs1b) + refine mrelStep_when (by simp [holLt_eq_true, HolOrd.ltVal, HolZero.zeroVal]) hs1a fun hpos => ?_ + have hsafe' := hsafe (hactW hactTrue) (hs1.idleSc_eq ▸ hneIdle) hpos + refine mrelStep_bind_mem (isRoundRobin_equiv sH.cur_sc sH s1aL hs1a) + fun robH robL hrob s1cH s1cL hs1c hm1c => ?_ + subst hrob + have hs1c_eq : s1cH = sH := by + unfold Sporadic_A.is_round_robin at hm1c + simp only [holBind, holReturn, Set.mem_singleton_iff] at hm1c + rcases hm1c with ⟨⟨sc1, s1'⟩, msc, hm_eq⟩ + cases hm_eq + exact getSchedContext_state_eq msc + rw [hs1c_eq] at hs1c ⊢ + cases robH with + | true => + simp only [holIf_true, ↓reduceIte] + exact mrel_drop_post (refillBudgetCheckRoundRobin_equiv sH.consumed_time) sH s1cL ⟨hs1c, hsafe'.1⟩ + | false => + simp only [holIf_false, Bool.false_eq_true, ↓reduceIte] + exact refillBudgetCheck_equiv hop sH.consumed_time hs1c hsafe'.2 + +theorem updateRestartPc_equiv (threadPtr : ObjRef) : + MRel SR Eq + (SchedContext_A.update_restart_pc threadPtr) + (Fl4Spec.updateRestartPc threadPtr) := by + unfold SchedContext_A.update_restart_pc Fl4Spec.updateRestartPc + refine asUser_equiv ?_ threadPtr + rw [nextInstructionRegister_eq, faultRegister_eq] + refine mrel_bind (getRegister_equiv _) fun vH vL hv => ?_ + subst hv + exact setRegister_equiv _ vH + +theorem suspend_equiv (thread : ObjRef) : + MRel SR Eq + (SchedContext_A.suspend thread) (Fl4Spec.suspend thread) := by + unfold SchedContext_A.suspend Fl4Spec.suspend + refine mrel_kbind (cancelIpc_equiv thread) ?_ + refine mrel_bind (getThreadState_equiv thread) fun tsH tsL hts => ?_ + subst hts + refine mrel_kbind (mrel_when (by cases tsH <;> simp [holEq_eq_true, embThreadState]) + fun _ => updateRestartPc_equiv thread) ?_ + refine mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq thread) ?_ + refine mrel_kbind (tcbReleaseRemove_equiv thread) ?_ + refine mrel_kbind (schedContextCancelYieldTo_equiv thread) ?_ + exact setThreadState_equiv thread .Inactive + +end SchedContextMonad + +end + +end L4vRefX64.Equiv.SchedContext diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Schedule.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Schedule.lean new file mode 100644 index 000000000..a4d45055b --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Schedule.lean @@ -0,0 +1,1189 @@ +import L4vRefX64.Spec.Schedule_A +import L4vRefX64.Rel.Invocation +import L4vRefX64.Equiv.ArchSwitch +import L4vRefX64.Equiv.Hardware +import L4vRefX64.Equiv.SchedContext + +namespace L4vRefX64.Equiv.Schedule + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.Hardware L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.ArchSwitch +open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Deterministic +open L4vRefX64.Equiv.IpcCancel L4vRefX64.Equiv.SchedContext L4vRefX64.Equiv.CSpaceAcc +open Fl4Spec Classical + +noncomputable section + +theorem idle_iff (st : Structures_A.thread_state) : + Schedule_A.idle st = true ↔ Fl4Spec.idle (embThreadState st) := by + cases st <;> simp [Schedule_A.idle, Fl4Spec.idle, embThreadState, holEq_eq_true] + +theorem domainEndMarker_eq : + Fl4Spec.domainEndMarker = Schedule_A.domain_end_marker := rfl + +private theorem bitvec8_existsUnique_max (S : Set (BitVec 8)) (hne : ∃ p, p ∈ S) : + ∃! m : BitVec 8, m ∈ S ∧ ∀ x ∈ S, x ≤ m := by + have hex : ∀ k : Nat, (∃ x ∈ S, x.toNat < k) → + ∃ m ∈ S, m.toNat < k ∧ ∀ x ∈ S, x.toNat < k → x ≤ m := by + intro k + induction k with + | zero => rintro ⟨x, _, hlt⟩; omega + | succ k ih => + intro h + by_cases htop : BitVec.ofNat 8 k ∈ S ∧ k < 256 + · refine ⟨BitVec.ofNat 8 k, htop.1, + by simp [BitVec.toNat_ofNat, Nat.mod_eq_of_lt htop.2], ?_⟩ + intro x hx hxk + rw [BitVec.le_def, BitVec.toNat_ofNat, Nat.mod_eq_of_lt htop.2] + omega + · have hlt : ∃ x ∈ S, x.toNat < k := by + rcases h with ⟨x, hx, hxk⟩ + by_cases hEq : x.toNat = k + · exfalso; apply htop + have hk : k < 256 := by have := x.isLt; omega + have hxb : x = BitVec.ofNat 8 k := by + apply BitVec.eq_of_toNat_eq + simp [BitVec.toNat_ofNat, Nat.mod_eq_of_lt hk, hEq] + exact ⟨hxb ▸ hx, hk⟩ + · exact ⟨x, hx, by omega⟩ + rcases ih hlt with ⟨m, hmS, hmk, hmax⟩ + refine ⟨m, hmS, by omega, fun x hx hxk => ?_⟩ + by_cases hEq : x.toNat = k + · exfalso; apply htop + have hk : k < 256 := by have := x.isLt; omega + have hxb : x = BitVec.ofNat 8 k := by + apply BitVec.eq_of_toNat_eq + simp [BitVec.toNat_ofNat, Nat.mod_eq_of_lt hk, hEq] + exact ⟨hxb ▸ hx, hk⟩ + · exact hmax x hx (by omega) + rcases hne with ⟨p, hp⟩ + rcases hex 256 ⟨p, hp, p.isLt⟩ with ⟨m, hmS, _, hmax⟩ + refine ⟨m, ⟨hmS, fun x hx => hmax x hx x.isLt⟩, fun m' ⟨hm'S, hmax'⟩ => ?_⟩ + exact BitVec.le_antisymm (hmax m' hm'S m'.isLt) (hmax' m hmS) + +theorem setMax_bitvec8_eq_holMax (S : Set (BitVec 8)) (hne : ∃ p, p ∈ S) : + Fl4Spec.setMax S = holMax S := by + obtain ⟨m, hm, huniq⟩ := bitvec8_existsUnique_max S hne + have h1 : Fl4Spec.setMax S = m := by + unfold Fl4Spec.setMax Fl4Spec.The + split_ifs with h + · exact huniq _ (Classical.choose_spec h).1 + · exfalso; exact h ⟨m, hm, huniq⟩ + have h2 : holMax S = m := by + unfold holMax holThe + split_ifs with h + · have hx := (Classical.choose_spec h).1 + generalize Classical.choose h = x at hx ⊢ + simp only [decide_eq_true_eq, HolOrd.leVal] at hx + exact huniq x hx + · exfalso + apply h + refine ⟨m, ?_, fun y hy => ?_⟩ + · simp only [decide_eq_true_eq, HolOrd.leVal]; exact hm + · simp only [decide_eq_true_eq, HolOrd.leVal] at hy; exact huniq y hy + rw [h1, h2] + +theorem maxNonEmptyQueue_eq (queues : Priority → ReadyQueue) (hne : ∃ prio, queues prio ≠ []) : + Fl4Spec.maxNonEmptyQueue queues = Schedule_A.max_non_empty_queue queues := by + unfold Fl4Spec.maxNonEmptyQueue Schedule_A.max_non_empty_queue + have hS : ({prio | queues prio ≠ []} : Set (BitVec 8)) = + holCollect (fun prio => holNot (holEq (queues prio) [])) := by + ext prio; simp [holCollect, holNot_eq_true, holEq_eq_true] + rw [← hS, setMax_bitvec8_eq_holMax _ hne] + +theorem maxNonEmptyQueue_ne_nil (queues : Priority → ReadyQueue) (hne : ∃ prio, queues prio ≠ []) : + Schedule_A.max_non_empty_queue queues ≠ [] := by + rw [← maxNonEmptyQueue_eq queues hne] + unfold Fl4Spec.maxNonEmptyQueue Fl4Spec.setMax Fl4Spec.The + obtain ⟨m, hm, huniq⟩ := bitvec8_existsUnique_max {prio | queues prio ≠ []} hne + split_ifs with h + · exact (Classical.choose_spec h).1.1 + · exfalso; exact h ⟨m, hm, huniq⟩ + +section SchedMonad +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 isHighestPrio_iff (d : Domain) (p : Priority) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) : + Schedule_A.is_highest_prio d p sH = true ↔ Fl4Spec.isHighestPrio d p sL := by + unfold Schedule_A.is_highest_prio Fl4Spec.isHighestPrio + rw [hs.readyQueues_eq] + simp only [holDisj_eq_true, holAll_eq_true, holEq_eq_true, holLe_eq_true, HolOrd.leVal, ge_iff_le] + by_cases hall : ∀ prio, sH.ready_queues d prio = [] + · simp [hall] + · have hne : ∃ prio, sH.ready_queues d prio ≠ [] := by + by_contra h; exact hall (fun prio => by by_contra h'; exact h ⟨prio, h'⟩) + have hS : ({prio | sH.ready_queues d prio ≠ []} : Set (BitVec 8)) = + holCollect (fun prio => holNot (holEq (sH.ready_queues d prio) [])) := by + ext prio; simp [holCollect, holNot_eq_true, holEq_eq_true] + rw [← hS, setMax_bitvec8_eq_holMax _ hne] + +private theorem holGets_member_state {σ α : Type} {f : σ → α} {s s' : σ} {v : α} + (hm : (v, s') ∈ (holGets f s).1) : s' = s := by + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm + exact hm.2 + +private theorem holAssert_member_state {σ : Type} {b : Bool} {s s' : σ} {v : Unit} + (hm : (v, s') ∈ (holAssert b s).1) : s' = s := by + simp only [holAssert, Set.mem_ofPred_eq, Prod.mk.injEq] at hm + exact hm.2.2 + +private theorem holAssertOpt_member_state {σ α : Type} {o : Option α} {s s' : σ} {v : α} + (hm : (v, s') ∈ (holAssertOpt o s).1) : s' = s := by + cases o <;> simp_all [holAssertOpt, holReturn, holFail] + +omit [StateExt ZL] in +private theorem threadGet_member_state {α : Type} [Nonempty α] + {f : Structures_A.tcb → α} {t : ObjRef} {s s' : Structures_A.state ZH} {v : α} + (hm : (v, s') ∈ (KHeap_A.thread_get f t s).1) : s' = s := by + unfold KHeap_A.thread_get at hm + simp only [holBind, Set.mem_ofPred_eq, Prod.exists, holFunApp, holGetsThe] at hm + obtain ⟨tcb, st, hget, hret⟩ := hm + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hret + exact hret.2.trans (holAssertOpt_member_state hget) + +theorem switchToThread_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : ReferenceBaseCarriers sH) : + MRelStep SR Eq (Schedule_A.switch_to_thread thread sH) (Fl4Spec.switchToThread thread sL) := by + unfold Schedule_A.switch_to_thread Fl4Spec.switchToThread + refine mrelStep_bind_mem (mrel_get (Rs := SR) sH sL hs) + fun aH aL ha s1H s1L hs1 hm1 => ?_ + simp only [holGet, Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + obtain ⟨heqa, heqs⟩ := hm1 + subst aH + subst s1H + refine mrelStep_bind_mem (mrel_assert (by + have hgt := getTcb_equiv thread sH aL ha + cases h1 : KHeap_A.get_tcb thread sH <;> cases h2 : Fl4Spec.getTcb thread aL <;> + simp [h1, h2, OptRel, holNot_eq_true, holEq_eq_true] at hgt ⊢) sH s1L hs1) + fun _ _ _ s2H s2L hs2 hm2 => ?_ + have heq := holAssert_member_state hm2 + subst s2H + refine mrelStep_bind_mem (archSwitchToThread_equiv hop thread hs2 hb) + fun _ _ _ s3H s3L hs3 _ => ?_ + refine mrelStep_bind_mem (tcbSchedAction_equiv tcbSchedDequeue_eq thread s3H s3L hs3) + fun _ _ _ s4H s4L hs4 _ => ?_ + exact (mrel_modify fun _ _ h => { h with curThread_eq := rfl }) s4H s4L hs4 + +theorem guardedSwitchTo_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : ReferenceBaseCarriers sH) : + MRelStep SR Eq (Schedule_A.guarded_switch_to thread sH) (Fl4Spec.guardedSwitchTo thread sL) := by + unfold Schedule_A.guarded_switch_to Fl4Spec.guardedSwitchTo + refine mrelStep_bind_mem (threadGet_equiv (fun _ => rfl) thread sH sL hs) + fun scH scL hsc s1H s1L hs1 hm1 => ?_ + subst hsc + have heq1 := threadGet_member_state hm1 + subst s1H + refine mrelStep_bind_mem (mrel_assertOpt (Ra := Eq) (by cases scH <;> simp [OptRel]) sH s1L hs1) + fun _ _ _ s2H s2L hs2 hm2 => ?_ + have heq2 := holAssertOpt_member_state hm2 + subst s2H + refine mrelStep_bind_mem (mrel_gets (Rs := SR) (Ra := Eq) (fun _ _ h => (schedulable_eq h thread).symm) + sH s2L hs2) fun bH bL hbool s3H s3L hs3 hm3 => ?_ + subst hbool + have heq3 := holGets_member_state hm3 + subst s3H + refine mrelStep_bind_mem (mrel_assert Iff.rfl sH s3L hs3) + fun _ _ _ s4H s4L hs4 hm4 => ?_ + have heq4 := holAssert_member_state hm4 + subst s4H + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curDomain_eq.symm) sH s4L hs4) + fun dH dL hd s5H s5L hs5 hm5 => ?_ + subst hd + have heq5 := holGets_member_state hm5 + subst s5H + refine mrelStep_bind_mem (threadGet_equiv (fun _ => rfl) thread sH s5L hs5) + fun ndH ndL hnd s6H s6L hs6 hm6 => ?_ + subst hnd + have heq6 := threadGet_member_state hm6 + subst s6H + refine mrelStep_bind_mem (mrel_assert (holEq_eq_true _ _) sH s6L hs6) + fun _ _ _ s7H s7L hs7 hm7 => ?_ + have heq7 := holAssert_member_state hm7 + subst s7H + exact switchToThread_equiv hop thread hs7 hb + +theorem switchToIdleThread_equiv + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : ReferenceBaseCarriers sH) : + MRelStep SR Eq (Schedule_A.switch_to_idle_thread sH) (Fl4Spec.switchToIdleThread sL) := by + unfold Schedule_A.switch_to_idle_thread Fl4Spec.switchToIdleThread + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.idleThread_eq.symm) sH sL hs) + fun tH tL ht s1H s1L hs1 hm1 => ?_ + subst ht + have heq1 := holGets_member_state hm1 + subst s1H + refine mrelStep_bind_mem (archSwitchToIdleThread_equiv hs1 hb) fun _ _ _ s2H s2L hs2 _ => ?_ + exact (mrel_modify fun _ _ h => { h with curThread_eq := rfl }) s2H s2L hs2 + +theorem decDomainTime_equiv : + MRel SR Eq + (Schedule_A.dec_domain_time (tv_z := ZH)) + (Fl4Spec.decDomainTime (Z := ZL)) := by + unfold Schedule_A.dec_domain_time Fl4Spec.decDomainTime + exact mrel_modify fun _ _ hs => { hs with + domainTime_eq := by simp [Structures_A.abstract_state.domain_time_update, hs.domainTime_eq, HolSub.subVal, HolOne.oneVal] } + +theorem domainScheduleConfigure_equiv (index : Nat) (domain : Domain) (duration : DomainDuration) : + MRel SR Eq + (Schedule_A.domain_schedule_configure index domain duration) + (Fl4Spec.domainScheduleConfigure index domain duration) := by + unfold Schedule_A.domain_schedule_configure Fl4Spec.domainScheduleConfigure + exact mrel_modify fun _ _ hs => { hs with + domainList_eq := by simp [Structures_A.abstract_state.domain_list_update, hs.domainList_eq, holListUpdate_eq] ; rfl } + +theorem domainSetStart_equiv (hop : OpaqueRel RestRel) (index : Nat) : + MRel SR Eq + (Schedule_A.domain_set_start index) (Fl4Spec.domainSetStart index) := by + unfold Schedule_A.domain_set_start Fl4Spec.domainSetStart + refine mrel_kbind (mrel_modify fun _ _ hs => { hs with domainStartIndex_eq := rfl }) ?_ + refine mrel_kbind (mrel_modify fun _ _ hs => { hs with domainTime_eq := rfl }) ?_ + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ hs => by simp only [holComp, holSize_list, hs.domainList_eq]; rfl) fun nH nL hn => ?_ + subst hn + refine mrel_kbind (mrel_modify fun _ _ hs => { hs with domainIndex_eq := rfl }) ?_ + exact rescheduleRequired_equiv hop + +/-- Side condition for `next_domain`: the incremented and start indices are within `domain_list`. -/ +def DomainListSafe (sH : Structures_A.state ZH) : Prop := + sH.domain_index + 1 < sH.domain_list.length ∧ sH.domain_start_index < sH.domain_list.length + +private theorem the_getElem?_eq_holNth {α : Type} [Nonempty α] [Inhabited α] (xs : List α) (i : Nat) (h : i < xs.length) : + the xs[i]? = holNth xs i := by + simp [the, holNth, holTheOpt, List.getElem?_eq_getElem h] + +theorem nextDomain_equiv {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hdom : DomainListSafe sH) : + MRelStep SR Eq + (Schedule_A.next_domain sH) (Fl4Spec.nextDomain sL) := by + unfold Schedule_A.next_domain Fl4Spec.nextDomain + have hstep1 : MRelStep SR Eq + (holModify (fun s => + holLet (HolAdd.addVal s.domain_index (HolOne.oneVal (α := Nat))) fun index_inc => + holLet (holIf (holEq (holNth s.domain_list index_inc) Schedule_A.domain_end_marker) + s.domain_start_index index_inc) fun index' => + holLet (holNth s.domain_list index') fun dom_entry => + Structures_A.abstract_state.reprogram_timer_update (fun _ => true) + (Structures_A.abstract_state.domain_time_update (fun _ => holUcast (w := 64) dom_entry.2) + (Structures_A.abstract_state.cur_domain_update (fun _ => dom_entry.1) + (Structures_A.abstract_state.domain_index_update (fun _ => index') s)))) sH) + (NonDet.modify (fun s : State ZL => + let indexInc := s.domainIndex + 1 + let index' := if the s.domainList[indexInc]? = domainEndMarker then s.domainStartIndex else indexInc + let domEntry := the s.domainList[index']? + { s with domainIndex := index', curDomain := domEntry.1, domainTime := ucast 64 domEntry.2, + reprogramTimer := true }) sL) := by + have hinc : sH.domain_index + 1 < sH.domain_list.length := hdom.1 + have hst : sH.domain_start_index < sH.domain_list.length := hdom.2 + have hnth1 : the sL.domainList[sL.domainIndex + 1]? = holNth sH.domain_list (sH.domain_index + 1) := by + rw [hs.domainList_eq, hs.domainIndex_eq] + exact the_getElem?_eq_holNth sH.domain_list (sH.domain_index + 1) hinc + have hidxEq : (if the sL.domainList[sL.domainIndex + 1]? = domainEndMarker + then sL.domainStartIndex else sL.domainIndex + 1) = + holIf (holEq (holNth sH.domain_list (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) + Schedule_A.domain_end_marker) sH.domain_start_index (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat))) := by + rw [hnth1, hs.domainStartIndex_eq, hs.domainIndex_eq, domainEndMarker_eq] + change (if holNth sH.domain_list (sH.domain_index + 1) = Schedule_A.domain_end_marker + then sH.domain_start_index else sH.domain_index + 1) = _ + by_cases hc : holNth sH.domain_list (sH.domain_index + 1) = Schedule_A.domain_end_marker + · have hT : holEq (holNth sH.domain_list (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) + Schedule_A.domain_end_marker = true := by simpa [holEq_eq_true, HolAdd.addVal, HolOne.oneVal] using hc + rw [ite_eq_left_iff.mpr (fun h => absurd hc h), hT, holIf_true] + · have hF : holEq (holNth sH.domain_list (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) + Schedule_A.domain_end_marker = false := by + rw [Bool.eq_false_iff]; simpa [holEq_eq_true, HolAdd.addVal, HolOne.oneVal] using hc + rw [ite_eq_right_iff.mpr (fun h => absurd h hc), hF, holIf_false]; rfl + have hidxLt : (holIf (holEq (holNth sH.domain_list (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) + Schedule_A.domain_end_marker) sH.domain_start_index (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) < + sH.domain_list.length := by + by_cases hc : holNth sH.domain_list (sH.domain_index + 1) = Schedule_A.domain_end_marker + · have hT : holEq (holNth sH.domain_list (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) + Schedule_A.domain_end_marker = true := by simpa [holEq_eq_true, HolAdd.addVal, HolOne.oneVal] using hc + rw [hT, holIf_true]; exact hst + · have hF : holEq (holNth sH.domain_list (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) + Schedule_A.domain_end_marker = false := by + rw [Bool.eq_false_iff]; simpa [holEq_eq_true, HolAdd.addVal, HolOne.oneVal] using hc + rw [hF, holIf_false]; exact hinc + have hentry : the sL.domainList[if the sL.domainList[sL.domainIndex + 1]? = domainEndMarker + then sL.domainStartIndex else sL.domainIndex + 1]? = + holNth sH.domain_list (holIf (holEq (holNth sH.domain_list (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) + Schedule_A.domain_end_marker) sH.domain_start_index (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat)))) := by + rw [hidxEq, hs.domainList_eq] + exact the_getElem?_eq_holNth sH.domain_list _ hidxLt + have hrel_step : SR + (holLet (HolAdd.addVal sH.domain_index (HolOne.oneVal (α := Nat))) fun index_inc => + holLet (holIf (holEq (holNth sH.domain_list index_inc) Schedule_A.domain_end_marker) + sH.domain_start_index index_inc) fun index' => + holLet (holNth sH.domain_list index') fun dom_entry => + Structures_A.abstract_state.reprogram_timer_update (fun _ => true) + (Structures_A.abstract_state.domain_time_update (fun _ => holUcast (w := 64) dom_entry.2) + (Structures_A.abstract_state.cur_domain_update (fun _ => dom_entry.1) + (Structures_A.abstract_state.domain_index_update (fun _ => index') sH)))) + (let indexInc := sL.domainIndex + 1 + let index' := if the sL.domainList[indexInc]? = domainEndMarker then sL.domainStartIndex else indexInc + let domEntry := the sL.domainList[index']? + { sL with + domainIndex := index' + curDomain := domEntry.1 + domainTime := ucast 64 domEntry.2 + reprogramTimer := true }) := + { hs with + domainIndex_eq := hidxEq + curDomain_eq := congrArg Prod.fst hentry + domainTime_eq := by dsimp only [holLet]; rw [hentry]; rfl + reprogramTimer_eq := rfl } + refine ⟨by simp [holModify, NonDet.modify], ?_, ?_⟩ + · intro aH sH' hm + simp only [holModify, Set.mem_singleton_iff, Prod.mk.injEq] at hm + obtain ⟨_, hs'⟩ := hm; cases aH; subst hs' + exact ⟨(), _, by simp [NonDet.modify], rfl, hrel_step⟩ + · intro aL sL' hm + simp only [NonDet.modify, Set.mem_singleton_iff, Prod.mk.injEq] at hm + obtain ⟨_, hs'⟩ := hm; cases aL; subst hs' + exact ⟨(), _, by simp [holModify], rfl, hrel_step⟩ + refine mrelStep_bind_mem hstep1 fun _ _ _ s1H s1L hs1 _ => ?_ + refine doExtendedOp_equiv (RestRel := RestRel) ?_ s1H s1L hs1 + exact mrel_modify fun sH' sL' h => { h with + exst_rel := by + have hex := h.exst_rel + simp only [FunRel] at hex ⊢ + have hcdt : sL'.exst.cdtListInternal = sH'.more.exst.cdt_list_internal := by + simpa [embDetExt] using congrArg DetExt.cdtListInternal hex + simp [embDetExt, Deterministic_A.trans_state, + Deterministic_A.det_ext.work_units_completed_internal_update, + Structures_A.abstract_state.extend, Structures_A.abstract_state.truncate, + Structures_A.state.fields, Structures_A.state.exst, + Fl4Spec.transState, Fl4Spec.workUnitsCompletedUpdate, HolZero.zeroVal, hcdt] } + +private theorem timerPrecision_eq (hop : OpaqueRel RestRel) : + Fl4Spec.timerPrecision = Arch_Structs_B.timerPrecision := usToTicks_eq hop 1 + +theorem setNextInterrupt_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) : + MRel SR Eq + (Schedule_A.set_next_interrupt (tv_z := ZH)) + (Fl4Spec.setNextInterrupt (Z := ZL)) := by + unfold Schedule_A.set_next_interrupt Fl4Spec.setNextInterrupt + refine mrel_bind (mrel_gets fun _ _ hs => hs.curTime_eq.symm) fun tmH tmL htm => ?_; subst htm + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun thH thL hth => ?_; subst hth + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) thH) fun scH scL hsc => ?_; subst hsc + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases scH <;> simp [OptRel])) fun scpH scpL hscp => ?_; subst hscp + refine mrel_bind (getRefillHead_equiv scpH) fun rH rL hr => ?_; subst hr + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun ni1H ni1L hni1 => ?_; subst hni1 + have htail : ∀ ni2 : BitVec 64, + MRel SR Eq + (holBind (holGets Structures_A.abstract_state_ext.release_queue) fun rq => + holBind (holIf (holEq rq []) (holReturn ni2) + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context (holHd rq)) fun rqsc_opt => + holBind (holAssertOpt rqsc_opt) fun rqsc_ptr => + holBind (KHeap_A.get_refill_head rqsc_ptr) fun rlq_head_refill => + holFunApp holReturn (holMin rlq_head_refill.r_time ni2))) fun ni3 => + holFunApp Structures_A.do_machine_op (MachineOps.setDeadline (HolSub.subVal ni3 Arch_Structs_B.timerPrecision))) + (do + let rq ← NonDet.gets fun s : State ZL => s.releaseQueue + let ni3 ← if rq = [] then pure ni2 else do + let rqscOpt ← getTcbObjRef Tcb.tcbSchedContext (the rq.head?) + let rqscPtr ← NonDet.assertOpt rqscOpt + let rlqHeadRefill ← getRefillHead rqscPtr + pure (min rlqHeadRefill.rTime ni2) + doMachineOp <| setDeadline (ni3 - timerPrecision)) := by + intro ni2 + refine mrel_bind (mrel_gets (Rs := SR) (Ra := Eq) fun _ _ hs => hs.releaseQueue_eq.symm) fun rqH rqL hrq => ?_; subst hrq + cases rqH with + | nil => + simp only [holEq, decide_true, ↓reduceIte, holIf_true] + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun ni3H ni3L hni3 => ?_; subst hni3 + rw [timerPrecision_eq hop] + exact mrel_doMachineOp (setDeadline_equiv hop _) + | cons hd tl => + simp only [holEq, List.cons_ne_nil, decide_false, ↓reduceIte, holIf_false, holHd, List.head?_cons, the, + KHeap.holBind_assoc] + refine mrel_bind (getTcbObjRef_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) (fun _ => rfl) hd) fun rscH rscL hrsc => ?_; subst hrsc + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases rscH <;> simp [OptRel])) fun rpH rpL hrp => ?_; subst hrp + refine mrel_bind (getRefillHead_equiv rpH) fun rrH rrL hrr => ?_; subst hrr + have hmin : min rrH.r_time ni2 = holMin rrH.r_time ni2 := by + by_cases hle : rrH.r_time ≤ ni2 <;> simp [holMin, HolOrd.leVal, Min.min, hle] + refine mrel_bind (mrel_return (Ra := Eq) hmin.symm) fun ni3H ni3L hni3 => ?_; subst hni3 + rw [timerPrecision_eq hop] + exact mrel_doMachineOp (setDeadline_equiv hop _) + by_cases hnd : 1 < Fl4Spec.numDomains + · have hndH : holLt (HolOne.oneVal (α := Nat)) Kernel_Config.numDomains = true := by + simp only [holLt_eq_true, HolOrd.ltVal, HolOne.oneVal, ← hc.numDomains_eq]; exact hnd + simp only [hndH, holIf_true, hnd, ↓reduceIte, KHeap.holBind_assoc] + refine mrel_bind (mrel_gets (Rs := SR) (Ra := Eq) fun _ _ hs => hs.domainTime_eq.symm) fun dtH dtL hdt => ?_; subst hdt + have hmin : min ni1H (tmH + dtH) = holMin ni1H (HolAdd.addVal tmH dtH) := by + by_cases hle : ni1H ≤ tmH + dtH <;> simp [holMin, HolOrd.leVal, HolAdd.addVal, Min.min, hle] + refine mrel_bind (mrel_return (Ra := Eq) hmin.symm) fun ni2H ni2L hni2 => ?_; subst hni2 + exact htail ni2H + · have hndH : holLt (HolOne.oneVal (α := Nat)) Kernel_Config.numDomains = false := by + simp only [holLt, HolOrd.ltVal, HolOne.oneVal, ← hc.numDomains_eq, decide_eq_false_iff_not]; exact hnd + simp only [hndH, holIf_false, hnd, ↓reduceIte] + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun ni2H ni2L hni2 => ?_; subst hni2 + exact htail ni2H + +/-- Side condition for `switch_sched_context`: if `commit_time` is invoked (`reprogram = true`), +the state satisfies `CommitTimeSafe`. -/ +def SwitchScSafe (sH : Structures_A.state ZH) : Prop := + ∀ csc s1 ct s2 scOpt s3 scp s4 sc' s5 u s6 rep s7, + (csc, s1) ∈ (holGets (fun s : Structures_A.state ZH => s.cur_sc) sH).1 → + (ct, s2) ∈ (holGets (fun s : Structures_A.state ZH => s.cur_thread) s1).1 → + (scOpt, s3) ∈ (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context ct s2).1 → + (scp, s4) ∈ (holAssertOpt scOpt s3).1 → + (sc', s5) ∈ (KHeap_A.get_sched_context csc s4).1 → + (u, s6) ∈ (holWhen (holNot (holEq scp csc)) + (holBind (holModify (Structures_A.abstract_state.reprogram_timer_update (fun _ => true))) + (holKBind (Sporadic_A.if_cond_refill_unblock_check (some scp) none none))) s5).1 → + (rep, s7) ∈ (holGets (fun s : Structures_A.state ZH => s.reprogram_timer) s6).1 → + rep = true → CommitTimeSafe s7 + +theorem switchSchedContext_equiv (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : SwitchScSafe sH) : + MRelStep SR Eq + (Schedule_A.switch_sched_context sH) (Fl4Spec.switchSchedContext sL) := by + unfold Schedule_A.switch_sched_context Fl4Spec.switchSchedContext + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun cscH cscL hcsc s1H s1L hs1 hm1 => ?_; subst hcsc + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curThread_eq.symm) s1H s1L hs1) + fun ctH ctL hct s2H s2L hs2 hm2 => ?_; subst hct + refine mrelStep_bind_mem (getTcbObjRef_equiv (fun _ => rfl) ctH s2H s2L hs2) + fun scOptH scOptL hscOpt s3H s3L hs3 hm3 => ?_; subst hscOpt + refine mrelStep_bind_mem (mrel_assertOpt (Ra := Eq) (by cases scOptH <;> simp [OptRel]) s3H s3L hs3) + fun scpH scpL hscp s4H s4L hs4 hm4 => ?_; subst hscp + refine mrelStep_bind_mem (getSchedContext_equiv cscH s4H s4L hs4) + fun sc'H sc'L hsc' s5H s5L hs5 hm5 => ?_; subst hsc' + refine mrelStep_bind_mem + (mrel_when (by simp [holNot_eq_true, holEq_eq_true]) (fun _ => + mrel_kbind (mrel_modify fun _ _ h => { h with reprogramTimer_eq := rfl }) + (ifConstantBandwidthRefillUnblockCheck_equiv (some scpH))) s5H s5L hs5) + fun uH uL _ s6H s6L hs6 hm6 => ?_ + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.reprogramTimer_eq.symm) s6H s6L hs6) + fun repH repL hrep s7H s7L hs7 hm7 => ?_; subst hrep + have hctStep : MRelStep SR Eq + (holWhen repH SchedContext_A.commit_time s7H) + (NonDet.when (repH = true) Fl4Spec.commitTime s7L) := by + cases repH with + | false => + simp only [holWhen, NonDet.when, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl s7H s7L hs7 + | true => + simp only [holWhen, NonDet.when, ↓reduceIte] + exact commitTime_equiv hop hs7 (hsafe cscH s1H ctH s2H scOptH s3H scpH s4H sc'H s5H uH s6H true s7H + hm1 hm2 hm3 hm4 hm5 hm6 hm7 rfl) + refine mrelStep_bind_mem hctStep fun _ _ _ s8H s8L hs8 _ => ?_ + exact mrel_modify (fun _ _ h => { h with curSc_eq := rfl }) s8H s8L hs8 + +theorem scAndTimer_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : SwitchScSafe sH) : + MRelStep SR Eq + (Schedule_A.sc_and_timer sH) (Fl4Spec.scAndTimer sL) := by + unfold Schedule_A.sc_and_timer Fl4Spec.scAndTimer + refine mrelStep_bind_mem (switchSchedContext_equiv hop hs hsafe) fun _ _ _ s1H s1L hs1 _ => ?_ + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.reprogramTimer_eq.symm) s1H s1L hs1) + fun repH repL hrep s2H s2L hs2 _ => ?_; subst hrep + refine mrel_when (Rs := SR) Iff.rfl (fun _ => ?_) s2H s2L hs2 + refine mrel_kbind (setNextInterrupt_equiv hc hop) ?_ + exact mrel_modify fun _ _ h => { h with reprogramTimer_eq := rfl } + +/-! ## Release queue and `awaken` -/ + +theorem readTcbRefillReady_equiv (t : ObjRef) : + LookupRel SR Eq + (Schedule_A.read_tcb_refill_ready t) (Fl4Spec.readTcbRefillReady t) := by + unfold Schedule_A.read_tcb_refill_ready Fl4Spec.readTcbRefillReady + refine lookup_bind (readTcbObjRef_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + (fH := Structures_A.tcb_ext.tcb_sched_context) (fL := Tcb.tcbSchedContext) (fun _ => rfl) t) + fun oH oL ho => ?_; subst ho + refine lookup_bind (Ra := Eq) (fun _ _ _ => by cases oH <;> simp [holOAssertOpt, Lookup.oassertOpt, holOFail, holOReturn, Lookup.ofail, Lookup.oreturn, OptRel]) + fun pH pL hp => ?_; subst hp + refine lookup_bind (readScRefillReady_equiv pH) fun bH bL hb => ?_; subst hb + exact lookup_oreturn rfl + +theorem readReleaseQNonEmptyAndReady_equiv : + LookupRel SR Eq + (Schedule_A.read_release_q_non_empty_and_ready (tv_z := ZH)) + (Fl4Spec.readReleaseQNonEmptyAndReady (Z := ZL)) := by + unfold Schedule_A.read_release_q_non_empty_and_ready Fl4Spec.readReleaseQNonEmptyAndReady + refine lookup_bind (Rs := SR) (Ra := Eq) + (fun _ _ hs => by simp [holAsks, Lookup.asks, hs.releaseQueue_eq, OptRel]) + fun rqH rqL hrq => ?_; subst hrq + cases rqH with + | nil => + intro sH sL _ + simp [holEq, holIf_true, holOReturn, Lookup.oreturn, OptRel] + | cons hd tl => + intro sH sL hs + simp only [holEq, List.cons_ne_nil, ↓reduceIte, holHd, List.head?_cons, the] + exact readTcbRefillReady_equiv hd sH sL hs + +theorem tcbReleaseDequeue_equiv (hop : OpaqueRel RestRel) : + MRel SR Eq + (Schedule_A.tcb_release_dequeue (tv_z := ZH)) + (Fl4Spec.tcbReleaseDequeue (Z := ZL)) := by + intro sH sL hs + unfold Schedule_A.tcb_release_dequeue Fl4Spec.tcbReleaseDequeue + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.releaseQueue_eq.symm) sH sL hs) + fun rqH rqL hrq s1H s1L hs1 _ => ?_; subst hrq + cases rqH with + | nil => + refine mrelStep_bind_mem (mrel_assert (by simp [holNot_eq_true, holEq_eq_true]) s1H s1L hs1) + fun _ _ _ s2H s2L hs2 hm2 => ?_ + simp [holAssert, holNot, holEq] at hm2 + | cons hd tl => + refine mrelStep_bind_mem (mrel_assert (by simp [holNot_eq_true, holEq_eq_true]) s1H s1L hs1) + fun _ _ _ s2H s2L hs2 _ => ?_ + simp only [holHd, List.head?_cons, the] + exact (mrel_kbind (tcbReleaseRemove_equiv hd) (possibleSwitchTo_equiv hop hd)) s2H s2L hs2 + +/-- Side condition for `awaken`: every thread in `release_queue` has a valid TCB + SC with non-empty refills. -/ +def AwakenSafe (sH : Structures_A.state ZH) : Prop := + ∀ t ∈ sH.release_queue, Schedule_A.read_tcb_refill_ready t sH ≠ none + +private theorem tcbReleaseDequeue_preserves_awakenSafe + {sH sH' : Structures_A.state ZH} + (hsafe : AwakenSafe sH) + (hmem : ((), sH') ∈ (Schedule_A.tcb_release_dequeue sH).1) : + AwakenSafe sH' := by + have hget_eq : ∀ {α : Type} {f : Structures_A.state ZH → Option α} {sx sy : Structures_A.state ZH} {a}, + (a, sy) ∈ (holGetsThe f sx).1 → sy = sx := by + intro α f sx sy a h + unfold holGetsThe holAssertOpt at h + cases hf : f sx <;> simp [hf, holFail, holReturn, Set.mem_singleton_iff] at h + exact h.2 + have hthread_get : ∀ {α : Type} [Nonempty α] {f : Structures_A.tcb → α} {t : ObjRef} + {sx sy : Structures_A.state ZH} {a}, + (a, sy) ∈ (KHeap_A.thread_get f t sx).1 → sy = sx := by + intro α _ f t sx sy a h + unfold KHeap_A.thread_get at h + rcases h with ⟨⟨_, s1⟩, h1, h2⟩ + have := hget_eq h1; subst this + simp only [holReturn, holFunApp, Set.mem_singleton_iff, Prod.mk.injEq] at h2 + exact h2.2 + have htsa : ∀ {sx sy : Structures_A.state ZH} {f t u}, + (u, sy) ∈ (KHeap_A.tcb_sched_action f t sx).1 → + sy.kheap = sx.kheap ∧ sy.cur_time = sx.cur_time ∧ sy.release_queue = sx.release_queue := by + intro sx sy f t u hm' + unfold KHeap_A.tcb_sched_action KHeap_A.get_tcb_queue KHeap_A.set_tcb_queue at hm' + rcases hm' with ⟨⟨_, s1a⟩, h1a, ⟨_, s2a⟩, h2a, ⟨_, s3a⟩, h3a, ⟨_, s4a⟩, h4a, h5a⟩ + have := hthread_get h1a; subst this + have := hthread_get h2a; subst this + rcases h3a with ⟨⟨_, s30⟩, h30, h31⟩ + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at h30 + have := h30.2; subst this + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at h31 + have := h31.2; subst this + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at h4a + have := h4a.2; subst this + simp only [holModify, Set.mem_singleton_iff, Prod.mk.injEq] at h5a + have := h5a.2; subst this + exact ⟨rfl, rfl, rfl⟩ + have hssa : ∀ {sx sy : Structures_A.state ZH} {act' u}, + (u, sy) ∈ (KHeap_A.set_scheduler_action act' sx).1 → + sy.kheap = sx.kheap ∧ sy.cur_time = sx.cur_time ∧ sy.release_queue = sx.release_queue := by + intro sx sy act' u hm' + unfold KHeap_A.set_scheduler_action at hm' + simp only [holModify, Set.mem_singleton_iff, Prod.mk.injEq] at hm' + have := hm'.2; subst this + exact ⟨rfl, rfl, rfl⟩ + have hrr_pres : ∀ {sx sy : Structures_A.state ZH} {u}, + (u, sy) ∈ (KHeap_A.reschedule_required sx).1 → + sy.kheap = sx.kheap ∧ sy.cur_time = sx.cur_time ∧ sy.release_queue = sx.release_queue := by + intro sx sy u hm' + unfold KHeap_A.reschedule_required at hm' + rcases hm' with ⟨⟨act, s1⟩, h1, ⟨_, s2⟩, h2, h3⟩ + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at h1 + have hs1 : s1 = sx := h1.2; subst s1 + have h2eq : s2.kheap = sx.kheap ∧ s2.cur_time = sx.cur_time ∧ s2.release_queue = sx.release_queue := by + cases act with + | resume_cur_thread => + simp only [Structures_A.case_scheduler_action, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at h2 + have := h2.2; subst s2; exact ⟨rfl, rfl, rfl⟩ + | choose_new_thread => + simp only [Structures_A.case_scheduler_action, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at h2 + have := h2.2; subst s2; exact ⟨rfl, rfl, rfl⟩ + | switch_thread t => + simp only [Structures_A.case_scheduler_action] at h2 + rcases h2 with ⟨⟨sched, sa⟩, ha, hb⟩ + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at ha + have hsa : sa = sx := ha.2; subst sa + cases sched with + | false => + simp only [holWhen, holFunApp, Bool.false_eq_true, ↓reduceIte, holReturn, + Set.mem_singleton_iff, Prod.mk.injEq] at hb + have := hb.2; subst s2; exact ⟨rfl, rfl, rfl⟩ + | true => + simp only [holWhen, holFunApp, ↓reduceIte] at hb + rcases hb with ⟨⟨scOpt, sb⟩, hsb, ⟨scp, sc⟩, hsc, ⟨_, sd⟩, hsd, ⟨_, se⟩, hse, ⟨_, sf⟩, hsf, hsg⟩ + have := hthread_get hsb; subst sb + unfold holAssertOpt at hsc + cases scOpt with + | none => simp [holFail] at hsc + | some _ => + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hsc + have := hsc.2; subst sc + have := hget_eq hsd; subst sd + have := hget_eq hse; subst se + simp only [holAssert, Set.mem_ofPred_eq, Prod.mk.injEq] at hsf + have := hsf.2.2; subst sf + exact htsa hsg + have h3eq := hssa h3 + exact ⟨h3eq.1.trans h2eq.1, h3eq.2.1.trans h2eq.2.1, h3eq.2.2.trans h2eq.2.2⟩ + have hk_ct_rq : sH'.kheap = sH.kheap ∧ sH'.cur_time = sH.cur_time ∧ + ∀ t ∈ sH'.release_queue, t ∈ sH.release_queue := by + unfold Schedule_A.tcb_release_dequeue at hmem + rcases hmem with ⟨⟨rq, s1⟩, h1, ⟨_, s2⟩, h2, ⟨_, s3⟩, hrem, hps⟩ + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at h1 + have hs1 : s1 = sH := h1.2; subst s1 + simp only [holAssert, Set.mem_ofPred_eq, Prod.mk.injEq] at h2 + have hs2 : s2 = sH := h2.2.2; subst s2 + have hrem_eq : s3.kheap = sH.kheap ∧ s3.cur_time = sH.cur_time ∧ + ∀ t ∈ s3.release_queue, t ∈ sH.release_queue := by + unfold KHeap_A.tcb_release_remove at hrem + rcases hrem with ⟨⟨qs, sa⟩, ha, ⟨_, sb⟩, hb, ⟨qsp, sc⟩, hc, hd⟩ + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at ha + obtain ⟨hqs, hsa⟩ := ha; subst sa + have hsb : sb.kheap = sH.kheap ∧ sb.cur_time = sH.cur_time ∧ sb.release_queue = sH.release_queue := by + unfold holFunApp holWhen at hb + split at hb + · simp only [holModify, Set.mem_singleton_iff, Prod.mk.injEq] at hb + have := hb.2; subst sb; exact ⟨rfl, rfl, rfl⟩ + · simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hb + have := hb.2; subst sb; exact ⟨rfl, rfl, rfl⟩ + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hc + obtain ⟨hqsp, hsc⟩ := hc; subst sc + simp only [holModify, Set.mem_singleton_iff, Prod.mk.injEq] at hd + have := hd.2; subst s3 + refine ⟨hsb.1, hsb.2.1, fun t ht => ?_⟩ + simp only [Structures_A.abstract_state.release_queue_update, hqsp, + KHeap_A.tcb_sched_dequeue, holListFilter, List.mem_filter] at ht + exact hqs ▸ ht.1 + have hps_eq : sH'.kheap = s3.kheap ∧ sH'.cur_time = s3.cur_time ∧ sH'.release_queue = s3.release_queue := by + unfold KHeap_A.possible_switch_to at hps + rcases hps with ⟨⟨scOpt, sa⟩, ha, ⟨inq, sb⟩, hb, hrest⟩ + have := hthread_get ha; subst sa + simp only [holGets, holFunApp, Set.mem_singleton_iff, Prod.mk.injEq] at hb + have := hb.2; subst sb + dsimp only at hrest + by_cases hwt : holConj (holNot (holEq scOpt none)) (holNot inq) = true + · simp only [holFunApp, holWhen, hwt, ↓reduceIte] at hrest + rcases hrest with ⟨⟨curDom, sc⟩, hc', ⟨tDom, sd⟩, hd, ⟨act, se⟩, he, hf⟩ + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hc' + have := hc'.2; subst sc + have := hthread_get hd; subst sd + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at he + have := he.2; subst se + by_cases hdom : holNot (holEq tDom curDom) = true + · simp only [hdom, holIf_true] at hf + exact htsa hf + · have hdomF : holNot (holEq tDom curDom) = false := Bool.eq_false_iff.mpr hdom + simp only [hdomF, holIf_false] at hf + by_cases hact : holNot (holEq act .resume_cur_thread) = true + · simp only [hact, holIf_true] at hf + rcases hf with ⟨⟨_, sx⟩, hx, hy⟩ + have hx' := hrr_pres hx + have hy' := htsa hy + exact ⟨hy'.1.trans hx'.1, hy'.2.1.trans hx'.2.1, hy'.2.2.trans hx'.2.2⟩ + · have hactF : holNot (holEq act .resume_cur_thread) = false := Bool.eq_false_iff.mpr hact + simp only [hactF, holIf_false] at hf + exact hssa hf + · have hwf : holConj (holNot (holEq scOpt none)) (holNot inq) = false := Bool.eq_false_iff.mpr hwt + simp only [holFunApp, holWhen, hwf, Bool.false_eq_true, ↓reduceIte, holReturn, + Set.mem_singleton_iff, Prod.mk.injEq] at hrest + have hsH' := hrest.2; rw [hsH']; exact ⟨rfl, rfl, rfl⟩ + exact ⟨hps_eq.1.trans hrem_eq.1, hps_eq.2.1.trans hrem_eq.2.1, fun t ht => hrem_eq.2.2 t (hps_eq.2.2 ▸ ht)⟩ + intro t ht + have ht0 := hk_ct_rq.2.2 t ht + have hrr := hsafe t ht0 + have heq : Schedule_A.read_tcb_refill_ready t sH' = Schedule_A.read_tcb_refill_ready t sH := by + have h1 : KHeap_A.read_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context t sH' = + KHeap_A.read_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context t sH := by + simp [KHeap_A.read_tcb_obj_ref, KHeap_A.thread_read, KHeap_A.get_tcb, KHeap_A.read_object, + holOLiftM, holOBind, holOReturn, holSwp, holCaseOption, hk_ct_rq.1] + have h2 : ∀ p, KHeap_A.read_sc_refill_ready p sH' = KHeap_A.read_sc_refill_ready p sH := fun p => by + unfold KHeap_A.read_sc_refill_ready KHeap_A.read_refill_head KHeap_A.read_sched_context KHeap_A.read_object + simp only [holOBind, holAsks, holOAssert, holFunApp, holSwp, hk_ct_rq.1, hk_ct_rq.2.1] + cases sH.kheap p with + | none => rfl + | some ko => + cases ko <;> try (simp [Structures_A.case_kernel_object, holOFail]) + rename_i sc n + simp only [holOReturn] + by_cases hne : sc.sc_refills = [] <;> simp [hne, holOFail, holOReturn] + unfold Schedule_A.read_tcb_refill_ready + simp only [holOBind, h1, holOAssertOpt] + cases KHeap_A.read_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context t sH with + | none => rfl + | some o => cases o with + | none => simp [holOFail] + | some p => simp only [holOReturn, h2 p] + rw [heq]; exact hrr + +theorem awaken_equiv (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : AwakenSafe sH) : + MRelStep SR Eq + (Schedule_A.awaken sH) (Fl4Spec.awaken sL) := by + unfold Schedule_A.awaken Fl4Spec.awaken + have h := mrel_whileLoop_guarded + (Rs := fun (sH : Structures_A.state ZH) (sL : State ZL) => SR sH sL ∧ AwakenSafe sH) + (Ra := Eq) + (CH := fun _ s => holTheOpt (Schedule_A.read_release_q_non_empty_and_ready s)) + (CL := fun _ s => the (Fl4Spec.readReleaseQNonEmptyAndReady s) = true) + (BH := fun _ => Schedule_A.tcb_release_dequeue) + (BL := fun _ => Fl4Spec.tcbReleaseDequeue) + (rH := ()) (rL := ()) + (by + intro _ _ _ s1H s1L ⟨hs1, hp⟩ + have hlr := readReleaseQNonEmptyAndReady_equiv s1H s1L hs1 + have hne : Schedule_A.read_release_q_non_empty_and_ready s1H ≠ none := by + unfold Schedule_A.read_release_q_non_empty_and_ready + simp only [holOBind, holAsks] + cases hq : s1H.release_queue with + | nil => simp [holEq, holIf_true, holOReturn] + | cons hd tl => + simp only [holEq, List.cons_ne_nil, holHd] + exact hp hd (by simp [hq]) + cases hH : Schedule_A.read_release_q_non_empty_and_ready s1H with + | none => exact absurd hH hne + | some bH => + cases hL : Fl4Spec.readReleaseQNonEmptyAndReady s1L with + | none => simp [hH, hL, OptRel] at hlr + | some bL => + simp only [hH, hL, OptRel] at hlr + subst hlr + simp [holTheOpt, the]) + (by + intro _ _ _ s1H s1L ⟨hs1, hp⟩ _ + obtain ⟨hf, h1, h2⟩ := tcbReleaseDequeue_equiv hop s1H s1L hs1 + refine ⟨hf, ?_, ?_⟩ + · intro aH s2H hm + obtain ⟨aL, s2L, hmL, ha, hs2⟩ := h1 aH s2H hm + exact ⟨aL, s2L, hmL, ha, hs2, tcbReleaseDequeue_preserves_awakenSafe hp hm⟩ + · intro aL s2L hmL + obtain ⟨aH, s2H, hm, ha, hs2⟩ := h2 aL s2L hmL + exact ⟨aH, s2H, hm, ha, hs2, tcbReleaseDequeue_preserves_awakenSafe hp hm⟩) + rfl sH sL ⟨hs, hsafe⟩ + exact ⟨h.1, + fun aH sH' hm => let ⟨aL, sL', hmL, ha, hs', _⟩ := h.2.1 aH sH' hm; ⟨aL, sL', hmL, ha, hs'⟩, + fun aL sL' hmL => let ⟨aH, sH', hm, ha, hs', _⟩ := h.2.2 aL sL' hmL; ⟨aH, sH', hm, ha, hs'⟩⟩ + +theorem chooseThread_equiv (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : ReferenceBaseCarriers sH) : + MRelStep SR Eq (Schedule_A.choose_thread sH) (Fl4Spec.chooseThread sL) := by + unfold Schedule_A.choose_thread Fl4Spec.chooseThread + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curDomain_eq.symm) sH sL hs) + fun dH dL hd s1H s1L hs1 hm1 => ?_ + subst hd + have heq1 := holGets_member_state hm1 + subst s1H + refine mrelStep_bind_mem (mrel_gets (Rs := SR) (Ra := Eq) (fun _ _ h => by rw [h.readyQueues_eq]) + sH s1L hs1) fun qH qL hq s2H s2L hs2 hm2 => ?_ + subst hq + have heq2 := holGets_member_state hm2 + subst s2H + have htest : holAll (fun p => holEq (qH p) []) = true ↔ ∀ p, qH p = [] := by + simp [holAll_eq_true] + by_cases he : ∀ p, qH p = [] + · rw [htest.mpr he, holIf_true, ite_eq_left he] + exact switchToIdleThread_equiv hs2 hb + · have hf : holAll (fun p => holEq (qH p) []) = false := + Bool.eq_false_iff.mpr (mt htest.mp he) + rw [hf, holIf_false, ite_eq_right he] + have hne : ∃ p, qH p ≠ [] := by + by_contra h; exact he (fun p => by by_contra h'; exact h ⟨p, h'⟩) + rw [maxNonEmptyQueue_eq qH hne] + have hqne := maxNonEmptyQueue_ne_nil qH hne + cases hm : Schedule_A.max_non_empty_queue qH with + | nil => exact absurd hm hqne + | cons hd _ => + simp only [holHd, List.head?_cons, the] + exact guardedSwitchTo_equiv hop hd hs2 hb + +theorem scheduleSwitchThreadFastfail_equiv (ct it : ObjRef) (ctPrio targetPrio : Priority) : + MRel SR Eq + (Schedule_A.schedule_switch_thread_fastfail ct it ctPrio targetPrio) + (Fl4Spec.scheduleSwitchThreadFastfail ct it ctPrio targetPrio) := by + unfold Schedule_A.schedule_switch_thread_fastfail Fl4Spec.scheduleSwitchThreadFastfail + refine mrel_return ?_ + apply Bool.eq_iff_iff.mpr + simp only [holImp_eq_true, holNot_eq_true, holLt_eq_true, HolOrd.ltVal, decide_eq_true_eq] + by_cases h : ct = it <;> simp [h] + +theorem checkDomainTime_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) : + MRel SR Eq + (Schedule_A.check_domain_time (tv_z := ZH)) (Fl4Spec.checkDomainTime (Z := ZL)) := by + unfold Schedule_A.check_domain_time Fl4Spec.checkDomainTime + refine mrel_bind (mrel_gets fun _ _ hs => (isCurDomainExpired_eq hc hs).symm) fun eH eL he => ?_ + subst he + exact mrel_when Iff.rfl fun _ => + mrel_kbind (mrel_modify fun _ _ hs => { hs with reprogramTimer_eq := rfl }) + (rescheduleRequired_equiv hop) + +/-- The preparation performed before the scheduler selects a new thread. -/ +def chooseNewThreadPreparation (s : Structures_A.state ZH) : HolNonDet (Structures_A.state ZH) Unit := + holWhen (holEq s.domain_time (HolZero.zeroVal (α := BitVec 64))) + (holBind Arch_A.arch_prepare_next_domain (holKBind Schedule_A.next_domain)) + +structure ChooseNewThreadSafe (s : Structures_A.state ZH) : Prop where + domain : s.domain_time = 0 → + ∀ s', ((), s') ∈ (Arch_A.arch_prepare_next_domain s).1 → DomainListSafe s' + base : ∀ s', ((), s') ∈ (chooseNewThreadPreparation s s).1 → ReferenceBaseCarriers s' + +theorem scheduleChooseNewThread_equiv (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : ChooseNewThreadSafe sH) : + MRelStep SR Eq + (Schedule_A.schedule_choose_new_thread sH) (Fl4Spec.scheduleChooseNewThread sL) := by + unfold Schedule_A.schedule_choose_new_thread Fl4Spec.scheduleChooseNewThread + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.domainTime_eq.symm) sH sL hs) + fun dtH dtL hdt s1H s1L hs1 hm1 => ?_; subst hdt + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + obtain ⟨hdt0, hs1eq⟩ := hm1 + subst hdt0; rw [hs1eq] at hs1 ⊢ + have hstep : MRelStep SR Eq + (holWhen (holEq sH.domain_time (HolZero.zeroVal (α := BitVec 64))) + (holBind Arch_A.arch_prepare_next_domain (holKBind Schedule_A.next_domain)) sH) + (NonDet.when (sH.domain_time = 0) (do Fl4Spec.archPrepareNextDomain; Fl4Spec.nextDomain) s1L) := by + by_cases h0 : sH.domain_time = 0 + · simp only [h0, holEq, HolZero.zeroVal, ↓reduceIte, holWhen, NonDet.when] + refine mrelStep_bind_mem (archPrepareNextDomain_equiv hop sH s1L hs1) + fun _ _ _ s2H s2L hs2 hm2 => ?_ + exact nextDomain_equiv hs2 (hsafe.domain h0 s2H hm2) + · have h0F : holEq sH.domain_time (HolZero.zeroVal (α := BitVec 64)) = false := by + simp only [holEq, HolZero.zeroVal, decide_eq_false_iff_not]; exact h0 + simp only [h0, h0F, holWhen, NonDet.when, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl sH s1L hs1 + refine mrelStep_bind_mem hstep fun u _ _ s2H s2L hs2 hm2 => ?_ + cases u + refine mrelStep_bind_mem (chooseThread_equiv hop hs2 (hsafe.base s2H hm2)) + fun _ _ _ s3H s3L hs3 _ => ?_ + exact setSchedulerAction_equiv .resume_cur_thread s3H s3L hs3 + +/-- Conditions for the reached scheduler paths. A root switch requires base carriers, +and the domain and refill guards apply at their respective continuations. -/ +def ScheduleSafe (sH : Structures_A.state ZH) : Prop := + AwakenSafe sH ∧ + (∀ s1, ((), s1) ∈ (Schedule_A.awaken sH).1 → + ∀ s2, ((), s2) ∈ (Schedule_A.check_domain_time s1).1 → + (s2.scheduler_action = .choose_new_thread → + ∀ s', ((), s') ∈ (holWhen (KHeap_A.schedulable s2.cur_thread s2) + (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue s2.cur_thread) s2).1 → + ChooseNewThreadSafe s') ∧ + (∀ cand, s2.scheduler_action = .switch_thread cand → + ∀ sa, ((), sa) ∈ (holWhen (KHeap_A.schedulable s2.cur_thread s2) + (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue s2.cur_thread) s2).1 → + ∀ it sb tp sc cp sd ff se cd sf hi sg, + (it, sb) ∈ (holGets (fun s : Structures_A.state ZH => s.idle_thread) sa).1 → + (tp, sc) ∈ (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority cand sb).1 → + (cp, sd) ∈ (holIf (holNot (holEq s2.cur_thread it)) + (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority s2.cur_thread) + (holReturn (HolZero.zeroVal (α := BitVec 8))) sc).1 → + (ff, se) ∈ (Schedule_A.schedule_switch_thread_fastfail s2.cur_thread it cp tp sd).1 → + (cd, sf) ∈ (holGets (fun s : Structures_A.state ZH => s.cur_domain) se).1 → + (hi, sg) ∈ (holGets (Schedule_A.is_highest_prio cd tp) sf).1 → + (holConj ff (holNot hi) = true → + ∀ sh, ((), sh) ∈ (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue cand sg).1 → + ∀ si, ((), si) ∈ (KHeap_A.set_scheduler_action .choose_new_thread sh).1 → + ChooseNewThreadSafe si) ∧ + (holConj ff (holNot hi) = false → + holConj (KHeap_A.schedulable s2.cur_thread s2) (holEq cp tp) = true → + ∀ sh, ((), sh) ∈ (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_append cand sg).1 → + ∀ si, ((), si) ∈ (KHeap_A.set_scheduler_action .choose_new_thread sh).1 → + ChooseNewThreadSafe si) ∧ + (holConj ff (holNot hi) = false → + holConj (KHeap_A.schedulable s2.cur_thread s2) (holEq cp tp) = false → + ReferenceBaseCarriers sg)) ∧ + ∀ s3, + (s2.scheduler_action = .resume_cur_thread ∧ s3 = s2 ∨ + s2.scheduler_action = .choose_new_thread ∧ + ((), s3) ∈ (holBind (holWhen (KHeap_A.schedulable s2.cur_thread s2) + (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue s2.cur_thread)) + (holKBind Schedule_A.schedule_choose_new_thread) s2).1 ∨ + ∃ cand, s2.scheduler_action = .switch_thread cand ∧ + ((), s3) ∈ (holBind (holWhen (KHeap_A.schedulable s2.cur_thread s2) + (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue s2.cur_thread)) (holKBind + (holBind (holGets fun s => s.idle_thread) fun it => + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority cand) fun target_prio => + holBind (holIf (holNot (holEq s2.cur_thread it)) + (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority s2.cur_thread) + (holReturn (HolZero.zeroVal (α := BitVec 8)))) fun ct_prio => + holBind (Schedule_A.schedule_switch_thread_fastfail s2.cur_thread it ct_prio target_prio) fun fastfail => + holBind (holGets fun s => s.cur_domain) fun cur_dom => + holBind (holGets (Schedule_A.is_highest_prio cur_dom target_prio)) fun highest => + holIf (holConj fastfail (holNot highest)) + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue cand) (holKBind + (holBind (KHeap_A.set_scheduler_action .choose_new_thread) (holKBind Schedule_A.schedule_choose_new_thread)))) + (holIf (holConj (KHeap_A.schedulable s2.cur_thread s2) (holEq ct_prio target_prio)) + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_append cand) (holKBind + (holBind (KHeap_A.set_scheduler_action .choose_new_thread) (holKBind Schedule_A.schedule_choose_new_thread)))) + (holBind (Schedule_A.guarded_switch_to cand) (holKBind (KHeap_A.set_scheduler_action .resume_cur_thread)))))) s2).1) → + SwitchScSafe s3) + +theorem schedule_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : ScheduleSafe sH) : + MRelStep SR Eq + (Schedule_A.schedule sH) (Fl4Spec.schedule sL) := by + unfold Schedule_A.schedule Fl4Spec.schedule + refine mrelStep_bind_mem (awaken_equiv hop hs hsafe.1) fun _ _ _ s1H s1L hs1 hm1 => ?_ + refine mrelStep_bind_mem (checkDomainTime_equiv hc hop s1H s1L hs1) fun _ _ _ s2H s2L hs2 hm2 => ?_ + have ⟨hdomChoose, hdomSwitch, hswAll⟩ := hsafe.2 s1H hm1 s2H hm2 + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curThread_eq.symm) s2H s2L hs2) + fun ctH ctL hct s2aH s2aL hs2a hm2a => ?_; subst hct + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm2a + obtain ⟨hct0, hs2aeq⟩ := hm2a; subst hct0; rw [hs2aeq] at hs2a ⊢ + refine mrelStep_bind_mem (mrel_gets (Rs := SR) (Ra := Eq) (fun _ _ h => (schedulable_eq h s2H.cur_thread).symm) s2H s2aL hs2a) + fun schH schL hsch s2bH s2bL hs2b hm2b => ?_; subst hsch + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm2b + obtain ⟨hsch0, hs2beq⟩ := hm2b; subst hsch0; rw [hs2beq] at hs2b ⊢ + refine mrelStep_bind_mem (mrel_gets (Ra := FunRel embSchedulerAction) (fun _ _ h => h.schedulerAction_eq) s2H s2bL hs2b) + fun actH actL hact s2cH s2cL hs2c hm2c => ?_; subst hact + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm2c + obtain ⟨hact0, hs2ceq⟩ := hm2c; subst hact0; rw [hs2ceq] at hs2c ⊢ + cases hact_eq : s2H.scheduler_action with + | resume_cur_thread => + simp only [Structures_A.case_scheduler_action, embSchedulerAction, KHeap.holBind_return_left] + exact scAndTimer_equiv hc hop hs2c (hswAll s2H (Or.inl ⟨hact_eq, rfl⟩)) + | choose_new_thread => + simp only [Structures_A.case_scheduler_action, embSchedulerAction, KHeap.holBind_assoc] + refine mrelStep_bind_mem + (mrel_when Iff.rfl (fun _ => tcbSchedAction_equiv tcbSchedEnqueue_eq s2H.cur_thread) s2H s2cL hs2c) + fun u' _ _ s'H s'L hs' hm' => ?_ + cases u' + refine mrelStep_bind_mem (scheduleChooseNewThread_equiv hop hs' (hdomChoose hact_eq s'H hm')) + fun _ _ _ s3H s3L hs3 hm3 => ?_ + exact scAndTimer_equiv hc hop hs3 (hswAll s3H (Or.inr (Or.inl ⟨hact_eq, ⟨((), s'H), hm', hm3⟩⟩))) + | switch_thread cand => + simp only [Structures_A.case_scheduler_action, embSchedulerAction] + have hbranch : MRelStep SR Eq + (holBind (holWhen (KHeap_A.schedulable s2H.cur_thread s2H) + (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue s2H.cur_thread)) (holKBind + (holBind (holGets fun s => s.idle_thread) fun it => + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority cand) fun target_prio => + holBind (holIf (holNot (holEq s2H.cur_thread it)) + (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority s2H.cur_thread) + (holReturn (HolZero.zeroVal (α := BitVec 8)))) fun ct_prio => + holBind (Schedule_A.schedule_switch_thread_fastfail s2H.cur_thread it ct_prio target_prio) fun fastfail => + holBind (holGets fun s => s.cur_domain) fun cur_dom => + holBind (holGets (Schedule_A.is_highest_prio cur_dom target_prio)) fun highest => + holIf (holConj fastfail (holNot highest)) + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue cand) (holKBind + (holBind (KHeap_A.set_scheduler_action .choose_new_thread) (holKBind Schedule_A.schedule_choose_new_thread)))) + (holIf (holConj (KHeap_A.schedulable s2H.cur_thread s2H) (holEq ct_prio target_prio)) + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_append cand) (holKBind + (holBind (KHeap_A.set_scheduler_action .choose_new_thread) (holKBind Schedule_A.schedule_choose_new_thread)))) + (holBind (Schedule_A.guarded_switch_to cand) (holKBind (KHeap_A.set_scheduler_action .resume_cur_thread)))))) s2H) + (Fl4Spec.scheduleSwitchThreadBranch cand s2H.cur_thread (KHeap_A.schedulable s2H.cur_thread s2H) s2cL) := by + unfold Fl4Spec.scheduleSwitchThreadBranch + refine mrelStep_bind_mem (mrel_when Iff.rfl (fun _ => tcbSchedAction_equiv tcbSchedEnqueue_eq s2H.cur_thread) s2H s2cL hs2c) + fun ua _ _ saH saL hsa hma => ?_ + cases ua + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.idleThread_eq.symm) saH saL hsa) + fun itH itL hit sbH sbL hsb hmb => ?_; subst hit + refine mrelStep_bind_mem (threadGet_equiv (fun _ => rfl) cand sbH sbL hsb) + fun tpH tpL htp scH scL hsc hmc => ?_; subst htp + have hcont : ∀ (cpH : BitVec 8) (sdH : Structures_A.state ZH) (sdL : State ZL), SR sdH sdL → + (cpH, sdH) ∈ (holIf (holNot (holEq s2H.cur_thread itH)) + (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority s2H.cur_thread) + (holReturn (HolZero.zeroVal (α := BitVec 8))) scH).1 → + MRelStep SR Eq + ((holBind (Schedule_A.schedule_switch_thread_fastfail s2H.cur_thread itH cpH tpH) fun fastfail => + holBind (holGets fun s => s.cur_domain) fun cur_dom => + holBind (holGets (Schedule_A.is_highest_prio cur_dom tpH)) fun highest => + holIf (holConj fastfail (holNot highest)) + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue cand) (holKBind + (holBind (KHeap_A.set_scheduler_action .choose_new_thread) (holKBind Schedule_A.schedule_choose_new_thread)))) + (holIf (holConj (KHeap_A.schedulable s2H.cur_thread s2H) (holEq cpH tpH)) + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_append cand) (holKBind + (holBind (KHeap_A.set_scheduler_action .choose_new_thread) (holKBind Schedule_A.schedule_choose_new_thread)))) + (holBind (Schedule_A.guarded_switch_to cand) (holKBind (KHeap_A.set_scheduler_action .resume_cur_thread))))) sdH) + ((do + let fastfail ← scheduleSwitchThreadFastfail s2H.cur_thread itH cpH tpH + let curDom ← NonDet.gets fun s : State ZL => s.curDomain + let highest ← NonDet.gets fun s => decide (isHighestPrio curDom tpH s) + if fastfail = true ∧ ¬highest = true then do + tcbSchedAction tcbSchedEnqueue cand + setSchedulerAction .chooseNewThread + scheduleChooseNewThread + else if KHeap_A.schedulable s2H.cur_thread s2H = true ∧ cpH = tpH then do + tcbSchedAction tcbSchedAppend cand + setSchedulerAction .chooseNewThread + scheduleChooseNewThread + else do + guardedSwitchTo cand + setSchedulerAction .resumeCurThread) sdL) := by + intro cpH sdH sdL hsd hmd + refine mrelStep_bind_mem (scheduleSwitchThreadFastfail_equiv s2H.cur_thread itH cpH tpH sdH sdL hsd) + fun ffH ffL hff seH seL hse hme => ?_; subst hff + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => h.curDomain_eq.symm) seH seL hse) + fun cdH cdL hcd sfH sfL hsf hmf => ?_; subst hcd + refine mrelStep_bind_mem (mrel_gets (fun _ _ h => (Bool.eq_iff_iff.mpr (by + rw [decide_eq_true_iff]; exact isHighestPrio_iff cdH tpH h))) sfH sfL hsf) + fun hiH hiL hhi sgH sgL hsg hmg => ?_; subst hhi + have ⟨hsw1, hsw2, hswBase⟩ := hdomSwitch cand hact_eq saH hma itH sbH tpH scH cpH sdH ffH seH cdH sfH hiH sgH + hmb hmc hmd hme hmf hmg + by_cases h1 : holConj ffH (holNot hiH) = true + · have h1L : ffH = true ∧ ¬hiH = true := by simpa [holConj_eq_true, holNot_eq_true] using h1 + rw [h1, holIf_true, ite_eq_left h1L] + refine mrelStep_bind_mem (tcbSchedAction_equiv tcbSchedEnqueue_eq cand sgH sgL hsg) + fun uh _ _ shH shL hsh hmh => ?_ + cases uh + refine mrelStep_bind_mem (setSchedulerAction_equiv .choose_new_thread shH shL hsh) + fun ui _ _ siH siL hsi hmi => ?_ + cases ui + exact scheduleChooseNewThread_equiv hop hsi (hsw1 h1 shH hmh siH hmi) + · have h1F : holConj ffH (holNot hiH) = false := Bool.eq_false_iff.mpr h1 + have h1LF : ¬(ffH = true ∧ ¬hiH = true) := by simpa [holConj_eq_true, holNot_eq_true] using h1 + rw [h1F, holIf_false, ite_eq_right h1LF] + by_cases h2 : holConj (KHeap_A.schedulable s2H.cur_thread s2H) (holEq cpH tpH) = true + · have h2L : KHeap_A.schedulable s2H.cur_thread s2H = true ∧ cpH = tpH := by + simpa [holConj_eq_true, holEq_eq_true] using h2 + rw [h2, holIf_true, ite_eq_left h2L] + refine mrelStep_bind_mem (tcbSchedAction_equiv tcbSchedAppend_eq cand sgH sgL hsg) + fun uh _ _ shH shL hsh hmh => ?_ + cases uh + refine mrelStep_bind_mem (setSchedulerAction_equiv .choose_new_thread shH shL hsh) + fun ui _ _ siH siL hsi hmi => ?_ + cases ui + exact scheduleChooseNewThread_equiv hop hsi (hsw2 h1F h2 shH hmh siH hmi) + · have h2F : holConj (KHeap_A.schedulable s2H.cur_thread s2H) (holEq cpH tpH) = false := + Bool.eq_false_iff.mpr h2 + have h2LF : ¬(KHeap_A.schedulable s2H.cur_thread s2H = true ∧ cpH = tpH) := by + simpa [holConj_eq_true, holEq_eq_true] using h2 + rw [h2F, holIf_false, ite_eq_right h2LF] + refine mrelStep_bind_mem (guardedSwitchTo_equiv hop cand hsg (hswBase h1F h2F)) + fun _ _ _ stH stL hst _ => ?_ + exact setSchedulerAction_equiv .resume_cur_thread stH stL hst + by_cases hci : s2H.cur_thread = itH + · have hF : holNot (holEq s2H.cur_thread itH) = false := by simp [holNot, holEq, hci] + rw [hF, holIf_false, ite_eq_right_iff.mpr (fun h => absurd hci h)] + refine mrelStep_bind_mem + (mrel_return (Rs := SR) (Ra := Eq) (aH := HolZero.zeroVal (α := BitVec 8)) (aL := (0 : BitVec 8)) rfl scH scL hsc) + fun cpH cpL hcp sdH sdL hsd hmd => ?_ + subst hcp + exact hcont cpH sdH sdL hsd (by rw [hF, holIf_false]; exact hmd) + · have hT : holNot (holEq s2H.cur_thread itH) = true := by simp [holNot, holEq, hci] + rw [hT, holIf_true, ite_eq_left_iff.mpr (fun h => absurd hci h)] + refine mrelStep_bind_mem (threadGet_equiv (fun _ => rfl) s2H.cur_thread scH scL hsc) + fun cpH cpL hcp sdH sdL hsd hmd => ?_ + subst hcp + exact hcont cpH sdH sdL hsd (by rw [hT, holIf_true]; exact hmd) + refine mrelStep_bind_mem hbranch fun _ _ _ s3H s3L hs3 hm3 => ?_ + exact scAndTimer_equiv hc hop hs3 (hswAll s3H (Or.inr (Or.inr ⟨cand, hact_eq, hm3⟩))) + +def sched_context_yield_to_p (sc_ptr : ObjRef) : HolNonDet (Structures_A.state ZH) (List Word) := + holBind (KHeap_A.get_sc_obj_ref Structures_A.sched_context_ext.sc_yield_from sc_ptr) fun sc_yf_opt => + holBind (holWhen (holNot (holEq sc_yf_opt none)) + (holBind (complete_yield_to_p (holTheOpt sc_yf_opt)) (holKBind + (holBind (KHeap_A.get_sc_obj_ref Structures_A.sched_context_ext.sc_yield_from sc_ptr) fun sc_yf_opt' => + holAssert (holEq sc_yf_opt' none))))) (holKBind + (holBind (SchedContext_A.sched_context_resume sc_ptr) (holKBind + (holBind (holBind (KHeap_A.get_sc_obj_ref Structures_A.sched_context_ext.sc_tcb sc_ptr) fun sc_tcb_opt => + holBind (holAssertOpt sc_tcb_opt) fun tcb_ptr => + holBind (holGets (KHeap_A.schedulable tcb_ptr)) fun sched => + holIf sched + (holBind (holGets fun s => s.cur_thread) fun ct_ptr => + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority tcb_ptr) fun prios => + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_priority ct_ptr) fun ct_prios => + holIf (holLt prios ct_prios) + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue tcb_ptr) (holKBind + (holReturn true))))) + (holBind (KHeap_A.thread_set (Structures_A.tcb.tcb_yield_to_update (fun _ => some sc_ptr)) ct_ptr) (holKBind + (holBind (KHeap_A.update_sched_context sc_ptr (Structures_A.sched_context.sc_yield_from_update (fun _ => some ct_ptr))) (holKBind + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue ct_ptr) (holKBind + (holBind (KHeap_A.tcb_sched_action KHeap_A.tcb_sched_enqueue tcb_ptr) (holKBind + (holBind KHeap_A.reschedule_required (holKBind (holReturn false)))))))))))))) + (holReturn true)) fun return_now => + holIf return_now (SchedContext_A.return_consumed sc_ptr) (holReturn []))))) + +def invoke_sched_context_p : Invocations_A.sched_context_invocation → HolNonDet (Structures_A.state ZH) (List Word) + | .InvokeSchedContextConsumed sc_ptr => SchedContext_A.return_consumed sc_ptr + | .InvokeSchedContextBind sc_ptr cap => + match cap with + | .ThreadCap tcb_ptr => holBind (SchedContext_A.sched_context_bind_tcb sc_ptr tcb_ptr) (holKBind (holReturn [])) + | .NotificationCap ntfn _ _ => holBind (IpcCancel_A.sched_context_bind_ntfn sc_ptr ntfn) (holKBind (holReturn [])) + | _ => holFail + | .InvokeSchedContextUnbindObject sc_ptr cap => + match cap with + | .ThreadCap _ => holBind (IpcCancel_A.sched_context_unbind_tcb sc_ptr) (holKBind (holReturn [])) + | .NotificationCap _ _ _ => holBind (IpcCancel_A.sched_context_unbind_ntfn sc_ptr) (holKBind (holReturn [])) + | _ => holFail + | .InvokeSchedContextUnbind sc_ptr => + holBind (IpcCancel_A.sched_context_unbind_all_tcbs sc_ptr) (holKBind + (holBind (IpcCancel_A.sched_context_unbind_ntfn sc_ptr) (holKBind + (holBind (IpcCancel_A.sched_context_unbind_reply sc_ptr) (holKBind (holReturn [])))))) + | .InvokeSchedContextYieldTo sc_ptr => sched_context_yield_to_p sc_ptr + +theorem patched_schedContextYieldTo_equiv (hop : OpaqueRel RestRel) (scPtr : ObjRef) : + MRel SR Eq + (sched_context_yield_to_p scPtr) (Fl4Spec.schedContextYieldTo scPtr) := by + unfold sched_context_yield_to_p Fl4Spec.schedContextYieldTo + refine mrel_bind (getScObjRef_equiv (fun _ => rfl) scPtr) fun yfH yfL hyf => ?_; subst hyf + refine mrel_kbind (mrel_when (by simp [holNot_eq_true, holEq_eq_true]) (fun hne => by + cases yfH with + | none => exact absurd rfl hne + | some yf => + simp only [holTheOpt, the] + refine mrel_kbind (patched_completeYieldTo_equiv hop yf) ?_ + refine mrel_bind (getScObjRef_equiv (fun _ => rfl) scPtr) fun yf2H yf2L hyf2 => ?_; subst hyf2 + exact mrel_assert (by simp [holEq_eq_true]))) ?_ + refine mrel_kbind (schedContextResume_equiv hop scPtr) ?_ + refine mrel_bind (Ra := Eq) (by + refine mrel_bind (getScObjRef_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) (fun _ => rfl) scPtr) fun tH tL ht => ?_; subst ht + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases tH <;> simp [OptRel])) fun tpH tpL htp => ?_; subst htp + refine mrel_bind (mrel_gets (Rs := SR) (Ra := Eq) fun _ _ hs => (schedulable_eq hs tpH).symm) fun schH schL hsch => ?_; subst hsch + refine mrel_if Iff.rfl (fun _ => ?_) (fun _ => mrel_return rfl) + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun ctH ctL hct => ?_; subst hct + refine mrel_bind (threadGet_equiv (fun _ => rfl) tpH) fun pH pL hp => ?_; subst hp + refine mrel_bind (threadGet_equiv (fun _ => rfl) ctH) fun cpH cpL hcp => ?_; subst hcp + refine mrel_if (by simp [holLt_eq_true, HolOrd.ltVal]) + (fun _ => + mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq tpH) + (mrel_kbind (tcbSchedAction_equiv tcbSchedEnqueue_eq tpH) (mrel_return rfl))) + (fun _ => + mrel_kbind (threadSet_equiv (fun _ => rfl) ctH) + (mrel_kbind (updateSchedContext_equiv (fun _ => rfl) scPtr) + (mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq tpH) + (mrel_kbind (tcbSchedAction_equiv tcbSchedEnqueue_eq ctH) + (mrel_kbind (tcbSchedAction_equiv tcbSchedEnqueue_eq tpH) + (mrel_kbind (rescheduleRequired_equiv hop) (mrel_return rfl)))))))) + fun rnH rnL hrn => ?_; subst hrn + exact mrel_if Iff.rfl (fun _ => returnConsumed_equiv hop scPtr) (fun _ => mrel_return rfl) + +theorem patched_invokeSchedContext_equiv (hop : OpaqueRel RestRel) + (iv : Invocations_A.sched_context_invocation) : + MRel SR Eq + (invoke_sched_context_p iv) (Fl4Spec.invokeSchedContext (embSchedContextInv iv)) := by + cases iv with + | InvokeSchedContextConsumed scPtr => exact returnConsumed_equiv hop scPtr + | InvokeSchedContextBind scPtr cap => + unfold invoke_sched_context_p Fl4Spec.invokeSchedContext embSchedContextInv + cases cap <;> try exact mrel_fail + · exact mrel_kbind (schedContextBindNtfn_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr _) (mrel_return rfl) + · exact mrel_kbind (schedContextBindTcb_equiv hop scPtr _) (mrel_return rfl) + | InvokeSchedContextUnbindObject scPtr cap => + unfold invoke_sched_context_p Fl4Spec.invokeSchedContext embSchedContextInv + cases cap <;> try exact mrel_fail + · exact mrel_kbind (schedContextUnbindNtfn_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr) (mrel_return rfl) + · exact mrel_kbind (schedContextUnbindTcb_equiv hop scPtr) (mrel_return rfl) + | InvokeSchedContextUnbind scPtr => + unfold invoke_sched_context_p Fl4Spec.invokeSchedContext embSchedContextInv + exact mrel_kbind (schedContextUnbindAllTcbs_equiv hop scPtr) + (mrel_kbind (schedContextUnbindNtfn_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr) + (mrel_kbind (schedContextUnbindReply_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) scPtr) (mrel_return rfl))) + | InvokeSchedContextYieldTo scPtr => exact patched_schedContextYieldTo_equiv hop scPtr + +end SchedMonad + +end + +end L4vRefX64.Equiv.Schedule diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Structures.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Structures.lean new file mode 100644 index 000000000..2d4d7acf0 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Structures.lean @@ -0,0 +1,210 @@ +import L4vRefX64.Equiv.Machine + +namespace L4vRefX64.Equiv.Structures + +open L4vRefX64.Prim +open L4vRefX64.Spec +open L4vRefX64.Rel +open Fl4Spec +open Classical + +noncomputable section + +theorem cteLevelBits_eq : cteLevelBits = Arch_Structs_A.cte_level_bits := rfl +theorem untypedMaxBits_eq : untypedMaxBits = Arch_Structs_A.untyped_max_bits := rfl + +theorem aaType_eq (ao : Arch_Structs_A.arch_kernel_obj) : + Fl4Spec.aaType (embArchKobj ao) = embAAType (Arch_Structs_A.aa_type ao) := by + cases ao with + | DataPage device size => cases device <;> rfl + | _ => rfl + +theorem runnable_eq (ts : Structures_A.thread_state) : + Fl4Spec.runnable (embThreadState ts) = Structures_A.runnable ts := by cases ts <;> rfl + +theorem ipcQueuedThreadState_eq (ts : Structures_A.thread_state) : + Fl4Spec.ipcQueuedThreadState (embThreadState ts) = Structures_A.ipc_queued_thread_state ts := by + cases ts <;> rfl + +theorem MIN_REFILLS_eq : Fl4Spec.MIN_REFILLS = Structures_A.MIN_REFILLS := rfl +theorem MIN_BUDGET_US_eq {RestRel} (ho : OpaqueRel RestRel) : + Fl4Spec.MIN_BUDGET_US = Structures_A.MIN_BUDGET_US := by + unfold Fl4Spec.MIN_BUDGET_US Structures_A.MIN_BUDGET_US + rw [ho.kernelWCETUs_eq]; rfl +theorem minSchedContextBits_eq : Fl4Spec.minSchedContextBits = Structures_A.min_sched_context_bits := rfl +theorem sizeofSchedContextT_eq : Fl4Spec.sizeofSchedContextT = Structures_A.sizeof_sched_context_t := rfl +theorem refillSizeBytes_eq : Fl4Spec.refillSizeBytes = Structures_A.refill_size_bytes := rfl +theorem maxNumRefills_eq (sz : Nat) : + Fl4Spec.maxNumRefills sz = Structures_A.max_num_refills sz := rfl +theorem scSporadicFlag_eq : Fl4Spec.scSporadicFlag = Structures_A.sc_sporadic_flag := rfl +theorem defaultSchedContext_eq : + Fl4Spec.defaultSchedContext = embSchedContext Structures_A.default_sched_context := rfl +theorem defaultReply_eq : + Fl4Spec.defaultReply = embReply Structures_A.default_reply := rfl + +theorem aobjOf_eq (ko : Structures_A.kernel_object) : + Fl4Spec.aobjOf (embKernelObject ko) = (Structures_A.aobj_of ko).map embArchKobj := by + cases ko <;> rfl + +theorem wellFormedCnodeN_iff (n : Nat) (cs : List Bool → Option Structures_A.cap) : + Structures_A.well_formed_cnode_n n cs = true ↔ Fl4Spec.wellFormedCnodeN n (embCnodeContents cs) := by + unfold Structures_A.well_formed_cnode_n Fl4Spec.wellFormedCnodeN + simp only [holEq_eq_true, holDom, Fl4Spec.dom, holCollect_eq, holSize_list] + have hdom : {a | embCnodeContents cs a ≠ none} = {a | cs a ≠ none} := by + ext x; simp [embCnodeContents] + rw [hdom] + +theorem validSchedContextSize_iff (n : Nat) : + Structures_A.valid_sched_context_size n = true ↔ Fl4Spec.validSchedContextSize n := by + unfold Structures_A.valid_sched_context_size Fl4Spec.validSchedContextSize + simp [holLe_eq_true, HolOrd.leVal, minSchedContextBits_eq, untypedMaxBits_eq]; rfl + +/-- Exact agreement of `objBits` on all non-Notification objects. -/ +theorem aType_eq (ko : Structures_A.kernel_object) : + Fl4Spec.aType (embKernelObject ko) = embAType (Structures_A.a_type ko) := by + cases ko with + | CNode sz cs => + unfold Fl4Spec.aType Structures_A.a_type + simp only [embKernelObject, Structures_A.case_kernel_object, holIf_eq] + by_cases h : Fl4Spec.wellFormedCnodeN sz (embCnodeContents cs) + · simp [h, (wellFormedCnodeN_iff sz cs).mpr h, embAType] + · have h' : Structures_A.well_formed_cnode_n sz cs ≠ true := fun hh => h ((wellFormedCnodeN_iff sz cs).mp hh) + simp [h, h', embAType, cteLevelBits_eq, HolAdd.addVal] + | SchedContext sc n => + unfold Fl4Spec.aType Structures_A.a_type + simp only [embKernelObject, Structures_A.case_kernel_object, holIf_eq] + by_cases h : Fl4Spec.validSchedContextSize n + · simp [h, (validSchedContextSize_iff n).mpr h, embAType] + · have h' : Structures_A.valid_sched_context_size n ≠ true := fun hh => h ((validSchedContextSize_iff n).mp hh) + simp [h, h', embAType, minSchedContextBits_eq, HolAdd.addVal] + | ArchObj ao => + simp [Fl4Spec.aType, Structures_A.a_type, Structures_A.case_kernel_object, + embKernelObject, embAType, aaType_eq] + | _ => rfl + +theorem tcbCnodeIndex_eq (n : Nat) : + Fl4Spec.tcbCnodeIndex n = Structures_A.tcb_cnode_index n := rfl + +theorem zombieCteBits_eq (n : Option Nat) : + Fl4Spec.zombieCteBits n = Structures_A.zombie_cte_bits n := by cases n <;> rfl + +theorem archTcbContextSet_eq (uc : MachineOps.user_context) (a : Arch_Structs_A.arch_tcb) : + Fl4Spec.archTcbContextSet (embUserContext uc) (embArchTcb a) = + embArchTcb (Arch_Structs_A.arch_tcb_context_set uc a) := rfl + +theorem archTcbContextGet_eq (a : Arch_Structs_A.arch_tcb) : + Fl4Spec.archTcbContextGet (embArchTcb a) = embUserContext (Arch_Structs_A.arch_tcb_context_get a) := rfl + + +theorem tcbCnodeMap_eq_nonExt (t : Structures_A.tcb) (idx : CnodeIndex) + (h5 : idx ≠ tcbCnodeIndex 5) : + Fl4Spec.tcbCnodeMap (embTcb t) idx = (Structures_A.tcb_cnode_map t idx).map embCap := by + unfold Fl4Spec.tcbCnodeMap Structures_A.tcb_cnode_map + simp only [holFunUpd, HolZero.zeroVal, HolOne.oneVal, + HolNumeral.ofNatVal, ← tcbCnodeIndex_eq, Function.update, h5, ↓reduceDIte] + by_cases h4 : idx = tcbCnodeIndex 4; · subst h4; simp [embTcb] + simp only [h4, ↓reduceDIte] + by_cases h3 : idx = tcbCnodeIndex 3; · subst h3; simp [embTcb] + simp only [h3, ↓reduceDIte] + by_cases h2 : idx = tcbCnodeIndex 2; · subst h2; simp [embTcb] + simp only [h2, ↓reduceDIte] + by_cases h1 : idx = tcbCnodeIndex 1; · subst h1; simp [embTcb] + simp only [h1, ↓reduceDIte] + by_cases h0 : idx = tcbCnodeIndex 0; · subst h0; simp [embTcb] + simp [h0] + +theorem isCnodeCap_eq (c : Structures_A.cap) : + Fl4Spec.isCnodeCap (embCap c) = Structures_A.is_cnode_cap c := by + cases c <;> rfl + +theorem capOf_eq_nonExt (ko : Structures_A.kernel_object) (idx : CnodeIndex) + (h : (∀ t, ko ≠ .TCB t) ∨ idx ≠ tcbCnodeIndex 5) : + Fl4Spec.capOf (embKernelObject ko) idx = (Structures_A.cap_of ko idx).map embCap := by + cases ko with + | CNode sz cs => rfl + | TCB t => + rcases h with hno | h5 + · exact (hno t rfl).elim + · exact tcbCnodeMap_eq_nonExt t idx h5 + | _ => rfl + +theorem epQueue_eq (ep : Structures_A.endpoint) : + (embEndpoint ep).epQueue = Structures_A.endpoint.ep_queue ep := by cases ep <;> rfl + +theorem ntfnQueue_eq (n : Structures_A.ntfn) : + (embNtfn n).ntfnQueue = Structures_A.ntfn.ntfn_queue n := by cases n <;> rfl + +theorem ntfnBadge_eq (b : Badge) : + (embNtfn (.ActiveNtfn b)).ntfnBadge = Structures_A.ntfn.ntfn_badge (.ActiveNtfn b) := rfl + +theorem defaultEp_eq : Fl4Spec.defaultEp = embEndpoint Structures_A.default_ep := rfl +theorem defaultNtfn_eq : Fl4Spec.defaultNtfn = embNtfn Structures_A.default_ntfn := rfl +theorem defaultNotification_eq : + Fl4Spec.defaultNotification = embNotification Structures_A.default_notification := rfl + +theorem replyObject_eq (ts : Structures_A.thread_state) : + Fl4Spec.replyObject (embThreadState ts) = Structures_A.reply_object ts := by + cases ts <;> rfl + +theorem isBlockedOnReceive_iff (ts : Structures_A.thread_state) : + Structures_A.is_blocked_on_receive ts = true ↔ Fl4Spec.isBlockedOnReceive (embThreadState ts) := by + cases ts <;> simp [Structures_A.is_blocked_on_receive, Fl4Spec.isBlockedOnReceive, embThreadState] + +theorem isBlockedOnSend_iff (ts : Structures_A.thread_state) : + Structures_A.is_blocked_on_send ts = true ↔ Fl4Spec.isBlockedOnSend (embThreadState ts) := by + cases ts <;> simp [Structures_A.is_blocked_on_send, Fl4Spec.isBlockedOnSend, embThreadState] + +theorem isBlockedOnReply_iff (ts : Structures_A.thread_state) : + Structures_A.is_blocked_on_reply ts = true ↔ Fl4Spec.isBlockedOnReply (embThreadState ts) := by + cases ts <;> simp [Structures_A.is_blocked_on_reply, Fl4Spec.isBlockedOnReply, embThreadState] + +theorem isBlockedOnNtfn_iff (ts : Structures_A.thread_state) : + Structures_A.is_blocked_on_ntfn ts = true ↔ Fl4Spec.isBlockedOnNtfn (embThreadState ts) := by + cases ts <;> simp [Structures_A.is_blocked_on_ntfn, Fl4Spec.isBlockedOnNtfn, embThreadState] + + +theorem messageInfoToData_eq (mi : Structures_A.message_info) : + Fl4Spec.messageInfoToData (embMessageInfo mi) = Structures_A.message_info_to_data mi := by + cases mi + simp [Fl4Spec.messageInfoToData, Structures_A.message_info_to_data, + embMessageInfo, holWordOr, holWordShiftl, HolNumeral.ofNatVal, BitVec.or_assoc] + +theorem dataToMessageInfo_eq (w : Data) : + Fl4Spec.dataToMessageInfo w = embMessageInfo (Structures_A.data_to_message_info w) := by + unfold Fl4Spec.dataToMessageInfo Structures_A.data_to_message_info embMessageInfo + simp only [holLet_eq, holIf_eq, holLt_eq_true, HolOrd.ltVal] + rfl + +theorem capTransferDataSize_eq : Fl4Spec.capTransferDataSize = Structures_A.cap_transfer_data_size := rfl +theorem msgMaxLength_eq : Fl4Spec.msgMaxLength = Structures_A.msg_max_length := rfl +theorem msgMaxExtraCaps_eq : Fl4Spec.msgMaxExtraCaps = Structures_A.msg_max_extra_caps := rfl +theorem maxIpcLength_eq : Fl4Spec.maxIpcLength = Structures_A.max_ipc_length := rfl + +theorem msgAlignBits_eq : Fl4Spec.msgAlignBits = Structures_A.msg_align_bits := by + have hmax : Fl4Spec.maxIpcLength = 128 := by + simp [Fl4Spec.maxIpcLength, Fl4Spec.msgMaxLength, Fl4Spec.msgMaxExtraCaps, + Fl4Spec.capTransferDataSize] + have hmaxH : Structures_A.max_ipc_length = 128 := by rw [← maxIpcLength_eq, hmax] + unfold Fl4Spec.msgAlignBits Structures_A.msg_align_bits holLeast + have h1 : ∀ h : ∃ n, Fl4Spec.maxIpcLength ≤ 2 ^ n, Nat.find h = 7 := by + intro h; rw [Nat.find_eq_iff, hmax] + refine ⟨by omega, fun m hm => ?_⟩ + match m with + | 0 | 1 | 2 | 3 | 4 | 5 | 6 => omega + | n + 7 => omega + have hex : ∃ n : Nat, holLe Structures_A.max_ipc_length (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) n) = true := by + refine ⟨7, ?_⟩ + simp [holLe_eq_true, HolOrd.leVal, HolPow.powVal, HolNumeral.ofNatVal, hmaxH] + have h2 : Nat.find hex = 7 := by + rw [Nat.find_eq_iff] + simp only [holLe_eq_true, HolOrd.leVal, HolPow.powVal, HolNumeral.ofNatVal, hmaxH] + refine ⟨by simp, fun m hm => ?_⟩ + match m with + | 0 | 1 | 2 | 3 | 4 | 5 | 6 => simp + | n + 7 => omega + simp only [hex, ↓reduceDIte, h1, h2] + rfl + +end + +end L4vRefX64.Equiv.Structures diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Syscall.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Syscall.lean new file mode 100644 index 000000000..97fe991c6 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Syscall.lean @@ -0,0 +1,1339 @@ +import L4vRefX64.Equiv.InvocationDecode +import L4vRefX64.Equiv.ArchInvoke +import L4vRefX64.Equiv.Retype +import L4vRefX64.Equiv.Interrupt +import L4vRefX64.Equiv.CSpace +import L4vRefX64.Equiv.Tcb +import L4vRefX64.Equiv.Schedule +import L4vRefX64.Spec.Syscall_A + +/-! +# X64 kernel-entry correspondence + +* [P] `ConfigRel` and `OpaqueRel RestRel` relate the fixed PC99 configuration, + time constants, oracles, and opaque machine operations. +* [P] `CallKernelSafe` admits the input carriers and guards reached event, + preemption, and scheduling continuations. +* [P] `HandleEventSafe` selects the route-specific obligations. + `EventBudgetSafe` guards budget handling after timestamp collection, and + `SyscallDispatchSafe` guards dispatch after a successful budget restart. +* [P] `PreemptionSafe` guards the branch that charges time on the reached + scheduling context. +-/ + +namespace L4vRefX64.Equiv.Syscall + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Ipc L4vRefX64.Equiv.Interrupt +open L4vRefX64.Equiv.Schedule L4vRefX64.Equiv.Tcb +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.Deterministic L4vRefX64.Equiv.CSpace +open L4vRefX64.Equiv +open L4vRefX64.Equiv.InvocationDecode L4vRefX64.Equiv.ArchInvoke L4vRefX64.Equiv.Retype +open L4vRefX64.Equiv.CSpaceAcc L4vRefX64.Equiv.ArchVSpace L4vRefX64.Equiv.TcbAcc +open Fl4Spec + +noncomputable section + +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 + +private theorem withoutPreemption_step_equiv {αH αL : Type} [Nonempty αH] + {Ra : αH → αL → Prop} + {mH : HolNonDet (Structures_A.state ZH) αH} {mL : SMonad ZL αL} + {sH : Structures_A.state ZH} {sL : State ZL} (hm : MRelStep SR Ra (mH sH) (mL sL)) : + MRelStep SR (SumExceptRel Eq Ra) + (Exceptions_A.without_preemption mH sH) ((Fl4Spec.withoutPreemption mL).run sL) := + mrelStep_liftE hm + +private theorem holGets_mem {σ α : Type} (f : σ → α) (s s' : σ) (a : α) + (h : (a, s') ∈ (holGets f s).1) : a = f s ∧ s' = s := by + simpa only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] using h + +/-! ## `Syscall_A`: `perform_invocation` -/ + +def perform_invocation_p (block call can_donate : Bool) : + Invocations_A.invocation → HolNonDet (Structures_A.state ZH) (Sum Unit (List Data)) + | .InvokeUntyped i => + holBindE (invoke_untyped_p i) (holKBind (holReturnOk [])) + | .InvokeEndpoint ep badge can_grant can_grant_reply => + Exceptions_A.without_preemption + (holBind (holGets Structures_A.abstract_state_ext.cur_thread) fun thread => + holBind (send_ipc_p block call badge can_grant can_grant_reply can_donate thread ep) + (holKBind (holReturn []))) + | .InvokeNotification ep badge => + holBindE (Exceptions_A.without_preemption (Ipc_A.send_signal ep badge)) + (holKBind (holReturnOk [])) + | .InvokeTCB i => invoke_tcb_p i + | .InvokeDomain dom_inv => + holLiftE (holBind (Tcb_A.invoke_domain dom_inv) (holKBind (holReturn []))) + | .InvokeReply reply grant => + holLiftE (holBind (holGets Structures_A.abstract_state_ext.cur_thread) fun sender => + holBind (do_reply_transfer_p sender reply grant) (holKBind (holReturn []))) + | .InvokeCNode i => + holBindE (invoke_cnode_p i) (holKBind (holReturnOk [])) + | .InvokeIRQControl i => + holBindE (invoke_irq_control_p i) (holKBind (holReturnOk [])) + | .InvokeIRQHandler i => + holBindE (holLiftE (invoke_irq_handler_p i)) (holKBind (holReturnOk [])) + | .InvokeSchedContext i => + Exceptions_A.without_preemption (invoke_sched_context_p i) + | .InvokeSchedControl i => + holBindE (holLiftE (Ipc_A.invoke_sched_control_configure_flags i)) + (holKBind (holReturnOk [])) + | .InvokeArchObject i => arch_perform_invocation_p i + +/-- [P] The reached invocation and state satisfy the selected performer's capability, +carrier, or refill conditions. -/ +def PerformInvSafe (i : Invocations_A.invocation) (sH : Structures_A.state ZH) : Prop := + match i with + | .InvokeUntyped ui => + match ui with + | .Retype src _ _ _ _ _ slots _ => + NonExtTcbSlot src.2 ∧ ∀ s ∈ slots, NonExtTcbSlot s.2 + | .InvokeEndpoint ep _ canGrant _ => SendIpcSafe canGrant sH.cur_thread ep sH + | .InvokeNotification _ _ => True + | .InvokeTCB ti => InvokeTcbSafe ti sH + | .InvokeDomain _ => True + | .InvokeReply reply grant => DoReplyTransferSafe sH.cur_thread reply grant sH + | .InvokeCNode ci => InvokeCnodeSafe ci sH + | .InvokeIRQControl ici => InvokeIrqControlSafe ici sH + | .InvokeIRQHandler ihi => InvokeIrqHandlerSafe ihi sH + | .InvokeSchedContext _ => True + | .InvokeSchedControl sci => InvokeSchedControlSafe sci sH + | .InvokeArchObject ai => ReferenceBaseCarriers sH ∧ ArchPerformSafe ai sH + +theorem patched_performInvocation_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (block call canDonate : Bool) (i : Invocations_A.invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : PerformInvSafe i sH) : + MRelStep SR (SumExceptRel Eq Eq) + (perform_invocation_p block call canDonate i sH) + (ExceptT.run (Fl4Spec.performInvocation block call canDonate (embInvocation i)) sL) := by + cases i with + | InvokeUntyped ui => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + cases ui with + | Retype src reset base rbase newTy objSz slots isDev => + rcases hsafe with ⟨hsrc, hslots⟩ + exact (mrele_kbindE (patched_invokeUntyped_equiv hop hc _ hsrc hslots) (mrele_returnOk rfl)) sH sL hs + | InvokeEndpoint ep badge canGrant canGrantReply => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + refine withoutPreemption_step_equiv ?_ + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH sL hs) + fun tH tL ht s1H s1L hs1 hm1 => ?_ + subst ht + obtain ⟨htEq, hs1eq⟩ := holGets_mem _ sH s1H tH hm1; subst htEq; subst s1H + refine mrelStep_bind_mem (patched_sendIpc_equiv hop block call badge canGrant canGrantReply canDonate sH.cur_thread ep hs1 hsafe) + fun _ _ _ s2H s2L hs2 _ => mrel_return rfl s2H s2L hs2 + | InvokeNotification ep badge => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact (mrele_kbindE (withoutPreemption_equiv (sendSignal_equiv hop ep badge)) + (mrele_returnOk rfl)) sH sL hs + | InvokeTCB ti => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact patched_invokeTcb_equiv hop hc ti hs hsafe + | InvokeDomain domInv => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact (mrele_liftE (mrel_kbind (invokeDomain_equiv hop domInv) (mrel_return rfl))) sH sL hs + | InvokeReply reply grant => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + refine mrelStep_liftE ?_ + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH sL hs) + fun tH tL ht s1H s1L hs1 hm1 => ?_ + subst ht + obtain ⟨htEq, hs1eq⟩ := holGets_mem _ sH s1H tH hm1; subst htEq; subst s1H + refine mrelStep_bind_mem (patched_doReplyTransfer_equiv hop sH.cur_thread reply grant hs1 hsafe) + fun _ _ _ s2H s2L hs2 _ => mrel_return rfl s2H s2L hs2 + | InvokeCNode ci => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact mrelStep_kbindE_mem (patched_invokeCnode_equiv hop hc ci hs hsafe) + fun _ s1H s1L hs1 _ => mrele_returnOk rfl s1H s1L hs1 + | InvokeIRQControl ici => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact mrelStep_kbindE_mem (patched_invokeIrqControl_equiv hop ici hs hsafe) + fun _ s1H s1L hs1 _ => mrele_returnOk rfl s1H s1L hs1 + | InvokeIRQHandler ihi => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact mrelStep_kbindE_mem (mrelStep_liftE (patched_invokeIrqHandler_equiv hop ihi hs hsafe)) + fun _ s1H s1L hs1 _ => mrele_returnOk rfl s1H s1L hs1 + | InvokeSchedContext sci => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact (withoutPreemption_equiv (patched_invokeSchedContext_equiv hop sci)) sH sL hs + | InvokeSchedControl sci => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact mrelStep_kbindE_mem + (mrelStep_liftE (invokeSchedControlConfigureFlags_equiv hop sci hs hsafe)) + fun _ s1H s1L hs1 _ => mrele_returnOk rfl s1H s1L hs1 + | InvokeArchObject ai => + unfold perform_invocation_p Fl4Spec.performInvocation + simp only [embInvocation] + exact patched_archPerformInvocation_equiv hop ai hs (hs.baseCarriers_iff.mpr hsafe.1) hsafe.2 + +private theorem leanLiftE_some_mem {σ ε α : Type} {m : NonDet σ α} + {s s' : σ} {a : α} (h : (Except.ok a, s') ∈ ((NonDetE.liftE (ε := ε) m).run s).1) : + (a, s') ∈ (m s).1 := by + rcases h with ⟨⟨x, st⟩, hrun, hret⟩ + have heq := Prod.mk.inj (Set.mem_singleton_iff.mp hret) + obtain ⟨ha, rfl⟩ := heq + cases ha + exact hrun + +/-- The syscall combinator transfers only the continuations reached by a fault, +a successful lookup, a decode error, or a successful decode. -/ +theorem syscall_step_equiv {αH αL βH βL γH γL : Type} + [Nonempty αH] [Nonempty βH] [Nonempty γH] + {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} {Rc : γH → γL → Prop} + {mFaultH : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.fault αH)} + {mFaultL : FMonad ZL αL} + {hFaultH : ExceptionTypes_A.fault → HolNonDet (Structures_A.state ZH) γH} + {hFaultL : Fault → SMonad ZL γL} + {mErrorH : αH → HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error βH)} + {mErrorL : αL → SEMonad ZL βL} + {hErrorH : ExceptionTypes_A.syscall_error → HolNonDet (Structures_A.state ZH) γH} + {hErrorL : SyscallError → SMonad ZL γL} + {mFinaliseH : βH → HolNonDet (Structures_A.state ZH) (Sum Unit γH)} + {mFinaliseL : βL → PMonad ZL γL} + {sH : Structures_A.state ZH} {sL : State ZL} + (hmFault : MRelStep SR (SumExceptRel (FunRel embFault) Ra) (mFaultH sH) (ExceptT.run mFaultL sL)) + (hhFault : ∀ fH s1H s1L, SR s1H s1L → (Sum.inl fH, s1H) ∈ (mFaultH sH).1 → + MRelStep SR Rc (hFaultH fH s1H) (hFaultL (embFault fH) s1L)) + (hmError : ∀ aH aL s1H s1L, Ra aH aL → SR s1H s1L → + (Sum.inr aH, s1H) ∈ (mFaultH sH).1 → (Except.ok aL, s1L) ∈ (mFaultL.run sL).1 → + MRelStep SR (SumExceptRel (FunRel embSyscallError) Rb) + (mErrorH aH s1H) (ExceptT.run (mErrorL aL) s1L)) + (hhError : ∀ aH eH s1H s2H s2L, SR s2H s2L → + (Sum.inr aH, s1H) ∈ (mFaultH sH).1 → (Sum.inl eH, s2H) ∈ (mErrorH aH s1H).1 → + MRelStep SR Rc (hErrorH eH s2H) (hErrorL (embSyscallError eH) s2L)) + (hmFinalise : ∀ aH bH bL s1H s2H s2L, Rb bH bL → SR s2H s2L → + (Sum.inr aH, s1H) ∈ (mFaultH sH).1 → (Sum.inr bH, s2H) ∈ (mErrorH aH s1H).1 → + MRelStep SR (SumExceptRel Eq Rc) (mFinaliseH bH s2H) (ExceptT.run (mFinaliseL bL) s2L)) : + MRelStep SR (SumExceptRel Eq Rc) + (Syscall_A.syscall mFaultH hFaultH mErrorH hErrorH mFinaliseH sH) + (ExceptT.run (Fl4Spec.syscall mFaultL hFaultL mErrorL hErrorL mFinaliseL) sL) := by + unfold Syscall_A.syscall Fl4Spec.syscall + dsimp only [holFunApp] + refine mrelStep_bindE_mem_both (withoutPreemption_step_equiv hmFault) + fun rH rL hr s1H s1L hs1 hmem1 hmem1L => ?_ + have hmem1' : (rH, s1H) ∈ (mFaultH sH).1 := by + simp only [Exceptions_A.without_preemption, holLiftE, holLiftM, holBind, holReturn, + Set.mem_ofPred_eq, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hmem1 + rcases hmem1 with ⟨⟨r0, s0⟩, hm0, rfl, rfl⟩ + exact hm0 + cases rH with + | inl fH => + cases rL with + | error fL => + simp only [SumExceptRel] at hr + subst hr + simp only [holCaseSum] + exact withoutPreemption_step_equiv (hhFault fH s1H s1L hs1 hmem1') + | ok _ => simp only [SumExceptRel] at hr + | inr aH => + cases rL with + | error _ => simp only [SumExceptRel] at hr + | ok aL => + simp only [SumExceptRel] at hr + simp only [holCaseSum] + refine mrelStep_bindE_mem (withoutPreemption_step_equiv (hmError aH aL s1H s1L hr hs1 hmem1' (leanLiftE_some_mem hmem1L))) + fun eH eL he s2H s2L hs2 hmem2 => ?_ + have hmem2' : (eH, s2H) ∈ (mErrorH aH s1H).1 := by + simp only [Exceptions_A.without_preemption, holLiftE, holLiftM, holBind, holReturn, + Set.mem_ofPred_eq, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hmem2 + rcases hmem2 with ⟨⟨r0, s0⟩, hm0, rfl, rfl⟩ + exact hm0 + cases eH with + | inl errH => + cases eL with + | error errL => + simp only [SumExceptRel] at he + subst he + exact withoutPreemption_step_equiv (hhError aH errH s1H s2H s2L hs2 hmem1' hmem2') + | ok _ => simp only [SumExceptRel] at he + | inr bH => + cases eL with + | error _ => simp only [SumExceptRel] at he + | ok bL => + simp only [SumExceptRel] at he + exact hmFinalise aH bH bL s1H s2H s2L he hs2 hmem1' hmem2' + +/-- The sufficient-budget interrupt branch uses the upstream event term verbatim. +The refill premise is checked at the state returned by timestamp collection. -/ +theorem handleInterruptEvent_equiv_sufficient (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hbudget : ∀ st, ((), st) ∈ (KHeap_A.update_time_stamp sH).1 → + KHeap_A.read_sc_refill_sufficient st.cur_sc st.consumed_time st = some true) : + MRelStep SR (SumExceptRel Eq Eq) + (Syscall_A.handle_event .Interrupt sH) ((Fl4Spec.handleEvent .interrupt).run sL) := by + change MRelStep SR (SumExceptRel Eq Eq) + (holLiftE (holBind KHeap_A.update_time_stamp + (holKBind (holBind Ipc_A.check_budget (holKBind (Interrupt_A.maybe_handle_interrupt false))))) sH) + ((NonDetE.liftE (do + Fl4Spec.updateTimeStamp + let _ ← Fl4Spec.checkBudget + Fl4Spec.maybeHandleInterrupt false)).run sL) + apply mrelStep_liftE + refine mrelStep_bind_mem (updateTimeStamp_equiv hc hop sH sL hs) fun _ _ _ stH stL ht hm => ?_ + have ⟨hh, hl⟩ := checkBudget_run_sufficient hc hop ht (hbudget stH hm) + have hb : MRelStep SR Eq (Ipc_A.check_budget stH) (Fl4Spec.checkBudget stL) := by + rw [hh, hl] + exact mrel_return rfl stH stL ht + exact mrelStep_bind_mem hb fun _ _ _ s1H s1L hs1 _ => + maybeHandleInterrupt_equiv hop false s1H s1L hs1 + +/-- Interrupt entry retains the upstream event and preemption-handling terms and +uses the FL4-compatible activation term. -/ +def call_kernel_interrupt_p : HolNonDet (Structures_A.state ZH) Unit := + holBind (holHandleE (Syscall_A.handle_event .Interrupt) + (fun _ => Exceptions_A.without_preemption Syscall_A.preemption_path)) + (holKBind (holBind Schedule_A.schedule (holKBind activate_thread_p))) + +theorem patched_callKernel_interrupt_equiv_sufficient (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hbudget : ∀ st, ((), st) ∈ (KHeap_A.update_time_stamp sH).1 → + KHeap_A.read_sc_refill_sufficient st.cur_sc st.consumed_time st = some true) + (hschedule : ∀ st, (Sum.inr (), st) ∈ (Syscall_A.handle_event .Interrupt sH).1 → + ScheduleSafe st) : + MRelStep SR Eq (call_kernel_interrupt_p sH) (Fl4Spec.callKernel .interrupt sL) := by + have hevent := handleInterruptEvent_equiv_sufficient hc hop hs hbudget + unfold call_kernel_interrupt_p Fl4Spec.callKernel + refine mrelStep_bind_mem (mrelStep_handleE_mem (Re' := Eq) hevent ?_) ?_ + · intro eH _ _ stH _ _ hmem + change (Sum.inl eH, stH) ∈ (holLiftE _ sH).1 at hmem + simp [holLiftE, holLiftM, holBind, holReturn] at hmem + · intro resultH _ _ stH stL hst hmem + change _ ∈ (holHandleE _ _ sH).1 at hmem + obtain ⟨⟨eventResult, eventState⟩, he, hcont⟩ := hmem + cases eventResult with + | inl _ => + change _ ∈ (holLiftE _ sH).1 at he + simp [holLiftE, holLiftM, holBind, holReturn] at he + | inr value => + cases value + change _ ∈ (holReturnOk () eventState).1 at hcont + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hcont + rcases hcont with ⟨_, rfl⟩ + exact mrelStep_bind_mem (schedule_equiv hc hop hst (hschedule stH he)) + fun _ _ _ s1H s1L hs1 _ => patched_activateThread_equiv hop s1H s1L hs1 + +theorem getCapReg_equiv (reg : MachineTypes.register) : + MRel SR Eq (Syscall_A.get_cap_reg reg) (Fl4Spec.getCapReg (embRegister reg)) := by + unfold Syscall_A.get_cap_reg Fl4Spec.getCapReg + simp only [holFunApp] + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ hs => hs.curThread_eq.symm) fun ctH ctL hct => ?_ + subst hct + unfold holLiftM NonDet.liftM + exact mrel_bind (asUser_equiv (getRegister_equiv reg) ctH) fun _ _ hd => by + subst hd + exact mrel_return rfl + +abbrev InvocationLookupH := CslotPtr × Structures_A.cap × List (Structures_A.cap × CslotPtr) × Option ObjRef +abbrev InvocationLookupL := CslotPtr × Cap × List (Cap × CslotPtr) × Option ObjRef + +def invocation_lookup_p (thread : ObjRef) (cptr : CapRef) (info : Structures_A.message_info) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.fault InvocationLookupH) := + holBindE (Exceptions_A.cap_fault_on_failure (holOfBl (w := 64) cptr) false + (lookup_cap_and_slot_p thread cptr)) fun (cap, slot) => + holBindE (holLiftE (Patched.lookupIpcBuffer false thread)) fun buffer => + holBindE (lookup_extra_caps_p thread buffer info) fun caps => + holReturnOk (slot, cap, caps, buffer) + +def invocationLookup (thread : ObjRef) (cptr : CapRef) (info : MessageInfo) : + FMonad ZL InvocationLookupL := do + let (cap, slot) ← Fl4Spec.capFaultOnFailure (Fl4Spec.ofBl cptr) false + (Fl4Spec.lookupCapAndSlot thread cptr) + let buffer ← NonDetE.liftE (Fl4Spec.lookupIpcBuffer false thread) + let caps ← Fl4Spec.lookupExtraCaps thread buffer info + NonDetE.returnOk (slot, cap, caps, buffer) + +def invocation_decode_p (huge firstPhase : Bool) (thread : ObjRef) + (info : Structures_A.message_info) (input : InvocationLookupH) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.syscall_error Invocations_A.invocation) := + let (slot, cap, caps, buffer) := input + holBindE (holLiftE (Tcb_A.get_mrs thread buffer info)) fun args => + decode_invocation_p huge firstPhase info.mi_label args slot cap caps + +def handle_invocation_p (huge calling blocking canDonate firstPhase : Bool) (cptr : CapRef) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holBindE (holLiftE (holGets fun s : Structures_A.state ZH => s.cur_thread)) fun thread => + holBindE (Exceptions_A.without_preemption (Ipc_A.get_message_info thread)) fun info => + Syscall_A.syscall + (invocation_lookup_p thread cptr info) + (fun fault => holWhen blocking (handle_fault_p thread fault)) + (invocation_decode_p huge firstPhase thread info) + (fun err => holWhen calling (Patched.reply_from_kernel thread (ExceptionTypes_A.msg_from_syscall_error err))) + (fun oper => + holBindE (Exceptions_A.without_preemption (KHeap_A.set_thread_state thread .Restart)) (holKBind + (holBindE (perform_invocation_p blocking calling canDonate oper) fun reply => + Exceptions_A.without_preemption + (holBind (KHeap_A.get_thread_state thread) fun state => + match state with + | .Restart => + holBind (holWhen calling (Patched.reply_from_kernel thread (0, reply))) (holKBind + (KHeap_A.set_thread_state thread .Running)) + | _ => holReturn ())))) + +/-- [P] Decode and perform guards apply after successful lookup, argument +collection, decode, and the transition to Restart. -/ +def HandleInvSafe (huge firstPhase : Bool) (cptr : CapRef) (sH : Structures_A.state ZH) : Prop := + ∀ info s0, (info, s0) ∈ (Ipc_A.get_message_info sH.cur_thread sH).1 → + ∀ input s1, (Sum.inr input, s1) ∈ (invocation_lookup_p sH.cur_thread cptr info s0).1 → + (∀ args t, (args, t) ∈ (Tcb_A.get_mrs sH.cur_thread input.2.2.2 info s1).1 → + ReferenceBaseCarriers t ∧ BaseDecodeInputs input.2.1 args input.2.2.1) ∧ + (∀ oper s2, (Sum.inr oper, s2) ∈ (invocation_decode_p huge firstPhase sH.cur_thread info input s1).1 → + ∀ s3, ((), s3) ∈ (KHeap_A.set_thread_state sH.cur_thread .Restart s2).1 → + PerformInvSafe oper s3) + +/-- [P] Only reached FL4 decoder calls observe the supplied huge-page feature. -/ +def InvocationPlatformSafe (huge : Bool) (cptr : CapRef) (sL : State ZL) : Prop := + ∀ info s0, (info, s0) ∈ (Fl4Spec.getMessageInfo sL.curThread sL).1 → + ∀ input s1, (Except.ok input, s1) ∈ ((invocationLookup sL.curThread cptr info).run s0).1 → + ∀ args t, (args, t) ∈ (Fl4Spec.getMrs sL.curThread input.2.2.2 info s1).1 → + t.archState.x64Plat.hugePages = huge + +theorem patched_handleInvocation_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (huge calling blocking canDonate firstPhase : Bool) (cptr : CapRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : HandleInvSafe huge firstPhase cptr sH) + (hplatform : InvocationPlatformSafe huge cptr sL) : + MRelStep SR (SumExceptRel Eq Eq) + (handle_invocation_p huge calling blocking canDonate firstPhase cptr sH) + ((Fl4Spec.handleInvocation calling blocking canDonate firstPhase cptr).run sL) := by + unfold handle_invocation_p Fl4Spec.handleInvocation + refine mrelStep_bindE_mem_both + (mrelStep_liftE (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH sL hs)) + fun tH tL ht s0H s0L hs0 hm0 hm0L => ?_ + subst ht + have hstartH : (tH, s0H) ∈ (holGets (fun s : Structures_A.state ZH => s.cur_thread) sH).1 := by + rcases hm0 with ⟨⟨a, t⟩, hread, hret⟩ + rcases Prod.mk.inj (Set.mem_singleton_iff.mp hret) with ⟨hr, rfl⟩ + cases hr + exact hread + obtain ⟨htread, hsread⟩ := holGets_mem _ _ _ _ hstartH + subst tH s0H + have hstartL := leanLiftE_some_mem hm0L + have hstateL := (Prod.mk.inj (Set.mem_singleton_iff.mp hstartL)).2 + subst s0L + refine mrelStep_bindE_mem_both + (withoutPreemption_step_equiv (getMessageInfo_equiv sH.cur_thread sH sL hs0)) + fun infoH infoL hinfo s1H s1L hs1 hm1 hm1L => ?_ + subst hinfo + have hm1' : (infoH, s1H) ∈ (Ipc_A.get_message_info sH.cur_thread sH).1 := by + rcases hm1 with ⟨⟨a, t⟩, hread, hret⟩ + rcases Prod.mk.inj (Set.mem_singleton_iff.mp hret) with ⟨hr, rfl⟩ + cases hr + exact hread + have hm1L' := leanLiftE_some_mem hm1L + let Rphase1 : InvocationLookupH → InvocationLookupL → Prop := + ProdRel Eq (ProdRel (FunRel embCap) (ProdRel (ListRel (ProdRel (FunRel embCap) Eq)) Eq)) + refine syscall_step_equiv (Ra := Rphase1) (Rb := FunRel embInvocation) (Rc := Eq) ?_ ?_ ?_ ?_ ?_ + · change MRelStep SR (SumExceptRel (FunRel embFault) Rphase1) + (invocation_lookup_p sH.cur_thread cptr infoH s1H) + ((invocationLookup sH.cur_thread cptr (embMessageInfo infoH)).run s1L) + unfold invocation_lookup_p invocationLookup + refine (mrele_bindE (capFaultOnFailure_equiv (holOfBl (w := 64) cptr) false + (patched_lookupCapAndSlot_equiv sH.cur_thread cptr)) ?_) s1H s1L hs1 + rintro ⟨capH, slotH⟩ ⟨capL, slotL⟩ ⟨hcap, hslot⟩ + subst hcap + subst hslot + refine mrele_bindE (mrele_liftE (patched_lookupIpcBuffer_equiv false sH.cur_thread)) + fun bufH bufL hbuf => ?_ + subst hbuf + refine mrele_bindE (patched_lookupExtraCaps_equiv sH.cur_thread bufH infoH) + fun exH exL hex => ?_ + exact mrele_returnOk ⟨rfl, rfl, hex, rfl⟩ + · intro fH s2H s2L hs2 _ + exact (mrel_when Iff.rfl fun _ => patched_handleFault_equiv hop sH.cur_thread fH) s2H s2L hs2 + · rintro ⟨slot, cap, caps, buf⟩ ⟨slL, capL, capsL, bufL⟩ s2H s2L + ⟨hsl, hcap, hcaps, hbuf⟩ hs2 hlookup hlookupL + subst hsl + subst hcap + subst hbuf + have hcapsEq : capsL = caps.map (fun p => (embCap p.1, p.2)) := by + have aux : ∀ {cs : List (Structures_A.cap × CslotPtr)} {ds : List (Cap × CslotPtr)}, + ListRel (ProdRel (FunRel embCap) Eq) cs ds → ds = cs.map (fun p => (embCap p.1, p.2)) := by + intro cs ds hr + induction hr with + | nil => rfl + | cons hd _ ih => + rcases hd with ⟨h1, h2⟩ + exact congrArg₂ List.cons (Prod.ext h1 h2.symm) ih + exact aux hcaps + subst hcapsEq + have hd := (hsafe infoH s1H hm1' (slot, cap, caps, buf) s2H hlookup).1 + have hp := hplatform (embMessageInfo infoH) s1L (hs.curThread_eq ▸ hm1L') + (slot, embCap cap, caps.map (fun p => (embCap p.1, p.2)), buf) s2L (hs.curThread_eq ▸ hlookupL) + refine mrelStep_bindE_mem_both (mrelStep_liftE (getMrs_equiv sH.cur_thread buf infoH s2H s2L hs2)) + fun argsH argsL hargs stH stL hst hargsH hargsL => ?_ + subst hargs + obtain ⟨hb, hi⟩ := hd argsH stH (by + rcases hargsH with ⟨⟨a, t⟩, hread, hret⟩ + rcases Prod.mk.inj (Set.mem_singleton_iff.mp hret) with ⟨hr, rfl⟩ + cases hr + exact hread) + have heq := hp argsH stL (hs.curThread_eq ▸ leanLiftE_some_mem hargsL) + rw [← heq] + exact patched_decodeInvocation_equiv hc hop firstPhase infoH.mi_label argsH cptr slot cap caps buf + hst (hst.baseCarriers_iff.mpr hb) hi + · intro _ err _ s3H s3L hs3 _ _ + exact (mrel_when Iff.rfl fun _ => by + rw [msgFromSyscallError_eq] + exact patched_replyFromKernel_equiv sH.cur_thread _) s3H s3L hs3 + · intro input opH opL s2H s3H s3L hopEq hs3 hlookup hdecode + subst hopEq + refine mrelStep_kbindE_mem + (withoutPreemption_step_equiv (setThreadState_equiv sH.cur_thread .Restart s3H s3L hs3)) + fun result s4H s4L hs4 hm4 => ?_ + cases result + have hm4' : ((), s4H) ∈ (KHeap_A.set_thread_state sH.cur_thread .Restart s3H).1 := by + rcases hm4 with ⟨⟨a, t⟩, hrun, hret⟩ + rcases Prod.mk.inj (Set.mem_singleton_iff.mp hret) with ⟨hr, rfl⟩ + cases hr + exact hrun + have hperf := (hsafe infoH s1H hm1' input s2H hlookup).2 opH s3H hdecode s4H hm4' + refine mrelStep_bindE_mem + (patched_performInvocation_equiv hc hop blocking calling canDonate opH hs4 hperf) + fun repH repL hrep s5H s5L hs5 _ => ?_ + subst hrep + refine (withoutPreemption_equiv ?_) s5H s5L hs5 + refine mrel_bind (getThreadState_equiv sH.cur_thread) fun stH stL hst => ?_ + subst hst + cases stH with + | Restart => + refine mrel_kbind (mrel_when Iff.rfl fun _ => + patched_replyFromKernel_equiv sH.cur_thread (0, repH)) ?_ + exact setThreadState_equiv sH.cur_thread .Running + | _ => exact mrel_return rfl + +def lookup_reply_p : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.fault Structures_A.cap) := + holBindE (holLiftE (Syscall_A.get_cap_reg MachineTypes.replyRegister)) fun cref => + holBindE (holLiftE (holGets Structures_A.abstract_state_ext.cur_thread)) fun ct => + holBindE (Exceptions_A.cap_fault_on_failure (holOfBl (w := 64) cref) true (lookup_cap_p ct cref)) fun cap => + if Structures_A.is_reply_cap cap = true then holReturnOk cap + else holThrowError (.CapFault (holOfBl (w := 64) cref) true (.MissingCapability 0)) + +theorem patched_lookupReply_equiv : + MRelE SR (FunRel embFault) (FunRel embCap) + lookup_reply_p Fl4Spec.lookupReply := by + unfold lookup_reply_p Fl4Spec.lookupReply + refine mrele_bindE (mrele_liftE (getCapReg_equiv MachineTypes.replyRegister)) fun crH crL hcr => ?_ + subst hcr + refine mrele_bindE (mrele_liftE (mrel_gets (Ra := Eq) fun _ _ hs => hs.curThread_eq.symm)) + fun ctH ctL hct => ?_ + subst hct + refine mrele_bindE (capFaultOnFailure_equiv (holOfBl (w := 64) crH) true + (patched_lookupCap_equiv ctH crH)) fun cH cL hc => ?_ + subst hc + cases cH <;> first | exact mrele_returnOk rfl | exact mrele_throwError rfl + + +def receive_cptr (thread : ObjRef) : HolNonDet (Structures_A.state ZH) CapRef := + holLiftM Machine_A.data_to_cptr + (KHeap_A.as_user thread (MachineOps.getRegister Machine_A.cap_register)) + +private def recvCptrL (thread : ObjRef) : SMonad ZL CapRef := + NonDet.liftM Fl4Spec.dataToCptr + (Fl4Spec.asUser thread (Fl4Spec.getRegister Fl4Spec.cap_register)) + +private theorem recvCptr_equiv (thread : ObjRef) : + MRel SR Eq (receive_cptr thread) (recvCptrL thread) := by + unfold receive_cptr recvCptrL holLiftM NonDet.liftM + exact mrel_bind (asUser_equiv (getRegister_equiv Machine_A.cap_register) thread) fun _ _ h => by + subst h + exact mrel_return rfl + +def receive_lookup (thread : ObjRef) (cptr : CapRef) : + HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.fault Structures_A.cap) := + Exceptions_A.cap_fault_on_failure (holOfBl (w := 64) cptr) true (lookup_cap_p thread cptr) + + +def receive_from_cap (blocking canReply : Bool) (thread : ObjRef) (cptr : CapRef) + (cap : Structures_A.cap) : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.fault Unit) := + let failCap : HolNonDet (Structures_A.state ZH) (Sum ExceptionTypes_A.fault Unit) := + holThrowError (.CapFault (holOfBl (w := 64) cptr) true (.MissingCapability 0)) + match cap with + | .EndpointCap _ _ rights => + if holMember CapRights_A.AllowRecv rights = true then + holBindE (if canReply then lookup_reply_p else holReturnOk .NullCap) + (fun replyCap => holLiftE (receive_ipc_p thread cap blocking replyCap)) + else failCap + | .NotificationCap ptr _ rights => + if holMember CapRights_A.AllowRecv rights = true then + holBindE (holLiftE (KHeap_A.get_sk_obj_ref Structures_A.kernel_object.Notification + Structures_A.notification_ext.ntfn_bound_tcb ptr)) fun bound => + if bound = some thread ∨ bound = none then + holLiftE (Ipc_A.receive_signal thread cap blocking) + else failCap + else failCap + | _ => failCap + +/-- Receive through the adapted slot map, endpoint transfer and fault delivery. -/ +def handle_recv_p (blocking canReply : Bool) : HolNonDet (Structures_A.state ZH) Unit := + holBind (holGets fun s => s.cur_thread) fun thread => + holBind (receive_cptr thread) fun cptr => + holCatch + (holBindE (receive_lookup thread cptr) (receive_from_cap blocking canReply thread cptr)) + (handle_fault_p thread) + +/-- Every reached receive-capability lookup returns a notification with receive +rights. Every reached binding read permits the current thread. -/ +def NotificationReceiveSafe (s : Structures_A.state ZH) : Prop := + ∀ cptr st, (cptr, st) ∈ (receive_cptr s.cur_thread s).1 → + (∀ fault out, (Sum.inl fault, out) ∉ (receive_lookup s.cur_thread cptr st).1) ∧ + (∀ cap out, (Sum.inr cap, out) ∈ (receive_lookup s.cur_thread cptr st).1 → + ∃ ptr badge rights, cap = .NotificationCap ptr badge rights ∧ + CapRights_A.AllowRecv ∈ rights ∧ + ∀ bound next, + (bound, next) ∈ (KHeap_A.get_sk_obj_ref Structures_A.kernel_object.Notification + Structures_A.notification_ext.ntfn_bound_tcb ptr out).1 → + bound = some s.cur_thread ∨ bound = none) + + +theorem patched_handleRecv_equiv_notification (hop : OpaqueRel RestRel) (blocking canReply : Bool) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : NotificationReceiveSafe sH) : + MRelStep SR Eq (handle_recv_p blocking canReply sH) (Fl4Spec.handleRecv blocking canReply sL) := by + unfold handle_recv_p receive_from_cap Fl4Spec.handleRecv + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH sL hs) + fun tH tL ht s0H s0L hs0 hm0 => ?_ + subst ht + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm0 + obtain ⟨hthread, hstate⟩ := hm0 + subst tH + subst s0H + refine mrelStep_bind_mem (recvCptr_equiv sH.cur_thread sH s0L hs0) + fun cH cL hc s1H s1L hs1 hm1 => ?_ + subst hc + obtain ⟨herrors, hsuccess⟩ := hsafe cH s1H hm1 + refine mrelStep_catch_mem (Re := FunRel embFault) ?_ ?_ + · refine mrelStep_bindE_mem + (capFaultOnFailure_equiv (holOfBl (w := 64) cH) true + (patched_lookupCap_equiv sH.cur_thread cH) s1H s1L hs1) + fun capH capL hcap s2H s2L hs2 hm2 => ?_ + subst hcap + obtain ⟨ptr, badge, rights, rfl, hrights, hallow⟩ := hsuccess capH s2H hm2 + have hrH := (holMember_eq_true _ _).mpr hrights + have hrL : Fl4Spec.AllowRecv ∈ embRightsSet rights := + (embRightsSet_mem _ _).mpr hrights + simp only [embCap, hrH, hrL, ↓reduceIte] + refine mrelStep_bindE_mem (mrelStep_liftE (getNtfnObjRef_equiv + (fH := Structures_A.notification_ext.ntfn_bound_tcb) + (fL := Notification.ntfnBoundTcb) (fun _ => rfl) ptr s2H s2L hs2)) + fun bH bL hb s3H s3L hs3 hm3 => ?_ + subst hb + have hm : (bH,s3H) ∈ (KHeap_A.get_sk_obj_ref Structures_A.kernel_object.Notification + Structures_A.notification_ext.ntfn_bound_tcb ptr s2H).1 := by + rcases hm3 with ⟨⟨v, st⟩, hrun, hret⟩ + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hret + rcases hret with ⟨rfl, rfl⟩ + exact hrun + simp only [hallow bH s3H hm, ↓reduceIte] + exact mrelStep_liftE + (receiveSignal_equiv hop sH.cur_thread (.NotificationCap ptr badge rights) blocking s3H s3L hs3) + · intro fH _ _ stH _ _ hm + rcases hm with ⟨⟨capH, s2H⟩, hlookup, hcont⟩ + cases capH with + | inl err => exact False.elim (herrors err s2H hlookup) + | inr cap => + obtain ⟨ptr, badge, rights, rfl, hrights, hallow⟩ := hsuccess cap s2H hlookup + have hrH := (holMember_eq_true _ _).mpr hrights + simp only [hrH, ↓reduceIte] at hcont + rcases hcont with ⟨⟨bound, s3H⟩, hbound, hbranch⟩ + cases bound with + | inl err => + simp [holLiftE, holLiftM, holBind, holReturn] at hbound + | inr value => + have hvalue : (value, s3H) ∈ (KHeap_A.get_sk_obj_ref Structures_A.kernel_object.Notification + Structures_A.notification_ext.ntfn_bound_tcb ptr s2H).1 := by + rcases hbound with ⟨⟨v, st⟩, hrun, hret⟩ + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hret + rcases hret with ⟨rfl, rfl⟩ + exact hrun + simp only [hallow value s3H hvalue, ↓reduceIte] at hbranch + simp [holLiftE, holLiftM, holBind, holReturn] at hbranch + + +/-- State-indexed, run-guarded safety predicate for `handle_recv_p`. -/ +def HandleRecvSafe (isBlocking canReply : Bool) (sH : Structures_A.state ZH) : Prop := + ∀ epCptr s1, (epCptr, s1) ∈ (receive_cptr sH.cur_thread sH).1 → + ∀ ref badge rights s2, + (Sum.inr (.EndpointCap ref badge rights), s2) ∈ + (receive_lookup sH.cur_thread epCptr s1).1 → + holMember CapRights_A.AllowRecv rights = true → + if canReply then + ∀ rc s3, (Sum.inr rc, s3) ∈ (lookup_reply_p s2).1 → + ReceiveIpcSafe sH.cur_thread (.EndpointCap ref badge rights) isBlocking rc s3 + else + ReceiveIpcSafe sH.cur_thread (.EndpointCap ref badge rights) isBlocking .NullCap s2 + +theorem patched_handleRecv_equiv (hop : OpaqueRel RestRel) + (isBlocking canReply : Bool) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : HandleRecvSafe isBlocking canReply sH) : + MRelStep SR Eq + (handle_recv_p isBlocking canReply sH) + (Fl4Spec.handleRecv isBlocking canReply sL) := by + unfold handle_recv_p receive_from_cap Fl4Spec.handleRecv + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH sL hs) + fun tH tL ht s0H s0L hs0 hm0 => ?_; subst ht + obtain ⟨htEq, hs0eq⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm0) + subst tH s0H + refine mrelStep_bind_mem (recvCptr_equiv sH.cur_thread sH s0L hs0) + fun epH epL hep s1H s1L hs1 hm1 => ?_ + subst hep + refine mrelStep_catch_mem (Re := FunRel embFault) ?_ + (fun fH fL hf sF1 sF2 hsF _ => by + subst hf + exact patched_handleFault_equiv hop sH.cur_thread fH sF1 sF2 hsF) + refine mrelStep_bindE_mem (capFaultOnFailure_equiv (holOfBl (w := 64) epH) true + (patched_lookupCap_equiv sH.cur_thread epH) s1H s1L hs1) fun capH capL hcap s2H s2L hs2 hm2 => ?_ + subst hcap + cases capH with + | EndpointCap ref badge rights => + dsimp only [embCap] + have hrecv : holMember CapRights_A.AllowRecv rights = true ↔ + Fl4Spec.AllowRecv ∈ embRightsSet rights := by + rw [holMember_eq_true] + exact (embRightsSet_mem CapRights_A.AllowRecv rights).symm + by_cases hR : holMember CapRights_A.AllowRecv rights = true + · have hRL := hrecv.mp hR + simp only [hR, hRL, ↓reduceIte] + have hsr := hsafe epH s1H hm1 ref badge rights s2H hm2 hR + cases canReply with + | true => + simp only [ite_true] at hsr ⊢ + refine mrelStep_bindE_mem (patched_lookupReply_equiv s2H s2L hs2) + fun rcH rcL hrc s3H s3L hs3 hm3 => ?_; subst hrc + exact mrelStep_liftE (patched_receiveIpc_equiv hop sH.cur_thread (.EndpointCap ref badge rights) isBlocking rcH hs3 (hsr rcH s3H hm3)) + | false => + simp only [Bool.false_eq_true, ite_false] at hsr ⊢ + refine mrelStep_bindE_mem (mrele_returnOk (Re := FunRel embFault) (Ra := FunRel embCap) rfl s2H s2L hs2) + fun rcH rcL hrc s3H s3L hs3 hm3 => ?_; subst hrc + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hm3 + obtain ⟨hrcEq, hs3eq⟩ := hm3; subst hrcEq; subst s3H + exact mrelStep_liftE (patched_receiveIpc_equiv hop sH.cur_thread (.EndpointCap ref badge rights) isBlocking .NullCap hs3 hsr) + · have hRF : holMember CapRights_A.AllowRecv rights = false := Bool.eq_false_iff.mpr hR + have hRLF := mt hrecv.mpr hR + simp only [hRF, hRLF, Bool.false_eq_true, ↓reduceIte] + exact mrele_throwError (Re := FunRel embFault) rfl s2H s2L hs2 + | NotificationCap ref badge rights => + dsimp only [embCap] + have hrecv : holMember CapRights_A.AllowRecv rights = true ↔ + Fl4Spec.AllowRecv ∈ embRightsSet rights := by + rw [holMember_eq_true] + exact (embRightsSet_mem CapRights_A.AllowRecv rights).symm + by_cases hR : holMember CapRights_A.AllowRecv rights = true + · have hRL := hrecv.mp hR + simp only [hR, hRL, ↓reduceIte] + refine mrelStep_bindE_mem + (mrelStep_liftE (getNtfnObjRef_equiv (fH := Structures_A.notification_ext.ntfn_bound_tcb) + (fL := Notification.ntfnBoundTcb) (fun _ => rfl) ref s2H s2L hs2)) + fun btH btL hbt s3H s3L hs3 _ => ?_ + subst hbt + by_cases hbound : btH = some sH.cur_thread ∨ btH = none + · simp only [hbound, ↓reduceIte] + exact mrelStep_liftE (receiveSignal_equiv hop sH.cur_thread (.NotificationCap ref badge rights) isBlocking s3H s3L hs3) + · simp only [hbound, ↓reduceIte] + exact mrele_throwError (Re := FunRel embFault) rfl s3H s3L hs3 + · have hRF : holMember CapRights_A.AllowRecv rights = false := Bool.eq_false_iff.mpr hR + have hRLF := mt hrecv.mpr hR + simp only [hRF, hRLF, Bool.false_eq_true, ↓reduceIte] + exact mrele_throwError (Re := FunRel embFault) rfl s2H s2L hs2 + | _ => + dsimp only [embCap] + exact mrele_throwError (Re := FunRel embFault) rfl s2H s2L hs2 + +/-- The nonblocking wait route uses the FL4-compatible receive lookup. -/ +def handle_nbwait_p : HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holBindE (holLiftE KHeap_A.update_time_stamp) fun _ => + holBindE (holLiftE Ipc_A.check_budget_restart) fun restart => + holWhenE restart (holLiftE (handle_recv_p false false)) + +def NbWaitSafe (s : Structures_A.state ZH) : Prop := + ∀ st, ((), st) ∈ (KHeap_A.update_time_stamp s).1 → + KHeap_A.read_sc_refill_sufficient st.cur_sc st.consumed_time st = some true ∧ + ∀ next, (true, next) ∈ (Ipc_A.check_budget_restart st).1 → + NotificationReceiveSafe next + +private theorem holLiftE_some_mem {σ ε α : Type} {m : HolNonDet σ α} + {s s' : σ} {a : α} (h : (Sum.inr a, s') ∈ (holLiftE (ε := ε) m s).1) : + (a, s') ∈ (m s).1 := by + rcases h with ⟨⟨x, st⟩, hrun, hret⟩ + simp only [holReturn, Set.mem_singleton_iff, Prod.mk.injEq, Sum.inr.injEq] at hret + obtain ⟨rfl, rfl⟩ := hret + exact hrun + +private theorem holLiftE_no_error {σ ε α : Type} {m : HolNonDet σ α} + {s s' : σ} {e : ε} (h : (Sum.inl e, s') ∈ (holLiftE m s).1) : False := by + simp [holLiftE, holLiftM, holBind, holReturn] at h + +theorem patched_handleNbWait_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hsafe : NbWaitSafe sH) : + MRelStep SR (SumExceptRel Eq Eq) (handle_nbwait_p sH) + ((Fl4Spec.handleEvent (.syscallEvent .sysNBWait)).run sL) := by + unfold handle_nbwait_p + change MRelStep SR (SumExceptRel Eq Eq) + (holBindE (holLiftE KHeap_A.update_time_stamp) (fun _ => + holBindE (holLiftE Ipc_A.check_budget_restart) fun restart => + holWhenE restart (holLiftE (handle_recv_p false false))) sH) + ((do + NonDetE.liftE Fl4Spec.updateTimeStamp + let restart ← NonDetE.liftE Fl4Spec.checkBudgetRestart + NonDetE.whenE restart (NonDetE.liftE (Fl4Spec.handleRecv false false)) : + PMonad ZL Unit).run sL) + refine mrelStep_kbindE_mem (mrelStep_liftE (updateTimeStamp_equiv hc hop sH sL hs)) + fun _ s1H s1L hs1 hm1 => ?_ + obtain ⟨hbudget, hrecv⟩ := hsafe s1H (holLiftE_some_mem hm1) + refine mrelStep_bindE_mem + (mrelStep_liftE (checkBudgetRestart_equiv_sufficient hc hop hs1 hbudget)) + fun rH rL hr s2H s2L hs2 hm2 => ?_ + subst hr + cases rH with + | true => + exact mrelStep_liftE (patched_handleRecv_equiv_notification hop false false hs2 + (hrecv s2H (holLiftE_some_mem hm2))) + | false => exact mrele_returnOk rfl s2H s2L hs2 + +private theorem nbWait_no_error {s s' : Structures_A.state ZH} + (h : (Sum.inl (), s') ∈ (handle_nbwait_p s).1) : False := by + rcases h with ⟨⟨timestamp, s1⟩, htime, hrest⟩ + cases timestamp with + | inl err => exact holLiftE_no_error htime + | inr _ => + rcases hrest with ⟨⟨budget, s2⟩, hbudget, hrecv⟩ + cases budget with + | inl err => exact holLiftE_no_error hbudget + | inr result => + cases result + · simp [holWhenE, holReturnOk, holReturn] at hrecv + · exact holLiftE_no_error hrecv + +def call_kernel_nbwait_p : HolNonDet (Structures_A.state ZH) Unit := + holBind (holHandleE handle_nbwait_p (fun _ => Exceptions_A.without_preemption Syscall_A.preemption_path)) + (holKBind (holBind Schedule_A.schedule (holKBind activate_thread_p))) + +theorem patched_callKernel_nbwait_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : NbWaitSafe sH) + (hschedule : ∀ st, (Sum.inr (), st) ∈ (handle_nbwait_p sH).1 → ScheduleSafe st) : + MRelStep SR Eq (call_kernel_nbwait_p sH) (Fl4Spec.callKernel (.syscallEvent .sysNBWait) sL) := by + unfold call_kernel_nbwait_p Fl4Spec.callKernel + refine mrelStep_bind_mem (mrelStep_handleE_mem (Re' := Eq) + (patched_handleNbWait_equiv hc hop hs hsafe) ?_) ?_ + · intro eH _ _ s1H _ _ hm + cases eH + exact False.elim (nbWait_no_error hm) + · intro resultH _ _ s2H s2L hs2 hm + obtain ⟨⟨eventResult, eventState⟩, he, hcont⟩ := hm + cases eventResult with + | inl e => + cases e + exact False.elim (nbWait_no_error he) + | inr value => + cases value + change _ ∈ (holReturnOk () eventState).1 at hcont + simp only [holReturnOk, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hcont + obtain ⟨_, rfl⟩ := hcont + exact mrelStep_bind_mem (schedule_equiv hc hop hs2 (hschedule s2H he)) + fun _ _ _ s3H s3L hs3 _ => patched_activateThread_equiv hop s3H s3L hs3 + + +def HandleYieldSafe (s : Structures_A.state ZH) : Prop := + ∀ ptr s1, (ptr, s1) ∈ (holGets Structures_A.abstract_state_ext.cur_sc s).1 → + ∀ sc s2, (sc, s2) ∈ (KHeap_A.get_sched_context ptr s1).1 → + ∀ used s3, (used, s3) ∈ (holGets Structures_A.abstract_state_ext.consumed_time s2).1 → + ∀ head s4, (head, s4) ∈ (KHeap_A.get_refill_head ptr s3).1 → + ChargeBudgetSafe head.r_amount s4 + +theorem handleYield_equiv (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : HandleYieldSafe sH) : + MRelStep SR Eq (Syscall_A.handle_yield sH) (Fl4Spec.handleYield sL) := by + unfold Syscall_A.handle_yield Fl4Spec.handleYield + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) sH sL hs) + fun pH pL hp s1H s1L hs1 hm1 => ?_ + subst hp + refine mrelStep_bind_mem (getSchedContext_equiv pH s1H s1L hs1) fun scH scL hsc s2H s2L hs2 hm2 => ?_ + subst hsc + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.consumedTime_eq.symm) s2H s2L hs2) + fun uH uL hu s3H s3L hs3 hm3 => ?_ + subst hu + refine mrelStep_bind_mem (getRefillHead_equiv pH s3H s3L hs3) fun hdH hdL hhd s4H s4L hs4 hm4 => ?_ + subst hhd + refine mrelStep_bind_mem (chargeBudget_equiv_without_timeout hop hdH.r_amount hs4 + (hsafe pH s1H hm1 scH s2H hm2 uH s3H hm3 hdH s4H hm4)) fun _ _ _ s5H s5L hs5 _ => ?_ + exact updateSchedContext_equiv (fun sc => by rfl) pH s5H s5L hs5 + + +def preemption_path_p : HolNonDet (Structures_A.state ZH) Unit := + holBind (holGets Structures_A.abstract_state_ext.cur_thread) fun ct => + holBind (holGets (KHeap_A.schedulable ct)) fun sched => + holBind + (if sched = true then holBind check_budget_p (holKBind (holReturn ())) + else + holBind (holGets Structures_A.abstract_state_ext.cur_sc) fun csc => + holBind (KHeap_A.get_sc_active csc) fun active => + if active = true then + holBind (holGets Structures_A.abstract_state_ext.consumed_time) fun consumed => + charge_budget_p consumed false + else + holModify (Structures_A.abstract_state.consumed_time_update (fun _ => 0))) + (holKBind (Interrupt_A.maybe_handle_interrupt true)) + +/-- [P] Preemption charges only after the reached active-context read. -/ +def PreemptionSafe (s : Structures_A.state ZH) : Prop := + if KHeap_A.schedulable s.cur_thread s = true then CheckBudgetSafe s + else ∀ t, (true, t) ∈ (KHeap_A.get_sc_active s.cur_sc s).1 → + ChargeBudgetSafe t.consumed_time t + +theorem patched_preemptionPath_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : PreemptionSafe sH) : + MRelStep SR Eq (preemption_path_p sH) (Fl4Spec.preemptionPath sL) := by + unfold preemption_path_p Fl4Spec.preemptionPath + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm) sH sL hs) + fun ctH ctL hct s1H s1L hs1 hm1 => ?_ + subst hct + obtain ⟨hct', hs1eq⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm1) + subst hct'; subst s1H + refine mrelStep_bind_mem + (mrel_gets (fH := KHeap_A.schedulable sH.cur_thread) + (fL := Fl4Spec.schedulable sH.cur_thread) (Ra := Eq) + (fun _ _ h => (schedulable_eq h sH.cur_thread).symm) sH s1L hs1) + fun scH scL hsc s2H s2L hs2 hm2 => ?_ + subst hsc + obtain ⟨hsc', hs2eq⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm2) + subst hsc'; subst s2H + cases hsched : KHeap_A.schedulable sH.cur_thread sH with + | true => + simp only [ite_true] + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (patched_checkBudget_equiv hc hop hs2 (by simpa [PreemptionSafe, hsched] using hsafe)) + fun _ _ _ s3H s3L hs3 _ => ?_ + simp only [holKBind] + rw [KHeap.holBind_return_left] + exact maybeHandleInterrupt_equiv hop true s3H s3L hs3 + | false => + simp only [Bool.false_eq_true, ite_false] + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.curSc_eq.symm) sH s2L hs2) + fun cscH cscL hcsc s3H s3L hs3 hm3 => ?_ + subst hcsc + obtain ⟨hcsc', hs3eq⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm3) + subst hcsc'; subst s3H + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (getScActive_equiv sH.cur_sc sH s3L hs3) + fun actH actL hact s4H s4L hs4 hm4 => ?_ + subst hact + cases actH with + | true => + simp only [ite_true] + rw [KHeap.holBind_assoc] + refine mrelStep_bind_mem (mrel_gets (Ra := Eq) (fun _ _ h => h.consumedTime_eq.symm) s4H s4L hs4) + fun conH conL hcon s5H s5L hs5 hm5 => ?_ + subst hcon + obtain ⟨hcon', hs5eq⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm5) + subst conH s5H + have hcb : ChargeBudgetSafe s4H.consumed_time s4H := by + have h := hsafe + rw [PreemptionSafe, hsched] at h + exact h s4H hm4 + exact mrelStep_bind_mem (patched_chargeBudget_equiv hop s4H.consumed_time false hs5 hcb) + fun _ _ _ s6H s6L hs6 _ => maybeHandleInterrupt_equiv hop true s6H s6L hs6 + | false => + simp only [Bool.false_eq_true, ite_false] + exact mrelStep_bind_mem ((mrel_modify fun _ _ h => { h with consumedTime_eq := rfl }) s4H s4L hs4) + fun _ _ _ s5H s5L hs5 _ => maybeHandleInterrupt_equiv hop true s5H s5L hs5 + + +theorem handleVmFault_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) + (kind : MachineTypes.vmfault_type) : + MRelE SR (FunRel embFault) Eq (ArchVSpace_A.handle_vm_fault thread kind) + (Fl4Spec.handleVmFault thread (embVMFaultType kind)) := by + unfold ArchVSpace_A.handle_vm_fault Fl4Spec.handleVmFault + refine mrele_bindE (mrele_liftE (mrel_doMachineOp (Hardware.getFaultAddress_equiv hop))) + fun addrH addrL ha => ?_ + subst ha + refine mrele_bindE (mrele_liftE (asUser_equiv + (getRegister_equiv MachineTypes.register.ErrorRegister) thread)) fun errH errL he => ?_ + subst he + cases kind <;> exact mrele_throwError rfl + +theorem handleHypervisorFault_equiv (thread : ObjRef) (fault : MachineTypes.hyp_fault_type) : + MRel SR Eq (Hypervisor_A.handle_hypervisor_fault thread fault) + (Fl4Spec.handleHypervisorFault thread (embHypFaultType fault)) := by + cases fault + exact mrel_return rfl + +/-- [P] Budget charging is checked at the state reached by timestamp collection. -/ +def EventBudgetSafe (s : Structures_A.state ZH) : Prop := + ∀ next, ((), next) ∈ (KHeap_A.update_time_stamp s).1 → CheckBudgetSafe next + +def handle_interrupt_p : HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + Exceptions_A.without_preemption (holBind KHeap_A.update_time_stamp + (holKBind (holBind check_budget_p (holKBind (Interrupt_A.maybe_handle_interrupt false))))) + +theorem patched_handleInterrupt_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hsafe : EventBudgetSafe sH) : + MRelStep SR (SumExceptRel Eq Eq) + (handle_interrupt_p sH) ((Fl4Spec.handleEvent .interrupt).run sL) := by + change MRelStep SR (SumExceptRel Eq Eq) + (holLiftE (holBind KHeap_A.update_time_stamp + (holKBind (holBind check_budget_p (holKBind (Interrupt_A.maybe_handle_interrupt false))))) sH) + ((NonDetE.liftE (do + Fl4Spec.updateTimeStamp + let _ ← Fl4Spec.checkBudget + Fl4Spec.maybeHandleInterrupt false)).run sL) + apply mrelStep_liftE + refine mrelStep_bind_mem (updateTimeStamp_equiv hc hop sH sL hs) fun _ _ _ stH stL ht hm => ?_ + exact mrelStep_bind_mem (patched_checkBudget_equiv hc hop ht (hsafe stH hm)) + fun _ _ _ s1H s1L hs1 _ => maybeHandleInterrupt_equiv hop false s1H s1L hs1 + +def handle_fault_event_p (handler : ObjRef → HolNonDet (Structures_A.state ZH) Unit) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + Exceptions_A.without_preemption (holBind KHeap_A.update_time_stamp (holKBind + (holBind check_budget_restart_p fun restart => + holWhen restart (holBind (holGets fun s => s.cur_thread) handler)))) + +private theorem handleFaultEvent_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + {handlerH : ObjRef → HolNonDet (Structures_A.state ZH) Unit} + {handlerL : ObjRef → SMonad ZL Unit} (hh : ∀ t, MRel SR Eq (handlerH t) (handlerL t)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hsafe : EventBudgetSafe sH) : + MRelStep SR (SumExceptRel Eq Eq) (handle_fault_event_p handlerH sH) + ((Fl4Spec.withoutPreemption (do + Fl4Spec.updateTimeStamp + let restart ← Fl4Spec.checkBudgetRestart + NonDet.when restart (do + let t ← NonDet.gets fun s : State ZL => s.curThread + handlerL t))).run sL) := by + unfold handle_fault_event_p Exceptions_A.without_preemption Fl4Spec.withoutPreemption + apply mrelStep_liftE + refine mrelStep_bind_mem (updateTimeStamp_equiv hc hop sH sL hs) + fun u _ _ s1H s1L hs1 hm1 => ?_ + cases u + refine mrelStep_bind_mem (patched_checkBudgetRestart_equiv hc hop hs1 (hsafe s1H hm1)) + fun rH rL hr s2H s2L hs2 _ => ?_ + subst hr + exact mrel_when Iff.rfl (fun _ => + mrel_bind (mrel_gets (Ra := Eq) (fun _ _ h => h.curThread_eq.symm)) + fun tH tL ht => by subst ht; exact hh tH) s2H s2L hs2 + +def handle_non_syscall_p : Event_H.event → HolNonDet (Structures_A.state ZH) (Sum Unit Unit) + | .UnknownSyscall n => handle_fault_event_p fun t => + handle_fault_p t (.UnknownSyscallException (holOfNat n)) + | .UserLevelFault w1 w2 => handle_fault_event_p fun t => + handle_fault_p t (.UserException (holWordAnd w1 (holWordMask 32)) (holWordAnd w2 (holWordMask 28))) + | .VMFaultEvent kind => handle_fault_event_p fun t => + holCatch (ArchVSpace_A.handle_vm_fault t kind) (handle_fault_p t) + | .HypervisorEvent fault => handle_fault_event_p fun t => + Hypervisor_A.handle_hypervisor_fault t fault + | .Interrupt => handle_interrupt_p + | .SyscallEvent call => Syscall_A.handle_event (.SyscallEvent call) + +theorem patched_handleNonSyscall_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (ev : Event_H.event) (hevent : ∀ call, ev ≠ .SyscallEvent call) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hsafe : EventBudgetSafe sH) : + MRelStep SR (SumExceptRel Eq Eq) (handle_non_syscall_p ev sH) + ((Fl4Spec.handleEvent (embEvent ev)).run sL) := by + cases ev with + | Interrupt => exact patched_handleInterrupt_equiv hc hop hs hsafe + | SyscallEvent call => exact False.elim (hevent call rfl) + | UnknownSyscall n => + exact handleFaultEvent_equiv hc hop (fun t => patched_handleFault_equiv hop t + (.UnknownSyscallException (holOfNat n))) hs hsafe + | UserLevelFault w1 w2 => + exact handleFaultEvent_equiv hc hop (fun t => patched_handleFault_equiv hop t + (.UserException (holWordAnd w1 (holWordMask 32)) (holWordAnd w2 (holWordMask 28)))) hs hsafe + | VMFaultEvent kind => + exact handleFaultEvent_equiv hc hop (fun t => mrele_catch (handleVmFault_equiv hop t kind) + fun fH fL hf => by subst hf; exact patched_handleFault_equiv hop t fH) hs hsafe + | HypervisorEvent fault => + exact handleFaultEvent_equiv hc hop (fun t => handleHypervisorFault_equiv t fault) hs hsafe + + +private def event_with_preemption + (event : HolNonDet (Structures_A.state ZH) (Sum Unit Unit)) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holHandleE event (fun _ => Exceptions_A.without_preemption preemption_path_p) + +private def kernel_after_event + (event : HolNonDet (Structures_A.state ZH) (Sum Unit Unit)) : + HolNonDet (Structures_A.state ZH) Unit := + holBind (event_with_preemption event) + (holKBind (holBind Schedule_A.schedule (holKBind activate_thread_p))) + +private theorem kernelAfterEvent_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (ev : Fl4Spec.Event) + {event : HolNonDet (Structures_A.state ZH) (Sum Unit Unit)} + {sH : Structures_A.state ZH} {sL : State ZL} + (hevent : MRelStep SR (SumExceptRel Eq Eq) (event sH) ((Fl4Spec.handleEvent ev).run sL)) + (hpre : ∀ next, (Sum.inl (), next) ∈ (event sH).1 → PreemptionSafe next) + (hsched : ∀ result next, (result, next) ∈ (event_with_preemption event sH).1 → ScheduleSafe next) : + MRelStep SR Eq (kernel_after_event event sH) (Fl4Spec.callKernel ev sL) := by + unfold kernel_after_event event_with_preemption Fl4Spec.callKernel + refine mrelStep_bind_mem (mrelStep_handleE_mem (Re' := Eq) hevent ?_) ?_ + · intro eH eL _ nextH nextL hnext hm + cases eH + cases eL + exact mrelStep_liftE (patched_preemptionPath_equiv hc hop hnext (hpre nextH hm)) + · intro result _ _ nextH nextL hnext hm + exact mrelStep_bind_mem (schedule_equiv hc hop hnext (hsched result nextH hm)) + fun _ _ _ stH stL hst _ => patched_activateThread_equiv hop stH stL hst + +/-- Patched kernel entry for interrupts and fault events. -/ +def call_kernel_non_syscall_p (event : Event_H.event) : HolNonDet (Structures_A.state ZH) Unit := + kernel_after_event (handle_non_syscall_p event) + +def NonSyscallKernelSafe (event : Event_H.event) (s : Structures_A.state ZH) : Prop := + EventBudgetSafe s ∧ + (∀ next, (Sum.inl (), next) ∈ (handle_non_syscall_p event s).1 → PreemptionSafe next) ∧ + (∀ result next, (result, next) ∈ (event_with_preemption (handle_non_syscall_p event) s).1 → + ScheduleSafe next) + +theorem patched_callKernelNonSyscall_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (event : Event_H.event) (hevent : ∀ call, event ≠ .SyscallEvent call) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : NonSyscallKernelSafe event sH) : + MRelStep SR Eq (call_kernel_non_syscall_p event sH) (Fl4Spec.callKernel (embEvent event) sL) := + kernelAfterEvent_equiv hc hop (embEvent event) + (patched_handleNonSyscall_equiv hc hop event hevent hs hsafe.1) hsafe.2.1 hsafe.2.2 + +def invocation_from_reg_p (huge calling blocking canDonate firstPhase : Bool) + (reg : MachineTypes.register) : HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holBindE (holLiftE (Syscall_A.get_cap_reg reg)) fun cptr => + handle_invocation_p huge calling blocking canDonate firstPhase cptr + +/-- [P] The actual register reads reach states with the applicable invocation guards. -/ +def InvocationFromRegSafe (huge firstPhase : Bool) (reg : MachineTypes.register) + (sH : Structures_A.state ZH) (sL : State ZL) : Prop := + ∀ cptr tH tL, (cptr, tH) ∈ (Syscall_A.get_cap_reg reg sH).1 → + (cptr, tL) ∈ (Fl4Spec.getCapReg (embRegister reg) sL).1 → + HandleInvSafe huge firstPhase cptr tH ∧ InvocationPlatformSafe huge cptr tL + +theorem patched_invocationFromReg_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (huge calling blocking canDonate firstPhase : Bool) (reg : MachineTypes.register) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : InvocationFromRegSafe huge firstPhase reg sH sL) : + MRelStep SR (SumExceptRel Eq Eq) + (invocation_from_reg_p huge calling blocking canDonate firstPhase reg sH) + ((do + let cptr ← NonDetE.liftE (Fl4Spec.getCapReg (embRegister reg)) + Fl4Spec.handleInvocation calling blocking canDonate firstPhase cptr : PMonad ZL Unit).run sL) := by + unfold invocation_from_reg_p + refine mrelStep_bindE_mem_both (mrelStep_liftE (getCapReg_equiv reg sH sL hs)) + fun cH cL hcptr tH tL ht hmH hmL => ?_ + subst hcptr + obtain ⟨hi, hp⟩ := hsafe cH tH tL (holLiftE_some_mem hmH) (leanLiftE_some_mem hmL) + exact patched_handleInvocation_equiv hc hop huge calling blocking canDonate firstPhase cH ht hi hp + +def invoke_then_receive_p (huge canReply : Bool) (reg : MachineTypes.register) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holBindE (invocation_from_reg_p huge false false true true reg) (holKBind + (Exceptions_A.without_preemption (handle_recv_p true canReply))) + +/-- [P] The receiving branch is guarded when the first invocation returns. -/ +def InvokeThenReceiveSafe (huge canReply : Bool) (reg : MachineTypes.register) + (sH : Structures_A.state ZH) (sL : State ZL) : Prop := + InvocationFromRegSafe huge true reg sH sL ∧ + ∀ t, (Sum.inr (), t) ∈ (invocation_from_reg_p huge false false true true reg sH).1 → + HandleRecvSafe true canReply t + +theorem patched_invokeThenReceive_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (huge canReply : Bool) (reg : MachineTypes.register) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : InvokeThenReceiveSafe huge canReply reg sH sL) : + MRelStep SR (SumExceptRel Eq Eq) + (invoke_then_receive_p huge canReply reg sH) + ((do + let cptr ← Fl4Spec.withoutPreemption (Fl4Spec.getCapReg (embRegister reg)) + Fl4Spec.handleInvocation false false true true cptr + Fl4Spec.withoutPreemption (Fl4Spec.handleRecv true canReply) : PMonad ZL Unit).run sL) := by + unfold invoke_then_receive_p invocation_from_reg_p + rw [holBindE_assoc] + refine mrelStep_bindE_mem_both + (withoutPreemption_step_equiv (getCapReg_equiv reg sH sL hs)) + fun cH cL hcptr tH tL ht hregH hregL => ?_ + subst hcptr + obtain ⟨hi, hp⟩ := hsafe.1 cH tH tL (holLiftE_some_mem hregH) (leanLiftE_some_mem hregL) + refine mrelStep_kbindE_mem + (patched_handleInvocation_equiv hc hop huge false false true true cH ht hi hp) + fun result uH uL hu hret => ?_ + cases result + have hfirst : (Sum.inr (), uH) ∈ (invocation_from_reg_p huge false false true true reg sH).1 := + ⟨⟨Sum.inr cH, tH⟩, hregH, hret⟩ + exact withoutPreemption_step_equiv + (patched_handleRecv_equiv hop true canReply hu (hsafe.2 uH hfirst)) + +def syscall_dispatch_p (huge : Bool) : + Event_H.syscall → HolNonDet (Structures_A.state ZH) (Sum Unit Unit) + | .SysSend => invocation_from_reg_p huge false true false false Machine_A.cap_register + | .SysNBSend => invocation_from_reg_p huge false false false false Machine_A.cap_register + | .SysCall => invocation_from_reg_p huge true true true false Machine_A.cap_register + | .SysReplyRecv => invoke_then_receive_p huge true MachineTypes.replyRegister + | .SysNBSendRecv => invoke_then_receive_p huge true MachineTypes.nbsendRecvDest + | .SysNBSendWait => invoke_then_receive_p huge false MachineTypes.replyRegister + | .SysRecv => Exceptions_A.without_preemption (handle_recv_p true true) + | .SysNBRecv => Exceptions_A.without_preemption (handle_recv_p false true) + | .SysWait => Exceptions_A.without_preemption (handle_recv_p true false) + | .SysNBWait => Exceptions_A.without_preemption (handle_recv_p false false) + | .SysYield => Exceptions_A.without_preemption Syscall_A.handle_yield + +private def syscallDispatch (call : Fl4Spec.Syscall) : PMonad ZL Unit := + match call with + | .sysSend => Fl4Spec.handleSend true + | .sysNBSend => Fl4Spec.handleSend false + | .sysCall => Fl4Spec.handleCall + | .sysRecv => Fl4Spec.withoutPreemption (Fl4Spec.handleRecv true true) + | .sysYield => Fl4Spec.withoutPreemption Fl4Spec.handleYield + | .sysReplyRecv => do + let cptr ← Fl4Spec.withoutPreemption (Fl4Spec.getCapReg Fl4Spec.replyRegister) + Fl4Spec.handleInvocation false false true true cptr + Fl4Spec.withoutPreemption (Fl4Spec.handleRecv true true) + | .sysNBSendRecv => do + let cptr ← Fl4Spec.withoutPreemption (Fl4Spec.getCapReg Fl4Spec.nbsendRecvDest) + Fl4Spec.handleInvocation false false true true cptr + Fl4Spec.withoutPreemption (Fl4Spec.handleRecv true true) + | .sysNBSendWait => do + let cptr ← Fl4Spec.withoutPreemption (Fl4Spec.getCapReg Fl4Spec.replyRegister) + Fl4Spec.handleInvocation false false true true cptr + Fl4Spec.withoutPreemption (Fl4Spec.handleRecv true false) + | .sysWait => Fl4Spec.withoutPreemption (Fl4Spec.handleRecv true false) + | .sysNBWait => Fl4Spec.withoutPreemption (Fl4Spec.handleRecv false false) + | .sysNBRecv => Fl4Spec.withoutPreemption (Fl4Spec.handleRecv false true) + +/-- [P] Dispatch obligations for the reached syscall and input pair. -/ +def SyscallDispatchSafe (huge : Bool) (call : Event_H.syscall) + (sH : Structures_A.state ZH) (sL : State ZL) : Prop := + match call with + | .SysSend | .SysNBSend | .SysCall => InvocationFromRegSafe huge false Machine_A.cap_register sH sL + | .SysReplyRecv => InvokeThenReceiveSafe huge true MachineTypes.replyRegister sH sL + | .SysNBSendRecv => InvokeThenReceiveSafe huge true MachineTypes.nbsendRecvDest sH sL + | .SysNBSendWait => InvokeThenReceiveSafe huge false MachineTypes.replyRegister sH sL + | .SysRecv => HandleRecvSafe true true sH + | .SysNBRecv => HandleRecvSafe false true sH + | .SysWait => HandleRecvSafe true false sH + | .SysNBWait => HandleRecvSafe false false sH + | .SysYield => HandleYieldSafe sH + +private theorem patched_syscallDispatch_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (huge : Bool) (call : Event_H.syscall) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : SyscallDispatchSafe huge call sH sL) : + MRelStep SR (SumExceptRel Eq Eq) + (syscall_dispatch_p huge call sH) ((syscallDispatch (embSyscall call)).run sL) := by + cases call with + | SysSend => exact patched_invocationFromReg_equiv hc hop huge false true false false _ hs hsafe + | SysNBSend => exact patched_invocationFromReg_equiv hc hop huge false false false false _ hs hsafe + | SysCall => exact patched_invocationFromReg_equiv hc hop huge true true true false _ hs hsafe + | SysReplyRecv => exact patched_invokeThenReceive_equiv hc hop huge true _ hs hsafe + | SysNBSendRecv => exact patched_invokeThenReceive_equiv hc hop huge true _ hs hsafe + | SysNBSendWait => exact patched_invokeThenReceive_equiv hc hop huge false _ hs hsafe + | SysRecv => exact withoutPreemption_step_equiv (patched_handleRecv_equiv hop true true hs hsafe) + | SysNBRecv => exact withoutPreemption_step_equiv (patched_handleRecv_equiv hop false true hs hsafe) + | SysWait => exact withoutPreemption_step_equiv (patched_handleRecv_equiv hop true false hs hsafe) + | SysNBWait => exact withoutPreemption_step_equiv (patched_handleRecv_equiv hop false false hs hsafe) + | SysYield => exact withoutPreemption_step_equiv (handleYield_equiv hop hs hsafe) + +def handle_syscall_p (huge : Bool) (call : Event_H.syscall) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + holBindE (holLiftE KHeap_A.update_time_stamp) (holKBind + (holBindE (holLiftE check_budget_restart_p) fun restart => + holWhenE restart (syscall_dispatch_p huge call))) + +/-- [P] Budget and dispatch guards use actual runs of the preceding operations. -/ +def HandleSyscallSafe (huge : Bool) (call : Event_H.syscall) + (sH : Structures_A.state ZH) (sL : State ZL) : Prop := + EventBudgetSafe sH ∧ + ∀ tH tL, ((), tH) ∈ (KHeap_A.update_time_stamp sH).1 → + ((), tL) ∈ (Fl4Spec.updateTimeStamp sL).1 → + ∀ uH uL, (true, uH) ∈ (check_budget_restart_p tH).1 → + (true, uL) ∈ (Fl4Spec.checkBudgetRestart tL).1 → + SyscallDispatchSafe huge call uH uL + +theorem patched_handleSyscall_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (huge : Bool) (call : Event_H.syscall) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : HandleSyscallSafe huge call sH sL) : + MRelStep SR (SumExceptRel Eq Eq) (handle_syscall_p huge call sH) + ((Fl4Spec.handleEvent (.syscallEvent (embSyscall call))).run sL) := by + change MRelStep SR (SumExceptRel Eq Eq) + (holBindE (holLiftE KHeap_A.update_time_stamp) (fun _ => + holBindE (holLiftE check_budget_restart_p) fun restart => + holWhenE restart (syscall_dispatch_p huge call)) sH) + ((do + NonDetE.liftE Fl4Spec.updateTimeStamp + let restart ← NonDetE.liftE Fl4Spec.checkBudgetRestart + NonDetE.whenE restart (syscallDispatch (embSyscall call)) : PMonad ZL Unit).run sL) + refine mrelStep_bindE_mem_both (mrelStep_liftE (updateTimeStamp_equiv hc hop sH sL hs)) + fun _ _ _ tH tL ht htimeH htimeL => ?_ + have htime := holLiftE_some_mem htimeH + refine mrelStep_bindE_mem_both + (mrelStep_liftE (patched_checkBudgetRestart_equiv hc hop ht (hsafe.1 tH htime))) + fun bH bL hb uH uL hu hbudgetH hbudgetL => ?_ + subst hb + cases bH + · exact mrele_returnOk rfl uH uL hu + · exact patched_syscallDispatch_equiv hc hop huge call hu + (hsafe.2 tH tL htime (leanLiftE_some_mem htimeL) uH uL + (holLiftE_some_mem hbudgetH) (leanLiftE_some_mem hbudgetL)) + +def handle_event_p (huge : Bool) (event : Event_H.event) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + match event with + | .SyscallEvent call => handle_syscall_p huge call + | _ => handle_non_syscall_p event + +/-- [P] Dispatch or budget obligations for the selected event. -/ +def HandleEventSafe (huge : Bool) (event : Event_H.event) + (sH : Structures_A.state ZH) (sL : State ZL) : Prop := + match event with + | .SyscallEvent call => HandleSyscallSafe huge call sH sL + | _ => EventBudgetSafe sH + +theorem patched_handleEvent_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (huge : Bool) (event : Event_H.event) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : HandleEventSafe huge event sH sL) : + MRelStep SR (SumExceptRel Eq Eq) (handle_event_p huge event sH) + ((Fl4Spec.handleEvent (embEvent event)).run sL) := by + cases event with + | SyscallEvent call => exact patched_handleSyscall_equiv hc hop huge call hs hsafe + | _ => exact patched_handleNonSyscall_equiv hc hop _ (by intro _ h; cases h) hs hsafe + +/-- Patched X64 Syscall_A.call_kernel. The platform feature is supplied to the architecture decoder. -/ +def call_kernel_p (huge : Bool) (event : Event_H.event) : HolNonDet (Structures_A.state ZH) Unit := + kernel_after_event (handle_event_p huge event) + +/-- [P] Base carriers and guards for the actual event, preemption, and schedule prefixes. -/ +structure CallKernelSafe (huge : Bool) (event : Event_H.event) + (sH : Structures_A.state ZH) (sL : State ZL) : Prop where + carriers : ReferenceBaseCarriers sH + eventSafe : HandleEventSafe huge event sH sL + preemption : ∀ t, (Sum.inl (), t) ∈ (handle_event_p huge event sH).1 → PreemptionSafe t + schedule : ∀ result t, (result, t) ∈ (event_with_preemption (handle_event_p huge event) sH).1 → ScheduleSafe t + +theorem patched_callKernel_equiv (hc : ConfigRel) (hop : OpaqueRel RestRel) + (huge : Bool) (event : Event_H.event) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : CallKernelSafe huge event sH sL) : + MRelStep SR Eq (call_kernel_p huge event sH) (Fl4Spec.callKernel (embEvent event) sL) := + kernelAfterEvent_equiv hc hop (embEvent event) + (patched_handleEvent_equiv hc hop huge event hs hsafe.eventSafe) hsafe.preemption hsafe.schedule + + +end + +end L4vRefX64.Equiv.Syscall diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Tcb.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Tcb.lean new file mode 100644 index 000000000..4fd41f79a --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Tcb.lean @@ -0,0 +1,575 @@ +import L4vRefX64.Equiv.ArchSwitch +import L4vRefX64.Equiv.SchedContext +import L4vRefX64.Equiv.Schedule +import L4vRefX64.Equiv.Ipc +import L4vRefX64.Equiv.Decode +import L4vRefX64.Spec.Tcb_A + +namespace L4vRefX64.Equiv.Tcb + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.SchedContext L4vRefX64.Equiv.ArchSwitch +open L4vRefX64.Equiv.Schedule L4vRefX64.Equiv.Fpu L4vRefX64.Equiv.IpcCancel L4vRefX64.Equiv.CSpaceAcc +open L4vRefX64.Equiv.Ipc L4vRefX64.Equiv.CSpace L4vRefX64.Equiv.Deterministic +open Fl4Spec Classical + +noncomputable section + +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 archPrepareSetDomain_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) (domain : Domain) : + MRel SR Eq (ArchTcb_A.arch_prepare_set_domain thread domain) + (Fl4Spec.archPrepareSetDomain thread domain) := by + unfold ArchTcb_A.arch_prepare_set_domain Fl4Spec.archPrepareSetDomain + refine mrel_bind (mrel_gets (Ra := Eq) (fun _ _ h => h.curDomain_eq.symm)) fun dH dL hd => ?_ + subst hd + unfold holWhen NonDet.when + simp only [holFunApp] + have hguard : holNot (@holEq (BitVec 8) dH domain) = true ↔ @Ne Domain dH domain := + (holNot_eq_true _).trans (not_congr (@holEq_eq_true (BitVec 8) dH domain)) + by_cases hd : @Ne Domain dH domain + · rw [ite_eq_left (hguard.mpr hd), ite_eq_left hd] + exact fpuRelease_equiv hop thread + · rw [ite_eq_right (mt hguard.mp hd), ite_eq_right hd] + exact mrel_return rfl + +theorem setDomain_equiv (hop : OpaqueRel RestRel) (tptr : ObjRef) (newDom : Domain) : + MRel SR Eq + (Tcb_A.set_domain tptr newDom) (Fl4Spec.setDomain tptr newDom) := by + unfold Tcb_A.set_domain Fl4Spec.setDomain + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun curH curL hcur => ?_; subst hcur + refine mrel_kbind (tcbSchedAction_equiv tcbSchedDequeue_eq tptr) ?_ + refine mrel_kbind (threadSetDomain_equiv tptr newDom) ?_ + refine mrel_bind (mrel_gets fun _ _ hs => (schedulable_eq hs tptr).symm) fun schH schL hsch => ?_; subst hsch + refine mrel_kbind (mrel_when Iff.rfl fun _ => tcbSchedAction_equiv tcbSchedEnqueue_eq tptr) ?_ + exact mrel_when (by simp [holEq_eq_true]) fun _ => rescheduleRequired_equiv hop + +theorem invokeSetDomain_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) (domain : Domain) : + MRel SR Eq + (Tcb_A.invoke_set_domain thread domain) (Fl4Spec.invokeSetDomain thread domain) := by + unfold Tcb_A.invoke_set_domain Fl4Spec.invokeSetDomain + exact mrel_kbind (archPrepareSetDomain_equiv hop thread domain) (setDomain_equiv hop thread domain) + +theorem invokeDomain_equiv (hop : OpaqueRel RestRel) (iv : Invocations_A.domain_invocation) : + MRel SR Eq + (Tcb_A.invoke_domain iv) (Fl4Spec.invokeDomain (embDomainInv iv)) := by + cases iv with + | InvokeDomainSet thread domain => exact invokeSetDomain_equiv hop thread domain + | InvokeDomainScheduleSetStart index => exact domainSetStart_equiv hop index + | InvokeDomainScheduleConfigure index domain duration => + exact domainScheduleConfigure_equiv index domain duration + +theorem restart_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) : + MRel SR Eq + (Tcb_A.restart thread) (Fl4Spec.restart thread) := by + unfold Tcb_A.restart Fl4Spec.restart + refine mrel_bind (getThreadState_equiv thread) fun stH stL hst => ?_; subst hst + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) thread) fun scH scL hsc => ?_; subst hsc + refine mrel_when (by + simp only [holConj_eq_true, holNot_eq_true, runnable_eq, Fl4Spec.idle] + exact and_congr_right fun _ => by cases stH <;> simp [embThreadState]) fun _ => ?_ + refine mrel_kbind (cancelIpc_equiv thread) ?_ + refine mrel_kbind (setThreadState_equiv thread .Restart) ?_ + refine mrel_kbind (ifSporadicCurScTestRefillUnblockCheck_equiv scH) ?_ + refine mrel_kbind (mrel_maybeM (Ra := Eq) (fun pH pL hp => by subst hp; exact schedContextResume_equiv hop pH) + (by cases scH <;> simp [OptRel])) ?_ + exact testPossibleSwitchTo_equiv hop thread + +def activate_thread_p : HolNonDet (Structures_A.state ZH) Unit := + holBind (holGets fun s => s.cur_thread) fun thread => + holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_yield_to thread) fun yt_opt => + holBind (holWhen (holNot (holEq yt_opt none)) (complete_yield_to_p thread)) (holKBind + (holBind (KHeap_A.get_thread_state thread) fun state => + match state with + | .Running => holReturn () + | .Restart => + holBind (KHeap_A.as_user thread MachineOps.getRestartPC) fun pc => + holBind (KHeap_A.as_user thread (MachineOps.setNextPC pc)) (holKBind + (KHeap_A.set_thread_state thread .Running)) + | .IdleThreadState => Arch_A.arch_activate_idle_thread thread + | _ => holFail)) + +theorem patched_activateThread_equiv (hop : OpaqueRel RestRel) : + MRel SR Eq + (activate_thread_p (ZH := ZH)) (Fl4Spec.activateThread (Z := ZL)) := by + unfold activate_thread_p Fl4Spec.activateThread + refine mrel_bind (mrel_gets fun _ _ hs => hs.curThread_eq.symm) fun thH thL hth => ?_; subst hth + refine mrel_bind (getTcbObjRef_equiv (fun _ => rfl) thH) fun ytH ytL hyt => ?_; subst hyt + refine mrel_kbind (mrel_when (by simp [holNot_eq_true, holEq_eq_true]) + fun _ => patched_completeYieldTo_equiv hop thH) ?_ + refine mrel_bind (getThreadState_equiv thH) fun stH stL hst => ?_; subst hst + cases stH with + | Running => exact mrel_return rfl + | Restart => + refine mrel_bind (asUser_equiv getRestartPC_equiv thH) fun pcH pcL hpc => ?_; subst hpc + exact mrel_kbind (asUser_equiv (setNextPC_equiv pcH) thH) (setThreadState_equiv thH .Running) + | IdleThreadState => exact archActivateIdleThread_equiv thH + | _ => exact mrel_fail +theorem bindNotification_equiv (tcbptr ntfnptr : ObjRef) : + MRel SR Eq + (Tcb_A.bind_notification tcbptr ntfnptr) (Fl4Spec.bindNotification tcbptr ntfnptr) := by + unfold Tcb_A.bind_notification Fl4Spec.bindNotification + exact mrel_kbind (setNtfnObjRef_equiv (fun _ _ => rfl) ntfnptr (some tcbptr)) + (threadSet_equiv (fun _ => rfl) tcbptr) + +private theorem listRel_take {αH αL : Type} {R : αH → αL → Prop} (n : Nat) + {xs : List αH} {ys : List αL} (h : ListRel R xs ys) : + ListRel R (xs.take n) (ys.take n) := by + induction h generalizing n with + | nil => simp [ListRel.nil] + | cons h1 _ ih => + cases n with + | zero => exact ListRel.nil + | succ k => exact ListRel.cons h1 (ih k) + +private theorem listRel_append {αH αL : Type} {R : αH → αL → Prop} + {xs1 xs2 : List αH} {ys1 ys2 : List αL} + (h1 : ListRel R xs1 ys1) (h2 : ListRel R xs2 ys2) : + ListRel R (xs1 ++ xs2) (ys1 ++ ys2) := by + induction h1 with + | nil => exact h2 + | cons ha _ ih => exact ListRel.cons ha ih + + +private theorem frameRegisters_eq : + Fl4Spec.frameRegisters = MachineTypes.frameRegisters.map embRegister := by + have hstart : holFromEnum MachineTypes.register.RAX = 0 := by + simp [holFromEnum, HolEnum.enumList, MachineTypes.enum_register, holTheIndex] + have hend : holFromEnum MachineTypes.register.R15 = 14 := by + simp [holFromEnum, HolEnum.enumList, MachineTypes.enum_register, holTheIndex] + rw [MachineTypes.frameRegisters, holUptoEnum, hstart, hend] + rfl + +private theorem frame_registers_eq : + Fl4Spec.frame_registers = Machine_A.frame_registers.map embRegister := + frameRegisters_eq + +private theorem gp_registers_eq : + Fl4Spec.gp_registers = Machine_A.gp_registers.map embRegister := rfl + +private theorem gpRegisters_eq : + Fl4Spec.gpRegisters = MachineTypes.gpRegisters.map embRegister := rfl + +private theorem tlsBaseRegister_eq : + Fl4Spec.tlsBaseRegister = embRegister MachineTypes.tlsBaseRegister := rfl + +private theorem archPostModifyRegisters_equiv (cur thread : ObjRef) : + MRel SR Eq (ArchTcb_A.arch_post_modify_registers cur thread) + (Fl4Spec.archPostModifyRegisters cur thread) := by + unfold ArchTcb_A.arch_post_modify_registers Fl4Spec.archPostModifyRegisters + refine mrel_when (by simp [holNot_eq_true, holEq_eq_true]) fun _ => ?_ + exact asUser_equiv (setRegister_equiv .ErrorRegister 0) thread + +private theorem archPostSetFlags_equiv (hop : OpaqueRel RestRel) (thread : ObjRef) + (flags : Set Structs_B.tcb_flag) : + MRel SR Eq (ArchTcb_A.arch_post_set_flags thread flags) + (Fl4Spec.archPostSetFlags thread (embTcbFlags flags)) := by + unfold ArchTcb_A.arch_post_set_flags Fl4Spec.archPostSetFlags + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ h => h.curThread_eq.symm) fun curH curL hc => ?_ + subst hc + refine mrel_if (by rw [holMember_eq_true]; exact (embTcbFlags_mem .FpuDisabled flags).symm) + (fun _ => fpuRelease_equiv hop thread) fun _ => ?_ + exact mrel_when (by rw [holEq_eq_true]) fun _ => lazyFpuRestore_equiv hop thread + +private theorem tcbFlagsToWord_eq (flags : Set Structs_B.tcb_flag) : + Fl4Spec.tcbFlagsToWord (embTcbFlags flags) = Structures_A.tcb_flags_to_word flags := by + unfold Fl4Spec.tcbFlagsToWord Structures_A.tcb_flags_to_word + have hp : (fun w => Fl4Spec.wordToTcbFlags w = embTcbFlags flags ∧ + w &&& ~~~Fl4Spec.tcbFlagMask = 0) = (fun w => + holConj (holEq (Structures_A.word_to_tcb_flags w) flags) + (holEq (holWordAnd w (holWordNot Structs_B.tcbFlagMask)) HolZero.zeroVal) = true) := by + funext w + rw [L4vRefX64.Equiv.Decode.wordToTcbFlags_eq] + simp only [holConj_eq_true, holEq_eq_true, embTcbFlags_eq_iff] + rfl + rw [hp] + rfl + +private theorem withoutPreemption_step_equiv {αH αL : Type} [Nonempty αH] + {Ra : αH → αL → Prop} + {mH : HolNonDet (Structures_A.state ZH) αH} {mL : SMonad ZL αL} + {sH : Structures_A.state ZH} {sL : State ZL} (hm : MRelStep SR Ra (mH sH) (mL sL)) : + MRelStep SR (SumExceptRel Eq Ra) + (Exceptions_A.without_preemption mH sH) ((Fl4Spec.withoutPreemption mL).run sL) := + mrelStep_liftE hm + +def check_cap_at_p (cap : Structures_A.cap) (slot : CslotPtr) + (m : HolNonDet (Structures_A.state ZH) Unit) : HolNonDet (Structures_A.state ZH) Unit := + holBind (get_cap_p slot) fun cap' => holWhen (CSpace_A.same_object_as cap cap') m + +theorem patched_checkCapAt_equiv (cap : Structures_A.cap) (slot : CslotPtr) + {mH : HolNonDet (Structures_A.state ZH) Unit} {mL : SMonad ZL Unit} + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hm : ∀ cH s1H s1L, SR s1H s1L → (cH, s1H) ∈ (get_cap_p slot sH).1 → + CSpace_A.same_object_as cap cH = true → MRelStep SR Eq (mH s1H) (mL s1L)) : + MRelStep SR Eq (check_cap_at_p cap slot mH sH) (Fl4Spec.checkCapAt (embCap cap) slot mL sL) := by + unfold check_cap_at_p Fl4Spec.checkCapAt + refine mrelStep_bind_mem (patched_getCap_equiv slot sH sL hs) fun cH cL hc s1H s1L hs1 hm1 => ?_ + subst hc + by_cases hso : CSpace_A.same_object_as cap cH = true + · have hsoL : Fl4Spec.sameObjectAs (embCap cap) (embCap cH) := (sameObjectAs_iff cap cH).mp hso + simp only [hso, holWhen, NonDet.when, hsoL, ↓reduceIte] + exact hm cH s1H s1L hs1 hm1 hso + · have hsoF : CSpace_A.same_object_as cap cH = false := Bool.eq_false_iff.mpr hso + have hsoLF : ¬Fl4Spec.sameObjectAs (embCap cap) (embCap cH) := mt (sameObjectAs_iff cap cH).mpr hso + simp only [hsoF, holWhen, NonDet.when, hsoLF, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl s1H s1L hs1 + +def install_tcb_cap_p (target : ObjRef) (slot : CslotPtr) (n : Nat) + (slot_opt : Option (Structures_A.cap × CslotPtr)) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + match slot_opt with + | none => holReturnOk () + | some (new_cap, src_slot) => + holBindE (cap_delete_p (target, Structures_A.tcb_cnode_index n)) (holKBind + (holUnlessE (holEq new_cap .NullCap) + (holLiftE (check_cap_at_p new_cap src_slot + (check_cap_at_p (.ThreadCap target) slot + (cap_insert_p new_cap src_slot (target, Structures_A.tcb_cnode_index n))))))) + +def install_tcb_frame_cap_p (target : ObjRef) (slot : CslotPtr) + (buffer : Option (VSpaceRef × Option (Structures_A.cap × CslotPtr))) : + HolNonDet (Structures_A.state ZH) (Sum Unit Unit) := + match buffer with + | none => holReturnOk () + | some (ptr, frame) => + holBindE (cap_delete_p (target, Structures_A.tcb_cnode_index 2)) (holKBind + (holBindE (holLiftE (KHeap_A.thread_set (fun t => Structures_A.tcb.tcb_ipc_buffer_update (fun _ => ptr) t) target)) (holKBind + (holBindE (holLiftE (match frame with + | none => holReturn () + | some (new_cap, src_slot) => + check_cap_at_p new_cap src_slot + (check_cap_at_p (.ThreadCap target) slot + (cap_insert_p new_cap src_slot (target, Structures_A.tcb_cnode_index 2))))) (holKBind + (holBindE (holLiftE (holGets fun s => s.cur_thread)) fun cur => + holLiftE (holWhen (holEq target cur) KHeap_A.reschedule_required))))))) + +def invoke_tcb_p : Invocations_A.tcb_invocation → HolNonDet (Structures_A.state ZH) (Sum Unit (List Word)) + | .Suspend thread => holLiftE (holBind (SchedContext_A.suspend thread) (holKBind (holReturn []))) + | .Resume thread => holLiftE (holBind (Tcb_A.restart thread) (holKBind (holReturn []))) + | .ThreadControlCaps target slot fh th croot vroot buf => + holBindE (install_tcb_cap_p target slot 3 fh) (holKBind + (holBindE (install_tcb_cap_p target slot 4 th) (holKBind + (holBindE (install_tcb_cap_p target slot 0 croot) (holKBind + (holBindE (install_tcb_cap_p target slot 1 vroot) (holKBind + (holBindE (install_tcb_frame_cap_p target slot buf) (holKBind (holReturnOk [])))))))))) + | .ThreadControlSched target slot fh mcp prio sc => + holBindE (install_tcb_cap_p target slot 3 fh) (holKBind + (holBindE (holLiftE (holMaybeM (holCaseProd fun newmcp _ => KHeap_A.set_mcpriority target newmcp) mcp)) (holKBind + (holBindE (holLiftE (holMaybeM (holCaseProd fun p _ => IpcCancel_A.set_priority target p) prio)) (holKBind + (holBindE (holLiftE (holMaybeM (holCaseOption + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context target) fun sc_ptr_opt => + holBind (holAssertOpt sc_ptr_opt) IpcCancel_A.sched_context_unbind_tcb) + (fun sc_ptr => SchedContext_A.sched_context_bind_tcb sc_ptr target)) sc)) (holKBind (holReturnOk [])))))))) + | .CopyRegisters dest src ss rt tf ti ta => Tcb_A.invoke_tcb (.CopyRegisters dest src ss rt tf ti ta) + | .ReadRegisters src ss n a => Tcb_A.invoke_tcb (.ReadRegisters src ss n a) + | .WriteRegisters dest rt vals a => Tcb_A.invoke_tcb (.WriteRegisters dest rt vals a) + | .NotificationControl tcb n => Tcb_A.invoke_tcb (.NotificationControl tcb n) + | .SetTLSBase tcb tls => Tcb_A.invoke_tcb (.SetTLSBase tcb tls) + | .SetFlags tcb cf sf => Tcb_A.invoke_tcb (.SetFlags tcb cf sf) + +private def TcbCapInsertSafe (target : ObjRef) (slot dest : CslotPtr) (newCap : Structures_A.cap) + (src : CslotPtr) (s : Structures_A.state ZH) : Prop := + ∀ c1 t, (c1, t) ∈ (get_cap_p src s).1 → CSpace_A.same_object_as newCap c1 = true → + ∀ c2 u, (c2, u) ∈ (get_cap_p slot t).1 → CSpace_A.same_object_as (.ThreadCap target) c2 = true → + CapInsertSafe newCap src dest u + +/-- [P] Deleting the previous capability terminates and both actual identity checks admit insertion. -/ +def InstallTcbCapSafe (target : ObjRef) (slot : CslotPtr) (n : Nat) + (slotOpt : Option (Structures_A.cap × CslotPtr)) (sH : Structures_A.state ZH) : Prop := + match slotOpt with + | none => True + | some (newCap, srcSlot) => + let dest := (target, Structures_A.tcb_cnode_index n) + RecDelDom (.CTEDeleteCall dest true) sH ∧ + (newCap ≠ .NullCap → ∀ t, (Sum.inr (), t) ∈ (cap_delete_p dest sH).1 → + TcbCapInsertSafe target slot dest newCap srcSlot t) + +theorem patched_installTcbCap_equiv (hop : OpaqueRel RestRel) (hc : ConfigRel) + (target : ObjRef) (slot : CslotPtr) (n : Nat) + (slotOpt : Option (Structures_A.cap × CslotPtr)) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : InstallTcbCapSafe target slot n slotOpt sH) : + MRelStep SR (SumExceptRel Eq Eq) + (install_tcb_cap_p target slot n slotOpt sH) + (Fl4Spec.installTcbCap target slot n (slotOpt.map fun p => (embCap p.1, p.2)) sL) := by + cases slotOpt with + | none => exact mrele_returnOk rfl sH sL hs + | some p => + rcases p with ⟨newCap, srcSlot⟩ + obtain ⟨hdom, hins⟩ := hsafe + unfold install_tcb_cap_p Fl4Spec.installTcbCap + simp only [Option.map, tcbCnodeIndex_eq n] + refine mrelStep_bindE_mem (patched_capDelete_equiv_on_dom hop hc hs hdom) + fun u1 _ _ s1H s1L hs1 hm1 => ?_ + cases u1 + by_cases hnull : newCap = .NullCap + · subst hnull + simp only [holUnlessE, NonDetE.unlessE, holEq, embCap, ↓reduceIte] + exact mrele_returnOk rfl s1H s1L hs1 + · have hnullH : holEq newCap .NullCap = false := by + cases h : holEq newCap .NullCap + · rfl + · rw [holEq_eq_true] at h; exact absurd h hnull + have hnullL : embCap newCap ≠ .nullCap := by + intro h; apply hnull; cases newCap <;> simp [embCap] at h; rfl + simp only [holUnlessE, NonDetE.unlessE, hnullH, hnullL, Bool.false_eq_true, ↓reduceIte] + refine withoutPreemption_step_equiv (patched_checkCapAt_equiv newCap srcSlot hs1 + fun c1 s2H s2L hs2 hm2 hfirst => + patched_checkCapAt_equiv (.ThreadCap target) slot hs2 + fun c2 s3H s3L hs3 hm3 hsecond => + patched_capInsert_equiv newCap srcSlot (target, Structures_A.tcb_cnode_index n) + hs3 (hins hnull s1H hm1 c1 s2H hm2 hfirst c2 s3H hm3 hsecond)) + +/-- [P] Frame-cap installation admits deletion and insertion at their reached states. -/ +def InstallTcbFrameCapSafe (target : ObjRef) (slot : CslotPtr) + (buf : Option (VSpaceRef × Option (Structures_A.cap × CslotPtr))) + (sH : Structures_A.state ZH) : Prop := + match buf with + | none => True + | some (ptr, frame) => + RecDelDom (.CTEDeleteCall (target, Structures_A.tcb_cnode_index 2) true) sH ∧ + match frame with + | none => True + | some (newCap, srcSlot) => + ∀ s1, (Sum.inr (), s1) ∈ (cap_delete_p (target, Structures_A.tcb_cnode_index 2) sH).1 → + ∀ s2, ((), s2) ∈ (KHeap_A.thread_set (Structures_A.tcb.tcb_ipc_buffer_update fun _ => ptr) target s1).1 → + TcbCapInsertSafe target slot (target, Structures_A.tcb_cnode_index 2) newCap srcSlot s2 + +theorem patched_installTcbFrameCap_equiv (hop : OpaqueRel RestRel) (hc : ConfigRel) + (target : ObjRef) (slot : CslotPtr) + (buf : Option (VSpaceRef × Option (Structures_A.cap × CslotPtr))) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : InstallTcbFrameCapSafe target slot buf sH) : + MRelStep SR (SumExceptRel Eq Eq) + (install_tcb_frame_cap_p target slot buf sH) + (Fl4Spec.installTcbFrameCap target slot + (buf.map fun p => (p.1, p.2.map fun q => (embCap q.1, q.2))) sL) := by + cases buf with + | none => exact mrele_returnOk rfl sH sL hs + | some p => + rcases p with ⟨ptr, frame⟩ + obtain ⟨hdom, hfr⟩ := hsafe + unfold install_tcb_frame_cap_p Fl4Spec.installTcbFrameCap + have h2 : Fl4Spec.tcbCnodeIndex 2 = Structures_A.tcb_cnode_index 2 := tcbCnodeIndex_eq 2 + simp only [Option.map, h2] + refine mrelStep_bindE_mem (patched_capDelete_equiv_on_dom hop hc hs hdom) + fun u1 _ _ s1H s1L hs1 hm1 => ?_ + cases u1 + refine mrelStep_bindE_mem (mrele_liftE (threadSet_equiv (fun _ => rfl) target) s1H s1L hs1) + fun u2 _ _ s2H s2L hs2 hm2 => ?_ + cases u2 + have hm2' : ((), s2H) ∈ (KHeap_A.thread_set (Structures_A.tcb.tcb_ipc_buffer_update fun _ => ptr) target s1H).1 := by + simp only [holLiftE, holLiftM, holBind, holReturn, Set.mem_ofPred_eq, + Set.mem_singleton_iff, Prod.mk.injEq] at hm2 + rcases hm2 with ⟨⟨r0, s0⟩, hm, _, hs0eq⟩ + cases r0; subst hs0eq; exact hm + have hfrStep : MRelStep SR (SumExceptRel (εH := Unit) (εL := Unit) Eq Eq) + (holLiftE (match frame with + | none => holReturn () + | some (new_cap, src_slot) => + check_cap_at_p new_cap src_slot + (check_cap_at_p (.ThreadCap target) slot + (cap_insert_p new_cap src_slot (target, Structures_A.tcb_cnode_index 2)))) s2H) + (NonDetE.liftE (match frame.map fun q => (embCap q.1, q.2) with + | none => pure () + | some (newCap, srcSlot) => + Fl4Spec.checkCapAt newCap srcSlot + (Fl4Spec.checkCapAt (.threadCap target) slot + (Fl4Spec.capInsert newCap srcSlot (target, Structures_A.tcb_cnode_index 2)))) s2L) := by + cases frame with + | none => exact mrele_liftE (mrel_return rfl) s2H s2L hs2 + | some q => + rcases q with ⟨newCap, srcSlot⟩ + exact withoutPreemption_step_equiv (patched_checkCapAt_equiv newCap srcSlot hs2 + fun c1 s3H s3L hs3 hm3 hfirst => + patched_checkCapAt_equiv (.ThreadCap target) slot hs3 + fun c2 s4H s4L hs4 hm4 hsecond => + patched_capInsert_equiv newCap srcSlot (target, Structures_A.tcb_cnode_index 2) + hs4 (hfr s1H hm1 s2H hm2' c1 s3H hm3 hfirst c2 s4H hm4 hsecond)) + refine mrelStep_bindE_mem hfrStep fun _ _ _ s3H s3L hs3 _ => ?_ + refine mrelStep_bindE_mem (mrele_liftE (mrel_gets fun _ _ h => h.curThread_eq.symm) s3H s3L hs3) + fun curH curL hcur s4H s4L hs4 _ => ?_; subst hcur + exact mrele_liftE (mrel_when (by simp [holEq_eq_true]) fun _ => rescheduleRequired_equiv hop) s4H s4L hs4 + +/-- [P] TCB configuration admits each of its reached capability installations. -/ +def InvokeTcbSafe (iv : Invocations_A.tcb_invocation) (sH : Structures_A.state ZH) : Prop := + match iv with + | .ThreadControlCaps target slot fh th croot vroot buf => + InstallTcbCapSafe target slot 3 fh sH ∧ + (∀ s1, (Sum.inr (), s1) ∈ (install_tcb_cap_p target slot 3 fh sH).1 → + InstallTcbCapSafe target slot 4 th s1 ∧ + ∀ s2, (Sum.inr (), s2) ∈ (install_tcb_cap_p target slot 4 th s1).1 → + InstallTcbCapSafe target slot 0 croot s2 ∧ + ∀ s3, (Sum.inr (), s3) ∈ (install_tcb_cap_p target slot 0 croot s2).1 → + InstallTcbCapSafe target slot 1 vroot s3 ∧ + ∀ s4, (Sum.inr (), s4) ∈ (install_tcb_cap_p target slot 1 vroot s3).1 → + InstallTcbFrameCapSafe target slot buf s4) + | .ThreadControlSched target slot fh _ _ _ => InstallTcbCapSafe target slot 3 fh sH + | _ => True + +theorem patched_invokeTcb_equiv (hop : OpaqueRel RestRel) (hc : ConfigRel) + (iv : Invocations_A.tcb_invocation) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hsafe : InvokeTcbSafe iv sH) : + MRelStep SR (SumExceptRel Eq Eq) + (invoke_tcb_p iv sH) (Fl4Spec.invokeTcb (embTcbInv iv) sL) := by + cases iv with + | Suspend thread => + exact mrele_liftE (mrel_kbind (suspend_equiv thread) (mrel_return rfl)) sH sL hs + | Resume thread => + exact mrele_liftE (mrel_kbind (restart_equiv hop thread) (mrel_return rfl)) sH sL hs + | ThreadControlCaps target slot fh th croot vroot buf => + unfold invoke_tcb_p Fl4Spec.invokeTcb embTcbInv + refine mrelStep_bindE_mem (patched_installTcbCap_equiv hop hc target slot 3 fh hs hsafe.1) + fun _ _ _ s1H s1L hs1 hm1 => ?_ + have ⟨h4, hrest1⟩ := hsafe.2 s1H hm1 + refine mrelStep_bindE_mem (patched_installTcbCap_equiv hop hc target slot 4 th hs1 h4) + fun _ _ _ s2H s2L hs2 hm2 => ?_ + have ⟨h0, hrest2⟩ := hrest1 s2H hm2 + refine mrelStep_bindE_mem (patched_installTcbCap_equiv hop hc target slot 0 croot hs2 h0) + fun _ _ _ s3H s3L hs3 hm3 => ?_ + have ⟨h1, hrest3⟩ := hrest2 s3H hm3 + refine mrelStep_bindE_mem (patched_installTcbCap_equiv hop hc target slot 1 vroot hs3 h1) + fun _ _ _ s4H s4L hs4 hm4 => ?_ + refine mrelStep_bindE_mem (patched_installTcbFrameCap_equiv hop hc target slot buf hs4 (hrest3 s4H hm4)) + fun _ _ _ s5H s5L hs5 _ => ?_ + exact mrele_returnOk rfl s5H s5L hs5 + | ThreadControlSched target slot fh mcp prio sc => + unfold invoke_tcb_p Fl4Spec.invokeTcb embTcbInv + refine mrelStep_bindE_mem (patched_installTcbCap_equiv hop hc target slot 3 fh hs hsafe) + fun _ _ _ s1H s1L hs1 _ => ?_ + refine mrelStep_bindE_mem (mrele_liftE (mrel_maybeM (Ra := Eq) (fun pH pL hp => by + subst hp; rcases pH with ⟨nm, _⟩; exact setMcpriority_equiv target nm) + (by cases mcp <;> simp [OptRel])) s1H s1L hs1) fun _ _ _ s2H s2L hs2 _ => ?_ + refine mrelStep_bindE_mem (mrele_liftE (mrel_maybeM (Ra := Eq) (fun pH pL hp => by + subst hp; rcases pH with ⟨pr, _⟩; exact setPriority_equiv hop target pr) + (by cases prio <;> simp [OptRel])) s2H s2L hs2) fun _ _ _ s3H s3L hs3 _ => ?_ + refine mrelStep_bindE_mem (mrele_liftE (mrel_maybeM (Rs := SR) (Ra := Eq) (fun oH oL ho => by + subst ho + cases oH with + | none => + simp only [holCaseOption] + refine mrel_bind (getTcbObjRef_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) (fun _ => rfl) target) fun scH scL hsc => ?_; subst hsc + refine mrel_bind (mrel_assertOpt (Ra := Eq) (by cases scH <;> simp [OptRel])) fun pH pL hp => ?_; subst hp + exact schedContextUnbindTcb_equiv hop pH + | some scPtr => + simp only [holCaseOption] + exact schedContextBindTcb_equiv hop scPtr target) + (by cases sc <;> simp [OptRel])) s3H s3L hs3) fun _ _ _ s4H s4L hs4 _ => ?_ + exact mrele_returnOk rfl s4H s4L hs4 + | CopyRegisters dest src ss rt tf ti ta => + unfold invoke_tcb_p Tcb_A.invoke_tcb Fl4Spec.invokeTcb embTcbInv + refine mrele_liftE ?_ sH sL hs + refine mrel_kbind (mrel_when Iff.rfl fun _ => suspend_equiv src) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => restart_equiv hop dest) ?_ + refine mrel_bind (archGetSanitiseRegisterInfo_equiv dest) fun bH bL hb => ?_; subst hb + have hfrList : ListRel (FunRel embRegister) Machine_A.frame_registers Fl4Spec.frame_registers := by + rw [frame_registers_eq] + induction Machine_A.frame_registers with + | nil => exact ListRel.nil + | cons r rs ih => exact ListRel.cons rfl ih + have hgpList : ListRel (FunRel embRegister) MachineTypes.gpRegisters Fl4Spec.gpRegisters := by + rw [gpRegisters_eq] + induction MachineTypes.gpRegisters with + | nil => exact ListRel.nil + | cons r rs ih => exact ListRel.cons rfl ih + refine mrel_kbind (mrel_when Iff.rfl fun _ => + mrel_kbind (mrel_mapMx (fun rH rL hr => by + subst hr + exact mrel_bind (asUser_equiv (getRegister_equiv rH) src) fun vH vL hv => by + subst hv; rw [sanitiseRegister_eq]; exact asUser_equiv (setRegister_equiv rH _) dest) hfrList) + (mrel_bind (asUser_equiv getRestartPC_equiv dest) fun pcH pcL hpc => by + subst hpc; exact asUser_equiv (setNextPC_equiv pcH) dest)) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => + mrel_mapMx (fun rH rL hr => by + subst hr + exact mrel_bind (asUser_equiv (getRegister_equiv rH) src) fun vH vL hv => by + subst hv; rw [sanitiseRegister_eq]; exact asUser_equiv (setRegister_equiv rH _) dest) hgpList) ?_ + refine mrel_bind (mrel_gets fun _ _ h => h.curThread_eq.symm) fun curH curL hcur => ?_; subst hcur + refine mrel_kbind (archPostModifyRegisters_equiv curH dest) ?_ + refine mrel_kbind (mrel_when (by simp [holEq_eq_true]) fun _ => rescheduleRequired_equiv hop) ?_ + exact mrel_return rfl + | ReadRegisters src ss n a => + unfold invoke_tcb_p Tcb_A.invoke_tcb Fl4Spec.invokeTcb embTcbInv + refine mrele_liftE ?_ sH sL hs + refine mrel_kbind (mrel_when Iff.rfl fun _ => suspend_equiv src) ?_ + refine mrel_bind (mrel_gets fun _ _ h => h.curThread_eq.symm) fun _ _ _ => ?_ + have hall : ListRel (FunRel embRegister) + (holListTake (holUnsigned n) (holListAppend Machine_A.frame_registers Machine_A.gp_registers)) + ((Fl4Spec.frame_registers ++ Fl4Spec.gp_registers).take (Fl4Spec.unat n)) := by + have h1 : ListRel (FunRel embRegister) Machine_A.frame_registers Fl4Spec.frame_registers := by + rw [frame_registers_eq]; induction Machine_A.frame_registers with | nil => exact ListRel.nil | cons _ _ ih => exact ListRel.cons rfl ih + have h2 : ListRel (FunRel embRegister) Machine_A.gp_registers Fl4Spec.gp_registers := by + rw [gp_registers_eq]; induction Machine_A.gp_registers with | nil => exact ListRel.nil | cons _ _ ih => exact ListRel.cons rfl ih + exact listRel_take n.toNat (listRel_append h1 h2) + refine mrel_bind (mrel_return (Ra := ListRel (FunRel embRegister)) hall) fun rsH rsL hrs => ?_ + have hm : MRel SR (ListRel Eq) + (KHeap_A.as_user src (holMapM MachineOps.getRegister rsH)) + (Fl4Spec.asUser src (NonDet.mapM Fl4Spec.getRegister rsL)) := + asUser_equiv (mrel_mapM (fun rH rL hr => by subst hr; exact getRegister_equiv rH) hrs) src + intro s1H s1L hs1 + have h := hm s1H s1L hs1 + have hlr : ∀ {xs ys : List Word}, ListRel Eq xs ys → xs = ys := by + intro xs ys hl; induction hl with | nil => rfl | cons h1 _ ih => subst h1; exact congrArg _ ih + exact ⟨h.1, + fun aH sH' hm' => let ⟨aL, sL', hm'', ha, hs'⟩ := h.2.1 aH sH' hm'; ⟨aL, sL', hm'', hlr ha, hs'⟩, + fun aL sL' hm' => let ⟨aH, sH', hm'', ha, hs'⟩ := h.2.2 aL sL' hm'; ⟨aH, sH', hm'', hlr ha, hs'⟩⟩ + | WriteRegisters dest rt vals a => + unfold invoke_tcb_p Tcb_A.invoke_tcb Fl4Spec.invokeTcb embTcbInv + refine mrele_liftE ?_ sH sL hs + refine mrel_bind (mrel_gets fun _ _ h => h.curThread_eq.symm) fun selfH selfL hself => ?_; subst hself + refine mrel_bind (archGetSanitiseRegisterInfo_equiv dest) fun bH bL hb => ?_; subst hb + have hall : ListRel (FunRel embRegister) + (holListAppend MachineTypes.frameRegisters MachineTypes.gpRegisters) + (Fl4Spec.frameRegisters ++ Fl4Spec.gpRegisters) := by + have h1 : ListRel (FunRel embRegister) MachineTypes.frameRegisters Fl4Spec.frameRegisters := by + rw [frameRegisters_eq]; induction MachineTypes.frameRegisters with | nil => exact ListRel.nil | cons _ _ ih => exact ListRel.cons rfl ih + have h2 : ListRel (FunRel embRegister) MachineTypes.gpRegisters Fl4Spec.gpRegisters := by + rw [gpRegisters_eq]; induction MachineTypes.gpRegisters with | nil => exact ListRel.nil | cons _ _ ih => exact ListRel.cons rfl ih + exact listRel_append h1 h2 + refine mrel_kbind (asUser_equiv + (mrel_kbind (mrel_zipWithM (fun rH rL hr vH vL hv => by + subst hr; subst hv; rw [sanitiseRegister_eq]; exact setRegister_equiv rH _) hall (listRel_eq vals)) + (mrel_bind getRestartPC_equiv fun pcH pcL hpc => by subst hpc; exact setNextPC_equiv pcH)) dest) ?_ + refine mrel_kbind (archPostModifyRegisters_equiv selfH dest) ?_ + refine mrel_kbind (mrel_when Iff.rfl fun _ => restart_equiv hop dest) ?_ + refine mrel_kbind (mrel_when (by simp [holEq_eq_true]) fun _ => rescheduleRequired_equiv hop) ?_ + exact mrel_return rfl + | NotificationControl tcb n => + cases n with + | some ntfnptr => exact mrele_liftE (mrel_kbind (bindNotification_equiv tcb ntfnptr) (mrel_return rfl)) sH sL hs + | none => exact mrele_liftE (mrel_kbind (unbindNotification_equiv tcb) (mrel_return rfl)) sH sL hs + | SetTLSBase tcb tls => + unfold invoke_tcb_p Tcb_A.invoke_tcb Fl4Spec.invokeTcb embTcbInv + refine mrele_liftE ?_ sH sL hs + refine mrel_bind (archGetSanitiseRegisterInfo_equiv tcb) fun bH bL hb => ?_; subst hb + refine mrel_kbind (asUser_equiv (by + rw [tlsBaseRegister_eq, sanitiseRegister_eq]; exact setRegister_equiv MachineTypes.tlsBaseRegister _) tcb) ?_ + refine mrel_bind (mrel_gets fun _ _ h => h.curThread_eq.symm) fun curH curL hcur => ?_; subst hcur + refine mrel_kbind (mrel_when (by simp [holEq_eq_true]) fun _ => rescheduleRequired_equiv hop) ?_ + exact mrel_return rfl + | SetFlags tcb cf sf => + unfold invoke_tcb_p Tcb_A.invoke_tcb Fl4Spec.invokeTcb embTcbInv + refine mrele_liftE ?_ sH sL hs + refine mrel_bind (threadGet_equiv (Ra := FunRel embTcbFlags) (fun _ => rfl) tcb) fun flH flL hfl => ?_; subst hfl + have hnf : embTcbFlags flH \ embTcbFlags cf ∪ embTcbFlags sf = + embTcbFlags (HolCompleteLattice.holSup (HolSub.subVal flH cf) sf) := by + ext x + obtain ⟨f, rfl⟩ : ∃ f, x = embTcbFlag f := ⟨unembTcbFlag x, (embTcbFlag_unemb x).symm⟩ + simp only [Set.mem_union, Set.mem_sdiff, embTcbFlags_mem, + HolCompleteLattice.holSup, HolSub.subVal] + refine mrel_bind (mrel_return (Ra := FunRel embTcbFlags) hnf) fun nfH nfL hnf' => ?_; subst hnf' + refine mrel_kbind (setFlags_equiv tcb nfH) ?_ + refine mrel_kbind (archPostSetFlags_equiv hop tcb nfH) ?_ + exact mrel_return (by rw [tcbFlagsToWord_eq]) + + +end + +end L4vRefX64.Equiv.Tcb diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/TcbAcc.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/TcbAcc.lean new file mode 100644 index 000000000..f3c4df47b --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/TcbAcc.lean @@ -0,0 +1,300 @@ +import L4vRefX64.Equiv.ArchVSpace +import L4vRefX64.Spec.TcbAcc_A + +namespace L4vRefX64.Equiv.TcbAcc + +open L4vRefX64.Prim +open L4vRefX64.Spec +open L4vRefX64.Rel +open L4vRefX64.Equiv.Machine +open L4vRefX64.Equiv.Structures +open L4vRefX64.Equiv.KHeap +open L4vRefX64.Equiv.ArchVSpace +open Fl4Spec +open Classical + +noncomputable section + +section TcbAccMonad + +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 loadWordOffs_equiv (ptr : ObjRef) (offs : Nat) : + MRel SR Eq (Tcb_A.load_word_offs ptr offs) (Fl4Spec.loadWordOffs ptr offs) := by + unfold Tcb_A.load_word_offs Fl4Spec.loadWordOffs + exact mrel_doMachineOp (loadWord_equiv _) + +theorem storeWordOffs_equiv (ptr : ObjRef) (offs : Nat) (v : Word) : + MRel SR Eq + (TcbAcc_A.store_word_offs ptr offs v) (Fl4Spec.storeWordOffs ptr offs v) := by + unfold TcbAcc_A.store_word_offs Fl4Spec.storeWordOffs + refine mrel_bind (mrel_get (Rs := SR)) fun sH sL hs => ?_ + have haddr : ptr + BitVec.ofNat 64 (offs * Fl4Spec.wordSize) = + HolAdd.addVal ptr ((holOfNat (α := BitVec 64)) (HolMul.mulVal offs Machine_Word_64_Basics.word_size)) := by + rw [wordSize_eq]; rfl + rw [haddr] + refine mrel_kbind (mrel_assert (inUserFrame_iff hs _)) ?_ + exact mrel_doMachineOp (storeWord_equiv _ v) + +theorem setMessageInfo_equiv (thread : ObjRef) (info : Structures_A.message_info) : + MRel SR Eq + (TcbAcc_A.set_message_info thread info) + (Fl4Spec.setMessageInfo thread (embMessageInfo info)) := by + unfold TcbAcc_A.set_message_info Fl4Spec.setMessageInfo + simp only [holFunApp] + rw [messageInfoToData_eq] + change MRel SR Eq + (KHeap_A.as_user thread (MachineOps.setRegister Machine_A.msg_info_register (Structures_A.message_info_to_data info))) + (Fl4Spec.asUser thread (Fl4Spec.setRegister (embRegister Machine_A.msg_info_register) (Structures_A.message_info_to_data info))) + exact asUser_equiv (setRegister_equiv _ _) thread + +private theorem theIndex_map_embRegister (xs : List MachineTypes.register) (r : MachineTypes.register) : + Fl4Spec.theIndex (xs.map embRegister) (embRegister r) = holTheIndex xs r := by + induction xs with + | nil => rfl + | cons x xs ih => + simp only [List.map_cons, Fl4Spec.theIndex, holTheIndex] + by_cases h : x = r + · subst h; simp + · have h' : embRegister x ≠ embRegister r := fun heq => h (embRegister_injective heq) + simp [h, h', ih] + +theorem setMrs_equiv (thread : ObjRef) (buf : Option ObjRef) (msgs : List Message) : + MRel SR Eq + (TcbAcc_A.set_mrs thread buf msgs) (Fl4Spec.setMrs thread buf msgs) := by + unfold TcbAcc_A.set_mrs Fl4Spec.setMrs + refine mrel_bind (mrel_getsThe (getTcb_equiv thread)) fun tH tL ht => ?_ + subst ht + refine mrel_bind (mrel_return (Ra := FunRel embUserRegs) + (by simp [FunRel, embTcb, archTcbGetRegisters_eq])) fun ctxH ctxL hctx => ?_ + subst hctx + have hmr : Fl4Spec.msg_registers = Machine_A.msg_registers.map embRegister := msg_registers_eq + have hnew : (fun reg => + if reg ∈ Fl4Spec.msg_registers.take msgs.length + then the msgs[Fl4Spec.theIndex Fl4Spec.msg_registers reg]? + else embUserRegs ctxH reg) = + embUserRegs (fun reg => + holIf (holMember reg (holListSet (holListTake (holSize msgs) Machine_A.msg_registers))) + (holNth msgs (holTheIndex Machine_A.msg_registers reg)) (ctxH reg)) := by + funext reg + rw [← embRegister_unemb reg] + generalize unembRegister reg = r + simp only [embUserRegs_embRegister, holIf_eq, holMember_eq_true, holListSet_eq, + holListTake_eq, holSize_list, Set.mem_ofPred_eq] + have hmem_iff : embRegister r ∈ Fl4Spec.msg_registers.take msgs.length ↔ + r ∈ Machine_A.msg_registers.take msgs.length := by + rw [hmr, ← List.map_take] + exact ⟨fun h => by + rcases List.mem_map.mp h with ⟨r', hr', heq⟩ + rw [← embRegister_injective heq]; exact hr', + fun h => List.mem_map.mpr ⟨r, h, rfl⟩⟩ + by_cases hm : r ∈ Machine_A.msg_registers.take msgs.length + · have hmL : embRegister r ∈ Fl4Spec.msg_registers.take msgs.length := hmem_iff.mpr hm + simp only [hm, hmL, ↓reduceIte] + rw [hmr, theIndex_map_embRegister] + unfold the holNth holTheOpt + cases msgs[holTheIndex Machine_A.msg_registers r]? <;> rfl + · have hmL : embRegister r ∉ Fl4Spec.msg_registers.take msgs.length := fun h => hm (hmem_iff.mp h) + simp only [hm, hmL, ↓reduceIte] + refine mrel_bind (mrel_return (Ra := FunRel embUserRegs) hnew) fun nrH nrL hnr => ?_ + subst hnr + have hobj : KernelObject.tcb { embTcb tH with + tcbArch := Fl4Spec.archTcbSetRegisters (embUserRegs nrH) (embTcb tH).tcbArch } = + embKernelObject (.TCB (Structures_A.tcb.tcb_arch_update + (fun _ => Arch_Structs_A.arch_tcb_set_registers nrH tH.tcb_arch) tH)) := by + simp [embKernelObject, embTcb, Structures_A.tcb.tcb_arch_update, archTcbSetRegisters_eq] + rw [hobj] + refine mrel_kbind (setObject_equiv thread _) ?_ + have hrem : msgs.drop Fl4Spec.msg_registers.length = + holListDrop (holSize Machine_A.msg_registers) msgs := by + rw [hmr, List.length_map]; rfl + refine mrel_bind (mrel_return hrem.symm) fun remH remL hrem' => ?_ + subst hrem' + cases buf with + | none => + simp only [holCaseOption_none] + refine mrel_return ?_ + rw [hmr, List.length_map, natToLen_eq] + simp only [holMin, HolOrd.leVal, holSize_list] + congr 1; rw [Nat.min_def]; split_ifs <;> simp [*] + | some pptr => + simp only [holCaseOption_some] + have hrange : List.range' (Fl4Spec.msg_registers.length + 1) + (Fl4Spec.msgMaxLength + 1 - (Fl4Spec.msg_registers.length + 1)) = + holListUpt (HolAdd.addVal (holSize Machine_A.msg_registers) (HolOne.oneVal (α := Nat))) + (Nat.succ Structures_A.msg_max_length) := by + rw [hmr, List.length_map, msgMaxLength_eq]; rfl + refine mrel_kbind (mrel_zipWithMx (Ra := Eq) (Rb := Eq) (fun xH xL hx vH vL hv => by + subst hx; subst hv; exact storeWordOffs_equiv pptr xH vH) + (by rw [hrange]; exact listRel_eq _) (listRel_eq remH)) ?_ + refine mrel_return ?_ + rw [msgMaxLength_eq, natToLen_eq] + simp only [holFunApp, holMin, HolOrd.leVal, holSize_list] + congr 1; rw [Nat.min_def]; split_ifs <;> simp [*] + +private theorem listRel_length_eq {αH αL : Type} {R : αH → αL → Prop} + {xs : List αH} {ys : List αL} (h : ListRel R xs ys) : xs.length = ys.length := by + induction h with + | nil => rfl + | cons _ _ ih => simp [ih] + +private theorem listRel_take {αH αL : Type} {R : αH → αL → Prop} (n : Nat) + {xs : List αH} {ys : List αL} (h : ListRel R xs ys) : + ListRel R (xs.take n) (ys.take n) := by + induction h generalizing n with + | nil => simp [ListRel.nil] + | cons h1 _ ih => + cases n with + | zero => exact ListRel.nil + | succ k => exact ListRel.cons h1 (ih k) + +theorem copyMrs_equiv (sender : ObjRef) (sbuf : Option ObjRef) + (receiver : ObjRef) (rbuf : Option ObjRef) (n : LengthType) : + MRel SR Eq + (Tcb_A.copy_mrs sender sbuf receiver rbuf n) + (Fl4Spec.copyMrs sender sbuf receiver rbuf n) := by + unfold Tcb_A.copy_mrs Fl4Spec.copyMrs + have hregs : ListRel (FunRel embRegister) + (holListTake (holUnsigned n) Machine_A.msg_registers) + (Fl4Spec.msg_registers.take (Fl4Spec.unat n)) := by + have hm : ListRel (FunRel embRegister) Machine_A.msg_registers Fl4Spec.msg_registers := by + rw [msg_registers_eq] + induction Machine_A.msg_registers with + | nil => exact ListRel.nil + | cons r rs ih => exact ListRel.cons rfl ih + exact listRel_take n.toNat hm + refine mrel_bind (mrel_return (Ra := ListRel (FunRel embRegister)) hregs) fun hwH hwL hhw => ?_ + refine mrel_kbind (mrel_mapM (fun rH rL hr => by + subst hr + exact mrel_bind (asUser_equiv (getRegister_equiv rH) sender) fun vH vL hv => by + subst hv; exact asUser_equiv (setRegister_equiv rH vH) receiver) hhw) ?_ + have hcont : ∀ (bmH bmL : List Unit), ListRel Eq bmH bmL → MRel SR Eq + (holFunApp holReturn (holFunApp (holMin n) (holFunApp Machine_A.nat_to_len (HolAdd.addVal (holSize hwH) (holSize bmH))))) + (pure (min n (Fl4Spec.natToLen (hwL.length + bmL.length)))) := fun bmH bmL hbm => + mrel_return (by + have h1 := listRel_length_eq hhw + have h2 := listRel_length_eq hbm + have hnat : Machine_A.nat_to_len (HolAdd.addVal (holSize hwH) (holSize bmH)) = + Fl4Spec.natToLen (hwL.length + bmL.length) := by + rw [← natToLen_eq]; simp only [holSize, HolSize.sizeVal, HolAdd.addVal, h1, h2]; rfl + simp only [holFunApp, hnat] + by_cases h : n ≤ Fl4Spec.natToLen (hwL.length + bmL.length) <;> + simp [holMin, HolOrd.leVal, Min.min, h]) + cases sbuf with + | none => + simp only [holCaseProd, holCaseOption] + exact mrel_bind (mrel_return ListRel.nil) hcont + | some sb => + cases rbuf with + | none => + simp only [holCaseProd, holCaseOption] + exact mrel_bind (mrel_return ListRel.nil) hcont + | some rb => + simp only [holCaseProd, holCaseOption] + have hlen : Fl4Spec.msg_registers.length = Machine_A.msg_registers.length := by + rw [msg_registers_eq, List.length_map] + have hrange : holListUpt (HolAdd.addVal (holSize Machine_A.msg_registers) (HolOne.oneVal (α := Nat))) + (Nat.succ (holUnsigned n)) = + List.range' (Fl4Spec.msg_registers.length + 1) (Fl4Spec.unat n + 1 - (Fl4Spec.msg_registers.length + 1)) := by + rw [hlen]; rfl + refine mrel_bind (by + rw [hrange] + exact mrel_mapM (fun xH xL hx => by + subst hx + exact mrel_bind (loadWordOffs_equiv sb xH) fun vH vL hv => by + subst hv; exact storeWordOffs_equiv rb xH vH) (listRel_eq _)) hcont + +theorem getMrs_equiv (thread : ObjRef) (buf : Option ObjRef) (info : Structures_A.message_info) : + MRel SR Eq + (Tcb_A.get_mrs thread buf info) + (Fl4Spec.getMrs thread buf (embMessageInfo info)) := by + unfold Tcb_A.get_mrs Fl4Spec.getMrs + refine mrel_bind (threadGet_equiv (Ra := fun fH fL => ∀ r, fL (embRegister r) = fH r) + (fun t r => by + simp [embTcb, embArchTcb, embUserContext, Fl4Spec.archTcbGetRegisters, + Arch_Structs_A.arch_tcb_get_registers, holComp]; rfl) thread) fun ctxH ctxL hctx => ?_ + have hcpu : Fl4Spec.msg_registers.map ctxL = holListMap ctxH Machine_A.msg_registers := by + rw [msg_registers_eq, List.map_map] + unfold holListMap + refine List.map_congr_left fun r _ => hctx r + refine mrel_bind (mrel_return (Ra := Eq) hcpu.symm) fun cpuH cpuL hcpu' => ?_; subst hcpu' + have hcont : ∀ (bmH bmL : List Word), ListRel Eq bmH bmL → MRel SR Eq + (holReturn (holFunApp (holListTake (holUnsigned info.mi_length)) (holListAppend cpuH bmH))) + (pure ((cpuH ++ bmL).take (Fl4Spec.unat (embMessageInfo info).miLength))) := fun bmH bmL hbm => by + have hbm_eq : bmH = bmL := by + induction hbm with + | nil => rfl + | cons h1 _ ih => subst h1; exact congrArg _ ih + subst hbm_eq + exact mrel_return (by + cases info + simp [embMessageInfo, holListTake, holListAppend, Fl4Spec.unat, holUnsigned] + rfl) + cases buf with + | none => + simp only [holCaseOption] + exact mrel_bind (mrel_return ListRel.nil) hcont + | some pptr => + simp only [holCaseOption] + have hlen : Fl4Spec.msg_registers.length = Machine_A.msg_registers.length := by + rw [msg_registers_eq, List.length_map] + have hml : Fl4Spec.msgMaxLength = Structures_A.msg_max_length := rfl + have hrange : holListUpt (HolAdd.addVal (holSize Machine_A.msg_registers) (HolOne.oneVal (α := Nat))) + (Nat.succ Structures_A.msg_max_length) = + List.range' (Fl4Spec.msg_registers.length + 1) (Fl4Spec.msgMaxLength + 1 - (Fl4Spec.msg_registers.length + 1)) := by + rw [hlen, hml]; rfl + refine mrel_bind (by + rw [hrange] + exact mrel_mapM (fun xH xL hx => by subst hx; exact loadWordOffs_equiv pptr xH) (listRel_eq _)) hcont + +/-- Helper for composing any patched `lookup_ipc_buffer` equivalent with `reply_from_kernel`'s body. -/ +theorem replyFromKernel_body_equiv + {lookupH : HolNonDet (Structures_A.state ZH) (Option ObjRef)} + {lookupL : SMonad ZL (Option ObjRef)} + (hlookup : MRel SR Eq lookupH lookupL) + (thread : ObjRef) (label : Data) (msg : List Data) : + MRel SR Eq + (holBind lookupH fun buf => + holBind (KHeap_A.as_user thread (MachineOps.setRegister Machine_A.badge_register 0)) + (holKBind (holBind (TcbAcc_A.set_mrs thread buf msg) fun len => + TcbAcc_A.set_message_info thread (Structures_A.message_info.MI len 0 0 label)))) + (do + let buf ← lookupL + Fl4Spec.asUser thread (Fl4Spec.setRegister Fl4Spec.badge_register 0) + let len ← Fl4Spec.setMrs thread buf msg + Fl4Spec.setMessageInfo thread ⟨len, 0, 0, label⟩) := by + refine mrel_bind hlookup fun bH bL hb => ?_ + subst hb + refine mrel_kbind (by + change MRel SR Eq + (KHeap_A.as_user thread (MachineOps.setRegister Machine_A.badge_register 0)) + (Fl4Spec.asUser thread (Fl4Spec.setRegister (embRegister Machine_A.badge_register) 0)) + exact asUser_equiv (setRegister_equiv _ 0) thread) ?_ + refine mrel_bind (setMrs_equiv thread bH msg) fun lenH lenL hlen => ?_ + subst hlen + exact setMessageInfo_equiv thread (Structures_A.message_info.MI lenH 0 0 label) + +theorem patched_replyFromKernel_equiv (thread : ObjRef) (msg : Data × List Data) : + MRel SR Eq (Patched.reply_from_kernel thread msg) (Fl4Spec.replyFromKernel thread msg) := by + rcases msg with ⟨label, message⟩ + unfold Patched.reply_from_kernel Fl4Spec.replyFromKernel + simp only [holCaseProd_eq] + change MRel SR Eq _ (NonDet.bind (NonDet.pure (label, message)) + (fun (l, m) => do + let buf ← Fl4Spec.lookupIpcBuffer true thread + Fl4Spec.asUser thread (Fl4Spec.setRegister Fl4Spec.badge_register 0) + let len ← Fl4Spec.setMrs thread buf m + Fl4Spec.setMessageInfo thread ⟨len, 0, 0, l⟩)) + rw [IpcCancel.nonDet_bind_pure_left] + exact replyFromKernel_body_equiv (patched_lookupIpcBuffer_equiv + (RestRel := RestRel) (ZH := ZH) (ZL := ZL) true thread) thread label message + +end TcbAccMonad + +end + +end L4vRefX64.Equiv.TcbAcc diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Types.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Types.lean new file mode 100644 index 000000000..c3c71f756 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Types.lean @@ -0,0 +1,43 @@ +import L4vRefX64.Rel.Embed +import L4vRefX64.Rel.Monad +import L4vRefX64.Spec.VMRights_A + +namespace L4vRefX64.Equiv.Types + +open L4vRefX64.Prim +open L4vRefX64.Rel +open L4vRefX64.Spec + +theorem vmReadOnly_eq : Fl4Spec.vmReadOnly = embRightsSet VMRights_A.vm_read_only := by + ext x; simp [Fl4Spec.vmReadOnly, VMRights_A.vm_read_only, embRightsSet, embRights, HolCompleteLattice.holBot] + +theorem vmReadWrite_eq : Fl4Spec.vmReadWrite = embRightsSet VMRights_A.vm_read_write := by + ext x; simp [Fl4Spec.vmReadWrite, VMRights_A.vm_read_write, embRightsSet, embRights, HolCompleteLattice.holBot] + + +theorem vmKernelOnly_eq : Fl4Spec.vmKernelOnly = embRightsSet VMRights_A.vm_kernel_only := by + ext x + simp [Fl4Spec.vmKernelOnly, VMRights_A.vm_kernel_only, HolCompleteLattice.holBot] + +theorem validateVmRights_eq (rs : Set CapRights_A.rights) : + Fl4Spec.validateVmRights (embRightsSet rs) = embRightsSet (VMRights_A.validate_vm_rights rs) := by + unfold Fl4Spec.validateVmRights VMRights_A.validate_vm_rights + simp only [holIf_eq, holMember_eq_true] + by_cases hr : CapRights_A.rights.AllowRead ∈ rs + · have hr' : Fl4Spec.Rights.allowRead ∈ embRightsSet rs := (embRightsSet_mem .AllowRead rs).mpr hr + by_cases hw : CapRights_A.rights.AllowWrite ∈ rs + · have hw' : Fl4Spec.Rights.allowWrite ∈ embRightsSet rs := (embRightsSet_mem .AllowWrite rs).mpr hw + simp [hr, hr', hw, hw', vmReadWrite_eq] + · have hw' : Fl4Spec.Rights.allowWrite ∉ embRightsSet rs := fun h => hw ((embRightsSet_mem .AllowWrite rs).mp h) + simp [hr, hr', hw, hw', vmReadOnly_eq] + · have hr' : Fl4Spec.Rights.allowRead ∉ embRightsSet rs := fun h => hr ((embRightsSet_mem .AllowRead rs).mp h) + simp [hr, hr', vmKernelOnly_eq] + +theorem maskVmRights_eq (V R : Set CapRights_A.rights) : + Fl4Spec.maskVmRights (embRightsSet V) (embRightsSet R) = + embRightsSet (VMRights_A.mask_vm_rights V R) := by + unfold Fl4Spec.maskVmRights VMRights_A.mask_vm_rights + rw [← embRightsSet_inter] + exact validateVmRights_eq (V ∩ R) + +end L4vRefX64.Equiv.Types diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceAccess.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceAccess.lean new file mode 100644 index 000000000..5a2bf0087 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceAccess.lean @@ -0,0 +1,294 @@ +import L4vRefX64.Equiv.KHeap +import L4vRefX64.Spec.ArchVSpaceAcc_A + +namespace L4vRefX64.Equiv.VSpaceAccess + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.Machine +open Fl4Spec Classical + +noncomputable section + +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 + +private theorem embedUpdate {ι α β : Type} [DecidableEq ι] (embed : α → β) (entries : ι → α) + (index : ι) (value : α) : + Function.update (embed ∘ entries) index (embed value) = + embed ∘ holFunUpd entries index value := by + funext i + by_cases h : i = index <;> simp [Function.update, holFunUpd, h] + +theorem getPt_equiv (ptr : ObjRef) : + MRel SR (FunRel (fun table => embPTE ∘ table)) + (ArchVSpaceAcc_A.get_pt ptr) (Fl4Spec.getPt ptr) := by + unfold ArchVSpaceAcc_A.get_pt Fl4Spec.getPt + refine mrel_bind (getObject_equiv ptr) fun objectH objectL h => ?_ + subst h + cases objectH with + | ArchObj object => cases object <;> first | exact mrel_return rfl | exact mrel_fail + | _ => exact mrel_fail + +theorem setPt_equiv (ptr : ObjRef) (table : BitVec 9 → Arch_Structs_A.pte) : + MRel SR Eq (ArchVSpaceAcc_A.set_pt ptr table) (Fl4Spec.setPt ptr (embPTE ∘ table)) := + setObject_equiv ptr (.ArchObj (.PageTable table)) + +theorem getPte_equiv (ptr : ObjRef) : + MRel SR (FunRel embPTE) (ArchVSpaceAcc_A.get_pte ptr) (Fl4Spec.getPte ptr) := by + unfold ArchVSpaceAcc_A.get_pte Fl4Spec.getPte + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPt_equiv addrH) fun tableH tableL htable => ?_ + subst htable + exact mrel_return rfl + +theorem storePte_equiv (ptr : ObjRef) (entry : Arch_Structs_A.pte) : + MRel SR Eq (ArchVSpaceAcc_A.store_pte ptr entry) (Fl4Spec.storePte ptr (embPTE entry)) := by + unfold ArchVSpaceAcc_A.store_pte Fl4Spec.storePte + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPt_equiv addrH) fun tableH tableL htable => ?_ + subst htable + refine mrel_bind (mrel_return (Ra := FunRel (fun table => embPTE ∘ table)) + ?_) fun newH newL hnew => ?_ + · change _ = embPTE ∘ holFunUpd tableH (Fl4Spec.ucast 9 offsetH) entry + exact embedUpdate embPTE tableH (Fl4Spec.ucast 9 offsetH) entry + · subst hnew + exact setPt_equiv addrH newH + +theorem getPd_equiv (ptr : ObjRef) : + MRel SR (FunRel (fun table => embPDE ∘ table)) + (ArchVSpaceAcc_A.get_pd ptr) (Fl4Spec.getPd ptr) := by + unfold ArchVSpaceAcc_A.get_pd Fl4Spec.getPd + refine mrel_bind (getObject_equiv ptr) fun objectH objectL h => ?_ + subst h + cases objectH with + | ArchObj object => cases object <;> first | exact mrel_return rfl | exact mrel_fail + | _ => exact mrel_fail + +theorem setPd_equiv (ptr : ObjRef) (table : BitVec 9 → Arch_Structs_A.pde) : + MRel SR Eq (ArchVSpaceAcc_A.set_pd ptr table) (Fl4Spec.setPd ptr (embPDE ∘ table)) := + setObject_equiv ptr (.ArchObj (.PageDirectory table)) + +theorem getPde_equiv (ptr : ObjRef) : + MRel SR (FunRel embPDE) (ArchVSpaceAcc_A.get_pde ptr) (Fl4Spec.getPde ptr) := by + unfold ArchVSpaceAcc_A.get_pde Fl4Spec.getPde + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPd_equiv addrH) fun tableH tableL htable => ?_ + subst htable + exact mrel_return rfl + +theorem storePde_equiv (ptr : ObjRef) (entry : Arch_Structs_A.pde) : + MRel SR Eq (ArchVSpaceAcc_A.store_pde ptr entry) (Fl4Spec.storePde ptr (embPDE entry)) := by + unfold ArchVSpaceAcc_A.store_pde Fl4Spec.storePde + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPd_equiv addrH) fun tableH tableL htable => ?_ + subst htable + refine mrel_bind (mrel_return (Ra := FunRel (fun table => embPDE ∘ table)) + ?_) fun newH newL hnew => ?_ + · change _ = embPDE ∘ holFunUpd tableH (Fl4Spec.ucast 9 offsetH) entry + exact embedUpdate embPDE tableH (Fl4Spec.ucast 9 offsetH) entry + · subst hnew + exact setPd_equiv addrH newH + +theorem getPdpt_equiv (ptr : ObjRef) : + MRel SR (FunRel (fun table => embPDPTE ∘ table)) + (ArchVSpaceAcc_A.get_pdpt ptr) (Fl4Spec.getPdpt ptr) := by + unfold ArchVSpaceAcc_A.get_pdpt Fl4Spec.getPdpt + refine mrel_bind (getObject_equiv ptr) fun objectH objectL h => ?_ + subst h + cases objectH with + | ArchObj object => cases object <;> first | exact mrel_return rfl | exact mrel_fail + | _ => exact mrel_fail + +theorem setPdpt_equiv (ptr : ObjRef) (table : BitVec 9 → Arch_Structs_A.pdpte) : + MRel SR Eq (ArchVSpaceAcc_A.set_pdpt ptr table) (Fl4Spec.setPdpt ptr (embPDPTE ∘ table)) := + setObject_equiv ptr (.ArchObj (.PDPointerTable table)) + +theorem getPdpte_equiv (ptr : ObjRef) : + MRel SR (FunRel embPDPTE) (ArchVSpaceAcc_A.get_pdpte ptr) (Fl4Spec.getPdpte ptr) := by + unfold ArchVSpaceAcc_A.get_pdpte Fl4Spec.getPdpte + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPdpt_equiv addrH) fun tableH tableL htable => ?_ + subst htable + exact mrel_return rfl + +theorem storePdpte_equiv (ptr : ObjRef) (entry : Arch_Structs_A.pdpte) : + MRel SR Eq (ArchVSpaceAcc_A.store_pdpte ptr entry) (Fl4Spec.storePdpte ptr (embPDPTE entry)) := by + unfold ArchVSpaceAcc_A.store_pdpte Fl4Spec.storePdpte + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPdpt_equiv addrH) fun tableH tableL htable => ?_ + subst htable + refine mrel_bind (mrel_return (Ra := FunRel (fun table => embPDPTE ∘ table)) + ?_) fun newH newL hnew => ?_ + · change _ = embPDPTE ∘ holFunUpd tableH (Fl4Spec.ucast 9 offsetH) entry + exact embedUpdate embPDPTE tableH (Fl4Spec.ucast 9 offsetH) entry + · subst hnew + exact setPdpt_equiv addrH newH + +theorem getPml4_equiv (ptr : ObjRef) : + MRel SR (FunRel (fun table => embPML4E ∘ table)) + (ArchVSpaceAcc_A.get_pml4 ptr) (Fl4Spec.getPml4 ptr) := by + unfold ArchVSpaceAcc_A.get_pml4 Fl4Spec.getPml4 + refine mrel_bind (getObject_equiv ptr) fun objectH objectL h => ?_ + subst h + cases objectH with + | ArchObj object => cases object <;> first | exact mrel_return rfl | exact mrel_fail + | _ => exact mrel_fail + +theorem setPml4_equiv (ptr : ObjRef) (table : BitVec 9 → Arch_Structs_A.pml4e) : + MRel SR Eq (ArchVSpaceAcc_A.set_pml4 ptr table) (Fl4Spec.setPml4 ptr (embPML4E ∘ table)) := + setObject_equiv ptr (.ArchObj (.PageMapL4 table)) + +theorem getPml4e_equiv (ptr : ObjRef) : + MRel SR (FunRel embPML4E) (ArchVSpaceAcc_A.get_pml4e ptr) (Fl4Spec.getPml4e ptr) := by + unfold ArchVSpaceAcc_A.get_pml4e Fl4Spec.getPml4e + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPml4_equiv addrH) fun tableH tableL htable => ?_ + subst htable + exact mrel_return rfl + +theorem storePml4e_equiv (ptr : ObjRef) (entry : Arch_Structs_A.pml4e) : + MRel SR Eq (ArchVSpaceAcc_A.store_pml4e ptr entry) (Fl4Spec.storePml4e ptr (embPML4E entry)) := by + unfold ArchVSpaceAcc_A.store_pml4e Fl4Spec.storePml4e + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun addrH addrL haddr => ?_ + subst haddr + refine mrel_bind (mrel_return (Ra := Eq) (by rw [mask_eq]; rfl)) fun offsetH offsetL hoffset => ?_ + subst hoffset + refine mrel_bind (getPml4_equiv addrH) fun tableH tableL htable => ?_ + subst htable + refine mrel_bind (mrel_return (Ra := FunRel (fun table => embPML4E ∘ table)) + ?_) fun newH newL hnew => ?_ + · change _ = embPML4E ∘ holFunUpd tableH (Fl4Spec.ucast 9 offsetH) entry + exact embedUpdate embPML4E tableH (Fl4Spec.ucast 9 offsetH) entry + · subst hnew + exact setPml4_equiv addrH newH +theorem getPtIndex_eq (address : ObjRef) : + Fl4Spec.getPtIndex address = ArchVSpaceAcc_A.get_pt_index address := by + unfold Fl4Spec.getPtIndex ArchVSpaceAcc_A.get_pt_index + rw [mask_eq] + rfl + +theorem getPdIndex_eq (address : ObjRef) : + Fl4Spec.getPdIndex address = ArchVSpaceAcc_A.get_pd_index address := by + unfold Fl4Spec.getPdIndex ArchVSpaceAcc_A.get_pd_index + rw [mask_eq] + rfl + +theorem getPdptIndex_eq (address : ObjRef) : + Fl4Spec.getPdptIndex address = ArchVSpaceAcc_A.get_pdpt_index address := by + unfold Fl4Spec.getPdptIndex ArchVSpaceAcc_A.get_pdpt_index + rw [mask_eq] + rfl + +theorem getPml4Index_eq (address : ObjRef) : + Fl4Spec.getPml4Index address = ArchVSpaceAcc_A.get_pml4_index address := by + unfold Fl4Spec.getPml4Index ArchVSpaceAcc_A.get_pml4_index + rw [mask_eq] + rfl + +theorem ptrFromPAddr_eq (address : ObjRef) : + Fl4Spec.ptrFromPAddr address = Platform.ptrFromPAddr address := rfl + +theorem lookupPml4Slot_eq (root address : ObjRef) : + Fl4Spec.lookupPml4Slot root address = ArchVSpaceAcc_A.lookup_pml4_slot root address := by + unfold Fl4Spec.lookupPml4Slot ArchVSpaceAcc_A.lookup_pml4_slot + rw [getPml4Index_eq] + rfl + +theorem lookupPdptSlot_equiv (root address : ObjRef) : + MRelE SR (FunRel embLookupFailure) Eq + (ArchVSpaceAcc_A.lookup_pdpt_slot root address) (Fl4Spec.lookupPdptSlot root address) := by + unfold ArchVSpaceAcc_A.lookup_pdpt_slot Fl4Spec.lookupPdptSlot + refine mrele_bindE (mrele_returnOk (Ra := Eq) (lookupPml4Slot_eq root address).symm) fun slotH slotL hslot => ?_ + subst hslot + refine mrele_bindE (mrele_liftE (getPml4e_equiv slotH)) fun entryH entryL hentry => ?_ + subst hentry + cases entryH with + | PDPointerTablePML4E table attributes rights => + refine mrele_bindE (mrele_returnOk (Ra := Eq) (ptrFromPAddr_eq table).symm) fun addrH addrL haddr => ?_ + subst haddr + refine mrele_bindE (mrele_returnOk (Ra := Eq) (getPdptIndex_eq address).symm) fun indexH indexL hindex => ?_ + subst hindex + exact mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun _ _ hresult => mrele_returnOk hresult + | _ => exact mrele_throwError rfl + +theorem lookupPdSlot_equiv (root address : ObjRef) : + MRelE SR (FunRel embLookupFailure) Eq + (ArchVSpaceAcc_A.lookup_pd_slot root address) (Fl4Spec.lookupPdSlot root address) := by + unfold ArchVSpaceAcc_A.lookup_pd_slot Fl4Spec.lookupPdSlot + refine mrele_bindE (lookupPdptSlot_equiv root address) fun slotH slotL hslot => ?_ + subst hslot + refine mrele_bindE (mrele_liftE (getPdpte_equiv slotH)) fun entryH entryL hentry => ?_ + subst hentry + cases entryH with + | PageDirectoryPDPTE table attributes rights => + refine mrele_bindE (mrele_returnOk (Ra := Eq) (ptrFromPAddr_eq table).symm) fun addrH addrL haddr => ?_ + subst haddr + refine mrele_bindE (mrele_returnOk (Ra := Eq) (getPdIndex_eq address).symm) fun indexH indexL hindex => ?_ + subst hindex + exact mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun _ _ hresult => mrele_returnOk hresult + | _ => exact mrele_throwError rfl + +theorem lookupPtSlot_equiv (root address : ObjRef) : + MRelE SR (FunRel embLookupFailure) Eq + (ArchVSpaceAcc_A.lookup_pt_slot root address) (Fl4Spec.lookupPtSlot root address) := by + unfold ArchVSpaceAcc_A.lookup_pt_slot Fl4Spec.lookupPtSlot + refine mrele_bindE (lookupPdSlot_equiv root address) fun slotH slotL hslot => ?_ + subst hslot + refine mrele_bindE (mrele_liftE (getPde_equiv slotH)) fun entryH entryL hentry => ?_ + subst hentry + cases entryH with + | PageTablePDE table attributes rights => + refine mrele_bindE (mrele_returnOk (Ra := Eq) (ptrFromPAddr_eq table).symm) fun addrH addrL haddr => ?_ + subst haddr + refine mrele_bindE (mrele_returnOk (Ra := Eq) (getPtIndex_eq address).symm) fun indexH indexL hindex => ?_ + subst hindex + exact mrele_bindE (mrele_returnOk (Ra := Eq) rfl) fun _ _ hresult => mrele_returnOk hresult + | _ => exact mrele_throwError rfl + +theorem copyGlobalMappings_equiv (root : ObjRef) : + MRel SR Eq (ArchVSpaceAcc_A.copy_global_mappings root) (Fl4Spec.copyGlobalMappings root) := by + unfold ArchVSpaceAcc_A.copy_global_mappings Fl4Spec.copyGlobalMappings + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ hs => by rw [hs.archState_eq]; rfl) fun gpH gpL hgp => ?_ + subst hgp + refine mrel_bind (mrel_return (Ra := Eq) (getPml4Index_eq Fl4Spec.pptr_base).symm) fun baseH baseL hbase => ?_ + subst hbase + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun sizeH sizeL hsize => ?_ + subst hsize + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun limitH limitL hlimit => ?_ + subst hlimit + rw [holUptoEnum_bv_eq] + refine mrel_mapMx (Rb := Eq) (fun iH iL hi => ?_) (listRel_eq _) + subst hi + refine mrel_bind (mrel_return (Ra := Eq) rfl) fun offH offL hoff => ?_ + subst hoff + refine mrel_bind (getPml4e_equiv (gpH + offH)) fun entryH entryL hentry => ?_ + subst hentry + exact storePml4e_equiv (root + offH) entryH + +end + +end L4vRefX64.Equiv.VSpaceAccess diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceRoot.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceRoot.lean new file mode 100644 index 000000000..b303f5155 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceRoot.lean @@ -0,0 +1,274 @@ +import L4vRefX64.Equiv.ArchVSpace + +namespace L4vRefX64.Equiv.VSpaceRoot + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.KHeap L4vRefX64.Equiv.CSpaceAcc L4vRefX64.Equiv.IpcCancel +open Fl4Spec Classical + +noncomputable section + +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 asidLowBitsOf_eq (asid : Asid) : + Fl4Spec.asidLowBitsOf asid = ArchVSpaceAcc_A.asid_low_bits_of asid := rfl + +theorem asidHighBitsOf_cast (asid : Asid) : + (Fl4Spec.asidHighBitsOf asid).setWidth 3 = ArchVSpaceAcc_A.asid_high_bits_of asid := by + change ((asid >>> 9).setWidth 11).setWidth 3 = (asid >>> 9).setWidth 3 + apply BitVec.eq_of_toNat_eq + simp + +theorem asidHighBitsOf_lt (asid : Asid) (h : BaseAsid asid) : + (Fl4Spec.asidHighBitsOf asid).toNat < 8 := by + change ((asid >>> 9).setWidth 11).toNat < 8 + simp only [BitVec.toNat_setWidth, BitVec.toNat_ushiftRight] + change asid.toNat < 4096 at h + rw [Nat.shiftRight_eq_div_pow] + have hs : asid.toNat / 512 < 8 := by omega + exact lt_of_le_of_lt (Nat.mod_le _ _) hs + +theorem asidTable_eq {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (asid : Asid) (h : BaseAsid asid) : + sL.archState.x64AsidTable (Fl4Spec.asidHighBitsOf asid) = + sH.arch_state.x64_asid_table (ArchVSpaceAcc_A.asid_high_bits_of asid) := by + rw [hs.archState_eq] + change (if (Fl4Spec.asidHighBitsOf asid).toNat < 8 then + sH.arch_state.x64_asid_table ((Fl4Spec.asidHighBitsOf asid).setWidth 3) else none) = _ + rw [ite_eq_left (asidHighBitsOf_lt asid h), asidHighBitsOf_cast] + +theorem getAsidPool_equiv (ptr : ObjRef) : + MRel SR Eq (ArchVSpaceAcc_A.get_asid_pool ptr) (Fl4Spec.getAsidPool ptr) := by + unfold ArchVSpaceAcc_A.get_asid_pool Fl4Spec.getAsidPool + refine mrel_bind (getObject_equiv ptr) fun kH kL hk => ?_ + subst hk + cases kH with + | ArchObj archObj => + cases archObj <;> first | exact mrel_return rfl | exact mrel_fail + | _ => exact mrel_fail + +omit [StateExt ZL] in +theorem getAsidPool_member {sH sH' : Structures_A.state ZH} {ptr : ObjRef} + {entries : AsidLowIndex → Option ObjRef} + (hm : (entries, sH') ∈ (ArchVSpaceAcc_A.get_asid_pool ptr sH).1) : + sH' = sH ∧ sH.kheap ptr = some (.ArchObj (.ASIDPool entries)) := by + unfold ArchVSpaceAcc_A.get_asid_pool at hm + simp only [holBind, Set.mem_ofPred_eq, Prod.exists] at hm + obtain ⟨obj, s1, hread, hpool⟩ := hm + obtain ⟨hk, rfl⟩ := getObject_member hread + cases obj with + | ArchObj arch => + cases arch <;> + simp only [Structures_A.case_kernel_object, Arch_Structs_A.case_arch_kernel_obj, + holReturn, holFail, Set.mem_singleton_iff, Prod.mk.injEq, Set.mem_empty_iff_false] at hpool + next table => + obtain ⟨rfl, rfl⟩ := hpool + exact ⟨rfl, hk⟩ + | _ => simp only [Structures_A.case_kernel_object, holFail, Set.mem_empty_iff_false] at hpool + +private theorem holReturnOk_member {σ ε α : Type} {s s' : σ} {a b : α} + (hm : (Sum.inr (α := ε) b, s') ∈ (holReturnOk a s).1) : s' = s ∧ b = a := by + simpa [holReturnOk, holReturn, and_comm] using hm + +theorem findVspaceForAsid_equiv (asid : Asid) (hasid : BaseAsid asid) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) : + MRelStep SR (SumExceptRel (FunRel embLookupFailure) Eq) + (ArchVSpace_A.find_vspace_for_asid asid sH) + ((Fl4Spec.findVspaceForAsid asid).run sL) := by + unfold ArchVSpace_A.find_vspace_for_asid Fl4Spec.findVspaceForAsid + refine mrelStep_kbindE_mem + (mrele_assertE (Re := FunRel embLookupFailure) (by + simp [holLt_eq_true, HolOrd.ltVal, HolZero.zeroVal]) sH sL hs) + fun u s1H s1L hs1 hm1 => ?_ + have hstate : s1H = sH := by + unfold holAssertE holLiftE holLiftM holAssert at hm1 + cases h : holLt (HolZero.zeroVal (α := BitVec 64)) asid <;> + simp_all [holBind, holReturn] + subst s1H + refine mrelStep_bindE_mem (mrelStep_liftE + ((mrel_gets (Rs := SR) (Ra := fun tableH tableL => + tableL (Fl4Spec.asidHighBitsOf asid) = tableH (ArchVSpaceAcc_A.asid_high_bits_of asid)) + (fun _ _ h => asidTable_eq h asid hasid)) sH s1L hs1)) + fun tableH tableL ht s2H s2L hs2 hm2 => ?_ + have hs2eq : s2H = sH := by + simp [holLiftE, holLiftM, holBind, holGets, holReturn] at hm2 + exact hm2.2 + subst s2H + refine mrelStep_bindE_mem ((mrele_returnOk (Ra := Eq) ht.symm) sH s2L hs2) + fun ptrH ptrL hp s3H s3L hs3 hm3 => ?_ + obtain ⟨hs3eq, hptrEq⟩ := holReturnOk_member hm3 + subst s3H + subst ptrH + subst ptrL + cases hptr : tableH (ArchVSpaceAcc_A.asid_high_bits_of asid) with + | none => + simp only [holCaseOption_none] + refine mrelStep_bindE_mem + ((mrele_throwError (Ra := Eq) (Re := FunRel embLookupFailure) rfl) sH s3L hs3) + fun _ _ _ _ _ _ hnone => ?_ + simp [holThrowError, holReturn] at hnone + | some ptr => + simp only [holCaseOption_some] + refine mrelStep_bindE_mem (mrelStep_liftE ((getAsidPool_equiv ptr) sH s3L hs3)) + fun entriesH entriesL he s4H s4L hs4 hm4 => ?_ + subst he + have hpool : (entriesH, s4H) ∈ (ArchVSpaceAcc_A.get_asid_pool ptr sH).1 := by + simpa [holLiftE, holLiftM, holBind, holReturn] using hm4 + have hheap := (getAsidPool_member hpool).2 + have hheapL : sL.kheap ptr = some (.archObj (.asidPool entriesH)) := by + rw [hs.kheap_eq, hheap] + rfl + have hnative : Fl4Spec.nativeAsidRoot (entriesH (Fl4Spec.asidLowBitsOf asid)) = + entriesH (ArchVSpaceAcc_A.asid_low_bits_of asid) := by + rw [asidLowBitsOf_eq] + cases hentry : entriesH (ArchVSpaceAcc_A.asid_low_bits_of asid) with + | none => rfl + | some root => + change (if root &&& (1 : Word) = 0 then some root else none) = some root + rw [ite_eq_left (hb.untaggedAsidEntries _ _ _ _ hheapL hentry)] + refine mrelStep_bindE_mem ((mrele_returnOk (Ra := Eq) hnative.symm) s4H s4L hs4) + fun aH aL ha s5H s5L hs5 _ => ?_ + subst ha + cases aH with + | none => exact (mrele_throwError (Ra := Eq) (Re := FunRel embLookupFailure) rfl) s5H s5L hs5 + | some root => exact (mrele_returnOk (Ra := Eq) rfl) s5H s5L hs5 + +theorem getCurrentCr3_equiv : + MRel SR (FunRel embCr3) ArchVSpace_A.get_current_cr3 Fl4Spec.getCurrentCr3 := + mrel_gets fun _ _ hs => by rw [hs.archState_eq]; rfl + +theorem embCr3_injective : Function.Injective embCr3 := by + rintro ⟨baseH, asidH⟩ ⟨baseL, asidL⟩ h + cases h + rfl + +theorem setCurrentCr3_equiv (c : Arch_Structs_A.cr3) : + MRel SR Eq (ArchVSpace_A.set_current_cr3 c) (Fl4Spec.setCurrentCr3 (embCr3 c)) := by + unfold ArchVSpace_A.set_current_cr3 Fl4Spec.setCurrentCr3 + refine mrel_modify fun sH sL hs => ?_ + have harch := congrArg (fun ar : ArchState => { ar with x64CurrentCr3 := embCr3 c }) hs.archState_eq + exact { hs with archState_eq := harch } + +theorem makeCr3_eq (vspace : ObjRef) (asid : Asid) : + embCr3 (ArchVSpace_A.make_cr3 vspace asid) = Fl4Spec.makeCr3 vspace asid := rfl + +theorem setCurrentVspaceRoot_equiv (vspace : ObjRef) (asid : Asid) : + MRel SR Eq (ArchVSpace_A.set_current_vspace_root vspace asid) + (Fl4Spec.setCurrentVspaceRoot vspace asid) := + setCurrentCr3_equiv (ArchVSpace_A.make_cr3 vspace asid) + +theorem addrFromPPtr_eq (ptr : ObjRef) : Platform.addrFromPPtr ptr = Fl4Spec.addrFromPPtr ptr := rfl + +theorem addrFromKPPtr_eq (ptr : ObjRef) : Platform.addrFromKPPtr ptr = Fl4Spec.addrFromKPPtr ptr := rfl + +private theorem getVTable_base {sH : Structures_A.state ZH} {sL : State ZL} + (hs : SR sH sL) (hb : BaseCarriers sL) (thread : ObjRef) (cap : Structures_A.cap) + (hcap : (match sH.kheap thread with + | some (.CNode _ caps) => caps (Structures_A.tcb_cnode_index 1) + | some (.TCB tcb) => Structures_A.tcb_cnode_map tcb (Structures_A.tcb_cnode_index 1) + | _ => none) = some cap) : BaseCap (embCap cap) := by + cases hk : sH.kheap thread with + | none => simp [hk] at hcap + | some obj => + cases obj with + | CNode n cs => + have hkL : sL.kheap thread = some (.cnode n fun slot => (cs slot).map embCap) := by + rw [hs.kheap_eq, hk] + rfl + refine hb.cnodeCaps thread n _ (Structures_A.tcb_cnode_index 1) (embCap cap) hkL ?_ + have hentry : cs (Structures_A.tcb_cnode_index 1) = some cap := by simpa [hk] using hcap + rw [hentry] + rfl + | TCB t => + have hkL : sL.kheap thread = some (.tcb (embTcb t)) := by + rw [hs.kheap_eq, hk] + rfl + have hslot : Structures_A.tcb_cnode_map t (Structures_A.tcb_cnode_index 1) = + some t.tcb_vtable := by + have h12 : Structures_A.tcb_cnode_index 1 ≠ Structures_A.tcb_cnode_index 2 := by decide + have h13 : Structures_A.tcb_cnode_index 1 ≠ Structures_A.tcb_cnode_index 3 := by decide + have h14 : Structures_A.tcb_cnode_index 1 ≠ Structures_A.tcb_cnode_index 4 := by decide + simp [Structures_A.tcb_cnode_map, holFunUpd, Function.update, + HolOne.oneVal, HolNumeral.ofNatVal, h12, h13, h14] + have hv : t.tcb_vtable = cap := by + simpa [hk, hslot] using hcap + rw [← hv] + exact (hb.tcbs thread (embTcb t) hkL).vtable + | _ => simp [hk] at hcap + +private theorem globalRoot_equiv : + MRel SR Eq + (holBind (holGets (holComp Arch_Structs_A.arch_state_ext.x64_global_pml4 + Structures_A.abstract_state_ext.arch_state)) fun global => + ArchVSpace_A.set_current_vspace_root (Platform.addrFromKPPtr global) 0) + (do + let global ← NonDet.gets fun s : State ZL => s.archState.x64GlobalPml4 + Fl4Spec.setCurrentVspaceRoot (Fl4Spec.addrFromKPPtr global) 0) := by + refine mrel_bind (mrel_gets (Ra := Eq) fun _ _ h => by rw [h.archState_eq]; rfl) ?_ + intro gH gL hg + subst hg + exact setCurrentVspaceRoot_equiv _ _ + +theorem setVmRoot_equiv (thread : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) : + MRelStep SR Eq (ArchVSpace_A.set_vm_root thread sH) (Fl4Spec.setVmRoot thread sL) := by + unfold ArchVSpace_A.set_vm_root Fl4Spec.setVmRoot + change MRelStep SR Eq _ (NonDet.bind (NonDet.pure (thread, Fl4Spec.tcbCnodeIndex 1)) _ sL) + rw [KHeap.holBind_return_left, nonDet_bind_pure_left] + refine mrelStep_bind_mem + ((getCap_equiv_nonExt (thread, Fl4Spec.tcbCnodeIndex 1) + (show Fl4Spec.tcbCnodeIndex 1 ≠ Fl4Spec.tcbCnodeIndex 5 from by decide)) sH sL hs) + fun cH cL hc s1H s1L hs1 hm => ?_ + subst hc + obtain ⟨hs1eq, hheap⟩ := getCap_member_heap hm + subst s1H + have hbase := getVTable_base hs hb thread cH hheap + have hb1 := hs1.baseCarriers_iff.mpr (hs.baseCarriers_iff.mp hb) + have hglobal := globalRoot_equiv (RestRel := RestRel) (ZH := ZH) (ZL := ZL) + have hinvalid : MRelStep SR Eq + (holCatch (holThrowError ExceptionTypes_A.lookup_failure.InvalidRoot) (fun _ => + holBind (holGets (holComp Arch_Structs_A.arch_state_ext.x64_global_pml4 + Structures_A.abstract_state_ext.arch_state)) fun global => + ArchVSpace_A.set_current_vspace_root (Platform.addrFromKPPtr global) 0) sH) + (NonDetE.catch (NonDetE.throwError LookupFailure.invalidRoot) (fun _ => do + let global ← NonDet.gets fun s : State ZL => s.archState.x64GlobalPml4 + Fl4Spec.setCurrentVspaceRoot (Fl4Spec.addrFromKPPtr global) 0) s1L) := by + refine mrelStep_catch_mem + ((mrele_throwError (Re := FunRel embLookupFailure) (Ra := Eq) rfl) sH s1L hs1) + fun _ _ _ stH stL hst _ => hglobal stH stL hst + cases cH with + | ArchObjectCap ac => + cases ac with + | PML4Cap p mapping => + cases mapping with + | none => exact hinvalid + | some asid => + have hasid : BaseAsid asid := hbase asid rfl + simp only [Structures_A.case_cap, Arch_Structs_A.case_arch_cap, holCaseOption_some, + embCap, embArchCap] + refine mrelStep_catch_mem (Re := FunRel embLookupFailure) ?_ fun _ _ _ stH stL hst _ => hglobal stH stL hst + refine mrelStep_bindE_mem (findVspaceForAsid_equiv asid hasid hs1 hb1) + fun pH pL hp stH stL hst _ => ?_ + subst hp + refine mrelStep_kbindE_mem + ((mrele_whenE (Re := FunRel embLookupFailure) (by simp [holNot_eq_true, holEq_eq_true]) + fun _ => mrele_throwError rfl) stH stL hst) + fun _ st2H st2L hst2 _ => ?_ + refine mrelStep_bindE_mem + (mrelStep_liftE (getCurrentCr3_equiv st2H st2L hst2)) + fun crH crL hcr st3H st3L hst3 _ => ?_ + subst hcr + refine (mrele_whenE (Re := FunRel embLookupFailure) ?_ fun _ => + mrele_liftE (setCurrentCr3_equiv _)) st3H st3L hst3 + rw [holNot_eq_true, ← makeCr3_eq, ← addrFromPPtr_eq] + exact not_congr ((holEq_eq_true _ _).trans embCr3_injective.eq_iff.symm) + | _ => exact hinvalid + | _ => exact hinvalid + +end + +end L4vRefX64.Equiv.VSpaceRoot diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceUnmap.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceUnmap.lean new file mode 100644 index 000000000..8d03c52c9 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/VSpaceUnmap.lean @@ -0,0 +1,466 @@ +import L4vRefX64.Equiv.VSpaceAccess +import L4vRefX64.Equiv.VSpaceRoot +import L4vRefX64.Equiv.Hardware + +namespace L4vRefX64.Equiv.VSpaceUnmap + +open L4vRefX64.Prim L4vRefX64.Spec L4vRefX64.Rel +open L4vRefX64.Equiv.Machine L4vRefX64.Equiv.VSpaceRoot L4vRefX64.Equiv.VSpaceAccess +open L4vRefX64.Equiv.Hardware L4vRefX64.Equiv.KHeap +open Fl4Spec Classical + +noncomputable section + +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 invalidatePageStructureCacheAsid_equiv (hop : OpaqueRel RestRel) (root : ObjRef) (asid : Asid) : + MRel SR Eq (ArchVSpace_A.invalidate_page_structure_cache_asid root asid) + (Fl4Spec.invalidatePageStructureCacheAsid root asid) := + mrel_doMachineOp (invalidateLocalPageStructureCacheASID_equiv hop root asid) + +theorem flushAll_equiv (hop : OpaqueRel RestRel) (root : ObjRef) (asid : Asid) : + MRel SR Eq (ArchVSpace_A.flush_all root asid) (Fl4Spec.flushAll root asid) := + mrel_doMachineOp (invalidateASID_equiv hop root asid) + +theorem flushTable_equiv (hop : OpaqueRel RestRel) (root addr table : ObjRef) (asid : Asid) : + MRel SR Eq (ArchVSpace_A.flush_table root addr table asid) (Fl4Spec.flushTable root addr table asid) := by + unfold ArchVSpace_A.flush_table Fl4Spec.flushTable + simp only [holFunApp] + refine mrel_kbind (mrel_assert (by rw [holEq_eq_true]; rfl)) ?_ + refine mrel_bind (getPt_equiv table) fun ptH ptL hpt => ?_ + subst hpt + unfold NonDet.forMx + rw [holUptoEnum_bv_eq] + refine mrel_mapMx (Rb := Eq) (fun idxH idxL hidx => ?_) (listRel_eq _) + subst hidx + refine mrel_bind (mrel_return (Ra := FunRel embPTE) rfl) fun eH eL he => ?_ + subst he + cases eH with + | InvalidPTE => exact mrel_return rfl + | SmallPagePTE _ _ _ => + exact mrel_doMachineOp (invalidateTranslationSingleASID_equiv hop + (addr + (BitVec.setWidth 64 idxH <<< MachineTypes.pageBits)) asid) + +private theorem decide_irrel {p : Prop} (a b : Decidable p) : @decide p a = @decide p b := + congrArg (fun d => @decide p d) (Subsingleton.elim a b) + +theorem checkMappingPptr_eq (ptr : ObjRef) (entry : Arch_Structs_A.vm_page_entry) : + ArchVSpace_A.check_mapping_pptr ptr entry = Fl4Spec.checkMappingPptr ptr (embVMPageEntry entry) := by + cases entry with + | VMPTE e => cases e <;> simp [ArchVSpace_A.check_mapping_pptr, Fl4Spec.checkMappingPptr, + Arch_Structs_A.case_vm_page_entry, Arch_Structs_A.case_pte, embVMPageEntry, embPTE, holEq, addrFromPPtr_eq]; exact decide_irrel _ _ + | VMPDE e => cases e <;> simp [ArchVSpace_A.check_mapping_pptr, Fl4Spec.checkMappingPptr, + Arch_Structs_A.case_vm_page_entry, Arch_Structs_A.case_pde, embVMPageEntry, embPDE, holEq, addrFromPPtr_eq]; exact decide_irrel _ _ + | VMPDPTE e => cases e <;> simp [ArchVSpace_A.check_mapping_pptr, Fl4Spec.checkMappingPptr, + Arch_Structs_A.case_vm_page_entry, Arch_Structs_A.case_pdpte, embVMPageEntry, embPDPTE, holEq, addrFromPPtr_eq]; exact decide_irrel _ _ + + +/-- [P] The input state and the ASID admit the original native carrier. -/ +theorem unmapPage_equiv (hop : OpaqueRel RestRel) (size : MachineTypes.vmpage_size) + (asid : Asid) (addr ptr : ObjRef) (hasid : BaseAsid asid) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) (hb : BaseCarriers sL) : + MRelStep SR Eq (ArchVSpace_A.unmap_page size asid addr ptr sH) + (Fl4Spec.unmapPage (embVMPageSize size) asid addr ptr sL) := by + unfold ArchVSpace_A.unmap_page Fl4Spec.unmapPage + simp only [holFunApp] + refine mrelStep_catch_mem (Re := FunRel embLookupFailure) ?_ (fun _ _ _ uH uL hu _ => mrel_return rfl uH uL hu) + refine mrelStep_bindE_mem (findVspaceForAsid_equiv asid hasid hs hb) fun rootH rootL hroot tH tL ht _ => ?_ + subst hroot + have hinv := mrel_doMachineOp (ExstRel := ser.exstRel) (invalidateTranslationSingleASID_equiv hop addr asid) + cases size <;> simp only [MachineTypes.case_vmpage_size, embVMPageSize, holBindE_assoc, holKBind] + · refine (mrele_bindE (lookupPtSlot_equiv rootH addr) fun slotH slotL hslot => ?_) tH tL ht + subst hslot + refine mrele_bindE (mrele_liftE (getPte_equiv slotH)) fun eH eL he => ?_ + subst he + refine mrele_kbindE (mrele_unlessE (by rw [checkMappingPptr_eq]; rfl) (fun _ => mrele_throwError rfl)) ?_ + exact mrele_kbindE (mrele_liftE (storePte_equiv slotH .InvalidPTE)) (mrele_liftE hinv) + · refine (mrele_bindE (lookupPdSlot_equiv rootH addr) fun slotH slotL hslot => ?_) tH tL ht + subst hslot + refine mrele_bindE (mrele_liftE (getPde_equiv slotH)) fun eH eL he => ?_ + subst he + refine mrele_kbindE (mrele_unlessE (by rw [checkMappingPptr_eq]; rfl) (fun _ => mrele_throwError rfl)) ?_ + exact mrele_kbindE (mrele_liftE (storePde_equiv slotH .InvalidPDE)) (mrele_liftE hinv) + · refine (mrele_bindE (lookupPdptSlot_equiv rootH addr) fun slotH slotL hslot => ?_) tH tL ht + subst hslot + refine mrele_bindE (mrele_liftE (getPdpte_equiv slotH)) fun eH eL he => ?_ + subst he + refine mrele_kbindE (mrele_unlessE (by rw [checkMappingPptr_eq]; rfl) (fun _ => mrele_throwError rfl)) ?_ + exact mrele_kbindE (mrele_liftE (storePdpte_equiv slotH .InvalidPDPTE)) (mrele_liftE hinv) + +private theorem unmapTableFinish_equiv (hop : OpaqueRel RestRel) (vspace : ObjRef) (asid : Asid) + {mH nH : HolNonDet (Structures_A.state ZH) Unit} {mL nL : SMonad ZL Unit} + (hm : MRel SR Eq mH mL) (hn : MRel SR Eq nH nL) : + MRelE SR (FunRel embLookupFailure) Eq + (holLiftE (holBind mH (holKBind (holBind nH + (holKBind (ArchVSpace_A.invalidate_page_structure_cache_asid (Platform.addrFromPPtr vspace) asid)))))) + (NonDetE.liftE (do + mL + nL + Fl4Spec.invalidatePageStructureCacheAsid (Fl4Spec.addrFromPPtr vspace) asid)) := by + rw [addrFromPPtr_eq] + exact mrele_liftE (mrel_kbind hm (mrel_kbind hn (invalidatePageStructureCacheAsid_equiv hop (Fl4Spec.addrFromPPtr vspace) asid))) + +/-- [P] The input state and the ASID admit the original native carrier. -/ +theorem unmapPageTable_equiv (hop : OpaqueRel RestRel) (asid : Asid) (addr table : ObjRef) + (hasid : BaseAsid asid) {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) : + MRelStep SR Eq (ArchVSpace_A.unmap_page_table asid addr table sH) (Fl4Spec.unmapPageTable asid addr table sL) := by + unfold ArchVSpace_A.unmap_page_table Fl4Spec.unmapPageTable + simp only [holFunApp] + refine mrelStep_catch_mem (Re := FunRel embLookupFailure) ?_ + (fun _ _ _ tH tL ht _ => mrel_return rfl tH tL ht) + refine mrelStep_bindE_mem (findVspaceForAsid_equiv asid hasid hs hb) fun rootH rootL hr tH tL ht _ => ?_ + subst hr + refine (mrele_bindE (lookupPdSlot_equiv rootH addr) fun slotH slotL hslot => ?_) tH tL ht + subst hslot + refine mrele_bindE (mrele_liftE (getPde_equiv slotH)) fun eH eL he => ?_ + subst he + cases eH with + | PageTablePDE base _ _ => + simp only [Arch_Structs_A.case_pde, embPDE, holIf_eq] + have hcheck : holEq (Platform.addrFromPPtr table) base = true ↔ Fl4Spec.addrFromPPtr table = base := by + rw [holEq_eq_true, addrFromPPtr_eq] + have hfinish := unmapTableFinish_equiv hop rootH asid + (flushTable_equiv (ZH := ZH) (ZL := ZL) hop rootH addr table asid) (storePde_equiv slotH .InvalidPDE) + by_cases h : Fl4Spec.addrFromPPtr table = base + · rw [ite_eq_left (hcheck.mpr h), ite_eq_left h] + exact mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) hfinish + · rw [ite_eq_right (mt hcheck.mp h), ite_eq_right h] + exact mrele_kbindE (mrele_throwError (Ra := Eq) rfl) hfinish + | _ => + exact mrele_kbindE (mrele_throwError (Ra := Eq) rfl) + (unmapTableFinish_equiv hop rootH asid + (flushTable_equiv hop rootH addr table asid) (storePde_equiv slotH .InvalidPDE)) + +/-- [P] The input state and the ASID admit the original native carrier. -/ +theorem unmapPd_equiv (hop : OpaqueRel RestRel) (asid : Asid) (addr table : ObjRef) + (hasid : BaseAsid asid) {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) : + MRelStep SR Eq (ArchVSpace_A.unmap_pd asid addr table sH) (Fl4Spec.unmapPd asid addr table sL) := by + unfold ArchVSpace_A.unmap_pd Fl4Spec.unmapPd + simp only [holFunApp] + refine mrelStep_catch_mem (Re := FunRel embLookupFailure) ?_ + (fun _ _ _ tH tL ht _ => mrel_return rfl tH tL ht) + refine mrelStep_bindE_mem (findVspaceForAsid_equiv asid hasid hs hb) fun rootH rootL hr tH tL ht _ => ?_ + subst hr + refine (mrele_bindE (lookupPdptSlot_equiv rootH addr) fun slotH slotL hslot => ?_) tH tL ht + subst hslot + refine mrele_bindE (mrele_liftE (getPdpte_equiv slotH)) fun eH eL he => ?_ + subst he + cases eH with + | PageDirectoryPDPTE base _ _ => + simp only [Arch_Structs_A.case_pdpte, embPDPTE, holIf_eq] + have hcheck : holEq base (Platform.addrFromPPtr table) = true ↔ base = Fl4Spec.addrFromPPtr table := by + rw [holEq_eq_true, addrFromPPtr_eq] + have hfinish := unmapTableFinish_equiv hop rootH asid + (flushAll_equiv (ZH := ZH) (ZL := ZL) hop rootH asid) (storePdpte_equiv slotH .InvalidPDPTE) + by_cases h : base = Fl4Spec.addrFromPPtr table + · rw [ite_eq_left (hcheck.mpr h), ite_eq_left h] + exact mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) hfinish + · rw [ite_eq_right (mt hcheck.mp h), ite_eq_right h] + exact mrele_kbindE (mrele_throwError (Ra := Eq) rfl) hfinish + | _ => + exact mrele_kbindE (mrele_throwError (Ra := Eq) rfl) + (unmapTableFinish_equiv hop rootH asid + (flushAll_equiv hop rootH asid) (storePdpte_equiv slotH .InvalidPDPTE)) + +/-- [P] The input state and the ASID admit the original native carrier. -/ +theorem unmapPdpt_equiv (hop : OpaqueRel RestRel) (asid : Asid) (addr table : ObjRef) + (hasid : BaseAsid asid) {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) : + MRelStep SR Eq (ArchVSpace_A.unmap_pdpt asid addr table sH) (Fl4Spec.unmapPdpt asid addr table sL) := by + unfold ArchVSpace_A.unmap_pdpt Fl4Spec.unmapPdpt + simp only [holFunApp] + refine mrelStep_catch_mem (Re := FunRel embLookupFailure) ?_ + (fun _ _ _ tH tL ht _ => mrel_return rfl tH tL ht) + refine mrelStep_bindE_mem (findVspaceForAsid_equiv asid hasid hs hb) fun rootH rootL hr tH tL ht _ => ?_ + subst hr + refine (mrele_bindE (mrele_returnOk (Ra := Eq) (lookupPml4Slot_eq rootH addr).symm) fun slotH slotL hslot => ?_) + tH tL ht + subst hslot + refine mrele_bindE (mrele_liftE (getPml4e_equiv slotH)) fun eH eL he => ?_ + subst he + have hfinish := mrele_liftE (Re := FunRel embLookupFailure) + (mrel_kbind (flushAll_equiv (ZH := ZH) (ZL := ZL) hop rootH asid) (storePml4e_equiv slotH .InvalidPML4E)) + cases eH with + | PDPointerTablePML4E base _ _ => + simp only [Arch_Structs_A.case_pml4e, embPML4E, holIf_eq] + have hcheck : holEq base (Platform.addrFromPPtr table) = true ↔ base = Fl4Spec.addrFromPPtr table := by + rw [holEq_eq_true, addrFromPPtr_eq] + by_cases h : base = Fl4Spec.addrFromPPtr table + · rw [ite_eq_left (hcheck.mpr h), ite_eq_left h] + exact mrele_kbindE (mrele_returnOk (Ra := Eq) rfl) hfinish + · rw [ite_eq_right (mt hcheck.mp h), ite_eq_right h] + exact mrele_kbindE (mrele_throwError (Ra := Eq) rfl) hfinish + | _ => exact mrele_kbindE (mrele_throwError (Ra := Eq) rfl) hfinish + +private theorem setAsidPool_equiv (ptr : ObjRef) (pool : AsidLowIndex → Option ObjRef) : + MRel SR Eq (ArchVSpaceAcc_A.set_asid_pool ptr pool) (Fl4Spec.setAsidPool ptr pool) := + setObject_equiv ptr (.ArchObj (.ASIDPool pool)) + +private theorem hwAsidInvalidate_equiv (hop : OpaqueRel RestRel) (asid : Asid) (root : ObjRef) : + MRel SR Eq (ArchVSpace_A.hw_asid_invalidate asid root) (Fl4Spec.hwAsidInvalidate asid root) := + mrel_doMachineOp (invalidateASID_equiv hop root asid) + +/-- [P] The deleted ASID lies in the common range, and an actual pool write +leaves the base carriers that the subsequent root switch consumes. -/ +def DeleteAsidSafe (asid : Asid) (root : ObjRef) (s : Structures_A.state ZH) : Prop := + BaseAsid asid ∧ + ∀ ptr, s.arch_state.x64_asid_table (ArchVSpaceAcc_A.asid_high_bits_of asid) = some ptr → + ∀ pool t, (pool, t) ∈ (ArchVSpaceAcc_A.get_asid_pool ptr s).1 → + pool (ArchVSpaceAcc_A.asid_low_bits_of asid) = some root → + ∀ u, ((), u) ∈ (ArchVSpace_A.hw_asid_invalidate asid root t).1 → + ∀ v, ((), v) ∈ (ArchVSpaceAcc_A.set_asid_pool ptr + (holFunUpd pool (ArchVSpaceAcc_A.asid_low_bits_of asid) none) u).1 → + ReferenceBaseCarriers v + +theorem deleteAsid_equiv (hop : OpaqueRel RestRel) (asid : Asid) (root : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (hi : DeleteAsidSafe asid root sH) : + MRelStep SR Eq (ArchVSpace_A.delete_asid asid root sH) (Fl4Spec.deleteAsid asid root sL) := by + unfold ArchVSpace_A.delete_asid Fl4Spec.deleteAsid + refine mrelStep_bind_mem + (mrel_gets (Rs := SR) (Ra := fun f g => g (Fl4Spec.asidHighBitsOf asid) = + f (ArchVSpaceAcc_A.asid_high_bits_of asid)) (fun _ _ h => asidTable_eq h asid hi.1) sH sL hs) + fun f g ht tH tL hrel hread => ?_ + have ⟨hf, hstate⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hread) + subst f + subst tH + rw [ht] + simp only [holComp] + generalize hptr : sH.arch_state.x64_asid_table (ArchVSpaceAcc_A.asid_high_bits_of asid) = found + cases found with + | none => exact mrel_return rfl sH tL hrel + | some ptr => + simp only [holCaseOption_some] + refine mrelStep_bind_mem (getAsidPool_equiv ptr sH tL hrel) fun poolH poolL hp uH uL hu hpool => ?_ + subst hp + have hheap := (getAsidPool_member hpool).2 + have hheapL : sL.kheap ptr = some (.archObj (.asidPool poolH)) := by + rw [hs.kheap_eq, hheap] + rfl + rw [asidLowBitsOf_eq] + generalize hentry : poolH (ArchVSpaceAcc_A.asid_low_bits_of asid) = entry + cases entry with + | none => + have hfalse : holEq (none : Option ObjRef) (some root) = false := by + simp [holEq] + simp only [holFunApp, hfalse, holWhen, Bool.false_eq_true, ↓reduceIte] + change MRelStep SR Eq (holReturn () uH) (NonDet.pure () uL) + exact mrel_return rfl uH uL hu + | some p => + have htag := hb.untaggedAsidEntries _ _ _ _ hheapL hentry + have hroot : Fl4Spec.asidEntryRoot p = p := by + have hmask : ((~~~(1 : Word)) ||| 1) = -1 := by decide + calc + Fl4Spec.asidEntryRoot p = (p &&& ~~~1) ||| (p &&& 1) := by + rw [htag] + exact BitVec.or_zero.symm + _ = p &&& (~~~1 ||| 1) := BitVec.and_or_distrib_left.symm + _ = p := by + rw [hmask] + change p &&& BitVec.allOnes 64 = p + exact BitVec.and_allOnes + simp only [holFunApp, hroot, htag, ↓reduceIte] + by_cases hpRoot : p = root + swap + · have hfalse : holEq (some p) (some root) = false := by + apply Bool.eq_false_iff.mpr + intro hm + exact hpRoot (Option.some.inj ((holEq_eq_true _ _).mp hm)) + simp only [hfalse, holWhen, Bool.false_eq_true, ↓reduceIte, NonDet.when, ite_eq_right hpRoot] + exact mrel_return rfl uH uL hu + subst p + simp only [holEq, decide_true, holWhen, NonDet.when, ↓reduceIte] + refine mrelStep_bind_mem (hwAsidInvalidate_equiv hop asid root uH uL hu) + fun a _ _ vH vL hv hinv => ?_ + cases a + change MRelStep SR Eq (holBind (holReturn (holFunUpd poolH _ none)) _ vH) + (NonDet.bind (NonDet.pure (Function.update poolH _ none)) _ vL) + let updated := @Function.update AsidLowIndex (fun _ => Option ObjRef) instDecidableEqBitVec + poolH (ArchVSpaceAcc_A.asid_low_bits_of asid) none + have hupdate : holFunUpd poolH (ArchVSpaceAcc_A.asid_low_bits_of asid) none = updated := by + funext k + by_cases hk : k = ArchVSpaceAcc_A.asid_low_bits_of asid <;> + simp [updated, holFunUpd, Function.update, hk] + rw [KHeap.holBind_return_left, hupdate, IpcCancel.nonDet_bind_pure_left] + simp only [Bind.bind] + refine mrelStep_bind_mem (Rs := SR) (Rs' := SR) (Ra := Eq) ?_ + fun b _ _ xH xL hx hwrite => ?_ + · exact setAsidPool_equiv ptr updated vH vL hv + cases b + have hb' := hx.baseCarriers_iff.mpr (hi.2 ptr hptr poolH uH hpool hentry vH hinv xH + (by rwa [hupdate])) + refine mrelStep_bind_mem (mrel_gets (Rs := SR) (Ra := Eq) + (fun _ _ h => h.curThread_eq.symm) xH xL hx) fun thH thL hth yH yL hy hyread => ?_ + subst hth + have hyState : yH = xH := (Prod.mk.inj (Set.mem_singleton_iff.mp hyread)).2 + subst yH + exact setVmRoot_equiv thH hy (hy.baseCarriers_iff.mpr (hx.baseCarriers_iff.mp hb')) +theorem widenAsidTable_update (table : BitVec 3 → Option ObjRef) + (idx : AsidHighIndex) (val : Option ObjRef) (hi : idx.toNat < 8) : + Function.update (Patched.widen_asid_table table) idx val = + Patched.widen_asid_table (Function.update table (idx.setWidth 3) val) := by + funext j + by_cases he : j = idx + · subst j + simp [Patched.widen_asid_table, hi] + · rw [Function.update_of_ne he] + unfold Patched.widen_asid_table + by_cases hj : j.toNat < 8 + · rw [ite_eq_left hj, ite_eq_left hj, Function.update_of_ne] + intro he' + apply he + apply BitVec.eq_of_toNat_eq + have hcast := congrArg BitVec.toNat he' + simpa only [BitVec.toNat_setWidth, Nat.mod_eq_of_lt hj, Nat.mod_eq_of_lt hi] using hcast + · rw [ite_eq_right hj, ite_eq_right hj] + + +private def asid_pool_offsets : List Asid := holUptoEnum 0 (((1 : Asid) <<< MiscMachine_A.asid_low_bits) - 1) + +private def invalidate_asid_pool (base : Asid) (pool : AsidLowIndex → Option ObjRef) : + HolNonDet (Structures_A.state ZH) (List Unit) := + holMapM (fun offset => + holWhen (holNot (holEq (pool (holUcast offset)) none)) + (ArchVSpace_A.hw_asid_invalidate (base + offset) (holTheOpt (pool (holUcast offset))))) asid_pool_offsets + +private def clear_asid_table (base : Asid) (table : BitVec 3 → Option ObjRef) : + HolNonDet (Structures_A.state ZH) Unit := + holModify fun s => Structures_A.abstract_state.arch_state_update + (fun _ => Arch_Structs_A.arch_state.x64_asid_table_update + (fun _ => holFunUpd table (ArchVSpaceAcc_A.asid_high_bits_of base) none) s.arch_state) s + +/-- [P] The pool's ASID lies in range and the table write leaves base carriers +for the subsequent root switch. -/ +def DeleteAsidPoolSafe (base : Asid) (ptr : ObjRef) (s : Structures_A.state ZH) : Prop := + BaseAsid base ∧ + (ArchVSpaceAcc_A.asid_low_bits_of base = 0 → + s.arch_state.x64_asid_table (ArchVSpaceAcc_A.asid_high_bits_of base) = some ptr → + ∀ pool t, (pool, t) ∈ (ArchVSpaceAcc_A.get_asid_pool ptr s).1 → + ∀ results u, (results, u) ∈ (invalidate_asid_pool base pool t).1 → + ∀ v, ((), v) ∈ (clear_asid_table base s.arch_state.x64_asid_table u).1 → + ReferenceBaseCarriers v) + +private theorem clearAsidTable_equiv (base : Asid) (table : BitVec 3 → Option ObjRef) + (hbase : BaseAsid base) : + MRel SR Eq (clear_asid_table base table) + (NonDet.modify fun s : State ZL => { s with archState := { s.archState with + x64AsidTable := Function.update (Patched.widen_asid_table table) (Fl4Spec.asidHighBitsOf base) none } }) := by + unfold clear_asid_table + apply mrel_modify + intro sH sL hs + have htable : Function.update (Patched.widen_asid_table table) (Fl4Spec.asidHighBitsOf base) none = + Patched.widen_asid_table (holFunUpd table (ArchVSpaceAcc_A.asid_high_bits_of base) none) := by + rw [widenAsidTable_update table _ _ (asidHighBitsOf_lt base hbase), asidHighBitsOf_cast] + apply congrArg Patched.widen_asid_table + funext k + by_cases hk : k = ArchVSpaceAcc_A.asid_high_bits_of base <;> simp [holFunUpd, Function.update, hk] + let wide := Function.update (Patched.widen_asid_table table) (Fl4Spec.asidHighBitsOf base) none + have harch : ({sL.archState with x64AsidTable := wide} : ArchState) = + embArchState sL.archState.x64Plat + (Arch_Structs_A.arch_state.x64_asid_table_update + (fun _ => holFunUpd table (ArchVSpaceAcc_A.asid_high_bits_of base) none) sH.arch_state) := by + conv => lhs; rw [hs.archState_eq] + dsimp only [wide] + rw [htable] + rfl + exact { hs with archState_eq := harch } + +private def invalidateAsidPool (base : Asid) (pool : AsidLowIndex → Option ObjRef) : + SMonad ZL (List Unit) := + NonDet.mapM (fun offset : Asid => + NonDet.when (nativeAsidRoot (pool (ucast asidLowLen offset)) ≠ none) <| + hwAsidInvalidate (base + offset) (the (nativeAsidRoot (pool (ucast asidLowLen offset))))) + (uptoEnum 0 (((1 : Asid) <<< asidLowBits) - 1)) + +private theorem invalidateAsidPool_equiv (hop : OpaqueRel RestRel) (base : Asid) + (pool : AsidLowIndex → Option ObjRef) + (hpool : ∀ index root, pool index = some root → root &&& 1 = 0) : + MRel SR (ListRel Eq) (invalidate_asid_pool base pool) (invalidateAsidPool base pool) := by + unfold invalidate_asid_pool asid_pool_offsets invalidateAsidPool + rw [holUptoEnum_bv_eq] + refine mrel_mapM (Ra := Eq) (fun oH oL ho => ?_) (listRel_eq _) + subst ho + have hnative : nativeAsidRoot (pool (ucast asidLowLen oH)) = pool (holUcast oH) := by + change nativeAsidRoot (pool (holUcast oH)) = _ + cases hr : pool (holUcast oH) with + | none => rfl + | some root => + change (if root &&& (1 : Word) = 0 then some root else none) = some root + rw [ite_eq_left (hpool _ _ hr)] + rw [hnative] + apply mrel_when (by simp [holNot_eq_true, holEq_eq_true]) + intro _ + exact hwAsidInvalidate_equiv hop _ _ + +set_option maxRecDepth 20000 in +theorem deleteAsidPool_equiv (hop : OpaqueRel RestRel) (base : Asid) (ptr : ObjRef) + {sH : Structures_A.state ZH} {sL : State ZL} (hs : SR sH sL) + (hb : BaseCarriers sL) (hi : DeleteAsidPoolSafe base ptr sH) : + MRelStep SR Eq (ArchVSpace_A.delete_asid_pool base ptr sH) (Fl4Spec.deleteAsidPool base ptr sL) := by + unfold ArchVSpace_A.delete_asid_pool Fl4Spec.deleteAsidPool + simp only [holFunApp, Bind.bind] + have hassert : MRelStep SR Eq + (holAssert (holEq (ArchVSpaceAcc_A.asid_low_bits_of base) 0) sH) + (NonDet.assert (Fl4Spec.asidLowBitsOf base = 0) sL) := + mrel_assert (by rw [asidLowBitsOf_eq, holEq_eq_true]) sH sL hs + refine mrelStep_bind_mem hassert fun a _ _ tH tL ht hr => ?_ + cases a + have ⟨hlow, hstate⟩ : ArchVSpaceAcc_A.asid_low_bits_of base = 0 ∧ tH = sH := by + simpa [holAssert, holEq_eq_true, HolZero.zeroVal] using hr + subst tH + refine mrelStep_bind_mem (mrel_gets (Rs := SR) + (Ra := fun f g => g = Patched.widen_asid_table f) + (fun _ _ h => congrArg ArchState.x64AsidTable h.archState_eq) sH tL ht) + fun f g hfg uH uL hu htread => ?_ + subst g + obtain ⟨hf, hstate⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp htread) + subst f + subst uH + simp only [holComp] + have hidx : Patched.widen_asid_table sH.arch_state.x64_asid_table (Fl4Spec.asidHighBitsOf base) = + sH.arch_state.x64_asid_table (ArchVSpaceAcc_A.asid_high_bits_of base) := by + simp only [Patched.widen_asid_table, asidHighBitsOf_lt base hi.1, ↓reduceIte, asidHighBitsOf_cast] + by_cases hptr : sH.arch_state.x64_asid_table (ArchVSpaceAcc_A.asid_high_bits_of base) = some ptr + · have hwide : Patched.widen_asid_table sH.arch_state.x64_asid_table (Fl4Spec.asidHighBitsOf base) = + some ptr := hidx.trans hptr + simp only [holWhen, holEq, hptr, decide_true, NonDet.when, hwide, ↓reduceIte] + refine mrelStep_bind_mem (getAsidPool_equiv ptr sH uL hu) fun poolH poolL hp vH vL hv hm => ?_ + subst hp + have hheapL : sL.kheap ptr = some (.archObj (.asidPool poolH)) := by + rw [hs.kheap_eq, (getAsidPool_member hm).2] + rfl + change MRelStep SR Eq (holBind (invalidate_asid_pool base poolH) _ vH) + (NonDet.bind (invalidateAsidPool base poolH) _ vL) + have hguard := hi.2 hlow hptr poolH vH hm + have hmap := invalidateAsidPool_equiv hop base poolH + (fun index root => hb.untaggedAsidEntries ptr poolH index root hheapL) vH vL hv + generalize haction : invalidate_asid_pool (ZH := ZH) base poolH = action at hguard hmap ⊢ + refine mrelStep_bind_mem (Rs' := SR) (Ra := ListRel Eq) (mH := action) + (mL := invalidateAsidPool base poolH) hmap fun xsH _ _ wH wL hw hrmap => ?_ + have hafter := hguard xsH wH hrmap + simp only [Pure.pure, KHeap.holBind_return_left, IpcCancel.nonDet_bind_pure_left] + refine mrelStep_bind_mem (mH := clear_asid_table base sH.arch_state.x64_asid_table) + (clearAsidTable_equiv base sH.arch_state.x64_asid_table hi.1 wH wL hw) + fun b _ _ xH xL hx hwrite => ?_ + cases b + have hb' : ReferenceBaseCarriers xH := hafter xH hwrite + refine mrelStep_bind_mem (mrel_gets (Rs := SR) (Ra := Eq) + (fun _ _ h => h.curThread_eq.symm) xH xL hx) fun thH thL hth yH yL hy hthread => ?_ + subst hth + have hstate : yH = xH := (Prod.mk.inj (Set.mem_singleton_iff.mp hthread)).2 + subst yH + exact setVmRoot_equiv thH hy (hy.baseCarriers_iff.mpr hb') + · have hwide : Patched.widen_asid_table sH.arch_state.x64_asid_table (Fl4Spec.asidHighBitsOf base) ≠ + some ptr := fun h => hptr (hidx.symm.trans h) + simp only [holWhen, holEq, NonDet.when, hwide, hptr, decide_false, Bool.false_eq_true, ↓reduceIte] + exact mrel_return rfl sH uL hu + +end + +end L4vRefX64.Equiv.VSpaceUnmap diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Witness.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Witness.lean new file mode 100644 index 000000000..c68ff240d --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Equiv/Witness.lean @@ -0,0 +1,3332 @@ +import L4vRefX64.Equiv.Schedule +import L4vRefX64.Equiv.Interrupt +import L4vRefX64.Equiv.Tcb +import L4vRefX64.Equiv.Syscall + +namespace L4vRefX64.Equiv.Witness + +open L4vRefX64.Spec +open L4vRefX64.Rel +open L4vRefX64.Prim +open Fl4Spec +open Classical + +noncomputable section + +/-- A concrete inhabitant of the frozen Lean config carrier for the generated PC99 inputs. -/ +def pc99Config : Fl4Spec.KernelConfig where + numDomains := 16 + numDomains_not_zero := by decide + numDomains_fits_domainBits := by decide + resetChunkBits := 8 + retypeFanOutLimit := 256 + +/-- The generated fields and the frozen Lean carrier's invariants are jointly satisfiable. -/ +theorem pc99Config_exists : ∃ cfg : Fl4Spec.KernelConfig, KernelConfigMatches cfg := + ⟨pc99Config, { numDomains_eq := rfl, resetChunkBits_eq := rfl, retypeFanOutLimit_eq := rfl }⟩ + +private def zeroArchTcb : Arch_Structs_A.arch_tcb where + tcb_context := .UserContext (fun _ => 0) (fun _ => 0) + tcb_cur_fpu := false + more := () + +def mkTcb (st : Structures_A.thread_state) (sc : Option ObjRef) : Structures_A.tcb := + { tcb_ctable := .NullCap + tcb_vtable := .NullCap + tcb_ipcframe := .NullCap + tcb_fault_handler := .NullCap + tcb_timeout_handler := .NullCap + tcb_state := st + tcb_ipc_buffer := 0#64 + tcb_fault := none + tcb_bound_notification := none + tcb_mcpriority := 0#8 + tcb_sched_context := sc + tcb_yield_to := none + tcb_priority := 0#8 + tcb_domain := 0#8 + tcb_flags := ∅ + tcb_arch := zeroArchTcb + more := () } + +def baseSc : Structures_A.sched_context := + { sc_period := 100#64 + sc_budget := 100#64 + sc_consumed := 0#64 + sc_tcb := some 0x1000#64 + sc_ntfn := none + sc_refills := [{ r_time := 0#64, r_amount := 100#64, more := () }] + sc_refill_max := 2 + sc_badge := 0#64 + sc_yield_from := none + sc_replies := [] + sc_sporadic := false + more := () } + +def referenceMachine (rest : MachineTypes.machine_state_rest) : MachineTypes.machine_state where + irq_masks := fun _ => true + irq_state := 0 + time_state := 0 + last_machine_time := 0 + underlying_memory := fun _ => 0 + device_state := fun _ => none + fpu_enabled := false + machine_state_rest := rest + more := () + +def leanMachine (msH : MachineTypes.machine_state) (rest : MachineStateRest) : MachineState where + irqMasks := msH.irq_masks + irqState := msH.irq_state + timeState := msH.time_state + lastMachineTime := msH.last_machine_time + underlyingMemory := msH.underlying_memory + deviceState := msH.device_state + fpuEnabled := msH.fpu_enabled + machineStateRest := rest + +theorem leanMachine_related + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (msH : MachineTypes.machine_state) (rL : MachineStateRest) + (h : RestRel msH.machine_state_rest rL) : MachineStateRel RestRel msH (leanMachine msH rL) where + irqMasks_eq := rfl + irqState_eq := rfl + timeState_eq := rfl + lastMachineTime_eq := rfl + underlyingMemory_eq := rfl + deviceState_eq := rfl + fpuEnabled_eq := rfl + rest_rel := h + +private def nativeArch : Arch_Structs_A.arch_state where + x64_asid_table := fun _ => none + x64_global_pml4 := 0 + x64_kernel_vspace := fun _ => .X64VSpaceInvalidRegion + x64_global_pts := [] + x64_global_pdpts := [] + x64_global_pds := [] + x64_current_cr3 := .mk 0 0 + x64_allocated_io_ports := fun _ => false + x64_num_ioapics := 0 + x64_ioapic_nirqs := fun _ => 0 + x64_irq_state := fun _ => .IRQFree + x64_current_fpu_owner := none + more := () + +private def nativeHeap (liveSc : Structures_A.sched_context) (p : ObjRef) : Option Structures_A.kernel_object := + if p = 0x1000 then some (.TCB (mkTcb .Running (some 0x2000))) + else if p = 0x2000 then some (.SchedContext liveSc 7) + else if p = 0x3000 then some (.TCB (mkTcb .IdleThreadState (some Machine_A.idle_sc_ptr))) + else if p = Machine_A.idle_sc_ptr then + some (.SchedContext { baseSc with sc_tcb := some 0x3000 } 7) + else none + +def referenceState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit where + kheap := nativeHeap baseSc + cdt := fun _ => none + is_original_cap := fun _ => false + cur_thread := 0x1000 + idle_thread := 0x3000 + consumed_time := 0 + cur_time := 0 + cur_sc := 0x2000 + reprogram_timer := false + scheduler_action := .resume_cur_thread + domain_list := [(0, 100)] + domain_index := 0 + domain_start_index := 0 + cur_domain := 0 + domain_time := 100 + ready_queues := fun _ _ => [] + release_queue := [] + machine_state := referenceMachine rH + interrupt_irq_node := fun _ => 0 + interrupt_states := fun _ => .IRQInactive + arch_state := nativeArch + more := { exst := (), more := () } + +private def nativePlatform : X64Platform where + hugePages := true + tdxActive := false + tdxDmaRam := fun _ _ => false + +def leanState (sH : Structures_A.state Unit) (rL : MachineStateRest) : State Unit where + kheap := fun p => (sH.kheap p).map embKernelObject + cdt := sH.cdt + isOriginalCap := sH.is_original_cap + curThread := sH.cur_thread + idleThread := sH.idle_thread + idleSc := Machine_A.idle_sc_ptr + consumedTime := sH.consumed_time + curTime := sH.cur_time + curSc := sH.cur_sc + reprogramTimer := sH.reprogram_timer + schedulerAction := embSchedulerAction sH.scheduler_action + domainList := sH.domain_list + domainIndex := sH.domain_index + domainStartIndex := sH.domain_start_index + curDomain := sH.cur_domain + domainTime := sH.domain_time + readyQueues := sH.ready_queues + releaseQueue := sH.release_queue + machineState := leanMachine sH.machine_state rL + interruptIrqNode := sH.interrupt_irq_node + interruptStates := embIrqState ∘ sH.interrupt_states + archState := embArchState nativePlatform sH.arch_state + exst := () + +private theorem nativeTcb (st : Structures_A.thread_state) (sc : Option ObjRef) : + BaseTcb (embTcb (mkTcb st sc)) := by + constructor + · trivial + · trivial + · trivial + · trivial + · trivial + · rfl + · cases st <;> simp [embTcb, mkTcb, embThreadState] + +private theorem nativeHeap_base (sc : Structures_A.sched_context) : + BaseCarriersFor (fun p => (nativeHeap sc p).map embKernelObject) + (embCr3 nativeArch.x64_current_cr3) := by + constructor + · intro p ao h + simp only [nativeHeap] at h + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + · intro p size cs _ _ h _ + simp only [nativeHeap] at h + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + · intro p t h + simp only [nativeHeap] at h + split at h + · simp [embKernelObject] at h + rw [← h] + exact nativeTcb _ _ + split at h <;> try { simp [embKernelObject] at h } + split at h + · simp [embKernelObject] at h + rw [← h] + exact nativeTcb _ _ + split at h <;> simp [embKernelObject] at h + · intro p entries index root h _ + simp only [nativeHeap] at h + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + · change (0 : Nat) < 2 ^ 12 + decide + +theorem referenceState_base (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) : + BaseCarriers (leanState (referenceState rH) rL) := + nativeHeap_base baseSc + +theorem leanState_related + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (sH : Structures_A.state Unit) (rL : MachineStateRest) + (hr : RestRel sH.machine_state.machine_state_rest rL) : + StateRel RestRel Eq sH (leanState sH rL) where + kheap_eq _ := rfl + cdt_eq := rfl + isOriginalCap_eq := rfl + curThread_eq := rfl + idleThread_eq := rfl + idleSc_eq := rfl + consumedTime_eq := rfl + curTime_eq := rfl + curSc_eq := rfl + reprogramTimer_eq := rfl + schedulerAction_eq := rfl + domainList_eq := rfl + domainIndex_eq := rfl + domainStartIndex_eq := rfl + curDomain_eq := rfl + domainTime_eq := rfl + readyQueues_eq := rfl + releaseQueue_eq := rfl + machineState_rel := leanMachine_related _ _ hr + interruptIrqNode_eq := rfl + interruptStates_eq _ := rfl + archState_eq := rfl + exst_rel := Subsingleton.elim _ _ + +theorem referenceState_related + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) (hr : RestRel rH rL) : + StateRel RestRel Eq (referenceState rH) (leanState (referenceState rH) rL) := + leanState_related (referenceState rH) rL hr + +/-- The witness heap has a running TCB bound to the active budget-bearing context. -/ +theorem liveThread (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) : + let sL := leanState (referenceState rH) rL + ∃ tcb sc, sL.kheap sL.curThread = some (.tcb tcb) ∧ + tcb.tcbState = .running ∧ tcb.tcbSchedContext = some sL.curSc ∧ + sL.kheap sL.curSc = some (.schedContext sc 7) ∧ + sc.scRefillMax = 2 ∧ sc.scRefills = [⟨0, 100⟩] := by + refine ⟨embTcb (mkTcb .Running (some 0x2000)), embSchedContext baseSc, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · simp [leanState, referenceState, nativeHeap, embKernelObject] + · rfl + · rfl + · simp [leanState, referenceState, nativeHeap, embKernelObject] + · rfl + · rfl + +private theorem maskedIrqLeanRun (ms : MachineState) (mask : ∀ irq, ms.irqMasks irq = true) : + Fl4Spec.getActiveIRQ false ms = ({(none, { ms with irqState := ms.irqState + 1 })}, False) := by + rcases ms with ⟨irqMasks, irqState, timeState, lastTime, memory, device, fpu, rest⟩ + change ∀ irq, irqMasks irq = true at mask + apply Prod.ext + · ext result + simp [Fl4Spec.getActiveIRQ, NonDet.bind, NonDet.gets, NonDet.modify, NonDet.pure, mask, + bind, pure] + · simp [Fl4Spec.getActiveIRQ, NonDet.bind, NonDet.gets, NonDet.modify, NonDet.pure, mask, + bind, pure] + +/-- A masked interrupt query succeeds on both sides and advances the IRQ oracle position. -/ +theorem maskedIrqWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) + (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) (hr : RestRel rH rL) : + let h := referenceMachine rH + let l := leanMachine h rL + ∃ h' l', (none, h') ∈ (MachineOps.getActiveIRQ false h).1 ∧ + (none, l') ∈ (Fl4Spec.getActiveIRQ false l).1 ∧ + (MachineOps.getActiveIRQ false h).2 = false ∧ + ¬ (Fl4Spec.getActiveIRQ false l).2 ∧ MachineStateRel RestRel h' l' ∧ + h'.irq_state = 1 ∧ l'.irqState = 1 := by + let h := referenceMachine rH + let l := leanMachine h rL + let l' := { l with irqState := l.irqState + 1 } + have run := maskedIrqLeanRun l (fun _ => rfl) + have related := Machine.getActiveIRQ_equiv hop false h l (leanMachine_related h rL hr) + have lmem : (none, l') ∈ (Fl4Spec.getActiveIRQ false l).1 := by rw [run]; rfl + obtain ⟨irq, h', hmem, heq, hpost⟩ := related.2.2 none l' lmem + subst irq + have lfail : ¬ (Fl4Spec.getActiveIRQ false l).2 := by rw [run]; exact not_false + have hfail : (MachineOps.getActiveIRQ false h).2 = false := + Bool.eq_false_iff.mpr (fun htrue => lfail (related.1.mp htrue)) + exact ⟨h', l', hmem, lmem, hfail, lfail, hpost, hpost.irqState_eq.symm, rfl⟩ + +private def clockCeiling : Word := -(Fl4Spec.getCurrentTimeBuffer + 1) + +private theorem minBudget_lt_maxTime : Fl4Spec.MIN_BUDGET < Fl4Spec.maxTime := by + rw [BitVec.lt_def, BitVec.toNat_allOnes] + unfold Fl4Spec.MIN_BUDGET Fl4Spec.kernelWCETTicks Fl4Spec.usToTicks + simp only [BitVec.toNat_mul, BitVec.toNat_udiv, Nat.reducePow] + have hprod : (Fl4Spec.kernelWCETUs.toNat * Fl4Spec.ticksPerTimerUnit.toNat) % 2 ^ 64 / + Fl4Spec.timerUnit.toNat ≤ Fl4Spec.kernelWCETUs.toNat * Fl4Spec.ticksPerTimerUnit.toNat := + (Nat.div_le_self _ _).trans (Nat.mod_le _ _) + have hbound := Fl4Spec.MIN_BUDGET_bound + simp only [Fl4Spec.unat, BitVec.toNat_allOnes] at hbound + exact (Nat.mod_le _ _).trans_lt (lt_of_le_of_lt (Nat.mul_le_mul_left 2 hprod) (by + simpa [Nat.mul_assoc] using hbound)) + +private theorem clockAtCeilingRun (ms : MachineState) (h : ms.lastMachineTime = clockCeiling) : + Fl4Spec.getCurrentTime ms = + ({(clockCeiling, { ms with timeState := ms.timeState + 1 })}, False) := by + have hmin : min clockCeiling.toNat + (clockCeiling.toNat + Fl4Spec.timeOracle (ms.timeState + 1)) = clockCeiling.toNat := + Nat.min_eq_left (Nat.le_add_right _ _) + apply Prod.ext + · ext result + simp only [Fl4Spec.getCurrentTime, NonDet.bind, NonDet.gets, NonDet.modify, + NonDet.pure, Bind.bind, Pure.pure, Set.mem_ofPred_eq, Set.mem_singleton_iff, + exists_eq_left, Function.comp_apply, Fl4Spec.unat, h] + rw [show (-(getCurrentTimeBuffer + 1) : Word64) = clockCeiling from rfl, hmin, + BitVec.ofNat_toNat, ← h] + have hwidth : ms.lastMachineTime.setWidth 64 = ms.lastMachineTime := by + apply BitVec.eq_of_toNat_eq + simp + rw [hwidth] + · simp [Fl4Spec.getCurrentTime, NonDet.bind, NonDet.gets, NonDet.modify, + NonDet.pure, Bind.bind, Pure.pure] + +private theorem timeStampAtCeilingRun {s : State Unit} + (hclock : s.machineState.lastMachineTime = clockCeiling) + (htime : s.curTime = clockCeiling) + (hbudget : Fl4Spec.MIN_BUDGET < s.domainTime) : + Fl4Spec.updateTimeStamp s = + ({((), { s with machineState := + { s.machineState with timeState := s.machineState.timeState + 1 } })}, False) := by + let nextMachine := { s.machineState with timeState := s.machineState.timeState + 1 } + have hmachine : Fl4Spec.doMachineOp Fl4Spec.getCurrentTime s = + ({(clockCeiling, { s with machineState := nextMachine })}, False) := by + apply Prod.ext + · ext result + simp [Fl4Spec.doMachineOp, NonDet.bind, NonDet.gets, NonDet.selectF, + NonDet.modify, NonDet.pure, Bind.bind, Pure.pure, clockAtCeilingRun _ hclock, nextMachine] + · simp [Fl4Spec.doMachineOp, NonDet.bind, NonDet.gets, NonDet.selectF, + NonDet.modify, NonDet.pure, Bind.bind, Pure.pure, clockAtCeilingRun _ hclock] + have hnot : ¬ s.domainTime ≤ Fl4Spec.MIN_BUDGET := by + rw [BitVec.le_def] + rw [BitVec.lt_def] at hbudget + omega + simp [Fl4Spec.updateTimeStamp, NonDet.bind, NonDet.gets, NonDet.modify, + NonDet.pure, NonDet.when, Bind.bind, Pure.pure, hmachine, htime, hnot] + split <;> rfl + + +private theorem clockAtCeilingRunH + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (ms : MachineTypes.machine_state) + (h : ms.last_machine_time = clockCeiling) : + MachineOps.getCurrentTime ms = + ({(clockCeiling, { ms with time_state := ms.time_state + 1 })}, false) := by + have hcap : HolNeg.negVal (HolAdd.addVal + (HolMul.mulVal (HolNumeral.ofNatVal (α := Word) 5) Time.MAX_PERIOD) + (HolOne.oneVal (α := Word))) = clockCeiling := by + rw [← Machine.MAX_PERIOD_eq hop] + rfl + have hle : clockCeiling.toNat ≤ clockCeiling.toNat + MachineTypes.time_oracle (ms.time_state + 1) := + Nat.le_add_right _ _ + have hcurrent : holMin (holUnsigned (HolNeg.negVal (HolAdd.addVal + (HolMul.mulVal (HolNumeral.ofNatVal (α := Word) 5) Time.MAX_PERIOD) + (HolOne.oneVal (α := Word))))) + (HolAdd.addVal (holUnsigned clockCeiling) + (MachineTypes.time_oracle (HolAdd.addVal ms.time_state (HolOne.oneVal (α := Nat))))) = + clockCeiling.toNat := by + rw [hcap] + simp [holMin, HolOrd.leVal, holUnsigned, HolAdd.addVal, HolOne.oneVal, hle] + have hword : holOfNat clockCeiling.toNat = clockCeiling := by + apply BitVec.eq_of_toNat_eq + simp [holOfNat, HolNumeral.ofNatVal] + apply Prod.ext + · ext result + simp only [MachineOps.getCurrentTime, holBind, holModify, holGets, holReturn, holFunApp, + holKBind, holComp, MachineTypes.machine_state.time_state_update, + MachineTypes.machine_state.last_machine_time_update, Set.mem_ofPred_eq, + Set.mem_singleton_iff, exists_eq_left, h, hcurrent, hword] + rw [← h] + rfl + · simp [MachineOps.getCurrentTime, holBind, holModify, holGets, holReturn, + holFunApp, holKBind] + +private theorem maskedIrqRunH (ms : MachineTypes.machine_state) + (mask : ∀ irq, ms.irq_masks irq = true) : + MachineOps.getActiveIRQ false ms = ({(none, { ms with irq_state := ms.irq_state + 1 })}, false) := by + apply Prod.ext + · ext result + simp [MachineOps.getActiveIRQ, holBind, holGets, holModify, holReturn, + holFunApp, holKBind, holComp, holDisj, mask, holIf, + MachineTypes.machine_state.irq_state_update, HolAdd.addVal, HolOne.oneVal] + · simp [MachineOps.getActiveIRQ, holBind, holGets, holModify, holReturn, + holFunApp, holKBind, holComp, holDisj, mask, holIf] + + +private theorem machineOperationRunH {α : Type} [Nonempty α] + (m : HolNonDet MachineTypes.machine_state α) (s : Structures_A.state Unit) + (a : α) (ms : MachineTypes.machine_state) + (h : m s.machine_state = ({(a, ms)}, false)) : + Structures_A.do_machine_op m s = ({(a, { s with machine_state := ms })}, false) := by + apply Prod.ext + · ext result + simp [Structures_A.do_machine_op, holBind, holGets, holSelectF, holModify, + holReturn, holKBind, holCaseProd, Structures_A.abstract_state.machine_state_update, h] + · simp [Structures_A.do_machine_op, holBind, holGets, holSelectF, holModify, + holReturn, holKBind, holCaseProd, h] + +private theorem timeStampAtCeilingRunH + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) {s : Structures_A.state Unit} + (hclock : s.machine_state.last_machine_time = clockCeiling) + (htime : s.cur_time = clockCeiling) + (hbudget : Fl4Spec.MIN_BUDGET < s.domain_time) : + KHeap_A.update_time_stamp s = + ({((), { s with machine_state := + { s.machine_state with time_state := s.machine_state.time_state + 1 } })}, false) := by + have hrun := machineOperationRunH _ s _ _ (clockAtCeilingRunH hop s.machine_state hclock) + have hbudgetH := KHeap.minBudget_eq hop + have hnot : ¬ s.domain_time ≤ Structures_A.MIN_BUDGET := by + rw [← hbudgetH, BitVec.le_def] + rw [BitVec.lt_def] at hbudget + omega + simp [KHeap_A.update_time_stamp, holBind, holGets, holModify, holReturn, + holKBind, holWhen, holFunApp, holIf, holLe_eq_true, HolOrd.leVal, HolSub.subVal, HolAdd.addVal, + Structures_A.abstract_state.cur_time_update, + Structures_A.abstract_state.consumed_time_update, hrun, htime, hnot] + split <;> rfl + + +private def entrySc : Structures_A.sched_context := + { baseSc with sc_refills := [{ r_time := 0, r_amount := Fl4Spec.maxTime, more := () }] } + +def interruptEntryState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + { referenceState rH with + kheap := nativeHeap entrySc + cur_time := clockCeiling + domain_time := Fl4Spec.maxTime + machine_state := { referenceMachine rH with last_machine_time := clockCeiling } } + + +theorem interruptEntry_base (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) : + BaseCarriers (leanState (interruptEntryState rH) rL) := + nativeHeap_base entrySc + +private theorem minBudget_one_tick_slack + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) : (1 : Word) + Fl4Spec.MIN_BUDGET < Fl4Spec.maxTime := by + let k := Fl4Spec.kernelWCETUs.toNat + let ticks := Fl4Spec.ticksPerTimerUnit.toNat + let period := Fl4Spec.MAX_PERIOD_US.toNat + have ht : 0 < ticks := by + apply Nat.pos_of_ne_zero + intro h + exact Fl4Spec.ticks_per_timer_unit_non_zero (BitVec.eq_of_toNat_eq h) + have hp : 0 < period := by + change 0 < Fl4Spec.MAX_PERIOD_US.toNat + rw [hop.maxPeriodUs_eq] + decide + have hraw : 2 * k * ticks < 2 ^ 64 - 1 := by + simpa only [Fl4Spec.unat, BitVec.toNat_allOnes, k, ticks] using Fl4Spec.MIN_BUDGET_bound + have hkw : 2 * k < 2 ^ 64 := by + have hb := Nat.mul_le_mul_left (2 * k) ht + omega + have hkp : 2 * k ≤ period := by + have h := BitVec.le_def.mp Fl4Spec.MIN_BUDGET_le_MAX_PERIOD + rw [BitVec.toNat_mul] at h + change (2 * k) % 2 ^ 64 ≤ period at h + simpa only [Nat.mod_eq_of_lt hkw] using h + have hbudget : Fl4Spec.MIN_BUDGET.toNat ≤ 2 * k * ticks := by + unfold Fl4Spec.MIN_BUDGET Fl4Spec.kernelWCETTicks Fl4Spec.usToTicks + change (2 * ((Fl4Spec.kernelWCETUs * Fl4Spec.ticksPerTimerUnit) / Fl4Spec.timerUnit).toNat) % 2 ^ 64 ≤ _ + have hdiv : ((k * ticks) % 2 ^ 64) / Fl4Spec.timerUnit.toNat ≤ k * ticks := + (Nat.div_le_self _ _).trans (Nat.mod_le _ _) + simp only [BitVec.toNat_udiv, BitVec.toNat_mul] + exact (Nat.mod_le _ _).trans (by simpa only [Nat.mul_assoc, k, ticks] using Nat.mul_le_mul_left 2 hdiv) + have hcap : 5 * (period * ticks) < 2 ^ 64 - 1 := by + simpa only [Fl4Spec.unat, BitVec.toNat_allOnes, period, ticks, Nat.mul_assoc] + using Fl4Spec.getCurrentTime_buffer_bound + have hle := hbudget.trans (Nat.mul_le_mul_right ticks hkp) + have hpos : 0 < period * ticks := Nat.mul_pos hp ht + rw [BitVec.lt_def, BitVec.toNat_add, BitVec.toNat_allOnes] + change (1 + Fl4Spec.MIN_BUDGET.toNat) % 2 ^ 64 < 2 ^ 64 - 1 + exact (Nat.mod_le _ _).trans_lt (by omega) + +private def oneTickEntry (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + { interruptEntryState rH with cur_time := clockCeiling - 1 } + +private def oneTickStamped (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := interruptEntryState rH + { s with + consumed_time := 1 + domain_time := Fl4Spec.maxTime - 1 + machine_state := { s.machine_state with time_state := 1 } } + +private theorem oneTickStamp_run + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) : + KHeap_A.update_time_stamp (oneTickEntry rH) = ({((), oneTickStamped rH)}, false) := by + let s := oneTickEntry rH + have hrun := machineOperationRunH _ s _ _ (clockAtCeilingRunH hop s.machine_state rfl) + have hdiff : clockCeiling - (clockCeiling - 1#64) = 1#64 := by bv_omega + have hnot : ¬ Fl4Spec.maxTime ≤ (1 : Word) + Structures_A.MIN_BUDGET := by + rw [← KHeap.minBudget_eq hop] + rw [BitVec.le_def] + have h := BitVec.lt_def.mp (minBudget_one_tick_slack hop) + omega + have hdomains : holLt (HolOne.oneVal (α := Nat)) Kernel_Config.numDomains = true := by + apply (holLt_eq_true _ _).mpr + change 1 < 16 + omega + change KHeap_A.update_time_stamp s = _ + unfold KHeap_A.update_time_stamp + rw [hol_bind_singleton_at _ (show holGets _ s = _ from rfl)] + simp only [holFunApp] + rw [hol_bind_singleton_at _ hrun] + simp [holBind, holGets, holModify, holReturn, + holKBind, holWhen, holIf, holLe_eq_true, HolOrd.leVal, HolSub.subVal, HolAdd.addVal, + Structures_A.abstract_state.cur_time_update, Structures_A.abstract_state.consumed_time_update, + hdomains, s, oneTickEntry, oneTickStamped, interruptEntryState, referenceState] + have hne : 1#64 + Structures_A.MIN_BUDGET ≠ 18446744073709551615#64 := by + intro h + apply hnot + change 18446744073709551615#64 ≤ 1#64 + Structures_A.MIN_BUDGET + rw [h] + exact BitVec.le_def.mpr (Nat.le_refl _) + rw [hdiff, ite_eq_right hne] + rfl + +/-- Timestamp collection consumes one tick from the domain and charges it to +the interrupted thread in both related states. -/ +theorem liveOneTickWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let sH := oneTickEntry rH + let sL := leanState sH rL + ∃ outL, ((), outL) ∈ (Fl4Spec.updateTimeStamp sL).1 ∧ ¬ (Fl4Spec.updateTimeStamp sL).2 ∧ + StateRel RestRel Eq (oneTickStamped rH) outL ∧ outL.consumedTime = 1 ∧ + outL.domainTime = Fl4Spec.maxTime - 1 := by + dsimp only + let sH := oneTickEntry rH + have hrel := KHeap.updateTimeStamp_equiv hc hop sH (leanState sH rL) (leanState_related sH rL hr) + have hrun := oneTickStamp_run hop rH + have hm : ((), oneTickStamped rH) ∈ (KHeap_A.update_time_stamp sH).1 := by rw [hrun]; rfl + obtain ⟨_, outL, hmem, _, hpost⟩ := hrel.2.1 () (oneTickStamped rH) hm + refine ⟨outL, hmem, ?_, hpost, hpost.consumedTime_eq, hpost.domainTime_eq⟩ + intro hf + have hh := hrel.1.mpr hf + rw [hrun] at hh + cases hh + +private def afterTimeStamp (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := interruptEntryState rH + { s with machine_state := { s.machine_state with time_state := 1 } } + +private def afterInterrupt (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := afterTimeStamp rH + { s with machine_state := { s.machine_state with irq_state := 1 } } + +private theorem interruptEntry_refillL (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) : + let sL := leanState (afterTimeStamp rH) rL + Fl4Spec.readScRefillSufficient sL.curSc sL.consumedTime sL = some true := by + simp [leanState, afterTimeStamp, interruptEntryState, referenceState, nativeHeap, entrySc, embKernelObject, + embSchedContext, embRefill, Fl4Spec.readScRefillSufficient, Fl4Spec.readRefillHead, + Fl4Spec.readSchedContext, Fl4Spec.readObject, Fl4Spec.refillHd, Fl4Spec.refillSufficient, + Fl4Spec.refillCapacity, Fl4Spec.the, Fl4Spec.Lookup.oassert, Fl4Spec.Lookup.oreturn, + bind, ReaderT.bind, show Fl4Spec.MIN_BUDGET ≤ Fl4Spec.maxTime from by + rw [BitVec.le_def] + exact Nat.le_of_lt (BitVec.lt_def.mp minBudget_lt_maxTime)] + +private theorem interruptEntry_refillH + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) + (hr : RestRel rH rL) : + let sH := afterTimeStamp rH + KHeap_A.read_sc_refill_sufficient sH.cur_sc sH.consumed_time sH = some true := by + let sH := afterTimeStamp rH + let sL := leanState sH rL + have hs : StateRel RestRel Eq sH sL := leanState_related sH rL hr + have hm := KHeap.readScRefillSufficient_equiv hop sH.cur_sc sH.consumed_time sH sL hs + change OptRel Eq (KHeap_A.read_sc_refill_sufficient sH.cur_sc sH.consumed_time sH) + (Fl4Spec.readScRefillSufficient sL.curSc sL.consumedTime sL) at hm + rw [interruptEntry_refillL rH rL] at hm + cases h : KHeap_A.read_sc_refill_sufficient sH.cur_sc sH.consumed_time sH with + | none => simp [h, OptRel] at hm + | some result => + have htrue : result = true := by simpa only [h, OptRel] using hm + exact h.trans (congrArg some htrue) + + +private theorem whileLoop_initiallyFalse {σ α : Type} + (C : α → σ → Prop) (B : α → NonDet σ α) (a : α) (s : σ) (h : ¬ C a s) : + NonDet.whileLoop C B a s = ({(a, s)}, False) := by + apply Prod.ext + · ext ⟨value, st⟩ + constructor + · intro hr + cases hr with + | done _ => rfl + | step hc _ _ => exact (h hc).elim + · intro hm + have heq : (value, st) = (a, s) := hm + cases heq + exact NonDet.WhileResults.done h + · apply propext + constructor + · rintro (⟨value, st, hr, hc, _⟩ | ⟨trace, hinit, hseq⟩) + · have reach : ∀ {value st}, NonDet.WhileReach C B a s value st → (value, st) = (a, s) := by + intro value st hreach + induction hreach with + | start => rfl + | step _ htest _ ih => + have eq := Prod.mk.inj ih + rw [eq.1, eq.2] at htest + exact (h htest).elim + have eq := Prod.mk.inj (reach hr) + rw [eq.1, eq.2] at hc + exact h hc + · have hc := (hseq 0).1 + rw [hinit] at hc + exact h hc + · intro hn; exact hn.elim + +private theorem emptyReleaseQueue_awaken {s : State Unit} (h : s.releaseQueue = []) : + Fl4Spec.awaken s = ({((), s)}, False) := by + unfold Fl4Spec.awaken + refine whileLoop_initiallyFalse _ _ _ _ ?_ + simp [Fl4Spec.readReleaseQNonEmptyAndReady, Lookup.asks, Lookup.oreturn, bind, ReaderT.bind, + Fl4Spec.the, h] + +private theorem holWhile_initiallyFalse {σ α : Type} + (C : α → σ → Bool) (B : α → HolNonDet σ α) (a : α) (s : σ) (h : C a s = false) : + holWhileLoop C B a s = ({(a, s)}, false) := by + apply Prod.ext + · ext result + change HolWhileResults C B a s result ↔ result = (a, s) + constructor + · intro hr + cases hr with + | done _ => rfl + | step htest _ _ => simp [h] at htest + · intro he + subst result + exact .done h + · change decide _ = false + apply decide_eq_false + rintro (⟨value, st, hr, hc, _⟩ | ⟨trace, hinit, hseq⟩) + · have reach : ∀ {value st}, HolWhileReach C B a s value st → (value, st) = (a, s) := by + intro value st hreach + induction hreach with + | start => rfl + | step _ htest _ ih => + have eq := Prod.mk.inj ih + rw [eq.1, eq.2, h] at htest + cases htest + have eq := Prod.mk.inj (reach hr) + rw [eq.1, eq.2, h] at hc + cases hc + · have htest := (hseq 0).1 + rw [hinit, h] at htest + cases htest + +private theorem emptyReleaseQueue_awakenH + {s : Structures_A.state Unit} (h : s.release_queue = []) : + Schedule_A.awaken s = ({((), s)}, false) := by + unfold Schedule_A.awaken + refine holWhile_initiallyFalse _ _ _ _ ?_ + simp [Schedule_A.read_release_q_non_empty_and_ready, holAsks, holOBind, holIf, + holEq_eq_true, holOReturn, holTheOpt, h] + +private theorem scheduleSafe_resume + {s : Structures_A.state Unit} (hqueue : s.release_queue = []) + (hdom : KHeap_A.is_cur_domain_expired s = false) + (hact : s.scheduler_action = .resume_cur_thread) (hrep : s.reprogram_timer = false) + (htcb : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context s.cur_thread s = + ({(some s.cur_sc, s)}, false)) + (hsc : ∃ sc, KHeap_A.get_sched_context s.cur_sc s = ({(sc, s)}, false)) : + Schedule.ScheduleSafe s := by + obtain ⟨sc, hsc⟩ := hsc + have hcheck : Schedule_A.check_domain_time s = ({((), s)}, false) := by + simp [Schedule_A.check_domain_time, holBind, holGets, holFunApp, holWhen, holReturn, hdom] + refine ⟨by simp [Schedule.AwakenSafe, hqueue], ?_⟩ + intro s1 hs1 s2 hs2 + rw [emptyReleaseQueue_awakenH hqueue] at hs1 + simp only [Set.mem_singleton_iff, Prod.mk.injEq, true_and] at hs1 + subst s1 + rw [hcheck] at hs2 + simp only [Set.mem_singleton_iff, Prod.mk.injEq, true_and] at hs2 + subst s2 + refine ⟨by simp [hact], by simp [hact], ?_⟩ + intro s3 hs3 + have hs : s3 = s := by simpa [hact] using hs3 + subst s3 + unfold Schedule.SwitchScSafe + intro csc s1 ct s2 scOpt s3 scp s4 sc' s5 u s6 rep s7 hm1 hm2 hm3 hm4 hm5 hm6 hm7 hrep' + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm1 + obtain ⟨hcsc, hs1⟩ := hm1 + subst csc s1 + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm2 + obtain ⟨hct, hs2⟩ := hm2 + subst ct s2 + rw [htcb] at hm3 + obtain ⟨ho,hs3⟩ := (Prod.mk.inj (Set.mem_singleton_iff.mp hm3)) + subst scOpt s3 + simp only [holAssertOpt, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm4 + obtain ⟨hp,hs4⟩ := hm4 + subst scp s4 + rw [hsc] at hm5 + obtain ⟨hrsc,hs5⟩ := (Prod.mk.inj (Set.mem_singleton_iff.mp hm5)) + subst sc' s5 + simp only [holEq, decide_true, holNot, Bool.not_true, holWhen, Bool.false_eq_true, + ↓reduceIte, holReturn, Set.mem_singleton_iff, Prod.mk.injEq] at hm6 + obtain ⟨_, hs6⟩ := hm6 + subst s6 + simp only [holGets, Set.mem_singleton_iff, Prod.mk.injEq] at hm7 + obtain ⟨hr, _⟩ := hm7 + rw [hr, hrep] at hrep' + cases hrep' + + +private theorem liveIrqEventRun + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Syscall_A.handle_event .Interrupt (interruptEntryState rH) = + ({(.inr (), afterInterrupt rH)}, false) := by + let s0 := interruptEntryState rH + let s1 := afterTimeStamp rH + have htime : KHeap_A.update_time_stamp s0 = ({((), s1)}, false) := + timeStampAtCeilingRunH hop rfl rfl minBudget_lt_maxTime + have hrel : StateRel RestRel Eq s1 (leanState s1 rL) := leanState_related s1 rL hr + have hb := (Ipc.checkBudget_run_sufficient hc hop hrel (interruptEntry_refillH hop rH rL hr)).1 + have hirq := machineOperationRunH (MachineOps.getActiveIRQ false) s1 _ _ + (maskedIrqRunH s1.machine_state fun _ => rfl) + have hhandle : Interrupt_A.maybe_handle_interrupt false s1 = ({((), afterInterrupt rH)}, false) := by + unfold Interrupt_A.maybe_handle_interrupt holFunApp + rw [hol_bind_singleton_at _ hirq] + rfl + change holLiftE (holBind KHeap_A.update_time_stamp + (holKBind (holBind Ipc_A.check_budget (holKBind (Interrupt_A.maybe_handle_interrupt false))))) s0 = _ + have hrun : holBind KHeap_A.update_time_stamp + (holKBind (holBind Ipc_A.check_budget (holKBind (Interrupt_A.maybe_handle_interrupt false)))) s0 = + ({((), afterInterrupt rH)}, false) := by + rw [hol_bind_singleton_at _ htime] + change holBind Ipc_A.check_budget (holKBind (Interrupt_A.maybe_handle_interrupt false)) s1 = _ + rw [hol_bind_singleton_at _ hb] + exact hhandle + unfold holLiftE holLiftM + rw [hol_bind_singleton_at _ hrun] + rfl + +private theorem liveTcbRead {α : Type} [Nonempty α] (rH : MachineTypes.machine_state_rest) + (read : Structures_A.tcb → α) : + KHeap_A.thread_get read (afterInterrupt rH).cur_thread (afterInterrupt rH) = + ({(read (mkTcb .Running (some 0x2000)), afterInterrupt rH)}, false) := by + let s := afterInterrupt rH + have hread : holGetsThe (KHeap_A.get_tcb s.cur_thread) s = + ({(mkTcb .Running (some 0x2000), s)}, false) := rfl + unfold KHeap_A.thread_get holFunApp + exact hol_bind_singleton_at _ hread + +private theorem liveScRead (rH : MachineTypes.machine_state_rest) : + KHeap_A.get_sched_context (afterInterrupt rH).cur_sc (afterInterrupt rH) = + ({(entrySc, afterInterrupt rH)}, false) := by + let s := afterInterrupt rH + have hobj : KHeap_A.get_object s.cur_sc s = ({(.SchedContext entrySc 7, s)}, false) := rfl + unfold KHeap_A.get_sched_context + rw [hol_bind_singleton_at _ hobj] + rfl + +private theorem liveDomainNotExpired (rH : MachineTypes.machine_state_rest) : + KHeap_A.is_cur_domain_expired (afterInterrupt rH) = false := by + have hn : (Fl4Spec.maxTime : Word) ≠ 0 := by decide + apply Bool.eq_false_iff.mpr + intro h + unfold KHeap_A.is_cur_domain_expired at h + exact hn ((holEq_eq_true _ _).mp ((holConj_eq_true _ _).mp h).2) + +private theorem liveScheduleSafe (rH : MachineTypes.machine_state_rest) : + Schedule.ScheduleSafe (afterInterrupt rH) := by + apply scheduleSafe_resume rfl (liveDomainNotExpired rH) rfl rfl + · exact liveTcbRead rH Structures_A.tcb_ext.tcb_sched_context + · exact ⟨entrySc, liveScRead rH⟩ + +private theorem scheduleResumeRun (s : Structures_A.state Unit) + (hrelease : s.release_queue = []) (hdom : KHeap_A.is_cur_domain_expired s = false) + (hact : s.scheduler_action = .resume_cur_thread) (hrep : s.reprogram_timer = false) + (htc : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context s.cur_thread s = + ({(some s.cur_sc, s)}, false)) + (hsc : KHeap_A.get_sched_context s.cur_sc s = ({(entrySc, s)}, false)) : + Schedule_A.schedule s = ({((), s)}, false) := by + have hcheck : Schedule_A.check_domain_time s = ({((), s)}, false) := by + simp [Schedule_A.check_domain_time, holBind, holGets, holFunApp, holWhen, holReturn, hdom] + have hsched : Schedule_A.switch_sched_context s = ({((), s)}, false) := by + unfold Schedule_A.switch_sched_context + rw [hol_bind_singleton_at _ (show holGets _ s = _ from rfl), + hol_bind_singleton_at _ (show holGets _ s = _ from rfl), hol_bind_singleton_at _ htc, + hol_bind_singleton_at _ (show holAssertOpt (some s.cur_sc) s = _ from rfl), + hol_bind_singleton_at _ hsc] + simp [holBind, holKBind, holFunApp, holWhen, holEq_eq_true, holNot_eq_true, holReturn, + holGets, holModify, hrep, Structures_A.abstract_state.cur_sc_update] + cases s + simp_all + have htimer : Schedule_A.sc_and_timer s = ({((), s)}, false) := by + unfold Schedule_A.sc_and_timer + rw [hol_bind_singleton_at _ hsched] + simp [holKBind, holBind, holGets, holFunApp, holWhen, holReturn, hrep] + change Schedule_A.schedule s = ({((), s)}, false) + unfold Schedule_A.schedule + rw [hol_bind_singleton_at _ (emptyReleaseQueue_awakenH hrelease)] + simp only [holKBind] + rw [hol_bind_singleton_at _ hcheck] + simp only [holKBind] + rw [hol_bind_singleton_at _ (show holGets _ s = _ from rfl), + hol_bind_singleton_at _ (show holGets _ s = _ from rfl), + hol_bind_singleton_at _ (show holGets _ s = _ from rfl)] + simp only [hact, Structures_A.case_scheduler_action] + rw [hol_bind_singleton_at _ (show holReturn () s = _ from rfl)] + exact htimer + +private theorem liveScheduleRun (rH : MachineTypes.machine_state_rest) : + Schedule_A.schedule (afterInterrupt rH) = ({((), afterInterrupt rH)}, false) := + scheduleResumeRun _ rfl (liveDomainNotExpired rH) rfl rfl + (liveTcbRead rH Structures_A.tcb_ext.tcb_sched_context) (liveScRead rH) + +private theorem liveActivationRun (rH : MachineTypes.machine_state_rest) : + Tcb.activate_thread_p (afterInterrupt rH) = ({((), afterInterrupt rH)}, false) := by + let s := afterInterrupt rH + have hyield : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_yield_to s.cur_thread s = + ({(none, s)}, false) := liveTcbRead rH Structures_A.tcb_ext.tcb_yield_to + have hstate : KHeap_A.get_thread_state s.cur_thread s = + ({(.Running, s)}, false) := liveTcbRead rH Structures_A.tcb_ext.tcb_state + change Tcb.activate_thread_p s = ({((), s)}, false) + simp [Tcb.activate_thread_p, holBind, holGets, holKBind, holReturn, holWhen, holNot_eq_true, + holEq_eq_true, hyield, hstate] + + +/-- This interrupt run witnesses the sufficient-refill and scheduling premises +with live TCB and SC objects and concrete externally observable oracle advances. -/ +theorem liveInterruptRelated + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let sH := interruptEntryState rH + let sL := leanState sH rL + MRelStep (StateRel RestRel Eq) Eq (Syscall.call_kernel_interrupt_p sH) + (Fl4Spec.callKernel .interrupt sL) := by + dsimp only + apply Syscall.patched_callKernel_interrupt_equiv_sufficient hc hop (leanState_related _ rL hr) + · intro st hstep + have hrun : KHeap_A.update_time_stamp (interruptEntryState rH) = + ({((), afterTimeStamp rH)}, false) := + timeStampAtCeilingRunH hop rfl rfl minBudget_lt_maxTime + rw [hrun] at hstep + have hs := (Prod.mk.inj (Set.mem_singleton_iff.mp hstep)).2 + subst st + exact interruptEntry_refillH hop rH rL hr + · intro st hstep + rw [liveIrqEventRun hc hop rH rL hr] at hstep + have hs := (Prod.mk.inj (Set.mem_singleton_iff.mp hstep)).2 + subst st + exact liveScheduleSafe rH + + +theorem liveInterruptWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let sH := interruptEntryState rH + let sL := leanState sH rL + let outH := afterInterrupt rH + ∃ outL, ((), outH) ∈ (Syscall.call_kernel_interrupt_p sH).1 ∧ + ((), outL) ∈ (Fl4Spec.callKernel .interrupt sL).1 ∧ + (Syscall.call_kernel_interrupt_p sH).2 = false ∧ + ¬ (Fl4Spec.callKernel .interrupt sL).2 ∧ + StateRel RestRel Eq outH outL ∧ + outH.machine_state.irq_state = 1 ∧ outL.machineState.irqState = 1 ∧ + outH.machine_state.time_state = 1 ∧ outL.machineState.timeState = 1 := by + dsimp only + let s0 := interruptEntryState rH + let outH := afterInterrupt rH + have hfull : Syscall.call_kernel_interrupt_p s0 = ({((), outH)}, false) := by + have hevent := liveIrqEventRun hc hop rH rL hr + change Syscall_A.handle_event .Interrupt s0 = ({(.inr (), outH)}, false) at hevent + have hhandled : + holHandleE (Syscall_A.handle_event .Interrupt) + (fun _ => Exceptions_A.without_preemption Syscall_A.preemption_path) s0 = + ({(.inr (), outH)}, false) := by + unfold holHandleE holHandleE' + rw [hol_bind_singleton_at _ hevent] + rfl + unfold Syscall.call_kernel_interrupt_p + rw [hol_bind_singleton_at _ hhandled] + change holBind Schedule_A.schedule (holKBind Tcb.activate_thread_p) outH = _ + rw [hol_bind_singleton_at _ (liveScheduleRun rH)] + exact liveActivationRun rH + have hrel := liveInterruptRelated hc hop rH rL hr + have hm : ((), outH) ∈ (Syscall.call_kernel_interrupt_p s0).1 := by rw [hfull]; rfl + obtain ⟨_, outL, hlean, _, hpost⟩ := hrel.2.1 () outH hm + refine ⟨outL, hm, hlean, by rw [hfull], ?_, hpost, rfl, hpost.machineState_rel.irqState_eq, + rfl, hpost.machineState_rel.timeState_eq⟩ + intro hf + have hh := hrel.1.mpr hf + rw [hfull] at hh + cases hh + + +private def waitRights : Set CapRights_A.rights := {CapRights_A.AllowRecv} + +private def waitCap : Structures_A.cap := .NotificationCap 0x5000 0 waitRights + +private def waitCnode (slot : List Bool) : Option Structures_A.cap := + if slot = [false] then some waitCap + else if slot = [true] then some .NullCap + else none + +private def waitTcb : Structures_A.tcb := + { mkTcb .Running (some 0x2000) with tcb_ctable := .CNodeCap 0x4000 1 (List.replicate 63 false) } + +private def waitNtfn : Structures_A.notification := + { ntfn_obj := .ActiveNtfn 0x62 + ntfn_bound_tcb := none + ntfn_sc := none + more := () } + +private def waitHeap (p : ObjRef) : Option Structures_A.kernel_object := + if p = 0x1000 then some (.TCB waitTcb) + else if p = 0x4000 then some (.CNode 1 waitCnode) + else if p = 0x5000 then some (.Notification waitNtfn) + else nativeHeap entrySc p + +def nbWaitEntryState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + { interruptEntryState rH with kheap := waitHeap } + +theorem nbWaitEntry_base (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) : + BaseCarriers (leanState (nbWaitEntryState rH) rL) := by + have hbase := nativeHeap_base entrySc + change BaseCarriersFor (fun ptr => (waitHeap ptr).map embKernelObject) + (embCr3 nativeArch.x64_current_cr3) + constructor + · intro ptr obj h + simp only [waitHeap] at h + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + exact hbase.noVirtHeap ptr obj h + · intro ptr size caps slot cap h hcap + simp only [waitHeap] at h + split at h <;> try { simp [embKernelObject] at h } + split at h + · simp [embKernelObject] at h + obtain ⟨_, rfl⟩ := h + simp only [embCnodeContents, waitCnode] at hcap + split at hcap + · simp at hcap + rw [← hcap] + trivial + split at hcap + · simp at hcap + rw [← hcap] + trivial + · simp at hcap + split at h <;> try { simp [embKernelObject] at h } + exact hbase.cnodeCaps ptr size caps slot cap h hcap + · intro ptr t h + simp only [waitHeap] at h + split at h + · simp [embKernelObject] at h + rw [← h] + exact ⟨trivial, trivial, trivial, trivial, trivial, rfl, by decide⟩ + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + exact hbase.tcbs ptr t h + · intro ptr entries index root h hroot + simp only [waitHeap] at h + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + split at h <;> try { simp [embKernelObject] at h } + exact hbase.untaggedAsidEntries ptr entries index root h hroot + · exact hbase.commonPcid + +private def nbWaitTimedState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + { afterTimeStamp rH with kheap := waitHeap } + +private theorem waitCnode_wellFormed : Structures_A.well_formed_cnode_n 1 waitCnode = true := by + apply (holEq_eq_true _ _).mpr + ext xs + simp only [holDom, holCollect, Set.mem_ofPred_eq, holEq_eq_true, holSize_list] + cases xs with + | nil => simp [waitCnode] + | cons x xs => + cases x <;> cases xs <;> simp [waitCnode] + +private theorem getWaitCap_run (rH : MachineTypes.machine_state_rest) : + CSpace.get_cap_p (0x4000, [false]) (nbWaitTimedState rH) = + ({(waitCap, nbWaitTimedState rH)}, false) := by + let s := nbWaitTimedState rH + have ho : KHeap_A.get_object 0x4000 s = ({(.CNode 1 waitCnode, s)}, false) := rfl + change CSpace.get_cap_p (0x4000, [false]) s = ({(waitCap, s)}, false) + unfold CSpace.get_cap_p + rw [hol_bind_singleton_at _ ho] + simp [holBind, holAssert, holKBind, holReturn, holAssertOpt, waitCnode_wellFormed, waitCnode] + + +private theorem setObjectRunH (s : Structures_A.state Unit) (ptr : ObjRef) + (old new : Structures_A.kernel_object) + (hheap : s.kheap ptr = some old) (hkind : Structures_A.a_type old = Structures_A.a_type new) : + KHeap_A.set_object ptr new s = + ({((), { s with kheap := holFunUpd s.kheap ptr (some new) })}, false) := by + have hget : KHeap_A.get_object ptr s = ({(old, s)}, false) := by + unfold KHeap_A.get_object holFunApp KHeap_A.read_object holGetsThe holSwp + rw [hheap] + rfl + unfold KHeap_A.set_object + rw [hol_bind_singleton_at _ hget] + simp [holBind, holAssert, holEq_eq_true, hkind, holKBind, holGet, holPut, + Structures_A.abstract_state.kheap_update] + +private theorem getEmptyWaitSlot_run (rH : MachineTypes.machine_state_rest) : + CSpace.get_cap_p (0x4000, [true]) (nbWaitTimedState rH) = + ({(.NullCap, nbWaitTimedState rH)}, false) := by + let s := nbWaitTimedState rH + have ho : KHeap_A.get_object 0x4000 s = ({(.CNode 1 waitCnode, s)}, false) := rfl + change CSpace.get_cap_p (0x4000, [true]) s = _ + unfold CSpace.get_cap_p + rw [hol_bind_singleton_at _ ho] + simp [holBind, holAssert, holKBind, holReturn, holAssertOpt, waitCnode_wellFormed, waitCnode, s] + +private theorem singletonSlot_nonExt (b : Bool) : CSpaceAcc.NonExtTcbSlot [b] := by + intro h + have hl := congrArg List.length h + change 1 = 3 at hl + omega + +private theorem insertWaitCap_safe (rH : MachineTypes.machine_state_rest) : + CSpace.CapInsertSafe waitCap (0x4000, [false]) (0x4000, [true]) (nbWaitTimedState rH) := by + intro src st hsrc + rw [getWaitCap_run rH] at hsrc + obtain ⟨rfl, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hsrc) + refine ⟨⟨?_, ?_⟩, ?_⟩ + · rintro ⟨_, _, _, h⟩ + cases h + · intro _ + exact Or.inr ⟨0x5000, 0, waitRights, rfl⟩ + · intro old st hold _ + rw [getEmptyWaitSlot_run rH] at hold + obtain ⟨rfl, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hold) + exact ⟨Or.inl (singletonSlot_nonExt false), fun _ _ _ => Or.inl (Or.inl (singletonSlot_nonExt true))⟩ + +private def populatedWaitCnode : List Bool → Option Structures_A.cap := + holFunUpd waitCnode [true] (some waitCap) + +private theorem setWaitCap_run (rH : MachineTypes.machine_state_rest) : + let s := nbWaitTimedState rH + CSpace.set_cap_p waitCap (0x4000, [true]) s = + ({((), { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 populatedWaitCnode)) })}, false) := by + let s := nbWaitTimedState rH + dsimp only + have ho : KHeap_A.get_object 0x4000 s = ({(.CNode 1 waitCnode, s)}, false) := rfl + have hslot := singletonSlot_nonExt true + have hmember : holMember [true] (holDom waitCnode) = true := by + simp [holMember_eq_true, holDom, waitCnode] + unfold CSpace.set_cap_p + simp only [hslot, ↓reduceIte, CSpaceAcc_A.set_cap, holCaseProd_eq] + change holBind (KHeap_A.get_object 0x4000) _ s = _ + rw [hol_bind_singleton_at _ ho] + simp only [Structures_A.case_kernel_object, hmember, waitCnode_wellFormed, + holConj, Bool.true_and, holIf_true, holFunApp] + rw [KHeap.holBind_return_left] + refine setObjectRunH s 0x4000 (.CNode 1 waitCnode) (.CNode 1 populatedWaitCnode) rfl ?_ + have hdom : holDom populatedWaitCnode = holDom waitCnode := by + ext slot + by_cases h : slot = [true] <;> + simp [populatedWaitCnode, holFunUpd, holDom, waitCnode, h] + have hwf : Structures_A.well_formed_cnode_n 1 populatedWaitCnode = true := by + have h := waitCnode_wellFormed + unfold Structures_A.well_formed_cnode_n at h ⊢ + simpa only [hdom] using h + simp [Structures_A.a_type, Structures_A.case_kernel_object, waitCnode_wellFormed, hwf, holIf_true] + +theorem liveSetCapWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := nbWaitTimedState rH + ∃ outH outL, + ((), outH) ∈ (CSpace.set_cap_p waitCap (0x4000, [true]) s).1 ∧ + ((), outL) ∈ (Fl4Spec.setCap (embCap waitCap) (0x4000, [true]) (leanState s rL)).1 ∧ + ¬ (Fl4Spec.setCap (embCap waitCap) (0x4000, [true]) (leanState s rL)).2 ∧ + StateRel RestRel Eq outH outL ∧ + outL.kheap 0x4000 = some (.cnode 1 (embCnodeContents populatedWaitCnode)) := by + dsimp only + let s := nbWaitTimedState rH + let outH := { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 populatedWaitCnode)) } + have hsafe : CSpace.SetCapSafe waitCap (0x4000, [true]) s := Or.inl (Or.inl (singletonSlot_nonExt true)) + have hrel := CSpace.patched_setCap_equiv_at waitCap (0x4000, [true]) + (leanState_related s rL hr) hsafe + have hm : ((), outH) ∈ (CSpace.set_cap_p waitCap (0x4000, [true]) s).1 := by + rw [setWaitCap_run rH]; rfl + obtain ⟨_, outL, hlean, _, hpost⟩ := hrel.2.1 () outH hm + refine ⟨outH, outL, hm, hlean, ?_, hpost, ?_⟩ + · intro hf + have hh := hrel.1.mpr hf + rw [setWaitCap_run rH] at hh + cases hh + · rw [hpost.kheap_eq] + simp [outH, holFunUpd, embKernelObject] + +private theorem insertWaitCap_run (rH : MachineTypes.machine_state_rest) : + let s := nbWaitTimedState rH + let target := { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 populatedWaitCnode)) } + CSpace.cap_insert_p waitCap (0x4000, [false]) (0x4000, [true]) s = ({((), target)}, false) := by + let s := nbWaitTimedState rH + dsimp only + unfold CSpace.cap_insert_p + rw [hol_bind_singleton_at _ (getWaitCap_run rH)] + have hrev : CSpace_A.is_cap_revocable waitCap waitCap = false := by + simp [CSpace_A.is_cap_revocable, waitCap, Structures_A.case_cap, Structures_A.cap_ep_badge, + holNot, holEq] + rw [hrev, KHeap.holBind_return_left, hol_bind_singleton_at _ (getEmptyWaitSlot_run rH)] + have hassert : holAssert (holEq Structures_A.cap.NullCap .NullCap) s = ({((), s)}, false) := by + simp [holAssert, holEq] + rw [hol_bind_singleton_at _ hassert] + simp only [holKBind] + have hsrc : CSpace.set_untyped_cap_as_full_p waitCap waitCap (0x4000, [false]) s = ({((), s)}, false) := rfl + rw [hol_bind_singleton_at _ hsrc] + simp only [holKBind] + rw [hol_bind_singleton_at _ (setWaitCap_run rH)] + let target := { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 populatedWaitCnode)) } + have hcdt : holFunUpd target.cdt (0x4000, [true]) none = target.cdt := by + change holFunUpd (fun _ : CslotPtr => (none : Option CslotPtr)) (0x4000, [true]) none = fun _ => none + funext slot + simp [holFunUpd] + have horig : holFunUpd target.is_original_cap (0x4000, [true]) false = target.is_original_cap := by + change holFunUpd (fun _ : CslotPtr => false) (0x4000, [true]) false = fun _ => false + funext slot + simp [holFunUpd] + have hext : ∀ m, Deterministic_A.do_extended_op m target = ({((), target)}, false) := by + intro m + have hwrap : Deterministic_A.state_ext_class.wrap_ext_op m target = holReturn () target := rfl + simp [Deterministic_A.do_extended_op, hwrap, holBind, holGet, holSelectF, holMkEf, + holReturn, holCaseProd, holModify, Structures_A.state.exst_update] + have horigRun : CSpaceAcc_A.set_original (0x4000, [true]) false target = ({((), target)}, false) := by + unfold CSpaceAcc_A.set_original + rw [hol_bind_singleton_at _ (show holGets (fun st : Structures_A.state Unit => st.is_original_cap) target = _ from rfl)] + change holModify (fun st => Structures_A.abstract_state.is_original_cap_update + (fun _ => holFunUpd target.is_original_cap (0x4000, [true]) false) st) target = _ + rw [horig] + rfl + change holBind (holGets fun st : Structures_A.state Unit => st.is_original_cap) _ target = ({((), target)}, false) + rw [hol_bind_singleton_at _ (show holGets (fun st : Structures_A.state Unit => st.is_original_cap) target = _ from rfl)] + rw [KHeap.holBind_return_left] + have hpar : CSpace.should_be_parent_of_p waitCap (target.is_original_cap (0x4000, [false])) waitCap false = false := rfl + rw [hpar] + rw [hol_bind_singleton_at _ (show holGets (fun st : Structures_A.state Unit => st.cdt (0x4000, [false])) target = _ from rfl)] + rw [hol_bind_singleton_at _ (show holGets (fun st : Structures_A.state Unit => st.cdt (0x4000, [true])) target = _ from rfl)] + have hstep : ∀ cdt : Cdt, holIf false (some ((0x4000, [false]) : CslotPtr)) (cdt (0x4000, [false])) = + cdt (0x4000, [false]) := fun _ => rfl + simp only [hstep] + have hupdate : CSpaceAcc_A.update_cdt + (fun cdt => holFunUpd cdt (0x4000, [true]) (cdt (0x4000, [false]))) target = + ({((), target)}, false) := by + unfold CSpaceAcc_A.update_cdt + rw [hol_bind_singleton_at _ (show holGets (fun st : Structures_A.state Unit => st.cdt) target = _ from rfl)] + have hsrcCdt : target.cdt (0x4000, [false]) = none := rfl + change CSpaceAcc_A.set_cdt (holFunUpd target.cdt (0x4000, [true]) (target.cdt (0x4000, [false]))) target = _ + rw [hsrcCdt, hcdt] + simp [CSpaceAcc_A.set_cdt, holBind, holGet, holPut, Structures_A.abstract_state.cdt_update] + rw [hol_bind_singleton_at _ hupdate] + simp only [holKBind] + rw [hol_bind_singleton_at _ (hext _)] + exact horigRun + +theorem liveCapInsertWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := nbWaitTimedState rH + ∃ outH outL, + ((), outH) ∈ (CSpace.cap_insert_p waitCap (0x4000, [false]) (0x4000, [true]) s).1 ∧ + ((), outL) ∈ (Fl4Spec.capInsert (embCap waitCap) (0x4000, [false]) (0x4000, [true]) (leanState s rL)).1 ∧ + ¬ (Fl4Spec.capInsert (embCap waitCap) (0x4000, [false]) (0x4000, [true]) (leanState s rL)).2 ∧ + StateRel RestRel Eq outH outL ∧ + outL.kheap 0x4000 = some (.cnode 1 (embCnodeContents populatedWaitCnode)) := by + dsimp only + let s := nbWaitTimedState rH + let outH := { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 populatedWaitCnode)) } + have hrel := CSpace.patched_capInsert_equiv waitCap (0x4000, [false]) (0x4000, [true]) + (leanState_related s rL hr) (insertWaitCap_safe rH) + have hm : ((), outH) ∈ (CSpace.cap_insert_p waitCap (0x4000, [false]) (0x4000, [true]) s).1 := by + rw [insertWaitCap_run rH]; rfl + obtain ⟨_, outL, hlean, _, hpost⟩ := hrel.2.1 () outH hm + refine ⟨outH, outL, hm, hlean, ?_, hpost, ?_⟩ + · intro hf + have hh := hrel.1.mpr hf + rw [insertWaitCap_run rH] at hh + cases hh + · rw [hpost.kheap_eq] + simp [outH, holFunUpd, embKernelObject] + +private theorem heapUpdate_current (s : Structures_A.state Unit) (ptr : ObjRef) : + holFunUpd s.kheap ptr (s.kheap ptr) = s.kheap := by + funext x + by_cases h : x = ptr + · subst x + simp [holFunUpd] + · simp [holFunUpd, h] + +private theorem waitCapRegister_run (rH : MachineTypes.machine_state_rest) : + KHeap_A.as_user (nbWaitTimedState rH).cur_thread + (MachineOps.getRegister Machine_A.cap_register) (nbWaitTimedState rH) = + ({((0 : Word), nbWaitTimedState rH)}, false) := by + let s := nbWaitTimedState rH + have hread : holGetsThe (KHeap_A.get_tcb s.cur_thread) s = ({(waitTcb, s)}, false) := rfl + have hsame : KHeap_A.set_object s.cur_thread (.TCB waitTcb) s = ({((), s)}, false) := by + rw [setObjectRunH s s.cur_thread (.TCB waitTcb) (.TCB waitTcb) rfl rfl] + have hh : s.kheap s.cur_thread = some (.TCB waitTcb) := rfl + rw [← hh, heapUpdate_current] + change KHeap_A.as_user s.cur_thread _ s = ({(0, s)}, false) + unfold KHeap_A.as_user holFunApp + rw [hol_bind_singleton_at _ hread] + have hreg : MachineOps.getRegister Machine_A.cap_register + (Arch_Structs_A.arch_tcb_context_get waitTcb.tcb_arch) = + ({(0, Arch_Structs_A.arch_tcb_context_get waitTcb.tcb_arch)}, false) := rfl + have harch : Structures_A.tcb.tcb_arch_update + (fun _ => Arch_Structs_A.arch_tcb_context_set + (Arch_Structs_A.arch_tcb_context_get waitTcb.tcb_arch) waitTcb.tcb_arch) waitTcb = waitTcb := rfl + simp [holBind, holReturn, holSelectF, holCaseProd, hreg, harch, hsame, holKBind] + + +private def waitCptr : CapRef := Machine_A.data_to_cptr 0 + +private theorem waitSlot_run (rH : MachineTypes.machine_state_rest) : + CSpace.lookup_slot_for_thread_p (nbWaitTimedState rH).cur_thread waitCptr (nbWaitTimedState rH) = + ({(.inr ((0x4000, [false]), []), nbWaitTimedState rH)}, false) := by + let s := nbWaitTimedState rH + have hread : holGetsThe (KHeap_A.get_tcb s.cur_thread) s = ({(waitTcb, s)}, false) := rfl + have hlift : holLiftE (ε := ExceptionTypes_A.lookup_failure) + (holGetsThe (KHeap_A.get_tcb s.cur_thread)) s = ({(.inr waitTcb, s)}, false) := by + unfold holLiftE holLiftM + rw [hol_bind_singleton_at _ hread] + rfl + change CSpace.lookup_slot_for_thread_p s.cur_thread waitCptr s = _ + unfold CSpace.lookup_slot_for_thread_p holBindE + rw [hol_bind_singleton_at _ hlift] + change CSpace.resolve_address_bits_p (waitTcb.tcb_ctable, waitCptr) s = _ + unfold CSpace.resolve_address_bits_p + rw [CSpace.holResolveAddrBits.eq_1] + have hguard : holLe (List.replicate 63 false) waitCptr = true := by + apply (holLe_eq_true _ _).mpr + change List.IsPrefix _ _ + exact ⟨[false], by decide⟩ + have hlen : waitCptr.length = 64 := rfl + have hoff : (waitCptr.drop 63).take 1 = [false] := rfl + have hrest : waitCptr.drop 64 = [] := rfl + have hnot : holNot (holLe (List.replicate 63 false) waitCptr) = false := by rw [hguard]; rfl + have hdepth : holLt (64 : Nat) 64 = false := by + apply Bool.eq_false_iff.mpr + simp [holLt_eq_true, HolOrd.ltVal] + have hnonzero : (64 : Nat) ≠ 0 := by decide + simp only [waitTcb, hnot, hdepth, hlen, holWhenE, Bool.false_eq_true, + ↓reduceIte, ↓reduceDIte, List.length_replicate, Nat.reduceAdd, hnonzero, hoff, hrest] + simp [holBindE, holBind, holReturnOk, holReturn, holKBind, s] + +private theorem lookupWaitCap_run (rH : MachineTypes.machine_state_rest) : + CSpace.lookup_cap_p (nbWaitTimedState rH).cur_thread waitCptr (nbWaitTimedState rH) = + ({(.inr waitCap, nbWaitTimedState rH)}, false) := by + unfold CSpace.lookup_cap_p holBindE + rw [hol_bind_singleton_at _ (waitSlot_run rH)] + change holLiftE (CSpace.get_cap_p (0x4000, [false])) (nbWaitTimedState rH) = _ + unfold holLiftE holLiftM + rw [hol_bind_singleton_at _ (getWaitCap_run rH)] + rfl + + +private theorem notificationPartialInv_eq (n : Structures_A.notification) : + Lib.partial_inv Structures_A.kernel_object.Notification (.Notification n) = some n := by + have hu : ∃! x, holEq (Structures_A.kernel_object.Notification x) (.Notification n) = true := by + refine ⟨n, (holEq_eq_true _ _).mpr rfl, ?_⟩ + intro x hx + exact Structures_A.kernel_object.Notification.inj ((holEq_eq_true _ _).mp hx) + unfold Lib.partial_inv holThe + simp only [(holEx1_eq_true _).mpr hu, holIf_true, hu, ↓reduceDIte] + exact congrArg some + ((Classical.choose_spec hu).2 _ ((holEq_eq_true _ _).mpr rfl)).symm + +private theorem simpleNotificationRunH (s : Structures_A.state Unit) + (ptr : ObjRef) (n : Structures_A.notification) (h : s.kheap ptr = some (.Notification n)) : + KHeap_A.get_simple_ko Structures_A.kernel_object.Notification ptr s = ({(n, s)}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.Notification n, s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [h] + rfl + unfold KHeap_A.get_simple_ko + rw [hol_bind_singleton_at _ hobj] + simp [holAssert, Structures_A.a_type, Structures_A.case_kernel_object, holMember_eq_true, + holInsert_eq, holBind, holKBind, holCaseOption, notificationPartialInv_eq, holReturn] + +private theorem waitNotificationBinding_run (rH : MachineTypes.machine_state_rest) : + KHeap_A.get_sk_obj_ref Structures_A.kernel_object.Notification + Structures_A.notification_ext.ntfn_bound_tcb 0x5000 (nbWaitTimedState rH) = + ({(none, nbWaitTimedState rH)}, false) := by + unfold KHeap_A.get_sk_obj_ref + rw [hol_bind_singleton_at _ (simpleNotificationRunH _ _ waitNtfn rfl)] + rfl + + +private theorem waitReceiveCptr_run (rH : MachineTypes.machine_state_rest) : + Syscall.receive_cptr (nbWaitTimedState rH).cur_thread (nbWaitTimedState rH) = + ({(waitCptr, nbWaitTimedState rH)}, false) := by + unfold Syscall.receive_cptr holLiftM + exact hol_bind_singleton_at _ (waitCapRegister_run rH) + +private theorem waitReceiveLookup_run (rH : MachineTypes.machine_state_rest) : + Syscall.receive_lookup (nbWaitTimedState rH).cur_thread waitCptr (nbWaitTimedState rH) = + ({(.inr waitCap, nbWaitTimedState rH)}, false) := by + unfold Syscall.receive_lookup Exceptions_A.cap_fault_on_failure holHandleE' + rw [hol_bind_singleton_at _ (lookupWaitCap_run rH)] + rfl + +private theorem waitNotificationSafe (rH : MachineTypes.machine_state_rest) : + Syscall.NotificationReceiveSafe (nbWaitTimedState rH) := by + intro cptr st hreg + rw [waitReceiveCptr_run rH] at hreg + obtain ⟨hcptr, hst⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hreg) + subst cptr st + rw [waitReceiveLookup_run rH] + constructor + · intro fault out h + simp at h + · intro cap out h + obtain ⟨hc, hout⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp h) + cases hc + subst out + refine ⟨0x5000, 0, waitRights, rfl, by simp [waitRights], ?_⟩ + intro bound next hrun + rw [waitNotificationBinding_run rH] at hrun + exact Or.inr (Prod.mk.inj (Set.mem_singleton_iff.mp hrun)).1 + + +private theorem tcbReadRunH {α : Type} [Nonempty α] (s : Structures_A.state Unit) + (ptr : ObjRef) (tcb : Structures_A.tcb) (proj : Structures_A.tcb → α) + (htcb : s.kheap ptr = some (.TCB tcb)) : + KHeap_A.thread_get proj ptr s = ({(proj tcb, s)}, false) := by + have hget : KHeap_A.get_tcb ptr s = some tcb := by + simp [KHeap_A.get_tcb, KHeap_A.read_object, holSwp, holCaseOption, Structures_A.case_kernel_object, htcb] + have hread : holGetsThe (KHeap_A.get_tcb ptr) s = ({(tcb, s)}, false) := by + simp [holGetsThe, hget, holAssertOpt, holReturn] + unfold KHeap_A.thread_get holFunApp + exact hol_bind_singleton_at _ hread + +private theorem setNotificationRunH (s : Structures_A.state Unit) (ptr : ObjRef) + (before after : Structures_A.notification) (hn : s.kheap ptr = some (.Notification before)) : + KHeap_A.set_simple_ko Structures_A.kernel_object.Notification ptr after s = + ({((), { s with kheap := holFunUpd s.kheap ptr (some (.Notification after)) })}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.Notification before, s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hn] + rfl + have hset := setObjectRunH s ptr (.Notification before) (.Notification after) hn rfl + unfold KHeap_A.set_simple_ko + rw [hol_bind_singleton_at _ hobj] + simp [holAssert, Structures_A.a_type, Structures_A.case_kernel_object, holMember_eq_true, + holInsert_eq, holBind, holKBind, holNot_eq_true, holEq_eq_true, notificationPartialInv_eq, hset] + +private def waitBadge : Word := 0x62 + +private def badgeTcb : Structures_A.tcb := + let ctx : MachineOps.user_context := + .UserContext (fun _ => 0) (holFunUpd (fun _ => 0) Machine_A.badge_register waitBadge) + { waitTcb with tcb_arch := { waitTcb.tcb_arch with tcb_context := ctx } } + +private def nbWaitBadgeState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := nbWaitTimedState rH + { s with kheap := holFunUpd s.kheap s.cur_thread (some (.TCB badgeTcb)) } + +private def idleWaitNtfn : Structures_A.notification := + { waitNtfn with ntfn_obj := .IdleNtfn } + +private def nbWaitResultState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := nbWaitBadgeState rH + { s with kheap := holFunUpd s.kheap 0x5000 (some (.Notification idleWaitNtfn)) } + +private theorem waitSetBadge_run (rH : MachineTypes.machine_state_rest) : + KHeap_A.as_user (nbWaitTimedState rH).cur_thread (MachineOps.setRegister Machine_A.badge_register waitBadge) + (nbWaitTimedState rH) = ({((), nbWaitBadgeState rH)}, false) := by + let s := nbWaitTimedState rH + have hread : holGetsThe (KHeap_A.get_tcb s.cur_thread) s = ({(waitTcb, s)}, false) := rfl + have hset := setObjectRunH s s.cur_thread (.TCB waitTcb) (.TCB badgeTcb) rfl rfl + change KHeap_A.as_user s.cur_thread _ s = + ({((), { s with kheap := holFunUpd s.kheap s.cur_thread (some (.TCB badgeTcb)) })}, false) + unfold KHeap_A.as_user holFunApp + rw [hol_bind_singleton_at _ hread] + have hreg : MachineOps.setRegister Machine_A.badge_register waitBadge + (Arch_Structs_A.arch_tcb_context_get waitTcb.tcb_arch) = + ({((), badgeTcb.tcb_arch.tcb_context)}, false) := rfl + have harch : Structures_A.tcb.tcb_arch_update + (fun _ => Arch_Structs_A.arch_tcb_context_set + badgeTcb.tcb_arch.tcb_context waitTcb.tcb_arch) waitTcb = badgeTcb := rfl + simp [holBind, holReturn, holSelectF, holCaseProd, hreg, harch, hset, holKBind] + +private theorem waitSetNotification_run (rH : MachineTypes.machine_state_rest) : + KHeap_A.set_simple_ko Structures_A.kernel_object.Notification 0x5000 idleWaitNtfn + (nbWaitBadgeState rH) = ({((), nbWaitResultState rH)}, false) := by + apply setNotificationRunH _ _ waitNtfn + change holFunUpd waitHeap 0x1000 (some (.TCB badgeTcb)) 0x5000 = _ + simp [holFunUpd, Function.update, waitHeap] + + +private theorem nbWaitTimeStamp_run + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) : + KHeap_A.update_time_stamp (nbWaitEntryState rH) = ({((), nbWaitTimedState rH)}, false) := + timeStampAtCeilingRunH hop rfl rfl minBudget_lt_maxTime + +private theorem waitBudgetRead + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) + (hr : RestRel rH rL) : + let s := nbWaitTimedState rH + KHeap_A.read_sc_refill_sufficient s.cur_sc s.consumed_time s = some true := by + let s := nbWaitTimedState rH + let t := afterTimeStamp rH + have hs : KHeap_A.read_object s.cur_sc s = some (.SchedContext entrySc 7) := rfl + have ht : KHeap_A.read_object t.cur_sc t = some (.SchedContext entrySc 7) := rfl + have h := interruptEntry_refillH hop rH rL hr + change KHeap_A.read_sc_refill_sufficient t.cur_sc t.consumed_time t = some true at h + change KHeap_A.read_sc_refill_sufficient s.cur_sc t.consumed_time s = some true + simp only [KHeap_A.read_sc_refill_sufficient, KHeap_A.read_refill_head, KHeap_A.read_sched_context, + holOBind, hs, ht, Structures_A.case_kernel_object, holOReturn, holOAssert] at h ⊢ + have hnonempty : holNot (holEq entrySc.sc_refills []) = true := by + simp [holNot_eq_true, holEq_eq_true, entrySc] + simp only [hnonempty, ↓reduceIte, holOReturn] at h ⊢ + exact h + +private theorem waitBudgetRestart_run + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Ipc_A.check_budget_restart (nbWaitTimedState rH) = ({(true, nbWaitTimedState rH)}, false) := by + let s := nbWaitTimedState rH + have hs : StateRel RestRel Eq s (leanState s rL) := leanState_related s rL hr + have hb := (Ipc.checkBudget_run_sufficient hc hop hs (waitBudgetRead hop rH rL hr)).1 + have hdomain : KHeap_A.is_cur_domain_expired s = false := liveDomainNotExpired rH + rw [hdomain] at hb + have hthread : KHeap_A.get_thread_state s.cur_thread s = ({(.Running, s)}, false) := + tcbReadRunH s s.cur_thread waitTcb Structures_A.tcb_ext.tcb_state rfl + change Ipc_A.check_budget_restart s = ({(true, s)}, false) + unfold Ipc_A.check_budget_restart + rw [hol_bind_singleton_at _ hb] + simp [holBind, holGets, holFunApp, holWhen, holReturn, holNot, holConj, holKBind, hthread] + +private theorem nbWaitSafe + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Syscall.NbWaitSafe (nbWaitEntryState rH) := by + intro st htime + rw [nbWaitTimeStamp_run hop rH] at htime + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp htime)).2 + subst st + refine ⟨waitBudgetRead hop rH rL hr, ?_⟩ + intro next hnext + rw [waitBudgetRestart_run hc hop rH rL hr] at hnext + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hnext)).2 + subst next + exact waitNotificationSafe rH + +private theorem waitScRead_run (rH : MachineTypes.machine_state_rest) : + let s := nbWaitResultState rH + KHeap_A.get_sched_context s.cur_sc s = ({(entrySc, s)}, false) := by + let s := nbWaitResultState rH + have hobj : KHeap_A.get_object s.cur_sc s = ({(.SchedContext entrySc 7, s)}, false) := by + change holAssertOpt (holFunUpd (holFunUpd waitHeap 0x1000 (some (.TCB badgeTcb))) + 0x5000 (some (.Notification idleWaitNtfn)) 0x2000) s = _ + simp [holFunUpd, Function.update, waitHeap, nativeHeap, holAssertOpt, holReturn] + change KHeap_A.get_sched_context s.cur_sc s = _ + unfold KHeap_A.get_sched_context + rw [hol_bind_singleton_at _ hobj] + rfl + +private theorem waitThreadRef_run (rH : MachineTypes.machine_state_rest) : + let s := nbWaitResultState rH + KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context s.cur_thread s = + ({(some s.cur_sc, s)}, false) := by + let s := nbWaitResultState rH + apply tcbReadRunH s s.cur_thread badgeTcb Structures_A.tcb_ext.tcb_sched_context + change holFunUpd (holFunUpd waitHeap 0x1000 (some (.TCB badgeTcb))) + 0x5000 (some (.Notification idleWaitNtfn)) 0x1000 = _ + simp [holFunUpd, Function.update] + +private theorem waitFinishReceive_run (rH : MachineTypes.machine_state_rest) : + let s := nbWaitResultState rH + holBind (SchedContext_A.maybe_donate_sc s.cur_thread 0x5000) (holKBind + (holBind (KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context s.cur_thread) + Sporadic_A.if_sporadic_cur_sc_test_refill_unblock_check)) s = ({((), s)}, false) := by + let s := nbWaitResultState rH + have htc : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context s.cur_thread s = + ({(some s.cur_sc, s)}, false) := waitThreadRef_run rH + have hdone : SchedContext_A.maybe_donate_sc s.cur_thread 0x5000 s = ({((), s)}, false) := by + unfold SchedContext_A.maybe_donate_sc + rw [hol_bind_singleton_at _ htc] + simp [holFunApp, holWhen, holEq_eq_true, holReturn] + have hcheck : Sporadic_A.if_sporadic_cur_sc_test_refill_unblock_check (some s.cur_sc) s = + ({((), s)}, false) := by + unfold Sporadic_A.if_sporadic_cur_sc_test_refill_unblock_check Sporadic_A.if_cond_refill_unblock_check + simp only [holMaybeM] + have hsc : KHeap_A.get_sched_context s.cur_sc s = ({(entrySc, s)}, false) := waitScRead_run rH + rw [hol_bind_singleton_at _ hsc] + simp [holBind, holGets, holReturn, holCaseOption, holCaseBool, holFunApp, holWhen, + holConj_eq_true, holNot_eq_true, holEq_eq_true, holImp_eq_true, entrySc, baseSc] + change holBind _ _ s = _ + rw [hol_bind_singleton_at _ hdone] + simp only [holKBind] + rw [hol_bind_singleton_at _ htc] + exact hcheck + + +private theorem holLiftE_singleton_at {σ ε α : Type} + {m : HolNonDet σ α} {s t : σ} {a : α} (hm : m s = ({(a, t)}, false)) : + holLiftE (ε := ε) m s = ({(.inr a, t)}, false) := by + unfold holLiftE holLiftM + rw [hol_bind_singleton_at _ hm] + rfl + +private theorem receiveWaitSignal_run (rH : MachineTypes.machine_state_rest) : + Ipc_A.receive_signal (nbWaitTimedState rH).cur_thread waitCap false (nbWaitTimedState rH) = + ({((), nbWaitResultState rH)}, false) := by + let s := nbWaitTimedState rH + let t := nbWaitBadgeState rH + let u := nbWaitResultState rH + have hget : KHeap_A.get_simple_ko Structures_A.kernel_object.Notification 0x5000 s = + ({(waitNtfn, s)}, false) := simpleNotificationRunH s 0x5000 waitNtfn rfl + have hset : KHeap_A.set_simple_ko Structures_A.kernel_object.Notification 0x5000 idleWaitNtfn t = + ({((), u)}, false) := waitSetNotification_run rH + have hbadge : KHeap_A.as_user s.cur_thread (MachineOps.setRegister Machine_A.badge_register waitBadge) s = + ({((), t)}, false) := waitSetBadge_run rH + change Ipc_A.receive_signal s.cur_thread waitCap false s = ({((), u)}, false) + simp only [Ipc_A.receive_signal, waitCap, Structures_A.case_cap] + rw [hol_bind_singleton_at _ (show holReturn (0x5000 : Word) s = _ from rfl), + hol_bind_singleton_at _ hget] + simp only [waitNtfn, Structures_A.case_ntfn, holFunApp] + simp only [waitBadge] at hbadge + rw [hol_bind_singleton_at _ hbadge] + simp only [holKBind] + have hset' : KHeap_A.set_simple_ko Structures_A.kernel_object.Notification 0x5000 + (Structures_A.notification.ntfn_obj_update (holK .IdleNtfn) waitNtfn) t = + ({((), u)}, false) := hset + simp only [waitNtfn] at hset' + rw [hol_bind_singleton_at _ hset'] + exact waitFinishReceive_run rH + +private theorem handleWaitReceive_run (rH : MachineTypes.machine_state_rest) : + Syscall.handle_recv_p false false (nbWaitTimedState rH) = ({((), nbWaitResultState rH)}, false) := by + let s := nbWaitTimedState rH + let u := nbWaitResultState rH + have hlookup : Syscall.receive_lookup s.cur_thread waitCptr s = ({(.inr waitCap, s)}, false) := + waitReceiveLookup_run rH + have hbound : KHeap_A.get_sk_obj_ref Structures_A.kernel_object.Notification + Structures_A.notification_ext.ntfn_bound_tcb 0x5000 s = ({(none, s)}, false) := + waitNotificationBinding_run rH + have hinner : holBindE (Syscall.receive_lookup s.cur_thread waitCptr) + (Syscall.receive_from_cap false false s.cur_thread waitCptr) s = ({(.inr (), u)}, false) := by + unfold holBindE + rw [hol_bind_singleton_at _ hlookup] + have hright : holMember CapRights_A.AllowRecv waitRights = true := + (holMember_eq_true _ _).mpr (by simp [waitRights]) + simp only [waitCap, Syscall.receive_from_cap, hright, ↓reduceIte, holBindE] + rw [hol_bind_singleton_at _ (holLiftE_singleton_at hbound)] + simp only [or_true, ↓reduceIte] + exact holLiftE_singleton_at (receiveWaitSignal_run rH) + have hcptr : Syscall.receive_cptr s.cur_thread s = ({(waitCptr, s)}, false) := + waitReceiveCptr_run rH + change Syscall.handle_recv_p false false s = ({((), u)}, false) + unfold Syscall.handle_recv_p + rw [hol_bind_singleton_at _ (show holGets _ s = _ from rfl), hol_bind_singleton_at _ hcptr] + unfold holCatch + rw [hol_bind_singleton_at _ hinner] + rfl + +private theorem waitEvent_run + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Syscall.handle_nbwait_p (nbWaitEntryState rH) = ({(.inr (), nbWaitResultState rH)}, false) := by + unfold Syscall.handle_nbwait_p holBindE + rw [hol_bind_singleton_at _ (holLiftE_singleton_at (nbWaitTimeStamp_run hop rH))] + dsimp only + rw [hol_bind_singleton_at _ (holLiftE_singleton_at (waitBudgetRestart_run hc hop rH rL hr))] + simp only [holWhenE, ↓reduceIte] + exact holLiftE_singleton_at (handleWaitReceive_run rH) + + +private theorem waitResult_tcb (rH : MachineTypes.machine_state_rest) : + (nbWaitResultState rH).kheap 0x1000 = some (.TCB badgeTcb) := by + change holFunUpd (holFunUpd waitHeap 0x1000 (some (.TCB badgeTcb))) + 0x5000 (some (.Notification idleWaitNtfn)) 0x1000 = _ + simp [holFunUpd, Function.update] + +private theorem waitResult_ntfn (rH : MachineTypes.machine_state_rest) : + (nbWaitResultState rH).kheap 0x5000 = some (.Notification idleWaitNtfn) := by + simp [nbWaitResultState, holFunUpd, Function.update] + +private theorem waitScheduleSafe (rH : MachineTypes.machine_state_rest) : + Schedule.ScheduleSafe (nbWaitResultState rH) := + scheduleSafe_resume rfl (liveDomainNotExpired rH) rfl rfl (waitThreadRef_run rH) ⟨entrySc, waitScRead_run rH⟩ + +private theorem waitScheduleRun (rH : MachineTypes.machine_state_rest) : + Schedule_A.schedule (nbWaitResultState rH) = ({((), nbWaitResultState rH)}, false) := + scheduleResumeRun _ rfl (liveDomainNotExpired rH) rfl rfl (waitThreadRef_run rH) (waitScRead_run rH) + +private theorem waitActivationRun (rH : MachineTypes.machine_state_rest) : + Tcb.activate_thread_p (nbWaitResultState rH) = ({((), nbWaitResultState rH)}, false) := by + let s := nbWaitResultState rH + have htc : s.kheap s.cur_thread = some (.TCB badgeTcb) := waitResult_tcb rH + have hyield : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_yield_to s.cur_thread s = + ({(none, s)}, false) := tcbReadRunH s s.cur_thread badgeTcb Structures_A.tcb_ext.tcb_yield_to htc + have hstate : KHeap_A.get_thread_state s.cur_thread s = + ({(.Running, s)}, false) := tcbReadRunH s s.cur_thread badgeTcb Structures_A.tcb_ext.tcb_state htc + change Tcb.activate_thread_p s = ({((), s)}, false) + simp [Tcb.activate_thread_p, holBind, holGets, holKBind, holReturn, holWhen, holNot_eq_true, + holEq_eq_true, hyield, hstate] + +private theorem waitRefillRun + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := nbWaitTimedState rH + KHeap_A.get_sc_refill_sufficient s.cur_sc s.consumed_time s = ({(true, s)}, false) := by + dsimp only + simp [KHeap_A.get_sc_refill_sufficient, holGetsThe, waitBudgetRead hop rH rL hr, holAssertOpt, holReturn] + +private theorem waitPatchedBudgetRestartRun + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Ipc.check_budget_restart_p (nbWaitTimedState rH) = ({(true, nbWaitTimedState rH)}, false) := by + let s := nbWaitTimedState rH + have hbudget : Ipc.check_budget_p s = ({(true, s)}, false) := by + unfold Ipc.check_budget_p + rw [hol_bind_singleton_at _ (show holGets _ s = _ from rfl), + hol_bind_singleton_at _ (show holGets _ s = _ from rfl), + hol_bind_singleton_at _ (waitRefillRun hop rH rL hr)] + simp [holIf_true, holGets, holBind, holReturn, holNot, s] + exact liveDomainNotExpired rH + have hthread : KHeap_A.get_thread_state s.cur_thread s = ({(.Running, s)}, false) := + tcbReadRunH s s.cur_thread waitTcb Structures_A.tcb_ext.tcb_state rfl + unfold Ipc.check_budget_restart_p + rw [hol_bind_singleton_at _ hbudget] + simp [holBind, holGets, holWhen, holReturn, holNot, holConj, holKBind, hthread, s] + +private theorem waitGeneralReceiveSafe (rH : MachineTypes.machine_state_rest) : + Syscall.HandleRecvSafe false false (nbWaitTimedState rH) := by + intro cptr t hreg + rw [waitReceiveCptr_run rH] at hreg + obtain ⟨hcptr, ht⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hreg) + subst cptr t + intro _ _ _ _ hlookup + rw [waitReceiveLookup_run rH] at hlookup + cases (Prod.mk.inj (Set.mem_singleton_iff.mp hlookup)).1 + +private theorem waitGeneralEventRun + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Syscall.handle_syscall_p nativePlatform.hugePages .SysNBWait (nbWaitEntryState rH) = + ({(.inr (), nbWaitResultState rH)}, false) := by + unfold Syscall.handle_syscall_p holBindE holKBind + rw [hol_bind_singleton_at _ (holLiftE_singleton_at (nbWaitTimeStamp_run hop rH))] + dsimp only + rw [hol_bind_singleton_at _ (holLiftE_singleton_at (waitPatchedBudgetRestartRun hop rH rL hr))] + simp only [holWhenE, ↓reduceIte, Syscall.syscall_dispatch_p, Exceptions_A.without_preemption] + exact holLiftE_singleton_at (handleWaitReceive_run rH) + +private theorem waitGeneralKernelSafe + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Syscall.CallKernelSafe nativePlatform.hugePages (.SyscallEvent .SysNBWait) (nbWaitEntryState rH) + (leanState (nbWaitEntryState rH) rL) := by + refine + { carriers := (leanState_related _ _ hr).baseCarriers_iff.mp (nbWaitEntry_base rH rL) + eventSafe := ?_ + preemption := ?_ + schedule := ?_ } + · constructor + · intro t h + rw [nbWaitTimeStamp_run hop rH] at h + have ht := (Prod.mk.inj (Set.mem_singleton_iff.mp h)).2 + subst t + intro u hb + rw [waitRefillRun hop rH rL hr] at hb + cases (Prod.mk.inj (Set.mem_singleton_iff.mp hb)).1 + · intro tH _ htime _ uH _ hbudget _ + rw [nbWaitTimeStamp_run hop rH] at htime + have ht := (Prod.mk.inj (Set.mem_singleton_iff.mp htime)).2 + subst tH + rw [waitPatchedBudgetRestartRun hop rH rL hr] at hbudget + have hu := (Prod.mk.inj (Set.mem_singleton_iff.mp hbudget)).2 + subst uH + exact waitGeneralReceiveSafe rH + · intro t h + change (Sum.inl (), t) ∈ (Syscall.handle_syscall_p nativePlatform.hugePages .SysNBWait + (nbWaitEntryState rH)).1 at h + rw [waitGeneralEventRun hop rH rL hr] at h + cases (Prod.mk.inj (Set.mem_singleton_iff.mp h)).1 + · intro result t h + change (result, t) ∈ (holHandleE (Syscall.handle_syscall_p nativePlatform.hugePages .SysNBWait) + (fun _ => Exceptions_A.without_preemption Syscall.preemption_path_p) (nbWaitEntryState rH)).1 at h + unfold holHandleE holHandleE' at h + rw [hol_bind_singleton_at _ (waitGeneralEventRun hop rH rL hr)] at h + have ht := (Prod.mk.inj (Set.mem_singleton_iff.mp h)).2 + subst t + exact waitScheduleSafe rH + +/-- Nonblocking wait consumes an active notification and returns its badge on +both sides. The same successful execution discharges all reached entry guards. -/ +theorem liveNbWaitWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let sH := nbWaitEntryState rH + let sL := leanState sH rL + let outH := nbWaitResultState rH + ∃ outL, ((), outH) ∈ (Syscall.call_kernel_p nativePlatform.hugePages (.SyscallEvent .SysNBWait) sH).1 ∧ + ((), outL) ∈ (Fl4Spec.callKernel (.syscallEvent .sysNBWait) sL).1 ∧ + (Syscall.call_kernel_p nativePlatform.hugePages (.SyscallEvent .SysNBWait) sH).2 = false ∧ + ¬ (Fl4Spec.callKernel (.syscallEvent .sysNBWait) sL).2 ∧ + StateRel RestRel Eq outH outL ∧ + (∃ tcb, outL.kheap 0x1000 = some (.tcb tcb) ∧ + tcb.tcbArch.tcbContext.userRegs Fl4Spec.badge_register = (0x62 : Word)) ∧ + (∃ ntfn, outL.kheap 0x5000 = some (.notification ntfn) ∧ ntfn.ntfnObj = .idleNtfn) := by + dsimp only + let s := nbWaitEntryState rH + let u := nbWaitResultState rH + have he := waitGeneralEventRun hop rH rL hr + have hruns : Syscall.call_kernel_p nativePlatform.hugePages (.SyscallEvent .SysNBWait) s = + ({((), u)}, false) := by + have hhandled : holHandleE (Syscall.handle_syscall_p nativePlatform.hugePages .SysNBWait) + (fun _ => Exceptions_A.without_preemption Syscall.preemption_path_p) s = + ({(.inr (), u)}, false) := by + unfold holHandleE holHandleE' + rw [hol_bind_singleton_at _ he] + rfl + change holBind + (holHandleE (Syscall.handle_syscall_p nativePlatform.hugePages .SysNBWait) + (fun _ => Exceptions_A.without_preemption Syscall.preemption_path_p)) + (holKBind (holBind Schedule_A.schedule (holKBind Tcb.activate_thread_p))) s = _ + rw [hol_bind_singleton_at _ hhandled] + change holBind Schedule_A.schedule (holKBind Tcb.activate_thread_p) u = _ + rw [hol_bind_singleton_at _ (waitScheduleRun rH)] + exact waitActivationRun rH + have hrel := Syscall.patched_callKernel_equiv hc hop nativePlatform.hugePages (.SyscallEvent .SysNBWait) + (leanState_related s rL hr) (waitGeneralKernelSafe hop rH rL hr) + have hm : ((), u) ∈ (Syscall.call_kernel_p nativePlatform.hugePages (.SyscallEvent .SysNBWait) s).1 := by rw [hruns]; rfl + obtain ⟨_, outL, hout, _, hpost⟩ := hrel.2.1 () u hm + refine ⟨outL, hm, hout, by rw [hruns], ?_, hpost, ?_, ?_⟩ + · intro hf + have hbad := hrel.1.mpr hf + rw [hruns] at hbad + cases hbad + · refine ⟨embTcb badgeTcb, ?_, ?_⟩ + · rw [hpost.kheap_eq, waitResult_tcb] + rfl + · rw [Machine.badge_register_eq] + change embUserRegs (holFunUpd (fun _ => 0) Machine_A.badge_register waitBadge) + (embRegister Machine_A.badge_register) = _ + rw [embUserRegs_embRegister] + simp [holFunUpd, Function.update, waitBadge] + · refine ⟨embNotification idleWaitNtfn, ?_, rfl⟩ + rw [hpost.kheap_eq, waitResult_ntfn] + rfl + + +private def oneTickInterruptState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := oneTickStamped rH + { s with machine_state := { s.machine_state with irq_state := 1 } } + +private theorem oneTickRefillRead + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := oneTickStamped rH + KHeap_A.read_sc_refill_sufficient s.cur_sc s.consumed_time s = some true := by + let sH := oneTickStamped rH + let sL := leanState sH rL + have hcap : Fl4Spec.MIN_BUDGET ≤ Fl4Spec.maxTime - 1 := by + have h := minBudget_one_tick_slack hop + have hn := minBudget_lt_maxTime + unfold Fl4Spec.maxTime at h hn ⊢ + bv_omega + have hread : Fl4Spec.readScRefillSufficient sL.curSc sL.consumedTime sL = some true := by + simp [sH, sL, leanState, oneTickStamped, interruptEntryState, referenceState, nativeHeap, entrySc, + embKernelObject, embSchedContext, embRefill, Fl4Spec.readScRefillSufficient, + Fl4Spec.readRefillHead, Fl4Spec.readSchedContext, Fl4Spec.readObject, Fl4Spec.refillHd, + Fl4Spec.refillSufficient, Fl4Spec.refillCapacity, Fl4Spec.the, Fl4Spec.Lookup.oassert, + Fl4Spec.Lookup.oreturn, bind, ReaderT.bind] + exact hcap + have ht := KHeap.readScRefillSufficient_equiv hop sH.cur_sc sH.consumed_time sH sL + (leanState_related sH rL hr) + change OptRel Eq (KHeap_A.read_sc_refill_sufficient sH.cur_sc sH.consumed_time sH) + (Fl4Spec.readScRefillSufficient sL.curSc sL.consumedTime sL) at ht + rw [hread] at ht + cases h : KHeap_A.read_sc_refill_sufficient sH.cur_sc sH.consumed_time sH with + | none => simp [h, OptRel] at ht + | some result => + have htrue : result = true := by simpa only [h, OptRel] using ht + exact h.trans (congrArg some htrue) + +private theorem oneTickBudgetRead + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := oneTickStamped rH + KHeap_A.get_sc_refill_sufficient s.cur_sc s.consumed_time s = ({(true, s)}, false) := by + intro s + have hread := oneTickRefillRead hop rH rL hr + change KHeap_A.read_sc_refill_sufficient s.cur_sc s.consumed_time s = _ at hread + simp [KHeap_A.get_sc_refill_sufficient, holGetsThe, hread, holAssertOpt, holReturn] + +private theorem oneTickInterruptEvent_run + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Syscall.handle_interrupt_p (oneTickEntry rH) = ({(.inr (), oneTickInterruptState rH)}, false) := by + let s := oneTickStamped rH + have hb : Ipc.check_budget_p s = ({(!KHeap_A.is_cur_domain_expired s, s)}, false) := by + unfold Ipc.check_budget_p + rw [hol_bind_singleton_at _ (show holGets _ s = _ from rfl), + hol_bind_singleton_at _ (show holGets _ s = _ from rfl), + hol_bind_singleton_at _ (oneTickBudgetRead hop rH rL hr)] + simp [holIf_true, holGets, holBind, holReturn, holNot, s] + have hirq := machineOperationRunH (MachineOps.getActiveIRQ false) s _ _ + (maskedIrqRunH s.machine_state fun _ => rfl) + have hhandle : Interrupt_A.maybe_handle_interrupt false s = + ({((), oneTickInterruptState rH)}, false) := by + unfold Interrupt_A.maybe_handle_interrupt holFunApp + rw [hol_bind_singleton_at _ hirq] + rfl + have hrun : holBind KHeap_A.update_time_stamp + (holKBind (holBind Ipc.check_budget_p (holKBind (Interrupt_A.maybe_handle_interrupt false)))) + (oneTickEntry rH) = ({((), oneTickInterruptState rH)}, false) := by + rw [hol_bind_singleton_at _ (oneTickStamp_run hop rH)] + change holBind Ipc.check_budget_p (holKBind (Interrupt_A.maybe_handle_interrupt false)) s = _ + rw [hol_bind_singleton_at _ hb] + exact hhandle + unfold Syscall.handle_interrupt_p Exceptions_A.without_preemption + exact holLiftE_singleton_at hrun + +private theorem oneTickHandled_run + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + holHandleE Syscall.handle_interrupt_p + (fun _ => Exceptions_A.without_preemption Syscall.preemption_path_p) + (oneTickEntry rH) = ({(.inr (), oneTickInterruptState rH)}, false) := by + unfold holHandleE holHandleE' + rw [hol_bind_singleton_at _ (oneTickInterruptEvent_run hop rH rL hr)] + rfl + +private theorem oneTickDomainNotExpired (rH : MachineTypes.machine_state_rest) : + KHeap_A.is_cur_domain_expired (oneTickInterruptState rH) = false := by + apply Bool.eq_false_iff.mpr + intro h + unfold KHeap_A.is_cur_domain_expired at h + have hn : (Fl4Spec.maxTime - 1 : Word) ≠ 0 := by decide + exact hn ((holEq_eq_true _ _).mp ((holConj_eq_true _ _).mp h).2) + +private theorem oneTickScRun (rH : MachineTypes.machine_state_rest) : + let s := oneTickInterruptState rH + KHeap_A.get_sched_context s.cur_sc s = ({(entrySc, s)}, false) := by + intro s + have hget : KHeap_A.get_object s.cur_sc s = ({(.SchedContext entrySc 7, s)}, false) := rfl + unfold KHeap_A.get_sched_context + rw [hol_bind_singleton_at _ hget] + rfl + +private theorem oneTickTcbRun {α : Type} [Nonempty α] (rH : MachineTypes.machine_state_rest) + (proj : Structures_A.tcb → α) : + let s := oneTickInterruptState rH + KHeap_A.thread_get proj s.cur_thread s = + ({(proj (mkTcb .Running (some 0x2000)), s)}, false) := + tcbReadRunH _ _ _ proj rfl + +private theorem oneTickNonSyscallKernelSafe + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + Syscall.NonSyscallKernelSafe .Interrupt (oneTickEntry rH) := by + refine ⟨?_, ?_, ?_⟩ + · intro next hm + rw [oneTickStamp_run hop rH] at hm + obtain ⟨_, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm) + intro shorter hs + rw [oneTickBudgetRead hop rH rL hr] at hs + cases (Prod.mk.inj (Set.mem_singleton_iff.mp hs)).1 + · intro next hm + change (Sum.inl (), next) ∈ (Syscall.handle_interrupt_p (oneTickEntry rH)).1 at hm + rw [oneTickInterruptEvent_run hop rH rL hr] at hm + cases (Prod.mk.inj (Set.mem_singleton_iff.mp hm)).1 + · intro result next hm + change (result, next) ∈ (holHandleE Syscall.handle_interrupt_p + (fun _ => Exceptions_A.without_preemption Syscall.preemption_path_p) (oneTickEntry rH)).1 at hm + rw [oneTickHandled_run hop rH rL hr] at hm + obtain ⟨_, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hm) + exact scheduleSafe_resume rfl (oneTickDomainNotExpired rH) rfl rfl + (oneTickTcbRun rH Structures_A.tcb_ext.tcb_sched_context) ⟨entrySc, oneTickScRun rH⟩ + +/-- A masked interrupt runs through the kernel entry with a positive elapsed tick, +both oracle positions advancing and corresponding successful post-states. -/ +theorem liveOneTickInterruptWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let sH := oneTickEntry rH + let sL := leanState sH rL + let outH := oneTickInterruptState rH + ∃ outL, ((), outH) ∈ (Syscall.call_kernel_p nativePlatform.hugePages .Interrupt sH).1 ∧ + ((), outL) ∈ (Fl4Spec.callKernel .interrupt sL).1 ∧ + (Syscall.call_kernel_p nativePlatform.hugePages .Interrupt sH).2 = false ∧ + ¬ (Fl4Spec.callKernel .interrupt sL).2 ∧ StateRel RestRel Eq outH outL ∧ + outL.machineState.irqState = 1 ∧ outL.machineState.timeState = 1 ∧ + outL.consumedTime = 1 ∧ outL.domainTime = Fl4Spec.maxTime - 1 := by + dsimp only + let s := oneTickEntry rH + let out := oneTickInterruptState rH + have hsched := scheduleResumeRun out rfl (oneTickDomainNotExpired rH) rfl rfl + (oneTickTcbRun rH Structures_A.tcb_ext.tcb_sched_context) (oneTickScRun rH) + have hactivation : Tcb.activate_thread_p out = ({((), out)}, false) := by + have hyield : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_yield_to out.cur_thread out = + ({(none, out)}, false) := oneTickTcbRun rH Structures_A.tcb_ext.tcb_yield_to + have hstate : KHeap_A.get_thread_state out.cur_thread out = + ({(.Running, out)}, false) := oneTickTcbRun rH Structures_A.tcb_ext.tcb_state + simp [Tcb.activate_thread_p, holBind, holGets, holKBind, holReturn, holWhen, holNot_eq_true, + holEq_eq_true, hyield, hstate] + have hrun : Syscall.call_kernel_p nativePlatform.hugePages .Interrupt s = ({((), out)}, false) := by + change holBind (holHandleE Syscall.handle_interrupt_p + (fun _ => Exceptions_A.without_preemption Syscall.preemption_path_p)) + (holKBind (holBind Schedule_A.schedule (holKBind Tcb.activate_thread_p))) s = _ + rw [hol_bind_singleton_at _ (oneTickHandled_run hop rH rL hr)] + change holBind Schedule_A.schedule (holKBind Tcb.activate_thread_p) out = _ + rw [hol_bind_singleton_at _ hsched] + exact hactivation + have hbase : BaseCarriers (leanState s rL) := interruptEntry_base rH rL + have hsafe := oneTickNonSyscallKernelSafe hop rH rL hr + have hi : Syscall.CallKernelSafe nativePlatform.hugePages .Interrupt s (leanState s rL) := + { carriers := (leanState_related s rL hr).baseCarriers_iff.mp hbase + eventSafe := hsafe.1 + preemption := hsafe.2.1 + schedule := hsafe.2.2 } + have hrel := Syscall.patched_callKernel_equiv hc hop nativePlatform.hugePages .Interrupt + (leanState_related s rL hr) hi + have hm : ((), out) ∈ (Syscall.call_kernel_p nativePlatform.hugePages .Interrupt s).1 := by rw [hrun]; rfl + obtain ⟨_, outL, hmem, _, hpost⟩ := hrel.2.1 () out hm + refine ⟨outL, hm, hmem, by rw [hrun], ?_, hpost, hpost.machineState_rel.irqState_eq, + hpost.machineState_rel.timeState_eq, hpost.consumedTime_eq, hpost.domainTime_eq⟩ + intro hf + have hbad := hrel.1.mpr hf + rw [hrun] at hbad + cases hbad + + +private def witnessCnode (first second : Structures_A.cap) (slot : List Bool) : Option Structures_A.cap := + if slot = [false] then some first + else if slot = [true] then some second + else none + +private theorem witnessCnode_wellFormed (first second : Structures_A.cap) : + Structures_A.well_formed_cnode_n 1 (witnessCnode first second) = true := by + apply (holEq_eq_true _ _).mpr + ext xs + simp only [holDom, holCollect, Set.mem_ofPred_eq, holEq_eq_true, holSize_list] + cases xs with + | nil => simp [witnessCnode] + | cons b tail => cases b <;> cases tail <;> simp [witnessCnode] + +private theorem getCnodeSlotRun (s : Structures_A.state Unit) (ptr : ObjRef) + (first second : Structures_A.cap) (flag : Bool) + (hheap : s.kheap ptr = some (.CNode 1 (witnessCnode first second))) : + CSpace.get_cap_p (ptr, [flag]) s = ({(if flag then second else first, s)}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.CNode 1 (witnessCnode first second), s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + unfold CSpace.get_cap_p + cases flag <;> rw [hol_bind_singleton_at _ hobj] <;> + simp [holBind, holAssert, holKBind, holReturn, holAssertOpt, witnessCnode_wellFormed, witnessCnode] + +private theorem setCnodeSlotRun (s : Structures_A.state Unit) (ptr : ObjRef) + (first second cap : Structures_A.cap) (flag : Bool) + (hheap : s.kheap ptr = some (.CNode 1 (witnessCnode first second))) : + let caps := holFunUpd (witnessCnode first second) [flag] (some cap) + let out := { s with kheap := holFunUpd s.kheap ptr (some (.CNode 1 caps)) } + CSpace.set_cap_p cap (ptr, [flag]) s = ({((), out)}, false) := by + dsimp only + have hobj : KHeap_A.get_object ptr s = ({(.CNode 1 (witnessCnode first second), s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + let updated := holFunUpd (witnessCnode first second) [flag] (some cap) + have hmember : holMember [flag] (holDom (witnessCnode first second)) = true := by + cases flag <;> simp [holMember_eq_true, holDom, witnessCnode] + unfold CSpace.set_cap_p + simp only [singletonSlot_nonExt flag, ↓reduceIte, CSpaceAcc_A.set_cap, holCaseProd_eq] + change holBind (KHeap_A.get_object ptr) _ s = _ + rw [hol_bind_singleton_at _ hobj] + simp only [Structures_A.case_kernel_object, hmember, witnessCnode_wellFormed, + holConj, Bool.true_and, holIf_true, holFunApp] + rw [KHeap.holBind_return_left] + refine setObjectRunH s ptr (.CNode 1 (witnessCnode first second)) (.CNode 1 updated) hheap ?_ + have hdom : holDom updated = holDom (witnessCnode first second) := by + ext slot + by_cases heq : slot = [flag] + · subst slot + cases flag <;> simp [updated, holDom, witnessCnode] + · simp [updated, holDom, heq] + have hwf : Structures_A.well_formed_cnode_n 1 updated = true := by + have h := witnessCnode_wellFormed first second + unfold Structures_A.well_formed_cnode_n at h ⊢ + simpa only [hdom] using h + simp [Structures_A.a_type, Structures_A.case_kernel_object, witnessCnode_wellFormed, hwf, holIf_true] + +private theorem relatedSuccessfulRun {αH αL σH σL : Type} + {SR : σH → σL → Prop} {Ra : αH → αL → Prop} {retH : αH} {outH : σH} + {runH : Set (αH × σH) × Bool} {runL : Set (αL × σL) × Prop} + (hm : MRelStep SR Ra runH runL) (hr : runH = ({(retH, outH)}, false)) : + ∃ retL outL, (retL, outL) ∈ runL.1 ∧ Ra retH retL ∧ SR outH outL ∧ ¬runL.2 := by + obtain ⟨retL, outL, hmem, heq, hpost⟩ := hm.2.1 retH outH (by rw [hr]; rfl) + exact ⟨retL, outL, hmem, heq, hpost, fun h => by simpa only [hr, Bool.false_eq_true] using hm.1.mpr h⟩ + +private def capWitnessState (rH : MachineTypes.machine_state_rest) + (first second : Structures_A.cap) : Structures_A.state Unit := + { referenceState rH with + kheap := fun ptr => if ptr = 0x4000 then some (.CNode 1 (witnessCnode first second)) else none } + +private theorem capWitnessBase (rH : MachineTypes.machine_state_rest) (rL : MachineStateRest) + (first second : Structures_A.cap) (hfirst : BaseCap (embCap first)) (hsecond : BaseCap (embCap second)) : + BaseCarriers (leanState (capWitnessState rH first second) rL) := by + change BaseCarriersFor (fun ptr => ((capWitnessState rH first second).kheap ptr).map embKernelObject) + (embCr3 nativeArch.x64_current_cr3) + constructor + · intro ptr a h + by_cases hptr : ptr = 0x4000 <;> simp [capWitnessState, hptr, embKernelObject] at h + · intro ptr size caps slot cap h hcap + by_cases hptr : ptr = 0x4000 + · simp [capWitnessState, hptr, embKernelObject] at h + obtain ⟨_, rfl⟩ := h + simp only [embCnodeContents, witnessCnode] at hcap + split at hcap + · simpa [← Option.some.inj hcap] using hfirst + split at hcap + · simpa [← Option.some.inj hcap] using hsecond + · simp at hcap + · change (if ptr = (0x4000 : ObjRef) then some (Structures_A.kernel_object.CNode 1 + (witnessCnode first second)) else none).map embKernelObject = _ at h + rw [ite_eq_right hptr] at h + cases h + · intro ptr t h + by_cases hptr : ptr = 0x4000 <;> simp [capWitnessState, hptr, embKernelObject] at h + · intro ptr entries index root h _ + by_cases hptr : ptr = 0x4000 <;> simp [capWitnessState, hptr, embKernelObject] at h + · exact (nativeHeap_base baseSc).commonPcid + +private abbrev capWitnessSlot : CslotPtr := (0x4000, [false]) + +private def witnessFrame : Arch_Structs_A.arch_cap := + .PageCap false 0x6000 VMRights_A.vm_read_write .VMVSpaceMap .X64SmallPage (some (1, 0)) + +private def clearedWitnessFrame : Structures_A.cap := + .ArchObjectCap (.PageCap false 0x6000 VMRights_A.vm_read_write .VMNoMap .X64SmallPage none) + +private theorem witnessFrame_base : BaseCap (embCap (.ArchObjectCap witnessFrame)) := by + constructor + · intro he + cases he + change ∀ asid addr, some ((1 : Asid), (0 : VSpaceRef)) = some (asid, addr) → BaseAsid asid + intro asid addr h + have ha := (Prod.mk.inj (Option.some.inj h)).1 + subst asid + unfold BaseAsid + decide + +private theorem witnessPageUnmapPrefixRun (rH : MachineTypes.machine_state_rest) : + let s := capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap + ArchVSpace_A.unmap_page .X64SmallPage 1 0 0x6000 s = ({((), s)}, false) := by + let s := capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap + have hfind : ArchVSpace_A.find_vspace_for_asid 1 s = + ({(.inl .InvalidRoot, s)}, false) := by + unfold ArchVSpace_A.find_vspace_for_asid + have ha : holLt (HolZero.zeroVal (α := Word)) (1 : Word) = true := + (holLt_eq_true _ _).mpr (by change (0 : Word) < 1; decide) + have hassert : holAssertE (ε := ExceptionTypes_A.lookup_failure) + (holLt (HolZero.zeroVal (α := Word)) (1 : Word)) s = ({(.inr (), s)}, false) := by + rw [ha] + apply holLiftE_singleton_at + simp [holAssert] + dsimp only [holBindE] + erw [hol_bind_singleton_at _ hassert] + simp [holBind, holLiftE, holLiftM, holGets, holReturn, + holCaseOption, holThrowError, holReturnOk, holFunApp, holKBind, holComp, + capWitnessState, nativeArch, referenceState, s] + change ArchVSpace_A.unmap_page .X64SmallPage 1 0 0x6000 s = _ + unfold ArchVSpace_A.unmap_page holCatch + have hbound (f : ObjRef → HolNonDet (Structures_A.state Unit) + (Sum ExceptionTypes_A.lookup_failure Unit)) : + holBindE (ArchVSpace_A.find_vspace_for_asid 1) f s = ({(.inl .InvalidRoot, s)}, false) := by + unfold holBindE + rw [hol_bind_singleton_at _ hfind] + rfl + rw [hol_bind_singleton_at _ (hbound _)] + rfl + +private theorem witnessPageUnmapSafe (rH : MachineTypes.machine_state_rest) : + ArchInvoke.PageUnmapSafe witnessFrame capWitnessSlot + (capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap) := by + constructor + · intro a v h + injection h with he + have ha := (Prod.mk.inj he).1 + subst a + unfold BaseAsid + decide + · intro t ht + change ((), t) ∈ (ArchVSpace_A.unmap_page .X64SmallPage 1 0 0x6000 _).1 at ht + rw [witnessPageUnmapPrefixRun rH] at ht + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp ht)).2 + subst t + intro cap target hcap + rw [getCnodeSlotRun _ 0x4000 (.ArchObjectCap witnessFrame) .NullCap false rfl] at hcap + have hc := (Prod.mk.inj (Set.mem_singleton_iff.mp hcap)).1 + subst cap + exact ⟨rfl, Or.inl (Or.inl (singletonSlot_nonExt false))⟩ + +private def clearedFrameState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap + let caps := holFunUpd (witnessCnode (.ArchObjectCap witnessFrame) .NullCap) [false] (some clearedWitnessFrame) + { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 caps)) } + +private theorem witnessPageUnmapRun (rH : MachineTypes.machine_state_rest) : + let s := capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap + let out := clearedFrameState rH + ArchInvoke.perform_page_invocation_unmap_p witnessFrame capWitnessSlot s = ({((), out)}, false) := by + dsimp only + unfold ArchInvoke.perform_page_invocation_unmap_p + change holBind (ArchVSpace_A.unmap_page (tv_z := Unit) .X64SmallPage 1 0 0x6000) _ + (capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap) = _ + rw [hol_bind_singleton_at _ (witnessPageUnmapPrefixRun rH)] + change holBind (CSpace.get_cap_p capWitnessSlot) _ _ = _ + rw [hol_bind_singleton_at _ (getCnodeSlotRun _ 0x4000 (.ArchObjectCap witnessFrame) .NullCap false rfl)] + exact setCnodeSlotRun _ 0x4000 (.ArchObjectCap witnessFrame) .NullCap clearedWitnessFrame false rfl + +/-- Successful frame unmapping clears a stale native mapping cap. -/ +theorem livePageUnmapWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap + let runH := ArchInvoke.perform_page_invocation_unmap_p witnessFrame capWitnessSlot s + let runL := Fl4Spec.performPageInvocationUnmap (embArchCap witnessFrame) capWitnessSlot (leanState s rL) + ∃ outH outL, runH = ({((), outH)}, false) ∧ ((), outL) ∈ runL.1 ∧ ¬runL.2 ∧ + StateRel RestRel Eq outH outL ∧ + outL.kheap 0x4000 = some (.cnode 1 (embCnodeContents + (holFunUpd (witnessCnode (.ArchObjectCap witnessFrame) .NullCap) [false] (some clearedWitnessFrame)))) := by + dsimp only + have hrun := witnessPageUnmapRun rH + have hrel := ArchInvoke.patched_performPageInvocationUnmap_equiv hop witnessFrame capWitnessSlot + (leanState_related _ _ hr) (capWitnessBase rH rL _ .NullCap witnessFrame_base trivial) (witnessPageUnmapSafe rH) + obtain ⟨_, out, hm, rfl, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + refine ⟨_, out, hrun, hm, hf, hpost, ?_⟩ + rw [hpost.kheap_eq] + simp [clearedFrameState, holFunUpd, embKernelObject] + +/-- The native architecture dispatcher reaches and clears the same frame cap. -/ +theorem liveArchPageUnmapWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap + let op := ArchInvocation_A.arch_invocation.InvokePage (.PageUnmap witnessFrame capWitnessSlot) + let runH := ArchInvoke.arch_perform_invocation_p op s + let runL := (Fl4Spec.archPerformInvocation (embArchInv op)).run (leanState s rL) + ∃ outH outL, runH = ({(.inr [], outH)}, false) ∧ (Except.ok [], outL) ∈ runL.1 ∧ + ¬runL.2 ∧ StateRel RestRel Eq outH outL := by + dsimp only + let op := ArchInvocation_A.arch_invocation.InvokePage (.PageUnmap witnessFrame capWitnessSlot) + have hrel := ArchInvoke.patched_archPerformInvocation_equiv hop op (leanState_related _ _ hr) + (capWitnessBase rH rL _ .NullCap witnessFrame_base trivial) (witnessPageUnmapSafe rH) + have hrun : ArchInvoke.arch_perform_invocation_p op + (capWitnessState rH (.ArchObjectCap witnessFrame) .NullCap) = + ({(.inr [], clearedFrameState rH)}, false) := by + change holLiftE (holBind (ArchInvoke.perform_page_invocation_unmap_p witnessFrame capWitnessSlot) + (fun _ => holReturn [])) _ = _ + apply holLiftE_singleton_at + rw [hol_bind_singleton_at _ (witnessPageUnmapRun rH)] + rfl + obtain ⟨ret, out, hm, hret, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + cases ret with + | error bad => cases hret + | ok val => + have hv : val = [] := hret.symm + subst val + exact ⟨_, out, hrun, hm, hf, hpost⟩ + + +/-- A direct scheduler run on the state reached by the nonblocking notification wait. -/ +theorem liveScheduleWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := nbWaitResultState rH + ∃ out, ((), out) ∈ (Fl4Spec.schedule (leanState s rL)).1 ∧ + ¬ (Fl4Spec.schedule (leanState s rL)).2 ∧ StateRel RestRel Eq s out := by + dsimp only + have hstep := Schedule.schedule_equiv hc hop (leanState_related _ _ hr) (waitScheduleSafe rH) + obtain ⟨_, out, hm, rfl, hpost, hf⟩ := relatedSuccessfulRun hstep (waitScheduleRun rH) + exact ⟨out, hm, hf, hpost⟩ + +private def witnessPageTableCap : Structures_A.cap := + .ArchObjectCap (.PageTableCap 0x6000 none) + +/-- The direct page table unmap reads and writes its populated native cap slot. -/ +theorem livePageTableUnmapWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := capWitnessState rH witnessPageTableCap .NullCap + let runH := ArchInvoke.perform_page_table_unmap_p witnessPageTableCap capWitnessSlot s + let runL := Fl4Spec.performPageTableInvocation (embPageTableInv (.PageTableUnmap witnessPageTableCap capWitnessSlot)) (leanState s rL) + ∃ outH outL, runH = ({((), outH)}, false) ∧ ((), outL) ∈ runL.1 ∧ ¬runL.2 ∧ + StateRel RestRel Eq outH outL := by + dsimp only + let s := capWitnessState rH witnessPageTableCap .NullCap + let caps := holFunUpd (witnessCnode witnessPageTableCap .NullCap) [false] (some witnessPageTableCap) + let out := { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 caps)) } + have hread := getCnodeSlotRun s 0x4000 witnessPageTableCap .NullCap false rfl + have hsafe : ArchInvoke.PageTableUnmapSafe witnessPageTableCap capWitnessSlot s := by + constructor + · intro _ _ h + cases h + · intro t hm + have ht : t = s := (Prod.mk.inj (Set.mem_singleton_iff.mp hm)).2 + subst t + intro cap target hcap + rw [hread] at hcap + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hcap)).1 + subst cap + exact ⟨trivial, Or.inl (Or.inl (singletonSlot_nonExt false))⟩ + have hbase : BaseCap (embCap witnessPageTableCap) := by + intro _ _ h + cases h + have hrel := ArchInvoke.patched_performPageTableUnmap_equiv hop witnessPageTableCap capWitnessSlot + (leanState_related s rL hr) (capWitnessBase rH rL witnessPageTableCap .NullCap hbase trivial) hsafe + have hrun : ArchInvoke.perform_page_table_unmap_p witnessPageTableCap capWitnessSlot s = ({((), out)}, false) := by + unfold ArchInvoke.perform_page_table_unmap_p + change holBind (holReturn ()) _ s = _ + rw [KHeap.holBind_return_left] + change holBind (CSpace.get_cap_p capWitnessSlot) _ s = _ + rw [hol_bind_singleton_at _ hread] + exact setCnodeSlotRun s 0x4000 witnessPageTableCap .NullCap witnessPageTableCap false rfl + obtain ⟨_, outL, hm, rfl, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + exact ⟨out, outL, hrun, hm, hf, hpost⟩ + +private def witnessPageDirectoryCap : Structures_A.cap := + .ArchObjectCap (.PageDirectoryCap 0x6000 none) + +/-- The direct page directory unmap reads and writes its populated native cap slot. -/ +theorem livePageDirectoryUnmapWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := capWitnessState rH witnessPageDirectoryCap .NullCap + let runH := ArchInvoke.perform_page_directory_unmap_p witnessPageDirectoryCap capWitnessSlot s + let runL := Fl4Spec.performPageDirectoryInvocation (embPageDirectoryInv (.PageDirectoryUnmap witnessPageDirectoryCap capWitnessSlot)) (leanState s rL) + ∃ outH outL, runH = ({((), outH)}, false) ∧ ((), outL) ∈ runL.1 ∧ ¬runL.2 ∧ + StateRel RestRel Eq outH outL := by + dsimp only + let s := capWitnessState rH witnessPageDirectoryCap .NullCap + let caps := holFunUpd (witnessCnode witnessPageDirectoryCap .NullCap) [false] (some witnessPageDirectoryCap) + let out := { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 caps)) } + have hread := getCnodeSlotRun s 0x4000 witnessPageDirectoryCap .NullCap false rfl + have hsafe : ArchInvoke.PageDirectoryUnmapSafe witnessPageDirectoryCap capWitnessSlot s := by + constructor + · intro _ _ h + cases h + · intro t hm + have ht : t = s := (Prod.mk.inj (Set.mem_singleton_iff.mp hm)).2 + subst t + intro cap target hcap + rw [hread] at hcap + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hcap)).1 + subst cap + exact ⟨trivial, Or.inl (Or.inl (singletonSlot_nonExt false))⟩ + have hbase : BaseCap (embCap witnessPageDirectoryCap) := by + intro _ _ h + cases h + have hrel := ArchInvoke.patched_performPageDirectoryUnmap_equiv hop witnessPageDirectoryCap capWitnessSlot + (leanState_related s rL hr) (capWitnessBase rH rL witnessPageDirectoryCap .NullCap hbase trivial) hsafe + have hrun : ArchInvoke.perform_page_directory_unmap_p witnessPageDirectoryCap capWitnessSlot s = ({((), out)}, false) := by + unfold ArchInvoke.perform_page_directory_unmap_p + change holBind (holReturn ()) _ s = _ + rw [KHeap.holBind_return_left] + change holBind (CSpace.get_cap_p capWitnessSlot) _ s = _ + rw [hol_bind_singleton_at _ hread] + exact setCnodeSlotRun s 0x4000 witnessPageDirectoryCap .NullCap witnessPageDirectoryCap false rfl + obtain ⟨_, outL, hm, rfl, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + exact ⟨out, outL, hrun, hm, hf, hpost⟩ + +private theorem doExtendedOpUnitRun + (m : HolNonDet (Structures_A.state Deterministic_A.det_ext) Unit) + (s : Structures_A.state Unit) : + Deterministic_A.do_extended_op m s = ({((), s)}, false) := by + have hwrap : Deterministic_A.state_ext_class.wrap_ext_op m s = holReturn () s := rfl + simp [Deterministic_A.do_extended_op, hwrap, holBind, holGet, holSelectF, holMkEf, + holReturn, holCaseProd, holModify, Structures_A.state.exst_update] + +private def afterCapInsert (cap srcCap : Structures_A.cap) (src dest : CslotPtr) + (s : Structures_A.state Unit) : Structures_A.state Unit := + let orig := CSpace_A.is_cap_revocable cap srcCap + let parent := CSpace.should_be_parent_of_p srcCap (s.is_original_cap src) cap orig + { s with + cdt := holFunUpd s.cdt dest (holIf parent (some src) (s.cdt src)) + is_original_cap := holFunUpd s.is_original_cap dest orig } + +private theorem capInsertRun (cap srcCap : Structures_A.cap) (src dest : CslotPtr) + (s written : Structures_A.state Unit) + (hsrc : CSpace.get_cap_p src s = ({(srcCap, s)}, false)) + (hdest : CSpace.get_cap_p dest s = ({(.NullCap, s)}, false)) + (hnon : Structures_A.is_untyped_cap cap = false) + (hwrite : CSpace.set_cap_p cap dest s = ({((), written)}, false)) : + CSpace.cap_insert_p cap src dest s = ({((), afterCapInsert cap srcCap src dest written)}, false) := by + unfold CSpace.cap_insert_p + rw [hol_bind_singleton_at _ hsrc, KHeap.holBind_return_left, hol_bind_singleton_at _ hdest] + have hassert : holAssert (holEq Structures_A.cap.NullCap .NullCap) s = ({((), s)}, false) := by + simp [holAssert, holEq] + rw [hol_bind_singleton_at _ hassert] + simp only [holKBind] + have hfull : CSpace.set_untyped_cap_as_full_p srcCap cap src s = ({((), s)}, false) := by + simp [CSpace.set_untyped_cap_as_full_p, hnon, holConj, holIf_false, holReturn] + rw [hol_bind_singleton_at _ hfull] + simp only [holKBind] + rw [hol_bind_singleton_at _ hwrite] + simp only [holKBind] + rw [hol_bind_singleton_at _ (show holGets _ written = _ from rfl), KHeap.holBind_return_left, + hol_bind_singleton_at _ (show holGets _ written = _ from rfl), + hol_bind_singleton_at _ (show holGets _ written = _ from rfl)] + let orig := CSpace_A.is_cap_revocable cap srcCap + let parent := CSpace.should_be_parent_of_p srcCap (written.is_original_cap src) cap orig + let cdt := holFunUpd written.cdt dest (holIf parent (some src) (written.cdt src)) + let t := { written with cdt := cdt } + have hcdt : CSpaceAcc_A.update_cdt + (fun cdt => holFunUpd cdt dest (holIf parent (some src) (cdt src))) written = ({((), t)}, false) := by + unfold CSpaceAcc_A.update_cdt + rw [hol_bind_singleton_at _ (show holGets _ written = _ from rfl)] + simp [CSpaceAcc_A.set_cdt, holBind, holGet, holPut, Structures_A.abstract_state.cdt_update, t, cdt] + change holBind (CSpaceAcc_A.update_cdt _) _ written = _ + rw [hol_bind_singleton_at _ hcdt] + simp only [holKBind] + rw [hol_bind_singleton_at _ (doExtendedOpUnitRun _ t)] + change CSpaceAcc_A.set_original dest orig t = _ + unfold CSpaceAcc_A.set_original + rw [hol_bind_singleton_at _ (show holGets _ t = _ from rfl)] + rfl + +private theorem capInsertSafeAtKnownSource (cap srcCap : Structures_A.cap) + (src dest : CslotPtr) (s : Structures_A.state Unit) + (hread : CSpace.get_cap_p src s = ({(srcCap, s)}, false)) + (hvalid : CSpace.DeriveSrcValid cap srcCap) + (hsrc : CSpaceAcc.NonExtTcbSlot src.2) (hdest : CSpaceAcc.NonExtTcbSlot dest.2) : + CSpace.CapInsertSafe cap src dest s := by + intro actual t h + rw [hread] at h + obtain ⟨rfl, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp h) + exact ⟨hvalid, fun _ _ _ _ => ⟨Or.inl hsrc, fun _ _ _ => Or.inl (Or.inl hdest)⟩⟩ + +/-- The interrupt-control performer changes the IRQ state and installs its handler cap. -/ +theorem liveInvokeIrqControlWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := capWitnessState rH .IRQControlCap .NullCap + let op := Invocations_A.irq_control_invocation.IRQControl 0 (0x4000, [true]) capWitnessSlot + let runH := Interrupt.invoke_irq_control_p op s + let runL := (Fl4Spec.invokeIrqControl (embIrqControlInv op)).run (leanState s rL) + ∃ outH outL, runH = ({(.inr (), outH)}, false) ∧ (Except.ok (), outL) ∈ runL.1 ∧ + ¬runL.2 ∧ StateRel RestRel Eq outH outL ∧ outL.interruptStates 0 = .irqSignal := by + dsimp only + let s := capWitnessState rH .IRQControlCap .NullCap + let hstate := { s with interrupt_states := holFunUpd s.interrupt_states 0 .IRQSignal } + let t := { hstate with machine_state := { s.machine_state with + irq_masks := holFunUpd s.machine_state.irq_masks 0 false } } + let cap := Structures_A.cap.IRQHandlerCap 0 + let src : CslotPtr := capWitnessSlot + let dest : CslotPtr := (0x4000, [true]) + let op := Invocations_A.irq_control_invocation.IRQControl 0 dest src + let caps := holFunUpd (witnessCnode .IRQControlCap .NullCap) [true] (some cap) + let written := { t with kheap := holFunUpd t.kheap 0x4000 (some (.CNode 1 caps)) } + have hirq : KHeap_A.set_irq_state .IRQSignal 0 s = ({((), t)}, false) := by + unfold KHeap_A.set_irq_state + rw [hol_bind_singleton_at _ (show holModify _ s = ({((), hstate)}, false) from rfl)] + have hm : MachineOps.maskInterrupt false 0 hstate.machine_state = ({((), t.machine_state)}, false) := rfl + have he : holEq Structures_A.irq_state.IRQSignal Structures_A.irq_state.IRQInactive = false := by + simp [holEq] + simp only [holKBind, holFunApp, he] + exact machineOperationRunH _ hstate () t.machine_state hm + have hread := getCnodeSlotRun t 0x4000 .IRQControlCap .NullCap false rfl + have hvalid : CSpace.DeriveSrcValid cap .IRQControlCap := by + change CSpace.DeriveSrcValid (.IRQHandlerCap 0) .IRQControlCap + constructor <;> rintro ⟨_, _, _, he⟩ <;> cases he + have hsafe : Interrupt.InvokeIrqControlSafe op s := by + intro u hu + rw [hirq] at hu + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hu)).2 + subst u + exact capInsertSafeAtKnownSource cap .IRQControlCap src dest t hread hvalid + (singletonSlot_nonExt false) (singletonSlot_nonExt true) + have hrel := Interrupt.patched_invokeIrqControl_equiv hop op (leanState_related s rL hr) hsafe + have hrun : Interrupt.invoke_irq_control_p op s = + ({(.inr (), afterCapInsert cap .IRQControlCap src dest written)}, false) := by + apply holLiftE_singleton_at + change holBind (KHeap_A.set_irq_state .IRQSignal 0) _ s = _ + rw [hol_bind_singleton_at _ hirq] + exact capInsertRun cap .IRQControlCap src dest t written hread + (getCnodeSlotRun t 0x4000 .IRQControlCap .NullCap true rfl) rfl + (setCnodeSlotRun t 0x4000 .IRQControlCap .NullCap cap true rfl) + obtain ⟨ret, out, hm, hret, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + cases ret with + | error bad => cases hret + | ok _ => + refine ⟨_, out, hrun, hm, hf, hpost, ?_⟩ + rw [hpost.interruptStates_eq] + simp [afterCapInsert, written, t, hstate, holFunUpd, embIrqState] + + +private def zeroCnode (cap : Structures_A.cap) (slot : List Bool) : Option Structures_A.cap := + if slot = [] then some cap else none + +private theorem zeroCnode_wellFormed (cap : Structures_A.cap) : + Structures_A.well_formed_cnode_n 0 (zeroCnode cap) = true := by + apply (holEq_eq_true _ _).mpr + ext slot + cases slot <;> simp [holDom, holCollect, holEq_eq_true, holSize_list, zeroCnode] + +private theorem getZeroSlotRun (s : Structures_A.state Unit) (ptr : ObjRef) + (cap : Structures_A.cap) (hheap : s.kheap ptr = some (.CNode 0 (zeroCnode cap))) : + CSpace.get_cap_p (ptr, []) s = ({(cap, s)}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.CNode 0 (zeroCnode cap), s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + unfold CSpace.get_cap_p + rw [hol_bind_singleton_at _ hobj] + simp [holBind, holAssert, holKBind, holReturn, holAssertOpt, zeroCnode_wellFormed, zeroCnode] + +private theorem setZeroSlotRun (s : Structures_A.state Unit) (ptr : ObjRef) + (old cap : Structures_A.cap) (hheap : s.kheap ptr = some (.CNode 0 (zeroCnode old))) : + CSpace.set_cap_p cap (ptr, []) s = + ({((), { s with kheap := holFunUpd s.kheap ptr (some (.CNode 0 (zeroCnode cap))) })}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.CNode 0 (zeroCnode old), s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + have hslot : CSpaceAcc.NonExtTcbSlot [] := by unfold CSpaceAcc.NonExtTcbSlot; decide + have hmem : holMember ([] : List Bool) (holDom (zeroCnode old)) = true := by + simp [holMember_eq_true, holDom, zeroCnode] + unfold CSpace.set_cap_p + simp only [hslot, ↓reduceIte, CSpaceAcc_A.set_cap, holCaseProd_eq] + change holBind (KHeap_A.get_object ptr) _ s = _ + rw [hol_bind_singleton_at _ hobj] + simp only [Structures_A.case_kernel_object, hmem, zeroCnode_wellFormed, + holConj, Bool.true_and, holIf_true, holFunApp] + rw [KHeap.holBind_return_left] + have hc : holFunUpd (zeroCnode old) [] (some cap) = zeroCnode cap := by + funext slot + by_cases hs : slot = [] <;> simp [holFunUpd, zeroCnode, hs] + rw [hc] + exact setObjectRunH s ptr (.CNode 0 (zeroCnode old)) (.CNode 0 (zeroCnode cap)) hheap (by + simp [Structures_A.a_type, Structures_A.case_kernel_object, zeroCnode_wellFormed, holIf_true]) + +private def irqHandlerWitnessState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := capWitnessState rH waitCap .NullCap + { s with + kheap := holFunUpd s.kheap 0x7000 (some (.CNode 0 (zeroCnode .NullCap))) + interrupt_irq_node := fun _ => 0x7000 } + +/-- Setting an IRQ handler inserts the notification into the reached IRQ slot. -/ +theorem liveInvokeIrqHandlerWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := irqHandlerWitnessState rH + let op := Invocations_A.irq_handler_invocation.SetIRQHandler 0 waitCap capWitnessSlot + let runH := Interrupt.invoke_irq_handler_p op s + let runL := Fl4Spec.invokeIrqHandler (embIrqHandlerInv op) (leanState s rL) + ∃ outH outL, runH = ({((), outH)}, false) ∧ ((), outL) ∈ runL.1 ∧ + ¬runL.2 ∧ StateRel RestRel Eq outH outL ∧ + outL.kheap 0x7000 = some (.cnode 0 (embCnodeContents (zeroCnode waitCap))) := by + dsimp only + let s := irqHandlerWitnessState rH + let dest : CslotPtr := (0x7000, []) + let op := Invocations_A.irq_handler_invocation.SetIRQHandler 0 waitCap capWitnessSlot + let written := { s with kheap := holFunUpd s.kheap 0x7000 (some (.CNode 0 (zeroCnode waitCap))) } + have hdest := getZeroSlotRun s 0x7000 .NullCap (by simp [s, irqHandlerWitnessState, holFunUpd]) + have hsrc := getCnodeSlotRun s 0x4000 waitCap .NullCap false + (by simp [s, irqHandlerWitnessState, holFunUpd, Function.update, capWitnessState]) + have hirq : KHeap_A.get_irq_slot 0 s = ({(dest, s)}, false) := rfl + have hdelete : CSpace.cap_delete_one_p dest s = ({((), s)}, false) := by + unfold CSpace.cap_delete_one_p + rw [hol_bind_singleton_at _ hdest] + simp [holUnless, holEq, holReturn] + have hvalid : CSpace.DeriveSrcValid waitCap waitCap := by + constructor + · rintro ⟨_, _, _, h⟩ + change Structures_A.cap.NotificationCap _ _ _ = _ at h + cases h + · intro _ + exact Or.inr ⟨0x5000, 0, waitRights, rfl⟩ + have hsafe : Interrupt.InvokeIrqHandlerSafe op s := by + intro slot t hslot + rw [hirq] at hslot + obtain ⟨rfl, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hslot) + intro u hu + rw [hdelete] at hu + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hu)).2 + subst u + exact capInsertSafeAtKnownSource waitCap waitCap capWitnessSlot dest s hsrc hvalid + (singletonSlot_nonExt false) (by change CSpaceAcc.NonExtTcbSlot []; unfold CSpaceAcc.NonExtTcbSlot; decide) + have hrel := Interrupt.patched_invokeIrqHandler_equiv hop op (leanState_related s rL hr) hsafe + have hrun : Interrupt.invoke_irq_handler_p op s = + ({((), afterCapInsert waitCap waitCap capWitnessSlot dest written)}, false) := by + simp only [op, Interrupt.invoke_irq_handler_p] + rw [hol_bind_singleton_at _ hirq, hol_bind_singleton_at _ hdelete] + exact capInsertRun waitCap waitCap capWitnessSlot dest s written hsrc hdest rfl + (setZeroSlotRun s 0x7000 .NullCap waitCap (by simp [s, irqHandlerWitnessState, holFunUpd])) + obtain ⟨_, out, hm, rfl, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + refine ⟨_, out, hrun, hm, hf, hpost, ?_⟩ + rw [hpost.kheap_eq] + simp [afterCapInsert, written, holFunUpd, embKernelObject] + + +private abbrev faultHandlerIndex : List Bool := Structures_A.tcb_cnode_index 3 + +private theorem faultHandlerSlot_nonExt : CSpaceAcc.NonExtTcbSlot faultHandlerIndex := by + change Structures_A.tcb_cnode_index 3 ≠ Fl4Spec.tcbCnodeIndex 5 + rw [← Structures.tcbCnodeIndex_eq 3] + decide + +private theorem getTcbFaultHandlerRun (s : Structures_A.state Unit) (ptr : ObjRef) (tcb : Structures_A.tcb) + (hheap : s.kheap ptr = some (.TCB tcb)) : + CSpace.get_cap_p (ptr, faultHandlerIndex) s = ({(tcb.tcb_fault_handler, s)}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.TCB tcb, s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + have h34 : Structures_A.tcb_cnode_index 3 ≠ Structures_A.tcb_cnode_index 4 := by + rw [← Structures.tcbCnodeIndex_eq 3, ← Structures.tcbCnodeIndex_eq 4] + decide + have h35 : Structures_A.tcb_cnode_index 3 ≠ Fl4Spec.tcbCnodeIndex 5 := faultHandlerSlot_nonExt + have hslot : Patched.tcb_cnode_map tcb faultHandlerIndex = some tcb.tcb_fault_handler := by + simp [Patched.tcb_cnode_map, faultHandlerIndex, Structures_A.tcb_cnode_map, + HolNumeral.ofNatVal, holFunUpd, h34, h35] + unfold CSpace.get_cap_p + rw [hol_bind_singleton_at _ hobj] + simp [holBind, holReturn, holAssertOpt, hslot] + +private theorem setTcbFaultHandlerRun (s : Structures_A.state Unit) (ptr : ObjRef) (tcb : Structures_A.tcb) + (cap : Structures_A.cap) (hheap : s.kheap ptr = some (.TCB tcb)) : + let obj := Structures_A.kernel_object.TCB { tcb with tcb_fault_handler := cap } + let t := { s with kheap := holFunUpd s.kheap ptr (some obj) } + CSpace.set_cap_p cap (ptr, faultHandlerIndex) s = ({((), t)}, false) := by + dsimp only + have hobj : KHeap_A.get_object ptr s = ({(.TCB tcb, s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + have hi (n : Nat) (hn : n < 3) : Structures_A.tcb_cnode_index 3 ≠ Structures_A.tcb_cnode_index n := by + have hn' : n = 0 ∨ n = 1 ∨ n = 2 := by omega + rcases hn' with rfl | rfl | rfl <;> + rw [← Structures.tcbCnodeIndex_eq] <;> decide + unfold CSpace.set_cap_p + simp only [faultHandlerSlot_nonExt, ↓reduceIte, CSpaceAcc_A.set_cap, holCaseProd_eq] + change holBind (KHeap_A.get_object ptr) _ s = _ + rw [hol_bind_singleton_at _ hobj] + have hf n (hn : n < 3) : holEq (Structures_A.tcb_cnode_index 3) (Structures_A.tcb_cnode_index n) = false := + Bool.eq_false_iff.mpr (mt (holEq_eq_true _ _).mp (hi n hn)) + have h3 : holEq (Structures_A.tcb_cnode_index 3) (Structures_A.tcb_cnode_index 3) = true := + (holEq_eq_true _ _).mpr rfl + simp only [Structures_A.case_kernel_object, faultHandlerIndex, HolZero.zeroVal, HolOne.oneVal, + HolNumeral.ofNatVal, hf 0 (by decide), hf 1 (by decide), hf 2 (by decide), h3, + holIf_false, holIf_true, holFunApp] + rw [KHeap.holBind_return_left] + exact setObjectRunH s ptr (.TCB tcb) (.TCB { tcb with tcb_fault_handler := cap }) hheap rfl + +private theorem deleteNullSlotRun (slot : CslotPtr) (s : Structures_A.state Unit) + (hcap : CSpace.get_cap_p slot s = ({(.NullCap, s)}, false)) : + CSpace.RecDelDom (.CTEDeleteCall slot true) s ∧ CSpace.cap_delete_p slot s = ({(.inr (), s)}, false) := by + let final : Set (Sum Unit (Bool × Structures_A.cap) × Structures_A.state Unit) × Bool := + ({(.inr (true, .NullCap), s)}, false) + let deleted : Set (Sum Unit (Bool × Structures_A.cap) × Structures_A.state Unit) × Bool := + ({(.inr holUndefined, s)}, false) + have hlookup : Exceptions_A.without_preemption (CSpace.get_cap_p slot) s = ({(.inr .NullCap, s)}, false) := + holLiftE_singleton_at hcap + have hfin r : CSpace.rec_del_step_p r (.FinaliseSlotCall slot true) s = final := by + simp only [CSpace.rec_del_step_p, holBindE] + rw [hol_bind_singleton_at _ hlookup] + simp [holEq, holIf_true, holReturnOk, holReturn, final] + have hbad : ∀ cap t, (Sum.inr cap, t) ∈ (Exceptions_A.without_preemption (CSpace.get_cap_p slot) s).1 → + cap ≠ .NullCap → False := by + intro cap t hm hne + rw [hlookup] at hm + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hm)).1 + exact hne (Sum.inr.inj he) + have hempty : CSpace.empty_slot_p slot .NullCap s = ({((), s)}, false) := by + unfold CSpace.empty_slot_p + rw [hol_bind_singleton_at _ hcap] + simp [holEq, holIf_true, holReturn] + have hdel r (hr : r (.FinaliseSlotCall slot true, s) = final) : + CSpace.rec_del_step_p r (.CTEDeleteCall slot true) s = deleted := by + simp only [CSpace.rec_del_step_p, holBindE] + have hr' : (fun t => r (.FinaliseSlotCall slot true, t)) s = ({(.inr (true, .NullCap), s)}, false) := hr + rw [hol_bind_singleton_at _ hr'] + dsimp only + have hw : Exceptions_A.without_preemption + (holWhen (holDisj true true) (CSpace.empty_slot_p slot .NullCap)) s = ({(.inr (), s)}, false) := by + apply holLiftE_singleton_at + exact hempty + rw [hol_bind_singleton_at _ hw] + rfl + let r := fun _ : CSpace_A.rec_del_call × Structures_A.state Unit => final + have hgfin : CSpace.RecDelPGraph (.FinaliseSlotCall slot true, s) (r (.FinaliseSlotCall slot true, s)) := by + change CSpace.RecDelPGraph (.FinaliseSlotCall slot true, s) final + rw [← hfin r] + exact CSpace.RecDelPGraph.finaliseSlot + (fun cap t _ _ hm hn _ => False.elim (hbad cap t hm hn)) + (fun cap t _ _ _ _ _ hm hn _ _ _ => False.elim (hbad cap t hm hn)) + (fun cap t _ _ _ _ _ _ _ hm hn _ _ _ _ _ => False.elim (hbad cap t hm hn)) + (fun cap t _ _ _ _ _ _ _ _ _ _ _ hm hn _ _ _ _ _ _ _ => False.elim (hbad cap t hm hn)) + have hgdel : CSpace.RecDelPGraph (.CTEDeleteCall slot true, s) deleted := by + rw [← hdel r rfl] + exact CSpace.RecDelPGraph.cteDelete hgfin + have hfinal_unique : ∀ y, CSpace.RecDelPGraph (.FinaliseSlotCall slot true, s) y → y = final := by + intro y hy + cases hy with + | finaliseSlot => exact hfin _ + have hunique : ∀ y, CSpace.RecDelPGraph (.CTEDeleteCall slot true, s) y → y = deleted := by + intro y hy + cases hy with + | cteDelete hsub => + rename_i rr + exact hdel rr (hfinal_unique _ hsub) + refine ⟨⟨deleted, hgdel, hunique⟩, ?_⟩ + have hrecdel : CSpace.rec_del_p (.CTEDeleteCall slot true) s = deleted := by + unfold CSpace.rec_del_p + exact CSpace.holTheDefault_eq_of_iff (fun y => by + simp only [decide_eq_true_eq] + exact ⟨hunique y, fun h => h.symm ▸ hgdel⟩) + unfold CSpace.cap_delete_p holBindE + rw [hol_bind_singleton_at _ hrecdel] + rfl + +private def tcbInstallWitnessState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := capWitnessState rH waitCap (.ThreadCap 0x1000) + { s with kheap := holFunUpd s.kheap 0x1000 (some (.TCB (mkTcb .Running none))) } + +/-- A non-null fault-handler capability passes both identity checks and is installed in the TCB. -/ +theorem liveInvokeTcbInstallWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hc : ConfigRel) (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := tcbInstallWitnessState rH + let op := Invocations_A.tcb_invocation.ThreadControlSched 0x1000 (0x4000, [true]) + (some (waitCap, capWitnessSlot)) none none none + let runH := Tcb.invoke_tcb_p op s + let runL := (Fl4Spec.invokeTcb (embTcbInv op)).run (leanState s rL) + ∃ outH outL, runH = ({(.inr [], outH)}, false) ∧ (Except.ok [], outL) ∈ runL.1 ∧ + ¬runL.2 ∧ StateRel RestRel Eq outH outL ∧ + ∃ tcb, outL.kheap 0x1000 = some (.tcb tcb) ∧ tcb.tcbFaultHandler = embCap waitCap := by + dsimp only + let s := tcbInstallWitnessState rH + let tcb := mkTcb .Running none + let src : CslotPtr := capWitnessSlot + let invoked : CslotPtr := (0x4000, [true]) + let dest : CslotPtr := (0x1000, faultHandlerIndex) + let op := Invocations_A.tcb_invocation.ThreadControlSched 0x1000 invoked (some (waitCap, src)) none none none + let installedTcb := { tcb with tcb_fault_handler := waitCap } + let written := { s with kheap := holFunUpd s.kheap 0x1000 (some (.TCB installedTcb)) } + have htcb : s.kheap 0x1000 = some (.TCB tcb) := by + simp [s, tcbInstallWitnessState, holFunUpd, tcb] + have hcnode : s.kheap 0x4000 = some (.CNode 1 (witnessCnode waitCap (.ThreadCap 0x1000))) := by + simp [s, tcbInstallWitnessState, holFunUpd, Function.update, capWitnessState] + have hsrc : CSpace.get_cap_p src s = ({(waitCap, s)}, false) := + getCnodeSlotRun s 0x4000 waitCap (.ThreadCap 0x1000) false hcnode + have hinvoked : CSpace.get_cap_p invoked s = ({(.ThreadCap 0x1000, s)}, false) := + getCnodeSlotRun s 0x4000 waitCap (.ThreadCap 0x1000) true hcnode + have hnull := getTcbFaultHandlerRun s 0x1000 tcb htcb + obtain ⟨hdom, hdelete⟩ := deleteNullSlotRun dest s hnull + have hvalid : CSpace.DeriveSrcValid waitCap waitCap := by + constructor + · rintro ⟨_, _, _, he⟩ + change Structures_A.cap.NotificationCap _ _ _ = _ at he + cases he + · intro _ + exact Or.inr ⟨0x5000, 0, waitRights, rfl⟩ + have hins := capInsertSafeAtKnownSource waitCap waitCap src dest s hsrc hvalid + (singletonSlot_nonExt false) faultHandlerSlot_nonExt + have hsafe : Tcb.InvokeTcbSafe op s := by + refine ⟨hdom, ?_⟩ + intro _ t hm + rw [hdelete] at hm + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hm)).2 + subst t + intro c u hrun _ _ v hrun2 _ + rw [hsrc] at hrun + have hu := (Prod.mk.inj (Set.mem_singleton_iff.mp hrun)).2 + subst u + rw [hinvoked] at hrun2 + have hv := (Prod.mk.inj (Set.mem_singleton_iff.mp hrun2)).2 + subst v + exact hins + have hrel := Tcb.patched_invokeTcb_equiv hop hc op (leanState_related s rL hr) hsafe + have hinstall : Tcb.install_tcb_cap_p 0x1000 invoked 3 (some (waitCap, src)) s = + ({(.inr (), afterCapInsert waitCap waitCap src dest written)}, false) := by + simp only [Tcb.install_tcb_cap_p, holBindE] + rw [hol_bind_singleton_at _ hdelete] + have hn : holEq waitCap .NullCap = false := by simp [holEq, waitCap] + simp only [holKBind, holUnlessE, hn] + apply holLiftE_singleton_at + unfold Tcb.check_cap_at_p + rw [hol_bind_singleton_at _ hsrc] + have hnSame : CSpace_A.same_object_as waitCap waitCap = true := by + simp [CSpace_A.same_object_as, CSpace_A.same_region_as, Structures_A.case_cap, waitCap, holEq, + Structures_A.is_ntfn_cap, Structures_A.obj_ref_of] + have htSame : CSpace_A.same_object_as (.ThreadCap 0x1000) (.ThreadCap 0x1000) = true := by + simp [CSpace_A.same_object_as, CSpace_A.same_region_as, Structures_A.case_cap, holEq, + Structures_A.is_thread_cap, Structures_A.obj_ref_of] + simp only [holWhen, hnSame, ↓reduceIte] + rw [hol_bind_singleton_at _ hinvoked] + simp only [htSame, ↓reduceIte] + exact capInsertRun waitCap waitCap src dest s written hsrc hnull rfl + (setTcbFaultHandlerRun s 0x1000 tcb waitCap htcb) + have hrun : Tcb.invoke_tcb_p op s = ({(.inr [], afterCapInsert waitCap waitCap src dest written)}, false) := by + simp only [op, Tcb.invoke_tcb_p, holBindE] + rw [hol_bind_singleton_at _ hinstall] + simp [holKBind, holLiftE, holLiftM, holMaybeM, holBind, holReturn, holReturnOk] + obtain ⟨ret, out, hm, hret, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + cases ret with + | error bad => cases hret + | ok val => + have hv : val = [] := hret.symm + subst val + refine ⟨_, out, hrun, hm, hf, hpost, embTcb installedTcb, ?_, rfl⟩ + rw [hpost.kheap_eq] + simp [afterCapInsert, written, holFunUpd, embKernelObject] + + +private theorem storeZeroRun (m : MachineTypes.machine_state) (p : Word) + (hm : m.underlying_memory = fun _ => 0) (hp : p &&& 7 = 0) : + MachineOps.storeWord p 0 m = ({((), m)}, false) := by + have halign : holEq (holWordAnd p (holWordMask (w := 64) (HolNumeral.ofNatVal 3))) HolZero.zeroVal = true := + (holEq_eq_true _ _).mpr hp + have ha : holAssert (holEq (holWordAnd p (holWordMask (w := 64) (HolNumeral.ofNatVal 3))) + HolZero.zeroVal) m = ({((), m)}, false) := by + simp [holAssert, halign] + unfold MachineOps.storeWord + rw [hol_bind_singleton_at _ ha] + have hfold : holListFold (fun i old => holFunUpd old (p + holOfInt (w := 64) i) + (holNth (holWordRsplit (m := 8) (0 : Word)) (7 - holIntToNat i))) (holListUpto 0 7) m.underlying_memory = + m.underlying_memory := by + rw [hm] + simp only [holListUpto, holListFold] + change (([0, 1, 2, 3, 4, 5, 6, 7] : List Int).foldl + (fun old i => holFunUpd old (p + holOfInt (w := 64) i) + (holNth (holWordRsplit (m := 8) (0 : Word)) (7 - holIntToNat i))) (fun _ => 0)) = _ + simp only [List.foldl_cons, List.foldl_nil] + have h0 : holNth (holWordRsplit (m := 8) (0 : Word)) 0 = 0 := rfl + have h1 : holNth (holWordRsplit (m := 8) (0 : Word)) 1 = 0 := rfl + have h2 : holNth (holWordRsplit (m := 8) (0 : Word)) 2 = 0 := rfl + have h3 : holNth (holWordRsplit (m := 8) (0 : Word)) 3 = 0 := rfl + have h4 : holNth (holWordRsplit (m := 8) (0 : Word)) 4 = 0 := rfl + have h5 : holNth (holWordRsplit (m := 8) (0 : Word)) 5 = 0 := rfl + have h6 : holNth (holWordRsplit (m := 8) (0 : Word)) 6 = 0 := rfl + have h7 : holNth (holWordRsplit (m := 8) (0 : Word)) 7 = 0 := rfl + simp only [holFunUpd, holIntToNat, Int.toNat, Nat.reduceSub, + h0, h1, h2, h3, h4, h5, h6, h7] + funext q + simp [Function.update] + let mem := holListFold (fun i old => + holFunUpd old (p + holOfInt (w := 64) i) + (holNth (holWordRsplit (m := 8) (0 : Word)) (7 - holIntToNat i))) + (holListUpto 0 7) m.underlying_memory + let out := { m with underlying_memory := mem } + change ({((), out)}, false) = _ + change mem = m.underlying_memory at hfold + unfold out + rw [hfold] + +private theorem zeroPageRun (rH : MachineTypes.machine_state_rest) : + let m := referenceMachine rH + MachineOps.freeMemory 0x6000 MachineTypes.pageBits m = ({((), m)}, false) := by + dsimp only + let m := referenceMachine rH + change holMapMx (fun p => MachineOps.storeWord p 0) (holUptoEnumStep 0x6000 0x6008 0x6fff) m = _ + rw [Machine.holUptoEnumStep_eq] + have hslots : Fl4Spec.uptoEnumStep (0x6000 : Word) 0x6008 0x6fff = + (List.range 512).map (fun i => 0x6000 + BitVec.ofNat 64 i * 8) := by + have hlt : ¬ (0x6fff : Word) < 0x6000 := by decide + unfold Fl4Spec.uptoEnumStep Fl4Spec.uptoEnum + rw [ite_eq_right hlt] + change ((List.range' 0 512).map (BitVec.ofNat 64)).map (fun x => 0x6000 + x * 8) = _ + rw [← List.range_eq_range', List.map_map] + rfl + rw [hslots] + have loop (ps : List Word) (hp : ∀ p ∈ ps, p &&& 7 = 0) : + holMapMx (fun p => MachineOps.storeWord p 0) ps m = ({((), m)}, false) := by + induction ps with + | nil => rfl + | cons p ps ih => + simp only [holMapMx] + rw [hol_bind_singleton_at _ (storeZeroRun m p rfl (hp p List.mem_cons_self))] + exact ih (fun v hv => hp v (List.mem_cons_of_mem p hv)) + apply loop + intro p hp + obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hp + have hi' := List.mem_range.mp hi + have hval : (0x6000 + BitVec.ofNat 64 i * 8 : Word).toNat = 0x6000 + i * 8 := by + simp [BitVec.toNat_add, BitVec.toNat_mul] + omega + apply BitVec.eq_of_toNat_eq + rw [BitVec.toNat_and, hval] + change (0x6000 + i * 8) &&& (2 ^ 3 - 1) = 0 + rw [Nat.and_two_pow_sub_one_eq_mod] + omega + +private def poolWitnessParent : Structures_A.cap := .UntypedCap false 0x6000 12 0 +private def poolWitnessCap : Structures_A.cap := .ArchObjectCap (.ASIDPoolCap 0x6000 0) +private def poolWitnessOp : ArchInvocation_A.arch_invocation := + .InvokeASIDControl (.MakePool 0x6000 (0x4000, [true]) capWitnessSlot 0) + +private theorem deletePoolAreaRun (rH : MachineTypes.machine_state_rest) : + let s := capWitnessState rH poolWitnessParent .NullCap + Retype_A.delete_objects 0x6000 MachineTypes.pageBits s = ({((), s)}, false) := by + dsimp only + let s := capWitnessState rH poolWitnessParent .NullCap + unfold Retype_A.delete_objects + rw [hol_bind_singleton_at _ (machineOperationRunH _ s () s.machine_state (zeroPageRun rH))] + change ({((), Retype_A.detype (holAtLeastAtMost (0x6000 : Word) 0x6fff) s)}, false) = _ + have hk : (fun p => holIf (holMember p (holAtLeastAtMost (0x6000 : Word) 0x6fff)) none (s.kheap p)) = s.kheap := by + funext p + by_cases hp : p = 0x4000 + · subst p + have hnot : holMember (0x4000 : Word) (holAtLeastAtMost (0x6000 : Word) 0x6fff) = false := by + apply Bool.eq_false_iff.mpr + intro hb + have hmem := (holMember_eq_true _ _).mp hb + exact (by decide : ¬ (0x6000 : Word) ≤ 0x4000) hmem.1 + rw [hnot, holIf_false] + · have hnone : s.kheap p = none := by + change (if p = (0x4000 : Word) then some (Structures_A.kernel_object.CNode 1 (witnessCnode poolWitnessParent .NullCap)) else none) = none + rw [ite_eq_right hp] + rw [hnone] + exact ite_self _ + unfold Retype_A.detype Structures_A.abstract_state.kheap_update + rw [hk] + +/-- Native MakePool clears the backing page, creates a pool, and installs the ASID cap and table entry. -/ +theorem liveMakeAsidPoolWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := capWitnessState rH poolWitnessParent .NullCap + let runH := ArchInvoke.arch_perform_invocation_p poolWitnessOp s + let runL := (Fl4Spec.archPerformInvocation (embArchInv poolWitnessOp)).run (leanState s rL) + ∃ outH outL, runH = ({(.inr [], outH)}, false) ∧ (Except.ok [], outL) ∈ runL.1 ∧ + ¬runL.2 ∧ StateRel RestRel Eq outH outL ∧ outL.archState.x64AsidTable 0 = some 0x6000 := by + dsimp only + let s := capWitnessState rH poolWitnessParent .NullCap + let src : CslotPtr := capWitnessSlot + let dest : CslotPtr := (0x4000, [true]) + let maxParent := CSpace_A.max_free_index_update poolWitnessParent + let srcMap := holFunUpd (witnessCnode poolWitnessParent .NullCap) [false] (some maxParent) + let t := { s with kheap := holFunUpd s.kheap 0x4000 (some (.CNode 1 srcMap)) } + let pool := Patched.default_object (.ArchObject .ASIDPoolObj) false 0 t.cur_domain + let u := { t with kheap := holFunUpd t.kheap 0x6000 (some pool) } + let destMap := holFunUpd srcMap [true] (some poolWitnessCap) + let written := { u with kheap := holFunUpd u.kheap 0x4000 (some (.CNode 1 destMap)) } + let ins := afterCapInsert poolWitnessCap maxParent src dest written + let out := { ins with arch_state := { ins.arch_state with + x64_asid_table := Function.update ins.arch_state.x64_asid_table (ArchVSpaceAcc_A.asid_high_bits_of 0) (some 0x6000) } } + have hdel := deletePoolAreaRun rH + have hsrc : CSpace.get_cap_p src s = ({(poolWitnessParent, s)}, false) := + getCnodeSlotRun s 0x4000 poolWitnessParent .NullCap false rfl + have hparent : CSpace.set_cap_p maxParent src s = ({((), t)}, false) := + setCnodeSlotRun s 0x4000 poolWitnessParent .NullCap maxParent false rfl + have hcreate : Retype.retype_region_p 0x6000 1 0 (.ArchObject .ASIDPoolObj) false t = ({([0x6000], u)}, false) := by + unfold Retype.retype_region_p + rw [KHeap.holBind_return_left, KHeap.holBind_return_left] + change holBind (holWhen (holNot (holEq (.ArchObject .ASIDPoolObj : Structures_A.apiobject_type) .Untyped)) _) _ + t = ({([0x6000], u)}, false) + have hn : holNot (holEq (.ArchObject .ASIDPoolObj : Structures_A.apiobject_type) .Untyped) = true := by + simp [holNot, holEq] + simp only [holWhen, hn, ↓reduceIte, KHeap.holBind_assoc] + rw [hol_bind_singleton_at _ (show holGets _ t = _ from rfl), + hol_bind_singleton_at _ (show holGets _ t = _ from rfl), KHeap.holBind_return_left] + rw [hol_bind_singleton_at _ (show holModify _ t = ({((), u)}, false) from rfl)] + rfl + have hmap : srcMap = witnessCnode maxParent .NullCap := by + funext slot + by_cases h : slot = [false] <;> simp [srcMap, witnessCnode, h] + have hheap : u.kheap 0x4000 = some (.CNode 1 (witnessCnode maxParent .NullCap)) := by + simp [u, t, holFunUpd, Function.update, hmap] + have hmax : CSpace.get_cap_p src u = ({(maxParent, u)}, false) := + getCnodeSlotRun u 0x4000 maxParent .NullCap false hheap + have hvalid : CSpace.DeriveSrcValid poolWitnessCap maxParent := by + unfold poolWitnessCap + constructor <;> rintro ⟨_, _, _, he⟩ <;> cases he + have hsafe : ArchInvoke.ArchPerformSafe poolWitnessOp s := by + constructor + · change BaseAsid 0 + unfold BaseAsid + decide + · intro a ha cap b hb + rw [hdel] at ha + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp ha)).2 + subst a + rw [hsrc] at hb + obtain ⟨rfl, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hb) + refine ⟨Or.inl (Or.inl (singletonSlot_nonExt false)), ?_⟩ + intro v hv objs w hw + rw [hparent] at hv + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hv)).2 + subst v + rw [hcreate] at hw + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hw)).2 + subst w + exact capInsertSafeAtKnownSource poolWitnessCap maxParent src dest u hmax hvalid + (singletonSlot_nonExt false) (singletonSlot_nonExt true) + have hrel := ArchInvoke.patched_archPerformInvocation_equiv hop poolWitnessOp (leanState_related s rL hr) + (capWitnessBase rH rL poolWitnessParent .NullCap trivial trivial) hsafe + have hrun : ArchInvoke.arch_perform_invocation_p poolWitnessOp s = ({(.inr [], out)}, false) := by + apply holLiftE_singleton_at + change holBind (ArchInvoke.perform_asid_control_invocation_p (.MakePool 0x6000 dest src 0)) _ s = _ + have hperform : ArchInvoke.perform_asid_control_invocation_p (.MakePool 0x6000 dest src 0) s = ({((), out)}, false) := by + simp only [ArchInvoke.perform_asid_control_invocation_p] + rw [hol_bind_singleton_at _ hdel, hol_bind_singleton_at _ hsrc, + hol_bind_singleton_at _ hparent, hol_bind_singleton_at _ hcreate] + have hwritten : CSpace.set_cap_p poolWitnessCap dest u = ({((), written)}, false) := by + simpa only [written, destMap, hmap] using setCnodeSlotRun u 0x4000 maxParent .NullCap poolWitnessCap true hheap + have hins := capInsertRun poolWitnessCap maxParent src dest u written hmax + (getCnodeSlotRun u 0x4000 maxParent .NullCap true hheap) rfl hwritten + rw [hol_bind_singleton_at _ (show CSpace.cap_insert_p (.ArchObjectCap (.ASIDPoolCap 0x6000 0)) + src dest u = _ from hins)] + have ha : holAssert (holEq (ArchVSpaceAcc_A.asid_low_bits_of 0) 0) ins = ({((), ins)}, false) := by + have he : holEq (ArchVSpaceAcc_A.asid_low_bits_of 0) 0 = true := + (holEq_eq_true _ _).mpr rfl + simp only [holAssert, he, true_and, Bool.not_true] + rfl + rw [hol_bind_singleton_at _ ha] + change holBind (holGets _) _ ins = _ + rw [hol_bind_singleton_at _ (show holGets _ ins = _ from rfl), KHeap.holBind_return_left] + rfl + rw [hol_bind_singleton_at _ hperform] + rfl + obtain ⟨ret, outL, hm, hret, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + cases ret with + | error bad => cases hret + | ok val => + have he : val = [] := hret.symm + subst val + refine ⟨out, outL, hrun, hm, hf, hpost, ?_⟩ + rw [hpost.archState_eq] + change Patched.widen_asid_table out.arch_state.x64_asid_table 0 = _ + rfl + + +private theorem replyPartialInv_eq (reply : Structures_A.reply) : + Lib.partial_inv Structures_A.kernel_object.Reply (.Reply reply) = some reply := by + have hu : ∃! r, holEq (Structures_A.kernel_object.Reply r) (.Reply reply) = true := by + refine ⟨reply, (holEq_eq_true _ _).mpr rfl, ?_⟩ + intro r hr + exact Structures_A.kernel_object.Reply.inj ((holEq_eq_true _ _).mp hr) + unfold Lib.partial_inv holThe + simp only [(holEx1_eq_true _).mpr hu, holIf_true, hu, ↓reduceDIte] + exact congrArg some ((Classical.choose_spec hu).2 _ ((holEq_eq_true _ _).mpr rfl)).symm + +private theorem simpleReplyRun (s : Structures_A.state Unit) (ptr : ObjRef) + (reply : Structures_A.reply) (hheap : s.kheap ptr = some (.Reply reply)) : + KHeap_A.get_simple_ko Structures_A.kernel_object.Reply ptr s = ({(reply, s)}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.Reply reply, s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + unfold KHeap_A.get_simple_ko + rw [hol_bind_singleton_at _ hobj] + simp [holAssert, Structures_A.a_type, Structures_A.case_kernel_object, holMember_eq_true, + holInsert_eq, holBind, holKBind, holCaseOption, replyPartialInv_eq, holReturn] + +private theorem setReplyRun (s : Structures_A.state Unit) (ptr : ObjRef) + (before after : Structures_A.reply) (hheap : s.kheap ptr = some (.Reply before)) : + KHeap_A.set_simple_ko Structures_A.kernel_object.Reply ptr after s = + ({((), { s with kheap := holFunUpd s.kheap ptr (some (.Reply after)) })}, false) := by + have hobj : KHeap_A.get_object ptr s = ({(.Reply before, s)}, false) := by + change holAssertOpt (s.kheap ptr) s = _ + rw [hheap] + rfl + have hs := setObjectRunH s ptr (.Reply before) (.Reply after) hheap rfl + unfold KHeap_A.set_simple_ko + rw [hol_bind_singleton_at _ hobj] + simp [holAssert, Structures_A.a_type, Structures_A.case_kernel_object, holMember_eq_true, + holInsert_eq, holBind, holKBind, holNot_eq_true, holEq_eq_true, replyPartialInv_eq, hs] + +private theorem getTcbRun (s : Structures_A.state Unit) (ptr : ObjRef) + (tcb : Structures_A.tcb) (hheap : s.kheap ptr = some (.TCB tcb)) : + holGetsThe (KHeap_A.get_tcb ptr) s = ({(tcb, s)}, false) := by + simp [holGetsThe, KHeap_A.get_tcb, KHeap_A.read_object, holSwp, holCaseOption, + Structures_A.case_kernel_object, hheap, holAssertOpt, holReturn] + +private theorem threadSetRun (s : Structures_A.state Unit) (ptr : ObjRef) + (tcb : Structures_A.tcb) (f : Structures_A.tcb → Structures_A.tcb) + (hheap : s.kheap ptr = some (.TCB tcb)) : + KHeap_A.thread_set f ptr s = + ({((), { s with kheap := holFunUpd s.kheap ptr (some (.TCB (f tcb))) })}, false) := by + unfold KHeap_A.thread_set holFunApp + rw [hol_bind_singleton_at _ (getTcbRun s ptr tcb hheap)] + exact setObjectRunH s ptr (.TCB tcb) (.TCB (f tcb)) hheap rfl + +private theorem setOtherThreadStateRun (s : Structures_A.state Unit) (ptr : ObjRef) + (tcb : Structures_A.tcb) (state : Structures_A.thread_state) + (hheap : s.kheap ptr = some (.TCB tcb)) (hneq : ptr ≠ s.cur_thread) : + let out := { tcb with tcb_state := state } + KHeap_A.set_thread_state ptr state s = + ({((), { s with kheap := holFunUpd s.kheap ptr (some (.TCB out)) })}, false) := by + dsimp only + let out := { tcb with tcb_state := state } + let t := { s with kheap := holFunUpd s.kheap ptr (some (.TCB out)) } + unfold KHeap_A.set_thread_state + rw [hol_bind_singleton_at _ (threadSetRun s ptr tcb + (Structures_A.tcb.tcb_state_update (fun _ => state)) hheap)] + change KHeap_A.set_thread_state_act ptr t = _ + have hf : holEq ptr t.cur_thread = false := Bool.eq_false_iff.mpr (mt (holEq_eq_true _ _).mp hneq) + unfold KHeap_A.set_thread_state_act + rw [hol_bind_singleton_at _ (show holGets _ t = _ from rfl), + hol_bind_singleton_at _ (show holGets _ t = _ from rfl), + hol_bind_singleton_at _ (show holGets _ t = _ from rfl)] + simp [holWhen, holConj, holFunApp, hf, holReturn, t, out] + +private def replyWitnessFault : ExceptionTypes_A.fault := .CapFault 0 false (.MissingCapability 0) +private def replyWitnessSender : Structures_A.tcb := mkTcb .Running none +private def replyWitnessReceiver : Structures_A.tcb := + { mkTcb (.BlockedOnReply 0x5000) none with tcb_fault := some replyWitnessFault } +private def linkedWitnessReply : Structures_A.reply := { reply_tcb := some 0x2000, reply_sc := none, more := () } +private def unlinkedWitnessReply : Structures_A.reply := { linkedWitnessReply with reply_tcb := none } + +private def replyWitnessState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + { referenceState rH with kheap := fun p => + if p = 0x1000 then some (.TCB replyWitnessSender) + else if p = 0x2000 then some (.TCB replyWitnessReceiver) + else if p = 0x5000 then some (.Reply linkedWitnessReply) + else none } + +private def replyUnlinkedState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := replyWitnessState rH + { s with kheap := holFunUpd s.kheap 0x5000 (some (.Reply unlinkedWitnessReply)) } + +private def replyInactiveTcb : Structures_A.tcb := { replyWitnessReceiver with tcb_state := .Inactive } +private def replyInactiveState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := replyUnlinkedState rH + { s with kheap := holFunUpd s.kheap 0x2000 (some (.TCB replyInactiveTcb)) } + +private theorem replyReadRun (rH : MachineTypes.machine_state_rest) : + holLiftM Structures_A.reply_ext.reply_tcb (KHeap_A.get_simple_ko Structures_A.kernel_object.Reply 0x5000) + (replyWitnessState rH) = ({(some 0x2000, replyWitnessState rH)}, false) := by + unfold holLiftM + rw [hol_bind_singleton_at _ (simpleReplyRun _ 0x5000 linkedWitnessReply rfl)] + rfl + +private theorem replyRemoveRun (rH : MachineTypes.machine_state_rest) : + IpcCancel_A.reply_remove 0x2000 0x5000 (replyWitnessState rH) = + ({((), replyInactiveState rH)}, false) := by + let s := replyWitnessState rH + let t := replyUnlinkedState rH + let h := simpleReplyRun s 0x5000 linkedWitnessReply rfl + have hcaller : KHeap_A.get_thread_state 0x2000 s = ({(.BlockedOnReply 0x5000, s)}, false) := + tcbReadRunH s 0x2000 replyWitnessReceiver Structures_A.tcb_ext.tcb_state rfl + have hsc : IpcCancel_A.sc_with_reply 0x5000 s = none := by + have hnone : ∀ p sc n, s.kheap p ≠ some (.SchedContext sc n) := by + intro p sc n he + change (if p = (0x1000 : ObjRef) then some (Structures_A.kernel_object.TCB replyWitnessSender) + else if p = 0x2000 then some (Structures_A.kernel_object.TCB replyWitnessReceiver) + else if p = 0x5000 then some (Structures_A.kernel_object.Reply linkedWitnessReply) else none) = _ at he + split at he <;> try cases he + split at he <;> try cases he + split at he <;> cases he + unfold IpcCancel_A.sc_with_reply Lib.partial_inv + simp [holEx1_eq_true, holEx_eq_true, holConj_eq_true, holEq_eq_true, hnone, holIf] + have hlink : IpcCancel_A.reply_unlink_tcb 0x2000 0x5000 s = ({((), replyInactiveState rH)}, false) := by + unfold IpcCancel_A.reply_unlink_tcb + rw [hol_bind_singleton_at _ h] + have ha : holAssert (holEq linkedWitnessReply.reply_tcb (some 0x2000)) s = ({((), s)}, false) := by + simp [holAssert, holEq, linkedWitnessReply] + rw [hol_bind_singleton_at _ ha] + simp only [holKBind] + rw [hol_bind_singleton_at _ hcaller] + have he : holEq (Structures_A.thread_state.BlockedOnReply (0x5000 : Word)) (.BlockedOnReply 0x5000) = true := + (holEq_eq_true _ _).mpr rfl + simp only [he, holDisj, Bool.true_or] + rw [hol_bind_singleton_at _ (show holAssert true s = ({((), s)}, false) from by simp [holAssert])] + have hupdate : KHeap_A.update_sk_obj_ref Structures_A.kernel_object.Reply Structures_A.reply.reply_tcb_update + 0x5000 none s = ({((), t)}, false) := by + unfold KHeap_A.update_sk_obj_ref + rw [hol_bind_singleton_at _ h] + exact setReplyRun s 0x5000 linkedWitnessReply unlinkedWitnessReply rfl + simp only [holKBind] + rw [hol_bind_singleton_at _ hupdate] + apply setOtherThreadStateRun t 0x2000 replyWitnessReceiver .Inactive + · simp [t, replyUnlinkedState, holFunUpd, Function.update, replyWitnessState] + · change (0x2000 : Word) ≠ 0x1000 + decide + have ha : holAssert (holEq linkedWitnessReply.reply_tcb (some 0x2000)) s = ({((), s)}, false) := by + simp [holAssert, holEq, linkedWitnessReply] + unfold IpcCancel_A.reply_remove + rw [hol_bind_singleton_at _ h, hol_bind_singleton_at _ ha] + simp only [holKBind, holFunApp] + rw [hol_bind_singleton_at _ (show holGets (IpcCancel_A.sc_with_reply 0x5000) s = + ({(none, s)}, false) by rw [← hsc]; rfl)] + rw [holCaseOption, KHeap.holBind_return_left] + exact hlink + +private def replyClearedTcb : Structures_A.tcb := { replyInactiveTcb with tcb_fault := none } +private def replyClearedState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := replyInactiveState rH + { s with kheap := holFunUpd s.kheap 0x2000 (some (.TCB replyClearedTcb)) } +private def replyResumedTcb : Structures_A.tcb := { replyClearedTcb with tcb_state := .Restart } +private def replyResumedState (rH : MachineTypes.machine_state_rest) : Structures_A.state Unit := + let s := replyClearedState rH + { s with kheap := holFunUpd s.kheap 0x2000 (some (.TCB replyResumedTcb)) } + +private theorem replyMessageInfoRun (rH : MachineTypes.machine_state_rest) : + let s := replyInactiveState rH + Ipc_A.get_message_info 0x1000 s = ({(Structures_A.data_to_message_info 0, s)}, false) := by + dsimp only + let s := replyInactiveState rH + have hheap : s.kheap 0x1000 = some (.TCB replyWitnessSender) := by + simp [s, replyInactiveState, replyUnlinkedState, replyWitnessState, holFunUpd, Function.update] + have hset : KHeap_A.set_object 0x1000 (.TCB replyWitnessSender) s = ({((), s)}, false) := by + rw [setObjectRunH s 0x1000 (.TCB replyWitnessSender) (.TCB replyWitnessSender) hheap rfl] + rw [← hheap, heapUpdate_current] + have hreg : KHeap_A.as_user 0x1000 (MachineOps.getRegister Machine_A.msg_info_register) s = + ({((0 : Word), s)}, false) := by + unfold KHeap_A.as_user holFunApp + rw [hol_bind_singleton_at _ (getTcbRun s 0x1000 replyWitnessSender hheap)] + have hread : MachineOps.getRegister Machine_A.msg_info_register + (Arch_Structs_A.arch_tcb_context_get replyWitnessSender.tcb_arch) = + ({(0, replyWitnessSender.tcb_arch.tcb_context)}, false) := rfl + have hsetArch : Structures_A.tcb.tcb_arch_update + (fun _ => Arch_Structs_A.arch_tcb_context_set replyWitnessSender.tcb_arch.tcb_context + replyWitnessSender.tcb_arch) replyWitnessSender = replyWitnessSender := rfl + have hset' : KHeap_A.set_object 4096#64 (.TCB replyWitnessSender) s = ({((), s)}, false) := hset + simp [holBind, holReturn, holSelectF, holCaseProd, hread, hsetArch, hset', holKBind] + unfold Ipc_A.get_message_info holFunApp + rw [hol_bind_singleton_at _ hreg] + rfl + +private theorem replyFaultBodyRun (rH : MachineTypes.machine_state_rest) : + let s := replyInactiveState rH + holBind (Ipc_A.get_message_info 0x1000) (fun mi => + holBind (Patched.lookupIpcBuffer false 0x1000) fun buf => + holBind (Tcb_A.get_mrs 0x1000 buf mi) fun mrs => + holBind (Ipc_A.handle_fault_reply replyWitnessFault 0x2000 mi.mi_label mrs) fun restart => + holBind (KHeap_A.thread_set (Structures_A.tcb.tcb_fault_update fun _ => none) 0x2000) + (holKBind (KHeap_A.set_thread_state 0x2000 (if restart then .Restart else .Inactive)))) + s = ({((), replyResumedState rH)}, false) := by + dsimp only + let s := replyInactiveState rH + have hsend : s.kheap 0x1000 = some (.TCB replyWitnessSender) := by + simp [s, replyInactiveState, replyUnlinkedState, replyWitnessState, holFunUpd, Function.update] + have hrecv : s.kheap 0x2000 = some (.TCB replyInactiveTcb) := by + simp [s, replyInactiveState, holFunUpd] + have hbuf : Patched.lookupIpcBuffer false 0x1000 s = ({(none, s)}, false) := by + unfold Patched.lookupIpcBuffer Patched.lookupIpcBufferAt + rw [hol_bind_singleton_at _ (tcbReadRunH s 0x1000 replyWitnessSender Structures_A.tcb_ext.tcb_ipc_buffer hsend), + KHeap.holBind_return_left] + have hslot : CSpaceAcc_A.get_cap (0x1000, Structures_A.tcb_cnode_index 2) s = ({(.NullCap, s)}, false) := by + have hobj : KHeap_A.get_object 0x1000 s = ({(.TCB replyWitnessSender, s)}, false) := by + change holAssertOpt (s.kheap 0x1000) s = _ + rw [hsend] + rfl + unfold CSpaceAcc_A.get_cap + simp only [holCaseProd_eq] + rw [hol_bind_singleton_at _ hobj] + have hmap : Structures_A.tcb_cnode_map replyWitnessSender (Fl4Spec.tcbCnodeIndex 2) = some .NullCap := by + have h23 : Fl4Spec.tcbCnodeIndex 2 ≠ Structures_A.tcb_cnode_index 3 := by + rw [← Structures.tcbCnodeIndex_eq 3]; decide + have h24 : Fl4Spec.tcbCnodeIndex 2 ≠ Structures_A.tcb_cnode_index 4 := by + rw [← Structures.tcbCnodeIndex_eq 4]; decide + simp [Structures_A.tcb_cnode_map, holFunUpd, HolNumeral.ofNatVal, h23, h24, + ← Structures.tcbCnodeIndex_eq 2, replyWitnessSender, mkTcb] + have hmap' : Structures_A.tcb_cnode_map replyWitnessSender (Structures_A.tcb_cnode_index 2) = some .NullCap := + Structures.tcbCnodeIndex_eq 2 ▸ hmap + simp [Structures_A.case_kernel_object, holBind, holReturn, holAssertOpt, hmap'] + rw [hol_bind_singleton_at _ hslot] + rfl + have hmrs : Tcb_A.get_mrs 0x1000 none (Structures_A.data_to_message_info 0) s = ({([], s)}, false) := by + unfold Tcb_A.get_mrs + rw [hol_bind_singleton_at _ (tcbReadRunH s 0x1000 replyWitnessSender _ hsend)] + simp only [holCaseOption, KHeap.holBind_return_left] + have hlen : (Structures_A.data_to_message_info 0).mi_length = 0 := by + change holIf (holLt (120 : Word) 0) 120 0 = 0 + have hfalse : holLt (120 : Word) 0 = false := + Bool.eq_false_iff.mpr (mt (holLt_eq_true _ _).mp (by + change ¬ ((120 : Word) < 0) + decide)) + rw [hfalse, holIf_false] + rw [hlen] + rfl + rw [hol_bind_singleton_at _ (replyMessageInfoRun rH), hol_bind_singleton_at _ hbuf, + hol_bind_singleton_at _ hmrs] + have hf : Ipc_A.handle_fault_reply replyWitnessFault 0x2000 + (Structures_A.data_to_message_info 0).mi_label [] s = ({(true, s)}, false) := rfl + rw [hol_bind_singleton_at _ hf, hol_bind_singleton_at _ (threadSetRun s 0x2000 replyInactiveTcb _ hrecv)] + apply setOtherThreadStateRun (replyClearedState rH) 0x2000 replyClearedTcb .Restart + · simp [replyClearedState, holFunUpd] + · change (0x2000 : Word) ≠ 0x1000 + decide + +/-- A linked capability-fault reply removes the reply object link, clears the fault, and restarts the caller. -/ +theorem liveLinkedFaultReplyWitness + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + (hop : OpaqueRel RestRel) (rH : MachineTypes.machine_state_rest) + (rL : MachineStateRest) (hr : RestRel rH rL) : + let s := replyWitnessState rH + let runH := Ipc.do_reply_transfer_p 0x1000 0x5000 false s + let runL := Fl4Spec.doReplyTransfer 0x1000 0x5000 false (leanState s rL) + ∃ outH outL, runH = ({((), outH)}, false) ∧ ((), outL) ∈ runL.1 ∧ ¬runL.2 ∧ + StateRel RestRel Eq outH outL ∧ + outL.kheap 0x5000 = some (.reply (embReply unlinkedWitnessReply)) ∧ + outL.kheap 0x2000 = some (.tcb (embTcb replyResumedTcb)) := by + dsimp only + let s := replyWitnessState rH + let t := replyInactiveState rH + let out := replyResumedState rH + have hrecv : t.kheap 0x2000 = some (.TCB replyInactiveTcb) := by simp [t, replyInactiveState, holFunUpd] + have hcaller : KHeap_A.get_thread_state 0x2000 s = ({(.BlockedOnReply 0x5000, s)}, false) := + tcbReadRunH s 0x2000 replyWitnessReceiver Structures_A.tcb_ext.tcb_state rfl + have hsc : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context 0x2000 t = ({(none, t)}, false) := + tcbReadRunH t 0x2000 replyInactiveTcb Structures_A.tcb_ext.tcb_sched_context hrecv + have hfault : KHeap_A.thread_get Structures_A.tcb_ext.tcb_fault 0x2000 t = ({(some replyWitnessFault, t)}, false) := + tcbReadRunH t 0x2000 replyInactiveTcb Structures_A.tcb_ext.tcb_fault hrecv + have hrefill : Sporadic_A.if_cond_refill_unblock_check none (some false) (some false) t = ({((), t)}, false) := rfl + have hfinal : out.kheap 0x2000 = some (.TCB replyResumedTcb) := by simp [out, replyResumedState, holFunUpd] + have hscOut : KHeap_A.get_tcb_obj_ref Structures_A.tcb_ext.tcb_sched_context 0x2000 out = ({(none, out)}, false) := + tcbReadRunH out 0x2000 replyResumedTcb Structures_A.tcb_ext.tcb_sched_context hfinal + have hstateOut : KHeap_A.get_thread_state 0x2000 out = ({(.Restart, out)}, false) := + tcbReadRunH out 0x2000 replyResumedTcb Structures_A.tcb_ext.tcb_state hfinal + have hsafe : Ipc.DoReplyTransferSafe 0x1000 0x5000 false s := by + intro receiver s1 hm s2 h2 s4 h4 scOpt s5 h5 s6 h6 fault s7 h7 + rw [replyReadRun rH] at hm + have he := Prod.mk.inj (Set.mem_singleton_iff.mp hm) + have hrec := Option.some.inj he.1 + have hs1 := he.2 + subst receiver s1 + rw [hcaller] at h2 + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp h2)).2 + subst s2 + rw [replyRemoveRun rH] at h4 + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp h4)).2 + subst s4 + rw [hsc] at h5 + obtain ⟨rfl, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp h5) + rw [hrefill] at h6 + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp h6)).2 + subst s6 + rw [hfault] at h7 + obtain ⟨rfl, rfl⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp h7) + refine ⟨(fun he => by cases he), ?_⟩ + intro st hm sc after hscAfter + dsimp only at hm + rw [replyFaultBodyRun rH] at hm + have he := (Prod.mk.inj (Set.mem_singleton_iff.mp hm)).2 + subst st + rw [hscOut] at hscAfter + cases (Prod.mk.inj (Set.mem_singleton_iff.mp hscAfter)).1 + have hrel := Ipc.patched_doReplyTransfer_equiv hop 0x1000 0x5000 false (leanState_related s rL hr) hsafe + have hrun : Ipc.do_reply_transfer_p 0x1000 0x5000 false s = ({((), out)}, false) := by + unfold Ipc.do_reply_transfer_p + rw [hol_bind_singleton_at _ (replyReadRun rH)] + simp only [holMaybeM] + rw [hol_bind_singleton_at _ hcaller] + dsimp only + have ha : holAssert (holEq (0x5000 : Word) 0x5000) s = ({((), s)}, false) := by simp [holAssert, holEq] + rw [hol_bind_singleton_at _ ha] + simp only [holKBind] + rw [hol_bind_singleton_at _ (replyRemoveRun rH)] + simp only [holKBind] + rw [hol_bind_singleton_at _ hsc, hol_bind_singleton_at _ hrefill] + simp only [holKBind] + rw [hol_bind_singleton_at _ hfault] + dsimp only + rw [hol_bind_singleton_at _ (replyFaultBodyRun rH)] + simp only [holKBind] + rw [hol_bind_singleton_at _ hscOut, hol_bind_singleton_at _ hstateOut] + simp [holWhen, holConj, holNot, holEq, holReturn] + obtain ⟨_, outL, hm, rfl, hpost, hf⟩ := relatedSuccessfulRun hrel hrun + refine ⟨out, outL, hrun, hm, hf, hpost, ?_, ?_⟩ + · rw [hpost.kheap_eq] + simp [out, replyResumedState, replyClearedState, replyInactiveState, replyUnlinkedState, + holFunUpd, Function.update, embKernelObject] + · rw [hpost.kheap_eq, hfinal] + rfl + + +end + +end L4vRefX64.Equiv.Witness diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Manifest.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Manifest.lean new file mode 100644 index 000000000..40fa5e32a --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Manifest.lean @@ -0,0 +1,1157 @@ +import L4vRefX64.Spec +import L4vRefX64.Equiv.ArchCap +import L4vRefX64.Equiv.ArchDecode +import L4vRefX64.Equiv.ArchInvoke +import L4vRefX64.Equiv.ArchSwitch +import L4vRefX64.Equiv.ArchVSpace +import L4vRefX64.Equiv.CSpace +import L4vRefX64.Equiv.CSpaceAcc +import L4vRefX64.Equiv.Decode +import L4vRefX64.Equiv.Deterministic +import L4vRefX64.Equiv.Fpu +import L4vRefX64.Equiv.Hardware +import L4vRefX64.Equiv.Interrupt +import L4vRefX64.Equiv.InvocationDecode +import L4vRefX64.Equiv.Ipc +import L4vRefX64.Equiv.IpcCancel +import L4vRefX64.Equiv.KHeap +import L4vRefX64.Equiv.Machine +import L4vRefX64.Equiv.Retype +import L4vRefX64.Equiv.SchedContext +import L4vRefX64.Equiv.Schedule +import L4vRefX64.Equiv.Structures +import L4vRefX64.Equiv.Syscall +import L4vRefX64.Equiv.Tcb +import L4vRefX64.Equiv.TcbAcc +import L4vRefX64.Equiv.Types +import L4vRefX64.Equiv.VSpaceAccess +import L4vRefX64.Equiv.VSpaceRoot +import L4vRefX64.Equiv.VSpaceUnmap +import L4vRefX64.Equiv.Witness +import L4vRefX64.Patched +import L4vRefX64.Rel.Config +import L4vRefX64.Rel.Embed +import L4vRefX64.Rel.Extension +import L4vRefX64.Rel.Invocation +import L4vRefX64.Rel.Lift +import L4vRefX64.Rel.Monad +import L4vRefX64.Rel.State + +/-! Axiom audit for the public X64 correspondence and witness theorems. -/ + +-- L4vRefX64.Equiv.ArchCap +#print axioms L4vRefX64.Equiv.ArchCap.archIsPhysical_eq +#print axioms L4vRefX64.Equiv.ArchCap.updateCnodeCapData_eq +#print axioms L4vRefX64.Equiv.ArchCap.archSameRegionAs_iff +#print axioms L4vRefX64.Equiv.ArchCap.sameAobjectAs_iff +#print axioms L4vRefX64.Equiv.ArchCap.archIsCapRevocable_iff +#print axioms L4vRefX64.Equiv.ArchCap.archCapCleanupOpt_eq +#print axioms L4vRefX64.Equiv.ArchCap.archGenObjRefs_eq +#print axioms L4vRefX64.Equiv.ArchCap.archDeriveCap_equiv +#print axioms L4vRefX64.Equiv.ArchCap.setIoportMask_equiv +#print axioms L4vRefX64.Equiv.ArchCap.archPostCapDeletion_equiv + +-- L4vRefX64.Equiv.ArchDecode +#print axioms L4vRefX64.Equiv.ArchDecode.attribsFromWord_eq +#print axioms L4vRefX64.Equiv.ArchDecode.filterVmAttributes_eq +#print axioms L4vRefX64.Equiv.ArchDecode.patched_decodePageTableInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.patched_decodePageDirectoryInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.patched_decodePdptInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.attrMask_eq +#print axioms L4vRefX64.Equiv.ArchDecode.attrMaskPat_eq +#print axioms L4vRefX64.Equiv.ArchDecode.checkVpAlignment_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.ensureSafeMapping_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.patched_createMappingEntries_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.patched_decodeAsidPoolInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.patched_decodeAsidControlInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.patched_decodePageInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchDecode.patched_archDecodeInvocation_equiv + +-- L4vRefX64.Equiv.ArchInvoke +#print axioms L4vRefX64.Equiv.ArchInvoke.performIoPortInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performIoportControlInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.storeAsidPoolEntry_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performAsidPoolInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performAsidControlInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPageMap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPageTableMap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPageDirectoryMap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPdptMap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPageInvocationUnmap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPageTableUnmap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPageDirectoryUnmap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPdptUnmap_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_performPageInvocation_equiv +#print axioms L4vRefX64.Equiv.ArchInvoke.patched_archPerformInvocation_equiv + +-- L4vRefX64.Equiv.ArchSwitch +#print axioms L4vRefX64.Equiv.ArchSwitch.archSwitchToThread_equiv +#print axioms L4vRefX64.Equiv.ArchSwitch.archSwitchToIdleThread_equiv +#print axioms L4vRefX64.Equiv.ArchSwitch.archPrepareNextDomain_equiv +#print axioms L4vRefX64.Equiv.ArchSwitch.archActivateIdleThread_equiv + +-- L4vRefX64.Equiv.ArchVSpace +#print axioms L4vRefX64.Equiv.ArchVSpace.inUserFrame_iff +#print axioms L4vRefX64.Equiv.ArchVSpace.patched_lookupIpcBuffer_equiv +#print axioms L4vRefX64.Equiv.ArchVSpace.checkValidIpcBuffer_equiv + +-- L4vRefX64.Equiv.CSpace +#print axioms L4vRefX64.Equiv.CSpace.acapRightsUpdate_eq +#print axioms L4vRefX64.Equiv.CSpace.capRightsUpdate_eq +#print axioms L4vRefX64.Equiv.CSpace.maskCap_eq +#print axioms L4vRefX64.Equiv.CSpace.dataToRights_eq +#print axioms L4vRefX64.Equiv.CSpace.maxFreeIndex_eq +#print axioms L4vRefX64.Equiv.CSpace.isUntypedCap_eq +#print axioms L4vRefX64.Equiv.CSpace.freeIndexUpdate_eq +#print axioms L4vRefX64.Equiv.CSpace.untypedSzBits_eq +#print axioms L4vRefX64.Equiv.CSpace.maxFreeIndexUpdate_eq +#print axioms L4vRefX64.Equiv.CSpace.isEpCap_eq +#print axioms L4vRefX64.Equiv.CSpace.isNtfnCap_eq +#print axioms L4vRefX64.Equiv.CSpace.updateCapData_eq +#print axioms L4vRefX64.Equiv.CSpace.longRunningDelete_eq +#print axioms L4vRefX64.Equiv.CSpace.locateSlot_eq +#print axioms L4vRefX64.Equiv.CSpace.canFastFinalise_eq +#print axioms L4vRefX64.Equiv.CSpace.capRemoveable_iff_nullOrZombie +#print axioms L4vRefX64.Equiv.CSpace.capCyclicZombie_iff +#print axioms L4vRefX64.Equiv.CSpace.exposedRdcall_eq +#print axioms L4vRefX64.Equiv.CSpace.isCTEDeleteCall_eq +#print axioms L4vRefX64.Equiv.CSpace.slotRdcall_eq +#print axioms L4vRefX64.Equiv.CSpace.getBadge_eq +#print axioms L4vRefX64.Equiv.CSpace.isPhysical_eq +#print axioms L4vRefX64.Equiv.CSpace.archObjSize_eq +#print axioms L4vRefX64.Equiv.CSpace.objSize_eq_nonNtfn +#print axioms L4vRefX64.Equiv.CSpace.objSize_ntfn_delta +#print axioms L4vRefX64.Equiv.CSpace.isThreadCap_eq +#print axioms L4vRefX64.Equiv.CSpace.isSchedContextCap_eq +#print axioms L4vRefX64.Equiv.CSpace.sameRegionAs_iff_nonNtfn +#print axioms L4vRefX64.Equiv.CSpace.patched_objSize_eq +#print axioms L4vRefX64.Equiv.CSpace.patched_sameRegionAs_iff +#print axioms L4vRefX64.Equiv.CSpace.sameObjectAs_iff +#print axioms L4vRefX64.Equiv.CSpace.shouldBeParentOf_iff_nonNtfn +#print axioms L4vRefX64.Equiv.CSpace.patched_shouldBeParentOf_iff +#print axioms L4vRefX64.Equiv.CSpace.isCapRevocable_iff +#print axioms L4vRefX64.Equiv.CSpace.hasCancelSendRights_iff +#print axioms L4vRefX64.Equiv.CSpace.objRefs_eq +#print axioms L4vRefX64.Equiv.CSpace.embGenObjRef_injective +#print axioms L4vRefX64.Equiv.CSpace.archCapSetMap_eq +#print axioms L4vRefX64.Equiv.CSpace.genObjRefs_eq +#print axioms L4vRefX64.Equiv.CSpace.genObjRefs_nullCap +#print axioms L4vRefX64.Equiv.CSpace.ensureNoChildren_equiv +#print axioms L4vRefX64.Equiv.CSpace.setUntypedCapAsFull_equiv_nonExt +#print axioms L4vRefX64.Equiv.CSpace.deriveCap_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_getCap_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_setCap_equiv_at +#print axioms L4vRefX64.Equiv.CSpace.holTheDefault_of_existsUnique +#print axioms L4vRefX64.Equiv.CSpace.holTheDefault_eq_of_iff +#print axioms L4vRefX64.Equiv.CSpace.holBindE_returnOk_left +#print axioms L4vRefX64.Equiv.CSpace.holBindE_congr_at +#print axioms L4vRefX64.Equiv.CSpace.getCap_state_eq +#print axioms L4vRefX64.Equiv.CSpace.resolveAddressBits'_graph_iff +#print axioms L4vRefX64.Equiv.CSpace.resolveAddressBits_eq_rec +#print axioms L4vRefX64.Equiv.CSpace.mrele_fail_liftE +#print axioms L4vRefX64.Equiv.CSpace.patched_resolveAddressBits'_equiv +#print axioms L4vRefX64.Equiv.CSpace.getCap_eq_patched_of_not_tcb +#print axioms L4vRefX64.Equiv.CSpace.patched_lookupSlotForThread_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_lookupCapAndSlot_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_lookupCap_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_lookupSlotForCnodeOp_equiv +#print axioms L4vRefX64.Equiv.CSpace.captransferFromWords_equiv +#print axioms L4vRefX64.Equiv.CSpace.loadCapTransfer_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_getReceiveSlots_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_setUntypedCapAsFull_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_capInsert_equiv +#print axioms L4vRefX64.Equiv.CSpace.isFinalCap'_iff +#print axioms L4vRefX64.Equiv.CSpace.isFinalCap_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_slotCapLongRunningDelete_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_capSwap_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_capMove_equiv +#print axioms L4vRefX64.Equiv.CSpace.postCapDeletion_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_setCap_equiv_null +#print axioms L4vRefX64.Equiv.CSpace.patched_emptySlot_equiv +#print axioms L4vRefX64.Equiv.CSpace.fastFinalise_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_capDeleteOne_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_deletingIrqHandler_equiv +#print axioms L4vRefX64.Equiv.CSpace.archFinaliseCap_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_finaliseCap_equiv +#print axioms L4vRefX64.Equiv.CSpace.patched_capSwapForDelete_equiv +#print axioms L4vRefX64.Equiv.CSpace.nonDet_lfp_unfold +#print axioms L4vRefX64.Equiv.CSpace.recDelF_mono +#print axioms L4vRefX64.Equiv.CSpace.recDel_unfold +#print axioms L4vRefX64.Equiv.CSpace.capRevokeF_mono +#print axioms L4vRefX64.Equiv.CSpace.capRevoke_unfold +#print axioms L4vRefX64.Equiv.CSpace.firstCslotOf_eq +#print axioms L4vRefX64.Equiv.CSpace.recDelPGraph_mrelStep +#print axioms L4vRefX64.Equiv.CSpace.patched_recDel_equiv_on_dom +#print axioms L4vRefX64.Equiv.CSpace.patched_capDelete_equiv_on_dom +#print axioms L4vRefX64.Equiv.CSpace.patched_finaliseSlot_equiv_on_dom +#print axioms L4vRefX64.Equiv.CSpace.capRevokePGraph_mrelStep +#print axioms L4vRefX64.Equiv.CSpace.patched_capRevoke_equiv_on_dom +#print axioms L4vRefX64.Equiv.CSpace.patched_invokeCnode_equiv + +-- L4vRefX64.Equiv.CSpaceAcc +#print axioms L4vRefX64.Equiv.CSpaceAcc.isCdtParent_iff +#print axioms L4vRefX64.Equiv.CSpaceAcc.cdtParentRel_eq +#print axioms L4vRefX64.Equiv.CSpaceAcc.parentOf_iff +#print axioms L4vRefX64.Equiv.CSpaceAcc.parentOfTrancl_iff +#print axioms L4vRefX64.Equiv.CSpaceAcc.parentOfRtrancl_iff +#print axioms L4vRefX64.Equiv.CSpaceAcc.descendantsOf_eq +#print axioms L4vRefX64.Equiv.CSpaceAcc.canMergeRefill_iff +#print axioms L4vRefX64.Equiv.CSpaceAcc.mergeRefill_eq +#print axioms L4vRefX64.Equiv.CSpaceAcc.getCap_equiv_nonExt +#print axioms L4vRefX64.Equiv.CSpaceAcc.getCap_member_heap +#print axioms L4vRefX64.Equiv.CSpaceAcc.setCap_equiv_nonExt +#print axioms L4vRefX64.Equiv.CSpaceAcc.ensureEmpty_equiv_nonExt +#print axioms L4vRefX64.Equiv.CSpaceAcc.setCdt_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.updateCdt_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.setOriginal_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.isRoundRobin_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.refillPopHead_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.refillHeadOverlapping_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.updateRefillHd_equiv_nonEmpty +#print axioms L4vRefX64.Equiv.CSpaceAcc.mergeOverlappingRefills_equiv_two +#print axioms L4vRefX64.Equiv.CSpaceAcc.refillHeadOverlappingLoop_equiv_nonEmpty +#print axioms L4vRefX64.Equiv.CSpaceAcc.refillUnblockCheck_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.ifCondRefillUnblockCheck_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.ifSporadicCurScAssertRefillUnblockCheck_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.ifSporadicAndActiveRefillUnblockCheck_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.ifSporadicCurScTestRefillUnblockCheck_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.ifSporadicActiveCurScTestRefillUnblockCheck_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.ifSporadicActiveCurScAssertRefillUnblockCheck_equiv +#print axioms L4vRefX64.Equiv.CSpaceAcc.ifConstantBandwidthRefillUnblockCheck_equiv + +-- L4vRefX64.Equiv.Decode +#print axioms L4vRefX64.Equiv.Decode.genInvocationType_eq +#print axioms L4vRefX64.Equiv.Decode.the_getElem_map +#print axioms L4vRefX64.Equiv.Decode.genInvocationLabels_fromEnum_eq +#print axioms L4vRefX64.Equiv.Decode.genInvocationLabels_uptoEnum_eq +#print axioms L4vRefX64.Equiv.Decode.mem_uptoEnum_genInvocationLabels_iff +#print axioms L4vRefX64.Equiv.Decode.patched_ensureEmpty_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_lookupTargetSlot_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_lookupSourceSlot_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_lookupPivotSlot_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeCnodeInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.mrele_kbindE_whenE_throw' +#print axioms L4vRefX64.Equiv.Decode.parseTimeArg_eq +#print axioms L4vRefX64.Equiv.Decode.parseTimeArgA_eq +#print axioms L4vRefX64.Equiv.Decode.decodeDomainSet_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeDomainScheduleSetStart_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeDomainScheduleConfigure_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeDomainInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSchedContextBind_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSchedContextUnbindObject_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSchedContextYieldTo_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSchedContextInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSchedControlInvocationFlags_equiv +#print axioms L4vRefX64.Equiv.Decode.alignUp_eq +#print axioms L4vRefX64.Equiv.Decode.archDataToObjType_equiv_base +#print axioms L4vRefX64.Equiv.Decode.dataToObjType_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeUntypedInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.archInvocationLabel_iff +#print axioms L4vRefX64.Equiv.Decode.patched_archDecodeIrqControlInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeIrqControlInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeIrqHandlerInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeReadRegisters_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeCopyRegisters_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeWriteRegisters_equiv +#print axioms L4vRefX64.Equiv.Decode.checkPrio_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSetPriority_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSetMcpriority_equiv +#print axioms L4vRefX64.Equiv.Decode.hasHandlerRights_iff +#print axioms L4vRefX64.Equiv.Decode.validFaultHandler_iff +#print axioms L4vRefX64.Equiv.Decode.decodeSetIpcBuffer_equiv +#print axioms L4vRefX64.Equiv.Decode.checkHandlerEp_equiv +#print axioms L4vRefX64.Equiv.Decode.wordToTcbFlags_eq +#print axioms L4vRefX64.Equiv.Decode.patched_decodeCvSpace_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeSetSpace_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeUpdateSc_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeTcbConfigure_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSetTimeoutEp_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeBindNotification_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeUnbindNotification_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSetTlsBase_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSetFlags_equiv +#print axioms L4vRefX64.Equiv.Decode.decodeSetSchedParams_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeTcbInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.ensurePortOperationAllowed_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodePortInvocation_equiv +#print axioms L4vRefX64.Equiv.Decode.isIoportRangeFree_equiv +#print axioms L4vRefX64.Equiv.Decode.patched_decodeIoportControlInvocation_equiv + +-- L4vRefX64.Equiv.Deterministic +#print axioms L4vRefX64.Equiv.Deterministic.listReplace_eq +#print axioms L4vRefX64.Equiv.Deterministic.listReplaceList_eq +#print axioms L4vRefX64.Equiv.Deterministic.listSwap_eq +#print axioms L4vRefX64.Equiv.Deterministic.listInsertAfter_eq +#print axioms L4vRefX64.Equiv.Deterministic.listRemove_eq +#print axioms L4vRefX64.Equiv.Deterministic.afterInList_eq +#print axioms L4vRefX64.Equiv.Deterministic.workUnitsLimit_eq +#print axioms L4vRefX64.Equiv.Deterministic.transState_rel +#print axioms L4vRefX64.Equiv.Deterministic.truncateState_rel +#print axioms L4vRefX64.Equiv.Deterministic.workUnitsCompleted_eq +#print axioms L4vRefX64.Equiv.Deterministic.cdtList_eq +#print axioms L4vRefX64.Equiv.Deterministic.nextChild_eq +#print axioms L4vRefX64.Equiv.Deterministic.nextSib_eq +#print axioms L4vRefX64.Equiv.Deterministic.holLfp_rel_eq_true +#print axioms L4vRefX64.Equiv.Deterministic.next_not_child_graph_iff +#print axioms L4vRefX64.Equiv.Deterministic.nextNotChildGraph_unique +#print axioms L4vRefX64.Equiv.Deterministic.nextNotChild_eq_on_dom +#print axioms L4vRefX64.Equiv.Deterministic.nextSlot_eq_on_dom +#print axioms L4vRefX64.Equiv.Deterministic.nextRevokeCap_eq_on_some +#print axioms L4vRefX64.Equiv.Deterministic.validList2_iff +#print axioms L4vRefX64.Equiv.Deterministic.validList_iff +#print axioms L4vRefX64.Equiv.Deterministic.setCdtList_equiv +#print axioms L4vRefX64.Equiv.Deterministic.updateCdtList_equiv +#print axioms L4vRefX64.Equiv.Deterministic.capSwapExt_equiv +#print axioms L4vRefX64.Equiv.Deterministic.capMoveExt_equiv +#print axioms L4vRefX64.Equiv.Deterministic.capInsertExt_equiv +#print axioms L4vRefX64.Equiv.Deterministic.emptySlotExt_equiv +#print axioms L4vRefX64.Equiv.Deterministic.createCapExt_equiv +#print axioms L4vRefX64.Equiv.Deterministic.updateWorkUnits_equiv +#print axioms L4vRefX64.Equiv.Deterministic.resetWorkUnits_equiv +#print axioms L4vRefX64.Equiv.Deterministic.workUnitsLimitReached_equiv +#print axioms L4vRefX64.Equiv.Deterministic.mrel_selectF_mkEf +#print axioms L4vRefX64.Equiv.Deterministic.orChoice_equiv +#print axioms L4vRefX64.Equiv.Deterministic.orChoiceE_equiv +#print axioms L4vRefX64.Equiv.Deterministic.doExtendedOp_equiv +#print axioms L4vRefX64.Equiv.Deterministic.selectExt_equiv +#print axioms L4vRefX64.Equiv.Deterministic.withoutPreemption_equiv +#print axioms L4vRefX64.Equiv.Deterministic.capFaultOnFailure_equiv +#print axioms L4vRefX64.Equiv.Deterministic.lookupErrorOnFailure_equiv +#print axioms L4vRefX64.Equiv.Deterministic.nullCapOnFailure_equiv +#print axioms L4vRefX64.Equiv.Deterministic.unifyFailure_equiv +#print axioms L4vRefX64.Equiv.Deterministic.emptyOnFailure_equiv +#print axioms L4vRefX64.Equiv.Deterministic.constOnFailure_equiv +#print axioms L4vRefX64.Equiv.Deterministic.rangeCheck_equiv + +-- L4vRefX64.Equiv.Fpu +#print axioms L4vRefX64.Equiv.Fpu.saveFpuState_equiv +#print axioms L4vRefX64.Equiv.Fpu.loadFpuState_equiv +#print axioms L4vRefX64.Equiv.Fpu.setX64CurrentFpuOwner_equiv +#print axioms L4vRefX64.Equiv.Fpu.switchLocalFpuOwner_equiv +#print axioms L4vRefX64.Equiv.Fpu.fpuRelease_equiv +#print axioms L4vRefX64.Equiv.Fpu.lazyFpuRestore_equiv + +-- L4vRefX64.Equiv.Hardware +#print axioms L4vRefX64.Equiv.Hardware.setDeadline_equiv +#print axioms L4vRefX64.Equiv.Hardware.invalidateASID_equiv +#print axioms L4vRefX64.Equiv.Hardware.invalidateLocalPageStructureCacheASID_equiv +#print axioms L4vRefX64.Equiv.Hardware.invalidateTranslationSingleASID_equiv +#print axioms L4vRefX64.Equiv.Hardware.ioapicMapPinToVector_equiv +#print axioms L4vRefX64.Equiv.Hardware.out8_equiv +#print axioms L4vRefX64.Equiv.Hardware.out16_equiv +#print axioms L4vRefX64.Equiv.Hardware.out32_equiv +#print axioms L4vRefX64.Equiv.Hardware.in8_equiv +#print axioms L4vRefX64.Equiv.Hardware.in16_equiv +#print axioms L4vRefX64.Equiv.Hardware.in32_equiv +#print axioms L4vRefX64.Equiv.Hardware.getFaultAddress_equiv +#print axioms L4vRefX64.Equiv.Hardware.enableFpu_equiv +#print axioms L4vRefX64.Equiv.Hardware.disableFpu_equiv +#print axioms L4vRefX64.Equiv.Hardware.readFpuState_equiv +#print axioms L4vRefX64.Equiv.Hardware.writeFpuState_equiv + +-- L4vRefX64.Equiv.Interrupt +#print axioms L4vRefX64.Equiv.Interrupt.ackInterrupt_equiv +#print axioms L4vRefX64.Equiv.Interrupt.ackDeadlineIRQ_equiv +#print axioms L4vRefX64.Equiv.Interrupt.archMaskIrqSignal_equiv +#print axioms L4vRefX64.Equiv.Interrupt.handleReservedIrq_equiv +#print axioms L4vRefX64.Equiv.Interrupt.handleSpuriousIrq_equiv +#print axioms L4vRefX64.Equiv.Interrupt.handleInterrupt_equiv +#print axioms L4vRefX64.Equiv.Interrupt.maybeHandleInterrupt_equiv +#print axioms L4vRefX64.Equiv.Interrupt.patched_invokeIrqHandler_equiv +#print axioms L4vRefX64.Equiv.Interrupt.patched_invokeIrqControl_equiv + +-- L4vRefX64.Equiv.InvocationDecode +#print axioms L4vRefX64.Equiv.InvocationDecode.patched_decodeInvocation_equiv + +-- L4vRefX64.Equiv.Ipc +#print axioms L4vRefX64.Equiv.Ipc.bufferCptrIndex_eq +#print axioms L4vRefX64.Equiv.Ipc.isActive_eq +#print axioms L4vRefX64.Equiv.Ipc.isTimeoutFault_eq +#print axioms L4vRefX64.Equiv.Ipc.receiveBlocked_eq +#print axioms L4vRefX64.Equiv.Ipc.sendIpcBlocked_equiv +#print axioms L4vRefX64.Equiv.Ipc.completeSignal_equiv +#print axioms L4vRefX64.Equiv.Ipc.doNbrecvFailedTransfer_equiv +#print axioms L4vRefX64.Equiv.Ipc.receiveIpcBlocked_equiv +#print axioms L4vRefX64.Equiv.Ipc.updateWaitingNtfn_equiv +#print axioms L4vRefX64.Equiv.Ipc.sendSignal_equiv +#print axioms L4vRefX64.Equiv.Ipc.receiveSignalBlocked_equiv +#print axioms L4vRefX64.Equiv.Ipc.receiveSignal_equiv +#print axioms L4vRefX64.Equiv.Ipc.refillResetRr_equiv +#print axioms L4vRefX64.Equiv.Ipc.schedulable_implies_tcb +#print axioms L4vRefX64.Equiv.Ipc.checkBudget_run_sufficient +#print axioms L4vRefX64.Equiv.Ipc.checkBudgetRestart_equiv_sufficient +#print axioms L4vRefX64.Equiv.Ipc.isValidTimeoutHandler_equiv +#print axioms L4vRefX64.Equiv.Ipc.endTimeslice_equiv_without_timeout +#print axioms L4vRefX64.Equiv.Ipc.chargeBudget_equiv_without_timeout +#print axioms L4vRefX64.Equiv.Ipc.getMessageInfo_equiv +#print axioms L4vRefX64.Equiv.Ipc.getExtraCptrs_equiv +#print axioms L4vRefX64.Equiv.Ipc.getExtraCptr_equiv +#print axioms L4vRefX64.Equiv.Ipc.setExtraBadge_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_lookupExtraCaps_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_transferCapsLoop_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_transferCaps_equiv +#print axioms L4vRefX64.Equiv.Ipc.msgFromSyscallError_eq +#print axioms L4vRefX64.Equiv.Ipc.sanitiseRegister_eq +#print axioms L4vRefX64.Equiv.Ipc.archGetSanitiseRegisterInfo_equiv +#print axioms L4vRefX64.Equiv.Ipc.handleFaultReply_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_makeArchFaultMsg_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_makeFaultMsg_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_doFaultTransfer_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_doNormalTransfer_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_doIpcTransfer_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_sendIpc_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_receiveIpc_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_sendFaultIpc_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_handleTimeout_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_handleFault_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_doReplyTransfer_equiv +#print axioms L4vRefX64.Equiv.Ipc.invokeSchedControlConfigureFlags_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_endTimeslice_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_chargeBudget_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_checkBudget_equiv +#print axioms L4vRefX64.Equiv.Ipc.patched_checkBudgetRestart_equiv + +-- L4vRefX64.Equiv.IpcCancel +#print axioms L4vRefX64.Equiv.IpcCancel.holBind_kbind_return_left +#print axioms L4vRefX64.Equiv.IpcCancel.holBind_kbind_assoc +#print axioms L4vRefX64.Equiv.IpcCancel.nonDet_bind_pure_left +#print axioms L4vRefX64.Equiv.IpcCancel.updateEpQueue_eq +#print axioms L4vRefX64.Equiv.IpcCancel.ntfnQueueOf_eq +#print axioms L4vRefX64.Equiv.IpcCancel.updateNtfnQueue_waiting_eq +#print axioms L4vRefX64.Equiv.IpcCancel.epBlocked_eq +#print axioms L4vRefX64.Equiv.IpcCancel.ntfnBlocked_eq +#print axioms L4vRefX64.Equiv.IpcCancel.removeAll_eq +#print axioms L4vRefX64.Equiv.IpcCancel.ntfn_isWaitingNtfn_eq +#print axioms L4vRefX64.Equiv.IpcCancel.blockingIpcBadge_eq +#print axioms L4vRefX64.Equiv.IpcCancel.capIrqOpt_eq +#print axioms L4vRefX64.Equiv.IpcCancel.capIrqs_eq +#print axioms L4vRefX64.Equiv.IpcCancel.schedContextBindNtfn_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.doUnbindNtfnSc_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.schedContextUnbindNtfn_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.schedContextMaybeUnbindNtfn_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.schedContextUnbindReply_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.schedContextUnbindTcb_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.testReschedule_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.schedContextDonate_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.replyUnlinkSc_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.replyUnlinkTcb_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.scWithReply_eq +#print axioms L4vRefX64.Equiv.IpcCancel.replyRemove_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.replyRemoveTcb_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.noReplyInTs_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.bindScReply_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.replyPush_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.tcbEpDequeue_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.tcbNtfnDequeue_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.orderedInsert_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.tcbAppend_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.tcbEpAppend_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.tcbNtfnAppend_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.reorderEp_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.reorderNtfn_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.setPriority_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.restartThreadIfNoFault_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.removeAndRestartEpQueuedThread_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.cancelAllIpc_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.removeAndRestartBadgedThread_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.cancelBadgedSends_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.doUnbindNotification_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.unbindNotification_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.unbindMaybeNotification_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.removeAndRestartNtfnQueuedThread_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.cancelAllSignals_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.getBlockingObject_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.blockedCancelIpc_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.schedContextUnbindAllTcbs_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.cancelSignal_equiv +#print axioms L4vRefX64.Equiv.IpcCancel.cancelIpc_equiv + +-- L4vRefX64.Equiv.KHeap +#print axioms L4vRefX64.Equiv.KHeap.minBudget_eq +#print axioms L4vRefX64.Equiv.KHeap.tcbOf_eq +#print axioms L4vRefX64.Equiv.KHeap.scFieldsOf_eq +#print axioms L4vRefX64.Equiv.KHeap.scOf_eq +#print axioms L4vRefX64.Equiv.KHeap.cnodeOf_eq +#print axioms L4vRefX64.Equiv.KHeap.isSimpleType_iff +#print axioms L4vRefX64.Equiv.KHeap.ntfnSetBoundTcb_eq +#print axioms L4vRefX64.Equiv.KHeap.ntfnSetObj_eq +#print axioms L4vRefX64.Equiv.KHeap.activeSc_eq +#print axioms L4vRefX64.Equiv.KHeap.scActive_eq +#print axioms L4vRefX64.Equiv.KHeap.refillHd_eq +#print axioms L4vRefX64.Equiv.KHeap.refillTl_eq +#print axioms L4vRefX64.Equiv.KHeap.refillCapacity_eq +#print axioms L4vRefX64.Equiv.KHeap.refillSufficient_eq +#print axioms L4vRefX64.Equiv.KHeap.refillReady'_eq +#print axioms L4vRefX64.Equiv.KHeap.refillReady_eq +#print axioms L4vRefX64.Equiv.KHeap.scReleased_eq +#print axioms L4vRefX64.Equiv.KHeap.tcbSchedEnqueue_eq +#print axioms L4vRefX64.Equiv.KHeap.tcbSchedAppend_eq +#print axioms L4vRefX64.Equiv.KHeap.tcbSchedDequeue_eq +#print axioms L4vRefX64.Equiv.KHeap.tcbsOf_eq +#print axioms L4vRefX64.Equiv.KHeap.scsFieldsOf_eq +#print axioms L4vRefX64.Equiv.KHeap.scsOf_eq +#print axioms L4vRefX64.Equiv.KHeap.holBind_return_left +#print axioms L4vRefX64.Equiv.KHeap.holBind_assoc +#print axioms L4vRefX64.Equiv.KHeap.lookup_bind +#print axioms L4vRefX64.Equiv.KHeap.lookup_oassert' +#print axioms L4vRefX64.Equiv.KHeap.mask_eq +#print axioms L4vRefX64.Equiv.KHeap.scSizesOf_eq +#print axioms L4vRefX64.Equiv.KHeap.cnodesOf_eq +#print axioms L4vRefX64.Equiv.KHeap.cnodeSizesOf_eq +#print axioms L4vRefX64.Equiv.KHeap.cnodeContentsOf_eq +#print axioms L4vRefX64.Equiv.KHeap.readObject_equiv +#print axioms L4vRefX64.Equiv.KHeap.getObject_equiv +#print axioms L4vRefX64.Equiv.KHeap.getObject_member +#print axioms L4vRefX64.Equiv.KHeap.setObject_equiv +#print axioms L4vRefX64.Equiv.KHeap.getTcb_equiv +#print axioms L4vRefX64.Equiv.KHeap.threadRead_equiv +#print axioms L4vRefX64.Equiv.KHeap.threadGet_equiv +#print axioms L4vRefX64.Equiv.KHeap.threadSet_equiv +#print axioms L4vRefX64.Equiv.KHeap.archThreadGet_equiv +#print axioms L4vRefX64.Equiv.KHeap.archThreadSet_equiv +#print axioms L4vRefX64.Equiv.KHeap.readThreadState_equiv +#print axioms L4vRefX64.Equiv.KHeap.getThreadState_equiv +#print axioms L4vRefX64.Equiv.KHeap.readTcbObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.getTcbObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.setTcbObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.partialInv_rel +#print axioms L4vRefX64.Equiv.KHeap.getSimpleKo_equiv +#print axioms L4vRefX64.Equiv.KHeap.setSimpleKo_equiv +#print axioms L4vRefX64.Equiv.KHeap.embEndpoint_injective +#print axioms L4vRefX64.Equiv.KHeap.embNotification_injective +#print axioms L4vRefX64.Equiv.KHeap.embReply_injective +#print axioms L4vRefX64.Equiv.KHeap.getEndpoint_equiv +#print axioms L4vRefX64.Equiv.KHeap.setEndpoint_equiv +#print axioms L4vRefX64.Equiv.KHeap.getNotification_equiv +#print axioms L4vRefX64.Equiv.KHeap.setNotification_equiv +#print axioms L4vRefX64.Equiv.KHeap.getReply_equiv +#print axioms L4vRefX64.Equiv.KHeap.setReply_equiv +#print axioms L4vRefX64.Equiv.KHeap.getReplyTcb_equiv +#print axioms L4vRefX64.Equiv.KHeap.getIrqState_equiv +#print axioms L4vRefX64.Equiv.KHeap.setIrqState_equiv +#print axioms L4vRefX64.Equiv.KHeap.getIrqSlot_equiv +#print axioms L4vRefX64.Equiv.KHeap.readSchedContext_equiv +#print axioms L4vRefX64.Equiv.KHeap.getSchedContext_equiv +#print axioms L4vRefX64.Equiv.KHeap.readScObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.getScObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.setSchedContext_equiv +#print axioms L4vRefX64.Equiv.KHeap.updateSchedContext_equiv +#print axioms L4vRefX64.Equiv.KHeap.setScObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.readScActive_equiv +#print axioms L4vRefX64.Equiv.KHeap.getScActive_equiv +#print axioms L4vRefX64.Equiv.KHeap.inReleaseQueue_eq +#print axioms L4vRefX64.Equiv.KHeap.schedulable_eq +#print axioms L4vRefX64.Equiv.KHeap.ctSchedulable_eq +#print axioms L4vRefX64.Equiv.KHeap.getRefills_equiv +#print axioms L4vRefX64.Equiv.KHeap.readRefillHead_equiv +#print axioms L4vRefX64.Equiv.KHeap.getRefillHead_equiv +#print axioms L4vRefX64.Equiv.KHeap.readRefillTail_equiv +#print axioms L4vRefX64.Equiv.KHeap.getRefillTail_equiv +#print axioms L4vRefX64.Equiv.KHeap.readScRefillCapacity_equiv +#print axioms L4vRefX64.Equiv.KHeap.getScRefillCapacity_equiv +#print axioms L4vRefX64.Equiv.KHeap.readScRefillSufficient_equiv +#print axioms L4vRefX64.Equiv.KHeap.getScRefillSufficient_equiv +#print axioms L4vRefX64.Equiv.KHeap.readScRefillReady_equiv +#print axioms L4vRefX64.Equiv.KHeap.getScRefillReady_equiv +#print axioms L4vRefX64.Equiv.KHeap.readScReleased_equiv +#print axioms L4vRefX64.Equiv.KHeap.getScReleased_equiv +#print axioms L4vRefX64.Equiv.KHeap.getTcbQueue_equiv +#print axioms L4vRefX64.Equiv.KHeap.setTcbQueue_equiv +#print axioms L4vRefX64.Equiv.KHeap.tcbSchedAction_equiv +#print axioms L4vRefX64.Equiv.KHeap.isBlocked_equiv +#print axioms L4vRefX64.Equiv.KHeap.setReleaseQueue_equiv +#print axioms L4vRefX64.Equiv.KHeap.tcbReleaseRemove_equiv +#print axioms L4vRefX64.Equiv.KHeap.setSchedulerAction_equiv +#print axioms L4vRefX64.Equiv.KHeap.threadSetPriority_equiv +#print axioms L4vRefX64.Equiv.KHeap.threadSetDomain_equiv +#print axioms L4vRefX64.Equiv.KHeap.rescheduleRequired_equiv +#print axioms L4vRefX64.Equiv.KHeap.possibleSwitchTo_equiv +#print axioms L4vRefX64.Equiv.KHeap.scheduleTcb_equiv +#print axioms L4vRefX64.Equiv.KHeap.setThreadStateAct_equiv +#print axioms L4vRefX64.Equiv.KHeap.setThreadState_equiv +#print axioms L4vRefX64.Equiv.KHeap.setMcpriority_equiv +#print axioms L4vRefX64.Equiv.KHeap.getSkObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.updateSkObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.getNtfnObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.setNtfnObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.getReplyObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.setReplyObjRef_equiv +#print axioms L4vRefX64.Equiv.KHeap.isIrqActive_equiv +#print axioms L4vRefX64.Equiv.KHeap.setFlags_equiv +#print axioms L4vRefX64.Equiv.KHeap.asUser_equiv +#print axioms L4vRefX64.Equiv.KHeap.throwOnFalse_equiv +#print axioms L4vRefX64.Equiv.KHeap.isCurDomainExpired_eq +#print axioms L4vRefX64.Equiv.KHeap.updateTimeStamp_equiv +#print axioms L4vRefX64.Equiv.KHeap.preemptionPoint_equiv + +-- L4vRefX64.Equiv.Machine +#print axioms L4vRefX64.Equiv.Machine.usToTicks_eq +#print axioms L4vRefX64.Equiv.Machine.ticksToUs_eq +#print axioms L4vRefX64.Equiv.Machine.MAX_PERIOD_eq +#print axioms L4vRefX64.Equiv.Machine.MAX_RELEASE_TIME_eq +#print axioms L4vRefX64.Equiv.Machine.getCurrentTime_equiv +#print axioms L4vRefX64.Equiv.Machine.getActiveIRQ_equiv +#print axioms L4vRefX64.Equiv.Machine.maskInterrupt_equiv +#print axioms L4vRefX64.Equiv.Machine.getRegister_equiv +#print axioms L4vRefX64.Equiv.Machine.setRegister_equiv +#print axioms L4vRefX64.Equiv.Machine.wordSize_eq +#print axioms L4vRefX64.Equiv.Machine.pageBitsForSize_eq +#print axioms L4vRefX64.Equiv.Machine.ptrAdd_eq +#print axioms L4vRefX64.Equiv.Machine.holUptoEnum_bv_eq +#print axioms L4vRefX64.Equiv.Machine.holUptoEnumStep_eq +#print axioms L4vRefX64.Equiv.Machine.wordBits_eq +#print axioms L4vRefX64.Equiv.Machine.dataToCptr_eq +#print axioms L4vRefX64.Equiv.Machine.natToLen_eq +#print axioms L4vRefX64.Equiv.Machine.msg_info_register_eq +#print axioms L4vRefX64.Equiv.Machine.msg_registers_eq +#print axioms L4vRefX64.Equiv.Machine.badge_register_eq +#print axioms L4vRefX64.Equiv.Machine.nextInstructionRegister_eq +#print axioms L4vRefX64.Equiv.Machine.faultRegister_eq +#print axioms L4vRefX64.Equiv.Machine.getRestartPC_equiv +#print axioms L4vRefX64.Equiv.Machine.setNextPC_equiv +#print axioms L4vRefX64.Equiv.Machine.loadWord_equiv +#print axioms L4vRefX64.Equiv.Machine.storeWord_equiv +#print axioms L4vRefX64.Equiv.Machine.clearMemory_equiv +#print axioms L4vRefX64.Equiv.Machine.clearMemoryVM_equiv +#print axioms L4vRefX64.Equiv.Machine.initMemory_equiv +#print axioms L4vRefX64.Equiv.Machine.freeMemory_equiv +#print axioms L4vRefX64.Equiv.Machine.isAligned_iff + +-- L4vRefX64.Equiv.Retype +#print axioms L4vRefX64.Equiv.Retype.archDefaultCap_eq +#print axioms L4vRefX64.Equiv.Retype.defaultArchObject_eq +#print axioms L4vRefX64.Equiv.Retype.emptyContext_eq +#print axioms L4vRefX64.Equiv.Retype.initArchTcb_eq +#print axioms L4vRefX64.Equiv.Retype.defaultCap_eq +#print axioms L4vRefX64.Equiv.Retype.emptyCnode_eq +#print axioms L4vRefX64.Equiv.Retype.patched_defaultTcb_equiv +#print axioms L4vRefX64.Equiv.Retype.patched_defaultObject_eq +#print axioms L4vRefX64.Equiv.Retype.patched_objBitsApi_equiv +#print axioms L4vRefX64.Equiv.Retype.objBitsApi_ntfn_delta +#print axioms L4vRefX64.Equiv.Retype.getFreeRef_eq +#print axioms L4vRefX64.Equiv.Retype.getFreeIndex_eq +#print axioms L4vRefX64.Equiv.Retype.isDeviceUntypedCap_eq +#print axioms L4vRefX64.Equiv.Retype.bitsOf_eq +#print axioms L4vRefX64.Equiv.Retype.freeIndexOf_eq' +#print axioms L4vRefX64.Equiv.Retype.objRefOf_eq +#print axioms L4vRefX64.Equiv.Retype.reserveRegion_equiv +#print axioms L4vRefX64.Equiv.Retype.archPostResetUntyped_equiv +#print axioms L4vRefX64.Equiv.Retype.detype_rel +#print axioms L4vRefX64.Equiv.Retype.deleteObjects_equiv +#print axioms L4vRefX64.Equiv.Retype.createCap_equiv_nonExt +#print axioms L4vRefX64.Equiv.Retype.patched_retypeRegion_equiv +#print axioms L4vRefX64.Equiv.Retype.resetUntypedCap_equiv +#print axioms L4vRefX64.Equiv.Retype.initArchObjects_equiv +#print axioms L4vRefX64.Equiv.Retype.patched_invokeUntyped_equiv + +-- L4vRefX64.Equiv.SchedContext +#print axioms L4vRefX64.Equiv.SchedContext.wordsFromTime_eq +#print axioms L4vRefX64.Equiv.SchedContext.refillsSum_eq +#print axioms L4vRefX64.Equiv.SchedContext.maxRefillsCap_eq +#print axioms L4vRefX64.Equiv.SchedContext.readReadyTime_equiv +#print axioms L4vRefX64.Equiv.SchedContext.readTcbReadyTime_equiv +#print axioms L4vRefX64.Equiv.SchedContext.readyTimesAppend_equiv +#print axioms L4vRefX64.Equiv.SchedContext.tcbReleaseEnqueue_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillSize_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillFull_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillSingle_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillSum_equiv +#print axioms L4vRefX64.Equiv.SchedContext.setRefills_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillAddTail_equiv +#print axioms L4vRefX64.Equiv.SchedContext.updateRefillTl_equiv_nonEmpty +#print axioms L4vRefX64.Equiv.SchedContext.setRefillHd_equiv_nonEmpty +#print axioms L4vRefX64.Equiv.SchedContext.setRefillTl_equiv_nonEmpty +#print axioms L4vRefX64.Equiv.SchedContext.maybeAddEmptyTail_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillNew_equiv +#print axioms L4vRefX64.Equiv.SchedContext.mrelStep_when +#print axioms L4vRefX64.Equiv.SchedContext.mrel_bind_post +#print axioms L4vRefX64.Equiv.SchedContext.mrel_strengthen_post +#print axioms L4vRefX64.Equiv.SchedContext.mrel_drop_post +#print axioms L4vRefX64.Equiv.SchedContext.mrel_lift_preserves_state +#print axioms L4vRefX64.Equiv.SchedContext.holGetsThe_state_eq +#print axioms L4vRefX64.Equiv.SchedContext.scheduleUsed_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillBudgetCheckRoundRobin_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillHeadInsufficient_equiv +#print axioms L4vRefX64.Equiv.SchedContext.mergeNonoverlappingHeadRefill_equiv_safe +#print axioms L4vRefX64.Equiv.SchedContext.mrel_whileLoop_guarded +#print axioms L4vRefX64.Equiv.SchedContext.headInsufficientLoop_equiv_safe +#print axioms L4vRefX64.Equiv.SchedContext.headRefillOverrun_equiv +#print axioms L4vRefX64.Equiv.SchedContext.chargeEntireHeadRefill_equiv +#print axioms L4vRefX64.Equiv.SchedContext.handleOverrun_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillBudgetCheck_equiv +#print axioms L4vRefX64.Equiv.SchedContext.refillUpdate_equiv_nonEmpty +#print axioms L4vRefX64.Equiv.SchedContext.postpone_equiv +#print axioms L4vRefX64.Equiv.SchedContext.schedContextResume_equiv +#print axioms L4vRefX64.Equiv.SchedContext.schedContextUpdateConsumed_equiv +#print axioms L4vRefX64.Equiv.SchedContext.returnConsumed_equiv +#print axioms L4vRefX64.Equiv.SchedContext.schedContextCancelYieldTo_equiv +#print axioms L4vRefX64.Equiv.SchedContext.patched_setConsumed_equiv +#print axioms L4vRefX64.Equiv.SchedContext.patched_completeYieldTo_equiv +#print axioms L4vRefX64.Equiv.SchedContext.patched_schedContextUnbindYieldFrom_equiv +#print axioms L4vRefX64.Equiv.SchedContext.patched_unbindFromSc_equiv +#print axioms L4vRefX64.Equiv.SchedContext.testPossibleSwitchTo_equiv +#print axioms L4vRefX64.Equiv.SchedContext.schedContextBindTcb_equiv +#print axioms L4vRefX64.Equiv.SchedContext.schedContextSetInactive_equiv +#print axioms L4vRefX64.Equiv.SchedContext.maybeDonateSc_equiv +#print axioms L4vRefX64.Equiv.SchedContext.maybeReturnSc_equiv +#print axioms L4vRefX64.Equiv.SchedContext.commitTime_equiv +#print axioms L4vRefX64.Equiv.SchedContext.updateRestartPc_equiv +#print axioms L4vRefX64.Equiv.SchedContext.suspend_equiv + +-- L4vRefX64.Equiv.Schedule +#print axioms L4vRefX64.Equiv.Schedule.idle_iff +#print axioms L4vRefX64.Equiv.Schedule.domainEndMarker_eq +#print axioms L4vRefX64.Equiv.Schedule.setMax_bitvec8_eq_holMax +#print axioms L4vRefX64.Equiv.Schedule.maxNonEmptyQueue_eq +#print axioms L4vRefX64.Equiv.Schedule.maxNonEmptyQueue_ne_nil +#print axioms L4vRefX64.Equiv.Schedule.isHighestPrio_iff +#print axioms L4vRefX64.Equiv.Schedule.switchToThread_equiv +#print axioms L4vRefX64.Equiv.Schedule.guardedSwitchTo_equiv +#print axioms L4vRefX64.Equiv.Schedule.switchToIdleThread_equiv +#print axioms L4vRefX64.Equiv.Schedule.decDomainTime_equiv +#print axioms L4vRefX64.Equiv.Schedule.domainScheduleConfigure_equiv +#print axioms L4vRefX64.Equiv.Schedule.domainSetStart_equiv +#print axioms L4vRefX64.Equiv.Schedule.nextDomain_equiv +#print axioms L4vRefX64.Equiv.Schedule.setNextInterrupt_equiv +#print axioms L4vRefX64.Equiv.Schedule.switchSchedContext_equiv +#print axioms L4vRefX64.Equiv.Schedule.scAndTimer_equiv +#print axioms L4vRefX64.Equiv.Schedule.readTcbRefillReady_equiv +#print axioms L4vRefX64.Equiv.Schedule.readReleaseQNonEmptyAndReady_equiv +#print axioms L4vRefX64.Equiv.Schedule.tcbReleaseDequeue_equiv +#print axioms L4vRefX64.Equiv.Schedule.awaken_equiv +#print axioms L4vRefX64.Equiv.Schedule.chooseThread_equiv +#print axioms L4vRefX64.Equiv.Schedule.scheduleSwitchThreadFastfail_equiv +#print axioms L4vRefX64.Equiv.Schedule.checkDomainTime_equiv +#print axioms L4vRefX64.Equiv.Schedule.scheduleChooseNewThread_equiv +#print axioms L4vRefX64.Equiv.Schedule.schedule_equiv +#print axioms L4vRefX64.Equiv.Schedule.patched_schedContextYieldTo_equiv +#print axioms L4vRefX64.Equiv.Schedule.patched_invokeSchedContext_equiv + +-- L4vRefX64.Equiv.Structures +#print axioms L4vRefX64.Equiv.Structures.cteLevelBits_eq +#print axioms L4vRefX64.Equiv.Structures.untypedMaxBits_eq +#print axioms L4vRefX64.Equiv.Structures.aaType_eq +#print axioms L4vRefX64.Equiv.Structures.runnable_eq +#print axioms L4vRefX64.Equiv.Structures.ipcQueuedThreadState_eq +#print axioms L4vRefX64.Equiv.Structures.MIN_REFILLS_eq +#print axioms L4vRefX64.Equiv.Structures.MIN_BUDGET_US_eq +#print axioms L4vRefX64.Equiv.Structures.minSchedContextBits_eq +#print axioms L4vRefX64.Equiv.Structures.sizeofSchedContextT_eq +#print axioms L4vRefX64.Equiv.Structures.refillSizeBytes_eq +#print axioms L4vRefX64.Equiv.Structures.maxNumRefills_eq +#print axioms L4vRefX64.Equiv.Structures.scSporadicFlag_eq +#print axioms L4vRefX64.Equiv.Structures.defaultSchedContext_eq +#print axioms L4vRefX64.Equiv.Structures.defaultReply_eq +#print axioms L4vRefX64.Equiv.Structures.aobjOf_eq +#print axioms L4vRefX64.Equiv.Structures.wellFormedCnodeN_iff +#print axioms L4vRefX64.Equiv.Structures.validSchedContextSize_iff +#print axioms L4vRefX64.Equiv.Structures.aType_eq +#print axioms L4vRefX64.Equiv.Structures.tcbCnodeIndex_eq +#print axioms L4vRefX64.Equiv.Structures.zombieCteBits_eq +#print axioms L4vRefX64.Equiv.Structures.archTcbContextSet_eq +#print axioms L4vRefX64.Equiv.Structures.archTcbContextGet_eq +#print axioms L4vRefX64.Equiv.Structures.tcbCnodeMap_eq_nonExt +#print axioms L4vRefX64.Equiv.Structures.isCnodeCap_eq +#print axioms L4vRefX64.Equiv.Structures.capOf_eq_nonExt +#print axioms L4vRefX64.Equiv.Structures.epQueue_eq +#print axioms L4vRefX64.Equiv.Structures.ntfnQueue_eq +#print axioms L4vRefX64.Equiv.Structures.ntfnBadge_eq +#print axioms L4vRefX64.Equiv.Structures.defaultEp_eq +#print axioms L4vRefX64.Equiv.Structures.defaultNtfn_eq +#print axioms L4vRefX64.Equiv.Structures.defaultNotification_eq +#print axioms L4vRefX64.Equiv.Structures.replyObject_eq +#print axioms L4vRefX64.Equiv.Structures.isBlockedOnReceive_iff +#print axioms L4vRefX64.Equiv.Structures.isBlockedOnSend_iff +#print axioms L4vRefX64.Equiv.Structures.isBlockedOnReply_iff +#print axioms L4vRefX64.Equiv.Structures.isBlockedOnNtfn_iff +#print axioms L4vRefX64.Equiv.Structures.messageInfoToData_eq +#print axioms L4vRefX64.Equiv.Structures.dataToMessageInfo_eq +#print axioms L4vRefX64.Equiv.Structures.capTransferDataSize_eq +#print axioms L4vRefX64.Equiv.Structures.msgMaxLength_eq +#print axioms L4vRefX64.Equiv.Structures.msgMaxExtraCaps_eq +#print axioms L4vRefX64.Equiv.Structures.maxIpcLength_eq +#print axioms L4vRefX64.Equiv.Structures.msgAlignBits_eq + +-- L4vRefX64.Equiv.Syscall +#print axioms L4vRefX64.Equiv.Syscall.patched_performInvocation_equiv +#print axioms L4vRefX64.Equiv.Syscall.syscall_step_equiv +#print axioms L4vRefX64.Equiv.Syscall.handleInterruptEvent_equiv_sufficient +#print axioms L4vRefX64.Equiv.Syscall.patched_callKernel_interrupt_equiv_sufficient +#print axioms L4vRefX64.Equiv.Syscall.getCapReg_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_handleInvocation_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_lookupReply_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_handleRecv_equiv_notification +#print axioms L4vRefX64.Equiv.Syscall.patched_handleRecv_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_handleNbWait_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_callKernel_nbwait_equiv +#print axioms L4vRefX64.Equiv.Syscall.handleYield_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_preemptionPath_equiv +#print axioms L4vRefX64.Equiv.Syscall.handleVmFault_equiv +#print axioms L4vRefX64.Equiv.Syscall.handleHypervisorFault_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_handleInterrupt_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_handleNonSyscall_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_callKernelNonSyscall_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_invocationFromReg_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_invokeThenReceive_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_handleSyscall_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_handleEvent_equiv +#print axioms L4vRefX64.Equiv.Syscall.patched_callKernel_equiv + +-- L4vRefX64.Equiv.Tcb +#print axioms L4vRefX64.Equiv.Tcb.archPrepareSetDomain_equiv +#print axioms L4vRefX64.Equiv.Tcb.setDomain_equiv +#print axioms L4vRefX64.Equiv.Tcb.invokeSetDomain_equiv +#print axioms L4vRefX64.Equiv.Tcb.invokeDomain_equiv +#print axioms L4vRefX64.Equiv.Tcb.restart_equiv +#print axioms L4vRefX64.Equiv.Tcb.patched_activateThread_equiv +#print axioms L4vRefX64.Equiv.Tcb.bindNotification_equiv +#print axioms L4vRefX64.Equiv.Tcb.patched_checkCapAt_equiv +#print axioms L4vRefX64.Equiv.Tcb.patched_installTcbCap_equiv +#print axioms L4vRefX64.Equiv.Tcb.patched_installTcbFrameCap_equiv +#print axioms L4vRefX64.Equiv.Tcb.patched_invokeTcb_equiv + +-- L4vRefX64.Equiv.TcbAcc +#print axioms L4vRefX64.Equiv.TcbAcc.loadWordOffs_equiv +#print axioms L4vRefX64.Equiv.TcbAcc.storeWordOffs_equiv +#print axioms L4vRefX64.Equiv.TcbAcc.setMessageInfo_equiv +#print axioms L4vRefX64.Equiv.TcbAcc.setMrs_equiv +#print axioms L4vRefX64.Equiv.TcbAcc.copyMrs_equiv +#print axioms L4vRefX64.Equiv.TcbAcc.getMrs_equiv +#print axioms L4vRefX64.Equiv.TcbAcc.replyFromKernel_body_equiv +#print axioms L4vRefX64.Equiv.TcbAcc.patched_replyFromKernel_equiv + +-- L4vRefX64.Equiv.Types +#print axioms L4vRefX64.Equiv.Types.vmReadOnly_eq +#print axioms L4vRefX64.Equiv.Types.vmReadWrite_eq +#print axioms L4vRefX64.Equiv.Types.vmKernelOnly_eq +#print axioms L4vRefX64.Equiv.Types.validateVmRights_eq +#print axioms L4vRefX64.Equiv.Types.maskVmRights_eq + +-- L4vRefX64.Equiv.VSpaceAccess +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPt_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.setPt_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPte_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.storePte_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPd_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.setPd_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPde_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.storePde_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPdpt_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.setPdpt_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPdpte_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.storePdpte_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPml4_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.setPml4_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPml4e_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.storePml4e_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPtIndex_eq +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPdIndex_eq +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPdptIndex_eq +#print axioms L4vRefX64.Equiv.VSpaceAccess.getPml4Index_eq +#print axioms L4vRefX64.Equiv.VSpaceAccess.ptrFromPAddr_eq +#print axioms L4vRefX64.Equiv.VSpaceAccess.lookupPml4Slot_eq +#print axioms L4vRefX64.Equiv.VSpaceAccess.lookupPdptSlot_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.lookupPdSlot_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.lookupPtSlot_equiv +#print axioms L4vRefX64.Equiv.VSpaceAccess.copyGlobalMappings_equiv + +-- L4vRefX64.Equiv.VSpaceRoot +#print axioms L4vRefX64.Equiv.VSpaceRoot.asidLowBitsOf_eq +#print axioms L4vRefX64.Equiv.VSpaceRoot.asidHighBitsOf_cast +#print axioms L4vRefX64.Equiv.VSpaceRoot.asidHighBitsOf_lt +#print axioms L4vRefX64.Equiv.VSpaceRoot.asidTable_eq +#print axioms L4vRefX64.Equiv.VSpaceRoot.getAsidPool_equiv +#print axioms L4vRefX64.Equiv.VSpaceRoot.getAsidPool_member +#print axioms L4vRefX64.Equiv.VSpaceRoot.findVspaceForAsid_equiv +#print axioms L4vRefX64.Equiv.VSpaceRoot.getCurrentCr3_equiv +#print axioms L4vRefX64.Equiv.VSpaceRoot.embCr3_injective +#print axioms L4vRefX64.Equiv.VSpaceRoot.setCurrentCr3_equiv +#print axioms L4vRefX64.Equiv.VSpaceRoot.makeCr3_eq +#print axioms L4vRefX64.Equiv.VSpaceRoot.setCurrentVspaceRoot_equiv +#print axioms L4vRefX64.Equiv.VSpaceRoot.addrFromPPtr_eq +#print axioms L4vRefX64.Equiv.VSpaceRoot.addrFromKPPtr_eq +#print axioms L4vRefX64.Equiv.VSpaceRoot.setVmRoot_equiv + +-- L4vRefX64.Equiv.VSpaceUnmap +#print axioms L4vRefX64.Equiv.VSpaceUnmap.invalidatePageStructureCacheAsid_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.flushAll_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.flushTable_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.checkMappingPptr_eq +#print axioms L4vRefX64.Equiv.VSpaceUnmap.unmapPage_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.unmapPageTable_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.unmapPd_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.unmapPdpt_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.deleteAsid_equiv +#print axioms L4vRefX64.Equiv.VSpaceUnmap.widenAsidTable_update +#print axioms L4vRefX64.Equiv.VSpaceUnmap.deleteAsidPool_equiv + +-- L4vRefX64.Equiv.Witness +#print axioms L4vRefX64.Equiv.Witness.pc99Config_exists +#print axioms L4vRefX64.Equiv.Witness.leanMachine_related +#print axioms L4vRefX64.Equiv.Witness.referenceState_base +#print axioms L4vRefX64.Equiv.Witness.leanState_related +#print axioms L4vRefX64.Equiv.Witness.referenceState_related +#print axioms L4vRefX64.Equiv.Witness.liveThread +#print axioms L4vRefX64.Equiv.Witness.maskedIrqWitness +#print axioms L4vRefX64.Equiv.Witness.interruptEntry_base +#print axioms L4vRefX64.Equiv.Witness.liveOneTickWitness +#print axioms L4vRefX64.Equiv.Witness.liveInterruptRelated +#print axioms L4vRefX64.Equiv.Witness.liveInterruptWitness +#print axioms L4vRefX64.Equiv.Witness.nbWaitEntry_base +#print axioms L4vRefX64.Equiv.Witness.liveSetCapWitness +#print axioms L4vRefX64.Equiv.Witness.liveCapInsertWitness +#print axioms L4vRefX64.Equiv.Witness.liveNbWaitWitness +#print axioms L4vRefX64.Equiv.Witness.liveOneTickInterruptWitness +#print axioms L4vRefX64.Equiv.Witness.livePageUnmapWitness +#print axioms L4vRefX64.Equiv.Witness.liveArchPageUnmapWitness +#print axioms L4vRefX64.Equiv.Witness.liveScheduleWitness +#print axioms L4vRefX64.Equiv.Witness.livePageTableUnmapWitness +#print axioms L4vRefX64.Equiv.Witness.livePageDirectoryUnmapWitness +#print axioms L4vRefX64.Equiv.Witness.liveInvokeIrqControlWitness +#print axioms L4vRefX64.Equiv.Witness.liveInvokeIrqHandlerWitness +#print axioms L4vRefX64.Equiv.Witness.liveInvokeTcbInstallWitness +#print axioms L4vRefX64.Equiv.Witness.liveMakeAsidPoolWitness +#print axioms L4vRefX64.Equiv.Witness.liveLinkedFaultReplyWitness + +-- L4vRefX64.Patched +#print axioms L4vRefX64.Patched.newContext_selectors_delta +#print axioms L4vRefX64.Patched.newContext_equiv +#print axioms L4vRefX64.Patched.decodeObjectType_common +#print axioms L4vRefX64.Patched.decodeObjectType_codes7to11_delta +#print axioms L4vRefX64.Patched.lookupIpcBuffer_slot_delta +#print axioms L4vRefX64.Patched.notificationBits_delta +#print axioms L4vRefX64.Patched.asidWidths_delta +#print axioms L4vRefX64.Patched.cr3Mask_preserved +#print axioms L4vRefX64.Patched.ioPortOwner_delta +#print axioms L4vRefX64.Patched.tcbEptSlot_delta +#print axioms L4vRefX64.Patched.makeArchFaultMsg_delta +#print axioms L4vRefX64.Patched.compiledNumDomains_delta +#print axioms L4vRefX64.Patched.asidFreeIndex_delta +#print axioms L4vRefX64.Patched.patched_tcbCnodeMap_eq +#print axioms L4vRefX64.Patched.invocationType_equiv +#print axioms L4vRefX64.Patched.invocationLabel_numbering_delta +#print axioms L4vRefX64.Patched.cnodeRevoke_label_delta +#print axioms L4vRefX64.Patched.hugePages_delta +#print axioms L4vRefX64.Patched.endTimeslice_runningVM_delta +#print axioms L4vRefX64.Patched.finaliseTcbZombieSlots_delta +#print axioms L4vRefX64.Patched.maxPeriodUs_delta + +-- L4vRefX64.Rel.Config + +-- L4vRefX64.Rel.Embed +#print axioms L4vRefX64.Rel.set_image_inter +#print axioms L4vRefX64.Rel.set_image_diff +#print axioms L4vRefX64.Rel.set_image_union +#print axioms L4vRefX64.Rel.set_image_univ +#print axioms L4vRefX64.Rel.fun_update_comp +#print axioms L4vRefX64.Rel.unembRights_emb +#print axioms L4vRefX64.Rel.embRights_unemb +#print axioms L4vRefX64.Rel.embRights_injective +#print axioms L4vRefX64.Rel.embRights_surjective +#print axioms L4vRefX64.Rel.embRightsSet_mem +#print axioms L4vRefX64.Rel.embRightsSet_injective +#print axioms L4vRefX64.Rel.embRightsSet_eq_iff +#print axioms L4vRefX64.Rel.embRightsSet_empty +#print axioms L4vRefX64.Rel.embRightsSet_univ +#print axioms L4vRefX64.Rel.embRightsSet_insert +#print axioms L4vRefX64.Rel.embRightsSet_inter +#print axioms L4vRefX64.Rel.embRightsSet_union +#print axioms L4vRefX64.Rel.embRightsSet_diff +#print axioms L4vRefX64.Rel.unembTcbFlag_emb +#print axioms L4vRefX64.Rel.embTcbFlag_unemb +#print axioms L4vRefX64.Rel.embTcbFlag_injective +#print axioms L4vRefX64.Rel.embTcbFlag_surjective +#print axioms L4vRefX64.Rel.embTcbFlags_mem +#print axioms L4vRefX64.Rel.embTcbFlags_injective +#print axioms L4vRefX64.Rel.embTcbFlags_eq_iff +#print axioms L4vRefX64.Rel.embTcbFlags_empty +#print axioms L4vRefX64.Rel.embTcbFlags_insert +#print axioms L4vRefX64.Rel.embTcbFlags_inter +#print axioms L4vRefX64.Rel.embTcbFlags_union +#print axioms L4vRefX64.Rel.embTcbFlags_diff +#print axioms L4vRefX64.Rel.unembVMPageSize_emb +#print axioms L4vRefX64.Rel.embVMPageSize_unemb +#print axioms L4vRefX64.Rel.embVMPageSize_injective +#print axioms L4vRefX64.Rel.embVMPageSize_eq_iff +#print axioms L4vRefX64.Rel.unembSyscall_emb +#print axioms L4vRefX64.Rel.embSyscall_unemb +#print axioms L4vRefX64.Rel.unembIrqState_emb +#print axioms L4vRefX64.Rel.embIrqState_unemb +#print axioms L4vRefX64.Rel.embIrqState_injective +#print axioms L4vRefX64.Rel.embIrqState_eq_iff +#print axioms L4vRefX64.Rel.embSchedulerAction_injective +#print axioms L4vRefX64.Rel.embSchedulerAction_eq_iff +#print axioms L4vRefX64.Rel.embLookupFailure_injective +#print axioms L4vRefX64.Rel.embLookupFailure_eq_iff +#print axioms L4vRefX64.Rel.embArchFault_eq_iff +#print axioms L4vRefX64.Rel.embFault_injective +#print axioms L4vRefX64.Rel.embFault_eq_iff +#print axioms L4vRefX64.Rel.embSyscallError_injective +#print axioms L4vRefX64.Rel.embSyscallError_eq_iff +#print axioms L4vRefX64.Rel.unembRegister_emb +#print axioms L4vRefX64.Rel.embRegister_unemb +#print axioms L4vRefX64.Rel.embRegister_injective +#print axioms L4vRefX64.Rel.embUserRegs_embRegister +#print axioms L4vRefX64.Rel.archTcbGetRegisters_eq +#print axioms L4vRefX64.Rel.archTcbSetRegisters_eq +#print axioms L4vRefX64.Rel.embVMMapType_eq_iff +#print axioms L4vRefX64.Rel.embArchCap_injective +#print axioms L4vRefX64.Rel.embArchCap_eq_iff +#print axioms L4vRefX64.Rel.embCap_injective +#print axioms L4vRefX64.Rel.embCap_eq_iff +#print axioms L4vRefX64.Rel.embCnodeContents_injective +#print axioms L4vRefX64.Rel.embMessageInfo_injective +#print axioms L4vRefX64.Rel.embEndpoint_injective +#print axioms L4vRefX64.Rel.embNtfn_injective +#print axioms L4vRefX64.Rel.embNotification_injective +#print axioms L4vRefX64.Rel.embSenderPayload_injective +#print axioms L4vRefX64.Rel.embReceiverPayload_injective +#print axioms L4vRefX64.Rel.embThreadState_injective +#print axioms L4vRefX64.Rel.embThreadState_eq_iff +#print axioms L4vRefX64.Rel.embRefill_injective +#print axioms L4vRefX64.Rel.embAAType_injective +#print axioms L4vRefX64.Rel.embDetExt_injective + +-- L4vRefX64.Rel.Extension + +-- L4vRefX64.Rel.Invocation +#print axioms L4vRefX64.Rel.unembArchInvocationLabel_emb +#print axioms L4vRefX64.Rel.embArchInvocationLabel_unemb +#print axioms L4vRefX64.Rel.unembGenInvocationLabels_emb +#print axioms L4vRefX64.Rel.embGenInvocationLabels_unemb +#print axioms L4vRefX64.Rel.unembInvocationLabel_emb +#print axioms L4vRefX64.Rel.embInvocationLabel_injective +#print axioms L4vRefX64.Rel.embInvocationLabel_eq_iff +#print axioms L4vRefX64.Rel.invocationLabels_enum_eq +#print axioms L4vRefX64.Rel.genInvocationLabels_enum_eq + +-- L4vRefX64.Rel.Lift +#print axioms L4vRefX64.Rel.mrel_ignoreFailure +#print axioms L4vRefX64.Rel.mrel_machineRestLift +#print axioms L4vRefX64.Rel.mrel_machineOpLift +#print axioms L4vRefX64.Rel.mrel_doMachineOp + +-- L4vRefX64.Rel.Monad +#print axioms L4vRefX64.Rel.holNot_eq_true +#print axioms L4vRefX64.Rel.holConj_eq_true +#print axioms L4vRefX64.Rel.holDisj_eq_true +#print axioms L4vRefX64.Rel.holImp_eq_true +#print axioms L4vRefX64.Rel.holEq_eq_true +#print axioms L4vRefX64.Rel.holNotEq_eq_true +#print axioms L4vRefX64.Rel.holAll_eq_true +#print axioms L4vRefX64.Rel.holEx_eq_true +#print axioms L4vRefX64.Rel.holEx1_eq_true +#print axioms L4vRefX64.Rel.holIf_true +#print axioms L4vRefX64.Rel.holIf_false +#print axioms L4vRefX64.Rel.holIf_eq +#print axioms L4vRefX64.Rel.holLet_eq +#print axioms L4vRefX64.Rel.holFunApp_eq +#print axioms L4vRefX64.Rel.holComp_eq +#print axioms L4vRefX64.Rel.holId_eq +#print axioms L4vRefX64.Rel.holKBind_eq +#print axioms L4vRefX64.Rel.holFunUpd_eq +#print axioms L4vRefX64.Rel.holCaseProd_eq +#print axioms L4vRefX64.Rel.holCaseOption_none +#print axioms L4vRefX64.Rel.holCaseOption_some +#print axioms L4vRefX64.Rel.holCaseSum_inl +#print axioms L4vRefX64.Rel.holCaseSum_inr +#print axioms L4vRefX64.Rel.holCaseBool_true +#print axioms L4vRefX64.Rel.holCaseBool_false +#print axioms L4vRefX64.Rel.holCaseList_nil +#print axioms L4vRefX64.Rel.holCaseList_cons +#print axioms L4vRefX64.Rel.holMember_eq_true +#print axioms L4vRefX64.Rel.holCollect_eq +#print axioms L4vRefX64.Rel.holInsert_eq +#print axioms L4vRefX64.Rel.holImage_eq +#print axioms L4vRefX64.Rel.holLt_eq_true +#print axioms L4vRefX64.Rel.holLe_eq_true +#print axioms L4vRefX64.Rel.holDvd_nat_eq_true +#print axioms L4vRefX64.Rel.holDvd_int_eq_true +#print axioms L4vRefX64.Rel.holListSet_eq +#print axioms L4vRefX64.Rel.holListMap_eq +#print axioms L4vRefX64.Rel.holListAppend_eq +#print axioms L4vRefX64.Rel.holListTake_eq +#print axioms L4vRefX64.Rel.holListDrop_eq +#print axioms L4vRefX64.Rel.holListFilter_eq +#print axioms L4vRefX64.Rel.holListRev_eq +#print axioms L4vRefX64.Rel.holListZip_eq +#print axioms L4vRefX64.Rel.holListReplicate_eq +#print axioms L4vRefX64.Rel.holListUpdate_eq +#print axioms L4vRefX64.Rel.holListButlast_eq +#print axioms L4vRefX64.Rel.holSize_list +#print axioms L4vRefX64.Rel.holSize_fin +#print axioms L4vRefX64.Rel.holSize_bv +#print axioms L4vRefX64.Rel.holSize_nat +#print axioms L4vRefX64.Rel.optRel_funRel +#print axioms L4vRefX64.Rel.listRel_funRel +#print axioms L4vRefX64.Rel.listRel_eq +#print axioms L4vRefX64.Rel.setRel_funRel +#print axioms L4vRefX64.Rel.setRel_eq +#print axioms L4vRefX64.Rel.mrel_mono +#print axioms L4vRefX64.Rel.mrel_conseq_res +#print axioms L4vRefX64.Rel.mrel_weaken_pre +#print axioms L4vRefX64.Rel.mrel_return +#print axioms L4vRefX64.Rel.mrel_pure +#print axioms L4vRefX64.Rel.mrel_bind +#print axioms L4vRefX64.Rel.mrel_kbind +#print axioms L4vRefX64.Rel.mrel_get +#print axioms L4vRefX64.Rel.mrel_put +#print axioms L4vRefX64.Rel.mrel_gets +#print axioms L4vRefX64.Rel.mrel_modify +#print axioms L4vRefX64.Rel.mrel_fail +#print axioms L4vRefX64.Rel.mrel_assert +#print axioms L4vRefX64.Rel.mrel_stateAssert +#print axioms L4vRefX64.Rel.mrel_assertOpt +#print axioms L4vRefX64.Rel.mrel_getsThe +#print axioms L4vRefX64.Rel.mrel_getsMap +#print axioms L4vRefX64.Rel.mrel_select +#print axioms L4vRefX64.Rel.mrel_selectF +#print axioms L4vRefX64.Rel.mrel_when +#print axioms L4vRefX64.Rel.mrel_unless +#print axioms L4vRefX64.Rel.mrel_if +#print axioms L4vRefX64.Rel.mrel_liftM +#print axioms L4vRefX64.Rel.mrel_maybeM +#print axioms L4vRefX64.Rel.mrel_mapM +#print axioms L4vRefX64.Rel.mrel_mapMx +#print axioms L4vRefX64.Rel.mrel_zipWithM +#print axioms L4vRefX64.Rel.mrel_zipWithMx +#print axioms L4vRefX64.Rel.mrel_whileLoop +#print axioms L4vRefX64.Rel.mrele_returnOk +#print axioms L4vRefX64.Rel.mrele_pure +#print axioms L4vRefX64.Rel.mrele_throwError +#print axioms L4vRefX64.Rel.mrele_throw +#print axioms L4vRefX64.Rel.mrele_liftE +#print axioms L4vRefX64.Rel.mrele_bindE +#print axioms L4vRefX64.Rel.mrele_kbindE +#print axioms L4vRefX64.Rel.mrele_whenE +#print axioms L4vRefX64.Rel.mrele_unlessE +#print axioms L4vRefX64.Rel.mrele_assertE +#print axioms L4vRefX64.Rel.mrele_throwOpt +#print axioms L4vRefX64.Rel.mrele_catch +#print axioms L4vRefX64.Rel.mrele_handleE' +#print axioms L4vRefX64.Rel.mrele_handleE +#print axioms L4vRefX64.Rel.mrele_liftME +#print axioms L4vRefX64.Rel.mrele_mapME +#print axioms L4vRefX64.Rel.mrele_mapMEx +#print axioms L4vRefX64.Rel.mrele_if +#print axioms L4vRefX64.Rel.lookup_oreturn +#print axioms L4vRefX64.Rel.lookup_ofail +#print axioms L4vRefX64.Rel.lookup_obind +#print axioms L4vRefX64.Rel.lookup_oassert +#print axioms L4vRefX64.Rel.lookup_optMap +#print axioms L4vRefX64.Rel.mrelStep_bind_mem_both +#print axioms L4vRefX64.Rel.mrelStep_bind_mem +#print axioms L4vRefX64.Rel.nonDet_bind_gets_at +#print axioms L4vRefX64.Rel.nonDet_bind_singleton_at +#print axioms L4vRefX64.Rel.hol_bind_singleton_at +#print axioms L4vRefX64.Rel.holBindE_assoc +#print axioms L4vRefX64.Rel.mrelStep_bindE_mem_both +#print axioms L4vRefX64.Rel.mrelStep_bindE_mem +#print axioms L4vRefX64.Rel.mrelStep_kbindE_mem +#print axioms L4vRefX64.Rel.mrelStep_liftE +#print axioms L4vRefX64.Rel.mrelStep_handleE_mem +#print axioms L4vRefX64.Rel.mrelStep_catch_mem + +-- L4vRefX64.Rel.State +#print axioms L4vRefX64.Rel.BaseCarriers.noVirtObjects +#print axioms L4vRefX64.Rel.StateRel.baseCarriers_iff diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Patched.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Patched.lean new file mode 100644 index 000000000..e82d7ec7e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Patched.lean @@ -0,0 +1,506 @@ +import Fl4Spec +import L4vRefX64.Spec.ArchDecode_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.ArchFault_A +import L4vRefX64.Spec.TcbAcc_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Retype_A +import L4vRefX64.Spec.MiscMachine_A +import L4vRefX64.Rel.Invocation +import L4vRefX64.Rel.Config +import L4vRefX64.Rel.Monad +import L4vRefX64.Equiv.Structures +import Mathlib.Tactic.IntervalCases + +namespace L4vRefX64.Patched + +open L4vRefX64.Prim +open L4vRefX64.Spec +open L4vRefX64.Rel +open Classical + +noncomputable section + +/-- Change the user-mode selectors to the FL4 GDT layout and preserve the other fields. -/ +def newContext : MachineOps.user_context := + match Machine_A.new_context with + | .UserContext fpu regs => + .UserContext fpu (holFunUpd (holFunUpd regs .CS 0x33) .SS 0x2B) + +private theorem upstream_cs : MachineTypes.selCS3 = 0x2B := by + simp [MachineTypes.selCS3, MachineTypes.gdtToSel_masked, MachineTypes.gdtToSel, + holFromEnum, HolEnum.enumList, MachineTypes.enum_gdtslot, holTheIndex] + rfl + +private theorem upstream_ss : MachineTypes.selDS3 = 0x33 := by + simp [MachineTypes.selDS3, MachineTypes.gdtToSel_masked, MachineTypes.gdtToSel, + holFromEnum, HolEnum.enumList, MachineTypes.enum_gdtslot, holTheIndex] + rfl + +/-- The upstream and FL4 initial contexts set the two selectors to opposite values. +The patched context uses the FL4 selector values. -/ +theorem newContext_selectors_delta : + MachineOps.user_context.user_regs Machine_A.new_context .CS = 0x2B ∧ + MachineOps.user_context.user_regs Machine_A.new_context .SS = 0x33 ∧ + MachineOps.user_context.user_regs newContext .CS = Fl4Spec.newContext.userRegs .cs ∧ + MachineOps.user_context.user_regs newContext .SS = Fl4Spec.newContext.userRegs .ss := by + simp [newContext, Machine_A.new_context, MachineOps.user_context.user_regs, + MachineOps.case_user_context, holFunUpd, Function.update, upstream_cs, upstream_ss, + show Fl4Spec.newContext.userRegs .cs = 0x33 from rfl, + show Fl4Spec.newContext.userRegs .ss = 0x2B from rfl] + +theorem newContext_equiv {RestRel} (hop : OpaqueRel RestRel) : + embUserContext newContext = Fl4Spec.newContext := by + unfold newContext Fl4Spec.newContext Machine_A.new_context embUserContext + rw [hop.fpuNullState_eq] + apply congrArg (Fl4Spec.UserContext.mk MachineOps.FPUNullState) + funext register + cases register <;> + simp [embUserRegs, unembRegister, holFunUpd, Function.update, HolZero.zeroVal, + HolNumeral.ofNatVal, Fl4Spec.selCS3, Fl4Spec.selDS3] + +def default_object (type : Structures_A.apiobject_type) (device : Bool) (bits : Nat) + (domain : BitVec 8) : Structures_A.kernel_object := + match type with + | .TCBObject => + .TCB { Structures_A.default_tcb domain with tcb_arch := ⟨newContext, false, ()⟩ } + | _ => Retype_A.default_object type device bits domain + +def obj_bits_api (type : Structures_A.apiobject_type) (bits : Nat) : Nat := + match type with + | .NotificationObject => 6 + | _ => Retype_A.obj_bits_api type bits + +/-- Extend the checked base decoder with FL4's architecture-relative object codes. -/ +def decodeObjectType (n : Nat) : Option Fl4Spec.AObjectType := + match n with + | 7 => some .vcpuObj + | 8 => some .eptPml4Obj + | 9 => some .eptPdptObj + | 10 => some .eptPdObj + | 11 => some .eptPtObj + | _ => (ArchDecode_A.arch_data_to_obj_type n).map embAObjectType + +theorem decodeObjectType_common (n : Nat) (h : n ≤ 6) : + (ArchDecode_A.arch_data_to_obj_type n).map embAObjectType = Fl4Spec.archDataToObjType n ∧ + decodeObjectType n = Fl4Spec.archDataToObjType n := by + interval_cases n <;> simp [ArchDecode_A.arch_data_to_obj_type, holEq, holIf, + HolNumeral.ofNatVal, HolOne.oneVal, HolZero.zeroVal, decodeObjectType, embAObjectType, + Fl4Spec.archDataToObjType] + +/-- Codes 7 through 11 are absent in the checked reference and admitted by FL4. -/ +theorem decodeObjectType_codes7to11_delta (n : Nat) (lo : 7 ≤ n) (hi : n ≤ 11) : + ArchDecode_A.arch_data_to_obj_type n = none ∧ + decodeObjectType n = Fl4Spec.archDataToObjType n ∧ Fl4Spec.archDataToObjType n ≠ none := by + interval_cases n <;> simp [ArchDecode_A.arch_data_to_obj_type, holEq, holIf, + HolNumeral.ofNatVal, HolOne.oneVal, HolZero.zeroVal, decodeObjectType, + Fl4Spec.archDataToObjType] + +def ipcBufferAddress (isReceiver : Bool) (buffer : BitVec 64) : + Structures_A.cap → Option (BitVec 64) + | .ArchObjectCap (.PageCap _ ptr rights _ size _) => + holIf (holDisj (holLe VMRights_A.vm_read_write rights) + (holConj (holLe VMRights_A.vm_read_only rights) (holNot isReceiver))) + (some (HolAdd.addVal ptr (holWordAnd buffer (holWordMask (MachineTypes.pageBitsForSize size))))) + none + | _ => none + +/-- The buffer-frame slot is the only change in this definition. -/ +def lookupIpcBufferAt {Z : Type} [Nonempty Z] [Deterministic_A.state_ext_class Z] + (slot : Nat) (isReceiver : Bool) (thread : BitVec 64) : + HolNonDet (Structures_A.state Z) (Option (BitVec 64)) := + holBind (KHeap_A.thread_get Structures_A.tcb_ext.tcb_ipc_buffer thread) fun buffer => + holBind (holReturn (thread, Structures_A.tcb_cnode_index slot)) fun cslot => + holBind (CSpaceAcc_A.get_cap cslot) fun cap => holReturn (ipcBufferAddress isReceiver buffer cap) + +def lookupIpcBuffer {Z : Type} [Nonempty Z] [Deterministic_A.state_ext_class Z] := + lookupIpcBufferAt (Z := Z) 2 + +theorem lookupIpcBuffer_slot_delta {Z : Type} [Nonempty Z] [Deterministic_A.state_ext_class Z] + (isReceiver : Bool) (thread : BitVec 64) : + ArchVSpace_A.lookup_ipc_buffer (tv_z := Z) isReceiver thread = + lookupIpcBufferAt 4 isReceiver thread ∧ + lookupIpcBuffer (Z := Z) isReceiver thread = lookupIpcBufferAt 2 isReceiver thread := by + constructor + · unfold ArchVSpace_A.lookup_ipc_buffer lookupIpcBufferAt + congr + funext buffer + congr + funext cslot + congr + funext cap + cases cap with + | ArchObjectCap arch => + cases arch with + | PageCap => + simp only [Structures_A.case_cap, Arch_Structs_A.case_arch_cap, ipcBufferAddress] + unfold holIf + split <;> rfl + | _ => rfl + | _ => rfl + · rfl + +def reply_from_kernel {Z : Type} [Nonempty Z] [Deterministic_A.state_ext_class Z] + (thread : BitVec 64) (x : BitVec 64 × List (BitVec 64)) : + HolNonDet (Structures_A.state Z) Unit := + holCaseProd (fun msg_label msg => + holBind (lookupIpcBuffer true thread) fun ipc_buffer => + holBind (KHeap_A.as_user thread (MachineOps.setRegister Machine_A.badge_register 0)) + (holKBind (holBind (TcbAcc_A.set_mrs thread ipc_buffer msg) fun len => + TcbAcc_A.set_message_info thread (Structures_A.message_info.MI len 0 0 msg_label)))) x + +/-- The retained X64 notification object uses five size bits. The FL4 MCS model uses six. -/ +theorem notificationBits_delta : + Arch_Structs_A.ntfn_bits = 5 ∧ Fl4Spec.ntfnBits = 6 := + ⟨rfl, rfl⟩ + +/-- The high ASID index widens by eight bits while the low index remains nine bits. -/ +theorem asidWidths_delta : + MiscMachine_A.asid_high_bits = 3 ∧ Fl4Spec.asidHighBits = 11 ∧ + MiscMachine_A.asid_low_bits = 9 ∧ Fl4Spec.asidLowBits = 9 ∧ + MiscMachine_A.asid_bits = 12 ∧ Fl4Spec.asidBits = 20 := + ⟨rfl, rfl, rfl, rfl, rfl, rfl⟩ + +/-- The common platform retains the same 12-bit PCID field in CR3. -/ +theorem cr3Mask_preserved : + (ArchVSpace_A.cr3_addr_mask : BitVec 64) = Fl4Spec.cr3AddrMask := + rfl + +/-- The port embeds the two-field HOL I/O capability with an empty VCPU owner. -/ +theorem ioPortOwner_delta (first last : Fl4Spec.IoPort) : + Rel.embArchCap (.IOPortCap first last) = .ioPortCap first last none := + rfl + +/-- The reference TCB has no EPT slot. In the base embedding, the additional slot is empty. -/ +theorem tcbEptSlot_delta (tcb : Structures_A.tcb) : + Structures_A.tcb_cnode_map tcb (Structures_A.tcb_cnode_index 5) = none ∧ + Fl4Spec.tcbCnodeMap (Rel.embTcb tcb) (Fl4Spec.tcbCnodeIndex 5) = some .nullCap := by + have h0 : Structures_A.tcb_cnode_index 5 ≠ Structures_A.tcb_cnode_index 0 := by decide + have h1 : Structures_A.tcb_cnode_index 5 ≠ Structures_A.tcb_cnode_index 1 := by decide + have h2 : Structures_A.tcb_cnode_index 5 ≠ Structures_A.tcb_cnode_index 2 := by decide + have h3 : Structures_A.tcb_cnode_index 5 ≠ Structures_A.tcb_cnode_index 3 := by decide + have h4 : Structures_A.tcb_cnode_index 5 ≠ Structures_A.tcb_cnode_index 4 := by decide + constructor + · simp [Structures_A.tcb_cnode_map, holFunUpd, Function.update, + HolZero.zeroVal, HolOne.oneVal, HolNumeral.ofNatVal, h0, h1, h2, h3, h4] + · simp [Fl4Spec.tcbCnodeMap, Rel.embTcb] + +/-- Replace the legacy VM fault label and keep the upstream message payload and state. -/ +def makeArchFaultMsg {Z : Type} [Nonempty Z] [Deterministic_A.state_ext_class Z] + (fault : Machine_A.arch_fault) (thread : BitVec 64) : + HolNonDet (Structures_A.state Z) (BitVec 64 × List (BitVec 64)) := + holBind (ArchFault_A.make_arch_fault_msg fault thread) fun msg => holReturn (6, msg.2) + +theorem makeArchFaultMsg_delta {Z : Type} [Nonempty Z] [Deterministic_A.state_ext_class Z] + (vaddr thread : BitVec 64) (words : List (BitVec 64)) : + ArchFault_A.make_arch_fault_msg (tv_z := Z) (.VMFault vaddr words) thread = + holBind (KHeap_A.as_user thread MachineOps.getRestartPC) (fun pc => holReturn (5, pc :: vaddr :: words)) ∧ + makeArchFaultMsg (Z := Z) (.VMFault vaddr words) thread = + holBind (KHeap_A.as_user thread MachineOps.getRestartPC) (fun pc => holReturn (6, pc :: vaddr :: words)) := by + constructor + · rfl + · funext state + apply Prod.ext + · ext ⟨msg, next⟩ + simp [makeArchFaultMsg, ArchFault_A.make_arch_fault_msg, holBind, holReturn, and_assoc, + and_comm] + · simp [makeArchFaultMsg, ArchFault_A.make_arch_fault_msg, holBind, holReturn] + +/-- The pinned Rust build's single-domain configuration differs from the PC99 reference. +This comparison does not identify that build with the opaque Lean global. -/ +theorem compiledNumDomains_delta (h : Fl4Spec.numDomains = 1) : ¬ Rel.ConfigRel := by + intro cfg + exact Nat.one_ne_zero (by + have heq := cfg.numDomains_eq + change Fl4Spec.numDomains = 16 at heq + omega) + +/-- Promote the native ASID table to the widened indexing used by FL4. -/ +def widen_asid_table (table : BitVec 3 → Option (BitVec 64)) : + BitVec 11 → Option (BitVec 64) := + fun i => if i.toNat < 8 then table (i.setWidth 3) else none + +/-- l4v: Deterministic_A.free_asid_select over the widened ASID table. -/ +def free_asid_select_p (table : BitVec 11 → Option (BitVec 64)) : BitVec 11 := + (holHd (holListFilter + (holCaseProd fun i entry => holConj (holLe i (2 ^ (11 : Nat) - 1)) (holEq entry none)) + (holAssocs table))).1 + +/-- A full upstream ASID table has no free index. Its FL4 embedding still +has free indices in the widened range, beginning at high index eight. -/ +theorem asidFreeIndex_delta (arch : Arch_Structs_A.arch_state) (platform : Fl4Spec.X64Platform) + (hfull : ∀ i, arch.x64_asid_table i ≠ none) : + HolNeg.negVal (holDom arch.x64_asid_table) = (∅ : Set (BitVec 3)) ∧ + (8 : Fl4Spec.AsidHighIndex) ∈ (Fl4Spec.dom (Rel.embArchState platform arch).x64AsidTable)ᶜ ∧ + ¬ Rel.BaseAsid ((Fl4Spec.ucast 64 (8 : Fl4Spec.AsidHighIndex)) <<< Fl4Spec.asidLowBits) := by + refine ⟨?_, ?_, by change ¬(4096 : Nat) < 2 ^ 12; decide⟩ + · ext i + change (¬ arch.x64_asid_table i ≠ none) ↔ i ∈ (∅ : Set (BitVec 3)) + simp [hfull] + · change ¬(if (8 : Fl4Spec.AsidHighIndex).toNat < 8 + then arch.x64_asid_table ((8 : Fl4Spec.AsidHighIndex).setWidth 3) else none) ≠ none + rw [ite_eq_right (by decide)] + simp + +/-- Extend the reference TCB slots with the empty EPT root of a base FL4 TCB. -/ +def tcb_cnode_map (tcb : Structures_A.tcb) (index : Fl4Spec.CnodeIndex) : Option Structures_A.cap := + if index = Fl4Spec.tcbCnodeIndex 5 then some .NullCap + else Structures_A.tcb_cnode_map tcb index + +theorem patched_tcbCnodeMap_eq (tcb : Structures_A.tcb) (index : Fl4Spec.CnodeIndex) : + Fl4Spec.tcbCnodeMap (embTcb tcb) index = (tcb_cnode_map tcb index).map embCap := by + by_cases h : index = Fl4Spec.tcbCnodeIndex 5 + · subst index + simp [tcb_cnode_map, Fl4Spec.tcbCnodeMap, embTcb, embCap, Function.update] + · rw [tcb_cnode_map, ite_eq_right h] + exact Equiv.Structures.tcbCnodeMap_eq_nonExt tcb index h + +/-- Decode the FL4 ABI's positions into the labels shared with the reference. -/ +def invocation_type (word : Fl4Spec.Data) : InvocationLabels_H.invocation_label := + match (Fl4Spec.InvocationLabel.fl4Numbering[Fl4Spec.dataToNat word]?).bind id with + | some label => unembInvocationLabel label + | none => .GenInvocationLabel .InvalidInvocation + +private theorem fl4Numbering_at_fromEnum (label : Fl4Spec.InvocationLabel) : + Fl4Spec.InvocationLabel.fl4Numbering[label.fromEnum]? = some (some label) := by + cases label with + | genInvocationLabel label => cases label <;> decide + | archInvocationLabel label => cases label <;> decide + +private theorem fl4Numbering_length : Fl4Spec.InvocationLabel.fl4Numbering.length = 72 := by decide + +private theorem fl4Numbering_at + (n : Nat) (h : n < 72) : + ((Fl4Spec.InvocationLabel.fl4Numbering[n]?).bind id).all + (fun label => decide (label.fromEnum = n)) = true := by + have all : ∀ index < 72, + ((Fl4Spec.InvocationLabel.fl4Numbering[index]?).bind id).all + (fun label => decide (label.fromEnum = index)) = true := by decide + exact all n h + +theorem invocationType_equiv (word : Fl4Spec.Data) : + embInvocationLabel (invocation_type word) = Fl4Spec.invocationType word := by + unfold invocation_type Fl4Spec.invocationType + by_cases h : ∃ label : Fl4Spec.InvocationLabel, label.fromEnum = Fl4Spec.dataToNat word + · rw [ite_eq_left h] + obtain ⟨label, hlabel⟩ := h + unfold Fl4Spec.InvocationLabel.toEnum + rw [← hlabel, fl4Numbering_at_fromEnum] + exact embInvocationLabel_unemb label + · rw [ite_eq_right h] + split + · rename_i label hl + exfalso + apply h + refine ⟨label, ?_⟩ + by_cases hlt : Fl4Spec.dataToNat word < 72 + · have hn := fl4Numbering_at (Fl4Spec.dataToNat word) hlt + rw [hl] at hn + simpa using hn + · rw [List.getElem?_eq_none (by rw [fl4Numbering_length]; omega)] at hl + cases hl + · rfl + +private theorem holIndex_witness {α : Type} [Nonempty α] (xs : List α) (label : α) + (h : label ∈ xs) : xs[holTheIndex xs label]? = some label := by + induction xs with + | nil => exact (List.not_mem_nil h).elim + | cons head tail ih => + by_cases he : head = label + · subst head + simp [holTheIndex] + · have ht : label ∈ tail := (List.mem_cons.mp h).resolve_left (Ne.symm he) + simp [holTheIndex, he, ih ht] + +private theorem referenceLabel_mem (label : InvocationLabels_H.invocation_label) : + label ∈ InvocationLabels_H.enum_invocation_label := by + have h : embInvocationLabel label ∈ Fl4Spec.InvocationLabel.enum := by + cases label with + | GenInvocationLabel label => cases label <;> decide + | ArchInvocationLabel label => cases label <;> decide + rw [← invocationLabels_enum_eq] at h + obtain ⟨someLabel, hmem, heq⟩ := List.mem_map.mp h + exact embInvocationLabel_injective heq ▸ hmem + +theorem invocationLabel_numbering_delta (label : InvocationLabels_H.invocation_label) : + let upstream := BitVec.ofNat 64 (holFromEnum label) + let abi := BitVec.ofNat 64 (embInvocationLabel label).fromEnum + InvocationLabels_A.invocation_type upstream = label ∧ + invocation_type abi = label ∧ + Fl4Spec.invocationType abi = embInvocationLabel label := by + have hi := holIndex_witness InvocationLabels_H.enum_invocation_label label (referenceLabel_mem label) + have hindex : holFromEnum label < InvocationLabels_H.enum_invocation_label.length := by + change holTheIndex InvocationLabels_H.enum_invocation_label label < + InvocationLabels_H.enum_invocation_label.length + by_contra hn + rw [List.getElem?_eq_none (by omega)] at hi + cases hi + have hsz : InvocationLabels_H.enum_invocation_label.length = 59 := rfl + have hH : Machine_A.data_to_nat (BitVec.ofNat 64 (holFromEnum label)) = holFromEnum label := by + change holFromEnum label % 2 ^ 64 = holFromEnum label + apply Nat.mod_eq_of_lt + omega + have hLBound : (embInvocationLabel label).fromEnum < 72 := by + cases label with + | GenInvocationLabel label => cases label <;> decide + | ArchInvocationLabel label => cases label <;> decide + have hL : Fl4Spec.dataToNat (BitVec.ofNat 64 (embInvocationLabel label).fromEnum) = + (embInvocationLabel label).fromEnum := by + change (embInvocationLabel label).fromEnum % 2 ^ 64 = (embInvocationLabel label).fromEnum + apply Nat.mod_eq_of_lt + omega + constructor + · unfold InvocationLabels_A.invocation_type + rw [hH] + have hex : holEx (fun v : InvocationLabels_H.invocation_label => + holEq (holFromEnum v) (holFromEnum label)) = true := + (holEx_eq_true _).mpr ⟨label, (holEq_eq_true _ _).mpr rfl⟩ + rw [hex, holIf_true] + unfold holToEnum holNth + change holTheOpt InvocationLabels_H.enum_invocation_label[holTheIndex + InvocationLabels_H.enum_invocation_label label]? = label + rw [hi] + rfl + · constructor + · unfold invocation_type + rw [hL, fl4Numbering_at_fromEnum] + exact unembInvocationLabel_emb label + · rw [← invocationType_equiv] + unfold invocation_type + rw [hL, fl4Numbering_at_fromEnum] + exact embInvocationLabel_unemb _ + +theorem cnodeRevoke_label_delta : + InvocationLabels_A.invocation_type (18 : BitVec 64) = .GenInvocationLabel .CNodeRevoke ∧ + Fl4Spec.invocationType (25 : BitVec 64) = .genInvocationLabel .cnodeRevoke := by + have h := invocationLabel_numbering_delta (.GenInvocationLabel .CNodeRevoke) + have hidx : holFromEnum (InvocationLabels_H.invocation_label.GenInvocationLabel .CNodeRevoke) = 18 := by + simp [holFromEnum, HolEnum.enumList, InvocationLabels_H.enum_invocation_label, + InvocationLabels_H.enum_gen_invocation_labels, holListAppend, holListMap, holTheIndex] + refine ⟨?_, h.2.2⟩ + change InvocationLabels_A.invocation_type (BitVec.ofNat 64 18) = _ + rw [← hidx] + exact h.1 + + +/-- The platform capability has no upstream state field. Take the FL4 platform +flag as an input and preserve the upstream program for supported page sizes. -/ +def create_mapping_entries {ZH : Type} [Nonempty ZH] [Deterministic_A.state_ext_class ZH] + (hugePages : Bool) (base vptr : BitVec 64) (size : MachineTypes.vmpage_size) + (rights : Set CapRights_A.rights) (attr : Set ArchVMAttributes_A.vm_attribute) + (root : BitVec 64) : + HolNonDet (Structures_A.state ZH) + (Sum ExceptionTypes_A.syscall_error (Arch_Structs_A.vm_page_entry × BitVec 64)) := + match size with + | .X64HugePage => + if hugePages then ArchVSpace_A.create_mapping_entries base vptr size rights attr root + else holThrowError .IllegalOperation + | _ => ArchVSpace_A.create_mapping_entries base vptr size rights attr root + +/-- On a platform without 1 GiB pages, FL4 returns IllegalOperation without +walking the page tables. The original upstream function can return a mapping +when its PDPT lookup succeeds. -/ +theorem hugePages_delta {ZH ZL : Type} [Nonempty ZH] [Deterministic_A.state_ext_class ZH] + (sH sH' : Structures_A.state ZH) (sL : Fl4Spec.State ZL) + (base vptr root slot : BitVec 64) + (rightsH : Set CapRights_A.rights) (attrH : Set ArchVMAttributes_A.vm_attribute) + (rightsL : Fl4Spec.VMRights) (attrL : Fl4Spec.VMAttributes) + (hdisabled : sL.archState.x64Plat.hugePages = false) + (hslot : (.inr slot, sH') ∈ + (Exceptions_A.lookup_error_on_failure false + (ArchVSpaceAcc_A.lookup_pdpt_slot root vptr) sH).1) : + (Sum.inr (.VMPDPTE (.HugePagePDPTE base (attrH \ ArchVSpace_A.attr_mask') rightsH), slot), sH') ∈ + (ArchVSpace_A.create_mapping_entries base vptr .X64HugePage rightsH attrH root sH).1 ∧ + create_mapping_entries false base vptr .X64HugePage rightsH attrH root sH = + ({(.inl .IllegalOperation, sH)}, false) ∧ + (Fl4Spec.createMappingEntries base vptr .x64HugePage rightsL attrL root).run sL = + ({(.error .illegalOperation, sL)}, False) := by + refine ⟨?_, rfl, ?_⟩ + · simp only [ArchVSpace_A.create_mapping_entries, holFunApp, holBindE, holBind] + exact ⟨(.inr slot, sH'), hslot, by simp [holReturnOk, holReturn, HolSub.subVal]⟩ + · unfold Fl4Spec.createMappingEntries + let next : Bool → Fl4Spec.SEMonad ZL (Fl4Spec.VMPageEntry × Fl4Spec.ObjRef) := fun huge => do + Fl4Spec.NonDetE.unlessE huge (Fl4Spec.NonDetE.throwError .illegalOperation) + let p ← Fl4Spec.lookupErrorOnFailure false (Fl4Spec.lookupPdptSlot root vptr) + Fl4Spec.NonDetE.returnOk (.vmPDPTE (.hugePagePDPTE base (attrL \ Fl4Spec.attrMask') rightsL), p) + have hnext (st : Fl4Spec.State ZL) : (next false).run st = + ({(.error .illegalOperation, st)}, False) := by + change Fl4Spec.NonDet.bind (Fl4Spec.NonDet.pure + (.error Fl4Spec.SyscallError.illegalOperation : Except Fl4Spec.SyscallError Unit)) + (ExceptT.bindCont _) st = _ + simp [Fl4Spec.NonDet.bind, Fl4Spec.NonDet.pure, ExceptT.bindCont, Pure.pure] + change Fl4Spec.NonDet.bind + (Fl4Spec.NonDet.bind + (Fl4Spec.NonDet.gets (fun s : Fl4Spec.State ZL => s.archState.x64Plat.hugePages)) + (fun huge => Fl4Spec.NonDet.pure (.ok huge))) + (ExceptT.bindCont next) sL = _ + simp [Fl4Spec.NonDet.bind, Fl4Spec.NonDet.gets, Fl4Spec.NonDet.pure, + ExceptT.bindCont, hdisabled] + exact hnext sL + +/-- A running VM skips the timeout-handler branch that unmodified upstream +takes after successful round-robin and timeout-handler reads. -/ +theorem endTimeslice_runningVM_delta {ZH ZL : Type} + [Nonempty ZH] [Deterministic_A.state_ext_class ZH] [Fl4Spec.StateExt ZL] + (sH : Structures_A.state ZH) (sL : Fl4Spec.State ZL) + (hroundH : Sporadic_A.is_round_robin sH.cur_sc sH = ({(false, sH)}, false)) + (hvalid : Ipc_A.is_valid_timeout_handler sH.cur_thread sH = ({(true, sH)}, false)) + (hroundL : Fl4Spec.isRoundRobin sL.curSc sL = ({(false, sL)}, False)) + (hvm : Fl4Spec.getThreadState sL.curThread sL = ({(.runningVM, sL)}, False)) : + Ipc_A.end_timeslice true sH = + holBind (KHeap_A.get_sched_context sH.cur_sc) (fun sc => + Ipc_A.handle_timeout sH.cur_thread (.Timeout sc.sc_badge)) sH ∧ + Fl4Spec.endTimeslice true sL = (do + let ready ← Fl4Spec.getScRefillReady sL.curSc + let sufficient ← Fl4Spec.getScRefillSufficient sL.curSc 0 + if ready ∧ sufficient then Fl4Spec.tcbSchedAction Fl4Spec.tcbSchedAppend sL.curThread + else Fl4Spec.postpone sL.curSc) sL := by + constructor + · unfold Ipc_A.end_timeslice + rw [hol_bind_singleton_at _ (show holGets _ sH = _ from rfl), + hol_bind_singleton_at _ hroundH, + hol_bind_singleton_at _ (show holGets _ sH = _ from rfl), + hol_bind_singleton_at _ hvalid] + rfl + · unfold Fl4Spec.endTimeslice + simp only [Bind.bind, nonDet_bind_gets_at] + rw [nonDet_bind_singleton_at _ hroundL, nonDet_bind_gets_at, + nonDet_bind_singleton_at _ hvm] + simp only [↓reduceIte] + change Fl4Spec.NonDet.bind (Fl4Spec.NonDet.pure false) _ sL = _ + rw [nonDet_bind_singleton_at _ (show Fl4Spec.NonDet.pure false sL = _ from rfl)] + simp only [Bool.false_eq_true, and_false, ↓reduceIte] + + +/-- The same finalization sequence returns a five-slot upstream TCB zombie +and a six-slot FL4 TCB zombie. The sixth slot holds the EPT root. -/ +theorem finaliseTcbZombieSlots_delta {ZH ZL : Type} + [Nonempty ZH] [Deterministic_A.state_ext_class ZH] [Fl4Spec.StateExt ZL] + (t : Fl4Spec.ObjRef) : + CSpace_A.finalise_cap (tv_z := ZH) (.ThreadCap t) true = + (holBind (IpcCancel_A.unbind_notification t) fun _ => + holBind (SchedContext_A.unbind_from_sc t) fun _ => + holBind (SchedContext_A.suspend t) fun _ => + holBind (ArchVSpace_A.prepare_thread_delete t) fun _ => + holReturn (.Zombie t none 5, .NullCap)) ∧ + Fl4Spec.finaliseCap (Z := ZL) (.threadCap t) true = (do + Fl4Spec.unbindNotification t + Fl4Spec.unbindFromSc t + Fl4Spec.suspend t + Fl4Spec.prepareThreadDelete t + pure (.zombie t none 6, .nullCap)) := by + exact ⟨rfl, rfl⟩ + + +/-- The original abstract reference fixes the maximum period at one hour. +The frozen FL4 specification reads its maximum period from the platform. -/ +theorem maxPeriodUs_delta : + Time.MAX_PERIOD_US = (3600000000 : BitVec 64) ∧ + Fl4Spec.MAX_PERIOD_US = Fl4Spec.timeConsts.maxPeriodUs := + ⟨rfl, rfl⟩ + + +end + +end L4vRefX64.Patched diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Prim.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Prim.lean new file mode 100644 index 000000000..d6a5c5a9e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Prim.lean @@ -0,0 +1,507 @@ +/- +Minimal-TCB shallow embedding of Isabelle/HOL + l4v library primitives used by +the mechanically emitted `L4vRefX64.Spec.*` theories (from `aspec-full.jsonl`). + +Every combinator mirrors its Isabelle/HOL definition literally: +- `HOL.bool` is `Bool` (using `Classical.propDecidable` for `=`, `∀`, `∃`, `∈`, `<`, `≤`, `∣`). +- `Nondet_Monad` is literally `σ → Set (α × σ) × Bool` (and exception monad uses `Sum ε α`). +- `Reader_Option_Monad` is literally `σ → Option α`. +- `Word.word n` is `BitVec n`; `Numeral_Type.5` is `Fin 5`. +- `THE` / `THE_default` / `Eps` / `undefined` use `Classical.choice`. +-/ +import Mathlib.Data.Set.Basic +import Mathlib.Data.Set.Image +import Mathlib.Data.Nat.Find +import Mathlib.Logic.Relation +import Mathlib.Logic.Function.Basic +import Mathlib.Order.CompleteLattice.Basic + +namespace L4vRefX64 +namespace Prim + +open Classical + +noncomputable section + +/-! ## Core HOL logic & choice -/ + +abbrev HolNonDet (σ α : Type) := σ → Set (α × σ) × Bool +abbrev HolLookup (σ α : Type) := σ → Option α + +def holUndefined {α : Type} [h : Nonempty α] : α := Classical.choice h + +def holThe {α : Type} [Nonempty α] (P : α → Bool) : α := + if h : ∃! x, P x = true then Classical.choose h else holUndefined + +def holTheDefault {α : Type} (d : α) (P : α → Bool) : α := + if h : ∃! x, P x = true then Classical.choose h else d + +def holEps {α : Type} [Nonempty α] (P : α → Bool) : α := + if h : ∃ x, P x = true then Classical.choose h else holUndefined + +def holEq {α : Type} (a b : α) : Bool := decide (a = b) +def holNotEq {α : Type} (a b : α) : Bool := decide (a ≠ b) +def holAll {α : Type} (P : α → Bool) : Bool := decide (∀ x, P x = true) +def holEx {α : Type} (P : α → Bool) : Bool := decide (∃ x, P x = true) +def holEx1 {α : Type} (P : α → Bool) : Bool := decide (∃! x, P x = true) +def holConj (a b : Bool) : Bool := a && b +def holDisj (a b : Bool) : Bool := a || b +def holNot (a : Bool) : Bool := !a +def holImp (a b : Bool) : Bool := (!a) || b +def holIf {α : Type} (c : Bool) (t e : α) : α := if c = true then t else e +def holLet {α β : Type} (x : α) (f : α → β) : β := f x + +/-! ## Inductive / Wellfounded (`lfp`, `accp`) -/ + +/-- Complete-lattice `lfp` on Bool-valued predicates (`α → Bool`, `α → β → Bool`, etc.). -/ +class HolCompleteLattice (α : Type) where + holLe : α → α → Prop + holInfSet : Set α → α + holLfp : (α → α) → α + holBot : α + holTop : α + holInf : α → α → α + holSup : α → α → α + +instance : HolCompleteLattice Bool where + holLe x y := x = true → y = true + holInfSet S := decide (∀ x ∈ S, x = true) + holLfp F := decide (∀ x : Bool, (F x = true → x = true) → x = true) + holBot := false + holTop := true + holInf := (· && ·) + holSup := (· || ·) + +instance {α : Type} : HolCompleteLattice (Set α) where + holLe S T := S ⊆ T + holInfSet := sInf + holLfp F := sInf {S : Set α | F S ⊆ S} + holBot := ∅ + holTop := Set.univ + holInf := (· ∩ ·) + holSup := (· ∪ ·) + +instance {α β : Type} [HolCompleteLattice β] : HolCompleteLattice (α → β) where + holLe f g := ∀ a, HolCompleteLattice.holLe (f a) (g a) + holInfSet S := fun a => HolCompleteLattice.holInfSet {b | ∃ f ∈ S, f a = b} + holLfp F := fun a => + HolCompleteLattice.holInfSet {b | ∃ f : α → β, (∀ x, HolCompleteLattice.holLe (F f x) (f x)) ∧ f a = b} + holBot := fun _ => HolCompleteLattice.holBot + holTop := fun _ => HolCompleteLattice.holTop + holInf f g := fun a => HolCompleteLattice.holInf (f a) (g a) + holSup f g := fun a => HolCompleteLattice.holSup (f a) (g a) + +/-- Exact Tarski `lfp` for unary Bool-valued predicates `α → Bool`. -/ +def holLfp1 {α : Type} (F : (α → Bool) → α → Bool) : α → Bool := + fun x => decide (∀ P : α → Bool, (∀ a, F P a = true → P a = true) → P x = true) + +/-- Exact Tarski `lfp` for binary Bool-valued relations `α → β → Bool` (used by `*_graph`, `*_rel`). -/ +def holLfp2 {α β : Type} (F : (α → β → Bool) → α → β → Bool) : α → β → Bool := + fun x y => decide (∀ P : α → β → Bool, (∀ a b, F P a b = true → P a b = true) → P x y = true) + +/-- Isabelle `Wellfounded.accp r x`: accessible part of relation `r : α → α → Bool`. -/ +def holAccp {α : Type} (r : α → α → Bool) (x : α) : Bool := + decide (Acc (fun a b => r a b = true) x) + +/-! ## Functions, Products, Options, Sums -/ + +def holId {α : Type} (x : α) : α := x +def holComp {α β γ : Type} (f : β → γ) (g : α → β) (x : α) : γ := f (g x) +def holFunUpd {α β : Type} (f : α → β) (a : α) (b : β) : α → β := Function.update f a b +def holMapFun {α β γ δ : Type} (f : β → α) (g : γ → δ) (h : α → γ) (x : β) : δ := g (h (f x)) +def holK {α β : Type} (x : α) (_ : β) : α := x +def holFunApp {α β : Type} (f : α → β) (x : α) : β := f x +def holSwp {α β γ : Type} (f : α → β → γ) (y : β) (x : α) : γ := f x y + +def holCaseProd {α β γ : Type} (f : α → β → γ) (p : α × β) : γ := f p.1 p.2 +def holCaseBool {α : Type} (t f : α) (b : Bool) : α := if b = true then t else f + +def holCaseOption {α β : Type} (n : β) (s : α → β) : Option α → β + | none => n + | some a => s a + +def holTheOpt {α : Type} [Nonempty α] : Option α → α + | some a => a + | none => holUndefined + +def holMapOption {α β : Type} (f : α → β) : Option α → Option β + | none => none + | some a => some (f a) + +def holSetOption {α : Type} : Option α → Set α + | none => ∅ + | some a => {a} + +def holCaseSum {α β γ : Type} (fl : α → γ) (fr : β → γ) : Sum α β → γ + | .inl a => fl a + | .inr b => fr b + +def holIsl {α β : Type} : Sum α β → Bool + | .inl _ => true + | .inr _ => false + +def holProjl {α β : Type} [Nonempty α] : Sum α β → α + | .inl a => a + | .inr _ => holUndefined + +def holProjr {α β : Type} [Nonempty β] : Sum α β → β + | .inr b => b + | .inl _ => holUndefined + +/-! ## Sets, Maps, Relations -/ + +def holCollect {α : Type} (P : α → Bool) : Set α := {x | P x = true} +def holMember {α : Type} (x : α) (S : Set α) : Bool := decide (x ∈ S) +def holInsert {α : Type} (x : α) (S : Set α) : Set α := Set.insert x S +def holImage {α β : Type} (f : α → β) (S : Set α) : Set β := f '' S +def holDom {α β : Type} (m : α → Option β) : Set α := {a | m a ≠ none} +def holRan {α β : Type} (m : α → Option β) : Set β := {b | ∃ a, m a = some b} +def holTrancl {α : Type} (r : Set (α × α)) : Set (α × α) := + {p | Relation.TransGen (fun x y => (x, y) ∈ r) p.1 p.2} +def holRtrancl {α : Type} (r : Set (α × α)) : Set (α × α) := + {p | Relation.ReflTransGen (fun x y => (x, y) ∈ r) p.1 p.2} + +/-! ## Polymorphic Numerals, Arithmetic, Orders, BitVecs -/ + +class HolNumeral (α : Type) where + ofNatVal : Nat → α + +instance : HolNumeral Nat where ofNatVal n := n +instance : HolNumeral Int where ofNatVal n := Int.ofNat n +instance {w : Nat} : HolNumeral (BitVec w) where ofNatVal n := BitVec.ofNat w n +instance {n : Nat} [NeZero n] : HolNumeral (Fin n) where ofNatVal k := Fin.ofNat n k + +class HolZero (α : Type) where + zeroVal : α + +instance : HolZero Nat where zeroVal := 0 +instance : HolZero Int where zeroVal := 0 +instance {w : Nat} : HolZero (BitVec w) where zeroVal := 0 +instance {n : Nat} [NeZero n] : HolZero (Fin n) where zeroVal := 0 + +class HolOne (α : Type) where + oneVal : α + +instance : HolOne Nat where oneVal := 1 +instance : HolOne Int where oneVal := 1 +instance {w : Nat} : HolOne (BitVec w) where oneVal := 1 +instance {n : Nat} [NeZero n] : HolOne (Fin n) where oneVal := Fin.ofNat n 1 + +class HolAdd (α : Type) where addVal : α → α → α +instance : HolAdd Nat where addVal := Nat.add +instance : HolAdd Int where addVal := Int.add +instance {w : Nat} : HolAdd (BitVec w) where addVal := BitVec.add +instance {n : Nat} : HolAdd (Fin n) where addVal := Fin.add + +class HolSub (α : Type) where subVal : α → α → α +instance : HolSub Nat where subVal := Nat.sub +instance : HolSub Int where subVal := Int.sub +instance {w : Nat} : HolSub (BitVec w) where subVal := BitVec.sub +instance {n : Nat} : HolSub (Fin n) where subVal := Fin.sub +instance {α : Type} : HolSub (Set α) where subVal := (· \ ·) + +class HolMul (α : Type) where mulVal : α → α → α +instance : HolMul Nat where mulVal := Nat.mul +instance : HolMul Int where mulVal := Int.mul +instance {w : Nat} : HolMul (BitVec w) where mulVal := BitVec.mul +instance {n : Nat} : HolMul (Fin n) where mulVal := Fin.mul + +class HolDiv (α : Type) where divVal : α → α → α +instance : HolDiv Nat where divVal := Nat.div +instance : HolDiv Int where divVal := Int.ediv +instance {w : Nat} : HolDiv (BitVec w) where divVal := BitVec.udiv + +class HolNeg (α : Type) where negVal : α → α +instance : HolNeg Int where negVal := Int.neg +instance {w : Nat} : HolNeg (BitVec w) where negVal := BitVec.neg +instance {n : Nat} : HolNeg (Fin n) where negVal a := -a +instance {α : Type} : HolNeg (Set α) where negVal S := Sᶜ + +class HolPow (α : Type) where powVal : α → Nat → α +instance : HolPow Nat where powVal := Nat.pow +instance : HolPow Int where powVal a n := a ^ n +instance {w : Nat} : HolPow (BitVec w) where powVal a n := BitVec.ofNat w (a.toNat ^ n) + +class HolOrd (α : Type) where + ltVal : α → α → Prop + leVal : α → α → Prop + +instance : HolOrd Nat where ltVal := (· < ·); leVal := (· ≤ ·) +instance : HolOrd Int where ltVal := (· < ·); leVal := (· ≤ ·) +instance {w : Nat} : HolOrd (BitVec w) where ltVal := (· < ·); leVal := (· ≤ ·) +instance {n : Nat} : HolOrd (Fin n) where ltVal := (· < ·); leVal := (· ≤ ·) +instance {α : Type} : HolOrd (Set α) where ltVal := (· ⊂ ·); leVal := (· ⊆ ·) +/-- Isabelle `List.prefixeq` (`xs ≤ ys` on lists is prefix order, used in `resolve_address_bits'`). -/ +instance {α : Type} : HolOrd (List α) where + ltVal xs ys := xs <+: ys ∧ xs ≠ ys + leVal xs ys := xs <+: ys + +def holLt {α : Type} [HolOrd α] (a b : α) : Bool := decide (HolOrd.ltVal a b) +def holLe {α : Type} [HolOrd α] (a b : α) : Bool := decide (HolOrd.leVal a b) +def holMin {α : Type} [HolOrd α] (a b : α) : α := if HolOrd.leVal a b then a else b + +def holAtLeastAtMost {α : Type} [HolOrd α] (a b : α) : Set α := + {x | HolOrd.leVal a x ∧ HolOrd.leVal x b} + +def holAtLeastLessThan {α : Type} [HolOrd α] (a b : α) : Set α := + {x | HolOrd.leVal a x ∧ HolOrd.ltVal x b} + +def holMax {α : Type} [HolOrd α] [Nonempty α] (S : Set α) : α := + holThe fun m => decide (m ∈ S ∧ ∀ x ∈ S, HolOrd.leVal x m) + +def holLeast (P : Nat → Bool) : Nat := + if h : ∃ n, P n = true then Nat.find h else holUndefined + +class HolDvd (α : Type) where + dvdVal : α → α → Bool + +instance : HolDvd Nat where dvdVal a b := decide (a ∣ b) +instance : HolDvd Int where dvdVal a b := decide (a ∣ b) + +def holDvd {α : Type} [HolDvd α] (a b : α) : Bool := HolDvd.dvdVal a b + +def holOfNat {α : Type} [HolNumeral α] (n : Nat) : α := HolNumeral.ofNatVal n +def holOfInt {w : Nat} (i : Int) : BitVec w := BitVec.ofInt w i +def holIntToNat (i : Int) : Nat := i.toNat + +/-! ## Bit operations on `BitVec` (and `Nat` where used) -/ + +def holWordAnd {w : Nat} (a b : BitVec w) : BitVec w := a &&& b +def holWordOr {w : Nat} (a b : BitVec w) : BitVec w := a ||| b +def holWordNot {w : Nat} (a : BitVec w) : BitVec w := ~~~a +def holWordShiftl {w : Nat} (a : BitVec w) (n : Nat) : BitVec w := a <<< n +def holWordShiftr {w : Nat} (a : BitVec w) (n : Nat) : BitVec w := a >>> n +def holWordMask {w : Nat} (n : Nat) : BitVec w := (1 <<< n) - 1 +def holWordBit {w : Nat} (a : BitVec w) (n : Nat) : Bool := a.getLsbD n +class HolTakeBit (α : Type) where + takeBitVal : Nat → α → α + +instance : HolTakeBit Nat where takeBitVal n a := a % (2 ^ n) +instance : HolTakeBit Int where takeBitVal n a := a % ((2 : Int) ^ n) +instance {w : Nat} : HolTakeBit (BitVec w) where takeBitVal n a := a &&& holWordMask n + +def holWordTakeBit {α : Type} [HolTakeBit α] (n : Nat) (a : α) : α := HolTakeBit.takeBitVal n a +def holHaskellBit {w : Nat} (n : Nat) : BitVec w := (1 : BitVec w) <<< n +def holUnsigned {w : Nat} (a : BitVec w) : Nat := a.toNat +def holUcast {v w : Nat} (a : BitVec v) : BitVec w := a.setWidth w +def holMaxWord {w : Nat} : BitVec w := BitVec.allOnes w +def holToBl {w : Nat} (a : BitVec w) : List Bool := (List.range w).reverse.map a.getLsbD +def holOfBl {w : Nat} (bs : List Bool) : BitVec w := + bs.foldl (fun acc b => (acc <<< 1) ||| (if b then 1 else 0)) 0 +def holWordRcat {m n : Nat} (ws : List (BitVec m)) : BitVec n := + ws.foldl (fun acc b => (acc <<< m) ||| b.setWidth n) 0 +def holWordRsplit {n m : Nat} (w : BitVec n) : List (BitVec m) := + (List.range ((n + m - 1) / m)).reverse.map fun k => (w >>> (k * m)).setWidth m + +/-- Isabelle `Word.rep`: unsigned integer representation `word → Int` (`uint`). -/ +def holWordRep {w : Nat} (a : BitVec w) : Int := Int.ofNat a.toNat + +/-! ## Lists -/ + +def holCaseList {α β : Type} (n : β) (c : α → List α → β) : List α → β + | [] => n + | x :: xs => c x xs + +def holHd {α : Type} [Nonempty α] : List α → α + | x :: _ => x + | [] => holUndefined + +def holTl {α : Type} : List α → List α + | _ :: xs => xs + | [] => [] + +def holLast {α : Type} [Nonempty α] (xs : List α) : α := + holTheOpt xs.getLast? + +def holButlast {α : Type} (xs : List α) : List α := xs.dropLast + +def holNth {α : Type} [Nonempty α] (xs : List α) (i : Nat) : α := + holTheOpt xs[i]? + +def holListSet {α : Type} (xs : List α) : Set α := {x | x ∈ xs} +def holListMap {α β : Type} (f : α → β) (xs : List α) : List β := xs.map f +def holListAppend {α : Type} (xs ys : List α) : List α := xs ++ ys +def holListTake {α : Type} (n : Nat) (xs : List α) : List α := xs.take n +def holListDrop {α : Type} (n : Nat) (xs : List α) : List α := xs.drop n +def holListFilter {α : Type} (P : α → Bool) (xs : List α) : List α := xs.filter P +def holListTakeWhile {α : Type} (P : α → Bool) (xs : List α) : List α := xs.takeWhile P +def holListDropWhile {α : Type} (P : α → Bool) (xs : List α) : List α := xs.dropWhile P +def holListFind {α : Type} (P : α → Bool) (xs : List α) : Option α := xs.find? P +def holListReplicate {α : Type} (n : Nat) (x : α) : List α := List.replicate n x +def holListRev {α : Type} (xs : List α) : List α := xs.reverse +def holListZip {α β : Type} (xs : List α) (ys : List β) : List (α × β) := xs.zip ys +def holListRemoveAll {α : Type} (x : α) (xs : List α) : List α := xs.filter (fun y => decide (y ≠ x)) +def holListUpdate {α : Type} (xs : List α) (i : Nat) (v : α) : List α := xs.set i v +def holListFold {α β : Type} (f : α → β → β) (xs : List α) (acc : β) : β := xs.foldl (fun b a => f a b) acc +def holListFoldr {α β : Type} (f : α → β → β) (xs : List α) (acc : β) : β := xs.foldr f acc +def holListUpt (i j : Nat) : List Nat := List.range' i (j - i) +def holListUpto (i j : Int) : List Int := (List.range (j - i + 1).toNat).map fun k : Nat => i + (k : Int) +def holListDistinct {α : Type} : List α → Bool + | [] => true + | x :: xs => decide (x ∉ xs) && holListDistinct xs +def holSumList {α : Type} [HolZero α] [HolAdd α] (xs : List α) : α := + xs.foldr HolAdd.addVal HolZero.zeroVal +class HolSize (α : Type) where + sizeVal : α → Nat + +instance {α : Type} : HolSize (List α) where sizeVal := List.length +instance {n : Nat} : HolSize (Fin n) where sizeVal := Fin.val +instance {w : Nat} : HolSize (BitVec w) where sizeVal _ := w +instance : HolSize Nat where sizeVal := id + +def holSize {α : Type} [HolSize α] (x : α) : Nat := HolSize.sizeVal x + +/-! ## Enumeration (`enum`, `fromEnum`, `toEnum`, `upto_enum`, `upto_enum_step`, `assocs`, `the_index`) -/ + +class HolEnum (α : Type) where + enumList : List α + +instance {w : Nat} : HolEnum (BitVec w) where + enumList := (List.range (2 ^ w)).map (BitVec.ofNat w) + +instance {n : Nat} [NeZero n] : HolEnum (Fin n) where + enumList := (List.range n).map (Fin.ofNat n) + +def holTheIndex {α : Type} : List α → α → Nat + | [], _ => holUndefined + | x :: xs, y => if x = y then 0 else holTheIndex xs y + 1 + +def holFromEnum {α : Type} [HolEnum α] (x : α) : Nat := holTheIndex (HolEnum.enumList (α := α)) x +def holToEnum {α : Type} [HolEnum α] [Nonempty α] (n : Nat) : α := holNth (HolEnum.enumList (α := α)) n +def holMinBound {α : Type} [HolEnum α] [Nonempty α] : α := holHd (HolEnum.enumList (α := α)) +def holMaxBound {α : Type} [HolEnum α] [Nonempty α] : α := holLast (HolEnum.enumList (α := α)) + +def holUptoEnum {α : Type} [HolEnum α] [Nonempty α] (a b : α) : List α := + (holListUpt (holFromEnum a) (holFromEnum b + 1)).map holToEnum + +def holUptoEnumStep {w : Nat} (a b c : BitVec w) : List (BitVec w) := + if c < a then [] else (holUptoEnum (0 : BitVec w) ((c - a) / (b - a))).map fun x => a + x * (b - a) + +def holAssocs {α β : Type} [HolEnum α] (f : α → β) : List (α × β) := + (HolEnum.enumList (α := α)).map fun x => (x, f x) + +/-! ## Nondet_Monad (38 ops) + Nondet_Empty_Fail + Reader_Option_Monad (9 ops) -/ + +def holReturn {σ α : Type} (a : α) : HolNonDet σ α := fun s => ({(a, s)}, false) + +def holBind {σ α β : Type} (m : HolNonDet σ α) (f : α → HolNonDet σ β) : HolNonDet σ β := fun s => + ({r | ∃ x ∈ (m s).1, r ∈ (f x.1 x.2).1}, + decide ((m s).2 = true ∨ ∃ x ∈ (m s).1, (f x.1 x.2).2 = true)) + +def holKBind {α β : Type} (x : α) (_ : β) : α := x + +def holGet {σ : Type} : HolNonDet σ σ := fun s => ({(s, s)}, false) +def holPut {σ : Type} (s : σ) : HolNonDet σ Unit := fun _ => ({((), s)}, false) +def holGets {σ α : Type} (f : σ → α) : HolNonDet σ α := fun s => ({(f s, s)}, false) +def holModify {σ : Type} (f : σ → σ) : HolNonDet σ Unit := fun s => ({((), f s)}, false) +def holSelect {σ α : Type} (A : Set α) : HolNonDet σ α := fun s => ({x | x.1 ∈ A ∧ x.2 = s}, false) +def holSelectF {σ α : Type} (S : Set α × Bool) : HolNonDet σ α := fun s => ({x | x.1 ∈ S.1 ∧ x.2 = s}, S.2) +def holMkEf {α : Type} (S : Set α × Bool) : Set α × Bool := (S.1, decide (S.1 = ∅ ∨ S.2 = true)) +def holFail {σ α : Type} : HolNonDet σ α := fun _ => (∅, true) +def holAssert {σ : Type} (b : Bool) : HolNonDet σ Unit := fun s => ({x | b = true ∧ x = ((), s)}, !b) +def holStateAssert {σ : Type} (P : σ → Bool) : HolNonDet σ Unit := fun s => holAssert (P s) s +def holAssertOpt {σ α : Type} : Option α → HolNonDet σ α + | some a => holReturn a + | none => holFail +def holGetsThe {σ α : Type} (f : σ → Option α) : HolNonDet σ α := fun s => holAssertOpt (f s) s +def holGetsMap {σ γ α : Type} (f : σ → γ → Option α) (p : γ) : HolNonDet σ α := + holBind (holGets f) fun m => holAssertOpt (m p) +def holWhen {σ : Type} (b : Bool) (m : HolNonDet σ Unit) : HolNonDet σ Unit := + if b = true then m else holReturn () +def holUnless {σ : Type} (b : Bool) (m : HolNonDet σ Unit) : HolNonDet σ Unit := + if b = true then holReturn () else m +def holLiftM {σ α β : Type} (f : α → β) (m : HolNonDet σ α) : HolNonDet σ β := + holBind m fun x => holReturn (f x) +def holMaybeM {σ α : Type} (f : α → HolNonDet σ Unit) : Option α → HolNonDet σ Unit + | some x => f x + | none => holReturn () +def holMapM {σ α β : Type} (f : α → HolNonDet σ β) : List α → HolNonDet σ (List β) + | [] => holReturn [] + | a :: as => holBind (f a) fun b => holBind (holMapM f as) fun bs => holReturn (b :: bs) +def holMapMx {σ α β : Type} (f : α → HolNonDet σ β) : List α → HolNonDet σ Unit + | [] => holReturn () + | a :: as => holBind (f a) fun _ => holMapMx f as +def holZipWithM {σ α β γ : Type} (f : α → β → HolNonDet σ γ) : List α → List β → HolNonDet σ (List γ) + | a :: as, b :: bs => holBind (f a b) fun c => holBind (holZipWithM f as bs) fun cs => holReturn (c :: cs) + | _, _ => holReturn [] +def holZipWithMx {σ α β γ : Type} (f : α → β → HolNonDet σ γ) : List α → List β → HolNonDet σ Unit + | a :: as, b :: bs => holBind (f a b) fun _ => holZipWithMx f as bs + | _, _ => holReturn () + +inductive HolWhileResults {σ α : Type} (C : α → σ → Bool) (B : α → HolNonDet σ α) : α → σ → α × σ → Prop + | done {r s} : C r s = false → HolWhileResults C B r s (r, s) + | step {r s r' s' x} : C r s = true → (r', s') ∈ (B r s).1 → HolWhileResults C B r' s' x → HolWhileResults C B r s x + +inductive HolWhileReach {σ α : Type} (C : α → σ → Bool) (B : α → HolNonDet σ α) (r₀ : α) (s₀ : σ) : α → σ → Prop + | start : HolWhileReach C B r₀ s₀ r₀ s₀ + | step {r s r' s'} : HolWhileReach C B r₀ s₀ r s → C r s = true → (r', s') ∈ (B r s).1 → HolWhileReach C B r₀ s₀ r' s' + +def holWhileLoop {σ α : Type} (C : α → σ → Bool) (B : α → HolNonDet σ α) (r : α) : HolNonDet σ α := fun s => + ({x | HolWhileResults C B r s x}, + decide ((∃ r' s', HolWhileReach C B r s r' s' ∧ C r' s' = true ∧ (B r' s').2 = true) ∨ + (∃ f : Nat → α × σ, f 0 = (r, s) ∧ ∀ n, C (f n).1 (f n).2 = true ∧ f (n + 1) ∈ (B (f n).1 (f n).2).1))) + +/-! ### Exception monad (`HolNonDet σ (Sum ε α)`) -/ + +def holReturnOk {σ ε α : Type} (a : α) : HolNonDet σ (Sum ε α) := holReturn (.inr a) +def holThrowError {σ ε α : Type} (e : ε) : HolNonDet σ (Sum ε α) := holReturn (.inl e) +def holLiftE {σ ε α : Type} (m : HolNonDet σ α) : HolNonDet σ (Sum ε α) := holLiftM Sum.inr m +def holBindE {σ ε α β : Type} (m : HolNonDet σ (Sum ε α)) (f : α → HolNonDet σ (Sum ε β)) : HolNonDet σ (Sum ε β) := + holBind m fun + | .inl e => holThrowError e + | .inr a => f a +def holWhenE {σ ε : Type} (b : Bool) (m : HolNonDet σ (Sum ε Unit)) : HolNonDet σ (Sum ε Unit) := + if b = true then m else holReturnOk () +def holUnlessE {σ ε : Type} (b : Bool) (m : HolNonDet σ (Sum ε Unit)) : HolNonDet σ (Sum ε Unit) := + if b = true then holReturnOk () else m +def holAssertE {σ ε : Type} (b : Bool) : HolNonDet σ (Sum ε Unit) := holLiftE (holAssert b) +def holThrowOpt {σ ε α : Type} (e : ε) : Option α → HolNonDet σ (Sum ε α) + | some a => holReturnOk a + | none => holThrowError e +def holCatch {σ ε α : Type} (m : HolNonDet σ (Sum ε α)) (h : ε → HolNonDet σ α) : HolNonDet σ α := + holBind m fun + | .inl e => h e + | .inr a => holReturn a +def holHandleE' {σ ε ε' α : Type} (m : HolNonDet σ (Sum ε α)) (h : ε → HolNonDet σ (Sum ε' α)) : HolNonDet σ (Sum ε' α) := + holBind m fun + | .inl e => h e + | .inr a => holReturnOk a +def holHandleE {σ ε α : Type} (m : HolNonDet σ (Sum ε α)) (h : ε → HolNonDet σ (Sum ε α)) : HolNonDet σ (Sum ε α) := + holHandleE' m h +def holLiftME {σ ε α β : Type} (f : α → β) (m : HolNonDet σ (Sum ε α)) : HolNonDet σ (Sum ε β) := + holBindE m fun x => holReturnOk (f x) +def holMapME {σ ε α β : Type} (f : α → HolNonDet σ (Sum ε β)) : List α → HolNonDet σ (Sum ε (List β)) + | [] => holReturnOk [] + | a :: as => holBindE (f a) fun b => holBindE (holMapME f as) fun bs => holReturnOk (b :: bs) +def holMapMEx {σ ε α β : Type} (f : α → HolNonDet σ (Sum ε β)) : List α → HolNonDet σ (Sum ε Unit) + | [] => holReturnOk () + | a :: as => holBindE (f a) fun _ => holMapMEx f as + +/-! ### Reader_Option_Monad (`σ → Option α`) -/ + +def holOReturn {σ α : Type} (a : α) : HolLookup σ α := fun _ => some a +def holOFail {σ α : Type} : HolLookup σ α := fun _ => none +def holOBind {σ α β : Type} (f : HolLookup σ α) (g : α → HolLookup σ β) : HolLookup σ β := + fun s => match f s with | none => none | some a => g a s +def holOAssert {σ : Type} (b : Bool) : HolLookup σ Unit := if b = true then holOReturn () else holOFail +def holOAssertOpt {σ α : Type} : Option α → HolLookup σ α + | none => holOFail + | some a => holOReturn a +def holOLiftM {σ α β : Type} (f : α → β) (m : HolLookup σ α) : HolLookup σ β := + holOBind m fun a => holOReturn (f a) +def holAsks {σ α : Type} (f : σ → α) : HolLookup σ α := fun s => some (f s) +def holOptMap {σ α β : Type} (f : σ → Option α) (g : α → Option β) : σ → Option β := + fun s => match f s with | none => none | some x => g x +def holOptMapSome {σ α β : Type} (f : σ → Option α) (g : α → β) : σ → Option β := + fun s => (f s).map g +def holOptPred {α β : Type} (P : α → Bool) (proj : β → Option α) : β → Bool := + fun x => match proj x with | none => false | some y => P y + +/-! ### Isabelle `itself` dummy carrier -/ +inductive HolItself (α : Type) where + | type : HolItself α +deriving Inhabited + +end +end Prim +end L4vRefX64 diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/PrimX64.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/PrimX64.lean new file mode 100644 index 000000000..7f38e5346 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/PrimX64.lean @@ -0,0 +1,24 @@ +import L4vRefX64.Prim + +namespace L4vRefX64.Prim + +open Classical + +noncomputable section + +/-- Isabelle `Set.Bex`, bounded existential quantification. -/ +def holBex {α : Type} (S : Set α) (p : α → Bool) : Bool := + decide (∃ x ∈ S, p x = true) + +/-- Operations used by the checked polymorphic definition of `cr3_addr_mask`. -/ +class HolShiftMask (α : Type) where + shiftLeft : α → Nat → α + mask : Nat → α + +instance {w : Nat} : HolShiftMask (BitVec w) where + shiftLeft := holWordShiftl + mask := holWordMask + +end + +end L4vRefX64.Prim diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Config.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Config.lean new file mode 100644 index 000000000..18bda15c4 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Config.lean @@ -0,0 +1,17 @@ +import Fl4Spec.Machine +import L4vRefX64.Spec.Kernel_Config + +namespace L4vRefX64.Rel + +open L4vRefX64.Spec + +/-- The fields present in the frozen Lean config and the generated PC99 config. -/ +structure KernelConfigMatches (cfg : Fl4Spec.KernelConfig) : Prop where + numDomains_eq : cfg.numDomains = Kernel_Config.numDomains + resetChunkBits_eq : cfg.resetChunkBits = Kernel_Config.resetChunkBits + retypeFanOutLimit_eq : cfg.retypeFanOutLimit = Kernel_Config.retypeFanOutLimit + +/-- [P] The fixed Lean kernel configuration corresponds to the checked PC99 MCS configuration. -/ +abbrev ConfigRel : Prop := KernelConfigMatches Fl4Spec.kernelConfig + +end L4vRefX64.Rel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Embed.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Embed.lean new file mode 100644 index 000000000..ebd44be7e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Embed.lean @@ -0,0 +1,613 @@ +import Fl4Spec +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Event_H +import L4vRefX64.Spec.InvocationLabels_H + +namespace L4vRefX64.Rel + +open L4vRefX64.Prim +open L4vRefX64.Spec +open Fl4Spec +open Classical + +noncomputable section + +abbrev embIrq (i : BitVec 8) : Irq := i + +/-! ## Generic bijection helpers for function/set transport -/ + +theorem set_image_inter {α β : Type} {f : α → β} (hf : Function.Injective f) (S T : Set α) : + f '' (S ∩ T) = (f '' S) ∩ (f '' T) := Set.image_inter hf + +theorem set_image_diff {α β : Type} {f : α → β} (hf : Function.Injective f) (S T : Set α) : + f '' (S \ T) = (f '' S) \ (f '' T) := Set.image_sdiff hf S T + +theorem set_image_union {α β : Type} (f : α → β) (S T : Set α) : + f '' (S ∪ T) = (f '' S) ∪ (f '' T) := Set.image_union f S T + +theorem set_image_univ {α β : Type} {f : α → β} (hf : Function.Surjective f) : + f '' Set.univ = Set.univ := Set.image_univ_of_surjective hf + +theorem fun_update_comp {α β γ : Type} {inst1 : DecidableEq α} {inst2 : DecidableEq β} + {e : α → β} {u : β → α} + (heu : ∀ x, u (e x) = x) (hue : ∀ y, e (u y) = y) + (f : α → γ) (a : α) (v : γ) : + (fun b => @Function.update α (fun _ => γ) inst1 f a v (u b)) = + @Function.update β (fun _ => γ) inst2 (fun b => f (u b)) (e a) v := by + funext b + by_cases h : b = e a + · subst h; simp [Function.update, heu] + · have h' : u b ≠ a := fun h1 => h (by rw [← h1, hue]) + simp [Function.update, h, h'] + +/-! ## Basic finite enum bijections -/ + +def embRights : CapRights_A.rights → Rights + | .AllowRead => .allowRead + | .AllowWrite => .allowWrite + | .AllowGrant => .allowGrant + | .AllowGrantReply => .allowGrantReply + +def unembRights : Rights → CapRights_A.rights + | .allowRead => .AllowRead + | .allowWrite => .AllowWrite + | .allowGrant => .AllowGrant + | .allowGrantReply => .AllowGrantReply + +@[simp] theorem unembRights_emb (x) : unembRights (embRights x) = x := by cases x <;> rfl +@[simp] theorem embRights_unemb (x) : embRights (unembRights x) = x := by cases x <;> rfl +theorem embRights_injective : Function.Injective embRights := Function.LeftInverse.injective unembRights_emb +theorem embRights_surjective : Function.Surjective embRights := Function.RightInverse.surjective embRights_unemb + +def embRightsSet (S : Set CapRights_A.rights) : CapRights := embRights '' S + +@[simp] theorem embRightsSet_mem (r : CapRights_A.rights) (S : Set CapRights_A.rights) : + embRights r ∈ embRightsSet S ↔ r ∈ S := + embRights_injective.mem_set_image + +theorem embRightsSet_injective : Function.Injective embRightsSet := + Set.image_injective.mpr embRights_injective + +@[simp] theorem embRightsSet_eq_iff (S T : Set CapRights_A.rights) : + embRightsSet S = embRightsSet T ↔ S = T := embRightsSet_injective.eq_iff + +@[simp] theorem embRightsSet_empty : embRightsSet ∅ = ∅ := Set.image_empty _ +@[simp] theorem embRightsSet_univ : embRightsSet Set.univ = Set.univ := set_image_univ embRights_surjective +@[simp] theorem embRightsSet_insert (r S) : embRightsSet (insert r S) = insert (embRights r) (embRightsSet S) := Set.image_insert_eq +@[simp] theorem embRightsSet_inter (S T) : embRightsSet (S ∩ T) = embRightsSet S ∩ embRightsSet T := set_image_inter embRights_injective S T +@[simp] theorem embRightsSet_union (S T) : embRightsSet (S ∪ T) = embRightsSet S ∪ embRightsSet T := set_image_union _ S T +@[simp] theorem embRightsSet_diff (S T) : embRightsSet (S \ T) = embRightsSet S \ embRightsSet T := set_image_diff embRights_injective S T + +def embTcbFlag : Structs_B.tcb_flag → TcbFlag + | .FpuDisabled => .fpuDisabled + +def unembTcbFlag : TcbFlag → Structs_B.tcb_flag + | .fpuDisabled => .FpuDisabled + +@[simp] theorem unembTcbFlag_emb (x) : unembTcbFlag (embTcbFlag x) = x := by cases x; rfl +@[simp] theorem embTcbFlag_unemb (x) : embTcbFlag (unembTcbFlag x) = x := by cases x; rfl +theorem embTcbFlag_injective : Function.Injective embTcbFlag := Function.LeftInverse.injective unembTcbFlag_emb +theorem embTcbFlag_surjective : Function.Surjective embTcbFlag := Function.RightInverse.surjective embTcbFlag_unemb + +def embTcbFlags (S : Set Structs_B.tcb_flag) : TcbFlags := embTcbFlag '' S + +@[simp] theorem embTcbFlags_mem (f S) : embTcbFlag f ∈ embTcbFlags S ↔ f ∈ S := + embTcbFlag_injective.mem_set_image + +theorem embTcbFlags_injective : Function.Injective embTcbFlags := + Set.image_injective.mpr embTcbFlag_injective + +@[simp] theorem embTcbFlags_eq_iff (S T) : embTcbFlags S = embTcbFlags T ↔ S = T := embTcbFlags_injective.eq_iff +@[simp] theorem embTcbFlags_empty : embTcbFlags ∅ = ∅ := Set.image_empty _ +@[simp] theorem embTcbFlags_insert (a S) : embTcbFlags (insert a S) = insert (embTcbFlag a) (embTcbFlags S) := Set.image_insert_eq +@[simp] theorem embTcbFlags_inter (S T) : embTcbFlags (S ∩ T) = embTcbFlags S ∩ embTcbFlags T := set_image_inter embTcbFlag_injective S T +@[simp] theorem embTcbFlags_union (S T) : embTcbFlags (S ∪ T) = embTcbFlags S ∪ embTcbFlags T := set_image_union _ S T +@[simp] theorem embTcbFlags_diff (S T) : embTcbFlags (S \ T) = embTcbFlags S \ embTcbFlags T := set_image_diff embTcbFlag_injective S T + +def embVMPageSize : MachineTypes.vmpage_size → VMPageSize + | .X64SmallPage => .x64SmallPage + | .X64LargePage => .x64LargePage + | .X64HugePage => .x64HugePage + +def unembVMPageSize : VMPageSize → MachineTypes.vmpage_size + | .x64SmallPage => .X64SmallPage + | .x64LargePage => .X64LargePage + | .x64HugePage => .X64HugePage + +@[simp] theorem unembVMPageSize_emb (x) : unembVMPageSize (embVMPageSize x) = x := by cases x <;> rfl +@[simp] theorem embVMPageSize_unemb (x) : embVMPageSize (unembVMPageSize x) = x := by cases x <;> rfl +theorem embVMPageSize_injective : Function.Injective embVMPageSize := Function.LeftInverse.injective unembVMPageSize_emb +@[simp] theorem embVMPageSize_eq_iff (a b) : embVMPageSize a = embVMPageSize b ↔ a = b := embVMPageSize_injective.eq_iff + +def embVMFaultType : MachineTypes.vmfault_type → VMFaultType + | .X64DataFault => .x64DataFault + | .X64InstructionFault => .x64InstructionFault + +def embHypFaultType : MachineTypes.hyp_fault_type → HypFaultType + | .X64NoHypFaults => .x64NoHypFaults + +def embSyscall : Event_H.syscall → Syscall + | .SysCall => .sysCall | .SysReplyRecv => .sysReplyRecv | .SysNBSendRecv => .sysNBSendRecv + | .SysNBSendWait => .sysNBSendWait | .SysSend => .sysSend | .SysNBSend => .sysNBSend + | .SysRecv => .sysRecv | .SysYield => .sysYield | .SysNBRecv => .sysNBRecv + | .SysWait => .sysWait | .SysNBWait => .sysNBWait + +def unembSyscall : Syscall → Event_H.syscall + | .sysCall => .SysCall | .sysReplyRecv => .SysReplyRecv | .sysNBSendRecv => .SysNBSendRecv + | .sysNBSendWait => .SysNBSendWait | .sysSend => .SysSend | .sysNBSend => .SysNBSend + | .sysRecv => .SysRecv | .sysYield => .SysYield | .sysNBRecv => .SysNBRecv + | .sysWait => .SysWait | .sysNBWait => .SysNBWait + +@[simp] theorem unembSyscall_emb (x) : unembSyscall (embSyscall x) = x := by cases x <;> rfl +@[simp] theorem embSyscall_unemb (x) : embSyscall (unembSyscall x) = x := by cases x <;> rfl + +def embEvent : Event_H.event → Event + | .SyscallEvent s => .syscallEvent (embSyscall s) + | .UnknownSyscall n => .unknownSyscall n + | .UserLevelFault w1 w2 => .userLevelFault w1 w2 + | .Interrupt => .interrupt + | .VMFaultEvent f => .vmFaultEvent (embVMFaultType f) + | .HypervisorEvent h => .hypervisorEvent (embHypFaultType h) + +def embIrqState : Structures_A.irq_state → IrqState + | .IRQInactive => .irqInactive + | .IRQSignal => .irqSignal + | .IRQTimer => .irqTimer + | .IRQReserved => .irqReserved + +def unembIrqState : IrqState → Structures_A.irq_state + | .irqInactive => .IRQInactive + | .irqSignal => .IRQSignal + | .irqTimer => .IRQTimer + | .irqReserved => .IRQReserved + +@[simp] theorem unembIrqState_emb (x) : unembIrqState (embIrqState x) = x := by cases x <;> rfl +@[simp] theorem embIrqState_unemb (x) : embIrqState (unembIrqState x) = x := by cases x <;> rfl +theorem embIrqState_injective : Function.Injective embIrqState := Function.LeftInverse.injective unembIrqState_emb +@[simp] theorem embIrqState_eq_iff (a b) : embIrqState a = embIrqState b ↔ a = b := embIrqState_injective.eq_iff + +def embSchedulerAction : Structures_A.scheduler_action → SchedulerAction + | .resume_cur_thread => .resumeCurThread + | .switch_thread t => .switchThread t + | .choose_new_thread => .chooseNewThread + +theorem embSchedulerAction_injective : Function.Injective embSchedulerAction := by + intro a b h; cases a <;> cases b <;> simp [embSchedulerAction] at h ⊢; exact h + +@[simp] theorem embSchedulerAction_eq_iff (a b) : + embSchedulerAction a = embSchedulerAction b ↔ a = b := embSchedulerAction_injective.eq_iff + +/-! ## Faults, Errors, Machine / User Contexts -/ + +def embLookupFailure : ExceptionTypes_A.lookup_failure → LookupFailure + | .InvalidRoot => .invalidRoot + | .MissingCapability n => .missingCapability n + | .DepthMismatch n m => .depthMismatch n m + | .GuardMismatch n g => .guardMismatch n g + +theorem embLookupFailure_injective : Function.Injective embLookupFailure := by + intro a b h; cases a <;> cases b <;> simp [embLookupFailure] at h ⊢ <;> exact h + +@[simp] theorem embLookupFailure_eq_iff (a b) : + embLookupFailure a = embLookupFailure b ↔ a = b := embLookupFailure_injective.eq_iff + +def embArchFault : Machine_A.arch_fault → ArchFault + | .VMFault addr data => .vmFault addr data + +@[simp] theorem embArchFault_eq_iff (a b) : + embArchFault a = embArchFault b ↔ a = b := by + cases a + cases b + simp [embArchFault] + +def embFault : ExceptionTypes_A.fault → Fault + | .CapFault a b lf => .capFault a b (embLookupFailure lf) + | .UnknownSyscallException n => .unknownSyscallException n + | .UserException n c => .userException n c + | .Timeout b => .timeout b + | .ArchFault af => .archFault (embArchFault af) + +theorem embFault_injective : Function.Injective embFault := by + intro a b h; cases a <;> cases b <;> simp [embFault] at h ⊢ <;> exact h + +@[simp] theorem embFault_eq_iff (a b) : embFault a = embFault b ↔ a = b := embFault_injective.eq_iff + +def embSyscallError : ExceptionTypes_A.syscall_error → SyscallError + | .InvalidArgument n => .invalidArgument n + | .InvalidCapability n => .invalidCapability n + | .IllegalOperation => .illegalOperation + | .RangeError lo hi => .rangeError lo hi + | .AlignmentError => .alignmentError + | .FailedLookup b lf => .failedLookup b (embLookupFailure lf) + | .TruncatedMessage => .truncatedMessage + | .DeleteFirst => .deleteFirst + | .RevokeFirst => .revokeFirst + | .NotEnoughMemory n => .notEnoughMemory n + +theorem embSyscallError_injective : Function.Injective embSyscallError := by + intro a b h; cases a <;> cases b <;> simp [embSyscallError] at h ⊢ <;> exact h + +@[simp] theorem embSyscallError_eq_iff (a b) : + embSyscallError a = embSyscallError b ↔ a = b := embSyscallError_injective.eq_iff + +def embRegister : MachineTypes.register → Register + | .RAX => .rax + | .RBX => .rbx + | .RCX => .rcx + | .RDX => .rdx + | .RSI => .rsi + | .RDI => .rdi + | .RBP => .rbp + | .R8 => .r8 + | .R9 => .r9 + | .R10 => .r10 + | .R11 => .r11 + | .R12 => .r12 + | .R13 => .r13 + | .R14 => .r14 + | .R15 => .r15 + | .FaultIP => .faultIP + | .FS_BASE => .fsBase + | .GS_BASE => .gsBase + | .ErrorRegister => .errorRegister + | .NextIP => .nextIP + | .CS => .cs + | .FLAGS => .flags + | .RSP => .rsp + | .SS => .ss + +def unembRegister : Register → MachineTypes.register + | .rax => .RAX + | .rbx => .RBX + | .rcx => .RCX + | .rdx => .RDX + | .rsi => .RSI + | .rdi => .RDI + | .rbp => .RBP + | .r8 => .R8 + | .r9 => .R9 + | .r10 => .R10 + | .r11 => .R11 + | .r12 => .R12 + | .r13 => .R13 + | .r14 => .R14 + | .r15 => .R15 + | .faultIP => .FaultIP + | .fsBase => .FS_BASE + | .gsBase => .GS_BASE + | .errorRegister => .ErrorRegister + | .nextIP => .NextIP + | .cs => .CS + | .flags => .FLAGS + | .rsp => .RSP + | .ss => .SS + +@[simp] theorem unembRegister_emb (r) : unembRegister (embRegister r) = r := by cases r <;> rfl +@[simp] theorem embRegister_unemb (r) : embRegister (unembRegister r) = r := by cases r <;> rfl + +theorem embRegister_injective : Function.Injective embRegister := + Function.LeftInverse.injective unembRegister_emb + +def embUserRegs (registers : MachineTypes.register → Word) : Register → Word := + registers ∘ unembRegister + +@[simp] theorem embUserRegs_embRegister (registers : MachineTypes.register → Word) + (register : MachineTypes.register) : + embUserRegs registers (embRegister register) = registers register := by + simp [embUserRegs] + +def embUserContext : MachineOps.user_context → UserContext + | .UserContext fpu regs => { userFpuState := fpu, userRegs := embUserRegs regs } + +def embArchTcb (a : Arch_Structs_A.arch_tcb) : ArchTcb := + { tcbContext := embUserContext a.tcb_context, tcbCurFpu := a.tcb_cur_fpu } + +@[simp] theorem archTcbGetRegisters_eq (a : Arch_Structs_A.arch_tcb) : + Fl4Spec.archTcbGetRegisters (embArchTcb a) = + embUserRegs (Arch_Structs_A.arch_tcb_get_registers a) := by + rcases a with ⟨context, ownsFpu, tail⟩ + cases context + rfl + +@[simp] theorem archTcbSetRegisters_eq (registers : MachineTypes.register → Word) + (a : Arch_Structs_A.arch_tcb) : + Fl4Spec.archTcbSetRegisters (embUserRegs registers) (embArchTcb a) = + embArchTcb (Arch_Structs_A.arch_tcb_set_registers registers a) := by + rcases a with ⟨context, ownsFpu, tail⟩ + cases context + rfl + +def embVMMapType : MachineTypes.vmmap_type → VMMapType + | .VMNoMap => .vmNoMap + | .VMVSpaceMap => .vmVSpaceMap + +def embTableAttr : ArchVMAttributes_A.table_attr → TableAttr + | .Accessed => .accessed + | .CacheDisabled => .cacheDisabled + | .WriteThrough => .writeThrough + | .ExecuteDisable => .executeDisable + +def embVMAttribute : ArchVMAttributes_A.vm_attribute → VMAttribute + | .PTAttr a => .ptAttr (embTableAttr a) + | .Global => .global + | .PAT => .pat + | .Dirty => .dirty + +def embTableAttrs (attrs : Set ArchVMAttributes_A.table_attr) : TableAttrs := embTableAttr '' attrs + +def embVMAttrs (attrs : Set ArchVMAttributes_A.vm_attribute) : VMAttributes := embVMAttribute '' attrs + +def embPTE : Arch_Structs_A.pte → PTE + | .InvalidPTE => .invalidPTE + | .SmallPagePTE p attr rights => .smallPagePTE p (embVMAttrs attr) (embRightsSet rights) + +def embPDE : Arch_Structs_A.pde → PDE + | .InvalidPDE => .invalidPDE + | .PageTablePDE p attr rights => .pageTablePDE p (embTableAttrs attr) (embRightsSet rights) + | .LargePagePDE p attr rights => .largePagePDE p (embVMAttrs attr) (embRightsSet rights) + +def embPDPTE : Arch_Structs_A.pdpte → PDPTE + | .InvalidPDPTE => .invalidPDPTE + | .PageDirectoryPDPTE p attr rights => + .pageDirectoryPDPTE p (embTableAttrs attr) (embRightsSet rights) + | .HugePagePDPTE p attr rights => .hugePagePDPTE p (embVMAttrs attr) (embRightsSet rights) + +def embPML4E : Arch_Structs_A.pml4e → PML4E + | .InvalidPML4E => .invalidPML4E + | .PDPointerTablePML4E p attr rights => + .pdPointerTablePML4E p (embTableAttrs attr) (embRightsSet rights) + +def embArchCap : Arch_Structs_A.arch_cap → ArchCap + | .ASIDPoolCap p b => .asidPoolCap p b + | .ASIDControlCap => .asidControlCap + | .IOPortCap first last => .ioPortCap first last none + | .IOPortControlCap => .ioPortControlCap + | .PageCap d r rs m s info => .pageCap d r (embRightsSet rs) (embVMMapType m) (embVMPageSize s) info + | .PageTableCap r m => .pageTableCap r m + | .PageDirectoryCap r m => .pageDirectoryCap r m + | .PDPointerTableCap r m => .pdPointerTableCap r m + | .PML4Cap r m => .pml4Cap r m + +@[simp] theorem embVMMapType_eq_iff (a b) : + embVMMapType a = embVMMapType b ↔ a = b := by + cases a <;> cases b <;> simp [embVMMapType] + +theorem embArchCap_injective : Function.Injective embArchCap := by + intro a b h + cases a <;> cases b <;> simp [embArchCap] at h ⊢ + all_goals exact h + +@[simp] theorem embArchCap_eq_iff (a b) : + embArchCap a = embArchCap b ↔ a = b := embArchCap_injective.eq_iff + +def embArchKobj : Arch_Structs_A.arch_kernel_obj → ArchKernelObj + | .ASIDPool f => .asidPool f + | .PageTable f => .pageTable (embPTE ∘ f) + | .PageDirectory f => .pageDirectory (embPDE ∘ f) + | .PDPointerTable f => .pdPointerTable (embPDPTE ∘ f) + | .PageMapL4 f => .pageMapL4 (embPML4E ∘ f) + | .DataPage d n => .dataPage d (embVMPageSize n) + +def embX64IrqState : Arch_Structs_A.X64IRQState → X64IRQState + | .IRQFree => .irqFree + | .IRQReserved => .irqReserved + | .IRQMSI bus dev func handle => .irqMSI bus dev func handle + | .IRQIOAPIC apic pin level polarity masked => .irqIOAPIC apic pin level polarity masked + +def embRegionUse : Arch_Structs_B.x64vspace_region_use → X64VSpaceRegionUse + | .X64VSpaceUserRegion => .x64VSpaceUserRegion + | .X64VSpaceInvalidRegion => .x64VSpaceInvalidRegion + | .X64VSpaceKernelWindow => .x64VSpaceKernelWindow + | .X64VSpaceDeviceWindow => .x64VSpaceDeviceWindow + +def embCr3 : Arch_Structs_A.cr3 → Cr3 + | .mk base pcid => .cr3 base pcid + +def embArchState (platform : X64Platform) (a : Arch_Structs_A.arch_state) : ArchState where + x64AsidTable i := if i.toNat < 8 then a.x64_asid_table (i.setWidth 3) else none + x64GlobalPml4 := a.x64_global_pml4 + x64KernelVspace := embRegionUse ∘ a.x64_kernel_vspace + x64GlobalPts := a.x64_global_pts + x64GlobalPdpts := a.x64_global_pdpts + x64GlobalPds := a.x64_global_pds + x64CurrentCr3 := embCr3 a.x64_current_cr3 + x64AllocatedIoPorts := a.x64_allocated_io_ports + x64NumIoapics := a.x64_num_ioapics + x64IoapicNirqs := a.x64_ioapic_nirqs + x64IrqState := embX64IrqState ∘ a.x64_irq_state + x64CurrentFpuOwner := a.x64_current_fpu_owner + x64Plat := platform + +/-- Transport the base HOL object codes to the port's object types. -/ +def embAObjectType : Arch_Structs_A.aobject_type → Fl4Spec.AObjectType + | .SmallPageObj => .smallPageObj + | .LargePageObj => .largePageObj + | .HugePageObj => .hugePageObj + | .PageTableObj => .pageTableObj + | .PageDirectoryObj => .pageDirectoryObj + | .PDPTObj => .pdptObj + | .PML4Obj => .pml4Obj + | .ASIDPoolObj => .asidPoolObj + +def embCap : Structures_A.cap → Cap + | .NullCap => .nullCap + | .UntypedCap d r b fi => .untypedCap d r b fi + | .EndpointCap r b rs => .endpointCap r b (embRightsSet rs) + | .NotificationCap r b rs => .notificationCap r b (embRightsSet rs) + | .ReplyCap r rs => .replyCap r (embRightsSet rs) + | .CNodeCap r b g => .cnodeCap r b g + | .ThreadCap r => .threadCap r + | .DomainCap => .domainCap + | .SchedContextCap r b => .schedContextCap r b + | .SchedControlCap => .schedControlCap + | .IRQControlCap => .irqControlCap + | .IRQHandlerCap i => .irqHandlerCap (embIrq i) + | .Zombie r b n => .zombie r b n + | .ArchObjectCap a => .archObjectCap (embArchCap a) + +theorem embCap_injective : Function.Injective embCap := by + intro a b h; cases a <;> cases b <;> simp [embCap] at h ⊢ <;> exact h + +@[simp] theorem embCap_eq_iff (a b) : embCap a = embCap b ↔ a = b := embCap_injective.eq_iff + +def embCnodeContents (cs : List Bool → Option Structures_A.cap) : CnodeContents := + fun i => (cs i).map embCap + +theorem embCnodeContents_injective : Function.Injective embCnodeContents := by + intro a b h; funext i + have hi := congrFun h i + simp only [embCnodeContents] at hi + cases ha : a i <;> cases hb : b i <;> simp [ha, hb] at hi ⊢ + exact hi + +def embMessageInfo : Structures_A.message_info → MessageInfo + | .MI l e u lb => ⟨l, e, u, lb⟩ + +theorem embMessageInfo_injective : Function.Injective embMessageInfo := by + intro a b h; cases a; cases b; simp [embMessageInfo] at h; rcases h with ⟨rfl, rfl, rfl, rfl⟩; rfl + +def embEndpoint : Structures_A.endpoint → Endpoint + | .IdleEP => .idleEP + | .SendEP q => .sendEP q + | .RecvEP q => .recvEP q + +theorem embEndpoint_injective : Function.Injective embEndpoint := by + intro a b h; cases a <;> cases b <;> simp [embEndpoint] at h ⊢ <;> exact h + +def embNtfn : Structures_A.ntfn → Ntfn + | .IdleNtfn => .idleNtfn + | .WaitingNtfn q => .waitingNtfn q + | .ActiveNtfn b => .activeNtfn b + +theorem embNtfn_injective : Function.Injective embNtfn := by + intro a b h; cases a <;> cases b <;> simp [embNtfn] at h ⊢ <;> exact h + +def embNotification (n : Structures_A.notification) : Notification := + ⟨embNtfn n.ntfn_obj, n.ntfn_bound_tcb, n.ntfn_sc⟩ + +theorem embNotification_injective : Function.Injective embNotification := by + intro a b h; cases a with | mk o1 b1 s1 u1 => cases b with | mk o2 b2 s2 u2 => + cases u1; cases u2; simp [embNotification] at h; rcases h with ⟨h1, rfl, rfl⟩ + rw [embNtfn_injective h1] + +def embSenderPayload (p : Structures_A.sender_payload) : SenderPayload := + ⟨p.sender_badge, p.sender_can_grant, p.sender_can_grant_reply, p.sender_is_call⟩ + +theorem embSenderPayload_injective : Function.Injective embSenderPayload := by + intro a b h; cases a with | mk x1 x2 x3 x4 u1 => cases b with | mk y1 y2 y3 y4 u2 => + cases u1; cases u2; simp [embSenderPayload] at h; rcases h with ⟨rfl, rfl, rfl, rfl⟩; rfl + +def embReceiverPayload (p : Structures_A.receiver_payload) : ReceiverPayload := + ⟨p.receiver_can_grant⟩ + +theorem embReceiverPayload_injective : Function.Injective embReceiverPayload := by + intro a b h; cases a with | mk x1 u1 => cases b with | mk y1 u2 => + cases u1; cases u2; simp [embReceiverPayload] at h; subst h; rfl + +def embThreadState : Structures_A.thread_state → ThreadState + | .Running => .running + | .Inactive => .inactive + | .Restart => .restart + | .BlockedOnReceive ep ro d => .blockedOnReceive ep ro (embReceiverPayload d) + | .BlockedOnSend ep d => .blockedOnSend ep (embSenderPayload d) + | .BlockedOnReply r => .blockedOnReply r + | .BlockedOnNotification n => .blockedOnNotification n + | .IdleThreadState => .idleThreadState + +theorem embThreadState_injective : Function.Injective embThreadState := by + intro a b h; cases a <;> cases b <;> simp [embThreadState] at h ⊢ + · rcases h with ⟨rfl, rfl, h3⟩; exact ⟨rfl, rfl, embReceiverPayload_injective h3⟩ + · rcases h with ⟨rfl, h2⟩; exact ⟨rfl, embSenderPayload_injective h2⟩ + · exact h + · exact h + +@[simp] theorem embThreadState_eq_iff (a b) : + embThreadState a = embThreadState b ↔ a = b := embThreadState_injective.eq_iff + +def embTcb (t : Structures_A.tcb) : Tcb := + { tcbCtable := embCap t.tcb_ctable, + tcbVtable := embCap t.tcb_vtable, + tcbIpcframe := embCap t.tcb_ipcframe, + tcbFaultHandler := embCap t.tcb_fault_handler, + tcbTimeoutHandler := embCap t.tcb_timeout_handler, + tcbState := embThreadState t.tcb_state, + tcbIpcBuffer := t.tcb_ipc_buffer, + tcbFault := t.tcb_fault.map embFault, + tcbBoundNotification := t.tcb_bound_notification, + tcbMcpriority := t.tcb_mcpriority, + tcbSchedContext := t.tcb_sched_context, + tcbYieldTo := t.tcb_yield_to, + tcbPriority := t.tcb_priority, + tcbDomain := t.tcb_domain, + tcbFlags := embTcbFlags t.tcb_flags, + tcbArch := embArchTcb t.tcb_arch, + tcbEpt := .nullCap } + +def embRefill (r : Structures_A.refill) : Refill := ⟨r.r_time, r.r_amount⟩ + +theorem embRefill_injective : Function.Injective embRefill := by + intro a b h; cases a with | mk x1 x2 u1 => cases b with | mk y1 y2 u2 => + cases u1; cases u2; simp [embRefill] at h; rcases h with ⟨rfl, rfl⟩; rfl + +def embSchedContext (sc : Structures_A.sched_context) : SchedContext := + { scPeriod := sc.sc_period, + scBudget := sc.sc_budget, + scConsumed := sc.sc_consumed, + scTcb := sc.sc_tcb, + scNtfn := sc.sc_ntfn, + scRefills := sc.sc_refills.map embRefill, + scRefillMax := sc.sc_refill_max, + scBadge := sc.sc_badge, + scYieldFrom := sc.sc_yield_from, + scReplies := sc.sc_replies, + scSporadic := sc.sc_sporadic } + +def embReply (r : Structures_A.reply) : Reply := ⟨r.reply_tcb, r.reply_sc⟩ + +def embKernelObject : Structures_A.kernel_object → KernelObject + | .CNode sz cs => .cnode sz (embCnodeContents cs) + | .TCB t => .tcb (embTcb t) + | .Endpoint ep => .endpoint (embEndpoint ep) + | .Notification n => .notification (embNotification n) + | .SchedContext sc n => .schedContext (embSchedContext sc) n + | .Reply r => .reply (embReply r) + | .ArchObj ao => .archObj (embArchKobj ao) + +def embAAType : Arch_Structs_A.aa_type_T → AAType + | .AASIDPool => .aASIDPool + | .APageTable => .aPageTable + | .APageDirectory => .aPageDirectory + | .APDPointerTable => .aPDPointerTable + | .APageMapL4 => .aPageMapL4 + | .AUserData sz => .aUserData (embVMPageSize sz) + | .ADeviceData sz => .aDeviceData (embVMPageSize sz) + +theorem embAAType_injective : Function.Injective embAAType := by + intro a b h + cases a <;> cases b <;> simp [embAAType] at h ⊢ <;> exact h + +def embAType : Structures_A.a_type_T → AType + | .ATCB => .aTCB + | .AEndpoint => .aEndpoint + | .ANTFN => .aNTFN + | .ASchedContext n => .aSchedContext n + | .AReply => .aReply + | .ACapTable n => .aCapTable n + | .AGarbage n => .aGarbage n + | .AArch a => .aArch (embAAType a) + +def embCapTransfer (ct : Structures_A.captransfer) : CapTransfer := + ⟨ct.ct_receive_root, ct.ct_receive_index, ct.ct_receive_depth⟩ + +def embDetExt (d : Deterministic_A.det_ext) : DetExt := + ⟨d.work_units_completed_internal, d.cdt_list_internal⟩ + +theorem embDetExt_injective : Function.Injective embDetExt := by + intro a b h; cases a with | mk x1 x2 u1 => cases b with | mk y1 y2 u2 => + cases u1; cases u2; simp [embDetExt] at h; rcases h with ⟨rfl, rfl⟩; rfl + + +end + +end L4vRefX64.Rel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Extension.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Extension.lean new file mode 100644 index 000000000..799fbf7d9 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Extension.lean @@ -0,0 +1,59 @@ +import L4vRefX64.Rel.State + +namespace L4vRefX64.Rel + +open L4vRefX64.Prim +open L4vRefX64.Spec +open Fl4Spec + +noncomputable section + +class StateExtRel + (RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop) + (ZH ZL : Type) [Nonempty ZH] [Deterministic_A.state_ext_class ZH] [StateExt ZL] where + exstRel : ZH → ZL → Prop + extInit_rel : exstRel Deterministic_A.state_ext_class.ext_init StateExt.extInit + selectSwitch_eq : ∀ zH zL, exstRel zH zL → + Deterministic_A.state_ext_class.select_switch zH = StateExt.selectSwitch zL + unwrapExt_rel : ∀ sH sL, StateRel RestRel exstRel sH sL → + StateExt.selectSwitch sL.exst = true → + StateRel RestRel (FunRel embDetExt) + (Deterministic_A.state_ext_class.unwrap_ext sH) (StateExt.unwrapExt sL) + wrapExt_rel : ∀ fH fL, + (∀ dH dL, dL = embDetExt dH → fL dL = embDetExt (fH dH)) → + ∀ zH zL, exstRel zH zL → + exstRel (Deterministic_A.state_ext_class.wrap_ext fH zH) (StateExt.wrapExt fL zL) + wrapExtBool_rel : ∀ mH mL, + MRel (StateRel RestRel (FunRel embDetExt)) Eq mH mL → + MRel (StateRel RestRel exstRel) Eq + (Deterministic_A.state_ext_class.wrap_ext_bool mH) (StateExt.wrapExtBool mL) + wrapExtOp_rel : ∀ mH mL, + MRel (StateRel RestRel (FunRel embDetExt)) Eq mH mL → + MRel (StateRel RestRel exstRel) Eq + (Deterministic_A.state_ext_class.wrap_ext_op mH) (StateExt.wrapExtOp mL) + +instance {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} : + StateExtRel RestRel Unit Unit where + exstRel := Eq + extInit_rel := rfl + selectSwitch_eq _ _ _ := rfl + unwrapExt_rel _ _ _ h := by simp [StateExt.selectSwitch] at h + wrapExt_rel _ _ _ _ _ _ := rfl + wrapExtBool_rel _ _ _ := by + change MRel _ Eq (holSelect Set.univ) (NonDet.select Set.univ) + exact mrel_select (setRel_eq Set.univ) + wrapExtOp_rel _ _ _ := mrel_return rfl + +instance {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} : + StateExtRel RestRel Deterministic_A.det_ext DetExt where + exstRel := FunRel embDetExt + extInit_rel := by rfl + selectSwitch_eq _ _ _ := rfl + unwrapExt_rel _ _ h _ := h + wrapExt_rel _ _ hf _ _ hz := hf _ _ hz + wrapExtBool_rel _ _ hm := hm + wrapExtOp_rel _ _ hm := hm + +end + +end L4vRefX64.Rel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Invocation.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Invocation.lean new file mode 100644 index 000000000..0de47ab72 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Invocation.lean @@ -0,0 +1,315 @@ +import L4vRefX64.Rel.Embed +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.InvocationLabels_A + +namespace L4vRefX64.Rel + +open L4vRefX64.Prim L4vRefX64.Spec +open Fl4Spec + +noncomputable section + +def embArchInvocationLabel : ArchInvocationLabels_H.arch_invocation_label → ArchInvocationLabel + | .X64PDPTMap => .x64PDPTMap + | .X64PDPTUnmap => .x64PDPTUnmap + | .X64PageDirectoryMap => .x64PageDirectoryMap + | .X64PageDirectoryUnmap => .x64PageDirectoryUnmap + | .X64PageTableMap => .x64PageTableMap + | .X64PageTableUnmap => .x64PageTableUnmap + | .X64PageMap => .x64PageMap + | .X64PageUnmap => .x64PageUnmap + | .X64PageGetAddress => .x64PageGetAddress + | .X64ASIDControlMakePool => .x64ASIDControlMakePool + | .X64ASIDPoolAssign => .x64ASIDPoolAssign + | .X64IOPortControlIssue => .x64IOPortControlIssue + | .X64IOPortIn8 => .x64IOPortIn8 + | .X64IOPortIn16 => .x64IOPortIn16 + | .X64IOPortIn32 => .x64IOPortIn32 + | .X64IOPortOut8 => .x64IOPortOut8 + | .X64IOPortOut16 => .x64IOPortOut16 + | .X64IOPortOut32 => .x64IOPortOut32 + | .X64IRQIssueIRQHandlerIOAPIC => .x64IRQIssueIRQHandlerIOAPIC + | .X64IRQIssueIRQHandlerMSI => .x64IRQIssueIRQHandlerMSI + +def unembArchInvocationLabel : ArchInvocationLabel → ArchInvocationLabels_H.arch_invocation_label + | .x64PDPTMap => .X64PDPTMap + | .x64PDPTUnmap => .X64PDPTUnmap + | .x64PageDirectoryMap => .X64PageDirectoryMap + | .x64PageDirectoryUnmap => .X64PageDirectoryUnmap + | .x64PageTableMap => .X64PageTableMap + | .x64PageTableUnmap => .X64PageTableUnmap + | .x64PageMap => .X64PageMap + | .x64PageUnmap => .X64PageUnmap + | .x64PageGetAddress => .X64PageGetAddress + | .x64ASIDControlMakePool => .X64ASIDControlMakePool + | .x64ASIDPoolAssign => .X64ASIDPoolAssign + | .x64IOPortControlIssue => .X64IOPortControlIssue + | .x64IOPortIn8 => .X64IOPortIn8 + | .x64IOPortIn16 => .X64IOPortIn16 + | .x64IOPortIn32 => .X64IOPortIn32 + | .x64IOPortOut8 => .X64IOPortOut8 + | .x64IOPortOut16 => .X64IOPortOut16 + | .x64IOPortOut32 => .X64IOPortOut32 + | .x64IRQIssueIRQHandlerIOAPIC => .X64IRQIssueIRQHandlerIOAPIC + | .x64IRQIssueIRQHandlerMSI => .X64IRQIssueIRQHandlerMSI + +@[simp] theorem unembArchInvocationLabel_emb (label : ArchInvocationLabels_H.arch_invocation_label) : + unembArchInvocationLabel (embArchInvocationLabel label) = label := by cases label <;> rfl + +@[simp] theorem embArchInvocationLabel_unemb (label : ArchInvocationLabel) : + embArchInvocationLabel (unembArchInvocationLabel label) = label := by cases label <;> rfl + +def embGenInvocationLabels : InvocationLabels_H.gen_invocation_labels → GenInvocationLabels + | .InvalidInvocation => .invalidInvocation + | .UntypedRetype => .untypedRetype + | .TCBReadRegisters => .tcbReadRegisters + | .TCBWriteRegisters => .tcbWriteRegisters + | .TCBCopyRegisters => .tcbCopyRegisters + | .TCBConfigure => .tcbConfigure + | .TCBSetPriority => .tcbSetPriority + | .TCBSetMCPriority => .tcbSetMCPriority + | .TCBSetSchedParams => .tcbSetSchedParams + | .TCBSetTimeoutEndpoint => .tcbSetTimeoutEndpoint + | .TCBSetIPCBuffer => .tcbSetIPCBuffer + | .TCBSetSpace => .tcbSetSpace + | .TCBSuspend => .tcbSuspend + | .TCBResume => .tcbResume + | .TCBBindNotification => .tcbBindNotification + | .TCBUnbindNotification => .tcbUnbindNotification + | .TCBSetTLSBase => .tcbSetTLSBase + | .TCBSetFlags => .tcbSetFlags + | .CNodeRevoke => .cnodeRevoke + | .CNodeDelete => .cnodeDelete + | .CNodeCancelBadgedSends => .cnodeCancelBadgedSends + | .CNodeCopy => .cnodeCopy + | .CNodeMint => .cnodeMint + | .CNodeMove => .cnodeMove + | .CNodeMutate => .cnodeMutate + | .CNodeRotate => .cnodeRotate + | .IRQIssueIRQHandler => .irqIssueIRQHandler + | .IRQAckIRQ => .irqAckIRQ + | .IRQSetIRQHandler => .irqSetIRQHandler + | .IRQClearIRQHandler => .irqClearIRQHandler + | .DomainSetSet => .domainSetSet + | .DomainScheduleConfigure => .domainScheduleConfigure + | .DomainScheduleSetStart => .domainScheduleSetStart + | .SchedControlConfigureFlags => .schedControlConfigureFlags + | .SchedContextBind => .schedContextBind + | .SchedContextUnbind => .schedContextUnbind + | .SchedContextUnbindObject => .schedContextUnbindObject + | .SchedContextConsumed => .schedContextConsumed + | .SchedContextYieldTo => .schedContextYieldTo + +def unembGenInvocationLabels : GenInvocationLabels → InvocationLabels_H.gen_invocation_labels + | .invalidInvocation => .InvalidInvocation + | .untypedRetype => .UntypedRetype + | .tcbReadRegisters => .TCBReadRegisters + | .tcbWriteRegisters => .TCBWriteRegisters + | .tcbCopyRegisters => .TCBCopyRegisters + | .tcbConfigure => .TCBConfigure + | .tcbSetPriority => .TCBSetPriority + | .tcbSetMCPriority => .TCBSetMCPriority + | .tcbSetSchedParams => .TCBSetSchedParams + | .tcbSetTimeoutEndpoint => .TCBSetTimeoutEndpoint + | .tcbSetIPCBuffer => .TCBSetIPCBuffer + | .tcbSetSpace => .TCBSetSpace + | .tcbSuspend => .TCBSuspend + | .tcbResume => .TCBResume + | .tcbBindNotification => .TCBBindNotification + | .tcbUnbindNotification => .TCBUnbindNotification + | .tcbSetTLSBase => .TCBSetTLSBase + | .tcbSetFlags => .TCBSetFlags + | .cnodeRevoke => .CNodeRevoke + | .cnodeDelete => .CNodeDelete + | .cnodeCancelBadgedSends => .CNodeCancelBadgedSends + | .cnodeCopy => .CNodeCopy + | .cnodeMint => .CNodeMint + | .cnodeMove => .CNodeMove + | .cnodeMutate => .CNodeMutate + | .cnodeRotate => .CNodeRotate + | .irqIssueIRQHandler => .IRQIssueIRQHandler + | .irqAckIRQ => .IRQAckIRQ + | .irqSetIRQHandler => .IRQSetIRQHandler + | .irqClearIRQHandler => .IRQClearIRQHandler + | .domainSetSet => .DomainSetSet + | .domainScheduleConfigure => .DomainScheduleConfigure + | .domainScheduleSetStart => .DomainScheduleSetStart + | .schedControlConfigureFlags => .SchedControlConfigureFlags + | .schedContextBind => .SchedContextBind + | .schedContextUnbind => .SchedContextUnbind + | .schedContextUnbindObject => .SchedContextUnbindObject + | .schedContextConsumed => .SchedContextConsumed + | .schedContextYieldTo => .SchedContextYieldTo + +@[simp] theorem unembGenInvocationLabels_emb (label : InvocationLabels_H.gen_invocation_labels) : + unembGenInvocationLabels (embGenInvocationLabels label) = label := by cases label <;> rfl + +@[simp] theorem embGenInvocationLabels_unemb (label : GenInvocationLabels) : + embGenInvocationLabels (unembGenInvocationLabels label) = label := by cases label <;> rfl + + +def embInvocationLabel : InvocationLabels_H.invocation_label → InvocationLabel + | .GenInvocationLabel l => .genInvocationLabel (embGenInvocationLabels l) + | .ArchInvocationLabel l => .archInvocationLabel (embArchInvocationLabel l) + +def unembInvocationLabel : InvocationLabel → InvocationLabels_H.invocation_label + | .genInvocationLabel l => .GenInvocationLabel (unembGenInvocationLabels l) + | .archInvocationLabel l => .ArchInvocationLabel (unembArchInvocationLabel l) + +@[simp] theorem unembInvocationLabel_emb (x) : unembInvocationLabel (embInvocationLabel x) = x := by cases x <;> simp [embInvocationLabel, unembInvocationLabel] +@[simp] theorem embInvocationLabel_unemb (x) : embInvocationLabel (unembInvocationLabel x) = x := by cases x <;> simp [embInvocationLabel, unembInvocationLabel] +theorem embInvocationLabel_injective : Function.Injective embInvocationLabel := Function.LeftInverse.injective unembInvocationLabel_emb +@[simp] theorem embInvocationLabel_eq_iff (a b) : embInvocationLabel a = embInvocationLabel b ↔ a = b := embInvocationLabel_injective.eq_iff + + +theorem invocationLabels_enum_eq : + InvocationLabels_H.enum_invocation_label.map embInvocationLabel = InvocationLabel.enum := rfl + +theorem genInvocationLabels_enum_eq : + InvocationLabels_H.enum_gen_invocation_labels.map embGenInvocationLabels = GenInvocationLabels.enum := rfl + +def embVMPageEntry : Arch_Structs_A.vm_page_entry → VMPageEntry + | .VMPTE pte => .vmPTE (embPTE pte) + | .VMPDE pde => .vmPDE (embPDE pde) + | .VMPDPTE pdpte => .vmPDPTE (embPDPTE pdpte) + +def embPdptInv : ArchInvocation_A.pdpt_invocation → PdptInvocation + | .PDPTMap cap slot entry target root => .pdptMap (embCap cap) slot (embPML4E entry) target root + | .PDPTUnmap cap slot => .pdptUnmap (embCap cap) slot + +def embPageDirectoryInv : ArchInvocation_A.page_directory_invocation → PageDirectoryInvocation + | .PageDirectoryMap cap slot entry target root => + .pageDirectoryMap (embCap cap) slot (embPDPTE entry) target root + | .PageDirectoryUnmap cap slot => .pageDirectoryUnmap (embCap cap) slot + +def embPageTableInv : ArchInvocation_A.page_table_invocation → PageTableInvocation + | .PageTableMap cap slot entry target root => .pageTableMap (embCap cap) slot (embPDE entry) target root + | .PageTableUnmap cap slot => .pageTableUnmap (embCap cap) slot + +def embAsidControlInv : ArchInvocation_A.asid_control_invocation → AsidControlInvocation + | .MakePool frame slot parent base => .makePool frame slot parent base + +def embAsidPoolInv : ArchInvocation_A.asid_pool_invocation → AsidPoolInvocation + | .Assign asid pool slot => .assign asid pool slot + +def embPageInv : ArchInvocation_A.page_invocation → PageInvocation + | .PageMap cap slot (entry, target) root => .pageMap (embCap cap) slot (embVMPageEntry entry, target) root + | .PageUnmap cap slot => .pageUnmap (embArchCap cap) slot + | .PageGetAddr address => .pageGetAddr address + +def embIoPortData : ArchInvocation_A.io_port_invocation_data → IoPortInvocationData + | .IOPortIn8 => .ioPortIn8 + | .IOPortIn16 => .ioPortIn16 + | .IOPortIn32 => .ioPortIn32 + | .IOPortOut8 data => .ioPortOut8 data + | .IOPortOut16 data => .ioPortOut16 data + | .IOPortOut32 data => .ioPortOut32 data + +def embIoPortInv : ArchInvocation_A.io_port_invocation → IoPortInvocation + | .IOPortInvocation port data => .ioPortInvocation port (embIoPortData data) + +def embIoPortControlInv : ArchInvocation_A.io_port_control_invocation → IoPortControlInvocation + | .IOPortControlInvocation first last dest control => .ioPortControlInvocation first last dest control + +def embArchInv : ArchInvocation_A.arch_invocation → ArchInvocation + | .InvokePageTable inv => .invokePageTable (embPageTableInv inv) + | .InvokePageDirectory inv => .invokePageDirectory (embPageDirectoryInv inv) + | .InvokePDPT inv => .invokePDPT (embPdptInv inv) + | .InvokePage inv => .invokePage (embPageInv inv) + | .InvokeASIDControl inv => .invokeASIDControl (embAsidControlInv inv) + | .InvokeASIDPool inv => .invokeASIDPool (embAsidPoolInv inv) + | .InvokeIOPort inv => .invokeIOPort (embIoPortInv inv) + | .InvokeIOPortControl inv => .invokeIOPortControl (embIoPortControlInv inv) + +def embArchCopyRegSets : ArchInvocation_A.arch_copy_register_sets → ArchCopyRegisterSets + | .X64NoExtraRegisters => .x64NoExtraRegisters + +def embArchIrqControlInv : ArchInvocation_A.arch_irq_control_invocation → ArchIrqControlInvocation + | .IssueIRQHandlerIOAPIC irq dest src ioapic pin level polarity vector => + .issueIRQHandlerIOAPIC irq dest src ioapic pin level polarity vector + | .IssueIRQHandlerMSI irq dest src bus dev func handle => + .issueIRQHandlerMSI irq dest src bus dev func handle + +def embApiObjectType : Structures_A.apiobject_type → ApiObjectType + | .Untyped => .untyped + | .TCBObject => .tcbObject + | .EndpointObject => .endpointObject + | .NotificationObject => .notificationObject + | .CapTableObject => .capTableObject + | .SchedContextObject => .schedContextObject + | .ReplyObject => .replyObject + | .ArchObject t => .archObject (embAObjectType t) + +def embCnodeInv : Invocations_A.cnode_invocation → CnodeInvocation + | .InsertCall c s d => .insertCall (embCap c) s d + | .MoveCall c s d => .moveCall (embCap c) s d + | .RevokeCall s => .revokeCall s + | .DeleteCall s => .deleteCall s + | .RotateCall c1 c2 s1 s2 s3 => .rotateCall (embCap c1) (embCap c2) s1 s2 s3 + | .CancelBadgedSendsCall c => .cancelBadgedSendsCall (embCap c) + +def embUntypedInv : Invocations_A.untyped_invocation → UntypedInvocation + | .Retype sl r b rb nt sz sls d => .retype sl r b rb (embApiObjectType nt) sz sls d + +def embTcbInv : Invocations_A.tcb_invocation → TcbInvocation + | .WriteRegisters d r vs a => .writeRegisters d r vs (embArchCopyRegSets a) + | .ReadRegisters s susp n a => .readRegisters s susp n (embArchCopyRegSets a) + | .CopyRegisters d s ss rt tf ti a => .copyRegisters d s ss rt tf ti (embArchCopyRegSets a) + | .ThreadControlCaps t sl fh th cr vr buf => + .threadControlCaps t sl + (fh.map fun (c, p) => (embCap c, p)) + (th.map fun (c, p) => (embCap c, p)) + (cr.map fun (c, p) => (embCap c, p)) + (vr.map fun (c, p) => (embCap c, p)) + (buf.map fun (v, o) => (v, o.map fun (c, p) => (embCap c, p))) + | .ThreadControlSched t sl fh mcp prio sc => + .threadControlSched t sl + (fh.map fun (c, p) => (embCap c, p)) + mcp prio sc + | .Suspend t => .suspend t + | .Resume t => .resume t + | .NotificationControl t n => .notificationControl t n + | .SetTLSBase t b => .setTLSBase t b + | .SetFlags t cl st => .setFlags t (embTcbFlags cl) (embTcbFlags st) + +def embSchedContextInv : Invocations_A.sched_context_invocation → SchedContextInvocation + | .InvokeSchedContextConsumed p => .invokeSchedContextConsumed p + | .InvokeSchedContextBind p c => .invokeSchedContextBind p (embCap c) + | .InvokeSchedContextUnbindObject p c => .invokeSchedContextUnbindObject p (embCap c) + | .InvokeSchedContextUnbind p => .invokeSchedContextUnbind p + | .InvokeSchedContextYieldTo p => .invokeSchedContextYieldTo p + +def embSchedControlInv : Invocations_A.sched_control_invocation → SchedControlInvocation + | .InvokeSchedControlConfigureFlags p b per ref bg fl => + .invokeSchedControlConfigureFlags p b per ref bg fl + +def embIrqControlInv : Invocations_A.irq_control_invocation → IrqControlInvocation + | .IRQControl i h c => .irqControl (embIrq i) h c + | .ArchIRQControl a => .archIRQControl (embArchIrqControlInv a) + +def embIrqHandlerInv : Invocations_A.irq_handler_invocation → IrqHandlerInvocation + | .ACKIrq i => .aCKIrq (embIrq i) + | .SetIRQHandler i c s => .setIRQHandler (embIrq i) (embCap c) s + | .ClearIRQHandler i => .clearIRQHandler (embIrq i) + +def embDomainInv : Invocations_A.domain_invocation → DomainInvocation + | .InvokeDomainSet t d => .invokeDomainSet t d + | .InvokeDomainScheduleSetStart i => .invokeDomainScheduleSetStart i + | .InvokeDomainScheduleConfigure i d dur => .invokeDomainScheduleConfigure i d dur + +def embInvocation : Invocations_A.invocation → Invocation + | .InvokeUntyped i => .invokeUntyped (embUntypedInv i) + | .InvokeEndpoint ep b cg cgr => .invokeEndpoint ep b cg cgr + | .InvokeNotification n b => .invokeNotification n b + | .InvokeReply r cg => .invokeReply r cg + | .InvokeTCB i => .invokeTCB (embTcbInv i) + | .InvokeDomain i => .invokeDomain (embDomainInv i) + | .InvokeSchedContext i => .invokeSchedContext (embSchedContextInv i) + | .InvokeSchedControl i => .invokeSchedControl (embSchedControlInv i) + | .InvokeCNode i => .invokeCNode (embCnodeInv i) + | .InvokeIRQControl i => .invokeIRQControl (embIrqControlInv i) + | .InvokeIRQHandler i => .invokeIRQHandler (embIrqHandlerInv i) + | .InvokeArchObject i => .invokeArchObject (embArchInv i) + +end +end L4vRefX64.Rel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Lift.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Lift.lean new file mode 100644 index 000000000..4728c148f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Lift.lean @@ -0,0 +1,107 @@ +import L4vRefX64.Rel.State +import L4vRefX64.Spec.MachineMonad + +namespace L4vRefX64.Rel + +open L4vRefX64.Prim +open L4vRefX64.Spec +open Fl4Spec +open Classical + +noncomputable section + +theorem mrel_ignoreFailure {σH σL : Type} [Nonempty σH] {Rs : σH → σL → Prop} + {mH : HolNonDet σH Unit} {mL : NonDet σL Unit} + (hm : MRel Rs Eq mH mL) : + MRel Rs Eq (MachineMonad.ignore_failure mH) (Fl4Spec.ignoreFailure mL) := by + intro sH sL hs + obtain ⟨_, h1, h2⟩ := hm sH sL hs + have hempty : (mH sH).1 = ∅ ↔ (mL sL).1 = ∅ := by + constructor + · intro hH; ext ⟨aL, sL'⟩; simp only [Set.mem_empty_iff_false, iff_false] + intro hmL; obtain ⟨aH, sH', hmH, _, _⟩ := h2 aL sL' hmL; rw [hH] at hmH; exact hmH + · intro hL; ext ⟨aH, sH'⟩; simp only [Set.mem_empty_iff_false, iff_false] + intro hmH; obtain ⟨aL, sL', hmL, _, _⟩ := h1 aH sH' hmH; rw [hL] at hmL; exact hmL + by_cases hH : (mH sH).1 = ∅ + · have hL : (mL sL).1 = ∅ := hempty.mp hH + have heqH : MachineMonad.ignore_failure mH sH = ({((), sH)}, false) := by + unfold MachineMonad.ignore_failure + simp [hH, holIf_eq, holEq_eq_true, HolCompleteLattice.holBot, holInsert_eq] + have heqL : Fl4Spec.ignoreFailure mL sL = ({((), sL)}, False) := by + unfold Fl4Spec.ignoreFailure; simp [hL] + rw [heqH, heqL] + refine ⟨by simp, ?_, ?_⟩ + · intro aH sH' hm; simp at hm; exact ⟨(), sL, by simp, rfl, hm ▸ hs⟩ + · intro aL sL' hm; simp at hm; exact ⟨(), sH, by simp, rfl, hm ▸ hs⟩ + · have hL : (mL sL).1 ≠ ∅ := fun h => hH (hempty.mpr h) + have heqH : MachineMonad.ignore_failure mH sH = ((mH sH).1, false) := by + unfold MachineMonad.ignore_failure + simp [hH, holIf_eq, holEq_eq_true, HolCompleteLattice.holBot] + have heqL : Fl4Spec.ignoreFailure mL sL = ((mL sL).1, False) := by + unfold Fl4Spec.ignoreFailure; simp [hL] + rw [heqH, heqL] + exact ⟨by simp, h1, h2⟩ + +theorem mrel_machineRestLift + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {αH αL : Type} [Nonempty αH] {Ra : αH → αL → Prop} + {fH : HolNonDet MachineTypes.machine_state_rest αH} + {fL : MachineRestMonad αL} + (hf : MRel RestRel Ra fH fL) : + MRel (MachineStateRel RestRel) Ra + (MachineMonad.machine_rest_lift fH) (Fl4Spec.machineRestLift fL) := by + unfold MachineMonad.machine_rest_lift Fl4Spec.machineRestLift + refine mrel_bind (mrel_gets fun msH msL hms => hms.rest_rel) ?_ + intro mrH mrL hmr + obtain ⟨hfail, h1, h2⟩ := hf mrH mrL hmr + refine mrel_bind (mrel_selectF (Ra := ProdRel Ra RestRel) hfail ⟨?_, ?_⟩) ?_ + · rintro ⟨aH, mrH'⟩ hmH + obtain ⟨aL, mrL', hmL, ha, hr'⟩ := h1 aH mrH' hmH + exact ⟨(aL, mrL'), hmL, ha, hr'⟩ + · rintro ⟨aL, mrL'⟩ hmL + obtain ⟨aH, mrH', hmH, ha, hr'⟩ := h2 aL mrL' hmL + exact ⟨(aH, mrH'), hmH, ha, hr'⟩ + · rintro ⟨aH, mrH'⟩ ⟨aL, mrL'⟩ ⟨ha, hmr'⟩ + simp only [holCaseProd_eq] + refine mrel_kbind (mrel_modify fun msH msL hms => ?_) (mrel_return ha) + exact { hms with rest_rel := hmr' } + +theorem mrel_machineOpLift + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {fH : HolNonDet MachineTypes.machine_state_rest Unit} + {fL : MachineRestMonad Unit} + (hf : MRel RestRel Eq fH fL) : + MRel (MachineStateRel RestRel) Eq + (MachineMonad.machine_op_lift fH) (Fl4Spec.machineOpLift fL) := by + unfold MachineMonad.machine_op_lift Fl4Spec.machineOpLift + exact mrel_machineRestLift (mrel_ignoreFailure hf) + +theorem mrel_doMachineOp + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {ZH ZL αH αL : Type} [Nonempty ZH] [Nonempty αH] + {ExstRel : ZH → ZL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet MachineTypes.machine_state αH} + {mL : MachineMonad αL} + (hm : MRel (MachineStateRel RestRel) Ra mH mL) : + MRel (StateRel RestRel ExstRel) Ra + (Structures_A.do_machine_op mH) (Fl4Spec.doMachineOp mL) := by + unfold Structures_A.do_machine_op Fl4Spec.doMachineOp + refine mrel_bind (mrel_gets fun sH sL hs => hs.machineState_rel) ?_ + intro msH msL hms + obtain ⟨hfail, h1, h2⟩ := hm msH msL hms + refine mrel_bind (mrel_selectF (Ra := ProdRel Ra (MachineStateRel RestRel)) hfail ⟨?_, ?_⟩) ?_ + · rintro ⟨aH, msH'⟩ hmH + obtain ⟨aL, msL', hmL, ha, hms'⟩ := h1 aH msH' hmH + exact ⟨(aL, msL'), hmL, ha, hms'⟩ + · rintro ⟨aL, msL'⟩ hmL + obtain ⟨aH, msH', hmH, ha, hms'⟩ := h2 aL msL' hmL + exact ⟨(aH, msH'), hmH, ha, hms'⟩ + · rintro ⟨aH, msH'⟩ ⟨aL, msL'⟩ ⟨ha, hms'⟩ + simp only [holCaseProd_eq] + refine mrel_kbind (mrel_modify fun sH sL hs => ?_) (mrel_return ha) + exact { hs with machineState_rel := hms' } + + +end + +end L4vRefX64.Rel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Monad.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Monad.lean new file mode 100644 index 000000000..c34868edf --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/Monad.lean @@ -0,0 +1,1145 @@ +/- +Compositional monad and HOL-primitive transfer library bridging +`L4vRefX64.Prim` (`Bool`-valued logic, `HolNonDet`, `HolLookup`) and +`Fl4Spec` (`Prop`-valued logic, `NonDet`, `NonDetE`). +-/ +import L4vRefX64.Prim +import Fl4Spec.Monad + +namespace L4vRefX64.Rel + +open L4vRefX64.Prim +open Fl4Spec +open Classical + +noncomputable section + +/-! ## Basic HOL-to-Lean simplification lemmas -/ + +@[simp] theorem holNot_eq_true (b : Bool) : holNot b = true ↔ b ≠ true := by + cases b <;> simp [holNot] + +@[simp] theorem holConj_eq_true (a b : Bool) : holConj a b = true ↔ a = true ∧ b = true := by + cases a <;> cases b <;> simp [holConj] + +@[simp] theorem holDisj_eq_true (a b : Bool) : holDisj a b = true ↔ a = true ∨ b = true := by + cases a <;> cases b <;> simp [holDisj] + +@[simp] theorem holImp_eq_true (a b : Bool) : holImp a b = true ↔ (a = true → b = true) := by + cases a <;> cases b <;> simp [holImp] + +@[simp] theorem holEq_eq_true {α : Type} (a b : α) : holEq a b = true ↔ a = b := by + simp [holEq] + +@[simp] theorem holNotEq_eq_true {α : Type} (a b : α) : holNotEq a b = true ↔ a ≠ b := by + simp [holNotEq] + +@[simp] theorem holAll_eq_true {α : Type} (P : α → Bool) : + holAll P = true ↔ ∀ x, P x = true := by + simp [holAll] + +@[simp] theorem holEx_eq_true {α : Type} (P : α → Bool) : + holEx P = true ↔ ∃ x, P x = true := by + simp [holEx] + +@[simp] theorem holEx1_eq_true {α : Type} (P : α → Bool) : + holEx1 P = true ↔ ∃! x, P x = true := by + simp [holEx1] + +@[simp] theorem holIf_true {α : Type} (t e : α) : holIf true t e = t := rfl +@[simp] theorem holIf_false {α : Type} (t e : α) : holIf false t e = e := rfl +theorem holIf_eq {α : Type} (c : Bool) (t e : α) : holIf c t e = if c = true then t else e := by + cases c <;> rfl + +@[simp] theorem holLet_eq {α β : Type} (x : α) (f : α → β) : holLet x f = f x := rfl +@[simp] theorem holFunApp_eq {α β : Type} (f : α → β) (x : α) : holFunApp f x = f x := rfl +@[simp] theorem holComp_eq {α β γ : Type} (f : β → γ) (g : α → β) (x : α) : + holComp f g x = f (g x) := rfl +@[simp] theorem holId_eq {α : Type} (x : α) : holId x = x := rfl +@[simp] theorem holKBind_eq {α β : Type} (x : α) (y : β) : holKBind x y = x := rfl + +@[simp] theorem holFunUpd_eq {α β : Type} (f : α → β) (a : α) (b : β) : + holFunUpd f a b = Function.update f a b := by + funext x + simp [holFunUpd, Function.update] + +@[simp] theorem holCaseProd_eq {α β γ : Type} (f : α → β → γ) (p : α × β) : + holCaseProd f p = f p.1 p.2 := by + cases p; rfl + +@[simp] theorem holCaseOption_none {α β : Type} (n : β) (s : α → β) : + holCaseOption n s none = n := rfl +@[simp] theorem holCaseOption_some {α β : Type} (n : β) (s : α → β) (a : α) : + holCaseOption n s (some a) = s a := rfl + +@[simp] theorem holCaseSum_inl {α β γ : Type} (f : α → γ) (g : β → γ) (a : α) : + holCaseSum f g (.inl a) = f a := rfl +@[simp] theorem holCaseSum_inr {α β γ : Type} (f : α → γ) (g : β → γ) (b : β) : + holCaseSum f g (.inr b) = g b := rfl + +@[simp] theorem holCaseBool_true {α : Type} (t f : α) : holCaseBool t f true = t := rfl +@[simp] theorem holCaseBool_false {α : Type} (t f : α) : holCaseBool t f false = f := rfl + +@[simp] theorem holCaseList_nil {α β : Type} (n : β) (c : α → List α → β) : + holCaseList n c [] = n := rfl +@[simp] theorem holCaseList_cons {α β : Type} (n : β) (c : α → List α → β) (x : α) (xs : List α) : + holCaseList n c (x :: xs) = c x xs := rfl + +@[simp] theorem holMember_eq_true {α : Type} (x : α) (S : Set α) : + holMember x S = true ↔ x ∈ S := by + simp [holMember] + +@[simp] theorem holCollect_eq {α : Type} (P : α → Bool) : + holCollect P = {x | P x = true} := rfl + +@[simp] theorem holInsert_eq {α : Type} (x : α) (S : Set α) : + holInsert x S = insert x S := rfl + +@[simp] theorem holImage_eq {α β : Type} (f : α → β) (S : Set α) : + holImage f S = f '' S := rfl + +@[simp] theorem holLt_eq_true {α : Type} [HolOrd α] (a b : α) : + holLt a b = true ↔ HolOrd.ltVal a b := by + simp [holLt] + +@[simp] theorem holLe_eq_true {α : Type} [HolOrd α] (a b : α) : + holLe a b = true ↔ HolOrd.leVal a b := by + simp [holLe] + +@[simp] theorem holDvd_nat_eq_true (a b : Nat) : holDvd a b = true ↔ a ∣ b := by + simp [holDvd, HolDvd.dvdVal] + +@[simp] theorem holDvd_int_eq_true (a b : Int) : holDvd a b = true ↔ a ∣ b := by + simp [holDvd, HolDvd.dvdVal] + +@[simp] theorem holListSet_eq {α : Type} (xs : List α) : holListSet xs = {x | x ∈ xs} := rfl +@[simp] theorem holListMap_eq {α β : Type} (f : α → β) (xs : List α) : + holListMap f xs = xs.map f := rfl +@[simp] theorem holListAppend_eq {α : Type} (xs ys : List α) : + holListAppend xs ys = xs ++ ys := rfl +@[simp] theorem holListTake_eq {α : Type} (n : Nat) (xs : List α) : + holListTake n xs = xs.take n := rfl +@[simp] theorem holListDrop_eq {α : Type} (n : Nat) (xs : List α) : + holListDrop n xs = xs.drop n := rfl +@[simp] theorem holListFilter_eq {α : Type} (P : α → Bool) (xs : List α) : + holListFilter P xs = xs.filter P := rfl +@[simp] theorem holListRev_eq {α : Type} (xs : List α) : holListRev xs = xs.reverse := rfl +@[simp] theorem holListZip_eq {α β : Type} (xs : List α) (ys : List β) : + holListZip xs ys = xs.zip ys := rfl +@[simp] theorem holListReplicate_eq {α : Type} (n : Nat) (x : α) : + holListReplicate n x = List.replicate n x := rfl +@[simp] theorem holListUpdate_eq {α : Type} (xs : List α) (i : Nat) (v : α) : + holListUpdate xs i v = xs.set i v := rfl +@[simp] theorem holListButlast_eq {α : Type} (xs : List α) : + holButlast xs = xs.dropLast := rfl +@[simp] theorem holSize_list {α : Type} (xs : List α) : holSize xs = xs.length := rfl +@[simp] theorem holSize_fin {n : Nat} (x : Fin n) : holSize x = x.val := rfl +@[simp] theorem holSize_bv {w : Nat} (x : BitVec w) : holSize x = w := rfl +@[simp] theorem holSize_nat (n : Nat) : holSize n = n := rfl + +/-! ## Relations on `Option`, `Sum`/`Except`, `Prod`, `List`, `Set` -/ + +def OptRel {αH αL : Type} (Ra : αH → αL → Prop) : Option αH → Option αL → Prop + | none, none => True + | some aH, some aL => Ra aH aL + | _, _ => False + +def SumExceptRel {εH εL αH αL : Type} (Re : εH → εL → Prop) (Ra : αH → αL → Prop) : + Sum εH αH → Except εL αL → Prop + | .inl eH, .error eL => Re eH eL + | .inr aH, .ok aL => Ra aH aL + | _, _ => False + +def ProdRel {αH αL βH βL : Type} (Ra : αH → αL → Prop) (Rb : βH → βL → Prop) : + αH × βH → αL × βL → Prop := + fun p q => Ra p.1 q.1 ∧ Rb p.2 q.2 + +def SetRel {αH αL : Type} (Ra : αH → αL → Prop) (SH : Set αH) (SL : Set αL) : Prop := + (∀ aH ∈ SH, ∃ aL ∈ SL, Ra aH aL) ∧ (∀ aL ∈ SL, ∃ aH ∈ SH, Ra aH aL) + +inductive ListRel {αH αL : Type} (Ra : αH → αL → Prop) : List αH → List αL → Prop + | nil : ListRel Ra [] [] + | cons {aH aL asH asL} : Ra aH aL → ListRel Ra asH asL → ListRel Ra (aH :: asH) (aL :: asL) + +/-- Functional relation induced by an embedding `f : αH → αL`. -/ +abbrev FunRel {αH αL : Type} (f : αH → αL) : αH → αL → Prop := + fun aH aL => aL = f aH + +theorem optRel_funRel {αH αL : Type} (f : αH → αL) (oH : Option αH) (oL : Option αL) : + OptRel (FunRel f) oH oL ↔ oL = oH.map f := by + cases oH <;> cases oL <;> simp [OptRel, FunRel] + +theorem listRel_funRel {αH αL : Type} (f : αH → αL) (xsH : List αH) (xsL : List αL) : + ListRel (FunRel f) xsH xsL ↔ xsL = xsH.map f := by + induction xsH generalizing xsL with + | nil => + cases xsL with + | nil => simp [ListRel.nil] + | cons _ _ => constructor <;> (intro h; cases h) + | cons x xs ih => + cases xsL with + | nil => constructor <;> (intro h; cases h) + | cons y ys => + constructor + · intro h; cases h with | cons h1 h2 => simp [FunRel] at h1; rw [h1, (ih ys).mp h2]; rfl + · intro h; simp only [List.map_cons, List.cons.injEq] at h + exact ListRel.cons h.1 ((ih ys).mpr h.2) + +theorem listRel_eq {α : Type} (xs : List α) : ListRel Eq xs xs := by + induction xs with + | nil => exact .nil + | cons _ _ ih => exact .cons rfl ih + +theorem setRel_funRel {αH αL : Type} (f : αH → αL) (SH : Set αH) : + SetRel (FunRel f) SH (f '' SH) := by + constructor + · intro aH ha; exact ⟨f aH, ⟨aH, ha, rfl⟩, rfl⟩ + · rintro aL ⟨aH, ha, rfl⟩; exact ⟨aH, ha, rfl⟩ + +theorem setRel_eq {α : Type} (S : Set α) : SetRel Eq S S := by + constructor + · intro a ha; exact ⟨a, ha, rfl⟩ + · intro a ha; exact ⟨a, ha, rfl⟩ + +/-! ## Exact Bidirectional Monad Bisimulation `MRel`, `MRelE`, `LookupRel` -/ + +/-- Exact bidirectional bisimulation between Isabelle `HolNonDet` (Bool fail flag) +and Lean `Fl4Spec.NonDet` (Prop fail flag). -/ +def MRel {σH σL αH αL : Type} + (Rs : σH → σL → Prop) (Ra : αH → αL → Prop) + (mH : HolNonDet σH αH) (mL : NonDet σL αL) : Prop := + ∀ sH sL, Rs sH sL → + ((mH sH).2 = true ↔ (mL sL).2) ∧ + (∀ aH sH', (aH, sH') ∈ (mH sH).1 → ∃ aL sL', (aL, sL') ∈ (mL sL).1 ∧ Ra aH aL ∧ Rs sH' sL') ∧ + (∀ aL sL', (aL, sL') ∈ (mL sL).1 → ∃ aH sH', (aH, sH') ∈ (mH sH).1 ∧ Ra aH aL ∧ Rs sH' sL') + +/-- Exact bidirectional bisimulation for the exception monad. -/ +def MRelE {σH σL εH εL αH αL : Type} + (Rs : σH → σL → Prop) (Re : εH → εL → Prop) (Ra : αH → αL → Prop) + (mH : HolNonDet σH (Sum εH αH)) (mL : NonDetE σL εL αL) : Prop := + MRel Rs (SumExceptRel Re Ra) mH (ExceptT.run mL) + +/-- Exact relation for `Reader_Option_Monad` lookups. -/ +def LookupRel {σH σL αH αL : Type} (Rs : σH → σL → Prop) (Ra : αH → αL → Prop) + (fH : HolLookup σH αH) (fL : σL → Option αL) : Prop := + ∀ sH sL, Rs sH sL → OptRel Ra (fH sH) (fL sL) + +/-! ### Strengthening / Weakening -/ + +theorem mrel_mono {σH σL αH αL : Type} + {Rs Rs' : σH → σL → Prop} {Ra Ra' : αH → αL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (h : MRel Rs Ra mH mL) + (hpre : ∀ sH sL, Rs' sH sL → Rs sH sL) + (hpostS : ∀ sH sL, Rs sH sL → Rs' sH sL) + (hpostA : ∀ aH aL, Ra aH aL → Ra' aH aL) : + MRel Rs' Ra' mH mL := by + intro sH sL hs + obtain ⟨hf, h1, h2⟩ := h sH sL (hpre sH sL hs) + refine ⟨hf, ?_, ?_⟩ + · intro aH sH' hm + obtain ⟨aL, sL', hm', ha, hs'⟩ := h1 aH sH' hm + exact ⟨aL, sL', hm', hpostA aH aL ha, hpostS sH' sL' hs'⟩ + · intro aL sL' hm + obtain ⟨aH, sH', hm', ha, hs'⟩ := h2 aL sL' hm + exact ⟨aH, sH', hm', hpostA aH aL ha, hpostS sH' sL' hs'⟩ + +theorem mrel_conseq_res {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra Ra' : αH → αL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (h : MRel Rs Ra mH mL) (hpostA : ∀ aH aL, Ra aH aL → Ra' aH aL) : + MRel Rs Ra' mH mL := + mrel_mono h (fun _ _ h => h) (fun _ _ h => h) hpostA + +theorem mrel_weaken_pre {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (h : ∀ sH sL, Rs sH sL → + ((mH sH).2 = true ↔ (mL sL).2) ∧ + (∀ aH sH', (aH, sH') ∈ (mH sH).1 → ∃ aL sL', (aL, sL') ∈ (mL sL).1 ∧ Ra aH aL ∧ Rs sH' sL') ∧ + (∀ aL sL', (aL, sL') ∈ (mL sL).1 → ∃ aH sH', (aH, sH') ∈ (mH sH).1 ∧ Ra aH aL ∧ Rs sH' sL')) : + MRel Rs Ra mH mL := h + +/-! ### Nondet_Monad compositional rules -/ + +theorem mrel_return {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {aH : αH} {aL : αL} (ha : Ra aH aL) : + MRel Rs Ra (holReturn aH) (NonDet.pure aL) := by + intro sH sL hs + refine ⟨by simp [holReturn, NonDet.pure], ?_, ?_⟩ + · intro xH sH' hmem + simp [holReturn] at hmem + rcases hmem with ⟨rfl, rfl⟩ + exact ⟨aL, sL, by simp [NonDet.pure], ha, hs⟩ + · intro xL sL' hmem + simp [NonDet.pure] at hmem + rcases hmem with ⟨rfl, rfl⟩ + exact ⟨aH, sH, by simp [holReturn], ha, hs⟩ + +theorem mrel_pure {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {aH : αH} {aL : αL} (ha : Ra aH aL) : + MRel Rs Ra (holReturn aH) (pure aL) := + mrel_return ha + +theorem mrel_bind {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + {fH : αH → HolNonDet σH βH} {fL : αL → NonDet σL βL} + (hm : MRel Rs Ra mH mL) + (hf : ∀ aH aL, Ra aH aL → MRel Rs Rb (fH aH) (fL aL)) : + MRel Rs Rb (holBind mH fH) (NonDet.bind mL fL) := by + intro sH sL hs + obtain ⟨hmf, hm1, hm2⟩ := hm sH sL hs + refine ⟨?_, ?_, ?_⟩ + · simp only [holBind, NonDet.bind, decide_eq_true_eq] + constructor + · rintro (h | ⟨⟨aH, sH'⟩, hmem, hfail⟩) + · exact Or.inl (hmf.mp h) + · obtain ⟨aL, sL', hmemL, ha, hs'⟩ := hm1 aH sH' hmem + exact Or.inr ⟨(aL, sL'), hmemL, (hf aH aL ha sH' sL' hs').1.mp hfail⟩ + · rintro (h | ⟨⟨aL, sL'⟩, hmem, hfail⟩) + · exact Or.inl (hmf.mpr h) + · obtain ⟨aH, sH', hmemH, ha, hs'⟩ := hm2 aL sL' hmem + exact Or.inr ⟨(aH, sH'), hmemH, (hf aH aL ha sH' sL' hs').1.mpr hfail⟩ + · rintro bH sH'' ⟨⟨aH, sH'⟩, hmem1, hmem2⟩ + obtain ⟨aL, sL', hmem1L, ha, hs'⟩ := hm1 aH sH' hmem1 + obtain ⟨bL, sL'', hmem2L, hb, hs''⟩ := (hf aH aL ha sH' sL' hs').2.1 bH sH'' hmem2 + exact ⟨bL, sL'', ⟨(aL, sL'), hmem1L, hmem2L⟩, hb, hs''⟩ + · rintro bL sL'' ⟨⟨aL, sL'⟩, hmem1, hmem2⟩ + obtain ⟨aH, sH', hmem1H, ha, hs'⟩ := hm2 aL sL' hmem1 + obtain ⟨bH, sH'', hmem2H, hb, hs''⟩ := (hf aH aL ha sH' sL' hs').2.2 bL sL'' hmem2 + exact ⟨bH, sH'', ⟨(aH, sH'), hmem1H, hmem2H⟩, hb, hs''⟩ + +theorem mrel_kbind {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + {gH : HolNonDet σH βH} {gL : NonDet σL βL} + (hm : MRel Rs Ra mH mL) (hg : MRel Rs Rb gH gL) : + MRel Rs Rb (holBind mH (holKBind gH)) (NonDet.bind mL fun _ => gL) := + mrel_bind hm fun _ _ _ => hg + +theorem mrel_get {σH σL : Type} {Rs : σH → σL → Prop} : + MRel Rs Rs holGet NonDet.get := by + intro sH sL hs + refine ⟨by simp [holGet, NonDet.get], ?_, ?_⟩ + · intro xH sH' hmem + simp [holGet] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨sL, sL, by simp [NonDet.get], hs, hs⟩ + · intro xL sL' hmem + simp [NonDet.get] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨sH, sH, by simp [holGet], hs, hs⟩ + +theorem mrel_put {σH σL : Type} {Rs : σH → σL → Prop} {tH : σH} {tL : σL} (ht : Rs tH tL) : + MRel Rs Eq (holPut tH) (NonDet.put tL) := by + intro sH sL _ + refine ⟨by simp [holPut, NonDet.put], ?_, ?_⟩ + · intro xH sH' hmem + simp [holPut] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨(), tL, by simp [NonDet.put], rfl, ht⟩ + · intro xL sL' hmem + simp [NonDet.put] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨(), tH, by simp [holPut], rfl, ht⟩ + +theorem mrel_gets {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {fH : σH → αH} {fL : σL → αL} (hf : ∀ sH sL, Rs sH sL → Ra (fH sH) (fL sL)) : + MRel Rs Ra (holGets fH) (NonDet.gets fL) := by + intro sH sL hs + refine ⟨by simp [holGets, NonDet.gets], ?_, ?_⟩ + · intro aH sH' hmem + simp [holGets] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨fL sL, sL, by simp [NonDet.gets], hf _ _ hs, hs⟩ + · intro aL sL' hmem + simp [NonDet.gets] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨fH sH, sH, by simp [holGets], hf _ _ hs, hs⟩ + +theorem mrel_modify {σH σL : Type} {Rs : σH → σL → Prop} + {fH : σH → σH} {fL : σL → σL} (hf : ∀ sH sL, Rs sH sL → Rs (fH sH) (fL sL)) : + MRel Rs Eq (holModify fH) (NonDet.modify fL) := by + intro sH sL hs + refine ⟨by simp [holModify, NonDet.modify], ?_, ?_⟩ + · intro aH sH' hmem + simp [holModify] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨(), fL sL, by simp [NonDet.modify], rfl, hf sH sL hs⟩ + · intro aL sL' hmem + simp [NonDet.modify] at hmem; rcases hmem with ⟨rfl, rfl⟩ + exact ⟨(), fH sH, by simp [holModify], rfl, hf sH sL hs⟩ + +theorem mrel_fail {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} : + MRel Rs Ra (holFail : HolNonDet σH αH) (NonDet.fail : NonDet σL αL) := by + intro sH sL _ + simp [holFail, NonDet.fail] + +theorem mrel_assert {σH σL : Type} {Rs : σH → σL → Prop} {b : Bool} {P : Prop} (h : b = true ↔ P) : + MRel Rs Eq (holAssert b) (NonDet.assert P) := by + intro sH sL hs + refine ⟨by cases b <;> simp [holAssert, NonDet.assert] at h ⊢ <;> tauto, ?_, ?_⟩ + · rintro aH sH' ⟨hb, heq⟩ + injection heq with h1 h2; subst h1; subst h2 + exact ⟨(), sL, ⟨h.mp hb, rfl⟩, rfl, hs⟩ + · rintro aL sL' ⟨hp, heq⟩ + injection heq with h1 h2; subst h1; subst h2 + exact ⟨(), sH, ⟨h.mpr hp, rfl⟩, rfl, hs⟩ + +theorem mrel_stateAssert {σH σL : Type} {Rs : σH → σL → Prop} + {PH : σH → Bool} {PL : σL → Prop} (h : ∀ sH sL, Rs sH sL → (PH sH = true ↔ PL sL)) : + MRel Rs Eq (holStateAssert PH) (NonDet.stateAssert PL) := by + intro sH sL hs + exact mrel_assert (h sH sL hs) sH sL hs + +theorem mrel_assertOpt {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {oH : Option αH} {oL : Option αL} (ho : OptRel Ra oH oL) : + MRel Rs Ra (holAssertOpt oH) (NonDet.assertOpt oL) := by + cases oH <;> cases oL <;> simp [OptRel] at ho + · exact mrel_fail + · exact mrel_return ho + +theorem mrel_getsThe {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {fH : σH → Option αH} {fL : σL → Option αL} (hf : LookupRel Rs Ra fH fL) : + MRel Rs Ra (holGetsThe fH) (NonDet.getsThe fL) := by + intro sH sL hs + exact mrel_assertOpt (hf sH sL hs) sH sL hs + +theorem mrel_getsMap {σH σL γH γL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {fH : σH → γH → Option αH} {fL : σL → γL → Option αL} {pH : γH} {pL : γL} + (hf : ∀ sH sL, Rs sH sL → OptRel Ra (fH sH pH) (fL sL pL)) : + MRel Rs Ra (holGetsMap fH pH) (NonDet.getsMap fL pL) := by + unfold holGetsMap NonDet.getsMap + intro sH sL hs + have h1 := mrel_assertOpt (Rs := Rs) (hf sH sL hs) sH sL hs + simpa [holBind, NonDet.bind, holGets, NonDet.gets] using h1 + +theorem mrel_select {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {SH : Set αH} {SL : Set αL} (hS : SetRel Ra SH SL) : + MRel Rs Ra (holSelect SH) (NonDet.select SL) := by + intro sH sL hs + refine ⟨by simp [holSelect, NonDet.select], ?_, ?_⟩ + · rintro aH sH' ⟨ha, rfl⟩ + obtain ⟨aL, haL, hrel⟩ := hS.1 aH ha + exact ⟨aL, sL, ⟨haL, rfl⟩, hrel, hs⟩ + · rintro aL sL' ⟨ha, rfl⟩ + obtain ⟨aH, haH, hrel⟩ := hS.2 aL ha + exact ⟨aH, sH, ⟨haH, rfl⟩, hrel, hs⟩ + +theorem mrel_selectF {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {SH : Set αH × Bool} {SL : Set αL × Prop} + (hfail : SH.2 = true ↔ SL.2) (hset : SetRel Ra SH.1 SL.1) : + MRel Rs Ra (holSelectF SH) (NonDet.selectF SL) := by + intro sH sL hs + refine ⟨hfail, ?_, ?_⟩ + · rintro aH sH' ⟨ha, rfl⟩ + obtain ⟨aL, haL, hrel⟩ := hset.1 aH ha + exact ⟨aL, sL, ⟨haL, rfl⟩, hrel, hs⟩ + · rintro aL sL' ⟨ha, rfl⟩ + obtain ⟨aH, haH, hrel⟩ := hset.2 aL ha + exact ⟨aH, sH, ⟨haH, rfl⟩, hrel, hs⟩ + +theorem mrel_when {σH σL : Type} {Rs : σH → σL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {mH : HolNonDet σH Unit} {mL : NonDet σL Unit} + (hm : P → MRel Rs Eq mH mL) : + MRel Rs Eq (holWhen b mH) (NonDet.when P mL) := by + unfold holWhen NonDet.when + by_cases hp : P + · have hb : b = true := h.mpr hp + simp [hp, hb] + exact hm hp + · have hb : b ≠ true := fun h1 => hp (h.mp h1) + simp [hp, hb] + exact mrel_return rfl + +theorem mrel_unless {σH σL : Type} {Rs : σH → σL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {mH : HolNonDet σH Unit} {mL : NonDet σL Unit} + (hm : ¬P → MRel Rs Eq mH mL) : + MRel Rs Eq (holUnless b mH) (NonDet.unless P mL) := by + unfold holUnless NonDet.unless + by_cases hp : P + · have hb : b = true := h.mpr hp + simp [hp, hb] + exact mrel_return rfl + · have hb : b ≠ true := fun h1 => hp (h.mp h1) + simp [hp, hb] + exact hm hp + +theorem mrel_if {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {tH eH : HolNonDet σH αH} {tL eL : NonDet σL αL} + (ht : P → MRel Rs Ra tH tL) (he : ¬P → MRel Rs Ra eH eL) : + MRel Rs Ra (holIf b tH eH) (if P then tL else eL) := by + by_cases hp : P + · have hb : b = true := h.mpr hp + simp [hb, hp]; exact ht hp + · have hb : b = false := by cases b <;> simp_all + simp [hb, hp]; exact he hp + +theorem mrel_liftM {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : αH → βH} {fL : αL → βL} {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (hf : ∀ aH aL, Ra aH aL → Rb (fH aH) (fL aL)) (hm : MRel Rs Ra mH mL) : + MRel Rs Rb (holLiftM fH mH) (NonDet.liftM fL mL) := + mrel_bind hm fun aH aL ha => mrel_return (hf aH aL ha) + +theorem mrel_maybeM {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {fH : αH → HolNonDet σH Unit} {fL : αL → NonDet σL Unit} + {oH : Option αH} {oL : Option αL} + (hf : ∀ aH aL, Ra aH aL → MRel Rs Eq (fH aH) (fL aL)) (ho : OptRel Ra oH oL) : + MRel Rs Eq (holMaybeM fH oH) (NonDet.maybeM fL oL) := by + cases oH <;> cases oL <;> simp [OptRel] at ho + · exact mrel_return rfl + · exact hf _ _ ho + +theorem mrel_mapM {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : αH → HolNonDet σH βH} {fL : αL → NonDet σL βL} + (hf : ∀ aH aL, Ra aH aL → MRel Rs Rb (fH aH) (fL aL)) + {xsH : List αH} {xsL : List αL} (hxs : ListRel Ra xsH xsL) : + MRel Rs (ListRel Rb) (holMapM fH xsH) (NonDet.mapM fL xsL) := by + induction hxs with + | nil => exact mrel_return ListRel.nil + | @cons aH aL asH asL ha _ ih => + unfold holMapM NonDet.mapM + exact mrel_bind (hf aH aL ha) fun bH bL hb => + mrel_bind ih fun bsH bsL hbs => + mrel_return (ListRel.cons hb hbs) + +theorem mrel_mapMx {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : αH → HolNonDet σH βH} {fL : αL → NonDet σL βL} + (hf : ∀ aH aL, Ra aH aL → MRel Rs Rb (fH aH) (fL aL)) + {xsH : List αH} {xsL : List αL} (hxs : ListRel Ra xsH xsL) : + MRel Rs Eq (holMapMx fH xsH) (NonDet.mapMx fL xsL) := by + induction hxs with + | nil => exact mrel_return rfl + | @cons aH aL asH asL ha _ ih => + unfold holMapMx NonDet.mapMx + exact mrel_bind (hf aH aL ha) fun _ _ _ => ih + +theorem mrel_zipWithM {σH σL αH αL βH βL γH γL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} {Rc : γH → γL → Prop} + {fH : αH → βH → HolNonDet σH γH} {fL : αL → βL → NonDet σL γL} + (hf : ∀ aH aL, Ra aH aL → ∀ bH bL, Rb bH bL → MRel Rs Rc (fH aH bH) (fL aL bL)) + {xsH : List αH} {xsL : List αL} (hxs : ListRel Ra xsH xsL) + {ysH : List βH} {ysL : List βL} (hys : ListRel Rb ysH ysL) : + MRel Rs (ListRel Rc) (holZipWithM fH xsH ysH) (NonDet.zipWithM fL xsL ysL) := by + induction hxs generalizing ysH ysL with + | nil => cases hys <;> exact mrel_return ListRel.nil + | @cons aH aL asH asL ha _ ih => + cases hys with + | nil => exact mrel_return ListRel.nil + | @cons bH bL bsH bsL hb hbs => + unfold holZipWithM NonDet.zipWithM + exact mrel_bind (hf aH aL ha bH bL hb) fun cH cL hc => + mrel_bind (ih hbs) fun csH csL hcs => + mrel_return (ListRel.cons hc hcs) + +theorem mrel_zipWithMx {σH σL αH αL βH βL γH γL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} {Rc : γH → γL → Prop} + {fH : αH → βH → HolNonDet σH γH} {fL : αL → βL → NonDet σL γL} + (hf : ∀ aH aL, Ra aH aL → ∀ bH bL, Rb bH bL → MRel Rs Rc (fH aH bH) (fL aL bL)) + {xsH : List αH} {xsL : List αL} (hxs : ListRel Ra xsH xsL) + {ysH : List βH} {ysL : List βL} (hys : ListRel Rb ysH ysL) : + MRel Rs Eq (holZipWithMx fH xsH ysH) (NonDet.zipWithMx fL xsL ysL) := by + induction hxs generalizing ysH ysL with + | nil => cases hys <;> exact mrel_return rfl + | @cons aH aL asH asL ha _ ih => + cases hys with + | nil => exact mrel_return rfl + | @cons bH bL bsH bsL hb hbs => + unfold holZipWithMx NonDet.zipWithMx + exact mrel_bind (hf aH aL ha bH bL hb) fun _ _ _ => ih hbs + +theorem mrel_whileLoop {σH σL αH αL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {CH : αH → σH → Bool} {CL : αL → σL → Prop} + {BH : αH → HolNonDet σH αH} {BL : αL → NonDet σL αL} + (hC : ∀ rH rL, Ra rH rL → ∀ sH sL, Rs sH sL → (CH rH sH = true ↔ CL rL sL)) + (hB : ∀ rH rL, Ra rH rL → MRel Rs Ra (BH rH) (BL rL)) + {rH : αH} {rL : αL} (hr : Ra rH rL) : + MRel Rs Ra (holWhileLoop CH BH rH) (NonDet.whileLoop CL BL rL) := by + have hRes1 : ∀ {rH sH x}, HolWhileResults CH BH rH sH x → + ∀ rL sL, Ra rH rL → Rs sH sL → + ∃ rL' sL', NonDet.WhileResults CL BL rL sL (rL', sL') ∧ Ra x.1 rL' ∧ Rs x.2 sL' := by + intro rH sH x h + induction h with + | @done rH sH hcf => + intro rL sL hr hs + have hnc : ¬CL rL sL := fun hc => by have := (hC rH rL hr sH sL hs).mpr hc; simp [hcf] at this + exact ⟨rL, sL, .done hnc, hr, hs⟩ + | @step rH sH rH' sH' x hct hmem _ ih => + intro rL sL hr hs + have hcL : CL rL sL := (hC rH rL hr sH sL hs).mp hct + obtain ⟨rL', sL', hmemL, hr', hs'⟩ := (hB rH rL hr sH sL hs).2.1 rH' sH' hmem + obtain ⟨rL'', sL'', hres, ha'', hs''⟩ := ih rL' sL' hr' hs' + exact ⟨rL'', sL'', .step hcL hmemL hres, ha'', hs''⟩ + have hRes2 : ∀ {rL sL x}, NonDet.WhileResults CL BL rL sL x → + ∀ rH sH, Ra rH rL → Rs sH sL → + ∃ rH' sH', HolWhileResults CH BH rH sH (rH', sH') ∧ Ra rH' x.1 ∧ Rs sH' x.2 := by + intro rL sL x h + induction h with + | @done rL sL hnc => + intro rH sH hr hs + have hcf : CH rH sH = false := by + cases hc : CH rH sH + · rfl + · exfalso; exact hnc ((hC rH rL hr sH sL hs).mp hc) + exact ⟨rH, sH, .done hcf, hr, hs⟩ + | @step rL sL rL' sL' x hcL hmem _ ih => + intro rH sH hr hs + have hct : CH rH sH = true := (hC rH rL hr sH sL hs).mpr hcL + obtain ⟨rH', sH', hmemH, hr', hs'⟩ := (hB rH rL hr sH sL hs).2.2 rL' sL' hmem + obtain ⟨rH'', sH'', hres, ha'', hs''⟩ := ih rH' sH' hr' hs' + exact ⟨rH'', sH'', .step hct hmemH hres, ha'', hs''⟩ + have hReach1 : ∀ {r0H s0H rH sH}, HolWhileReach CH BH r0H s0H rH sH → + ∀ r0L s0L, Ra r0H r0L → Rs s0H s0L → + ∃ rL sL, NonDet.WhileReach CL BL r0L s0L rL sL ∧ Ra rH rL ∧ Rs sH sL := by + intro r0H s0H rH sH h + induction h with + | start => + intro r0L s0L hr0 hs0 + exact ⟨r0L, s0L, .start, hr0, hs0⟩ + | @step rH sH rH' sH' _ hct hmem ih => + intro r0L s0L hr0 hs0 + obtain ⟨rL, sL, hreach, hr, hs⟩ := ih r0L s0L hr0 hs0 + have hcL : CL rL sL := (hC rH rL hr sH sL hs).mp hct + obtain ⟨rL', sL', hmemL, hr', hs'⟩ := (hB rH rL hr sH sL hs).2.1 rH' sH' hmem + exact ⟨rL', sL', .step hreach hcL hmemL, hr', hs'⟩ + have hReach2 : ∀ {r0L s0L rL sL}, NonDet.WhileReach CL BL r0L s0L rL sL → + ∀ r0H s0H, Ra r0H r0L → Rs s0H s0L → + ∃ rH sH, HolWhileReach CH BH r0H s0H rH sH ∧ Ra rH rL ∧ Rs sH sL := by + intro r0L s0L rL sL h + induction h with + | start => + intro r0H s0H hr0 hs0 + exact ⟨r0H, s0H, .start, hr0, hs0⟩ + | @step rL sL rL' sL' _ hcL hmem ih => + intro r0H s0H hr0 hs0 + obtain ⟨rH, sH, hreach, hr, hs⟩ := ih r0H s0H hr0 hs0 + have hct : CH rH sH = true := (hC rH rL hr sH sL hs).mpr hcL + obtain ⟨rH', sH', hmemH, hr', hs'⟩ := (hB rH rL hr sH sL hs).2.2 rL' sL' hmem + exact ⟨rH', sH', .step hreach hct hmemH, hr', hs'⟩ + intro sH sL hs + refine ⟨?_, ?_, ?_⟩ + · simp only [holWhileLoop, NonDet.whileLoop, decide_eq_true_eq] + constructor + · rintro (⟨rH', sH', hreach, hct, hfail⟩ | ⟨fH, hf0, hfstep⟩) + · obtain ⟨rL', sL', hreachL, hr', hs'⟩ := hReach1 hreach rL sL hr hs + exact Or.inl ⟨rL', sL', hreachL, (hC rH' rL' hr' sH' sL' hs').mp hct, + (hB rH' rL' hr' sH' sL' hs').1.mp hfail⟩ + · -- Build matching infinite sequence fL by dependent recursion on Nat + let stepL : ∀ n, {p : αL × σL // Ra (fH n).1 p.1 ∧ Rs (fH n).2 p.2} := + Nat.rec + ⟨(rL, sL), by rw [hf0]; exact ⟨hr, hs⟩⟩ + (fun n ih => + let h1 := hfstep n + let ex := (hB (fH n).1 ih.1.1 ih.2.1 (fH n).2 ih.1.2 ih.2.2).2.1 + (fH (n + 1)).1 (fH (n + 1)).2 h1.2 + ⟨(Classical.choose ex, Classical.choose (Classical.choose_spec ex)), + (Classical.choose_spec (Classical.choose_spec ex)).2⟩) + refine Or.inr ⟨fun n => (stepL n).1, rfl, fun n => ?_⟩ + have h1 := hfstep n + refine ⟨(hC (fH n).1 (stepL n).1.1 (stepL n).2.1 (fH n).2 (stepL n).1.2 (stepL n).2.2).mp h1.1, ?_⟩ + exact (Classical.choose_spec (Classical.choose_spec + ((hB (fH n).1 (stepL n).1.1 (stepL n).2.1 (fH n).2 (stepL n).1.2 (stepL n).2.2).2.1 + (fH (n + 1)).1 (fH (n + 1)).2 h1.2))).1 + · rintro (⟨rL', sL', hreach, hcL, hfail⟩ | ⟨fL, hf0, hfstep⟩) + · obtain ⟨rH', sH', hreachH, hr', hs'⟩ := hReach2 hreach rH sH hr hs + exact Or.inl ⟨rH', sH', hreachH, (hC rH' rL' hr' sH' sL' hs').mpr hcL, + (hB rH' rL' hr' sH' sL' hs').1.mpr hfail⟩ + · let stepH : ∀ n, {p : αH × σH // Ra p.1 (fL n).1 ∧ Rs p.2 (fL n).2} := + Nat.rec + ⟨(rH, sH), by rw [hf0]; exact ⟨hr, hs⟩⟩ + (fun n ih => + let h1 := hfstep n + let ex := (hB ih.1.1 (fL n).1 ih.2.1 ih.1.2 (fL n).2 ih.2.2).2.2 + (fL (n + 1)).1 (fL (n + 1)).2 h1.2 + ⟨(Classical.choose ex, Classical.choose (Classical.choose_spec ex)), + (Classical.choose_spec (Classical.choose_spec ex)).2⟩) + refine Or.inr ⟨fun n => (stepH n).1, rfl, fun n => ?_⟩ + have h1 := hfstep n + refine ⟨(hC (stepH n).1.1 (fL n).1 (stepH n).2.1 (stepH n).1.2 (fL n).2 (stepH n).2.2).mpr h1.1, ?_⟩ + exact (Classical.choose_spec (Classical.choose_spec + ((hB (stepH n).1.1 (fL n).1 (stepH n).2.1 (stepH n).1.2 (fL n).2 (stepH n).2.2).2.2 + (fL (n + 1)).1 (fL (n + 1)).2 h1.2))).1 + · intro aH sH' hmem + exact hRes1 hmem rL sL hr hs + · intro aL sL' hmem + exact hRes2 hmem rH sH hr hs + +/-! ### Exception monad (`MRelE`) compositional rules -/ + +theorem mrele_returnOk {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {aH : αH} {aL : αL} (ha : Ra aH aL) : + MRelE Rs Re Ra (holReturnOk aH) (NonDetE.returnOk aL) := + mrel_return (Ra := SumExceptRel Re Ra) ha + +theorem mrele_pure {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {aH : αH} {aL : αL} (ha : Ra aH aL) : + MRelE Rs Re Ra (holReturnOk aH) (pure aL) := + mrel_return (Ra := SumExceptRel Re Ra) ha + +theorem mrele_throwError {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {eH : εH} {eL : εL} (he : Re eH eL) : + MRelE Rs Re Ra (holThrowError eH) (NonDetE.throwError eL) := + mrel_return (Ra := SumExceptRel Re Ra) he + +theorem mrele_throw {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {eH : εH} {eL : εL} (he : Re eH eL) : + MRelE Rs Re Ra (holThrowError eH) (throw eL) := + mrel_return (Ra := SumExceptRel Re Ra) he + +theorem mrele_liftE {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + (hm : MRel Rs Ra mH mL) : + MRelE Rs Re Ra (holLiftE mH) (NonDetE.liftE mL) := by + unfold MRelE holLiftE holLiftM NonDetE.liftE ExceptT.lift ExceptT.mk + exact mrel_bind hm fun aH aL ha => mrel_return (Ra := SumExceptRel Re Ra) ha + +theorem mrele_bindE {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {fH : αH → HolNonDet σH (Sum εH βH)} {fL : αL → NonDetE σL εL βL} + (hm : MRelE Rs Re Ra mH mL) + (hf : ∀ aH aL, Ra aH aL → MRelE Rs Re Rb (fH aH) (fL aL)) : + MRelE Rs Re Rb (holBindE mH fH) (mL >>= fL) := by + unfold MRelE holBindE + have hrun : ExceptT.run (mL >>= fL) = NonDet.bind (ExceptT.run mL) (ExceptT.bindCont fL) := rfl + rw [hrun] + exact mrel_bind hm fun xH xL hx => by + cases xH <;> cases xL <;> simp [SumExceptRel] at hx + · exact mrel_return (Ra := SumExceptRel Re Rb) hx + · exact hf _ _ hx + +theorem mrele_kbindE {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {gH : HolNonDet σH (Sum εH βH)} {gL : NonDetE σL εL βL} + (hm : MRelE Rs Re Ra mH mL) (hg : MRelE Rs Re Rb gH gL) : + MRelE Rs Re Rb (holBindE mH (holKBind gH)) (mL >>= fun _ => gL) := + mrele_bindE hm fun _ _ _ => hg + +theorem mrele_whenE {σH σL εH εL : Type} {Rs : σH → σL → Prop} {Re : εH → εL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {mH : HolNonDet σH (Sum εH Unit)} {mL : NonDetE σL εL Unit} + (hm : P → MRelE Rs Re Eq mH mL) : + MRelE Rs Re Eq (holWhenE b mH) (NonDetE.whenE P mL) := by + unfold holWhenE NonDetE.whenE + by_cases hp : P + · have hb : b = true := h.mpr hp + simp [hp, hb]; exact hm hp + · have hb : b ≠ true := fun h1 => hp (h.mp h1) + simp [hp, hb]; exact mrele_returnOk rfl + +theorem mrele_unlessE {σH σL εH εL : Type} {Rs : σH → σL → Prop} {Re : εH → εL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {mH : HolNonDet σH (Sum εH Unit)} {mL : NonDetE σL εL Unit} + (hm : ¬P → MRelE Rs Re Eq mH mL) : + MRelE Rs Re Eq (holUnlessE b mH) (NonDetE.unlessE P mL) := by + unfold holUnlessE NonDetE.unlessE + by_cases hp : P + · have hb : b = true := h.mpr hp + simp [hp, hb]; exact mrele_returnOk rfl + · have hb : b ≠ true := fun h1 => hp (h.mp h1) + simp [hp, hb]; exact hm hp + +theorem mrele_assertE {σH σL εH εL : Type} {Rs : σH → σL → Prop} {Re : εH → εL → Prop} + {b : Bool} {P : Prop} (h : b = true ↔ P) : + MRelE Rs Re Eq (holAssertE b) (NonDetE.assertE P) := + mrele_liftE (mrel_assert h) + +theorem mrele_throwOpt {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {eH : εH} {eL : εL} (he : Re eH eL) + {oH : Option αH} {oL : Option αL} (ho : OptRel Ra oH oL) : + MRelE Rs Re Ra (holThrowOpt eH oH) (NonDetE.throwOpt eL oL) := by + cases oH <;> cases oL <;> simp [OptRel] at ho + · exact mrele_throwError he + · exact mrele_returnOk ho + +theorem mrele_catch {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {hH : εH → HolNonDet σH αH} {hL : εL → NonDet σL αL} + (hm : MRelE Rs Re Ra mH mL) + (hh : ∀ eH eL, Re eH eL → MRel Rs Ra (hH eH) (hL eL)) : + MRel Rs Ra (holCatch mH hH) (NonDetE.catch mL hL) := by + unfold holCatch NonDetE.catch + exact mrel_bind hm fun xH xL hx => by + cases xH <;> cases xL <;> simp [SumExceptRel] at hx + · exact hh _ _ hx + · exact mrel_return hx + +theorem mrele_handleE' {σH σL εH εL εH' εL' αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Re' : εH' → εL' → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {hH : εH → HolNonDet σH (Sum εH' αH)} {hL : εL → NonDetE σL εL' αL} + (hm : MRelE Rs Re Ra mH mL) + (hh : ∀ eH eL, Re eH eL → MRelE Rs Re' Ra (hH eH) (hL eL)) : + MRelE Rs Re' Ra (holHandleE' mH hH) (NonDetE.handleE mL hL) := by + unfold MRelE holHandleE' NonDetE.handleE ExceptT.mk + exact mrel_bind hm fun xH xL hx => by + cases xH <;> cases xL <;> simp [SumExceptRel] at hx + · exact hh _ _ hx + · exact mrel_return (Ra := SumExceptRel Re' Ra) hx + +theorem mrele_handleE {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {hH : εH → HolNonDet σH (Sum εH αH)} {hL : εL → NonDetE σL εL αL} + (hm : MRelE Rs Re Ra mH mL) + (hh : ∀ eH eL, Re eH eL → MRelE Rs Re Ra (hH eH) (hL eL)) : + MRelE Rs Re Ra (holHandleE mH hH) (NonDetE.handleE mL hL) := + mrele_handleE' hm hh + +theorem mrele_liftME {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : αH → βH} {fL : αL → βL} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + (hf : ∀ aH aL, Ra aH aL → Rb (fH aH) (fL aL)) (hm : MRelE Rs Re Ra mH mL) : + MRelE Rs Re Rb (holLiftME fH mH) (NonDetE.liftME fL mL) := + mrele_bindE hm fun aH aL ha => mrele_returnOk (hf aH aL ha) + +theorem mrele_mapME {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : αH → HolNonDet σH (Sum εH βH)} {fL : αL → NonDetE σL εL βL} + (hf : ∀ aH aL, Ra aH aL → MRelE Rs Re Rb (fH aH) (fL aL)) + {xsH : List αH} {xsL : List αL} (hxs : ListRel Ra xsH xsL) : + MRelE Rs Re (ListRel Rb) (holMapME fH xsH) (NonDetE.mapME fL xsL) := by + induction hxs with + | nil => exact mrele_returnOk ListRel.nil + | @cons aH aL asH asL ha _ ih => + unfold holMapME NonDetE.mapME + exact mrele_bindE (hf aH aL ha) fun bH bL hb => + mrele_bindE ih fun bsH bsL hbs => + mrele_returnOk (ListRel.cons hb hbs) + +theorem mrele_mapMEx {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : αH → HolNonDet σH (Sum εH βH)} {fL : αL → NonDetE σL εL βL} + (hf : ∀ aH aL, Ra aH aL → MRelE Rs Re Rb (fH aH) (fL aL)) + {xsH : List αH} {xsL : List αL} (hxs : ListRel Ra xsH xsL) : + MRelE Rs Re Eq (holMapMEx fH xsH) (NonDetE.mapMEx fL xsL) := by + induction hxs with + | nil => exact mrele_returnOk rfl + | @cons aH aL asH asL ha _ ih => + unfold holMapMEx NonDetE.mapMEx + exact mrele_bindE (hf aH aL ha) fun _ _ _ => ih + +theorem mrele_if {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) + {tH eH : HolNonDet σH (Sum εH αH)} {tL eL : NonDetE σL εL αL} + (ht : P → MRelE Rs Re Ra tH tL) (he : ¬P → MRelE Rs Re Ra eH eL) : + MRelE Rs Re Ra (holIf b tH eH) (if P then tL else eL) := by + by_cases hp : P + · have hb : b = true := h.mpr hp + simp [hb, hp]; exact ht hp + · have hb : b = false := by cases b <;> simp_all + simp [hb, hp]; exact he hp + +/-! ### `Reader_Option_Monad` (`LookupRel`) compositional rules -/ + +theorem lookup_oreturn {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} + {aH : αH} {aL : αL} (ha : Ra aH aL) : + LookupRel Rs Ra (holOReturn aH) (fun _ => some aL) := + fun _ _ _ => ha + +theorem lookup_ofail {σH σL αH αL : Type} {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} : + LookupRel Rs Ra (holOFail : HolLookup σH αH) (fun _ => (none : Option αL)) := + fun _ _ _ => trivial + +theorem lookup_obind {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : HolLookup σH αH} {fL : σL → Option αL} + {gH : αH → HolLookup σH βH} {gL : αL → σL → Option βL} + (hf : LookupRel Rs Ra fH fL) + (hg : ∀ aH aL, Ra aH aL → LookupRel Rs Rb (gH aH) (gL aL)) : + LookupRel Rs Rb (holOBind fH gH) (fun s => match fL s with | none => none | some a => gL a s) := by + intro sH sL hs + have h := hf sH sL hs + unfold holOBind + cases h1 : fH sH <;> cases h2 : fL sL <;> simp [h1, h2, OptRel] at h ⊢ + exact hg _ _ h sH sL hs + +theorem lookup_oassert {σH σL : Type} {Rs : σH → σL → Prop} + {b : Bool} {P : Prop} [Decidable P] (h : b = true ↔ P) : + LookupRel Rs Eq (holOAssert b) (fun _ => if P then some () else none) := by + intro _ _ _ + unfold holOAssert holOReturn holOFail + by_cases hp : P + · have hb : b = true := h.mpr hp; simp [hp, hb, OptRel] + · have hb : b ≠ true := fun h1 => hp (h.mp h1); simp [hp, hb, OptRel] + +theorem lookup_optMap {σH σL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {fH : σH → Option αH} {fL : σL → Option αL} + {gH : αH → Option βH} {gL : αL → Option βL} + (hf : LookupRel Rs Ra fH fL) + (hg : ∀ aH aL, Ra aH aL → OptRel Rb (gH aH) (gL aL)) : + LookupRel Rs Rb (holOptMap fH gH) (fun s => (fL s).bind gL) := by + intro sH sL hs + have h := hf sH sL hs + unfold holOptMap + cases h1 : fH sH <;> cases h2 : fL sL <;> simp [h1, h2, OptRel] at h ⊢ + exact hg _ _ h + +/-! ## Pointwise correspondence with run-guarded continuations -/ + +/-- Pointwise monad relation step (used by `mrel_bind_post` to thread state postconditions). -/ +def MRelStep {σH σL αH αL : Type} (Rs : σH → σL → Prop) (Ra : αH → αL → Prop) + (rH : Set (αH × σH) × Bool) (rL : Set (αL × σL) × Prop) : Prop := + (rH.2 = true ↔ rL.2) ∧ + (∀ aH sH', (aH, sH') ∈ rH.1 → ∃ aL sL', (aL, sL') ∈ rL.1 ∧ Ra aH aL ∧ Rs sH' sL') ∧ + (∀ aL sL', (aL, sL') ∈ rL.1 → ∃ aH sH', (aH, sH') ∈ rH.1 ∧ Ra aH aL ∧ Rs sH' sL') + +theorem mrelStep_bind_mem_both {σH σL αH αL βH βL : Type} + {Rs Rs' : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + {fH : αH → HolNonDet σH βH} {fL : αL → NonDet σL βL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs' Ra (mH sH) (mL sL)) + (hf : ∀ aH aL, Ra aH aL → ∀ sH' sL', Rs' sH' sL' → (aH, sH') ∈ (mH sH).1 → + (aL, sL') ∈ (mL sL).1 → + MRelStep Rs Rb (fH aH sH') (fL aL sL')) : + MRelStep Rs Rb (holBind mH fH sH) (NonDet.bind mL fL sL) := by + obtain ⟨hfm, hm1, hm2⟩ := hm + refine ⟨?_, ?_, ?_⟩ + · simp only [holBind, NonDet.bind, decide_eq_true_eq] + constructor + · rintro (h | ⟨⟨aH, sH'⟩, hmem, hfail⟩) + · exact Or.inl (hfm.mp h) + · obtain ⟨aL, sL', hmemL, ha, hs'⟩ := hm1 aH sH' hmem + exact Or.inr ⟨(aL, sL'), hmemL, (hf aH aL ha sH' sL' hs' hmem hmemL).1.mp hfail⟩ + · rintro (h | ⟨⟨aL, sL'⟩, hmem, hfail⟩) + · exact Or.inl (hfm.mpr h) + · obtain ⟨aH, sH', hmemH, ha, hs'⟩ := hm2 aL sL' hmem + exact Or.inr ⟨(aH, sH'), hmemH, (hf aH aL ha sH' sL' hs' hmemH hmem).1.mpr hfail⟩ + · intro bH sH'' hmem + simp only [holBind, Set.mem_ofPred_eq] at hmem + rcases hmem with ⟨⟨aH, sH'⟩, hmem1, hmem2⟩ + obtain ⟨aL, sL', hmem1L, ha, hs'⟩ := hm1 aH sH' hmem1 + obtain ⟨bL, sL'', hmem2L, hb, hs''⟩ := (hf aH aL ha sH' sL' hs' hmem1 hmem1L).2.1 bH sH'' hmem2 + exact ⟨bL, sL'', by simp only [NonDet.bind]; exact ⟨(aL, sL'), hmem1L, hmem2L⟩, hb, hs''⟩ + · intro bL sL'' hmem + simp only [NonDet.bind] at hmem + rcases hmem with ⟨⟨aL, sL'⟩, hmem1, hmem2⟩ + obtain ⟨aH, sH', hmem1H, ha, hs'⟩ := hm2 aL sL' hmem1 + obtain ⟨bH, sH'', hmem2H, hb, hs''⟩ := (hf aH aL ha sH' sL' hs' hmem1H hmem1).2.2 bL sL'' hmem2 + exact ⟨bH, sH'', by simp only [holBind]; exact ⟨(aH, sH'), hmem1H, hmem2H⟩, hb, hs''⟩ + + +theorem mrelStep_bind_mem {σH σL αH αL βH βL : Type} + {Rs Rs' : σH → σL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + {fH : αH → HolNonDet σH βH} {fL : αL → NonDet σL βL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs' Ra (mH sH) (mL sL)) + (hf : ∀ aH aL, Ra aH aL → ∀ sH' sL', Rs' sH' sL' → (aH, sH') ∈ (mH sH).1 → + MRelStep Rs Rb (fH aH sH') (fL aL sL')) : + MRelStep Rs Rb (holBind mH fH sH) (NonDet.bind mL fL sL) := + mrelStep_bind_mem_both hm fun aH aL ha tH tL ht hmem _ => hf aH aL ha tH tL ht hmem + + +theorem nonDet_bind_gets_at {σ α β : Type} (read : σ → α) (next : α → NonDet σ β) + (state : σ) : NonDet.bind (NonDet.gets read) next state = next (read state) state := by + apply Prod.ext + · ext result + simp [NonDet.bind, NonDet.gets] + · simp [NonDet.bind, NonDet.gets] + + +theorem nonDet_bind_singleton_at {σ α β : Type} {first : NonDet σ α} + (next : α → NonDet σ β) {s s' : σ} {value : α} + (run : first s = ({(value, s')}, False)) : + NonDet.bind first next s = next value s' := by + apply Prod.ext + · ext result + simp [NonDet.bind, run] + · simp [NonDet.bind, run] + +theorem hol_bind_singleton_at {σ α β : Type} {first : HolNonDet σ α} + (next : α → HolNonDet σ β) {s s' : σ} {value : α} + (run : first s = ({(value, s')}, false)) : + holBind first next s = next value s' := by + apply Prod.ext + · ext result + simp [holBind, run] + · simp [holBind, run] + +end +theorem holBindE_assoc {σ ε α β γ : Type} + (m : HolNonDet σ (Sum ε α)) (f : α → HolNonDet σ (Sum ε β)) (g : β → HolNonDet σ (Sum ε γ)) : + holBindE (holBindE m f) g = holBindE m (fun a => holBindE (f a) g) := by + funext s + apply Prod.ext + · ext ⟨r, s'⟩ + simp only [holBindE, holBind, holThrowError, Set.mem_ofPred_eq] + constructor + · rintro ⟨⟨x, s1⟩, ⟨⟨y, s2⟩, hm, hf⟩, hg⟩ + refine ⟨⟨y, s2⟩, hm, ?_⟩ + cases y with + | inl e => + simp only [] at hf + rcases hf with ⟨rfl, rfl⟩ + simp only [] at hg + rcases hg with ⟨rfl, rfl⟩ + rfl + | inr a => exact ⟨⟨x, s1⟩, hf, hg⟩ + · rintro ⟨⟨y, s2⟩, hm, hfg⟩ + cases y with + | inl e => + simp only [] at hfg + rcases hfg with ⟨rfl, rfl⟩ + exact ⟨⟨Sum.inl e, s'⟩, ⟨⟨Sum.inl e, s'⟩, hm, rfl⟩, rfl⟩ + | inr a => + rcases hfg with ⟨⟨x, s1⟩, hf, hg⟩ + exact ⟨⟨x, s1⟩, ⟨⟨Sum.inr a, s2⟩, hm, hf⟩, hg⟩ + · apply Bool.eq_iff_iff.mpr + have hfail : ∀ {α' β' : Type} (m' : HolNonDet σ (Sum ε α')) (f' : α' → HolNonDet σ (Sum ε β')) (s0 : σ), + (holBindE m' f' s0).2 = true ↔ + (m' s0).2 = true ∨ ∃ x ∈ (m' s0).1, + match x.1 with + | Sum.inl _ => False + | Sum.inr a => (f' a x.2).2 = true := by + intro α' β' m' f' s0 + unfold holBindE holBind + rw [decide_eq_true_eq] + apply or_congr_right + apply exists_congr; intro x + apply and_congr_right; intro _ + cases x.1 with + | inl e => simp [holThrowError, holReturn] + | inr a => rfl + rw [hfail, hfail, hfail] + constructor + · rintro ((hm | ⟨⟨y, s2⟩, hm, hf⟩) | ⟨⟨x, s1⟩, hmem, hgx⟩) + · exact Or.inl hm + · refine Or.inr ⟨⟨y, s2⟩, hm, ?_⟩ + cases y with + | inl e => exact False.elim hf + | inr a => dsimp only; rw [hfail]; exact Or.inl hf + · simp only [holBindE, holBind, holThrowError, Set.mem_ofPred_eq] at hmem + rcases hmem with ⟨⟨y, s2⟩, hm, hf⟩ + refine Or.inr ⟨⟨y, s2⟩, hm, ?_⟩ + cases y with + | inl e => + simp only [] at hf + rcases hf with ⟨rfl, rfl⟩ + exact False.elim hgx + | inr a => + dsimp only; rw [hfail] + exact Or.inr ⟨⟨x, s1⟩, hf, hgx⟩ + · rintro (hm | ⟨⟨y, s2⟩, hm, hfg⟩) + · exact Or.inl (Or.inl hm) + · cases y with + | inl e => exact False.elim hfg + | inr a => + dsimp only at hfg + rw [hfail] at hfg + rcases hfg with hf | ⟨⟨x, s1⟩, hf, hg⟩ + · exact Or.inl (Or.inr ⟨⟨Sum.inr a, s2⟩, hm, hf⟩) + · refine Or.inr ⟨⟨x, s1⟩, ?_, hg⟩ + simp only [holBindE, holBind, Set.mem_ofPred_eq] + exact ⟨⟨Sum.inr a, s2⟩, hm, hf⟩ + +theorem mrelStep_bindE_mem_both {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {fH : αH → HolNonDet σH (Sum εH βH)} {fL : αL → NonDetE σL εL βL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs (SumExceptRel Re Ra) (mH sH) (ExceptT.run mL sL)) + (hf : ∀ aH aL, Ra aH aL → ∀ s1H s1L, Rs s1H s1L → (Sum.inr aH, s1H) ∈ (mH sH).1 → + (Except.ok aL, s1L) ∈ (mL.run sL).1 → + MRelStep Rs (SumExceptRel Re Rb) (fH aH s1H) (ExceptT.run (fL aL) s1L)) : + MRelStep Rs (SumExceptRel Re Rb) + (holBindE mH fH sH) (ExceptT.run (mL >>= fL) sL) := by + change MRelStep Rs (SumExceptRel Re Rb) + (holBind mH (fun | .inl e => holThrowError e | .inr a => fH a) sH) + (NonDet.bind (ExceptT.run mL) (ExceptT.bindCont (fun a => ExceptT.run (fL a))) sL) + refine mrelStep_bind_mem_both hm fun xH xL hx s1H s1L hs1 hmemH hmemL => ?_ + cases xH <;> cases xL <;> simp only [SumExceptRel] at hx + · exact mrel_return (Ra := SumExceptRel Re Rb) (show SumExceptRel Re Rb (Sum.inl _) (Except.error _) from hx) s1H s1L hs1 + · exact hf _ _ hx s1H s1L hs1 hmemH hmemL + +theorem mrelStep_bindE_mem {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {fH : αH → HolNonDet σH (Sum εH βH)} {fL : αL → NonDetE σL εL βL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs (SumExceptRel Re Ra) (mH sH) (ExceptT.run mL sL)) + (hf : ∀ aH aL, Ra aH aL → ∀ s1H s1L, Rs s1H s1L → (Sum.inr aH, s1H) ∈ (mH sH).1 → + MRelStep Rs (SumExceptRel Re Rb) (fH aH s1H) (ExceptT.run (fL aL) s1L)) : + MRelStep Rs (SumExceptRel Re Rb) + (holBindE mH fH sH) (ExceptT.run (mL >>= fL) sL) := + mrelStep_bindE_mem_both hm fun aH aL ha tH tL ht hmem _ => hf aH aL ha tH tL ht hmem + + +theorem mrelStep_kbindE_mem {σH σL εH εL αH αL βH βL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} {Rb : βH → βL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {gH : HolNonDet σH (Sum εH βH)} {gL : NonDetE σL εL βL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs (SumExceptRel Re Ra) (mH sH) (ExceptT.run mL sL)) + (hg : ∀ aH s1H s1L, Rs s1H s1L → (Sum.inr aH, s1H) ∈ (mH sH).1 → + MRelStep Rs (SumExceptRel Re Rb) (gH s1H) (ExceptT.run gL s1L)) : + MRelStep Rs (SumExceptRel Re Rb) + (holBindE mH (holKBind gH) sH) (ExceptT.run (mL >>= fun _ => gL) sL) := + mrelStep_bindE_mem hm fun aH _ _ s1H s1L hs1 hmem => hg aH s1H s1L hs1 hmem + +theorem mrelStep_liftE {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet σH αH} {mL : NonDet σL αL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs Ra (mH sH) (mL sL)) : + MRelStep Rs (SumExceptRel Re Ra) + (holLiftE mH sH) (ExceptT.run (NonDetE.liftE mL) sL) := by + change MRelStep Rs (SumExceptRel Re Ra) + (holBind mH (fun a => holReturn (Sum.inr a)) sH) + (NonDet.bind mL (fun a => NonDet.pure (Except.ok a)) sL) + exact mrelStep_bind_mem hm fun aH aL ha s1H s1L hs1 _ => + mrel_return (Ra := SumExceptRel Re Ra) (show SumExceptRel Re Ra (Sum.inr aH) (Except.ok aL) from ha) s1H s1L hs1 + +theorem mrelStep_handleE_mem {σH σL εH εL εH' εL' αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Re' : εH' → εL' → Prop} + {Ra : αH → αL → Prop} {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {fH : εH → HolNonDet σH (Sum εH' αH)} {fL : εL → NonDetE σL εL' αL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs (SumExceptRel Re Ra) (mH sH) (mL.run sL)) + (hf : ∀ eH eL, Re eH eL → ∀ tH tL, Rs tH tL → + (Sum.inl eH, tH) ∈ (mH sH).1 → + MRelStep Rs (SumExceptRel Re' Ra) (fH eH tH) ((fL eL).run tL)) : + MRelStep Rs (SumExceptRel Re' Ra) (holHandleE' mH fH sH) ((NonDetE.handleE mL fL).run sL) := by + unfold holHandleE' NonDetE.handleE ExceptT.mk ExceptT.run + refine mrelStep_bind_mem hm fun xH xL hx tH tL ht hmem => ?_ + cases xH with + | inl eH => + cases xL with + | error eL => exact hf eH eL hx tH tL ht hmem + | ok _ => exact False.elim hx + | inr aH => + cases xL with + | error _ => exact False.elim hx + | ok aL => + exact mrel_return (Ra := SumExceptRel Re' Ra) (aH := .inr aH) (aL := .ok aL) + hx tH tL ht + +theorem mrelStep_catch_mem {σH σL εH εL αH αL : Type} + {Rs : σH → σL → Prop} {Re : εH → εL → Prop} {Ra : αH → αL → Prop} + {mH : HolNonDet σH (Sum εH αH)} {mL : NonDetE σL εL αL} + {hH : εH → HolNonDet σH αH} {hL : εL → NonDet σL αL} + {sH : σH} {sL : σL} + (hm : MRelStep Rs (SumExceptRel Re Ra) (mH sH) (mL.run sL)) + (hh : ∀ eH eL, Re eH eL → ∀ s1H s1L, Rs s1H s1L → + (Sum.inl eH, s1H) ∈ (mH sH).1 → MRelStep Rs Ra (hH eH s1H) (hL eL s1L)) : + MRelStep Rs Ra (holCatch mH hH sH) (NonDetE.catch mL hL sL) := by + unfold holCatch NonDetE.catch + refine mrelStep_bind_mem hm fun aH aL ha s1H s1L hs1 hmem => ?_ + cases aH <;> cases aL <;> simp only [SumExceptRel] at ha + · exact hh _ _ ha s1H s1L hs1 hmem + · exact mrel_return ha s1H s1L hs1 + +end L4vRefX64.Rel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/State.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/State.lean new file mode 100644 index 000000000..4db58d9cb --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Rel/State.lean @@ -0,0 +1,171 @@ +import Fl4Spec.Ext.VirtGuest +import L4vRefX64.Rel.Embed +import L4vRefX64.Rel.Monad +import L4vRefX64.Rel.Config +import L4vRefX64.Spec.Time + +namespace L4vRefX64.Rel + +open Fl4Spec +open L4vRefX64.Spec +open L4vRefX64.Prim + +noncomputable section + +/-- ASIDs carried by the X64 reference fit in its 12-bit address-space namespace. -/ +def BaseAsid (asid : Asid) : Prop := asid.toNat < 2 ^ 12 + +private def BaseMapping (mapping : Option (Asid × VSpaceRef)) : Prop := + ∀ asid vaddr, mapping = some (asid, vaddr) → BaseAsid asid + +def BaseCap : Cap → Prop + | .archObjectCap (.vcpuCap _) => False + | .archObjectCap (.eptCap _ _ _) => False + | .archObjectCap .tdxControlCap => False + | .archObjectCap (.ioPortCap _ _ owner) => owner = none + | .archObjectCap (.pageCap _ _ _ mapType _ mapping) => + mapType ≠ .vmEptMap ∧ BaseMapping mapping + | .archObjectCap (.pageTableCap _ mapping) + | .archObjectCap (.pageDirectoryCap _ mapping) + | .archObjectCap (.pdPointerTableCap _ mapping) => BaseMapping mapping + | .archObjectCap (.pml4Cap _ mapping) => + ∀ asid, mapping = some asid → BaseAsid asid + | .archObjectCap (.asidPoolCap _ base) => BaseAsid base + | _ => True + +structure BaseTcb (t : Tcb) : Prop where + ctable : BaseCap t.tcbCtable + vtable : BaseCap t.tcbVtable + ipcframe : BaseCap t.tcbIpcframe + faultHandler : BaseCap t.tcbFaultHandler + timeoutHandler : BaseCap t.tcbTimeoutHandler + eptSlot : t.tcbEpt = .nullCap + nativeThread : t.tcbState ≠ .runningVM + +/-- Conditions on the two state components that contain base-carrier values. -/ +structure BaseCarriersFor (heap : KHeap) (cr3 : Cr3) : Prop where + noVirtHeap : ∀ ptr obj, heap ptr = some (.archObj obj) → + (∀ vcpu, obj ≠ .vcpu vcpu) ∧ (∀ level entries, obj ≠ .ept level entries) + cnodeCaps : ∀ ptr size caps slot cap, heap ptr = some (.cnode size caps) → + caps slot = some cap → BaseCap cap + tcbs : ∀ ptr t, heap ptr = some (.tcb t) → BaseTcb t + untaggedAsidEntries : ∀ ptr entries index root, + heap ptr = some (.archObj (.asidPool entries)) → entries index = some root → + root &&& 1 = 0 + commonPcid : BaseAsid (cr3Pcid cr3) + +abbrev BaseCarriers {Z : Type} (s : State Z) : Prop := + BaseCarriersFor s.kheap s.archState.x64CurrentCr3 + +theorem BaseCarriers.noVirtObjects {Z : Type} {s : State Z} + (h : BaseCarriers s) : NoVirtObjects s := + h.noVirtHeap + +/-- Machine-state relation with an explicit correspondence for the opaque rest. -/ +structure MachineStateRel + (RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop) + (sH : MachineTypes.machine_state) (sL : MachineState) : Prop where + irqMasks_eq : sL.irqMasks = sH.irq_masks + irqState_eq : sL.irqState = sH.irq_state + timeState_eq : sL.timeState = sH.time_state + lastMachineTime_eq : sL.lastMachineTime = sH.last_machine_time + underlyingMemory_eq : sL.underlyingMemory = sH.underlying_memory + deviceState_eq : sL.deviceState = sH.device_state + fpuEnabled_eq : sL.fpuEnabled = sH.fpu_enabled + rest_rel : RestRel sH.machine_state_rest sL.machineStateRest + +/-- The reference describes a single core. The selected FL4 core supplies its idle SC. -/ +structure StateRel + (RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop) + {ZH ZL : Type} (ExstRel : ZH → ZL → Prop) + (sH : Structures_A.state ZH) (sL : State ZL) : Prop where + kheap_eq : ∀ p, sL.kheap p = (sH.kheap p).map embKernelObject + cdt_eq : sL.cdt = sH.cdt + isOriginalCap_eq : sL.isOriginalCap = sH.is_original_cap + curThread_eq : sL.curThread = sH.cur_thread + idleThread_eq : sL.idleThread = sH.idle_thread + idleSc_eq : sL.idleSc = Machine_A.idle_sc_ptr + consumedTime_eq : sL.consumedTime = sH.consumed_time + curTime_eq : sL.curTime = sH.cur_time + curSc_eq : sL.curSc = sH.cur_sc + reprogramTimer_eq : sL.reprogramTimer = sH.reprogram_timer + schedulerAction_eq : sL.schedulerAction = embSchedulerAction sH.scheduler_action + domainList_eq : sL.domainList = sH.domain_list + domainIndex_eq : sL.domainIndex = sH.domain_index + domainStartIndex_eq : sL.domainStartIndex = sH.domain_start_index + curDomain_eq : sL.curDomain = sH.cur_domain + domainTime_eq : sL.domainTime = sH.domain_time + readyQueues_eq : sL.readyQueues = sH.ready_queues + releaseQueue_eq : sL.releaseQueue = sH.release_queue + machineState_rel : MachineStateRel RestRel sH.machine_state sL.machineState + interruptIrqNode_eq : sL.interruptIrqNode = sH.interrupt_irq_node + interruptStates_eq : ∀ i, sL.interruptStates i = embIrqState (sH.interrupt_states i) + archState_eq : sL.archState = embArchState sL.archState.x64Plat sH.arch_state + exst_rel : ExstRel sH.more.exst sL.exst + +def ReferenceBaseCarriers {ZH : Type} (s : Structures_A.state ZH) : Prop := + BaseCarriersFor (fun ptr => (s.kheap ptr).map embKernelObject) (embCr3 s.arch_state.x64_current_cr3) + +theorem StateRel.baseCarriers_iff + {RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop} + {ZH ZL : Type} {ExstRel : ZH → ZL → Prop} + {sH : Structures_A.state ZH} {sL : State ZL} + (hs : StateRel RestRel ExstRel sH sL) : BaseCarriers sL ↔ ReferenceBaseCarriers sH := by + unfold BaseCarriers ReferenceBaseCarriers + have hheap := funext hs.kheap_eq + have hcr3 := congrArg ArchState.x64CurrentCr3 hs.archState_eq + rw [hheap, hcr3] + rfl + +abbrev EventRel := FunRel embEvent + +/-- [P] Correspondence of the opaque symbols reachable from the checked kernel entry. -/ +structure OpaqueRel + (RestRel : MachineTypes.machine_state_rest → MachineStateRest → Prop) : Prop where + irqOracle_eq : Fl4Spec.irqOracle = MachineTypes.irq_oracle + timeOracle_eq : Fl4Spec.timeOracle = MachineTypes.time_oracle + kernelWCETUs_eq : Fl4Spec.kernelWCETUs = Time.kernelWCET_us + maxPeriodUs_eq : Fl4Spec.MAX_PERIOD_US = Time.MAX_PERIOD_US + maxTicksToUs_eq : Fl4Spec.maxTicksToUs = Time.max_ticks_to_us + ticksPerTimerUnit_eq : Fl4Spec.ticksPerTimerUnit = Time.ticks_per_timer_unit + timerUnit_eq : Fl4Spec.timerUnit = Time.timer_unit + fpuNullState_eq : Fl4Spec.FPUNullState = MachineOps.FPUNullState + readFpuState_eq : ∀ rH rL, RestRel rH rL → + Fl4Spec.readFpuStateVal rL = MachineOps.readFpuState_val rH + faultAddress_eq : ∀ msH msL, MachineStateRel RestRel msH msL → + Fl4Spec.getFaultAddressVal msL = MachineOps.getFaultAddress_val msH + in8Val_eq : ∀ msH msL, MachineStateRel RestRel msH msL → + Fl4Spec.in8Val msL = MachineOps.in8_val msH + in16Val_eq : ∀ msH msL, MachineStateRel RestRel msH msL → + Fl4Spec.in16Val msL = MachineOps.in16_val msH + in32Val_eq : ∀ msH msL, MachineStateRel RestRel msH msL → + Fl4Spec.in32Val msL = MachineOps.in32_val msH + disableFpu_rel : MRel RestRel Eq MachineOps.disableFpu_impl Fl4Spec.disableFpuImpl + enableFpu_rel : MRel RestRel Eq MachineOps.enableFpu_impl Fl4Spec.enableFpuImpl + writeFpuState_rel : ∀ fpu, MRel RestRel Eq (MachineOps.writeFpuState_impl fpu) + (Fl4Spec.writeFpuStateImpl fpu) + invalidateAsid_rel : ∀ base asid, MRel RestRel Eq (MachineOps.invalidateASID_impl base asid) + (Fl4Spec.invalidateASIDImpl base asid) + invalidateLocalCacheAsid_rel : ∀ base asid, + MRel RestRel Eq (MachineOps.invalidateLocalPageStructureCacheASID_impl base asid) + (Fl4Spec.invalidateLocalPageStructureCacheASIDImpl base asid) + invalidateSingleAsid_rel : ∀ addr asid, + MRel RestRel Eq (MachineOps.invalidateTranslationSingleASID_impl addr asid) + (Fl4Spec.invalidateTranslationSingleASIDImpl addr asid) + ioapicMapPin_rel : ∀ apic pin level polarity vector, + MRel RestRel Eq (MachineOps.ioapicMapPinToVector_impl apic pin level polarity vector) + (Fl4Spec.ioapicMapPinToVectorImpl apic pin level polarity vector) + in8_rel : ∀ port, MRel RestRel Eq (MachineOps.in8_impl port) (Fl4Spec.in8Impl port) + in16_rel : ∀ port, MRel RestRel Eq (MachineOps.in16_impl port) (Fl4Spec.in16Impl port) + in32_rel : ∀ port, MRel RestRel Eq (MachineOps.in32_impl port) (Fl4Spec.in32Impl port) + out8_rel : ∀ port value, MRel RestRel Eq (MachineOps.out8_impl port value) + (Fl4Spec.out8Impl port value) + out16_rel : ∀ port value, MRel RestRel Eq (MachineOps.out16_impl port value) + (Fl4Spec.out16Impl port value) + out32_rel : ∀ port value, MRel RestRel Eq (MachineOps.out32_impl port value) + (Fl4Spec.out32Impl port value) + setDeadline_rel : ∀ d, MRel RestRel Eq (MachineOps.setDeadline_impl d) (Fl4Spec.setDeadlineImpl d) + +end + +end L4vRefX64.Rel diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec.lean new file mode 100644 index 000000000..309bff3e1 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec.lean @@ -0,0 +1,60 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py — DO NOT EDIT +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Arch_Structs_B +import L4vRefX64.Spec.Nondet_Empty_Fail +import L4vRefX64.Spec.Lib +import L4vRefX64.Spec.Kernel_Config +import L4vRefX64.Spec.Platform +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.MachineMonad +import L4vRefX64.Spec.Time +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.MiscMachine_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.VMRights_A +import L4vRefX64.Spec.ArchVMAttributes_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.List_Lib +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.ArchInvocation_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.ArchVSpaceAcc_A +import L4vRefX64.Spec.ArchRetype_A +import L4vRefX64.Spec.Retype_A +import L4vRefX64.Spec.FPU_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.ArchCSpace_A +import L4vRefX64.Spec.TcbAcc_A +import L4vRefX64.Spec.Sporadic_A +import L4vRefX64.Spec.ArchIpcCancel_A +import L4vRefX64.Spec.Init_A +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Spec.SchedContext_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.Arch_A +import L4vRefX64.Spec.Schedule_A +import L4vRefX64.Spec.ArchTcb_A +import L4vRefX64.Spec.Tcb_A +import L4vRefX64.Spec.ArchFault_A +import L4vRefX64.Spec.Ipc_A +import L4vRefX64.Spec.ArchInterrupt_A +import L4vRefX64.Spec.Interrupt_A +import L4vRefX64.Spec.InvocationLabels_A +import L4vRefX64.Spec.ArchDecode_A +import L4vRefX64.Spec.Decode_A +import L4vRefX64.Spec.Hypervisor_A +import L4vRefX64.Spec.Event_H +import L4vRefX64.Spec.Syscall_A +import L4vRefX64.Spec.ArchInvocationLabels_H +import L4vRefX64.Spec.InvocationLabels_H +import L4vRefX64.Spec.Kernel_Config_Lemmas +import L4vRefX64.Spec.Reader_Option_Monad +import L4vRefX64.Spec.Aligned +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.More_Word_Operations diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Aligned.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Aligned.lean new file mode 100644 index 000000000..3bcba5615 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Aligned.lean @@ -0,0 +1,14 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (Word_Lib.Aligned) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Aligned +open L4vRefX64.Prim +open Classical +noncomputable section +def is_aligned {w_tv_a : Nat} : ((BitVec w_tv_a) → (Nat → Bool)) := + (holMapFun holWordRep holId (fun (k : Int) => (fun (n : Nat) => (holDvd (HolPow.powVal (HolNumeral.ofNatVal (α := Int) 2) n) (holWordTakeBit w_tv_a k))))) +end +end L4vRefX64.Spec.Aligned diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchCSpace_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchCSpace_A.lean new file mode 100644 index 000000000..8bc6bf4ed --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchCSpace_A.lean @@ -0,0 +1,51 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchCSpace_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchCSpace_A +open L4vRefX64.Prim +open Classical +noncomputable section +def arch_is_cap_revocable : (L4vRefX64.Spec.Structures_A.cap → (L4vRefX64.Spec.Structures_A.cap → Bool)) := + (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_cap : L4vRefX64.Spec.Structures_A.cap) => (holIf (holEx (fun (f : (BitVec 16)) => (holEx (fun (l : (BitVec 16)) => (holEq new_cap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap f l))))))) (holEq src_cap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortControlCap)) false))) + +def arch_is_physical : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → Bool) := + (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => true)) false (fun (x : (BitVec 16)) => (fun (xa : (BitVec 16)) => false)) false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => true)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => true)) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => true)) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => true)) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => true)) cap)) + +def arch_same_region_as : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → Bool)) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev r R t s m), c_p => (holEx (fun (dev_p : Bool) => (holEx (fun (r_p : (BitVec 64)) => (holEx (fun (R_p : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEx (fun (t_p : L4vRefX64.Spec.MachineTypes.vmmap_type) => (holEx (fun (s_p : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holEx (fun (m_p : (Option ((BitVec 64) × (BitVec 64)))) => (holConj (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev_p r_p R_p t_p s_p m_p)) (holLet (HolSub.subVal (HolAdd.addVal r (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.MachineTypes.pageBitsForSize s))) (HolOne.oneVal (α := (BitVec 64)))) (fun (topA : (BitVec 64)) => (holLet (HolSub.subVal (HolAdd.addVal r_p (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.MachineTypes.pageBitsForSize s_p))) (HolOne.oneVal (α := (BitVec 64)))) (fun (topB : (BitVec 64)) => (holConj (holLe r r_p) (holConj (holLe topB topA) (holLe r_p topB)))))))))))))))))))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap r uu), c_p => (holEx (fun (r_p : (BitVec 64)) => (holEx (fun (d_p : (Option ((BitVec 64) × (BitVec 64)))) => (holConj (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap r_p d_p)) (holEq r r_p)))))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap r uv), c_p => (holEx (fun (r_p : (BitVec 64)) => (holEx (fun (d_p : (Option ((BitVec 64) × (BitVec 64)))) => (holConj (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap r_p d_p)) (holEq r r_p)))))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap r uw), c_p => (holEx (fun (r_p : (BitVec 64)) => (holEx (fun (d_p : (Option ((BitVec 64) × (BitVec 64)))) => (holConj (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap r_p d_p)) (holEq r r_p)))))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap r ux), c_p => (holEx (fun (r_p : (BitVec 64)) => (holEx (fun (d_p : (Option (BitVec 64))) => (holConj (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap r_p d_p)) (holEq r r_p)))))) + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDControlCap, c_p => (holEq c_p L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDControlCap) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDPoolCap r uy), c_p => (holEx (fun (r_p : (BitVec 64)) => (holEx (fun (d_p : (BitVec 64)) => (holConj (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDPoolCap r_p d_p)) (holEq r r_p)))))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap frst lst), c_p => (holEx (fun (frst_p : (BitVec 16)) => (holEx (fun (lst_p : (BitVec 16)) => (holConj (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap frst_p lst_p)) (holConj (holEq frst_p frst) (holEq lst_p lst))))))) + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortControlCap, c_p => (holDisj (holEq c_p L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortControlCap) (holEx (fun (f : (BitVec 16)) => (holEx (fun (l : (BitVec 16)) => (holEq c_p (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap f l))))))) + +def cnode_guard_size_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 6) + +def cnode_padding_bits : Nat := + (HolZero.zeroVal (α := Nat)) + +def is_irq_control_descendant : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → Bool) := + (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => false) + +def same_aobject_as : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → Bool)) := + (fun (cp : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (cp_p : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holCaseProd (fun (a : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (b : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p) (fun (f_p : (BitVec 16)) => (fun (l_p : (BitVec 16)) => false)) (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) b) (fun (dev : Bool) => (fun (ref : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (xa : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (pgsz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (xb : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p) (fun (dev_p : Bool) => (fun (ref_p : (BitVec 64)) => (fun (xc : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (xd : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (pgsz_p : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (xe : (Option ((BitVec 64) × (BitVec 64)))) => (holConj (holEq (Prod.mk dev (Prod.mk ref pgsz)) (Prod.mk dev_p (Prod.mk ref_p pgsz_p))) (holLe ref (HolSub.subVal (HolAdd.addVal ref (HolPow.powVal (HolNumeral.ofNatVal (α := (BitVec 64)) 2) (L4vRefX64.Spec.MachineTypes.pageBitsForSize pgsz))) (HolOne.oneVal (α := (BitVec 64)))))))))))) (fun (worda : (BitVec 64)) => (fun (optiona : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (worda : (BitVec 64)) => (fun (optiona : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (worda : (BitVec 64)) => (fun (optiona : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (worda : (BitVec 64)) => (fun (optiona : (Option (BitVec 64))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) b))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as cp cp_p))) a))) (Prod.mk cp cp_p)))) + +def should_be_arch_parent_of : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Bool → Bool))) := + (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (acap_p : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (original_p : Bool) => true))) + +def update_cnode_cap_data : ((BitVec 64) → (Nat × (BitVec 64))) := + (fun (w : (BitVec 64)) => (holLet (HolNumeral.ofNatVal (α := Nat) 58) (fun (guard_bits : Nat) => (holLet (holUnsigned (holWordAnd (holWordShiftr w L4vRefX64.Spec.ArchCSpace_A.cnode_padding_bits) ((holWordMask (w := 64)) L4vRefX64.Spec.ArchCSpace_A.cnode_guard_size_bits))) (fun (guard_size_p : Nat) => (holLet (holWordAnd (holWordShiftr w (HolAdd.addVal L4vRefX64.Spec.ArchCSpace_A.cnode_padding_bits L4vRefX64.Spec.ArchCSpace_A.cnode_guard_size_bits)) ((holWordMask (w := 64)) guard_bits)) (fun (guard_p_p : (BitVec 64)) => (Prod.mk guard_size_p guard_p_p)))))))) +end +end L4vRefX64.Spec.ArchCSpace_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchDecode_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchDecode_A.lean new file mode 100644 index 000000000..e0360c00b --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchDecode_A.lean @@ -0,0 +1,93 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchDecode_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Aligned +import L4vRefX64.Spec.ArchInvocationLabels_H +import L4vRefX64.Spec.ArchInvocation_A +import L4vRefX64.Spec.ArchVMAttributes_A +import L4vRefX64.Spec.ArchVSpaceAcc_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.Interrupt_A +import L4vRefX64.Spec.InvocationLabels_A +import L4vRefX64.Spec.InvocationLabels_H +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.MiscMachine_A +import L4vRefX64.Spec.Platform +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.VMRights_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchDecode_A +open L4vRefX64.Prim +open Classical +noncomputable section +def arch_check_irq {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) + +def arch_data_to_obj_type : (Nat → (Option L4vRefX64.Spec.Arch_Structs_A.aobject_type)) := + (fun (n : Nat) => (holIf (holEq n (HolZero.zeroVal (α := Nat))) (Option.some L4vRefX64.Spec.Arch_Structs_A.aobject_type.PDPTObj) (holIf (holEq n (HolOne.oneVal (α := Nat))) (Option.some L4vRefX64.Spec.Arch_Structs_A.aobject_type.PML4Obj) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 2)) (Option.some L4vRefX64.Spec.Arch_Structs_A.aobject_type.HugePageObj) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 3)) (Option.some L4vRefX64.Spec.Arch_Structs_A.aobject_type.SmallPageObj) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 4)) (Option.some L4vRefX64.Spec.Arch_Structs_A.aobject_type.LargePageObj) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 5)) (Option.some L4vRefX64.Spec.Arch_Structs_A.aobject_type.PageTableObj) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 6)) (Option.some L4vRefX64.Spec.Arch_Structs_A.aobject_type.PageDirectoryObj) (Option.none (α := L4vRefX64.Spec.Arch_Structs_A.aobject_type)))))))))) + +def is_ioport_range_free {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 16) → ((BitVec 16) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_allocated_io_ports L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (alloc_ports : ((BitVec 16) → Bool)) => (holFunApp holReturn (holEq (HolCompleteLattice.holInf (holAtLeastAtMost f l) (holCollect alloc_ports)) (HolCompleteLattice.holBot (α := (Set (BitVec 16)))))))))) + +def decode_ioport_control_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (extra_caps : (List L4vRefX64.Spec.Structures_A.cap)) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortControlIssue)) (holIf (holConj (holLe (HolNumeral.ofNatVal (α := Nat) 4) (holSize args)) (holLe (HolOne.oneVal (α := Nat)) (holSize extra_caps))) (holLet ((holUcast (w := 16)) (holNth args (HolZero.zeroVal (α := Nat)))) (fun (first_port : (BitVec 16)) => (holLet ((holUcast (w := 16)) (holNth args (HolOne.oneVal (α := Nat)))) (fun (last_port : (BitVec 16)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 2)) (fun (index : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 3)) (fun (depth : (BitVec 64)) => (holLet (holNth extra_caps (HolZero.zeroVal (α := Nat))) (fun (cnode : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holLt last_port first_port)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchDecode_A.is_ioport_range_free first_port last_port)) (fun (check : Bool) => (holBindE (holFunApp (holWhenE (holNot check)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst)) (holKBind (holBindE (L4vRefX64.Spec.CSpace_A.lookup_target_slot cnode (L4vRefX64.Spec.Machine_A.data_to_cptr index) (holUnsigned depth)) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holBindE (L4vRefX64.Spec.CSpaceAcc_A.ensure_empty dest_slot) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeIOPortControl (L4vRefX64.Spec.ArchInvocation_A.io_port_control_invocation.IOPortControlInvocation first_port last_port dest_slot slot))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))))) + +def filter_vm_attributes : ((Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) → (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) := + (fun (attrs : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (holCollect (fun (s : L4vRefX64.Spec.ArchVMAttributes_A.table_attr) => (holBex attrs (fun (s_p : L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) => (holEq s_p (L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PTAttr s))))))) + +def decode_page_directory_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cte : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (p : (BitVec 64)) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageDirectoryMap)) (holIf (holConj (holLt (HolOne.oneVal (α := Nat)) (holSize args)) (holLt (HolZero.zeroVal (α := Nat)) (holSize extra_caps))) (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (vaddr : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (attr : (BitVec 64)) => (holLet (Prod.fst (holNth extra_caps (HolZero.zeroVal (α := Nat)))) (fun (pml4_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holNot (holEq mapped_address (Option.none (α := ((BitVec 64) × (BitVec 64))))))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordAnd vaddr (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pdpt_shift_bits)))) (fun (vaddr_p : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (pml4 : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holCaseOption (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (asid : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk pml4 asid))) option))) arch_cap)) pml4_cap) (holCaseProd (fun (pml4 : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.Machine_A.user_vtop vaddr_p)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat))))) (holKBind (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid)) (fun (pml4_p : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holNot (holEq pml4_p pml4))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pdpt_slot pml4 vaddr_p)) (fun (pdpt_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpte pdpt_slot)) (fun (old_pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (holBindE (holFunApp (holUnlessE (holEq old_pdpte L4vRefX64.Spec.Arch_Structs_A.pdpte.InvalidPDPTE)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst)) (holKBind (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Arch_Structs_A.pdpte.PageDirectoryPDPTE (L4vRefX64.Spec.Platform.addrFromPPtr p) (holFunApp L4vRefX64.Spec.ArchDecode_A.filter_vm_attributes (L4vRefX64.Spec.ArchVMAttributes_A.attribs_from_word attr)) L4vRefX64.Spec.VMRights_A.vm_read_write)) (fun (pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (holFunApp (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap p) (Option.some (Prod.mk asid vaddr_p))))) (fun (cap_p : L4vRefX64.Spec.Structures_A.cap) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePageDirectory (L4vRefX64.Spec.ArchInvocation_A.page_directory_invocation.PageDirectoryMap cap_p cte pdpte pdpt_slot pml4))))))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageDirectoryUnmap)) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.IpcCancel_A.is_final_cap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap cap))) (fun (final : Bool) => (holBindE (holFunApp (holUnlessE final) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePageDirectory (L4vRefX64.Spec.ArchInvocation_A.page_directory_invocation.PageDirectoryUnmap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap cap) cte))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap)))))) + +def check_vp_alignment {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.MachineTypes.vmpage_size → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (vptr : (BitVec 64)) => (holFunApp (holUnlessE (L4vRefX64.Spec.Aligned.is_aligned vptr (L4vRefX64.Spec.MachineTypes.pageBitsForSize sz))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.AlignmentError)))) + +def decode_page_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cte : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (dev : Bool) => (fun (p : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (map_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (pgsz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageMap)) (holIf (holConj (holLt (HolNumeral.ofNatVal (α := Nat) 2) (holSize args)) (holLt (HolZero.zeroVal (α := Nat)) (holSize extra_caps))) (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (vaddr : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (rights_mask : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 2)) (fun (attr : (BitVec 64)) => (holLet (Prod.fst (holNth extra_caps (HolZero.zeroVal (α := Nat)))) (fun (vspace_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (pm : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holCaseOption (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (asid : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk pm asid))) option))) arch_cap)) vspace_cap) (holCaseProd (fun (vspace : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holBindE (holCaseOption (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (HolAdd.addVal vaddr ((holHaskellBit (w := 64)) (L4vRefX64.Spec.MachineTypes.pageBitsForSize pgsz)))) (fun (vtop : (BitVec 64)) => (holFunApp (holWhenE (holDisj (holLt L4vRefX64.Spec.Machine_A.user_vtop vaddr) (holLt L4vRefX64.Spec.Machine_A.user_vtop vtop))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat))))))) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (asid_p : (BitVec 64)) => (fun (vaddr_p : (BitVec 64)) => (holBindE (holWhenE (holNot (holEq asid_p asid)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holWhenE (holNot (holEq map_type L4vRefX64.Spec.MachineTypes.vmmap_type.VMVSpaceMap))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holWhenE (holNot (holEq vaddr_p vaddr)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat))))))))))) a)) mapped_address) (holKBind (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid)) (fun (vspace_p : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holNot (holEq vspace_p vspace))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (L4vRefX64.Spec.VMRights_A.mask_vm_rights R) (L4vRefX64.Spec.CSpace_A.data_to_rights rights_mask))) (fun (vm_rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.check_vp_alignment pgsz vaddr) (holKBind (holBindE (L4vRefX64.Spec.ArchVSpace_A.create_mapping_entries (L4vRefX64.Spec.Platform.addrFromPPtr p) vaddr pgsz vm_rights (L4vRefX64.Spec.ArchVMAttributes_A.attribs_from_word attr) vspace) (fun (entries : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (holBindE (L4vRefX64.Spec.ArchVSpace_A.ensure_safe_mapping entries) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePage (L4vRefX64.Spec.ArchInvocation_A.page_invocation.PageMap (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev p R L4vRefX64.Spec.MachineTypes.vmmap_type.VMVSpaceMap pgsz (Option.some (Prod.mk asid vaddr)))) cte entries vspace))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageUnmap)) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePage (L4vRefX64.Spec.ArchInvocation_A.page_invocation.PageUnmap cap cte))) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageGetAddress)) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePage (L4vRefX64.Spec.ArchInvocation_A.page_invocation.PageGetAddr p))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap)))))) + +def decode_page_table_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cte : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (p : (BitVec 64)) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageTableMap)) (holIf (holConj (holLt (HolOne.oneVal (α := Nat)) (holSize args)) (holLt (HolZero.zeroVal (α := Nat)) (holSize extra_caps))) (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (vaddr : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (attr : (BitVec 64)) => (holLet (Prod.fst (holNth extra_caps (HolZero.zeroVal (α := Nat)))) (fun (pml4_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holNot (holEq mapped_address (Option.none (α := ((BitVec 64) × (BitVec 64))))))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordAnd vaddr (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pd_shift_bits)))) (fun (vaddr_p : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (pml4 : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holCaseOption (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (asid : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk pml4 asid))) option))) arch_cap)) pml4_cap) (holCaseProd (fun (pml4 : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.Machine_A.user_vtop vaddr_p)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat))))) (holKBind (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid)) (fun (pml4_p : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holNot (holEq pml4_p pml4))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pd_slot pml4 vaddr_p)) (fun (pd_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pde pd_slot)) (fun (old_pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (holBindE (holFunApp (holUnlessE (holEq old_pde L4vRefX64.Spec.Arch_Structs_A.pde.InvalidPDE)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst)) (holKBind (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Arch_Structs_A.pde.PageTablePDE (L4vRefX64.Spec.Platform.addrFromPPtr p) (holFunApp L4vRefX64.Spec.ArchDecode_A.filter_vm_attributes (L4vRefX64.Spec.ArchVMAttributes_A.attribs_from_word attr)) L4vRefX64.Spec.VMRights_A.vm_read_write)) (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (holFunApp (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap p) (Option.some (Prod.mk asid vaddr_p))))) (fun (cap_p : L4vRefX64.Spec.Structures_A.cap) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePageTable (L4vRefX64.Spec.ArchInvocation_A.page_table_invocation.PageTableMap cap_p cte pde pd_slot pml4))))))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageTableUnmap)) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.IpcCancel_A.is_final_cap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap cap))) (fun (final : Bool) => (holBindE (holFunApp (holUnlessE final) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePageTable (L4vRefX64.Spec.ArchInvocation_A.page_table_invocation.PageTableUnmap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap cap) cte))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap)))))) + +def decode_pdpt_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cte : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (p : (BitVec 64)) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PDPTMap)) (holIf (holConj (holLt (HolOne.oneVal (α := Nat)) (holSize args)) (holLt (HolZero.zeroVal (α := Nat)) (holSize extra_caps))) (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (vaddr : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (attr : (BitVec 64)) => (holLet (Prod.fst (holNth extra_caps (HolZero.zeroVal (α := Nat)))) (fun (pml4_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holNot (holEq mapped_address (Option.none (α := ((BitVec 64) × (BitVec 64))))))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordAnd vaddr (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pml4_shift_bits)))) (fun (vaddr_p : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (pml4 : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holCaseOption (holFunApp (holThrowError (α := ((BitVec 64) × (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (asid : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk pml4 asid))) option))) arch_cap)) pml4_cap) (holCaseProd (fun (pml4 : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.Machine_A.user_vtop vaddr_p)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat))))) (holKBind (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid)) (fun (pml4_p : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holNot (holEq pml4_p pml4))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pml4_slot pml4 vaddr_p)) (fun (pml_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4e pml_slot)) (fun (old_pml4e : L4vRefX64.Spec.Arch_Structs_A.pml4e) => (holBindE (holFunApp (holUnlessE (holEq old_pml4e L4vRefX64.Spec.Arch_Structs_A.pml4e.InvalidPML4E)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst)) (holKBind (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Arch_Structs_A.pml4e.PDPointerTablePML4E (L4vRefX64.Spec.Platform.addrFromPPtr p) (holFunApp L4vRefX64.Spec.ArchDecode_A.filter_vm_attributes (L4vRefX64.Spec.ArchVMAttributes_A.attribs_from_word attr)) L4vRefX64.Spec.VMRights_A.vm_read_write)) (fun (pml4e : L4vRefX64.Spec.Arch_Structs_A.pml4e) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (holFunApp (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap p) (Option.some (Prod.mk asid vaddr_p))))) (fun (cap_p : L4vRefX64.Spec.Structures_A.cap) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePDPT (L4vRefX64.Spec.ArchInvocation_A.pdpt_invocation.PDPTMap cap_p cte pml4e pml_slot pml4))))))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PDPTUnmap)) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.IpcCancel_A.is_final_cap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap cap))) (fun (final : Bool) => (holBindE (holFunApp (holUnlessE final) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokePDPT (L4vRefX64.Spec.ArchInvocation_A.pdpt_invocation.PDPTUnmap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap cap) cte))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap)))))) + +def ensure_port_operation_allowed {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((BitVec 32) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (start_port : (BitVec 32)) => (fun (sz : Nat) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (first_allowed : (BitVec 16)) => (fun (last_allowed : (BitVec 16)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (HolSub.subVal (HolAdd.addVal start_port ((holOfNat (α := (BitVec 32))) sz)) (HolOne.oneVal (α := (BitVec 32))))) (fun (end_port : (BitVec 32)) => (holBindE ((holAssertE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holLe first_allowed last_allowed)) (holKBind (holBindE ((holAssertE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holLe start_port end_port)) (holKBind (holFunApp (holWhenE (holDisj (holLt start_port ((holUcast (w := 32)) first_allowed)) (holLt ((holUcast (w := 32)) last_allowed) end_port))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))))))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap)))) + +def decode_port_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.InvocationLabels_H.case_invocation_label (fun (gen_invocation_labels : L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels) => ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (fun (arch_invocation_label : L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label) => (L4vRefX64.Spec.ArchInvocationLabels_H.case_arch_invocation_label ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolOne.oneVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 16)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (port : (BitVec 16)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.ensure_port_operation_allowed cap ((holUcast (w := 32)) port) (HolOne.oneVal (α := Nat))) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeIOPort (holFunApp (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation.IOPortInvocation port) L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data.IOPortIn8))))))))) (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolOne.oneVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 16)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (port : (BitVec 16)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.ensure_port_operation_allowed cap ((holUcast (w := 32)) port) (HolNumeral.ofNatVal (α := Nat) 2)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeIOPort (holFunApp (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation.IOPortInvocation port) L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data.IOPortIn16))))))))) (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolOne.oneVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 16)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (port : (BitVec 16)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.ensure_port_operation_allowed cap ((holUcast (w := 32)) port) (HolNumeral.ofNatVal (α := Nat) 4)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeIOPort (holFunApp (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation.IOPortInvocation port) L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data.IOPortIn32))))))))) (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 16)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (port : (BitVec 16)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.ensure_port_operation_allowed cap ((holUcast (w := 32)) port) (HolOne.oneVal (α := Nat))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 8)) (holNth args (HolOne.oneVal (α := Nat))))) (fun (output_data : (BitVec 8)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeIOPort (holFunApp (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation.IOPortInvocation port) (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data.IOPortOut8 output_data)))))))))))) (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 16)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (port : (BitVec 16)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.ensure_port_operation_allowed cap ((holUcast (w := 32)) port) (HolNumeral.ofNatVal (α := Nat) 2)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 16)) (holNth args (HolOne.oneVal (α := Nat))))) (fun (output_data : (BitVec 16)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeIOPort (holFunApp (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation.IOPortInvocation port) (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data.IOPortOut16 output_data)))))))))))) (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 16)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (port : (BitVec 16)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.ensure_port_operation_allowed cap ((holUcast (w := 32)) port) (HolNumeral.ofNatVal (α := Nat) 4)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 32)) (holNth args (HolOne.oneVal (α := Nat))))) (fun (output_data : (BitVec 32)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeIOPort (holFunApp (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation.IOPortInvocation port) (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data.IOPortOut32 output_data)))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) arch_invocation_label)) (L4vRefX64.Spec.InvocationLabels_A.invocation_type label))))) + +def arch_decode_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((List Bool) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (x_slot : (List Bool)) => (fun (cte : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (p : (BitVec 64)) => (fun (base : (BitVec 64)) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64ASIDPoolAssign)) (holIf (holLt (HolZero.zeroVal (α := Nat)) (holSize extra_caps)) (holLet (holNth extra_caps (HolZero.zeroVal (α := Nat))) (holCaseProd (fun (pd_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (pd_cap_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (x : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holCaseOption (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_asid_table L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state))) (fun (asid_table : ((BitVec 3) → (Option (BitVec 64)))) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (asid_table (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_high_bits_of base))) (fun (pool_ptr : (Option (BitVec 64))) => (holBindE (holFunApp (holWhenE (holEq pool_ptr (Option.none (α := (BitVec 64))))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup false L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) (holKBind (holBindE (holFunApp (holWhenE (holNot (holEq p (holTheOpt pool_ptr)))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat))))) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_asid_pool p)) (fun (pool : ((BitVec 9) → (Option (BitVec 64)))) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (HolCompleteLattice.holInf (HolNeg.negVal (holDom pool)) (holCollect (fun (x_1 : (BitVec 9)) => (holNot (holEq (HolAdd.addVal ((holUcast (w := 64)) x_1) base) (HolZero.zeroVal (α := (BitVec 64))))))))) (fun (free_set : (Set (BitVec 9))) => (holBindE (holFunApp (holWhenE (holEq free_set (HolCompleteLattice.holBot (α := (Set (BitVec 9)))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Deterministic_A.select_ext (fun (uu_ : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.free_asid_pool_select pool base)) free_set)) (fun (offset : (BitVec 9)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeASIDPool (L4vRefX64.Spec.ArchInvocation_A.asid_pool_invocation.Assign (HolAdd.addVal ((holUcast (w := 64)) offset) base) p pd_cap_slot))))))))))))))))))) (fun (a : (BitVec 64)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) option))) arch_cap)) pd_cap))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64ASIDControlMakePool)) (holIf (holConj (holLt (HolOne.oneVal (α := Nat)) (holSize args)) (holLt (HolOne.oneVal (α := Nat)) (holSize extra_caps))) (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (index : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (depth : (BitVec 64)) => (holLet (holNth extra_caps (HolZero.zeroVal (α := Nat))) (holCaseProd (fun (untyped : L4vRefX64.Spec.Structures_A.cap) => (fun (parent_slot : ((BitVec 64) × (List Bool))) => (holLet (Prod.fst (holNth extra_caps (HolOne.oneVal (α := Nat)))) (fun (root : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_asid_table L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state))) (fun (asid_table : ((BitVec 3) → (Option (BitVec 64)))) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (HolNeg.negVal (holDom asid_table))) (fun (free_set : (Set (BitVec 3))) => (holBindE (holFunApp (holWhenE (holEq free_set (HolCompleteLattice.holBot (α := (Set (BitVec 3)))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Deterministic_A.select_ext (fun (uu_ : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.free_asid_select asid_table)) free_set)) (fun (free : (BitVec 3)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordShiftl ((holUcast (w := 64)) free) L4vRefX64.Spec.MiscMachine_A.asid_low_bits)) (fun (base : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (p : (BitVec 64)) => (fun (n : Nat) => (fun (f : Nat) => (holCaseBool (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk p n)) bool))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFunApp (holThrowError (α := ((BitVec 64) × Nat))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) untyped) (holCaseProd (fun (p : (BitVec 64)) => (fun (n : Nat) => (holBindE (holIf (holEq n L4vRefX64.Spec.MachineTypes.pageBits) (holBindE (L4vRefX64.Spec.CSpace_A.ensure_no_children parent_slot) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) p))) (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (frame : (BitVec 64)) => (holBindE (L4vRefX64.Spec.CSpace_A.lookup_target_slot root (holToBl index) (holUnsigned depth)) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holBindE (L4vRefX64.Spec.CSpaceAcc_A.ensure_empty dest_slot) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.ArchInvocation_A.arch_invocation.InvokeASIDControl (L4vRefX64.Spec.ArchInvocation_A.asid_control_invocation.MakePool frame dest_slot parent_slot base))))))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (L4vRefX64.Spec.ArchDecode_A.decode_port_invocation label args (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap f l)))) (L4vRefX64.Spec.ArchDecode_A.decode_ioport_control_invocation label args cte cap (holListMap Prod.fst extra_caps)) (fun (x : Bool) => (fun (xa : (BitVec 64)) => (fun (xb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (xc : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (xd : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (xe : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchDecode_A.decode_page_invocation label args cte cap extra_caps))))))) (fun (x : (BitVec 64)) => (fun (xa : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchDecode_A.decode_page_table_invocation label args cte cap extra_caps))) (fun (x : (BitVec 64)) => (fun (xa : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchDecode_A.decode_page_directory_invocation label args cte cap extra_caps))) (fun (x : (BitVec 64)) => (fun (xa : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.ArchDecode_A.decode_pdpt_invocation label args cte cap extra_caps))) (fun (a : (BitVec 64)) => (fun (b : (Option (BitVec 64))) => ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) cap))))))) + +def arch_decode_irq_control_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (cps : (List L4vRefX64.Spec.Structures_A.cap)) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IRQIssueIRQHandlerIOAPIC)) (holIf (holConj (holLe (HolNumeral.ofNatVal (α := Nat) 7) (holSize args)) (holLe (HolOne.oneVal (α := Nat)) (holSize cps))) (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 6)) (fun (pre_irq : (BitVec 64)) => (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (index : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (depth : (BitVec 64)) => (holLet (holNth cps (HolZero.zeroVal (α := Nat))) (fun (cnode : L4vRefX64.Spec.Structures_A.cap) => (holLet (HolAdd.addVal ((holUcast (w := 8)) pre_irq) L4vRefX64.Spec.Platform.minUserIRQ) (fun (irqv : (BitVec 8)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 2)) (fun (ioapic : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 3)) (fun (pin : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 4)) (fun (level : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 5)) (fun (polarity : (BitVec 64)) => (holLet (HolAdd.addVal ((holUcast (w := 64)) irqv) L4vRefX64.Spec.MachineOps.irqIntOffset) (fun (vector : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt ((holUcast (w := 64)) (HolSub.subVal L4vRefX64.Spec.Platform.maxUserIRQ L4vRefX64.Spec.Platform.minUserIRQ)) pre_irq)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holUcast (w := 64)) (HolSub.subVal L4vRefX64.Spec.Platform.maxUserIRQ L4vRefX64.Spec.Platform.minUserIRQ))))) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.is_irq_active irqv)) (fun (irq_active : Bool) => (holBindE (holFunApp (holWhenE irq_active) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst)) (holKBind (holBindE (L4vRefX64.Spec.CSpace_A.lookup_target_slot cnode (L4vRefX64.Spec.Machine_A.data_to_cptr index) (holUnsigned depth)) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holBindE (L4vRefX64.Spec.CSpaceAcc_A.ensure_empty dest_slot) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_num_ioapics L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state))) (fun (numIOAPICs : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_ioapic_nirqs L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state))) (fun (ioapic_nirqs : ((BitVec 64) → (BitVec 8))) => (holBindE (holFunApp (holWhenE (holEq numIOAPICs (HolZero.zeroVal (α := (BitVec 64))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holWhenE (holLt (HolSub.subVal numIOAPICs (HolOne.oneVal (α := (BitVec 64)))) ioapic)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) (HolSub.subVal numIOAPICs (HolOne.oneVal (α := (BitVec 64))))))) (holKBind (holBindE (holFunApp (holWhenE (holLt ((holUcast (w := 64)) (HolSub.subVal (ioapic_nirqs ioapic) (HolOne.oneVal (α := (BitVec 8))))) pin)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holUcast (w := 64)) (HolSub.subVal (ioapic_nirqs ioapic) (HolOne.oneVal (α := (BitVec 8)))))))) (holKBind (holBindE (holFunApp (holWhenE (holLt (HolOne.oneVal (α := (BitVec 64))) level)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) (HolOne.oneVal (α := (BitVec 64)))))) (holKBind (holBindE (holFunApp (holWhenE (holLt (HolOne.oneVal (α := (BitVec 64))) polarity)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) (HolOne.oneVal (α := (BitVec 64)))))) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation.IssueIRQHandlerIOAPIC irqv dest_slot src_slot ioapic pin level polarity vector)))))))))))))))))))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.invocation_type label) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IRQIssueIRQHandlerMSI)) (holIf (holConj (holLe (HolNumeral.ofNatVal (α := Nat) 7) (holSize args)) (holLe (HolOne.oneVal (α := Nat)) (holSize cps))) (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 6)) (fun (pre_irq : (BitVec 64)) => (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (index : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (depth : (BitVec 64)) => (holLet (holNth cps (HolZero.zeroVal (α := Nat))) (fun (cnode : L4vRefX64.Spec.Structures_A.cap) => (holLet (HolAdd.addVal ((holUcast (w := 8)) pre_irq) L4vRefX64.Spec.Platform.minUserIRQ) (fun (irqv : (BitVec 8)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 2)) (fun (bus : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 3)) (fun (dev : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 4)) (fun (func : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 5)) (fun (handle : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt ((holUcast (w := 64)) (HolSub.subVal L4vRefX64.Spec.Platform.maxUserIRQ L4vRefX64.Spec.Platform.minUserIRQ)) pre_irq)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holUcast (w := 64)) (HolSub.subVal L4vRefX64.Spec.Platform.maxUserIRQ L4vRefX64.Spec.Platform.minUserIRQ))))) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.is_irq_active irqv)) (fun (irq_active : Bool) => (holBindE (holFunApp (holWhenE irq_active) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst)) (holKBind (holBindE (L4vRefX64.Spec.CSpace_A.lookup_target_slot cnode (L4vRefX64.Spec.Machine_A.data_to_cptr index) (holUnsigned depth)) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holBindE (L4vRefX64.Spec.CSpaceAcc_A.ensure_empty dest_slot) (holKBind (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.MachineOps.maxPCIBus bus)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) L4vRefX64.Spec.MachineOps.maxPCIBus))) (holKBind (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.MachineOps.maxPCIDev dev)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) L4vRefX64.Spec.MachineOps.maxPCIDev))) (holKBind (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.MachineOps.maxPCIFunc func)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) L4vRefX64.Spec.MachineOps.maxPCIFunc))) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation.IssueIRQHandlerMSI irqv dest_slot src_slot bus dev func handle)))))))))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) ((holThrowError (α := L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))))) + +def args_at_least {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Nat → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (n : Nat) => (fun (args : (List (BitVec 64))) => (holFunApp (holWhenE ((fun a b => holLt b a) n (List.length args))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)))) + +def decode_io_unmap_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cte : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.ArchInvocation_A.arch_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) + +def get_iovm_rights : ((Set L4vRefX64.Spec.CapRights_A.rights) → ((Set L4vRefX64.Spec.CapRights_A.rights) → (Set L4vRefX64.Spec.CapRights_A.rights))) := + (fun (cover : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (base : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holEq cover (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowRead (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (holIf (holMember L4vRefX64.Spec.CapRights_A.rights.AllowRead base) (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowRead (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))) (holIf (holMember L4vRefX64.Spec.CapRights_A.rights.AllowRead cover) (HolCompleteLattice.holSup (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowRead (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))) (holIf (holMember L4vRefX64.Spec.CapRights_A.rights.AllowWrite base) (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowWrite (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (holIf (holMember L4vRefX64.Spec.CapRights_A.rights.AllowWrite base) (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowWrite (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))))))) + +def page_base : ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.vmpage_size → (BitVec 64))) := + (fun (vaddr : (BitVec 64)) => (fun (vmsize : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holWordAnd vaddr (holWordNot ((holWordMask (w := 64)) (L4vRefX64.Spec.MachineTypes.pageBitsForSize vmsize)))))) + +def page_cap_set_vmmap_type : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (L4vRefX64.Spec.MachineTypes.vmmap_type → L4vRefX64.Spec.Arch_Structs_A.arch_cap)) := + (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (t : L4vRefX64.Spec.MachineTypes.vmmap_type) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (fun (dev : Bool) => (fun (p : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (map_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (pgsz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev p R t pgsz mapped_address))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) cap))) +end +end L4vRefX64.Spec.ArchDecode_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchFault_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchFault_A.lean new file mode 100644 index 000000000..9b69d2ee4 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchFault_A.lean @@ -0,0 +1,23 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchFault_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.Tcb_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchFault_A +open L4vRefX64.Prim +open Classical +noncomputable section +def handle_arch_fault_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Machine_A.arch_fault → ((BitVec 64) → ((BitVec 64) → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (vmf : L4vRefX64.Spec.Machine_A.arch_fault) => (fun (thread : (BitVec 64)) => (fun (x : (BitVec 64)) => (fun (y : (List (BitVec 64))) => (holReturn true))))) + +def make_arch_fault_msg {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Machine_A.arch_fault → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (List (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | (L4vRefX64.Spec.Machine_A.arch_fault.VMFault vptr archData), thread => (holBind (L4vRefX64.Spec.KHeap_A.as_user thread L4vRefX64.Spec.MachineOps.getRestartPC) (fun (pc : (BitVec 64)) => (holReturn (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 5) (List.cons pc (List.cons vptr archData)))))) +end +end L4vRefX64.Spec.ArchFault_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInterrupt_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInterrupt_A.lean new file mode 100644 index 000000000..fa8de707e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInterrupt_A.lean @@ -0,0 +1,30 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchInterrupt_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.Ipc_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchInterrupt_A +open L4vRefX64.Prim +open Classical +noncomputable section +def arch_invoke_irq_handler {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.irq_handler_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.ACKIrq irq) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.maskInterrupt false irq)) + | (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.SetIRQHandler v va vb) => (holReturn ()) + | (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.ClearIRQHandler v) => (holReturn ()) + +def arch_mask_irq_signal {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.maskInterrupt true irq))) + +def handle_reserved_irq {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (holReturn ())) + +def handle_spurious_irq {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holReturn ()) +end +end L4vRefX64.Spec.ArchInterrupt_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInvocationLabels_H.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInvocationLabels_H.lean new file mode 100644 index 000000000..fa64d8516 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInvocationLabels_H.lean @@ -0,0 +1,60 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.ArchInvocationLabels_H) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchInvocationLabels_H +open L4vRefX64.Prim +open Classical +noncomputable section +inductive arch_invocation_label where + | X64PDPTMap + | X64PDPTUnmap + | X64PageDirectoryMap + | X64PageDirectoryUnmap + | X64PageTableMap + | X64PageTableUnmap + | X64PageMap + | X64PageUnmap + | X64PageGetAddress + | X64ASIDControlMakePool + | X64ASIDPoolAssign + | X64IOPortControlIssue + | X64IOPortIn8 + | X64IOPortIn16 + | X64IOPortIn32 + | X64IOPortOut8 + | X64IOPortOut16 + | X64IOPortOut32 + | X64IRQIssueIRQHandlerIOAPIC + | X64IRQIssueIRQHandlerMSI +instance : Nonempty arch_invocation_label := ⟨arch_invocation_label.X64PDPTMap⟩ +def case_arch_invocation_label {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : r_ty) (f6 : r_ty) (f7 : r_ty) (f8 : r_ty) (f9 : r_ty) (f10 : r_ty) (f11 : r_ty) (f12 : r_ty) (f13 : r_ty) (f14 : r_ty) (f15 : r_ty) (f16 : r_ty) (f17 : r_ty) (f18 : r_ty) (f19 : r_ty) : arch_invocation_label → r_ty + | .X64PDPTMap => f0 + | .X64PDPTUnmap => f1 + | .X64PageDirectoryMap => f2 + | .X64PageDirectoryUnmap => f3 + | .X64PageTableMap => f4 + | .X64PageTableUnmap => f5 + | .X64PageMap => f6 + | .X64PageUnmap => f7 + | .X64PageGetAddress => f8 + | .X64ASIDControlMakePool => f9 + | .X64ASIDPoolAssign => f10 + | .X64IOPortControlIssue => f11 + | .X64IOPortIn8 => f12 + | .X64IOPortIn16 => f13 + | .X64IOPortIn32 => f14 + | .X64IOPortOut8 => f15 + | .X64IOPortOut16 => f16 + | .X64IOPortOut32 => f17 + | .X64IRQIssueIRQHandlerIOAPIC => f18 + | .X64IRQIssueIRQHandlerMSI => f19 + +def enum_arch_invocation_label : (List L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label) := + (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PDPTMap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PDPTUnmap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageDirectoryMap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageDirectoryUnmap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageTableMap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageTableUnmap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageMap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageUnmap (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64PageGetAddress (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64ASIDControlMakePool (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64ASIDPoolAssign (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortControlIssue (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortIn8 (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortIn16 (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortIn32 (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortOut8 (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortOut16 (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IOPortOut32 (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IRQIssueIRQHandlerIOAPIC (List.cons L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label.X64IRQIssueIRQHandlerMSI (List.nil (α := L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label)))))))))))))))))))))) + +instance : HolEnum L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label where enumList := L4vRefX64.Spec.ArchInvocationLabels_H.enum_arch_invocation_label +end +end L4vRefX64.Spec.ArchInvocationLabels_H diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInvocation_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInvocation_A.lean new file mode 100644 index 000000000..c63b197f0 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchInvocation_A.lean @@ -0,0 +1,145 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchInvocation_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchInvocation_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive arch_copy_register_sets where + | X64NoExtraRegisters +instance : Nonempty arch_copy_register_sets := ⟨arch_copy_register_sets.X64NoExtraRegisters⟩ +def case_arch_copy_register_sets {r_ty : Type} (f0 : r_ty) : arch_copy_register_sets → r_ty + | .X64NoExtraRegisters => f0 + +inductive asid_control_invocation where + | MakePool (a0 : (BitVec 64)) (a1 : ((BitVec 64) × (List Bool))) (a2 : ((BitVec 64) × (List Bool))) (a3 : (BitVec 64)) +instance : Nonempty asid_control_invocation := ⟨asid_control_invocation.MakePool holUndefined holUndefined holUndefined holUndefined⟩ +def case_asid_control_invocation {r_ty : Type} (f0 : (BitVec 64) → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → (BitVec 64) → r_ty) : asid_control_invocation → r_ty + | .MakePool x0 x1 x2 x3 => f0 x0 x1 x2 x3 + +inductive asid_pool_invocation where + | Assign (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : ((BitVec 64) × (List Bool))) +instance : Nonempty asid_pool_invocation := ⟨asid_pool_invocation.Assign holUndefined holUndefined holUndefined⟩ +def case_asid_pool_invocation {r_ty : Type} (f0 : (BitVec 64) → (BitVec 64) → ((BitVec 64) × (List Bool)) → r_ty) : asid_pool_invocation → r_ty + | .Assign x0 x1 x2 => f0 x0 x1 x2 + +inductive io_port_control_invocation where + | IOPortControlInvocation (a0 : (BitVec 16)) (a1 : (BitVec 16)) (a2 : ((BitVec 64) × (List Bool))) (a3 : ((BitVec 64) × (List Bool))) +instance : Nonempty io_port_control_invocation := ⟨io_port_control_invocation.IOPortControlInvocation holUndefined holUndefined holUndefined holUndefined⟩ +def case_io_port_control_invocation {r_ty : Type} (f0 : (BitVec 16) → (BitVec 16) → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → r_ty) : io_port_control_invocation → r_ty + | .IOPortControlInvocation x0 x1 x2 x3 => f0 x0 x1 x2 x3 + +inductive io_port_invocation_data where + | IOPortIn8 + | IOPortIn16 + | IOPortIn32 + | IOPortOut8 (a0 : (BitVec 8)) + | IOPortOut16 (a0 : (BitVec 16)) + | IOPortOut32 (a0 : (BitVec 32)) +instance : Nonempty io_port_invocation_data := ⟨io_port_invocation_data.IOPortIn8⟩ +def case_io_port_invocation_data {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : (BitVec 8) → r_ty) (f4 : (BitVec 16) → r_ty) (f5 : (BitVec 32) → r_ty) : io_port_invocation_data → r_ty + | .IOPortIn8 => f0 + | .IOPortIn16 => f1 + | .IOPortIn32 => f2 + | .IOPortOut8 x0 => f3 x0 + | .IOPortOut16 x0 => f4 x0 + | .IOPortOut32 x0 => f5 x0 + +inductive io_port_invocation where + | IOPortInvocation (a0 : (BitVec 16)) (a1 : L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data) +instance : Nonempty io_port_invocation := ⟨io_port_invocation.IOPortInvocation holUndefined holUndefined⟩ +def case_io_port_invocation {r_ty : Type} (f0 : (BitVec 16) → L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data → r_ty) : io_port_invocation → r_ty + | .IOPortInvocation x0 x1 => f0 x0 x1 + +inductive page_directory_invocation where + | PageDirectoryMap (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) (a2 : L4vRefX64.Spec.Arch_Structs_A.pdpte) (a3 : (BitVec 64)) (a4 : (BitVec 64)) + | PageDirectoryUnmap (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) +instance : Nonempty page_directory_invocation := ⟨page_directory_invocation.PageDirectoryMap holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +def case_page_directory_invocation {r_ty : Type} (f0 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → L4vRefX64.Spec.Arch_Structs_A.pdpte → (BitVec 64) → (BitVec 64) → r_ty) (f1 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → r_ty) : page_directory_invocation → r_ty + | .PageDirectoryMap x0 x1 x2 x3 x4 => f0 x0 x1 x2 x3 x4 + | .PageDirectoryUnmap x0 x1 => f1 x0 x1 + +inductive page_invocation where + | PageMap (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) (a2 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) (a3 : (BitVec 64)) + | PageUnmap (a0 : L4vRefX64.Spec.Arch_Structs_A.arch_cap) (a1 : ((BitVec 64) × (List Bool))) + | PageGetAddr (a0 : (BitVec 64)) +instance : Nonempty page_invocation := ⟨page_invocation.PageMap holUndefined holUndefined holUndefined holUndefined⟩ +def case_page_invocation {r_ty : Type} (f0 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64)) → (BitVec 64) → r_ty) (f1 : L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((BitVec 64) × (List Bool)) → r_ty) (f2 : (BitVec 64) → r_ty) : page_invocation → r_ty + | .PageMap x0 x1 x2 x3 => f0 x0 x1 x2 x3 + | .PageUnmap x0 x1 => f1 x0 x1 + | .PageGetAddr x0 => f2 x0 + +inductive page_table_invocation where + | PageTableMap (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) (a2 : L4vRefX64.Spec.Arch_Structs_A.pde) (a3 : (BitVec 64)) (a4 : (BitVec 64)) + | PageTableUnmap (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) +instance : Nonempty page_table_invocation := ⟨page_table_invocation.PageTableMap holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +def case_page_table_invocation {r_ty : Type} (f0 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → L4vRefX64.Spec.Arch_Structs_A.pde → (BitVec 64) → (BitVec 64) → r_ty) (f1 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → r_ty) : page_table_invocation → r_ty + | .PageTableMap x0 x1 x2 x3 x4 => f0 x0 x1 x2 x3 x4 + | .PageTableUnmap x0 x1 => f1 x0 x1 + +inductive pdpt_invocation where + | PDPTMap (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) (a2 : L4vRefX64.Spec.Arch_Structs_A.pml4e) (a3 : (BitVec 64)) (a4 : (BitVec 64)) + | PDPTUnmap (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) +instance : Nonempty pdpt_invocation := ⟨pdpt_invocation.PDPTMap holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +def case_pdpt_invocation {r_ty : Type} (f0 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → L4vRefX64.Spec.Arch_Structs_A.pml4e → (BitVec 64) → (BitVec 64) → r_ty) (f1 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → r_ty) : pdpt_invocation → r_ty + | .PDPTMap x0 x1 x2 x3 x4 => f0 x0 x1 x2 x3 x4 + | .PDPTUnmap x0 x1 => f1 x0 x1 + +inductive arch_invocation where + | InvokePageTable (a0 : L4vRefX64.Spec.ArchInvocation_A.page_table_invocation) + | InvokePageDirectory (a0 : L4vRefX64.Spec.ArchInvocation_A.page_directory_invocation) + | InvokePDPT (a0 : L4vRefX64.Spec.ArchInvocation_A.pdpt_invocation) + | InvokePage (a0 : L4vRefX64.Spec.ArchInvocation_A.page_invocation) + | InvokeASIDControl (a0 : L4vRefX64.Spec.ArchInvocation_A.asid_control_invocation) + | InvokeASIDPool (a0 : L4vRefX64.Spec.ArchInvocation_A.asid_pool_invocation) + | InvokeIOPort (a0 : L4vRefX64.Spec.ArchInvocation_A.io_port_invocation) + | InvokeIOPortControl (a0 : L4vRefX64.Spec.ArchInvocation_A.io_port_control_invocation) +instance : Nonempty arch_invocation := ⟨arch_invocation.InvokePageTable holUndefined⟩ +def case_arch_invocation {r_ty : Type} (f0 : L4vRefX64.Spec.ArchInvocation_A.page_table_invocation → r_ty) (f1 : L4vRefX64.Spec.ArchInvocation_A.page_directory_invocation → r_ty) (f2 : L4vRefX64.Spec.ArchInvocation_A.pdpt_invocation → r_ty) (f3 : L4vRefX64.Spec.ArchInvocation_A.page_invocation → r_ty) (f4 : L4vRefX64.Spec.ArchInvocation_A.asid_control_invocation → r_ty) (f5 : L4vRefX64.Spec.ArchInvocation_A.asid_pool_invocation → r_ty) (f6 : L4vRefX64.Spec.ArchInvocation_A.io_port_invocation → r_ty) (f7 : L4vRefX64.Spec.ArchInvocation_A.io_port_control_invocation → r_ty) : arch_invocation → r_ty + | .InvokePageTable x0 => f0 x0 + | .InvokePageDirectory x0 => f1 x0 + | .InvokePDPT x0 => f2 x0 + | .InvokePage x0 => f3 x0 + | .InvokeASIDControl x0 => f4 x0 + | .InvokeASIDPool x0 => f5 x0 + | .InvokeIOPort x0 => f6 x0 + | .InvokeIOPortControl x0 => f7 x0 + +inductive arch_irq_control_invocation where + | IssueIRQHandlerIOAPIC (a0 : (BitVec 8)) (a1 : ((BitVec 64) × (List Bool))) (a2 : ((BitVec 64) × (List Bool))) (a3 : (BitVec 64)) (a4 : (BitVec 64)) (a5 : (BitVec 64)) (a6 : (BitVec 64)) (a7 : (BitVec 64)) + | IssueIRQHandlerMSI (a0 : (BitVec 8)) (a1 : ((BitVec 64) × (List Bool))) (a2 : ((BitVec 64) × (List Bool))) (a3 : (BitVec 64)) (a4 : (BitVec 64)) (a5 : (BitVec 64)) (a6 : (BitVec 64)) +instance : Nonempty arch_irq_control_invocation := ⟨arch_irq_control_invocation.IssueIRQHandlerIOAPIC holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +def case_arch_irq_control_invocation {r_ty : Type} (f0 : (BitVec 8) → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → (BitVec 64) → (BitVec 64) → (BitVec 64) → (BitVec 64) → (BitVec 64) → r_ty) (f1 : (BitVec 8) → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → (BitVec 64) → (BitVec 64) → (BitVec 64) → (BitVec 64) → r_ty) : arch_irq_control_invocation → r_ty + | .IssueIRQHandlerIOAPIC x0 x1 x2 x3 x4 x5 x6 x7 => f0 x0 x1 x2 x3 x4 x5 x6 x7 + | .IssueIRQHandlerMSI x0 x1 x2 x3 x4 x5 x6 => f1 x0 x1 x2 x3 x4 x5 x6 + +def ArchDefaultExtraRegisters : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets := + L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets.X64NoExtraRegisters + +def page_invocation.page_get_paddr : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → (BitVec 64)) + | page_invocation => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (uu : L4vRefX64.Spec.Structures_A.cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := (BitVec 64))))))) (fun (uu : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (holUndefined (α := (BitVec 64))))) (fun (x3 : (BitVec 64)) => x3) page_invocation) + +def page_invocation.page_map_cap : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → L4vRefX64.Spec.Structures_A.cap) + | page_invocation => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (x11 : L4vRefX64.Spec.Structures_A.cap) => (fun (x12 : ((BitVec 64) × (List Bool))) => (fun (x13 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (x14 : (BitVec 64)) => x11)))) (fun (uu : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (holUndefined (α := L4vRefX64.Spec.Structures_A.cap)))) (fun (uu : (BitVec 64)) => (holUndefined (α := L4vRefX64.Spec.Structures_A.cap))) page_invocation) + +def page_invocation.page_map_ct_slot : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → ((BitVec 64) × (List Bool))) + | page_invocation => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (x11 : L4vRefX64.Spec.Structures_A.cap) => (fun (x12 : ((BitVec 64) × (List Bool))) => (fun (x13 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (x14 : (BitVec 64)) => x12)))) (fun (uu : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (holUndefined (α := ((BitVec 64) × (List Bool)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := ((BitVec 64) × (List Bool))))) page_invocation) + +def page_invocation.page_map_entries : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) + | page_invocation => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (x11 : L4vRefX64.Spec.Structures_A.cap) => (fun (x12 : ((BitVec 64) × (List Bool))) => (fun (x13 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (x14 : (BitVec 64)) => x13)))) (fun (uu : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (holUndefined (α := (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))))) page_invocation) + +def page_invocation.page_map_vspace : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → (BitVec 64)) + | page_invocation => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (x11 : L4vRefX64.Spec.Structures_A.cap) => (fun (x12 : ((BitVec 64) × (List Bool))) => (fun (x13 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (x14 : (BitVec 64)) => x14)))) (fun (uu : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (BitVec 64)))) page_invocation) + +def page_invocation.page_unmap_cap : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → L4vRefX64.Spec.Arch_Structs_A.arch_cap) + | page_invocation => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (uu : L4vRefX64.Spec.Structures_A.cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))))) (fun (x21 : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (x22 : ((BitVec 64) × (List Bool))) => x21)) (fun (uu : (BitVec 64)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap))) page_invocation) + +def page_invocation.page_unmap_cap_slot : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → ((BitVec 64) × (List Bool))) + | page_invocation => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (uu : L4vRefX64.Spec.Structures_A.cap) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := ((BitVec 64) × (List Bool)))))))) (fun (x21 : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (x22 : ((BitVec 64) × (List Bool))) => x22)) (fun (uu : (BitVec 64)) => (holUndefined (α := ((BitVec 64) × (List Bool))))) page_invocation) +end +end L4vRefX64.Spec.ArchInvocation_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchIpcCancel_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchIpcCancel_A.lean new file mode 100644 index 000000000..4ec603d0c --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchIpcCancel_A.lean @@ -0,0 +1,38 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchIpcCancel_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Sporadic_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchIpcCancel_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive arch_gen_obj_ref where + | IOPortRef (a0 : (BitVec 16)) +instance : Nonempty arch_gen_obj_ref := ⟨arch_gen_obj_ref.IOPortRef holUndefined⟩ +def case_arch_gen_obj_ref {r_ty : Type} (f0 : (BitVec 16) → r_ty) : arch_gen_obj_ref → r_ty + | .IOPortRef x0 => f0 x0 + +def arch_cap_cleanup_opt : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → L4vRefX64.Spec.Structures_A.cap) := + (fun (ac : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => L4vRefX64.Spec.Structures_A.cap.NullCap)) L4vRefX64.Spec.Structures_A.cap.NullCap (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap f l)))) L4vRefX64.Spec.Structures_A.cap.NullCap (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => L4vRefX64.Spec.Structures_A.cap.NullCap)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => L4vRefX64.Spec.Structures_A.cap.NullCap)) ac)) + +def arch_gen_obj_refs : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref)) := + (fun (ac : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))) (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (holImage L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref.IOPortRef (holInsert f (HolCompleteLattice.holBot (α := (Set (BitVec 16)))))))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref))))) ac)) + +def set_ioport_mask {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 16) → ((BitVec 16) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (fun (val : Bool) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_allocated_io_ports L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (allocated_ports : ((BitVec 16) → Bool)) => (holBind (holReturn (fun (p : (BitVec 16)) => (holIf (holConj (holLe f p) (holLe p l)) val (allocated_ports p)))) (fun (ap_p : ((BitVec 16) → Bool)) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.arch_state_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_state.x64_allocated_io_ports_update (fun (uu__1 : ((BitVec 16) → Bool)) => ap_p) (L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state s))) s)))))))))) + +def free_ioport_range {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 16) → ((BitVec 16) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (L4vRefX64.Spec.ArchIpcCancel_A.set_ioport_mask f l false))) + +def arch_post_cap_deletion {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ac : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holReturn ()))) (holReturn ()) (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (L4vRefX64.Spec.ArchIpcCancel_A.free_ioport_range f l))) (holReturn ()) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holReturn ()))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holReturn ()))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holReturn ()))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holReturn ()))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holReturn ()))) ac)) +end +end L4vRefX64.Spec.ArchIpcCancel_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchRetype_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchRetype_A.lean new file mode 100644 index 000000000..e66516f63 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchRetype_A.lean @@ -0,0 +1,33 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchRetype_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchInvocation_A +import L4vRefX64.Spec.ArchVSpaceAcc_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchRetype_A +open L4vRefX64.Prim +open Classical +noncomputable section +def arch_post_reset_untyped {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (is_device : Bool) => (fun (sz : Nat) => (holReturn ()))) + +def empty_context : L4vRefX64.Spec.MachineOps.user_context := + (L4vRefX64.Spec.MachineOps.user_context.UserContext (fun (uu_ : (Fin 576)) => (HolZero.zeroVal (α := (BitVec 8)))) (fun (uu_ : L4vRefX64.Spec.MachineTypes.register) => (HolZero.zeroVal (α := (BitVec 64))))) + +def init_arch_objects {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.apiobject_type → (Bool → ((BitVec 64) → (Nat → (Nat → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) := + (fun (new_type : L4vRefX64.Spec.Structures_A.apiobject_type) => (fun (is_device : Bool) => (fun (ptr : (BitVec 64)) => (fun (num_objects : Nat) => (fun (obj_sz : Nat) => (fun (refs : (List (BitVec 64))) => (holWhen (holEq new_type (L4vRefX64.Spec.Structures_A.apiobject_type.ArchObject L4vRefX64.Spec.Arch_Structs_A.aobject_type.PML4Obj)) (holMapMx L4vRefX64.Spec.ArchVSpaceAcc_A.copy_global_mappings refs)))))))) + +def init_arch_tcb : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) := + (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext.mk L4vRefX64.Spec.ArchRetype_A.empty_context false ()) + +def reserve_region {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Nat → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (ptr : (BitVec 64)) => (fun (byteLength : Nat) => (fun (is_kernel : Bool) => (holReturn ())))) +end +end L4vRefX64.Spec.ArchRetype_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchTcb_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchTcb_A.lean new file mode 100644 index 000000000..49ae681cf --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchTcb_A.lean @@ -0,0 +1,39 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchTcb_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.FPU_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchTcb_A +open L4vRefX64.Prim +open Classical +noncomputable section +def arch_get_sanitise_register_info {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (t : (BitVec 64)) => (holReturn false)) + +def arch_post_modify_registers {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)))) := + (fun (cur : (BitVec 64)) => (fun (t : (BitVec 64)) => (holFunApp (holWhen (holNot (holEq t cur))) (holFunApp (L4vRefX64.Spec.KHeap_A.as_user t) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.MachineTypes.register.ErrorRegister (HolZero.zeroVal (α := (BitVec 64)))))))) + +def arch_post_set_flags {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((BitVec 64) → ((Set L4vRefX64.Spec.Structs_B.tcb_flag) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)))) := + (fun (t : (BitVec 64)) => (fun (flags : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holIf (holMember L4vRefX64.Spec.Structs_B.tcb_flag.FpuDisabled flags) (L4vRefX64.Spec.FPU_A.fpu_release t) (holWhen (holEq t cur) (L4vRefX64.Spec.FPU_A.lazy_fpu_restore t))))))) + +def arch_prepare_set_domain {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((BitVec 64) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)))) := + (fun (t : (BitVec 64)) => (fun (new_dom : (BitVec 8)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_domain) (fun (cur_domain : (BitVec 8)) => (holFunApp (holWhen (holNot (holEq cur_domain new_dom))) (L4vRefX64.Spec.FPU_A.fpu_release t)))))) + +def sanitise_and_flags : (BitVec 64) := + (holWordAnd ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 12)) (holWordAnd (holWordNot ((holHaskellBit (w := 64)) (HolNumeral.ofNatVal (α := Nat) 8))) (holWordAnd (holWordNot ((holHaskellBit (w := 64)) (HolNumeral.ofNatVal (α := Nat) 3))) (holWordNot ((holHaskellBit (w := 64)) (HolNumeral.ofNatVal (α := Nat) 5)))))) + +def sanitise_or_flags : (BitVec 64) := + (holWordOr ((holHaskellBit (w := 64)) (HolOne.oneVal (α := Nat))) ((holHaskellBit (w := 64)) (HolNumeral.ofNatVal (α := Nat) 9))) + +def sanitise_register : (Bool → (L4vRefX64.Spec.MachineTypes.register → ((BitVec 64) → (BitVec 64)))) := + (fun (t : Bool) => (fun (r : L4vRefX64.Spec.MachineTypes.register) => (fun (v : (BitVec 64)) => (holLet (holIf (holDisj (holEq r L4vRefX64.Spec.MachineTypes.register.FaultIP) (holDisj (holEq r L4vRefX64.Spec.MachineTypes.register.NextIP) (holDisj (holEq r L4vRefX64.Spec.MachineTypes.register.FS_BASE) (holEq r L4vRefX64.Spec.MachineTypes.register.GS_BASE)))) (holIf (holConj (holLt (HolNumeral.ofNatVal (α := (BitVec 64)) 140737488355327) v) (holLt v (HolNumeral.ofNatVal (α := (BitVec 64)) 18446603336221196288))) (HolZero.zeroVal (α := (BitVec 64))) v) v) (fun (val : (BitVec 64)) => (holIf (holEq r L4vRefX64.Spec.MachineTypes.register.FLAGS) (holWordAnd (holWordOr val L4vRefX64.Spec.ArchTcb_A.sanitise_or_flags) L4vRefX64.Spec.ArchTcb_A.sanitise_and_flags) val)))))) +end +end L4vRefX64.Spec.ArchTcb_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVMAttributes_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVMAttributes_A.lean new file mode 100644 index 000000000..ff4629836 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVMAttributes_A.lean @@ -0,0 +1,41 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchVMAttributes_A) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchVMAttributes_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive table_attr where + | Accessed + | CacheDisabled + | WriteThrough + | ExecuteDisable +instance : Nonempty table_attr := ⟨table_attr.Accessed⟩ +def case_table_attr {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) : table_attr → r_ty + | .Accessed => f0 + | .CacheDisabled => f1 + | .WriteThrough => f2 + | .ExecuteDisable => f3 + +inductive vm_attribute where + | PTAttr (a0 : L4vRefX64.Spec.ArchVMAttributes_A.table_attr) + | Global + | PAT + | Dirty +instance : Nonempty vm_attribute := ⟨vm_attribute.PTAttr holUndefined⟩ +def case_vm_attribute {r_ty : Type} (f0 : L4vRefX64.Spec.ArchVMAttributes_A.table_attr → r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) : vm_attribute → r_ty + | .PTAttr x0 => f0 x0 + | .Global => f1 + | .PAT => f2 + | .Dirty => f3 + +def attribs_from_word : ((BitVec 64) → (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) := + (fun (w : (BitVec 64)) => (holLet (holIf (holWordBit w (HolZero.zeroVal (α := Nat))) (holInsert (L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PTAttr L4vRefX64.Spec.ArchVMAttributes_A.table_attr.WriteThrough) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)))) (fun (V : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (holLet (holIf (holWordBit w (HolOne.oneVal (α := Nat))) (holInsert (L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PTAttr L4vRefX64.Spec.ArchVMAttributes_A.table_attr.CacheDisabled) V) V) (fun (V_p : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (holIf (holWordBit w (HolNumeral.ofNatVal (α := Nat) 2)) (holInsert L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PAT V_p) V_p)))))) + +def attribs_to_word : ((Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) → (BitVec 64)) := + (fun (attribs : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (holLet (holIf (holMember (L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PTAttr L4vRefX64.Spec.ArchVMAttributes_A.table_attr.WriteThrough) attribs) (HolOne.oneVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64)))) (fun (V : (BitVec 64)) => (holLet (holIf (holMember (L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PTAttr L4vRefX64.Spec.ArchVMAttributes_A.table_attr.CacheDisabled) attribs) (HolAdd.addVal V (HolNumeral.ofNatVal (α := (BitVec 64)) 2)) V) (fun (V_p : (BitVec 64)) => (holIf (holMember L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PAT attribs) (HolAdd.addVal V_p (HolNumeral.ofNatVal (α := (BitVec 64)) 4)) V_p)))))) +end +end L4vRefX64.Spec.ArchVMAttributes_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVSpaceAcc_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVSpaceAcc_A.lean new file mode 100644 index 000000000..df9882a24 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVSpaceAcc_A.lean @@ -0,0 +1,122 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchVSpaceAcc_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchVMAttributes_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.MiscMachine_A +import L4vRefX64.Spec.Platform +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchVSpaceAcc_A +open L4vRefX64.Prim +open Classical +noncomputable section +def aobjs_of {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holOptMap (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s) L4vRefX64.Spec.Structures_A.aobj_of)) + +def asid_high_bits_of : ((BitVec 64) → (BitVec 3)) := + (fun (asid : (BitVec 64)) => ((holUcast (w := 3)) (holWordShiftr asid L4vRefX64.Spec.MiscMachine_A.asid_low_bits))) + +def asid_low_bits_of : ((BitVec 64) → (BitVec 9)) := + (fun (asid : (BitVec 64)) => ((holUcast (w := 9)) asid)) + +def get_pml4_index : ((BitVec 64) → (BitVec 64)) := + (fun (vptr : (BitVec 64)) => (holWordAnd (holWordShiftr vptr L4vRefX64.Spec.Arch_Structs_A.pml4_shift_bits) ((holWordMask (w := 64)) L4vRefX64.Spec.MachineTypes.ptTranslationBits))) + +def get_pml4 {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_kernel_obj (fun (v_fun : ((BitVec 9) → (Option (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (holReturn pt)) (fun (bool : Bool) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_kernel_obj)) kobj)))) + +def get_pml4e {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Arch_Structs_A.pml4e × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (holReturn (holWordAnd ptr (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pml4_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd ptr ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pml4_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4 base) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (holFunApp holReturn (pt ((holUcast (w := 9)) offset)))))))))) + +def set_pml4 {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (L4vRefX64.Spec.KHeap_A.set_object ptr (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageMapL4 pt))))) + +def store_pml4e {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Arch_Structs_A.pml4e → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (p : (BitVec 64)) => (fun (pte : L4vRefX64.Spec.Arch_Structs_A.pml4e) => (holBind (holReturn (holWordAnd p (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pml4_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd p ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pml4_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4 base) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (holBind (holFunApp holReturn (holFunUpd pt ((holUcast (w := 9)) offset) pte)) (fun (pt_p : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (L4vRefX64.Spec.ArchVSpaceAcc_A.set_pml4 base pt_p))))))))))) + +def copy_global_mappings {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (new_pm : (BitVec 64)) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_global_pml4 L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (global_pm : (BitVec 64)) => (holBind (holFunApp holReturn (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4_index L4vRefX64.Spec.Machine_A.pptr_base)) (fun (base : (BitVec 64)) => (holBind (holReturn (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)) (fun (pme_bits : Nat) => (holBind (holReturn (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) L4vRefX64.Spec.MachineTypes.ptTranslationBits)) (fun (pm_size : (BitVec 64)) => (holMapMx (fun (index : (BitVec 64)) => (holBind (holReturn (holWordShiftl index pme_bits)) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4e (HolAdd.addVal global_pm offset)) (fun (pme : L4vRefX64.Spec.Arch_Structs_A.pml4e) => (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pml4e (HolAdd.addVal new_pm offset) pme)))))) (holUptoEnum base (HolSub.subVal pm_size (HolOne.oneVal (α := (BitVec 64))))))))))))))) + +def get_asid_pool {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_kernel_obj (fun (pool : ((BitVec 9) → (Option (BitVec 64)))) => (holReturn pool)) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (bool : Bool) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → (Option (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_kernel_obj)) kobj)))) + +def get_pd {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_kernel_obj (fun (v_fun : ((BitVec 9) → (Option (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (pd : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (holReturn pd)) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (bool : Bool) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_kernel_obj)) kobj)))) + +def get_pd_index : ((BitVec 64) → (BitVec 64)) := + (fun (vptr : (BitVec 64)) => (holWordAnd (holWordShiftr vptr L4vRefX64.Spec.Arch_Structs_A.pd_shift_bits) ((holWordMask (w := 64)) L4vRefX64.Spec.MachineTypes.ptTranslationBits))) + +def get_pde {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Arch_Structs_A.pde × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (holReturn (holWordAnd ptr (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pd_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd ptr ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pd_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pd base) (fun (pd : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (holFunApp holReturn (pd ((holUcast (w := 9)) offset)))))))))) + +def get_pdpt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_kernel_obj (fun (v_fun : ((BitVec 9) → (Option (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (holReturn pt)) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (bool : Bool) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_kernel_obj)) kobj)))) + +def get_pdpt_index : ((BitVec 64) → (BitVec 64)) := + (fun (vptr : (BitVec 64)) => (holWordAnd (holWordShiftr vptr L4vRefX64.Spec.Arch_Structs_A.pdpt_shift_bits) ((holWordMask (w := 64)) L4vRefX64.Spec.MachineTypes.ptTranslationBits))) + +def get_pdpte {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Arch_Structs_A.pdpte × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (holReturn (holWordAnd ptr (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pdpt_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd ptr ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pdpt_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpt base) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (holFunApp holReturn (pt ((holUcast (w := 9)) offset)))))))))) + +def get_pt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_kernel_obj (fun (v_fun : ((BitVec 9) → (Option (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (holReturn pt)) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (v_fun : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (bool : Bool) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_kernel_obj)) kobj)))) + +def get_pt_index : ((BitVec 64) → (BitVec 64)) := + (fun (vptr : (BitVec 64)) => (holWordAnd (holWordShiftr vptr L4vRefX64.Spec.Arch_Structs_A.pt_shift_bits) ((holWordMask (w := 64)) L4vRefX64.Spec.MachineTypes.ptTranslationBits))) + +def get_pte {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Arch_Structs_A.pte × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (holReturn (holWordAnd ptr (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pt_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd ptr ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pt_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pt base) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (holFunApp holReturn (pt ((holUcast (w := 9)) offset)))))))))) + +def lookup_pml4_slot : ((BitVec 64) → ((BitVec 64) → (BitVec 64))) := + (fun (pm : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (holLet (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4_index vptr) (fun (pm_index : (BitVec 64)) => (HolAdd.addVal pm (holWordShiftl pm_index (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))))))) + +def lookup_pdpt_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (pd : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pml4_slot pd vptr)) (fun (pml4_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4e pml4_slot)) (fun (pml4e : L4vRefX64.Spec.Arch_Structs_A.pml4e) => (L4vRefX64.Spec.Arch_Structs_A.case_pml4e (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability L4vRefX64.Spec.Arch_Structs_A.pml4_shift_bits)) (fun (tab : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.Platform.ptrFromPAddr tab)) (fun (pd_1 : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpt_index vptr)) (fun (pd_index : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (HolAdd.addVal pd_1 (holWordShiftl pd_index (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)))) (fun (pd_slot : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) pd_slot)))))))))) pml4e))))))) + +def lookup_pd_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (pd : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (holBindE (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pdpt_slot pd vptr) (fun (pdpt_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpte pdpt_slot)) (fun (pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (L4vRefX64.Spec.Arch_Structs_A.case_pdpte (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability L4vRefX64.Spec.Arch_Structs_A.pdpt_shift_bits)) (fun (tab : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.Platform.ptrFromPAddr tab)) (fun (pd_1 : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pd_index vptr)) (fun (pd_index : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (HolAdd.addVal pd_1 (holWordShiftl pd_index (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)))) (fun (pd_slot : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) pd_slot)))))))))) (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability L4vRefX64.Spec.Arch_Structs_A.pdpt_shift_bits))))) pdpte))))))) + +def lookup_pd_slot_no_fail : ((BitVec 64) → ((BitVec 64) → (BitVec 64))) := + (fun (pd : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (HolAdd.addVal pd (holWordShiftl (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pd_index vptr) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))))) + +def lookup_pdpt_slot_no_fail : ((BitVec 64) → ((BitVec 64) → (BitVec 64))) := + (fun (pdpt : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (HolAdd.addVal pdpt (holWordShiftl (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpt_index vptr) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))))) + +def lookup_pt_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (vspace : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (holBindE (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pd_slot vspace vptr) (fun (pd_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pde pd_slot)) (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (L4vRefX64.Spec.Arch_Structs_A.case_pde (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability L4vRefX64.Spec.Arch_Structs_A.pd_shift_bits)) (fun (ptab : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.Platform.ptrFromPAddr ptab)) (fun (pt : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pt_index vptr)) (fun (pt_index : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (HolAdd.addVal pt (holWordShiftl pt_index (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)))) (fun (pt_slot : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) pt_slot)))))))))) (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability L4vRefX64.Spec.Arch_Structs_A.pd_shift_bits))))) pde))))))) + +def lookup_pt_slot_no_fail : ((BitVec 64) → ((BitVec 64) → (BitVec 64))) := + (fun (pt : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (HolAdd.addVal pt (holWordShiftl (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pt_index vptr) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))))) + +def set_asid_pool {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 9) → (Option (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (pool : ((BitVec 9) → (Option (BitVec 64)))) => (L4vRefX64.Spec.KHeap_A.set_object ptr (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.ASIDPool pool))))) + +def set_pd {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (pd : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (L4vRefX64.Spec.KHeap_A.set_object ptr (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageDirectory pd))))) + +def set_pdpt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (L4vRefX64.Spec.KHeap_A.set_object ptr (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PDPointerTable pt))))) + +def set_pt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (L4vRefX64.Spec.KHeap_A.set_object ptr (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageTable pt))))) + +def store_pde {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Arch_Structs_A.pde → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (p : (BitVec 64)) => (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (holBind (holReturn (holWordAnd p (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pd_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd p ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pd_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pd base) (fun (pd : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (holBind (holFunApp holReturn (holFunUpd pd ((holUcast (w := 9)) offset) pde)) (fun (pd_p : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => (L4vRefX64.Spec.ArchVSpaceAcc_A.set_pd base pd_p))))))))))) + +def store_pdpte {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Arch_Structs_A.pdpte → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (p : (BitVec 64)) => (fun (pte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (holBind (holReturn (holWordAnd p (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pdpt_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd p ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pdpt_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpt base) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (holBind (holFunApp holReturn (holFunUpd pt ((holUcast (w := 9)) offset) pte)) (fun (pt_p : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => (L4vRefX64.Spec.ArchVSpaceAcc_A.set_pdpt base pt_p))))))))))) + +def store_pte {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Arch_Structs_A.pte → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (p : (BitVec 64)) => (fun (pte : L4vRefX64.Spec.Arch_Structs_A.pte) => (holBind (holReturn (holWordAnd p (holWordNot ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pt_bits)))) (fun (base : (BitVec 64)) => (holBind (holReturn (holWordShiftr (holWordAnd p ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pt_bits)) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) (fun (offset : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pt base) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (holBind (holFunApp holReturn (holFunUpd pt ((holUcast (w := 9)) offset) pte)) (fun (pt_p : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => (L4vRefX64.Spec.ArchVSpaceAcc_A.set_pt base pt_p))))))))))) +end +end L4vRefX64.Spec.ArchVSpaceAcc_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVSpace_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVSpace_A.lean new file mode 100644 index 000000000..a4ae76337 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ArchVSpace_A.lean @@ -0,0 +1,148 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ArchVSpace_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Aligned +import L4vRefX64.Spec.ArchVMAttributes_A +import L4vRefX64.Spec.ArchVSpaceAcc_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.FPU_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.MiscMachine_A +import L4vRefX64.Spec.Platform +import L4vRefX64.Spec.Retype_A +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.VMRights_A +set_option maxRecDepth 2048 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ArchVSpace_A +open L4vRefX64.Prim +open Classical +noncomputable section +def arch_derive_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Structures_A.cap) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (c : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (x : (BitVec 64)) => (fun (xa : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c)))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c)) (fun (x : (BitVec 16)) => (fun (xa : (BitVec 16)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c)))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.cap.NullCap) (fun (dev : Bool) => (fun (r : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (mt : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (pgs : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (x : (Option ((BitVec 64) × (BitVec 64)))) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev r R L4vRefX64.Spec.MachineTypes.vmmap_type.VMNoMap pgs (Option.none (α := ((BitVec 64) × (BitVec 64))))))))))))) (fun (xa : (BitVec 64)) => (fun (a : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption ((holThrowError (α := L4vRefX64.Spec.Structures_A.cap)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (x : ((BitVec 64) × (BitVec 64))) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c))) a))) (fun (xa : (BitVec 64)) => (fun (a : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption ((holThrowError (α := L4vRefX64.Spec.Structures_A.cap)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (x : ((BitVec 64) × (BitVec 64))) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c))) a))) (fun (xa : (BitVec 64)) => (fun (a : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption ((holThrowError (α := L4vRefX64.Spec.Structures_A.cap)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (x : ((BitVec 64) × (BitVec 64))) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c))) a))) (fun (xa : (BitVec 64)) => (fun (a : (Option (BitVec 64))) => (holCaseOption ((holThrowError (α := L4vRefX64.Spec.Structures_A.cap)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (x : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c))) a))) c)) + +def hw_asid_invalidate {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (asid : (BitVec 64)) => (fun (vspace : (BitVec 64)) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.invalidateASID vspace ((holUcast (w := 64)) asid))))) + +def find_vspace_for_asid {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (asid : (BitVec 64)) => (holBindE ((holAssertE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holLt (HolZero.zeroVal (α := (BitVec 64))) asid)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_asid_table L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state))) (fun (asid_table : ((BitVec 3) → (Option (BitVec 64)))) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (asid_table (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_high_bits_of asid))) (fun (pool_ptr : (Option (BitVec 64))) => (holBindE (holCaseOption ((holThrowError (α := ((BitVec 9) → (Option (BitVec 64))))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (ptr : (BitVec 64)) => (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_asid_pool ptr))) pool_ptr) (fun (pool : ((BitVec 9) → (Option (BitVec 64)))) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (pool (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_low_bits_of asid))) (fun (pml4 : (Option (BitVec 64))) => (holCaseOption ((holThrowError (α := (BitVec 64))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (ptr : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) ptr)) pml4)))))))))))) + +def get_current_cr3 {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Arch_Structs_A.cr3 × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_current_cr3 L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) + +def cr3_addr_mask {tv_a : Type} [Nonempty tv_a] [HolShiftMask tv_a] : tv_a := + (HolShiftMask.shiftLeft ((HolShiftMask.mask (α := tv_a)) L4vRefX64.Spec.Arch_Structs_A.pml4_shift_bits) L4vRefX64.Spec.MiscMachine_A.asid_bits) + +def make_cr3 : ((BitVec 64) → ((BitVec 64) → L4vRefX64.Spec.Arch_Structs_A.cr3)) := + (fun (vspace : (BitVec 64)) => (fun (asid : (BitVec 64)) => (L4vRefX64.Spec.Arch_Structs_A.cr3.mk (holWordAnd vspace L4vRefX64.Spec.ArchVSpace_A.cr3_addr_mask) asid))) + +def set_current_cr3 {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Arch_Structs_A.cr3 → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (c : L4vRefX64.Spec.Arch_Structs_A.cr3) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.arch_state_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_state.x64_current_cr3_update (fun (uu__1 : L4vRefX64.Spec.Arch_Structs_A.cr3) => c) (L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state s))) s)))) + +def set_current_vspace_root {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (vspace : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holFunApp L4vRefX64.Spec.ArchVSpace_A.set_current_cr3 (L4vRefX64.Spec.ArchVSpace_A.make_cr3 vspace asid)))) + +def set_vm_root {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb : (BitVec 64)) => (holBind (holReturn (Prod.mk tcb (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolOne.oneVal (α := Nat))))) (fun (thread_root_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap thread_root_slot) (fun (thread_root : L4vRefX64.Spec.Structures_A.cap) => (holCatch (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) (fun (word : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (word : (BitVec 8)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) (fun (pml4 : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holCaseOption ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (asid : (BitVec 64)) => (holBindE (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid) (fun (pml4_p : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holNot (holEq pml4 pml4_p))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) L4vRefX64.Spec.ArchVSpace_A.get_current_cr3) (fun (cur_cr3 : L4vRefX64.Spec.Arch_Structs_A.cr3) => (holFunApp (holWhenE (holNot (holEq cur_cr3 (L4vRefX64.Spec.ArchVSpace_A.make_cr3 (L4vRefX64.Spec.Platform.addrFromPPtr pml4) asid)))) (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holFunApp L4vRefX64.Spec.ArchVSpace_A.set_current_cr3 (L4vRefX64.Spec.ArchVSpace_A.make_cr3 (L4vRefX64.Spec.Platform.addrFromPPtr pml4) asid))))))))))) option))) arch_cap)) thread_root) (fun (uu_ : L4vRefX64.Spec.ExceptionTypes_A.lookup_failure) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_global_pml4 L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (global_pml4 : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.set_current_vspace_root (L4vRefX64.Spec.Platform.addrFromKPPtr global_pml4) (HolZero.zeroVal (α := (BitVec 64))))))))))))) + +def delete_asid {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (asid : (BitVec 64)) => (fun (pml4 : (BitVec 64)) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_asid_table L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (asid_table : ((BitVec 3) → (Option (BitVec 64)))) => (holCaseOption (holReturn ()) (fun (pool_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_asid_pool pool_ptr) (fun (pool : ((BitVec 9) → (Option (BitVec 64)))) => (holFunApp (holWhen (holEq (pool (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_low_bits_of asid)) (Option.some pml4))) (holBind (L4vRefX64.Spec.ArchVSpace_A.hw_asid_invalidate asid pml4) (holKBind (holBind (holReturn (holFunUpd pool (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_low_bits_of asid) (Option.none (α := (BitVec 64))))) (fun (pool_p : ((BitVec 9) → (Option (BitVec 64)))) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.set_asid_pool pool_ptr pool_p) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (tcb : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.set_vm_root tcb))))))))))))) (asid_table (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_high_bits_of asid))))))) + +def delete_asid_pool {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (base : (BitVec 64)) => (fun (ptr : (BitVec 64)) => (holBind (holAssert (holEq (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_low_bits_of base) (HolZero.zeroVal (α := (BitVec 9))))) (holKBind (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_asid_table L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (asid_table : ((BitVec 3) → (Option (BitVec 64)))) => (holFunApp (holWhen (holEq (asid_table (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_high_bits_of base)) (Option.some ptr))) (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_asid_pool ptr) (fun (pool : ((BitVec 9) → (Option (BitVec 64)))) => (holBind (holMapM (fun (offset : (BitVec 64)) => (holFunApp (holWhen (holNot (holEq (pool ((holUcast (w := 9)) offset)) (Option.none (α := (BitVec 64)))))) (L4vRefX64.Spec.ArchVSpace_A.hw_asid_invalidate (HolAdd.addVal base offset) (holTheOpt (pool ((holUcast (w := 9)) offset)))))) (holUptoEnum (HolZero.zeroVal (α := (BitVec 64))) (HolSub.subVal (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) L4vRefX64.Spec.MiscMachine_A.asid_low_bits) (HolOne.oneVal (α := (BitVec 64)))))) (holKBind (holBind (holReturn (holFunUpd asid_table (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_high_bits_of base) (Option.none (α := (BitVec 64))))) (fun (asid_table_p : ((BitVec 3) → (Option (BitVec 64)))) => (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.arch_state_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_state.x64_asid_table_update (fun (uu__1 : ((BitVec 3) → (Option (BitVec 64)))) => asid_table_p) (L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state s))) s))) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (tcb : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.set_vm_root tcb)))))))))))))))))) + +def check_mapping_pptr : ((BitVec 64) → (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry → Bool)) := + (fun (pptr : (BitVec 64)) => (fun (entry : L4vRefX64.Spec.Arch_Structs_A.vm_page_entry) => (L4vRefX64.Spec.Arch_Structs_A.case_vm_page_entry (fun (pte : L4vRefX64.Spec.Arch_Structs_A.pte) => (L4vRefX64.Spec.Arch_Structs_A.case_pte false (fun (base : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEq base (L4vRefX64.Spec.Platform.addrFromPPtr pptr))))) pte)) (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (L4vRefX64.Spec.Arch_Structs_A.case_pde false (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (base : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEq base (L4vRefX64.Spec.Platform.addrFromPPtr pptr))))) pde)) (fun (pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (L4vRefX64.Spec.Arch_Structs_A.case_pdpte false (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (base : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEq base (L4vRefX64.Spec.Platform.addrFromPPtr pptr))))) pdpte)) entry))) + +def unmap_page {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.MachineTypes.vmpage_size → ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (pgsz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (asid : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (fun (pptr : (BitVec 64)) => (holCatch (holBindE (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid) (fun (vspace : (BitVec 64)) => (holBindE (L4vRefX64.Spec.MachineTypes.case_vmpage_size (holBindE (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pt_slot vspace vptr) (fun (pt_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pte pt_slot)) (fun (pte : L4vRefX64.Spec.Arch_Structs_A.pte) => (holBindE (holFunApp (holUnlessE (L4vRefX64.Spec.ArchVSpace_A.check_mapping_pptr pptr (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPTE pte))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pte pt_slot L4vRefX64.Spec.Arch_Structs_A.pte.InvalidPTE)))))))) (holBindE (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pd_slot vspace vptr) (fun (pd_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pde pd_slot)) (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (holBindE (holFunApp (holUnlessE (L4vRefX64.Spec.ArchVSpace_A.check_mapping_pptr pptr (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDE pde))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pde pd_slot L4vRefX64.Spec.Arch_Structs_A.pde.InvalidPDE)))))))) (holBindE (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pdpt_slot vspace vptr) (fun (pdpt_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpte pdpt_slot)) (fun (pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (holBindE (holFunApp (holUnlessE (L4vRefX64.Spec.ArchVSpace_A.check_mapping_pptr pptr (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDPTE pdpte))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pdpte pdpt_slot L4vRefX64.Spec.Arch_Structs_A.pdpte.InvalidPDPTE)))))))) pgsz) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.invalidateTranslationSingleASID vptr ((holUcast (w := 64)) asid)))))))) (holFunApp holK (holReturn ()))))))) + +def flush_table {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (pml4_ref : (BitVec 64)) => (fun (vptr : (BitVec 64)) => (fun (pt_ref : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holBind (holAssert (holEq (holWordAnd vptr ((holWordMask (w := 64)) (HolAdd.addVal L4vRefX64.Spec.MachineTypes.ptTranslationBits L4vRefX64.Spec.MachineTypes.pageBits))) (HolZero.zeroVal (α := (BitVec 64))))) (holKBind (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pt pt_ref) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => ((fun xs f => holMapMx f xs) (holUptoEnum (HolZero.zeroVal (α := (BitVec 9))) (HolNeg.negVal (HolOne.oneVal (α := (BitVec 9))))) (fun (index : (BitVec 9)) => (holBind (holFunApp holReturn (pt index)) (fun (pte : L4vRefX64.Spec.Arch_Structs_A.pte) => (L4vRefX64.Spec.Arch_Structs_A.case_pte (holReturn ()) (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.invalidateTranslationSingleASID (HolAdd.addVal vptr (holWordShiftl ((holUcast (w := 64)) index) L4vRefX64.Spec.MachineTypes.pageBits)) ((holUcast (w := 64)) asid)))))) pte))))))))))))) + +def invalidate_page_structure_cache_asid {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (vspace : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.invalidateLocalPageStructureCacheASID vspace ((holUcast (w := 64)) asid))))) + +def unmap_page_table {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (asid : (BitVec 64)) => (fun (vaddr : (BitVec 64)) => (fun (pt : (BitVec 64)) => (holCatch (holBindE (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid) (fun (vspace : (BitVec 64)) => (holBindE (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pd_slot vspace vaddr) (fun (pd_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pde pd_slot)) (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (holBindE (L4vRefX64.Spec.Arch_Structs_A.case_pde ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (addr : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holEq (L4vRefX64.Spec.Platform.addrFromPPtr pt) addr) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) ()) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))))) (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) pde) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holBind (L4vRefX64.Spec.ArchVSpace_A.flush_table vspace vaddr pt asid) (holKBind (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pde pd_slot L4vRefX64.Spec.Arch_Structs_A.pde.InvalidPDE) (holKBind (L4vRefX64.Spec.ArchVSpace_A.invalidate_page_structure_cache_asid (L4vRefX64.Spec.Platform.addrFromPPtr vspace) asid)))))))))))))) (holFunApp holK (holReturn ())))))) + +def flush_all {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (vspace : (BitVec 64)) => (fun (asid : (BitVec 64)) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.invalidateASID vspace ((holUcast (w := 64)) asid))))) + +def unmap_pd {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (asid : (BitVec 64)) => (fun (vaddr : (BitVec 64)) => (fun (pd : (BitVec 64)) => (holCatch (holBindE (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid) (fun (vspace : (BitVec 64)) => (holBindE (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pdpt_slot vspace vaddr) (fun (pdpt_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpte pdpt_slot)) (fun (pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (holBindE (L4vRefX64.Spec.Arch_Structs_A.case_pdpte ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (pd_p : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holEq pd_p (L4vRefX64.Spec.Platform.addrFromPPtr pd)) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) ()) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))))) (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) pdpte) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holBind (L4vRefX64.Spec.ArchVSpace_A.flush_all vspace asid) (holKBind (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pdpte pdpt_slot L4vRefX64.Spec.Arch_Structs_A.pdpte.InvalidPDPTE) (holKBind (L4vRefX64.Spec.ArchVSpace_A.invalidate_page_structure_cache_asid (L4vRefX64.Spec.Platform.addrFromPPtr vspace) asid)))))))))))))) (holFunApp holK (holReturn ())))))) + +def unmap_pdpt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (asid : (BitVec 64)) => (fun (vaddr : (BitVec 64)) => (fun (pdpt : (BitVec 64)) => (holCatch (holBindE (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid) (fun (vspace : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pml4_slot vspace vaddr)) (fun (pm_slot : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4e pm_slot)) (fun (pml4e : L4vRefX64.Spec.Arch_Structs_A.pml4e) => (holBindE (L4vRefX64.Spec.Arch_Structs_A.case_pml4e ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (pt_p : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holEq pt_p (L4vRefX64.Spec.Platform.addrFromPPtr pdpt)) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) ()) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))))) pml4e) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holBind (L4vRefX64.Spec.ArchVSpace_A.flush_all vspace asid) (holKBind (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pml4e pm_slot L4vRefX64.Spec.Arch_Structs_A.pml4e.InvalidPML4E)))))))))))) (holFunApp holK (holReturn ())))))) + +def arch_finalise_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.cap × L4vRefX64.Spec.Structures_A.cap) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (c : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (x : Bool) => (holCaseProd (fun (aa : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (xc : Bool) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (ptr : (BitVec 64)) => (fun (b : (BitVec 64)) => (holCaseBool (holBind (L4vRefX64.Spec.ArchVSpace_A.delete_asid_pool b ptr) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) xc))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (holCaseBool (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap f l)))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) xc))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (x_1 : Bool) => (fun (ptr : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (xb : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (s : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (aa_1 : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (a : (BitVec 64)) => (fun (v : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpace_A.unmap_page s a v ptr) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)))))) aa_1)) option))))))) (fun (ptr : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (aa_1 : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (a : (BitVec 64)) => (fun (v : (BitVec 64)) => (holCaseBool (holBind (L4vRefX64.Spec.ArchVSpace_A.unmap_page_table a v ptr) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) xc))) aa_1)) option))) (fun (ptr : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (aa_1 : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (a : (BitVec 64)) => (fun (v : (BitVec 64)) => (holCaseBool (holBind (L4vRefX64.Spec.ArchVSpace_A.unmap_pd a v ptr) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) xc))) aa_1)) option))) (fun (ptr : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (aa_1 : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (a : (BitVec 64)) => (fun (v : (BitVec 64)) => (holCaseBool (holBind (L4vRefX64.Spec.ArchVSpace_A.unmap_pdpt a v ptr) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) xc))) aa_1)) option))) (fun (ptr : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holCaseOption (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (a : (BitVec 64)) => (holCaseBool (holBind (L4vRefX64.Spec.ArchVSpace_A.delete_asid a ptr) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) xc)) option))) aa))) (Prod.mk c x)))) + +def arch_update_cap_data : (Bool → ((BitVec 64) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → L4vRefX64.Spec.Structures_A.cap))) := + (fun (preserve : Bool) => (fun (data : (BitVec 64)) => (fun (c : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap c)))) + +def attr_mask : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) := + (holInsert L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.Global (holInsert L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.Dirty (holInsert (L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PTAttr L4vRefX64.Spec.ArchVMAttributes_A.table_attr.Accessed) (holInsert (L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PTAttr L4vRefX64.Spec.ArchVMAttributes_A.table_attr.ExecuteDisable) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute))))))) + +def attr_mask' : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) := + (HolCompleteLattice.holSup L4vRefX64.Spec.ArchVSpace_A.attr_mask (holInsert L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute.PAT (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute))))) + +def check_valid_ipc_buffer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (vptr : (BitVec 64)) => (fun (c : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 8)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (bool : Bool) => (fun (x : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (xb : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (xc : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (xd : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseBool ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holBindE (holFunApp (holWhenE (holNot (L4vRefX64.Spec.Aligned.is_aligned vptr L4vRefX64.Spec.Structures_A.msg_align_bits))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.AlignmentError)) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()))) bool))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) arch_cap)) c))) + +def create_mapping_entries {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.vmpage_size → ((Set L4vRefX64.Spec.CapRights_A.rights) → ((Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) + | base, vptr, L4vRefX64.Spec.MachineTypes.vmpage_size.X64SmallPage, vm_rights, attrib, pd => (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pt_slot pd vptr)) (fun (p : (BitVec 64)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPTE (L4vRefX64.Spec.Arch_Structs_A.pte.SmallPagePTE base (HolSub.subVal attrib L4vRefX64.Spec.ArchVSpace_A.attr_mask) vm_rights)) p)))) + | base, vptr, L4vRefX64.Spec.MachineTypes.vmpage_size.X64LargePage, vm_rights, attrib, pdpt => (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pd_slot pdpt vptr)) (fun (p : (BitVec 64)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDE (L4vRefX64.Spec.Arch_Structs_A.pde.LargePagePDE base (HolSub.subVal attrib L4vRefX64.Spec.ArchVSpace_A.attr_mask) vm_rights)) p)))) + | base, vptr, L4vRefX64.Spec.MachineTypes.vmpage_size.X64HugePage, vm_rights, attrib, pml4 => (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure false) (L4vRefX64.Spec.ArchVSpaceAcc_A.lookup_pdpt_slot pml4 vptr)) (fun (p : (BitVec 64)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDPTE (L4vRefX64.Spec.Arch_Structs_A.pdpte.HugePagePDPTE base (HolSub.subVal attrib L4vRefX64.Spec.ArchVSpace_A.attr_mask') vm_rights)) p)))) + +def ensure_safe_mapping {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPTE L4vRefX64.Spec.Arch_Structs_A.pte.InvalidPTE), uu) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDE L4vRefX64.Spec.Arch_Structs_A.pde.InvalidPDE), uv) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDPTE L4vRefX64.Spec.Arch_Structs_A.pdpte.InvalidPDPTE), uw) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPTE (L4vRefX64.Spec.Arch_Structs_A.pte.SmallPagePTE ux uy uz)), pt_slot) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDE (L4vRefX64.Spec.Arch_Structs_A.pde.LargePagePDE va vb vc)), pd_slot) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pde pd_slot)) (L4vRefX64.Spec.Arch_Structs_A.case_pde ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst)))) (fun (x : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (xb : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ())))))) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDPTE (L4vRefX64.Spec.Arch_Structs_A.pdpte.HugePagePDPTE vd ve vf)), pdpt_slot) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pdpte pdpt_slot)) (L4vRefX64.Spec.Arch_Structs_A.case_pdpte ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) (fun (word : (BitVec 64)) => (fun (set1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (set2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst)))) (fun (x : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (xb : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ())))))) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDE (L4vRefX64.Spec.Arch_Structs_A.pde.PageTablePDE vg vh vi)), vj) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | ((L4vRefX64.Spec.Arch_Structs_A.vm_page_entry.VMPDPTE (L4vRefX64.Spec.Arch_Structs_A.pdpte.PageDirectoryPDPTE vk vl vm)), vn) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + +def find_vspace_for_asid_assert {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (asid : (BitVec 64)) => (holBind (holCatch (L4vRefX64.Spec.ArchVSpace_A.find_vspace_for_asid asid) (holK (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (pml4 : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pml4 pml4) (holKBind (holReturn pml4)))))) + +def flush_pd {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + L4vRefX64.Spec.ArchVSpace_A.flush_all + +def flush_pdpt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + L4vRefX64.Spec.ArchVSpace_A.flush_all + +def getCurrentVSpaceRoot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind L4vRefX64.Spec.ArchVSpace_A.get_current_cr3 (fun (cur : L4vRefX64.Spec.Arch_Structs_A.cr3) => (holFunApp holReturn (L4vRefX64.Spec.Arch_Structs_A.cr3_base_address cur)))) + +def handle_vm_fault {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.vmfault_type → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.fault Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (fault_type : L4vRefX64.Spec.MachineTypes.vmfault_type) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.getFaultAddress)) (fun (addr : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (L4vRefX64.Spec.MachineOps.getRegister L4vRefX64.Spec.MachineTypes.register.ErrorRegister))) (fun (fault : (BitVec 64)) => (L4vRefX64.Spec.MachineTypes.case_vmfault_type (holFunApp (holThrowError (α := Unit)) (holFunApp L4vRefX64.Spec.ExceptionTypes_A.fault.ArchFault (L4vRefX64.Spec.Machine_A.arch_fault.VMFault addr (List.cons (HolZero.zeroVal (α := (BitVec 64))) (List.cons (holWordAnd fault ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 5))) (List.nil (α := (BitVec 64)))))))) (holFunApp (holThrowError (α := Unit)) (holFunApp L4vRefX64.Spec.ExceptionTypes_A.fault.ArchFault (L4vRefX64.Spec.Machine_A.arch_fault.VMFault addr (List.cons (HolOne.oneVal (α := (BitVec 64))) (List.cons (holWordAnd fault ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 5))) (List.nil (α := (BitVec 64)))))))) fault_type))))))) + +def in_user_frame {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → Bool)) := + (fun (p : (BitVec 64)) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (sz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holEq (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s (holWordAnd p (holWordNot ((holWordMask (w := 64)) (L4vRefX64.Spec.MachineTypes.pageBitsForSize sz))))) (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.DataPage false sz)))))))) + +def is_valid_vtable_root : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (c : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (r : (BitVec 64)) => (holEx (fun (a : (BitVec 64)) => (holEq c (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap r (Option.some a))))))))) + +def lookup_ipc_buffer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (is_receiver : Bool) => (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_ipc_buffer thread) (fun (buffer_ptr : (BitVec 64)) => (holBind (holReturn (Prod.mk thread (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 4)))) (fun (buffer_frame_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap buffer_frame_slot) (fun (buffer_cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holReturn (Option.none (α := (BitVec 64)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holReturn (Option.none (α := (BitVec 64)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn (Option.none (α := (BitVec 64))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn (Option.none (α := (BitVec 64))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn (Option.none (α := (BitVec 64)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holReturn (Option.none (α := (BitVec 64))))))) (fun (word : (BitVec 64)) => (holReturn (Option.none (α := (BitVec 64))))) (holReturn (Option.none (α := (BitVec 64)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holReturn (Option.none (α := (BitVec 64)))))) (holReturn (Option.none (α := (BitVec 64)))) (holReturn (Option.none (α := (BitVec 64)))) (fun (word : (BitVec 8)) => (holReturn (Option.none (α := (BitVec 64))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holReturn (Option.none (α := (BitVec 64))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holReturn (Option.none (α := (BitVec 64)))))) (holReturn (Option.none (α := (BitVec 64)))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holReturn (Option.none (α := (BitVec 64)))))) (holReturn (Option.none (α := (BitVec 64)))) (fun (x : Bool) => (fun (p : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (xa : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vms : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (xb : (Option ((BitVec 64) × (BitVec 64)))) => (holIf (holDisj (holLe L4vRefX64.Spec.VMRights_A.vm_read_write R) (holConj (holLe L4vRefX64.Spec.VMRights_A.vm_read_only R) (holNot is_receiver))) (holFunApp holReturn (holFunApp Option.some (HolAdd.addVal p (holWordAnd buffer_ptr ((holWordMask (w := 64)) (L4vRefX64.Spec.MachineTypes.pageBitsForSize vms)))))) (holReturn (Option.none (α := (BitVec 64))))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holReturn (Option.none (α := (BitVec 64)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holReturn (Option.none (α := (BitVec 64)))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holReturn (Option.none (α := (BitVec 64)))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holReturn (Option.none (α := (BitVec 64)))))) arch_cap)) buffer_cap))))))))) + +def prepare_thread_delete {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread_ptr : (BitVec 64)) => (L4vRefX64.Spec.FPU_A.fpu_release thread_ptr)) + +def update_map_data : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → ((Option ((BitVec 64) × (BitVec 64))) → ((Option L4vRefX64.Spec.MachineTypes.vmmap_type) → L4vRefX64.Spec.Arch_Structs_A.arch_cap))) := + (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (m : (Option ((BitVec 64) × (BitVec 64)))) => (fun (mt : (Option L4vRefX64.Spec.MachineTypes.vmmap_type)) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (fun (a : (BitVec 16)) => (fun (a_1 : (BitVec 16)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (fun (dev : Bool) => (fun (p : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (x : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (sz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (xa : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev p R (holTheOpt mt) sz m))))))) (fun (p : (BitVec 64)) => (fun (x : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap p m))) (fun (p : (BitVec 64)) => (fun (x : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap p m))) (fun (p : (BitVec 64)) => (fun (x : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap p m))) (fun (a : (BitVec 64)) => (fun (a_1 : (Option (BitVec 64))) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) cap)))) +end +end L4vRefX64.Spec.ArchVSpace_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_A.lean new file mode 100644 index 000000000..9fc1358d2 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_A.lean @@ -0,0 +1,98 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Arch_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchInvocation_A +import L4vRefX64.Spec.ArchIpcCancel_A +import L4vRefX64.Spec.ArchVSpaceAcc_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.FPU_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.Platform +import L4vRefX64.Spec.Retype_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Arch_A +open L4vRefX64.Prim +open Classical +noncomputable section +def arch_activate_idle_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (t : (BitVec 64)) => (holReturn ())) + +def update_irq_state {tv_a : Type} [Nonempty tv_a] : ((BitVec 8) → (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → ((L4vRefX64.Spec.Structures_A.abstract_state_ext tv_a) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext tv_a))) × Bool)))) := + (fun (irq : (BitVec 8)) => (fun (irqState : L4vRefX64.Spec.Arch_Structs_A.X64IRQState) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_irq_state L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (irq_states : ((BitVec 8) → L4vRefX64.Spec.Arch_Structs_A.X64IRQState)) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext tv_a)) => (L4vRefX64.Spec.Structures_A.abstract_state.arch_state_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_state.x64_irq_state_update (fun (uu__1 : ((BitVec 8) → L4vRefX64.Spec.Arch_Structs_A.X64IRQState)) => (holFunUpd irq_states irq irqState)) (L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state s))) s))))))) + +def arch_invoke_irq_control {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (aic : L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_arch_irq_control_invocation (fun (irq : (BitVec 8)) => (fun (dest : ((BitVec 64) × (List Bool))) => (fun (src : ((BitVec 64) × (List Bool))) => (fun (ioapic : (BitVec 64)) => (fun (pin : (BitVec 64)) => (fun (level : (BitVec 64)) => (fun (polarity : (BitVec 64)) => (fun (vector : (BitVec 64)) => (L4vRefX64.Spec.Exceptions_A.without_preemption (holBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.ioapicMapPinToVector ioapic pin level polarity vector)) (holKBind (holBind (holFunApp holReturn (L4vRefX64.Spec.Arch_Structs_A.X64IRQState.IRQIOAPIC (holWordAnd ioapic ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 5))) (holWordAnd pin ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 5))) (holWordAnd level (HolOne.oneVal (α := (BitVec 64)))) (holWordAnd polarity (HolOne.oneVal (α := (BitVec 64)))) true)) (fun (irq_state : L4vRefX64.Spec.Arch_Structs_A.X64IRQState) => (holBind (L4vRefX64.Spec.Arch_A.update_irq_state irq irq_state) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_irq_state L4vRefX64.Spec.Structures_A.irq_state.IRQSignal (L4vRefX64.Spec.MachineOps.IRQ irq)) (holKBind (L4vRefX64.Spec.CSpace_A.cap_insert (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap (L4vRefX64.Spec.MachineOps.IRQ irq)) src dest)))))))))))))))))) (fun (irq : (BitVec 8)) => (fun (dest : ((BitVec 64) × (List Bool))) => (fun (src : ((BitVec 64) × (List Bool))) => (fun (bus : (BitVec 64)) => (fun (dev : (BitVec 64)) => (fun (func : (BitVec 64)) => (fun (handle : (BitVec 64)) => (L4vRefX64.Spec.Exceptions_A.without_preemption (holBind (holFunApp holReturn (L4vRefX64.Spec.Arch_Structs_A.X64IRQState.IRQMSI (holWordAnd bus ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 8))) (holWordAnd dev ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 5))) (holWordAnd func ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 3))) (holWordAnd handle ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 32))))) (fun (irq_state : L4vRefX64.Spec.Arch_Structs_A.X64IRQState) => (holBind (L4vRefX64.Spec.Arch_A.update_irq_state irq irq_state) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_irq_state L4vRefX64.Spec.Structures_A.irq_state.IRQSignal (L4vRefX64.Spec.MachineOps.IRQ irq)) (holKBind (L4vRefX64.Spec.CSpace_A.cap_insert (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap (L4vRefX64.Spec.MachineOps.IRQ irq)) src dest))))))))))))))) aic)) + +def arch_no_return {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (oper : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind oper (holKBind (holReturn (List.nil (α := (BitVec 64))))))) + +def page_bits : Nat := + L4vRefX64.Spec.MachineTypes.pageBits + +def perform_asid_control_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.asid_control_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.ArchInvocation_A.asid_control_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_asid_control_invocation (fun (frame : (BitVec 64)) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (parent : ((BitVec 64) × (List Bool))) => (fun (base : (BitVec 64)) => (holBind (L4vRefX64.Spec.Retype_A.delete_objects frame L4vRefX64.Spec.Arch_A.page_bits) (holKBind (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap parent) (fun (pcap : L4vRefX64.Spec.Structures_A.cap) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap (L4vRefX64.Spec.CSpace_A.free_index_update (fun (uu_ : Nat) => (L4vRefX64.Spec.CSpace_A.max_free_index (L4vRefX64.Spec.CSpace_A.untyped_sz_bits pcap))) pcap) parent) (holKBind (holBind (L4vRefX64.Spec.Retype_A.retype_region frame (HolOne.oneVal (α := Nat)) (HolZero.zeroVal (α := Nat)) (L4vRefX64.Spec.Structures_A.apiobject_type.ArchObject L4vRefX64.Spec.Arch_Structs_A.aobject_type.ASIDPoolObj) false) (holKBind (holBind (L4vRefX64.Spec.CSpace_A.cap_insert (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDPoolCap frame base)) parent slot) (holKBind (holBind (holAssert (holEq (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_low_bits_of base) (HolZero.zeroVal (α := (BitVec 9))))) (holKBind (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_asid_table L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (asid_table : ((BitVec 3) → (Option (BitVec 64)))) => (holBind (holReturn (holFunUpd asid_table (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_high_bits_of base) (Option.some frame))) (fun (asid_table_p : ((BitVec 3) → (Option (BitVec 64)))) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.arch_state_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_state.x64_asid_table_update (fun (uu__1 : ((BitVec 3) → (Option (BitVec 64)))) => asid_table_p) (L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state s))) s))))))))))))))))))))))) iv)) + +def store_asid_pool_entry {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((BitVec 64) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))))) := + (fun (pool_ptr : (BitVec 64)) => (fun (asid : (BitVec 64)) => (fun (pml4base : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_asid_pool pool_ptr) (fun (pool : ((BitVec 9) → (Option (BitVec 64)))) => (holBind (holReturn (holFunUpd pool (L4vRefX64.Spec.ArchVSpaceAcc_A.asid_low_bits_of asid) pml4base)) (fun (pool_p : ((BitVec 9) → (Option (BitVec 64)))) => (L4vRefX64.Spec.ArchVSpaceAcc_A.set_asid_pool pool_ptr pool_p)))))))) + +def perform_asid_pool_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.asid_pool_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.ArchInvocation_A.asid_pool_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_asid_pool_invocation (fun (asid : (BitVec 64)) => (fun (pool_ptr : (BitVec 64)) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap ct_slot) (fun (pml4_cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (pml4_base : (BitVec 64)) => (fun (x : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap pml4_base (Option.some asid))) ct_slot) (holKBind (L4vRefX64.Spec.Arch_A.store_asid_pool_entry pool_ptr asid (Option.some pml4_base)))))) arch_cap)) pml4_cap)))))) iv)) + +def port_in {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (f : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) => (holBind (L4vRefX64.Spec.Structures_A.do_machine_op f) (fun (res : (BitVec 64)) => (holReturn (List.cons res (List.nil (α := (BitVec 64)))))))) + +def port_out {w_tv_a : Nat} {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec w_tv_a) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) → ((BitVec w_tv_a) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : ((BitVec w_tv_a) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) => (fun (w : (BitVec w_tv_a)) => (holBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (f w)) (holKBind (holReturn (List.nil (α := (BitVec 64)))))))) + +def perform_io_port_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.io_port_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (i : L4vRefX64.Spec.ArchInvocation_A.io_port_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_io_port_invocation (fun (port : (BitVec 16)) => (fun (port_data : L4vRefX64.Spec.ArchInvocation_A.io_port_invocation_data) => (L4vRefX64.Spec.ArchInvocation_A.case_io_port_invocation_data (L4vRefX64.Spec.Arch_A.port_in (L4vRefX64.Spec.MachineOps.in8 port)) (L4vRefX64.Spec.Arch_A.port_in (L4vRefX64.Spec.MachineOps.in16 port)) (L4vRefX64.Spec.Arch_A.port_in (L4vRefX64.Spec.MachineOps.in32 port)) (fun (w : (BitVec 8)) => (L4vRefX64.Spec.Arch_A.port_out (L4vRefX64.Spec.MachineOps.out8 port) w)) (fun (w : (BitVec 16)) => (L4vRefX64.Spec.Arch_A.port_out (L4vRefX64.Spec.MachineOps.out16 port) w)) (fun (w : (BitVec 32)) => (L4vRefX64.Spec.Arch_A.port_out (L4vRefX64.Spec.MachineOps.out32 port) w)) port_data))) i)) + +def perform_ioport_control_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.io_port_control_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (i : L4vRefX64.Spec.ArchInvocation_A.io_port_control_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_io_port_control_invocation (fun (f : (BitVec 16)) => (fun (l : (BitVec 16)) => (fun (dest_slot : ((BitVec 64) × (List Bool))) => (fun (control_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.ArchIpcCancel_A.set_ioport_mask f l true) (holKBind (holBind (holFunApp holReturn (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap f l))) (fun (c : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.CSpace_A.cap_insert (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap f l)) control_slot dest_slot))))))))) i)) + +def perform_page_directory_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.page_directory_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.ArchInvocation_A.page_directory_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_page_directory_invocation (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (fun (pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (fun (pdpt_slot : (BitVec 64)) => (fun (vspace : (BitVec 64)) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap cap ct_slot) (holKBind (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pdpte pdpt_slot pdpte) (holKBind (holBind (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (x : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (v_as : (BitVec 64)) => (fun (xa : (BitVec 64)) => (holReturn v_as))) a)) option))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_cap)) cap) (fun (asid : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.invalidate_page_structure_cache_asid (L4vRefX64.Spec.Platform.addrFromPPtr vspace) asid)))))))))))) (fun (capa : L4vRefX64.Spec.Structures_A.cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (p : (BitVec 64)) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (holBind (holCaseOption (holReturn ()) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (asid : (BitVec 64)) => (fun (vaddr : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpace_A.unmap_pd asid vaddr p) (holKBind (holBind (holReturn (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)) (fun (pde_bits : Nat) => (holBind (holReturn (holUptoEnumStep p (HolAdd.addVal p (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) pde_bits)) (HolSub.subVal (HolAdd.addVal p (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) L4vRefX64.Spec.Arch_Structs_A.pd_bits)) (HolOne.oneVal (α := (BitVec 64)))))) (fun (slots : (List (BitVec 64))) => (holMapMx (holSwp L4vRefX64.Spec.ArchVSpaceAcc_A.store_pde L4vRefX64.Spec.Arch_Structs_A.pde.InvalidPDE) slots))))))))) a)) mapped_address) (holKBind (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.cap.the_arch_cap) (L4vRefX64.Spec.CSpaceAcc_A.get_cap ct_slot)) (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.CSpaceAcc_A.set_cap (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.ArchVSpace_A.update_map_data cap (Option.none (α := ((BitVec 64) × (BitVec 64)))) (Option.none (α := L4vRefX64.Spec.MachineTypes.vmmap_type)))) ct_slot))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_cap)) capa))) iv)) + +def perform_page_invocation_unmap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (dev : Bool) => (fun (base : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (map_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (sz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (mapped : (Option ((BitVec 64) × (BitVec 64)))) => (holBind (holCaseOption (holReturn ()) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (asid : (BitVec 64)) => (fun (vaddr : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.unmap_page sz asid vaddr base))) a)) mapped) (holKBind (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.cap.the_arch_cap) (L4vRefX64.Spec.CSpaceAcc_A.get_cap ct_slot)) (fun (cap_1 : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.CSpaceAcc_A.set_cap (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.ArchVSpace_A.update_map_data cap_1 (Option.none (α := ((BitVec 64) × (BitVec 64)))) (Option.some L4vRefX64.Spec.MachineTypes.vmmap_type.VMNoMap))) ct_slot))))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap))) + +def perform_page_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.page_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.ArchInvocation_A.page_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_page_invocation (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (fun (entries : (L4vRefX64.Spec.Arch_Structs_A.vm_page_entry × (BitVec 64))) => (fun (vspace : (BitVec 64)) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap cap ct_slot) (holKBind (holBind (holCaseProd (fun (a : L4vRefX64.Spec.Arch_Structs_A.vm_page_entry) => (fun (slot : (BitVec 64)) => (L4vRefX64.Spec.Arch_Structs_A.case_vm_page_entry (fun (pte : L4vRefX64.Spec.Arch_Structs_A.pte) => (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pte slot pte)) (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pde slot pde)) (fun (pdpte : L4vRefX64.Spec.Arch_Structs_A.pdpte) => (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pdpte slot pdpte)) a))) entries) (holKBind (holBind (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (x : Bool) => (fun (xa : (BitVec 64)) => (fun (xb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (xc : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (xd : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (v_as : (BitVec 64)) => (fun (xe : (BitVec 64)) => (holReturn v_as))) a)) option))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_cap)) cap) (fun (asid : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpace_A.invalidate_page_structure_cache_asid (L4vRefX64.Spec.Platform.addrFromPPtr vspace) asid) (holKBind (holReturn (List.nil (α := (BitVec 64)))))))))))))))) (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (dev : Bool) => (fun (base : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (map_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (sz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (mapped : (Option ((BitVec 64) × (BitVec 64)))) => (holBind (holCaseOption (holReturn ()) (fun (x : ((BitVec 64) × (BitVec 64))) => (L4vRefX64.Spec.MachineTypes.case_vmmap_type (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (L4vRefX64.Spec.Arch_A.perform_page_invocation_unmap cap ct_slot) map_type)) mapped) (holKBind (holReturn (List.nil (α := (BitVec 64)))))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap))) (fun (ptr : (BitVec 64)) => (holReturn (List.cons (L4vRefX64.Spec.Platform.addrFromPPtr ptr) (List.nil (α := (BitVec 64)))))) iv)) + +def perform_page_table_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.page_table_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.ArchInvocation_A.page_table_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_page_table_invocation (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (fun (pde : L4vRefX64.Spec.Arch_Structs_A.pde) => (fun (pd_slot : (BitVec 64)) => (fun (vspace : (BitVec 64)) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap cap ct_slot) (holKBind (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pde pd_slot pde) (holKBind (holBind (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (x : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (v_as : (BitVec 64)) => (fun (xa : (BitVec 64)) => (holReturn v_as))) a)) option))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_cap)) cap) (fun (asid : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.invalidate_page_structure_cache_asid (L4vRefX64.Spec.Platform.addrFromPPtr vspace) asid)))))))))))) (fun (capa : L4vRefX64.Spec.Structures_A.cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (p : (BitVec 64)) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (holBind (holCaseOption (holReturn ()) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (asid : (BitVec 64)) => (fun (vaddr : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpace_A.unmap_page_table asid vaddr p) (holKBind (holBind (holReturn (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)) (fun (pte_bits : Nat) => (holBind (holReturn (holUptoEnumStep p (HolAdd.addVal p (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) pte_bits)) (HolSub.subVal (HolAdd.addVal p (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) L4vRefX64.Spec.Arch_Structs_A.pt_bits)) (HolOne.oneVal (α := (BitVec 64)))))) (fun (slots : (List (BitVec 64))) => (holMapMx (holSwp L4vRefX64.Spec.ArchVSpaceAcc_A.store_pte L4vRefX64.Spec.Arch_Structs_A.pte.InvalidPTE) slots))))))))) a)) mapped_address) (holKBind (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.cap.the_arch_cap) (L4vRefX64.Spec.CSpaceAcc_A.get_cap ct_slot)) (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.CSpaceAcc_A.set_cap (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.ArchVSpace_A.update_map_data cap (Option.none (α := ((BitVec 64) × (BitVec 64)))) (Option.none (α := L4vRefX64.Spec.MachineTypes.vmmap_type)))) ct_slot))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_cap)) capa))) iv)) + +def perform_pdpt_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.pdpt_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.ArchInvocation_A.pdpt_invocation) => (L4vRefX64.Spec.ArchInvocation_A.case_pdpt_invocation (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (fun (pml4e : L4vRefX64.Spec.Arch_Structs_A.pml4e) => (fun (pml4_slot : (BitVec 64)) => (fun (vspace : (BitVec 64)) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap cap ct_slot) (holKBind (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.store_pml4e pml4_slot pml4e) (holKBind (holBind (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (x : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holCaseOption (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (v_as : (BitVec 64)) => (fun (xa : (BitVec 64)) => (holReturn v_as))) a)) option))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_cap)) cap) (fun (asid : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.invalidate_page_structure_cache_asid (L4vRefX64.Spec.Platform.addrFromPPtr vspace) asid)))))))))))) (fun (capa : L4vRefX64.Spec.Structures_A.cap) => (fun (ct_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (vmmap_type : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (vmpage_size : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (p : (BitVec 64)) => (fun (mapped_address : (Option ((BitVec 64) × (BitVec 64)))) => (holBind (holCaseOption (holReturn ()) (fun (a : ((BitVec 64) × (BitVec 64))) => (holCaseProd (fun (asid : (BitVec 64)) => (fun (vaddr : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpace_A.unmap_pdpt asid vaddr p) (holKBind (holBind (holReturn (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)) (fun (pdept_bits : Nat) => (holBind (holReturn (holUptoEnumStep p (HolAdd.addVal p (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) pdept_bits)) (HolSub.subVal (HolAdd.addVal p (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) L4vRefX64.Spec.Arch_Structs_A.pdpt_bits)) (HolOne.oneVal (α := (BitVec 64)))))) (fun (slots : (List (BitVec 64))) => (holMapMx (holSwp L4vRefX64.Spec.ArchVSpaceAcc_A.store_pdpte L4vRefX64.Spec.Arch_Structs_A.pdpte.InvalidPDPTE) slots))))))))) a)) mapped_address) (holKBind (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.cap.the_arch_cap) (L4vRefX64.Spec.CSpaceAcc_A.get_cap ct_slot)) (fun (cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.CSpaceAcc_A.set_cap (holFunApp L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.ArchVSpace_A.update_map_data cap (Option.none (α := ((BitVec 64) × (BitVec 64)))) (Option.none (α := L4vRefX64.Spec.MachineTypes.vmmap_type)))) ct_slot))))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) arch_cap)) capa))) iv)) + +def arch_perform_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ArchInvocation_A.arch_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit (List (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (i : L4vRefX64.Spec.ArchInvocation_A.arch_invocation) => (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.ArchInvocation_A.case_arch_invocation (fun (oper : L4vRefX64.Spec.ArchInvocation_A.page_table_invocation) => (holFunApp (fun (oper_1 : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind oper_1 (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (L4vRefX64.Spec.Arch_A.perform_page_table_invocation oper))) (fun (oper : L4vRefX64.Spec.ArchInvocation_A.page_directory_invocation) => (holFunApp (fun (oper_1 : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind oper_1 (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (L4vRefX64.Spec.Arch_A.perform_page_directory_invocation oper))) (fun (oper : L4vRefX64.Spec.ArchInvocation_A.pdpt_invocation) => (holFunApp (fun (oper_1 : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind oper_1 (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (L4vRefX64.Spec.Arch_A.perform_pdpt_invocation oper))) (fun (oper : L4vRefX64.Spec.ArchInvocation_A.page_invocation) => (L4vRefX64.Spec.Arch_A.perform_page_invocation oper)) (fun (oper : L4vRefX64.Spec.ArchInvocation_A.asid_control_invocation) => (holFunApp (fun (oper_1 : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind oper_1 (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (L4vRefX64.Spec.Arch_A.perform_asid_control_invocation oper))) (fun (oper : L4vRefX64.Spec.ArchInvocation_A.asid_pool_invocation) => (holFunApp (fun (oper_1 : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind oper_1 (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (L4vRefX64.Spec.Arch_A.perform_asid_pool_invocation oper))) (fun (oper : L4vRefX64.Spec.ArchInvocation_A.io_port_invocation) => (L4vRefX64.Spec.Arch_A.perform_io_port_invocation oper)) (fun (oper : L4vRefX64.Spec.ArchInvocation_A.io_port_control_invocation) => (holFunApp (fun (oper_1 : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind oper_1 (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (L4vRefX64.Spec.Arch_A.perform_ioport_control_invocation oper))) i))) + +def arch_prepare_next_domain {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (L4vRefX64.Spec.FPU_A.switch_local_fpu_owner (Option.none (α := (BitVec 64)))) + +def arch_switch_to_idle_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.idle_thread) (fun (thread : (BitVec 64)) => (L4vRefX64.Spec.ArchVSpace_A.set_vm_root thread))) + +def arch_switch_to_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (t : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpace_A.set_vm_root t) (holKBind (L4vRefX64.Spec.FPU_A.lazy_fpu_restore t)))) + +def pde_check_if_mapped {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (slot : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pde slot) (fun (pd : L4vRefX64.Spec.Arch_Structs_A.pde) => (holReturn (holNot (holEq pd L4vRefX64.Spec.Arch_Structs_A.pde.InvalidPDE)))))) + +def pte_check_if_mapped {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (slot : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpaceAcc_A.get_pte slot) (fun (pt : L4vRefX64.Spec.Arch_Structs_A.pte) => (holReturn (holNot (holEq pt L4vRefX64.Spec.Arch_Structs_A.pte.InvalidPTE)))))) +end +end L4vRefX64.Spec.Arch_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_Structs_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_Structs_A.lean new file mode 100644 index 000000000..cb7f586b5 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_Structs_A.lean @@ -0,0 +1,500 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Arch_Structs_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchVMAttributes_A +import L4vRefX64.Spec.Arch_Structs_B +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.VMRights_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Arch_Structs_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive X64IRQState where + | IRQFree + | IRQReserved + | IRQMSI (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : (BitVec 64)) (a3 : (BitVec 64)) + | IRQIOAPIC (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : (BitVec 64)) (a3 : (BitVec 64)) (a4 : Bool) +instance : Nonempty X64IRQState := ⟨X64IRQState.IRQFree⟩ +def case_X64IRQState {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : (BitVec 64) → (BitVec 64) → (BitVec 64) → (BitVec 64) → r_ty) (f3 : (BitVec 64) → (BitVec 64) → (BitVec 64) → (BitVec 64) → Bool → r_ty) : X64IRQState → r_ty + | .IRQFree => f0 + | .IRQReserved => f1 + | .IRQMSI x0 x1 x2 x3 => f2 x0 x1 x2 x3 + | .IRQIOAPIC x0 x1 x2 x3 x4 => f3 x0 x1 x2 x3 x4 + +inductive aa_type_T where + | AASIDPool + | APageTable + | APageDirectory + | APDPointerTable + | APageMapL4 + | AUserData (a0 : L4vRefX64.Spec.MachineTypes.vmpage_size) + | ADeviceData (a0 : L4vRefX64.Spec.MachineTypes.vmpage_size) +instance : Nonempty aa_type_T := ⟨aa_type_T.AASIDPool⟩ +def case_aa_type {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : L4vRefX64.Spec.MachineTypes.vmpage_size → r_ty) (f6 : L4vRefX64.Spec.MachineTypes.vmpage_size → r_ty) : aa_type_T → r_ty + | .AASIDPool => f0 + | .APageTable => f1 + | .APageDirectory => f2 + | .APDPointerTable => f3 + | .APageMapL4 => f4 + | .AUserData x0 => f5 x0 + | .ADeviceData x0 => f6 x0 + +inductive aobject_type where + | SmallPageObj + | LargePageObj + | HugePageObj + | PageTableObj + | PageDirectoryObj + | PDPTObj + | PML4Obj + | ASIDPoolObj +instance : Nonempty aobject_type := ⟨aobject_type.SmallPageObj⟩ +def case_aobject_type {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : r_ty) (f6 : r_ty) (f7 : r_ty) : aobject_type → r_ty + | .SmallPageObj => f0 + | .LargePageObj => f1 + | .HugePageObj => f2 + | .PageTableObj => f3 + | .PageDirectoryObj => f4 + | .PDPTObj => f5 + | .PML4Obj => f6 + | .ASIDPoolObj => f7 + +inductive arch_cap where + | ASIDPoolCap (a0 : (BitVec 64)) (a1 : (BitVec 64)) + | ASIDControlCap + | IOPortCap (a0 : (BitVec 16)) (a1 : (BitVec 16)) + | IOPortControlCap + | PageCap (a0 : Bool) (a1 : (BitVec 64)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) (a3 : L4vRefX64.Spec.MachineTypes.vmmap_type) (a4 : L4vRefX64.Spec.MachineTypes.vmpage_size) (a5 : (Option ((BitVec 64) × (BitVec 64)))) + | PageTableCap (a0 : (BitVec 64)) (a1 : (Option ((BitVec 64) × (BitVec 64)))) + | PageDirectoryCap (a0 : (BitVec 64)) (a1 : (Option ((BitVec 64) × (BitVec 64)))) + | PDPointerTableCap (a0 : (BitVec 64)) (a1 : (Option ((BitVec 64) × (BitVec 64)))) + | PML4Cap (a0 : (BitVec 64)) (a1 : (Option (BitVec 64))) +instance : Nonempty arch_cap := ⟨arch_cap.ASIDPoolCap holUndefined holUndefined⟩ +def case_arch_cap {r_ty : Type} (f0 : (BitVec 64) → (BitVec 64) → r_ty) (f1 : r_ty) (f2 : (BitVec 16) → (BitVec 16) → r_ty) (f3 : r_ty) (f4 : Bool → (BitVec 64) → (Set L4vRefX64.Spec.CapRights_A.rights) → L4vRefX64.Spec.MachineTypes.vmmap_type → L4vRefX64.Spec.MachineTypes.vmpage_size → (Option ((BitVec 64) × (BitVec 64))) → r_ty) (f5 : (BitVec 64) → (Option ((BitVec 64) × (BitVec 64))) → r_ty) (f6 : (BitVec 64) → (Option ((BitVec 64) × (BitVec 64))) → r_ty) (f7 : (BitVec 64) → (Option ((BitVec 64) × (BitVec 64))) → r_ty) (f8 : (BitVec 64) → (Option (BitVec 64)) → r_ty) : arch_cap → r_ty + | .ASIDPoolCap x0 x1 => f0 x0 x1 + | .ASIDControlCap => f1 + | .IOPortCap x0 x1 => f2 x0 x1 + | .IOPortControlCap => f3 + | .PageCap x0 x1 x2 x3 x4 x5 => f4 x0 x1 x2 x3 x4 x5 + | .PageTableCap x0 x1 => f5 x0 x1 + | .PageDirectoryCap x0 x1 => f6 x0 x1 + | .PDPointerTableCap x0 x1 => f7 x0 x1 + | .PML4Cap x0 x1 => f8 x0 x1 + +inductive pde where + | InvalidPDE + | PageTablePDE (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) + | LargePagePDE (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) +instance : Nonempty pde := ⟨pde.InvalidPDE⟩ +def case_pde {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 64) → (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) (f2 : (BitVec 64) → (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) : pde → r_ty + | .InvalidPDE => f0 + | .PageTablePDE x0 x1 x2 => f1 x0 x1 x2 + | .LargePagePDE x0 x1 x2 => f2 x0 x1 x2 + +inductive pdpte where + | InvalidPDPTE + | PageDirectoryPDPTE (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) + | HugePagePDPTE (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) +instance : Nonempty pdpte := ⟨pdpte.InvalidPDPTE⟩ +def case_pdpte {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 64) → (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) (f2 : (BitVec 64) → (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) : pdpte → r_ty + | .InvalidPDPTE => f0 + | .PageDirectoryPDPTE x0 x1 x2 => f1 x0 x1 x2 + | .HugePagePDPTE x0 x1 x2 => f2 x0 x1 x2 + +inductive pml4e where + | InvalidPML4E + | PDPointerTablePML4E (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) +instance : Nonempty pml4e := ⟨pml4e.InvalidPML4E⟩ +def case_pml4e {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 64) → (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) : pml4e → r_ty + | .InvalidPML4E => f0 + | .PDPointerTablePML4E x0 x1 x2 => f1 x0 x1 x2 + +inductive pte where + | InvalidPTE + | SmallPagePTE (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) +instance : Nonempty pte := ⟨pte.InvalidPTE⟩ +def case_pte {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 64) → (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) : pte → r_ty + | .InvalidPTE => f0 + | .SmallPagePTE x0 x1 x2 => f1 x0 x1 x2 + +inductive arch_kernel_obj where + | ASIDPool (a0 : ((BitVec 9) → (Option (BitVec 64)))) + | PageTable (a0 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) + | PageDirectory (a0 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) + | PDPointerTable (a0 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) + | PageMapL4 (a0 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) + | DataPage (a0 : Bool) (a1 : L4vRefX64.Spec.MachineTypes.vmpage_size) +instance : Nonempty arch_kernel_obj := ⟨arch_kernel_obj.ASIDPool holUndefined⟩ +def case_arch_kernel_obj {r_ty : Type} (f0 : ((BitVec 9) → (Option (BitVec 64))) → r_ty) (f1 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte) → r_ty) (f2 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) → r_ty) (f3 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) → r_ty) (f4 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) → r_ty) (f5 : Bool → L4vRefX64.Spec.MachineTypes.vmpage_size → r_ty) : arch_kernel_obj → r_ty + | .ASIDPool x0 => f0 x0 + | .PageTable x0 => f1 x0 + | .PageDirectory x0 => f2 x0 + | .PDPointerTable x0 => f3 x0 + | .PageMapL4 x0 => f4 x0 + | .DataPage x0 x1 => f5 x0 x1 + +inductive cr3 where + | mk (a0 : (BitVec 64)) (a1 : (BitVec 64)) +instance : Nonempty cr3 := ⟨cr3.mk holUndefined holUndefined⟩ +def case_cr3 {r_ty : Type} (f0 : (BitVec 64) → (BitVec 64) → r_ty) : cr3 → r_ty + | .mk x0 x1 => f0 x0 x1 + +inductive translation_type where + | NotTranslated + | Translated +instance : Nonempty translation_type := ⟨translation_type.NotTranslated⟩ +def case_translation_type {r_ty : Type} (f0 : r_ty) (f1 : r_ty) : translation_type → r_ty + | .NotTranslated => f0 + | .Translated => f1 + +inductive iocte where + | InvalidIOCTE + | VTDCTE (a0 : (BitVec 16)) (a1 : Bool) (a2 : Nat) (a3 : (BitVec 64)) (a4 : L4vRefX64.Spec.Arch_Structs_A.translation_type) (a5 : Bool) +instance : Nonempty iocte := ⟨iocte.InvalidIOCTE⟩ +def case_iocte {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 16) → Bool → Nat → (BitVec 64) → L4vRefX64.Spec.Arch_Structs_A.translation_type → Bool → r_ty) : iocte → r_ty + | .InvalidIOCTE => f0 + | .VTDCTE x0 x1 x2 x3 x4 x5 => f1 x0 x1 x2 x3 x4 x5 + +inductive iopte where + | InvalidIOPTE + | VTDPTE (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.CapRights_A.rights)) +instance : Nonempty iopte := ⟨iopte.InvalidIOPTE⟩ +def case_iopte {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 64) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) : iopte → r_ty + | .InvalidIOPTE => f0 + | .VTDPTE x0 x1 => f1 x0 x1 + +inductive iorte where + | InvalidIORTE + | VTDRTE (a0 : (BitVec 64)) (a1 : Bool) +instance : Nonempty iorte := ⟨iorte.InvalidIORTE⟩ +def case_iorte {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 64) → Bool → r_ty) : iorte → r_ty + | .InvalidIORTE => f0 + | .VTDRTE x0 x1 => f1 x0 x1 + +inductive vm_page_entry where + | VMPTE (a0 : L4vRefX64.Spec.Arch_Structs_A.pte) + | VMPDE (a0 : L4vRefX64.Spec.Arch_Structs_A.pde) + | VMPDPTE (a0 : L4vRefX64.Spec.Arch_Structs_A.pdpte) +instance : Nonempty vm_page_entry := ⟨vm_page_entry.VMPTE holUndefined⟩ +def case_vm_page_entry {r_ty : Type} (f0 : L4vRefX64.Spec.Arch_Structs_A.pte → r_ty) (f1 : L4vRefX64.Spec.Arch_Structs_A.pde → r_ty) (f2 : L4vRefX64.Spec.Arch_Structs_A.pdpte → r_ty) : vm_page_entry → r_ty + | .VMPTE x0 => f0 x0 + | .VMPDE x0 => f1 x0 + | .VMPDPTE x0 => f2 x0 + +structure arch_state_ext (more : Type) where + x64_asid_table : ((BitVec 3) → (Option (BitVec 64))) + x64_global_pml4 : (BitVec 64) + x64_kernel_vspace : ((BitVec 64) → L4vRefX64.Spec.Arch_Structs_B.x64vspace_region_use) + x64_global_pts : (List (BitVec 64)) + x64_global_pdpts : (List (BitVec 64)) + x64_global_pds : (List (BitVec 64)) + x64_current_cr3 : L4vRefX64.Spec.Arch_Structs_A.cr3 + x64_allocated_io_ports : ((BitVec 16) → Bool) + x64_num_ioapics : (BitVec 64) + x64_ioapic_nirqs : ((BitVec 64) → (BitVec 8)) + x64_irq_state : ((BitVec 8) → L4vRefX64.Spec.Arch_Structs_A.X64IRQState) + x64_current_fpu_owner : (Option (BitVec 64)) + more : more +instance {more : Type} [Nonempty more] : Nonempty (arch_state_ext more) := ⟨arch_state_ext.mk holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +abbrev arch_state := arch_state_ext Unit +def arch_state.truncate {more : Type} (r : (arch_state_ext more)) : arch_state_ext Unit := { r with more := () } +def arch_state.extend {more : Type} (r : arch_state_ext Unit) (m : more) : (arch_state_ext more) := { r with more := m } +def arch_state.x64_asid_table_update {more : Type} (g : ((BitVec 3) → (Option (BitVec 64))) → ((BitVec 3) → (Option (BitVec 64)))) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_asid_table := g r.x64_asid_table } +def arch_state.x64_global_pml4_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_global_pml4 := g r.x64_global_pml4 } +def arch_state.x64_kernel_vspace_update {more : Type} (g : ((BitVec 64) → L4vRefX64.Spec.Arch_Structs_B.x64vspace_region_use) → ((BitVec 64) → L4vRefX64.Spec.Arch_Structs_B.x64vspace_region_use)) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_kernel_vspace := g r.x64_kernel_vspace } +def arch_state.x64_global_pts_update {more : Type} (g : (List (BitVec 64)) → (List (BitVec 64))) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_global_pts := g r.x64_global_pts } +def arch_state.x64_global_pdpts_update {more : Type} (g : (List (BitVec 64)) → (List (BitVec 64))) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_global_pdpts := g r.x64_global_pdpts } +def arch_state.x64_global_pds_update {more : Type} (g : (List (BitVec 64)) → (List (BitVec 64))) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_global_pds := g r.x64_global_pds } +def arch_state.x64_current_cr3_update {more : Type} (g : L4vRefX64.Spec.Arch_Structs_A.cr3 → L4vRefX64.Spec.Arch_Structs_A.cr3) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_current_cr3 := g r.x64_current_cr3 } +def arch_state.x64_allocated_io_ports_update {more : Type} (g : ((BitVec 16) → Bool) → ((BitVec 16) → Bool)) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_allocated_io_ports := g r.x64_allocated_io_ports } +def arch_state.x64_num_ioapics_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_num_ioapics := g r.x64_num_ioapics } +def arch_state.x64_ioapic_nirqs_update {more : Type} (g : ((BitVec 64) → (BitVec 8)) → ((BitVec 64) → (BitVec 8))) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_ioapic_nirqs := g r.x64_ioapic_nirqs } +def arch_state.x64_irq_state_update {more : Type} (g : ((BitVec 8) → L4vRefX64.Spec.Arch_Structs_A.X64IRQState) → ((BitVec 8) → L4vRefX64.Spec.Arch_Structs_A.X64IRQState)) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_irq_state := g r.x64_irq_state } +def arch_state.x64_current_fpu_owner_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (arch_state_ext more)) : (arch_state_ext more) := { r with x64_current_fpu_owner := g r.x64_current_fpu_owner } + +structure arch_tcb_ext (more : Type) where + tcb_context : L4vRefX64.Spec.MachineOps.user_context + tcb_cur_fpu : Bool + more : more +instance {more : Type} [Nonempty more] : Nonempty (arch_tcb_ext more) := ⟨arch_tcb_ext.mk holUndefined holUndefined holUndefined⟩ +abbrev arch_tcb := arch_tcb_ext Unit +def arch_tcb.truncate {more : Type} (r : (arch_tcb_ext more)) : arch_tcb_ext Unit := { r with more := () } +def arch_tcb.extend {more : Type} (r : arch_tcb_ext Unit) (m : more) : (arch_tcb_ext more) := { r with more := m } +def arch_tcb.tcb_context_update {more : Type} (g : L4vRefX64.Spec.MachineOps.user_context → L4vRefX64.Spec.MachineOps.user_context) (r : (arch_tcb_ext more)) : (arch_tcb_ext more) := { r with tcb_context := g r.tcb_context } +def arch_tcb.tcb_cur_fpu_update {more : Type} (g : Bool → Bool) (r : (arch_tcb_ext more)) : (arch_tcb_ext more) := { r with tcb_cur_fpu := g r.tcb_cur_fpu } + +def X64IRQState.IRQLevel : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := (BitVec 64))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : (BitVec 64)) => (fun (x43 : (BitVec 64)) => (fun (x44 : (BitVec 64)) => (fun (x45 : Bool) => x43))))) X64IRQState) + +def X64IRQState.IRQMasked : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → Bool) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := Bool)) (holUndefined (α := Bool)) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := Bool)))))) (fun (x41 : (BitVec 64)) => (fun (x42 : (BitVec 64)) => (fun (x43 : (BitVec 64)) => (fun (x44 : (BitVec 64)) => (fun (x45 : Bool) => x45))))) X64IRQState) + +def X64IRQState.IRQPin : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := (BitVec 64))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : (BitVec 64)) => (fun (x43 : (BitVec 64)) => (fun (x44 : (BitVec 64)) => (fun (x45 : Bool) => x42))))) X64IRQState) + +def X64IRQState.IRQPolarity : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := (BitVec 64))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : (BitVec 64)) => (fun (x43 : (BitVec 64)) => (fun (x44 : (BitVec 64)) => (fun (x45 : Bool) => x44))))) X64IRQState) + +def X64IRQState.IRQioapic : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (holUndefined (α := (BitVec 64))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : (BitVec 64)) => (fun (x43 : (BitVec 64)) => (fun (x44 : (BitVec 64)) => (fun (x45 : Bool) => x41))))) X64IRQState) + +def X64IRQState.MSIBus : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (x31 : (BitVec 64)) => (fun (x32 : (BitVec 64)) => (fun (x33 : (BitVec 64)) => (fun (x34 : (BitVec 64)) => x31)))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (fun (uu_4 : Bool) => (holUndefined (α := (BitVec 64)))))))) X64IRQState) + +def X64IRQState.MSIDev : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (x31 : (BitVec 64)) => (fun (x32 : (BitVec 64)) => (fun (x33 : (BitVec 64)) => (fun (x34 : (BitVec 64)) => x32)))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (fun (uu_4 : Bool) => (holUndefined (α := (BitVec 64)))))))) X64IRQState) + +def X64IRQState.MSIFunc : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (x31 : (BitVec 64)) => (fun (x32 : (BitVec 64)) => (fun (x33 : (BitVec 64)) => (fun (x34 : (BitVec 64)) => x33)))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (fun (uu_4 : Bool) => (holUndefined (α := (BitVec 64)))))))) X64IRQState) + +def X64IRQState.MSIHandle : (L4vRefX64.Spec.Arch_Structs_A.X64IRQState → (BitVec 64)) + | X64IRQState => (L4vRefX64.Spec.Arch_Structs_A.case_X64IRQState (holUndefined (α := (BitVec 64))) (holUndefined (α := (BitVec 64))) (fun (x31 : (BitVec 64)) => (fun (x32 : (BitVec 64)) => (fun (x33 : (BitVec 64)) => (fun (x34 : (BitVec 64)) => x34)))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : (BitVec 64)) => (fun (uu_4 : Bool) => (holUndefined (α := (BitVec 64)))))))) X64IRQState) + +def aa_type : (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj → L4vRefX64.Spec.Arch_Structs_A.aa_type_T) := + (fun (ao : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_kernel_obj (fun (f : ((BitVec 9) → (Option (BitVec 64)))) => L4vRefX64.Spec.Arch_Structs_A.aa_type_T.AASIDPool) (fun (pt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pte)) => L4vRefX64.Spec.Arch_Structs_A.aa_type_T.APageTable) (fun (pd : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde)) => L4vRefX64.Spec.Arch_Structs_A.aa_type_T.APageDirectory) (fun (pdpt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte)) => L4vRefX64.Spec.Arch_Structs_A.aa_type_T.APDPointerTable) (fun (pm : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e)) => L4vRefX64.Spec.Arch_Structs_A.aa_type_T.APageMapL4) (fun (dev : Bool) => (fun (sz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (holIf dev (L4vRefX64.Spec.Arch_Structs_A.aa_type_T.ADeviceData sz) (L4vRefX64.Spec.Arch_Structs_A.aa_type_T.AUserData sz)))) ao)) + +def acap_rights_update : ((Set L4vRefX64.Spec.CapRights_A.rights) → (L4vRefX64.Spec.Arch_Structs_A.arch_cap → L4vRefX64.Spec.Arch_Structs_A.arch_cap)) := + (fun (rs : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (ac : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => ac)) ac (fun (word1 : (BitVec 16)) => (fun (word2 : (BitVec 16)) => ac)) ac (fun (dev : Bool) => (fun (x : (BitVec 64)) => (fun (rs_p : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (m : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (sz : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (v_as : (Option ((BitVec 64) × (BitVec 64)))) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev x (L4vRefX64.Spec.VMRights_A.validate_vm_rights rs) m sz v_as))))))) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ac)) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ac)) (fun (word : (BitVec 64)) => (fun (option : (Option ((BitVec 64) × (BitVec 64)))) => ac)) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => ac)) ac))) + +def aobj_ref : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Option (BitVec 64))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDPoolCap x uu) => (Option.some x) + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDControlCap => (Option.none (α := (BitVec 64))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap uv uw) => (Option.none (α := (BitVec 64))) + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortControlCap => (Option.none (α := (BitVec 64))) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap ux x uy uz va vb) => (Option.some x) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap x vc) => (Option.some x) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap x vd) => (Option.some x) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap x ve) => (Option.some x) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap x vf) => (Option.some x) + +def arch_cap.acap_asid_base : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (BitVec 64)) + | arch_cap => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (x11 : (BitVec 64)) => (fun (x12 : (BitVec 64)) => x12)) (holUndefined (α := (BitVec 64))) (fun (uu : (BitVec 16)) => (fun (uu_1 : (BitVec 16)) => (holUndefined (α := (BitVec 64))))) (holUndefined (α := (BitVec 64))) (fun (uu : Bool) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (uu_3 : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (uu_4 : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (uu_5 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (BitVec 64))))) arch_cap) + +def arch_cap.acap_asid_pool : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (BitVec 64)) + | arch_cap => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (x11 : (BitVec 64)) => (fun (x12 : (BitVec 64)) => x11)) (holUndefined (α := (BitVec 64))) (fun (uu : (BitVec 16)) => (fun (uu_1 : (BitVec 16)) => (holUndefined (α := (BitVec 64))))) (holUndefined (α := (BitVec 64))) (fun (uu : Bool) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (uu_3 : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (uu_4 : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (uu_5 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (BitVec 64))))) arch_cap) + +def arch_cap.acap_io_port_first_port : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (BitVec 16)) + | arch_cap => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (BitVec 16))))) (holUndefined (α := (BitVec 16))) (fun (x31 : (BitVec 16)) => (fun (x32 : (BitVec 16)) => x31)) (holUndefined (α := (BitVec 16))) (fun (uu : Bool) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (uu_3 : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (uu_4 : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (uu_5 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (BitVec 16))))) arch_cap) + +def arch_cap.acap_io_port_last_port : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (BitVec 16)) + | arch_cap => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (BitVec 16))))) (holUndefined (α := (BitVec 16))) (fun (x31 : (BitVec 16)) => (fun (x32 : (BitVec 16)) => x32)) (holUndefined (α := (BitVec 16))) (fun (uu : Bool) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (uu_3 : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (uu_4 : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (uu_5 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (BitVec 16))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (BitVec 16))))) arch_cap) + +def arch_cap.acap_rights : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Set L4vRefX64.Spec.CapRights_A.rights)) + | arch_cap => (L4vRefX64.Spec.Arch_Structs_A.case_arch_cap (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))) (fun (uu : (BitVec 16)) => (fun (uu_1 : (BitVec 16)) => (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))) (fun (x51 : Bool) => (fun (x52 : (BitVec 64)) => (fun (x53 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (x54 : L4vRefX64.Spec.MachineTypes.vmmap_type) => (fun (x55 : L4vRefX64.Spec.MachineTypes.vmpage_size) => (fun (x56 : (Option ((BitVec 64) × (BitVec 64)))) => x53)))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option ((BitVec 64) × (BitVec 64)))) => (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) arch_cap) + +def arch_cap_badge : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Option (BitVec 64))) := + (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (Option.none (α := (BitVec 64)))) + +def arch_cap_is_device : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → Bool) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDPoolCap uu uv) => false + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDControlCap => false + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap uw ux) => false + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortControlCap => false + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap is_dev uy uz va vb vc) => is_dev + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap vd ve) => false + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap vf vg) => false + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap vh vi) => false + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap vj vk) => false + +def arch_default_cap : (L4vRefX64.Spec.Arch_Structs_A.aobject_type → ((BitVec 64) → (Nat → (Bool → L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) := + (fun (tp : L4vRefX64.Spec.Arch_Structs_A.aobject_type) => (fun (r : (BitVec 64)) => (fun (n : Nat) => (fun (dev : Bool) => (L4vRefX64.Spec.Arch_Structs_A.case_aobject_type (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev r L4vRefX64.Spec.VMRights_A.vm_read_write L4vRefX64.Spec.MachineTypes.vmmap_type.VMNoMap L4vRefX64.Spec.MachineTypes.vmpage_size.X64SmallPage (Option.none (α := ((BitVec 64) × (BitVec 64))))) (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev r L4vRefX64.Spec.VMRights_A.vm_read_write L4vRefX64.Spec.MachineTypes.vmmap_type.VMNoMap L4vRefX64.Spec.MachineTypes.vmpage_size.X64LargePage (Option.none (α := ((BitVec 64) × (BitVec 64))))) (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap dev r L4vRefX64.Spec.VMRights_A.vm_read_write L4vRefX64.Spec.MachineTypes.vmmap_type.VMNoMap L4vRefX64.Spec.MachineTypes.vmpage_size.X64HugePage (Option.none (α := ((BitVec 64) × (BitVec 64))))) (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap r (Option.none (α := ((BitVec 64) × (BitVec 64))))) (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap r (Option.none (α := ((BitVec 64) × (BitVec 64))))) (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap r (Option.none (α := ((BitVec 64) × (BitVec 64))))) (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap r (Option.none (α := (BitVec 64)))) (L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDPoolCap r (HolZero.zeroVal (α := (BitVec 64)))) tp))))) + +def arch_is_frame_type : (L4vRefX64.Spec.Arch_Structs_A.aobject_type → Bool) := + (fun (aobj : L4vRefX64.Spec.Arch_Structs_A.aobject_type) => (L4vRefX64.Spec.Arch_Structs_A.case_aobject_type true true true false false false false false aobj)) + +def table_size : Nat := + (HolAdd.addVal L4vRefX64.Spec.MachineTypes.ptTranslationBits (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat)) + +def arch_kobj_size : (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj → Nat) + | (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.ASIDPool uu) => L4vRefX64.Spec.MachineTypes.pageBits + | (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageTable uv) => L4vRefX64.Spec.Arch_Structs_A.table_size + | (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageDirectory uw) => L4vRefX64.Spec.Arch_Structs_A.table_size + | (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PDPointerTable ux) => L4vRefX64.Spec.Arch_Structs_A.table_size + | (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageMapL4 uy) => L4vRefX64.Spec.Arch_Structs_A.table_size + | (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.DataPage uz sz) => (L4vRefX64.Spec.MachineTypes.pageBitsForSize sz) + +def arch_obj_size : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → Nat) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDPoolCap uu uv) => L4vRefX64.Spec.MachineTypes.pageBits + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.ASIDControlCap => (HolZero.zeroVal (α := Nat)) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortCap uw ux) => (HolZero.zeroVal (α := Nat)) + | L4vRefX64.Spec.Arch_Structs_A.arch_cap.IOPortControlCap => (HolZero.zeroVal (α := Nat)) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageCap uy uz va vb sz vc) => (L4vRefX64.Spec.MachineTypes.pageBitsForSize sz) + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageTableCap vd ve) => L4vRefX64.Spec.Arch_Structs_A.table_size + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PageDirectoryCap vf vg) => L4vRefX64.Spec.Arch_Structs_A.table_size + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PDPointerTableCap vh vi) => L4vRefX64.Spec.Arch_Structs_A.table_size + | (L4vRefX64.Spec.Arch_Structs_A.arch_cap.PML4Cap vj vk) => L4vRefX64.Spec.Arch_Structs_A.table_size + +def arch_tcb_context_get : ((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → L4vRefX64.Spec.MachineOps.user_context) := + (fun (a_tcb : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext.tcb_context a_tcb)) + +def arch_tcb_context_set : (L4vRefX64.Spec.MachineOps.user_context → ((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit))) := + (fun (uc : L4vRefX64.Spec.MachineOps.user_context) => (fun (a_tcb : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_tcb.tcb_context_update (fun (uu_ : L4vRefX64.Spec.MachineOps.user_context) => uc) a_tcb))) + +def arch_tcb_get_registers : ((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) := + (fun (a_tcb : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) => (L4vRefX64.Spec.MachineOps.user_context.user_regs (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext.tcb_context a_tcb))) + +def arch_tcb_set_registers : ((L4vRefX64.Spec.MachineTypes.register → (BitVec 64)) → ((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit))) := + (fun (regs : (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) => (fun (a_tcb : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_tcb.tcb_context_update (fun (uu_ : L4vRefX64.Spec.MachineOps.user_context) => (L4vRefX64.Spec.MachineOps.user_context.UserContext (L4vRefX64.Spec.MachineOps.user_context.user_fpu_state (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext.tcb_context a_tcb)) regs)) a_tcb))) + +def badge_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 64) + +def cr3_base_address : (L4vRefX64.Spec.Arch_Structs_A.cr3 → (BitVec 64)) + | (L4vRefX64.Spec.Arch_Structs_A.cr3.mk addr uu) => addr + +def cr3_pcid : (L4vRefX64.Spec.Arch_Structs_A.cr3 → (BitVec 64)) + | (L4vRefX64.Spec.Arch_Structs_A.cr3.mk uu pcid) => pcid + +def cte_level_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 5) + +def default_arch_object : (L4vRefX64.Spec.Arch_Structs_A.aobject_type → (Bool → (Nat → L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) := + (fun (tp : L4vRefX64.Spec.Arch_Structs_A.aobject_type) => (fun (dev : Bool) => (fun (n : Nat) => (L4vRefX64.Spec.Arch_Structs_A.case_aobject_type (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.DataPage dev L4vRefX64.Spec.MachineTypes.vmpage_size.X64SmallPage) (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.DataPage dev L4vRefX64.Spec.MachineTypes.vmpage_size.X64LargePage) (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.DataPage dev L4vRefX64.Spec.MachineTypes.vmpage_size.X64HugePage) (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageTable (fun (x : (BitVec 9)) => L4vRefX64.Spec.Arch_Structs_A.pte.InvalidPTE)) (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageDirectory (fun (x : (BitVec 9)) => L4vRefX64.Spec.Arch_Structs_A.pde.InvalidPDE)) (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PDPointerTable (fun (x : (BitVec 9)) => L4vRefX64.Spec.Arch_Structs_A.pdpte.InvalidPDPTE)) (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageMapL4 (fun (x : (BitVec 9)) => L4vRefX64.Spec.Arch_Structs_A.pml4e.InvalidPML4E)) (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.ASIDPool (fun (uu_ : (BitVec 9)) => (Option.none (α := (BitVec 64))))) tp)))) + +def default_arch_tcb : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) := + (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext.mk L4vRefX64.Spec.Machine_A.new_context false ()) + +def endpoint_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 4) + +def iocte.address_width : (L4vRefX64.Spec.Arch_Structs_A.iocte → Nat) + | iocte => (L4vRefX64.Spec.Arch_Structs_A.case_iocte (holUndefined (α := Nat)) (fun (x21 : (BitVec 16)) => (fun (x22 : Bool) => (fun (x23 : Nat) => (fun (x24 : (BitVec 64)) => (fun (x25 : L4vRefX64.Spec.Arch_Structs_A.translation_type) => (fun (x26 : Bool) => x23)))))) iocte) + +def iocte.domain_id : (L4vRefX64.Spec.Arch_Structs_A.iocte → (BitVec 16)) + | iocte => (L4vRefX64.Spec.Arch_Structs_A.case_iocte (holUndefined (α := (BitVec 16))) (fun (x21 : (BitVec 16)) => (fun (x22 : Bool) => (fun (x23 : Nat) => (fun (x24 : (BitVec 64)) => (fun (x25 : L4vRefX64.Spec.Arch_Structs_A.translation_type) => (fun (x26 : Bool) => x21)))))) iocte) + +def iocte.iocte_present : (L4vRefX64.Spec.Arch_Structs_A.iocte → Bool) + | iocte => (L4vRefX64.Spec.Arch_Structs_A.case_iocte (holUndefined (α := Bool)) (fun (x21 : (BitVec 16)) => (fun (x22 : Bool) => (fun (x23 : Nat) => (fun (x24 : (BitVec 64)) => (fun (x25 : L4vRefX64.Spec.Arch_Structs_A.translation_type) => (fun (x26 : Bool) => x26)))))) iocte) + +def iocte.next_level_ptr : (L4vRefX64.Spec.Arch_Structs_A.iocte → (BitVec 64)) + | iocte => (L4vRefX64.Spec.Arch_Structs_A.case_iocte (holUndefined (α := (BitVec 64))) (fun (x21 : (BitVec 16)) => (fun (x22 : Bool) => (fun (x23 : Nat) => (fun (x24 : (BitVec 64)) => (fun (x25 : L4vRefX64.Spec.Arch_Structs_A.translation_type) => (fun (x26 : Bool) => x24)))))) iocte) + +def iocte.res_mem_reg : (L4vRefX64.Spec.Arch_Structs_A.iocte → Bool) + | iocte => (L4vRefX64.Spec.Arch_Structs_A.case_iocte (holUndefined (α := Bool)) (fun (x21 : (BitVec 16)) => (fun (x22 : Bool) => (fun (x23 : Nat) => (fun (x24 : (BitVec 64)) => (fun (x25 : L4vRefX64.Spec.Arch_Structs_A.translation_type) => (fun (x26 : Bool) => x22)))))) iocte) + +def iocte.translation_type : (L4vRefX64.Spec.Arch_Structs_A.iocte → L4vRefX64.Spec.Arch_Structs_A.translation_type) + | iocte => (L4vRefX64.Spec.Arch_Structs_A.case_iocte (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.translation_type)) (fun (x21 : (BitVec 16)) => (fun (x22 : Bool) => (fun (x23 : Nat) => (fun (x24 : (BitVec 64)) => (fun (x25 : L4vRefX64.Spec.Arch_Structs_A.translation_type) => (fun (x26 : Bool) => x25)))))) iocte) + +def iotable_size : Nat := + (HolAdd.addVal L4vRefX64.Spec.MachineTypes.ptTranslationBits (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat))) + +def iopt_bits : Nat := + L4vRefX64.Spec.Arch_Structs_A.iotable_size + +def iopte.frame_ptr : (L4vRefX64.Spec.Arch_Structs_A.iopte → (BitVec 64)) + | iopte => (L4vRefX64.Spec.Arch_Structs_A.case_iopte (holUndefined (α := (BitVec 64))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x21)) iopte) + +def iopte.io_pte_rights : (L4vRefX64.Spec.Arch_Structs_A.iopte → (Set L4vRefX64.Spec.CapRights_A.rights)) + | iopte => (L4vRefX64.Spec.Arch_Structs_A.case_iopte (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x22)) iopte) + +def iorte.context_table : (L4vRefX64.Spec.Arch_Structs_A.iorte → (BitVec 64)) + | iorte => (L4vRefX64.Spec.Arch_Structs_A.case_iorte (holUndefined (α := (BitVec 64))) (fun (x21 : (BitVec 64)) => (fun (x22 : Bool) => x21)) iorte) + +def iorte.iorte_present : (L4vRefX64.Spec.Arch_Structs_A.iorte → Bool) + | iorte => (L4vRefX64.Spec.Arch_Structs_A.case_iorte (holUndefined (α := Bool)) (fun (x21 : (BitVec 64)) => (fun (x22 : Bool) => x22)) iorte) + +def ntfn_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 5) + +def parse_time_arg : (Nat → ((List (BitVec 64)) → (BitVec 64))) := + (fun (i : Nat) => (fun (args : (List (BitVec 64))) => ((holUcast (w := 64)) (holNth args i)))) + +def pd_bits : Nat := + L4vRefX64.Spec.Arch_Structs_A.table_size + +def pd_shift_bits : Nat := + (HolAdd.addVal L4vRefX64.Spec.MachineTypes.pageBits L4vRefX64.Spec.MachineTypes.ptTranslationBits) + +def pde.pde_attrs : (L4vRefX64.Spec.Arch_Structs_A.pde → (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) + | pde => (L4vRefX64.Spec.Arch_Structs_A.case_pde (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)))))) (fun (x31 : (BitVec 64)) => (fun (x32 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x33 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x32))) pde) + +def pde.pde_rights : (L4vRefX64.Spec.Arch_Structs_A.pde → (Set L4vRefX64.Spec.CapRights_A.rights)) + | pde => (L4vRefX64.Spec.Arch_Structs_A.case_pde (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x23))) (fun (x31 : (BitVec 64)) => (fun (x32 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x33 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x33))) pde) + +def pde.pt_attrs : (L4vRefX64.Spec.Arch_Structs_A.pde → (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) + | pde => (L4vRefX64.Spec.Arch_Structs_A.case_pde (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x22))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)))))) pde) + +def pdpt_bits : Nat := + L4vRefX64.Spec.Arch_Structs_A.table_size + +def pdpt_shift_bits : Nat := + (HolAdd.addVal (HolAdd.addVal L4vRefX64.Spec.MachineTypes.pageBits L4vRefX64.Spec.MachineTypes.ptTranslationBits) L4vRefX64.Spec.MachineTypes.ptTranslationBits) + +def pdpte.pdpt_attrs : (L4vRefX64.Spec.Arch_Structs_A.pdpte → (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) + | pdpte => (L4vRefX64.Spec.Arch_Structs_A.case_pdpte (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)))))) (fun (x31 : (BitVec 64)) => (fun (x32 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x33 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x32))) pdpte) + +def pdpte.pdpt_frame : (L4vRefX64.Spec.Arch_Structs_A.pdpte → (BitVec 64)) + | pdpte => (L4vRefX64.Spec.Arch_Structs_A.case_pdpte (holUndefined (α := (BitVec 64))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := (BitVec 64)))))) (fun (x31 : (BitVec 64)) => (fun (x32 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x33 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x31))) pdpte) + +def pdpte.pdpt_rights : (L4vRefX64.Spec.Arch_Structs_A.pdpte → (Set L4vRefX64.Spec.CapRights_A.rights)) + | pdpte => (L4vRefX64.Spec.Arch_Structs_A.case_pdpte (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x23))) (fun (x31 : (BitVec 64)) => (fun (x32 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x33 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x33))) pdpte) + +def pdpte.pdpt_table : (L4vRefX64.Spec.Arch_Structs_A.pdpte → (BitVec 64)) + | pdpte => (L4vRefX64.Spec.Arch_Structs_A.case_pdpte (holUndefined (α := (BitVec 64))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x21))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := (BitVec 64)))))) pdpte) + +def pdpte.pdpt_table_attrs : (L4vRefX64.Spec.Arch_Structs_A.pdpte → (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) + | pdpte => (L4vRefX64.Spec.Arch_Structs_A.case_pdpte (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x22))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)))))) pdpte) + +def pml4_bits : Nat := + L4vRefX64.Spec.Arch_Structs_A.table_size + +def pml4_shift_bits : Nat := + (HolAdd.addVal (HolAdd.addVal (HolAdd.addVal L4vRefX64.Spec.MachineTypes.pageBits L4vRefX64.Spec.MachineTypes.ptTranslationBits) L4vRefX64.Spec.MachineTypes.ptTranslationBits) L4vRefX64.Spec.MachineTypes.ptTranslationBits) + +def pml4e.pml4_table : (L4vRefX64.Spec.Arch_Structs_A.pml4e → (BitVec 64)) + | pml4e => (L4vRefX64.Spec.Arch_Structs_A.case_pml4e (holUndefined (α := (BitVec 64))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x21))) pml4e) + +def pml4e.pml4e_attrs : (L4vRefX64.Spec.Arch_Structs_A.pml4e → (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) + | pml4e => (L4vRefX64.Spec.Arch_Structs_A.case_pml4e (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x22))) pml4e) + +def pml4e.pml4e_rights : (L4vRefX64.Spec.Arch_Structs_A.pml4e → (Set L4vRefX64.Spec.CapRights_A.rights)) + | pml4e => (L4vRefX64.Spec.Arch_Structs_A.case_pml4e (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x23))) pml4e) + +def pt_bits : Nat := + L4vRefX64.Spec.Arch_Structs_A.table_size + +def pt_shift_bits : Nat := + L4vRefX64.Spec.MachineTypes.pageBits + +def pte.pte_attrs : (L4vRefX64.Spec.Arch_Structs_A.pte → (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) + | pte => (L4vRefX64.Spec.Arch_Structs_A.case_pte (holUndefined (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x22))) pte) + +def pte.pte_frame : (L4vRefX64.Spec.Arch_Structs_A.pte → (BitVec 64)) + | pte => (L4vRefX64.Spec.Arch_Structs_A.case_pte (holUndefined (α := (BitVec 64))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x21))) pte) + +def pte.pte_rights : (L4vRefX64.Spec.Arch_Structs_A.pte → (Set L4vRefX64.Spec.CapRights_A.rights)) + | pte => (L4vRefX64.Spec.Arch_Structs_A.case_pte (holUndefined (α := (Set L4vRefX64.Spec.CapRights_A.rights))) (fun (x21 : (BitVec 64)) => (fun (x22 : (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute)) => (fun (x23 : (Set L4vRefX64.Spec.CapRights_A.rights)) => x23))) pte) + +def reply_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 5) + +def tcb_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 11) + +def untyped_max_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 47) + +def untyped_min_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 4) + +def vtd_cte_size_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 8) + +def vtd_pt_bits : Nat := + L4vRefX64.Spec.Arch_Structs_A.iotable_size + +def words_from_time : ((BitVec 64) → (List (BitVec 64))) := + (fun (t : (BitVec 64)) => (List.cons ((holUcast (w := 64)) t) (List.nil (α := (BitVec 64))))) + +def x64_num_io_pt_levels : Nat := + (HolNumeral.ofNatVal (α := Nat) 4) +end +end L4vRefX64.Spec.Arch_Structs_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_Structs_B.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_Structs_B.lean new file mode 100644 index 000000000..421420b21 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Arch_Structs_B.lean @@ -0,0 +1,31 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.Arch_Structs_B) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Time + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Arch_Structs_B +open L4vRefX64.Prim +open Classical +noncomputable section +inductive x64vspace_region_use where + | X64VSpaceUserRegion + | X64VSpaceInvalidRegion + | X64VSpaceKernelWindow + | X64VSpaceDeviceWindow +instance : Nonempty x64vspace_region_use := ⟨x64vspace_region_use.X64VSpaceUserRegion⟩ +def case_x64vspace_region_use {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) : x64vspace_region_use → r_ty + | .X64VSpaceUserRegion => f0 + | .X64VSpaceInvalidRegion => f1 + | .X64VSpaceKernelWindow => f2 + | .X64VSpaceDeviceWindow => f3 + +def parseTimeArg : (Nat → ((List (BitVec 64)) → (BitVec 64))) := + (fun (i : Nat) => (fun (args : (List (BitVec 64))) => ((holUcast (w := 64)) (holNth args i)))) + +def timerPrecision : (BitVec 64) := + (L4vRefX64.Spec.Time.us_to_ticks (HolOne.oneVal (α := (BitVec 64)))) +end +end L4vRefX64.Spec.Arch_Structs_B diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CSpaceAcc_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CSpaceAcc_A.lean new file mode 100644 index 000000000..e195da495 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CSpaceAcc_A.lean @@ -0,0 +1,52 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.CSpaceAcc_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.CSpaceAcc_A +open L4vRefX64.Prim +open Classical +noncomputable section +def is_cdt_parent : ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → Bool))) := + (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (fun (p : ((BitVec 64) × (List Bool))) => (fun (c : ((BitVec 64) × (List Bool))) => (holEq (t c) (Option.some p))))) + +def cdt_parent_rel : ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (Set (((BitVec 64) × (List Bool)) × ((BitVec 64) × (List Bool))))) := + (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holCollect (holCaseProd (fun (p : ((BitVec 64) × (List Bool))) => (fun (c : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.CSpaceAcc_A.is_cdt_parent t p c)))))) + +def descendants_of : (((BitVec 64) × (List Bool)) → ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (Set ((BitVec 64) × (List Bool))))) := + (fun (p : ((BitVec 64) × (List Bool))) => (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holCollect (fun (q : ((BitVec 64) × (List Bool))) => (holMember (Prod.mk p q) (holTrancl (L4vRefX64.Spec.CSpaceAcc_A.cdt_parent_rel t))))))) + +def get_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.cap × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (holCaseProd (fun (oref : (BitVec 64)) => (fun (cref : (List Bool)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object oref) (fun (obj : L4vRefX64.Spec.Structures_A.kernel_object) => (holBind (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (sz : Nat) => (fun (cnode : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holBind (holAssert (L4vRefX64.Spec.Structures_A.well_formed_cnode_n sz cnode)) (holKBind (holReturn cnode))))) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holReturn (L4vRefX64.Spec.Structures_A.tcb_cnode_map tcb))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) obj) (fun (caps : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holAssertOpt (caps cref))))))))) + +def ensure_empty {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holWhenE (holNot (holEq cap L4vRefX64.Spec.Structures_A.cap.NullCap)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst))))) + +def parent_of : ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → Bool))) := + (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (fun (p : ((BitVec 64) × (List Bool))) => (fun (c : ((BitVec 64) × (List Bool))) => (holMember (Prod.mk p c) (L4vRefX64.Spec.CSpaceAcc_A.cdt_parent_rel t))))) + +def parent_of_rtrancl : ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → Bool))) := + (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (fun (x : ((BitVec 64) × (List Bool))) => (fun (y : ((BitVec 64) × (List Bool))) => (holMember (Prod.mk x y) (holRtrancl (L4vRefX64.Spec.CSpaceAcc_A.cdt_parent_rel t)))))) + +def parent_of_trancl : ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → Bool))) := + (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (fun (x : ((BitVec 64) × (List Bool))) => (fun (y : ((BitVec 64) × (List Bool))) => (holMember (Prod.mk x y) (holTrancl (L4vRefX64.Spec.CSpaceAcc_A.cdt_parent_rel t)))))) + +def set_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holCaseProd (fun (oref : (BitVec 64)) => (fun (cref : (List Bool)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object oref) (fun (obj : L4vRefX64.Spec.Structures_A.kernel_object) => (holBind (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (sz : Nat) => (fun (cn : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holIf (holConj (holMember cref (holDom cn)) (L4vRefX64.Spec.Structures_A.well_formed_cnode_n sz cn)) (holFunApp holReturn (holFunApp (L4vRefX64.Spec.Structures_A.kernel_object.CNode sz) (holFunUpd cn cref (Option.some cap)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holIf (holEq cref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolZero.zeroVal (α := Nat)))) (holFunApp holReturn (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb.tcb_ctable_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => cap) tcb))) (holIf (holEq cref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolOne.oneVal (α := Nat)))) (holFunApp holReturn (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb.tcb_vtable_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => cap) tcb))) (holIf (holEq cref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 2))) (holFunApp holReturn (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb.tcb_ipcframe_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => cap) tcb))) (holIf (holEq cref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 3))) (holFunApp holReturn (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb.tcb_fault_handler_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => cap) tcb))) (holIf (holEq cref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 4))) (holFunApp holReturn (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb.tcb_timeout_handler_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => cap) tcb))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) obj) (fun (obj_p : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.KHeap_A.set_object oref obj_p))))))))) + +def set_cdt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holFunApp holPut (L4vRefX64.Spec.Structures_A.abstract_state.cdt_update (fun (uu_ : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => t) s))))) + +def set_original {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (v : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.is_original_cap) (fun (r : (((BitVec 64) × (List Bool)) → Bool)) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.is_original_cap_update (fun (uu_ : (((BitVec 64) × (List Bool)) → Bool)) => (holFunUpd r slot v)) s))))))) + +def update_cdt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (f : ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt) (fun (t : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.CSpaceAcc_A.set_cdt (f t))))) +end +end L4vRefX64.Spec.CSpaceAcc_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CSpace_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CSpace_A.lean new file mode 100644 index 000000000..16a14ed40 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CSpace_A.lean @@ -0,0 +1,274 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.CSpace_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchCSpace_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.SchedContext_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.CSpace_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive capclass where + | PhysicalClass + | OtherCapClass +instance : Nonempty capclass := ⟨capclass.PhysicalClass⟩ +def case_capclass {r_ty : Type} (f0 : r_ty) (f1 : r_ty) : capclass → r_ty + | .PhysicalClass => f0 + | .OtherCapClass => f1 + +inductive rec_del_call where + | CTEDeleteCall (a0 : ((BitVec 64) × (List Bool))) (a1 : Bool) + | FinaliseSlotCall (a0 : ((BitVec 64) × (List Bool))) (a1 : Bool) + | ReduceZombieCall (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) (a2 : Bool) +instance : Nonempty rec_del_call := ⟨rec_del_call.CTEDeleteCall holUndefined holUndefined⟩ +def case_rec_del_call {r_ty : Type} (f0 : ((BitVec 64) × (List Bool)) → Bool → r_ty) (f1 : ((BitVec 64) × (List Bool)) → Bool → r_ty) (f2 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → Bool → r_ty) : rec_del_call → r_ty + | .CTEDeleteCall x0 x1 => f0 x0 x1 + | .FinaliseSlotCall x0 x1 => f1 x0 x1 + | .ReduceZombieCall x0 x1 x2 => f2 x0 x1 x2 + +def can_fast_finalise : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap true (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (r : (BitVec 64)) => (fun (b : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => true))) (fun (r : (BitVec 64)) => (fun (b : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => true))) (fun (r : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => true)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => false))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => false) cap)) + +def cap_cyclic_zombie : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → Bool)) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (slot_p : (BitVec 64)) => (fun (bits : (Option Nat)) => (fun (n : Nat) => (holEq (Prod.mk slot_p (holListReplicate (L4vRefX64.Spec.Structures_A.zombie_cte_bits bits) false)) slot)))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => false) cap))) + +def cap_removeable : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → Bool)) + | L4vRefX64.Spec.Structures_A.cap.NullCap, slot => true + | (L4vRefX64.Spec.Structures_A.cap.Zombie slot_p bits n), slot => (holDisj (holEq n (HolZero.zeroVal (α := Nat))) (holConj (holEq n (HolOne.oneVal (α := Nat))) (holEq (Prod.mk slot_p (holListReplicate (L4vRefX64.Spec.Structures_A.zombie_cte_bits bits) false)) slot))) + | _, _ => holUndefined + +def cap_swap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (cap1 : L4vRefX64.Spec.Structures_A.cap) => (fun (slot1 : ((BitVec 64) × (List Bool))) => (fun (cap2 : L4vRefX64.Spec.Structures_A.cap) => (fun (slot2 : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap cap2 slot1) (holKBind (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap cap1 slot2) (holKBind (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s slot1))) (fun (slot1_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s slot2))) (fun (slot2_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt) (fun (cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBind (holReturn (fun (n : ((BitVec 64) × (List Bool))) => (holIf (holEq (cdt n) (Option.some slot1)) (Option.some slot2) (holIf (holEq (cdt n) (Option.some slot2)) (Option.some slot1) (cdt n))))) (fun (cdt_p : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cdt (holFunUpd (holFunUpd cdt_p slot1 (cdt_p slot2)) slot2 (cdt_p slot1))) (holKBind (holBind (L4vRefX64.Spec.Deterministic_A.do_extended_op (L4vRefX64.Spec.Deterministic_A.cap_swap_ext slot1 slot2 slot1_p slot2_p)) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.is_original_cap) (fun (is_original : (((BitVec 64) × (List Bool)) → Bool)) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_original slot1 (is_original slot2)) (holKBind (L4vRefX64.Spec.CSpaceAcc_A.set_original slot2 (is_original slot1)))))))))))))))))))))))))) + +def cap_swap_for_delete {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (slot1 : ((BitVec 64) × (List Bool))) => (fun (slot2 : ((BitVec 64) × (List Bool))) => (holFunApp (holWhen (holNot (holEq slot1 slot2))) (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot1) (fun (cap1 : L4vRefX64.Spec.Structures_A.cap) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot2) (fun (cap2 : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.CSpace_A.cap_swap cap1 slot1 cap2 slot2)))))))) + +def fast_finalise {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | L4vRefX64.Spec.Structures_A.cap.NullCap, final => (holReturn ()) + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap r uu), final => (holFunApp (holWhen final) (holBind (holLiftM L4vRefX64.Spec.Structures_A.reply_ext.reply_tcb (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply r)) (holCaseOption (holReturn ()) (fun (tp : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tp) (L4vRefX64.Spec.Structures_A.case_thread_state (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp) (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp) (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (fun (receiver_payload_ext : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp)))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp))) (L4vRefX64.Spec.IpcCancel_A.reply_remove tp) (fun (word : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp)) (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp))))))) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap r b R), final => (holFunApp (holWhen final) (L4vRefX64.Spec.IpcCancel_A.cancel_all_ipc r)) + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap r b R), final => (holFunApp (holWhen final) (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_maybe_unbind_ntfn r) (holKBind (holBind (L4vRefX64.Spec.IpcCancel_A.unbind_maybe_notification r) (holKBind (L4vRefX64.Spec.IpcCancel_A.cancel_all_signals r)))))) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc), uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb), uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap v), uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | L4vRefX64.Spec.Structures_A.cap.DomainCap, uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va), uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap, uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap, uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v), uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb), uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v), uw => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + +def cap_delete_one {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holFunApp (holUnless (holEq cap L4vRefX64.Spec.Structures_A.cap.NullCap)) (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holBind (L4vRefX64.Spec.CSpace_A.fast_finalise cap final) (holKBind (L4vRefX64.Spec.IpcCancel_A.empty_slot slot L4vRefX64.Spec.Structures_A.cap.NullCap))))))))) + +def deleting_irq_handler {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.get_irq_slot irq) (fun (slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.CSpace_A.cap_delete_one slot)))) + +def finalise_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.cap × L4vRefX64.Spec.Structures_A.cap) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | L4vRefX64.Spec.Structures_A.cap.NullCap, final => (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev r bits f), final => (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap r uu), final => (holFunApp (holLiftM (holK (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap))) (holFunApp (holWhen final) (holBind (holLiftM L4vRefX64.Spec.Structures_A.reply_ext.reply_tcb (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply r)) (holCaseOption (holReturn ()) (fun (tp : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tp) (L4vRefX64.Spec.Structures_A.case_thread_state (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp) (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp) (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (fun (receiver_payload_ext : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp)))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp))) (L4vRefX64.Spec.IpcCancel_A.reply_remove tp) (fun (word : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp)) (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tp)))))))) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap r b R), final => (holFunApp (holLiftM (holK (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap))) (holFunApp (holWhen final) (L4vRefX64.Spec.IpcCancel_A.cancel_all_ipc r))) + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap r b R), final => (holFunApp (holLiftM (holK (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap))) (holFunApp (holWhen final) (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_maybe_unbind_ntfn r) (holKBind (holBind (L4vRefX64.Spec.IpcCancel_A.unbind_maybe_notification r) (holKBind (L4vRefX64.Spec.IpcCancel_A.cancel_all_signals r))))))) + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap r bits g), final => (holReturn (Prod.mk (holIf final (L4vRefX64.Spec.Structures_A.cap.Zombie r (Option.some bits) (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) bits)) L4vRefX64.Spec.Structures_A.cap.NullCap) L4vRefX64.Spec.Structures_A.cap.NullCap)) + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap r), final => (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.IpcCancel_A.unbind_notification r)) (holKBind (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.SchedContext_A.unbind_from_sc r)) (holKBind (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.SchedContext_A.suspend r)) (holKBind (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.ArchVSpace_A.prepare_thread_delete r)) (holKBind (holReturn (Prod.mk (holIf final (L4vRefX64.Spec.Structures_A.cap.Zombie r (Option.none (α := Nat)) (HolNumeral.ofNatVal (α := Nat) 5)) L4vRefX64.Spec.Structures_A.cap.NullCap) L4vRefX64.Spec.Structures_A.cap.NullCap)))))))))) + | L4vRefX64.Spec.Structures_A.cap.DomainCap, final => (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap sc bits), final => (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_all_tcbs sc)) (holKBind (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_ntfn sc)) (holKBind (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_reply sc)) (holKBind (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.SchedContext_A.sched_context_unbind_yield_from sc)) (holKBind (holBind (holFunApp (holWhen final) (L4vRefX64.Spec.SchedContext_A.sched_context_set_inactive sc)) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)))))))))))) + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap, final => (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) + | (L4vRefX64.Spec.Structures_A.cap.Zombie r b n), final => (holBind (holAssert final) (holKBind (holReturn (Prod.mk (L4vRefX64.Spec.Structures_A.cap.Zombie r b n) L4vRefX64.Spec.Structures_A.cap.NullCap)))) + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap, final => (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap)) + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap irq), final => (holIf final (holBind (L4vRefX64.Spec.CSpace_A.deleting_irq_handler irq) (holKBind (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap irq))))) (holReturn (Prod.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap))) + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap a), final => (L4vRefX64.Spec.ArchVSpace_A.arch_finalise_cap a final) + +def rec_del_graph {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → (((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → (((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool) → Bool))) => (fun (x1 : (L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (fun (x2 : ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) => (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall slot exposed) s)) (holConj (holEq x2 (holBindE (fun (x1_1 : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) x1_1))) (holCaseProd (fun (success : Bool) => (fun (cleanup_info : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holFunApp (holWhen (holDisj exposed success)) (L4vRefX64.Spec.IpcCancel_A.empty_slot slot cleanup_info))) (holKBind ((holReturnOk (ε := Unit)) (holUndefined (α := (Bool × L4vRefX64.Spec.Structures_A.cap))))))))) s)) (p (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) s) (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) s))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) s)) (holConj (holEq x2 (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holIf (holEq cap L4vRefX64.Spec.Structures_A.cap.NullCap) ((holReturnOk (ε := Unit)) (Prod.mk true L4vRefX64.Spec.Structures_A.cap.NullCap)) (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap)) (fun (is_final : Bool) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.finalise_cap cap is_final)) (holCaseProd (fun (remainder : L4vRefX64.Spec.Structures_A.cap) => (fun (cleanup_info : L4vRefX64.Spec.Structures_A.cap) => (holIf (L4vRefX64.Spec.CSpace_A.cap_removeable remainder slot) ((holReturnOk (ε := Unit)) (Prod.mk true cleanup_info)) (holIf (holConj (L4vRefX64.Spec.CSpace_A.cap_cyclic_zombie remainder slot) (holNot exposed)) (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.set_cap remainder slot)) (holKBind ((holReturnOk (ε := Unit)) (Prod.mk false L4vRefX64.Spec.Structures_A.cap.NullCap)))) (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.set_cap remainder slot)) (holKBind (holBindE (fun (x1_1 : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall remainder slot exposed) x1_1))) (holKBind (holBindE L4vRefX64.Spec.KHeap_A.preemption_point (holKBind (fun (x1_1 : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) x1_1))))))))))))))))))) s)) (holConj (holAll (fun (rv : L4vRefX64.Spec.Structures_A.cap) => (holAll (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rva : Bool) => (holAll (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvb : (L4vRefX64.Spec.Structures_A.cap × L4vRefX64.Spec.Structures_A.cap)) => (holAll (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvc : Unit) => (holAll (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holImp (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) s))) (holImp (holNot (holEq rv L4vRefX64.Spec.Structures_A.cap.NullCap)) (holImp (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.IpcCancel_A.is_final_cap rv) st))) (holImp (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.finalise_cap rv rva) sta))) (holImp (holNot (L4vRefX64.Spec.CSpace_A.cap_removeable (Prod.fst rvb) slot)) (holImp (holNot (holConj (L4vRefX64.Spec.CSpace_A.cap_cyclic_zombie (Prod.fst rvb) slot) (holNot exposed))) (holImp (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.set_cap (Prod.fst rvb) slot) stb))) (p (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (Prod.fst rvb) slot exposed) stc) (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (Prod.fst rvb) slot exposed) stc)))))))))))))))))))))))))) (holAll (fun (rv : L4vRefX64.Spec.Structures_A.cap) => (holAll (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rva : Bool) => (holAll (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvb : (L4vRefX64.Spec.Structures_A.cap × L4vRefX64.Spec.Structures_A.cap)) => (holAll (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvc : Unit) => (holAll (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvd : (Bool × L4vRefX64.Spec.Structures_A.cap)) => (holAll (fun (std : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rve : Unit) => (holAll (fun (ste : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holImp (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) s))) (holImp (holNot (holEq rv L4vRefX64.Spec.Structures_A.cap.NullCap)) (holImp (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.IpcCancel_A.is_final_cap rv) st))) (holImp (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.finalise_cap rv rva) sta))) (holImp (holNot (L4vRefX64.Spec.CSpace_A.cap_removeable (Prod.fst rvb) slot)) (holImp (holNot (holConj (L4vRefX64.Spec.CSpace_A.cap_cyclic_zombie (Prod.fst rvb) slot) (holNot exposed))) (holImp (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.set_cap (Prod.fst rvb) slot) stb))) (holImp (holMember (Prod.mk (Sum.inr rvd) std) (Prod.fst (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (Prod.fst rvb) slot exposed) stc)))) (holImp (holMember (Prod.mk (Sum.inr rve) ste) (Prod.fst (L4vRefX64.Spec.KHeap_A.preemption_point std))) (p (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) ste) (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) ste))))))))))))))))))))))))))))))))))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (ptr : (BitVec 64)) => (holEx (fun (bits : (Option Nat)) => (holEx (fun (n : Nat) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.Zombie ptr bits (Nat.succ n)) slot false) s)) (holEq x2 (holBindE (holFunApp (holReturnOk (ε := Unit)) (L4vRefX64.Spec.Structures_A.first_cslot_of (L4vRefX64.Spec.Structures_A.cap.Zombie ptr bits (Nat.succ n)))) (fun (cn : ((BitVec 64) × (List Bool))) => (holBindE ((holAssertE (ε := Unit)) (holNot (holEq cn slot))) (holKBind (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.cap_swap_for_delete cn slot)) (holKBind ((holReturnOk (ε := Unit)) (holUndefined (α := (Bool × L4vRefX64.Spec.Structures_A.cap))))))))) s))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (ptr : (BitVec 64)) => (holEx (fun (bits : (Option Nat)) => (holEx (fun (n : Nat) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.Zombie ptr bits (Nat.succ n)) slot true) s)) (holConj (holEq x2 (holBindE ((holReturnOk (ε := Unit)) (Prod.mk ptr (L4vRefX64.Spec.Machine_A.nat_to_cref (L4vRefX64.Spec.Structures_A.zombie_cte_bits bits) n))) (fun (end_slot : ((BitVec 64) × (List Bool))) => (holBindE (fun (x1_1 : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall end_slot false) x1_1))) (holKBind (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot)) (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holIf (holEq new_cap (L4vRefX64.Spec.Structures_A.cap.Zombie ptr bits (Nat.succ n))) (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.set_cap (L4vRefX64.Spec.Structures_A.cap.Zombie ptr bits n) slot)) ((holAssertE (ε := Unit)) (holDisj (holEq new_cap L4vRefX64.Spec.Structures_A.cap.NullCap) (holConj (L4vRefX64.Spec.Structures_A.is_zombie new_cap) (holConj (holEq (L4vRefX64.Spec.Structures_A.first_cslot_of new_cap) slot) (holNot (holEq (L4vRefX64.Spec.Structures_A.first_cslot_of (L4vRefX64.Spec.Structures_A.cap.Zombie ptr bits (Nat.succ n))) slot))))))) (holKBind ((holReturnOk (ε := Unit)) (holUndefined (α := (Bool × L4vRefX64.Spec.Structures_A.cap))))))))))) s)) (holAll (fun (rv : ((BitVec 64) × (List Bool))) => (holAll (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holImp (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst ((holReturnOk (ε := Unit)) (Prod.mk ptr (L4vRefX64.Spec.Machine_A.nat_to_cref (L4vRefX64.Spec.Structures_A.zombie_cte_bits bits) n)) s))) (p (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall rv false) st) (rec_del_sum (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall rv false) st)))))))))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.NullCap slot exposed) s)) (holEq x2 (holFail s))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : Bool) => (holEx (fun (va : (BitVec 64)) => (holEx (fun (vb : Nat) => (holEx (fun (vc : Nat) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) slot exposed) s)) (holEq x2 (holFail s))))))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (BitVec 64)) => (holEx (fun (vb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) slot exposed) s)) (holEq x2 (holFail s))))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (BitVec 64)) => (holEx (fun (vb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) slot exposed) s)) (holEq x2 (holFail s))))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) slot exposed) s)) (holEq x2 (holFail s))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : Nat) => (holEx (fun (vb : (List Bool)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) slot exposed) s)) (holEq x2 (holFail s))))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) slot exposed) s)) (holEq x2 (holFail s))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.DomainCap slot exposed) s)) (holEq x2 (holFail s))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : Nat) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) slot exposed) s)) (holEq x2 (holFail s))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.SchedControlCap slot exposed) s)) (holEq x2 (holFail s))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.IRQControlCap slot exposed) s)) (holEq x2 (holFail s))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 8)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) slot exposed) s)) (holEq x2 (holFail s))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (Option Nat)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.Zombie v va (HolZero.zeroVal (α := Nat))) slot exposed) s)) (holEq x2 (holFail s))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) slot exposed) s)) (holEq x2 (holFail s))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.NullCap slot true) s)) (holEq x2 (holFail s))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : Bool) => (holEx (fun (va : (BitVec 64)) => (holEx (fun (vb : Nat) => (holEx (fun (vc : Nat) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) slot true) s)) (holEq x2 (holFail s))))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (BitVec 64)) => (holEx (fun (vb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) slot true) s)) (holEq x2 (holFail s))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (BitVec 64)) => (holEx (fun (vb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) slot true) s)) (holEq x2 (holFail s))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) slot true) s)) (holEq x2 (holFail s))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : Nat) => (holEx (fun (vb : (List Bool)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) slot true) s)) (holEq x2 (holFail s))))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) slot true) s)) (holEq x2 (holFail s))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.DomainCap slot true) s)) (holEq x2 (holFail s))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : Nat) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) slot true) s)) (holEq x2 (holFail s))))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.SchedControlCap slot true) s)) (holEq x2 (holFail s))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall L4vRefX64.Spec.Structures_A.cap.IRQControlCap slot true) s)) (holEq x2 (holFail s))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 8)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) slot true) s)) (holEq x2 (holFail s))))))))))) (holDisj (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : (BitVec 64)) => (holEx (fun (va : (Option Nat)) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.Zombie v va (HolZero.zeroVal (α := Nat))) slot true) s)) (holEq x2 (holFail s))))))))))))) (holEx (fun (rec_del_sum : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (v : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) slot true) s)) (holEq x2 (holFail s)))))))))))))))))))))))))))))))))))))))))))))) + +def rec_del_sumC {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (fun (x : (L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (holTheDefault (holUndefined (α := ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (y : ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) => (L4vRefX64.Spec.CSpace_A.rec_del_graph x y)))) + +def rec_del {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.CSpace_A.rec_del_call → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (x0 : L4vRefX64.Spec.CSpace_A.rec_del_call) => (fun (x1 : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.CSpace_A.rec_del_sumC (Prod.mk x0 x1)))) + +def cap_delete {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | slot => (holBindE (L4vRefX64.Spec.CSpace_A.rec_del (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall slot true)) (holKBind ((holReturnOk (ε := Unit)) ()))) + +def is_cap_revocable : (L4vRefX64.Spec.Structures_A.cap → (L4vRefX64.Spec.Structures_A.cap → Bool)) := + (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (x : Bool) => (fun (xa : (BitVec 64)) => (fun (xb : Nat) => (fun (xc : Nat) => true)))) (fun (x : (BitVec 64)) => (fun (xa : (BitVec 64)) => (fun (xb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holNot (holEq (L4vRefX64.Spec.Structures_A.cap_ep_badge new_cap) (L4vRefX64.Spec.Structures_A.cap_ep_badge src_cap)))))) (fun (x : (BitVec 64)) => (fun (xa : (BitVec 64)) => (fun (xb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holNot (holEq (L4vRefX64.Spec.Structures_A.cap_ep_badge new_cap) (L4vRefX64.Spec.Structures_A.cap_ep_badge src_cap)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (x : (BitVec 8)) => (holEq src_cap L4vRefX64.Spec.Structures_A.cap.IRQControlCap)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => false))) (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.ArchCSpace_A.arch_is_cap_revocable new_cap src_cap)) new_cap))) + +def free_index_update : ((Nat → Nat) → (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap)) := + (fun (g : (Nat → Nat)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap cap (fun (dev : Bool) => (fun (ref : (BitVec 64)) => (fun (sz : Nat) => (fun (f : Nat) => (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev ref sz (g f)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => cap))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => cap))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => cap)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => cap))) (fun (word : (BitVec 64)) => cap) cap (fun (word : (BitVec 64)) => (fun (nat : Nat) => cap)) cap cap (fun (word : (BitVec 8)) => cap) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => cap))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => cap) cap))) + +def max_free_index : (Nat → Nat) := + (fun (magnitude_bits : Nat) => (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) magnitude_bits)) + +def untyped_sz_bits : (L4vRefX64.Spec.Structures_A.cap → Nat) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev ref sz f) => sz + | _ => holUndefined + +def set_untyped_cap_as_full {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (src_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (holIf (holConj (L4vRefX64.Spec.Structures_A.is_untyped_cap src_cap) (holConj (L4vRefX64.Spec.Structures_A.is_untyped_cap new_cap) (holConj (holEq (L4vRefX64.Spec.Structures_A.obj_ref_of src_cap) (L4vRefX64.Spec.Structures_A.obj_ref_of new_cap)) (holEq (L4vRefX64.Spec.Structures_A.cap_bits_untyped src_cap) (L4vRefX64.Spec.Structures_A.cap_bits_untyped new_cap))))) (L4vRefX64.Spec.CSpaceAcc_A.set_cap (L4vRefX64.Spec.CSpace_A.free_index_update (fun (uu_ : Nat) => (L4vRefX64.Spec.CSpace_A.max_free_index (L4vRefX64.Spec.CSpace_A.untyped_sz_bits src_cap))) src_cap) src_slot) (holReturn ()))))) + +def is_physical : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => true)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => true))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => true))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => true)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => true))) (fun (word : (BitVec 64)) => true) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => true)) false false (fun (x : (BitVec 8)) => false) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => true))) (fun (c : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.ArchCSpace_A.arch_is_physical c)) cap)) + +def same_region_as : (L4vRefX64.Spec.Structures_A.cap → (L4vRefX64.Spec.Structures_A.cap → Bool)) + | L4vRefX64.Spec.Structures_A.cap.NullCap, c_p => false + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev r bits free), c_p => (holConj (L4vRefX64.Spec.CSpace_A.is_physical c_p) (holConj (holLe r (L4vRefX64.Spec.Structures_A.obj_ref_of c_p)) (holConj (holLe (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) (HolSub.subVal (HolAdd.addVal (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) (L4vRefX64.Spec.Structures_A.obj_size c_p)) (HolOne.oneVal (α := (BitVec 64))))) (holLe (HolSub.subVal (HolAdd.addVal (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) (L4vRefX64.Spec.Structures_A.obj_size c_p)) (HolOne.oneVal (α := (BitVec 64)))) (HolSub.subVal (HolAdd.addVal r (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) bits)) (HolOne.oneVal (α := (BitVec 64)))))))) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap r b R), c_p => (holConj (L4vRefX64.Spec.Structures_A.is_ep_cap c_p) (holEq (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) r)) + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap r b R), c_p => (holConj (L4vRefX64.Spec.Structures_A.is_ntfn_cap c_p) (holEq (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) r)) + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap r bits g), c_p => (holConj (L4vRefX64.Spec.Structures_A.is_cnode_cap c_p) (holConj (holEq (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) r) (holEq (L4vRefX64.Spec.Structures_A.bits_of c_p) bits))) + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap n cr), c_p => (holEx (fun (cr_p : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEq c_p (L4vRefX64.Spec.Structures_A.cap.ReplyCap n cr_p)))) + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap r), c_p => (holConj (L4vRefX64.Spec.Structures_A.is_thread_cap c_p) (holEq (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) r)) + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap sc n), c_p => (holConj (L4vRefX64.Spec.Structures_A.is_sched_context_cap c_p) (holConj (holEq (L4vRefX64.Spec.Structures_A.obj_ref_of c_p) sc) (holEq (L4vRefX64.Spec.Structures_A.bits_of c_p) n))) + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap, c_p => (holEq c_p L4vRefX64.Spec.Structures_A.cap.SchedControlCap) + | (L4vRefX64.Spec.Structures_A.cap.Zombie r b n), c_p => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap, c_p => (holDisj (holEq c_p L4vRefX64.Spec.Structures_A.cap.IRQControlCap) (holDisj (holEx (fun (n : (BitVec 8)) => (holEq c_p (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap n)))) (holConj (L4vRefX64.Spec.Structures_A.cap.is_ArchObjectCap c_p) (L4vRefX64.Spec.ArchCSpace_A.is_irq_control_descendant (L4vRefX64.Spec.Structures_A.cap.the_arch_cap c_p))))) + | L4vRefX64.Spec.Structures_A.cap.DomainCap, c_p => (holEq c_p L4vRefX64.Spec.Structures_A.cap.DomainCap) + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap n), c_p => (holEq c_p (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap n)) + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap a), c_p => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => false))) (L4vRefX64.Spec.ArchCSpace_A.arch_same_region_as a) c_p) + +def should_be_parent_of : (L4vRefX64.Spec.Structures_A.cap → (Bool → (L4vRefX64.Spec.Structures_A.cap → (Bool → Bool)))) := + (fun (c : L4vRefX64.Spec.Structures_A.cap) => (fun (original : Bool) => (fun (c_p : L4vRefX64.Spec.Structures_A.cap) => (fun (original_p : Bool) => (holConj original (holConj (L4vRefX64.Spec.CSpace_A.same_region_as c c_p) (L4vRefX64.Spec.Structures_A.case_cap true (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => true)))) (fun (ref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holImp (holNot (holEq badge (HolZero.zeroVal (α := (BitVec 64))))) (holConj (holEq (L4vRefX64.Spec.Structures_A.cap_ep_badge c_p) badge) (holNot original_p)))))) (fun (ref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holImp (holNot (holEq badge (HolZero.zeroVal (α := (BitVec 64))))) (holConj (holEq (L4vRefX64.Spec.Structures_A.cap_ep_badge c_p) badge) (holNot original_p)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => true)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => true))) (fun (word : (BitVec 64)) => true) true (fun (word : (BitVec 64)) => (fun (nat : Nat) => true)) true true (fun (word : (BitVec 8)) => true) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => true))) (fun (ac : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.ArchCSpace_A.should_be_arch_parent_of ac (L4vRefX64.Spec.Structures_A.cap.the_arch_cap c_p) original_p)) c))))))) + +def cap_insert {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap src_slot) (fun (src_cap : L4vRefX64.Spec.Structures_A.cap) => (holBind (holFunApp holReturn (L4vRefX64.Spec.CSpace_A.is_cap_revocable new_cap src_cap)) (fun (dest_original : Bool) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap dest_slot) (fun (old_cap : L4vRefX64.Spec.Structures_A.cap) => (holBind (holAssert (holEq old_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) (holKBind (holBind (L4vRefX64.Spec.CSpace_A.set_untyped_cap_as_full src_cap new_cap src_slot) (holKBind (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap new_cap dest_slot) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.is_original_cap) (fun (is_original : (((BitVec 64) × (List Bool)) → Bool)) => (holBind (holFunApp holReturn (L4vRefX64.Spec.CSpace_A.should_be_parent_of src_cap (is_original src_slot) new_cap dest_original)) (fun (src_parent : Bool) => (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s src_slot))) (fun (src_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s dest_slot))) (fun (dest_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.update_cdt (fun (cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holFunUpd cdt dest_slot (holIf src_parent (Option.some src_slot) (cdt src_slot))))) (holKBind (holBind (L4vRefX64.Spec.Deterministic_A.do_extended_op (L4vRefX64.Spec.Deterministic_A.cap_insert_ext src_parent src_slot dest_slot src_p dest_p)) (holKBind (L4vRefX64.Spec.CSpaceAcc_A.set_original dest_slot dest_original)))))))))))))))))))))))))))) + +def cap_move {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap new_cap dest_slot) (holKBind (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap L4vRefX64.Spec.Structures_A.cap.NullCap src_slot) (holKBind (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s src_slot))) (fun (src_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s dest_slot))) (fun (dest_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt) (fun (cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBind (holFunApp holReturn (cdt src_slot)) (fun (parent : (Option ((BitVec 64) × (List Bool)))) => (holBind (holFunApp holReturn (holFunUpd (holFunUpd cdt dest_slot parent) src_slot (Option.none (α := ((BitVec 64) × (List Bool)))))) (fun (cdt_p : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cdt (fun (r : ((BitVec 64) × (List Bool))) => (holIf (holEq (cdt_p r) (Option.some src_slot)) (Option.some dest_slot) (cdt_p r)))) (holKBind (holBind (L4vRefX64.Spec.Deterministic_A.do_extended_op (L4vRefX64.Spec.Deterministic_A.cap_move_ext src_slot dest_slot src_p dest_p)) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.is_original_cap) (fun (is_original : (((BitVec 64) × (List Bool)) → Bool)) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_original dest_slot (is_original src_slot)) (holKBind (L4vRefX64.Spec.CSpaceAcc_A.set_original src_slot false)))))))))))))))))))))))))) + +def cap_revoke_graph {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → (((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → (((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool) → Bool))) => (fun (x1 : (((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (fun (x2 : ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) => (holEx (fun (cap_revoke_sum : ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk slot s)) (holConj (holEq x2 (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt)) (fun (cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holReturnOk (ε := Unit)) (L4vRefX64.Spec.CSpaceAcc_A.descendants_of slot cdt)) (fun (descendants : (Set ((BitVec 64) × (List Bool)))) => (holWhenE (holConj (holNot (holEq cap L4vRefX64.Spec.Structures_A.cap.NullCap)) (holNot (holEq descendants (HolCompleteLattice.holBot (α := (Set ((BitVec 64) × (List Bool)))))))) (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Deterministic_A.select_ext (L4vRefX64.Spec.Deterministic_A.next_revoke_cap slot) descendants)) (fun (child : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap child)) (fun (cap_1 : L4vRefX64.Spec.Structures_A.cap) => (holBindE ((holAssertE (ε := Unit)) (holNot (holEq cap_1 L4vRefX64.Spec.Structures_A.cap.NullCap))) (holKBind (holBindE (L4vRefX64.Spec.CSpace_A.cap_delete child) (holKBind (holBindE L4vRefX64.Spec.KHeap_A.preemption_point (holKBind (fun (x1_1 : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (cap_revoke_sum (Prod.mk slot x1_1))))))))))))))))))) s)) (holAll (fun (rv : L4vRefX64.Spec.Structures_A.cap) => (holAll (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rva : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holAll (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvb : (Set ((BitVec 64) × (List Bool)))) => (holAll (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvc : ((BitVec 64) × (List Bool))) => (holAll (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvd : L4vRefX64.Spec.Structures_A.cap) => (holAll (fun (std : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rve : Unit) => (holAll (fun (ste : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvf : Unit) => (holAll (fun (stf : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvg : Unit) => (holAll (fun (stg : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holImp (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) s))) (holImp (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt) st))) (holImp (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp (holReturnOk (ε := Unit)) (L4vRefX64.Spec.CSpaceAcc_A.descendants_of slot rva) sta))) (holImp (holConj (holNot (holEq rv L4vRefX64.Spec.Structures_A.cap.NullCap)) (holNot (holEq rvb (HolCompleteLattice.holBot (α := (Set ((BitVec 64) × (List Bool)))))))) (holImp (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Deterministic_A.select_ext (L4vRefX64.Spec.Deterministic_A.next_revoke_cap slot) rvb) stb))) (holImp (holMember (Prod.mk (Sum.inr rvd) std) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap rvc) stc))) (holImp (holMember (Prod.mk (Sum.inr rve) ste) (Prod.fst ((holAssertE (ε := Unit)) (holNot (holEq rvd L4vRefX64.Spec.Structures_A.cap.NullCap)) std))) (holImp (holMember (Prod.mk (Sum.inr rvf) stf) (Prod.fst (L4vRefX64.Spec.CSpace_A.cap_delete rvc ste))) (holImp (holMember (Prod.mk (Sum.inr rvg) stg) (Prod.fst (L4vRefX64.Spec.KHeap_A.preemption_point stf))) (p (Prod.mk slot stg) (cap_revoke_sum (Prod.mk slot stg)))))))))))))))))))))))))))))))))))))))))))))))))))))))) + +def cap_revoke_sumC {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (fun (x : (((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (holTheDefault (holUndefined (α := ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (y : ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) => (L4vRefX64.Spec.CSpace_A.cap_revoke_graph x y)))) + +def cap_revoke {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (x0 : ((BitVec 64) × (List Bool))) => (fun (x1 : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.CSpace_A.cap_revoke_sumC (Prod.mk x0 x1)))) + +def cap_revoke_rel {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → Bool))) => (fun (x1 : (((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (fun (x2 : (((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rv : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rva : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holEx (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvb : (Set ((BitVec 64) × (List Bool)))) => (holEx (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvc : ((BitVec 64) × (List Bool))) => (holEx (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvd : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (std : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rve : Unit) => (holEx (fun (ste : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvf : Unit) => (holEx (fun (stf : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvg : Unit) => (holEx (fun (stg : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk slot stg)) (holConj (holEq x2 (Prod.mk slot s)) (holConj (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) s))) (holConj (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt) st))) (holConj (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp (holReturnOk (ε := Unit)) (L4vRefX64.Spec.CSpaceAcc_A.descendants_of slot rva) sta))) (holConj (holConj (holNot (holEq rv L4vRefX64.Spec.Structures_A.cap.NullCap)) (holNot (holEq rvb (HolCompleteLattice.holBot (α := (Set ((BitVec 64) × (List Bool)))))))) (holConj (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Deterministic_A.select_ext (L4vRefX64.Spec.Deterministic_A.next_revoke_cap slot) rvb) stb))) (holConj (holMember (Prod.mk (Sum.inr rvd) std) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap rvc) stc))) (holConj (holMember (Prod.mk (Sum.inr rve) ste) (Prod.fst ((holAssertE (ε := Unit)) (holNot (holEq rvd L4vRefX64.Spec.Structures_A.cap.NullCap)) std))) (holConj (holMember (Prod.mk (Sum.inr rvf) stf) (Prod.fst (L4vRefX64.Spec.CSpace_A.cap_delete rvc ste))) (holMember (Prod.mk (Sum.inr rvg) stg) (Prod.fst (L4vRefX64.Spec.KHeap_A.preemption_point stf))))))))))))))))))))))))))))))))))))))))))))))))))))) + +def captransfer_from_words {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.captransfer_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.loadWord ptr)) (fun (w0 : (BitVec 64)) => (holBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.loadWord (HolAdd.addVal ptr (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : (BitVec 64))))) (fun (w1 : (BitVec 64)) => (holBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.loadWord (HolAdd.addVal ptr (HolMul.mulVal (HolNumeral.ofNatVal (α := (BitVec 64)) 2) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : (BitVec 64)))))) (fun (w2 : (BitVec 64)) => (holReturn (L4vRefX64.Spec.Structures_A.captransfer_ext.mk (L4vRefX64.Spec.Machine_A.data_to_cptr w0) (L4vRefX64.Spec.Machine_A.data_to_cptr w1) w2 ()))))))))) + +def data_to_rights : ((BitVec 64) → (Set L4vRefX64.Spec.CapRights_A.rights)) := + (fun (data : (BitVec 64)) => (holLet (L4vRefX64.Spec.Machine_A.data_to_16 data) (fun (w : (BitVec 16)) => (holCollect (fun (x : L4vRefX64.Spec.CapRights_A.rights) => (L4vRefX64.Spec.CapRights_A.case_rights (holWordBit w (HolOne.oneVal (α := Nat))) (holWordBit w (HolZero.zeroVal (α := Nat))) (holWordBit w (HolNumeral.ofNatVal (α := Nat) 2)) (holWordBit w (HolNumeral.ofNatVal (α := Nat) 3)) x)))))) + +def ensure_no_children {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (cslot_ptr : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt)) (fun (cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holWhenE (holEx (fun (c : ((BitVec 64) × (List Bool))) => (holEq (cdt c) (Option.some cslot_ptr)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst))))) + +def derive_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Structures_A.cap) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap) (fun (dev : Bool) => (fun (ptr : (BitVec 64)) => (fun (sz : Nat) => (fun (f : Nat) => (holBindE (L4vRefX64.Spec.CSpace_A.ensure_no_children slot) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap)))) (fun (word : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap)) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.cap.NullCap) (fun (word : (BitVec 8)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) cap)) (fun (ptr : (BitVec 64)) => (fun (n : (Option Nat)) => (fun (sz : Nat) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.cap.NullCap)))) (fun (c : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.ArchVSpace_A.arch_derive_cap c)) cap))) + +def exposed_rdcall : (L4vRefX64.Spec.CSpace_A.rec_del_call → Bool) + | (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall slot exposed) => exposed + | (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) => exposed + | (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall cap slot exposed) => exposed + +def finalise_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit (Bool × L4vRefX64.Spec.Structures_A.cap)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | p, e => (L4vRefX64.Spec.CSpace_A.rec_del (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall p e)) + +def get_badge : (L4vRefX64.Spec.Structures_A.cap → (Option (BitVec 64))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (Option.none (α := (BitVec 64))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (Option.none (α := (BitVec 64))))))) (fun (oref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (cr : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.some badge)))) (fun (oref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (cr : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.some badge)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.none (α := (BitVec 64))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (Option.none (α := (BitVec 64)))))) (fun (word : (BitVec 64)) => (Option.none (α := (BitVec 64)))) (Option.none (α := (BitVec 64))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (Option.none (α := (BitVec 64))))) (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (fun (word : (BitVec 8)) => (Option.none (α := (BitVec 64)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (Option.none (α := (BitVec 64)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (Option.none (α := (BitVec 64)))) cap)) + +def load_cap_transfer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.captransfer_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (buffer : (BitVec 64)) => (holBind (holFunApp holReturn (HolAdd.addVal (HolAdd.addVal L4vRefX64.Spec.Structures_A.msg_max_length L4vRefX64.Spec.Structures_A.msg_max_extra_caps) (HolNumeral.ofNatVal (α := Nat) 2))) (fun (offset : Nat) => (L4vRefX64.Spec.CSpace_A.captransfer_from_words (HolAdd.addVal buffer (HolMul.mulVal ((holOfNat (α := (BitVec 64))) offset) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : (BitVec 64)))))))) + +def resolve_address_bits'_graph {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → Bool))) => (fun (x1 : ((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool)))) => (fun (x2 : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holEx (fun (resolve_address_bits_p_sum : (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) => (holEx (fun (z : (HolItself tv_z)) => (holEx (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (cref : (List Bool)) => (holConj (holEq x1 (Prod.mk z (Prod.mk cap cref))) (holConj (holEq x2 (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) (fun (oref : (BitVec 64)) => (fun (radix_bits : Nat) => (fun (guard : (List Bool)) => (holIf (holEq (HolAdd.addVal radix_bits (holSize guard)) (HolZero.zeroVal (α := Nat))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holBindE (holWhenE (holNot (holLe guard cref)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.GuardMismatch (holSize cref) guard))) (holKBind (holBindE (holWhenE (holLt (holSize cref) (HolAdd.addVal radix_bits (holSize guard))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.DepthMismatch (holSize cref) (HolAdd.addVal radix_bits (holSize guard))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holListTake radix_bits (holListDrop (holSize guard) cref))) (fun (offset : (List Bool)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holListDrop (HolAdd.addVal radix_bits (holSize guard)) cref)) (fun (rest : (List Bool)) => (holIf (holEq rest (List.nil (α := Bool))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (Prod.mk (Prod.mk oref offset) (List.nil (α := Bool)))) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap (Prod.mk oref offset))) (fun (next_cap : L4vRefX64.Spec.Structures_A.cap) => (holIf (L4vRefX64.Spec.Structures_A.is_cnode_cap next_cap) (resolve_address_bits_p_sum (Prod.mk z (Prod.mk next_cap rest))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (Prod.mk (Prod.mk oref offset) rest)))))))))))))))))) (fun (word : (BitVec 64)) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))) ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot) (fun (word : (BitVec 8)) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := (((BitVec 64) × (List Bool)) × (List Bool)))) L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot)) cap)) (holAll (fun (x61 : (BitVec 64)) => (holAll (fun (x62 : Nat) => (holAll (fun (x63 : (List Bool)) => (holAll (fun (v : Unit) => (holAll (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (s_p : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rv : Unit) => (holAll (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rva : (List Bool)) => (holAll (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvb : (List Bool)) => (holAll (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holAll (fun (rvc : L4vRefX64.Spec.Structures_A.cap) => (holAll (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holImp (holEq cap (L4vRefX64.Spec.Structures_A.cap.CNodeCap x61 x62 x63)) (holImp (holNot (holEq (HolAdd.addVal x62 (holSize x63)) (HolZero.zeroVal (α := Nat)))) (holImp (holMember (Prod.mk (Sum.inr v) s_p) (Prod.fst (holWhenE (holNot (holLe x63 cref)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.GuardMismatch (holSize cref) x63)) s))) (holImp (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holWhenE (holLt (holSize cref) (HolAdd.addVal x62 (holSize x63))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.DepthMismatch (holSize cref) (HolAdd.addVal x62 (holSize x63)))) s_p))) (holImp (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holListTake x62 (holListDrop (holSize x63) cref)) st))) (holImp (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holListDrop (HolAdd.addVal x62 (holSize x63)) cref) sta))) (holImp (holNot (holEq rvb (List.nil (α := Bool)))) (holImp (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap (Prod.mk x61 rva)) stb))) (holImp (L4vRefX64.Spec.Structures_A.is_cnode_cap rvc) (p (Prod.mk z (Prod.mk rvc rvb)) (resolve_address_bits_p_sum (Prod.mk z (Prod.mk rvc rvb))))))))))))))))))))))))))))))))))))))))))))))))))))))) + +def resolve_address_bits'_sumC {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (x : ((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool)))) => (holTheDefault (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (y : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (L4vRefX64.Spec.CSpace_A.resolve_address_bits'_graph x y)))) + +def resolve_address_bits' {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((HolItself tv_z) → ((L4vRefX64.Spec.Structures_A.cap × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (x0 : (HolItself tv_z)) => (fun (x1 : (L4vRefX64.Spec.Structures_A.cap × (List Bool))) => (L4vRefX64.Spec.CSpace_A.resolve_address_bits'_sumC (Prod.mk x0 x1)))) + +def resolve_address_bits {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.cap × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (L4vRefX64.Spec.CSpace_A.resolve_address_bits' (HolItself.type (α := tv_z))) + +def lookup_slot_for_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List Bool) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (((BitVec 64) × (List Bool)) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (cref : (List Bool)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb thread))) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.CSpace_A.resolve_address_bits (Prod.mk (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_ctable tcb) cref)))))) + +def lookup_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List Bool) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure L4vRefX64.Spec.Structures_A.cap) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (ref : (List Bool)) => (holBindE (L4vRefX64.Spec.CSpace_A.lookup_slot_for_thread thread ref) (holCaseProd (fun (ref_p : ((BitVec 64) × (List Bool))) => (fun (uu_ : (List Bool)) => (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap ref_p)))))))) + +def lookup_slot_for_cnode_op {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → (L4vRefX64.Spec.Structures_A.cap → ((List Bool) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (is_source : Bool) => (fun (croot : L4vRefX64.Spec.Structures_A.cap) => (fun (ptr : (List Bool)) => (fun (depth : Nat) => (holIf (L4vRefX64.Spec.Structures_A.is_cnode_cap croot) (holBindE (holFunApp (holWhenE (holDisj (holLt depth (HolOne.oneVal (α := Nat))) (holLt L4vRefX64.Spec.Machine_Word_64_Basics.word_bits depth))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolOne.oneVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) L4vRefX64.Spec.Machine_Word_64_Basics.word_bits)))) (holKBind (holFunApp (L4vRefX64.Spec.Exceptions_A.lookup_error_on_failure is_source) (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holListDrop (HolSub.subVal (holSize ptr) depth) ptr)) (fun (ptrbits_for_depth : (List Bool)) => (holBindE (L4vRefX64.Spec.CSpace_A.resolve_address_bits (Prod.mk croot ptrbits_for_depth)) (holCaseProd (fun (slot : ((BitVec 64) × (List Bool))) => (fun (rem : (List Bool)) => (holCaseList ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) slot) (fun (a : Bool) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := ((BitVec 64) × (List Bool)))) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.DepthMismatch (holSize rem) (HolZero.zeroVal (α := Nat)))))) rem)))))))))) ((holThrowError (α := ((BitVec 64) × (List Bool)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup is_source L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot))))))) + +def lookup_target_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((List Bool) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (L4vRefX64.Spec.CSpace_A.lookup_slot_for_cnode_op false) + +def get_receive_slots {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List ((BitVec 64) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | thread, (Option.some buffer) => (holBind (L4vRefX64.Spec.CSpace_A.load_cap_transfer buffer) (fun (ct : (L4vRefX64.Spec.Structures_A.captransfer_ext Unit)) => (holFunApp L4vRefX64.Spec.Exceptions_A.empty_on_failure (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.unify_failure (L4vRefX64.Spec.CSpace_A.lookup_cap thread (L4vRefX64.Spec.Structures_A.captransfer_ext.ct_receive_root ct))) (fun (cnode : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.unify_failure (L4vRefX64.Spec.CSpace_A.lookup_target_slot cnode (L4vRefX64.Spec.Structures_A.captransfer_ext.ct_receive_index ct) (holUnsigned (L4vRefX64.Spec.Structures_A.captransfer_ext.ct_receive_depth ct)))) (fun (slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holWhenE (holNot (holEq cap L4vRefX64.Spec.Structures_A.cap.NullCap)) ((holThrowError (α := Unit)) ())) (holKBind ((holReturnOk (ε := Unit)) (List.cons slot (List.nil (α := ((BitVec 64) × (List Bool))))))))))))))))) + | x, Option.none => (holReturn (List.nil (α := ((BitVec 64) × (List Bool))))) + +def has_cancel_send_rights : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (x : (BitVec 64)) => (fun (xa : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holEq R L4vRefX64.Spec.CapRights_A.all_rights)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => false))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => false) cap)) + +def invoke_cnode {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.cnode_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (i : L4vRefX64.Spec.Invocations_A.cnode_invocation) => (L4vRefX64.Spec.Invocations_A.case_cnode_invocation (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.cap_insert cap src_slot dest_slot))))) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.cap_move cap src_slot dest_slot))))) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.CSpace_A.cap_revoke dest_slot)) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.CSpace_A.cap_delete dest_slot)) (fun (cap1 : L4vRefX64.Spec.Structures_A.cap) => (fun (cap2 : L4vRefX64.Spec.Structures_A.cap) => (fun (slot1 : ((BitVec 64) × (List Bool))) => (fun (slot2 : ((BitVec 64) × (List Bool))) => (fun (slot3 : ((BitVec 64) × (List Bool))) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holIf (holEq slot1 slot3) (L4vRefX64.Spec.CSpace_A.cap_swap cap1 slot1 cap2 slot2) (holBind (L4vRefX64.Spec.CSpace_A.cap_move cap2 slot2 slot3) (holKBind (L4vRefX64.Spec.CSpace_A.cap_move cap1 slot1 slot2)))))))))) (fun (x : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (ep : (BitVec 64)) => (fun (b : (BitVec 64)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holFunApp (holWhen (holNot (holEq b (HolZero.zeroVal (α := (BitVec 64)))))) (L4vRefX64.Spec.IpcCancel_A.cancel_badged_sends ep b)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) x)) i)) + +def isCTEDeleteCall : (L4vRefX64.Spec.CSpace_A.rec_del_call → Bool) + | (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall slot exposed) => true + | (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) => false + | (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall cap slot exposed) => false + +def locate_slot : (((BitVec 64) × (List Bool)) → (Nat → ((BitVec 64) × (List Bool)))) := + (holCaseProd (fun (a : (BitVec 64)) => (fun (b : (List Bool)) => (fun (n : Nat) => (Prod.mk a (holListDrop (HolSub.subVal (HolNumeral.ofNatVal (α := Nat) 32) (holSize b)) (holToBl (HolAdd.addVal ((holOfBl (w := 32)) b) ((holOfNat (α := (BitVec 32))) n))))))))) + +def long_running_delete : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false)) (fun (ptr : (BitVec 64)) => (fun (bits : Nat) => (fun (gd : (List Bool)) => true))) (fun (ptr : (BitVec 64)) => true) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (ptr : (BitVec 64)) => (fun (bits : (Option Nat)) => (fun (n : Nat) => true))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => false) cap)) + +def lookup_cap_and_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List Bool) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (cptr : (List Bool)) => (holBindE (L4vRefX64.Spec.CSpace_A.lookup_slot_for_thread thread cptr) (holCaseProd (fun (slot : ((BitVec 64) × (List Bool))) => (fun (cr : (List Bool)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (Prod.mk cap slot)))))))))) + +def lookup_pivot_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((List Bool) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (L4vRefX64.Spec.CSpace_A.lookup_slot_for_cnode_op true) + +def lookup_source_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((List Bool) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × (List Bool))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (L4vRefX64.Spec.CSpace_A.lookup_slot_for_cnode_op true) + +def max_free_index_update : (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.CSpace_A.free_index_update (fun (uu_ : Nat) => (L4vRefX64.Spec.CSpace_A.max_free_index (L4vRefX64.Spec.CSpace_A.untyped_sz_bits cap))) cap)) + +def rec_del_rel {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → ((L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) → Bool))) => (fun (x1 : (L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (fun (x2 : (L4vRefX64.Spec.CSpace_A.rec_del_call × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) => (holDisj (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) s)) (holEq x2 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall slot exposed) s))))))))) (holDisj (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rv : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rva : Bool) => (holEx (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvb : (L4vRefX64.Spec.Structures_A.cap × L4vRefX64.Spec.Structures_A.cap)) => (holEx (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvc : Unit) => (holEx (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (Prod.fst rvb) slot exposed) stc)) (holConj (holEq x2 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) s)) (holConj (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) s))) (holConj (holNot (holEq rv L4vRefX64.Spec.Structures_A.cap.NullCap)) (holConj (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.IpcCancel_A.is_final_cap rv) st))) (holConj (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.finalise_cap rv rva) sta))) (holConj (holNot (L4vRefX64.Spec.CSpace_A.cap_removeable (Prod.fst rvb) slot)) (holConj (holNot (holConj (L4vRefX64.Spec.CSpace_A.cap_cyclic_zombie (Prod.fst rvb) slot) (holNot exposed))) (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.set_cap (Prod.fst rvb) slot) stb))))))))))))))))))))))))))))))))) (holDisj (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (exposed : Bool) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rv : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rva : Bool) => (holEx (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvb : (L4vRefX64.Spec.Structures_A.cap × L4vRefX64.Spec.Structures_A.cap)) => (holEx (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvc : Unit) => (holEx (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvd : (Bool × L4vRefX64.Spec.Structures_A.cap)) => (holEx (fun (std : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rve : Unit) => (holEx (fun (ste : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) ste)) (holConj (holEq x2 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) s)) (holConj (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) s))) (holConj (holNot (holEq rv L4vRefX64.Spec.Structures_A.cap.NullCap)) (holConj (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.IpcCancel_A.is_final_cap rv) st))) (holConj (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpace_A.finalise_cap rv rva) sta))) (holConj (holNot (L4vRefX64.Spec.CSpace_A.cap_removeable (Prod.fst rvb) slot)) (holConj (holNot (holConj (L4vRefX64.Spec.CSpace_A.cap_cyclic_zombie (Prod.fst rvb) slot) (holNot exposed))) (holConj (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.CSpaceAcc_A.set_cap (Prod.fst rvb) slot) stb))) (holConj (holMember (Prod.mk (Sum.inr rvd) std) (Prod.fst (L4vRefX64.Spec.CSpace_A.rec_del_sumC (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (Prod.fst rvb) slot exposed) stc)))) (holMember (Prod.mk (Sum.inr rve) ste) (Prod.fst (L4vRefX64.Spec.KHeap_A.preemption_point std))))))))))))))))))))))))))))))))))))))))))) (holEx (fun (ptr : (BitVec 64)) => (holEx (fun (bits : (Option Nat)) => (holEx (fun (n : Nat) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rv : ((BitVec 64) × (List Bool))) => (holEx (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall rv false) st)) (holConj (holEq x2 (Prod.mk (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall (L4vRefX64.Spec.Structures_A.cap.Zombie ptr bits (Nat.succ n)) slot true) s)) (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst ((holReturnOk (ε := Unit)) (Prod.mk ptr (L4vRefX64.Spec.Machine_A.nat_to_cref (L4vRefX64.Spec.Structures_A.zombie_cte_bits bits) n)) s)))))))))))))))))))))))))) + +def resolve_address_bits'_rel {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → (((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool))) → Bool))) => (fun (x1 : ((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool)))) => (fun (x2 : ((HolItself tv_z) × (L4vRefX64.Spec.Structures_A.cap × (List Bool)))) => (holEx (fun (z : (HolItself tv_z)) => (holEx (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (cref : (List Bool)) => (holEx (fun (x61 : (BitVec 64)) => (holEx (fun (x62 : Nat) => (holEx (fun (x63 : (List Bool)) => (holEx (fun (v : Unit) => (holEx (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (s_p : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rv : Unit) => (holEx (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rva : (List Bool)) => (holEx (fun (sta : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvb : (List Bool)) => (holEx (fun (stb : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (rvc : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (stc : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holEq x1 (Prod.mk z (Prod.mk rvc rvb))) (holConj (holEq x2 (Prod.mk z (Prod.mk cap cref))) (holConj (holEq cap (L4vRefX64.Spec.Structures_A.cap.CNodeCap x61 x62 x63)) (holConj (holNot (holEq (HolAdd.addVal x62 (holSize x63)) (HolZero.zeroVal (α := Nat)))) (holConj (holMember (Prod.mk (Sum.inr v) s_p) (Prod.fst (holWhenE (holNot (holLe x63 cref)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.GuardMismatch (holSize cref) x63)) s))) (holConj (holMember (Prod.mk (Sum.inr rv) st) (Prod.fst (holWhenE (holLt (holSize cref) (HolAdd.addVal x62 (holSize x63))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.DepthMismatch (holSize cref) (HolAdd.addVal x62 (holSize x63)))) s_p))) (holConj (holMember (Prod.mk (Sum.inr rva) sta) (Prod.fst (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holListTake x62 (holListDrop (holSize x63) cref)) st))) (holConj (holMember (Prod.mk (Sum.inr rvb) stb) (Prod.fst (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (holListDrop (HolAdd.addVal x62 (holSize x63)) cref) sta))) (holConj (holNot (holEq rvb (List.nil (α := Bool)))) (holConj (holMember (Prod.mk (Sum.inr rvc) stc) (Prod.fst (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.lookup_failure)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap (Prod.mk x61 rva)) stb))) (L4vRefX64.Spec.Structures_A.is_cnode_cap rvc))))))))))))))))))))))))))))))))))))))))))))))))) + +def same_object_as : (L4vRefX64.Spec.Structures_A.cap → (L4vRefX64.Spec.Structures_A.cap → Bool)) := + (fun (cp : L4vRefX64.Spec.Structures_A.cap) => (fun (cp_p : L4vRefX64.Spec.Structures_A.cap) => (holCaseProd (fun (a : L4vRefX64.Spec.Structures_A.cap) => (fun (x : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p) (fun (dev : Bool) => (fun (r : (BitVec 64)) => (fun (bits : Nat) => (fun (free : Nat) => false)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (word : (BitVec 64)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)) (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p))) (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p) false (fun (word : (BitVec 8)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (ac : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Structures_A.case_cap (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (word : (BitVec 64)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)) (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p))) (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p) (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p) (fun (word : (BitVec 8)) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (L4vRefX64.Spec.CSpace_A.same_region_as cp cp_p)))) (fun (ac_p : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.ArchCSpace_A.same_aobject_as ac ac_p)) x)) a))) (Prod.mk cp cp_p)))) + +def slot_cap_long_running_delete {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holReturn false) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap))))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap)))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap))))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap)))))))) (fun (word : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap)))))) (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap))))))) (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap))))) (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap))))) (fun (word : (BitVec 8)) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap)))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap)))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holBind (L4vRefX64.Spec.IpcCancel_A.is_final_cap cap) (fun (final : Bool) => (holReturn (holConj final (L4vRefX64.Spec.CSpace_A.long_running_delete cap)))))) cap)))) + +def slot_rdcall : (L4vRefX64.Spec.CSpace_A.rec_del_call → ((BitVec 64) × (List Bool))) + | (L4vRefX64.Spec.CSpace_A.rec_del_call.CTEDeleteCall slot exposed) => slot + | (L4vRefX64.Spec.CSpace_A.rec_del_call.FinaliseSlotCall slot exposed) => slot + | (L4vRefX64.Spec.CSpace_A.rec_del_call.ReduceZombieCall cap slot exposed) => slot + +def tcb_registers_caps_merge : ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit))) := + (fun (regtcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (fun (captcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_ipcframe_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_ipcframe captcb)) (L4vRefX64.Spec.Structures_A.tcb.tcb_vtable_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_vtable captcb)) (L4vRefX64.Spec.Structures_A.tcb.tcb_ctable_update (fun (uu_ : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_ctable captcb)) regtcb))))) + +def update_cap_data : (Bool → ((BitVec 64) → (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap))) := + (fun (preserve : Bool) => (fun (w : (BitVec 64)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holIf (L4vRefX64.Spec.Structures_A.is_ep_cap cap) (holIf (holConj (holEq (L4vRefX64.Spec.Structures_A.cap_ep_badge cap) (HolZero.zeroVal (α := (BitVec 64)))) (holNot preserve)) (L4vRefX64.Spec.Structures_A.badge_update w cap) L4vRefX64.Spec.Structures_A.cap.NullCap) (holIf (L4vRefX64.Spec.Structures_A.is_ntfn_cap cap) (holIf (holConj (holEq (L4vRefX64.Spec.Structures_A.cap_ep_badge cap) (HolZero.zeroVal (α := (BitVec 64)))) (holNot preserve)) (L4vRefX64.Spec.Structures_A.badge_update w cap) L4vRefX64.Spec.Structures_A.cap.NullCap) (holIf (L4vRefX64.Spec.Structures_A.is_cnode_cap cap) (holLet (L4vRefX64.Spec.Structures_A.the_cnode_cap cap) (holCaseProd (fun (oref : (BitVec 64)) => (holCaseProd (fun (bits : Nat) => (fun (guard : (List Bool)) => (holLet (L4vRefX64.Spec.ArchCSpace_A.update_cnode_cap_data w) (holCaseProd (fun (guard_size_p : Nat) => (fun (guard_p_p : (BitVec 64)) => (holLet (holListDrop (HolSub.subVal (holSize guard_p_p) guard_size_p) (holToBl guard_p_p)) (fun (guard_p : (List Bool)) => (holIf (holLt L4vRefX64.Spec.Machine_Word_64_Basics.word_bits (HolAdd.addVal guard_size_p bits)) L4vRefX64.Spec.Structures_A.cap.NullCap (L4vRefX64.Spec.Structures_A.cap.CNodeCap oref bits guard_p)))))))))))))) (holIf (L4vRefX64.Spec.Structures_A.is_arch_cap cap) (L4vRefX64.Spec.ArchVSpace_A.arch_update_cap_data preserve w (L4vRefX64.Spec.Structures_A.cap.the_arch_cap cap)) cap))))))) +end +end L4vRefX64.Spec.CSpace_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CapRights_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CapRights_A.lean new file mode 100644 index 000000000..95e1009d6 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/CapRights_A.lean @@ -0,0 +1,35 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.CapRights_A) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.CapRights_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive rights where + | AllowRead + | AllowWrite + | AllowGrant + | AllowGrantReply +instance : Nonempty rights := ⟨rights.AllowRead⟩ +def case_rights {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) : rights → r_ty + | .AllowRead => f0 + | .AllowWrite => f1 + | .AllowGrant => f2 + | .AllowGrantReply => f3 + +def AllowRecv : L4vRefX64.Spec.CapRights_A.rights := + L4vRefX64.Spec.CapRights_A.rights.AllowRead + +def AllowSend : L4vRefX64.Spec.CapRights_A.rights := + L4vRefX64.Spec.CapRights_A.rights.AllowWrite + +def CanModify : L4vRefX64.Spec.CapRights_A.rights := + L4vRefX64.Spec.CapRights_A.rights.AllowWrite + +def all_rights : (Set L4vRefX64.Spec.CapRights_A.rights) := + (HolCompleteLattice.holTop (α := (Set L4vRefX64.Spec.CapRights_A.rights))) +end +end L4vRefX64.Spec.CapRights_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Decode_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Decode_A.lean new file mode 100644 index 000000000..949a6f649 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Decode_A.lean @@ -0,0 +1,146 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Decode_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchDecode_A +import L4vRefX64.Spec.ArchInvocation_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Arch_Structs_B +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.InvocationLabels_A +import L4vRefX64.Spec.InvocationLabels_H +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.Kernel_Config +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.More_Word_Operations +import L4vRefX64.Spec.Retype_A +import L4vRefX64.Spec.SchedContext_A +import L4vRefX64.Spec.Schedule_A +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.Tcb_A +import L4vRefX64.Spec.Time + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Decode_A +open L4vRefX64.Prim +open Classical +noncomputable section +def has_handler_rights : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holConj (holMember L4vRefX64.Spec.CapRights_A.AllowSend (L4vRefX64.Spec.Structures_A.cap_rights cap)) (holNot (holEq (HolCompleteLattice.holInf (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowGrant (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowGrantReply (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (L4vRefX64.Spec.Structures_A.cap_rights cap)) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))))) + +def valid_fault_handler : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (HolCompleteLattice.holSup (HolCompleteLattice.holInf L4vRefX64.Spec.Structures_A.is_ep_cap L4vRefX64.Spec.Decode_A.has_handler_rights) (holEq L4vRefX64.Spec.Structures_A.cap.NullCap)) + +def check_handler_ep {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Nat → ((L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (pos : Nat) => (fun (h_cap_h_slot : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (holFunApp (holUnlessE (holFunApp L4vRefX64.Spec.Decode_A.valid_fault_handler (Prod.fst h_cap_h_slot))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability pos))) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) h_cap_h_slot))))) + +def check_prio {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (new_prio : (BitVec 64)) => (fun (auth_tcb : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_mcpriority auth_tcb)) (fun (mcp : (BitVec 8)) => (holFunApp (holWhenE (holLt ((holUcast (w := 64)) mcp) new_prio)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holUcast (w := 64)) mcp)))))))) + +def data_to_obj_type {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Structures_A.apiobject_type) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (v_type : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Machine_A.data_to_nat v_type)) (fun (n : Nat) => (holIf (holEq n (HolZero.zeroVal (α := Nat))) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.apiobject_type.Untyped) (holIf (holEq n (HolOne.oneVal (α := Nat))) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.apiobject_type.TCBObject) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 2)) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.apiobject_type.EndpointObject) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 3)) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.apiobject_type.NotificationObject) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 4)) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.apiobject_type.CapTableObject) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 5)) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.apiobject_type.SchedContextObject) (holIf (holEq n (HolNumeral.ofNatVal (α := Nat) 6)) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) L4vRefX64.Spec.Structures_A.apiobject_type.ReplyObject) (holCaseOption ((holThrowError (α := L4vRefX64.Spec.Structures_A.apiobject_type)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat)))) (fun (tp : L4vRefX64.Spec.Arch_Structs_A.aobject_type) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.apiobject_type.ArchObject tp))) (L4vRefX64.Spec.ArchDecode_A.arch_data_to_obj_type (HolSub.subVal n (HolNumeral.ofNatVal (α := Nat) 7)))))))))))))) + +def decode_bind_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (tcb : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holEq (holSize extra_caps) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_bound_notification tcb)) (fun (nTFN : (Option (BitVec 64))) => (holBindE (holCaseOption ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) (fun (x : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) nTFN) (holKBind (holBindE (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (ptr : (BitVec 64)) => (fun (x : (BitVec 64)) => (fun (r : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk ptr r))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word : (BitVec 64)) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 8)) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := ((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (Prod.fst (holHd extra_caps))) (holCaseProd (fun (ntfnptr : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBindE (holFunApp (holWhenE (holNot (holMember L4vRefX64.Spec.CapRights_A.AllowRecv rights))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr)) (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holBindE (holCaseProd (fun (a : L4vRefX64.Spec.Structures_A.ntfn) => (fun (b : (Option (BitVec 64))) => (L4vRefX64.Spec.Structures_A.case_ntfn (holCaseOption ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) (fun (a_1 : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) b) (fun (list : (List (BitVec 64))) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (fun (x : (BitVec 64)) => (holCaseOption ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) (fun (a_1 : (BitVec 64)) => ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) b)) a))) (Prod.mk (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn) (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_bound_tcb ntfn))) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.NotificationControl tcb (Option.some ntfnptr)))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 8)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) cap))) + +def decode_cnode_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.cnode_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (excaps : (List L4vRefX64.Spec.Structures_A.cap)) => (holBindE (holFunApp (holUnlessE (holMember (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) (holListSet (holUptoEnum L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeRevoke L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeRotate)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_cptr (holNth args (HolZero.zeroVal (α := Nat))))) (fun (index : (List Bool)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_nat (holNth args (HolOne.oneVal (α := Nat))))) (fun (bits : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holListDrop (HolNumeral.ofNatVal (α := Nat) 2) args)) (fun (args_1 : (List (BitVec 64))) => (holBindE (L4vRefX64.Spec.CSpace_A.lookup_target_slot cap index bits) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holIf (holConj (holLe (HolNumeral.ofNatVal (α := Nat) 2) (holSize args_1)) (holConj (holLt (HolZero.zeroVal (α := Nat)) (holSize excaps)) (holMember (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) (holListSet (holUptoEnum L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeCopy L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeMutate))))) (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_cptr (holNth args_1 (HolZero.zeroVal (α := Nat))))) (fun (src_index : (List Bool)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_nat (holNth args_1 (HolOne.oneVal (α := Nat))))) (fun (src_depth : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holListDrop (HolNumeral.ofNatVal (α := Nat) 2) args_1)) (fun (args_2 : (List (BitVec 64))) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excaps (HolZero.zeroVal (α := Nat)))) (fun (src_root_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (L4vRefX64.Spec.CSpaceAcc_A.ensure_empty dest_slot) (holKBind (holBindE (L4vRefX64.Spec.CSpace_A.lookup_source_slot src_root_cap src_index src_depth) (fun (src_slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap src_slot)) (fun (src_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holEq src_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) (holFunApp (holThrowError (α := Unit)) (holFunApp (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup true) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability src_depth)))) (holKBind (holBindE (holCaseProd (fun (a : L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels) => (fun (x : (List (BitVec 64))) => (L4vRefX64.Spec.InvocationLabels_H.case_gen_invocation_labels ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (holCaseList ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (rightsWord : (BitVec 64)) => (fun (x_1 : (List (BitVec 64))) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.CSpace_A.data_to_rights rightsWord)) (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk rights (Prod.mk (Option.none (α := (BitVec 64))) false))))))) x) (holCaseList ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (rightsWord : (BitVec 64)) => (fun (list : (List (BitVec 64))) => (holCaseList ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (capData : (BitVec 64)) => (fun (x_1 : (List (BitVec 64))) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.CSpace_A.data_to_rights rightsWord)) (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk rights (Prod.mk (Option.some capData) false))))))) list))) x) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk L4vRefX64.Spec.CapRights_A.all_rights (Prod.mk (Option.none (α := (BitVec 64))) true))) (holCaseList ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (capData : (BitVec 64)) => (fun (x_1 : (List (BitVec 64))) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk L4vRefX64.Spec.CapRights_A.all_rights (Prod.mk (Option.some capData) true))))) x) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) ((holThrowError (α := ((Set L4vRefX64.Spec.CapRights_A.rights) × ((Option (BitVec 64)) × Bool)))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) a))) (Prod.mk (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) args_2)) (holCaseProd (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holCaseProd (fun (cap_data : (Option (BitVec 64))) => (fun (is_move : Bool) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.mask_cap rights src_cap)) (fun (src_cap_1 : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holIf is_move (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpace_A.derive_cap src_slot) (holCaseOption src_cap_1 (fun (w : (BitVec 64)) => (L4vRefX64.Spec.CSpace_A.update_cap_data is_move w src_cap_1)) cap_data)) (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holEq new_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holIf is_move L4vRefX64.Spec.Invocations_A.cnode_invocation.MoveCall L4vRefX64.Spec.Invocations_A.cnode_invocation.InsertCall new_cap src_slot dest_slot)))))))))))))))))))))))))))))) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeRevoke) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.cnode_invocation.RevokeCall dest_slot)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeDelete) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.cnode_invocation.DeleteCall dest_slot)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeCancelBadgedSends) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap dest_slot)) (fun (cap_1 : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holUnlessE (L4vRefX64.Spec.CSpace_A.has_cancel_send_rights cap_1)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.cnode_invocation.CancelBadgedSendsCall cap_1)))))) (holIf (holConj (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeRotate) (holConj (holLt (HolNumeral.ofNatVal (α := Nat) 5) (holSize args_1)) (holLt (HolOne.oneVal (α := Nat)) (holSize excaps)))) (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args_1 (HolZero.zeroVal (α := Nat)))) (fun (pivot_new_data : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_cptr (holNth args_1 (HolOne.oneVal (α := Nat))))) (fun (pivot_index : (List Bool)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_nat (holNth args_1 (HolNumeral.ofNatVal (α := Nat) 2)))) (fun (pivot_depth : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args_1 (HolNumeral.ofNatVal (α := Nat) 3))) (fun (src_new_data : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_cptr (holNth args_1 (HolNumeral.ofNatVal (α := Nat) 4)))) (fun (src_index : (List Bool)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_nat (holNth args_1 (HolNumeral.ofNatVal (α := Nat) 5)))) (fun (src_depth : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excaps (HolZero.zeroVal (α := Nat)))) (fun (pivot_root_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excaps (HolOne.oneVal (α := Nat)))) (fun (src_root_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (L4vRefX64.Spec.CSpace_A.lookup_source_slot src_root_cap src_index src_depth) (fun (src_slot : ((BitVec 64) × (List Bool))) => (holBindE (L4vRefX64.Spec.CSpace_A.lookup_pivot_slot pivot_root_cap pivot_index pivot_depth) (fun (pivot_slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (holWhenE (holDisj (holEq pivot_slot src_slot) (holEq pivot_slot dest_slot))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holUnlessE (holEq src_slot dest_slot)) (L4vRefX64.Spec.CSpaceAcc_A.ensure_empty dest_slot)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap src_slot)) (fun (src_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holEq src_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) (holFunApp (holThrowError (α := Unit)) (holFunApp (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup true) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability src_depth)))) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap pivot_slot)) (fun (pivot_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holEq pivot_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) (holFunApp (holThrowError (α := Unit)) (holFunApp (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup false) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability pivot_depth)))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpace_A.update_cap_data true src_new_data src_cap)) (fun (new_src_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpace_A.update_cap_data true pivot_new_data pivot_cap)) (fun (new_pivot_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holEq new_src_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holWhenE (holEq new_pivot_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.cnode_invocation.RotateCall new_src_cap new_pivot_cap src_slot pivot_slot dest_slot)))))))))))))))))))))))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.cnode_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)))))))))))))))))))))) + +def decode_copy_registers {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (data : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (extra_caps : (List L4vRefX64.Spec.Structures_A.cap)) => (holCaseList ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (flags : (BitVec 64)) => (fun (x : (List (BitVec 64))) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordBit flags (HolZero.zeroVal (α := Nat)))) (fun (suspend_source : Bool) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordBit flags (HolOne.oneVal (α := Nat)))) (fun (resume_target : Bool) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordBit flags (HolNumeral.ofNatVal (α := Nat) 2))) (fun (transfer_frame : Bool) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordBit flags (HolNumeral.ofNatVal (α := Nat) 3))) (fun (transfer_integer : Bool) => (holBindE (holFunApp (holWhenE (holEq extra_caps (List.nil (α := L4vRefX64.Spec.Structures_A.cap)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holCaseList (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (a : L4vRefX64.Spec.Structures_A.cap) => (fun (x_1 : (List L4vRefX64.Spec.Structures_A.cap)) => (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (listb : (List Bool)) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (p : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) p)) (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFunApp (holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) a))) extra_caps) (fun (src_tcb : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : Bool) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : Nat) => (fun (a_3 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (fun (a_2 : (List Bool)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (p : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) p)) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : (BitVec 8)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Option Nat)) => (fun (a_2 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap) (fun (p : (BitVec 64)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.CopyRegisters p src_tcb suspend_source resume_target transfer_frame transfer_integer L4vRefX64.Spec.ArchInvocation_A.ArchDefaultExtraRegisters)))))))))))))))))) data)))) + +def decode_cv_space {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (excaps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holDisj (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2)) (holLt (holSize excaps) (HolNumeral.ofNatVal (α := Nat) 2)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args (HolZero.zeroVal (α := Nat)))) (fun (croot_data : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args (HolOne.oneVal (α := Nat)))) (fun (vroot_data : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excaps (HolZero.zeroVal (α := Nat)))) (fun (croot_arg : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excaps (HolOne.oneVal (α := Nat)))) (fun (vroot_arg : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holLiftM holNot) (holFunApp L4vRefX64.Spec.CSpace_A.slot_cap_long_running_delete (holFunApp L4vRefX64.Spec.Tcb_A.get_tcb_ctable_ptr (L4vRefX64.Spec.Structures_A.obj_ref_of cap))))) (fun (can_chg_cr : Bool) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holLiftM holNot) (holFunApp L4vRefX64.Spec.CSpace_A.slot_cap_long_running_delete (holFunApp L4vRefX64.Spec.Tcb_A.get_tcb_vtable_ptr (L4vRefX64.Spec.Structures_A.obj_ref_of cap))))) (fun (can_chg_vr : Bool) => (holBindE (holFunApp (holUnlessE (holConj can_chg_cr can_chg_vr)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.fst croot_arg)) (fun (croot_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.snd croot_arg)) (fun (croot_slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (L4vRefX64.Spec.CSpace_A.derive_cap croot_slot) (holIf (holEq croot_data (HolZero.zeroVal (α := (BitVec 64)))) holId (L4vRefX64.Spec.CSpace_A.update_cap_data false croot_data) croot_cap)) (fun (croot_cap_p : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holUnlessE (L4vRefX64.Spec.Structures_A.is_cnode_cap croot_cap_p)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk croot_cap_p croot_slot)) (fun (croot : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.fst vroot_arg)) (fun (vroot_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.snd vroot_arg)) (fun (vroot_slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (L4vRefX64.Spec.CSpace_A.derive_cap vroot_slot) (holIf (holEq vroot_data (HolZero.zeroVal (α := (BitVec 64)))) holId (L4vRefX64.Spec.CSpace_A.update_cap_data false vroot_data) vroot_cap)) (fun (vroot_cap_p : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holUnlessE (L4vRefX64.Spec.ArchVSpace_A.is_valid_vtable_root vroot_cap_p)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk vroot_cap_p vroot_slot)) (fun (vroot : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlCaps (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.some croot) (Option.some vroot) (Option.none (α := ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))))))))))))))))))))))))))))))))))))))))) + +def decode_domain_schedule_configure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.domain_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (args : (List (BitVec 64))) => (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolAdd.addVal (HolNumeral.ofNatVal (α := Nat) 2) L4vRefX64.Spec.Structs_B.timeArgLen))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holUnsigned (holNth args (HolZero.zeroVal (α := Nat))))) (fun (index : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args (HolOne.oneVal (α := Nat)))) (fun (domain : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Arch_Structs_B.parseTimeArg (HolNumeral.ofNatVal (α := Nat) 2) args)) (fun (duration : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_list)) (fun (sched : (List ((BitVec 8) × (BitVec 56)))) => (holBindE (holFunApp (holWhenE (holLe (HolSub.subVal (holSize sched) (HolOne.oneVal (α := Nat))) index)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) (HolSub.subVal (holSize sched) (HolNumeral.ofNatVal (α := Nat) 2)))))) (holKBind (holBindE (holFunApp (holWhenE (holLe L4vRefX64.Spec.Kernel_Config.numDomains (holUnsigned domain))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) (HolSub.subVal L4vRefX64.Spec.Kernel_Config.numDomains (HolOne.oneVal (α := Nat))))))) (holKBind (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.Structures_A.max_domain_duration duration)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolNumeral.ofNatVal (α := Nat) 2)))) (holKBind (holBindE (holFunApp (holWhenE (holConj (holEq duration (HolZero.zeroVal (α := (BitVec 64)))) (holNot (holEq domain (HolZero.zeroVal (α := (BitVec 64))))))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_start_index)) (fun (start : Nat) => (holBindE (holFunApp (holWhenE (holConj (holEq index start) (holEq duration (HolZero.zeroVal (α := (BitVec 64)))))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolNumeral.ofNatVal (α := Nat) 2)))) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.domain_invocation.InvokeDomainScheduleConfigure index ((holUcast (w := 8)) domain) ((holUcast (w := 56)) duration)))))))))))))))))))))))))) + +def decode_domain_schedule_set_start {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.domain_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (args : (List (BitVec 64))) => (holBindE (holFunApp (holWhenE (holEq (holSize args) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holUnsigned (holNth args (HolZero.zeroVal (α := Nat))))) (fun (index : Nat) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_list)) (fun (sched : (List ((BitVec 8) × (BitVec 56)))) => (holBindE (holFunApp (holWhenE (holLe (holSize sched) index)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) (HolSub.subVal (holSize sched) (HolOne.oneVal (α := Nat))))))) (holKBind (holBindE (holFunApp (holWhenE (holEq (holNth sched index) L4vRefX64.Spec.Schedule_A.domain_end_marker)) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat))))) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.domain_invocation.InvokeDomainScheduleSetStart index))))))))))))) + +def decode_domain_set {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.domain_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (args : (List (BitVec 64))) => (fun (excs : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holCaseList ((holThrowError (α := (BitVec 8))) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (x : (BitVec 64)) => (fun (xs : (List (BitVec 64))) => (holBindE (holFunApp (holWhenE (holLe L4vRefX64.Spec.Kernel_Config.numDomains (holUnsigned x))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolZero.zeroVal (α := Nat))))) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ((holUcast (w := 8)) x)))))) args) (fun (domain : (BitVec 8)) => (holBindE (holFunApp (holWhenE (holEq (holSize excs) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))))) (fun (ptr : (BitVec 64)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.domain_invocation.InvokeDomainSet ptr domain))) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat)))))) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat)))) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (Prod.fst (holHd excs))))))))) + +def decode_domain_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.domain_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (excs : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.InvocationLabels_H.case_gen_invocation_labels ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (L4vRefX64.Spec.Decode_A.decode_domain_set args excs) (L4vRefX64.Spec.Decode_A.decode_domain_schedule_configure args) (L4vRefX64.Spec.Decode_A.decode_domain_schedule_set_start args) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.domain_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label))))) + +def decode_irq_control_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.irq_control_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (cps : (List L4vRefX64.Spec.Structures_A.cap)) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQIssueIRQHandler) (holIf (holConj (holLe (HolNumeral.ofNatVal (α := Nat) 3) (holSize args)) (holLe (HolOne.oneVal (α := Nat)) (holSize cps))) (holLet (holNth args (HolZero.zeroVal (α := Nat))) (fun (irq_word : (BitVec 64)) => (holLet (holNth args (HolOne.oneVal (α := Nat))) (fun (index : (BitVec 64)) => (holLet (holNth args (HolNumeral.ofNatVal (α := Nat) 2)) (fun (depth : (BitVec 64)) => (holLet (holNth cps (HolZero.zeroVal (α := Nat))) (fun (cnode : L4vRefX64.Spec.Structures_A.cap) => (holLet ((holUcast (w := 8)) irq_word) (fun (irq : (BitVec 8)) => (holBindE (L4vRefX64.Spec.ArchDecode_A.arch_check_irq irq_word) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.is_irq_active irq)) (fun (irq_active : Bool) => (holBindE (holFunApp (holWhenE irq_active) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst)) (holKBind (holBindE (L4vRefX64.Spec.CSpace_A.lookup_target_slot cnode (L4vRefX64.Spec.Machine_A.data_to_cptr index) (holUnsigned depth)) (fun (dest_slot : ((BitVec 64) × (List Bool))) => (holBindE (L4vRefX64.Spec.CSpaceAcc_A.ensure_empty dest_slot) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.irq_control_invocation.IRQControl irq dest_slot src_slot)))))))))))))))))))))) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.irq_control_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.irq_control_invocation.ArchIRQControl) (L4vRefX64.Spec.ArchDecode_A.arch_decode_irq_control_invocation label args src_slot cps))))))) + +def decode_irq_handler_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 8) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.irq_handler_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (irq : (BitVec 8)) => (fun (cps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQAckIRQ) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.ACKIrq irq)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQSetIRQHandler) (holIf (holNot (holEq cps (List.nil (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (holLet (holHd cps) (holCaseProd (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (holIf (holConj (L4vRefX64.Spec.Structures_A.is_ntfn_cap cap) (holMember L4vRefX64.Spec.CapRights_A.AllowSend (L4vRefX64.Spec.Structures_A.cap_rights cap))) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.SetIRQHandler irq cap slot)) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.irq_handler_invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat))))))))) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.irq_handler_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holIf (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQClearIRQHandler) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.ClearIRQHandler irq)) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.irq_handler_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))))) + +def decode_sched_context_bind {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.sched_context_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (excaps : (List L4vRefX64.Spec.Structures_A.cap)) => (holBindE (holFunApp (holWhenE (holEq (holSize excaps) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holHd excaps)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr)) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (ntfn_ptr : (BitVec 64)) => (fun (x : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBindE (holFunApp (holWhenE (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_ntfn sc) (Option.none (α := (BitVec 64)))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification_ext.ntfn_sc ntfn_ptr)) (fun (sc_ptr_opt : (Option (BitVec 64))) => (holFunApp (holWhenE (holNot (holEq sc_ptr_opt (Option.none (α := (BitVec 64)))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (tcb_ptr : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc) (Option.none (α := (BitVec 64)))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb_ptr)) (fun (sc_ptr_opt : (Option (BitVec 64))) => (holBindE (holFunApp (holWhenE (holNot (holEq sc_ptr_opt (Option.none (α := (BitVec 64)))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_thread_state tcb_ptr)) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sc_released sc_ptr)) (fun (released : Bool) => (holFunApp (holWhenE (holConj (L4vRefX64.Spec.Structures_A.ipc_queued_thread_state st) (holNot released))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))))))))))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) cap) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.sched_context_invocation.InvokeSchedContextBind sc_ptr cap)))))))))))) + +def decode_sched_context_unbind_object {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.sched_context_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (excaps : (List L4vRefX64.Spec.Structures_A.cap)) => (holBindE (holFunApp (holWhenE (holEq (holSize excaps) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holHd excaps)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (ntfn_ptr : (BitVec 64)) => (fun (x : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_ntfn sc_ptr)) (fun (sc_ntfn_opt : (Option (BitVec 64))) => (holFunApp (holWhenE (holNot (holEq sc_ntfn_opt (Option.some ntfn_ptr)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (tcb_ptr : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc_ptr)) (fun (sc_tcb_opt : (Option (BitVec 64))) => (holBindE (holFunApp (holWhenE (holNot (holEq sc_tcb_opt (Option.some tcb_ptr)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (ct_ptr : (BitVec 64)) => (holFunApp (holWhenE (holEq tcb_ptr ct_ptr)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))))))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) cap) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.sched_context_invocation.InvokeSchedContextUnbindObject sc_ptr cap)))))))))) + +def decode_sched_context_yield_to {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.sched_context_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc_ptr)) (fun (sc_tcb_opt : (Option (BitVec 64))) => (holBindE (holFunApp (holWhenE (holEq sc_tcb_opt (Option.none (α := (BitVec 64))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (ct_ptr : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holEq sc_tcb_opt (Option.some ct_ptr))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority (holTheOpt sc_tcb_opt))) (fun (prios : (BitVec 8)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_mcpriority ct_ptr)) (fun (ct_mcp : (BitVec 8)) => (holBindE (holFunApp (holWhenE (holLt ct_mcp prios)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_yield_to ct_ptr)) (fun (yt_ptr : (Option (BitVec 64))) => (holBindE (holFunApp (holWhenE (holNot (holEq yt_ptr (Option.none (α := (BitVec 64)))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.sched_context_invocation.InvokeSchedContextYieldTo sc_ptr))))))))))))))))))))) + +def decode_sched_context_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.sched_context_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (sc_ptr : (BitVec 64)) => (fun (excaps : (List L4vRefX64.Spec.Structures_A.cap)) => (L4vRefX64.Spec.InvocationLabels_H.case_gen_invocation_labels (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.sched_context_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (L4vRefX64.Spec.Decode_A.decode_sched_context_bind sc_ptr excaps) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr)) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (ct_ptr : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc) (Option.some ct_ptr))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.sched_context_invocation.InvokeSchedContextUnbind sc_ptr)))))))) (L4vRefX64.Spec.Decode_A.decode_sched_context_unbind_object sc_ptr excaps) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.sched_context_invocation.InvokeSchedContextConsumed sc_ptr)) (L4vRefX64.Spec.Decode_A.decode_sched_context_yield_to sc_ptr) (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label))))) + +def decode_sched_control_invocation_flags {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.sched_control_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (excaps : (List L4vRefX64.Spec.Structures_A.cap)) => (holBindE (holFunApp (holUnlessE (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.SchedControlConfigureFlags)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holWhenE (holEq (holSize excaps) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolAdd.addVal (HolMul.mulVal L4vRefX64.Spec.Structs_B.timeArgLen (HolNumeral.ofNatVal (α := Nat) 2)) (HolNumeral.ofNatVal (α := Nat) 3)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Arch_Structs_A.parse_time_arg (HolZero.zeroVal (α := Nat)) args)) (fun (budget_us : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.Time.MAX_PERIOD_US budget_us)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) L4vRefX64.Spec.Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) L4vRefX64.Spec.Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Arch_Structs_A.parse_time_arg L4vRefX64.Spec.Structs_B.timeArgLen args)) (fun (period_us : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt L4vRefX64.Spec.Time.MAX_PERIOD_US period_us)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) L4vRefX64.Spec.Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) L4vRefX64.Spec.Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holWhenE (holLt budget_us L4vRefX64.Spec.Structures_A.MIN_BUDGET_US)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) L4vRefX64.Spec.Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) L4vRefX64.Spec.Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holWhenE (holLt period_us L4vRefX64.Spec.Structures_A.MIN_BUDGET_US)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) L4vRefX64.Spec.Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) L4vRefX64.Spec.Time.MAX_PERIOD_US)))) (holKBind (holBindE (holFunApp (holWhenE (holLt period_us budget_us)) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError ((holUcast (w := 64)) L4vRefX64.Spec.Structures_A.MIN_BUDGET_US) ((holUcast (w := 64)) period_us)))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holHd excaps)) (fun (target_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holNot (L4vRefX64.Spec.Structures_A.is_sched_context_cap target_cap))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.obj_ref_of target_cap)) (fun (sc_ptr : (BitVec 64)) => (holBindE ((holAssertE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holLe (L4vRefX64.Spec.Structures_A.MIN_REFILLS : Nat) (L4vRefX64.Spec.SchedContext_A.max_refills_cap target_cap))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) L4vRefX64.Spec.Structs_B.timeArgLen))) (fun (extra_refills : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt (HolSub.subVal (L4vRefX64.Spec.SchedContext_A.max_refills_cap target_cap) (L4vRefX64.Spec.Structures_A.MIN_REFILLS : Nat)) (holUnsigned extra_refills))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) (HolSub.subVal (L4vRefX64.Spec.SchedContext_A.max_refills_cap target_cap) (L4vRefX64.Spec.Structures_A.MIN_REFILLS : Nat)))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args (HolAdd.addVal (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) L4vRefX64.Spec.Structs_B.timeArgLen) (HolOne.oneVal (α := Nat))))) (fun (badge : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args (HolAdd.addVal (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) L4vRefX64.Spec.Structs_B.timeArgLen) (HolNumeral.ofNatVal (α := Nat) 2)))) (fun (flags : (BitVec 64)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.sched_control_invocation.InvokeSchedControlConfigureFlags sc_ptr (L4vRefX64.Spec.Time.us_to_ticks budget_us) (L4vRefX64.Spec.Time.us_to_ticks period_us) (HolAdd.addVal (holUnsigned extra_refills) (L4vRefX64.Spec.Structures_A.MIN_REFILLS : Nat)) badge flags))))))))))))))))))))))))))))))))))))))))) + +def decode_read_registers {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (data : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holCaseList ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (flags : (BitVec 64)) => (fun (list : (List (BitVec 64))) => (holCaseList ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (n : (BitVec 64)) => (fun (x : (List (BitVec 64))) => (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.range_check n (HolOne.oneVal (α := (BitVec 64)))) ((holOfNat (α := (BitVec 64))) (HolAdd.addVal (holSize L4vRefX64.Spec.MachineTypes.frameRegisters) (holSize L4vRefX64.Spec.MachineTypes.gpRegisters)))) (holKBind (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : Bool) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : Nat) => (fun (a_3 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (fun (a_2 : (List Bool)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (p : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) p)) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : (BitVec 8)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Option Nat)) => (fun (a_2 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap) (fun (p : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (self : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holEq p self)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ReadRegisters p (holWordBit flags (HolZero.zeroVal (α := Nat))) n L4vRefX64.Spec.ArchInvocation_A.ArchDefaultExtraRegisters)))))))))))) list))) data))) + +def decode_set_flags {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.SetFlags (L4vRefX64.Spec.Structures_A.obj_ref_of cap) (L4vRefX64.Spec.Structures_A.word_to_tcb_flags (holNth args (HolZero.zeroVal (α := Nat)))) (L4vRefX64.Spec.Structures_A.word_to_tcb_flags (holNth args (HolOne.oneVal (α := Nat)))))))))) + +def decode_set_ipc_buffer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (excs : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holEq (holSize args) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holWhenE (holEq (holSize excs) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Machine_A.data_to_vref (holNth args (HolZero.zeroVal (α := Nat))))) (fun (buffer : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excs (HolZero.zeroVal (α := Nat)))) (holCaseProd (fun (bcap : L4vRefX64.Spec.Structures_A.cap) => (fun (bslot : ((BitVec 64) × (List Bool))) => (holBindE (holIf (holEq buffer (HolZero.zeroVal (α := (BitVec 64)))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))) (holBindE (L4vRefX64.Spec.CSpace_A.derive_cap bslot bcap) (fun (buffer_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (L4vRefX64.Spec.ArchVSpace_A.check_valid_ipc_buffer buffer buffer_cap) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Option.some (Prod.mk buffer_cap bslot)))))))) (fun (newbuf : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlCaps (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.some (Prod.mk buffer newbuf)))))))))))))))))))) + +def decode_set_mcpriority {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holDisj (holEq (holSize args) (HolZero.zeroVal (α := Nat))) (holEq (holSize extra_caps) (HolZero.zeroVal (α := Nat))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 8)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (new_mcp : (BitVec 8)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (tcb_ptr : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) tcb_ptr)) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (Prod.fst (holNth extra_caps (HolZero.zeroVal (α := Nat))))) (fun (auth_tcb : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Decode_A.check_prio (holNth args (HolZero.zeroVal (α := Nat))) auth_tcb) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlSched (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.some (Prod.mk new_mcp auth_tcb)) (Option.none (α := ((BitVec 8) × (BitVec 64)))) (Option.none (α := (Option (BitVec 64)))))))))))))))))) + +def decode_set_priority {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holDisj (holEq (holSize args) (HolZero.zeroVal (α := Nat))) (holEq (holSize extra_caps) (HolZero.zeroVal (α := Nat))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ((holUcast (w := 8)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (prio : (BitVec 8)) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (tcb_ptr : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) tcb_ptr)) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (Prod.fst (holNth extra_caps (HolZero.zeroVal (α := Nat))))) (fun (auth_tcb : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Decode_A.check_prio (holNth args (HolZero.zeroVal (α := Nat))) auth_tcb) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlSched (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := ((BitVec 8) × (BitVec 64)))) (Option.some (Prod.mk prio auth_tcb)) (Option.none (α := (Option (BitVec 64)))))))))))))))))) + +def decode_update_sc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (Option (Option (BitVec 64)))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (sc_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.obj_ref_of cap)) (fun (tcb_ptr : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb_ptr)) (fun (tcb_sc : (Option (BitVec 64))) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (ct_ptr : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holEq tcb_ptr ct_ptr)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Option.none (α := (BitVec 64)))))))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2)))))) (fun (word : (BitVec 64)) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2)))) ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2))) (fun (x : (BitVec 64)) => (fun (xa : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.obj_ref_of sc_cap)) (fun (sc_ptr : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc_ptr)) (fun (sc_tcb : (Option (BitVec 64))) => (holBindE (holWhenE (holConj (holNot (holEq tcb_sc (Option.some sc_ptr))) (holDisj (holNot (holEq tcb_sc (Option.none (α := (BitVec 64))))) (holNot (holEq sc_tcb (Option.none (α := (BitVec 64))))))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.is_blocked tcb_ptr)) (fun (blocked : Bool) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_sc_released sc_ptr)) (fun (released : Bool) => (holBindE (holFunApp (holWhenE (holConj blocked (holNot released))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Option.some sc_ptr)))))))))))))))) ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2))) ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2))) (fun (word : (BitVec 8)) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := (Option (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolNumeral.ofNatVal (α := Nat) 2)))) sc_cap) (fun (sc_ptr_opt : (Option (BitVec 64))) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holIf (holNot (holEq tcb_sc sc_ptr_opt)) (Option.some sc_ptr_opt) (Option.none (α := (Option (BitVec 64))))))))))))))) + +def decode_set_sched_params {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holWhenE (holLt (holSize extra_caps) (HolNumeral.ofNatVal (α := Nat) 3))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 8)) (holNth args (HolZero.zeroVal (α := Nat))))) (fun (new_mcp : (BitVec 8)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (holUcast (w := 8)) (holNth args (HolOne.oneVal (α := Nat))))) (fun (new_prio : (BitVec 8)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp Prod.fst (holNth extra_caps (HolZero.zeroVal (α := Nat))))) (fun (auth_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp Prod.fst (holNth extra_caps (HolOne.oneVal (α := Nat))))) (fun (sc_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth extra_caps (HolNumeral.ofNatVal (α := Nat) 2))) (fun (fh_arg : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (tcb_ptr : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) tcb_ptr)) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))))) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat)))) (fun (word : (BitVec 8)) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := (BitVec 64))) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolOne.oneVal (α := Nat))))) auth_cap) (fun (auth_tcb : (BitVec 64)) => (holBindE (L4vRefX64.Spec.Decode_A.check_prio (holNth args (HolZero.zeroVal (α := Nat))) auth_tcb) (holKBind (holBindE (L4vRefX64.Spec.Decode_A.check_prio (holNth args (HolOne.oneVal (α := Nat))) auth_tcb) (holKBind (holBindE (L4vRefX64.Spec.Decode_A.decode_update_sc cap slot sc_cap) (fun (sc_ptr_opt_opt : (Option (Option (BitVec 64)))) => (holBindE (L4vRefX64.Spec.Decode_A.check_handler_ep (HolNumeral.ofNatVal (α := Nat) 3) fh_arg) (fun (fh : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlSched (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.some fh) (Option.some (Prod.mk new_mcp auth_tcb)) (Option.some (Prod.mk new_prio auth_tcb)) sc_ptr_opt_opt)))))))))))))))))))))))))))))) + +def decode_set_space {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (excaps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holDisj (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 2)) (holLt (holSize excaps) (HolNumeral.ofNatVal (α := Nat) 3)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (L4vRefX64.Spec.Decode_A.decode_cv_space (holListTake (HolNumeral.ofNatVal (α := Nat) 2) args) cap slot (holListTake (HolNumeral.ofNatVal (α := Nat) 2) (holListDrop (HolOne.oneVal (α := Nat)) excaps))) (fun (space : L4vRefX64.Spec.Invocations_A.tcb_invocation) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excaps (HolZero.zeroVal (α := Nat)))) (fun (fh_arg : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (L4vRefX64.Spec.Decode_A.check_handler_ep (HolOne.oneVal (α := Nat)) fh_arg) (fun (fault_handler : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlCaps (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.some fault_handler) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (L4vRefX64.Spec.Invocations_A.tcb_invocation.tc_new_croot space) (L4vRefX64.Spec.Invocations_A.tcb_invocation.tc_new_vroot space) (Option.none (α := ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))))))))))))) + +def decode_set_timeout_ep {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holLt (holSize extra_caps) (HolOne.oneVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth extra_caps (HolZero.zeroVal (α := Nat)))) (fun (th_arg : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (L4vRefX64.Spec.Decode_A.check_handler_ep (HolOne.oneVal (α := Nat)) th_arg) (fun (handler : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlCaps (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.some handler) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))))))))))) + +def decode_set_tls_base {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holEq (holSize args) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.SetTLSBase (L4vRefX64.Spec.Structures_A.obj_ref_of cap) ((holUcast (w := 64)) (holNth args (HolZero.zeroVal (α := Nat)))))))))) + +def decode_tcb_configure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (extra_caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 3))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holWhenE (holLt (holSize extra_caps) (HolNumeral.ofNatVal (α := Nat) 3))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth args (HolNumeral.ofNatVal (α := Nat) 2))) (fun (buffer : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth extra_caps (HolNumeral.ofNatVal (α := Nat) 2))) (fun (buffer_cap : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holBindE (L4vRefX64.Spec.Decode_A.decode_set_ipc_buffer (List.cons buffer (List.nil (α := (BitVec 64)))) cap slot (List.cons buffer_cap (List.nil (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (set_params : L4vRefX64.Spec.Invocations_A.tcb_invocation) => (holBindE (L4vRefX64.Spec.Decode_A.decode_cv_space (holListTake (HolNumeral.ofNatVal (α := Nat) 2) args) cap slot (holListTake (HolNumeral.ofNatVal (α := Nat) 2) extra_caps)) (fun (set_space : L4vRefX64.Spec.Invocations_A.tcb_invocation) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlCaps (L4vRefX64.Spec.Structures_A.obj_ref_of cap) slot (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (Option.none (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (L4vRefX64.Spec.Invocations_A.tcb_invocation.tc_new_croot set_space) (L4vRefX64.Spec.Invocations_A.tcb_invocation.tc_new_vroot set_space) (L4vRefX64.Spec.Invocations_A.tcb_invocation.tc_new_buffer set_params))))))))))))))))))) + +def decode_unbind_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (tcb : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_bound_notification tcb)) (fun (nTFN : (Option (BitVec 64))) => (holBindE (holCaseOption ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (x : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ())) nTFN) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.NotificationControl tcb (Option.none (α := (BitVec 64)))))))))) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 64)) => (fun (nat : Nat) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation))) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (fun (word : (BitVec 8)) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) cap)) + +def decode_write_registers {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (data : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holCaseList ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (flags : (BitVec 64)) => (fun (list : (List (BitVec 64))) => (holCaseList ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage) (fun (n : (BitVec 64)) => (fun (values : (List (BitVec 64))) => (holBindE (holFunApp (holWhenE (holLt (holSize values) (holUnsigned n))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : Bool) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : Nat) => (fun (a_3 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (fun (a_2 : (List Bool)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (p : (BitVec 64)) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) p)) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (a : (BitVec 8)) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Option Nat)) => (fun (a_2 : Nat) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (a : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holUndefined (α := ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) cap) (fun (p : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (self : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holEq p self)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.tcb_invocation.WriteRegisters p (holWordBit flags (HolZero.zeroVal (α := Nat))) (holListTake (holUnsigned n) values) L4vRefX64.Spec.ArchInvocation_A.ArchDefaultExtraRegisters)))))))))))) list))) data))) + +def decode_tcb_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.tcb_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (excs : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.InvocationLabels_H.case_gen_invocation_labels ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (L4vRefX64.Spec.Decode_A.decode_read_registers args cap) (L4vRefX64.Spec.Decode_A.decode_write_registers args cap) (holFunApp (L4vRefX64.Spec.Decode_A.decode_copy_registers args cap) (holListMap Prod.fst excs)) (L4vRefX64.Spec.Decode_A.decode_tcb_configure args cap slot excs) (L4vRefX64.Spec.Decode_A.decode_set_priority args cap slot excs) (L4vRefX64.Spec.Decode_A.decode_set_mcpriority args cap slot excs) (L4vRefX64.Spec.Decode_A.decode_set_sched_params args cap slot excs) (L4vRefX64.Spec.Decode_A.decode_set_timeout_ep cap slot excs) (L4vRefX64.Spec.Decode_A.decode_set_ipc_buffer args cap slot excs) (L4vRefX64.Spec.Decode_A.decode_set_space args cap slot excs) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Invocations_A.tcb_invocation.Suspend (L4vRefX64.Spec.Structures_A.obj_ref_of cap))) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp L4vRefX64.Spec.Invocations_A.tcb_invocation.Resume (L4vRefX64.Spec.Structures_A.obj_ref_of cap))) (L4vRefX64.Spec.Decode_A.decode_bind_notification cap excs) (L4vRefX64.Spec.Decode_A.decode_unbind_notification cap) (L4vRefX64.Spec.Decode_A.decode_set_tls_base args cap) (L4vRefX64.Spec.Decode_A.decode_set_flags args cap) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) ((holThrowError (α := L4vRefX64.Spec.Invocations_A.tcb_invocation)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation) (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label))))))) + +def decode_untyped_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Structures_A.cap → ((List L4vRefX64.Spec.Structures_A.cap) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.untyped_invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (excaps : (List L4vRefX64.Spec.Structures_A.cap)) => (holBindE (holFunApp (holUnlessE (holEq (L4vRefX64.Spec.InvocationLabels_A.gen_invocation_type label) L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.UntypedRetype)) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation)) (holKBind (holBindE (holFunApp (holWhenE (holLt (holSize args) (HolNumeral.ofNatVal (α := Nat) 6))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holWhenE (holEq (holSize excaps) (HolZero.zeroVal (α := Nat)))) ((holThrowError (α := Unit)) L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage)) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNth excaps (HolZero.zeroVal (α := Nat)))) (fun (root_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (L4vRefX64.Spec.Decode_A.data_to_obj_type (holNth args (HolZero.zeroVal (α := Nat)))) (fun (new_type : L4vRefX64.Spec.Structures_A.apiobject_type) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Machine_A.data_to_nat (holNth args (HolOne.oneVal (α := Nat))))) (fun (user_obj_size : Nat) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Retype_A.obj_bits_api new_type user_obj_size)) (fun (object_size : Nat) => (holBindE (holFunApp (holUnlessE (holConj (holLt user_obj_size L4vRefX64.Spec.Machine_Word_64_Basics.word_bits) (holLe object_size L4vRefX64.Spec.Arch_Structs_A.untyped_max_bits))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) L4vRefX64.Spec.Arch_Structs_A.untyped_max_bits)))) (holKBind (holBindE (holFunApp (holWhenE (holConj (holEq new_type L4vRefX64.Spec.Structures_A.apiobject_type.CapTableObject) (holEq user_obj_size (HolZero.zeroVal (α := Nat))))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holWhenE (holConj (holEq new_type L4vRefX64.Spec.Structures_A.apiobject_type.Untyped) (holLt user_obj_size L4vRefX64.Spec.Arch_Structs_A.untyped_min_bits))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holWhenE (holConj (holEq new_type L4vRefX64.Spec.Structures_A.apiobject_type.SchedContextObject) (holLt user_obj_size (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat)))) ((holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Machine_A.data_to_cptr (holNth args (HolNumeral.ofNatVal (α := Nat) 2)))) (fun (node_index : (List Bool)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Machine_A.data_to_nat (holNth args (HolNumeral.ofNatVal (α := Nat) 3)))) (fun (node_depth : Nat) => (holBindE (holIf (holEq node_depth (HolZero.zeroVal (α := Nat))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) root_cap) (holBindE (L4vRefX64.Spec.CSpace_A.lookup_target_slot root_cap node_index node_depth) (fun (node_slot : ((BitVec 64) × (List Bool))) => (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap node_slot))))) (fun (node_cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holIf (L4vRefX64.Spec.Structures_A.is_cnode_cap node_cap) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) ()) (holFunApp (holThrowError (α := Unit)) (holFunApp (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup false) (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability node_depth)))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Machine_A.data_to_nat (holNth args (HolNumeral.ofNatVal (α := Nat) 4)))) (fun (node_offset : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Machine_A.data_to_nat (holNth args (HolNumeral.ofNatVal (α := Nat) 5)))) (fun (node_window : Nat) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.bits_of node_cap)) (fun (radix_bits : Nat) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) radix_bits)) (fun (node_size : Nat) => (holBindE (holFunApp (holWhenE (holDisj (holLt node_offset (HolZero.zeroVal (α := Nat))) (holLt (HolSub.subVal node_size (HolOne.oneVal (α := Nat))) node_offset))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolZero.zeroVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) (HolSub.subVal node_size (HolOne.oneVal (α := Nat))))))) (holKBind (holBindE (holFunApp (holWhenE (holDisj (holLt node_window (HolOne.oneVal (α := Nat))) (holLt (holUnsigned L4vRefX64.Spec.Kernel_Config.retypeFanOutLimit) node_window))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolOne.oneVal (α := (BitVec 64))) L4vRefX64.Spec.Kernel_Config.retypeFanOutLimit))) (holKBind (holBindE (holFunApp (holWhenE (holDisj (holLt node_window (HolOne.oneVal (α := Nat))) (holLt (HolSub.subVal node_size node_offset) node_window))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError (HolOne.oneVal (α := (BitVec 64))) ((holOfNat (α := (BitVec 64))) (HolSub.subVal node_size node_offset))))) (holKBind (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.obj_ref_of node_cap)) (fun (oref : (BitVec 64)) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holListMap (L4vRefX64.Spec.Machine_A.nat_to_cref radix_bits) (holListUpt node_offset (HolAdd.addVal node_offset node_window)))) (fun (offsets : (List (List Bool))) => (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holListMap (fun (cref : (List Bool)) => (Prod.mk oref cref)) offsets)) (fun (slots : (List ((BitVec 64) × (List Bool)))) => (holBindE (holMapMEx L4vRefX64.Spec.CSpaceAcc_A.ensure_empty slots) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holFunApp (L4vRefX64.Spec.Exceptions_A.const_on_failure false) (holBindE (L4vRefX64.Spec.CSpace_A.ensure_no_children slot) (holKBind ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) true))))) (fun (reset : Bool) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holIf reset (HolZero.zeroVal (α := Nat)) (L4vRefX64.Spec.Structures_A.free_index_of cap))) (fun (free_index : Nat) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Retype_A.get_free_ref (L4vRefX64.Spec.Structures_A.obj_ref_of cap) free_index)) (fun (free_ref : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.More_Word_Operations.alignUp free_ref object_size)) (fun (aligned_free_ref : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (HolSub.subVal (L4vRefX64.Spec.Structures_A.obj_size cap) ((holOfNat (α := (BitVec 64))) free_index))) (fun (untyped_free_bytes : (BitVec 64)) => (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holWordShiftr untyped_free_bytes object_size)) (fun (max_count : (BitVec 64)) => (holBindE (holFunApp (holWhenE (holLt (holUnsigned max_count) node_window)) (holFunApp (holThrowError (α := Unit)) (holFunApp L4vRefX64.Spec.ExceptionTypes_A.syscall_error.NotEnoughMemory untyped_free_bytes))) (holKBind (holBindE ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (holNot (L4vRefX64.Spec.Structures_A.is_frame_type new_type))) (fun (not_frame : Bool) => (holBindE (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (dev : Bool) => (fun (p : (BitVec 64)) => (fun (n : Nat) => (fun (f : Nat) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (Prod.mk p dev)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error ((BitVec 64) × Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) cap) (holCaseProd (fun (ptr : (BitVec 64)) => (fun (is_device : Bool) => (holBindE (holFunApp (holWhenE (holConj is_device (holConj not_frame (holNot (holEq new_type L4vRefX64.Spec.Structures_A.apiobject_type.Untyped))))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument (HolOne.oneVal (α := Nat))))) (holKBind (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.untyped_invocation.Retype slot reset ptr aligned_free_ref new_type user_obj_size slots is_device))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) + +def decode_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → ((BitVec 64) → ((List (BitVec 64)) → ((List Bool) → (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Structures_A.cap → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error L4vRefX64.Spec.Invocations_A.invocation) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))))) := + (fun (first_phase : Bool) => (fun (label : (BitVec 64)) => (fun (args : (List (BitVec 64))) => (fun (cap_index : (List Bool)) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (excaps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (buffer : (Option (BitVec 64))) => (L4vRefX64.Spec.Structures_A.case_cap (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))) (fun (dev : Bool) => (fun (ptr : (BitVec 64)) => (fun (sz : Nat) => (fun (fi : Nat) => (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeUntyped) (L4vRefX64.Spec.Decode_A.decode_untyped_invocation label args slot cap (holListMap Prod.fst excaps))))))) (fun (ptr : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holMember L4vRefX64.Spec.CapRights_A.AllowSend rights) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.invocation.InvokeEndpoint ptr badge (holMember L4vRefX64.Spec.CapRights_A.rights.AllowGrant rights) (holMember L4vRefX64.Spec.CapRights_A.rights.AllowGrantReply rights))) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))))))) (fun (ptr : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holMember L4vRefX64.Spec.CapRights_A.AllowSend rights) (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.invocation.InvokeNotification ptr badge)) (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))))))) (fun (reply : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Invocations_A.invocation.InvokeReply reply (holMember L4vRefX64.Spec.CapRights_A.rights.AllowGrant rights))))) (fun (ptr : (BitVec 64)) => (fun (bits : Nat) => (fun (x : (List Bool)) => (holIf first_phase (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))) (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeCNode) (L4vRefX64.Spec.Decode_A.decode_cnode_invocation label args cap (holListMap Prod.fst excaps))))))) (fun (ptr : (BitVec 64)) => (holIf first_phase (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))) (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeTCB) (L4vRefX64.Spec.Decode_A.decode_tcb_invocation label args cap slot excaps)))) (holIf first_phase (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))) (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeDomain) (L4vRefX64.Spec.Decode_A.decode_domain_invocation label args excaps))) (fun (sc : (BitVec 64)) => (fun (sz : Nat) => (holIf first_phase (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))) (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeSchedContext) (L4vRefX64.Spec.Decode_A.decode_sched_context_invocation label sc (holListMap Prod.fst excaps)))))) (holIf first_phase (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat)))) (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeSchedControl) (L4vRefX64.Spec.Decode_A.decode_sched_control_invocation_flags label args (holListMap Prod.fst excaps)))) (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeIRQControl) (L4vRefX64.Spec.Decode_A.decode_irq_control_invocation label args slot (holListMap Prod.fst excaps))) (fun (irq : (BitVec 8)) => (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeIRQHandler) (L4vRefX64.Spec.Decode_A.decode_irq_handler_invocation label irq excaps))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFunApp (holThrowError (α := L4vRefX64.Spec.Invocations_A.invocation)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability (HolZero.zeroVal (α := Nat))))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFunApp (holLiftME L4vRefX64.Spec.Invocations_A.invocation.InvokeArchObject) (L4vRefX64.Spec.ArchDecode_A.arch_decode_invocation label args cap_index slot arch_cap excaps))) cap))))))))) +end +end L4vRefX64.Spec.Decode_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Deterministic_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Deterministic_A.lean new file mode 100644 index 000000000..7e0fa280a --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Deterministic_A.lean @@ -0,0 +1,184 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Deterministic_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.List_Lib +import L4vRefX64.Spec.MiscMachine_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Deterministic_A +open L4vRefX64.Prim +open Classical +noncomputable section +structure det_ext_ext (more : Type) where + work_units_completed_internal : (BitVec 64) + cdt_list_internal : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) + more : more +instance {more : Type} [Nonempty more] : Nonempty (det_ext_ext more) := ⟨det_ext_ext.mk holUndefined holUndefined holUndefined⟩ +abbrev det_ext := det_ext_ext Unit +def det_ext.truncate {more : Type} (r : (det_ext_ext more)) : det_ext_ext Unit := { r with more := () } +def det_ext.extend {more : Type} (r : det_ext_ext Unit) (m : more) : (det_ext_ext more) := { r with more := m } +def det_ext.work_units_completed_internal_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (det_ext_ext more)) : (det_ext_ext more) := { r with work_units_completed_internal := g r.work_units_completed_internal } +def det_ext.cdt_list_internal_update {more : Type} (g : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) (r : (det_ext_ext more)) : (det_ext_ext more) := { r with cdt_list_internal := g r.cdt_list_internal } + +class state_ext_class (Z : Type) where + ext_init : Z + select_switch : Z → Bool + unwrap_ext : L4vRefX64.Spec.Structures_A.state Z → L4vRefX64.Spec.Structures_A.state det_ext + wrap_ext : (det_ext → det_ext) → Z → Z + wrap_ext_bool : HolNonDet (L4vRefX64.Spec.Structures_A.state det_ext) Bool → HolNonDet (L4vRefX64.Spec.Structures_A.state Z) Bool + wrap_ext_op : HolNonDet (L4vRefX64.Spec.Structures_A.state det_ext) Unit → HolNonDet (L4vRefX64.Spec.Structures_A.state Z) Unit + +def OR_choice {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_a : Type} [Nonempty tv_a] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (c : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) => (fun (f : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (fun (g : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (ex : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holBind (holSelectF (holMkEf (L4vRefX64.Spec.Deterministic_A.state_ext_class.wrap_ext_bool c ex))) (holCaseProd (fun (rv : Bool) => (fun (uu_ : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holIf rv f g)))))))))) + +def OR_choiceE {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_e : Type} [Nonempty tv_e] {tv_a : Type} [Nonempty tv_a] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_e tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_e tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_e tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (c : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) => (fun (f : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_e tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (fun (g : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_e tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBindE ((holLiftE (ε := tv_e)) (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (ex : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holBindE (holFunApp (holLiftE (ε := tv_e)) (holSelectF (holMkEf (L4vRefX64.Spec.Deterministic_A.state_ext_class.wrap_ext_bool c ex)))) (holCaseProd (fun (rv : Bool) => (fun (uu_ : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holIf rv f g)))))))))) + +def trans_state {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] : ((tv_a → tv_b) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_b Unit)))) := + (fun (t : (tv_a → tv_b)) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.extend (L4vRefX64.Spec.Structures_A.abstract_state.truncate s) (L4vRefX64.Spec.Structures_A.state.fields (t (L4vRefX64.Spec.Structures_A.state.exst s)))))) + +def set_cdt_list : ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) := + (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (holFunApp holPut (L4vRefX64.Spec.Deterministic_A.trans_state (L4vRefX64.Spec.Deterministic_A.det_ext.cdt_list_internal_update (fun (uu_ : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => t)) s))))) + +def update_cdt_list : (((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) := + (fun (f : ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))))) => (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.det_ext_ext.cdt_list_internal (L4vRefX64.Spec.Structures_A.state.exst s)))) (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Deterministic_A.set_cdt_list (f t))))) + +def cap_insert_ext : (Bool → (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → ((Option ((BitVec 64) × (List Bool))) → ((Option ((BitVec 64) × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))))))) := + (fun (src_parent : Bool) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (dest_slot : ((BitVec 64) × (List Bool))) => (fun (src_p : (Option ((BitVec 64) × (List Bool)))) => (fun (dest_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseOption list (fun (p : ((BitVec 64) × (List Bool))) => (holFunUpd list p (L4vRefX64.Spec.List_Lib.list_remove (list p) dest_slot))) dest_p))) (holKBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseOption (holFunUpd list src_slot (holIf src_parent (holListAppend (List.cons dest_slot (List.nil (α := ((BitVec 64) × (List Bool))))) (list src_slot)) (list src_slot))) (fun (p : ((BitVec 64) × (List Bool))) => (holFunUpd (holFunUpd list src_slot (holIf src_parent (holListAppend (List.cons dest_slot (List.nil (α := ((BitVec 64) × (List Bool))))) (list src_slot)) (list src_slot))) p (holIf (holConj src_parent (holNot (holEq p src_slot))) (list p) (holIf (holNot (holEq src_slot dest_slot)) (L4vRefX64.Spec.List_Lib.list_insert_after (list p) src_slot dest_slot) (List.cons dest_slot (list p)))))) src_p)))))))))) + +def cap_move_ext : (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → ((Option ((BitVec 64) × (List Bool))) → ((Option ((BitVec 64) × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)))))) := + (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (dest_slot : ((BitVec 64) × (List Bool))) => (fun (src_p : (Option ((BitVec 64) × (List Bool)))) => (fun (dest_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseOption list (fun (p : ((BitVec 64) × (List Bool))) => (holFunUpd list p (L4vRefX64.Spec.List_Lib.list_remove (list p) dest_slot))) dest_p))) (holKBind (holIf (holEq src_slot dest_slot) (holReturn ()) (holBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseOption list (fun (p : ((BitVec 64) × (List Bool))) => (holFunUpd list p (L4vRefX64.Spec.List_Lib.list_replace (list p) src_slot dest_slot))) src_p))) (holKBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holFunUpd (holFunUpd list src_slot (List.nil (α := ((BitVec 64) × (List Bool))))) dest_slot (holListAppend (list src_slot) (list dest_slot)))))))))))))) + +def cap_swap_ext : (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → ((Option ((BitVec 64) × (List Bool))) → ((Option ((BitVec 64) × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)))))) := + (fun (slot1 : ((BitVec 64) × (List Bool))) => (fun (slot2 : ((BitVec 64) × (List Bool))) => (fun (slot1_op : (Option ((BitVec 64) × (List Bool)))) => (fun (slot2_op : (Option ((BitVec 64) × (List Bool)))) => (holBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holFunUpd (holFunUpd list slot1 (list slot2)) slot2 (list slot1)))) (holKBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseOption (holCaseOption list (fun (slot2_p : ((BitVec 64) × (List Bool))) => (holFunUpd list slot2_p (L4vRefX64.Spec.List_Lib.list_replace (list slot2_p) slot1 slot2))) (holIf (holEq slot1_op (Option.some slot1)) (Option.some slot2) (holIf (holEq slot1_op (Option.some slot2)) (Option.some slot1) slot1_op))) (fun (slot1_p : ((BitVec 64) × (List Bool))) => (holCaseOption (holFunUpd list slot1_p (L4vRefX64.Spec.List_Lib.list_replace (list slot1_p) slot2 slot1)) (fun (slot2_p : ((BitVec 64) × (List Bool))) => (holIf (holEq slot1_p slot2_p) (holFunUpd list slot1_p (L4vRefX64.Spec.List_Lib.list_swap (list slot1_p) slot1 slot2)) (holFunUpd (holFunUpd list slot1_p (L4vRefX64.Spec.List_Lib.list_replace (list slot1_p) slot2 slot1)) slot2_p (L4vRefX64.Spec.List_Lib.list_replace (list slot2_p) slot1 slot2)))) (holIf (holEq slot1_op (Option.some slot1)) (Option.some slot2) (holIf (holEq slot1_op (Option.some slot2)) (Option.some slot1) slot1_op)))) (holIf (holEq slot2_op (Option.some slot1)) (Option.some slot2) (holIf (holEq slot2_op (Option.some slot2)) (Option.some slot1) slot2_op))))))))))) + +def cdt_list : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.det_ext_ext.cdt_list_internal (L4vRefX64.Spec.Structures_A.state.exst s))) + +def cdt_list_update : (((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) := + (fun (f : ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))))) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.trans_state (L4vRefX64.Spec.Deterministic_A.det_ext.cdt_list_internal_update f) s))) + +def create_cap_ext : (((BitVec 64) × (List Bool)) → (((BitVec 64) × (List Bool)) → ((Option ((BitVec 64) × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))))) := + (fun (untyped : ((BitVec 64) × (List Bool))) => (fun (dest : ((BitVec 64) × (List Bool))) => (fun (dest_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseOption list (fun (p : ((BitVec 64) × (List Bool))) => (holFunUpd list p (L4vRefX64.Spec.List_Lib.list_remove (list p) dest))) dest_p))) (holKBind (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holFunUpd list untyped (holListAppend (List.cons dest (List.nil (α := ((BitVec 64) × (List Bool))))) (list untyped)))))))))) + +def do_extended_op {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (eop : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) => (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (ex : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holBind (holSelectF (holMkEf (L4vRefX64.Spec.Deterministic_A.state_ext_class.wrap_ext_op eop ex))) (holCaseProd (fun (uu_ : Unit) => (fun (es_p : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holModify (fun (state : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.state.exst_update (fun (uu__1 : tv_z) => (L4vRefX64.Spec.Structures_A.state.exst es_p)) state)))))))))) + +def empty_slot_ext : (((BitVec 64) × (List Bool)) → ((Option ((BitVec 64) × (List Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (slot_p : (Option ((BitVec 64) × (List Bool)))) => (L4vRefX64.Spec.Deterministic_A.update_cdt_list (fun (list : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseOption (holFunUpd list slot (List.nil (α := ((BitVec 64) × (List Bool))))) (fun (p : ((BitVec 64) × (List Bool))) => (holIf (holEq p slot) (holFunUpd list p (L4vRefX64.Spec.List_Lib.list_remove (list p) slot)) (holFunUpd (holFunUpd list p (L4vRefX64.Spec.List_Lib.list_replace_list (list p) slot (list slot))) slot (List.nil (α := ((BitVec 64) × (List Bool))))))) slot_p))))) + +def free_asid_pool_select {tv_a : Type} [Nonempty tv_a] : (((BitVec 9) → (Option tv_a)) → ((BitVec 64) → (BitVec 9))) := + (fun (pool : ((BitVec 9) → (Option tv_a))) => (fun (base : (BitVec 64)) => (Prod.fst (holHd (holListFilter (holCaseProd (fun (x : (BitVec 9)) => (fun (y : (Option tv_a)) => (holConj (holNot (holEq (HolAdd.addVal ((holUcast (w := 64)) x) base) (HolZero.zeroVal (α := (BitVec 64))))) (holEq y (Option.none (α := tv_a))))))) (holAssocs pool)))))) + +def free_asid_select {tv_a : Type} [Nonempty tv_a] : (((BitVec 3) → (Option tv_a)) → (BitVec 3)) := + (fun (asid_table : ((BitVec 3) → (Option tv_a))) => (Prod.fst (holHd (holListFilter (holCaseProd (fun (x : (BitVec 3)) => (fun (y : (Option tv_a)) => (holConj (holLe x (HolSub.subVal (HolPow.powVal (HolNumeral.ofNatVal (α := (BitVec 3)) 2) L4vRefX64.Spec.MiscMachine_A.asid_high_bits) (HolOne.oneVal (α := (BitVec 3))))) (holEq y (Option.none (α := tv_a))))))) (holAssocs asid_table))))) + +def next_child : (((BitVec 64) × (List Bool)) → ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → (Option ((BitVec 64) × (List Bool))))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holCaseList (Option.none (α := ((BitVec 64) × (List Bool)))) (fun (x : ((BitVec 64) × (List Bool))) => (fun (xs : (List ((BitVec 64) × (List Bool)))) => (Option.some x))) (t slot)))) + +def next_sib : (((BitVec 64) × (List Bool)) → ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (Option ((BitVec 64) × (List Bool)))))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (fun (m : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holCaseOption (Option.none (α := ((BitVec 64) × (List Bool)))) (fun (p : ((BitVec 64) × (List Bool))) => (L4vRefX64.Spec.List_Lib.after_in_list (t p) slot)) (m slot))))) + +def next_not_child_graph : ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → ((Option ((BitVec 64) × (List Bool))) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → ((Option ((BitVec 64) × (List Bool))) → Bool))) => (fun (x1 : (((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))))) => (fun (x2 : (Option ((BitVec 64) × (List Bool)))) => (holEx (fun (next_not_child_sum : ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → (Option ((BitVec 64) × (List Bool))))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holEx (fun (m : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holConj (holEq x1 (Prod.mk slot (Prod.mk t m))) (holConj (holEq x2 (holIf (holEq (L4vRefX64.Spec.Deterministic_A.next_sib slot t m) (Option.none (α := ((BitVec 64) × (List Bool))))) (holCaseOption (Option.none (α := ((BitVec 64) × (List Bool)))) (fun (p_1 : ((BitVec 64) × (List Bool))) => (next_not_child_sum (Prod.mk p_1 (Prod.mk t m)))) (m slot)) (L4vRefX64.Spec.Deterministic_A.next_sib slot t m))) (holAll (fun (x2_1 : ((BitVec 64) × (List Bool))) => (holImp (holEq (L4vRefX64.Spec.Deterministic_A.next_sib slot t m) (Option.none (α := ((BitVec 64) × (List Bool))))) (holImp (holEq (m slot) (Option.some x2_1)) (p (Prod.mk x2_1 (Prod.mk t m)) (next_not_child_sum (Prod.mk x2_1 (Prod.mk t m)))))))))))))))))))))) + +def next_not_child_sumC : ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → (Option ((BitVec 64) × (List Bool)))) := + (fun (x : (((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))))) => (holTheDefault (holUndefined (α := (Option ((BitVec 64) × (List Bool))))) (fun (y : (Option ((BitVec 64) × (List Bool)))) => (L4vRefX64.Spec.Deterministic_A.next_not_child_graph x y)))) + +def next_not_child : (((BitVec 64) × (List Bool)) → ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (Option ((BitVec 64) × (List Bool)))))) := + (fun (x0 : ((BitVec 64) × (List Bool))) => (fun (x1 : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (fun (x2 : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (L4vRefX64.Spec.Deterministic_A.next_not_child_sumC (Prod.mk x0 (Prod.mk x1 x2)))))) + +def next_not_child_rel : ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → Bool)) := + (HolCompleteLattice.holLfp (fun (p : ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → ((((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))))) → Bool))) => (fun (x1 : (((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))))) => (fun (x2 : (((BitVec 64) × (List Bool)) × ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) × (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))))) => (holEx (fun (slot : ((BitVec 64) × (List Bool))) => (holEx (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (holEx (fun (m : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holEx (fun (x2_1 : ((BitVec 64) × (List Bool))) => (holConj (holEq x1 (Prod.mk x2_1 (Prod.mk t m))) (holConj (holEq x2 (Prod.mk slot (Prod.mk t m))) (holConj (holEq (L4vRefX64.Spec.Deterministic_A.next_sib slot t m) (Option.none (α := ((BitVec 64) × (List Bool))))) (holEq (m slot) (Option.some x2_1))))))))))))))))) + +def next_revoke_cap : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((BitVec 64) × (List Bool)))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (ext : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (holTheOpt (L4vRefX64.Spec.Deterministic_A.next_child slot (L4vRefX64.Spec.Deterministic_A.det_ext_ext.cdt_list_internal (L4vRefX64.Spec.Structures_A.state.exst ext)))))) + +def next_slot : (((BitVec 64) × (List Bool)) → ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (Option ((BitVec 64) × (List Bool)))))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (fun (m : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holIf (holNot (holEq (t slot) (List.nil (α := ((BitVec 64) × (List Bool)))))) (L4vRefX64.Spec.Deterministic_A.next_child slot t) (L4vRefX64.Spec.Deterministic_A.next_not_child slot t m))))) + +def reset_work_units : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) := + (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.trans_state (L4vRefX64.Spec.Deterministic_A.det_ext.work_units_completed_internal_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64))))) s))) + +def select_ext {tv_d : Type} [Nonempty tv_d] {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → tv_d) → ((Set tv_d) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (tv_d × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)))) := + (fun (a : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → tv_d)) => (fun (S : (Set tv_d)) => (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit))) => (holBind (holIf (L4vRefX64.Spec.Deterministic_A.state_ext_class.select_switch (L4vRefX64.Spec.Structures_A.state.exst s)) (holReturn (a (L4vRefX64.Spec.Deterministic_A.state_ext_class.unwrap_ext s))) (holSelect S)) (fun (x : tv_d) => (holBind (holAssert (holMember x S)) (holKBind (holReturn x))))))))) + +def ext_init_det_ext_ext : (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) := + (L4vRefX64.Spec.Deterministic_A.det_ext_ext.mk (HolZero.zeroVal (α := (BitVec 64))) (holK (List.nil (α := ((BitVec 64) × (List Bool))))) ()) + +def select_switch_det_ext_ext : ((L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) → Bool) := + (fun (uu_ : (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit)) => true) + +def unwrap_ext_det_ext_ext : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) := + (fun (x : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => x) + +def wrap_ext_bool_det_ext_ext : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) := + (fun (x : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) => x) + +def wrap_ext_det_ext_ext : (((L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) → (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit)) → ((L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) → (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit))) := + (fun (x : ((L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) → (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit))) => x) + +def wrap_ext_op_det_ext_ext : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) := + (fun (x : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) => x) + +def ext_init_unit : Unit := + () + +def select_switch_unit : (Unit → Bool) := + (fun (s : Unit) => false) + +def unwrap_ext_unit : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext Unit Unit)) → (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) := + (fun (uu_ : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext Unit Unit))) => (holUndefined (α := (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))))) + +def wrap_ext_bool_unit : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext Unit Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext Unit Unit)))) × Bool))) := + (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) => (holSelect (HolCompleteLattice.holTop (α := (Set Bool))))) + +def wrap_ext_op_unit : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext Unit Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext Unit Unit)))) × Bool))) := + (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool))) => (holReturn ())) + +def wrap_ext_unit : (((L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) → (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit)) → (Unit → Unit)) := + (fun (f : ((L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) → (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit))) => (fun (s : Unit) => ())) + +def truncate_state {tv_a : Type} [Nonempty tv_a] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext Unit Unit))) := + (L4vRefX64.Spec.Deterministic_A.trans_state (fun (uu_ : tv_a) => ())) + +def update_work_units : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) := + (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.trans_state (L4vRefX64.Spec.Deterministic_A.det_ext.work_units_completed_internal_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Deterministic_A.det_ext_ext.work_units_completed_internal (L4vRefX64.Spec.Structures_A.state.exst s)) (HolOne.oneVal (α := (BitVec 64)))))) s))) + +def valid_list_2 : ((((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool)))) → ((((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → Bool)) := + (fun (t : (((BitVec 64) × (List Bool)) → (List ((BitVec 64) × (List Bool))))) => (fun (m : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holConj (holAll (fun (p : ((BitVec 64) × (List Bool))) => (holEq (holListSet (t p)) (holCollect (fun (c : ((BitVec 64) × (List Bool))) => (holEq (m c) (Option.some p))))))) (holAll (fun (p : ((BitVec 64) × (List Bool))) => (holListDistinct (t p))))))) + +def valid_list : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → Bool) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.valid_list_2 (L4vRefX64.Spec.Deterministic_A.cdt_list s) (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s))) + +def work_units_completed : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → (BitVec 64)) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.det_ext_ext.work_units_completed_internal (L4vRefX64.Spec.Structures_A.state.exst s))) + +def work_units_completed_update : (((BitVec 64) → (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) := + (fun (f : ((BitVec 64) → (BitVec 64))) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.trans_state (L4vRefX64.Spec.Deterministic_A.det_ext.work_units_completed_internal_update f) s))) + +def work_units_limit : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 100) + +def work_units_limit_reached : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit)))) × Bool)) := + (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.det_ext_ext.work_units_completed_internal (L4vRefX64.Spec.Structures_A.state.exst s)))) (fun (work_units : (BitVec 64)) => (holReturn (holLe L4vRefX64.Spec.Deterministic_A.work_units_limit work_units)))) + +instance : state_ext_class Unit where + ext_init := ext_init_unit + select_switch := select_switch_unit + unwrap_ext := unwrap_ext_unit + wrap_ext := wrap_ext_unit + wrap_ext_bool := wrap_ext_bool_unit + wrap_ext_op := wrap_ext_op_unit + +instance : state_ext_class det_ext where + ext_init := ext_init_det_ext_ext + select_switch := select_switch_det_ext_ext + unwrap_ext := unwrap_ext_det_ext_ext + wrap_ext := wrap_ext_det_ext_ext + wrap_ext_bool := wrap_ext_bool_det_ext_ext + wrap_ext_op := wrap_ext_op_det_ext_ext +end +end L4vRefX64.Spec.Deterministic_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Event_H.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Event_H.lean new file mode 100644 index 000000000..ad469c510 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Event_H.lean @@ -0,0 +1,54 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.Event_H) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.MachineTypes + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Event_H +open L4vRefX64.Prim +open Classical +noncomputable section +inductive syscall where + | SysCall + | SysReplyRecv + | SysNBSendRecv + | SysNBSendWait + | SysSend + | SysNBSend + | SysRecv + | SysYield + | SysNBRecv + | SysWait + | SysNBWait +instance : Nonempty syscall := ⟨syscall.SysCall⟩ +def case_syscall {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : r_ty) (f6 : r_ty) (f7 : r_ty) (f8 : r_ty) (f9 : r_ty) (f10 : r_ty) : syscall → r_ty + | .SysCall => f0 + | .SysReplyRecv => f1 + | .SysNBSendRecv => f2 + | .SysNBSendWait => f3 + | .SysSend => f4 + | .SysNBSend => f5 + | .SysRecv => f6 + | .SysYield => f7 + | .SysNBRecv => f8 + | .SysWait => f9 + | .SysNBWait => f10 + +inductive event where + | SyscallEvent (a0 : L4vRefX64.Spec.Event_H.syscall) + | UnknownSyscall (a0 : Nat) + | UserLevelFault (a0 : (BitVec 64)) (a1 : (BitVec 64)) + | Interrupt + | VMFaultEvent (a0 : L4vRefX64.Spec.MachineTypes.vmfault_type) + | HypervisorEvent (a0 : L4vRefX64.Spec.MachineTypes.hyp_fault_type) +instance : Nonempty event := ⟨event.SyscallEvent holUndefined⟩ +def case_event {r_ty : Type} (f0 : L4vRefX64.Spec.Event_H.syscall → r_ty) (f1 : Nat → r_ty) (f2 : (BitVec 64) → (BitVec 64) → r_ty) (f3 : r_ty) (f4 : L4vRefX64.Spec.MachineTypes.vmfault_type → r_ty) (f5 : L4vRefX64.Spec.MachineTypes.hyp_fault_type → r_ty) : event → r_ty + | .SyscallEvent x0 => f0 x0 + | .UnknownSyscall x0 => f1 x0 + | .UserLevelFault x0 x1 => f2 x0 x1 + | .Interrupt => f3 + | .VMFaultEvent x0 => f4 x0 + | .HypervisorEvent x0 => f5 x0 +end +end L4vRefX64.Spec.Event_H diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ExceptionTypes_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ExceptionTypes_A.lean new file mode 100644 index 000000000..9d196d491 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/ExceptionTypes_A.lean @@ -0,0 +1,81 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.ExceptionTypes_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.MiscMachine_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.ExceptionTypes_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive lookup_failure where + | InvalidRoot + | MissingCapability (a0 : Nat) + | DepthMismatch (a0 : Nat) (a1 : Nat) + | GuardMismatch (a0 : Nat) (a1 : (List Bool)) +instance : Nonempty lookup_failure := ⟨lookup_failure.InvalidRoot⟩ +def case_lookup_failure {r_ty : Type} (f0 : r_ty) (f1 : Nat → r_ty) (f2 : Nat → Nat → r_ty) (f3 : Nat → (List Bool) → r_ty) : lookup_failure → r_ty + | .InvalidRoot => f0 + | .MissingCapability x0 => f1 x0 + | .DepthMismatch x0 x1 => f2 x0 x1 + | .GuardMismatch x0 x1 => f3 x0 x1 + +inductive fault where + | CapFault (a0 : (BitVec 64)) (a1 : Bool) (a2 : L4vRefX64.Spec.ExceptionTypes_A.lookup_failure) + | UnknownSyscallException (a0 : (BitVec 64)) + | UserException (a0 : (BitVec 64)) (a1 : (BitVec 64)) + | Timeout (a0 : (BitVec 64)) + | ArchFault (a0 : L4vRefX64.Spec.Machine_A.arch_fault) +instance : Nonempty fault := ⟨fault.CapFault holUndefined holUndefined holUndefined⟩ +def case_fault {r_ty : Type} (f0 : (BitVec 64) → Bool → L4vRefX64.Spec.ExceptionTypes_A.lookup_failure → r_ty) (f1 : (BitVec 64) → r_ty) (f2 : (BitVec 64) → (BitVec 64) → r_ty) (f3 : (BitVec 64) → r_ty) (f4 : L4vRefX64.Spec.Machine_A.arch_fault → r_ty) : fault → r_ty + | .CapFault x0 x1 x2 => f0 x0 x1 x2 + | .UnknownSyscallException x0 => f1 x0 + | .UserException x0 x1 => f2 x0 x1 + | .Timeout x0 => f3 x0 + | .ArchFault x0 => f4 x0 + +inductive syscall_error where + | InvalidArgument (a0 : Nat) + | InvalidCapability (a0 : Nat) + | IllegalOperation + | RangeError (a0 : (BitVec 64)) (a1 : (BitVec 64)) + | AlignmentError + | FailedLookup (a0 : Bool) (a1 : L4vRefX64.Spec.ExceptionTypes_A.lookup_failure) + | TruncatedMessage + | DeleteFirst + | RevokeFirst + | NotEnoughMemory (a0 : (BitVec 64)) +instance : Nonempty syscall_error := ⟨syscall_error.InvalidArgument holUndefined⟩ +def case_syscall_error {r_ty : Type} (f0 : Nat → r_ty) (f1 : Nat → r_ty) (f2 : r_ty) (f3 : (BitVec 64) → (BitVec 64) → r_ty) (f4 : r_ty) (f5 : Bool → L4vRefX64.Spec.ExceptionTypes_A.lookup_failure → r_ty) (f6 : r_ty) (f7 : r_ty) (f8 : r_ty) (f9 : (BitVec 64) → r_ty) : syscall_error → r_ty + | .InvalidArgument x0 => f0 x0 + | .InvalidCapability x0 => f1 x0 + | .IllegalOperation => f2 + | .RangeError x0 x1 => f3 x0 x1 + | .AlignmentError => f4 + | .FailedLookup x0 x1 => f5 x0 x1 + | .TruncatedMessage => f6 + | .DeleteFirst => f7 + | .RevokeFirst => f8 + | .NotEnoughMemory x0 => f9 x0 + +def msg_from_lookup_failure : (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure → (List (BitVec 64))) + | L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.InvalidRoot => (List.cons (HolOne.oneVal (α := (BitVec 64))) (List.nil (α := (BitVec 64)))) + | (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability n) => (List.cons (HolNumeral.ofNatVal (α := (BitVec 64)) 2) (List.cons ((holOfNat (α := (BitVec 64))) n) (List.nil (α := (BitVec 64))))) + | (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.DepthMismatch n m) => (List.cons (HolNumeral.ofNatVal (α := (BitVec 64)) 3) (List.cons ((holOfNat (α := (BitVec 64))) n) (List.cons ((holOfNat (α := (BitVec 64))) m) (List.nil (α := (BitVec 64)))))) + | (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.GuardMismatch n g) => (List.cons (HolNumeral.ofNatVal (α := (BitVec 64)) 4) (List.cons ((holOfNat (α := (BitVec 64))) n) (List.cons ((holOfBl (w := 64)) g) (List.cons ((holOfNat (α := (BitVec 64))) (holSize g)) (List.nil (α := (BitVec 64))))))) + +def msg_from_syscall_error : (L4vRefX64.Spec.ExceptionTypes_A.syscall_error → ((BitVec 64) × (List (BitVec 64)))) + | (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidArgument n) => (Prod.mk (HolOne.oneVal (α := (BitVec 64))) (List.cons ((holOfNat (α := (BitVec 64))) n) (List.nil (α := (BitVec 64))))) + | (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.InvalidCapability n) => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 2) (List.cons ((holOfNat (α := (BitVec 64))) n) (List.nil (α := (BitVec 64))))) + | L4vRefX64.Spec.ExceptionTypes_A.syscall_error.IllegalOperation => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 3) (List.nil (α := (BitVec 64)))) + | (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError minv maxv) => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 4) (List.cons minv (List.cons maxv (List.nil (α := (BitVec 64)))))) + | L4vRefX64.Spec.ExceptionTypes_A.syscall_error.AlignmentError => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 5) (List.nil (α := (BitVec 64)))) + | (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup s lf) => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 6) (holListAppend (List.cons (holIf s (HolOne.oneVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64)))) (List.nil (α := (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.msg_from_lookup_failure lf))) + | L4vRefX64.Spec.ExceptionTypes_A.syscall_error.TruncatedMessage => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 7) (List.nil (α := (BitVec 64)))) + | L4vRefX64.Spec.ExceptionTypes_A.syscall_error.DeleteFirst => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 8) (List.nil (α := (BitVec 64)))) + | L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RevokeFirst => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 9) (List.nil (α := (BitVec 64)))) + | (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.NotEnoughMemory n) => (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 10) (List.cons n (List.nil (α := (BitVec 64))))) +end +end L4vRefX64.Spec.ExceptionTypes_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Exceptions_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Exceptions_A.lean new file mode 100644 index 000000000..17ef25963 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Exceptions_A.lean @@ -0,0 +1,38 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Exceptions_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Exceptions_A +open L4vRefX64.Prim +open Classical +noncomputable section +def cap_fault_on_failure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_a : Type} [Nonempty tv_a] : ((BitVec 64) → (Bool → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.fault tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (cptr : (BitVec 64)) => (fun (rp : Bool) => (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holHandleE' m (holComp (holThrowError (α := tv_a)) (L4vRefX64.Spec.ExceptionTypes_A.fault.CapFault cptr rp)))))) + +def const_on_failure {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_f : Type} [Nonempty tv_f] : (tv_a → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_f tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (c : tv_a) => (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_f tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holCatch m (fun (x : tv_f) => (holReturn c))))) + +def empty_on_failure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_f : Type} [Nonempty tv_f] {tv_a : Type} [Nonempty tv_a] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_f (List tv_a)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_f (List tv_a)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holCatch m (fun (x : tv_f) => (holReturn (List.nil (α := tv_a)))))) + +def lookup_error_on_failure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_a : Type} [Nonempty tv_a] : (Bool → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (s : Bool) => (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holHandleE' m (holComp (holThrowError (α := tv_a)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.FailedLookup s))))) + +def null_cap_on_failure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.lookup_failure L4vRefX64.Spec.Structures_A.cap) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.cap × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (holLiftM (holCaseSum (fun (x : L4vRefX64.Spec.ExceptionTypes_A.lookup_failure) => L4vRefX64.Spec.Structures_A.cap.NullCap) holId)) + +def range_check {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (v : (BitVec 64)) => (fun (min_v : (BitVec 64)) => (fun (max_v : (BitVec 64)) => (holFunApp (holUnlessE (holConj (holLe min_v v) (holLe v max_v))) (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.syscall_error.RangeError min_v max_v)))))) + +def unify_failure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_f : Type} [Nonempty tv_f] {tv_a : Type} [Nonempty tv_a] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_f tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_f tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holHandleE' m (fun (x : tv_f) => ((holThrowError (α := tv_a)) ())))) + +def without_preemption {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_a : Type} [Nonempty tv_a] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (holLiftE (ε := Unit)) +end +end L4vRefX64.Spec.Exceptions_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/FPU_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/FPU_A.lean new file mode 100644 index 000000000..1c94c8d1d --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/FPU_A.lean @@ -0,0 +1,35 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.FPU_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.FPU_A +open L4vRefX64.Prim +open Classical +noncomputable section +def load_fpu_state {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (t : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.as_user t L4vRefX64.Spec.MachineOps.getFPUState) (fun (fpu_state : ((Fin 576) → (BitVec 8))) => (L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.writeFpuState fpu_state))))) + +def save_fpu_state {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (t : (BitVec 64)) => (holBind (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.readFpuState) (fun (fpu_state : ((Fin 576) → (BitVec 8))) => (L4vRefX64.Spec.KHeap_A.as_user t (L4vRefX64.Spec.MachineOps.setFPUState fpu_state))))) + +def set_x64_current_fpu_owner {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (new_owner : (Option (BitVec 64))) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_current_fpu_owner L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (cur_fpu_owner : (Option (BitVec 64))) => (holBind (holMaybeM (L4vRefX64.Spec.KHeap_A.arch_thread_set (L4vRefX64.Spec.Arch_Structs_A.arch_tcb.tcb_cur_fpu_update (fun (uu_ : Bool) => false))) cur_fpu_owner) (holKBind (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.arch_state_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_state.x64_current_fpu_owner_update (fun (uu__1 : (Option (BitVec 64))) => new_owner) (L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state s))) s))) (holKBind (holMaybeM (L4vRefX64.Spec.KHeap_A.arch_thread_set (L4vRefX64.Spec.Arch_Structs_A.arch_tcb.tcb_cur_fpu_update (fun (uu_ : Bool) => true))) new_owner)))))))) + +def switch_local_fpu_owner {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (new_owner : (Option (BitVec 64))) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_current_fpu_owner L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (cur_fpu_owner : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.enableFpu) (holKBind (holBind (holMaybeM L4vRefX64.Spec.FPU_A.save_fpu_state cur_fpu_owner) (holKBind (holBind (holCaseOption (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.disableFpu) (fun (tcb_ptr : (BitVec 64)) => (L4vRefX64.Spec.FPU_A.load_fpu_state tcb_ptr)) new_owner) (holKBind (L4vRefX64.Spec.FPU_A.set_x64_current_fpu_owner new_owner)))))))))) + +def fpu_release {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread_ptr : (BitVec 64)) => (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_current_fpu_owner L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (cur_fpu_owner : (Option (BitVec 64))) => (holFunApp (holWhen (holEq cur_fpu_owner (Option.some thread_ptr))) (L4vRefX64.Spec.FPU_A.switch_local_fpu_owner (Option.none (α := (BitVec 64)))))))) + +def lazy_fpu_restore {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_flags thread_ptr) (fun (flags : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holIf (holMember L4vRefX64.Spec.Structs_B.tcb_flag.FpuDisabled flags) (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.disableFpu) (holBind (holGets (holComp L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.x64_current_fpu_owner L4vRefX64.Spec.Structures_A.abstract_state_ext.arch_state)) (fun (cur_fpu_owner : (Option (BitVec 64))) => (holIf (holEq cur_fpu_owner (Option.some thread_ptr)) (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.enableFpu) (L4vRefX64.Spec.FPU_A.switch_local_fpu_owner (Option.some thread_ptr))))))))) +end +end L4vRefX64.Spec.FPU_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Hypervisor_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Hypervisor_A.lean new file mode 100644 index 000000000..e1d17235f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Hypervisor_A.lean @@ -0,0 +1,18 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Hypervisor_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Hypervisor_A +open L4vRefX64.Prim +open Classical +noncomputable section +def handle_hypervisor_fault {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.hyp_fault_type → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | thread, L4vRefX64.Spec.MachineTypes.hyp_fault_type.X64NoHypFaults => (holReturn ()) +end +end L4vRefX64.Spec.Hypervisor_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Init_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Init_A.lean new file mode 100644 index 000000000..60df71ec2 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Init_A.lean @@ -0,0 +1,62 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Init_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchRetype_A +import L4vRefX64.Spec.ArchVMAttributes_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Arch_Structs_B +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Platform +import L4vRefX64.Spec.Retype_A +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.Time + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Init_A +open L4vRefX64.Prim +open Classical +noncomputable section +def global_pd : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pde) := + (fun (i : (BitVec 9)) => (L4vRefX64.Spec.Arch_Structs_A.pde.LargePagePDE (holWordShiftl (HolAdd.addVal (HolNumeral.ofNatVal (α := (BitVec 64)) 261632) ((holUcast (w := 64)) i)) (HolNumeral.ofNatVal (α := Nat) 21)) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) + +def init_global_pd : (BitVec 64) := + (HolAdd.addVal L4vRefX64.Spec.Machine_A.kernel_base (HolNumeral.ofNatVal (α := (BitVec 64)) 24576)) + +def global_pdpt : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pdpte) := + (holFunUpd (fun (i : (BitVec 9)) => (L4vRefX64.Spec.Arch_Structs_A.pdpte.HugePagePDPTE (holWordShiftl ((holUcast (w := 64)) i) (HolNumeral.ofNatVal (α := Nat) 30)) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.vm_attribute))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) (HolNumeral.ofNatVal (α := (BitVec 9)) 511) (L4vRefX64.Spec.Arch_Structs_A.pdpte.PageDirectoryPDPTE (L4vRefX64.Spec.Platform.addrFromPPtr L4vRefX64.Spec.Init_A.init_global_pd) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) + +def init_global_pdpt : (BitVec 64) := + (HolAdd.addVal L4vRefX64.Spec.Machine_A.kernel_base (HolNumeral.ofNatVal (α := (BitVec 64)) 20480)) + +def global_pml4 : ((BitVec 9) → L4vRefX64.Spec.Arch_Structs_A.pml4e) := + (holFunUpd (fun (uu_ : (BitVec 9)) => L4vRefX64.Spec.Arch_Structs_A.pml4e.InvalidPML4E) (HolNumeral.ofNatVal (α := (BitVec 9)) 511) (L4vRefX64.Spec.Arch_Structs_A.pml4e.PDPointerTablePML4E (L4vRefX64.Spec.Platform.addrFromPPtr L4vRefX64.Spec.Init_A.init_global_pdpt) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.ArchVMAttributes_A.table_attr))) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) + +def init_global_pml4 : (BitVec 64) := + (HolAdd.addVal L4vRefX64.Spec.Machine_A.kernel_base (HolNumeral.ofNatVal (α := (BitVec 64)) 16384)) + +def init_arch_state : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit) := + (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext.mk (fun (x : (BitVec 3)) => (Option.none (α := (BitVec 64)))) L4vRefX64.Spec.Init_A.init_global_pml4 (fun (ref : (BitVec 64)) => (holIf (holMember ref (holAtLeastAtMost L4vRefX64.Spec.Machine_A.pptr_base (HolAdd.addVal L4vRefX64.Spec.Machine_A.pptr_base ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.pml4_shift_bits)))) L4vRefX64.Spec.Arch_Structs_B.x64vspace_region_use.X64VSpaceKernelWindow L4vRefX64.Spec.Arch_Structs_B.x64vspace_region_use.X64VSpaceInvalidRegion)) (List.nil (α := (BitVec 64))) (List.cons L4vRefX64.Spec.Init_A.init_global_pdpt (List.nil (α := (BitVec 64)))) (List.cons L4vRefX64.Spec.Init_A.init_global_pd (List.nil (α := (BitVec 64)))) (L4vRefX64.Spec.Arch_Structs_A.cr3.mk (HolZero.zeroVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64)))) (fun (uu_ : (BitVec 16)) => false) (HolOne.oneVal (α := (BitVec 64))) (fun (uu_ : (BitVec 64)) => ((holUcast (w := 8)) L4vRefX64.Spec.MachineOps.ioapicIRQLines)) (holK L4vRefX64.Spec.Arch_Structs_A.X64IRQState.IRQFree) (Option.none (α := (BitVec 64))) ()) + +def init_cdt {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] : (tv_a → (Option tv_b)) := + (fun (x : tv_a) => (Option.none (α := tv_b))) + +def init_irq_node_ptr : (BitVec 64) := + (HolAdd.addVal L4vRefX64.Spec.Machine_A.kernel_base (HolNumeral.ofNatVal (α := (BitVec 64)) 8192)) + +def init_kheap : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object)) := + (holFunUpd (holFunUpd (holFunUpd (holFunUpd (holFunUpd (fun (x : (BitVec 64)) => (holIf (holEx (fun (irq : (BitVec 8)) => (holEq (HolAdd.addVal L4vRefX64.Spec.Init_A.init_irq_node_ptr (holWordShiftl ((holUcast (w := 64)) irq) L4vRefX64.Spec.Arch_Structs_A.cte_level_bits)) x))) (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.CNode (HolZero.zeroVal (α := Nat)) (L4vRefX64.Spec.Retype_A.empty_cnode (HolZero.zeroVal (α := Nat))))) (Option.none (α := L4vRefX64.Spec.Structures_A.kernel_object)))) L4vRefX64.Spec.Machine_A.idle_thread_ptr (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb_ext.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.thread_state.IdleThreadState (HolZero.zeroVal (α := (BitVec 64))) (Option.none (α := L4vRefX64.Spec.ExceptionTypes_A.fault)) (Option.none (α := (BitVec 64))) (holMinBound (α := (BitVec 8))) (Option.some L4vRefX64.Spec.Machine_A.idle_sc_ptr) (Option.none (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 8))) L4vRefX64.Spec.Structures_A.default_domain (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.Structs_B.tcb_flag))) L4vRefX64.Spec.ArchRetype_A.init_arch_tcb ())))) L4vRefX64.Spec.Machine_A.idle_sc_ptr (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.SchedContext (L4vRefX64.Spec.Structures_A.sched_context.sc_refill_max_update (fun (uu_ : Nat) => (L4vRefX64.Spec.Structures_A.MIN_REFILLS : Nat)) (L4vRefX64.Spec.Structures_A.sched_context.sc_budget_update (fun (uu_ : (BitVec 64)) => L4vRefX64.Spec.Time.MAX_PERIOD) (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (uu_ : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (List.cons (L4vRefX64.Spec.Structures_A.refill_ext.mk (HolZero.zeroVal (α := (BitVec 64))) L4vRefX64.Spec.Time.MAX_PERIOD ()) (List.cons (L4vRefX64.Spec.Structures_A.refill_ext.mk L4vRefX64.Spec.Time.MAX_PERIOD (HolZero.zeroVal (α := (BitVec 64))) ()) (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit)))))) (L4vRefX64.Spec.Structures_A.sched_context.sc_tcb_update (fun (uu_ : (Option (BitVec 64))) => (Option.some L4vRefX64.Spec.Machine_A.idle_thread_ptr)) L4vRefX64.Spec.Structures_A.default_sched_context)))) (HolZero.zeroVal (α := Nat))))) L4vRefX64.Spec.Init_A.init_global_pml4 (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageMapL4 L4vRefX64.Spec.Init_A.global_pml4)))) L4vRefX64.Spec.Init_A.init_global_pdpt (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PDPointerTable L4vRefX64.Spec.Init_A.global_pdpt)))) L4vRefX64.Spec.Init_A.init_global_pd (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj.PageDirectory L4vRefX64.Spec.Init_A.global_pd)))) + +def init_ioc : (((BitVec 64) × (List Bool)) → Bool) := + (holCaseProd (fun (a : (BitVec 64)) => (fun (b : (List Bool)) => (holEx (fun (obj : L4vRefX64.Spec.Structures_A.kernel_object) => (holConj (holEq (L4vRefX64.Spec.Init_A.init_kheap a) (Option.some obj)) (holEx (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holConj (holEq (L4vRefX64.Spec.Structures_A.cap_of obj b) (Option.some cap)) (holNot (holEq cap L4vRefX64.Spec.Structures_A.cap.NullCap))))))))))) + +def init_A_st {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) := + (L4vRefX64.Spec.Structures_A.abstract_state_ext.mk L4vRefX64.Spec.Init_A.init_kheap L4vRefX64.Spec.Init_A.init_cdt L4vRefX64.Spec.Init_A.init_ioc L4vRefX64.Spec.Machine_A.idle_thread_ptr L4vRefX64.Spec.Machine_A.idle_thread_ptr (HolZero.zeroVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64))) L4vRefX64.Spec.Machine_A.idle_sc_ptr false L4vRefX64.Spec.Structures_A.scheduler_action.resume_cur_thread (List.cons (Prod.mk (HolZero.zeroVal (α := (BitVec 8))) (HolNeg.negVal (HolOne.oneVal (α := (BitVec 56))))) (List.cons (Prod.mk (HolZero.zeroVal (α := (BitVec 8))) (HolZero.zeroVal (α := (BitVec 56)))) (List.nil (α := ((BitVec 8) × (BitVec 56)))))) (HolZero.zeroVal (α := Nat)) (HolZero.zeroVal (α := Nat)) (HolZero.zeroVal (α := (BitVec 8))) (HolNumeral.ofNatVal (α := (BitVec 64)) 15) (holK (holK (List.nil (α := (BitVec 64))))) (List.nil (α := (BitVec 64))) L4vRefX64.Spec.MachineTypes.init_machine_state (fun (irq : (BitVec 8)) => (HolAdd.addVal L4vRefX64.Spec.Init_A.init_irq_node_ptr (holWordShiftl ((holUcast (w := 64)) irq) L4vRefX64.Spec.Arch_Structs_A.cte_level_bits))) (fun (uu_ : (BitVec 8)) => L4vRefX64.Spec.Structures_A.irq_state.IRQInactive) L4vRefX64.Spec.Init_A.init_arch_state (L4vRefX64.Spec.Structures_A.state_ext.mk (L4vRefX64.Spec.Deterministic_A.state_ext_class.ext_init : tv_a) ())) +end +end L4vRefX64.Spec.Init_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Interrupt_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Interrupt_A.lean new file mode 100644 index 000000000..368f8083f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Interrupt_A.lean @@ -0,0 +1,38 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Interrupt_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchInterrupt_A +import L4vRefX64.Spec.Arch_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.Ipc_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Platform +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Interrupt_A +open L4vRefX64.Prim +open Classical +noncomputable section +def handle_interrupt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (holIf (holLt L4vRefX64.Spec.Platform.maxIRQ irq) (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (holBind (L4vRefX64.Spec.MachineOps.maskInterrupt true irq) (holKBind (L4vRefX64.Spec.MachineOps.ackInterrupt irq)))) (holBind (L4vRefX64.Spec.KHeap_A.get_irq_state irq) (fun (st : L4vRefX64.Spec.Structures_A.irq_state) => (holBind (L4vRefX64.Spec.Structures_A.case_irq_state (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holBind (L4vRefX64.Spec.KHeap_A.get_irq_slot irq) (fun (slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBind (holFunApp (holWhen (holConj (L4vRefX64.Spec.Structures_A.is_ntfn_cap cap) (holMember L4vRefX64.Spec.CapRights_A.AllowSend (L4vRefX64.Spec.Structures_A.cap_rights cap)))) (L4vRefX64.Spec.Ipc_A.send_signal (L4vRefX64.Spec.Structures_A.obj_ref_of cap) (L4vRefX64.Spec.Structures_A.cap_ep_badge cap))) (holKBind (L4vRefX64.Spec.ArchInterrupt_A.arch_mask_irq_signal irq))))))) (holBind (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.ackDeadlineIRQ) (holKBind (holFunApp holModify (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (holK true))))) (L4vRefX64.Spec.ArchInterrupt_A.handle_reserved_irq irq) st) (holKBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.ackInterrupt irq)))))))) + +def invoke_irq_control {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.irq_control_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Invocations_A.irq_control_invocation.IRQControl irq handler_slot control_slot) => ((holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.KHeap_A.set_irq_state L4vRefX64.Spec.Structures_A.irq_state.IRQSignal irq) (holKBind (L4vRefX64.Spec.CSpace_A.cap_insert (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap irq) control_slot handler_slot)))) + | (L4vRefX64.Spec.Invocations_A.irq_control_invocation.ArchIRQControl invok) => (L4vRefX64.Spec.Arch_A.arch_invoke_irq_control invok) + +def invoke_irq_handler {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.irq_handler_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.ACKIrq irq) => (L4vRefX64.Spec.ArchInterrupt_A.arch_invoke_irq_handler (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.ACKIrq irq)) + | (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.SetIRQHandler irq cap slot) => (holBind (L4vRefX64.Spec.KHeap_A.get_irq_slot irq) (fun (irq_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpace_A.cap_delete_one irq_slot) (holKBind (L4vRefX64.Spec.CSpace_A.cap_insert cap slot irq_slot))))) + | (L4vRefX64.Spec.Invocations_A.irq_handler_invocation.ClearIRQHandler irq) => (holBind (L4vRefX64.Spec.KHeap_A.get_irq_slot irq) L4vRefX64.Spec.CSpace_A.cap_delete_one) + +def maybe_handle_interrupt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (in_kernel : Bool) => (holBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.getActiveIRQ in_kernel)) (fun (irq_opt : (Option (BitVec 8))) => (holCaseOption L4vRefX64.Spec.ArchInterrupt_A.handle_spurious_irq (fun (irq : (BitVec 8)) => (L4vRefX64.Spec.Interrupt_A.handle_interrupt irq)) irq_opt)))) +end +end L4vRefX64.Spec.Interrupt_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/InvocationLabels_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/InvocationLabels_A.lean new file mode 100644 index 000000000..c4d56c240 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/InvocationLabels_A.lean @@ -0,0 +1,21 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.InvocationLabels_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchInvocationLabels_H +import L4vRefX64.Spec.InvocationLabels_H +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.MiscMachine_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.InvocationLabels_A +open L4vRefX64.Prim +open Classical +noncomputable section +def invocation_type : ((BitVec 64) → L4vRefX64.Spec.InvocationLabels_H.invocation_label) := + (fun (x : (BitVec 64)) => (holIf (holEx (fun (v : L4vRefX64.Spec.InvocationLabels_H.invocation_label) => (holEq (holFromEnum v) (L4vRefX64.Spec.Machine_A.data_to_nat x)))) (holToEnum (L4vRefX64.Spec.Machine_A.data_to_nat x)) (L4vRefX64.Spec.InvocationLabels_H.invocation_label.GenInvocationLabel L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.InvalidInvocation))) + +def gen_invocation_type : ((BitVec 64) → L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels) := + (fun (x : (BitVec 64)) => (L4vRefX64.Spec.InvocationLabels_H.case_invocation_label (fun (l : L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels) => l) (fun (x_1 : L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label) => L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.InvalidInvocation) (L4vRefX64.Spec.InvocationLabels_A.invocation_type x))) +end +end L4vRefX64.Spec.InvocationLabels_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/InvocationLabels_H.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/InvocationLabels_H.lean new file mode 100644 index 000000000..307d2793d --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/InvocationLabels_H.lean @@ -0,0 +1,112 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.InvocationLabels_H) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchInvocationLabels_H + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.InvocationLabels_H +open L4vRefX64.Prim +open Classical +noncomputable section +inductive gen_invocation_labels where + | InvalidInvocation + | UntypedRetype + | TCBReadRegisters + | TCBWriteRegisters + | TCBCopyRegisters + | TCBConfigure + | TCBSetPriority + | TCBSetMCPriority + | TCBSetSchedParams + | TCBSetTimeoutEndpoint + | TCBSetIPCBuffer + | TCBSetSpace + | TCBSuspend + | TCBResume + | TCBBindNotification + | TCBUnbindNotification + | TCBSetTLSBase + | TCBSetFlags + | CNodeRevoke + | CNodeDelete + | CNodeCancelBadgedSends + | CNodeCopy + | CNodeMint + | CNodeMove + | CNodeMutate + | CNodeRotate + | IRQIssueIRQHandler + | IRQAckIRQ + | IRQSetIRQHandler + | IRQClearIRQHandler + | DomainSetSet + | DomainScheduleConfigure + | DomainScheduleSetStart + | SchedControlConfigureFlags + | SchedContextBind + | SchedContextUnbind + | SchedContextUnbindObject + | SchedContextConsumed + | SchedContextYieldTo +instance : Nonempty gen_invocation_labels := ⟨gen_invocation_labels.InvalidInvocation⟩ +def case_gen_invocation_labels {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : r_ty) (f6 : r_ty) (f7 : r_ty) (f8 : r_ty) (f9 : r_ty) (f10 : r_ty) (f11 : r_ty) (f12 : r_ty) (f13 : r_ty) (f14 : r_ty) (f15 : r_ty) (f16 : r_ty) (f17 : r_ty) (f18 : r_ty) (f19 : r_ty) (f20 : r_ty) (f21 : r_ty) (f22 : r_ty) (f23 : r_ty) (f24 : r_ty) (f25 : r_ty) (f26 : r_ty) (f27 : r_ty) (f28 : r_ty) (f29 : r_ty) (f30 : r_ty) (f31 : r_ty) (f32 : r_ty) (f33 : r_ty) (f34 : r_ty) (f35 : r_ty) (f36 : r_ty) (f37 : r_ty) (f38 : r_ty) : gen_invocation_labels → r_ty + | .InvalidInvocation => f0 + | .UntypedRetype => f1 + | .TCBReadRegisters => f2 + | .TCBWriteRegisters => f3 + | .TCBCopyRegisters => f4 + | .TCBConfigure => f5 + | .TCBSetPriority => f6 + | .TCBSetMCPriority => f7 + | .TCBSetSchedParams => f8 + | .TCBSetTimeoutEndpoint => f9 + | .TCBSetIPCBuffer => f10 + | .TCBSetSpace => f11 + | .TCBSuspend => f12 + | .TCBResume => f13 + | .TCBBindNotification => f14 + | .TCBUnbindNotification => f15 + | .TCBSetTLSBase => f16 + | .TCBSetFlags => f17 + | .CNodeRevoke => f18 + | .CNodeDelete => f19 + | .CNodeCancelBadgedSends => f20 + | .CNodeCopy => f21 + | .CNodeMint => f22 + | .CNodeMove => f23 + | .CNodeMutate => f24 + | .CNodeRotate => f25 + | .IRQIssueIRQHandler => f26 + | .IRQAckIRQ => f27 + | .IRQSetIRQHandler => f28 + | .IRQClearIRQHandler => f29 + | .DomainSetSet => f30 + | .DomainScheduleConfigure => f31 + | .DomainScheduleSetStart => f32 + | .SchedControlConfigureFlags => f33 + | .SchedContextBind => f34 + | .SchedContextUnbind => f35 + | .SchedContextUnbindObject => f36 + | .SchedContextConsumed => f37 + | .SchedContextYieldTo => f38 + +inductive invocation_label where + | GenInvocationLabel (a0 : L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels) + | ArchInvocationLabel (a0 : L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label) +instance : Nonempty invocation_label := ⟨invocation_label.GenInvocationLabel holUndefined⟩ +def case_invocation_label {r_ty : Type} (f0 : L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels → r_ty) (f1 : L4vRefX64.Spec.ArchInvocationLabels_H.arch_invocation_label → r_ty) : invocation_label → r_ty + | .GenInvocationLabel x0 => f0 x0 + | .ArchInvocationLabel x0 => f1 x0 + +def enum_gen_invocation_labels : (List L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels) := + (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.InvalidInvocation (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.UntypedRetype (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBReadRegisters (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBWriteRegisters (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBCopyRegisters (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBConfigure (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetPriority (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetMCPriority (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetSchedParams (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetTimeoutEndpoint (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetIPCBuffer (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetSpace (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSuspend (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBResume (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBBindNotification (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBUnbindNotification (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetTLSBase (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.TCBSetFlags (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeRevoke (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeDelete (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeCancelBadgedSends (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeCopy (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeMint (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeMove (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeMutate (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.CNodeRotate (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQIssueIRQHandler (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQAckIRQ (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQSetIRQHandler (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.IRQClearIRQHandler (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.DomainSetSet (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.DomainScheduleConfigure (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.DomainScheduleSetStart (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.SchedControlConfigureFlags (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.SchedContextBind (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.SchedContextUnbind (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.SchedContextUnbindObject (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.SchedContextConsumed (List.cons L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels.SchedContextYieldTo (List.nil (α := L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels))))))))))))))))))))))))))))))))))))))))) + +instance : HolEnum L4vRefX64.Spec.InvocationLabels_H.gen_invocation_labels where enumList := L4vRefX64.Spec.InvocationLabels_H.enum_gen_invocation_labels + +def enum_invocation_label : (List L4vRefX64.Spec.InvocationLabels_H.invocation_label) := + (holListAppend (List.nil (α := L4vRefX64.Spec.InvocationLabels_H.invocation_label)) (holListAppend (holListMap L4vRefX64.Spec.InvocationLabels_H.invocation_label.GenInvocationLabel L4vRefX64.Spec.InvocationLabels_H.enum_gen_invocation_labels) (holListMap L4vRefX64.Spec.InvocationLabels_H.invocation_label.ArchInvocationLabel L4vRefX64.Spec.ArchInvocationLabels_H.enum_arch_invocation_label))) + +instance : HolEnum L4vRefX64.Spec.InvocationLabels_H.invocation_label where enumList := L4vRefX64.Spec.InvocationLabels_H.enum_invocation_label +end +end L4vRefX64.Spec.InvocationLabels_H diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Invocations_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Invocations_A.lean new file mode 100644 index 000000000..4edba1d6e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Invocations_A.lean @@ -0,0 +1,178 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Invocations_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchInvocation_A +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Invocations_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive cnode_invocation where + | InsertCall (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) (a2 : ((BitVec 64) × (List Bool))) + | MoveCall (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : ((BitVec 64) × (List Bool))) (a2 : ((BitVec 64) × (List Bool))) + | RevokeCall (a0 : ((BitVec 64) × (List Bool))) + | DeleteCall (a0 : ((BitVec 64) × (List Bool))) + | RotateCall (a0 : L4vRefX64.Spec.Structures_A.cap) (a1 : L4vRefX64.Spec.Structures_A.cap) (a2 : ((BitVec 64) × (List Bool))) (a3 : ((BitVec 64) × (List Bool))) (a4 : ((BitVec 64) × (List Bool))) + | CancelBadgedSendsCall (a0 : L4vRefX64.Spec.Structures_A.cap) +instance : Nonempty cnode_invocation := ⟨cnode_invocation.InsertCall holUndefined holUndefined holUndefined⟩ +def case_cnode_invocation {r_ty : Type} (f0 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → r_ty) (f1 : L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → r_ty) (f2 : ((BitVec 64) × (List Bool)) → r_ty) (f3 : ((BitVec 64) × (List Bool)) → r_ty) (f4 : L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → r_ty) (f5 : L4vRefX64.Spec.Structures_A.cap → r_ty) : cnode_invocation → r_ty + | .InsertCall x0 x1 x2 => f0 x0 x1 x2 + | .MoveCall x0 x1 x2 => f1 x0 x1 x2 + | .RevokeCall x0 => f2 x0 + | .DeleteCall x0 => f3 x0 + | .RotateCall x0 x1 x2 x3 x4 => f4 x0 x1 x2 x3 x4 + | .CancelBadgedSendsCall x0 => f5 x0 + +inductive domain_invocation where + | InvokeDomainSet (a0 : (BitVec 64)) (a1 : (BitVec 8)) + | InvokeDomainScheduleSetStart (a0 : Nat) + | InvokeDomainScheduleConfigure (a0 : Nat) (a1 : (BitVec 8)) (a2 : (BitVec 56)) +instance : Nonempty domain_invocation := ⟨domain_invocation.InvokeDomainSet holUndefined holUndefined⟩ +def case_domain_invocation {r_ty : Type} (f0 : (BitVec 64) → (BitVec 8) → r_ty) (f1 : Nat → r_ty) (f2 : Nat → (BitVec 8) → (BitVec 56) → r_ty) : domain_invocation → r_ty + | .InvokeDomainSet x0 x1 => f0 x0 x1 + | .InvokeDomainScheduleSetStart x0 => f1 x0 + | .InvokeDomainScheduleConfigure x0 x1 x2 => f2 x0 x1 x2 + +inductive irq_control_invocation where + | IRQControl (a0 : (BitVec 8)) (a1 : ((BitVec 64) × (List Bool))) (a2 : ((BitVec 64) × (List Bool))) + | ArchIRQControl (a0 : L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation) +instance : Nonempty irq_control_invocation := ⟨irq_control_invocation.IRQControl holUndefined holUndefined holUndefined⟩ +def case_irq_control_invocation {r_ty : Type} (f0 : (BitVec 8) → ((BitVec 64) × (List Bool)) → ((BitVec 64) × (List Bool)) → r_ty) (f1 : L4vRefX64.Spec.ArchInvocation_A.arch_irq_control_invocation → r_ty) : irq_control_invocation → r_ty + | .IRQControl x0 x1 x2 => f0 x0 x1 x2 + | .ArchIRQControl x0 => f1 x0 + +inductive irq_handler_invocation where + | ACKIrq (a0 : (BitVec 8)) + | SetIRQHandler (a0 : (BitVec 8)) (a1 : L4vRefX64.Spec.Structures_A.cap) (a2 : ((BitVec 64) × (List Bool))) + | ClearIRQHandler (a0 : (BitVec 8)) +instance : Nonempty irq_handler_invocation := ⟨irq_handler_invocation.ACKIrq holUndefined⟩ +def case_irq_handler_invocation {r_ty : Type} (f0 : (BitVec 8) → r_ty) (f1 : (BitVec 8) → L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool)) → r_ty) (f2 : (BitVec 8) → r_ty) : irq_handler_invocation → r_ty + | .ACKIrq x0 => f0 x0 + | .SetIRQHandler x0 x1 x2 => f1 x0 x1 x2 + | .ClearIRQHandler x0 => f2 x0 + +inductive sched_context_invocation where + | InvokeSchedContextConsumed (a0 : (BitVec 64)) + | InvokeSchedContextBind (a0 : (BitVec 64)) (a1 : L4vRefX64.Spec.Structures_A.cap) + | InvokeSchedContextUnbindObject (a0 : (BitVec 64)) (a1 : L4vRefX64.Spec.Structures_A.cap) + | InvokeSchedContextUnbind (a0 : (BitVec 64)) + | InvokeSchedContextYieldTo (a0 : (BitVec 64)) +instance : Nonempty sched_context_invocation := ⟨sched_context_invocation.InvokeSchedContextConsumed holUndefined⟩ +def case_sched_context_invocation {r_ty : Type} (f0 : (BitVec 64) → r_ty) (f1 : (BitVec 64) → L4vRefX64.Spec.Structures_A.cap → r_ty) (f2 : (BitVec 64) → L4vRefX64.Spec.Structures_A.cap → r_ty) (f3 : (BitVec 64) → r_ty) (f4 : (BitVec 64) → r_ty) : sched_context_invocation → r_ty + | .InvokeSchedContextConsumed x0 => f0 x0 + | .InvokeSchedContextBind x0 x1 => f1 x0 x1 + | .InvokeSchedContextUnbindObject x0 x1 => f2 x0 x1 + | .InvokeSchedContextUnbind x0 => f3 x0 + | .InvokeSchedContextYieldTo x0 => f4 x0 + +inductive sched_control_invocation where + | InvokeSchedControlConfigureFlags (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : (BitVec 64)) (a3 : Nat) (a4 : (BitVec 64)) (a5 : (BitVec 64)) +instance : Nonempty sched_control_invocation := ⟨sched_control_invocation.InvokeSchedControlConfigureFlags holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +def case_sched_control_invocation {r_ty : Type} (f0 : (BitVec 64) → (BitVec 64) → (BitVec 64) → Nat → (BitVec 64) → (BitVec 64) → r_ty) : sched_control_invocation → r_ty + | .InvokeSchedControlConfigureFlags x0 x1 x2 x3 x4 x5 => f0 x0 x1 x2 x3 x4 x5 + +inductive tcb_invocation where + | WriteRegisters (a0 : (BitVec 64)) (a1 : Bool) (a2 : (List (BitVec 64))) (a3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) + | ReadRegisters (a0 : (BitVec 64)) (a1 : Bool) (a2 : (BitVec 64)) (a3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) + | CopyRegisters (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : Bool) (a3 : Bool) (a4 : Bool) (a5 : Bool) (a6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) + | ThreadControlCaps (a0 : (BitVec 64)) (a1 : ((BitVec 64) × (List Bool))) (a2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (a3 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (a4 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (a5 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (a6 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) + | ThreadControlSched (a0 : (BitVec 64)) (a1 : ((BitVec 64) × (List Bool))) (a2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) (a3 : (Option ((BitVec 8) × (BitVec 64)))) (a4 : (Option ((BitVec 8) × (BitVec 64)))) (a5 : (Option (Option (BitVec 64)))) + | Suspend (a0 : (BitVec 64)) + | Resume (a0 : (BitVec 64)) + | NotificationControl (a0 : (BitVec 64)) (a1 : (Option (BitVec 64))) + | SetTLSBase (a0 : (BitVec 64)) (a1 : (BitVec 64)) + | SetFlags (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) (a2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) +instance : Nonempty tcb_invocation := ⟨tcb_invocation.WriteRegisters holUndefined holUndefined holUndefined holUndefined⟩ +def case_tcb_invocation {r_ty : Type} (f0 : (BitVec 64) → Bool → (List (BitVec 64)) → L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets → r_ty) (f1 : (BitVec 64) → Bool → (BitVec 64) → L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets → r_ty) (f2 : (BitVec 64) → (BitVec 64) → Bool → Bool → Bool → Bool → L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets → r_ty) (f3 : (BitVec 64) → ((BitVec 64) × (List Bool)) → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))) → r_ty) (f4 : (BitVec 64) → ((BitVec 64) × (List Bool)) → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → (Option ((BitVec 8) × (BitVec 64))) → (Option ((BitVec 8) × (BitVec 64))) → (Option (Option (BitVec 64))) → r_ty) (f5 : (BitVec 64) → r_ty) (f6 : (BitVec 64) → r_ty) (f7 : (BitVec 64) → (Option (BitVec 64)) → r_ty) (f8 : (BitVec 64) → (BitVec 64) → r_ty) (f9 : (BitVec 64) → (Set L4vRefX64.Spec.Structs_B.tcb_flag) → (Set L4vRefX64.Spec.Structs_B.tcb_flag) → r_ty) : tcb_invocation → r_ty + | .WriteRegisters x0 x1 x2 x3 => f0 x0 x1 x2 x3 + | .ReadRegisters x0 x1 x2 x3 => f1 x0 x1 x2 x3 + | .CopyRegisters x0 x1 x2 x3 x4 x5 x6 => f2 x0 x1 x2 x3 x4 x5 x6 + | .ThreadControlCaps x0 x1 x2 x3 x4 x5 x6 => f3 x0 x1 x2 x3 x4 x5 x6 + | .ThreadControlSched x0 x1 x2 x3 x4 x5 => f4 x0 x1 x2 x3 x4 x5 + | .Suspend x0 => f5 x0 + | .Resume x0 => f6 x0 + | .NotificationControl x0 x1 => f7 x0 x1 + | .SetTLSBase x0 x1 => f8 x0 x1 + | .SetFlags x0 x1 x2 => f9 x0 x1 x2 + +inductive untyped_invocation where + | Retype (a0 : ((BitVec 64) × (List Bool))) (a1 : Bool) (a2 : (BitVec 64)) (a3 : (BitVec 64)) (a4 : L4vRefX64.Spec.Structures_A.apiobject_type) (a5 : Nat) (a6 : (List ((BitVec 64) × (List Bool)))) (a7 : Bool) +instance : Nonempty untyped_invocation := ⟨untyped_invocation.Retype holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +def case_untyped_invocation {r_ty : Type} (f0 : ((BitVec 64) × (List Bool)) → Bool → (BitVec 64) → (BitVec 64) → L4vRefX64.Spec.Structures_A.apiobject_type → Nat → (List ((BitVec 64) × (List Bool))) → Bool → r_ty) : untyped_invocation → r_ty + | .Retype x0 x1 x2 x3 x4 x5 x6 x7 => f0 x0 x1 x2 x3 x4 x5 x6 x7 + +inductive invocation where + | InvokeUntyped (a0 : L4vRefX64.Spec.Invocations_A.untyped_invocation) + | InvokeEndpoint (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : Bool) (a3 : Bool) + | InvokeNotification (a0 : (BitVec 64)) (a1 : (BitVec 64)) + | InvokeReply (a0 : (BitVec 64)) (a1 : Bool) + | InvokeTCB (a0 : L4vRefX64.Spec.Invocations_A.tcb_invocation) + | InvokeDomain (a0 : L4vRefX64.Spec.Invocations_A.domain_invocation) + | InvokeSchedContext (a0 : L4vRefX64.Spec.Invocations_A.sched_context_invocation) + | InvokeSchedControl (a0 : L4vRefX64.Spec.Invocations_A.sched_control_invocation) + | InvokeCNode (a0 : L4vRefX64.Spec.Invocations_A.cnode_invocation) + | InvokeIRQControl (a0 : L4vRefX64.Spec.Invocations_A.irq_control_invocation) + | InvokeIRQHandler (a0 : L4vRefX64.Spec.Invocations_A.irq_handler_invocation) + | InvokeArchObject (a0 : L4vRefX64.Spec.ArchInvocation_A.arch_invocation) +instance : Nonempty invocation := ⟨invocation.InvokeUntyped holUndefined⟩ +def case_invocation {r_ty : Type} (f0 : L4vRefX64.Spec.Invocations_A.untyped_invocation → r_ty) (f1 : (BitVec 64) → (BitVec 64) → Bool → Bool → r_ty) (f2 : (BitVec 64) → (BitVec 64) → r_ty) (f3 : (BitVec 64) → Bool → r_ty) (f4 : L4vRefX64.Spec.Invocations_A.tcb_invocation → r_ty) (f5 : L4vRefX64.Spec.Invocations_A.domain_invocation → r_ty) (f6 : L4vRefX64.Spec.Invocations_A.sched_context_invocation → r_ty) (f7 : L4vRefX64.Spec.Invocations_A.sched_control_invocation → r_ty) (f8 : L4vRefX64.Spec.Invocations_A.cnode_invocation → r_ty) (f9 : L4vRefX64.Spec.Invocations_A.irq_control_invocation → r_ty) (f10 : L4vRefX64.Spec.Invocations_A.irq_handler_invocation → r_ty) (f11 : L4vRefX64.Spec.ArchInvocation_A.arch_invocation → r_ty) : invocation → r_ty + | .InvokeUntyped x0 => f0 x0 + | .InvokeEndpoint x0 x1 x2 x3 => f1 x0 x1 x2 x3 + | .InvokeNotification x0 x1 => f2 x0 x1 + | .InvokeReply x0 x1 => f3 x0 x1 + | .InvokeTCB x0 => f4 x0 + | .InvokeDomain x0 => f5 x0 + | .InvokeSchedContext x0 => f6 x0 + | .InvokeSchedControl x0 => f7 x0 + | .InvokeCNode x0 => f8 x0 + | .InvokeIRQControl x0 => f9 x0 + | .InvokeIRQHandler x0 => f10 x0 + | .InvokeArchObject x0 => f11 x0 + +def domain_invocation.dom_domain : (L4vRefX64.Spec.Invocations_A.domain_invocation → (BitVec 8)) + | domain_invocation => (L4vRefX64.Spec.Invocations_A.case_domain_invocation (fun (x11 : (BitVec 64)) => (fun (x12 : (BitVec 8)) => x12)) (fun (uu : Nat) => (holUndefined (α := (BitVec 8)))) (fun (x31 : Nat) => (fun (x32 : (BitVec 8)) => (fun (x33 : (BitVec 56)) => x32))) domain_invocation) + +def domain_invocation.dom_duration : (L4vRefX64.Spec.Invocations_A.domain_invocation → (BitVec 56)) + | domain_invocation => (L4vRefX64.Spec.Invocations_A.case_domain_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 8)) => (holUndefined (α := (BitVec 56))))) (fun (uu : Nat) => (holUndefined (α := (BitVec 56)))) (fun (x31 : Nat) => (fun (x32 : (BitVec 8)) => (fun (x33 : (BitVec 56)) => x33))) domain_invocation) + +def domain_invocation.dom_index : (L4vRefX64.Spec.Invocations_A.domain_invocation → Nat) + | domain_invocation => (L4vRefX64.Spec.Invocations_A.case_domain_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 8)) => (holUndefined (α := Nat)))) (fun (x2 : Nat) => x2) (fun (x31 : Nat) => (fun (x32 : (BitVec 8)) => (fun (x33 : (BitVec 56)) => x31))) domain_invocation) + +def domain_invocation.dom_thread : (L4vRefX64.Spec.Invocations_A.domain_invocation → (BitVec 64)) + | domain_invocation => (L4vRefX64.Spec.Invocations_A.case_domain_invocation (fun (x11 : (BitVec 64)) => (fun (x12 : (BitVec 8)) => x11)) (fun (uu : Nat) => (holUndefined (α := (BitVec 64)))) (fun (uu : Nat) => (fun (uu_1 : (BitVec 8)) => (fun (uu_2 : (BitVec 56)) => (holUndefined (α := (BitVec 64)))))) domain_invocation) + +def tcb_invocation.tc_new_buffer : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : ((BitVec 64) × (List Bool))) => (fun (x43 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x44 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x45 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x46 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x47 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => x47))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_3 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_4 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_5 : (Option (Option (BitVec 64)))) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))) tcb_invocation) + +def tcb_invocation.tc_new_croot : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : ((BitVec 64) × (List Bool))) => (fun (x43 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x44 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x45 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x46 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x47 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => x45))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_3 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_4 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_5 : (Option (Option (BitVec 64)))) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))) tcb_invocation) + +def tcb_invocation.tc_new_fault_handler : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : ((BitVec 64) × (List Bool))) => (fun (x43 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x44 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x45 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x46 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x47 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => x43))))))) (fun (x51 : (BitVec 64)) => (fun (x52 : ((BitVec 64) × (List Bool))) => (fun (x53 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x54 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x55 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x56 : (Option (Option (BitVec 64)))) => x53)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))) tcb_invocation) + +def tcb_invocation.tc_new_mcpriority : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option ((BitVec 8) × (BitVec 64)))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_3 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_4 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_5 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_6 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))))))))) (fun (x51 : (BitVec 64)) => (fun (x52 : ((BitVec 64) × (List Bool))) => (fun (x53 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x54 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x55 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x56 : (Option (Option (BitVec 64)))) => x54)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))))) tcb_invocation) + +def tcb_invocation.tc_new_priority : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option ((BitVec 8) × (BitVec 64)))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_3 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_4 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_5 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_6 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))))))))) (fun (x51 : (BitVec 64)) => (fun (x52 : ((BitVec 64) × (List Bool))) => (fun (x53 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x54 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x55 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x56 : (Option (Option (BitVec 64)))) => x55)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option ((BitVec 8) × (BitVec 64)))))))) tcb_invocation) + +def tcb_invocation.tc_new_sc : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option (Option (BitVec 64)))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (Option (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (Option (BitVec 64))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (Option (BitVec 64)))))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_3 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_4 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_5 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_6 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => (holUndefined (α := (Option (Option (BitVec 64)))))))))))) (fun (x51 : (BitVec 64)) => (fun (x52 : ((BitVec 64) × (List Bool))) => (fun (x53 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x54 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x55 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x56 : (Option (Option (BitVec 64)))) => x56)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (Option (BitVec 64)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (Option (BitVec 64)))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option (Option (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option (Option (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option (Option (BitVec 64)))))))) tcb_invocation) + +def tcb_invocation.tc_new_timeout_handler : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : ((BitVec 64) × (List Bool))) => (fun (x43 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x44 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x45 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x46 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x47 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => x44))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_3 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_4 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_5 : (Option (Option (BitVec 64)))) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))) tcb_invocation) + +def tcb_invocation.tc_new_vroot : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : ((BitVec 64) × (List Bool))) => (fun (x43 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x44 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x45 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x46 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x47 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => x46))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : ((BitVec 64) × (List Bool))) => (fun (uu_2 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (uu_3 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_4 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (uu_5 : (Option (Option (BitVec 64)))) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))))) tcb_invocation) + +def tcb_invocation.tc_slot : (L4vRefX64.Spec.Invocations_A.tcb_invocation → ((BitVec 64) × (List Bool))) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := ((BitVec 64) × (List Bool)))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := ((BitVec 64) × (List Bool))))))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : ((BitVec 64) × (List Bool))) => (fun (x43 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x44 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x45 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x46 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x47 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => x42))))))) (fun (x51 : (BitVec 64)) => (fun (x52 : ((BitVec 64) × (List Bool))) => (fun (x53 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x54 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x55 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x56 : (Option (Option (BitVec 64)))) => x52)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := ((BitVec 64) × (List Bool))))) (fun (uu : (BitVec 64)) => (holUndefined (α := ((BitVec 64) × (List Bool))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := ((BitVec 64) × (List Bool)))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := ((BitVec 64) × (List Bool)))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := ((BitVec 64) × (List Bool))))))) tcb_invocation) + +def tcb_invocation.tc_target : (L4vRefX64.Spec.Invocations_A.tcb_invocation → (BitVec 64)) + | tcb_invocation => (L4vRefX64.Spec.Invocations_A.case_tcb_invocation (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (List (BitVec 64))) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Bool) => (fun (uu_2 : (BitVec 64)) => (fun (uu_3 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (BitVec 64))))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Bool) => (fun (uu_3 : Bool) => (fun (uu_4 : Bool) => (fun (uu_5 : Bool) => (fun (uu_6 : L4vRefX64.Spec.ArchInvocation_A.arch_copy_register_sets) => (holUndefined (α := (BitVec 64)))))))))) (fun (x41 : (BitVec 64)) => (fun (x42 : ((BitVec 64) × (List Bool))) => (fun (x43 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x44 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x45 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x46 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x47 : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => x41))))))) (fun (x51 : (BitVec 64)) => (fun (x52 : ((BitVec 64) × (List Bool))) => (fun (x53 : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (x54 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x55 : (Option ((BitVec 8) × (BitVec 64)))) => (fun (x56 : (Option (Option (BitVec 64)))) => x51)))))) (fun (uu : (BitVec 64)) => (holUndefined (α := (BitVec 64)))) (fun (uu : (BitVec 64)) => (holUndefined (α := (BitVec 64)))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option (BitVec 64))) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (holUndefined (α := (BitVec 64))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (fun (uu_2 : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holUndefined (α := (BitVec 64)))))) tcb_invocation) +end +end L4vRefX64.Spec.Invocations_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/IpcCancel_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/IpcCancel_A.lean new file mode 100644 index 000000000..9c26a2791 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/IpcCancel_A.lean @@ -0,0 +1,208 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.IpcCancel_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchIpcCancel_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Init_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.Lib +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Sporadic_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.IpcCancel_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive gen_obj_ref where + | ObjRef (a0 : (BitVec 64)) + | IRQRef (a0 : (BitVec 8)) + | ArchRef (a0 : L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref) +instance : Nonempty gen_obj_ref := ⟨gen_obj_ref.ObjRef holUndefined⟩ +def case_gen_obj_ref {r_ty : Type} (f0 : (BitVec 64) → r_ty) (f1 : (BitVec 8) → r_ty) (f2 : L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref → r_ty) : gen_obj_ref → r_ty + | .ObjRef x0 => f0 x0 + | .IRQRef x0 => f1 x0 + | .ArchRef x0 => f2 x0 + +def arch_cap_set_map {tv_a : Type} [Nonempty tv_a] : ((L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Set tv_a)) → (L4vRefX64.Spec.Structures_A.cap → (Set tv_a))) := + (fun (f : (L4vRefX64.Spec.Arch_Structs_A.arch_cap → (Set tv_a))) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (HolCompleteLattice.holBot (α := (Set tv_a))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (HolCompleteLattice.holBot (α := (Set tv_a))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (HolCompleteLattice.holBot (α := (Set tv_a)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (HolCompleteLattice.holBot (α := (Set tv_a)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (HolCompleteLattice.holBot (α := (Set tv_a))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (HolCompleteLattice.holBot (α := (Set tv_a)))))) (fun (word : (BitVec 64)) => (HolCompleteLattice.holBot (α := (Set tv_a)))) (HolCompleteLattice.holBot (α := (Set tv_a))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (HolCompleteLattice.holBot (α := (Set tv_a))))) (HolCompleteLattice.holBot (α := (Set tv_a))) (HolCompleteLattice.holBot (α := (Set tv_a))) (fun (word : (BitVec 8)) => (HolCompleteLattice.holBot (α := (Set tv_a)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (HolCompleteLattice.holBot (α := (Set tv_a)))))) (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (f acap)) cap))) + +def arch_gen_refs : (L4vRefX64.Spec.Structures_A.cap → (Set L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_ref)) := + (L4vRefX64.Spec.IpcCancel_A.arch_cap_set_map L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_refs) + +def bind_sc_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (reply_ptr : (BitVec 64)) => (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.sched_context_ext.sc_replies) (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr)) (fun (sc_replies : (List (BitVec 64))) => (holBind (holCaseList (holReturn ()) (fun (r : (BitVec 64)) => (fun (x : (List (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_sc_update r (Option.none (α := (BitVec 64)))))) sc_replies) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_replies_update (fun (uu_ : (List (BitVec 64))) => (List.cons reply_ptr sc_replies)))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_sc_update reply_ptr (Option.some sc_ptr)))))))))) + +def ep_blocked : (L4vRefX64.Spec.Structures_A.thread_state → (Option (BitVec 64))) := + (fun (ts : L4vRefX64.Spec.Structures_A.thread_state) => (L4vRefX64.Spec.Structures_A.case_thread_state (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (fun (r : (BitVec 64)) => (fun (x : (Option (BitVec 64))) => (fun (xa : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (Option.some r)))) (fun (r : (BitVec 64)) => (fun (x : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (Option.some r))) (fun (word : (BitVec 64)) => (Option.none (α := (BitVec 64)))) (fun (word : (BitVec 64)) => (Option.none (α := (BitVec 64)))) (Option.none (α := (BitVec 64))) ts)) + +def get_blocking_object {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.thread_state → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (holFunApp holAssertOpt (L4vRefX64.Spec.IpcCancel_A.ep_blocked state))) + +def reply_unlink_tcb {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (t : (BitVec 64)) => (fun (r : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply r) (fun (reply : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holBind (holAssert (holEq (L4vRefX64.Spec.Structures_A.reply_ext.reply_tcb reply) (Option.some t))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state t) (fun (ts : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (holAssert (holDisj (holEq ts (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReply r)) (holEx (fun (ep : (BitVec 64)) => (holEx (fun (d : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holEq ts (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReceive ep (Option.some r) d)))))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_tcb_update r (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state t L4vRefX64.Spec.Structures_A.thread_state.Inactive))))))))))))) + +def update_ep_queue : (L4vRefX64.Spec.Structures_A.endpoint → ((List (BitVec 64)) → (Bool → L4vRefX64.Spec.Structures_A.endpoint))) + | (L4vRefX64.Spec.Structures_A.endpoint.RecvEP q), q_p, uu => (L4vRefX64.Spec.Structures_A.endpoint.RecvEP q_p) + | (L4vRefX64.Spec.Structures_A.endpoint.SendEP q), q_p, uv => (L4vRefX64.Spec.Structures_A.endpoint.SendEP q_p) + | L4vRefX64.Spec.Structures_A.endpoint.IdleEP, q_p, is_recv => (holIf is_recv (L4vRefX64.Spec.Structures_A.endpoint.RecvEP q_p) (L4vRefX64.Spec.Structures_A.endpoint.SendEP q_p)) + +def tcb_ep_dequeue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (ep_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint ep_ptr) (fun (ep : L4vRefX64.Spec.Structures_A.endpoint) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.endpoint.ep_queue ep)) (fun (q : (List (BitVec 64))) => (holBind (holAssert (holMember tptr (holListSet q))) (holKBind (holBind (holFunApp holReturn (holListRemoveAll tptr q)) (fun (q_p : (List (BitVec 64))) => (holBind (holReturn (holCaseList L4vRefX64.Spec.Structures_A.endpoint.IdleEP (fun (a : (BitVec 64)) => (fun (list : (List (BitVec 64))) => (L4vRefX64.Spec.IpcCancel_A.update_ep_queue ep q_p true))) q_p)) (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint ep_ptr)))))))))))) + +def blocked_cancel_ipc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.thread_state → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (fun (tptr : (BitVec 64)) => (fun (reply_opt : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.IpcCancel_A.get_blocking_object state) (fun (epptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ep_dequeue tptr epptr) (holKBind (holBind (holCaseOption (holReturn ()) (fun (r : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.reply_unlink_tcb tptr r)) reply_opt) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state tptr L4vRefX64.Spec.Structures_A.thread_state.Inactive)))))))))) + +def blocking_ipc_badge : (L4vRefX64.Spec.Structures_A.thread_state → (BitVec 64)) + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnSend t payload) => (L4vRefX64.Spec.Structures_A.sender_payload_ext.sender_badge payload) + | _ => holUndefined + +def restart_thread_if_no_fault {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (t : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_fault t) (fun (fault : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (holIf (holEq fault (Option.none (α := L4vRefX64.Spec.ExceptionTypes_A.fault))) (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state t L4vRefX64.Spec.Structures_A.thread_state.Restart) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context t) (fun (sc_opt : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some false) (Option.some true)) (holKBind (L4vRefX64.Spec.KHeap_A.possible_switch_to t))))))) (L4vRefX64.Spec.KHeap_A.set_thread_state t L4vRefX64.Spec.Structures_A.thread_state.Inactive))))) + +def remove_and_restart_ep_queued_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (t : (BitVec 64)) => (fun (epptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ep_dequeue t epptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state t) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (holReturn (holIf (L4vRefX64.Spec.Structures_A.is_blocked_on_receive st) (L4vRefX64.Spec.Structures_A.reply_object st) (Option.none (α := (BitVec 64))))) (fun (reply_opt : (Option (BitVec 64))) => (holBind (holMaybeM (L4vRefX64.Spec.IpcCancel_A.reply_unlink_tcb t) reply_opt) (holKBind (L4vRefX64.Spec.IpcCancel_A.restart_thread_if_no_fault t))))))))))) + +def cancel_all_ipc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (epptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint epptr) (fun (ep : L4vRefX64.Spec.Structures_A.endpoint) => (L4vRefX64.Spec.Structures_A.case_endpoint (holReturn ()) (fun (list : (List (BitVec 64))) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.endpoint.ep_queue ep)) (fun (queue : (List (BitVec 64))) => (holBind (holMapMx (fun (t : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.remove_and_restart_ep_queued_thread t epptr)) queue) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) (fun (list : (List (BitVec 64))) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.endpoint.ep_queue ep)) (fun (queue : (List (BitVec 64))) => (holBind (holMapMx (fun (t : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.remove_and_restart_ep_queued_thread t epptr)) queue) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) ep)))) + +def tcb_ntfn_dequeue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (ntfn_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfn_ptr) (fun (notification : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.ntfn.ntfn_queue (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj notification))) (fun (q : (List (BitVec 64))) => (holBind (holAssert (holMember tptr (holListSet q))) (holKBind (holBind (holFunApp holReturn (holListRemoveAll tptr q)) (fun (q_p : (List (BitVec 64))) => (holBind (holFunApp holReturn (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (holK (holCaseList L4vRefX64.Spec.Structures_A.ntfn.IdleNtfn (fun (a : (BitVec 64)) => (fun (list : (List (BitVec 64))) => (L4vRefX64.Spec.Structures_A.ntfn.WaitingNtfn q_p))) q_p)) notification)) (fun (notification_p : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfn_ptr notification_p))))))))))))) + +def remove_and_restart_ntfn_queued_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (t : (BitVec 64)) => (fun (ntfnptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ntfn_dequeue t ntfnptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state t L4vRefX64.Spec.Structures_A.thread_state.Restart) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context t) (fun (sc_opt : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some false) (Option.some true)) (holKBind (L4vRefX64.Spec.KHeap_A.possible_switch_to t))))))))))) + +def cancel_all_signals {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ntfnptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (L4vRefX64.Spec.Structures_A.case_ntfn (holReturn ()) (fun (queue : (List (BitVec 64))) => (holBind (holMapMx (fun (t : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.remove_and_restart_ntfn_queued_thread t ntfnptr)) queue) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holReturn ())) (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn))))) + +def remove_and_restart_badged_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (t : (BitVec 64)) => (fun (epptr : (BitVec 64)) => (fun (badge : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state t) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holWhen (holEq (L4vRefX64.Spec.IpcCancel_A.blocking_ipc_badge st) badge) (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ep_dequeue t epptr) (holKBind (L4vRefX64.Spec.IpcCancel_A.restart_thread_if_no_fault t))))))))) + +def cancel_badged_sends {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (epptr : (BitVec 64)) => (fun (badge : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint epptr) (fun (ep : L4vRefX64.Spec.Structures_A.endpoint) => (L4vRefX64.Spec.Structures_A.case_endpoint (holReturn ()) (fun (queue : (List (BitVec 64))) => (holBind (holMapMx (fun (t : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.remove_and_restart_badged_thread t epptr badge)) queue) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (list : (List (BitVec 64))) => (holReturn ())) ep))))) + +def cancel_signal {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (threadptr : (BitVec 64)) => (fun (ntfnptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ntfn_dequeue threadptr ntfnptr) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state threadptr L4vRefX64.Spec.Structures_A.thread_state.Inactive))))) + +def sc_with_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (BitVec 64)))) := + (fun (r : (BitVec 64)) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Lib.partial_inv (fun (sc_ptr : (BitVec 64)) => (holEx (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holEx (fun (n : Nat) => (holConj (holEq (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s sc_ptr) (Option.some (L4vRefX64.Spec.Structures_A.kernel_object.SchedContext sc n))) (holMember r (holListSet (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_replies sc))))))))) true))) + +def reply_remove_tcb {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (rptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tptr) (fun (ts : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (holAssert (holEq ts (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReply rptr))) (holKBind (holBind (holFunApp holGets (L4vRefX64.Spec.IpcCancel_A.sc_with_reply rptr)) (fun (sc_ptr_opt : (Option (BitVec 64))) => (holBind (holCaseOption (holReturn ()) (fun (sc_ptr : (BitVec 64)) => (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.sched_context_ext.sc_replies) (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr)) (fun (sc_replies : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply_ext.reply_sc rptr) (fun (reply_sc : (Option (BitVec 64))) => (holBind (holAssert (holIf (holEq (holHd sc_replies) rptr) (holEq reply_sc (Option.some sc_ptr)) (holEq reply_sc (Option.none (α := (BitVec 64)))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_replies_update (holListTakeWhile (fun (r : (BitVec 64)) => (holNot (holEq r rptr)))))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_sc_update rptr (Option.none (α := (BitVec 64))))))))))))) sc_ptr_opt) (holKBind (L4vRefX64.Spec.IpcCancel_A.reply_unlink_tcb tptr rptr))))))))))) + +def cancel_ipc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tptr) (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_fault_update (fun (uu_ : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (Option.none (α := L4vRefX64.Spec.ExceptionTypes_A.fault))) tcb)) tptr) (holKBind (L4vRefX64.Spec.Structures_A.case_thread_state (holReturn ()) (holReturn ()) (holReturn ()) (fun (x : (BitVec 64)) => (fun (reply : (Option (BitVec 64))) => (fun (xa : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (L4vRefX64.Spec.IpcCancel_A.blocked_cancel_ipc state tptr reply)))) (fun (x : (BitVec 64)) => (fun (y : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (L4vRefX64.Spec.IpcCancel_A.blocked_cancel_ipc state tptr (Option.none (α := (BitVec 64)))))) (fun (reply : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.reply_remove_tcb tptr reply)) (fun (event : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.cancel_signal tptr event)) (holReturn ()) state)))))) + +def cap_cleanup_opt : (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap) := + (fun (c : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap L4vRefX64.Spec.Structures_A.cap.NullCap (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => L4vRefX64.Spec.Structures_A.cap.NullCap)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => L4vRefX64.Spec.Structures_A.cap.NullCap))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => L4vRefX64.Spec.Structures_A.cap.NullCap))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => L4vRefX64.Spec.Structures_A.cap.NullCap))) (fun (word : (BitVec 64)) => L4vRefX64.Spec.Structures_A.cap.NullCap) L4vRefX64.Spec.Structures_A.cap.NullCap (fun (word : (BitVec 64)) => (fun (nat : Nat) => L4vRefX64.Spec.Structures_A.cap.NullCap)) L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap (fun (x : (BitVec 8)) => c) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => L4vRefX64.Spec.Structures_A.cap.NullCap))) (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.ArchIpcCancel_A.arch_cap_cleanup_opt acap)) c)) + +def cap_irq_opt : (L4vRefX64.Spec.Structures_A.cap → (Option (BitVec 8))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (Option.none (α := (BitVec 8))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (Option.none (α := (BitVec 8))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.none (α := (BitVec 8)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.none (α := (BitVec 8)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.none (α := (BitVec 8))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (Option.none (α := (BitVec 8)))))) (fun (word : (BitVec 64)) => (Option.none (α := (BitVec 8)))) (Option.none (α := (BitVec 8))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (Option.none (α := (BitVec 8))))) (Option.none (α := (BitVec 8))) (Option.none (α := (BitVec 8))) (fun (irq : (BitVec 8)) => (Option.some irq)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (Option.none (α := (BitVec 8)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (Option.none (α := (BitVec 8)))) cap)) + +def cap_irqs : (L4vRefX64.Spec.Structures_A.cap → (Set (BitVec 8))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holSetOption (L4vRefX64.Spec.IpcCancel_A.cap_irq_opt cap))) + +def deleted_irq_handler {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (L4vRefX64.Spec.KHeap_A.set_irq_state L4vRefX64.Spec.Structures_A.irq_state.IRQInactive irq)) + +def do_unbind_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ntfnptr : (BitVec 64)) => (fun (tcbptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.set_ntfn_obj_ref L4vRefX64.Spec.Structures_A.notification.ntfn_bound_tcb_update ntfnptr (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.set_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb.tcb_bound_notification_update tcbptr (Option.none (α := (BitVec 64)))))))) + +def do_unbind_ntfn_sc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ntfnptr : (BitVec 64)) => (fun (scptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.set_ntfn_obj_ref L4vRefX64.Spec.Structures_A.notification.ntfn_sc_update ntfnptr (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.set_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context.sc_ntfn_update scptr (Option.none (α := (BitVec 64)))))))) + +def post_cap_deletion {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holReturn ()) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holReturn ()))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn ())))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn ())))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn ()))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holReturn ())))) (fun (word : (BitVec 64)) => (holReturn ())) (holReturn ()) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holReturn ()))) (holReturn ()) (holReturn ()) (fun (irq : (BitVec 8)) => (L4vRefX64.Spec.IpcCancel_A.deleted_irq_handler irq)) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holReturn ())))) (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.ArchIpcCancel_A.arch_post_cap_deletion acap)) cap)) + +def empty_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (slot : ((BitVec 64) × (List Bool))) => (fun (cleanup_info : L4vRefX64.Spec.Structures_A.cap) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holIf (holEq cap L4vRefX64.Spec.Structures_A.cap.NullCap) (holReturn ()) (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s slot))) (fun (slot_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt) (fun (cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBind (holFunApp holReturn (cdt slot)) (fun (parent : (Option ((BitVec 64) × (List Bool)))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cdt (holFunUpd (fun (p : ((BitVec 64) × (List Bool))) => (holIf (holEq (cdt p) (Option.some slot)) parent (cdt p))) slot (Option.none (α := ((BitVec 64) × (List Bool)))))) (holKBind (holBind (L4vRefX64.Spec.Deterministic_A.do_extended_op (L4vRefX64.Spec.Deterministic_A.empty_slot_ext slot slot_p)) (holKBind (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_original slot false) (holKBind (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap L4vRefX64.Spec.Structures_A.cap.NullCap slot) (holKBind (L4vRefX64.Spec.IpcCancel_A.post_cap_deletion cleanup_info)))))))))))))))))))) + +def gen_obj_refs : (L4vRefX64.Spec.Structures_A.cap → (Set L4vRefX64.Spec.IpcCancel_A.gen_obj_ref)) := + (fun (c : L4vRefX64.Spec.Structures_A.cap) => (HolCompleteLattice.holSup (HolCompleteLattice.holSup (holImage L4vRefX64.Spec.IpcCancel_A.gen_obj_ref.ObjRef (L4vRefX64.Spec.Structures_A.obj_refs c)) (holImage L4vRefX64.Spec.IpcCancel_A.gen_obj_ref.IRQRef (L4vRefX64.Spec.IpcCancel_A.cap_irqs c))) (holImage L4vRefX64.Spec.IpcCancel_A.gen_obj_ref.ArchRef (L4vRefX64.Spec.IpcCancel_A.arch_cap_set_map L4vRefX64.Spec.ArchIpcCancel_A.arch_gen_obj_refs c)))) + +def is_final_cap' {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → Bool)) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holEx (fun (cref : ((BitVec 64) × (List Bool))) => (holEq (holCollect (fun (cref_1 : ((BitVec 64) × (List Bool))) => (holEx (fun (cap_p : L4vRefX64.Spec.Structures_A.cap) => (holConj (holEq (Prod.fst (L4vRefX64.Spec.CSpaceAcc_A.get_cap cref_1 s)) (holInsert (Prod.mk cap_p s) (HolCompleteLattice.holBot (α := (Set (L4vRefX64.Spec.Structures_A.cap × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))))))) (holNot (holEq (HolCompleteLattice.holInf (L4vRefX64.Spec.IpcCancel_A.gen_obj_refs cap) (L4vRefX64.Spec.IpcCancel_A.gen_obj_refs cap_p)) (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.IpcCancel_A.gen_obj_ref)))))))))) (holInsert cref (HolCompleteLattice.holBot (α := (Set ((BitVec 64) × (List Bool))))))))))) + +def is_final_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holGets (L4vRefX64.Spec.IpcCancel_A.is_final_cap' cap))) + +def no_reply_in_ts {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tptr) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (L4vRefX64.Spec.Structures_A.case_thread_state (holReturn true) (holReturn true) (holReturn true) (fun (x : (BitVec 64)) => (fun (r : (Option (BitVec 64))) => (fun (xa : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holReturn (holEq r (Option.none (α := (BitVec 64)))))))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holReturn true))) (fun (r : (BitVec 64)) => (holReturn false)) (fun (word : (BitVec 64)) => (holReturn true)) (holReturn true) st)))) + +def ntfn_blocked : (L4vRefX64.Spec.Structures_A.thread_state → (Option (BitVec 64))) := + (fun (ts : L4vRefX64.Spec.Structures_A.thread_state) => (L4vRefX64.Spec.Structures_A.case_thread_state (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (fun (receiver_payload_ext : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (Option.none (α := (BitVec 64)))))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (Option.none (α := (BitVec 64))))) (fun (word : (BitVec 64)) => (Option.none (α := (BitVec 64)))) (fun (r : (BitVec 64)) => (Option.some r)) (Option.none (α := (BitVec 64))) ts)) + +def ntfn_queue_of : ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → (List (BitVec 64))) := + (fun (notification : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (L4vRefX64.Spec.Structures_A.ntfn.ntfn_queue (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj notification))) + +def ordered_insert {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_b : Type} [Nonempty tv_b] : (tv_a → ((List tv_a) → ((tv_a → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option tv_b))) → ((tv_b → (tv_b → Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (t : tv_a) => (fun (ts : (List tv_a)) => (fun (f : (tv_a → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option tv_b)))) => (fun (R : (tv_b → (tv_b → Bool))) => (holBind (holGetsThe (f t)) (fun (val : tv_b) => (holBind (holMapM (fun (t_p : tv_a) => (holGetsThe (f t_p))) ts) (fun (vals : (List tv_b)) => (holBind (holFunApp holReturn (holListZip ts vals)) (fun (zip : (List (tv_a × tv_b))) => (holBind (holFunApp holReturn (holListAppend (holListTakeWhile (holCaseProd (fun (t_p : tv_a) => (fun (val_p : tv_b) => (R val_p val)))) zip) (holListAppend (List.cons (Prod.mk t val) (List.nil (α := (tv_a × tv_b)))) (holListDropWhile (holCaseProd (fun (t_p : tv_a) => (fun (val_p : tv_b) => (R val_p val)))) zip)))) (fun (zip_p : (List (tv_a × tv_b))) => (holReturn (holListMap Prod.fst zip_p)))))))))))))) + +def tcb_append {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (qs : (List (BitVec 64))) => (L4vRefX64.Spec.IpcCancel_A.ordered_insert tptr qs (L4vRefX64.Spec.KHeap_A.thread_read L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority) (fun (x : (BitVec 8)) => (fun (y : (BitVec 8)) => (holLe y x)))))) + +def reorder_ep {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ep_ptr : (BitVec 64)) => (fun (tptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint ep_ptr) (fun (ep : L4vRefX64.Spec.Structures_A.endpoint) => (holBind (holAssert (holNot (holEq ep L4vRefX64.Spec.Structures_A.endpoint.IdleEP))) (holKBind (holBind (holReturn (L4vRefX64.Spec.Structures_A.endpoint.ep_queue ep)) (fun (qs : (List (BitVec 64))) => (holBind (holAssert (holNot (holEq qs (List.nil (α := (BitVec 64)))))) (holKBind (holBind (holFunApp holReturn (holListRemoveAll tptr qs)) (fun (qs_p : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_append tptr qs_p) (fun (qs_p_p : (List (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint ep_ptr (L4vRefX64.Spec.IpcCancel_A.update_ep_queue ep qs_p_p true)))))))))))))))) + +def reorder_ntfn {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ntfn_ptr : (BitVec 64)) => (fun (tptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfn_ptr) (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holBind (holAssert (L4vRefX64.Spec.Structures_A.ntfn.is_WaitingNtfn (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn))) (holKBind (holBind (holReturn (L4vRefX64.Spec.Structures_A.ntfn.ntfn_queue (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn))) (fun (qs : (List (BitVec 64))) => (holBind (holAssert (holNot (holEq qs (List.nil (α := (BitVec 64)))))) (holKBind (holBind (holFunApp holReturn (holListRemoveAll tptr qs)) (fun (qs_p : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_append tptr qs_p) (fun (qs_p_p : (List (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfn_ptr (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (fun (uu_ : L4vRefX64.Spec.Structures_A.ntfn) => (L4vRefX64.Spec.Structures_A.ntfn.WaitingNtfn qs_p_p)) ntfn)))))))))))))))) + +def test_reschedule {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (from_tptr : (BitVec 64)) => (holBind (holFunApp holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.scheduler_action) (fun (action : L4vRefX64.Spec.Structures_A.scheduler_action) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.case_scheduler_action false (holEq from_tptr) false action)) (fun (flag : Bool) => (holFunApp (holWhen (holDisj (holEq from_tptr cur) flag)) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))))) + +def sched_context_donate {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc_ptr) (fun (from_opt : (Option (BitVec 64))) => (holBind (holFunApp (holWhen (holNot (holEq from_opt (Option.none (α := (BitVec 64)))))) (holBind (holFunApp holAssertOpt from_opt) (fun (from_tptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue from_tptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_release_remove from_tptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_sched_context_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64))))) from_tptr) (holKBind (L4vRefX64.Spec.IpcCancel_A.test_reschedule from_tptr)))))))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_tcb_update (fun (uu_ : (Option (BitVec 64))) => (Option.some tcb_ptr)))) (holKBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_sched_context_update (fun (uu_ : (Option (BitVec 64))) => (Option.some sc_ptr))) tcb_ptr))))))))) + +def reply_push {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (caller : (BitVec 64)) => (fun (callee : (BitVec 64)) => (fun (reply_ptr : (BitVec 64)) => (fun (can_donate : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context caller) (fun (sc_caller : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context callee) (fun (sc_callee : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_tcb_update reply_ptr (Option.some caller)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state caller (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReply reply_ptr)) (holKBind (holFunApp (holWhen (holConj (holNot (holEq sc_caller (Option.none (α := (BitVec 64))))) (holConj (holEq sc_callee (Option.none (α := (BitVec 64)))) can_donate))) (holBind (L4vRefX64.Spec.IpcCancel_A.bind_sc_reply (holTheOpt sc_caller) reply_ptr) (holKBind (L4vRefX64.Spec.IpcCancel_A.sched_context_donate (holTheOpt sc_caller) callee)))))))))))))))) + +def reply_unlink_sc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (reply_ptr : (BitVec 64)) => (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.sched_context_ext.sc_replies) (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr)) (fun (sc_replies : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply reply_ptr) (fun (reply : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holIf (holEq (holHd sc_replies) reply_ptr) (holBind (holAssert (holEq (L4vRefX64.Spec.Structures_A.reply_ext.reply_sc reply) (Option.some sc_ptr))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_replies_update holTl)) (holKBind (holBind (holCaseList (holReturn ()) (fun (r_p : (BitVec 64)) => (fun (x : (List (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_sc_update r_p (Option.some sc_ptr)))) (holTl sc_replies)) (holKBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_sc_update reply_ptr (Option.none (α := (BitVec 64)))))))))) (holBind (holAssert (holEq (L4vRefX64.Spec.Structures_A.reply_ext.reply_sc reply) (Option.none (α := (BitVec 64))))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_replies_update (holListTakeWhile (fun (r : (BitVec 64)) => (holNot (holEq r reply_ptr))))))))))))))) + +def reply_remove {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (caller : (BitVec 64)) => (fun (r : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply r) (fun (reply : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holBind (holAssert (holEq (L4vRefX64.Spec.Structures_A.reply_ext.reply_tcb reply) (Option.some caller))) (holKBind (holBind (holFunApp holGets (L4vRefX64.Spec.IpcCancel_A.sc_with_reply r)) (fun (r_sc_opt : (Option (BitVec 64))) => (holBind (holCaseOption (holReturn ()) (fun (sc_ptr : (BitVec 64)) => (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.sched_context_ext.sc_replies) (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr)) (fun (replies : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context caller) (fun (caller_sc : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.IpcCancel_A.reply_unlink_sc sc_ptr r) (holKBind (holFunApp (holWhen (holConj (holEq (holHd replies) r) (holEq caller_sc (Option.none (α := (BitVec 64)))))) (L4vRefX64.Spec.IpcCancel_A.sched_context_donate sc_ptr caller))))))))) r_sc_opt) (holKBind (L4vRefX64.Spec.IpcCancel_A.reply_unlink_tcb caller r))))))))))) + +def sched_context_bind_ntfn {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc : (BitVec 64)) => (fun (ntfn : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification.ntfn_sc_update ntfn (Option.some sc)) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc (L4vRefX64.Spec.Structures_A.sched_context.sc_ntfn_update (fun (uu_ : (Option (BitVec 64))) => (Option.some ntfn)))))))) + +def sched_context_maybe_unbind_ntfn {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ntfn_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification_ext.ntfn_sc ntfn_ptr) (holMaybeM (fun (sc : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification.ntfn_sc_update ntfn_ptr (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc (L4vRefX64.Spec.Structures_A.sched_context.sc_ntfn_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64)))))))))))) + +def sched_context_unbind_tcb {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holFunApp holAssertOpt (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc)) (fun (tptr : (BitVec 64)) => (holBind (holFunApp holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (holFunApp (holWhen (holEq tptr cur)) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_release_remove tptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_sched_context_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64))))) tptr) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_tcb_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64))))))))))))))))))))) + +def sched_context_unbind_all_tcbs {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holFunApp (holWhen (holConj (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc) (Option.none (α := (BitVec 64))))) (holNot (holEq sc_ptr L4vRefX64.Spec.Machine_A.idle_sc_ptr)))) (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_tcb sc_ptr))))) + +def sched_context_unbind_ntfn {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_ntfn sc_ptr) (holMaybeM (fun (ntfn : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification.ntfn_sc_update ntfn (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_ntfn_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64)))))))))))) + +def sched_context_unbind_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.sched_context_ext.sc_replies) (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr)) (fun (replies : (List (BitVec 64))) => (holFunApp (holUnless (holEq replies (List.nil (α := (BitVec 64))))) (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_sc_update (holHd replies) (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_replies_update (fun (uu_ : (List (BitVec 64))) => (List.nil (α := (BitVec 64)))))))))))) + +def set_priority {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (prio : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tptr) (fun (ts : L4vRefX64.Spec.Structures_A.thread_state) => (holIf (L4vRefX64.Spec.Structures_A.runnable ts) (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_domain tptr) (fun (d : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority tptr) (fun (p : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_queue d p) (fun (queue : (List (BitVec 64))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holIf (holDisj (holMember tptr (holListSet queue)) (holEq tptr cur)) (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.thread_set_priority tptr prio) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue tptr) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) (L4vRefX64.Spec.KHeap_A.thread_set_priority tptr prio)))))))))) (holBind (L4vRefX64.Spec.KHeap_A.thread_set_priority tptr prio) (holKBind (holBind (holMaybeM (fun (ep : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.reorder_ep ep tptr)) (L4vRefX64.Spec.IpcCancel_A.ep_blocked ts)) (holKBind (holMaybeM (fun (ntfn : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.reorder_ntfn ntfn tptr)) (L4vRefX64.Spec.IpcCancel_A.ntfn_blocked ts))))))))))) + +def tcb_ep_append {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (tptr : (BitVec 64)) => (fun (ep_ptr : (BitVec 64)) => (fun (is_recv : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint ep_ptr) (fun (ep : L4vRefX64.Spec.Structures_A.endpoint) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.endpoint.ep_queue ep)) (fun (q : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_append tptr q) (fun (q_p : (List (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint ep_ptr (L4vRefX64.Spec.IpcCancel_A.update_ep_queue ep q_p is_recv))))))))))) + +def tcb_ntfn_append {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (ntfn_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfn_ptr) (fun (notification : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.ntfn.ntfn_queue (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj notification))) (fun (qs : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_append tptr qs) (fun (qs_p : (List (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfn_ptr (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (fun (uu_ : L4vRefX64.Spec.Structures_A.ntfn) => (L4vRefX64.Spec.Structures_A.ntfn.WaitingNtfn qs_p)) notification)))))))))) + +def unbind_maybe_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ntfnptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification_ext.ntfn_bound_tcb ntfnptr) (fun (tptr : (Option (BitVec 64))) => (holMaybeM (fun (t : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification.ntfn_bound_tcb_update ntfnptr (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_bound_notification_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64))))) t)))) tptr)))) + +def unbind_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_bound_notification tcb) (fun (ntfnptr : (Option (BitVec 64))) => (holMaybeM (fun (nptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification.ntfn_bound_tcb_update nptr (Option.none (α := (BitVec 64)))) (holKBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_bound_notification_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64))))) tcb)))) ntfnptr)))) + +def update_ntfn_queue : (L4vRefX64.Spec.Structures_A.ntfn → ((List (BitVec 64)) → L4vRefX64.Spec.Structures_A.ntfn)) + | (L4vRefX64.Spec.Structures_A.ntfn.WaitingNtfn q), q_p => (L4vRefX64.Spec.Structures_A.ntfn.WaitingNtfn q_p) + | _, _ => holUndefined +end +end L4vRefX64.Spec.IpcCancel_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Ipc_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Ipc_A.lean new file mode 100644 index 000000000..446534812 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Ipc_A.lean @@ -0,0 +1,159 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Ipc_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchFault_A +import L4vRefX64.Spec.ArchTcb_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.SchedContext_A +import L4vRefX64.Spec.Sporadic_A +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.TcbAcc_A +import L4vRefX64.Spec.Tcb_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Ipc_A +open L4vRefX64.Prim +open Classical +noncomputable section +def buffer_cptr_index : Nat := + (HolAdd.addVal L4vRefX64.Spec.Structures_A.msg_max_length (HolNumeral.ofNatVal (α := Nat) 2)) + +def is_valid_timeout_handler {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tptr : (BitVec 64)) => (holBind (holReturn (L4vRefX64.Spec.Tcb_A.get_tcb_timeout_handler_ptr tptr)) (fun (timeout_handler_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap timeout_handler_slot) (fun (timeout_handler_cap : L4vRefX64.Spec.Structures_A.cap) => (holReturn (L4vRefX64.Spec.Structures_A.is_ep_cap timeout_handler_cap))))))) + +def make_fault_msg {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ExceptionTypes_A.fault → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (List (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.CapFault cptr rp lf), thread => (holBind (L4vRefX64.Spec.KHeap_A.as_user thread L4vRefX64.Spec.MachineOps.getRestartPC) (fun (pc : (BitVec 64)) => (holReturn (Prod.mk (HolOne.oneVal (α := (BitVec 64))) (List.cons pc (List.cons cptr (List.cons (holIf rp (HolOne.oneVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64)))) (L4vRefX64.Spec.ExceptionTypes_A.msg_from_lookup_failure lf)))))))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.UnknownSyscallException n), thread => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (holMapM L4vRefX64.Spec.MachineOps.getRegister L4vRefX64.Spec.MachineTypes.syscallMessage)) (fun (msg : (List (BitVec 64))) => (holReturn (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 2) (holListAppend msg (List.cons n (List.nil (α := (BitVec 64))))))))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.UserException exception code), thread => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (holMapM L4vRefX64.Spec.MachineOps.getRegister L4vRefX64.Spec.MachineTypes.exceptionMessage)) (fun (msg : (List (BitVec 64))) => (holReturn (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 3) (holListAppend msg (List.cons exception (List.cons code (List.nil (α := (BitVec 64)))))))))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.Timeout badge), thread => (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb thread)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holCaseOption (holReturn (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 5) (List.cons badge (List.nil (α := (BitVec 64)))))) (fun (sc : (BitVec 64)) => (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_update_consumed sc) (fun (consumed : (BitVec 64)) => (holReturn (Prod.mk (HolNumeral.ofNatVal (α := (BitVec 64)) 5) (List.cons badge (L4vRefX64.Spec.Arch_Structs_A.words_from_time consumed))))))) (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb)))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.ArchFault af), thread => (L4vRefX64.Spec.ArchFault_A.make_arch_fault_msg af thread) + +def do_fault_transfer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (badge : (BitVec 64)) => (fun (sender : (BitVec 64)) => (fun (receiver : (BitVec 64)) => (fun (buf : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_fault sender) (fun (fault : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (holBind (holCaseOption (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.ExceptionTypes_A.fault × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (f : L4vRefX64.Spec.ExceptionTypes_A.fault) => (holReturn f)) fault) (fun (f : L4vRefX64.Spec.ExceptionTypes_A.fault) => (holBind (L4vRefX64.Spec.Ipc_A.make_fault_msg f sender) (holCaseProd (fun (label : (BitVec 64)) => (fun (msg : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.TcbAcc_A.set_mrs receiver buf msg) (fun (sent : (BitVec 64)) => (holBind (holFunApp (L4vRefX64.Spec.TcbAcc_A.set_message_info receiver) (L4vRefX64.Spec.Structures_A.message_info.MI sent (HolZero.zeroVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64))) label)) (holKBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user receiver) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register badge)))))))))))))))))) + +def get_message_info {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.message_info × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread : (BitVec 64)) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (L4vRefX64.Spec.MachineOps.getRegister L4vRefX64.Spec.Machine_A.msg_info_register)) (fun (x : (BitVec 64)) => (holFunApp holReturn (L4vRefX64.Spec.Structures_A.data_to_message_info x))))) + +def get_extra_cptrs {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((Option (BitVec 64)) → (L4vRefX64.Spec.Structures_A.message_info → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) + | (Option.some buf), mi => (holFunApp (holLiftM (holListMap L4vRefX64.Spec.Machine_A.data_to_cptr)) (holMapM (L4vRefX64.Spec.Tcb_A.load_word_offs buf) (holListUpt L4vRefX64.Spec.Ipc_A.buffer_cptr_index (HolAdd.addVal L4vRefX64.Spec.Ipc_A.buffer_cptr_index (holUnsigned (L4vRefX64.Spec.Structures_A.message_info.mi_extra_caps mi)))))) + | Option.none, mi => (holReturn (List.nil (α := (List Bool)))) + +def lookup_extra_caps {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Option (BitVec 64)) → (L4vRefX64.Spec.Structures_A.message_info → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.fault (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (thread : (BitVec 64)) => (fun (buffer : (Option (BitVec 64))) => (fun (mi : L4vRefX64.Spec.Structures_A.message_info) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (L4vRefX64.Spec.Ipc_A.get_extra_cptrs buffer mi)) (fun (cptrs : (List (List Bool))) => (holMapME (fun (cptr : (List Bool)) => (holFunApp (L4vRefX64.Spec.Exceptions_A.cap_fault_on_failure ((holOfBl (w := 64)) cptr) false) (L4vRefX64.Spec.CSpace_A.lookup_cap_and_slot thread cptr))) cptrs)))))) + +def set_extra_badge {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (buffer : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (n : Nat) => (L4vRefX64.Spec.TcbAcc_A.store_word_offs buffer (HolAdd.addVal L4vRefX64.Spec.Ipc_A.buffer_cptr_index n) badge)))) + +def transfer_caps_loop {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((Option (BitVec 64)) → ((BitVec 64) → (Nat → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((List ((BitVec 64) × (List Bool))) → (L4vRefX64.Spec.Structures_A.message_info → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.message_info × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) + | ep, rcv_buffer, n, List.nil, slots, mi => (holReturn (L4vRefX64.Spec.Structures_A.message_info.MI (L4vRefX64.Spec.Structures_A.message_info.mi_length mi) ((holOfNat (α := (BitVec 64))) n) (L4vRefX64.Spec.Structures_A.message_info.mi_caps_unwrapped mi) (L4vRefX64.Spec.Structures_A.message_info.mi_label mi))) + | ep, rcv_buffer, n, ((cap, slot) :: morecaps), slots, mi => (L4vRefX64.Spec.Exceptions_A.const_on_failure (L4vRefX64.Spec.Structures_A.message_info.MI (L4vRefX64.Spec.Structures_A.message_info.mi_length mi) ((holOfNat (α := (BitVec 64))) n) (L4vRefX64.Spec.Structures_A.message_info.mi_caps_unwrapped mi) (L4vRefX64.Spec.Structures_A.message_info.mi_label mi)) (holBindE (holFunApp (holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Ipc_A.transfer_caps_loop ep rcv_buffer (HolAdd.addVal n (HolOne.oneVal (α := Nat))) morecaps)) (fun (transfer_rest : ((List ((BitVec 64) × (List Bool))) → (L4vRefX64.Spec.Structures_A.message_info → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.message_info × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) => (holIf (holConj (L4vRefX64.Spec.Structures_A.is_ep_cap cap) (holEq ep (Option.some (L4vRefX64.Spec.Structures_A.obj_ref_of cap)))) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Ipc_A.set_extra_badge rcv_buffer (L4vRefX64.Spec.Structures_A.cap_ep_badge cap) n)) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (transfer_rest slots (L4vRefX64.Spec.Structures_A.message_info.MI (L4vRefX64.Spec.Structures_A.message_info.mi_length mi) (L4vRefX64.Spec.Structures_A.message_info.mi_extra_caps mi) (holWordOr (L4vRefX64.Spec.Structures_A.message_info.mi_caps_unwrapped mi) (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) n)) (L4vRefX64.Spec.Structures_A.message_info.mi_label mi)))))) (holIf (holNot (holEq slots (List.nil (α := ((BitVec 64) × (List Bool)))))) (holBindE (L4vRefX64.Spec.CSpace_A.derive_cap slot cap) (fun (cap_p : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holWhenE (holEq cap_p L4vRefX64.Spec.Structures_A.cap.NullCap)) ((holThrowError (α := Unit)) (holUndefined (α := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)))) (holKBind (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.CSpace_A.cap_insert cap_p slot (holHd slots))) (holKBind (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (transfer_rest (holTl slots) mi)))))))) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Structures_A.message_info.MI (L4vRefX64.Spec.Structures_A.message_info.mi_length mi) ((holOfNat (α := (BitVec 64))) n) (L4vRefX64.Spec.Structures_A.message_info.mi_caps_unwrapped mi) (L4vRefX64.Spec.Structures_A.message_info.mi_label mi)))))))) + +def transfer_caps {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.message_info → ((List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((Option (BitVec 64)) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.message_info × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (info : L4vRefX64.Spec.Structures_A.message_info) => (fun (caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (endpoint : (Option (BitVec 64))) => (fun (receiver : (BitVec 64)) => (fun (recv_buffer : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.CSpace_A.get_receive_slots receiver recv_buffer) (fun (dest_slots : (List ((BitVec 64) × (List Bool)))) => (holBind (holFunApp holReturn (L4vRefX64.Spec.Structures_A.message_info.MI (L4vRefX64.Spec.Structures_A.message_info.mi_length info) (HolZero.zeroVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64))) (L4vRefX64.Spec.Structures_A.message_info.mi_label info))) (fun (mi_p : L4vRefX64.Spec.Structures_A.message_info) => (holCaseOption (holReturn mi_p) (fun (receive_buffer : (BitVec 64)) => (L4vRefX64.Spec.Ipc_A.transfer_caps_loop endpoint receive_buffer (HolZero.zeroVal (α := Nat)) caps dest_slots mi_p)) recv_buffer)))))))))) + +def do_normal_transfer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Option (BitVec 64)) → ((Option (BitVec 64)) → ((BitVec 64) → (Bool → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))) := + (fun (sender : (BitVec 64)) => (fun (sbuf : (Option (BitVec 64))) => (fun (endpoint : (Option (BitVec 64))) => (fun (badge : (BitVec 64)) => (fun (grant : Bool) => (fun (receiver : (BitVec 64)) => (fun (rbuf : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Ipc_A.get_message_info sender) (fun (mi : L4vRefX64.Spec.Structures_A.message_info) => (holBind (holIf grant (holCatch (L4vRefX64.Spec.Ipc_A.lookup_extra_caps sender sbuf mi) (holK (holReturn (List.nil (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))))) (holReturn (List.nil (α := (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) (fun (caps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBind (L4vRefX64.Spec.Tcb_A.copy_mrs sender sbuf receiver rbuf (L4vRefX64.Spec.Structures_A.message_info.mi_length mi)) (fun (mrs_transferred : (BitVec 64)) => (holBind (L4vRefX64.Spec.Ipc_A.transfer_caps mi caps endpoint receiver rbuf) (fun (mi_p : L4vRefX64.Spec.Structures_A.message_info) => (holBind (holFunApp (L4vRefX64.Spec.TcbAcc_A.set_message_info receiver) (L4vRefX64.Spec.Structures_A.message_info.MI mrs_transferred (L4vRefX64.Spec.Structures_A.message_info.mi_extra_caps mi_p) (L4vRefX64.Spec.Structures_A.message_info.mi_caps_unwrapped mi_p) (L4vRefX64.Spec.Structures_A.message_info.mi_label mi))) (holKBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user receiver) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register badge))))))))))))))))))) + +def do_ipc_transfer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Option (BitVec 64)) → ((BitVec 64) → (Bool → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (sender : (BitVec 64)) => (fun (ep : (Option (BitVec 64))) => (fun (badge : (BitVec 64)) => (fun (grant : Bool) => (fun (receiver : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchVSpace_A.lookup_ipc_buffer true receiver) (fun (recv_buffer : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_fault sender) (fun (fault : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (holCaseOption (holBind (L4vRefX64.Spec.ArchVSpace_A.lookup_ipc_buffer false sender) (fun (send_buffer : (Option (BitVec 64))) => (L4vRefX64.Spec.Ipc_A.do_normal_transfer sender send_buffer ep badge grant receiver recv_buffer))) (fun (f : L4vRefX64.Spec.ExceptionTypes_A.fault) => (L4vRefX64.Spec.Ipc_A.do_fault_transfer badge sender receiver recv_buffer)) fault)))))))))) + +def send_ipc_blocked {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → (Bool → (Bool → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)))))))) := + (fun (thread : (BitVec 64)) => (fun (epptr : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (can_grant : Bool) => (fun (can_grant_reply : Bool) => (fun (call : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state thread (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnSend epptr (L4vRefX64.Spec.Structures_A.sender_payload_ext.mk badge can_grant can_grant_reply call ()))) (holKBind (L4vRefX64.Spec.IpcCancel_A.tcb_ep_append thread epptr false))))))))) + +def send_ipc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → (Bool → ((BitVec 64) → (Bool → (Bool → (Bool → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))))) := + (fun (block : Bool) => (fun (call : Bool) => (fun (badge : (BitVec 64)) => (fun (can_grant : Bool) => (fun (can_grant_reply : Bool) => (fun (can_donate : Bool) => (fun (thread : (BitVec 64)) => (fun (epptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint epptr) (fun (ep : L4vRefX64.Spec.Structures_A.endpoint) => (holCaseProd (fun (a : L4vRefX64.Spec.Structures_A.endpoint) => (fun (x : Bool) => (L4vRefX64.Spec.Structures_A.case_endpoint (holCaseBool (L4vRefX64.Spec.Ipc_A.send_ipc_blocked thread epptr badge can_grant can_grant_reply call) (holReturn ()) x) (fun (queue : (List (BitVec 64))) => (holCaseBool (L4vRefX64.Spec.Ipc_A.send_ipc_blocked thread epptr badge can_grant can_grant_reply call) (holReturn ()) x)) (fun (a_1 : (List (BitVec 64))) => (holCaseList (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (dest : (BitVec 64)) => (fun (queue : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ep_dequeue dest epptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state dest) (fun (recv_state : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (L4vRefX64.Spec.Structures_A.case_thread_state (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (x_1 : (BitVec 64)) => (fun (reply : (Option (BitVec 64))) => (fun (data : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holReturn reply)))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) recv_state) (fun (reply : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Ipc_A.do_ipc_transfer thread (Option.some epptr) badge can_grant dest) (holKBind (holBind (holMaybeM (L4vRefX64.Spec.IpcCancel_A.reply_unlink_tcb dest) reply) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context dest) (fun (sc_opt : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_fault thread) (fun (fault : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (holBind (holIf (holDisj call (holNot (holEq fault (Option.none (α := L4vRefX64.Spec.ExceptionTypes_A.fault))))) (holIf (holConj (holDisj can_grant can_grant_reply) (holNot (holEq reply (Option.none (α := (BitVec 64)))))) (L4vRefX64.Spec.IpcCancel_A.reply_push thread dest (holTheOpt reply) can_donate) (L4vRefX64.Spec.KHeap_A.set_thread_state thread L4vRefX64.Spec.Structures_A.thread_state.Inactive)) (holFunApp (holWhen (holConj can_donate (holEq sc_opt (Option.none (α := (BitVec 64)))))) (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context thread) (fun (thread_sc : (Option (BitVec 64))) => (L4vRefX64.Spec.IpcCancel_A.sched_context_donate (holTheOpt thread_sc) dest))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state dest L4vRefX64.Spec.Structures_A.thread_state.Running) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context dest) (fun (dest_sc : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check dest_sc (Option.some false) (Option.some false)) (holKBind (L4vRefX64.Spec.KHeap_A.possible_switch_to dest))))))))))))))))))))))))) a_1)) a))) (Prod.mk ep block)))))))))))) + +def send_fault_ipc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.cap → (L4vRefX64.Spec.ExceptionTypes_A.fault → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (tptr : (BitVec 64)) => (fun (handler_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (fault : L4vRefX64.Spec.ExceptionTypes_A.fault) => (fun (can_donate : Bool) => (L4vRefX64.Spec.Structures_A.case_cap (holReturn false) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (ref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_fault_update (fun (uu_ : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (Option.some fault)) tcb)) tptr) (holKBind (holBind (L4vRefX64.Spec.Ipc_A.send_ipc true false (L4vRefX64.Spec.Structures_A.cap_ep_badge handler_cap) (holMember L4vRefX64.Spec.CapRights_A.rights.AllowGrant rights) (holMember L4vRefX64.Spec.CapRights_A.rights.AllowGrantReply rights) can_donate tptr (L4vRefX64.Spec.Structures_A.cap_ep_ptr handler_cap)) (holKBind (holReturn true)))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) handler_cap))))) + +def handle_timeout {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.ExceptionTypes_A.fault → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (ex : L4vRefX64.Spec.ExceptionTypes_A.fault) => (holBind (L4vRefX64.Spec.Ipc_A.is_valid_timeout_handler tptr) (fun (valid : Bool) => (holBind (holAssert valid) (holKBind (holBind (holReturn (L4vRefX64.Spec.Tcb_A.get_tcb_timeout_handler_ptr tptr)) (fun (timeout_handler_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap timeout_handler_slot) (fun (timeout_handler_cap : L4vRefX64.Spec.Structures_A.cap) => (holBind (L4vRefX64.Spec.Ipc_A.send_fault_ipc tptr timeout_handler_cap ex false) (holKBind (holReturn ()))))))))))))) + +def end_timeslice {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (canTimeout : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.is_round_robin sc_ptr) (fun (round_robin : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct : (BitVec 64)) => (holBind (L4vRefX64.Spec.Ipc_A.is_valid_timeout_handler ct) (fun (valid : Bool) => (holIf (holConj canTimeout (holConj (holNot round_robin) valid)) (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (L4vRefX64.Spec.Ipc_A.handle_timeout ct (L4vRefX64.Spec.ExceptionTypes_A.fault.Timeout (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_badge sc))))) (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_ready sc_ptr) (fun (ready : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_sufficient sc_ptr (HolZero.zeroVal (α := (BitVec 64)))) (fun (sufficient : Bool) => (holIf (holConj ready sufficient) (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_append ct) (L4vRefX64.Spec.SchedContext_A.postpone sc_ptr)))))))))))))))) + +def refill_reset_rr {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (csc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head csc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_tail csc_ptr) (fun (tail : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd csc_ptr (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount tail))))) (holKBind (L4vRefX64.Spec.SchedContext_A.update_refill_tl csc_ptr (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64))))))))))))) + +def charge_budget {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (consumed : (BitVec 64)) => (fun (canTimeout : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (csc_ptr : (BitVec 64)) => (holBind (holFunApp (holWhen (holNot (holEq csc_ptr L4vRefX64.Spec.Machine_A.idle_sc_ptr))) (holBind (L4vRefX64.Spec.Sporadic_A.is_round_robin csc_ptr) (fun (robin : Bool) => (holBind (holIf robin (L4vRefX64.Spec.Ipc_A.refill_reset_rr csc_ptr) (L4vRefX64.Spec.SchedContext_A.refill_budget_check consumed)) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context csc_ptr (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (L4vRefX64.Spec.Structures_A.sched_context.sc_consumed_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_consumed sc) consumed)) sc)))))))) (holKBind (holBind (holFunApp holModify (L4vRefX64.Spec.Structures_A.abstract_state.consumed_time_update (holK (HolZero.zeroVal (α := (BitVec 64)))))) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable ct)) (fun (sched : Bool) => (holFunApp (holWhen sched) (holBind (L4vRefX64.Spec.Ipc_A.end_timeslice canTimeout) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holKBind (holModify (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true)))))))))))))))))))) + +def check_budget {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (csc : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.consumed_time) (fun (consumed : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_sufficient csc consumed) (fun (sufficient : Bool) => (holIf sufficient (holBind (holGets L4vRefX64.Spec.KHeap_A.is_cur_domain_expired) (fun (dom_exp : Bool) => (holReturn (holNot dom_exp)))) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.consumed_time) (fun (consumed_1 : (BitVec 64)) => (holBind (L4vRefX64.Spec.Ipc_A.charge_budget consumed_1 true) (holKBind (holReturn false)))))))))))) + +def check_budget_restart {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind L4vRefX64.Spec.Ipc_A.check_budget (fun (result : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state cur) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (holFunApp (holWhen (holConj (holNot result) (L4vRefX64.Spec.Structures_A.runnable st))) (L4vRefX64.Spec.KHeap_A.set_thread_state cur L4vRefX64.Spec.Structures_A.thread_state.Restart)) (holKBind (holReturn result))))))))) + +def complete_signal {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ntfnptr : (BitVec 64)) => (fun (tptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (L4vRefX64.Spec.Structures_A.case_ntfn (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (list : (List (BitVec 64))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (badge : (BitVec 64)) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user tptr) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register badge)) (holKBind (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (holK L4vRefX64.Spec.Structures_A.ntfn.IdleNtfn) ntfn)) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.maybe_donate_sc tptr ntfnptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tptr) (fun (sc_opt : (Option (BitVec 64))) => (holMaybeM (fun (scp : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context scp) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holFunApp (holWhen (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_sporadic sc)) (holBind (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification_ext.ntfn_sc ntfnptr) (fun (ntfn_scp : (Option (BitVec 64))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (cur_sc_ptr : (BitVec 64)) => (holFunApp (holWhen (holConj (holEq sc_opt ntfn_scp) (holNot (holEq scp cur_sc_ptr)))) (L4vRefX64.Spec.Sporadic_A.refill_unblock_check scp)))))))))) sc_opt)))))))))) (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn)))))) + +def do_nbrecv_failed_transfer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread : (BitVec 64)) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register (HolZero.zeroVal (α := (BitVec 64))))) (holKBind (holReturn ())))) + +def handle_fault_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.ExceptionTypes_A.fault → ((BitVec 64) → ((BitVec 64) → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.CapFault cptr rp lf), thread, x, y => (holReturn true) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.UnknownSyscallException n), thread, label, msg => (holBind (L4vRefX64.Spec.ArchTcb_A.arch_get_sanitise_register_info thread) (fun (t : Bool) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (holZipWithMx (fun (r : L4vRefX64.Spec.MachineTypes.register) => (fun (v : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.MachineOps.setRegister r) (L4vRefX64.Spec.ArchTcb_A.sanitise_register t r v)))) L4vRefX64.Spec.MachineTypes.syscallMessage msg)) (holKBind (holReturn (holEq label (HolZero.zeroVal (α := (BitVec 64))))))))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.UserException exception code), thread, label, msg => (holBind (L4vRefX64.Spec.ArchTcb_A.arch_get_sanitise_register_info thread) (fun (t : Bool) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (holZipWithMx (fun (r : L4vRefX64.Spec.MachineTypes.register) => (fun (v : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.MachineOps.setRegister r) (L4vRefX64.Spec.ArchTcb_A.sanitise_register t r v)))) L4vRefX64.Spec.MachineTypes.exceptionMessage msg)) (holKBind (holReturn (holEq label (HolZero.zeroVal (α := (BitVec 64))))))))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.Timeout badge), thread, label, msg => (holBind (L4vRefX64.Spec.ArchTcb_A.arch_get_sanitise_register_info thread) (fun (t : Bool) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (holZipWithMx (fun (r : L4vRefX64.Spec.MachineTypes.register) => (fun (v : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.MachineOps.setRegister r) (L4vRefX64.Spec.ArchTcb_A.sanitise_register t r v)))) L4vRefX64.Spec.MachineTypes.timeoutMessage msg)) (holKBind (holReturn (holEq label (HolZero.zeroVal (α := (BitVec 64))))))))) + | (L4vRefX64.Spec.ExceptionTypes_A.fault.ArchFault af), thread, label, msg => (L4vRefX64.Spec.ArchFault_A.handle_arch_fault_reply af thread label msg) + +def is_timeout_fault : (L4vRefX64.Spec.ExceptionTypes_A.fault → Bool) := + (fun (f : L4vRefX64.Spec.ExceptionTypes_A.fault) => (L4vRefX64.Spec.ExceptionTypes_A.case_fault (fun (word : (BitVec 64)) => (fun (bool : Bool) => (fun (lookup_failure : L4vRefX64.Spec.ExceptionTypes_A.lookup_failure) => false))) (fun (word : (BitVec 64)) => false) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => false)) (fun (x : (BitVec 64)) => true) (fun (arch_fault : L4vRefX64.Spec.Machine_A.arch_fault) => false) f)) + +def do_reply_transfer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (sender : (BitVec 64)) => (fun (reply : (BitVec 64)) => (fun (grant : Bool) => (holBind (holLiftM L4vRefX64.Spec.Structures_A.reply_ext.reply_tcb (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply reply)) (fun (recv_opt : (Option (BitVec 64))) => (holSwp holMaybeM recv_opt (fun (receiver : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state receiver) (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (L4vRefX64.Spec.Structures_A.case_thread_state (holReturn ()) (holReturn ()) (holReturn ()) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (fun (receiver_payload_ext : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holReturn ())))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holReturn ()))) (fun (r : (BitVec 64)) => (holBind (holAssert (holEq r reply)) (holKBind (holBind (L4vRefX64.Spec.IpcCancel_A.reply_remove receiver reply) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context receiver) (fun (sc_opt : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some false) (Option.some false)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_fault receiver) (fun (fault : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (holBind (holCaseOption (holBind (L4vRefX64.Spec.Ipc_A.do_ipc_transfer sender (Option.none (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64))) grant receiver) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state receiver L4vRefX64.Spec.Structures_A.thread_state.Running))) (fun (f : L4vRefX64.Spec.ExceptionTypes_A.fault) => (holBind (L4vRefX64.Spec.Ipc_A.get_message_info sender) (fun (mi : L4vRefX64.Spec.Structures_A.message_info) => (holBind (L4vRefX64.Spec.ArchVSpace_A.lookup_ipc_buffer false sender) (fun (buf : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Tcb_A.get_mrs sender buf mi) (fun (mrs : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.Ipc_A.handle_fault_reply f receiver (L4vRefX64.Spec.Structures_A.message_info.mi_label mi) mrs) (fun (restart : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_fault_update (fun (uu_ : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (Option.none (α := L4vRefX64.Spec.ExceptionTypes_A.fault))) tcb)) receiver) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state receiver (holIf restart L4vRefX64.Spec.Structures_A.thread_state.Restart L4vRefX64.Spec.Structures_A.thread_state.Inactive))))))))))))) fault) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context receiver) (fun (sc_opt_1 : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state receiver) (fun (state_1 : L4vRefX64.Spec.Structures_A.thread_state) => (holFunApp (holWhen (holConj (holNot (holEq sc_opt_1 (Option.none (α := (BitVec 64))))) (L4vRefX64.Spec.Structures_A.runnable state_1))) (holBind (holAssertOpt sc_opt_1) (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_time) (fun (curtime : (BitVec 64)) => (holIf (holConj (L4vRefX64.Spec.KHeap_A.refill_ready' (HolZero.zeroVal (α := (BitVec 64))) curtime (holHd (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc))) (L4vRefX64.Spec.KHeap_A.refill_sufficient (HolZero.zeroVal (α := (BitVec 64))) (holHd (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc)))) (L4vRefX64.Spec.KHeap_A.possible_switch_to receiver) (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb receiver)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holIf (holConj (L4vRefX64.Spec.Structures_A.is_ep_cap (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_timeout_handler tcb)) (holNot (holCaseOption false L4vRefX64.Spec.Ipc_A.is_timeout_fault fault))) (L4vRefX64.Spec.Ipc_A.handle_timeout receiver (L4vRefX64.Spec.ExceptionTypes_A.fault.Timeout (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_badge sc))) (L4vRefX64.Spec.SchedContext_A.postpone sc_ptr))))))))))))))))))))))))))))) (fun (word : (BitVec 64)) => (holReturn ())) (holReturn ()) state)))))))))) + +def get_extra_cptr {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List Bool) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (buffer : (BitVec 64)) => (fun (n : Nat) => (holLiftM L4vRefX64.Spec.Machine_A.data_to_cptr (L4vRefX64.Spec.Tcb_A.load_word_offs buffer (HolAdd.addVal n L4vRefX64.Spec.Ipc_A.buffer_cptr_index))))) + +def handle_no_fault {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tptr : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.set_thread_state tptr L4vRefX64.Spec.Structures_A.thread_state.Inactive)) + +def handle_fault {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.ExceptionTypes_A.fault → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (ex : L4vRefX64.Spec.ExceptionTypes_A.fault) => (holBind (holReturn (L4vRefX64.Spec.Tcb_A.get_tcb_fault_handler_ptr thread)) (fun (fault_handler_slot : ((BitVec 64) × (List Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap fault_handler_slot) (fun (fault_handler_cap : L4vRefX64.Spec.Structures_A.cap) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context thread) (fun (thread_sc_ptr_opt : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Ipc_A.send_fault_ipc thread fault_handler_cap ex (holNot (holEq thread_sc_ptr_opt (Option.none (α := (BitVec 64)))))) (fun (has_fh : Bool) => (holBind (holFunApp (holUnless has_fh) (L4vRefX64.Spec.Ipc_A.handle_no_fault thread)) (holKBind (holReturn ()))))))))))))) + +def invoke_sched_control_configure_flags {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.sched_control_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.Invocations_A.sched_control_invocation) => (L4vRefX64.Spec.Invocations_A.case_sched_control_invocation (fun (sc_ptr : (BitVec 64)) => (fun (budget : (BitVec 64)) => (fun (period : (BitVec 64)) => (fun (mrefills : Nat) => (fun (badge : (BitVec 64)) => (fun (flag : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holFunApp (holWhen (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc) (Option.none (α := (BitVec 64)))))) (holBind (holFunApp holAssertOpt (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc)) (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.tcb_release_remove tcb_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (cur_sc : (BitVec 64)) => (holFunApp (holWhen (holEq cur_sc sc_ptr)) L4vRefX64.Spec.SchedContext_A.commit_time)))))))))) (holKBind (holBind (holIf (holEq period budget) (L4vRefX64.Spec.SchedContext_A.refill_new sc_ptr (L4vRefX64.Spec.Structures_A.MIN_REFILLS : Nat) budget (HolZero.zeroVal (α := (BitVec 64)))) (holBind (L4vRefX64.Spec.KHeap_A.get_sc_active sc_ptr) (fun (active : Bool) => (holIf (holConj active (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc) (Option.none (α := (BitVec 64)))))) (holBind (holFunApp holAssertOpt (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc)) (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tcb_ptr) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holIf (L4vRefX64.Spec.Structures_A.runnable st) (L4vRefX64.Spec.SchedContext_A.refill_update sc_ptr period budget mrefills) (L4vRefX64.Spec.SchedContext_A.refill_new sc_ptr mrefills budget period)))))) (L4vRefX64.Spec.SchedContext_A.refill_new sc_ptr mrefills budget period))))) (holKBind (holBind (holFunApp (holWhen (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc) (Option.none (α := (BitVec 64)))))) (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_resume sc_ptr) (holKBind (holBind (holFunApp holAssertOpt (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc)) (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tcb_ptr) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct : (BitVec 64)) => (holIf (holEq tcb_ptr ct) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFunApp (holWhen (L4vRefX64.Spec.Structures_A.runnable st)) (L4vRefX64.Spec.KHeap_A.possible_switch_to tcb_ptr)))))))))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_badge_update (fun (uu_ : (BitVec 64)) => badge))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_sporadic_update (fun (uu_ : Bool) => (holWordBit flag (L4vRefX64.Spec.Structures_A.sc_sporadic_flag : Nat))))))))))))))))))))) iv)) + +def isActive : ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → Bool) := + (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (L4vRefX64.Spec.Structures_A.case_ntfn false (fun (list : (List (BitVec 64))) => false) (fun (x : (BitVec 64)) => true) (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn))) + +def receive_blocked : (L4vRefX64.Spec.Structures_A.thread_state → Bool) := + (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (L4vRefX64.Spec.Structures_A.case_thread_state false false false (fun (x : (BitVec 64)) => (fun (xa : (Option (BitVec 64))) => (fun (xb : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => true))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => false)) (fun (word : (BitVec 64)) => false) (fun (word : (BitVec 64)) => false) false st)) + +def receive_ipc_blocked {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : (Bool → ((BitVec 64) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)))))) := + (fun (is_blocking : Bool) => (fun (thread : (BitVec 64)) => (fun (epptr : (BitVec 64)) => (fun (reply : (Option (BitVec 64))) => (holIf is_blocking (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state thread (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReceive epptr reply (L4vRefX64.Spec.Structures_A.receiver_payload_ext.mk false ()))) (holKBind (holBind (holMaybeM (fun (r : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.reply.reply_tcb_update r (Option.some thread))) reply) (holKBind (L4vRefX64.Spec.IpcCancel_A.tcb_ep_append thread epptr true))))) (L4vRefX64.Spec.Ipc_A.do_nbrecv_failed_transfer thread)))))) + +def receive_ipc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.cap → (Bool → (L4vRefX64.Spec.Structures_A.cap → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (thread : (BitVec 64)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (is_blocking : Bool) => (fun (reply_cap : L4vRefX64.Spec.Structures_A.cap) => (holBind (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (ref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn (Prod.mk ref rights))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (Set L4vRefX64.Spec.CapRights_A.rights)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) cap) (holCaseProd (fun (epptr : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (L4vRefX64.Spec.Structures_A.case_cap (holReturn (Option.none (α := (BitVec 64)))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (r : (BitVec 64)) => (fun (x : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (holLiftM L4vRefX64.Spec.Structures_A.reply_ext.reply_tcb (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply r)) (fun (tptr : (Option (BitVec 64))) => (holBind (holFunApp (holWhen (holConj (holNot (holEq tptr (Option.none (α := (BitVec 64))))) (holNot (holEq (holTheOpt tptr) thread)))) (L4vRefX64.Spec.IpcCancel_A.cancel_ipc (holTheOpt tptr))) (holKBind (holReturn (Option.some r)))))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) reply_cap) (fun (reply : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint epptr) (fun (ep : L4vRefX64.Spec.Structures_A.endpoint) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_bound_notification thread) (fun (ntfnptr : (Option (BitVec 64))) => (holBind (holCaseOption (holReturn L4vRefX64.Spec.Structures_A.default_notification) (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification) ntfnptr) (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holIf (holConj (holNot (holEq ntfnptr (Option.none (α := (BitVec 64))))) (L4vRefX64.Spec.Ipc_A.isActive ntfn)) (L4vRefX64.Spec.Ipc_A.complete_signal (holTheOpt ntfnptr) thread) (holBind (holFunApp (holWhen (holConj (holNot (holEq ntfnptr (Option.none (α := (BitVec 64))))) is_blocking)) (L4vRefX64.Spec.SchedContext_A.maybe_return_sc (holTheOpt ntfnptr) thread)) (holKBind (L4vRefX64.Spec.Structures_A.case_endpoint (L4vRefX64.Spec.Ipc_A.receive_ipc_blocked is_blocking thread epptr reply) (fun (q : (List (BitVec 64))) => (holBind (holAssert (holNot (holEq q (List.nil (α := (BitVec 64)))))) (holKBind (holBind (holFunApp holReturn (holHd q)) (fun (sender : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ep_dequeue sender epptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state sender) (fun (sender_state : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (L4vRefX64.Spec.Structures_A.case_thread_state (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (fun (receiver_payload_ext : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (ref : (BitVec 64)) => (fun (data : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holReturn data))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) sender_state) (fun (data : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holBind (L4vRefX64.Spec.Ipc_A.do_ipc_transfer sender (Option.some epptr) (L4vRefX64.Spec.Structures_A.sender_payload_ext.sender_badge data) (L4vRefX64.Spec.Structures_A.sender_payload_ext.sender_can_grant data) thread) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context sender) (fun (sc_ptr : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_ptr (Option.some false) (Option.some true)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_fault sender) (fun (fault : (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) => (holIf (holDisj (L4vRefX64.Spec.Structures_A.sender_payload_ext.sender_is_call data) (holNot (holEq fault (Option.none (α := L4vRefX64.Spec.ExceptionTypes_A.fault))))) (holIf (holConj (holDisj (L4vRefX64.Spec.Structures_A.sender_payload_ext.sender_can_grant data) (L4vRefX64.Spec.Structures_A.sender_payload_ext.sender_can_grant_reply data)) (holNot (holEq reply (Option.none (α := (BitVec 64)))))) (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context sender) (fun (sender_sc : (Option (BitVec 64))) => (holBind (holFunApp holReturn (holConj (holNot (holEq sender_sc (Option.none (α := (BitVec 64))))) (holNot (holCaseOption false L4vRefX64.Spec.Ipc_A.is_timeout_fault fault)))) (fun (donate : Bool) => (L4vRefX64.Spec.IpcCancel_A.reply_push sender thread (holTheOpt reply) donate))))) (L4vRefX64.Spec.KHeap_A.set_thread_state sender L4vRefX64.Spec.Structures_A.thread_state.Inactive)) (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state sender L4vRefX64.Spec.Structures_A.thread_state.Running) (holKBind (L4vRefX64.Spec.KHeap_A.possible_switch_to sender))))))))))))))))))))))) (fun (list : (List (BitVec 64))) => (L4vRefX64.Spec.Ipc_A.receive_ipc_blocked is_blocking thread epptr reply)) ep)))))))))))))))))))) + +def receive_signal_blocked {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (thread : (BitVec 64)) => (fun (ntfnptr : (BitVec 64)) => (fun (is_blocking : Bool) => (holIf is_blocking (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state thread (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnNotification ntfnptr)) (holKBind (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ntfn_append thread ntfnptr) (holKBind (L4vRefX64.Spec.SchedContext_A.maybe_return_sc ntfnptr thread))))) (L4vRefX64.Spec.Ipc_A.do_nbrecv_failed_transfer thread))))) + +def receive_signal {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.cap → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (thread : (BitVec 64)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (is_blocking : Bool) => (holBind (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (ntfnptr : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holReturn ntfnptr)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) cap) (fun (ntfnptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (L4vRefX64.Spec.Structures_A.case_ntfn (L4vRefX64.Spec.Ipc_A.receive_signal_blocked thread ntfnptr is_blocking) (fun (list : (List (BitVec 64))) => (L4vRefX64.Spec.Ipc_A.receive_signal_blocked thread ntfnptr is_blocking)) (fun (badge : (BitVec 64)) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register badge)) (holKBind (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (holK L4vRefX64.Spec.Structures_A.ntfn.IdleNtfn) ntfn)) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.maybe_donate_sc thread ntfnptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context thread) (fun (sc_ptr : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_ptr (Option.some false) (Option.some false))))))))))) (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn))))))))) + +def remove_rights : ((Set L4vRefX64.Spec.CapRights_A.rights) → (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap)) := + (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.cap_rights_update (HolSub.subVal (L4vRefX64.Spec.Structures_A.cap_rights cap) rights) cap))) + +def update_waiting_ntfn {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (ntfnptr : (BitVec 64)) => (fun (queue : (List (BitVec 64))) => (fun (badge : (BitVec 64)) => (holBind (holAssert (holNot (holEq queue (List.nil (α := (BitVec 64)))))) (holKBind (holBind (holFunApp holReturn (holHd queue)) (fun (dest : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.tcb_ntfn_dequeue dest ntfnptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state dest L4vRefX64.Spec.Structures_A.thread_state.Running) (holKBind (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user dest) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register badge)) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.maybe_donate_sc dest ntfnptr) (holKBind (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable dest)) (fun (schedulable : Bool) => (holBind (holFunApp (holWhen schedulable) (L4vRefX64.Spec.KHeap_A.possible_switch_to dest)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context dest) (fun (scopt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check scopt (Option.some false) (Option.some false))))))))))))))))))))))) + +def send_signal {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ntfnptr : (BitVec 64)) => (fun (badge : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holCaseProd (fun (a : L4vRefX64.Spec.Structures_A.ntfn) => (fun (bound_tcb : (Option (BitVec 64))) => (L4vRefX64.Spec.Structures_A.case_ntfn (holCaseOption (holFunApp (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (holK (L4vRefX64.Spec.Structures_A.ntfn.ActiveNtfn badge)) ntfn)) (fun (tcb : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state tcb) (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holIf (L4vRefX64.Spec.Ipc_A.receive_blocked st) (holBind (L4vRefX64.Spec.IpcCancel_A.cancel_ipc tcb) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state tcb L4vRefX64.Spec.Structures_A.thread_state.Running) (holKBind (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user tcb) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register badge)) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.maybe_donate_sc tcb ntfnptr) (holKBind (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tcb)) (fun (schedulable : Bool) => (holBind (holFunApp (holWhen schedulable) (L4vRefX64.Spec.KHeap_A.possible_switch_to tcb)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb) (fun (scopt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check scopt (Option.some false) (Option.some false)))))))))))))))) (holFunApp (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (holK (L4vRefX64.Spec.Structures_A.ntfn.ActiveNtfn badge)) ntfn)))))) bound_tcb) (fun (queue : (List (BitVec 64))) => (L4vRefX64.Spec.Ipc_A.update_waiting_ntfn ntfnptr queue badge)) (fun (badge_p : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfnptr) (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (holK (L4vRefX64.Spec.Structures_A.ntfn.ActiveNtfn (L4vRefX64.Spec.Machine_A.combine_ntfn_badges badge badge_p))) ntfn))) a))) (Prod.mk (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_obj ntfn) (L4vRefX64.Spec.Structures_A.notification_ext.ntfn_bound_tcb ntfn))))))) +end +end L4vRefX64.Spec.Ipc_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/KHeap_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/KHeap_A.lean new file mode 100644 index 000000000..c76328c27 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/KHeap_A.lean @@ -0,0 +1,340 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.KHeap_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.Kernel_Config +import L4vRefX64.Spec.Lib +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.KHeap_A +open L4vRefX64.Prim +open Classical +noncomputable section +def active_sc : (Nat → Bool) := + (fun (refill_max : Nat) => (holLt (HolZero.zeroVal (α := Nat)) refill_max)) + +def read_object {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option L4vRefX64.Spec.Structures_A.kernel_object))) := + (holSwp L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap) + +def get_tcb {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) := + (fun (tcb_ref : (BitVec 64)) => (fun (state : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holCaseOption (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit))) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit))))) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (Option.some tcb)) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) kobj)) (L4vRefX64.Spec.KHeap_A.read_object tcb_ref state)))) + +def arch_thread_get {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → tv_a) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : ((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → tv_a)) => (fun (tptr : (BitVec 64)) => (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb tptr)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFunApp holReturn (f (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_arch tcb))))))) + +def get_object {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.kernel_object × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.read_object ptr))) + +def set_object {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.kernel_object → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (obj : L4vRefX64.Spec.Structures_A.kernel_object) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (holBind (holAssert (holEq (L4vRefX64.Spec.Structures_A.a_type kobj) (L4vRefX64.Spec.Structures_A.a_type obj))) (holKBind (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holPut (L4vRefX64.Spec.Structures_A.abstract_state.kheap_update (fun (uu_ : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object))) => (holFunUpd (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s) ptr (Option.some obj))) s)))))))))) + +def arch_thread_set {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : ((L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit))) => (fun (tptr : (BitVec 64)) => (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb tptr)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFunApp (L4vRefX64.Spec.KHeap_A.set_object tptr) (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb.tcb_arch_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) => (f (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_arch tcb))) tcb))))))) + +def as_user {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.MachineOps.user_context → ((Set (tv_a × L4vRefX64.Spec.MachineOps.user_context)) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (f : (L4vRefX64.Spec.MachineOps.user_context → ((Set (tv_a × L4vRefX64.Spec.MachineOps.user_context)) × Bool))) => (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb tptr)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holBind (holFunApp holReturn (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_context_get (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_arch tcb))) (fun (uc : L4vRefX64.Spec.MachineOps.user_context) => (holBind (holFunApp holSelectF (f uc)) (holCaseProd (fun (a : tv_a) => (fun (uc_p : L4vRefX64.Spec.MachineOps.user_context) => (holBind (holFunApp holReturn (L4vRefX64.Spec.Structures_A.tcb.tcb_arch_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_context_set uc_p (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_arch tcb))) tcb)) (fun (new_tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holBind (L4vRefX64.Spec.KHeap_A.set_object tptr (L4vRefX64.Spec.Structures_A.kernel_object.TCB new_tcb)) (holKBind (holReturn a))))))))))))))) + +def cnode_of : (L4vRefX64.Spec.Structures_A.kernel_object → (Option (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))))) := + (fun (ko : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (sz : Nat) => (fun (cnode : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (Option.some (Prod.mk sz cnode)))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (Option.none (α := (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)))))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (Option.none (α := (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)))))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (Option.none (α := (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)))))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (Option.none (α := (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (Option.none (α := (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)))))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (Option.none (α := (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)))))) ko)) + +def cnodes_of {tv_z : Type} [Nonempty tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option (Nat × ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)))))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holOptMap (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s) L4vRefX64.Spec.KHeap_A.cnode_of)) + +def cnode_contents_of {tv_z : Type} [Nonempty tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holOptMapSome (L4vRefX64.Spec.KHeap_A.cnodes_of s) Prod.snd)) + +def cnode_sizes_of {tv_z : Type} [Nonempty tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option Nat))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holOptMapSome (L4vRefX64.Spec.KHeap_A.cnodes_of s) Prod.fst)) + +def sc_of : (L4vRefX64.Spec.Structures_A.kernel_object → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))) := + (fun (ko : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (Option.none (α := (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (Option.none (α := (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (Option.none (α := (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (Option.none (α := (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (x : Nat) => (Option.some sc))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (Option.none (α := (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (Option.none (α := (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) ko)) + +def scs_of_kh {tv_obj_ref : Type} [Nonempty tv_obj_ref] : ((tv_obj_ref → (Option L4vRefX64.Spec.Structures_A.kernel_object)) → (tv_obj_ref → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) := + (fun (kh : (tv_obj_ref → (Option L4vRefX64.Spec.Structures_A.kernel_object))) => (holOptMap kh L4vRefX64.Spec.KHeap_A.sc_of)) + +def tcb_of : (L4vRefX64.Spec.Structures_A.kernel_object → (Option (L4vRefX64.Spec.Structures_A.tcb_ext Unit))) := + (fun (ko : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit))))) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (Option.some tcb)) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) ko)) + +def tcbs_of_kh {tv_obj_ref : Type} [Nonempty tv_obj_ref] : ((tv_obj_ref → (Option L4vRefX64.Spec.Structures_A.kernel_object)) → (tv_obj_ref → (Option (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) := + (fun (kh : (tv_obj_ref → (Option L4vRefX64.Spec.Structures_A.kernel_object))) => (holOptMap kh L4vRefX64.Spec.KHeap_A.tcb_of)) + +def schedulable {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → Bool)) := + (fun (t : (BitVec 64)) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holOptPred L4vRefX64.Spec.Structures_A.runnable (holOptMap (L4vRefX64.Spec.KHeap_A.tcbs_of_kh (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s)) (fun (s_1 : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (Option.some (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_state s_1)))) t) (holConj (holOptPred (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (L4vRefX64.Spec.KHeap_A.active_sc (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refill_max sc))) (holOptMap (holOptMap (L4vRefX64.Spec.KHeap_A.tcbs_of_kh (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s)) L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context) (L4vRefX64.Spec.KHeap_A.scs_of_kh (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s))) t) (holNot (holMember t (holListSet (L4vRefX64.Spec.Structures_A.abstract_state_ext.release_queue s)))))))) + +def ct_schedulable {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → Bool) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit))) => (L4vRefX64.Spec.KHeap_A.schedulable (L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread s) s)) + +def get_simple_ko {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((tv_a → L4vRefX64.Spec.Structures_A.kernel_object) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : (tv_a → L4vRefX64.Spec.Structures_A.kernel_object)) => (fun (ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (holBind (holAssert (holMember (L4vRefX64.Spec.Structures_A.a_type kobj) (holInsert L4vRefX64.Spec.Structures_A.a_type_T.AEndpoint (holInsert L4vRefX64.Spec.Structures_A.a_type_T.ANTFN (holInsert L4vRefX64.Spec.Structures_A.a_type_T.AReply (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.Structures_A.a_type_T)))))))) (holKBind (holCaseOption (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (e : tv_a) => (holReturn e)) (L4vRefX64.Spec.Lib.partial_inv f kobj)))))))) + +def get_endpoint {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.endpoint × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint) + +def get_irq_slot {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (((BitVec 64) × (List Bool)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (holGets (fun (st : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (Prod.mk (L4vRefX64.Spec.Structures_A.abstract_state_ext.interrupt_irq_node st irq) (List.nil (α := Bool)))))) + +def get_irq_state {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.irq_state × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.interrupt_states s irq)))) + +def get_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.notification_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification) + +def get_sk_obj_ref {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((tv_a → L4vRefX64.Spec.Structures_A.kernel_object) → ((tv_a → (Option (BitVec 64))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (C : (tv_a → L4vRefX64.Spec.Structures_A.kernel_object)) => (fun (f : (tv_a → (Option (BitVec 64)))) => (fun (ref : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko C ref) (fun (sc : tv_a) => (holFunApp holReturn (f sc))))))) + +def get_ntfn_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.notification_ext Unit) → (Option (BitVec 64))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (update : ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → (Option (BitVec 64)))) => (fun (ref : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification update ref))) + +def read_sched_context {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) := + (fun (ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holOFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holOFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holOFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holOFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))))) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (n : Nat) => (holOReturn sc))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holOFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (holOFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))))) kobj)))) + +def read_refill_head {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.refill_ext Unit)))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holOBind (holOAssert (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc) (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit)))))) (fun (uu_ : Unit) => (holOReturn (holHd (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc)))))))) + +def get_refill_head {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.refill_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holGetsThe (L4vRefX64.Spec.KHeap_A.read_refill_head sc_ptr))) + +def read_refill_tail {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (L4vRefX64.Spec.Structures_A.refill_ext Unit)))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holOBind (holOAssert (holNot (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc) (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit)))))) (fun (uu_ : Unit) => (holOReturn (holLast (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc)))))))) + +def get_refill_tail {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.refill_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holGetsThe (L4vRefX64.Spec.KHeap_A.read_refill_tail sc_ptr))) + +def get_sched_context {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (n : Nat) => (holReturn sc))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) kobj)))) + +def get_refills {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (L4vRefX64.Spec.Structures_A.refill_ext Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holFunApp holReturn (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc))))) + +def get_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.reply_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (L4vRefX64.Spec.KHeap_A.get_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply) + +def get_reply_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.reply_ext Unit) → (Option (BitVec 64))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (update : ((L4vRefX64.Spec.Structures_A.reply_ext Unit) → (Option (BitVec 64)))) => (fun (ref : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply update ref))) + +def get_reply_tcb {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (r : (BitVec 64)) => (holLiftM L4vRefX64.Spec.Structures_A.reply_ext.reply_tcb (L4vRefX64.Spec.KHeap_A.get_reply r))) + +def read_sc_active {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holFunApp holOReturn (L4vRefX64.Spec.KHeap_A.active_sc (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refill_max sc)))))) + +def get_sc_active {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holGetsThe (L4vRefX64.Spec.KHeap_A.read_sc_active sc_ptr))) + +def get_sc_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (Option (BitVec 64))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (Option (BitVec 64)))) => (fun (ref : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context ref) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holFunApp holReturn (f sc)))))) + +def refill_capacity : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → (BitVec 64))) := + (fun (usage : (BitVec 64)) => (fun (refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holIf (holLt (L4vRefX64.Spec.Structures_A.refill_ext.r_amount refill) usage) (HolZero.zeroVal (α := (BitVec 64))) (HolSub.subVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount refill) usage)))) + +def read_sc_refill_capacity {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (BitVec 64))))) := + (fun (sc_ptr : (BitVec 64)) => (fun (usage : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_refill_head sc_ptr) (fun (refill_head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holOReturn (L4vRefX64.Spec.KHeap_A.refill_capacity usage refill_head)))))) + +def get_sc_refill_capacity {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (usage : (BitVec 64)) => (holGetsThe (L4vRefX64.Spec.KHeap_A.read_sc_refill_capacity sc_ptr usage)))) + +def refill_ready' : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → Bool))) := + (fun (usage : (BitVec 64)) => (fun (curtime : (BitVec 64)) => (fun (refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holLe (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time refill) usage) curtime)))) + +def read_sc_refill_ready {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_refill_head sc_ptr) (fun (refill_head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holOBind (holAsks L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_time) (fun (cur_time : (BitVec 64)) => (holFunApp holOReturn (L4vRefX64.Spec.KHeap_A.refill_ready' (HolZero.zeroVal (α := (BitVec 64))) cur_time refill_head))))))) + +def get_sc_refill_ready {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holGetsThe (L4vRefX64.Spec.KHeap_A.read_sc_refill_ready sc_ptr))) + +def refill_sufficient : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → Bool)) := + (fun (usage : (BitVec 64)) => (fun (refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holLe L4vRefX64.Spec.Structures_A.MIN_BUDGET (L4vRefX64.Spec.KHeap_A.refill_capacity usage refill)))) + +def read_sc_refill_sufficient {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (usage : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holOReturn (L4vRefX64.Spec.KHeap_A.refill_sufficient usage head)))))) + +def get_sc_refill_sufficient {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (usage : (BitVec 64)) => (holGetsThe (L4vRefX64.Spec.KHeap_A.read_sc_refill_sufficient sc_ptr usage)))) + +def read_sc_released {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_sc_active sc_ptr) (fun (active : Bool) => (holIf active (L4vRefX64.Spec.KHeap_A.read_sc_refill_ready sc_ptr) (holOReturn false))))) + +def get_sc_released {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holGetsThe (L4vRefX64.Spec.KHeap_A.read_sc_released sc_ptr))) + +def thread_get {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → tv_a) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → tv_a)) => (fun (tptr : (BitVec 64)) => (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb tptr)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFunApp holReturn (f tcb)))))) + +def get_tcb_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (Option (BitVec 64))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Option (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (Option (BitVec 64)))) => (fun (ref : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.thread_get f ref))) + +def get_tcb_queue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (d : (BitVec 8)) => (fun (prio : (BitVec 8)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.ready_queues) (fun (queues : ((BitVec 8) → ((BitVec 8) → (List (BitVec 64))))) => (holReturn (queues d prio)))))) + +def get_thread_state {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (L4vRefX64.Spec.Structures_A.thread_state × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ref : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_state ref)) + +def in_release_queue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → Bool)) := + (fun (tcb_ptr : (BitVec 64)) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holMember tcb_ptr (holListSet (L4vRefX64.Spec.Structures_A.abstract_state_ext.release_queue s))))) + +def is_blocked {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread : (BitVec 64)) => (holFunApp (holLiftM L4vRefX64.Spec.Structures_A.ipc_queued_thread_state) (L4vRefX64.Spec.KHeap_A.get_thread_state thread))) + +def is_cur_domain_expired {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → Bool) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holConj (holLt (HolOne.oneVal (α := Nat)) L4vRefX64.Spec.Kernel_Config.numDomains) (holEq (L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_time s) (HolZero.zeroVal (α := (BitVec 64)))))) + +def is_irq_active {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (irq : (BitVec 8)) => (holFunApp (holLiftM (fun (st : L4vRefX64.Spec.Structures_A.irq_state) => (holNot (holEq st L4vRefX64.Spec.Structures_A.irq_state.IRQInactive)))) (L4vRefX64.Spec.KHeap_A.get_irq_state irq))) + +def is_simple_type : (L4vRefX64.Spec.Structures_A.kernel_object → Bool) := + (fun (ob : L4vRefX64.Spec.Structures_A.kernel_object) => (holMember (L4vRefX64.Spec.Structures_A.a_type ob) (holInsert L4vRefX64.Spec.Structures_A.a_type_T.AEndpoint (holInsert L4vRefX64.Spec.Structures_A.a_type_T.ANTFN (holInsert L4vRefX64.Spec.Structures_A.a_type_T.AReply (∅ : Set L4vRefX64.Spec.Structures_A.a_type_T)))))) + +def ntfn_set_bound_tcb : ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → ((Option (BitVec 64)) → (L4vRefX64.Spec.Structures_A.notification_ext Unit))) := + (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (fun (t : (Option (BitVec 64))) => (L4vRefX64.Spec.Structures_A.notification.ntfn_bound_tcb_update (fun (uu_ : (Option (BitVec 64))) => t) ntfn))) + +def ntfn_set_obj : ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → (L4vRefX64.Spec.Structures_A.ntfn → (L4vRefX64.Spec.Structures_A.notification_ext Unit))) := + (fun (ntfn : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (fun (a : L4vRefX64.Spec.Structures_A.ntfn) => (L4vRefX64.Spec.Structures_A.notification.ntfn_obj_update (fun (uu_ : L4vRefX64.Spec.Structures_A.ntfn) => a) ntfn))) + +def set_scheduler_action {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.scheduler_action → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (action : L4vRefX64.Spec.Structures_A.scheduler_action) => (holModify (fun (es : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.scheduler_action_update (fun (uu_ : L4vRefX64.Spec.Structures_A.scheduler_action) => action) es)))) + +def set_tcb_queue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((BitVec 8) → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (d : (BitVec 8)) => (fun (prio : (BitVec 8)) => (fun (queue : (List (BitVec 64))) => (holModify (fun (es : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.ready_queues_update (fun (uu_ : ((BitVec 8) → ((BitVec 8) → (List (BitVec 64))))) => (fun (d_p : (BitVec 8)) => (fun (p : (BitVec 8)) => (holIf (holConj (holEq d_p d) (holEq p prio)) queue (L4vRefX64.Spec.Structures_A.abstract_state_ext.ready_queues es d_p p))))) es)))))) + +def tcb_sched_action {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) → ((List (BitVec 64)) → (List (BitVec 64)))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (action : ((BitVec 64) → ((List (BitVec 64)) → (List (BitVec 64))))) => (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_domain thread) (fun (d : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority thread) (fun (prio : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_queue d prio) (fun (queue : (List (BitVec 64))) => (holBind (holReturn (action thread queue)) (fun (queue_p : (List (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.set_tcb_queue d prio queue_p))))))))))) + +def tcb_sched_enqueue : ((BitVec 64) → ((List (BitVec 64)) → (List (BitVec 64)))) := + (fun (thread : (BitVec 64)) => (fun (queue : (List (BitVec 64))) => (holIf (holNot (holMember thread (holListSet queue))) (List.cons thread queue) queue))) + +def reschedule_required {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.scheduler_action) (fun (action : L4vRefX64.Spec.Structures_A.scheduler_action) => (holBind (L4vRefX64.Spec.Structures_A.case_scheduler_action (holReturn ()) (fun (t : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable t)) (fun (sched : Bool) => (holFunApp (holWhen sched) (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context t) (fun (sc_opt : (Option (BitVec 64))) => (holBind (holAssertOpt sc_opt) (fun (scp : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_sufficient scp (HolZero.zeroVal (α := (BitVec 64)))) (fun (sufficient : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_ready scp) (fun (ready : Bool) => (holBind (holAssert (holConj sufficient ready)) (holKBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue t))))))))))))))) (holReturn ()) action) (holKBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.choose_new_thread))))) + +def possible_switch_to {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (target : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context target) (fun (sc_opt : (Option (BitVec 64))) => (holBind (holFunApp holGets (L4vRefX64.Spec.KHeap_A.in_release_queue target)) (fun (inq : Bool) => (holFunApp (holWhen (holConj (holNot (holEq sc_opt (Option.none (α := (BitVec 64))))) (holNot inq))) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_domain) (fun (cur_dom : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_domain target) (fun (target_dom : (BitVec 8)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.scheduler_action) (fun (action : L4vRefX64.Spec.Structures_A.scheduler_action) => (holIf (holNot (holEq target_dom cur_dom)) (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue target) (holIf (holNot (holEq action L4vRefX64.Spec.Structures_A.scheduler_action.resume_cur_thread)) (holBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holKBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue target))) (holFunApp L4vRefX64.Spec.KHeap_A.set_scheduler_action (L4vRefX64.Spec.Structures_A.scheduler_action.switch_thread target)))))))))))))))) + +def update_time_stamp {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_time) (fun (previous_time : (BitVec 64)) => (holBind (L4vRefX64.Spec.Structures_A.do_machine_op L4vRefX64.Spec.MachineOps.getCurrentTime) (fun (current_time : (BitVec 64)) => (holBind (holReturn (HolSub.subVal current_time previous_time)) (fun (consumed : (BitVec 64)) => (holBind (holModify (L4vRefX64.Spec.Structures_A.abstract_state.cur_time_update (fun (uu_ : (BitVec 64)) => current_time))) (holKBind (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.consumed_time_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.abstract_state_ext.consumed_time s) consumed)) s))) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_time) (fun (domain_time : (BitVec 64)) => (holFunApp (holWhen (holLt (HolOne.oneVal (α := Nat)) L4vRefX64.Spec.Kernel_Config.numDomains)) (holIf (holLe domain_time (HolAdd.addVal consumed L4vRefX64.Spec.Structures_A.MIN_BUDGET)) (holModify (L4vRefX64.Spec.Structures_A.abstract_state.domain_time_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64)))))) (holModify (L4vRefX64.Spec.Structures_A.abstract_state.domain_time_update (fun (uu_ : (BitVec 64)) => (HolSub.subVal domain_time consumed)))))))))))))))))) + +def preemption_point {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Deterministic_A.do_extended_op L4vRefX64.Spec.Deterministic_A.update_work_units)) (holKBind (L4vRefX64.Spec.Deterministic_A.OR_choiceE L4vRefX64.Spec.Deterministic_A.work_units_limit_reached (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Deterministic_A.do_extended_op L4vRefX64.Spec.Deterministic_A.reset_work_units)) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) L4vRefX64.Spec.KHeap_A.update_time_stamp) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.getActiveIRQ true))) (fun (irq_opt : (Option (BitVec 8))) => (holBindE (holFunApp (holLiftE (ε := Unit)) (holGets L4vRefX64.Spec.KHeap_A.is_cur_domain_expired)) (fun (exp : Bool) => (holBindE (holFunApp (holLiftE (ε := Unit)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc)) (fun (cur_sc : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := Unit)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.consumed_time)) (fun (consumed : (BitVec 64)) => (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.KHeap_A.get_sc_active cur_sc)) (fun (active : Bool) => (holBindE (holFunApp (holLiftE (ε := Unit)) (holFunApp holGets (L4vRefX64.Spec.KHeap_A.read_sc_refill_sufficient cur_sc consumed))) (fun (sufficient : (Option Bool)) => (holWhenE (holDisj (holNot (holEq irq_opt (Option.none (α := (BitVec 8))))) (holDisj exp (holNot (holConj active (holEq sufficient (Option.some true)))))) ((holThrowError (α := Unit)) ())))))))))))))))))) ((holReturnOk (ε := Unit)) ())))) + +def read_sc_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (Option (BitVec 64))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (Option (BitVec 64)))))) := + (fun (f : ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (Option (BitVec 64)))) => (fun (ref : (BitVec 64)) => (holOLiftM f (L4vRefX64.Spec.KHeap_A.read_sched_context ref)))) + +def thread_read {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → tv_a) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option tv_a)))) := + (fun (f : ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → tv_a)) => (fun (tptr : (BitVec 64)) => (holOLiftM f (L4vRefX64.Spec.KHeap_A.get_tcb tptr)))) + +def read_tcb_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (Option (BitVec 64))) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (Option (BitVec 64)))))) := + (fun (f : ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (Option (BitVec 64)))) => (fun (ref : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.thread_read f ref))) + +def read_thread_state {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option L4vRefX64.Spec.Structures_A.thread_state))) := + (fun (ref : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.thread_read L4vRefX64.Spec.Structures_A.tcb_ext.tcb_state ref)) + +def refill_hd {tv_a : Type} [Nonempty tv_a] : ((L4vRefX64.Spec.Structures_A.sched_context_ext tv_a) → (L4vRefX64.Spec.Structures_A.refill_ext Unit)) := + (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext tv_a)) => (holHd (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc))) + +def refill_ready : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → Bool)) := + (L4vRefX64.Spec.KHeap_A.refill_ready' (HolZero.zeroVal (α := (BitVec 64)))) + +def refill_tl {tv_a : Type} [Nonempty tv_a] : ((L4vRefX64.Spec.Structures_A.sched_context_ext tv_a) → (L4vRefX64.Spec.Structures_A.refill_ext Unit)) := + (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext tv_a)) => (holLast (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc))) + +def sc_active : ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → Bool) := + (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (L4vRefX64.Spec.KHeap_A.active_sc (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refill_max sc))) + +def sc_fields_of : (L4vRefX64.Spec.Structures_A.kernel_object → (Option ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat))) := + (fun (ko : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (Option.none (α := ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (Option.none (α := ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (Option.none (α := ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (Option.none (α := ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat)))) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (n : Nat) => (Option.some (Prod.mk sc n)))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (Option.none (α := ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (Option.none (α := ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat)))) ko)) + +def sc_released : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → Bool)) := + (fun (curtime : (BitVec 64)) => (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holConj (L4vRefX64.Spec.KHeap_A.active_sc (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refill_max sc)) (L4vRefX64.Spec.KHeap_A.refill_ready' (HolZero.zeroVal (α := (BitVec 64))) curtime (holHd (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc)))))) + +def scs_fields_of {tv_z : Type} [Nonempty tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) × Nat)))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holOptMap (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s) L4vRefX64.Spec.KHeap_A.sc_fields_of)) + +def sc_sizes_of {tv_z : Type} [Nonempty tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option Nat))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holOptMapSome (L4vRefX64.Spec.KHeap_A.scs_fields_of s) Prod.snd)) + +def schedule_tcb {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb_ptr : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.scheduler_action) (fun (sched_act : L4vRefX64.Spec.Structures_A.scheduler_action) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tcb_ptr)) (fun (schedulable : Bool) => (holFunApp (holWhen (holConj (holEq tcb_ptr cur) (holConj (holEq sched_act L4vRefX64.Spec.Structures_A.scheduler_action.resume_cur_thread) (holNot schedulable)))) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))))) + +def scs_of {tv_z : Type} [Nonempty tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.KHeap_A.scs_of_kh (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s))) + +def set_simple_ko {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((tv_a → L4vRefX64.Spec.Structures_A.kernel_object) → ((BitVec 64) → (tv_a → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (f : (tv_a → L4vRefX64.Spec.Structures_A.kernel_object)) => (fun (ptr : (BitVec 64)) => (fun (ep : tv_a) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (obj : L4vRefX64.Spec.Structures_A.kernel_object) => (holBind (holAssert (holMember (L4vRefX64.Spec.Structures_A.a_type obj) (holInsert L4vRefX64.Spec.Structures_A.a_type_T.AEndpoint (holInsert L4vRefX64.Spec.Structures_A.a_type_T.ANTFN (holInsert L4vRefX64.Spec.Structures_A.a_type_T.AReply (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.Structures_A.a_type_T)))))))) (holKBind (holBind (holAssert (holNot (holEq (L4vRefX64.Spec.Lib.partial_inv f obj) (Option.none (α := tv_a))))) (holKBind (L4vRefX64.Spec.KHeap_A.set_object ptr (f ep))))))))))) + +def set_endpoint {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.endpoint → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Endpoint) + +def thread_set {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (f : ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit))) => (fun (tptr : (BitVec 64)) => (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb tptr)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFunApp (L4vRefX64.Spec.KHeap_A.set_object tptr) (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.TCB (f tcb))))))) + +def set_flags {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Set L4vRefX64.Spec.Structs_B.tcb_flag) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ref : (BitVec 64)) => (fun (flags : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_flags_update (fun (uu_ : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => flags) tcb)) ref))) + +def set_irq_state {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.irq_state → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (state : L4vRefX64.Spec.Structures_A.irq_state) => (fun (irq : (BitVec 8)) => (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.interrupt_states_update (fun (uu_ : ((BitVec 8) → L4vRefX64.Spec.Structures_A.irq_state)) => (holFunUpd (L4vRefX64.Spec.Structures_A.abstract_state_ext.interrupt_states s) irq state)) s))) (holKBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.maskInterrupt (holEq state L4vRefX64.Spec.Structures_A.irq_state.IRQInactive) irq)))))) + +def set_mcpriority {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ref : (BitVec 64)) => (fun (mcp : (BitVec 8)) => (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_mcpriority_update (fun (uu_ : (BitVec 8)) => mcp) tcb)) ref))) + +def set_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Notification) + +def update_sk_obj_ref {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((tv_a → L4vRefX64.Spec.Structures_A.kernel_object) → ((((Option (BitVec 64)) → (Option (BitVec 64))) → (tv_a → tv_a)) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (C : (tv_a → L4vRefX64.Spec.Structures_A.kernel_object)) => (fun (f : (((Option (BitVec 64)) → (Option (BitVec 64))) → (tv_a → tv_a))) => (fun (ref : (BitVec 64)) => (fun (new : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_simple_ko C ref) (fun (sc : tv_a) => (L4vRefX64.Spec.KHeap_A.set_simple_ko C ref (f (holK new) sc)))))))) + +def set_ntfn_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((((Option (BitVec 64)) → (Option (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → (L4vRefX64.Spec.Structures_A.notification_ext Unit))) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (update : (((Option (BitVec 64)) → (Option (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.notification_ext Unit) → (L4vRefX64.Spec.Structures_A.notification_ext Unit)))) => (fun (ref : (BitVec 64)) => (fun (new : (Option (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification update ref new)))) + +def set_release_queue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (queue : (List (BitVec 64))) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.release_queue_update (fun (uu_ : (List (BitVec 64))) => queue) s)))) + +def set_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.reply_ext Unit) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (L4vRefX64.Spec.KHeap_A.set_simple_ko L4vRefX64.Spec.Structures_A.kernel_object.Reply) + +def set_reply_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((((Option (BitVec 64)) → (Option (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.reply_ext Unit) → (L4vRefX64.Spec.Structures_A.reply_ext Unit))) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (update : (((Option (BitVec 64)) → (Option (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.reply_ext Unit) → (L4vRefX64.Spec.Structures_A.reply_ext Unit)))) => (fun (ref : (BitVec 64)) => (fun (new : (Option (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Reply update ref new)))) + +def update_sched_context {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (f : ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))) => (holBind (L4vRefX64.Spec.KHeap_A.get_object ptr) (fun (obj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (n : Nat) => (L4vRefX64.Spec.KHeap_A.set_object ptr (L4vRefX64.Spec.Structures_A.kernel_object.SchedContext (f sc) n)))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) obj))))) + +def set_sc_obj_ref {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((tv_a → tv_a) → ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (L4vRefX64.Spec.Structures_A.sched_context_ext Unit))) → ((BitVec 64) → (tv_a → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (f : ((tv_a → tv_a) → ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)))) => (fun (ref : (BitVec 64)) => (fun (new : tv_a) => (L4vRefX64.Spec.KHeap_A.update_sched_context ref (f (fun (uu_ : tv_a) => new)))))) + +def set_sched_context {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (ptr : (BitVec 64)) => (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (n : Nat) => (L4vRefX64.Spec.KHeap_A.set_object ptr (L4vRefX64.Spec.Structures_A.kernel_object.SchedContext sc n))))) + +def set_tcb_obj_ref {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((((Option (BitVec 64)) → (Option (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit))) → ((BitVec 64) → ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (f : (((Option (BitVec 64)) → (Option (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) => (fun (ref : (BitVec 64)) => (fun (new : (Option (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.thread_set (f (fun (uu_ : (Option (BitVec 64))) => new)) ref)))) + +def set_thread_state_act {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb_ptr : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.scheduler_action) (fun (sched_act : L4vRefX64.Spec.Structures_A.scheduler_action) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tcb_ptr)) (fun (schedulable : Bool) => (holFunApp (holWhen (holConj (holEq tcb_ptr cur) (holConj (holEq sched_act L4vRefX64.Spec.Structures_A.scheduler_action.resume_cur_thread) (holNot schedulable)))) (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.choose_new_thread))))))))) + +def set_thread_state {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.thread_state → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ref : (BitVec 64)) => (fun (ts : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_state_update (fun (uu_ : L4vRefX64.Spec.Structures_A.thread_state) => ts) tcb)) ref) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state_act ref))))) + +def tcb_sched_dequeue : ((BitVec 64) → ((List (BitVec 64)) → (List (BitVec 64)))) := + (fun (thread : (BitVec 64)) => (fun (queue : (List (BitVec 64))) => (holListFilter (fun (y : (BitVec 64)) => (holNot (holEq thread y))) queue))) + +def tcb_release_remove {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb_ptr : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.release_queue) (fun (qs : (List (BitVec 64))) => (holBind (holFunApp (holWhen (holConj (holNot (holEq qs (List.nil (α := (BitVec 64))))) (holEq (holHd qs) tcb_ptr))) (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true) s)))) (holKBind (holBind (holReturn (L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tcb_ptr qs)) (fun (qs_p : (List (BitVec 64))) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.release_queue_update (fun (uu_ : (List (BitVec 64))) => qs_p) s)))))))))) + +def tcb_sched_append : ((BitVec 64) → ((List (BitVec 64)) → (List (BitVec 64)))) := + (fun (thread : (BitVec 64)) => (fun (queue : (List (BitVec 64))) => (holIf (holNot (holMember thread (holListSet queue))) (holListAppend queue (List.cons thread (List.nil (α := (BitVec 64))))) queue))) + +def tcbs_of {tv_z : Type} [Nonempty tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((BitVec 64) → (Option (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) := + (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.KHeap_A.tcbs_of_kh (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s))) + +def thread_set_domain {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (domain : (BitVec 8)) => (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_domain_update (fun (uu_ : (BitVec 8)) => domain) tcb)) tptr))) + +def thread_set_priority {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (prio : (BitVec 8)) => (L4vRefX64.Spec.KHeap_A.thread_set (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_priority_update (fun (uu_ : (BitVec 8)) => prio) tcb)) tptr))) + +def throw_on_false {tv_e : Type} [Nonempty tv_e] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (tv_e → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum tv_e Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ex : tv_e) => (fun (f : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBindE ((holLiftE (ε := tv_e)) f) (fun (v : Bool) => (holFunApp (holUnlessE v) ((holThrowError (α := Unit)) ex)))))) +end +end L4vRefX64.Spec.KHeap_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Kernel_Config.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Kernel_Config.lean new file mode 100644 index 000000000..d8790ef8f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Kernel_Config.lean @@ -0,0 +1,23 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.Kernel_Config) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Kernel_Config +open L4vRefX64.Prim +open Classical +noncomputable section +def config_HAVE_FPU : Bool := + true + +def numDomains : Nat := + (HolNumeral.ofNatVal (α := Nat) 16) + +def resetChunkBits : Nat := + (HolNumeral.ofNatVal (α := Nat) 8) + +def retypeFanOutLimit : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 256) +end +end L4vRefX64.Spec.Kernel_Config diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Kernel_Config_Lemmas.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Kernel_Config_Lemmas.lean new file mode 100644 index 000000000..543b4a865 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Kernel_Config_Lemmas.lean @@ -0,0 +1,15 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.Kernel_Config_Lemmas) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Kernel_Config + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Kernel_Config_Lemmas +open L4vRefX64.Prim +open Classical +noncomputable section +def domainBits : Nat := + (HolNumeral.ofNatVal (α := Nat) 8) +end +end L4vRefX64.Spec.Kernel_Config_Lemmas diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Lib.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Lib.lean new file mode 100644 index 000000000..3b5c92b1f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Lib.lean @@ -0,0 +1,14 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (Lib.Lib) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Lib +open L4vRefX64.Prim +open Classical +noncomputable section +def partial_inv {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] : ((tv_a → tv_b) → (tv_b → (Option tv_a))) := + (fun (f : (tv_a → tv_b)) => (fun (x : tv_b) => (holIf (holEx1 (fun (y : tv_a) => (holEq (f y) x))) (Option.some (holThe (fun (y : tv_a) => (holEq (f y) x)))) (Option.none (α := tv_a))))) +end +end L4vRefX64.Spec.Lib diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/List_Lib.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/List_Lib.lean new file mode 100644 index 000000000..41258790d --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/List_Lib.lean @@ -0,0 +1,34 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (Lib.List_Lib) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.List_Lib +open L4vRefX64.Prim +open Classical +noncomputable section +def after_in_list {tv_a : Type} [Nonempty tv_a] : ((List tv_a) → (tv_a → (Option tv_a))) + | List.nil, a => (Option.none (α := tv_a)) + | (x :: List.nil), a => (Option.none (α := tv_a)) + | (x :: (y :: xs)), a => (holIf (holEq a x) (Option.some y) (L4vRefX64.Spec.List_Lib.after_in_list (List.cons y xs) a)) + +def list_insert_after {tv_a : Type} [Nonempty tv_a] : ((List tv_a) → (tv_a → (tv_a → (List tv_a)))) + | List.nil, a, b => (List.nil (α := tv_a)) + | (x :: xs), a, b => (holIf (holEq x a) (List.cons x (List.cons b xs)) (List.cons x (L4vRefX64.Spec.List_Lib.list_insert_after xs a b))) + +def list_remove {tv_a : Type} [Nonempty tv_a] : ((List tv_a) → (tv_a → (List tv_a))) + | List.nil, a => (List.nil (α := tv_a)) + | (x :: xs), a => (holIf (holEq x a) (L4vRefX64.Spec.List_Lib.list_remove xs a) (List.cons x (L4vRefX64.Spec.List_Lib.list_remove xs a))) + +def list_replace {tv_a : Type} [Nonempty tv_a] : ((List tv_a) → (tv_a → (tv_a → (List tv_a)))) := + (fun (list : (List tv_a)) => (fun (a : tv_a) => (fun (b : tv_a) => (holListMap (fun (x : tv_a) => (holIf (holEq x a) b x)) list)))) + +def list_replace_list {tv_a : Type} [Nonempty tv_a] : ((List tv_a) → (tv_a → ((List tv_a) → (List tv_a)))) + | List.nil, a, list_p => (List.nil (α := tv_a)) + | (x :: xs), a, list_p => (holIf (holEq x a) (holListAppend list_p xs) (List.cons x (L4vRefX64.Spec.List_Lib.list_replace_list xs a list_p))) + +def list_swap {tv_a : Type} [Nonempty tv_a] : ((List tv_a) → (tv_a → (tv_a → (List tv_a)))) := + (fun (list : (List tv_a)) => (fun (a : tv_a) => (fun (b : tv_a) => (holListMap (fun (x : tv_a) => (holIf (holEq x a) b (holIf (holEq x b) a x))) list)))) +end +end L4vRefX64.Spec.List_Lib diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineMonad.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineMonad.lean new file mode 100644 index 000000000..475fd90c4 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineMonad.lean @@ -0,0 +1,21 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.MachineMonad) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.MachineTypes + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.MachineMonad +open L4vRefX64.Prim +open Classical +noncomputable section +def ignore_failure {tv_s : Type} [Nonempty tv_s] : ((tv_s → ((Set (Unit × tv_s)) × Bool)) → (tv_s → ((Set (Unit × tv_s)) × Bool))) := + (fun (f : (tv_s → ((Set (Unit × tv_s)) × Bool))) => (fun (s : tv_s) => (holIf (holEq (Prod.fst (f s)) (HolCompleteLattice.holBot (α := (Set (Unit × tv_s))))) (Prod.mk (holInsert (Prod.mk () s) (HolCompleteLattice.holBot (α := (Set (Unit × tv_s))))) false) (Prod.mk (Prod.fst (f s)) false)))) + +def machine_rest_lift {tv_a : Type} [Nonempty tv_a] : ((L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (tv_a × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (tv_a × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (f : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (tv_a × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))) => (holBind (holGets L4vRefX64.Spec.MachineTypes.machine_state_ext.machine_state_rest) (fun (mr : L4vRefX64.Spec.MachineTypes.machine_state_rest) => (holBind (holSelectF (f mr)) (holCaseProd (fun (r : tv_a) => (fun (mr_p : L4vRefX64.Spec.MachineTypes.machine_state_rest) => (holBind (holModify (fun (s : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (L4vRefX64.Spec.MachineTypes.machine_state.machine_state_rest_update (fun (uu_ : L4vRefX64.Spec.MachineTypes.machine_state_rest) => mr_p) s))) (holKBind (holReturn r)))))))))) + +def machine_op_lift : ((L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (holComp L4vRefX64.Spec.MachineMonad.machine_rest_lift L4vRefX64.Spec.MachineMonad.ignore_failure) +end +end L4vRefX64.Spec.MachineMonad diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineOps.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineOps.lean new file mode 100644 index 000000000..e8f4521de --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineOps.lean @@ -0,0 +1,267 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.MachineOps) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.MachineMonad +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.Time + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.MachineOps +open L4vRefX64.Prim +open Classical +noncomputable section +inductive user_context where + | UserContext (a0 : ((Fin 576) → (BitVec 8))) (a1 : (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) +instance : Nonempty user_context := ⟨user_context.UserContext holUndefined holUndefined⟩ +def case_user_context {r_ty : Type} (f0 : ((Fin 576) → (BitVec 8)) → (L4vRefX64.Spec.MachineTypes.register → (BitVec 64)) → r_ty) : user_context → r_ty + | .UserContext x0 x1 => f0 x0 x1 + +opaque FPUNullState : ((Fin 576) → (BitVec 8)) + +def IRQ : ((BitVec 8) → (BitVec 8)) := + holId + +def ackDeadlineIRQ : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holReturn ()) + +def ackInterrupt : ((BitVec 8) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (irq : (BitVec 8)) => (holReturn ())) + +def storeWord : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (p : (BitVec 64)) => (fun (w : (BitVec 64)) => (holBind (holAssert (holEq (holWordAnd p ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 3))) (HolZero.zeroVal (α := (BitVec 64))))) (holKBind (holModify (L4vRefX64.Spec.MachineTypes.machine_state.underlying_memory_update (holListFold (fun (i : Int) => (fun (m : ((BitVec 64) → (BitVec 8))) => (holFunUpd m (HolAdd.addVal p ((holOfInt (w := 64)) i)) (holNth ((holWordRsplit (m := 8)) w) (HolSub.subVal (HolNumeral.ofNatVal (α := Nat) 7) (holIntToNat i)))))) (holListUpto (HolZero.zeroVal (α := Int)) (HolNumeral.ofNatVal (α := Int) 7))))))))) + +def clearMemory : ((BitVec 64) → (Nat → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (bytelength : Nat) => (holMapMx (fun (p : (BitVec 64)) => (L4vRefX64.Spec.MachineOps.storeWord p (HolZero.zeroVal (α := (BitVec 64))))) (holUptoEnumStep ptr (HolAdd.addVal ptr (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : (BitVec 64))) (HolSub.subVal (HolAdd.addVal ptr ((holOfNat (α := (BitVec 64))) bytelength)) (HolOne.oneVal (α := (BitVec 64)))))))) + +def clearMemoryVM : ((BitVec 64) → (Nat → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (bits : Nat) => (holReturn ()))) + +opaque configureTimer_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +opaque configureTimer_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (BitVec 8)) + +def configureTimer : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 8) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holBind (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.configureTimer_impl) (holKBind (holGets L4vRefX64.Spec.MachineOps.configureTimer_val))) + +def debugPrint : ((List Unit) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (message : (List Unit)) => (holReturn ())) + +opaque device_regions : (List ((BitVec 64) × (BitVec 64))) + +opaque disableFpu_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +def disableFpu : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holBind (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.disableFpu_impl) (holKBind (holModify (fun (s : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (L4vRefX64.Spec.MachineTypes.machine_state.fpu_enabled_update (fun (uu_ : Bool) => false) s))))) + +opaque enableFpu_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +def enableFpu : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holBind (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.enableFpu_impl) (holKBind (holModify (fun (s : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (L4vRefX64.Spec.MachineTypes.machine_state.fpu_enabled_update (fun (uu_ : Bool) => true) s))))) + +def freeMemory : ((BitVec 64) → (Nat → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (bits : Nat) => (holMapMx (fun (p : (BitVec 64)) => (L4vRefX64.Spec.MachineOps.storeWord p (HolZero.zeroVal (α := (BitVec 64))))) (holUptoEnumStep ptr (HolAdd.addVal ptr (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : (BitVec 64))) (HolSub.subVal (HolAdd.addVal ptr (HolPow.powVal (HolNumeral.ofNatVal (α := (BitVec 64)) 2) bits)) (HolOne.oneVal (α := (BitVec 64)))))))) + +def non_kernel_IRQs : (Set (BitVec 8)) := + (HolCompleteLattice.holBot (α := (Set (BitVec 8)))) + +def getActiveIRQ : (Bool → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((Option (BitVec 8)) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (in_kernel : Bool) => (holBind (holFunApp holGets L4vRefX64.Spec.MachineTypes.machine_state_ext.irq_masks) (fun (is_masked : ((BitVec 8) → Bool)) => (holBind (holModify (fun (s : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (L4vRefX64.Spec.MachineTypes.machine_state.irq_state_update (fun (uu_ : Nat) => (HolAdd.addVal (L4vRefX64.Spec.MachineTypes.machine_state_ext.irq_state s) (HolOne.oneVal (α := Nat)))) s))) (holKBind (holBind (holFunApp holGets (holComp L4vRefX64.Spec.MachineTypes.irq_oracle L4vRefX64.Spec.MachineTypes.machine_state_ext.irq_state)) (fun (active_irq : (BitVec 8)) => (holIf (holDisj (is_masked active_irq) (holDisj (holEq active_irq (HolNumeral.ofNatVal (α := (BitVec 8)) 255)) (holConj in_kernel (holMember active_irq L4vRefX64.Spec.MachineOps.non_kernel_IRQs)))) (holReturn (Option.none (α := (BitVec 8)))) (holReturn (Option.some active_irq)))))))))) + +def getCurrentTime : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holBind (holModify (fun (s : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (L4vRefX64.Spec.MachineTypes.machine_state.time_state_update (fun (uu_ : Nat) => (HolAdd.addVal (L4vRefX64.Spec.MachineTypes.machine_state_ext.time_state s) (HolOne.oneVal (α := Nat)))) s))) (holKBind (holBind (holFunApp holGets (holComp L4vRefX64.Spec.MachineTypes.time_oracle L4vRefX64.Spec.MachineTypes.machine_state_ext.time_state)) (fun (passed : Nat) => (holBind (holGets L4vRefX64.Spec.MachineTypes.machine_state_ext.last_machine_time) (fun (last_p : (BitVec 64)) => (holBind (holReturn (holUnsigned last_p)) (fun (last : Nat) => (holBind (holReturn (holMin (holUnsigned (HolNeg.negVal (HolAdd.addVal (HolMul.mulVal (HolNumeral.ofNatVal (α := (BitVec 64)) 5) L4vRefX64.Spec.Time.MAX_PERIOD) (HolOne.oneVal (α := (BitVec 64)))))) (HolAdd.addVal last passed))) (fun (current : Nat) => (holBind (holModify (L4vRefX64.Spec.MachineTypes.machine_state.last_machine_time_update (fun (uu_ : (BitVec 64)) => ((holOfNat (α := (BitVec 64))) current)))) (holKBind (holReturn ((holOfNat (α := (BitVec 64))) current)))))))))))))) + +def getDeviceRegions : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((List ((BitVec 64) × (BitVec 64))) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holReturn L4vRefX64.Spec.MachineOps.device_regions) + +opaque getDeviceRegions_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +opaque getDeviceRegions_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (List ((BitVec 64) × (BitVec 64)))) + +def user_context.user_fpu_state : (L4vRefX64.Spec.MachineOps.user_context → ((Fin 576) → (BitVec 8))) := + (fun (user_context : L4vRefX64.Spec.MachineOps.user_context) => (L4vRefX64.Spec.MachineOps.case_user_context (fun (x1 : ((Fin 576) → (BitVec 8))) => (fun (x2 : (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) => x1)) user_context)) + +def getFPUState : (L4vRefX64.Spec.MachineOps.user_context → ((Set (((Fin 576) → (BitVec 8)) × L4vRefX64.Spec.MachineOps.user_context)) × Bool)) := + (holGets L4vRefX64.Spec.MachineOps.user_context.user_fpu_state) + +opaque getFaultAddress_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (BitVec 64)) + +def getFaultAddress : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holGets L4vRefX64.Spec.MachineOps.getFaultAddress_val) + +opaque getKernelDevices_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +opaque getKernelDevices_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (List ((BitVec 64) × (BitVec 64)))) + +def getKernelDevices : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((List ((BitVec 64) × (BitVec 64))) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holBind (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.getKernelDevices_impl) (holKBind (holGets L4vRefX64.Spec.MachineOps.getKernelDevices_val))) + +opaque memory_regions : (List ((BitVec 64) × (BitVec 64))) + +def getMemoryRegions : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((List ((BitVec 64) × (BitVec 64))) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holReturn L4vRefX64.Spec.MachineOps.memory_regions) + +def user_context.user_regs : (L4vRefX64.Spec.MachineOps.user_context → (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) := + (fun (user_context : L4vRefX64.Spec.MachineOps.user_context) => (L4vRefX64.Spec.MachineOps.case_user_context (fun (x1 : ((Fin 576) → (BitVec 8))) => (fun (x2 : (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) => x2)) user_context)) + +def getRegister : (L4vRefX64.Spec.MachineTypes.register → (L4vRefX64.Spec.MachineOps.user_context → ((Set ((BitVec 64) × L4vRefX64.Spec.MachineOps.user_context)) × Bool))) := + (fun (r : L4vRefX64.Spec.MachineTypes.register) => (holGets (fun (s : L4vRefX64.Spec.MachineOps.user_context) => (L4vRefX64.Spec.MachineOps.user_context.user_regs s r)))) + +def getRestartPC : (L4vRefX64.Spec.MachineOps.user_context → ((Set ((BitVec 64) × L4vRefX64.Spec.MachineOps.user_context)) × Bool)) := + (L4vRefX64.Spec.MachineOps.getRegister L4vRefX64.Spec.MachineTypes.register.FaultIP) + +opaque in16_impl : ((BitVec 16) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))) + +opaque in16_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (BitVec 64)) + +def in16 : ((BitVec 16) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (port : (BitVec 16)) => (holBind (holFunApp L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.in16_impl port)) (holKBind (holGets L4vRefX64.Spec.MachineOps.in16_val)))) + +opaque in32_impl : ((BitVec 16) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))) + +opaque in32_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (BitVec 64)) + +def in32 : ((BitVec 16) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (port : (BitVec 16)) => (holBind (holFunApp L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.in32_impl port)) (holKBind (holGets L4vRefX64.Spec.MachineOps.in32_val)))) + +opaque in8_impl : ((BitVec 16) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))) + +opaque in8_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (BitVec 64)) + +def in8 : ((BitVec 16) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (port : (BitVec 16)) => (holBind (holFunApp L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.in8_impl port)) (holKBind (holGets L4vRefX64.Spec.MachineOps.in8_val)))) + +opaque initL2Cache_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +def initL2Cache : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.initL2Cache_impl) + +def initMemory : ((BitVec 64) → (Nat → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + L4vRefX64.Spec.MachineOps.clearMemory + +opaque initTimer_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +def initTimer : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.initTimer_impl) + +opaque invalidateASID_impl : ((BitVec 64) → ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)))) + +def invalidateASID : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (vspace : (BitVec 64)) => (fun (asid : (BitVec 64)) => (L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.invalidateASID_impl vspace asid)))) + +opaque invalidateLocalPageStructureCacheASID_impl : ((BitVec 64) → ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)))) + +def invalidateLocalPageStructureCacheASID : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (vspace : (BitVec 64)) => (fun (asid : (BitVec 64)) => (L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.invalidateLocalPageStructureCacheASID_impl vspace asid)))) + +opaque invalidateTLB_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +def invalidateTLB : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.invalidateTLB_impl) + +opaque invalidateTLBEntry_impl : ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))) + +def invalidateTLBEntry : ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (vptr : (BitVec 64)) => (L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.invalidateTLBEntry_impl vptr))) + +opaque invalidateTranslationSingleASID_impl : ((BitVec 64) → ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)))) + +def invalidateTranslationSingleASID : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (vptr : (BitVec 64)) => (fun (asid : (BitVec 64)) => (L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.invalidateTranslationSingleASID_impl vptr asid)))) + +def ioapicIRQLines : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 24) + +opaque ioapicMapPinToVector_impl : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))))))) + +def ioapicMapPinToVector : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))))))) := + (fun (ioapic : (BitVec 64)) => (fun (pin : (BitVec 64)) => (fun (level : (BitVec 64)) => (fun (polarity : (BitVec 64)) => (fun (vector : (BitVec 64)) => (L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.ioapicMapPinToVector_impl ioapic pin level polarity vector))))))) + +def irqIntOffset : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 32) + +opaque irqIntOffset_val : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (BitVec 64)) + +def isFpuEnable : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Bool × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holGets L4vRefX64.Spec.MachineTypes.machine_state_ext.fpu_enabled) + +def loadWord : ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set ((BitVec 64) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (p : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.MachineTypes.machine_state_ext.underlying_memory) (fun (m : ((BitVec 64) → (BitVec 8))) => (holBind (holAssert (holEq (holWordAnd p ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 3))) (HolZero.zeroVal (α := (BitVec 64))))) (holKBind (holReturn ((holWordRcat (n := 64)) (holListMap (fun (i : Int) => (m (HolAdd.addVal p (HolSub.subVal (HolNumeral.ofNatVal (α := (BitVec 64)) 7) ((holOfInt (w := 64)) i))))) (holListUpto (HolZero.zeroVal (α := Int)) (HolNumeral.ofNatVal (α := Int) 7)))))))))) + +def maskInterrupt : (Bool → ((BitVec 8) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (m : Bool) => (fun (irq : (BitVec 8)) => (holModify (fun (s : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (L4vRefX64.Spec.MachineTypes.machine_state.irq_masks_update (fun (uu_ : ((BitVec 8) → Bool)) => (holFunUpd (L4vRefX64.Spec.MachineTypes.machine_state_ext.irq_masks s) irq m)) s))))) + +def maxPCIBus : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 255) + +def maxPCIDev : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 31) + +def maxPCIFunc : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 7) + +opaque mfence_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +def mfence : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.mfence_impl) + +def modify_registers : (((L4vRefX64.Spec.MachineTypes.register → (BitVec 64)) → (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) → (L4vRefX64.Spec.MachineOps.user_context → L4vRefX64.Spec.MachineOps.user_context)) := + (fun (f : ((L4vRefX64.Spec.MachineTypes.register → (BitVec 64)) → (L4vRefX64.Spec.MachineTypes.register → (BitVec 64)))) => (fun (uc : L4vRefX64.Spec.MachineOps.user_context) => (L4vRefX64.Spec.MachineOps.user_context.UserContext (L4vRefX64.Spec.MachineOps.user_context.user_fpu_state uc) (f (L4vRefX64.Spec.MachineOps.user_context.user_regs uc))))) + +opaque out16_impl : ((BitVec 16) → ((BitVec 16) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)))) + +def out16 : ((BitVec 16) → ((BitVec 16) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (port : (BitVec 16)) => (fun (dat : (BitVec 16)) => (holFunApp L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.out16_impl port dat)))) + +opaque out32_impl : ((BitVec 16) → ((BitVec 32) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)))) + +def out32 : ((BitVec 16) → ((BitVec 32) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (port : (BitVec 16)) => (fun (dat : (BitVec 32)) => (holFunApp L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.out32_impl port dat)))) + +opaque out8_impl : ((BitVec 16) → ((BitVec 8) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)))) + +def out8 : ((BitVec 16) → ((BitVec 8) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (port : (BitVec 16)) => (fun (dat : (BitVec 8)) => (holFunApp L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.out8_impl port dat)))) + +opaque readFpuState_val : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Fin 576) → (BitVec 8))) + +def readFpuState : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (((Fin 576) → (BitVec 8)) × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (holBind (holStateAssert L4vRefX64.Spec.MachineTypes.machine_state_ext.fpu_enabled) (holKBind (holFunApp L4vRefX64.Spec.MachineMonad.machine_rest_lift (holGets L4vRefX64.Spec.MachineOps.readFpuState_val)))) + +opaque resetTimer_impl : (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)) + +def resetTimer : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) := + (L4vRefX64.Spec.MachineMonad.machine_op_lift L4vRefX64.Spec.MachineOps.resetTimer_impl) + +opaque setDeadline_impl : ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))) + +def setDeadline : ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (d : (BitVec 64)) => (L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.setDeadline_impl d))) + +def setFPUState : (((Fin 576) → (BitVec 8)) → (L4vRefX64.Spec.MachineOps.user_context → ((Set (Unit × L4vRefX64.Spec.MachineOps.user_context)) × Bool))) := + (fun (fc : ((Fin 576) → (BitVec 8))) => (holModify (fun (s : L4vRefX64.Spec.MachineOps.user_context) => (L4vRefX64.Spec.MachineOps.user_context.UserContext fc (L4vRefX64.Spec.MachineOps.user_context.user_regs s))))) + +def setInterruptMode : ((BitVec 8) → (Bool → (Bool → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))))) := + (fun (irq : (BitVec 8)) => (fun (levelTrigger : Bool) => (fun (polarityLow : Bool) => (holReturn ())))) + +def setRegister : (L4vRefX64.Spec.MachineTypes.register → ((BitVec 64) → (L4vRefX64.Spec.MachineOps.user_context → ((Set (Unit × L4vRefX64.Spec.MachineOps.user_context)) × Bool)))) := + (fun (r : L4vRefX64.Spec.MachineTypes.register) => (fun (v : (BitVec 64)) => (holModify (fun (s : L4vRefX64.Spec.MachineOps.user_context) => (L4vRefX64.Spec.MachineOps.user_context.UserContext (L4vRefX64.Spec.MachineOps.user_context.user_fpu_state s) (holFunUpd (L4vRefX64.Spec.MachineOps.user_context.user_regs s) r v)))))) + +def setNextPC : ((BitVec 64) → (L4vRefX64.Spec.MachineOps.user_context → ((Set (Unit × L4vRefX64.Spec.MachineOps.user_context)) × Bool))) := + (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.MachineTypes.register.NextIP) + +def storeWordVM : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (w : (BitVec 64)) => (fun (p : (BitVec 64)) => (holReturn ()))) + +opaque writeCR3_impl : ((BitVec 64) → ((BitVec 64) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool)))) + +def writeCR3 : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)))) := + (fun (vspace : (BitVec 64)) => (fun (pcid : (BitVec 64)) => (L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.writeCR3_impl vspace pcid)))) + +opaque writeFpuState_impl : (((Fin 576) → (BitVec 8)) → (L4vRefX64.Spec.MachineTypes.machine_state_rest → ((Set (Unit × L4vRefX64.Spec.MachineTypes.machine_state_rest)) × Bool))) + +def writeFpuState : (((Fin 576) → (BitVec 8)) → ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (Unit × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) := + (fun (val : ((Fin 576) → (BitVec 8))) => (holBind (holStateAssert L4vRefX64.Spec.MachineTypes.machine_state_ext.fpu_enabled) (holKBind (holFunApp L4vRefX64.Spec.MachineMonad.machine_op_lift (L4vRefX64.Spec.MachineOps.writeFpuState_impl val))))) +end +end L4vRefX64.Spec.MachineOps diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineTypes.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineTypes.lean new file mode 100644 index 000000000..42e92c093 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MachineTypes.lean @@ -0,0 +1,254 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.MachineTypes) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Nondet_Empty_Fail +import L4vRefX64.Spec.Platform + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.MachineTypes +open L4vRefX64.Prim +open Classical +noncomputable section +opaque machine_state_rest_type : { T : Type // Nonempty T } := ⟨Unit, ⟨()⟩⟩ +def machine_state_rest : Type := machine_state_rest_type.1 +instance : Nonempty machine_state_rest := machine_state_rest_type.2 + +inductive gdtslot where + | GDT_NULL + | GDT_CS_0 + | GDT_DS_0 + | GDT_TSS + | GDT_TSS_Padding + | GDT_CS_3 + | GDT_DS_3 + | GDT_FS + | GDT_GS + | GDT_ENTRIES +instance : Nonempty gdtslot := ⟨gdtslot.GDT_NULL⟩ +def case_gdtslot {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : r_ty) (f6 : r_ty) (f7 : r_ty) (f8 : r_ty) (f9 : r_ty) : gdtslot → r_ty + | .GDT_NULL => f0 + | .GDT_CS_0 => f1 + | .GDT_DS_0 => f2 + | .GDT_TSS => f3 + | .GDT_TSS_Padding => f4 + | .GDT_CS_3 => f5 + | .GDT_DS_3 => f6 + | .GDT_FS => f7 + | .GDT_GS => f8 + | .GDT_ENTRIES => f9 + +inductive hyp_fault_type where + | X64NoHypFaults +instance : Nonempty hyp_fault_type := ⟨hyp_fault_type.X64NoHypFaults⟩ +def case_hyp_fault_type {r_ty : Type} (f0 : r_ty) : hyp_fault_type → r_ty + | .X64NoHypFaults => f0 + +inductive register where + | RAX + | RBX + | RCX + | RDX + | RSI + | RDI + | RBP + | R8 + | R9 + | R10 + | R11 + | R12 + | R13 + | R14 + | R15 + | FaultIP + | FS_BASE + | GS_BASE + | ErrorRegister + | NextIP + | CS + | FLAGS + | RSP + | SS +instance : Nonempty register := ⟨register.RAX⟩ +def case_register {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : r_ty) (f6 : r_ty) (f7 : r_ty) (f8 : r_ty) (f9 : r_ty) (f10 : r_ty) (f11 : r_ty) (f12 : r_ty) (f13 : r_ty) (f14 : r_ty) (f15 : r_ty) (f16 : r_ty) (f17 : r_ty) (f18 : r_ty) (f19 : r_ty) (f20 : r_ty) (f21 : r_ty) (f22 : r_ty) (f23 : r_ty) : register → r_ty + | .RAX => f0 + | .RBX => f1 + | .RCX => f2 + | .RDX => f3 + | .RSI => f4 + | .RDI => f5 + | .RBP => f6 + | .R8 => f7 + | .R9 => f8 + | .R10 => f9 + | .R11 => f10 + | .R12 => f11 + | .R13 => f12 + | .R14 => f13 + | .R15 => f14 + | .FaultIP => f15 + | .FS_BASE => f16 + | .GS_BASE => f17 + | .ErrorRegister => f18 + | .NextIP => f19 + | .CS => f20 + | .FLAGS => f21 + | .RSP => f22 + | .SS => f23 + +inductive vmfault_type where + | X64DataFault + | X64InstructionFault +instance : Nonempty vmfault_type := ⟨vmfault_type.X64DataFault⟩ +def case_vmfault_type {r_ty : Type} (f0 : r_ty) (f1 : r_ty) : vmfault_type → r_ty + | .X64DataFault => f0 + | .X64InstructionFault => f1 + +inductive vmmap_type where + | VMNoMap + | VMVSpaceMap +instance : Nonempty vmmap_type := ⟨vmmap_type.VMNoMap⟩ +def case_vmmap_type {r_ty : Type} (f0 : r_ty) (f1 : r_ty) : vmmap_type → r_ty + | .VMNoMap => f0 + | .VMVSpaceMap => f1 + +inductive vmpage_size where + | X64SmallPage + | X64LargePage + | X64HugePage +instance : Nonempty vmpage_size := ⟨vmpage_size.X64SmallPage⟩ +def case_vmpage_size {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) : vmpage_size → r_ty + | .X64SmallPage => f0 + | .X64LargePage => f1 + | .X64HugePage => f2 + +structure machine_state_ext (more : Type) where + irq_masks : ((BitVec 8) → Bool) + irq_state : Nat + time_state : Nat + last_machine_time : (BitVec 64) + underlying_memory : ((BitVec 64) → (BitVec 8)) + device_state : ((BitVec 64) → (Option (BitVec 8))) + fpu_enabled : Bool + machine_state_rest : L4vRefX64.Spec.MachineTypes.machine_state_rest + more : more +instance {more : Type} [Nonempty more] : Nonempty (machine_state_ext more) := ⟨machine_state_ext.mk holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +abbrev machine_state := machine_state_ext Unit +def machine_state.truncate {more : Type} (r : (machine_state_ext more)) : machine_state_ext Unit := { r with more := () } +def machine_state.extend {more : Type} (r : machine_state_ext Unit) (m : more) : (machine_state_ext more) := { r with more := m } +def machine_state.irq_masks_update {more : Type} (g : ((BitVec 8) → Bool) → ((BitVec 8) → Bool)) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with irq_masks := g r.irq_masks } +def machine_state.irq_state_update {more : Type} (g : Nat → Nat) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with irq_state := g r.irq_state } +def machine_state.time_state_update {more : Type} (g : Nat → Nat) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with time_state := g r.time_state } +def machine_state.last_machine_time_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with last_machine_time := g r.last_machine_time } +def machine_state.underlying_memory_update {more : Type} (g : ((BitVec 64) → (BitVec 8)) → ((BitVec 64) → (BitVec 8))) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with underlying_memory := g r.underlying_memory } +def machine_state.device_state_update {more : Type} (g : ((BitVec 64) → (Option (BitVec 8))) → ((BitVec 64) → (Option (BitVec 8)))) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with device_state := g r.device_state } +def machine_state.fpu_enabled_update {more : Type} (g : Bool → Bool) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with fpu_enabled := g r.fpu_enabled } +def machine_state.machine_state_rest_update {more : Type} (g : L4vRefX64.Spec.MachineTypes.machine_state_rest → L4vRefX64.Spec.MachineTypes.machine_state_rest) (r : (machine_state_ext more)) : (machine_state_ext more) := { r with machine_state_rest := g r.machine_state_rest } + +def enum_gdtslot : (List L4vRefX64.Spec.MachineTypes.gdtslot) := + (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_NULL (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_CS_0 (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_DS_0 (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_TSS (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_TSS_Padding (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_CS_3 (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_DS_3 (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_FS (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_GS (List.cons L4vRefX64.Spec.MachineTypes.gdtslot.GDT_ENTRIES (List.nil (α := L4vRefX64.Spec.MachineTypes.gdtslot)))))))))))) + +instance : HolEnum L4vRefX64.Spec.MachineTypes.gdtslot where enumList := L4vRefX64.Spec.MachineTypes.enum_gdtslot + +def enum_register : (List L4vRefX64.Spec.MachineTypes.register) := + (List.cons L4vRefX64.Spec.MachineTypes.register.RAX (List.cons L4vRefX64.Spec.MachineTypes.register.RBX (List.cons L4vRefX64.Spec.MachineTypes.register.RCX (List.cons L4vRefX64.Spec.MachineTypes.register.RDX (List.cons L4vRefX64.Spec.MachineTypes.register.RSI (List.cons L4vRefX64.Spec.MachineTypes.register.RDI (List.cons L4vRefX64.Spec.MachineTypes.register.RBP (List.cons L4vRefX64.Spec.MachineTypes.register.R8 (List.cons L4vRefX64.Spec.MachineTypes.register.R9 (List.cons L4vRefX64.Spec.MachineTypes.register.R10 (List.cons L4vRefX64.Spec.MachineTypes.register.R11 (List.cons L4vRefX64.Spec.MachineTypes.register.R12 (List.cons L4vRefX64.Spec.MachineTypes.register.R13 (List.cons L4vRefX64.Spec.MachineTypes.register.R14 (List.cons L4vRefX64.Spec.MachineTypes.register.R15 (List.cons L4vRefX64.Spec.MachineTypes.register.FaultIP (List.cons L4vRefX64.Spec.MachineTypes.register.FS_BASE (List.cons L4vRefX64.Spec.MachineTypes.register.GS_BASE (List.cons L4vRefX64.Spec.MachineTypes.register.ErrorRegister (List.cons L4vRefX64.Spec.MachineTypes.register.NextIP (List.cons L4vRefX64.Spec.MachineTypes.register.CS (List.cons L4vRefX64.Spec.MachineTypes.register.FLAGS (List.cons L4vRefX64.Spec.MachineTypes.register.RSP (List.cons L4vRefX64.Spec.MachineTypes.register.SS (List.nil (α := L4vRefX64.Spec.MachineTypes.register)))))))))))))))))))))))))) + +instance : HolEnum L4vRefX64.Spec.MachineTypes.register where enumList := L4vRefX64.Spec.MachineTypes.enum_register + +def enum_vmpage_size : (List L4vRefX64.Spec.MachineTypes.vmpage_size) := + (List.cons L4vRefX64.Spec.MachineTypes.vmpage_size.X64SmallPage (List.cons L4vRefX64.Spec.MachineTypes.vmpage_size.X64LargePage (List.cons L4vRefX64.Spec.MachineTypes.vmpage_size.X64HugePage (List.nil (α := L4vRefX64.Spec.MachineTypes.vmpage_size))))) + +instance : HolEnum L4vRefX64.Spec.MachineTypes.vmpage_size where enumList := L4vRefX64.Spec.MachineTypes.enum_vmpage_size + +def capRegister : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.register.RDI + +def badgeRegister : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.capRegister + +def exceptionMessage : (List L4vRefX64.Spec.MachineTypes.register) := + (List.cons L4vRefX64.Spec.MachineTypes.register.FaultIP (List.cons L4vRefX64.Spec.MachineTypes.register.RSP (List.cons L4vRefX64.Spec.MachineTypes.register.FLAGS (List.nil (α := L4vRefX64.Spec.MachineTypes.register))))) + +def faultRegister : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.register.FaultIP + +def frameRegisters : (List L4vRefX64.Spec.MachineTypes.register) := + (List.cons L4vRefX64.Spec.MachineTypes.register.FaultIP (List.cons L4vRefX64.Spec.MachineTypes.register.RSP (List.cons L4vRefX64.Spec.MachineTypes.register.FLAGS (holUptoEnum L4vRefX64.Spec.MachineTypes.register.RAX L4vRefX64.Spec.MachineTypes.register.R15)))) + +def gdtToSel (g : L4vRefX64.Spec.MachineTypes.gdtslot) : (BitVec 64) := + (holWordOr ((fun a f b => f a b) ((holOfNat (α := (BitVec 64))) (holFromEnum g)) holWordShiftl (HolNumeral.ofNatVal (α := Nat) 3)) (HolNumeral.ofNatVal (α := (BitVec 64)) 3)) + +def gdtToSel_masked (g : L4vRefX64.Spec.MachineTypes.gdtslot) : (BitVec 64) := + (holWordOr (L4vRefX64.Spec.MachineTypes.gdtToSel g) (HolNumeral.ofNatVal (α := (BitVec 64)) 3)) + +def gpRegisters : (List L4vRefX64.Spec.MachineTypes.register) := + (List.cons L4vRefX64.Spec.MachineTypes.register.FS_BASE (List.cons L4vRefX64.Spec.MachineTypes.register.GS_BASE (List.nil (α := L4vRefX64.Spec.MachineTypes.register)))) + +def selCS3 : (BitVec 64) := + (L4vRefX64.Spec.MachineTypes.gdtToSel_masked L4vRefX64.Spec.MachineTypes.gdtslot.GDT_CS_3) + +def selDS3 : (BitVec 64) := + (L4vRefX64.Spec.MachineTypes.gdtToSel_masked L4vRefX64.Spec.MachineTypes.gdtslot.GDT_DS_3) + +def initContext : (List (L4vRefX64.Spec.MachineTypes.register × (BitVec 64))) := + (List.cons (Prod.mk L4vRefX64.Spec.MachineTypes.register.CS L4vRefX64.Spec.MachineTypes.selCS3) (List.cons (Prod.mk L4vRefX64.Spec.MachineTypes.register.SS L4vRefX64.Spec.MachineTypes.selDS3) (List.cons (Prod.mk L4vRefX64.Spec.MachineTypes.register.FLAGS (holWordOr (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (HolNumeral.ofNatVal (α := Nat) 9)) ((holHaskellBit (w := 64)) (HolOne.oneVal (α := Nat))))) (List.nil (α := (L4vRefX64.Spec.MachineTypes.register × (BitVec 64))))))) + +def init_irq_masks : ((BitVec 8) → Bool) := + (fun (uu_ : (BitVec 8)) => true) + +def init_underlying_memory : ((BitVec 64) → (BitVec 8)) := + (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 8)))) + +def init_machine_state : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) := + (L4vRefX64.Spec.MachineTypes.machine_state_ext.mk L4vRefX64.Spec.MachineTypes.init_irq_masks (HolZero.zeroVal (α := Nat)) (HolZero.zeroVal (α := Nat)) (HolZero.zeroVal (α := (BitVec 64))) L4vRefX64.Spec.MachineTypes.init_underlying_memory (fun (x : (BitVec 64)) => (Option.none (α := (BitVec 8)))) false (holUndefined (α := L4vRefX64.Spec.MachineTypes.machine_state_rest)) ()) + +def msgInfoRegister : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.register.RSI + +def msgRegisters : (List L4vRefX64.Spec.MachineTypes.register) := + (List.cons L4vRefX64.Spec.MachineTypes.register.R10 (List.cons L4vRefX64.Spec.MachineTypes.register.R8 (List.cons L4vRefX64.Spec.MachineTypes.register.R9 (List.cons L4vRefX64.Spec.MachineTypes.register.R15 (List.nil (α := L4vRefX64.Spec.MachineTypes.register)))))) + +def nbsendRecvDest : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.register.R13 + +def nextInstructionRegister : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.register.NextIP + +def pageBits : Nat := + (HolNumeral.ofNatVal (α := Nat) 12) + +def ptTranslationBits : Nat := + (HolNumeral.ofNatVal (α := Nat) 9) + +def pageBitsForSize : (L4vRefX64.Spec.MachineTypes.vmpage_size → Nat) := + (fun (x0 : L4vRefX64.Spec.MachineTypes.vmpage_size) => (L4vRefX64.Spec.MachineTypes.case_vmpage_size L4vRefX64.Spec.MachineTypes.pageBits (HolAdd.addVal L4vRefX64.Spec.MachineTypes.pageBits L4vRefX64.Spec.MachineTypes.ptTranslationBits) (HolAdd.addVal (HolAdd.addVal L4vRefX64.Spec.MachineTypes.pageBits L4vRefX64.Spec.MachineTypes.ptTranslationBits) L4vRefX64.Spec.MachineTypes.ptTranslationBits) x0)) + +def replyRegister : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.register.R12 + +def selCS0 : (BitVec 64) := + (L4vRefX64.Spec.MachineTypes.gdtToSel_masked L4vRefX64.Spec.MachineTypes.gdtslot.GDT_CS_0) + +def selDS0 : (BitVec 64) := + (L4vRefX64.Spec.MachineTypes.gdtToSel L4vRefX64.Spec.MachineTypes.gdtslot.GDT_DS_0) + +def selFS : (BitVec 64) := + (L4vRefX64.Spec.MachineTypes.gdtToSel_masked L4vRefX64.Spec.MachineTypes.gdtslot.GDT_FS) + +def selGS : (BitVec 64) := + (L4vRefX64.Spec.MachineTypes.gdtToSel_masked L4vRefX64.Spec.MachineTypes.gdtslot.GDT_GS) + +def syscallMessage : (List L4vRefX64.Spec.MachineTypes.register) := + (holListAppend (holUptoEnum L4vRefX64.Spec.MachineTypes.register.RAX L4vRefX64.Spec.MachineTypes.register.R15) (List.cons L4vRefX64.Spec.MachineTypes.register.FaultIP (List.cons L4vRefX64.Spec.MachineTypes.register.RSP (List.cons L4vRefX64.Spec.MachineTypes.register.FLAGS (List.nil (α := L4vRefX64.Spec.MachineTypes.register)))))) + +def timeoutMessage : (List L4vRefX64.Spec.MachineTypes.register) := + (List.cons L4vRefX64.Spec.MachineTypes.register.FaultIP (List.cons L4vRefX64.Spec.MachineTypes.register.RSP (List.cons L4vRefX64.Spec.MachineTypes.register.FLAGS (List.cons L4vRefX64.Spec.MachineTypes.register.RAX (List.cons L4vRefX64.Spec.MachineTypes.register.RBX (List.cons L4vRefX64.Spec.MachineTypes.register.RCX (List.cons L4vRefX64.Spec.MachineTypes.register.RDX (List.cons L4vRefX64.Spec.MachineTypes.register.RSI (List.cons L4vRefX64.Spec.MachineTypes.register.RDI (List.cons L4vRefX64.Spec.MachineTypes.register.RBP (List.cons L4vRefX64.Spec.MachineTypes.register.R8 (List.cons L4vRefX64.Spec.MachineTypes.register.R9 (List.cons L4vRefX64.Spec.MachineTypes.register.R10 (List.cons L4vRefX64.Spec.MachineTypes.register.R11 (List.cons L4vRefX64.Spec.MachineTypes.register.R12 (List.cons L4vRefX64.Spec.MachineTypes.register.R13 (List.cons L4vRefX64.Spec.MachineTypes.register.R14 (List.cons L4vRefX64.Spec.MachineTypes.register.R15 (List.cons L4vRefX64.Spec.MachineTypes.register.FS_BASE (List.nil (α := L4vRefX64.Spec.MachineTypes.register))))))))))))))))))))) + +def tlsBaseRegister : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.register.FS_BASE + +opaque irq_oracle : (Nat → (BitVec 8)) + +opaque time_oracle : (Nat → Nat) +end +end L4vRefX64.Spec.MachineTypes diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Machine_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Machine_A.lean new file mode 100644 index 000000000..2651e330e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Machine_A.lean @@ -0,0 +1,102 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Machine_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.Platform + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Machine_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive arch_fault where + | VMFault (a0 : (BitVec 64)) (a1 : (List (BitVec 64))) +instance : Nonempty arch_fault := ⟨arch_fault.VMFault holUndefined holUndefined⟩ +def case_arch_fault {r_ty : Type} (f0 : (BitVec 64) → (List (BitVec 64)) → r_ty) : arch_fault → r_ty + | .VMFault x0 x1 => f0 x0 x1 + +def badge_register : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.badgeRegister + +def cap_register : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.capRegister + +def combine_ntfn_badges : ((BitVec 64) → ((BitVec 64) → (BitVec 64))) := + holWordOr + +def combine_ntfn_msgs : ((BitVec 64) → ((BitVec 64) → (BitVec 64))) := + holWordOr + +def data_to_16 : ((BitVec 64) → (BitVec 16)) := + (holUcast (w := 16)) + +def data_to_cptr : ((BitVec 64) → (List Bool)) := + holToBl + +def data_to_nat : ((BitVec 64) → Nat) := + holUnsigned + +def data_to_oref : ((BitVec 64) → (BitVec 64)) := + holId + +def data_to_vref : ((BitVec 64) → (BitVec 64)) := + holId + +def exception_message : (List L4vRefX64.Spec.MachineTypes.register) := + L4vRefX64.Spec.MachineTypes.exceptionMessage + +def frame_registers : (List L4vRefX64.Spec.MachineTypes.register) := + L4vRefX64.Spec.MachineTypes.frameRegisters + +def gp_registers : (List L4vRefX64.Spec.MachineTypes.register) := + L4vRefX64.Spec.MachineTypes.gpRegisters + +def kernel_base : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 18446744071562067968) + +def idle_sc_ptr : (BitVec 64) := + (HolAdd.addVal L4vRefX64.Spec.Machine_A.kernel_base (HolNumeral.ofNatVal (α := (BitVec 64)) 28672)) + +def idle_thread_ptr : (BitVec 64) := + (HolAdd.addVal L4vRefX64.Spec.Machine_A.kernel_base (HolNumeral.ofNatVal (α := (BitVec 64)) 4096)) + +def msg_info_register : L4vRefX64.Spec.MachineTypes.register := + L4vRefX64.Spec.MachineTypes.msgInfoRegister + +def msg_label_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 52) + +def msg_registers : (List L4vRefX64.Spec.MachineTypes.register) := + L4vRefX64.Spec.MachineTypes.msgRegisters + +def nat_to_cref : (Nat → (Nat → (List Bool))) := + (fun (len : Nat) => (fun (n : Nat) => (holListDrop (HolSub.subVal L4vRefX64.Spec.Machine_Word_64_Basics.word_bits len) (holToBl ((holOfNat (α := (BitVec 64))) n))))) + +def nat_to_len : (Nat → (BitVec 64)) := + (holOfNat (α := (BitVec 64))) + +def new_context : L4vRefX64.Spec.MachineOps.user_context := + (L4vRefX64.Spec.MachineOps.user_context.UserContext L4vRefX64.Spec.MachineOps.FPUNullState (holFunUpd (holFunUpd (holFunUpd (fun (r : L4vRefX64.Spec.MachineTypes.register) => (HolZero.zeroVal (α := (BitVec 64)))) L4vRefX64.Spec.MachineTypes.register.CS L4vRefX64.Spec.MachineTypes.selCS3) L4vRefX64.Spec.MachineTypes.register.SS L4vRefX64.Spec.MachineTypes.selDS3) L4vRefX64.Spec.MachineTypes.register.FLAGS (HolNumeral.ofNatVal (α := (BitVec 64)) 514))) + +def oref_to_data : ((BitVec 64) → (BitVec 64)) := + holId + +def pptr_base : (BitVec 64) := + L4vRefX64.Spec.Platform.pptrBase + +def slot_bits : Nat := + (HolNumeral.ofNatVal (α := Nat) 5) + +def syscall_message : (List L4vRefX64.Spec.MachineTypes.register) := + L4vRefX64.Spec.MachineTypes.syscallMessage + +def user_vtop : (BitVec 64) := + L4vRefX64.Spec.Platform.pptrUserTop + +def vref_to_data : ((BitVec 64) → (BitVec 64)) := + holId +end +end L4vRefX64.Spec.Machine_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Machine_Word_64_Basics.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Machine_Word_64_Basics.lean new file mode 100644 index 000000000..b3bdeffd1 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Machine_Word_64_Basics.lean @@ -0,0 +1,20 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (Word_Lib.Machine_Word_64_Basics) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Machine_Word_64_Basics +open L4vRefX64.Prim +open Classical +noncomputable section +def word_bits : Nat := + (64 : Nat) + +def word_size {tv_a : Type} [Nonempty tv_a] [HolNumeral tv_a] : tv_a := + (HolNumeral.ofNatVal (α := tv_a) 8) + +def word_size_bits {tv_a : Type} [Nonempty tv_a] [HolNumeral tv_a] : tv_a := + (HolNumeral.ofNatVal (α := tv_a) 3) +end +end L4vRefX64.Spec.Machine_Word_64_Basics diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MiscMachine_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MiscMachine_A.lean new file mode 100644 index 000000000..dd944a01d --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/MiscMachine_A.lean @@ -0,0 +1,21 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.MiscMachine_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Machine_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.MiscMachine_A +open L4vRefX64.Prim +open Classical +noncomputable section +def asid_bits : Nat := + (12 : Nat) + +def asid_high_bits : Nat := + (3 : Nat) + +def asid_low_bits : Nat := + (9 : Nat) +end +end L4vRefX64.Spec.MiscMachine_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/More_Word_Operations.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/More_Word_Operations.lean new file mode 100644 index 000000000..3983c8523 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/More_Word_Operations.lean @@ -0,0 +1,17 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (Word_Lib.More_Word_Operations) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.More_Word_Operations +open L4vRefX64.Prim +open Classical +noncomputable section +def alignUp {w_tv_a : Nat} : ((BitVec w_tv_a) → (Nat → (BitVec w_tv_a))) := + (fun (x : (BitVec w_tv_a)) => (fun (n : Nat) => (holWordAnd (HolSub.subVal (HolAdd.addVal x (HolPow.powVal (HolNumeral.ofNatVal (α := (BitVec w_tv_a)) 2) n)) (HolOne.oneVal (α := (BitVec w_tv_a)))) (holWordNot (HolSub.subVal (HolPow.powVal (HolNumeral.ofNatVal (α := (BitVec w_tv_a)) 2) n) (HolOne.oneVal (α := (BitVec w_tv_a)))))))) + +def ptr_add {w_tv_a : Nat} : ((BitVec w_tv_a) → (Nat → (BitVec w_tv_a))) := + (fun (ptr : (BitVec w_tv_a)) => (fun (n : Nat) => (HolAdd.addVal ptr ((holOfNat (α := (BitVec w_tv_a))) n)))) +end +end L4vRefX64.Spec.More_Word_Operations diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Nondet_Empty_Fail.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Nondet_Empty_Fail.lean new file mode 100644 index 000000000..26e6a0d9c --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Nondet_Empty_Fail.lean @@ -0,0 +1,14 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (Monads.Nondet_Empty_Fail) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Nondet_Empty_Fail +open L4vRefX64.Prim +open Classical +noncomputable section +def mk_ef {tv_a : Type} [Nonempty tv_a] : (((Set tv_a) × Bool) → ((Set tv_a) × Bool)) := + (fun (S : ((Set tv_a) × Bool)) => (Prod.mk (Prod.fst S) (holDisj (holEq (Prod.fst S) (HolCompleteLattice.holBot (α := (Set tv_a)))) (Prod.snd S)))) +end +end L4vRefX64.Spec.Nondet_Empty_Fail diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Platform.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Platform.lean new file mode 100644 index 000000000..ef5daacf8 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Platform.lean @@ -0,0 +1,64 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.Platform) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Kernel_Config +import L4vRefX64.Spec.Lib + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Platform +open L4vRefX64.Prim +open Classical +noncomputable section +inductive cr3 where + | X64CR3 (a0 : (BitVec 64)) (a1 : (BitVec 64)) +instance : Nonempty cr3 := ⟨cr3.X64CR3 holUndefined holUndefined⟩ +def case_cr3 {r_ty : Type} (f0 : (BitVec 64) → (BitVec 64) → r_ty) : cr3 → r_ty + | .X64CR3 x0 x1 => f0 x0 x1 + +def kernelELFBaseOffset : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 18446744071562067968) + +def addrFromKPPtr : ((BitVec 64) → (BitVec 64)) := + (fun (pptr : (BitVec 64)) => (HolSub.subVal pptr L4vRefX64.Spec.Platform.kernelELFBaseOffset)) + +def pptrBase : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 18446743523953737728) + +def addrFromPPtr : ((BitVec 64) → (BitVec 64)) := + (fun (pptr : (BitVec 64)) => (HolSub.subVal pptr L4vRefX64.Spec.Platform.pptrBase)) + +def cr3.CR3BaseAddress : (L4vRefX64.Spec.Platform.cr3 → (BitVec 64)) + | cr3 => (L4vRefX64.Spec.Platform.case_cr3 (fun (x1 : (BitVec 64)) => (fun (x2 : (BitVec 64)) => x1)) cr3) + +def cr3.cr3pcid : (L4vRefX64.Spec.Platform.cr3 → (BitVec 64)) + | cr3 => (L4vRefX64.Spec.Platform.case_cr3 (fun (x1 : (BitVec 64)) => (fun (x2 : (BitVec 64)) => x2)) cr3) + +def fromPAddr : ((BitVec 64) → (BitVec 64)) := + holId + +def maxIRQ : (BitVec 8) := + (HolNumeral.ofNatVal (α := (BitVec 8)) 125) + +def maxUserIRQ : (BitVec 8) := + (HolNumeral.ofNatVal (α := (BitVec 8)) 123) + +def minIRQ : (BitVec 8) := + (HolZero.zeroVal (α := (BitVec 8))) + +def minUserIRQ : (BitVec 8) := + (HolNumeral.ofNatVal (α := (BitVec 8)) 16) + +def pptrUserTop : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 140737488355327) + +def ptrFromPAddr : ((BitVec 64) → (BitVec 64)) := + (fun (paddr : (BitVec 64)) => (HolAdd.addVal paddr L4vRefX64.Spec.Platform.pptrBase)) + +def timerIRQ : (BitVec 8) := + L4vRefX64.Spec.Platform.maxIRQ + +def toPAddr : ((BitVec 64) → (BitVec 64)) := + holId +end +end L4vRefX64.Spec.Platform diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Reader_Option_Monad.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Reader_Option_Monad.lean new file mode 100644 index 000000000..a6b60a89d --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Reader_Option_Monad.lean @@ -0,0 +1,44 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (Monads.Reader_Option_Monad) — DO NOT EDIT +import L4vRefX64.PrimX64 + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Reader_Option_Monad +open L4vRefX64.Prim +open Classical +noncomputable section +def oreturn {tv_a : Type} [Nonempty tv_a] {tv_s : Type} [Nonempty tv_s] : (tv_a → (tv_s → (Option tv_a))) := + (holComp holK Option.some) + +def asks {tv_s : Type} [Nonempty tv_s] {tv_a : Type} [Nonempty tv_a] : ((tv_s → tv_a) → (tv_s → (Option tv_a))) := + (fun (f : (tv_s → tv_a)) => (holOBind Option.some (fun (v : tv_s) => (holOReturn (f v))))) + +def ofail {tv_s : Type} [Nonempty tv_s] {tv_a : Type} [Nonempty tv_a] : (tv_s → (Option tv_a)) := + (holK (Option.none (α := tv_a))) + +def oassert {tv_s : Type} [Nonempty tv_s] : (Bool → (tv_s → (Option Unit))) := + (fun (P : Bool) => (holIf P (holOReturn ()) (holOFail : (tv_s → (Option Unit))))) + +def oassert_opt {tv_a : Type} [Nonempty tv_a] {tv_s : Type} [Nonempty tv_s] : ((Option tv_a) → (tv_s → (Option tv_a))) := + (fun (r : (Option tv_a)) => (holCaseOption (holOFail : (tv_s → (Option tv_a))) (fun (x : tv_a) => (holOReturn x)) r)) + +def oliftM {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] {tv_s : Type} [Nonempty tv_s] : ((tv_a → tv_b) → ((tv_s → (Option tv_a)) → (tv_s → (Option tv_b)))) := + (fun (f : (tv_a → tv_b)) => (fun (m : (tv_s → (Option tv_a))) => (holOBind m (fun (x : tv_a) => (holOReturn (f x)))))) + +def opt_map {tv_s : Type} [Nonempty tv_s] {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] : ((tv_s → (Option tv_a)) → ((tv_a → (Option tv_b)) → (tv_s → (Option tv_b)))) := + (fun (f : (tv_s → (Option tv_a))) => (fun (g : (tv_a → (Option tv_b))) => (fun (s : tv_s) => (holCaseOption (Option.none (α := tv_b)) (fun (x : tv_a) => (g x)) (f s))))) + +def opt_map_Some {tv_s : Type} [Nonempty tv_s] {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] : ((tv_s → (Option tv_a)) → ((tv_a → tv_b) → (tv_s → (Option tv_b)))) := + (fun (f : (tv_s → (Option tv_a))) => (fun (g : (tv_a → tv_b)) => (holOptMap f (fun (s : tv_a) => (Option.some (g s)))))) + +def opt_pred {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] : ((tv_a → Bool) → ((tv_b → (Option tv_a)) → (tv_b → Bool))) := + (fun (P : (tv_a → Bool)) => (fun (proj : (tv_b → (Option tv_a))) => (fun (x : tv_b) => (holCaseOption false P (proj x))))) + +def ounless {tv_s : Type} [Nonempty tv_s] : (Bool → ((tv_s → (Option Unit)) → (tv_s → (Option Unit)))) := + (fun (P : Bool) => (fun (f : (tv_s → (Option Unit))) => (holIf P (holOReturn ()) f))) + +def owhen {tv_s : Type} [Nonempty tv_s] : (Bool → ((tv_s → (Option Unit)) → (tv_s → (Option Unit)))) := + (fun (P : Bool) => (fun (f : (tv_s → (Option Unit))) => (holIf P f (holOReturn ())))) +end +end L4vRefX64.Spec.Reader_Option_Monad diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Retype_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Retype_A.lean new file mode 100644 index 000000000..0e9f2307e --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Retype_A.lean @@ -0,0 +1,70 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Retype_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchRetype_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.Kernel_Config +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.More_Word_Operations +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Retype_A +open L4vRefX64.Prim +open Classical +noncomputable section +def default_cap : (L4vRefX64.Spec.Structures_A.apiobject_type → ((BitVec 64) → (Nat → (Bool → L4vRefX64.Spec.Structures_A.cap)))) + | L4vRefX64.Spec.Structures_A.apiobject_type.CapTableObject, oref, s, uu => (L4vRefX64.Spec.Structures_A.cap.CNodeCap oref s (List.nil (α := Bool))) + | L4vRefX64.Spec.Structures_A.apiobject_type.Untyped, oref, s, dev => (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev oref s (HolZero.zeroVal (α := Nat))) + | L4vRefX64.Spec.Structures_A.apiobject_type.TCBObject, oref, s, uv => (L4vRefX64.Spec.Structures_A.cap.ThreadCap oref) + | L4vRefX64.Spec.Structures_A.apiobject_type.EndpointObject, oref, s, uw => (L4vRefX64.Spec.Structures_A.cap.EndpointCap oref (HolZero.zeroVal (α := (BitVec 64))) (HolCompleteLattice.holTop (α := (Set L4vRefX64.Spec.CapRights_A.rights)))) + | L4vRefX64.Spec.Structures_A.apiobject_type.NotificationObject, oref, s, ux => (L4vRefX64.Spec.Structures_A.cap.NotificationCap oref (HolZero.zeroVal (α := (BitVec 64))) (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowRead (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowWrite (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))))) + | L4vRefX64.Spec.Structures_A.apiobject_type.SchedContextObject, oref, s, uy => (L4vRefX64.Spec.Structures_A.cap.SchedContextCap oref (HolSub.subVal s (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat))) + | L4vRefX64.Spec.Structures_A.apiobject_type.ReplyObject, oref, uz, va => (L4vRefX64.Spec.Structures_A.cap.ReplyCap oref (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowGrant (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowWrite (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))))) + | (L4vRefX64.Spec.Structures_A.apiobject_type.ArchObject aobj), oref, s, dev => (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.arch_default_cap aobj oref s dev)) + +def create_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.apiobject_type → (Nat → (((BitVec 64) × (List Bool)) → (Bool → ((((BitVec 64) × (List Bool)) × (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (v_type : L4vRefX64.Spec.Structures_A.apiobject_type) => (fun (bits : Nat) => (fun (untyped : ((BitVec 64) × (List Bool))) => (fun (is_device : Bool) => (holCaseProd (fun (dest : ((BitVec 64) × (List Bool))) => (fun (oref : (BitVec 64)) => (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt s dest))) (fun (dest_p : (Option ((BitVec 64) × (List Bool)))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cdt) (fun (cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cdt (holFunUpd cdt dest (Option.some untyped))) (holKBind (holBind (L4vRefX64.Spec.Deterministic_A.do_extended_op (L4vRefX64.Spec.Deterministic_A.create_cap_ext untyped dest dest_p)) (holKBind (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_original dest true) (holKBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap (L4vRefX64.Spec.Retype_A.default_cap v_type oref bits is_device) dest)))))))))))))))))) + +def empty_cnode : (Nat → ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) := + (fun (bits : Nat) => (fun (x : (List Bool)) => (holIf (holEq (holSize x) bits) (Option.some L4vRefX64.Spec.Structures_A.cap.NullCap) (Option.none (α := L4vRefX64.Spec.Structures_A.cap))))) + +def default_object : (L4vRefX64.Spec.Structures_A.apiobject_type → (Bool → (Nat → ((BitVec 8) → L4vRefX64.Spec.Structures_A.kernel_object)))) := + (fun (api : L4vRefX64.Spec.Structures_A.apiobject_type) => (fun (dev : Bool) => (fun (n : Nat) => (fun (d : (BitVec 8)) => (L4vRefX64.Spec.Structures_A.case_apiobject_type (holUndefined (α := L4vRefX64.Spec.Structures_A.kernel_object)) (L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.default_tcb d)) (L4vRefX64.Spec.Structures_A.kernel_object.Endpoint L4vRefX64.Spec.Structures_A.default_ep) (L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.default_notification) (L4vRefX64.Spec.Structures_A.kernel_object.CNode n (L4vRefX64.Spec.Retype_A.empty_cnode n)) (L4vRefX64.Spec.Structures_A.kernel_object.SchedContext L4vRefX64.Spec.Structures_A.default_sched_context (HolSub.subVal n (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat))) (L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.default_reply) (fun (aobj : L4vRefX64.Spec.Arch_Structs_A.aobject_type) => (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.default_arch_object aobj dev n))) api))))) + +def detype {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((Set (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) := + (fun (S : (Set (BitVec 64))) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.kheap_update (fun (uu_ : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object))) => (fun (x : (BitVec 64)) => (holIf (holMember x S) (Option.none (α := L4vRefX64.Spec.Structures_A.kernel_object)) (L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap s x)))) s))) + +def delete_objects {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (bits : Nat) => (holBind (L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.freeMemory ptr bits)) (holKBind (holModify (L4vRefX64.Spec.Retype_A.detype (holAtLeastAtMost ptr (HolSub.subVal (HolAdd.addVal ptr (HolPow.powVal (HolNumeral.ofNatVal (α := (BitVec 64)) 2) bits)) (HolOne.oneVal (α := (BitVec 64))))))))))) + +def get_free_index : ((BitVec 64) → ((BitVec 64) → Nat)) := + (fun (base : (BitVec 64)) => (fun (free : (BitVec 64)) => (holFunApp holUnsigned (HolSub.subVal free base)))) + +def get_free_ref : ((BitVec 64) → (Nat → (BitVec 64))) := + (fun (base : (BitVec 64)) => (fun (free_index : Nat) => (HolAdd.addVal base ((holOfNat (α := (BitVec 64))) free_index)))) + +def obj_bits_api : (L4vRefX64.Spec.Structures_A.apiobject_type → (Nat → Nat)) := + (fun (v_type : L4vRefX64.Spec.Structures_A.apiobject_type) => (fun (obj_size_bits : Nat) => (L4vRefX64.Spec.Structures_A.case_apiobject_type obj_size_bits (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.default_tcb L4vRefX64.Spec.Structures_A.default_domain))) (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.Endpoint (holUndefined (α := L4vRefX64.Spec.Structures_A.endpoint)))) (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.Notification (holUndefined (α := (L4vRefX64.Spec.Structures_A.notification_ext Unit))))) (HolAdd.addVal obj_size_bits L4vRefX64.Spec.Machine_A.slot_bits) obj_size_bits (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.Reply L4vRefX64.Spec.Structures_A.default_reply)) (fun (aobj : L4vRefX64.Spec.Arch_Structs_A.aobject_type) => (holFunApp L4vRefX64.Spec.Structures_A.obj_bits (holFunApp L4vRefX64.Spec.Structures_A.kernel_object.ArchObj (L4vRefX64.Spec.Arch_Structs_A.default_arch_object aobj false obj_size_bits)))) v_type))) + +def is_device_untyped_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap isdev uu uv uw) => isdev + | _ => holUndefined + +def reset_untyped_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (((BitVec 64) × (List Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (src_slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.CSpaceAcc_A.get_cap src_slot)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBindE (holFunApp (holReturnOk (ε := Unit)) (L4vRefX64.Spec.Structures_A.bits_of cap)) (fun (sz : Nat) => (holBindE (holFunApp (holReturnOk (ε := Unit)) (L4vRefX64.Spec.Structures_A.obj_ref_of cap)) (fun (base : (BitVec 64)) => (holIf (holEq (L4vRefX64.Spec.Structures_A.free_index_of cap) (HolZero.zeroVal (α := Nat))) ((holReturnOk (ε := Unit)) ()) (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Retype_A.delete_objects base sz)) (holKBind (holBindE (holFunApp (holReturnOk (ε := Unit)) (L4vRefX64.Spec.Retype_A.is_device_untyped_cap cap)) (fun (dev : Bool) => (holBindE (holIf (holDisj dev (holLt sz L4vRefX64.Spec.Kernel_Config.resetChunkBits)) (holFunApp (holLiftE (ε := Unit)) (holBind (holFunApp (holUnless dev) (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.clearMemory base (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) sz)))) (holKBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev base sz (HolZero.zeroVal (α := Nat))) src_slot)))) (holMapMEx (fun (i : Nat) => (holBindE (holFunApp (holLiftE (ε := Unit)) (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.clearMemory (HolAdd.addVal base (holWordShiftl ((holOfNat (α := (BitVec 64))) i) L4vRefX64.Spec.Kernel_Config.resetChunkBits)) (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) L4vRefX64.Spec.Kernel_Config.resetChunkBits)))) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.CSpaceAcc_A.set_cap (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev base sz (HolMul.mulVal i (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) L4vRefX64.Spec.Kernel_Config.resetChunkBits))) src_slot)) (holKBind L4vRefX64.Spec.KHeap_A.preemption_point))))) (holListRev (holListFilter (fun (i : Nat) => (holLt (HolMul.mulVal i (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) L4vRefX64.Spec.Kernel_Config.resetChunkBits)) (L4vRefX64.Spec.Structures_A.free_index_of cap))) (holListUpt (HolZero.zeroVal (α := Nat)) (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) (HolSub.subVal sz L4vRefX64.Spec.Kernel_Config.resetChunkBits))))))) (holKBind (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.ArchRetype_A.arch_post_reset_untyped dev sz)))))))))))))))) + +def retype_region {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Nat → (Nat → (L4vRefX64.Spec.Structures_A.apiobject_type → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (ptr : (BitVec 64)) => (fun (numObjects : Nat) => (fun (o_bits : Nat) => (fun (v_type : L4vRefX64.Spec.Structures_A.apiobject_type) => (fun (dev : Bool) => (holBind (holFunApp holReturn (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) (L4vRefX64.Spec.Retype_A.obj_bits_api v_type o_bits))) (fun (obj_size : Nat) => (holBind (holFunApp holReturn (holListMap (fun (p : Nat) => (L4vRefX64.Spec.More_Word_Operations.ptr_add ptr (HolMul.mulVal p obj_size))) (holListUpt (HolZero.zeroVal (α := Nat)) numObjects))) (fun (ptrs : (List (BitVec 64))) => (holBind (holWhen (holNot (holEq v_type L4vRefX64.Spec.Structures_A.apiobject_type.Untyped)) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.kheap) (fun (kh : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_domain) (fun (cd : (BitVec 8)) => (holBind (holFunApp holReturn (holListFoldr (fun (p : (BitVec 64)) => (fun (kh_1 : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object))) => (holFunUpd kh_1 p (Option.some (L4vRefX64.Spec.Retype_A.default_object v_type dev o_bits cd))))) ptrs kh)) (fun (kh_p : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object))) => (holFunApp holModify (L4vRefX64.Spec.Structures_A.abstract_state.kheap_update (holK kh_p)))))))))) (holKBind (holFunApp holReturn ptrs)))))))))))) + +def invoke_untyped {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.untyped_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ui : L4vRefX64.Spec.Invocations_A.untyped_invocation) => (L4vRefX64.Spec.Invocations_A.case_untyped_invocation (fun (src_slot : ((BitVec 64) × (List Bool))) => (fun (reset : Bool) => (fun (base : (BitVec 64)) => (fun (retype_base : (BitVec 64)) => (fun (new_type : L4vRefX64.Spec.Structures_A.apiobject_type) => (fun (obj_sz : Nat) => (fun (slots : (List ((BitVec 64) × (List Bool)))) => (fun (is_device : Bool) => (holBindE (holFunApp (holWhenE reset) (L4vRefX64.Spec.Retype_A.reset_untyped_cap src_slot)) (holKBind (holFunApp (holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap src_slot) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holBind (holFunApp holReturn (holWordShiftl ((holOfNat (α := (BitVec 64))) (holSize slots)) (L4vRefX64.Spec.Retype_A.obj_bits_api new_type obj_sz))) (fun (total_object_size : (BitVec 64)) => (holBind (holFunApp holReturn (HolAdd.addVal retype_base total_object_size)) (fun (free_ref : (BitVec 64)) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.set_cap (L4vRefX64.Spec.Structures_A.cap.UntypedCap is_device base (L4vRefX64.Spec.Structures_A.bits_of cap) (holUnsigned (HolSub.subVal free_ref base))) src_slot) (holKBind (holBind (L4vRefX64.Spec.Retype_A.retype_region retype_base (holSize slots) obj_sz new_type is_device) (fun (orefs : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.ArchRetype_A.init_arch_objects new_type is_device retype_base (holSize slots) obj_sz orefs) (holKBind (holMapMx (L4vRefX64.Spec.Retype_A.create_cap new_type obj_sz src_slot is_device) (holListZip slots orefs))))))))))))))))))))))))) ui)) +end +end L4vRefX64.Spec.Retype_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/SchedContext_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/SchedContext_A.lean new file mode 100644 index 000000000..2fbc6f78f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/SchedContext_A.lean @@ -0,0 +1,155 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.SchedContext_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Sporadic_A +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.TcbAcc_A +import L4vRefX64.Spec.Time + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.SchedContext_A +open L4vRefX64.Prim +open Classical +noncomputable section +def refill_size {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Nat × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refills sc_ptr) (fun (refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (holFunApp holReturn (holSize refills))))) + +def refill_single {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.SchedContext_A.refill_size sc_ptr) (fun (sz : Nat) => (holReturn (holEq sz (HolOne.oneVal (α := Nat))))))) + +def refill_add_tail {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (new_refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (holListAppend refills (List.cons new_refill (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit)))))))))) + +def refill_full {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holReturn (holEq (holSize (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc)) (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refill_max sc)))))) + +def update_refill_tl {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((L4vRefX64.Spec.Structures_A.refill_ext Unit) → (L4vRefX64.Spec.Structures_A.refill_ext Unit)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (f : ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (holListAppend (holButlast refills) (List.cons (f (holLast refills)) (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit)))))))))) + +def schedule_used {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (new : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refills sc_ptr) (fun (refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (holBind (holAssert (holNot (holEq refills (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit)))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_refill_tail sc_ptr) (fun (tail : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holIf (L4vRefX64.Spec.Sporadic_A.can_merge_refill tail new) (L4vRefX64.Spec.SchedContext_A.update_refill_tl sc_ptr (fun (r : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount tail) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount new))) r))) (holBind (L4vRefX64.Spec.SchedContext_A.refill_full sc_ptr) (fun (full : Bool) => (holIf (holNot full) (L4vRefX64.Spec.SchedContext_A.refill_add_tail sc_ptr new) (holBind (L4vRefX64.Spec.SchedContext_A.update_refill_tl sc_ptr (fun (r : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_time_update (fun (uu_ : (BitVec 64)) => (HolSub.subVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time new) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount tail))) r))) (holKBind (L4vRefX64.Spec.SchedContext_A.update_refill_tl sc_ptr (fun (r : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount tail) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount new))) r))))))))))))))))) + +def charge_entire_head_refill {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (usage : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (L4vRefX64.Spec.SchedContext_A.refill_single sc_ptr) (fun (single : Bool) => (holBind (holIf single (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (fun (r : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_time_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_period sc))) r))) (holBind (L4vRefX64.Spec.Sporadic_A.refill_pop_head sc_ptr) (fun (old_head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.SchedContext_A.schedule_used sc_ptr (L4vRefX64.Spec.Structures_A.refill.r_time_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time old_head) (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_period sc))) old_head))))) (holKBind (holReturn (HolSub.subVal usage (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head))))))))))))) + +def head_refill_overrun {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (usage : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holOReturn (holConj (holLe (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head) usage) (holLt (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) L4vRefX64.Spec.Time.MAX_RELEASE_TIME))))))) + +def handle_overrun {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (usage : (BitVec 64)) => (holWhileLoop (fun (usage_1 : (BitVec 64)) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holTheOpt (L4vRefX64.Spec.SchedContext_A.head_refill_overrun sc_ptr usage_1 s)))) (fun (usage_1 : (BitVec 64)) => (L4vRefX64.Spec.SchedContext_A.charge_entire_head_refill sc_ptr usage_1)) usage))) + +def merge_nonoverlapping_head_refill {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.refill_pop_head sc_ptr) (fun (old_head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount old_head))) head))) (holKBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_time_update (fun (uu_ : (BitVec 64)) => (HolSub.subVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount old_head))) head)))))))) + +def refill_head_insufficient {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holOReturn (holLt (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head) L4vRefX64.Spec.Structures_A.MIN_BUDGET))))) + +def head_insufficient_loop {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holWhileLoop (fun (uu_ : Unit) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holTheOpt (L4vRefX64.Spec.SchedContext_A.refill_head_insufficient sc_ptr s)))) (fun (uu_ : Unit) => (L4vRefX64.Spec.SchedContext_A.merge_nonoverlapping_head_refill sc_ptr)) ())) + +def refill_budget_check {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (usage : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.is_round_robin sc_ptr) (fun (robin : Bool) => (holBind (holAssert (holNot robin)) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.handle_overrun sc_ptr usage) (fun (usage_p : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (holFunApp (holWhen (holConj (holLt (HolZero.zeroVal (α := (BitVec 64))) usage_p) (holLt (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) L4vRefX64.Spec.Time.MAX_RELEASE_TIME))) (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.refill_ext.mk (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_period sc)) usage_p ())) (fun (used : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (fun (r : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolSub.subVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head) usage_p)) r))) (holKBind (holBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (fun (r : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_time_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) usage_p)) r))) (holKBind (L4vRefX64.Spec.SchedContext_A.schedule_used sc_ptr used)))))))))) (holKBind (L4vRefX64.Spec.SchedContext_A.head_insufficient_loop sc_ptr)))))))))))))) + +def refill_budget_check_round_robin {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (usage : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (fun (refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolSub.subVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount refill) usage)) refill))) (holKBind (L4vRefX64.Spec.SchedContext_A.update_refill_tl sc_ptr (fun (refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount refill) usage)) refill)))))))) + +def commit_time {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (csc : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_active csc) (fun (active : Bool) => (holBind (holFunApp (holWhen (holConj active (holNot (holEq csc L4vRefX64.Spec.Machine_A.idle_sc_ptr)))) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.consumed_time) (fun (consumed : (BitVec 64)) => (holBind (holFunApp (holWhen (holLt (HolZero.zeroVal (α := (BitVec 64))) consumed)) (holBind (L4vRefX64.Spec.Sporadic_A.is_round_robin csc) (fun (robin : Bool) => (holIf robin (L4vRefX64.Spec.SchedContext_A.refill_budget_check_round_robin consumed) (L4vRefX64.Spec.SchedContext_A.refill_budget_check consumed))))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context csc (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (L4vRefX64.Spec.Structures_A.sched_context.sc_consumed_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_consumed sc) consumed)) sc)))))))) (holKBind (holModify (L4vRefX64.Spec.Structures_A.abstract_state.consumed_time_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64)))))))))))) + +def sched_context_cancel_yield_to {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_yield_to thread) (fun (yt_opt : (Option (BitVec 64))) => (holMaybeM (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_yield_from_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64)))))) (holKBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_yield_to_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64))))) thread)))) yt_opt)))) + +def sched_context_update_consumed {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_consumed sc)) (fun (consumed : (BitVec 64)) => (holIf (holLe L4vRefX64.Spec.Time.max_ticks_to_us consumed) (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_consumed_update (fun (uu_ : (BitVec 64)) => (HolSub.subVal consumed L4vRefX64.Spec.Time.max_ticks_to_us)))) (holKBind (holReturn (L4vRefX64.Spec.Time.ticks_to_us L4vRefX64.Spec.Time.max_ticks_to_us)))) (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_consumed_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64)))))) (holKBind (holReturn (L4vRefX64.Spec.Time.ticks_to_us (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_consumed sc))))))))))) + +def set_consumed {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_update_consumed sc_ptr) (fun (consumed : (BitVec 64)) => (L4vRefX64.Spec.TcbAcc_A.reply_from_kernel tcb_ptr (Prod.mk (HolZero.zeroVal (α := (BitVec 64))) (L4vRefX64.Spec.Arch_Structs_A.words_from_time consumed))))))) + +def complete_yield_to {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_yield_to tcb_ptr) (fun (yt_opt : (Option (BitVec 64))) => (holMaybeM (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.SchedContext_A.set_consumed sc_ptr tcb_ptr) (holKBind (L4vRefX64.Spec.SchedContext_A.sched_context_cancel_yield_to tcb_ptr)))) yt_opt)))) + +def max_refills_cap : (L4vRefX64.Spec.Structures_A.cap → Nat) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (HolZero.zeroVal (α := Nat)) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (HolZero.zeroVal (α := Nat)))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (HolZero.zeroVal (α := Nat))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (HolZero.zeroVal (α := Nat))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (HolZero.zeroVal (α := Nat)))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (HolZero.zeroVal (α := Nat))))) (fun (word : (BitVec 64)) => (HolZero.zeroVal (α := Nat))) (HolZero.zeroVal (α := Nat)) (fun (x : (BitVec 64)) => (fun (sz : Nat) => (L4vRefX64.Spec.Structures_A.max_num_refills (HolAdd.addVal (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat) sz)))) (HolZero.zeroVal (α := Nat)) (HolZero.zeroVal (α := Nat)) (fun (word : (BitVec 8)) => (HolZero.zeroVal (α := Nat))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (HolZero.zeroVal (α := Nat))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (HolZero.zeroVal (α := Nat))) cap)) + +def maybe_add_empty_tail {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.is_round_robin sc_ptr) (fun (robin : Bool) => (holFunApp (holWhen robin) (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.refill_ext.mk (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) (HolZero.zeroVal (α := (BitVec 64))) ())) (L4vRefX64.Spec.SchedContext_A.refill_add_tail sc_ptr)))))))) + +def read_ready_time {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (BitVec 64)))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holOReturn (L4vRefX64.Spec.Structures_A.refill_ext.r_time head))))) + +def read_tcb_ready_time {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option (BitVec 64)))) := + (fun (tcb_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.thread_read L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb_ptr) (fun (sc_ptr_opt : (Option (BitVec 64))) => (holOBind (holOAssert (holNot (holEq sc_ptr_opt (Option.none (α := (BitVec 64)))))) (fun (uu_ : Unit) => (L4vRefX64.Spec.SchedContext_A.read_ready_time (holTheOpt sc_ptr_opt))))))) + +def ready_times_append {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (qs : (List (BitVec 64))) => (L4vRefX64.Spec.IpcCancel_A.ordered_insert tptr qs L4vRefX64.Spec.SchedContext_A.read_tcb_ready_time holLe))) + +def tcb_release_enqueue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb_ptr : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.release_queue) (fun (q : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.SchedContext_A.ready_times_append tcb_ptr q) (fun (q_p : (List (BitVec 64))) => (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.release_queue_update (fun (uu_ : (List (BitVec 64))) => q_p) s))) (holKBind (holWhen (holDisj (holEq q (List.nil (α := (BitVec 64)))) (holNot (holEq (holHd q_p) (holHd q)))) (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true) s))))))))))) + +def postpone {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc_ptr) (fun (tcb_opt : (Option (BitVec 64))) => (holBind (holAssertOpt tcb_opt) (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.tcb_release_enqueue tcb_ptr) (holKBind (holModify (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true)))))))))))) + +def sched_context_resume {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holFunApp holAssertOpt (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc)) (fun (tptr : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tptr)) (fun (sched : Bool) => (holFunApp (holWhen sched) (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_state tptr) (fun (ts : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_ready sc_ptr) (fun (ready : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_sufficient sc_ptr (HolZero.zeroVal (α := (BitVec 64)))) (fun (sufficient : Bool) => (holFunApp (holWhen (holConj (L4vRefX64.Spec.Structures_A.runnable ts) (holConj (L4vRefX64.Spec.KHeap_A.active_sc (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refill_max sc)) (holNot (holConj ready sufficient))))) (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_domain tptr) (fun (d : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority tptr) (fun (prio : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_queue d prio) (fun (queue : (List (BitVec 64))) => (holBind (holAssert (holNot (holMember tptr (holListSet queue)))) (holKBind (L4vRefX64.Spec.SchedContext_A.postpone sc_ptr)))))))))))))))))))))))) + +def maybe_donate_sc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tcb_ptr : (BitVec 64)) => (fun (ntfn_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb_ptr) (fun (sc_opt : (Option (BitVec 64))) => (holFunApp (holWhen (holEq sc_opt (Option.none (α := (BitVec 64))))) (holBind (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification_ext.ntfn_sc ntfn_ptr) (holMaybeM (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc_ptr) (fun (sc_tcb : (Option (BitVec 64))) => (holFunApp (holWhen (holEq sc_tcb (Option.none (α := (BitVec 64))))) (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_donate sc_ptr tcb_ptr) (holKBind (L4vRefX64.Spec.SchedContext_A.sched_context_resume sc_ptr)))))))))))))) + +def maybe_return_sc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ntfn_ptr : (BitVec 64)) => (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification_ext.ntfn_sc ntfn_ptr) (fun (nsc_opt : (Option (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb_ptr) (fun (tsc_opt : (Option (BitVec 64))) => (holFunApp (holWhen (holConj (holEq nsc_opt tsc_opt) (holNot (holEq nsc_opt (Option.none (α := (BitVec 64))))))) (holBind (holAssertOpt nsc_opt) (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_sched_context_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64))))) tcb_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_tcb_update (fun (uu_ : (Option (BitVec 64))) => (Option.none (α := (BitVec 64)))))) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct : (BitVec 64)) => (holWhen (holEq tcb_ptr ct) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))))))))))))) + +def refill_new {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Nat → ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (sc_ptr : (BitVec 64)) => (fun (max_refills : Nat) => (fun (budget : (BitVec 64)) => (fun (period : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_time) (fun (cur_time : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_period_update (fun (uu_ : (BitVec 64)) => period))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_budget_update (fun (uu_ : (BitVec 64)) => budget))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refill_max_update (fun (uu_ : Nat) => max_refills))) (holKBind (holBind (holReturn (L4vRefX64.Spec.Structures_A.refill_ext.mk cur_time budget ())) (fun (refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (uu_ : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (List.cons refill (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit))))))) (holKBind (L4vRefX64.Spec.SchedContext_A.maybe_add_empty_tail sc_ptr))))))))))))))))) + +def refills_sum : ((List (L4vRefX64.Spec.Structures_A.refill_ext Unit)) → (BitVec 64)) := + (fun (rf : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (holSumList (holListMap L4vRefX64.Spec.Structures_A.refill_ext.r_amount rf))) + +def refill_sum {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refills sc_ptr) (fun (refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (holFunApp holReturn (L4vRefX64.Spec.SchedContext_A.refills_sum refills))))) + +def refill_update {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((BitVec 64) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (sc_ptr : (BitVec 64)) => (fun (new_period : (BitVec 64)) => (fun (new_budget : (BitVec 64)) => (fun (new_max_refills : Nat) => (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (rfs : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (List.cons (holHd rfs) (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit))))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refill_max_update (fun (uu_ : Nat) => new_max_refills))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_period_update (fun (uu_ : (BitVec 64)) => new_period))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_budget_update (fun (uu_ : (BitVec 64)) => new_budget))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_ready sc_ptr) (fun (ready : Bool) => (holBind (holFunApp (holWhen ready) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_time) (fun (cur_time : (BitVec 64)) => (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (L4vRefX64.Spec.Structures_A.refill.r_time_update (fun (uu_ : (BitVec 64)) => cur_time)))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holIf (holLe new_budget (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head)) (holBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (L4vRefX64.Spec.Structures_A.refill.r_amount_update (fun (uu_ : (BitVec 64)) => new_budget))) (holKBind (L4vRefX64.Spec.SchedContext_A.maybe_add_empty_tail sc_ptr))) (holBind (holFunApp holReturn (HolSub.subVal new_budget (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head))) (fun (unused : (BitVec 64)) => (holBind (holReturn (L4vRefX64.Spec.Structures_A.refill_ext.mk (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time head) new_period) unused ())) (L4vRefX64.Spec.SchedContext_A.refill_add_tail sc_ptr))))))))))))))))))))))) + +def return_consumed {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_update_consumed sc_ptr) (fun (consumed : (BitVec 64)) => (holFunApp holReturn (L4vRefX64.Spec.Arch_Structs_A.words_from_time consumed))))) + +def sched_context_bind_tcb {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_sched_context_update (fun (uu_ : (Option (BitVec 64))) => (Option.some sc_ptr))) tcb_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_tcb_update (fun (uu_ : (Option (BitVec 64))) => (Option.some tcb_ptr)))) (holKBind (holBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check (Option.some sc_ptr) (Option.some true) (Option.some false)) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_resume sc_ptr) (holKBind (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tcb_ptr)) (fun (sched : Bool) => (holFunApp (holWhen sched) (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue tcb_ptr) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))))))))))))) + +def sched_context_set_inactive {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (uu_ : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit)))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refill_max_update (fun (uu_ : Nat) => (HolZero.zeroVal (α := Nat))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_budget_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64)))))) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_sporadic_update (fun (uu_ : Bool) => false)))))))))) + +def sched_context_unbind_yield_from {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holMaybeM L4vRefX64.Spec.SchedContext_A.complete_yield_to (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_yield_from sc))))) + +def set_refill_hd {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (new : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (fun (uu_ : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => new)))) + +def set_refill_tl {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (new : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.SchedContext_A.update_refill_tl sc_ptr (fun (uu_ : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => new)))) + +def set_refills {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((List (L4vRefX64.Spec.Structures_A.refill_ext Unit)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (uu_ : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => refills))))) + +def update_restart_pc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread_ptr : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.as_user thread_ptr (holBind (L4vRefX64.Spec.MachineOps.getRegister L4vRefX64.Spec.MachineTypes.nextInstructionRegister) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.MachineTypes.faultRegister)))) + +def suspend {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.cancel_ipc thread) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state thread) (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (holFunApp (holWhen (holEq state L4vRefX64.Spec.Structures_A.thread_state.Running)) (L4vRefX64.Spec.SchedContext_A.update_restart_pc thread)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue thread) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_release_remove thread) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_cancel_yield_to thread) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state thread L4vRefX64.Spec.Structures_A.thread_state.Inactive)))))))))))))) + +def test_possible_switch_to {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb_ptr : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tcb_ptr)) (fun (sched : Bool) => (holFunApp (holWhen sched) (L4vRefX64.Spec.KHeap_A.possible_switch_to tcb_ptr))))) + +def unbind_from_sc {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context tcb_ptr) (fun (sc_ptr_opt : (Option (BitVec 64))) => (holBind (holMaybeM L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_tcb sc_ptr_opt) (holKBind (holMaybeM (fun (scptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context scptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holMaybeM L4vRefX64.Spec.SchedContext_A.complete_yield_to (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_yield_from sc))))) sc_ptr_opt)))))) +end +end L4vRefX64.Spec.SchedContext_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Schedule_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Schedule_A.lean new file mode 100644 index 000000000..4bf3e28d7 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Schedule_A.lean @@ -0,0 +1,102 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Schedule_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Arch_Structs_B +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.Kernel_Config +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.SchedContext_A +import L4vRefX64.Spec.Sporadic_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Schedule_A +open L4vRefX64.Prim +open Classical +noncomputable section +def read_tcb_refill_ready {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool))) := + (fun (t : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context t) (fun (sc_opt : (Option (BitVec 64))) => (holOBind (holOAssertOpt sc_opt) (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_sc_refill_ready sc_ptr) holOReturn)))))) + +def read_release_q_non_empty_and_ready {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool)) := + (holOBind (holAsks L4vRefX64.Spec.Structures_A.abstract_state_ext.release_queue) (fun (rq : (List (BitVec 64))) => (holIf (holEq rq (List.nil (α := (BitVec 64)))) (holOReturn false) (L4vRefX64.Spec.Schedule_A.read_tcb_refill_ready (holHd rq))))) + +def tcb_release_dequeue {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.release_queue) (fun (rq : (List (BitVec 64))) => (holBind (holAssert (holNot (holEq rq (List.nil (α := (BitVec 64)))))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_release_remove (holHd rq)) (holKBind (L4vRefX64.Spec.KHeap_A.possible_switch_to (holHd rq)))))))) + +def awaken {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holWhileLoop (fun (r : Unit) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holTheOpt (L4vRefX64.Spec.Schedule_A.read_release_q_non_empty_and_ready s)))) (fun (uu_ : Unit) => L4vRefX64.Spec.Schedule_A.tcb_release_dequeue) ()) + +def check_domain_time {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.KHeap_A.is_cur_domain_expired) (fun (exp : Bool) => (holFunApp (holWhen exp) (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true) s))) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))) + +def switch_to_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (t : (BitVec 64)) => (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (state : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holBind (holAssert (holNot (holEq (L4vRefX64.Spec.KHeap_A.get_tcb t state) (Option.none (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))))) (holKBind (holBind (L4vRefX64.Spec.Arch_A.arch_switch_to_thread t) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue t) (holKBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.cur_thread_update (fun (uu_ : (BitVec 64)) => t) s)))))))))))) + +def guarded_switch_to {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context thread) (fun (sc_opt : (Option (BitVec 64))) => (holBind (holAssertOpt sc_opt) (fun (scp : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable thread)) (fun (sched : Bool) => (holBind (holAssert sched) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_domain) (fun (d : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_domain thread) (fun (next_domain : (BitVec 8)) => (holBind (holAssert (holEq next_domain d)) (holKBind (L4vRefX64.Spec.Schedule_A.switch_to_thread thread)))))))))))))))) + +def max_non_empty_queue : (((BitVec 8) → (List (BitVec 64))) → (List (BitVec 64))) := + (fun (queues : ((BitVec 8) → (List (BitVec 64)))) => (queues (holMax (holCollect (fun (prio : (BitVec 8)) => (holNot (holEq (queues prio) (List.nil (α := (BitVec 64)))))))))) + +def switch_to_idle_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.idle_thread) (fun (thread : (BitVec 64)) => (holBind L4vRefX64.Spec.Arch_A.arch_switch_to_idle_thread (holKBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.cur_thread_update (fun (uu_ : (BitVec 64)) => thread) s))))))) + +def choose_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_domain) (fun (d : (BitVec 8)) => (holBind (holGets (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state_ext.ready_queues s d))) (fun (queues : ((BitVec 8) → (List (BitVec 64)))) => (holIf (holAll (fun (prio : (BitVec 8)) => (holEq (queues prio) (List.nil (α := (BitVec 64)))))) L4vRefX64.Spec.Schedule_A.switch_to_idle_thread (L4vRefX64.Spec.Schedule_A.guarded_switch_to (holHd (L4vRefX64.Spec.Schedule_A.max_non_empty_queue queues)))))))) + +def dec_domain_time {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.domain_time_update (fun (uu_ : (BitVec 64)) => (HolSub.subVal (L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_time s) (HolOne.oneVal (α := (BitVec 64))))) s))) + +def domain_end_marker : ((BitVec 8) × (BitVec 56)) := + (Prod.mk (HolZero.zeroVal (α := (BitVec 8))) (HolZero.zeroVal (α := (BitVec 56)))) + +def domain_schedule_configure {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Nat → ((BitVec 8) → ((BitVec 56) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (index : Nat) => (fun (domain : (BitVec 8)) => (fun (duration : (BitVec 56)) => (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.domain_list_update (fun (uu_ : (List ((BitVec 8) × (BitVec 56)))) => (holListUpdate (L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_list s) index (Prod.mk domain duration))) s)))))) + +def domain_set_start {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (index : Nat) => (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.domain_start_index_update (fun (uu_ : Nat) => index) s))) (holKBind (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.domain_time_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64)))) s))) (holKBind (holBind (holGets (holComp holSize L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_list)) (fun (domain_list_len : Nat) => (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.domain_index_update (fun (uu_ : Nat) => (HolSub.subVal domain_list_len (HolNumeral.ofNatVal (α := Nat) 2))) s))) (holKBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))))))) + +def idle : (L4vRefX64.Spec.Structures_A.thread_state → Bool) := + (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holEq st L4vRefX64.Spec.Structures_A.thread_state.IdleThreadState)) + +def sched_context_yield_to {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_yield_from sc_ptr) (fun (sc_yf_opt : (Option (BitVec 64))) => (holBind (holFunApp (holWhen (holNot (holEq sc_yf_opt (Option.none (α := (BitVec 64)))))) (holBind (L4vRefX64.Spec.SchedContext_A.complete_yield_to (holTheOpt sc_yf_opt)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_yield_from sc_ptr) (fun (sc_yf_opt_1 : (Option (BitVec 64))) => (holAssert (holEq sc_yf_opt_1 (Option.none (α := (BitVec 64)))))))))) (holKBind (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_resume sc_ptr) (holKBind (holBind (holBind (L4vRefX64.Spec.KHeap_A.get_sc_obj_ref L4vRefX64.Spec.Structures_A.sched_context_ext.sc_tcb sc_ptr) (fun (sc_tcb_opt : (Option (BitVec 64))) => (holBind (holAssertOpt sc_tcb_opt) (fun (tcb_ptr : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tcb_ptr)) (fun (schedulable : Bool) => (holIf schedulable (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority tcb_ptr) (fun (prios : (BitVec 8)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority ct_ptr) (fun (ct_prios : (BitVec 8)) => (holIf (holLt prios ct_prios) (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue tcb_ptr) (holKBind (holReturn true))))) (holBind (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_yield_to_update (fun (uu_ : (Option (BitVec 64))) => (Option.some sc_ptr))) ct_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_yield_from_update (fun (uu_ : (Option (BitVec 64))) => (Option.some ct_ptr)))) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tcb_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue ct_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue tcb_ptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holKBind (holReturn false)))))))))))))))))))) (holReturn true)))))))) (fun (return_now : Bool) => (holIf return_now (L4vRefX64.Spec.SchedContext_A.return_consumed sc_ptr) (holReturn (List.nil (α := (BitVec 64)))))))))))))) + +def invoke_sched_context {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.sched_context_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (iv : L4vRefX64.Spec.Invocations_A.sched_context_invocation) => (L4vRefX64.Spec.Invocations_A.case_sched_context_invocation (fun (sc_ptr : (BitVec 64)) => (L4vRefX64.Spec.SchedContext_A.return_consumed sc_ptr)) (fun (sc_ptr : (BitVec 64)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (ntfn : (BitVec 64)) => (fun (x : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_bind_ntfn sc_ptr ntfn) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (tcb_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.SchedContext_A.sched_context_bind_tcb sc_ptr tcb_ptr) (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) cap))) (fun (sc_ptr : (BitVec 64)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (x : (BitVec 64)) => (fun (xa : (BitVec 64)) => (fun (xb : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_ntfn sc_ptr) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (x : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_tcb sc_ptr) (holKBind (holReturn (List.nil (α := (BitVec 64))))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (word : (BitVec 8)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) cap))) (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_all_tcbs sc_ptr) (holKBind (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_ntfn sc_ptr) (holKBind (holBind (L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_reply sc_ptr) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))))) (fun (sc_ptr : (BitVec 64)) => (L4vRefX64.Spec.Schedule_A.sched_context_yield_to sc_ptr)) iv)) + +def is_highest_prio {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 8) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → Bool))) := + (fun (d : (BitVec 8)) => (fun (p : (BitVec 8)) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holDisj (holAll (fun (prio : (BitVec 8)) => (holEq (L4vRefX64.Spec.Structures_A.abstract_state_ext.ready_queues s d prio) (List.nil (α := (BitVec 64)))))) (holLe (holMax (holCollect (fun (prio : (BitVec 8)) => (holNot (holEq (L4vRefX64.Spec.Structures_A.abstract_state_ext.ready_queues s d prio) (List.nil (α := (BitVec 64)))))))) p))))) + +def next_domain {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holLet (HolAdd.addVal (L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_index s) (HolOne.oneVal (α := Nat))) (fun (index_inc : Nat) => (holLet (holIf (holEq (holNth (L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_list s) index_inc) L4vRefX64.Spec.Schedule_A.domain_end_marker) (L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_start_index s) index_inc) (fun (index_p : Nat) => (holLet (holNth (L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_list s) index_p) (fun (dom_entry : ((BitVec 8) × (BitVec 56))) => (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true) (L4vRefX64.Spec.Structures_A.abstract_state.domain_time_update (fun (uu_ : (BitVec 64)) => ((holUcast (w := 64)) (Prod.snd dom_entry))) (L4vRefX64.Spec.Structures_A.abstract_state.cur_domain_update (fun (uu_ : (BitVec 8)) => (Prod.fst dom_entry)) (L4vRefX64.Spec.Structures_A.abstract_state.domain_index_update (fun (uu_ : Nat) => index_p) s)))))))))))) (holKBind (holFunApp L4vRefX64.Spec.Deterministic_A.do_extended_op (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext (L4vRefX64.Spec.Deterministic_A.det_ext_ext Unit) Unit))) => (L4vRefX64.Spec.Deterministic_A.trans_state (L4vRefX64.Spec.Deterministic_A.det_ext.work_units_completed_internal_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64))))) s)))))) + +def set_next_interrupt {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_time) (fun (cur_tm : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur_th : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context cur_th) (fun (sc_opt : (Option (BitVec 64))) => (holBind (holAssertOpt sc_opt) (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head sc_ptr) (fun (ct_head_refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (holFunApp holReturn (HolAdd.addVal cur_tm (L4vRefX64.Spec.Structures_A.refill_ext.r_amount ct_head_refill))) (fun (next_interrupt : (BitVec 64)) => (holBind (holIf (holLt (HolOne.oneVal (α := Nat)) L4vRefX64.Spec.Kernel_Config.numDomains) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_time) (fun (domain_tm : (BitVec 64)) => (holFunApp holReturn (holMin next_interrupt (HolAdd.addVal cur_tm domain_tm))))) (holReturn next_interrupt)) (fun (next_interrupt_1 : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.release_queue) (fun (rq : (List (BitVec 64))) => (holBind (holIf (holEq rq (List.nil (α := (BitVec 64)))) (holReturn next_interrupt_1) (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context (holHd rq)) (fun (rqsc_opt : (Option (BitVec 64))) => (holBind (holAssertOpt rqsc_opt) (fun (rqsc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head rqsc_ptr) (fun (rlq_head_refill : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holFunApp holReturn (holMin (L4vRefX64.Spec.Structures_A.refill_ext.r_time rlq_head_refill) next_interrupt_1))))))))) (fun (next_interrupt_2 : (BitVec 64)) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.setDeadline (HolSub.subVal next_interrupt_2 L4vRefX64.Spec.Arch_Structs_B.timerPrecision))))))))))))))))))))) + +def switch_sched_context {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (cur_sc : (BitVec 64)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur_th : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context cur_th) (fun (sc_opt : (Option (BitVec 64))) => (holBind (holAssertOpt sc_opt) (fun (scp : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context cur_sc) (fun (sc_p : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holFunApp (holWhen (holNot (holEq scp cur_sc))) (holBind (holModify (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true))) (holKBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check (Option.some scp) (Option.none (α := Bool)) (Option.none (α := Bool)))))) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.reprogram_timer) (fun (reprogram : Bool) => (holBind (holFunApp (holWhen reprogram) L4vRefX64.Spec.SchedContext_A.commit_time) (holKBind (holModify (L4vRefX64.Spec.Structures_A.abstract_state.cur_sc_update (fun (uu_ : (BitVec 64)) => scp))))))))))))))))))) + +def sc_and_timer {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind L4vRefX64.Spec.Schedule_A.switch_sched_context (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.reprogram_timer) (fun (reprogram : Bool) => (holFunApp (holWhen reprogram) (holBind L4vRefX64.Spec.Schedule_A.set_next_interrupt (holKBind (holModify (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => false)))))))))) + +def schedule_choose_new_thread {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.domain_time) (fun (dom_time : (BitVec 64)) => (holBind (holFunApp (holWhen (holEq dom_time (HolZero.zeroVal (α := (BitVec 64))))) (holBind L4vRefX64.Spec.Arch_A.arch_prepare_next_domain (holKBind L4vRefX64.Spec.Schedule_A.next_domain))) (holKBind (holBind L4vRefX64.Spec.Schedule_A.choose_thread (holKBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.resume_cur_thread))))))) + +def schedule_switch_thread_fastfail {tv_b : Type} [Nonempty tv_b] {tv_c : Type} [Nonempty tv_c] [HolOrd tv_c] {tv_a : Type} [Nonempty tv_a] : (tv_b → (tv_b → (tv_c → (tv_c → (tv_a → ((Set (Bool × tv_a)) × Bool)))))) := + (fun (ct : tv_b) => (fun (it : tv_b) => (fun (ct_prio : tv_c) => (fun (target_prio : tv_c) => (holFunApp holReturn (holImp (holNot (holEq ct it)) (holLt target_prio ct_prio))))))) + +def schedule {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)) := + (holBind L4vRefX64.Spec.Schedule_A.awaken (holKBind (holBind L4vRefX64.Spec.Schedule_A.check_domain_time (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable ct)) (fun (ct_schdble : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.scheduler_action) (fun (action : L4vRefX64.Spec.Structures_A.scheduler_action) => (holBind (L4vRefX64.Spec.Structures_A.case_scheduler_action (holReturn ()) (fun (candidate : (BitVec 64)) => (holBind (holWhen ct_schdble (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue ct)) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.idle_thread) (fun (it : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority candidate) (fun (target_prio : (BitVec 8)) => (holBind (holIf (holNot (holEq ct it)) (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority ct) (holReturn (HolZero.zeroVal (α := (BitVec 8))))) (fun (ct_prio : (BitVec 8)) => (holBind (L4vRefX64.Spec.Schedule_A.schedule_switch_thread_fastfail ct it ct_prio target_prio) (fun (fastfail : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_domain) (fun (cur_dom : (BitVec 8)) => (holBind (holGets (L4vRefX64.Spec.Schedule_A.is_highest_prio cur_dom target_prio)) (fun (highest : Bool) => (holIf (holConj fastfail (holNot highest)) (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue candidate) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.choose_new_thread) (holKBind L4vRefX64.Spec.Schedule_A.schedule_choose_new_thread)))) (holIf (holConj ct_schdble (holEq ct_prio target_prio)) (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_append candidate) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.choose_new_thread) (holKBind L4vRefX64.Spec.Schedule_A.schedule_choose_new_thread)))) (holBind (L4vRefX64.Spec.Schedule_A.guarded_switch_to candidate) (holKBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.resume_cur_thread)))))))))))))))))))) (holBind (holWhen ct_schdble (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue ct)) (holKBind L4vRefX64.Spec.Schedule_A.schedule_choose_new_thread)) action) (holKBind L4vRefX64.Spec.Schedule_A.sc_and_timer)))))))))))) + +def schedule_switch_thread_branch {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (candidate : (BitVec 64)) => (fun (ct : (BitVec 64)) => (fun (ct_schdble : Bool) => (holBind (holWhen ct_schdble (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue ct)) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.idle_thread) (fun (it : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority candidate) (fun (target_prio : (BitVec 8)) => (holBind (holIf (holNotEq ct it) (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_priority ct) (holReturn (HolZero.zeroVal (α := (BitVec 8))))) (fun (ct_prio : (BitVec 8)) => (holBind (L4vRefX64.Spec.Schedule_A.schedule_switch_thread_fastfail ct it ct_prio target_prio) (fun (fastfail : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_domain) (fun (cur_dom : (BitVec 8)) => (holBind (holGets (L4vRefX64.Spec.Schedule_A.is_highest_prio cur_dom target_prio)) (fun (highest : Bool) => (holIf (holConj fastfail (holNot highest)) (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue candidate) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.choose_new_thread) (holKBind L4vRefX64.Spec.Schedule_A.schedule_choose_new_thread)))) (holIf (holConj ct_schdble (holEq ct_prio target_prio)) (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_append candidate) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.choose_new_thread) (holKBind L4vRefX64.Spec.Schedule_A.schedule_choose_new_thread)))) (holBind (L4vRefX64.Spec.Schedule_A.guarded_switch_to candidate) (holKBind (L4vRefX64.Spec.KHeap_A.set_scheduler_action L4vRefX64.Spec.Structures_A.scheduler_action.resume_cur_thread)))))))))))))))))))))) +end +end L4vRefX64.Spec.Schedule_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Sporadic_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Sporadic_A.lean new file mode 100644 index 000000000..32c1c87e2 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Sporadic_A.lean @@ -0,0 +1,63 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Sporadic_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Sporadic_A +open L4vRefX64.Prim +open Classical +noncomputable section +def can_merge_refill {tv_a : Type} [Nonempty tv_a] {tv_b : Type} [Nonempty tv_b] : ((L4vRefX64.Spec.Structures_A.refill_ext tv_a) → ((L4vRefX64.Spec.Structures_A.refill_ext tv_b) → Bool)) := + (fun (r1 : (L4vRefX64.Spec.Structures_A.refill_ext tv_a)) => (fun (r2 : (L4vRefX64.Spec.Structures_A.refill_ext tv_b)) => (holLe (L4vRefX64.Spec.Structures_A.refill_ext.r_time r2) (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time r1) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount r1))))) + +def is_round_robin {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Bool × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holReturn (holEq (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_period sc) (HolZero.zeroVal (α := (BitVec 64)))))))) + +def merge_refill : ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → (L4vRefX64.Spec.Structures_A.refill_ext Unit))) := + (fun (r1 : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (fun (r2 : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Structures_A.refill_ext.mk (L4vRefX64.Spec.Structures_A.refill_ext.r_time r1) (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_amount r2) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount r1)) ()))) + +def refill_pop_head {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.refill_ext Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update holTl)) (holKBind (holReturn head)))))) + +def update_refill_hd {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((L4vRefX64.Spec.Structures_A.refill_ext Unit) → (L4vRefX64.Spec.Structures_A.refill_ext Unit)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (sc_ptr : (BitVec 64)) => (fun (f : ((L4vRefX64.Spec.Structures_A.refill_ext Unit) → (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (L4vRefX64.Spec.KHeap_A.update_sched_context sc_ptr (L4vRefX64.Spec.Structures_A.sched_context.sc_refills_update (fun (refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) => (List.cons (f (holHd refills)) (holTl refills))))))) + +def merge_overlapping_refills {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.refill_pop_head sc_ptr) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (L4vRefX64.Spec.Sporadic_A.merge_refill head))))) + +def refill_head_overlapping {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → (Option Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holOBind (L4vRefX64.Spec.KHeap_A.read_sched_context sc_ptr) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holOReturn (holConj (holLt (HolOne.oneVal (α := Nat)) (holSize (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc))) (holLe (L4vRefX64.Spec.Structures_A.refill_ext.r_time (holHd (holTl (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc)))) (HolAdd.addVal (L4vRefX64.Spec.Structures_A.refill_ext.r_time (holHd (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc))) (L4vRefX64.Spec.Structures_A.refill_ext.r_amount (holHd (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refills sc)))))))))) + +def refill_head_overlapping_loop {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holWhileLoop (fun (uu_ : Unit) => (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holTheOpt (L4vRefX64.Spec.Sporadic_A.refill_head_overlapping sc_ptr s)))) (fun (uu_ : Unit) => (L4vRefX64.Spec.Sporadic_A.merge_overlapping_refills sc_ptr)) ())) + +def refill_unblock_check {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (sc_ptr : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.is_round_robin sc_ptr) (fun (robin : Bool) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_refill_ready sc_ptr) (fun (ready : Bool) => (holFunApp (holWhen (holConj ready (holNot robin))) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_time) (fun (ct : (BitVec 64)) => (holBind (L4vRefX64.Spec.Sporadic_A.update_refill_hd sc_ptr (L4vRefX64.Spec.Structures_A.refill.r_time_update (fun (uu_ : (BitVec 64)) => ct))) (holKBind (holBind (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.reprogram_timer_update (fun (uu_ : Bool) => true) s))) (holKBind (L4vRefX64.Spec.Sporadic_A.refill_head_overlapping_loop sc_ptr))))))))))))) + +def if_cond_refill_unblock_check {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((Option (BitVec 64)) → ((Option Bool) → ((Option Bool) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))))) := + (fun (sc_opt : (Option (BitVec 64))) => (fun (active : (Option Bool)) => (fun (asst : (Option Bool)) => (holMaybeM (fun (scp : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context scp) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (cur_sc_ptr : (BitVec 64)) => (holBind (holReturn (holCaseOption (holNot (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_sporadic sc)) (fun (a : Bool) => (holCaseBool (holConj (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_sporadic sc) (L4vRefX64.Spec.KHeap_A.active_sc (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_refill_max sc))) (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_sporadic sc) a)) active)) (fun (guard : Bool) => (holFunApp (holWhen (holConj guard (holImp (holEq asst (Option.some false)) (holNot (holEq scp cur_sc_ptr))))) (holFunApp (holWhen (holImp (holEq asst (Option.some true)) (holNot (holEq scp cur_sc_ptr)))) (L4vRefX64.Spec.Sporadic_A.refill_unblock_check scp)))))))))) sc_opt)))) + +def if_constant_bandwidth_refill_unblock_check {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (sc_opt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.none (α := Bool)) (Option.none (α := Bool)))) + +def if_sporadic_active_cur_sc_assert_refill_unblock_check {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (sc_opt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some true) (Option.some true))) + +def if_sporadic_active_cur_sc_test_refill_unblock_check {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (sc_opt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some true) (Option.some false))) + +def if_sporadic_and_active_refill_unblock_check {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (sc_opt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some true) (Option.none (α := Bool)))) + +def if_sporadic_cur_sc_assert_refill_unblock_check {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (sc_opt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some false) (Option.some true))) + +def if_sporadic_cur_sc_test_refill_unblock_check {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((Option (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool))) := + (fun (sc_opt : (Option (BitVec 64))) => (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some false) (Option.some false))) +end +end L4vRefX64.Spec.Sporadic_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Structs_B.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Structs_B.lean new file mode 100644 index 000000000..7dcf3d588 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Structs_B.lean @@ -0,0 +1,27 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.Structs_B) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Kernel_Config + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Structs_B +open L4vRefX64.Prim +open Classical +noncomputable section +inductive tcb_flag where + | FpuDisabled +instance : Nonempty tcb_flag := ⟨tcb_flag.FpuDisabled⟩ +def case_tcb_flag {r_ty : Type} (f0 : r_ty) : tcb_flag → r_ty + | .FpuDisabled => f0 + +def tcbFlagToWord : (L4vRefX64.Spec.Structs_B.tcb_flag → (BitVec 64)) := + (fun (x0 : L4vRefX64.Spec.Structs_B.tcb_flag) => (L4vRefX64.Spec.Structs_B.case_tcb_flag ((holHaskellBit (w := 64)) (HolZero.zeroVal (α := Nat))) x0)) + +def tcbFlagMask : (BitVec 64) := + (holIf L4vRefX64.Spec.Kernel_Config.config_HAVE_FPU (L4vRefX64.Spec.Structs_B.tcbFlagToWord L4vRefX64.Spec.Structs_B.tcb_flag.FpuDisabled) (HolZero.zeroVal (α := (BitVec 64)))) + +def timeArgLen : Nat := + (HolDiv.divVal (64 : Nat) (64 : Nat)) +end +end L4vRefX64.Spec.Structs_B diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Structures_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Structures_A.lean new file mode 100644 index 000000000..1b929a5f7 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Structures_A.lean @@ -0,0 +1,790 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Structures_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Kernel_Config_Lemmas +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Time + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Structures_A +open L4vRefX64.Prim +open Classical +noncomputable section +inductive a_type_T where + | ATCB + | AEndpoint + | ANTFN + | ASchedContext (a0 : Nat) + | AReply + | ACapTable (a0 : Nat) + | AGarbage (a0 : Nat) + | AArch (a0 : L4vRefX64.Spec.Arch_Structs_A.aa_type_T) +instance : Nonempty a_type_T := ⟨a_type_T.ATCB⟩ +def case_a_type {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : Nat → r_ty) (f4 : r_ty) (f5 : Nat → r_ty) (f6 : Nat → r_ty) (f7 : L4vRefX64.Spec.Arch_Structs_A.aa_type_T → r_ty) : a_type_T → r_ty + | .ATCB => f0 + | .AEndpoint => f1 + | .ANTFN => f2 + | .ASchedContext x0 => f3 x0 + | .AReply => f4 + | .ACapTable x0 => f5 x0 + | .AGarbage x0 => f6 x0 + | .AArch x0 => f7 x0 + +inductive irq_state where + | IRQInactive + | IRQSignal + | IRQTimer + | IRQReserved +instance : Nonempty irq_state := ⟨irq_state.IRQInactive⟩ +def case_irq_state {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) : irq_state → r_ty + | .IRQInactive => f0 + | .IRQSignal => f1 + | .IRQTimer => f2 + | .IRQReserved => f3 + +inductive cap where + | NullCap + | UntypedCap (a0 : Bool) (a1 : (BitVec 64)) (a2 : Nat) (a3 : Nat) + | EndpointCap (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) + | NotificationCap (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : (Set L4vRefX64.Spec.CapRights_A.rights)) + | ReplyCap (a0 : (BitVec 64)) (a1 : (Set L4vRefX64.Spec.CapRights_A.rights)) + | CNodeCap (a0 : (BitVec 64)) (a1 : Nat) (a2 : (List Bool)) + | ThreadCap (a0 : (BitVec 64)) + | DomainCap + | SchedContextCap (a0 : (BitVec 64)) (a1 : Nat) + | SchedControlCap + | IRQControlCap + | IRQHandlerCap (a0 : (BitVec 8)) + | Zombie (a0 : (BitVec 64)) (a1 : (Option Nat)) (a2 : Nat) + | ArchObjectCap (a0 : L4vRefX64.Spec.Arch_Structs_A.arch_cap) +instance : Nonempty cap := ⟨cap.NullCap⟩ +def case_cap {r_ty : Type} (f0 : r_ty) (f1 : Bool → (BitVec 64) → Nat → Nat → r_ty) (f2 : (BitVec 64) → (BitVec 64) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) (f3 : (BitVec 64) → (BitVec 64) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) (f4 : (BitVec 64) → (Set L4vRefX64.Spec.CapRights_A.rights) → r_ty) (f5 : (BitVec 64) → Nat → (List Bool) → r_ty) (f6 : (BitVec 64) → r_ty) (f7 : r_ty) (f8 : (BitVec 64) → Nat → r_ty) (f9 : r_ty) (f10 : r_ty) (f11 : (BitVec 8) → r_ty) (f12 : (BitVec 64) → (Option Nat) → Nat → r_ty) (f13 : L4vRefX64.Spec.Arch_Structs_A.arch_cap → r_ty) : cap → r_ty + | .NullCap => f0 + | .UntypedCap x0 x1 x2 x3 => f1 x0 x1 x2 x3 + | .EndpointCap x0 x1 x2 => f2 x0 x1 x2 + | .NotificationCap x0 x1 x2 => f3 x0 x1 x2 + | .ReplyCap x0 x1 => f4 x0 x1 + | .CNodeCap x0 x1 x2 => f5 x0 x1 x2 + | .ThreadCap x0 => f6 x0 + | .DomainCap => f7 + | .SchedContextCap x0 x1 => f8 x0 x1 + | .SchedControlCap => f9 + | .IRQControlCap => f10 + | .IRQHandlerCap x0 => f11 x0 + | .Zombie x0 x1 x2 => f12 x0 x1 x2 + | .ArchObjectCap x0 => f13 x0 + +inductive endpoint where + | IdleEP + | SendEP (a0 : (List (BitVec 64))) + | RecvEP (a0 : (List (BitVec 64))) +instance : Nonempty endpoint := ⟨endpoint.IdleEP⟩ +def case_endpoint {r_ty : Type} (f0 : r_ty) (f1 : (List (BitVec 64)) → r_ty) (f2 : (List (BitVec 64)) → r_ty) : endpoint → r_ty + | .IdleEP => f0 + | .SendEP x0 => f1 x0 + | .RecvEP x0 => f2 x0 + +inductive ntfn where + | IdleNtfn + | WaitingNtfn (a0 : (List (BitVec 64))) + | ActiveNtfn (a0 : (BitVec 64)) +instance : Nonempty ntfn := ⟨ntfn.IdleNtfn⟩ +def case_ntfn {r_ty : Type} (f0 : r_ty) (f1 : (List (BitVec 64)) → r_ty) (f2 : (BitVec 64) → r_ty) : ntfn → r_ty + | .IdleNtfn => f0 + | .WaitingNtfn x0 => f1 x0 + | .ActiveNtfn x0 => f2 x0 + +structure notification_ext (more : Type) where + ntfn_obj : L4vRefX64.Spec.Structures_A.ntfn + ntfn_bound_tcb : (Option (BitVec 64)) + ntfn_sc : (Option (BitVec 64)) + more : more +instance {more : Type} [Nonempty more] : Nonempty (notification_ext more) := ⟨notification_ext.mk holUndefined holUndefined holUndefined holUndefined⟩ +abbrev notification := notification_ext Unit +def notification.truncate {more : Type} (r : (notification_ext more)) : notification_ext Unit := { r with more := () } +def notification.extend {more : Type} (r : notification_ext Unit) (m : more) : (notification_ext more) := { r with more := m } +def notification.ntfn_obj_update {more : Type} (g : L4vRefX64.Spec.Structures_A.ntfn → L4vRefX64.Spec.Structures_A.ntfn) (r : (notification_ext more)) : (notification_ext more) := { r with ntfn_obj := g r.ntfn_obj } +def notification.ntfn_bound_tcb_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (notification_ext more)) : (notification_ext more) := { r with ntfn_bound_tcb := g r.ntfn_bound_tcb } +def notification.ntfn_sc_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (notification_ext more)) : (notification_ext more) := { r with ntfn_sc := g r.ntfn_sc } + +structure reply_ext (more : Type) where + reply_tcb : (Option (BitVec 64)) + reply_sc : (Option (BitVec 64)) + more : more +instance {more : Type} [Nonempty more] : Nonempty (reply_ext more) := ⟨reply_ext.mk holUndefined holUndefined holUndefined⟩ +abbrev reply := reply_ext Unit +def reply.truncate {more : Type} (r : (reply_ext more)) : reply_ext Unit := { r with more := () } +def reply.extend {more : Type} (r : reply_ext Unit) (m : more) : (reply_ext more) := { r with more := m } +def reply.reply_tcb_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (reply_ext more)) : (reply_ext more) := { r with reply_tcb := g r.reply_tcb } +def reply.reply_sc_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (reply_ext more)) : (reply_ext more) := { r with reply_sc := g r.reply_sc } + +structure refill_ext (more : Type) where + r_time : (BitVec 64) + r_amount : (BitVec 64) + more : more +instance {more : Type} [Nonempty more] : Nonempty (refill_ext more) := ⟨refill_ext.mk holUndefined holUndefined holUndefined⟩ +abbrev refill := refill_ext Unit +def refill.truncate {more : Type} (r : (refill_ext more)) : refill_ext Unit := { r with more := () } +def refill.extend {more : Type} (r : refill_ext Unit) (m : more) : (refill_ext more) := { r with more := m } +def refill.r_time_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (refill_ext more)) : (refill_ext more) := { r with r_time := g r.r_time } +def refill.r_amount_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (refill_ext more)) : (refill_ext more) := { r with r_amount := g r.r_amount } + +structure sched_context_ext (more : Type) where + sc_period : (BitVec 64) + sc_budget : (BitVec 64) + sc_consumed : (BitVec 64) + sc_tcb : (Option (BitVec 64)) + sc_ntfn : (Option (BitVec 64)) + sc_refills : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit)) + sc_refill_max : Nat + sc_badge : (BitVec 64) + sc_yield_from : (Option (BitVec 64)) + sc_replies : (List (BitVec 64)) + sc_sporadic : Bool + more : more +instance {more : Type} [Nonempty more] : Nonempty (sched_context_ext more) := ⟨sched_context_ext.mk holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +abbrev sched_context := sched_context_ext Unit +def sched_context.truncate {more : Type} (r : (sched_context_ext more)) : sched_context_ext Unit := { r with more := () } +def sched_context.extend {more : Type} (r : sched_context_ext Unit) (m : more) : (sched_context_ext more) := { r with more := m } +def sched_context.sc_period_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_period := g r.sc_period } +def sched_context.sc_budget_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_budget := g r.sc_budget } +def sched_context.sc_consumed_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_consumed := g r.sc_consumed } +def sched_context.sc_tcb_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_tcb := g r.sc_tcb } +def sched_context.sc_ntfn_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_ntfn := g r.sc_ntfn } +def sched_context.sc_refills_update {more : Type} (g : (List (L4vRefX64.Spec.Structures_A.refill_ext Unit)) → (List (L4vRefX64.Spec.Structures_A.refill_ext Unit))) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_refills := g r.sc_refills } +def sched_context.sc_refill_max_update {more : Type} (g : Nat → Nat) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_refill_max := g r.sc_refill_max } +def sched_context.sc_badge_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_badge := g r.sc_badge } +def sched_context.sc_yield_from_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_yield_from := g r.sc_yield_from } +def sched_context.sc_replies_update {more : Type} (g : (List (BitVec 64)) → (List (BitVec 64))) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_replies := g r.sc_replies } +def sched_context.sc_sporadic_update {more : Type} (g : Bool → Bool) (r : (sched_context_ext more)) : (sched_context_ext more) := { r with sc_sporadic := g r.sc_sporadic } + +structure receiver_payload_ext (more : Type) where + receiver_can_grant : Bool + more : more +instance {more : Type} [Nonempty more] : Nonempty (receiver_payload_ext more) := ⟨receiver_payload_ext.mk holUndefined holUndefined⟩ +abbrev receiver_payload := receiver_payload_ext Unit +def receiver_payload.truncate {more : Type} (r : (receiver_payload_ext more)) : receiver_payload_ext Unit := { r with more := () } +def receiver_payload.extend {more : Type} (r : receiver_payload_ext Unit) (m : more) : (receiver_payload_ext more) := { r with more := m } +def receiver_payload.receiver_can_grant_update {more : Type} (g : Bool → Bool) (r : (receiver_payload_ext more)) : (receiver_payload_ext more) := { r with receiver_can_grant := g r.receiver_can_grant } + +structure sender_payload_ext (more : Type) where + sender_badge : (BitVec 64) + sender_can_grant : Bool + sender_can_grant_reply : Bool + sender_is_call : Bool + more : more +instance {more : Type} [Nonempty more] : Nonempty (sender_payload_ext more) := ⟨sender_payload_ext.mk holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +abbrev sender_payload := sender_payload_ext Unit +def sender_payload.truncate {more : Type} (r : (sender_payload_ext more)) : sender_payload_ext Unit := { r with more := () } +def sender_payload.extend {more : Type} (r : sender_payload_ext Unit) (m : more) : (sender_payload_ext more) := { r with more := m } +def sender_payload.sender_badge_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (sender_payload_ext more)) : (sender_payload_ext more) := { r with sender_badge := g r.sender_badge } +def sender_payload.sender_can_grant_update {more : Type} (g : Bool → Bool) (r : (sender_payload_ext more)) : (sender_payload_ext more) := { r with sender_can_grant := g r.sender_can_grant } +def sender_payload.sender_can_grant_reply_update {more : Type} (g : Bool → Bool) (r : (sender_payload_ext more)) : (sender_payload_ext more) := { r with sender_can_grant_reply := g r.sender_can_grant_reply } +def sender_payload.sender_is_call_update {more : Type} (g : Bool → Bool) (r : (sender_payload_ext more)) : (sender_payload_ext more) := { r with sender_is_call := g r.sender_is_call } + +inductive thread_state where + | Running + | Inactive + | Restart + | BlockedOnReceive (a0 : (BitVec 64)) (a1 : (Option (BitVec 64))) (a2 : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) + | BlockedOnSend (a0 : (BitVec 64)) (a1 : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) + | BlockedOnReply (a0 : (BitVec 64)) + | BlockedOnNotification (a0 : (BitVec 64)) + | IdleThreadState +instance : Nonempty thread_state := ⟨thread_state.Running⟩ +def case_thread_state {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : (BitVec 64) → (Option (BitVec 64)) → (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit) → r_ty) (f4 : (BitVec 64) → (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit) → r_ty) (f5 : (BitVec 64) → r_ty) (f6 : (BitVec 64) → r_ty) (f7 : r_ty) : thread_state → r_ty + | .Running => f0 + | .Inactive => f1 + | .Restart => f2 + | .BlockedOnReceive x0 x1 x2 => f3 x0 x1 x2 + | .BlockedOnSend x0 x1 => f4 x0 x1 + | .BlockedOnReply x0 => f5 x0 + | .BlockedOnNotification x0 => f6 x0 + | .IdleThreadState => f7 + +structure tcb_ext (more : Type) where + tcb_ctable : L4vRefX64.Spec.Structures_A.cap + tcb_vtable : L4vRefX64.Spec.Structures_A.cap + tcb_ipcframe : L4vRefX64.Spec.Structures_A.cap + tcb_fault_handler : L4vRefX64.Spec.Structures_A.cap + tcb_timeout_handler : L4vRefX64.Spec.Structures_A.cap + tcb_state : L4vRefX64.Spec.Structures_A.thread_state + tcb_ipc_buffer : (BitVec 64) + tcb_fault : (Option L4vRefX64.Spec.ExceptionTypes_A.fault) + tcb_bound_notification : (Option (BitVec 64)) + tcb_mcpriority : (BitVec 8) + tcb_sched_context : (Option (BitVec 64)) + tcb_yield_to : (Option (BitVec 64)) + tcb_priority : (BitVec 8) + tcb_domain : (BitVec 8) + tcb_flags : (Set L4vRefX64.Spec.Structs_B.tcb_flag) + tcb_arch : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) + more : more +instance {more : Type} [Nonempty more] : Nonempty (tcb_ext more) := ⟨tcb_ext.mk holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +abbrev tcb := tcb_ext Unit +def tcb.truncate {more : Type} (r : (tcb_ext more)) : tcb_ext Unit := { r with more := () } +def tcb.extend {more : Type} (r : tcb_ext Unit) (m : more) : (tcb_ext more) := { r with more := m } +def tcb.tcb_ctable_update {more : Type} (g : L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_ctable := g r.tcb_ctable } +def tcb.tcb_vtable_update {more : Type} (g : L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_vtable := g r.tcb_vtable } +def tcb.tcb_ipcframe_update {more : Type} (g : L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_ipcframe := g r.tcb_ipcframe } +def tcb.tcb_fault_handler_update {more : Type} (g : L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_fault_handler := g r.tcb_fault_handler } +def tcb.tcb_timeout_handler_update {more : Type} (g : L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_timeout_handler := g r.tcb_timeout_handler } +def tcb.tcb_state_update {more : Type} (g : L4vRefX64.Spec.Structures_A.thread_state → L4vRefX64.Spec.Structures_A.thread_state) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_state := g r.tcb_state } +def tcb.tcb_ipc_buffer_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_ipc_buffer := g r.tcb_ipc_buffer } +def tcb.tcb_fault_update {more : Type} (g : (Option L4vRefX64.Spec.ExceptionTypes_A.fault) → (Option L4vRefX64.Spec.ExceptionTypes_A.fault)) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_fault := g r.tcb_fault } +def tcb.tcb_bound_notification_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_bound_notification := g r.tcb_bound_notification } +def tcb.tcb_mcpriority_update {more : Type} (g : (BitVec 8) → (BitVec 8)) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_mcpriority := g r.tcb_mcpriority } +def tcb.tcb_sched_context_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_sched_context := g r.tcb_sched_context } +def tcb.tcb_yield_to_update {more : Type} (g : (Option (BitVec 64)) → (Option (BitVec 64))) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_yield_to := g r.tcb_yield_to } +def tcb.tcb_priority_update {more : Type} (g : (BitVec 8) → (BitVec 8)) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_priority := g r.tcb_priority } +def tcb.tcb_domain_update {more : Type} (g : (BitVec 8) → (BitVec 8)) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_domain := g r.tcb_domain } +def tcb.tcb_flags_update {more : Type} (g : (Set L4vRefX64.Spec.Structs_B.tcb_flag) → (Set L4vRefX64.Spec.Structs_B.tcb_flag)) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_flags := g r.tcb_flags } +def tcb.tcb_arch_update {more : Type} (g : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit) → (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) (r : (tcb_ext more)) : (tcb_ext more) := { r with tcb_arch := g r.tcb_arch } + +inductive kernel_object where + | CNode (a0 : Nat) (a1 : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) + | TCB (a0 : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) + | Endpoint (a0 : L4vRefX64.Spec.Structures_A.endpoint) + | Notification (a0 : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) + | SchedContext (a0 : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) (a1 : Nat) + | Reply (a0 : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) + | ArchObj (a0 : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) +instance : Nonempty kernel_object := ⟨kernel_object.CNode holUndefined holUndefined⟩ +def case_kernel_object {r_ty : Type} (f0 : Nat → ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)) → r_ty) (f1 : (L4vRefX64.Spec.Structures_A.tcb_ext Unit) → r_ty) (f2 : L4vRefX64.Spec.Structures_A.endpoint → r_ty) (f3 : (L4vRefX64.Spec.Structures_A.notification_ext Unit) → r_ty) (f4 : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit) → Nat → r_ty) (f5 : (L4vRefX64.Spec.Structures_A.reply_ext Unit) → r_ty) (f6 : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj → r_ty) : kernel_object → r_ty + | .CNode x0 x1 => f0 x0 x1 + | .TCB x0 => f1 x0 + | .Endpoint x0 => f2 x0 + | .Notification x0 => f3 x0 + | .SchedContext x0 x1 => f4 x0 x1 + | .Reply x0 => f5 x0 + | .ArchObj x0 => f6 x0 + +inductive scheduler_action where + | resume_cur_thread + | switch_thread (a0 : (BitVec 64)) + | choose_new_thread +instance : Nonempty scheduler_action := ⟨scheduler_action.resume_cur_thread⟩ +def case_scheduler_action {r_ty : Type} (f0 : r_ty) (f1 : (BitVec 64) → r_ty) (f2 : r_ty) : scheduler_action → r_ty + | .resume_cur_thread => f0 + | .switch_thread x0 => f1 x0 + | .choose_new_thread => f2 + +structure abstract_state_ext (more : Type) where + kheap : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object)) + cdt : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) + is_original_cap : (((BitVec 64) × (List Bool)) → Bool) + cur_thread : (BitVec 64) + idle_thread : (BitVec 64) + consumed_time : (BitVec 64) + cur_time : (BitVec 64) + cur_sc : (BitVec 64) + reprogram_timer : Bool + scheduler_action : L4vRefX64.Spec.Structures_A.scheduler_action + domain_list : (List ((BitVec 8) × (BitVec 56))) + domain_index : Nat + domain_start_index : Nat + cur_domain : (BitVec 8) + domain_time : (BitVec 64) + ready_queues : ((BitVec 8) → ((BitVec 8) → (List (BitVec 64)))) + release_queue : (List (BitVec 64)) + machine_state : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) + interrupt_irq_node : ((BitVec 8) → (BitVec 64)) + interrupt_states : ((BitVec 8) → L4vRefX64.Spec.Structures_A.irq_state) + arch_state : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit) + more : more +instance {more : Type} [Nonempty more] : Nonempty (abstract_state_ext more) := ⟨abstract_state_ext.mk holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined holUndefined⟩ +abbrev abstract_state := abstract_state_ext Unit +def abstract_state.truncate {more : Type} (r : (abstract_state_ext more)) : abstract_state_ext Unit := { r with more := () } +def abstract_state.extend {more : Type} (r : abstract_state_ext Unit) (m : more) : (abstract_state_ext more) := { r with more := m } +def abstract_state.kheap_update {more : Type} (g : ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object)) → ((BitVec 64) → (Option L4vRefX64.Spec.Structures_A.kernel_object))) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with kheap := g r.kheap } +def abstract_state.cdt_update {more : Type} (g : (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool)))) → (((BitVec 64) × (List Bool)) → (Option ((BitVec 64) × (List Bool))))) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with cdt := g r.cdt } +def abstract_state.is_original_cap_update {more : Type} (g : (((BitVec 64) × (List Bool)) → Bool) → (((BitVec 64) × (List Bool)) → Bool)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with is_original_cap := g r.is_original_cap } +def abstract_state.cur_thread_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with cur_thread := g r.cur_thread } +def abstract_state.idle_thread_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with idle_thread := g r.idle_thread } +def abstract_state.consumed_time_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with consumed_time := g r.consumed_time } +def abstract_state.cur_time_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with cur_time := g r.cur_time } +def abstract_state.cur_sc_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with cur_sc := g r.cur_sc } +def abstract_state.reprogram_timer_update {more : Type} (g : Bool → Bool) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with reprogram_timer := g r.reprogram_timer } +def abstract_state.scheduler_action_update {more : Type} (g : L4vRefX64.Spec.Structures_A.scheduler_action → L4vRefX64.Spec.Structures_A.scheduler_action) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with scheduler_action := g r.scheduler_action } +def abstract_state.domain_list_update {more : Type} (g : (List ((BitVec 8) × (BitVec 56))) → (List ((BitVec 8) × (BitVec 56)))) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with domain_list := g r.domain_list } +def abstract_state.domain_index_update {more : Type} (g : Nat → Nat) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with domain_index := g r.domain_index } +def abstract_state.domain_start_index_update {more : Type} (g : Nat → Nat) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with domain_start_index := g r.domain_start_index } +def abstract_state.cur_domain_update {more : Type} (g : (BitVec 8) → (BitVec 8)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with cur_domain := g r.cur_domain } +def abstract_state.domain_time_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with domain_time := g r.domain_time } +def abstract_state.ready_queues_update {more : Type} (g : ((BitVec 8) → ((BitVec 8) → (List (BitVec 64)))) → ((BitVec 8) → ((BitVec 8) → (List (BitVec 64))))) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with ready_queues := g r.ready_queues } +def abstract_state.release_queue_update {more : Type} (g : (List (BitVec 64)) → (List (BitVec 64))) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with release_queue := g r.release_queue } +def abstract_state.machine_state_update {more : Type} (g : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with machine_state := g r.machine_state } +def abstract_state.interrupt_irq_node_update {more : Type} (g : ((BitVec 8) → (BitVec 64)) → ((BitVec 8) → (BitVec 64))) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with interrupt_irq_node := g r.interrupt_irq_node } +def abstract_state.interrupt_states_update {more : Type} (g : ((BitVec 8) → L4vRefX64.Spec.Structures_A.irq_state) → ((BitVec 8) → L4vRefX64.Spec.Structures_A.irq_state)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with interrupt_states := g r.interrupt_states } +def abstract_state.arch_state_update {more : Type} (g : (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit) → (L4vRefX64.Spec.Arch_Structs_A.arch_state_ext Unit)) (r : (abstract_state_ext more)) : (abstract_state_ext more) := { r with arch_state := g r.arch_state } + +inductive apiobject_type where + | Untyped + | TCBObject + | EndpointObject + | NotificationObject + | CapTableObject + | SchedContextObject + | ReplyObject + | ArchObject (a0 : L4vRefX64.Spec.Arch_Structs_A.aobject_type) +instance : Nonempty apiobject_type := ⟨apiobject_type.Untyped⟩ +def case_apiobject_type {r_ty : Type} (f0 : r_ty) (f1 : r_ty) (f2 : r_ty) (f3 : r_ty) (f4 : r_ty) (f5 : r_ty) (f6 : r_ty) (f7 : L4vRefX64.Spec.Arch_Structs_A.aobject_type → r_ty) : apiobject_type → r_ty + | .Untyped => f0 + | .TCBObject => f1 + | .EndpointObject => f2 + | .NotificationObject => f3 + | .CapTableObject => f4 + | .SchedContextObject => f5 + | .ReplyObject => f6 + | .ArchObject x0 => f7 x0 + +structure captransfer_ext (more : Type) where + ct_receive_root : (List Bool) + ct_receive_index : (List Bool) + ct_receive_depth : (BitVec 64) + more : more +instance {more : Type} [Nonempty more] : Nonempty (captransfer_ext more) := ⟨captransfer_ext.mk holUndefined holUndefined holUndefined holUndefined⟩ +abbrev captransfer := captransfer_ext Unit +def captransfer.truncate {more : Type} (r : (captransfer_ext more)) : captransfer_ext Unit := { r with more := () } +def captransfer.extend {more : Type} (r : captransfer_ext Unit) (m : more) : (captransfer_ext more) := { r with more := m } +def captransfer.ct_receive_root_update {more : Type} (g : (List Bool) → (List Bool)) (r : (captransfer_ext more)) : (captransfer_ext more) := { r with ct_receive_root := g r.ct_receive_root } +def captransfer.ct_receive_index_update {more : Type} (g : (List Bool) → (List Bool)) (r : (captransfer_ext more)) : (captransfer_ext more) := { r with ct_receive_index := g r.ct_receive_index } +def captransfer.ct_receive_depth_update {more : Type} (g : (BitVec 64) → (BitVec 64)) (r : (captransfer_ext more)) : (captransfer_ext more) := { r with ct_receive_depth := g r.ct_receive_depth } + +inductive message_info where + | MI (a0 : (BitVec 64)) (a1 : (BitVec 64)) (a2 : (BitVec 64)) (a3 : (BitVec 64)) +instance : Nonempty message_info := ⟨message_info.MI holUndefined holUndefined holUndefined holUndefined⟩ +def case_message_info {r_ty : Type} (f0 : (BitVec 64) → (BitVec 64) → (BitVec 64) → (BitVec 64) → r_ty) : message_info → r_ty + | .MI x0 x1 x2 x3 => f0 x0 x1 x2 x3 + +structure state_ext (tv_a : Type) (more : Type) where + exst : tv_a + more : more +instance {tv_a : Type} [Nonempty tv_a] {more : Type} [Nonempty more] : Nonempty (state_ext tv_a more) := ⟨state_ext.mk holUndefined holUndefined⟩ +abbrev state (tv_a : Type) := L4vRefX64.Spec.Structures_A.abstract_state_ext (state_ext tv_a Unit) +def state.fields {tv_a : Type} (a0 : tv_a) : (state_ext tv_a Unit) := state_ext.mk a0 () +def state.exst {tv_a : Type} {more : Type} (r : (L4vRefX64.Spec.Structures_A.abstract_state_ext (state_ext tv_a more))) : tv_a := r.more.exst +def state.exst_update {tv_a : Type} {more : Type} (g : tv_a → tv_a) (r : (L4vRefX64.Spec.Structures_A.abstract_state_ext (state_ext tv_a more))) : (L4vRefX64.Spec.Structures_A.abstract_state_ext (state_ext tv_a more)) := { r with more := { r.more with exst := g r.more.exst } } + +def MIN_BUDGET : (BitVec 64) := + (HolMul.mulVal (HolNumeral.ofNatVal (α := (BitVec 64)) 2) L4vRefX64.Spec.Time.kernelWCET_ticks) + +def MIN_BUDGET_US : (BitVec 64) := + (HolMul.mulVal (HolNumeral.ofNatVal (α := (BitVec 64)) 2) L4vRefX64.Spec.Time.kernelWCET_us) + +def MIN_REFILLS {tv_a : Type} [Nonempty tv_a] [HolNumeral tv_a] : tv_a := + (HolNumeral.ofNatVal (α := tv_a) 2) + +def min_sched_context_bits {tv_a : Type} [Nonempty tv_a] [HolNumeral tv_a] : tv_a := + (HolNumeral.ofNatVal (α := tv_a) 7) + +def valid_sched_context_size : (Nat → Bool) := + (fun (n : Nat) => (holLe (HolAdd.addVal (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat) n) L4vRefX64.Spec.Arch_Structs_A.untyped_max_bits)) + +def well_formed_cnode_n : (Nat → (((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap)) → Bool)) := + (fun (n : Nat) => (fun (cs : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holEq (holDom cs) (holCollect (fun (x : (List Bool)) => (holEq (holSize x) n)))))) + +def a_type : (L4vRefX64.Spec.Structures_A.kernel_object → L4vRefX64.Spec.Structures_A.a_type_T) := + (fun (ob : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (sz : Nat) => (fun (cspace : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holIf (L4vRefX64.Spec.Structures_A.well_formed_cnode_n sz cspace) (L4vRefX64.Spec.Structures_A.a_type_T.ACapTable sz) (L4vRefX64.Spec.Structures_A.a_type_T.AGarbage (HolAdd.addVal L4vRefX64.Spec.Arch_Structs_A.cte_level_bits sz))))) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => L4vRefX64.Spec.Structures_A.a_type_T.ATCB) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => L4vRefX64.Spec.Structures_A.a_type_T.AEndpoint) (fun (notification : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => L4vRefX64.Spec.Structures_A.a_type_T.ANTFN) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (n : Nat) => (holIf (L4vRefX64.Spec.Structures_A.valid_sched_context_size n) (L4vRefX64.Spec.Structures_A.a_type_T.ASchedContext n) (L4vRefX64.Spec.Structures_A.a_type_T.AGarbage (HolAdd.addVal (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat) n))))) (fun (r : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => L4vRefX64.Spec.Structures_A.a_type_T.AReply) (fun (ao : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (L4vRefX64.Spec.Structures_A.a_type_T.AArch (L4vRefX64.Spec.Arch_Structs_A.aa_type ao))) ob)) + +def aobj_of : (L4vRefX64.Spec.Structures_A.kernel_object → (Option L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj)) := + (fun (ko : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (nat : Nat) => (fun (v_fun : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (Option.none (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj)))) (fun (tcb_ext : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (Option.none (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (Option.none (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (Option.none (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (Option.none (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj)))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (Option.none (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (aobj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (Option.some aobj)) ko)) + +def badge_update : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap)) := + (fun (data : (BitVec 64)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap cap (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => cap)))) (fun (oref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (cr : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.Structures_A.cap.EndpointCap oref (holWordAnd data ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.badge_bits)) cr)))) (fun (oref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (cr : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.Structures_A.cap.NotificationCap oref (holWordAnd data ((holWordMask (w := 64)) L4vRefX64.Spec.Arch_Structs_A.badge_bits)) cr)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => cap)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => cap))) (fun (word : (BitVec 64)) => cap) cap (fun (word : (BitVec 64)) => (fun (nat : Nat) => cap)) cap cap (fun (word : (BitVec 8)) => cap) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => cap))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => cap) cap))) + +def bits_of : (L4vRefX64.Spec.Structures_A.cap → Nat) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holUndefined (α := Nat)) (fun (x : Bool) => (fun (xa : (BitVec 64)) => (fun (bits : Nat) => (fun (xb : Nat) => bits)))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := Nat))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := Nat))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := Nat)))) (fun (x : (BitVec 64)) => (fun (radix_bits : Nat) => (fun (xa : (List Bool)) => radix_bits))) (fun (a : (BitVec 64)) => (holUndefined (α := Nat))) (holUndefined (α := Nat)) (fun (x : (BitVec 64)) => (fun (n : Nat) => n)) (holUndefined (α := Nat)) (holUndefined (α := Nat)) (fun (a : (BitVec 8)) => (holUndefined (α := Nat))) (fun (a : (BitVec 64)) => (fun (a_1 : (Option Nat)) => (fun (a_2 : Nat) => (holUndefined (α := Nat))))) (fun (a : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holUndefined (α := Nat))) cap)) + +def cap.is_ArchObjectCap : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holEx (fun (x14 : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holEq cap (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap x14))))) + +def cap.the_arch_cap : (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Arch_Structs_A.arch_cap) + | cap => (L4vRefX64.Spec.Structures_A.case_cap (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (fun (uu : Bool) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : Nat) => (fun (uu_3 : Nat) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (BitVec 64)) => (fun (uu_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap))))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (fun (uu : (BitVec 64)) => (fun (uu_1 : Nat) => (fun (uu_2 : (List Bool)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap))))) (fun (uu : (BitVec 64)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap))) (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (fun (uu : (BitVec 64)) => (fun (uu_1 : Nat) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)))) (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap)) (fun (uu : (BitVec 8)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap))) (fun (uu : (BitVec 64)) => (fun (uu_1 : (Option Nat)) => (fun (uu_2 : Nat) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_cap))))) (fun (x14 : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => x14) cap) + +def cap_badge : (L4vRefX64.Spec.Structures_A.cap → (Option (BitVec 64))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (Option.none (α := (BitVec 64))) (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => (Option.none (α := (BitVec 64))))))) (fun (r : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.some badge)))) (fun (r : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.some badge)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => (Option.none (α := (BitVec 64))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => (Option.none (α := (BitVec 64)))))) (fun (word : (BitVec 64)) => (Option.none (α := (BitVec 64)))) (Option.none (α := (BitVec 64))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (Option.none (α := (BitVec 64))))) (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (fun (word : (BitVec 8)) => (Option.none (α := (BitVec 64)))) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => (Option.none (α := (BitVec 64)))))) (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap_badge acap)) cap)) + +def cap_bits_untyped : (L4vRefX64.Spec.Structures_A.cap → Nat) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev r s f) => s + | _ => holUndefined + +def cap_ep_badge : (L4vRefX64.Spec.Structures_A.cap → (BitVec 64)) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap uu badge uv) => badge + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap uw badge ux) => badge + | _ => holUndefined + +def cap_ep_ptr : (L4vRefX64.Spec.Structures_A.cap → (BitVec 64)) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap obj_ref uu uv) => obj_ref + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap obj_ref uw ux) => obj_ref + | _ => holUndefined + +def tcb_cnode_index : (Nat → (List Bool)) := + (fun (n : Nat) => (holToBl ((holOfNat (α := (BitVec 3))) n))) + +def tcb_cnode_map : ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) := + (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holFunUpd (holFunUpd (holFunUpd (holFunUpd (holFunUpd (fun (x : (List Bool)) => (Option.none (α := L4vRefX64.Spec.Structures_A.cap))) (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolZero.zeroVal (α := Nat))) (Option.some (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_ctable tcb))) (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolOne.oneVal (α := Nat))) (Option.some (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_vtable tcb))) (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 2)) (Option.some (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_ipcframe tcb))) (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 3)) (Option.some (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_fault_handler tcb))) (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 4)) (Option.some (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_timeout_handler tcb)))) + +def cap_of : (L4vRefX64.Spec.Structures_A.kernel_object → ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) := + (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (x : Nat) => (fun (cs : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => cs)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb_cnode_map tcb)) (fun (endpoint : L4vRefX64.Spec.Structures_A.endpoint) => (fun (x : (List Bool)) => (Option.none (α := L4vRefX64.Spec.Structures_A.cap)))) (fun (notification_ext : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (fun (x : (List Bool)) => (Option.none (α := L4vRefX64.Spec.Structures_A.cap)))) (fun (sched_context_ext : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (nat : Nat) => (fun (x : (List Bool)) => (Option.none (α := L4vRefX64.Spec.Structures_A.cap))))) (fun (reply_ext : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (fun (x : (List Bool)) => (Option.none (α := L4vRefX64.Spec.Structures_A.cap)))) (fun (arch_kernel_obj : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => (fun (x : (List Bool)) => (Option.none (α := L4vRefX64.Spec.Structures_A.cap)))) kobj)) + +def cap_rights : (L4vRefX64.Spec.Structures_A.cap → (Set L4vRefX64.Spec.CapRights_A.rights)) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap uu uv cr) => cr + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap uw ux cr) => cr + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap uy cr) => cr + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap acap) => (L4vRefX64.Spec.Arch_Structs_A.arch_cap.acap_rights acap) + | _ => holUndefined + +def cap_rights_update : ((Set L4vRefX64.Spec.CapRights_A.rights) → (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap)) := + (fun (cr_p : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap cap (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => cap)))) (fun (oref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (cr : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.Structures_A.cap.EndpointCap oref badge cr_p)))) (fun (oref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (cr : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.Structures_A.cap.NotificationCap oref badge (HolSub.subVal cr_p (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowGrant (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowGrantReply (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))))))))) (fun (t : (BitVec 64)) => (fun (cr : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.Structures_A.cap.ReplyCap t (HolCompleteLattice.holSup (HolSub.subVal cr_p (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowRead (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowGrantReply (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))))) (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowWrite (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))))))) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => cap))) (fun (word : (BitVec 64)) => cap) cap (fun (word : (BitVec 64)) => (fun (nat : Nat) => cap)) cap cap (fun (word : (BitVec 8)) => cap) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => cap))) (fun (acap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap (L4vRefX64.Spec.Arch_Structs_A.acap_rights_update cr_p acap))) cap))) + +def cap_transfer_data_size : Nat := + (HolNumeral.ofNatVal (α := Nat) 3) + +def caps_of : (L4vRefX64.Spec.Structures_A.kernel_object → (Set L4vRefX64.Spec.Structures_A.cap)) := + (fun (kobj : L4vRefX64.Spec.Structures_A.kernel_object) => (holRan (L4vRefX64.Spec.Structures_A.cap_of kobj))) + +def data_to_message_info : ((BitVec 64) → L4vRefX64.Spec.Structures_A.message_info) := + (fun (w : (BitVec 64)) => (L4vRefX64.Spec.Structures_A.message_info.MI (holLet (holWordAnd w ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 7))) (fun (v : (BitVec 64)) => (holIf (holLt (HolNumeral.ofNatVal (α := (BitVec 64)) 120) v) (HolNumeral.ofNatVal (α := (BitVec 64)) 120) v))) (holWordAnd (holWordShiftr w (HolNumeral.ofNatVal (α := Nat) 7)) ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 2))) (holWordAnd (holWordShiftr w (HolNumeral.ofNatVal (α := Nat) 9)) ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 3))) (holWordAnd (holWordShiftr w (HolNumeral.ofNatVal (α := Nat) 12)) ((holWordMask (w := 64)) L4vRefX64.Spec.Machine_A.msg_label_bits)))) + +def default_domain : (BitVec 8) := + (holMinBound (α := (BitVec 8))) + +def default_ep : L4vRefX64.Spec.Structures_A.endpoint := + L4vRefX64.Spec.Structures_A.endpoint.IdleEP + +def default_ntfn : L4vRefX64.Spec.Structures_A.ntfn := + L4vRefX64.Spec.Structures_A.ntfn.IdleNtfn + +def default_notification : (L4vRefX64.Spec.Structures_A.notification_ext Unit) := + (L4vRefX64.Spec.Structures_A.notification_ext.mk L4vRefX64.Spec.Structures_A.default_ntfn (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) ()) + +def default_priority : (BitVec 8) := + (holMinBound (α := (BitVec 8))) + +def default_reply : (L4vRefX64.Spec.Structures_A.reply_ext Unit) := + (L4vRefX64.Spec.Structures_A.reply_ext.mk (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) ()) + +def default_sched_context : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit) := + (L4vRefX64.Spec.Structures_A.sched_context_ext.mk (HolZero.zeroVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (List.nil (α := (L4vRefX64.Spec.Structures_A.refill_ext Unit))) (HolZero.zeroVal (α := Nat)) (HolZero.zeroVal (α := (BitVec 64))) (Option.none (α := (BitVec 64))) (List.nil (α := (BitVec 64))) false ()) + +def default_tcb : ((BitVec 8) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) := + (fun (d : (BitVec 8)) => (L4vRefX64.Spec.Structures_A.tcb_ext.mk L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.cap.NullCap L4vRefX64.Spec.Structures_A.thread_state.Inactive (HolZero.zeroVal (α := (BitVec 64))) (Option.none (α := L4vRefX64.Spec.ExceptionTypes_A.fault)) (Option.none (α := (BitVec 64))) (holMinBound (α := (BitVec 8))) (Option.none (α := (BitVec 64))) (Option.none (α := (BitVec 64))) L4vRefX64.Spec.Structures_A.default_priority d (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.Structs_B.tcb_flag))) L4vRefX64.Spec.Arch_Structs_A.default_arch_tcb ())) + +def do_machine_op {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] : (((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (tv_a × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_a × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (mop : ((L4vRefX64.Spec.MachineTypes.machine_state_ext Unit) → ((Set (tv_a × (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit))) × Bool))) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.machine_state) (fun (ms : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (holBind (holSelectF (mop ms)) (holCaseProd (fun (r : tv_a) => (fun (ms_p : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => (holBind (holModify (fun (state : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.machine_state_update (fun (uu_ : (L4vRefX64.Spec.MachineTypes.machine_state_ext Unit)) => ms_p) state))) (holKBind (holReturn r)))))))))) + +def domain_duration_len : Nat := + (HolSub.subVal (HolNumeral.ofNatVal (α := Nat) 64) L4vRefX64.Spec.Kernel_Config_Lemmas.domainBits) + +def domain_len : Nat := + L4vRefX64.Spec.Kernel_Config_Lemmas.domainBits + +def endpoint.ep_queue : (L4vRefX64.Spec.Structures_A.endpoint → (List (BitVec 64))) + | endpoint => (L4vRefX64.Spec.Structures_A.case_endpoint (List.nil (α := (BitVec 64))) (fun (x2 : (List (BitVec 64))) => x2) (fun (x3 : (List (BitVec 64))) => x3) endpoint) + +def zombie_cte_bits : ((Option Nat) → Nat) := + (fun (N : (Option Nat)) => (holCaseOption (HolNumeral.ofNatVal (α := Nat) 3) (fun (n : Nat) => n) N)) + +def first_cslot_of : (L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (List Bool))) + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap oref) => (Prod.mk oref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolZero.zeroVal (α := Nat)))) + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap oref bits g) => (Prod.mk oref (holListReplicate bits false)) + | (L4vRefX64.Spec.Structures_A.cap.Zombie oref bits n) => (Prod.mk oref (holListReplicate (L4vRefX64.Spec.Structures_A.zombie_cte_bits bits) false)) + | _ => holUndefined + +def free_index_of : (L4vRefX64.Spec.Structures_A.cap → Nat) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holUndefined (α := Nat)) (fun (x : Bool) => (fun (xa : (BitVec 64)) => (fun (xb : Nat) => (fun (free_index : Nat) => free_index)))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := Nat))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := Nat))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := Nat)))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (fun (a_2 : (List Bool)) => (holUndefined (α := Nat))))) (fun (a : (BitVec 64)) => (holUndefined (α := Nat))) (holUndefined (α := Nat)) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (holUndefined (α := Nat)))) (holUndefined (α := Nat)) (holUndefined (α := Nat)) (fun (a : (BitVec 8)) => (holUndefined (α := Nat))) (fun (a : (BitVec 64)) => (fun (a_1 : (Option Nat)) => (fun (a_2 : Nat) => (holUndefined (α := Nat))))) (fun (a : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holUndefined (α := Nat))) cap)) + +def ipc_queued_thread_state : (L4vRefX64.Spec.Structures_A.thread_state → Bool) + | L4vRefX64.Spec.Structures_A.thread_state.Running => false + | L4vRefX64.Spec.Structures_A.thread_state.Inactive => false + | L4vRefX64.Spec.Structures_A.thread_state.Restart => false + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReceive uu uv uw) => true + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnSend ux uy) => true + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnNotification uz) => true + | L4vRefX64.Spec.Structures_A.thread_state.IdleThreadState => false + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReply va) => true + +def is_arch_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => false))) (fun (x : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => true) cap)) + +def is_blocked_on_ntfn : (L4vRefX64.Spec.Structures_A.thread_state → Bool) := + (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holEx (fun (ntfn : (BitVec 64)) => (holEq st (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnNotification ntfn))))) + +def is_blocked_on_receive : (L4vRefX64.Spec.Structures_A.thread_state → Bool) := + (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holEx (fun (ep : (BitVec 64)) => (holEx (fun (reply_opt : (Option (BitVec 64))) => (holEx (fun (receiver_data : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holEq st (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReceive ep reply_opt receiver_data))))))))) + +def is_blocked_on_reply : (L4vRefX64.Spec.Structures_A.thread_state → Bool) := + (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holEx (fun (reply : (BitVec 64)) => (holEq st (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReply reply))))) + +def is_blocked_on_send : (L4vRefX64.Spec.Structures_A.thread_state → Bool) := + (fun (st : L4vRefX64.Spec.Structures_A.thread_state) => (holEx (fun (ep : (BitVec 64)) => (holEx (fun (sender_data : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holEq st (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnSend ep sender_data))))))) + +def is_cnode_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap uu uv uw) => true + | L4vRefX64.Spec.Structures_A.cap.NullCap => false + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) => false + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) => false + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) => false + | L4vRefX64.Spec.Structures_A.cap.DomainCap => false + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) => false + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => false + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) => false + +def is_domain_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | L4vRefX64.Spec.Structures_A.cap.DomainCap => true + | L4vRefX64.Spec.Structures_A.cap.NullCap => false + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) => false + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) => false + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) => false + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => false + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) => false + +def is_ep_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap uu uv uw) => true + | L4vRefX64.Spec.Structures_A.cap.NullCap => false + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) => false + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) => false + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) => false + | L4vRefX64.Spec.Structures_A.cap.DomainCap => false + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) => false + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => false + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) => false + +def is_frame_type : (L4vRefX64.Spec.Structures_A.apiobject_type → Bool) := + (fun (obj : L4vRefX64.Spec.Structures_A.apiobject_type) => (L4vRefX64.Spec.Structures_A.case_apiobject_type false false false false false false false (fun (aobj : L4vRefX64.Spec.Arch_Structs_A.aobject_type) => (L4vRefX64.Spec.Arch_Structs_A.arch_is_frame_type aobj)) obj)) + +def is_ntfn_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap uu uv uw) => true + | L4vRefX64.Spec.Structures_A.cap.NullCap => false + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) => false + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) => false + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) => false + | L4vRefX64.Spec.Structures_A.cap.DomainCap => false + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) => false + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => false + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) => false + +def is_reply_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (x : (BitVec 64)) => (fun (xa : (Set L4vRefX64.Spec.CapRights_A.rights)) => true)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => false))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => false) cap)) + +def is_sched_context_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap uu uv) => true + | L4vRefX64.Spec.Structures_A.cap.NullCap => false + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) => false + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) => false + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) => false + | L4vRefX64.Spec.Structures_A.cap.DomainCap => false + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => false + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) => false + +def is_thread_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap uu) => true + | L4vRefX64.Spec.Structures_A.cap.NullCap => false + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap v va vb vc) => false + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) => false + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) => false + | L4vRefX64.Spec.Structures_A.cap.DomainCap => false + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) => false + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => false + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) => false + +def is_untyped_cap : (L4vRefX64.Spec.Structures_A.cap → Bool) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap uu uv uw ux) => true + | L4vRefX64.Spec.Structures_A.cap.NullCap => false + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap v va) => false + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap v) => false + | L4vRefX64.Spec.Structures_A.cap.DomainCap => false + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap v va) => false + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => false + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => false + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap v) => false + | (L4vRefX64.Spec.Structures_A.cap.Zombie v va vb) => false + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap v) => false + +def is_zombie : (L4vRefX64.Spec.Structures_A.cap → Bool) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap false (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => false)))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word1 : (BitVec 64)) => (fun (word2 : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => false)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => false))) (fun (word : (BitVec 64)) => false) false (fun (word : (BitVec 64)) => (fun (nat : Nat) => false)) false false (fun (word : (BitVec 8)) => false) (fun (x : (BitVec 64)) => (fun (xa : (Option Nat)) => (fun (xb : Nat) => true))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => false) cap)) + +def kernel_object.the_arch_obj : (L4vRefX64.Spec.Structures_A.kernel_object → L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) + | kernel_object => (L4vRefX64.Spec.Structures_A.case_kernel_object (fun (uu : Nat) => (fun (uu_1 : ((List Bool) → (Option L4vRefX64.Spec.Structures_A.cap))) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj)))) (fun (uu : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (uu : L4vRefX64.Spec.Structures_A.endpoint) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (uu : (L4vRefX64.Spec.Structures_A.notification_ext Unit)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (uu : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (fun (uu_1 : Nat) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj)))) (fun (uu : (L4vRefX64.Spec.Structures_A.reply_ext Unit)) => (holUndefined (α := L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj))) (fun (x7 : L4vRefX64.Spec.Arch_Structs_A.arch_kernel_obj) => x7) kernel_object) + +def mask_cap : ((Set L4vRefX64.Spec.CapRights_A.rights) → (L4vRefX64.Spec.Structures_A.cap → L4vRefX64.Spec.Structures_A.cap)) := + (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.cap_rights_update (HolCompleteLattice.holInf (L4vRefX64.Spec.Structures_A.cap_rights cap) rights) cap))) + +def max_domain_duration : (BitVec 64) := + ((holWordMask (w := 64)) (56 : Nat)) + +def msg_max_extra_caps : Nat := + (HolNumeral.ofNatVal (α := Nat) 3) + +def msg_max_length : Nat := + (HolNumeral.ofNatVal (α := Nat) 120) + +def max_ipc_length : Nat := + (HolAdd.addVal (HolAdd.addVal (HolAdd.addVal L4vRefX64.Spec.Structures_A.cap_transfer_data_size L4vRefX64.Spec.Structures_A.msg_max_length) L4vRefX64.Spec.Structures_A.msg_max_extra_caps) (HolNumeral.ofNatVal (α := Nat) 2)) + +def refill_size_bytes {tv_a : Type} [Nonempty tv_a] [HolNumeral tv_a] : tv_a := + (HolNumeral.ofNatVal (α := tv_a) 16) + +def sizeof_sched_context_t : Nat := + (HolAdd.addVal (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 10) (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : Nat)) (HolMul.mulVal (HolNumeral.ofNatVal (α := Nat) 2) (HolNumeral.ofNatVal (α := Nat) 8))) + +def max_num_refills : (Nat → Nat) := + (fun (sz : Nat) => (HolDiv.divVal (HolSub.subVal (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) sz) L4vRefX64.Spec.Structures_A.sizeof_sched_context_t) (L4vRefX64.Spec.Structures_A.refill_size_bytes : Nat))) + +def message_info.mi_caps_unwrapped : (L4vRefX64.Spec.Structures_A.message_info → (BitVec 64)) := + (fun (message_info : L4vRefX64.Spec.Structures_A.message_info) => (L4vRefX64.Spec.Structures_A.case_message_info (fun (x1 : (BitVec 64)) => (fun (x2 : (BitVec 64)) => (fun (x3 : (BitVec 64)) => (fun (x4 : (BitVec 64)) => x3)))) message_info)) + +def message_info.mi_extra_caps : (L4vRefX64.Spec.Structures_A.message_info → (BitVec 64)) := + (fun (message_info : L4vRefX64.Spec.Structures_A.message_info) => (L4vRefX64.Spec.Structures_A.case_message_info (fun (x1 : (BitVec 64)) => (fun (x2 : (BitVec 64)) => (fun (x3 : (BitVec 64)) => (fun (x4 : (BitVec 64)) => x2)))) message_info)) + +def message_info.mi_label : (L4vRefX64.Spec.Structures_A.message_info → (BitVec 64)) := + (fun (message_info : L4vRefX64.Spec.Structures_A.message_info) => (L4vRefX64.Spec.Structures_A.case_message_info (fun (x1 : (BitVec 64)) => (fun (x2 : (BitVec 64)) => (fun (x3 : (BitVec 64)) => (fun (x4 : (BitVec 64)) => x4)))) message_info)) + +def message_info.mi_length : (L4vRefX64.Spec.Structures_A.message_info → (BitVec 64)) := + (fun (message_info : L4vRefX64.Spec.Structures_A.message_info) => (L4vRefX64.Spec.Structures_A.case_message_info (fun (x1 : (BitVec 64)) => (fun (x2 : (BitVec 64)) => (fun (x3 : (BitVec 64)) => (fun (x4 : (BitVec 64)) => x1)))) message_info)) + +def message_info_to_data : (L4vRefX64.Spec.Structures_A.message_info → (BitVec 64)) + | (L4vRefX64.Spec.Structures_A.message_info.MI len exc unw mlabel) => (holLet (holWordShiftl exc (HolNumeral.ofNatVal (α := Nat) 7)) (fun (extra : (BitVec 64)) => (holLet (holWordShiftl unw (HolNumeral.ofNatVal (α := Nat) 9)) (fun (unwrapped : (BitVec 64)) => (holLet (holWordShiftl mlabel (HolNumeral.ofNatVal (α := Nat) 12)) (fun (label : (BitVec 64)) => (holWordOr label (holWordOr extra (holWordOr unwrapped len))))))))) + +def msg_align_bits : Nat := + (HolAdd.addVal (L4vRefX64.Spec.Machine_Word_64_Basics.word_size_bits : Nat) (holLeast (fun (n : Nat) => (holLe L4vRefX64.Spec.Structures_A.max_ipc_length (HolPow.powVal (HolNumeral.ofNatVal (α := Nat) 2) n))))) + +def ntfn.is_WaitingNtfn : (L4vRefX64.Spec.Structures_A.ntfn → Bool) + | ntfn => (holEx (fun (x2 : (List (BitVec 64))) => (holEq ntfn (L4vRefX64.Spec.Structures_A.ntfn.WaitingNtfn x2)))) + +def ntfn.ntfn_badge : (L4vRefX64.Spec.Structures_A.ntfn → (BitVec 64)) + | ntfn => (L4vRefX64.Spec.Structures_A.case_ntfn (holUndefined (α := (BitVec 64))) (fun (uu : (List (BitVec 64))) => (holUndefined (α := (BitVec 64)))) (fun (x3 : (BitVec 64)) => x3) ntfn) + +def ntfn.ntfn_queue : (L4vRefX64.Spec.Structures_A.ntfn → (List (BitVec 64))) + | ntfn => (L4vRefX64.Spec.Structures_A.case_ntfn (List.nil (α := (BitVec 64))) (fun (x2 : (List (BitVec 64))) => x2) (fun (_dummy_ : (BitVec 64)) => (List.nil (α := (BitVec 64)))) ntfn) + +def obj_bits : (L4vRefX64.Spec.Structures_A.kernel_object → Nat) + | (L4vRefX64.Spec.Structures_A.kernel_object.CNode sz cs) => (HolAdd.addVal L4vRefX64.Spec.Arch_Structs_A.cte_level_bits sz) + | (L4vRefX64.Spec.Structures_A.kernel_object.TCB t) => L4vRefX64.Spec.Arch_Structs_A.tcb_bits + | (L4vRefX64.Spec.Structures_A.kernel_object.Endpoint ep) => L4vRefX64.Spec.Arch_Structs_A.endpoint_bits + | (L4vRefX64.Spec.Structures_A.kernel_object.Notification ntfn) => L4vRefX64.Spec.Arch_Structs_A.ntfn_bits + | (L4vRefX64.Spec.Structures_A.kernel_object.SchedContext sc n) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat) n) + | (L4vRefX64.Spec.Structures_A.kernel_object.Reply r) => L4vRefX64.Spec.Arch_Structs_A.reply_bits + | (L4vRefX64.Spec.Structures_A.kernel_object.ArchObj ao) => (L4vRefX64.Spec.Arch_Structs_A.arch_kobj_size ao) + +def obj_ref_of : (L4vRefX64.Spec.Structures_A.cap → (BitVec 64)) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev r s f) => r + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap r uu) => r + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap r bits guard) => r + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap r b cr) => r + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap r b cr) => r + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap r) => r + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap r bits) => r + | (L4vRefX64.Spec.Structures_A.cap.Zombie ptr b n) => ptr + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap x) => (holTheOpt (L4vRefX64.Spec.Arch_Structs_A.aobj_ref x)) + | _ => holUndefined + +def obj_refs : (L4vRefX64.Spec.Structures_A.cap → (Set (BitVec 64))) + | L4vRefX64.Spec.Structures_A.cap.NullCap => (HolCompleteLattice.holBot (α := (Set (BitVec 64)))) + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap r uu) => (holInsert r (HolCompleteLattice.holBot (α := (Set (BitVec 64))))) + | L4vRefX64.Spec.Structures_A.cap.IRQControlCap => (HolCompleteLattice.holBot (α := (Set (BitVec 64)))) + | (L4vRefX64.Spec.Structures_A.cap.IRQHandlerCap irq) => (HolCompleteLattice.holBot (α := (Set (BitVec 64)))) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev r s f) => (HolCompleteLattice.holBot (α := (Set (BitVec 64)))) + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap r bits guard) => (holInsert r (HolCompleteLattice.holBot (α := (Set (BitVec 64))))) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap r b cr) => (holInsert r (HolCompleteLattice.holBot (α := (Set (BitVec 64))))) + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap r b cr) => (holInsert r (HolCompleteLattice.holBot (α := (Set (BitVec 64))))) + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap r) => (holInsert r (HolCompleteLattice.holBot (α := (Set (BitVec 64))))) + | L4vRefX64.Spec.Structures_A.cap.DomainCap => (HolCompleteLattice.holBot (α := (Set (BitVec 64)))) + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap r bits) => (holInsert r (HolCompleteLattice.holBot (α := (Set (BitVec 64))))) + | L4vRefX64.Spec.Structures_A.cap.SchedControlCap => (HolCompleteLattice.holBot (α := (Set (BitVec 64)))) + | (L4vRefX64.Spec.Structures_A.cap.Zombie ptr b n) => (holInsert ptr (HolCompleteLattice.holBot (α := (Set (BitVec 64))))) + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap x) => (holSetOption (L4vRefX64.Spec.Arch_Structs_A.aobj_ref x)) + +def obj_size : (L4vRefX64.Spec.Structures_A.cap → (BitVec 64)) + | L4vRefX64.Spec.Structures_A.cap.NullCap => (HolZero.zeroVal (α := (BitVec 64))) + | (L4vRefX64.Spec.Structures_A.cap.UntypedCap dev r bits f) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) bits) + | (L4vRefX64.Spec.Structures_A.cap.EndpointCap r b R) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.Endpoint (holUndefined (α := L4vRefX64.Spec.Structures_A.endpoint))))) + | (L4vRefX64.Spec.Structures_A.cap.NotificationCap r b R) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.Notification (holUndefined (α := (L4vRefX64.Spec.Structures_A.notification_ext Unit)))))) + | (L4vRefX64.Spec.Structures_A.cap.CNodeCap r bits g) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (HolAdd.addVal L4vRefX64.Spec.Arch_Structs_A.cte_level_bits bits)) + | (L4vRefX64.Spec.Structures_A.cap.ThreadCap r) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.TCB (holUndefined (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))))) + | (L4vRefX64.Spec.Structures_A.cap.SchedContextCap r bits) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (HolAdd.addVal (L4vRefX64.Spec.Structures_A.min_sched_context_bits : Nat) bits)) + | (L4vRefX64.Spec.Structures_A.cap.ReplyCap r uu) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.Reply (holUndefined (α := (L4vRefX64.Spec.Structures_A.reply_ext Unit)))))) + | (L4vRefX64.Spec.Structures_A.cap.Zombie r zb n) => (holCaseOption (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.Structures_A.obj_bits (L4vRefX64.Spec.Structures_A.kernel_object.TCB (holUndefined (α := (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))))) (fun (n_1 : Nat) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (HolAdd.addVal L4vRefX64.Spec.Arch_Structs_A.cte_level_bits n_1))) zb) + | (L4vRefX64.Spec.Structures_A.cap.ArchObjectCap a) => (holWordShiftl (HolOne.oneVal (α := (BitVec 64))) (L4vRefX64.Spec.Arch_Structs_A.arch_obj_size a)) + | _ => holUndefined + +def reply_object : (L4vRefX64.Spec.Structures_A.thread_state → (Option (BitVec 64))) + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReceive uu reply_opt uv) => reply_opt + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReply reply) => (Option.some reply) + | L4vRefX64.Spec.Structures_A.thread_state.Running => (Option.none (α := (BitVec 64))) + | L4vRefX64.Spec.Structures_A.thread_state.Inactive => (Option.none (α := (BitVec 64))) + | L4vRefX64.Spec.Structures_A.thread_state.Restart => (Option.none (α := (BitVec 64))) + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnSend v va) => (Option.none (α := (BitVec 64))) + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnNotification v) => (Option.none (α := (BitVec 64))) + | L4vRefX64.Spec.Structures_A.thread_state.IdleThreadState => (Option.none (α := (BitVec 64))) + +def runnable : (L4vRefX64.Spec.Structures_A.thread_state → Bool) + | L4vRefX64.Spec.Structures_A.thread_state.Running => true + | L4vRefX64.Spec.Structures_A.thread_state.Inactive => false + | L4vRefX64.Spec.Structures_A.thread_state.Restart => true + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReceive uu uv uw) => false + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnSend ux uy) => false + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnNotification uz) => false + | L4vRefX64.Spec.Structures_A.thread_state.IdleThreadState => false + | (L4vRefX64.Spec.Structures_A.thread_state.BlockedOnReply va) => false + +def sc_sporadic_flag {tv_a : Type} [Nonempty tv_a] [HolZero tv_a] : tv_a := + (HolZero.zeroVal (α := tv_a)) + +def scheduler_action.sch_act_target : (L4vRefX64.Spec.Structures_A.scheduler_action → (BitVec 64)) + | scheduler_action => (L4vRefX64.Spec.Structures_A.case_scheduler_action (holUndefined (α := (BitVec 64))) (fun (x2 : (BitVec 64)) => x2) (holUndefined (α := (BitVec 64))) scheduler_action) + +def word_to_tcb_flags : ((BitVec 64) → (Set L4vRefX64.Spec.Structs_B.tcb_flag)) := + (fun (w : (BitVec 64)) => (holCollect (fun (flag : L4vRefX64.Spec.Structs_B.tcb_flag) => (holNot (holEq (holWordAnd w (holWordAnd (L4vRefX64.Spec.Structs_B.tcbFlagToWord flag) L4vRefX64.Spec.Structs_B.tcbFlagMask)) (HolZero.zeroVal (α := (BitVec 64)))))))) + +def tcb_flags_to_word : ((Set L4vRefX64.Spec.Structs_B.tcb_flag) → (BitVec 64)) := + (fun (flags : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holThe (fun (w : (BitVec 64)) => (holConj (holEq (L4vRefX64.Spec.Structures_A.word_to_tcb_flags w) flags) (holEq (holWordAnd w (holWordNot L4vRefX64.Spec.Structs_B.tcbFlagMask)) (HolZero.zeroVal (α := (BitVec 64)))))))) + +def the_cnode_cap : (L4vRefX64.Spec.Structures_A.cap → ((BitVec 64) × (Nat × (List Bool)))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (L4vRefX64.Spec.Structures_A.case_cap (holUndefined (α := ((BitVec 64) × (Nat × (List Bool))))) (fun (a : Bool) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : Nat) => (fun (a_3 : Nat) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool))))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool)))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (BitVec 64)) => (fun (a_2 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool)))))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool))))))) (fun (oref : (BitVec 64)) => (fun (bits : Nat) => (fun (guard : (List Bool)) => (Prod.mk oref (Prod.mk bits guard))))) (fun (a : (BitVec 64)) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool)))))) (holUndefined (α := ((BitVec 64) × (Nat × (List Bool))))) (fun (a : (BitVec 64)) => (fun (a_1 : Nat) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool))))))) (holUndefined (α := ((BitVec 64) × (Nat × (List Bool))))) (holUndefined (α := ((BitVec 64) × (Nat × (List Bool))))) (fun (a : (BitVec 8)) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool)))))) (fun (a : (BitVec 64)) => (fun (a_1 : (Option Nat)) => (fun (a_2 : Nat) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool)))))))) (fun (a : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => (holUndefined (α := ((BitVec 64) × (Nat × (List Bool)))))) cap)) +end +end L4vRefX64.Spec.Structures_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Syscall_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Syscall_A.lean new file mode 100644 index 000000000..9db652afa --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Syscall_A.lean @@ -0,0 +1,86 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Syscall_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.CapRights_A +import L4vRefX64.Spec.Decode_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Event_H +import L4vRefX64.Spec.ExceptionTypes_A +import L4vRefX64.Spec.Exceptions_A +import L4vRefX64.Spec.Hypervisor_A +import L4vRefX64.Spec.Interrupt_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.Ipc_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Retype_A +import L4vRefX64.Spec.Schedule_A +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.TcbAcc_A +import L4vRefX64.Spec.Tcb_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Syscall_A +open L4vRefX64.Prim +open Classical +noncomputable section +def get_cap_reg {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.MachineTypes.register → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List Bool) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (reg : L4vRefX64.Spec.MachineTypes.register) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct : (BitVec 64)) => (holFunApp (holLiftM L4vRefX64.Spec.Machine_A.data_to_cptr) (holFunApp (L4vRefX64.Spec.KHeap_A.as_user ct) (L4vRefX64.Spec.MachineOps.getRegister reg)))))) + +def perform_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → (Bool → (Bool → (L4vRefX64.Spec.Invocations_A.invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit (List (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) + | uu, uv, uw, (L4vRefX64.Spec.Invocations_A.invocation.InvokeUntyped i) => (holBindE (L4vRefX64.Spec.Retype_A.invoke_untyped i) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))) + | block, call, can_donate, (L4vRefX64.Spec.Invocations_A.invocation.InvokeEndpoint ep badge can_grant can_grant_reply) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.Ipc_A.send_ipc block call badge can_grant can_grant_reply can_donate thread ep) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))) + | ux, uy, uz, (L4vRefX64.Spec.Invocations_A.invocation.InvokeNotification ep badge) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Ipc_A.send_signal ep badge)) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))) + | va, vb, vc, (L4vRefX64.Spec.Invocations_A.invocation.InvokeTCB i) => (L4vRefX64.Spec.Tcb_A.invoke_tcb i) + | vd, ve, vf, (L4vRefX64.Spec.Invocations_A.invocation.InvokeDomain dom_inv) => ((holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.Tcb_A.invoke_domain dom_inv) (holKBind (holReturn (List.nil (α := (BitVec 64))))))) + | vg, vh, vi, (L4vRefX64.Spec.Invocations_A.invocation.InvokeReply reply grant) => ((holLiftE (ε := Unit)) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (sender : (BitVec 64)) => (holBind (L4vRefX64.Spec.Ipc_A.do_reply_transfer sender reply grant) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))) + | vj, vk, vl, (L4vRefX64.Spec.Invocations_A.invocation.InvokeCNode i) => (holBindE (L4vRefX64.Spec.CSpace_A.invoke_cnode i) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))) + | vm, vn, vo, (L4vRefX64.Spec.Invocations_A.invocation.InvokeIRQControl i) => (holBindE (L4vRefX64.Spec.Interrupt_A.invoke_irq_control i) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))) + | vp, vq, vr, (L4vRefX64.Spec.Invocations_A.invocation.InvokeIRQHandler i) => (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Interrupt_A.invoke_irq_handler i)) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))) + | vs, vt, vu, (L4vRefX64.Spec.Invocations_A.invocation.InvokeSchedContext i) => (L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Schedule_A.invoke_sched_context i)) + | vv, vw, vx, (L4vRefX64.Spec.Invocations_A.invocation.InvokeSchedControl i) => (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Ipc_A.invoke_sched_control_configure_flags i)) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))) + | vy, vz, wa, (L4vRefX64.Spec.Invocations_A.invocation.InvokeArchObject i) => (L4vRefX64.Spec.Arch_A.arch_perform_invocation i) + +def syscall {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] {tv_a : Type} [Nonempty tv_a] {tv_c : Type} [Nonempty tv_c] {tv_b : Type} [Nonempty tv_b] : (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.fault tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.ExceptionTypes_A.fault → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_c × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) → ((tv_a → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error tv_b) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) → ((L4vRefX64.Spec.ExceptionTypes_A.syscall_error → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_c × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) → ((tv_b → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit tv_c) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit tv_c) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (m_fault : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.fault tv_a) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (fun (h_fault : (L4vRefX64.Spec.ExceptionTypes_A.fault → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_c × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) => (fun (m_error : (tv_a → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error tv_b) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) => (fun (h_error : (L4vRefX64.Spec.ExceptionTypes_A.syscall_error → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (tv_c × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) => (fun (m_finalise : (tv_b → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit tv_c) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption m_fault) (fun (r_fault : (Sum L4vRefX64.Spec.ExceptionTypes_A.fault tv_a)) => (holCaseSum (fun (f : L4vRefX64.Spec.ExceptionTypes_A.fault) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (h_fault f))) (fun (a : tv_a) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (m_error a)) (fun (r_error : (Sum L4vRefX64.Spec.ExceptionTypes_A.syscall_error tv_b)) => (holCaseSum (fun (e : L4vRefX64.Spec.ExceptionTypes_A.syscall_error) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (h_error e))) (fun (b : tv_b) => (m_finalise b)) r_error)))) r_fault)))))))) + +def handle_invocation {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → (Bool → (Bool → (Bool → ((List Bool) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (calling : Bool) => (fun (blocking : Bool) => (fun (can_donate : Bool) => (fun (first_phase : Bool) => (fun (cptr : (List Bool)) => (holBindE (holFunApp (holLiftE (ε := Unit)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (thread : (BitVec 64)) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Ipc_A.get_message_info thread)) (fun (info : L4vRefX64.Spec.Structures_A.message_info) => (L4vRefX64.Spec.Syscall_A.syscall (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.cap_fault_on_failure ((holOfBl (w := 64)) cptr) false) (L4vRefX64.Spec.CSpace_A.lookup_cap_and_slot thread cptr)) (holCaseProd (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (L4vRefX64.Spec.ArchVSpace_A.lookup_ipc_buffer false thread)) (fun (buffer : (Option (BitVec 64))) => (holBindE (L4vRefX64.Spec.Ipc_A.lookup_extra_caps thread buffer info) (fun (extracaps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (Prod.mk slot (Prod.mk cap (Prod.mk extracaps buffer)))))))))))) (fun (fault : L4vRefX64.Spec.ExceptionTypes_A.fault) => (holFunApp (holWhen blocking) (L4vRefX64.Spec.Ipc_A.handle_fault thread fault))) (holCaseProd (fun (slot : ((BitVec 64) × (List Bool))) => (holCaseProd (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holCaseProd (fun (extracaps : (List (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (fun (buffer : (Option (BitVec 64))) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.syscall_error)) (L4vRefX64.Spec.Tcb_A.get_mrs thread buffer info)) (fun (args : (List (BitVec 64))) => (L4vRefX64.Spec.Decode_A.decode_invocation first_phase (L4vRefX64.Spec.Structures_A.message_info.mi_label info) args cptr slot cap extracaps buffer)))))))))) (fun (err : L4vRefX64.Spec.ExceptionTypes_A.syscall_error) => (holFunApp (holWhen calling) (holFunApp (L4vRefX64.Spec.TcbAcc_A.reply_from_kernel thread) (L4vRefX64.Spec.ExceptionTypes_A.msg_from_syscall_error err)))) (fun (oper : L4vRefX64.Spec.Invocations_A.invocation) => (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.KHeap_A.set_thread_state thread L4vRefX64.Spec.Structures_A.thread_state.Restart)) (holKBind (holBindE (L4vRefX64.Spec.Syscall_A.perform_invocation blocking calling can_donate oper) (fun (reply : (List (BitVec 64))) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state thread) (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (L4vRefX64.Spec.Structures_A.case_thread_state (holReturn ()) (holReturn ()) (holBind (holFunApp (holWhen calling) (L4vRefX64.Spec.TcbAcc_A.reply_from_kernel thread (Prod.mk (HolZero.zeroVal (α := (BitVec 64))) reply))) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state thread L4vRefX64.Spec.Structures_A.thread_state.Running))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (fun (receiver_payload_ext : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holReturn ())))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holReturn ()))) (fun (word : (BitVec 64)) => (holReturn ())) (fun (word : (BitVec 64)) => (holReturn ())) (holReturn ()) state))))))))))))))))))) + +def handle_call {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Syscall_A.get_cap_reg L4vRefX64.Spec.Machine_A.cap_register)) (fun (cptr : (List Bool)) => (L4vRefX64.Spec.Syscall_A.handle_invocation true true true false cptr))) + +def lookup_reply {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.fault L4vRefX64.Spec.Structures_A.cap) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (L4vRefX64.Spec.Syscall_A.get_cap_reg L4vRefX64.Spec.MachineTypes.replyRegister)) (fun (cref : (List Bool)) => (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (ct : (BitVec 64)) => (holBindE (holFunApp (L4vRefX64.Spec.Exceptions_A.cap_fault_on_failure ((holOfBl (w := 64)) cref) true) (L4vRefX64.Spec.CSpace_A.lookup_cap ct cref)) (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (holIf (L4vRefX64.Spec.Structures_A.is_reply_cap cap) ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) cap) (holFunApp (holThrowError (α := L4vRefX64.Spec.Structures_A.cap)) (L4vRefX64.Spec.ExceptionTypes_A.fault.CapFault ((holOfBl (w := 64)) cref) true (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability (HolZero.zeroVal (α := Nat)))))))))))) + +def handle_recv {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (is_blocking : Bool) => (fun (can_reply : Bool) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (thread : (BitVec 64)) => (holBind (holFunApp (holLiftM L4vRefX64.Spec.Machine_A.data_to_cptr) (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (L4vRefX64.Spec.MachineOps.getRegister L4vRefX64.Spec.Machine_A.cap_register))) (fun (ep_cptr : (List Bool)) => (holCatch (holBindE (L4vRefX64.Spec.Exceptions_A.cap_fault_on_failure ((holOfBl (w := 64)) ep_cptr) true (L4vRefX64.Spec.CSpace_A.lookup_cap thread ep_cptr)) (fun (ep_cap : L4vRefX64.Spec.Structures_A.cap) => (holLet (holFunApp (holThrowError (α := Unit)) (L4vRefX64.Spec.ExceptionTypes_A.fault.CapFault ((holOfBl (w := 64)) ep_cptr) true (L4vRefX64.Spec.ExceptionTypes_A.lookup_failure.MissingCapability (HolZero.zeroVal (α := Nat))))) (fun (flt : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum L4vRefX64.Spec.ExceptionTypes_A.fault Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (L4vRefX64.Spec.Structures_A.case_cap flt (fun (bool : Bool) => (fun (word : (BitVec 64)) => (fun (nat1 : Nat) => (fun (nat2 : Nat) => flt)))) (fun (ref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holMember L4vRefX64.Spec.CapRights_A.AllowRecv rights) (holBindE (holIf can_reply L4vRefX64.Spec.Syscall_A.lookup_reply ((holReturnOk (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) L4vRefX64.Spec.Structures_A.cap.NullCap)) (fun (reply_cap : L4vRefX64.Spec.Structures_A.cap) => (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (L4vRefX64.Spec.Ipc_A.receive_ipc thread ep_cap is_blocking reply_cap)))) flt)))) (fun (ref : (BitVec 64)) => (fun (badge : (BitVec 64)) => (fun (rights : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holMember L4vRefX64.Spec.CapRights_A.AllowRecv rights) (holBindE (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (L4vRefX64.Spec.KHeap_A.get_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification_ext.ntfn_bound_tcb ref)) (fun (boundTCB : (Option (BitVec 64))) => (holIf (holDisj (holEq boundTCB (Option.some thread)) (holEq boundTCB (Option.none (α := (BitVec 64))))) (holFunApp (holLiftE (ε := L4vRefX64.Spec.ExceptionTypes_A.fault)) (L4vRefX64.Spec.Ipc_A.receive_signal thread ep_cap is_blocking)) flt))) flt)))) (fun (word : (BitVec 64)) => (fun (v_set : (Set L4vRefX64.Spec.CapRights_A.rights)) => flt)) (fun (word : (BitVec 64)) => (fun (nat : Nat) => (fun (list : (List Bool)) => flt))) (fun (word : (BitVec 64)) => flt) flt (fun (word : (BitVec 64)) => (fun (nat : Nat) => flt)) flt flt (fun (word : (BitVec 8)) => flt) (fun (word : (BitVec 64)) => (fun (option : (Option Nat)) => (fun (nat : Nat) => flt))) (fun (arch_cap : L4vRefX64.Spec.Arch_Structs_A.arch_cap) => flt) ep_cap))))) (L4vRefX64.Spec.Ipc_A.handle_fault thread)))))))) + +def handle_send {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (Bool → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (bl : Bool) => (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.Syscall_A.get_cap_reg L4vRefX64.Spec.Machine_A.cap_register)) (fun (cptr : (List Bool)) => (L4vRefX64.Spec.Syscall_A.handle_invocation false bl false false cptr)))) + +def handle_yield {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (cur_sc : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sched_context cur_sc) (fun (sc : (L4vRefX64.Spec.Structures_A.sched_context_ext Unit)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.consumed_time) (fun (consumed : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_refill_head cur_sc) (fun (head : (L4vRefX64.Spec.Structures_A.refill_ext Unit)) => (holBind (L4vRefX64.Spec.Ipc_A.charge_budget (L4vRefX64.Spec.Structures_A.refill_ext.r_amount head) false) (holKBind (L4vRefX64.Spec.KHeap_A.update_sched_context cur_sc (L4vRefX64.Spec.Structures_A.sched_context.sc_consumed_update (fun (uu_ : (BitVec 64)) => (HolAdd.addVal (L4vRefX64.Spec.Structures_A.sched_context_ext.sc_consumed sc) consumed)))))))))))))) + +def handle_event {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Event_H.event → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Event_H.event.SyscallEvent call) => (holBindE (holFunApp (holLiftE (ε := Unit)) L4vRefX64.Spec.KHeap_A.update_time_stamp) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) L4vRefX64.Spec.Ipc_A.check_budget_restart) (fun (restart : Bool) => (holWhenE restart (L4vRefX64.Spec.Event_H.case_syscall L4vRefX64.Spec.Syscall_A.handle_call (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.get_cap_reg L4vRefX64.Spec.MachineTypes.replyRegister)) (fun (reply_cptr : (List Bool)) => (holBindE (L4vRefX64.Spec.Syscall_A.handle_invocation false false true true reply_cptr) (holKBind (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.handle_recv true true)))))) (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.get_cap_reg L4vRefX64.Spec.MachineTypes.nbsendRecvDest)) (fun (dest : (List Bool)) => (holBindE (L4vRefX64.Spec.Syscall_A.handle_invocation false false true true dest) (holKBind (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.handle_recv true true)))))) (holBindE (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.get_cap_reg L4vRefX64.Spec.MachineTypes.replyRegister)) (fun (reply_cptr : (List Bool)) => (holBindE (L4vRefX64.Spec.Syscall_A.handle_invocation false false true true reply_cptr) (holKBind (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.handle_recv true false)))))) (L4vRefX64.Spec.Syscall_A.handle_send true) (L4vRefX64.Spec.Syscall_A.handle_send false) (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.handle_recv true true)) (L4vRefX64.Spec.Exceptions_A.without_preemption L4vRefX64.Spec.Syscall_A.handle_yield) (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.handle_recv false true)) (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.handle_recv true false)) (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (L4vRefX64.Spec.Syscall_A.handle_recv false false)) call)))))) + | (L4vRefX64.Spec.Event_H.event.UnknownSyscall n) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holBind L4vRefX64.Spec.KHeap_A.update_time_stamp (holKBind (holBind L4vRefX64.Spec.Ipc_A.check_budget_restart (fun (restart : Bool) => (holFunApp (holWhen restart) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (thread : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.Ipc_A.handle_fault thread) (holFunApp L4vRefX64.Spec.ExceptionTypes_A.fault.UnknownSyscallException ((holOfNat (α := (BitVec 64))) n))))))))))) + | (L4vRefX64.Spec.Event_H.event.UserLevelFault w1 w2) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holBind L4vRefX64.Spec.KHeap_A.update_time_stamp (holKBind (holBind L4vRefX64.Spec.Ipc_A.check_budget_restart (fun (restart : Bool) => (holFunApp (holWhen restart) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (thread : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.Ipc_A.handle_fault thread) (L4vRefX64.Spec.ExceptionTypes_A.fault.UserException (holWordAnd w1 ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 32))) (holWordAnd w2 ((holWordMask (w := 64)) (HolNumeral.ofNatVal (α := Nat) 28))))))))))))) + | L4vRefX64.Spec.Event_H.event.Interrupt => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holBind L4vRefX64.Spec.KHeap_A.update_time_stamp (holKBind (holBind L4vRefX64.Spec.Ipc_A.check_budget (holKBind (L4vRefX64.Spec.Interrupt_A.maybe_handle_interrupt false)))))) + | (L4vRefX64.Spec.Event_H.event.VMFaultEvent fault_type) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holBind L4vRefX64.Spec.KHeap_A.update_time_stamp (holKBind (holBind L4vRefX64.Spec.Ipc_A.check_budget_restart (fun (restart : Bool) => (holFunApp (holWhen restart) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (thread : (BitVec 64)) => (holCatch (L4vRefX64.Spec.ArchVSpace_A.handle_vm_fault thread fault_type) (L4vRefX64.Spec.Ipc_A.handle_fault thread)))))))))) + | (L4vRefX64.Spec.Event_H.event.HypervisorEvent hypfault_type) => (holFunApp L4vRefX64.Spec.Exceptions_A.without_preemption (holBind L4vRefX64.Spec.KHeap_A.update_time_stamp (holKBind (holBind L4vRefX64.Spec.Ipc_A.check_budget_restart (fun (restart : Bool) => (holFunApp (holWhen restart) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (thread : (BitVec 64)) => (L4vRefX64.Spec.Hypervisor_A.handle_hypervisor_fault thread hypfault_type))))))))) + +def preemption_path {tv_a : Type} [Nonempty tv_a] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_a] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (ct : (BitVec 64)) => (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable ct)) (fun (schedulable : Bool) => (holBind (holIf schedulable (holBind L4vRefX64.Spec.Ipc_A.check_budget (holKBind (holReturn ()))) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_sc) (fun (csc : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_sc_active csc) (fun (active : Bool) => (holIf active (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.consumed_time) (fun (consumed : (BitVec 64)) => (L4vRefX64.Spec.Ipc_A.charge_budget consumed false))) (holModify (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_a Unit))) => (L4vRefX64.Spec.Structures_A.abstract_state.consumed_time_update (fun (uu_ : (BitVec 64)) => (HolZero.zeroVal (α := (BitVec 64)))) s))))))))) (holKBind (L4vRefX64.Spec.Interrupt_A.maybe_handle_interrupt true))))))) + +def call_kernel {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Event_H.event → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (ev : L4vRefX64.Spec.Event_H.event) => (holBind (holHandleE (L4vRefX64.Spec.Syscall_A.handle_event ev) (fun (uu_ : Unit) => (L4vRefX64.Spec.Exceptions_A.without_preemption L4vRefX64.Spec.Syscall_A.preemption_path))) (holKBind (holBind L4vRefX64.Spec.Schedule_A.schedule (holKBind L4vRefX64.Spec.Tcb_A.activate_thread))))) +end +end L4vRefX64.Spec.Syscall_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/TcbAcc_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/TcbAcc_A.lean new file mode 100644 index 000000000..d5e2bf94f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/TcbAcc_A.lean @@ -0,0 +1,33 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.TcbAcc_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchCSpace_A +import L4vRefX64.Spec.ArchVSpace_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.Structures_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.TcbAcc_A +open L4vRefX64.Prim +open Classical +noncomputable section +def set_message_info {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (L4vRefX64.Spec.Structures_A.message_info → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (info : L4vRefX64.Spec.Structures_A.message_info) => (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (holFunApp (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.msg_info_register) (L4vRefX64.Spec.Structures_A.message_info_to_data info))))) + +def store_word_offs {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Nat → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (ptr : (BitVec 64)) => (fun (offs : Nat) => (fun (v : (BitVec 64)) => (holBind (holGet : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (fun (s : (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit))) => (holBind (holAssert (L4vRefX64.Spec.ArchVSpace_A.in_user_frame (HolAdd.addVal ptr ((holOfNat (α := (BitVec 64))) (HolMul.mulVal offs (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : Nat)))) s)) (holKBind (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.storeWord (HolAdd.addVal ptr ((holOfNat (α := (BitVec 64))) (HolMul.mulVal offs (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : Nat)))) v))))))))) + +def set_mrs {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Option (BitVec 64)) → ((List (BitVec 64)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (thread : (BitVec 64)) => (fun (buf : (Option (BitVec 64))) => (fun (msgs : (List (BitVec 64))) => (holBind (holFunApp holGetsThe (L4vRefX64.Spec.KHeap_A.get_tcb thread)) (fun (tcb : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (holBind (holReturn (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_get_registers (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_arch tcb))) (fun (context : (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) => (holBind (holReturn (fun (reg : L4vRefX64.Spec.MachineTypes.register) => (holIf (holMember reg (holListSet (holListTake (holSize msgs) L4vRefX64.Spec.Machine_A.msg_registers))) (holNth msgs (holTheIndex L4vRefX64.Spec.Machine_A.msg_registers reg)) (context reg)))) (fun (new_regs : (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) => (holBind (L4vRefX64.Spec.KHeap_A.set_object thread (L4vRefX64.Spec.Structures_A.kernel_object.TCB (L4vRefX64.Spec.Structures_A.tcb.tcb_arch_update (fun (uu_ : (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_ext Unit)) => (L4vRefX64.Spec.Arch_Structs_A.arch_tcb_set_registers new_regs (L4vRefX64.Spec.Structures_A.tcb_ext.tcb_arch tcb))) tcb))) (holKBind (holBind (holReturn (holListDrop (holSize L4vRefX64.Spec.Machine_A.msg_registers) msgs)) (fun (remaining_msgs : (List (BitVec 64))) => (holCaseOption (holFunApp holReturn (L4vRefX64.Spec.Machine_A.nat_to_len (holMin (holSize L4vRefX64.Spec.Machine_A.msg_registers) (holSize msgs)))) (fun (pptr : (BitVec 64)) => (holBind (holZipWithMx (fun (x : Nat) => (L4vRefX64.Spec.TcbAcc_A.store_word_offs pptr x)) (holListUpt (HolAdd.addVal (holSize L4vRefX64.Spec.Machine_A.msg_registers) (HolOne.oneVal (α := Nat))) (Nat.succ L4vRefX64.Spec.Structures_A.msg_max_length)) remaining_msgs) (holKBind (holFunApp holReturn (holFunApp L4vRefX64.Spec.Machine_A.nat_to_len (holMin (holSize msgs) L4vRefX64.Spec.Structures_A.msg_max_length)))))) buf)))))))))))))) + +def reply_from_kernel {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 64) × (List (BitVec 64))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (x : ((BitVec 64) × (List (BitVec 64)))) => (holBind (holReturn x) (holCaseProd (fun (label : (BitVec 64)) => (fun (msg : (List (BitVec 64))) => (holBind (L4vRefX64.Spec.ArchVSpace_A.lookup_ipc_buffer true thread) (fun (buf : (Option (BitVec 64))) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.Machine_A.badge_register (HolZero.zeroVal (α := (BitVec 64))))) (holKBind (holBind (L4vRefX64.Spec.TcbAcc_A.set_mrs thread buf msg) (fun (len : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.TcbAcc_A.set_message_info thread) (L4vRefX64.Spec.Structures_A.message_info.MI len (HolZero.zeroVal (α := (BitVec 64))) (HolZero.zeroVal (α := (BitVec 64))) label)))))))))))))) +end +end L4vRefX64.Spec.TcbAcc_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Tcb_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Tcb_A.lean new file mode 100644 index 000000000..4682670c4 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Tcb_A.lean @@ -0,0 +1,97 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.Tcb_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.ArchTcb_A +import L4vRefX64.Spec.Arch_A +import L4vRefX64.Spec.Arch_Structs_A +import L4vRefX64.Spec.CSpaceAcc_A +import L4vRefX64.Spec.CSpace_A +import L4vRefX64.Spec.Deterministic_A +import L4vRefX64.Spec.Invocations_A +import L4vRefX64.Spec.IpcCancel_A +import L4vRefX64.Spec.KHeap_A +import L4vRefX64.Spec.MachineOps +import L4vRefX64.Spec.MachineTypes +import L4vRefX64.Spec.Machine_A +import L4vRefX64.Spec.Machine_Word_64_Basics +import L4vRefX64.Spec.SchedContext_A +import L4vRefX64.Spec.Schedule_A +import L4vRefX64.Spec.Sporadic_A +import L4vRefX64.Spec.Structs_B +import L4vRefX64.Spec.Structures_A +import L4vRefX64.Spec.TcbAcc_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Tcb_A +open L4vRefX64.Prim +open Classical +noncomputable section +def activate_thread {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) := + (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_yield_to thread) (fun (yt_opt : (Option (BitVec 64))) => (holBind (holFunApp (holWhen (holNot (holEq yt_opt (Option.none (α := (BitVec 64)))))) (L4vRefX64.Spec.SchedContext_A.complete_yield_to thread)) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state thread) (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (L4vRefX64.Spec.Structures_A.case_thread_state (holReturn ()) (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) (holBind (L4vRefX64.Spec.KHeap_A.as_user thread L4vRefX64.Spec.MachineOps.getRestartPC) (fun (pc : (BitVec 64)) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user thread) (L4vRefX64.Spec.MachineOps.setNextPC pc)) (holKBind (L4vRefX64.Spec.KHeap_A.set_thread_state thread L4vRefX64.Spec.Structures_A.thread_state.Running))))) (fun (word : (BitVec 64)) => (fun (option : (Option (BitVec 64))) => (fun (receiver_payload_ext : (L4vRefX64.Spec.Structures_A.receiver_payload_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) (fun (word : (BitVec 64)) => (fun (sender_payload_ext : (L4vRefX64.Spec.Structures_A.sender_payload_ext Unit)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (fun (word : (BitVec 64)) => (holFail : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (L4vRefX64.Spec.Arch_A.arch_activate_idle_thread thread) state))))))))) + +def bind_notification {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tcbptr : (BitVec 64)) => (fun (ntfnptr : (BitVec 64)) => (holBind (holFunApp (fun (new : (Option (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.update_sk_obj_ref L4vRefX64.Spec.Structures_A.kernel_object.Notification L4vRefX64.Spec.Structures_A.notification.ntfn_bound_tcb_update ntfnptr new)) (Option.some tcbptr)) (holKBind (holFunApp (fun (new : (Option (BitVec 64))) => (L4vRefX64.Spec.KHeap_A.thread_set (L4vRefX64.Spec.Structures_A.tcb.tcb_bound_notification_update (fun (uu_ : (Option (BitVec 64))) => new)) tcbptr)) (Option.some ntfnptr)))))) + +def check_cap_at {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Structures_A.cap → (((BitVec 64) × (List Bool)) → (((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (cap : L4vRefX64.Spec.Structures_A.cap) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (m : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) => (holBind (L4vRefX64.Spec.CSpaceAcc_A.get_cap slot) (fun (cap_p : L4vRefX64.Spec.Structures_A.cap) => (holWhen (L4vRefX64.Spec.CSpace_A.same_object_as cap cap_p) m)))))) + +def load_word_offs {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (Nat → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (offs : Nat) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.loadWord (HolAdd.addVal ptr ((holOfNat (α := (BitVec 64))) (HolMul.mulVal offs (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : Nat)))))))) + +def copy_mrs {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Option (BitVec 64)) → ((BitVec 64) → ((Option (BitVec 64)) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))) := + (fun (sender : (BitVec 64)) => (fun (sbuf : (Option (BitVec 64))) => (fun (receiver : (BitVec 64)) => (fun (rbuf : (Option (BitVec 64))) => (fun (n : (BitVec 64)) => (holBind (holFunApp holReturn (holListTake (holUnsigned n) L4vRefX64.Spec.Machine_A.msg_registers)) (fun (hardware_mrs : (List L4vRefX64.Spec.MachineTypes.register)) => (holBind (holMapM (fun (r : L4vRefX64.Spec.MachineTypes.register) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user sender) (L4vRefX64.Spec.MachineOps.getRegister r)) (fun (v : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.KHeap_A.as_user receiver) (L4vRefX64.Spec.MachineOps.setRegister r v))))) hardware_mrs) (holKBind (holBind (holCaseProd (fun (a : (Option (BitVec 64))) => (fun (b : (Option (BitVec 64))) => (holCaseOption (holReturn (List.nil (α := Unit))) (fun (sb_ptr : (BitVec 64)) => (holCaseOption (holReturn (List.nil (α := Unit))) (fun (rb_ptr : (BitVec 64)) => (holMapM (fun (x : Nat) => (holBind (L4vRefX64.Spec.Tcb_A.load_word_offs sb_ptr x) (fun (v : (BitVec 64)) => (L4vRefX64.Spec.TcbAcc_A.store_word_offs rb_ptr x v)))) (holListUpt (HolAdd.addVal (holSize L4vRefX64.Spec.Machine_A.msg_registers) (HolOne.oneVal (α := Nat))) (Nat.succ (holUnsigned n))))) b)) a))) (Prod.mk sbuf rbuf)) (fun (buf_mrs : (List Unit)) => (holFunApp holReturn (holFunApp (holMin n) (holFunApp L4vRefX64.Spec.Machine_A.nat_to_len (HolAdd.addVal (holSize hardware_mrs) (holSize buf_mrs)))))))))))))))) + +def get_mrs {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((Option (BitVec 64)) → (L4vRefX64.Spec.Structures_A.message_info → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((List (BitVec 64)) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (thread : (BitVec 64)) => (fun (buf : (Option (BitVec 64))) => (fun (info : L4vRefX64.Spec.Structures_A.message_info) => (holBind (L4vRefX64.Spec.KHeap_A.thread_get (holComp L4vRefX64.Spec.Arch_Structs_A.arch_tcb_get_registers L4vRefX64.Spec.Structures_A.tcb_ext.tcb_arch) thread) (fun (context : (L4vRefX64.Spec.MachineTypes.register → (BitVec 64))) => (holBind (holReturn (holListMap context L4vRefX64.Spec.Machine_A.msg_registers)) (fun (cpu_mrs : (List (BitVec 64))) => (holBind (holCaseOption (holReturn (List.nil (α := (BitVec 64)))) (fun (pptr : (BitVec 64)) => (holMapM (fun (x : Nat) => (L4vRefX64.Spec.Tcb_A.load_word_offs pptr x)) (holListUpt (HolAdd.addVal (holSize L4vRefX64.Spec.Machine_A.msg_registers) (HolOne.oneVal (α := Nat))) (Nat.succ L4vRefX64.Spec.Structures_A.msg_max_length)))) buf) (fun (buf_mrs : (List (BitVec 64))) => (holReturn (holFunApp (holListTake (holUnsigned (L4vRefX64.Spec.Structures_A.message_info.mi_length info))) (holListAppend cpu_mrs buf_mrs)))))))))))) + +def get_tcb_ctable_ptr : ((BitVec 64) → ((BitVec 64) × (List Bool))) := + (fun (tcb_ref : (BitVec 64)) => (Prod.mk tcb_ref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolZero.zeroVal (α := Nat))))) + +def get_tcb_fault_handler_ptr : ((BitVec 64) → ((BitVec 64) × (List Bool))) := + (fun (tcb_ref : (BitVec 64)) => (Prod.mk tcb_ref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 3)))) + +def get_tcb_timeout_handler_ptr : ((BitVec 64) → ((BitVec 64) × (List Bool))) := + (fun (tcb_ref : (BitVec 64)) => (Prod.mk tcb_ref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 4)))) + +def get_tcb_vtable_ptr : ((BitVec 64) → ((BitVec 64) × (List Bool))) := + (fun (tcb_ref : (BitVec 64)) => (Prod.mk tcb_ref (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolOne.oneVal (α := Nat))))) + +def install_tcb_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 64) × (List Bool)) → (Nat → ((Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))) := + (fun (target : (BitVec 64)) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (n : Nat) => (fun (slot_opt : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holCaseOption ((holReturnOk (ε := Unit)) ()) (fun (a : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holCaseProd (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (holBindE (L4vRefX64.Spec.CSpace_A.cap_delete (Prod.mk target (L4vRefX64.Spec.Structures_A.tcb_cnode_index n))) (holKBind (holFunApp (holUnlessE (holEq new_cap L4vRefX64.Spec.Structures_A.cap.NullCap)) (holFunApp (holLiftE (ε := Unit)) (holFunApp (L4vRefX64.Spec.Tcb_A.check_cap_at new_cap src_slot) (holFunApp (L4vRefX64.Spec.Tcb_A.check_cap_at (L4vRefX64.Spec.Structures_A.cap.ThreadCap target) slot) (L4vRefX64.Spec.CSpace_A.cap_insert new_cap src_slot (Prod.mk target (L4vRefX64.Spec.Structures_A.tcb_cnode_index n))))))))))) a)) slot_opt))))) + +def install_tcb_frame_cap {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → (((BitVec 64) × (List Bool)) → ((Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit Unit) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (target : (BitVec 64)) => (fun (slot : ((BitVec 64) × (List Bool))) => (fun (buffer : (Option ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))))) => (holCaseOption ((holReturnOk (ε := Unit)) ()) (fun (a : ((BitVec 64) × (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))))) => (holCaseProd (fun (ptr : (BitVec 64)) => (fun (frame : (Option (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool))))) => (holBindE (L4vRefX64.Spec.CSpace_A.cap_delete (Prod.mk target (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 2)))) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (L4vRefX64.Spec.KHeap_A.thread_set (fun (t : (L4vRefX64.Spec.Structures_A.tcb_ext Unit)) => (L4vRefX64.Spec.Structures_A.tcb.tcb_ipc_buffer_update (fun (uu_ : (BitVec 64)) => ptr) t)) target)) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (holCaseOption (holReturn ()) (fun (a_1 : (L4vRefX64.Spec.Structures_A.cap × ((BitVec 64) × (List Bool)))) => (holCaseProd (fun (new_cap : L4vRefX64.Spec.Structures_A.cap) => (fun (src_slot : ((BitVec 64) × (List Bool))) => (holFunApp (L4vRefX64.Spec.Tcb_A.check_cap_at new_cap src_slot) (holFunApp (L4vRefX64.Spec.Tcb_A.check_cap_at (L4vRefX64.Spec.Structures_A.cap.ThreadCap target) slot) (L4vRefX64.Spec.CSpace_A.cap_insert new_cap src_slot (Prod.mk target (L4vRefX64.Spec.Structures_A.tcb_cnode_index (HolNumeral.ofNatVal (α := Nat) 2)))))))) a_1)) frame)) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread)) (fun (cur : (BitVec 64)) => (holFunApp (holLiftE (ε := Unit)) (holWhen (holEq target cur) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))))))))))))) a)) buffer)))) + +def set_domain {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (tptr : (BitVec 64)) => (fun (new_dom : (BitVec 8)) => (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_dequeue tptr) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.thread_set_domain tptr new_dom) (holKBind (holBind (holGets (L4vRefX64.Spec.KHeap_A.schedulable tptr)) (fun (sched : Bool) => (holBind (holFunApp (holWhen sched) (L4vRefX64.Spec.KHeap_A.tcb_sched_action L4vRefX64.Spec.KHeap_A.tcb_sched_enqueue tptr)) (holKBind (holWhen (holEq tptr cur) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))))))))))))))) + +def invoke_set_domain {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 8) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (thread : (BitVec 64)) => (fun (domain : (BitVec 8)) => (holBind (L4vRefX64.Spec.ArchTcb_A.arch_prepare_set_domain thread domain) (holKBind (L4vRefX64.Spec.Tcb_A.set_domain thread domain))))) + +def invoke_domain {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.domain_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (dom_inv : L4vRefX64.Spec.Invocations_A.domain_invocation) => (L4vRefX64.Spec.Invocations_A.case_domain_invocation (fun (thread : (BitVec 64)) => (fun (domain : (BitVec 8)) => (L4vRefX64.Spec.Tcb_A.invoke_set_domain thread domain))) (fun (index : Nat) => (L4vRefX64.Spec.Schedule_A.domain_set_start index)) (fun (index : Nat) => (fun (domain : (BitVec 8)) => (fun (duration : (BitVec 56)) => (L4vRefX64.Spec.Schedule_A.domain_schedule_configure index domain duration)))) dom_inv)) + +def restart {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) := + (fun (thread : (BitVec 64)) => (holBind (L4vRefX64.Spec.KHeap_A.get_thread_state thread) (fun (state : L4vRefX64.Spec.Structures_A.thread_state) => (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context thread) (fun (sc_opt : (Option (BitVec 64))) => (holFunApp (holWhen (holConj (holNot (L4vRefX64.Spec.Structures_A.runnable state)) (holNot (holEq state L4vRefX64.Spec.Structures_A.thread_state.IdleThreadState)))) (holBind (L4vRefX64.Spec.IpcCancel_A.cancel_ipc thread) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.set_thread_state thread L4vRefX64.Spec.Structures_A.thread_state.Restart) (holKBind (holBind (L4vRefX64.Spec.Sporadic_A.if_cond_refill_unblock_check sc_opt (Option.some false) (Option.some false)) (holKBind (holBind (holMaybeM L4vRefX64.Spec.SchedContext_A.sched_context_resume sc_opt) (holKBind (L4vRefX64.Spec.SchedContext_A.test_possible_switch_to thread))))))))))))))) + +def invoke_tcb {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : (L4vRefX64.Spec.Invocations_A.tcb_invocation → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((Sum Unit (List (BitVec 64))) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.Suspend thread) => ((holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.SchedContext_A.suspend thread) (holKBind (holReturn (List.nil (α := (BitVec 64))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.Resume thread) => ((holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.Tcb_A.restart thread) (holKBind (holReturn (List.nil (α := (BitVec 64))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlCaps target slot fault_handler timeout_handler croot vroot buffer) => (holBindE (L4vRefX64.Spec.Tcb_A.install_tcb_cap target slot (HolNumeral.ofNatVal (α := Nat) 3) fault_handler) (holKBind (holBindE (L4vRefX64.Spec.Tcb_A.install_tcb_cap target slot (HolNumeral.ofNatVal (α := Nat) 4) timeout_handler) (holKBind (holBindE (L4vRefX64.Spec.Tcb_A.install_tcb_cap target slot (HolZero.zeroVal (α := Nat)) croot) (holKBind (holBindE (L4vRefX64.Spec.Tcb_A.install_tcb_cap target slot (HolOne.oneVal (α := Nat)) vroot) (holKBind (holBindE (L4vRefX64.Spec.Tcb_A.install_tcb_frame_cap target slot buffer) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))))))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.ThreadControlSched target slot fault_handler mcp priority sc) => (holBindE (L4vRefX64.Spec.Tcb_A.install_tcb_cap target slot (HolNumeral.ofNatVal (α := Nat) 3) fault_handler) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (holMaybeM (holCaseProd (fun (newmcp : (BitVec 8)) => (fun (uu_ : (BitVec 64)) => (L4vRefX64.Spec.KHeap_A.set_mcpriority target newmcp)))) mcp)) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (holMaybeM (holCaseProd (fun (prio : (BitVec 8)) => (fun (uu_ : (BitVec 64)) => (L4vRefX64.Spec.IpcCancel_A.set_priority target prio)))) priority)) (holKBind (holBindE (holFunApp (holLiftE (ε := Unit)) (holMaybeM (holCaseOption (holBind (L4vRefX64.Spec.KHeap_A.get_tcb_obj_ref L4vRefX64.Spec.Structures_A.tcb_ext.tcb_sched_context target) (fun (sc_ptr_opt : (Option (BitVec 64))) => (holBind (holAssertOpt sc_ptr_opt) L4vRefX64.Spec.IpcCancel_A.sched_context_unbind_tcb))) (fun (sc_ptr : (BitVec 64)) => (L4vRefX64.Spec.SchedContext_A.sched_context_bind_tcb sc_ptr target))) sc)) (holKBind ((holReturnOk (ε := Unit)) (List.nil (α := (BitVec 64)))))))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.CopyRegisters dest src suspend_source resume_target transfer_frame transfer_integer transfer_arch) => (holFunApp (holLiftE (ε := Unit)) (holBind (holFunApp (holWhen suspend_source) (L4vRefX64.Spec.SchedContext_A.suspend src)) (holKBind (holBind (holFunApp (holWhen resume_target) (L4vRefX64.Spec.Tcb_A.restart dest)) (holKBind (holBind (L4vRefX64.Spec.ArchTcb_A.arch_get_sanitise_register_info dest) (fun (sanitise_info : Bool) => (holBind (holFunApp (holWhen transfer_frame) (holBind (holMapMx (fun (r : L4vRefX64.Spec.MachineTypes.register) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user src) (L4vRefX64.Spec.MachineOps.getRegister r)) (fun (v : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.KHeap_A.as_user dest) (L4vRefX64.Spec.MachineOps.setRegister r (L4vRefX64.Spec.ArchTcb_A.sanitise_register sanitise_info r v)))))) L4vRefX64.Spec.Machine_A.frame_registers) (holKBind (holBind (L4vRefX64.Spec.KHeap_A.as_user dest L4vRefX64.Spec.MachineOps.getRestartPC) (fun (pc : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.KHeap_A.as_user dest) (L4vRefX64.Spec.MachineOps.setNextPC pc))))))) (holKBind (holBind (holFunApp (holWhen transfer_integer) (holMapMx (fun (r : L4vRefX64.Spec.MachineTypes.register) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user src) (L4vRefX64.Spec.MachineOps.getRegister r)) (fun (v : (BitVec 64)) => (holFunApp (L4vRefX64.Spec.KHeap_A.as_user dest) (L4vRefX64.Spec.MachineOps.setRegister r (L4vRefX64.Spec.ArchTcb_A.sanitise_register sanitise_info r v)))))) L4vRefX64.Spec.MachineTypes.gpRegisters)) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchTcb_A.arch_post_modify_registers cur dest) (holKBind (holBind (holWhen (holEq dest cur) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))))))))))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.ReadRegisters src suspend_source n arch) => (holFunApp (holLiftE (ε := Unit)) (holBind (holFunApp (holWhen suspend_source) (L4vRefX64.Spec.SchedContext_A.suspend src)) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (self : (BitVec 64)) => (holBind (holReturn (holFunApp (holListTake (holUnsigned n)) (holListAppend L4vRefX64.Spec.Machine_A.frame_registers L4vRefX64.Spec.Machine_A.gp_registers))) (fun (regs : (List L4vRefX64.Spec.MachineTypes.register)) => (holFunApp (L4vRefX64.Spec.KHeap_A.as_user src) (holMapM L4vRefX64.Spec.MachineOps.getRegister regs))))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.WriteRegisters dest resume_target values arch) => (holFunApp (holLiftE (ε := Unit)) (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (self : (BitVec 64)) => (holBind (L4vRefX64.Spec.ArchTcb_A.arch_get_sanitise_register_info dest) (fun (b : Bool) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user dest) (holBind (holZipWithM (fun (r : L4vRefX64.Spec.MachineTypes.register) => (fun (v : (BitVec 64)) => (L4vRefX64.Spec.MachineOps.setRegister r (L4vRefX64.Spec.ArchTcb_A.sanitise_register b r v)))) (holListAppend L4vRefX64.Spec.MachineTypes.frameRegisters L4vRefX64.Spec.MachineTypes.gpRegisters) values) (holKBind (holBind L4vRefX64.Spec.MachineOps.getRestartPC L4vRefX64.Spec.MachineOps.setNextPC)))) (holKBind (holBind (L4vRefX64.Spec.ArchTcb_A.arch_post_modify_registers self dest) (holKBind (holBind (holFunApp (holWhen resume_target) (L4vRefX64.Spec.Tcb_A.restart dest)) (holKBind (holBind (holWhen (holEq dest self) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))))))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.NotificationControl tcb (Option.some ntfnptr)) => (holFunApp (holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.Tcb_A.bind_notification tcb ntfnptr) (holKBind (holReturn (List.nil (α := (BitVec 64))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.NotificationControl tcb Option.none) => (holFunApp (holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.IpcCancel_A.unbind_notification tcb) (holKBind (holReturn (List.nil (α := (BitVec 64))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.SetTLSBase tcb tls_base) => (holFunApp (holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.ArchTcb_A.arch_get_sanitise_register_info tcb) (fun (sanitise_info : Bool) => (holBind (holFunApp (L4vRefX64.Spec.KHeap_A.as_user tcb) (L4vRefX64.Spec.MachineOps.setRegister L4vRefX64.Spec.MachineTypes.tlsBaseRegister (L4vRefX64.Spec.ArchTcb_A.sanitise_register sanitise_info L4vRefX64.Spec.MachineTypes.tlsBaseRegister tls_base))) (holKBind (holBind (holGets L4vRefX64.Spec.Structures_A.abstract_state_ext.cur_thread) (fun (cur : (BitVec 64)) => (holBind (holWhen (holEq tcb cur) (L4vRefX64.Spec.KHeap_A.reschedule_required : ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) (holKBind (holReturn (List.nil (α := (BitVec 64))))))))))))) + | (L4vRefX64.Spec.Invocations_A.tcb_invocation.SetFlags tcb clearFlags setFlags) => (holFunApp (holLiftE (ε := Unit)) (holBind (L4vRefX64.Spec.KHeap_A.thread_get L4vRefX64.Spec.Structures_A.tcb_ext.tcb_flags tcb) (fun (flags : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holBind (holFunApp holReturn (HolCompleteLattice.holSup (HolSub.subVal flags clearFlags) setFlags)) (fun (new_flags : (Set L4vRefX64.Spec.Structs_B.tcb_flag)) => (holBind (L4vRefX64.Spec.KHeap_A.set_flags tcb new_flags) (holKBind (holBind (L4vRefX64.Spec.ArchTcb_A.arch_post_set_flags tcb new_flags) (holKBind (holReturn (List.cons (L4vRefX64.Spec.Structures_A.tcb_flags_to_word new_flags) (List.nil (α := (BitVec 64)))))))))))))) + +def load_word_offs_word {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((BitVec 64) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set ((BitVec 64) × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool)))) := + (fun (ptr : (BitVec 64)) => (fun (offs : (BitVec 64)) => (holFunApp L4vRefX64.Spec.Structures_A.do_machine_op (L4vRefX64.Spec.MachineOps.loadWord (HolAdd.addVal ptr (HolMul.mulVal offs (L4vRefX64.Spec.Machine_Word_64_Basics.word_size : (BitVec 64)))))))) + +def option_update_thread {tv_a : Type} [Nonempty tv_a] {tv_z : Type} [Nonempty tv_z] [L4vRefX64.Spec.Deterministic_A.state_ext_class tv_z] : ((BitVec 64) → ((tv_a → ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit))) → ((Option tv_a) → ((L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)) → ((Set (Unit × (L4vRefX64.Spec.Structures_A.abstract_state_ext (L4vRefX64.Spec.Structures_A.state_ext tv_z Unit)))) × Bool))))) := + (fun (thread : (BitVec 64)) => (fun (fn : (tv_a → ((L4vRefX64.Spec.Structures_A.tcb_ext Unit) → (L4vRefX64.Spec.Structures_A.tcb_ext Unit)))) => (holCaseOption (holReturn ()) (fun (v : tv_a) => (L4vRefX64.Spec.KHeap_A.thread_set (fn v) thread))))) +end +end L4vRefX64.Spec.Tcb_A diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Time.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Time.lean new file mode 100644 index 000000000..f056c617a --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/Time.lean @@ -0,0 +1,54 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ExecSpec.Time) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.Kernel_Config + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.Time +open L4vRefX64.Prim +open Classical +noncomputable section +def MAX_PERIOD_US : (BitVec 64) := + (HolMul.mulVal (HolMul.mulVal (HolMul.mulVal (HolNumeral.ofNatVal (α := (BitVec 64)) 60) (HolNumeral.ofNatVal (α := (BitVec 64)) 60)) (HolNumeral.ofNatVal (α := (BitVec 64)) 1000)) (HolNumeral.ofNatVal (α := (BitVec 64)) 1000)) + +opaque ticks_per_timer_unit : (BitVec 64) + +opaque timer_unit : (BitVec 64) + +def us_to_ticks : ((BitVec 64) → (BitVec 64)) := + (fun (us : (BitVec 64)) => (HolDiv.divVal (HolMul.mulVal us L4vRefX64.Spec.Time.ticks_per_timer_unit) L4vRefX64.Spec.Time.timer_unit)) + +def MAX_PERIOD : (BitVec 64) := + (L4vRefX64.Spec.Time.us_to_ticks L4vRefX64.Spec.Time.MAX_PERIOD_US) + +def MAX_RELEASE_TIME : (BitVec 64) := + (HolSub.subVal (HolNeg.negVal (HolOne.oneVal (α := (BitVec 64)))) (HolMul.mulVal (HolNumeral.ofNatVal (α := (BitVec 64)) 5) L4vRefX64.Spec.Time.MAX_PERIOD)) + +def us_in_ms : (BitVec 64) := + (HolNumeral.ofNatVal (α := (BitVec 64)) 1000) + +def time_buffer_const {tv_a : Type} [Nonempty tv_a] [HolNumeral tv_a] : tv_a := + (HolNumeral.ofNatVal (α := tv_a) 5) + +def getCurrentTime_buffer : (BitVec 64) := + (HolMul.mulVal (L4vRefX64.Spec.Time.time_buffer_const : (BitVec 64)) L4vRefX64.Spec.Time.MAX_PERIOD) + +opaque kernelWCET_us : (BitVec 64) + +def kernelWCET_ticks : (BitVec 64) := + (L4vRefX64.Spec.Time.us_to_ticks L4vRefX64.Spec.Time.kernelWCET_us) + +opaque maxTimer_us : (BitVec 64) + +opaque max_ticks_to_us : (BitVec 64) + +def max_time : (BitVec 64) := + (holMaxWord (w := 64)) + +opaque max_us_to_ticks : (BitVec 64) + +def ticks_to_us : ((BitVec 64) → (BitVec 64)) := + (fun (ticks : (BitVec 64)) => (HolDiv.divVal ticks (HolDiv.divVal L4vRefX64.Spec.Time.ticks_per_timer_unit L4vRefX64.Spec.Time.timer_unit))) +end +end L4vRefX64.Spec.Time diff --git a/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/VMRights_A.lean b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/VMRights_A.lean new file mode 100644 index 000000000..985a31985 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/L4vRefX64/Spec/VMRights_A.lean @@ -0,0 +1,30 @@ +-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl (ASpec.VMRights_A) — DO NOT EDIT +import L4vRefX64.PrimX64 +import L4vRefX64.Spec.CapRights_A + +set_option linter.unusedVariables false +set_option linter.unusedSectionVars false + +namespace L4vRefX64.Spec.VMRights_A +open L4vRefX64.Prim +open Classical +noncomputable section +def vm_kernel_only : (Set L4vRefX64.Spec.CapRights_A.rights) := + (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))) + +def vm_read_only : (Set L4vRefX64.Spec.CapRights_A.rights) := + (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowRead (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights)))) + +def vm_read_write : (Set L4vRefX64.Spec.CapRights_A.rights) := + (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowRead (holInsert L4vRefX64.Spec.CapRights_A.rights.AllowWrite (HolCompleteLattice.holBot (α := (Set L4vRefX64.Spec.CapRights_A.rights))))) + +def validate_vm_rights : ((Set L4vRefX64.Spec.CapRights_A.rights) → (Set L4vRefX64.Spec.CapRights_A.rights)) := + (fun (rs : (Set L4vRefX64.Spec.CapRights_A.rights)) => (holIf (holMember L4vRefX64.Spec.CapRights_A.rights.AllowRead rs) (holIf (holMember L4vRefX64.Spec.CapRights_A.rights.AllowWrite rs) L4vRefX64.Spec.VMRights_A.vm_read_write L4vRefX64.Spec.VMRights_A.vm_read_only) L4vRefX64.Spec.VMRights_A.vm_kernel_only)) + +def mask_vm_rights : ((Set L4vRefX64.Spec.CapRights_A.rights) → ((Set L4vRefX64.Spec.CapRights_A.rights) → (Set L4vRefX64.Spec.CapRights_A.rights))) := + (fun (V : (Set L4vRefX64.Spec.CapRights_A.rights)) => (fun (R : (Set L4vRefX64.Spec.CapRights_A.rights)) => (L4vRefX64.Spec.VMRights_A.validate_vm_rights (HolCompleteLattice.holInf V R)))) + +def valid_vm_rights : (Set (Set L4vRefX64.Spec.CapRights_A.rights)) := + (holInsert L4vRefX64.Spec.VMRights_A.vm_read_write (holInsert L4vRefX64.Spec.VMRights_A.vm_read_only (holInsert L4vRefX64.Spec.VMRights_A.vm_kernel_only (HolCompleteLattice.holBot (α := (Set (Set L4vRefX64.Spec.CapRights_A.rights))))))) +end +end L4vRefX64.Spec.VMRights_A diff --git a/proofs/Fl4SpecEquivX64/PATCHED_INVENTORY.md b/proofs/Fl4SpecEquivX64/PATCHED_INVENTORY.md new file mode 100644 index 000000000..51c880ef5 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/PATCHED_INVENTORY.md @@ -0,0 +1,149 @@ +# Patched X64 reference inventory + +The prefix `Spec.` below means `L4vRefX64.Spec.`. A row for a +factored helper or specialization names the generated containing operation. +The source locations and callee references were extracted from the Lean +definitions. Branch mappings and the reasons for the changes were checked +against the generated reference by inspection. + +The inventory contains 129 definitions ending in `_p`, with 128 across +12 `Equiv/` modules and `free_asid_select_p` in `Patched.lean`. It +includes helpers and specialized entry points used in the correspondence +suite. Some of these serve a specialized theorem or witness. + +The left side of `patched_callKernel_equiv` is `call_kernel_p` and its +hand-patched callees. The point-delta theorems check the stated differences +against generated originals. Reading the hand-written transcriptions +against those originals is part of the audit’s trusted computing base. + +| Patched definition | Generated reference | Reason for the wrapper | +| --- | --- | --- | +| [`ArchDecode.lean:102`](L4vRefX64/Equiv/ArchDecode.lean#L102) `table_mapping_p` | [`Spec.ArchDecode_A.decode_page_table_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L60), [`Spec.ArchDecode_A.decode_page_directory_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L51), [`Spec.ArchDecode_A.decode_pdpt_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L63) (Map argument, alignment and root checks) | Factored map checks and continuation used by `table_decoder_p`. The checks themselves retain the original operations | +| [`ArchDecode.lean:173`](L4vRefX64/Equiv/ArchDecode.lean#L173) `table_decoder_p` | [`Spec.ArchDecode_A.decode_page_table_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L60), [`Spec.ArchDecode_A.decode_page_directory_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L51), [`Spec.ArchDecode_A.decode_pdpt_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L63) (Shared map and unmap decoder) | Direct `Patched.invocation_type` call (FL4 invocation label numbering)
Propagates `table_mapping_p` | +| [`ArchDecode.lean:286`](L4vRefX64/Equiv/ArchDecode.lean#L286) `decode_page_table_invocation_p` | [`Spec.ArchDecode_A.decode_page_table_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L60) | Propagates `table_decoder_p` | +| [`ArchDecode.lean:340`](L4vRefX64/Equiv/ArchDecode.lean#L340) `decode_page_directory_invocation_p` | [`Spec.ArchDecode_A.decode_page_directory_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L51) | Propagates `table_decoder_p` | +| [`ArchDecode.lean:394`](L4vRefX64/Equiv/ArchDecode.lean#L394) `decode_pdpt_invocation_p` | [`Spec.ArchDecode_A.decode_pdpt_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L63) | Propagates `table_decoder_p` | +| [`ArchDecode.lean:604`](L4vRefX64/Equiv/ArchDecode.lean#L604) `decode_asid_pool_invocation_p` | [`Spec.ArchDecode_A.arch_decode_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L72) (ASIDPoolCap branch) | Direct `Patched.invocation_type` call (FL4 invocation label numbering) | +| [`ArchDecode.lean:691`](L4vRefX64/Equiv/ArchDecode.lean#L691) `decode_asid_control_invocation_p` | [`Spec.ArchDecode_A.arch_decode_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L72) (ASIDControlCap branch) | Direct `Patched.free_asid_select_p` call (widened ASID selection)
Direct `Patched.invocation_type` call (FL4 invocation label numbering)
Direct `Patched.widen_asid_table` call (11-bit high ASID index)
Propagates `ensure_empty_p`, `lookup_target_slot_p` | +| [`ArchDecode.lean:796`](L4vRefX64/Equiv/ArchDecode.lean#L796) `check_page_mapping_p` | [`Spec.ArchDecode_A.decode_page_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L57) (Existing-mapping and range checks) | Factored existing-mapping and address checks for `page_map_p`. The checks themselves retain the original operations | +| [`ArchDecode.lean:876`](L4vRefX64/Equiv/ArchDecode.lean#L876) `finish_page_map_p` | [`Spec.ArchDecode_A.decode_page_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L57) (Mapping entry construction and validation) | Direct `Patched.create_mapping_entries` call (1 GiB page support) | +| [`ArchDecode.lean:1036`](L4vRefX64/Equiv/ArchDecode.lean#L1036) `page_map_p` | [`Spec.ArchDecode_A.decode_page_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L57) (Map branch) | Propagates `check_page_mapping_p`, `finish_page_map_p` | +| [`ArchDecode.lean:1129`](L4vRefX64/Equiv/ArchDecode.lean#L1129) `decode_page_invocation_p` | [`Spec.ArchDecode_A.decode_page_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L57) | Direct `Patched.invocation_type` call (FL4 invocation label numbering)
Propagates `page_map_p` | +| [`ArchDecode.lean:1223`](L4vRefX64/Equiv/ArchDecode.lean#L1223) `arch_decode_invocation_p` | [`Spec.ArchDecode_A.arch_decode_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L72) | Propagates `decode_asid_control_invocation_p`, `decode_asid_pool_invocation_p`, `decode_ioport_control_invocation_p`, `decode_page_directory_invocation_p`, `decode_page_invocation_p`, `decode_page_table_invocation_p`, `decode_pdpt_invocation_p`, `decode_port_invocation_p` | +| [`ArchInvoke.lean:54`](L4vRefX64/Equiv/ArchInvoke.lean#L54) `perform_ioport_control_invocation_p` | [`Spec.Arch_A.perform_ioport_control_invocation`](L4vRefX64/Spec/Arch_A.lean#L62) | Propagates `cap_insert_p` | +| [`ArchInvoke.lean:100`](L4vRefX64/Equiv/ArchInvoke.lean#L100) `perform_asid_pool_invocation_p` | [`Spec.Arch_A.perform_asid_pool_invocation`](L4vRefX64/Spec/Arch_A.lean#L50) | Propagates `get_cap_p`, `set_cap_p` | +| [`ArchInvoke.lean:160`](L4vRefX64/Equiv/ArchInvoke.lean#L160) `perform_asid_control_invocation_p` | [`Spec.Arch_A.perform_asid_control_invocation`](L4vRefX64/Spec/Arch_A.lean#L44) | Propagates `cap_insert_p`, `get_cap_p`, `retype_region_p`, `set_cap_p` | +| [`ArchInvoke.lean:261`](L4vRefX64/Equiv/ArchInvoke.lean#L261) `perform_page_map_p` | [`Spec.Arch_A.perform_page_invocation`](L4vRefX64/Spec/Arch_A.lean#L71) (PageMap branch) | Uses the adapted `set_cap_p` through `perform_native_map` | +| [`ArchInvoke.lean:296`](L4vRefX64/Equiv/ArchInvoke.lean#L296) `perform_page_table_map_p` | [`Spec.Arch_A.perform_page_table_invocation`](L4vRefX64/Spec/Arch_A.lean#L74) (PageTableMap branch) | Uses the adapted `set_cap_p` through `perform_native_map` | +| [`ArchInvoke.lean:327`](L4vRefX64/Equiv/ArchInvoke.lean#L327) `perform_page_directory_map_p` | [`Spec.Arch_A.perform_page_directory_invocation`](L4vRefX64/Spec/Arch_A.lean#L65) (PageDirectoryMap branch) | Uses the adapted `set_cap_p` through `perform_native_map` | +| [`ArchInvoke.lean:358`](L4vRefX64/Equiv/ArchInvoke.lean#L358) `perform_pdpt_map_p` | [`Spec.Arch_A.perform_pdpt_invocation`](L4vRefX64/Spec/Arch_A.lean#L77) (PDPTMap branch) | Uses the adapted `set_cap_p` through `perform_native_map` | +| [`ArchInvoke.lean:412`](L4vRefX64/Equiv/ArchInvoke.lean#L412) `clear_mapping_cap_p` | [`Spec.Arch_A.perform_page_invocation_unmap`](L4vRefX64/Spec/Arch_A.lean#L68), [`Spec.Arch_A.perform_page_table_invocation`](L4vRefX64/Spec/Arch_A.lean#L74), [`Spec.Arch_A.perform_page_directory_invocation`](L4vRefX64/Spec/Arch_A.lean#L65), [`Spec.Arch_A.perform_pdpt_invocation`](L4vRefX64/Spec/Arch_A.lean#L77) (Shared cap clear in the unmap branches) | Propagates `get_cap_p`, `set_cap_p` | +| [`ArchInvoke.lean:483`](L4vRefX64/Equiv/ArchInvoke.lean#L483) `perform_page_invocation_unmap_p` | [`Spec.Arch_A.perform_page_invocation_unmap`](L4vRefX64/Spec/Arch_A.lean#L68) | Propagates `clear_mapping_cap_p` | +| [`ArchInvoke.lean:525`](L4vRefX64/Equiv/ArchInvoke.lean#L525) `perform_page_table_unmap_p` | [`Spec.Arch_A.perform_page_table_invocation`](L4vRefX64/Spec/Arch_A.lean#L74) (PageTableUnmap branch) | Propagates `clear_mapping_cap_p` | +| [`ArchInvoke.lean:591`](L4vRefX64/Equiv/ArchInvoke.lean#L591) `perform_page_directory_unmap_p` | [`Spec.Arch_A.perform_page_directory_invocation`](L4vRefX64/Spec/Arch_A.lean#L65) (PageDirectoryUnmap branch) | Propagates `clear_mapping_cap_p` | +| [`ArchInvoke.lean:657`](L4vRefX64/Equiv/ArchInvoke.lean#L657) `perform_pdpt_unmap_p` | [`Spec.Arch_A.perform_pdpt_invocation`](L4vRefX64/Spec/Arch_A.lean#L77) (PDPTUnmap branch) | Propagates `clear_mapping_cap_p` | +| [`ArchInvoke.lean:715`](L4vRefX64/Equiv/ArchInvoke.lean#L715) `perform_page_invocation_p` | [`Spec.Arch_A.perform_page_invocation`](L4vRefX64/Spec/Arch_A.lean#L71) | Propagates `perform_page_invocation_unmap_p`, `perform_page_map_p` | +| [`ArchInvoke.lean:764`](L4vRefX64/Equiv/ArchInvoke.lean#L764) `arch_no_return_p` | [`Spec.Arch_A.arch_no_return`](L4vRefX64/Spec/Arch_A.lean#L38) | Unchanged return adapter for the adapted architecture performers | +| [`ArchInvoke.lean:768`](L4vRefX64/Equiv/ArchInvoke.lean#L768) `arch_perform_invocation_p` | [`Spec.Arch_A.arch_perform_invocation`](L4vRefX64/Spec/Arch_A.lean#L80) | Propagates `arch_no_return_p`, `perform_asid_control_invocation_p`, `perform_asid_pool_invocation_p`, `perform_ioport_control_invocation_p`, `perform_page_directory_map_p`, `perform_page_directory_unmap_p`, `perform_page_invocation_p`, `perform_page_table_map_p`, `perform_page_table_unmap_p`, `perform_pdpt_map_p`, `perform_pdpt_unmap_p` | +| [`CSpace.lean:376`](L4vRefX64/Equiv/CSpace.lean#L376) `obj_size_p` | [`Spec.Structures_A.obj_size`](L4vRefX64/Spec/Structures_A.lean#L742) | Direct notification size delta: 64 bytes for a notification cap (see `Patched.notificationBits_delta` and `objSize_ntfn_delta`) | +| [`CSpace.lean:395`](L4vRefX64/Equiv/CSpace.lean#L395) `same_region_as_p` | [`Spec.CSpace_A.same_region_as`](L4vRefX64/Spec/CSpace_A.lean#L131) | Propagates `obj_size_p` | +| [`CSpace.lean:475`](L4vRefX64/Equiv/CSpace.lean#L475) `should_be_parent_of_p` | [`Spec.CSpace_A.should_be_parent_of`](L4vRefX64/Spec/CSpace_A.lean#L147) | Propagates `same_region_as_p` | +| [`CSpace.lean:641`](L4vRefX64/Equiv/CSpace.lean#L641) `get_cap_p` | [`Spec.CSpaceAcc_A.get_cap`](L4vRefX64/Spec/CSpaceAcc_A.lean#L25) | Direct `Patched.tcb_cnode_map` call (empty EPT slot in the base TCB) | +| [`CSpace.lean:678`](L4vRefX64/Equiv/CSpace.lean#L678) `set_cap_p` | [`Spec.CSpaceAcc_A.set_cap`](L4vRefX64/Spec/CSpaceAcc_A.lean#L40) | Direct TCB slot delta: the base EPT slot accepts a null cap (see `Patched.tcbEptSlot_delta`) | +| [`CSpace.lean:1063`](L4vRefX64/Equiv/CSpace.lean#L1063) `resolve_address_bits_p` | [`Spec.CSpace_A.resolve_address_bits'`](L4vRefX64/Spec/CSpace_A.lean#L200) (Resolver recursion behind the public wrapper) | Propagates `get_cap_p` | +| [`CSpace.lean:1148`](L4vRefX64/Equiv/CSpace.lean#L1148) `lookup_slot_for_thread_p` | [`Spec.CSpace_A.lookup_slot_for_thread`](L4vRefX64/Spec/CSpace_A.lean#L206) | Propagates `resolve_address_bits_p` | +| [`CSpace.lean:1161`](L4vRefX64/Equiv/CSpace.lean#L1161) `lookup_cap_and_slot_p` | [`Spec.CSpace_A.lookup_cap_and_slot`](L4vRefX64/Spec/CSpace_A.lean#L239) | Propagates `get_cap_p`, `lookup_slot_for_thread_p` | +| [`CSpace.lean:1177`](L4vRefX64/Equiv/CSpace.lean#L1177) `lookup_cap_p` | [`Spec.CSpace_A.lookup_cap`](L4vRefX64/Spec/CSpace_A.lean#L209) | Propagates `get_cap_p`, `lookup_slot_for_thread_p` | +| [`CSpace.lean:1191`](L4vRefX64/Equiv/CSpace.lean#L1191) `lookup_slot_for_cnode_op_p` | [`Spec.CSpace_A.lookup_slot_for_cnode_op`](L4vRefX64/Spec/CSpace_A.lean#L212) | Propagates `resolve_address_bits_p` | +| [`CSpace.lean:1224`](L4vRefX64/Equiv/CSpace.lean#L1224) `lookup_source_slot_p` | [`Spec.CSpace_A.lookup_source_slot`](L4vRefX64/Spec/CSpace_A.lean#L245) | Propagates `lookup_slot_for_cnode_op_p` | +| [`CSpace.lean:1225`](L4vRefX64/Equiv/CSpace.lean#L1225) `lookup_target_slot_p` | [`Spec.CSpace_A.lookup_target_slot`](L4vRefX64/Spec/CSpace_A.lean#L215) | Propagates `lookup_slot_for_cnode_op_p` | +| [`CSpace.lean:1226`](L4vRefX64/Equiv/CSpace.lean#L1226) `lookup_pivot_slot_p` | [`Spec.CSpace_A.lookup_pivot_slot`](L4vRefX64/Spec/CSpace_A.lean#L242) | Propagates `lookup_slot_for_cnode_op_p` | +| [`CSpace.lean:1249`](L4vRefX64/Equiv/CSpace.lean#L1249) `get_receive_slots_p` | [`Spec.CSpace_A.get_receive_slots`](L4vRefX64/Spec/CSpace_A.lean#L218) | Propagates `get_cap_p`, `lookup_cap_p`, `lookup_target_slot_p` | +| [`CSpace.lean:1310`](L4vRefX64/Equiv/CSpace.lean#L1310) `set_untyped_cap_as_full_p` | [`Spec.CSpace_A.set_untyped_cap_as_full`](L4vRefX64/Spec/CSpace_A.lean#L125) | Propagates `set_cap_p` | +| [`CSpace.lean:1347`](L4vRefX64/Equiv/CSpace.lean#L1347) `cap_insert_p` | [`Spec.CSpace_A.cap_insert`](L4vRefX64/Spec/CSpace_A.lean#L150) | Propagates `get_cap_p`, `set_cap_p`, `set_untyped_cap_as_full_p`, `should_be_parent_of_p` | +| [`CSpace.lean:1571`](L4vRefX64/Equiv/CSpace.lean#L1571) `slot_cap_long_running_delete_p` | [`Spec.CSpace_A.slot_cap_long_running_delete`](L4vRefX64/Spec/CSpace_A.lean#L260) | Propagates `get_cap_p` | +| [`CSpace.lean:1592`](L4vRefX64/Equiv/CSpace.lean#L1592) `cap_swap_p` | [`Spec.CSpace_A.cap_swap`](L4vRefX64/Spec/CSpace_A.lean#L56) | Propagates `set_cap_p` | +| [`CSpace.lean:1641`](L4vRefX64/Equiv/CSpace.lean#L1641) `cap_move_p` | [`Spec.CSpace_A.cap_move`](L4vRefX64/Spec/CSpace_A.lean#L153) | Propagates `set_cap_p` | +| [`CSpace.lean:1699`](L4vRefX64/Equiv/CSpace.lean#L1699) `empty_slot_p` | [`Spec.IpcCancel_A.empty_slot`](L4vRefX64/Spec/IpcCancel_A.lean#L123) | Propagates `get_cap_p`, `set_cap_p` | +| [`CSpace.lean:1770`](L4vRefX64/Equiv/CSpace.lean#L1770) `cap_delete_one_p` | [`Spec.CSpace_A.cap_delete_one`](L4vRefX64/Spec/CSpace_A.lean#L78) | Propagates `empty_slot_p`, `get_cap_p` | +| [`CSpace.lean:1788`](L4vRefX64/Equiv/CSpace.lean#L1788) `deleting_irq_handler_p` | [`Spec.CSpace_A.deleting_irq_handler`](L4vRefX64/Spec/CSpace_A.lean#L81) | Propagates `cap_delete_one_p` | +| [`CSpace.lean:1891`](L4vRefX64/Equiv/CSpace.lean#L1891) `finalise_cap_p` | [`Spec.CSpace_A.finalise_cap`](L4vRefX64/Spec/CSpace_A.lean#L84) | Direct TCB zombie-size delta: six slots (see `Patched.finaliseTcbZombieSlots_delta`)
Propagates `deleting_irq_handler_p`, `sched_context_unbind_yield_from_p`, `unbind_from_sc_p` | +| [`CSpace.lean:1973`](L4vRefX64/Equiv/CSpace.lean#L1973) `cap_swap_for_delete_p` | [`Spec.CSpace_A.cap_swap_for_delete`](L4vRefX64/Spec/CSpace_A.lean#L59) | Propagates `cap_swap_p`, `get_cap_p` | +| [`CSpace.lean:2191`](L4vRefX64/Equiv/CSpace.lean#L2191) `rec_del_step_p` | [`Spec.CSpace_A.rec_del`](L4vRefX64/Spec/CSpace_A.lean#L106), [`Spec.CSpace_A.rec_del_graph`](L4vRefX64/Spec/CSpace_A.lean#L100) (Recursive equations) | Propagates `cap_swap_for_delete_p`, `empty_slot_p`, `finalise_cap_p`, `get_cap_p`, `set_cap_p` | +| [`CSpace.lean:2291`](L4vRefX64/Equiv/CSpace.lean#L2291) `rec_del_p` | [`Spec.CSpace_A.rec_del`](L4vRefX64/Spec/CSpace_A.lean#L106) | Uses `RecDelPGraph`, built from `rec_del_step_p` | +| [`CSpace.lean:2295`](L4vRefX64/Equiv/CSpace.lean#L2295) `cap_delete_p` | [`Spec.CSpace_A.cap_delete`](L4vRefX64/Spec/CSpace_A.lean#L109) | Propagates `rec_del_p` | +| [`CSpace.lean:2298`](L4vRefX64/Equiv/CSpace.lean#L2298) `finalise_slot_p` | [`Spec.CSpace_A.finalise_slot`](L4vRefX64/Spec/CSpace_A.lean#L185) | Propagates `rec_del_p` | +| [`CSpace.lean:2524`](L4vRefX64/Equiv/CSpace.lean#L2524) `cap_revoke_step_p` | [`Spec.CSpace_A.cap_revoke`](L4vRefX64/Spec/CSpace_A.lean#L162), [`Spec.CSpace_A.cap_revoke_graph`](L4vRefX64/Spec/CSpace_A.lean#L156) (Recursive equations) | Propagates `cap_delete_p`, `get_cap_p` | +| [`CSpace.lean:2612`](L4vRefX64/Equiv/CSpace.lean#L2612) `cap_revoke_p` | [`Spec.CSpace_A.cap_revoke`](L4vRefX64/Spec/CSpace_A.lean#L162) | Uses `CapRevokePGraph`, built from `cap_revoke_step_p` | +| [`CSpace.lean:2683`](L4vRefX64/Equiv/CSpace.lean#L2683) `invoke_cnode_p` | [`Spec.CSpace_A.invoke_cnode`](L4vRefX64/Spec/CSpace_A.lean#L225) | Propagates `cap_delete_p`, `cap_insert_p`, `cap_move_p`, `cap_revoke_p`, `cap_swap_p` | +| [`Decode.lean:122`](L4vRefX64/Equiv/Decode.lean#L122) `ensure_empty_p` | [`Spec.CSpaceAcc_A.ensure_empty`](L4vRefX64/Spec/CSpaceAcc_A.lean#L28) | Propagates `get_cap_p` | +| [`Decode.lean:155`](L4vRefX64/Equiv/Decode.lean#L155) `decode_cnode_invocation_p` | [`Spec.Decode_A.decode_cnode_invocation`](L4vRefX64/Spec/Decode_A.lean#L56) | Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI
Propagates `ensure_empty_p`, `get_cap_p`, `lookup_pivot_slot_p`, `lookup_source_slot_p`, `lookup_target_slot_p` | +| [`Decode.lean:536`](L4vRefX64/Equiv/Decode.lean#L536) `decode_domain_invocation_p` | [`Spec.Decode_A.decode_domain_invocation`](L4vRefX64/Spec/Decode_A.lean#L74) | Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI | +| [`Decode.lean:655`](L4vRefX64/Equiv/Decode.lean#L655) `decode_sched_context_invocation_p` | [`Spec.Decode_A.decode_sched_context_invocation`](L4vRefX64/Spec/Decode_A.lean#L92) | Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI | +| [`Decode.lean:680`](L4vRefX64/Equiv/Decode.lean#L680) `decode_sched_control_invocation_flags_p` | [`Spec.Decode_A.decode_sched_control_invocation_flags`](L4vRefX64/Spec/Decode_A.lean#L95) | Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI | +| [`Decode.lean:795`](L4vRefX64/Equiv/Decode.lean#L795) `decode_untyped_invocation_p` | [`Spec.Decode_A.decode_untyped_invocation`](L4vRefX64/Spec/Decode_A.lean#L140) | Direct `Patched.obj_bits_api` call (MCS notification size)
Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI
Propagates `ensure_empty_p`, `get_cap_p`, `lookup_target_slot_p` | +| [`Decode.lean:990`](L4vRefX64/Equiv/Decode.lean#L990) `arch_decode_irq_control_invocation_p` | [`Spec.ArchDecode_A.arch_decode_irq_control_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L75) | Direct `Patched.invocation_type` call (FL4 invocation label numbering)
Propagates `ensure_empty_p`, `lookup_target_slot_p` | +| [`Decode.lean:1111`](L4vRefX64/Equiv/Decode.lean#L1111) `decode_irq_control_invocation_p` | [`Spec.Decode_A.decode_irq_control_invocation`](L4vRefX64/Spec/Decode_A.lean#L77) | Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI
Propagates `arch_decode_irq_control_invocation_p`, `ensure_empty_p`, `lookup_target_slot_p` | +| [`Decode.lean:1153`](L4vRefX64/Equiv/Decode.lean#L1153) `decode_irq_handler_invocation_p` | [`Spec.Decode_A.decode_irq_handler_invocation`](L4vRefX64/Spec/Decode_A.lean#L80) | Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI | +| [`Decode.lean:1499`](L4vRefX64/Equiv/Decode.lean#L1499) `decode_cv_space_p` | [`Spec.Decode_A.decode_cv_space`](L4vRefX64/Spec/Decode_A.lean#L62) | Propagates `slot_cap_long_running_delete_p` | +| [`Decode.lean:1607`](L4vRefX64/Equiv/Decode.lean#L1607) `decode_set_space_p` | [`Spec.Decode_A.decode_set_space`](L4vRefX64/Spec/Decode_A.lean#L119) | Propagates `decode_cv_space_p` | +| [`Decode.lean:1697`](L4vRefX64/Equiv/Decode.lean#L1697) `decode_tcb_configure_p` | [`Spec.Decode_A.decode_tcb_configure`](L4vRefX64/Spec/Decode_A.lean#L128) | Propagates `decode_cv_space_p` | +| [`Decode.lean:1915`](L4vRefX64/Equiv/Decode.lean#L1915) `decode_tcb_invocation_p` | [`Spec.Decode_A.decode_tcb_invocation`](L4vRefX64/Spec/Decode_A.lean#L137) | Uses `Decode.gen_invocation_type`, which applies the `Patched.invocation_type` ABI
Propagates `decode_set_space_p`, `decode_tcb_configure_p` | +| [`Decode.lean:1988`](L4vRefX64/Equiv/Decode.lean#L1988) `decode_port_invocation_p` | [`Spec.ArchDecode_A.decode_port_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L69) | Direct `Patched.invocation_type` call (FL4 invocation label numbering) | +| [`Decode.lean:2046`](L4vRefX64/Equiv/Decode.lean#L2046) `decode_ioport_control_invocation_p` | [`Spec.ArchDecode_A.decode_ioport_control_invocation`](L4vRefX64/Spec/ArchDecode_A.lean#L45) | Direct `Patched.invocation_type` call (FL4 invocation label numbering)
Propagates `ensure_empty_p`, `lookup_target_slot_p` | +| [`Interrupt.lean:111`](L4vRefX64/Equiv/Interrupt.lean#L111) `invoke_irq_handler_p` | [`Spec.Interrupt_A.invoke_irq_handler`](L4vRefX64/Spec/Interrupt_A.lean#L30) | Propagates `cap_delete_one_p`, `cap_insert_p` | +| [`Interrupt.lean:164`](L4vRefX64/Equiv/Interrupt.lean#L164) `install_irq_handler_p` | [`Spec.Arch_A.arch_invoke_irq_control`](L4vRefX64/Spec/Arch_A.lean#L35), [`Spec.Interrupt_A.invoke_irq_control`](L4vRefX64/Spec/Interrupt_A.lean#L26) (Shared issue branch) | Propagates `cap_insert_p` | +| [`Interrupt.lean:190`](L4vRefX64/Equiv/Interrupt.lean#L190) `arch_invoke_irq_control_p` | [`Spec.Arch_A.arch_invoke_irq_control`](L4vRefX64/Spec/Arch_A.lean#L35) | Propagates `install_irq_handler_p` | +| [`Interrupt.lean:246`](L4vRefX64/Equiv/Interrupt.lean#L246) `invoke_irq_control_p` | [`Spec.Interrupt_A.invoke_irq_control`](L4vRefX64/Spec/Interrupt_A.lean#L26) | Propagates `arch_invoke_irq_control_p`, `install_irq_handler_p` | +| [`InvocationDecode.lean:18`](L4vRefX64/Equiv/InvocationDecode.lean#L18) `decode_invocation_p` | [`Spec.Decode_A.decode_invocation`](L4vRefX64/Spec/Decode_A.lean#L143) | Propagates `arch_decode_invocation_p`, `decode_cnode_invocation_p`, `decode_domain_invocation_p`, `decode_irq_control_invocation_p`, `decode_irq_handler_invocation_p`, `decode_sched_context_invocation_p`, `decode_sched_control_invocation_flags_p`, `decode_tcb_invocation_p`, `decode_untyped_invocation_p` | +| [`Ipc.lean:544`](L4vRefX64/Equiv/Ipc.lean#L544) `lookup_extra_caps_p` | [`Spec.Ipc_A.lookup_extra_caps`](L4vRefX64/Spec/Ipc_A.lean#L55) | Propagates `lookup_cap_and_slot_p` | +| [`Ipc.lean:564`](L4vRefX64/Equiv/Ipc.lean#L564) `transfer_caps_loop_p` | [`Spec.Ipc_A.transfer_caps_loop`](L4vRefX64/Spec/Ipc_A.lean#L61) | Propagates `cap_insert_p` | +| [`Ipc.lean:753`](L4vRefX64/Equiv/Ipc.lean#L753) `transfer_caps_p` | [`Spec.Ipc_A.transfer_caps`](L4vRefX64/Spec/Ipc_A.lean#L65) | Propagates `get_receive_slots_p`, `transfer_caps_loop_p` | +| [`Ipc.lean:897`](L4vRefX64/Equiv/Ipc.lean#L897) `make_fault_msg_p` | [`Spec.Ipc_A.make_fault_msg`](L4vRefX64/Spec/Ipc_A.lean#L38) | Direct `Patched.makeArchFaultMsg` call (MCS VMFault label) | +| [`Ipc.lean:959`](L4vRefX64/Equiv/Ipc.lean#L959) `do_fault_transfer_p` | [`Spec.Ipc_A.do_fault_transfer`](L4vRefX64/Spec/Ipc_A.lean#L45) | Propagates `make_fault_msg_p` | +| [`Ipc.lean:994`](L4vRefX64/Equiv/Ipc.lean#L994) `do_normal_transfer_p` | [`Spec.Ipc_A.do_normal_transfer`](L4vRefX64/Spec/Ipc_A.lean#L68) | Propagates `lookup_extra_caps_p`, `transfer_caps_p` | +| [`Ipc.lean:1079`](L4vRefX64/Equiv/Ipc.lean#L1079) `do_ipc_transfer_p` | [`Spec.Ipc_A.do_ipc_transfer`](L4vRefX64/Spec/Ipc_A.lean#L71) | Direct `Patched.lookupIpcBuffer` call (MCS IPC buffer slot)
Propagates `do_fault_transfer_p`, `do_normal_transfer_p` | +| [`Ipc.lean:1120`](L4vRefX64/Equiv/Ipc.lean#L1120) `send_ipc_p` | [`Spec.Ipc_A.send_ipc`](L4vRefX64/Spec/Ipc_A.lean#L77) | Propagates `do_ipc_transfer_p` | +| [`Ipc.lean:1230`](L4vRefX64/Equiv/Ipc.lean#L1230) `receive_ipc_p` | [`Spec.Ipc_A.receive_ipc`](L4vRefX64/Spec/Ipc_A.lean#L141) | Propagates `do_ipc_transfer_p` | +| [`Ipc.lean:1700`](L4vRefX64/Equiv/Ipc.lean#L1700) `send_fault_ipc_p` | [`Spec.Ipc_A.send_fault_ipc`](L4vRefX64/Spec/Ipc_A.lean#L80) | Propagates `send_ipc_p` | +| [`Ipc.lean:1750`](L4vRefX64/Equiv/Ipc.lean#L1750) `handle_timeout_p` | [`Spec.Ipc_A.handle_timeout`](L4vRefX64/Spec/Ipc_A.lean#L83) | Propagates `send_fault_ipc_p` | +| [`Ipc.lean:1773`](L4vRefX64/Equiv/Ipc.lean#L1773) `handle_fault_p` | [`Spec.Ipc_A.handle_fault`](L4vRefX64/Spec/Ipc_A.lean#L126) | Propagates `send_fault_ipc_p` | +| [`Ipc.lean:1800`](L4vRefX64/Equiv/Ipc.lean#L1800) `do_reply_transfer_p` | [`Spec.Ipc_A.do_reply_transfer`](L4vRefX64/Spec/Ipc_A.lean#L117) | Direct `Patched.lookupIpcBuffer` call (MCS IPC buffer slot)
Propagates `do_ipc_transfer_p`, `handle_timeout_p` | +| [`Ipc.lean:2221`](L4vRefX64/Equiv/Ipc.lean#L2221) `end_timeslice_p` | [`Spec.Ipc_A.end_timeslice`](L4vRefX64/Spec/Ipc_A.lean#L86) | Propagates `handle_timeout_p` | +| [`Ipc.lean:2296`](L4vRefX64/Equiv/Ipc.lean#L2296) `charge_budget_p` | [`Spec.Ipc_A.charge_budget`](L4vRefX64/Spec/Ipc_A.lean#L92) | Propagates `end_timeslice_p` | +| [`Ipc.lean:2381`](L4vRefX64/Equiv/Ipc.lean#L2381) `check_budget_p` | [`Spec.Ipc_A.check_budget`](L4vRefX64/Spec/Ipc_A.lean#L95) | Propagates `charge_budget_p` | +| [`Ipc.lean:2432`](L4vRefX64/Equiv/Ipc.lean#L2432) `check_budget_restart_p` | [`Spec.Ipc_A.check_budget_restart`](L4vRefX64/Spec/Ipc_A.lean#L98) | Propagates `check_budget_p` | +| [`Retype.lean:207`](L4vRefX64/Equiv/Retype.lean#L207) `retype_region_p` | [`Spec.Retype_A.retype_region`](L4vRefX64/Spec/Retype_A.lean#L64) | Direct `Patched.default_object` call (initial context selectors and native object defaults)
Direct `Patched.obj_bits_api` call (MCS notification size) | +| [`Retype.lean:341`](L4vRefX64/Equiv/Retype.lean#L341) `invoke_untyped_p` | [`Spec.Retype_A.invoke_untyped`](L4vRefX64/Spec/Retype_A.lean#L67) | Direct `Patched.obj_bits_api` call (MCS notification size)
Propagates `retype_region_p` | +| [`SchedContext.lean:1167`](L4vRefX64/Equiv/SchedContext.lean#L1167) `set_consumed_p` | [`Spec.SchedContext_A.set_consumed`](L4vRefX64/Spec/SchedContext_A.lean#L74) | Direct `Patched.reply_from_kernel` call (MCS IPC buffer slot in kernel replies) | +| [`SchedContext.lean:1181`](L4vRefX64/Equiv/SchedContext.lean#L1181) `complete_yield_to_p` | [`Spec.SchedContext_A.complete_yield_to`](L4vRefX64/Spec/SchedContext_A.lean#L77) | Propagates `set_consumed_p` | +| [`SchedContext.lean:1199`](L4vRefX64/Equiv/SchedContext.lean#L1199) `sched_context_unbind_yield_from_p` | [`Spec.SchedContext_A.sched_context_unbind_yield_from`](L4vRefX64/Spec/SchedContext_A.lean#L131) | Propagates `complete_yield_to_p` | +| [`SchedContext.lean:1212`](L4vRefX64/Equiv/SchedContext.lean#L1212) `unbind_from_sc_p` | [`Spec.SchedContext_A.unbind_from_sc`](L4vRefX64/Spec/SchedContext_A.lean#L152) | Propagates `complete_yield_to_p` | +| [`Schedule.lean:1081`](L4vRefX64/Equiv/Schedule.lean#L1081) `sched_context_yield_to_p` | [`Spec.Schedule_A.sched_context_yield_to`](L4vRefX64/Spec/Schedule_A.lean#L69) | Propagates `complete_yield_to_p` | +| [`Schedule.lean:1108`](L4vRefX64/Equiv/Schedule.lean#L1108) `invoke_sched_context_p` | [`Spec.Schedule_A.invoke_sched_context`](L4vRefX64/Spec/Schedule_A.lean#L72) | Propagates `sched_context_yield_to_p` | +| [`Syscall.lean:57`](L4vRefX64/Equiv/Syscall.lean#L57) `perform_invocation_p` | [`Spec.Syscall_A.perform_invocation`](L4vRefX64/Spec/Syscall_A.lean#L37) | Propagates `arch_perform_invocation_p`, `do_reply_transfer_p`, `invoke_cnode_p`, `invoke_irq_control_p`, `invoke_irq_handler_p`, `invoke_sched_context_p`, `invoke_tcb_p`, `invoke_untyped_p`, `send_ipc_p` | +| [`Syscall.lean:299`](L4vRefX64/Equiv/Syscall.lean#L299) `call_kernel_interrupt_p` | [`Spec.Syscall_A.call_kernel`](L4vRefX64/Spec/Syscall_A.lean#L83) (Interrupt-only specialization) | Propagates `activate_thread_p` | +| [`Syscall.lean:346`](L4vRefX64/Equiv/Syscall.lean#L346) `invocation_lookup_p` | [`Spec.Syscall_A.handle_invocation`](L4vRefX64/Spec/Syscall_A.lean#L54) (Cap, buffer and extra-cap lookup prefix) | Direct `Patched.lookupIpcBuffer` call (MCS IPC buffer slot)
Propagates `lookup_cap_and_slot_p`, `lookup_extra_caps_p` | +| [`Syscall.lean:362`](L4vRefX64/Equiv/Syscall.lean#L362) `invocation_decode_p` | [`Spec.Syscall_A.handle_invocation`](L4vRefX64/Spec/Syscall_A.lean#L54) (Message-register and decoder phase) | Propagates `decode_invocation_p` | +| [`Syscall.lean:369`](L4vRefX64/Equiv/Syscall.lean#L369) `handle_invocation_p` | [`Spec.Syscall_A.handle_invocation`](L4vRefX64/Spec/Syscall_A.lean#L54) | Direct `Patched.reply_from_kernel` call (MCS IPC buffer slot in kernel replies)
Propagates `handle_fault_p`, `invocation_decode_p`, `invocation_lookup_p`, `perform_invocation_p` | +| [`Syscall.lean:521`](L4vRefX64/Equiv/Syscall.lean#L521) `lookup_reply_p` | [`Spec.Syscall_A.lookup_reply`](L4vRefX64/Spec/Syscall_A.lean#L60) | Propagates `lookup_cap_p` | +| [`Syscall.lean:584`](L4vRefX64/Equiv/Syscall.lean#L584) `handle_recv_p` | [`Spec.Syscall_A.handle_recv`](L4vRefX64/Spec/Syscall_A.lean#L63) | Uses `lookup_cap_p` through `receive_lookup` and `lookup_reply_p` and `receive_ipc_p` through `receive_from_cap`
Propagates `handle_fault_p` | +| [`Syscall.lean:760`](L4vRefX64/Equiv/Syscall.lean#L760) `handle_nbwait_p` | [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) (SysNBWait branch with timestamp and budget) | Propagates `handle_recv_p` | +| [`Syscall.lean:824`](L4vRefX64/Equiv/Syscall.lean#L824) `call_kernel_nbwait_p` | [`Spec.Syscall_A.call_kernel`](L4vRefX64/Spec/Syscall_A.lean#L83) (SysNBWait specialization) | Propagates `activate_thread_p`, `handle_nbwait_p` | +| [`Syscall.lean:881`](L4vRefX64/Equiv/Syscall.lean#L881) `preemption_path_p` | [`Spec.Syscall_A.preemption_path`](L4vRefX64/Spec/Syscall_A.lean#L80) | Propagates `charge_budget_p`, `check_budget_p` | +| [`Syscall.lean:985`](L4vRefX64/Equiv/Syscall.lean#L985) `handle_interrupt_p` | [`Spec.Interrupt_A.handle_interrupt`](L4vRefX64/Spec/Interrupt_A.lean#L23) | Propagates `check_budget_p` | +| [`Syscall.lean:1005`](L4vRefX64/Equiv/Syscall.lean#L1005) `handle_fault_event_p` | [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) (Shared fault-event timestamp and budget prefix) | Propagates `check_budget_restart_p` | +| [`Syscall.lean:1034`](L4vRefX64/Equiv/Syscall.lean#L1034) `handle_non_syscall_p` | [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) (Five non-syscall branches) | Propagates `handle_fault_event_p`, `handle_fault_p`, `handle_interrupt_p` | +| [`Syscall.lean:1097`](L4vRefX64/Equiv/Syscall.lean#L1097) `call_kernel_non_syscall_p` | [`Spec.Syscall_A.call_kernel`](L4vRefX64/Spec/Syscall_A.lean#L83) (Non-syscall specialization) | Uses `preemption_path_p` and `activate_thread_p` through `event_with_preemption` and `kernel_after_event`
Propagates `handle_non_syscall_p` | +| [`Syscall.lean:1114`](L4vRefX64/Equiv/Syscall.lean#L1114) `invocation_from_reg_p` | [`Spec.Syscall_A.handle_send`](L4vRefX64/Spec/Syscall_A.lean#L66), [`Spec.Syscall_A.handle_call`](L4vRefX64/Spec/Syscall_A.lean#L57), [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) (Invoke after reading the syscall's selected register) | Propagates `handle_invocation_p` | +| [`Syscall.lean:1142`](L4vRefX64/Equiv/Syscall.lean#L1142) `invoke_then_receive_p` | [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) (ReplyRecv, NBSendRecv and NBSendWait continuations) | Propagates `handle_recv_p`, `invocation_from_reg_p` | +| [`Syscall.lean:1180`](L4vRefX64/Equiv/Syscall.lean#L1180) `syscall_dispatch_p` | [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) (SyscallEvent dispatch) | Propagates `handle_recv_p`, `invocation_from_reg_p`, `invoke_then_receive_p` | +| [`Syscall.lean:1250`](L4vRefX64/Equiv/Syscall.lean#L1250) `handle_syscall_p` | [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) (SyscallEvent timestamp, budget and dispatch) | Propagates `check_budget_restart_p`, `syscall_dispatch_p` | +| [`Syscall.lean:1293`](L4vRefX64/Equiv/Syscall.lean#L1293) `handle_event_p` | [`Spec.Syscall_A.handle_event`](L4vRefX64/Spec/Syscall_A.lean#L72) | Propagates `handle_non_syscall_p`, `handle_syscall_p` | +| [`Syscall.lean:1317`](L4vRefX64/Equiv/Syscall.lean#L1317) `call_kernel_p` | [`Spec.Syscall_A.call_kernel`](L4vRefX64/Spec/Syscall_A.lean#L83) | Uses `preemption_path_p` and `activate_thread_p` through `event_with_preemption` and `kernel_after_event`
Propagates `handle_event_p` | +| [`Tcb.lean:83`](L4vRefX64/Equiv/Tcb.lean#L83) `activate_thread_p` | [`Spec.Tcb_A.activate_thread`](L4vRefX64/Spec/Tcb_A.lean#L30) | Propagates `complete_yield_to_p` | +| [`Tcb.lean:201`](L4vRefX64/Equiv/Tcb.lean#L201) `check_cap_at_p` | [`Spec.Tcb_A.check_cap_at`](L4vRefX64/Spec/Tcb_A.lean#L36) | Propagates `get_cap_p` | +| [`Tcb.lean:223`](L4vRefX64/Equiv/Tcb.lean#L223) `install_tcb_cap_p` | [`Spec.Tcb_A.install_tcb_cap`](L4vRefX64/Spec/Tcb_A.lean#L60) | Propagates `cap_delete_p`, `cap_insert_p`, `check_cap_at_p` | +| [`Tcb.lean:235`](L4vRefX64/Equiv/Tcb.lean#L235) `install_tcb_frame_cap_p` | [`Spec.Tcb_A.install_tcb_frame_cap`](L4vRefX64/Spec/Tcb_A.lean#L63) | Propagates `cap_delete_p`, `cap_insert_p`, `check_cap_at_p` | +| [`Tcb.lean:252`](L4vRefX64/Equiv/Tcb.lean#L252) `invoke_tcb_p` | [`Spec.Tcb_A.invoke_tcb`](L4vRefX64/Spec/Tcb_A.lean#L78) | Propagates `install_tcb_cap_p`, `install_tcb_frame_cap_p` | +| [`Patched.lean:225`](L4vRefX64/Patched.lean#L225) `free_asid_select_p` | [`Spec.Deterministic_A.free_asid_select`](L4vRefX64/Spec/Deterministic_A.lean#L75) | Direct widened ASID-table selection (see `Patched.asidWidths_delta` and `Patched.asidFreeIndex_delta`) | diff --git a/proofs/Fl4SpecEquivX64/PHASE2_REPORT.md b/proofs/Fl4SpecEquivX64/PHASE2_REPORT.md new file mode 100644 index 000000000..06c3b366f --- /dev/null +++ b/proofs/Fl4SpecEquivX64/PHASE2_REPORT.md @@ -0,0 +1,69 @@ +# X64 MCS specification equivalence + +The clean verification build compiled all 100 standalone Lean modules against +the pinned FL4 abstract specification. The warning gate passed, and all 1,043 +manifest records use only subsets of `propext`, `Classical.choice`, and +`Quot.sound`. The committed exporter and emitter reproduced the 59 reference theories +and `L4vRefX64/Spec.lean` byte for byte from the pinned upstream inputs +and [the checked-in selection lists](tools/). + +## Theorem and assumptions + +`L4vRefX64/Equiv/Syscall.lean` contains `patched_callKernel_equiv`. It relates the explicitly patched X64 MCS Isabelle reference to the frozen base `Fl4Spec.callKernel` for all 11 syscall routes and all five non-syscall event constructors. `MRelStep` equates the failure indicators and gives both directions of result-set correspondence with related post-states. The proof composes the event handler, preemption, scheduling and activation. The invocation path includes capability and argument lookup, decode, execution, fault and error handling, and reply. + +The theorem takes a related input pair and `CallKernelSafe`. The base carriers restrict the heap, capabilities, TCB states and EPT slot, guest mappings, ASID pool tags and CR3 PCID. They include `NoVirtObjects` and are transported between the models by `StateRel.baseCarriers_iff`. Continuation conditions apply to the results of concrete preceding runs. For example, syscall dispatch conditions follow successful timestamp collection and a true budget-restart result on both sides. Invocation guards follow successful capability lookup and argument reads, and performer guards apply after the reached transition to Restart. The patched decoder receives an explicit huge-page flag checked against the FL4 state at the reached decoder read. The postcondition is `StateRel`; admission to a subsequent kernel entry still requires its own `CallKernelSafe`. + +`ConfigRel` matches the fixed Lean configuration to the PC99 reference. `OpaqueRel RestRel` relates the opaque time and interrupt oracles, machine operations and time constants. The concrete witnesses take those assumptions where needed and take related initial machine-rest values. Their deterministic state extensions are `Unit` with equality. Separately, `pc99Config_exists` constructs a configuration with 16 domains, reset chunk width 8 and retype fanout 256. This proves the model-level match. The equality for the fixed opaque `Fl4Spec.kernelConfig` remains a premise. The audited target is the per-core base abstract specification. The Rust implementation, the FL4 extension entry points and an end-to-end boot equivalence are outside this theorem’s scope. + +## Successful executions + +Both kernel-entry witnesses instantiate `patched_callKernel_equiv` directly. Each proves result membership and no failure on both sides and relates the resulting states. + +| Witness in `Equiv/Witness.lean` | Checked execution | +| --- | --- | +| `liveOneTickInterruptWitness` | A masked interrupt passes through scheduling and activation, advances both oracle positions to 1, charges one tick, and reduces the domain countdown by one. | +| `liveNbWaitWitness` | A nonblocking wait consumes a notification, writes badge `0x62` and leaves the notification idle. | +| `liveScheduleWitness` | A direct successful scheduler execution from the state reached by the wait. | +| `livePageUnmapWitness`, `liveArchPageUnmapWitness` | The native frame performer and the architecture dispatcher clear a stale mapping cap after an absent ASID lookup. | +| `livePageTableUnmapWitness`, `livePageDirectoryUnmapWitness` | Each native unmap reads a populated cap with no installed mapping and writes back its unmapped form. | +| `liveInvokeIrqControlWitness`, `liveInvokeIrqHandlerWitness` | IRQ issue enters IRQSignal and inserts the cap. The set-handler invocation binds the reached notification. | +| `liveInvokeTcbInstallWitness` | The TCB installs a non-null notification fault-handler cap after concrete deletion and identity checks. | +| `liveMakeAsidPoolWitness` | The architecture dispatcher zeroes the backing page, updates the untyped parent, creates the pool, inserts its cap and sets ASID table slot 0 to `0x6000`. | +| `liveLinkedFaultReplyWitness` | The fault reply consumes the reply-object link, clears the caller’s fault and restarts the caller. | +| `liveSetCapWitness`, `liveCapInsertWitness` | Direct cap write and insertion reach the populated destination and related post-states. | + +## Checked reference differences + +The authorized X64 MCS Isabelle overlay makes the pinned upstream session +usable. Its typed export supplies the generated `Spec/` definitions. The +left side of `patched_callKernel_equiv` is `call_kernel_p` and its +hand-patched call tree, which propagates the named `Patched.lean` deltas. +There are 129 `_p` definitions in the suite, including 128 across 12 +`Equiv/` modules and `free_asid_select_p` in `Patched.lean`. This total +includes factored helpers and specialized entry points. The +[patched-definition inventory](PATCHED_INVENTORY.md) maps each wrapper to +its generated original or containing operation and gives the reason for +the adaptation. + +Lean checks the equivalence from this patched tree to frozen FL4 and the +point deltas listed below. Correspondence of the wrapper transcriptions +to the generated originals is checked by inspection and review and is part +of the trusted computing base. Per-wrapper Lean equality across that +boundary is outside the proof. + +| Theorem | Checked boundary | +| --- | --- | +| `newContext_selectors_delta` | Initial CS/SS change from `0x2B/0x33` to `0x33/0x2B`. This was an accepted Phase 1 Bucket A finding. | +| `decodeObjectType_codes7to11_delta` | Codes 7–11 have no upstream architecture object and decode to the VCPU and four EPT table types in FL4. This was an accepted Phase 1 Bucket A finding. | +| `notificationBits_delta`, `objBitsApi_ntfn_delta`, `objSize_ntfn_delta` | Notification size changes from 5 to 6 bits, including the retype and CSpace entry points. | +| `asidWidths_delta`, `asidFreeIndex_delta` | The high ASID field widens from 3 to 11 bits and the total width from 12 to 20. If all eight upstream indices are occupied, index eight is free in the embedding and its base lies outside the common range. | +| `cr3Mask_preserved` | The CR3 address mask preserves the 12-bit PCID layout. | +| `tcbEptSlot_delta`, `finaliseTcbZombieSlots_delta` | The extra EPT slot is empty on the base carriers and final TCB cleanup returns six zombie slots instead of five. | +| `lookupIpcBuffer_slot_delta`, `makeArchFaultMsg_delta` | The IPC frame moves from slot four to slot two and the VMFault message label moves from five to six. | +| `ioPortOwner_delta` | The native upstream I/O cap embeds with an empty FL4 owner. | +| `invocationLabel_numbering_delta`, `cnodeRevoke_label_delta` | All 59 shared labels decode at their respective numeric ABIs. For example, CNodeRevoke moves from 18 to 25. | +| `hugePages_delta` | With 1 GiB support disabled, FL4 rejects the mapping before a slot read. Upstream can return a mapping when the PDPT lookup succeeds. | +| `endTimeslice_runningVM_delta` | Under the stated non-round-robin read and handler observations, upstream calls the timeout handler whereas an FL4 running VM takes the requeue or postpone path. | +| `compiledNumDomains_delta`, `maxPeriodUs_delta` | A one-domain configuration is incompatible with the PC99 relation. The reference fixes the period maximum at one hour and FL4 obtains it from its platform constant. | + +See the [README](README.md) for the input pins, provenance, and verification commands. diff --git a/proofs/Fl4SpecEquivX64/README.md b/proofs/Fl4SpecEquivX64/README.md new file mode 100644 index 000000000..3aef7135b --- /dev/null +++ b/proofs/Fl4SpecEquivX64/README.md @@ -0,0 +1,164 @@ +# FL4 and l4v X64 MCS abstract specification equivalence + +This standalone Lean suite proves single-step equivalence between +`Fl4Spec.callKernel` and the hand-patched Isabelle/HOL X64 MCS reference. The main +theorem, [`patched_callKernel_equiv`](L4vRefX64/Equiv/Syscall.lean), assumes +`CallKernelSafe` and a related input pair. Its `MRelStep` conclusion matches +the failure indicators and relates every result and post-state in both +directions. + +`CallKernelSafe` admits the native base carriers and applies continuation +guards to the runs that reach them. Each subsequent step requires its own +admission. `ConfigRel` relates the fixed FL4 configuration to the generated +PC99 MCS configuration. `OpaqueRel RestRel` relates the opaque machine +operations, time constants, and oracles. The configuration witness constructs +a matching 16-domain configuration value, and the concrete execution witnesses +instantiate the guarded routes under these residual premises. + +Run this suite explicitly. It sits outside the default P0–P3 Lake and CI build +graph. See the [proof report](PHASE2_REPORT.md) for the witness branches, +specification deltas, and scope. + +## Pinned inputs + +| Input | Revision | +| --- | --- | +| [FL4 base abstract spec](../Fl4Spec) | `ed6b927999d462bc217cfcd44a5b02b8bab7c4ff` | +| seL4/l4v `rt` | `f44de69e426184f5edff14aeb8d8e03385f33c01` | +| seL4/seL4 | `c98d70adf15e8be7d3b99085c28d057069ba7155` | +| Isabelle | Isabelle2025-2 | + +The [X64 MCS build overlay](overlay/x64-mcs-overlay.patch) has SHA-256 +`a4d0d1fedd485661a71e95dd2b3123387146417c9e068d4f1cc40445b61f6021`. +Its [provenance](overlay/overlay-provenance.md) traces each hunk to the pinned +upstream inputs. The overlay addresses the X64 MCS build. + +## Trusted Computing Base (TCB) + +The Isabelle-to-Lean boundary comprises [`tools/ExportASpec.ML`](tools/ExportASpec.ML), +[`tools/emit_l4v_ref.py`](tools/emit_l4v_ref.py), the [X64 MCS Isabelle overlay](overlay/x64-mcs-overlay.patch), +[`L4vRefX64/Prim.lean`](L4vRefX64/Prim.lean), and +[`L4vRefX64/PrimX64.lean`](L4vRefX64/PrimX64.lean). + +The left side of `patched_callKernel_equiv` is `call_kernel_p` and its +hand-patched call tree. The suite contains 129 definitions with the `_p` +suffix. Of these, 128 are in 12 `Equiv/` modules and +`free_asid_select_p` is in `Patched.lean`. The wrappers propagate the +explicit deltas up to the kernel entry and include factored helpers and +specialized entries used by the witnesses. Lean checks the stated +point-delta theorems against the generated `Spec/` definitions and the +equivalence of the patched tree to FL4. Correspondence of the wrapper +transcriptions to their generated originals is established by inspection +and review. The suite has no per-wrapper Lean equality claims over that +boundary. The [patched-definition inventory](PATCHED_INVENTORY.md) names +the original operation and reason for every wrapper. + +Root repository pointers are planned for a follow-up after +[#157](https://github.com/losfair/FL4/pull/157) and +[#158](https://github.com/losfair/FL4/pull/158) merge. + +## Build and check axioms + +Set up the pinned `proofs/` Lake dependencies using the repository’s Lean +toolchain. From the FL4 root, run: + +```bash +cd proofs +lake build Fl4Spec +build_dir=$(mktemp -d) +lake env python3 Fl4SpecEquivX64/tools/build.py Fl4SpecEquivX64 "$build_dir" +``` + +Use a **fresh `build_dir`** for a full audit, and whenever the frozen +`Fl4Spec` dependencies change. The incremental builder tracks files and Lean +outputs inside this suite. It does not track modification times of the +external `Fl4Spec` outputs. A full run rebuilds every standalone module, +rejects warnings and unexpected manifest output, and checks the exact theorem +list against the allowlist of `propext`, `Classical.choice`, and `Quot.sound`. +Expected final lines: + +```text +AXIOM_AUDIT PASS: 1043/1043 theorems strictly standard +BUILD OK: 100 rebuilt, 100 total +``` + +From `proofs/`, run `python3 Fl4SpecEquivX64/tools/test_build.py -v` to test +the gate with synthetic success, missing required theorems, disallowed +axioms, and compiler warnings. + +## Reproduce the Isabelle reference + +Use a disposable l4v checkout at the pin with seL4 at the pin in a sibling +directory named `seL4`. Use Isabelle2025-2 and the pinned l4v checkout’s +build prerequisites. Set `suite` to the absolute path to this directory, +`l4v` to the disposable checkout, and `export_dir` to the absolute path of an +empty directory. +From any starting directory: + +```bash +export L4V_ARCH=X64 L4V_FEATURES=MCS +sel4=$(cd "$l4v/../seL4" && pwd) +test "$(git -C "$l4v" rev-parse HEAD)" = f44de69e426184f5edff14aeb8d8e03385f33c01 +test "$(git -C "$sel4" rev-parse HEAD)" = c98d70adf15e8be7d3b99085c28d057069ba7155 +git -C "$l4v" apply "$suite/overlay/x64-mcs-overlay.patch" +cd "$l4v" +l4v=$PWD +make -C spec ASpec-files design-spec TOOLPREFIX=/usr/bin/ ISABELLE_OUTPUT= \ + CONFIG="$sel4/configs/X64_verified.cmake" \ + 'KERNEL_CMAKE_EXTRA_OPTIONS=-DKernelIsMCS=ON -DKernelStaticMaxPeriodUs=3600000000' + +# Generate the X64 templates directly where the pinned design target lacks them. +mkdir -p "$export_dir/common" spec/design/X64 spec/machine/X64 +{ + for src in "$l4v"/spec/design/skel/*.thy; do + printf '%s --> %s\n' "$src" "$export_dir/common/${src##*/}" + done + for src in "$l4v"/spec/design/skel/X64/*.thy; do + printf '%s --> %s\n' "$src" "$l4v/spec/design/X64/${src##*/}" + done + for src in "$l4v"/spec/design/m-skel/X64/*.thy; do + printf '%s --> %s\n' "$src" "$l4v/spec/machine/X64/${src##*/}" + done +} > "$export_dir/filenames.txt" +( + cd tools/haskell-translator + L4CAP="$l4v/spec/haskell" L4CPP=-Wno-unicode python3 pars_skl.py "$export_dir/filenames.txt" +) +isabelle build -b -o document=false -o document_variants= -d . ASpec +``` + +From the l4v root, export from `ASpec.Syscall_A` with the committed +[`tools/phase1-theories.txt`](tools/phase1-theories.txt) list. It includes the +71 exported theories, including support theories. The emitter selects +definitions from this export and produces 59 generated Lean theory files. + +```bash +export ASPEC_EXPORT_ML="$suite/tools/ExportASpec.ML" +export ASPEC_RUN_EXPORT_ML="$suite/tools/Run_X64_Export.ML" +export ASPEC_THEORY_LIST="$suite/tools/phase1-theories.txt" +export ASPEC_EXPORT_OUTPUT="$export_dir/aspec-full.jsonl" +isabelle ML_process -l ASpec -d . -e ' + Context.setmp_generic_context + (SOME (Context.Theory (Thy_Info.get_theory "ASpec.Syscall_A"))) + (fn () => ( + ML_Context.eval_file ML_Compiler.flags (Path.explode (getenv "ASPEC_EXPORT_ML")); + ML_Context.eval_file ML_Compiler.flags (Path.explode (getenv "ASPEC_RUN_EXPORT_ML")))) () +' Arch IPC Cancelling\ + + theory ArchIpcCancel_A +-imports CSpaceAcc_A ++imports Sporadic_A + begin + + context Arch begin arch_global_naming (A) +diff --git a/spec/abstract/X64/Arch_A.thy b/spec/abstract/X64/Arch_A.thy +index 6cd85cc7..3a764efe 100644 +--- a/spec/abstract/X64/Arch_A.thy ++++ b/spec/abstract/X64/Arch_A.thy +@@ -12,7 +12,7 @@ Entry point for architecture dependent definitions. + chapter "Toplevel x64 Definitions" + + theory Arch_A +-imports TcbAcc_A ++imports CSpace_A + begin + + context Arch begin arch_global_naming (A) +diff --git a/spec/abstract/X64/Arch_Structs_A.thy b/spec/abstract/X64/Arch_Structs_A.thy +index 50ebff63..be5266f7 100644 +--- a/spec/abstract/X64/Arch_Structs_A.thy ++++ b/spec/abstract/X64/Arch_Structs_A.thy +@@ -178,6 +178,12 @@ where + | "arch_cap_is_device (PDPointerTableCap _ _) = False" + | "arch_cap_is_device (PML4Cap _ _) = False" + ++(* No badges on arch capabilities on this architecture *) ++definition arch_cap_badge :: "arch_cap \ machine_word option" where ++ "arch_cap_badge acap \ None" ++ ++lemmas arch_cap_badge_simps[simp] = arch_cap_badge_def ++ + definition tcb_bits :: nat where + "tcb_bits \ 11" + +@@ -187,6 +193,10 @@ definition endpoint_bits :: nat where + definition ntfn_bits :: nat where + "ntfn_bits \ 5" + ++definition reply_bits :: nat ++ where ++ "reply_bits \ 5" ++ + definition untyped_min_bits :: nat where + "untyped_min_bits \ 4" + +@@ -448,6 +458,14 @@ definition + where + "arch_tcb_get_registers a_tcb \ user_regs (tcb_context a_tcb)" + ++text \ Time \ ++ ++definition parse_time_arg :: "nat \ machine_word list \ time" where ++ "parse_time_arg i args = ucast (args ! i)" ++ ++definition words_from_time :: "time \ machine_word list" where ++ "words_from_time t = [ucast t]" ++ + end + + end +diff --git a/spec/abstract/X64/Init_A.thy b/spec/abstract/X64/Init_A.thy +index 9e9bfe6b..22e06cc1 100644 +--- a/spec/abstract/X64/Init_A.thy ++++ b/spec/abstract/X64/Init_A.thy +@@ -84,21 +84,27 @@ definition + TCB \ + tcb_ctable = NullCap, + tcb_vtable = NullCap, +- tcb_reply = NullCap, +- tcb_caller = NullCap, + tcb_ipcframe = NullCap, ++ tcb_fault_handler = NullCap, ++ tcb_timeout_handler = NullCap, + tcb_state = IdleThreadState, +- tcb_fault_handler = replicate word_bits False, + tcb_ipc_buffer = 0, + tcb_fault = None, + tcb_bound_notification = None, + tcb_mcpriority = minBound, ++ tcb_sched_context = Some idle_sc_ptr, ++ tcb_yield_to = None, + tcb_priority = 0, +- tcb_time_slice = timeSlice, + tcb_domain = default_domain, + tcb_flags = {}, + tcb_arch = init_arch_tcb + \, ++ idle_sc_ptr \ SchedContext (default_sched_context ++ \sc_tcb := Some idle_thread_ptr, ++ sc_refills := [\r_time = 0, r_amount = MAX_PERIOD\, ++ \r_time = MAX_PERIOD, r_amount = 0\], ++ sc_budget := MAX_PERIOD, ++ sc_refill_max := MIN_REFILLS\) 0, + init_global_pml4 \ ArchObj (PageMapL4 global_pml4), + init_global_pdpt \ ArchObj (PDPointerTable global_pdpt), + init_global_pd \ ArchObj (PageDirectory global_pd) +@@ -119,6 +125,10 @@ definition + is_original_cap = init_ioc, + cur_thread = idle_thread_ptr, + idle_thread = idle_thread_ptr, ++ consumed_time = 0, ++ cur_time = 0, ++ cur_sc = idle_sc_ptr, ++ reprogram_timer = False, + scheduler_action = resume_cur_thread, + domain_list = [(0, -1), (0, 0)], + domain_index = 0, +@@ -126,6 +136,7 @@ definition + cur_domain = 0, + domain_time = 15, + ready_queues = const (const []), ++ release_queue = [], + machine_state = init_machine_state, + interrupt_irq_node = \irq. init_irq_node_ptr + (ucast irq << cte_level_bits), + interrupt_states = \_. Structures_A.IRQInactive, +diff --git a/spec/abstract/X64/Machine_A.thy b/spec/abstract/X64/Machine_A.thy +index b8d9aeb0..009f0a94 100644 +--- a/spec/abstract/X64/Machine_A.thy ++++ b/spec/abstract/X64/Machine_A.thy +@@ -132,9 +132,12 @@ definition + idle_thread_ptr :: vspace_ref where + "idle_thread_ptr = kernel_base + 0x1000" + ++definition idle_sc_ptr :: vspace_ref where ++ "idle_sc_ptr = kernel_base + 0x7000" ++ + end + +-arch_requalify_consts (A) idle_thread_ptr ++arch_requalify_consts (A) idle_thread_ptr idle_sc_ptr + + context Arch begin arch_global_naming (A) + +diff --git a/spec/design/m-skel/X64/MachineTypes.thy b/spec/design/m-skel/X64/MachineTypes.thy +index 5a686861..e477135c 100644 +--- a/spec/design/m-skel/X64/MachineTypes.thy ++++ b/spec/design/m-skel/X64/MachineTypes.thy +@@ -36,6 +36,17 @@ context Arch begin arch_global_naming + (*>*) + #INCLUDE_HASKELL SEL4/Machine/RegisterSet/X64.lhs CONTEXT X64 bodies_only NOT getRegister setRegister getFPUState setFPUState newContext + ++definition replyRegister :: register where ++ "replyRegister \ R12" ++ ++definition nbsendRecvDest :: register where ++ "nbsendRecvDest \ R13" ++ ++definition timeoutMessage :: "register list" where ++ "timeoutMessage \ ++ [FaultIP, RSP, FLAGS, RAX, RBX, RCX, RDX, RSI, RDI, RBP, ++ R8, R9, R10, R11, R12, R13, R14, R15, FS_BASE]" ++ + section "Machine State" + + text \ +@@ -52,6 +63,8 @@ qualify X64 (in Arch) + record machine_state = + irq_masks :: "X64.irq \ bool" + irq_state :: nat ++ time_state :: nat \ \position in the time oracle\ ++ last_machine_time :: "64 word" \ \value we read from timer device\ + underlying_memory :: "word64 \ word8" + device_state :: "word64 \ word8 option" + fpu_enabled :: bool +@@ -59,6 +72,10 @@ record machine_state = + + consts irq_oracle :: "nat \ word8" + ++text \The values the timer device will return (how much time passed since last query)\ ++axiomatization ++ time_oracle :: "nat \ nat" ++ + end_qualify + + context Arch begin arch_global_naming +@@ -85,6 +102,8 @@ text \We leave open the underspecified rest of the machine state in the in + definition init_machine_state :: machine_state where + "init_machine_state \ \ irq_masks = init_irq_masks, + irq_state = 0, ++ time_state = 0, ++ last_machine_time = 0, + underlying_memory = init_underlying_memory, + device_state = Map.empty, + fpu_enabled = False, +diff --git a/spec/design/skel/X64/Arch_Structs_B.thy b/spec/design/skel/X64/Arch_Structs_B.thy +index 077fa728..5e886757 100644 +--- a/spec/design/skel/X64/Arch_Structs_B.thy ++++ b/spec/design/skel/X64/Arch_Structs_B.thy +@@ -18,6 +18,12 @@ context Arch begin arch_global_naming (H) + #INCLUDE_HASKELL SEL4/Model/StateData/X64.lhs CONTEXT X64_H ONLY X64VSpaceRegionUse + #INCLUDE_HASKELL SEL4/Object/Structures/X64.lhs ONLY parseTimeArg + ++definition timerPrecision :: "word64" where ++ "timerPrecision \ us_to_ticks 1" ++ + end (* context X64 *) + ++arch_requalify_consts (H) ++ timerPrecision ++ + end +diff --git a/spec/machine/X64/MachineOps.thy b/spec/machine/X64/MachineOps.thy +index cac284dd..ebafdd4f 100644 +--- a/spec/machine/X64/MachineOps.thy ++++ b/spec/machine/X64/MachineOps.thy +@@ -11,6 +11,7 @@ theory MachineOps + Word_Lib.WordSetup + Monads.Nondet_Monad + MachineMonad ++ Time + begin + + section "Wrapping and Lifting Machine Operations" +@@ -103,6 +104,32 @@ consts' resetTimer_impl :: "unit machine_rest_monad" + definition resetTimer :: "unit machine_monad" where + "resetTimer \ machine_op_lift resetTimer_impl" + ++text \ ++This encodes the following assumptions: ++ a) time increases monotonically, ++ b) global 64-bit time does not overflow during the lifetime of the system. ++\ ++definition ++ getCurrentTime :: "64 word machine_monad" ++where ++ "getCurrentTime = do ++ modify (\s. s \ time_state := time_state s + 1 \); ++ passed \ gets $ time_oracle o time_state; ++ last' \ gets last_machine_time; ++ last \ return (unat last'); ++ current \ return (min (unat (-(getCurrentTime_buffer + 1))) (last + passed)); ++ modify (\s. s\last_machine_time := of_nat current\); ++ return (of_nat current) ++ od" ++ ++consts' ++ setDeadline_impl :: "64 word \ unit machine_rest_monad" ++ ++definition ++ setDeadline :: "64 word \ unit machine_monad" ++where ++ "setDeadline d \ machine_op_lift (setDeadline_impl d)" ++ + consts' invalidateTLB_impl :: "unit machine_rest_monad" + definition invalidateTLB :: "unit machine_monad" where + "invalidateTLB \ machine_op_lift invalidateTLB_impl" +@@ -144,6 +171,9 @@ text \Does nothing on imx31\ + definition ackInterrupt :: "irq \ unit machine_monad" where + "ackInterrupt \ \irq. return ()" + ++definition ackDeadlineIRQ :: "unit machine_monad" where ++ "ackDeadlineIRQ \ return ()" ++ + text \Does nothing on imx31\ + definition setInterruptMode :: "irq \ bool \ bool \ unit machine_monad" where + "setInterruptMode \ \irq levelTrigger polarityLow. return ()" +diff --git a/spec/machine/X64/Platform.thy b/spec/machine/X64/Platform.thy +index 95b9c8e6..6c6adc7a 100644 +--- a/spec/machine/X64/Platform.thy ++++ b/spec/machine/X64/Platform.thy +@@ -59,6 +59,9 @@ definition minIRQ :: "irq" where + definition maxIRQ :: "irq" where + "maxIRQ \ 125" + ++definition timerIRQ :: "irq" where ++ "timerIRQ \ maxIRQ" ++ + definition minUserIRQ :: "irq" where + "minUserIRQ \ 16" + diff --git a/proofs/Fl4SpecEquivX64/tools/ExportASpec.ML b/proofs/Fl4SpecEquivX64/tools/ExportASpec.ML new file mode 100644 index 000000000..b9897a53b --- /dev/null +++ b/proofs/Fl4SpecEquivX64/tools/ExportASpec.ML @@ -0,0 +1,391 @@ +(* Read typed terms and declaration metadata from an Isabelle heap. *) +structure Export_ASpec = +struct + +fun quote s = + let + fun escape #"\"" = "\\\"" + | escape #"\\" = "\\\\" + | escape c = + if Char.ord c < 32 then + let + val digits = "0123456789abcdef" + val n = Char.ord c + in "\\u00" ^ str (String.sub (digits, n div 16)) ^ str (String.sub (digits, n mod 16)) end + else str c + in "\"" ^ String.translate escape s ^ "\"" end + +fun array values = "[" ^ commas values ^ "]" +fun object entries = "{" ^ commas (map (fn (k, v) => quote k ^ ":" ^ v) entries) ^ "}" +fun tagged name items = array (quote name :: items) +fun option f = the_default "null" o Option.map f +fun strings ss = array (map quote ss) +fun bool b = if b then "true" else "false" +fun number n = if n < 0 then "-" ^ Int.toString (~ n) else Int.toString n + +fun typ (Type (name, args)) = tagged "Type" [quote name, array (map typ args)] + | typ (TFree (name, sorts)) = tagged "TFree" [quote name, strings sorts] + | typ (TVar ((name, index), sorts)) = tagged "TVar" [quote name, number index, strings sorts] + +fun term (Const (name, T)) = tagged "Const" [quote name, typ T] + | term (Free (name, T)) = tagged "Free" [quote name, typ T] + | term (Var ((name, index), T)) = tagged "Var" [quote name, number index, typ T] + | term (Bound index) = tagged "Bound" [number index] + | term (Abs (name, T, body)) = tagged "Abs" [quote name, typ T, term body] + | term (f $ x) = tagged "App" [term f, term x] + +fun origin pos = + object [("file", option quote (Position.file_of pos)), + ("line", option number (Position.line_of pos)), + ("offset", option number (Position.offset_of pos))] + +fun declaration space name = origin (#pos (Name_Space.the_entry space name)) +fun theory_name thy = Context.theory_long_name thy + +fun ctr_kind Ctr_Sugar.Datatype = "datatype" + | ctr_kind Ctr_Sugar.Codatatype = "codatatype" + | ctr_kind Ctr_Sugar.Record = "record_sugar" + | ctr_kind Ctr_Sugar.Unknown = "constructor_sugar" + +fun classification (Spec_Rules.Equational (Spec_Rules.Primrec _)) = "primrec" + | classification (Spec_Rules.Equational Spec_Rules.Recdef) = "recdef" + | classification (Spec_Rules.Equational (Spec_Rules.Primcorec _)) = "primcorec" + | classification (Spec_Rules.Equational Spec_Rules.Corec) = "corec" + | classification (Spec_Rules.Equational Spec_Rules.Unknown_Recursion) = "equational" + | classification Spec_Rules.Inductive = "inductive" + | classification Spec_Rules.Co_Inductive = "coinductive" + | classification Spec_Rules.Unknown = "unknown" + +fun head_constant t = + (case Term.head_of t of Const (name, _) => SOME name | _ => NONE) + +fun local_to parents space name = + not (exists (fn parent => Name_Space.declared (space parent) name) parents) + +fun read_theory thy = + let + val name = theory_name thy + val parents = Theory.parents_of thy + val {types, ...} = Type.rep_tsig (Sign.tsig_of thy) + val consts = #constants (Consts.dest (Sign.consts_of thy)) + val new_types = Name_Space.dest_table types |> filter (local_to parents Sign.type_space o #1) + val new_consts = consts |> filter (local_to parents Sign.const_space o #1) + val definitions = Defs.dest_constdefs (map Theory.defs_of parents) (Theory.defs_of thy) + |> sort (prod_ord string_ord string_ord) + val rules = Spec_Rules.dest_theory thy + val record_infos = map_filter (fn (c, _) => + Option.map (pair c) (Record.get_info thy c)) new_types + val constructor_infos = map_filter (fn (c, _) => + Option.map (pair c) (Ctr_Sugar.ctr_sugar_of_global thy c)) new_types + val axioms = Theory.all_axioms_of thy |> filter (local_to parents Theory.axiom_space o #1) + val dependencies = Locale.dest_dependencies parents thy + val locales = Locale.get_locales thy |> filter (local_to parents Locale.locale_space) + val classes = Name_Space.get_names (Sign.class_space thy) |> filter (local_to parents Sign.class_space) + val facts = Name_Space.get_names (Global_Theory.fact_space thy) + |> filter (local_to parents Global_Theory.fact_space) + in + {thy = thy, new_types = new_types, new_consts = new_consts, definitions = definitions, + rules = rules, record_infos = record_infos, constructor_infos = constructor_infos, + axioms = axioms, dependencies = dependencies, locales = locales, classes = classes, facts = facts} + end + +fun definition_props thy axiom_table fact = + (case Symtab.lookup axiom_table fact of + SOME prop => ("definitional_axiom", [prop]) + | NONE => ("named_theorem", map Thm.prop_of (Global_Theory.get_thms thy fact))) + +fun generated_family name = + let + fun has prefix = exists (String.isPrefix prefix) (Long_Name.explode name) + fun under prefix = String.isPrefix prefix name + in + if under "Quickcheck_" orelse under "Random_Pred." orelse under "Random." orelse + under "Predicate_Compile." orelse has "random_" orelse has "exhaustive_" orelse + has "full_exhaustive_" orelse has "narrowing_" orelse has "partial_term_of_" + then SOME "isabelle_generated_quickcheck" + else if under "Typerep." orelse under "Code_Evaluation." orelse + has "typerep_" orelse has "term_of_" + then SOME "isabelle_generated_type_representation" + else NONE + end + +type reference_audit = + {omitted: Symtab.set, roots: string Symtab.table, traversed: int, + candidate_count: int, missing_definitions: (string * string) list} + +fun audit_references theories : reference_audit = + let + val roots = Unsynchronized.ref Symtab.empty + val generated_edges = Unsynchronized.ref Symtab.empty + val traversed = Unsynchronized.ref 0 + val missing_definitions = Unsynchronized.ref [] + val all_candidates = fold + (fn data => fold (fn (name, _) => + if is_some (generated_family name) then Symtab.insert_set name else I) (#new_consts data)) + theories Symtab.empty + fun candidate name = Symtab.defined all_candidates name + fun visit owners origin terms = + let + val _ = traversed := !traversed + 1 + val refs = build (fold Term.add_const_names terms) |> filter candidate |> distinct (op =) + in + if null refs then () + else if not (null owners) andalso forall candidate owners + then generated_edges := fold (fn owner => Symtab.map_default (owner, []) (append refs)) + owners (!generated_edges) + else roots := fold (fn ref_name => Symtab.default (ref_name, origin)) refs (!roots) + end + fun scan {thy, new_types = _, new_consts, definitions, rules, record_infos = _, + constructor_infos, axioms, dependencies, locales, classes = _, facts = _} = + let + val axiom_table = Symtab.make axioms + val def_names = Symtab.make_set (map #2 definitions) + fun scan_def (c, fact) = + (case Exn.capture (definition_props thy axiom_table) fact of + Exn.Res (_, props) => visit [c] fact props + | Exn.Exn exn => + if Exn.is_interrupt exn then Exn.reraise exn + else missing_definitions := (c, fact) :: !missing_definitions) + fun scan_rule ({name, terms, rules, ...}: Spec_Rules.spec_rule) = + visit (map_filter head_constant terms) name (terms @ map Thm.prop_of rules) + fun scan_constructor (type_name, {ctrs, casex, discs, selss, ...}: Ctr_Sugar.ctr_sugar) = + visit [] type_name (ctrs @ [casex] @ discs @ flat selss) + fun scan_locale ({source, morphism, ...}: Locale.locale_dependency) = + let + val (_, params) = Locale.parameters_of thy source + in + visit [] source (map (Morphism.term morphism o Free o #1) params) + end + fun scan_locale_spec name = + let val (assumption, definitions) = Locale.specification_of thy name + in visit [] name (the_list assumption @ definitions) end + in + List.app scan_def definitions; + List.app scan_rule rules; + List.app scan_constructor constructor_infos; + List.app scan_locale dependencies; + List.app scan_locale_spec locales; + List.app (fn (c, (_, abbrev)) => Option.app (fn t => visit [c] c [t]) abbrev) new_consts; + List.app (fn (a, p) => if Symtab.defined def_names a then () else visit [] a [p]) axioms + end + val _ = List.app scan theories + fun reachable [] seen = seen + | reachable ((parent, edge) :: pending) seen = + if Symtab.defined seen edge then reachable pending seen + else reachable + (map (pair edge) (Symtab.lookup_list (!generated_edges) edge) @ pending) + (Symtab.update (edge, parent) seen) + val retained = reachable (map swap (Symtab.dest (!roots))) Symtab.empty + val omitted = + if null (!missing_definitions) + then Symtab.fold (fn (c, _) => if Symtab.defined retained c then I else Symtab.insert_set c) + all_candidates Symtab.empty + else Symtab.empty + in + {omitted = omitted, roots = retained, traversed = !traversed, + candidate_count = Symtab.size all_candidates, missing_definitions = rev (!missing_definitions)} + end + +fun emit_theory put include_terms audit + {thy, new_types, new_consts, definitions, rules, record_infos, constructor_infos, + axioms, dependencies, locales, classes, facts} = + let + val name = theory_name thy + val parents = Theory.parents_of thy + val axiom_table = Symtab.make axioms + fun omitted c = exists (fn ({omitted, ...}: reference_audit) => Symtab.defined omitted c) (the_list audit) + fun skip_group names = not (null names) andalso forall omitted names + fun names_of ts = map_filter head_constant ts + val constructors = Symtab.make_set (maps (names_of o #ctrs o #2) constructor_infos) + val case_operators = Symtab.make_set (map_filter (head_constant o #casex o #2) constructor_infos) + val record_fields = Symtab.make_set (maps (map #1 o #fields o #2) record_infos) + val defined_names = Symtab.make_set (map #1 definitions) + fun bnf_ops bnf = + names_of (BNF_Def.map_of_bnf bnf :: BNF_Def.pred_of_bnf bnf :: + BNF_Def.rel_of_bnf bnf :: BNF_Def.sets_of_bnf bnf) + fun datatype_ops (c, _) = + let + val bnf = maps bnf_ops (the_list (BNF_Def.bnf_of_global thy c)) + val recs = map_filter (head_constant o #co_rec) + (maps (the_list o #fp_co_induct_sugar) (the_list (BNF_FP_Def_Sugar.fp_sugar_of_global thy c))) + val sizes = map (#1) (the_list (BNF_LFP_Size.size_of_global thy c)) + in + map (rpair "bnf_boilerplate") bnf @ map (rpair "datatype_recursion") (recs @ sizes) + end + fun lhs_name theorem = + let val (lhs, _) = Logic.dest_equals (Thm.prop_of theorem) + in head_constant lhs end + handle TERM _ => NONE + fun record_ops (_, {ext_def, select_defs, update_defs, defs, ...}: Record.info) = + map (rpair "record_package") (map_filter lhs_name (ext_def :: select_defs @ update_defs @ defs)) + val package_roles = Symtab.make (distinct (eq_fst (op =)) + (maps datatype_ops constructor_infos @ maps record_ops record_infos)) + fun const_class c = + (case generated_family c of + SOME kind => kind + | NONE => + if Symtab.defined constructors c then "datatype_constructor" + else if Symtab.defined case_operators c then "datatype_case" + else if Symtab.defined record_fields c then "record_field" + else if Symtab.defined defined_names c then "defined_constant" + else "declared_or_abbreviated_constant") + val fact_space = Global_Theory.fact_space thy + val axiom_space = Theory.axiom_space thy + + fun row kind fields = put (object (("kind", quote kind) :: ("theory", quote name) :: fields)) + fun constant_entry (c, (T, abbrev)) = + object [("name", quote c), ("type", typ T), + ("abbreviation", if omitted c then "null" else option term abbrev), + ("body_omitted", bool (omitted c)), + ("source", declaration (Sign.const_space thy) c), + ("classification", quote (const_class c))] + fun type_entry (c, decl) = + object [("name", quote c), ("source", declaration (Sign.type_space thy) c), + ("declaration", + (case decl of + Type.Logical_Type n => tagged "logical" [number n] + | Type.Abbreviation (args, T, syntactic) => + tagged "abbreviation" [strings args, typ T, bool syntactic] + | Type.Nonterminal => tagged "nonterminal" []))] + fun record_entry (c, {parent, fields, extension, ...}: Record.info) = + object [("name", quote c), ("source", declaration (Sign.type_space thy) c), + ("parent", option (fn (Ts, p) => array [quote p, array (map typ Ts)]) parent), + ("fields", array (map (fn (f, T) => array [quote f, typ T]) fields)), + ("extension", array [quote (#1 extension), array (map typ (#2 extension))])] + fun constructors_entry (c, {kind, ctrs, casex, discs, selss, ...}: Ctr_Sugar.ctr_sugar) = + object [("name", quote c), ("source", declaration (Sign.type_space thy) c), + ("constructor_kind", quote (ctr_kind kind)), + ("constructors", array (map term ctrs)), ("case", term casex), + ("discriminators", array (map term discs)), + ("selectors", array (map (array o map term) selss))] + fun export_rule ({pos, name = rule, rough_classification, terms, rules}: Spec_Rules.spec_rule) = + let val heads = map_filter head_constant terms in + row "spec_rule" ([("name", quote rule), ("source", origin pos), + ("classification", quote (classification rough_classification)), ("heads", strings heads)] @ + (if skip_group heads then [("body_omitted", quote "unreferenced_generated")] + else [("terms", array (map term terms)), ("propositions", array (map (term o Thm.prop_of) rules))])) + end + fun definition_source c fact = + if Name_Space.declared axiom_space fact then declaration axiom_space fact + else if Name_Space.declared fact_space fact then declaration fact_space fact + else declaration (Sign.const_space thy) c + fun export_definition (c, fact) = + let + val content = + if omitted c then [("provider", quote "unreferenced_generated")] + else + (case Exn.capture (definition_props thy axiom_table) fact of + Exn.Res (provider, props) => + [("provider", quote provider), ("propositions", array (map term props))] + | Exn.Exn exn => + if Exn.is_interrupt exn then Exn.reraise exn + else [("provider", quote "unresolved"), ("error", quote (Runtime.exn_message exn))]) + in row "definition" ([("constant", quote c), ("fact", quote fact), + ("source", definition_source c fact)] @ content) end + fun export_dependency ({source, target, prefix, morphism, pos, ...}: Locale.locale_dependency) = + let + val (type_params, params) = Locale.parameters_of thy source + val param_terms = map (Free o #1) params + val type_params' = fold (Term.add_tfreesT o #2 o #1) params type_params + fun type_subst v = + let val T = TFree v; val U = Morphism.typ morphism T + in if T = U then NONE else SOME (array [typ T, typ U]) end + fun term_subst t = + let val u = Morphism.term morphism t + in if t aconv u then NONE else SOME (array [term t, term u]) end + in row "locale_dependency" + [("locale", quote source), ("target", quote target), ("source", origin pos), + ("prefix", array (map (fn (p, mandatory) => array [quote p, bool mandatory]) prefix)), + ("type_substitutions", array (map_filter type_subst type_params')), + ("term_substitutions", array (map_filter term_subst param_terms))] + end + fun export_locale locale = + let val (assumption, definitions) = Locale.specification_of thy locale in + row "locale" [("name", quote locale), + ("source", declaration (Locale.locale_space thy) locale), + ("parameters", array (map (fn ((n, T), _) => array [quote n, typ T]) (Locale.params_of thy locale))), + ("propositions", array (map term (the_list assumption @ definitions)))] + end + + val datatype_names = map_filter (fn (c, {kind, ...}: Ctr_Sugar.ctr_sugar) => + if kind = Ctr_Sugar.Datatype orelse kind = Ctr_Sugar.Codatatype then SOME c else NONE) + constructor_infos + val def_names = distinct (op =) (map #1 definitions) + val def_fact_names = Symtab.make_set (map #2 definitions) + val const_names = map #1 new_consts + val abbreviation_names = map_filter (fn (c, (_, abbrev)) => + if is_some abbrev then SOME c else NONE) new_consts + + val _ = row "inventory" + [("parents", strings (map theory_name parents)), + ("file", quote (Path.implode (Resources.master_directory thy + + Path.basic (Context.theory_base_name thy ^ ".thy")))), + ("datatypes", strings datatype_names), ("records", strings (map #1 record_infos)), + ("classes", strings classes), ("locales", strings locales), ("named_facts", strings facts), + ("constant_declarations", strings const_names), ("constant_abbreviations", strings abbreviation_names), + ("symbol_classes", object (map (fn c => (c, quote (const_class c))) const_names)), + ("package_roles", object (map (fn (c, role) => (c, quote role)) (Symtab.dest package_roles))), + ("omitted_generated_bodies", strings (filter omitted const_names)), + ("definition_facts", array (map (fn (c, f) => array [quote c, quote f]) definitions)), + ("defined_constants", strings def_names), ("axioms", strings (map #1 axioms)), + ("non_definition_axioms", strings (map #1 (filter_out (Symtab.defined def_fact_names o #1) axioms))), + ("spec_rules", array (map (fn ({name, rough_classification, terms, ...}: Spec_Rules.spec_rule) => + object [("name", quote name), ("classification", quote (classification rough_classification)), + ("heads", strings (map_filter head_constant terms))]) rules)), + ("locale_dependencies", number (length dependencies))] + val _ = + if include_terms then + (List.app (fn t => row "type" [("entry", type_entry t)]) new_types; + List.app (fn c => row "constant" [("entry", constant_entry c)]) new_consts; + List.app (fn r => row "record" [("entry", record_entry r)]) record_infos; + List.app (fn s => row "constructors" [("entry", constructors_entry s)]) constructor_infos; + List.app export_definition definitions; + List.app export_rule rules; + List.app export_dependency dependencies; + List.app export_locale locales; + List.app (fn c => row "class" + [("name", quote c), ("source", declaration (Sign.class_space thy) c), + ("super_classes", strings (Sorts.super_classes (Sign.classes_of thy) c))]) classes; + if is_some audit then + List.app (fn f => row "fact" [("name", quote f), ("source", declaration fact_space f), + ("body_status", quote (if Symtab.defined def_fact_names f then "reference_definition" else "not_exported"))]) facts + else (); + List.app (fn (a, p) => + row "axiom" ([("name", quote a), ("source", declaration axiom_space a)] @ + (if is_some audit andalso Symtab.defined def_fact_names a + then [("body_ref", quote "definition")] + else [("proposition", term p)]))) axioms) + else () + in () end + +fun run_export check_generated root_name slice output = + let + val root = Thy_Info.get_theory root_name + val closure = insert (op =) root_name (map theory_name (Theory.ancestors_of root)) + val _ = List.app (fn name => + if member (op =) closure name then () else error ("Slice theory outside root closure: " ^ name)) slice + val theory_names = filter (member (op =) closure) (Thy_Info.get_names ()) + val _ = if length theory_names = length closure then () else error "Incomplete loaded theory closure" + val theories = map (read_theory o Thy_Info.get_theory) theory_names + val audit = if check_generated then SOME (audit_references theories) else NONE + in + File_Stream.open_output (fn stream => + let fun put row = File_Stream.output stream (row ^ "\n") + fun summary ({omitted, roots, traversed, candidate_count, missing_definitions}: reference_audit) = + put (object [("kind", quote "generated_reference_audit"), + ("scanned_root_and_dependency_groups", number traversed), + ("candidate_count", number candidate_count), + ("omitted", strings (Symtab.keys omitted)), + ("retained", object (map (apsnd quote) (Symtab.dest roots))), + ("unresolved_definition_facts", + array (map (fn (c, f) => array [quote c, quote f]) missing_definitions))]) + val _ = Option.app summary audit + in List.app (fn data => + emit_theory put (member (op =) slice (theory_name (#thy data))) audit data) theories end) + (Path.explode output) + end + +val run = run_export false +val run_audit = run_export true + +end; diff --git a/proofs/Fl4SpecEquivX64/tools/Run_X64_Export.ML b/proofs/Fl4SpecEquivX64/tools/Run_X64_Export.ML new file mode 100644 index 000000000..19d761e0c --- /dev/null +++ b/proofs/Fl4SpecEquivX64/tools/Run_X64_Export.ML @@ -0,0 +1,8 @@ +local + val root_name = "ASpec.Syscall_A" + val theory_list = File.read (Path.explode (getenv "ASPEC_THEORY_LIST")) + val theories = filter_out (fn s => s = "") (split_lines theory_list) + val output = getenv "ASPEC_EXPORT_OUTPUT" +in + val _ = Export_ASpec.run_audit root_name theories output +end diff --git a/proofs/Fl4SpecEquivX64/tools/build.py b/proofs/Fl4SpecEquivX64/tools/build.py new file mode 100644 index 000000000..84fd90a69 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/tools/build.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python3 +"""Incremental parallel builder & axiom/warning gate for L4vRefX64 against prebuilt proofs/ (.olean).""" + +import concurrent.futures +import os +import re +import subprocess +import sys +from pathlib import Path + +IMPORT_RE = re.compile(r"^import\s+(L4vRefX64(?:\.[A-Za-z0-9_']+)*)", re.M) +WARNING_RE = re.compile(r"(?:^|:)\s*warning:", re.M) +AXIOM_RE = re.compile( + r"^'([^\n]+?)' (?:depends on axioms: \[([^\]]+)\]|does not depend on any axioms)$", + re.M, +) +MANIFEST_RE = re.compile(r"^#print axioms (\S+)$", re.M) +ALLOWED_AXIOMS = {"propext", "Classical.choice", "Quot.sound"} +MIN_MANIFEST_AXIOMS = 1043 +REQUIRED_MANIFEST_THEOREMS = { + "L4vRefX64.Equiv.Syscall.patched_callKernel_equiv", + "L4vRefX64.Equiv.Witness.pc99Config_exists", + "L4vRefX64.Equiv.Witness.liveOneTickInterruptWitness", + "L4vRefX64.Equiv.Witness.liveNbWaitWitness", +} + + +def discover(root: Path): + mods = {} + for p in sorted(root.rglob("*.lean")): + rel = p.relative_to(root).with_suffix("") + mod = ".".join(rel.parts) + if not mod.startswith("L4vRefX64"): + continue + deps = IMPORT_RE.findall(p.read_text()) + mods[mod] = (p, deps) + return mods + + +def build_one(mod, path, root, build_dir, env): + olean = build_dir / Path(*mod.split(".")).with_suffix(".olean") + olean.parent.mkdir(parents=True, exist_ok=True) + cmd = ["lean", "-R", str(root), "-o", str(olean), str(path)] + proc = subprocess.run(cmd, env=env, capture_output=True, text=True) + if proc.returncode or WARNING_RE.search(proc.stdout) or WARNING_RE.search(proc.stderr): + olean.unlink(missing_ok=True) + return mod, proc.returncode, proc.stdout, proc.stderr + + +def needs_build(mod, path, deps, build_dir, built_set): + # Always re-run L4vRefX64.Manifest so the axiom & warning audit gate always executes. + if mod == "L4vRefX64.Manifest": + return True + olean = build_dir / Path(*mod.split(".")).with_suffix(".olean") + if not olean.exists(): + return True + omtime = olean.stat().st_mtime + if path.stat().st_mtime > omtime: + return True + for d in deps: + if d in built_set: + return True + do = build_dir / Path(*d.split(".")).with_suffix(".olean") + if not do.exists() or do.stat().st_mtime > omtime: + return True + return False + + +def audit_manifest_output(out: str, err: str, manifest_source: str): + combined = "\n".join(s for s in (out, err) if s) + if WARNING_RE.search(combined): + return False, "unexpected compiler warning(s) in L4vRefX64.Manifest" + matches = list(AXIOM_RE.finditer(combined)) + leftover = AXIOM_RE.sub("", combined).strip() + if leftover: + return False, f"unexpected non-axiom output in L4vRefX64.Manifest:\n{leftover}" + names = {match.group(1) for match in matches} + expected = MANIFEST_RE.findall(manifest_source) + if len(names) != len(matches) or len(set(expected)) != len(expected): + return False, "duplicate theorem in L4vRefX64.Manifest" + if names != set(expected): + missing = sorted(set(expected) - names) + unexpected = sorted(names - set(expected)) + return False, f"Manifest theorem list mismatch: missing {missing}, unexpected {unexpected}" + missing_required = sorted(REQUIRED_MANIFEST_THEOREMS - names) + if missing_required: + return False, f"missing required Manifest theorems: {missing_required}" + bad = [] + for m in matches: + name = m.group(1) + if m.group(2) is None: + axs = set() + else: + axs = {a.strip() for a in m.group(2).split(",") if a.strip()} + extra = sorted(axs - ALLOWED_AXIOMS) + if extra: + bad.append((name, extra)) + if bad: + details = "\n".join(f" {n}: disallowed axioms {a}" for n, a in bad) + return False, f"disallowed axioms detected:\n{details}" + if len(matches) < MIN_MANIFEST_AXIOMS: + return False, f"expected >= {MIN_MANIFEST_AXIOMS} audited theorems, got {len(matches)}" + return True, f"AXIOM_AUDIT PASS: {len(matches)}/{len(matches)} theorems strictly standard" + + +def main(): + root = Path(sys.argv[1]).resolve() + build_dir = Path(sys.argv[2]).resolve() + targets = sys.argv[3:] if len(sys.argv) > 3 else None + jobs = int(os.environ.get("L4V_REF_JOBS", "8")) + + mods = discover(root) + if not targets and "L4vRefX64.Manifest" not in mods: + print("ERROR: full builds require L4vRefX64.Manifest", file=sys.stderr) + return 1 + # Filter to transitive closure of targets if given + if targets: + wanted = set() + stack = list(targets) + while stack: + m = stack.pop() + if m in wanted: + continue + if m not in mods: + print(f"ERROR: unknown module {m}", file=sys.stderr) + return 1 + wanted.add(m) + for d in mods[m][1]: + if d in mods: + stack.append(d) + mods = {k: v for k, v in mods.items() if k in wanted} + + env = os.environ.copy() + lp = env.get("LEAN_PATH", "") + env["LEAN_PATH"] = f"{build_dir}:{lp}" if lp else str(build_dir) + + remaining = {m: set(d for d in deps if d in mods) for m, (_, deps) in mods.items()} + done = set() + rebuilt = set() + failed = False + manifest_summary = None + + with concurrent.futures.ThreadPoolExecutor(max_workers=jobs) as ex: + while remaining and not failed: + ready = sorted(m for m, ds in remaining.items() if not (ds - done)) + if not ready: + print("ERROR: cyclic imports:", remaining, file=sys.stderr) + return 1 + to_run = [] + for m in ready: + del remaining[m] + p, deps = mods[m] + if needs_build(m, p, deps, build_dir, rebuilt): + to_run.append((m, p)) + else: + done.add(m) + if not to_run: + continue + futs = [ex.submit(build_one, m, p, root, build_dir, env) for m, p in to_run] + for fut in concurrent.futures.as_completed(futs): + m, rc, out, err = fut.result() + combined = "\n".join(s for s in (out, err) if s) + if rc != 0: + failed = True + print(f"FAIL {m} (rc={rc}):", file=sys.stderr) + if out: + print(out, file=sys.stderr) + if err: + print(err, file=sys.stderr) + elif m == "L4vRefX64.Manifest": + ok, msg = audit_manifest_output(out, err, mods[m][0].read_text()) + if not ok: + failed = True + print(f"FAIL {m} (audit failed): {msg}", file=sys.stderr) + if out: + print(out, file=sys.stderr) + if err: + print(err, file=sys.stderr) + else: + rebuilt.add(m) + done.add(m) + manifest_summary = msg + print(f"OK {m}") + if out.strip(): + print(out.strip()) + elif WARNING_RE.search(combined): + failed = True + print(f"FAIL {m} (warnings disallowed):", file=sys.stderr) + if out: + print(out, file=sys.stderr) + if err: + print(err, file=sys.stderr) + else: + rebuilt.add(m) + done.add(m) + if out.strip() or err.strip(): + print(f"OK {m} (spec output):") + if out.strip(): + print(out.strip()) + if err.strip(): + print(err.strip()) + else: + print(f"OK {m}") + if failed: + return 1 + if manifest_summary: + print(manifest_summary) + print(f"BUILD OK: {len(rebuilt)} rebuilt, {len(done)} total") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/proofs/Fl4SpecEquivX64/tools/emit_l4v_ref.py b/proofs/Fl4SpecEquivX64/tools/emit_l4v_ref.py new file mode 100644 index 000000000..3e09e57d3 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/tools/emit_l4v_ref.py @@ -0,0 +1,1727 @@ +#!/usr/bin/env python3 +"""Syntax-directed HOL to Lean 4 emitter for the generated reference. + +The X64 mode indexes the raw Isabelle kernel export `aspec-full.jsonl` +and uses the checked-in Phase 1 symbol selection. The AArch64 mode uses +its Phase 1 indexes. +""" + +from collections import defaultdict +from pathlib import Path +import json +import sys + + +LEAN_KEYWORDS = { + "abbrev", "admit", "as", "at", "attribute", "axiom", "by", "calc", "catch", "class", + "def", "deriving", "do", "elab", "elab_rules", "else", "end", "example", "exists", + "export", "exposing", "extends", "finally", "for", "forall", "from", "fun", "have", + "hiding", "if", "import", "in", "inductive", "infix", "infixl", "infixr", "init", + "instance", "lemma", "let", "macro", "macro_rules", "match", "mut", "mutual", + "namespace", "nomatch", "noncomputable", "notation", "of", "opaque", "open", + "partial", "prefix", "private", "protected", "rec", "renaming", "return", "section", + "set", "set_option", "show", "sorry", "structure", "syntax", "then", "theorem", + "to", "try", "type", "universe", "unless", "unsafe", "using", "variable", "where", + "with", "Type", "Prop", "Sort", +} + +# Only these 6 non-list recursive Isabelle `function`-package functions emit +# their raw kernel `*_graph` / `*_rel` / `*_sumC` / `f` definitions directly +# (100% faithful to Isabelle's partial-function / lfp semantics without needing +# termination_by synthesis). +SIX_REC = [ + "ArchVSpaceAcc_A.AARCH64_A.pt_walk", + "ArchVSpaceAcc_A.AARCH64_A.pt_lookup_from_level", + "CSpace_A.resolve_address_bits'", + "CSpace_A.rec_del", + "CSpace_A.cap_revoke", + "Deterministic_A.next_not_child", +] + +# Known concrete length typedefs in ASpec (checked in Phase 1 type-comparisons) +HOL_TYPEDEF_LENS = { + "Machine_A.X64_A.asid_high_len": 3, + "Machine_A.X64_A.asid_len": 12, + "Machine_A.X64_A.asid_low_len": 9, + "Machine_A.X64_A.asid_rep_len": 64, + "Platform.X64.irq_len": 8, + "Platform.int_literal_len": 32, + "Machine_Word_64_Basics.machine_word_len": 64, + "Structs_B.ticks_len": 64, + "Time.ticks_len": 64, + "Platform.AARCH64.vs_index_len": 9, + "Platform.AARCH64.irq_len": 9, + "Platform.AARCH64.sgi_irq_len": 4, + "Platform.AARCH64.sgi_target_len": 3, + "Platform.AARCH64.pt_array_len": 512, + "Platform.AARCH64.vs_array_len": 512, + "Arch_Structs_A.AARCH64_A.ppn_len": 32, + "Structures_A.domain_len": 8, + "Structures_A.domain_duration_len": 56, +} + +# Only 2 same-theory type+term collisions exist in ASpec: +TYPE_COLLISIONS = { + "Arch_Structs_A.X64_A.aa_type": "aa_type_T", + "Arch_Structs_A.AARCH64_A.aa_type": "aa_type_T", + "Structures_A.a_type": "a_type_T", +} + +# Isabelle `Enum.enum_class.enum` instances in ASpec +ENUM_INSTANCES = { + "ArchInvocationLabels_H.AARCH64_H.arch_invocation_label": + "ArchInvocationLabels_H.enum_arch_invocation_label_inst.enum_arch_invocation_label", + "InvocationLabels_H.gen_invocation_labels": + "InvocationLabels_H.enum_gen_invocation_labels_inst.enum_gen_invocation_labels", + "InvocationLabels_H.invocation_label": + "InvocationLabels_H.enum_invocation_label_inst.enum_invocation_label", + "MachineTypes.AARCH64.register": + "MachineTypes.enum_register_inst.enum_register", + "MachineTypes.AARCH64.vcpureg": + "MachineTypes.enum_vcpureg_inst.enum_vcpureg", + "MachineTypes.AARCH64.vmpage_size": + "MachineTypes.enum_vmpage_size_inst.enum_vmpage_size", + "MachineTypes.AARCH64.vppievent_irq": + "MachineTypes.enum_vppievent_irq_inst.enum_vppievent_irq", +} + +STATE_EXT_METHODS = [ + "ext_init", "select_switch", "unwrap_ext", "wrap_ext", "wrap_ext_bool", "wrap_ext_op" +] + + +def esc(ident: str) -> str: + ident = ident.replace("\\", "u") + if ident in LEAN_KEYWORDS or (ident and ident[0].isdigit()): + return f"«{ident}»" + return ident + + +def short_thy(full_thy: str) -> str: + return full_thy.split(".", 1)[-1] + + +def hol_numeral_type(ty): + if not isinstance(ty, list) or not ty or ty[0] != "Type": + return None + nm, args = ty[1], ty[2] + if nm == "Numeral_Type.num1" and not args: + return 1 + if nm == "Numeral_Type.num0" and not args: + return 0 + if nm in ("Numeral_Type.bit0", "Numeral_Type.bit1") and len(args) == 1: + n = hol_numeral_type(args[0]) + if n is not None: + return 2 * n + (1 if nm.endswith("bit1") else 0) + if nm in HOL_TYPEDEF_LENS and not args: + return HOL_TYPEDEF_LENS[nm] + return None + + +def decode_hol_num(term): + """Decode `Num.num.One`, `Num.num.Bit0`, `Num.num.Bit1` into a Python int.""" + if not isinstance(term, list) or not term: + return None + if term[0] == "Const" and term[1] == "Num.num.One": + return 1 + if term[0] == "App" and term[1][0] == "Const": + if term[1][1] == "Num.num.Bit0": + n = decode_hol_num(term[2]) + return 2 * n if n is not None else None + if term[1][1] == "Num.num.Bit1": + n = decode_hol_num(term[2]) + return 2 * n + 1 if n is not None else None + return None + + +def unapply(term): + args = [] + cur = term + while isinstance(cur, list) and cur and cur[0] == "App": + args.append(cur[2]) + cur = cur[1] + args.reverse() + return cur, args + + +def fun_domains_and_ret(ty): + doms = [] + cur = ty + while isinstance(cur, list) and cur[:2] == ["Type", "fun"]: + doms.append(cur[2][0]) + cur = cur[2][1] + return doms, cur + + +def collect_tvars(ty, out): + """Collect (name, sorts_tuple) in deterministic left-to-right order.""" + if not isinstance(ty, list) or not ty: + return + if ty[0] in ("TFree", "TVar"): + nm = ty[1] + sorts = tuple(ty[-1]) + if nm not in out: + out[nm] = sorts + else: + # Merge sorts + merged = list(out[nm]) + for s in sorts: + if s not in merged: + merged.append(s) + out[nm] = tuple(merged) + elif ty[0] == "Type": + for ch in ty[2]: + collect_tvars(ch, out) + if ty[1] == "Word.word" and ty[2][0][0] in ("TFree", "TVar"): + width = ty[2][0][1] + if "Type_Length.len" not in out[width]: + out[width] += ("Type_Length.len",) + + +def unify_type_sorts(t_def, t_const, out): + """Transfer sort constraints from constant's declared type `t_const` to TVars in `t_def`.""" + if not isinstance(t_def, list) or not t_def or not isinstance(t_const, list) or not t_const: + return + if t_def[0] in ("TFree", "TVar") and t_const[0] in ("TFree", "TVar"): + nm = t_def[1] + sorts = tuple(t_const[-1]) + merged = list(out.get(nm, ())) + for s in sorts: + if s not in merged: + merged.append(s) + out[nm] = tuple(merged) + elif t_def[0] == "Type" and t_const[0] == "Type" and t_def[1] == t_const[1]: + for a, b in zip(t_def[2], t_const[2]): + unify_type_sorts(a, b, out) + + +def collect_term_tvars(term, out): + if not isinstance(term, list) or not term: + return + tag = term[0] + if tag == "Const": + collect_tvars(term[2], out) + elif tag == "App": + collect_term_tvars(term[1], out) + collect_term_tvars(term[2], out) + elif tag == "Abs": + collect_tvars(term[2], out) + collect_term_tvars(term[3], out) + elif tag in ("Free", "Var"): + collect_tvars(term[-1], out) + + +def collect_term_consts(term, out): + if not isinstance(term, list) or not term: + return + tag = term[0] + if tag == "Const": + out.add(term[1]) + elif tag == "App": + collect_term_consts(term[1], out) + collect_term_consts(term[2], out) + elif tag == "Abs": + collect_term_consts(term[3], out) + + +def clean_tvar(name: str) -> str: + s = name.lstrip("'").replace(".", "_") + return f"tv_{s}" + + +def clean_var(name: str, used=None) -> str: + s = name.replace("'", "_p").replace("\\", "u").replace(".", "_") + if not s or not (s[0].isalpha() or s[0] == "_"): + s = "v_" + s + if s in LEAN_KEYWORDS: + s = "v_" + s + if used is not None: + base = s + k = 1 + while s in used: + s = f"{base}_{k}" + k += 1 + used.add(s) + return s + + +def index_x64_export(raw): + """Recover the used declaration and theory indexes from the same export.""" + tools = Path(__file__).resolve().parent + theories = set((tools / "phase1-theories.txt").read_text().splitlines()) + by_theory = {} + parents = {} + + def symbol(theory, name): + return by_theory.setdefault((theory, name), {"theory": theory, "entries": []}) + + while line := raw.readline(): + offset = raw.tell() - len(line) + row = json.loads(line) + theory = row.get("theory") + if theory not in theories: + continue + kind = row["kind"] + if kind == "inventory": + parents[theory] = row["parents"] + for name, classification in row["symbol_classes"].items(): + symbol(theory, name)["classification"] = classification + elif kind in ("type", "constant", "record", "constructors"): + entry = row["entry"] + declaration = symbol(theory, entry["name"]) + declaration["entries"].append((kind, offset)) + if kind == "constant": + declaration["classification"] = entry["classification"] + elif kind == "definition": + symbol(theory, row["constant"])["entries"].append((kind, offset)) + elif kind == "spec_rule": + for name in row["heads"]: + symbol(theory, name)["entries"].append((kind, offset)) + elif kind in ("class", "locale"): + symbol(theory, row["name"])["entries"].append((kind, offset)) + + missing_theories = theories - parents.keys() + if missing_theories: + raise ValueError(f"Missing X64 export theories: {sorted(missing_theories)}") + # The audited Phase 1 index orders rows by theory and name before + # collapsing duplicate names. Preserve that selection here. + return {name: by_theory[theory, name] for theory, name in sorted(by_theory)}, parents + + +class Emitter: + def __init__(self, evidence_dir: Path, out_dir: Path, arch: str = "AARCH64"): + self.ev = evidence_dir + self.out = out_dir + self.is_x64 = arch == "X64" + self.lean_namespace = "L4vRefX64" if self.is_x64 else "L4vRefA64" + self.machine_state_rest = f"MachineTypes.{arch}.machine_state_rest" + self.enums = dict(ENUM_INSTANCES) + self.recursive_functions = list(SIX_REC) + if self.is_x64: + self.enums = { + name.replace(".AARCH64_H.", ".X64_H.").replace(".AARCH64.", ".X64."): value + for name, value in self.enums.items() + if not name.endswith((".vcpureg", ".vppievent_irq")) + } + # GDT selectors use the generated enumeration in RegisterSet/X64.lhs. + self.enums["MachineTypes.X64.gdtslot"] = "MachineTypes.enum_gdtslot_inst.enum_gdtslot" + self.recursive_functions = [n for n in SIX_REC if not n.startswith("ArchVSpaceAcc_A.")] + self.raw = (self.ev / "aspec-full.jsonl").open("rb") + + if self.is_x64: + self.hol_decls, self.thy_parents = index_x64_export(self.raw) + selection = Path(__file__).resolve().with_name("phase1-symbols.txt") + self.authored_names = set(selection.read_text().splitlines()) + self.authored_names.update((self.machine_state_rest, "Arch_Structs_A.X64_A.iotable_size")) + missing_symbols = self.authored_names - self.hol_decls.keys() + if missing_symbols: + raise ValueError(f"Missing X64 export symbols: {sorted(missing_symbols)}") + else: + with (self.ev / "hol-declarations.jsonl").open() as index: + self.hol_decls = {row["name"]: row for line in index if (row := json.loads(line))} + with (self.ev / "phase1-coverage.jsonl").open() as coverage: + self.authored_names = {row["name"] for line in coverage + if (row := json.loads(line))["side"] == "hol" and row["authored"]} + self.thy_parents = {} + for line in self.raw: + if b'"kind":"inventory"' in line: + record = json.loads(line) + self.thy_parents[record["theory"]] = record["parents"] + # Add helper defs for SIX_REC, ENUM_INSTANCES, and state_ext instances + self.extra_defs = set() + for v in self.enums.values(): + if v in self.hol_decls: + self.extra_defs.add(v) + for b in self.recursive_functions: + for suf in ("_graph", "_rel", "_sumC"): + if b + suf in self.hol_decls: + self.extra_defs.add(b + suf) + for nm in self.hol_decls: + if nm.startswith("Deterministic_A.state_ext_unit_inst.") or nm.startswith("Deterministic_A.state_ext_det_ext_ext_inst."): + if any(e[0] == "definition" for e in self.hol_decls[nm]["entries"]): + self.extra_defs.add(nm) + # Also add the few internal helpers referenced by authored bodies (not in authored_names) + for nm in [ + "Structures_A.cap.is_ArchObjectCap", + f"MachineOps.{arch}.user_context.user_fpu_state", + f"MachineOps.{arch}.user_context.user_regs", + "Structures_A.message_info.mi_length", + "Structures_A.message_info.mi_extra_caps", + "Structures_A.message_info.mi_caps_unwrapped", + "Structures_A.message_info.mi_label", + "Deterministic_A.state_ext_class.unwrap_ext", + "Deterministic_A.state_ext_class.wrap_ext", + ]: + if nm in self.hol_decls: + self.extra_defs.add(nm) + + self.emit_names = self.authored_names | self.extra_defs + + # Map every emitted symbol to its Lean qualified name & theory + self.datatypes = {} # hol_type_name -> (theory, lean_qname, tparams, [(ctor_hol, ctor_short, arg_types)]) + self.ctor_to_dt = {} # ctor_hol_name -> (dt_hol_name, lean_ctor_qname) + self.records = {} # hol_rec_name -> (theory, lean_ext_qname, parent_hol, tparams, [(fld_hol, fld_short, fld_ty)]) + self.rec_ext_types = {} # e.g. "Structures_A.tcb.tcb_ext" -> hol_rec_name + self.const_qname = {} # hol_const_name -> lean_qname + self.type_qname = {} # hol_type_name -> lean_qname + self.const_types = {} # hol_const_name -> hol_type + self.sym_theory = {} # hol_name -> theory + self.record_fields_map = {} # hol_field_name -> (hol_rec_name, fld_short, is_child) + self.rec_derived_consts = set() # record accessors/updaters/make/extend/truncate/fields/more + + self._index_all() + + def read_at(self, loc): + off = loc[1] if isinstance(loc, list) else loc + self.raw.seek(off) + return json.loads(self.raw.readline()) + + def _index_all(self): + # 1. Index datatypes, records, typedecls, constants + for nm in sorted(self.emit_names): + r = self.hol_decls[nm] + thy = r["theory"] + sthy = short_thy(thy) + self.sym_theory[nm] = thy + entries = r["entries"] + eks = {e[0] for e in entries} + + # Record + for e in entries: + if e[0] == "record": + rec = self.read_at(e[1])["entry"] + short = nm.rsplit(".", 1)[-1] + ext_hol = f"{nm}.{short}_ext" + ext_lean = f"L4vRefA64.Spec.{sthy}.{esc(short + '_ext')}" + self.rec_ext_types[ext_hol] = nm + self.type_qname[ext_hol] = ext_lean + self.type_qname[nm] = f"L4vRefA64.Spec.{sthy}.{esc(short)}" + parent = rec.get("parent") + parent_hol = parent[0] if parent else None + # Determine type params of record (only Structures_A.state has 'z) + tparams = [] + for _, fty in rec.get("fields", []): + tvs = {} + collect_tvars(fty, tvs) + for tv in tvs: + if tv not in tparams: + tparams.append(tv) + fields = [] + for fnm, fty in rec.get("fields", []): + fshort = fnm.rsplit(".", 1)[-1] + fields.append((fnm, fshort, fty)) + self.record_fields_map[fnm] = (nm, fshort, parent_hol is not None) + self.rec_derived_consts.add(fnm) + self.rec_derived_consts.add(fnm + "_update") + if parent_hol is not None: + self.const_qname[fnm] = f"L4vRefA64.Spec.{sthy}.{esc(short)}.{esc(fshort)}" + else: + self.const_qname[fnm] = f"L4vRefA64.Spec.{sthy}.{esc(short + '_ext')}.{esc(fshort)}" + self.const_qname[fnm + "_update"] = f"L4vRefA64.Spec.{sthy}.{esc(short)}.{esc(fshort + '_update')}" + self.records[nm] = (thy, ext_lean, parent_hol, tparams, fields) + self.const_qname[ext_hol] = f"{ext_lean}.mk" + for suf in ("truncate", "extend", "fields", "more", "more_update", "make"): + self.rec_derived_consts.add(f"{nm}.{suf}") + self.rec_derived_consts.add(ext_hol) + if parent_hol is None: + self.const_qname[f"{nm}.truncate"] = f"L4vRefA64.Spec.{sthy}.{esc(short)}.truncate" + self.const_qname[f"{nm}.extend"] = f"L4vRefA64.Spec.{sthy}.{esc(short)}.extend" + else: + self.const_qname[f"{nm}.fields"] = f"L4vRefA64.Spec.{sthy}.{esc(short)}.fields" + + # Datatype + for e in entries: + if e[0] == "constructors": + rec = self.read_at(e[1])["entry"] + short = TYPE_COLLISIONS.get(nm, nm.rsplit(".", 1)[-1]) + dt_lean = f"L4vRefA64.Spec.{sthy}.{esc(short)}" + self.type_qname[nm] = dt_lean + ctors = [] + tparams = [] + for c in rec.get("constructors", []): + if isinstance(c, list) and len(c) == 3 and c[0] == "Const": + cnm, cty = c[1], c[2] + else: + cnm, cty = c[0], c[1] + cshort = cnm.rsplit(".", 1)[-1] + if self.is_x64 and cshort == short: + cshort = "mk" + doms, ret = fun_domains_and_ret(cty) + tvs = {} + collect_tvars(ret, tvs) + for tv in tvs: + if tv not in tparams: + tparams.append(tv) + cq = f"{dt_lean}.{esc(cshort)}" + ctors.append((cnm, cshort, doms, cty)) + self.ctor_to_dt[cnm] = (nm, cq) + self.const_qname[cnm] = cq + self.const_types[cnm] = cty + self.datatypes[nm] = (thy, dt_lean, tparams, ctors) + dt_base = nm.rsplit(".", 1)[-1] + self.const_qname[f"{nm}.case_{dt_base}"] = f"L4vRefA64.Spec.{sthy}.{esc('case_' + dt_base)}" + + # typedecl: machine_state_rest + if nm == self.machine_state_rest: + self.type_qname[nm] = f"L4vRefA64.Spec.{sthy}.machine_state_rest" + + # Constant declaration + for e in entries: + if e[0] == "constant": + rec = self.read_at(e[1])["entry"] + cty = rec.get("type") + self.const_types[nm] = cty + if nm not in self.const_qname: + short = nm.rsplit(".", 1)[-1] + # Special disambiguation for enum instances / datatype selectors + if nm.startswith("Deterministic_A.state_ext_class."): + self.const_qname[nm] = f"L4vRefA64.Spec.Deterministic_A.state_ext_class.{esc(short)}" + elif nm.startswith("Deterministic_A.state_ext_unit_inst.") or nm.startswith("Deterministic_A.state_ext_det_ext_ext_inst."): + self.const_qname[nm] = f"L4vRefA64.Spec.Deterministic_A.{esc(short)}" + elif nm.rsplit(".", 1)[0] in self.datatypes and nm not in self.ctor_to_dt: + pdt = nm.rsplit(".", 1)[0] + pdt_short = TYPE_COLLISIONS.get(pdt, pdt.rsplit(".", 1)[-1]) + self.const_qname[nm] = f"L4vRefA64.Spec.{sthy}.{esc(pdt_short)}.{esc(short)}" + else: + self.const_qname[nm] = f"L4vRefA64.Spec.{sthy}.{esc(short)}" + + def emit_type(self, ty, tvar_map=None) -> str: + if tvar_map is None: + tvar_map = {} + if not isinstance(ty, list) or not ty: + return "Unit" + tag = ty[0] + if tag in ("TFree", "TVar"): + nm = ty[1] + if nm in tvar_map: + return tvar_map[nm] + return clean_tvar(nm) + if tag != "Type": + raise ValueError(f"Unknown type tag: {ty}") + nm, args = ty[1], ty[2] + + # Word.word L + if nm == "Word.word" and len(args) == 1: + n = hol_numeral_type(args[0]) + if n is not None: + return f"(BitVec {n})" + if args[0][0] in ("TFree", "TVar"): + wvar = tvar_map.get(args[0][1], "w_" + clean_tvar(args[0][1])) + return f"(BitVec {wvar})" + raise ValueError(f"Unsupported word length type: {args[0]}") + + # Standalone numeral type (vm_level = 5) + n = hol_numeral_type(ty) + if n is not None: + return f"(Fin {n})" + + if nm == "HOL.bool": + return "Bool" + if nm == "Nat.nat": + return "Nat" + if nm == "Int.int": + return "Int" + if nm == "Product_Type.unit": + return "Unit" + if nm == "Product_Type.prod": + return f"({self.emit_type(args[0], tvar_map)} × {self.emit_type(args[1], tvar_map)})" + if nm == "Sum_Type.sum": + return f"(Sum {self.emit_type(args[0], tvar_map)} {self.emit_type(args[1], tvar_map)})" + if nm == "List.list": + return f"(List {self.emit_type(args[0], tvar_map)})" + if nm == "Option.option": + return f"(Option {self.emit_type(args[0], tvar_map)})" + if nm == "Set.set": + return f"(Set {self.emit_type(args[0], tvar_map)})" + if nm == "fun": + return f"({self.emit_type(args[0], tvar_map)} → {self.emit_type(args[1], tvar_map)})" + if nm == "itself": + return f"(HolItself {self.emit_type(args[0], tvar_map)})" + if nm == "prop": + return "Prop" + + if nm in self.type_qname: + q = self.type_qname[nm] + if not args: + return q + a_str = " ".join(self.emit_type(a, tvar_map) for a in args) + return f"({q} {a_str})" + + raise ValueError(f"Unmapped HOL type: {ty}") + + def build_tvar_binders(self, tvars_dict): + """Given {hol_tvar: sorts_tuple}, return (binder_str, tvar_map, w_tvar_names).""" + binders = [] + tvar_map = {} + w_tvars = set() + for tv, sorts in tvars_dict.items(): + if "Type_Length.len" in sorts: + wname = "w_" + clean_tvar(tv) + tvar_map[tv] = wname + w_tvars.add(tv) + binders.append(f"{{{wname} : Nat}}") + else: + lname = clean_tvar(tv) + tvar_map[tv] = lname + binders.append(f"{{{lname} : Type}}") + # Every HOL type is nonempty + binders.append(f"[Nonempty {lname}]") + if "Deterministic_A.state_ext" in sorts: + binders.append(f"[L4vRefA64.Spec.Deterministic_A.state_ext_class {lname}]") + if "Num.numeral" in sorts: + binders.append(f"[HolNumeral {lname}]") + if "Groups.zero" in sorts: + binders.append(f"[HolZero {lname}]") + if "Orderings.ord" in sorts: + binders.append(f"[HolOrd {lname}]") + if self.is_x64 and "Bit_Operations.semiring_bit_operations" in sorts: + binders.append(f"[HolShiftMask {lname}]") + return " ".join(binders), tvar_map, w_tvars + + def emit_const_app(self, nm, cty, args, env, tvar_map): + """Emit application of HOL constant `nm` (with instantiated type `cty`) to `args`.""" + def E(t): + return self.emit_term(t, env, tvar_map) + + def T(ty): + return self.emit_type(ty, tvar_map) + + # ---- Special syntax / numerals ---- + if nm == "Num.numeral_class.numeral" and len(args) == 1: + val = decode_hol_num(args[0]) + if val is not None: + _, ret = fun_domains_and_ret(cty) + return f"(HolNumeral.ofNatVal (α := {T(ret)}) {val})" + if nm == "Groups.zero_class.zero" and not args: + return f"(HolZero.zeroVal (α := {T(cty)}))" + if nm == "Groups.one_class.one" and not args: + return f"(HolOne.oneVal (α := {T(cty)}))" + if nm == "Type_Length.len0_class.len_of" and len(args) == 1: + doms, _ = fun_domains_and_ret(cty) + # doms[0] is ["Type", "itself", [L]] + L = doms[0][2][0] + n = hol_numeral_type(L) + if n is not None: + return f"({n} : Nat)" + if L[0] in ("TFree", "TVar"): + return tvar_map.get(L[1], "w_" + clean_tvar(L[1])) + raise ValueError(f"Unsupported len_of type: {L}") + if nm == "Pure.type" and not args: + # cty is itself A + A = cty[2][0] + if A[0] in ("TFree", "TVar") and A[1] in tvar_map and tvar_map[A[1]].startswith("w_"): + return f"(HolItself.type (α := BitVec {tvar_map[A[1]]}))" + return f"(HolItself.type (α := {T(A)}))" + + # ---- Core HOL logic ---- + if nm in ("HOL.True", "HOL.induct_true") and not args: + return "true" + if nm == "HOL.False" and not args: + return "false" + if nm == "Product_Type.Unity" and not args: + return "()" + if nm == "HOL.undefined" and not args: + return f"(holUndefined (α := {T(cty)}))" + if nm == "HOL.Not": + return self._apply("holNot", args, env, tvar_map) + if nm in ("HOL.conj", "HOL.induct_conj"): + return self._apply("holConj", args, env, tvar_map) + if nm == "HOL.disj": + return self._apply("holDisj", args, env, tvar_map) + if nm in ("HOL.implies", "HOL.induct_implies"): + return self._apply("holImp", args, env, tvar_map) + if nm in ("HOL.eq", "HOL.induct_equal"): + return self._apply("holEq", args, env, tvar_map) + if nm == "HOL.not_equal": + return self._apply("holNotEq", args, env, tvar_map) + if nm in ("HOL.All", "HOL.induct_forall"): + return self._apply("holAll", args, env, tvar_map) + if nm == "HOL.Ex": + return self._apply("holEx", args, env, tvar_map) + if nm == "HOL.Ex1": + return self._apply("holEx1", args, env, tvar_map) + if nm == "HOL.If": + return self._apply("holIf", args, env, tvar_map) + if nm == "HOL.Let": + return self._apply("holLet", args, env, tvar_map) + if nm == "HOL.The": + return self._apply("holThe", args, env, tvar_map) + if nm == "Fun_Def.THE_default": + return self._apply("holTheDefault", args, env, tvar_map) + if nm == "Hilbert_Choice.Eps": + return self._apply("holEps", args, env, tvar_map) + if nm == "Wellfounded.accp": + return self._apply("holAccp", args, env, tvar_map) + if nm == "Inductive.complete_lattice_class.lfp": + # Dispatch holLfp1 vs holLfp2 by type + doms, ret = fun_domains_and_ret(cty) + rdoms, rret = fun_domains_and_ret(ret) + if len(rdoms) == 2 and rret == ["Type", "HOL.bool", []]: + return self._apply("holLfp2", args, env, tvar_map) + if len(rdoms) == 1 and rret == ["Type", "HOL.bool", []]: + return self._apply("holLfp1", args, env, tvar_map) + return self._apply("HolCompleteLattice.holLfp", args, env, tvar_map) + + # ---- Arithmetic / Orders / Lattices ---- + if nm == "Groups.plus_class.plus": + return self._apply("HolAdd.addVal", args, env, tvar_map) + if nm == "Groups.minus_class.minus": + return self._apply("HolSub.subVal", args, env, tvar_map) + if nm == "Groups.times_class.times": + return self._apply("HolMul.mulVal", args, env, tvar_map) + if nm == "Rings.divide_class.divide": + return self._apply("HolDiv.divVal", args, env, tvar_map) + if nm == "Groups.uminus_class.uminus": + return self._apply("HolNeg.negVal", args, env, tvar_map) + if nm == "Power.power_class.power": + return self._apply("HolPow.powVal", args, env, tvar_map) + if nm == "Orderings.ord_class.less": + return self._apply("holLt", args, env, tvar_map) + if nm == "Orderings.ord_class.greater": + return self._apply("(fun a b => holLt b a)", args, env, tvar_map) + if nm == "Orderings.ord_class.less_eq": + return self._apply("holLe", args, env, tvar_map) + if nm == "Orderings.ord_class.min": + return self._apply("holMin", args, env, tvar_map) + if nm == "Orderings.ord_class.Least": + return self._apply("holLeast", args, env, tvar_map) + if nm == "Lattices_Big.linorder_class.Max": + return self._apply("holMax", args, env, tvar_map) + if nm == "Orderings.bot_class.bot": + return f"(HolCompleteLattice.holBot (α := {T(cty)}))" + if nm == "Orderings.top_class.top": + return f"(HolCompleteLattice.holTop (α := {T(cty)}))" + if nm == "Lattices.inf_class.inf": + return self._apply("HolCompleteLattice.holInf", args, env, tvar_map) + if nm == "Lattices.sup_class.sup": + return self._apply("HolCompleteLattice.holSup", args, env, tvar_map) + if nm == "Rings.dvd_class.dvd": + return self._apply("holDvd", args, env, tvar_map) + if nm == "Nat.Suc": + return self._apply("Nat.succ", args, env, tvar_map) + if nm == "Nat.semiring_1_class.of_nat": + _, ret = fun_domains_and_ret(cty) + return self._apply(f"(holOfNat (α := {T(ret)}))", args, env, tvar_map) + if nm == "Int.ring_1_class.of_int": + _, ret = fun_domains_and_ret(cty) + if ret[:2] == ["Type", "Word.word"]: + w = hol_numeral_type(ret[2][0]) + return self._apply(f"(holOfInt (w := {w}))", args, env, tvar_map) + return self._apply("holId", args, env, tvar_map) + if nm == "Int.nat": + return self._apply("holIntToNat", args, env, tvar_map) + if nm == "Nat.size_class.size": + return self._apply("holSize", args, env, tvar_map) + + # ---- Bit operations / Word_Lib ---- + if nm in ("Bit_Operations.semiring_bit_operations_class.and", "Word_Syntax.wordAND"): + return self._apply("holWordAnd", args, env, tvar_map) + if nm == "Bit_Operations.semiring_bit_operations_class.or": + return self._apply("holWordOr", args, env, tvar_map) + if nm in ("Bit_Operations.ring_bit_operations_class.not", "Word_Syntax.wordNOT"): + return self._apply("holWordNot", args, env, tvar_map) + if nm == "Bit_Shifts_Infix_Syntax.semiring_bit_operations_class.shiftl": + if self.is_x64: + _, ret = fun_domains_and_ret(cty) + if ret[0] in ("TFree", "TVar"): + return self._apply("HolShiftMask.shiftLeft", args, env, tvar_map) + return self._apply("holWordShiftl", args, env, tvar_map) + if nm == "Bit_Shifts_Infix_Syntax.semiring_bit_operations_class.shiftr": + return self._apply("holWordShiftr", args, env, tvar_map) + if nm == "Bit_Operations.semiring_bit_operations_class.mask": + _, ret = fun_domains_and_ret(cty) + if self.is_x64 and ret[0] in ("TFree", "TVar"): + return self._apply(f"(HolShiftMask.mask (α := {T(ret)}))", args, env, tvar_map) + w = self._word_w(ret, tvar_map) + return self._apply(f"(holWordMask (w := {w}))", args, env, tvar_map) + if nm == "Bit_Operations.semiring_bits_class.bit": + return self._apply("holWordBit", args, env, tvar_map) + if nm == "Bit_Operations.semiring_bit_operations_class.take_bit": + return self._apply("holWordTakeBit", args, env, tvar_map) + if nm == "HaskellLib_H.bit": + _, ret = fun_domains_and_ret(cty) + w = self._word_w(ret, tvar_map) + return self._apply(f"(holHaskellBit (w := {w}))", args, env, tvar_map) + if nm == "Word.semiring_1_class.unsigned": + _, ret = fun_domains_and_ret(cty) + if ret == ["Type", "Nat.nat", []]: + return self._apply("holUnsigned", args, env, tvar_map) + if ret[:2] == ["Type", "Word.word"]: + w = self._word_w(ret, tvar_map) + return self._apply(f"(holUcast (w := {w}))", args, env, tvar_map) + if ret == ["Type", "Int.int", []]: + return self._apply("(fun x => Int.ofNat (holUnsigned x))", args, env, tvar_map) + return self._apply(f"(fun x => holOfNat (α := {T(ret)}) (holUnsigned x))", args, env, tvar_map) + if nm == "HaskellLib_H.fromIntegral": + doms, ret = fun_domains_and_ret(cty) + if doms[0][:2] == ["Type", "Word.word"] and ret[:2] == ["Type", "Word.word"]: + w = self._word_w(ret, tvar_map) + return self._apply(f"(holUcast (w := {w}))", args, env, tvar_map) + if doms[0] == ["Type", "Nat.nat", []]: + return self._apply(f"(holOfNat (α := {T(ret)}))", args, env, tvar_map) + return self._apply(f"(fun x => holOfNat (α := {T(ret)}) (holUnsigned x))", args, env, tvar_map) + if nm == "Legacy_Aliases.max_word": + w = self._word_w(cty, tvar_map) + return f"(holMaxWord (w := {w}))" + if nm == "Reversed_Bit_Lists.to_bl": + return self._apply("holToBl", args, env, tvar_map) + if nm == "Reversed_Bit_Lists.of_bl": + _, ret = fun_domains_and_ret(cty) + w = self._word_w(ret, tvar_map) + return self._apply(f"(holOfBl (w := {w}))", args, env, tvar_map) + if nm == "Word.word_rcat": + _, ret = fun_domains_and_ret(cty) + n = self._word_w(ret, tvar_map) + return self._apply(f"(holWordRcat (n := {n}))", args, env, tvar_map) + if nm == "Rsplit.word_rsplit": + _, ret = fun_domains_and_ret(cty) + # ret is List (BitVec m) + m = self._word_w(ret[2][0], tvar_map) + return self._apply(f"(holWordRsplit (m := {m}))", args, env, tvar_map) + if nm == "Word.rep": + return self._apply("holWordRep", args, env, tvar_map) + + # ---- Direct primitive map ---- + DIRECT = { + "Fun.id": "holId", + "Fun.comp": "holComp", + "Fun.fun_upd": "holFunUpd", + "Fun.map_fun": "holMapFun", + "Monad_Lib.K": "holK", + "Lib.const": "holK", + "Monad_Lib.fun_app": "holFunApp", + "Monad_Lib.swp": "holSwp", + "Product_Type.Pair": "Prod.mk", + "Product_Type.prod.fst": "Prod.fst", + "Product_Type.prod.snd": "Prod.snd", + "Product_Type.prod.case_prod": "holCaseProd", + "Product_Type.bool.case_bool": "holCaseBool", + "Option.option.None": "Option.none", + "Option.option.Some": "Option.some", + "Option.option.case_option": "holCaseOption", + "Option.option.the": "holTheOpt", + "Option.option.map_option": "holMapOption", + "Option.option.set_option": "holSetOption", + "Sum_Type.Inl": "Sum.inl", + "Sum_Type.Inr": "Sum.inr", + "Sum_Type.sum.case_sum": "holCaseSum", + "Sum_Type.sum.isl": "holIsl", + "Sum_Type.sum.projl": "holProjl", + "Sum_Type.sum.projr": "holProjr", + "Set.Collect": "holCollect", + "Set.Bex": "holBex", + "Set.member": "holMember", + "Set.insert": "holInsert", + "Set.image": "holImage", + "Set.empty": "(∅ : Set _)", + "Set_Interval.ord_class.atLeastAtMost": "holAtLeastAtMost", + "Set_Interval.ord_class.atLeastLessThan": "holAtLeastLessThan", + "Map.dom": "holDom", + "Map.ran": "holRan", + "Transitive_Closure.trancl": "holTrancl", + "Transitive_Closure.rtrancl": "holRtrancl", + "List.list.Nil": "List.nil", + "List.list.Cons": "List.cons", + "List.list.case_list": "holCaseList", + "List.list.hd": "holHd", + "List.list.tl": "holTl", + "List.last": "holLast", + "List.butlast": "holButlast", + "List.nth": "holNth", + "List.list.set": "holListSet", + "List.length": "List.length", + "List.list.map": "holListMap", + "List.append": "holListAppend", + "List.take": "holListTake", + "List.drop": "holListDrop", + "List.filter": "holListFilter", + "List.takeWhile": "holListTakeWhile", + "List.dropWhile": "holListDropWhile", + "List.find": "holListFind", + "List.replicate": "holListReplicate", + "List.rev": "holListRev", + "List.zip": "holListZip", + "List.removeAll": "holListRemoveAll", + "List.list_update": "holListUpdate", + "List.fold": "holListFold", + "List.foldr": "holListFoldr", + "List.upt": "holListUpt", + "List.upto": "holListUpto", + "List.distinct": "holListDistinct", + "Groups_List.monoid_add_class.sum_list": "holSumList", + "Enumeration.the_index": "holTheIndex", + "Enumeration.enum_class.fromEnum": "holFromEnum", + "HaskellLib_H.HS_bit_class.shiftL": "holWordShiftl", + "HaskellLib_H.HS_bit_class.shiftR": "holWordShiftr", + "HaskellLib_H.infix_apply": "(fun a f b => f a b)", + "HaskellLib_H.forM_x": "(fun xs f => holMapMx f xs)", + "Enumeration.enum_class.toEnum": "holToEnum", + "Enumeration.upto_enum": "holUptoEnum", + "Enumeration_Word.upto_enum_step": "holUptoEnumStep", + "Enumeration.enum_class.assocs": "holAssocs", + "Nondet_Monad.return": "holReturn", + "Nondet_Monad.bind": "holBind", + "Nondet_Monad.K_bind": "holKBind", + "Nondet_Monad.get": "holGet", + "Nondet_Monad.put": "holPut", + "Nondet_Monad.gets": "holGets", + "Nondet_Monad.modify": "holModify", + "Nondet_Monad.select": "holSelect", + "Nondet_Monad.select_f": "holSelectF", + "Nondet_Empty_Fail.mk_ef": "holMkEf", + "Nondet_Monad.fail": "holFail", + "Nondet_Monad.assert": "holAssert", + "Nondet_Monad.state_assert": "holStateAssert", + "Nondet_Monad.assert_opt": "holAssertOpt", + "Nondet_Monad.gets_the": "holGetsThe", + "Nondet_Monad.gets_map": "holGetsMap", + "Nondet_Monad.when": "holWhen", + "Nondet_Monad.unless": "holUnless", + "Nondet_Monad.liftM": "holLiftM", + "Nondet_Monad.maybeM": "holMaybeM", + "Nondet_Monad.mapM": "holMapM", + "Nondet_Monad.mapM_x": "holMapMx", + "Nondet_Monad.zipWithM": "holZipWithM", + "Nondet_Monad.zipWithM_x": "holZipWithMx", + "Nondet_Monad.whileLoop": "holWhileLoop", + "Nondet_Monad.returnOk": "holReturnOk", + "Nondet_Monad.throwError": "holThrowError", + "Nondet_Monad.liftE": "holLiftE", + "Nondet_Monad.bindE": "holBindE", + "Nondet_Monad.whenE": "holWhenE", + "Nondet_Monad.unlessE": "holUnlessE", + "Nondet_Monad.assertE": "holAssertE", + "Nondet_Monad.throw_opt": "holThrowOpt", + "Nondet_Monad.catch": "holCatch", + "Nondet_Monad.handleE'": "holHandleE'", + "Nondet_Monad.handleE": "holHandleE", + "Nondet_Monad.liftME": "holLiftME", + "Nondet_Monad.mapME": "holMapME", + "Nondet_Monad.mapME_x": "holMapMEx", + "Reader_Option_Monad.oreturn": "holOReturn", + "Reader_Option_Monad.ofail": "holOFail", + "Reader_Option_Monad.obind": "holOBind", + "Reader_Option_Monad.oassert": "holOAssert", + "Reader_Option_Monad.oassert_opt": "holOAssertOpt", + "Reader_Option_Monad.oliftM": "holOLiftM", + "Reader_Option_Monad.asks": "holAsks", + "Reader_Option_Monad.opt_map": "holOptMap", + "Reader_Option_Monad.opt_map_Some": "holOptMapSome", + "Reader_Option_Monad.opt_pred": "holOptPred", + } + if nm == "Enum.enum_class.enum": + # cty is List T + elem_ty = cty[2][0] + if elem_ty[0] == "Type" and elem_ty[1] in self.enums: + return self.const_qname[self.enums[elem_ty[1]]] + return f"(HolEnum.enumList (α := {T(elem_ty)}))" + if nm == "Enumeration.enum_class.minBound": + return f"(holMinBound (α := {T(cty)}))" + if nm == "Enumeration.enum_class.maxBound": + return f"(holMaxBound (α := {T(cty)}))" + if nm == "Option.option.None" and not args: + elem_ty = cty[2][0] + return f"(Option.none (α := {T(elem_ty)}))" + if nm == "List.list.Nil" and not args: + elem_ty = cty[2][0] + return f"(List.nil (α := {T(elem_ty)}))" + if nm == "Nondet_Monad.fail" and not args: + return f"(holFail : {T(cty)})" + if nm == "Reader_Option_Monad.ofail" and not args: + return f"(holOFail : {T(cty)})" + if nm == "Nondet_Monad.get" and not args: + return f"(holGet : {T(cty)})" + if nm == "Set.empty" and not args: + elem_ty = cty[2][0] + return f"(∅ : Set {T(elem_ty)})" + if nm == "Sum_Type.sum.Inl": + # cty = fun [A, Sum [A, B]] + sum_ty = cty[2][1] + return self._apply(f"(@Sum.inl {T(sum_ty[2][0])} {T(sum_ty[2][1])})", args, env, tvar_map) + if nm == "Sum_Type.sum.Inr": + # cty = fun [B, Sum [A, B]] + sum_ty = cty[2][1] + return self._apply(f"(@Sum.inr {T(sum_ty[2][0])} {T(sum_ty[2][1])})", args, env, tvar_map) + if nm in ("Nondet_Monad.returnOk", "Nondet_Monad.throwError", "Nondet_Monad.liftE", + "Nondet_Monad.assertE", "Nondet_Monad.throw_opt"): + # Extract (σ, E, A) from the Nondet_Monad return type σ → Set ((Sum E A) × σ) × Bool + _, ret_m = fun_domains_and_ret(cty) + # ret_m is prod [set [prod [Sum [E, A], σ]], bool] + try: + inner_prod = ret_m[2][0][2][0] # prod [Sum [E, A], σ] + sum_ty = inner_prod[2][0] # Sum [E, A] + E_ty, A_ty = sum_ty[2][0], sum_ty[2][1] + if nm == "Nondet_Monad.returnOk": + return self._apply(f"(holReturnOk (ε := {T(E_ty)}))", args, env, tvar_map) + if nm == "Nondet_Monad.throwError": + return self._apply(f"(holThrowError (α := {T(A_ty)}))", args, env, tvar_map) + if nm == "Nondet_Monad.liftE": + return self._apply(f"(holLiftE (ε := {T(E_ty)}))", args, env, tvar_map) + if nm == "Nondet_Monad.assertE": + return self._apply(f"(holAssertE (ε := {T(E_ty)}))", args, env, tvar_map) + if nm == "Nondet_Monad.throw_opt": + return self._apply(f"(holThrowOpt (α := {T(A_ty)}))", args, env, tvar_map) + except Exception: + pass + + if nm in DIRECT: + return self._apply(DIRECT[nm], args, env, tvar_map) + + # ---- Authored / local constant ---- + if nm in self.const_qname: + q = self.const_qname[nm] + # Special case: polymorphic constants with 0 args whose type needs annotation + if not args and nm in ( + "Kernel_Config.maxIRQ", "Platform.AARCH64.maxIRQ", + "Machine_Word_64_Basics.word_size", "Machine_Word_64_Basics.word_size_bits", + "Structures_A.MIN_REFILLS", "Structures_A.min_sched_context_bits", + "Structures_A.refill_size_bytes", "Structures_A.sc_sporadic_flag", + "Time.time_buffer_const", "Deterministic_A.state_ext_class.ext_init", + "Structures_A.state.state_ext", + ): + return f"({q} : {T(cty)})" + if not args and (nm.endswith(".get_tcb") or nm.endswith(".reschedule_required")): + return f"({q} : {T(cty)})" + return self._apply(q, args, env, tvar_map) + + raise ValueError(f"Unmapped HOL constant: {nm} :: {cty}") + + def _word_w(self, ty, tvar_map): + if ty[:2] == ["Type", "Word.word"]: + n = hol_numeral_type(ty[2][0]) + if n is not None: + return str(n) + if ty[2][0][0] in ("TFree", "TVar"): + return tvar_map.get(ty[2][0][1], "w_" + clean_tvar(ty[2][0][1])) + raise ValueError(f"Expected Word.word type, got {ty}") + + def _apply(self, head_str, args, env, tvar_map): + if not args: + return head_str + a_strs = " ".join(self.emit_term(a, env, tvar_map) for a in args) + return f"({head_str} {a_strs})" + + def emit_term(self, term, env, tvar_map) -> str: + tag = term[0] + if tag == "Bound": + idx = term[1] + return env[len(env) - 1 - idx] + if tag == "Free": + return clean_var(term[1]) + if tag == "Var": + return clean_var(term[1] + (f"_{term[2]}" if term[2] else "")) + if tag == "Abs": + vname, vty, body = term[1], term[2], term[3] + used = set(env) + lname = clean_var(vname, used) + ty_s = self.emit_type(vty, tvar_map) + body_s = self.emit_term(body, env + [lname], tvar_map) + return f"(fun ({lname} : {ty_s}) => {body_s})" + if tag == "Const": + return self.emit_const_app(term[1], term[2], [], env, tvar_map) + if tag == "App": + head, args = unapply(term) + if head[0] == "Const": + return self.emit_const_app(head[1], head[2], args, env, tvar_map) + h_s = self.emit_term(head, env, tvar_map) + a_s = " ".join(self.emit_term(a, env, tvar_map) for a in args) + return f"({h_s} {a_s})" + raise ValueError(f"Unknown term tag: {term}") + + def emit_pattern(self, pat, var_map): + """Emit a Lean pattern from a HOL spec_rule LHS argument.""" + tag = pat[0] + if tag in ("Free", "Var"): + key = (tag, pat[1], pat[2] if tag == "Var" else 0) + if key in var_map: + return var_map[key] + used = set(var_map.values()) + v = clean_var(pat[1], used) + var_map[key] = v + return v + if tag == "Const": + nm = pat[1] + if nm == "HOL.True": return "true" + if nm == "HOL.False": return "false" + if nm == "Product_Type.Unity": return "()" + if nm == "Option.option.None": return "Option.none" + if nm == "List.list.Nil": return "List.nil" + if nm in self.const_qname: + return self.const_qname[nm] + raise ValueError(f"Unknown pattern const: {nm}") + if tag == "App": + head, args = unapply(pat) + if head[0] != "Const": + raise ValueError(f"Non-const pattern head: {pat}") + nm = head[1] + if nm == "Product_Type.Pair" and len(args) == 2: + return f"({self.emit_pattern(args[0], var_map)}, {self.emit_pattern(args[1], var_map)})" + if nm == "List.list.Cons" and len(args) == 2: + return f"({self.emit_pattern(args[0], var_map)} :: {self.emit_pattern(args[1], var_map)})" + if nm == "Option.option.Some" and len(args) == 1: + return f"(Option.some {self.emit_pattern(args[0], var_map)})" + if nm == "Sum_Type.Inl" and len(args) == 1: + return f"(Sum.inl {self.emit_pattern(args[0], var_map)})" + if nm == "Sum_Type.Inr" and len(args) == 1: + return f"(Sum.inr {self.emit_pattern(args[0], var_map)})" + if nm in self.const_qname: + ps = " ".join(self.emit_pattern(a, var_map) for a in args) + return f"({self.const_qname[nm]} {ps})" + raise ValueError(f"Unknown pattern app const: {nm}") + raise ValueError(f"Unsupported pattern node: {pat}") + + def emit_pat_term(self, term, env, tvar_map, var_map): + """Emit RHS of a spec_rule where Free/Var map via var_map.""" + tag = term[0] + if tag in ("Free", "Var"): + key = (tag, term[1], term[2] if tag == "Var" else 0) + if key in var_map: + return var_map[key] + return clean_var(term[1]) + if tag == "Bound": + return env[len(env) - 1 - term[1]] + if tag == "Abs": + vname, vty, body = term[1], term[2], term[3] + used = set(env) | set(var_map.values()) + lname = clean_var(vname, used) + ty_s = self.emit_type(vty, tvar_map) + body_s = self.emit_pat_term(body, env + [lname], tvar_map, var_map) + return f"(fun ({lname} : {ty_s}) => {body_s})" + if tag == "Const": + return self.emit_const_app(term[1], term[2], [], env, tvar_map) + if tag == "App": + head, args = unapply(term) + if head[0] == "Const": + # Emit args using emit_pat_term by temporarily overriding emit_term? + # Cleaner: pass a small wrapper or handle var_map directly! + return self._emit_const_app_pat(head[1], head[2], args, env, tvar_map, var_map) + h_s = self.emit_pat_term(head, env, tvar_map, var_map) + a_s = " ".join(self.emit_pat_term(a, env, tvar_map, var_map) for a in args) + return f"({h_s} {a_s})" + raise ValueError(f"Unknown term tag: {term}") + + def _emit_const_app_pat(self, nm, cty, args, env, tvar_map, var_map): + orig = self.emit_term + self.emit_term = lambda t, e, tm: self.emit_pat_term(t, e, tm, var_map) + try: + return self.emit_const_app(nm, cty, args, env, tvar_map) + finally: + self.emit_term = orig + + def emit_datatype(self, dt_hol): + thy, dt_lean, tparams, ctors = self.datatypes[dt_hol] + short = dt_lean.rsplit(".", 1)[-1] + tp_map = {tv: clean_tvar(tv) for tv in tparams} + tp_bind = " ".join(f"({clean_tvar(tv)} : Type)" for tv in tparams) + lines = [f"inductive {short}" + (f" {tp_bind}" if tp_bind else "") + " where"] + for cnm, cshort, doms, _ in ctors: + if not doms: + lines.append(f" | {esc(cshort)}") + else: + args_s = " ".join(f"(a{i} : {self.emit_type(d, tp_map)})" for i, d in enumerate(doms)) + lines.append(f" | {esc(cshort)} {args_s}") + # Nonempty instance (using first constructor with holUndefined args) + c0_nm, c0_short, c0_doms, _ = ctors[0] + inst_bind = " ".join(f"{{{clean_tvar(tv)} : Type}} [Nonempty {clean_tvar(tv)}]" for tv in tparams) + dt_app = f"({short} {' '.join(clean_tvar(tv) for tv in tparams)})" if tparams else short + c0_args = " ".join("holUndefined" for _ in c0_doms) + c0_expr = f"{short}.{esc(c0_short)}" + (f" {c0_args}" if c0_args else "") + lines.append(f"instance" + (f" {inst_bind}" if inst_bind else "") + f" : Nonempty {dt_app} := ⟨{c0_expr}⟩") + + # case_
helper + dt_base = dt_hol.rsplit(".", 1)[-1] + case_name = esc("case_" + dt_base) + case_bind = (" ".join(f"{{{clean_tvar(tv)} : Type}}" for tv in tparams) + " ") if tparams else "" + fn_params = [] + for idx, (_, cshort, doms, _) in enumerate(ctors): + if not doms: + fn_params.append(f"(f{idx} : r_ty)") + else: + ft = " → ".join([self.emit_type(d, tp_map) for d in doms] + ["r_ty"]) + fn_params.append(f"(f{idx} : {ft})") + lines.append(f"def {case_name} {case_bind}{{r_ty : Type}} {' '.join(fn_params)} : {dt_app} → r_ty") + for idx, (_, cshort, doms, _) in enumerate(ctors): + if not doms: + lines.append(f" | .{esc(cshort)} => f{idx}") + else: + vs = " ".join(f"x{i}" for i in range(len(doms))) + lines.append(f" | .{esc(cshort)} {vs} => f{idx} {vs}") + return "\n".join(lines) + + def emit_record(self, rec_hol): + thy, ext_lean, parent_hol, tparams, fields = self.records[rec_hol] + short = rec_hol.rsplit(".", 1)[-1] + ext_short = esc(short + "_ext") + tp_map = {tv: clean_tvar(tv) for tv in tparams} + tp_bind = " ".join(f"({clean_tvar(tv)} : Type)" for tv in tparams) + bind_hdr = f"{tp_bind} (more : Type)" if tp_bind else "(more : Type)" + lines = [f"structure {ext_short} {bind_hdr} where"] + for fnm, fshort, fty in fields: + lines.append(f" {esc(fshort)} : {self.emit_type(fty, tp_map)}") + lines.append(" more : more") + + # Nonempty instance + tp_inst = " ".join(f"{{{clean_tvar(tv)} : Type}} [Nonempty {clean_tvar(tv)}]" for tv in tparams) + inst_hdr = f"{tp_inst} {{more : Type}} [Nonempty more]" if tp_inst else "{more : Type} [Nonempty more]" + ext_app = f"({ext_short} {' '.join(clean_tvar(tv) for tv in tparams)} more)" if tparams else f"({ext_short} more)" + u_args = " ".join(["holUndefined"] * (len(fields) + 1)) + lines.append(f"instance {inst_hdr} : Nonempty {ext_app} := ⟨{ext_short}.mk {u_args}⟩") + + # Abbrev + truncate/extend/fields + updates + if parent_hol is None: + ab_bind = f" {tp_bind}" if tp_bind else "" + ext_unit = f"{ext_short} {' '.join(clean_tvar(tv) for tv in tparams)} Unit" if tparams else f"{ext_short} Unit" + lines.append(f"abbrev {esc(short)}{ab_bind} := {ext_unit}") + tp_imp = " ".join(f"{{{clean_tvar(tv)} : Type}}" for tv in tparams) + imp_more = f"{tp_imp} {{more : Type}}" if tp_imp else "{more : Type}" + lines.append(f"def {esc(short)}.truncate {imp_more} (r : {ext_app}) : {ext_unit} := {{ r with more := () }}") + lines.append(f"def {esc(short)}.extend {imp_more} (r : {ext_unit}) (m : more) : {ext_app} := {{ r with more := m }}") + for fnm, fshort, fty in fields: + fty_s = self.emit_type(fty, tp_map) + lines.append( + f"def {esc(short)}.{esc(fshort + '_update')} {imp_more} (g : {fty_s} → {fty_s}) (r : {ext_app}) : {ext_app} := " + f"{{ r with {esc(fshort)} := g r.{esc(fshort)} }}" + ) + else: + p_ext_q = self.records[parent_hol][1] + ab_bind = f" {tp_bind}" if tp_bind else "" + ext_unit = f"({ext_short} {' '.join(clean_tvar(tv) for tv in tparams)} Unit)" if tparams else f"({ext_short} Unit)" + lines.append(f"abbrev {esc(short)}{ab_bind} := {p_ext_q} {ext_unit}") + tp_imp = " ".join(f"{{{clean_tvar(tv)} : Type}}" for tv in tparams) + imp_more = f"{tp_imp} {{more : Type}}" if tp_imp else "{more : Type}" + child_full = f"({p_ext_q} {ext_app})" + f_params = " ".join(f"(a{i} : {self.emit_type(fty, tp_map)})" for i, (_, _, fty) in enumerate(fields)) + a_vars = " ".join(f"a{i}" for i in range(len(fields))) + lines.append( + f"def {esc(short)}.fields" + (f" {tp_imp}" if tp_imp else "") + f" {f_params} : {ext_unit} := " + f"{ext_short}.mk {a_vars} ()" + ) + for fnm, fshort, fty in fields: + fty_s = self.emit_type(fty, tp_map) + lines.append( + f"def {esc(short)}.{esc(fshort)} {imp_more} (r : {child_full}) : {fty_s} := r.more.{esc(fshort)}" + ) + lines.append( + f"def {esc(short)}.{esc(fshort + '_update')} {imp_more} (g : {fty_s} → {fty_s}) (r : {child_full}) : {child_full} := " + f"{{ r with more := {{ r.more with {esc(fshort)} := g r.more.{esc(fshort)} }} }}" + ) + return "\n".join(lines) + + def emit_state_ext_class(self): + """Emit Deterministic_A.state_ext_class with its exact 6 methods.""" + lines = [ + "class state_ext_class (Z : Type) where", + " ext_init : Z", + " select_switch : Z → Bool", + " unwrap_ext : L4vRefA64.Spec.Structures_A.state Z → L4vRefA64.Spec.Structures_A.state det_ext", + " wrap_ext : (det_ext → det_ext) → Z → Z", + " wrap_ext_bool : HolNonDet (L4vRefA64.Spec.Structures_A.state det_ext) Bool → HolNonDet (L4vRefA64.Spec.Structures_A.state Z) Bool", + " wrap_ext_op : HolNonDet (L4vRefA64.Spec.Structures_A.state det_ext) Unit → HolNonDet (L4vRefA64.Spec.Structures_A.state Z) Unit", + ] + return "\n".join(lines) + + def emit_constant_def(self, nm): + r = self.hol_decls[nm] + cls = r.get("classification") + cty = self.const_types.get(nm) + entries = r["entries"] + short = self.const_qname[nm].removeprefix(f"L4vRefA64.Spec.{short_thy(r['theory'])}.") + + # Opaque / consts' / axiomatization (no definition, no spec_rule) + df_es = [e for e in entries if e[0] == "definition"] + sr_es = [e for e in entries if e[0] == "spec_rule" and not self.read_at(e[1]).get("body_omitted")] + + if not df_es and not sr_es: + if cls == "declared_or_abbreviated_constant": + # Check if `constant` entry carries an Isabelle `abbreviation` RHS + const_es = [e for e in entries if e[0] == "constant"] + abbr_rhs = None + if const_es: + abbr_rhs = self.read_at(const_es[0][1])["entry"].get("abbreviation") + if abbr_rhs is not None: + tvars = {} + collect_tvars(cty, tvars) + collect_term_tvars(abbr_rhs, tvars) + b_str, tm, _ = self.build_tvar_binders(tvars) + body_s = self.emit_term(abbr_rhs, [], tm) + ty_s = self.emit_type(cty, tm) + hdr = f"def {short}" + (f" {b_str}" if b_str else "") + f" : {ty_s} :=" + return f"{hdr}\n {body_s}" + tvars = {} + collect_tvars(cty, tvars) + b_str, tm, _ = self.build_tvar_binders(tvars) + if b_str: + return f"-- polymorphic decl {nm} (expanded by Isabelle kernel)" + return f"opaque {short} : {self.emit_type(cty, tm)}" + return None + + # Decide whether to emit from raw `definition` or from `spec_rule`s + use_raw_def = False + if nm in self.recursive_functions or nm in self.extra_defs or not sr_es: + use_raw_def = True + else: + # Check if raw definition is a plain_def (no _sumC, no rec_/corec_/ctor_) + if df_es: + p0 = self.read_at(df_es[0][1])["propositions"][0] + cs = set() + collect_term_consts(p0, cs) + if not any(c.endswith("_sumC") or ".rec_" in c or ".corec_" in c or ".ctor_rec_" in c or ".ctor_fold_" in c for c in cs): + # Check if single spec_rule has no constructor pattern matching + sr_props = [] + for e in sr_es: + sr_props.extend(self.read_at(e[1]).get("propositions") or []) + if len(sr_props) == 1: + use_raw_def = True + + if use_raw_def and df_es: + p = self.read_at(df_es[0][1])["propositions"][0] + # Strip Pure.eq or HOL.Trueprop (HOL.eq lhs rhs) + lhs, rhs = self._split_eq(p) + head, lhs_args = unapply(lhs) + # Collect tvars from both cty (or head type) and rhs, unifying sorts from cty + tvars = {} + head_ty = head[2] if head[0] == "Const" else cty + collect_tvars(head_ty, tvars) + unify_type_sorts(head_ty, cty, tvars) + collect_term_tvars(rhs, tvars) + b_str, tm, _ = self.build_tvar_binders(tvars) + # Handle LHS free args if any + if not lhs_args: + body_s = self.emit_term(rhs, [], tm) + ty_s = self.emit_type(head_ty, tm) + hdr = f"def {short}" + (f" {b_str}" if b_str else "") + f" : {ty_s} :=" + return f"{hdr}\n {body_s}" + else: + var_map = {} + arg_binders = [] + for a in lhs_args: + v = self.emit_pattern(a, var_map) + aty = self.emit_type(a[-1], tm) + arg_binders.append(f"({v} : {aty})") + body_s = self.emit_pat_term(rhs, [], tm, var_map) + _, ret_ty = fun_domains_and_ret(head_ty) + # Compute remaining type after lhs_args + cur_ty = head_ty + for _ in lhs_args: + cur_ty = cur_ty[2][1] + hdr = f"def {short}" + (f" {b_str}" if b_str else "") + " " + " ".join(arg_binders) + f" : {self.emit_type(cur_ty, tm)} :=" + return f"{hdr}\n {body_s}" + + # Multi-equation spec_rule pattern match + sr_props = [] + for e in sr_es: + sr_props.extend(self.read_at(e[1]).get("propositions") or []) + # Axiomatized constants (like MachineTypes.irq_oracle, time_oracle) have empty or non-equation spec_rules + if not df_es: + def _is_eq_prop(p): + t = p + if isinstance(t, list) and t[0] == "App" and t[1][:2] == ["Const", "HOL.Trueprop"]: + t = t[2] + return (isinstance(t, list) and t[0] == "App" and t[1][0] == "App" + and t[1][1][0] == "Const" and t[1][1][1] in ("HOL.eq", "Pure.eq")) + if not sr_props or not all(_is_eq_prop(p) for p in sr_props): + tvars = {} + collect_tvars(cty, tvars) + _, tm, _ = self.build_tvar_binders(tvars) + return f"opaque {short} : {self.emit_type(cty, tm)}" + # If the first spec_rule has all-variable LHS args (e.g. datatype selectors/discriminators + # whose first spec_rule is `sel x = case_T ... x` followed by per-constructor simp rules), + # keep only that first defining equation so Lean does not reject the redundant simp rules. + if len(sr_props) > 1: + lhs0, _ = self._split_eq(sr_props[0]) + _, args0 = unapply(lhs0) + if args0 and all(isinstance(a, list) and a and a[0] in ("Free", "Var") for a in args0): + sr_props = [sr_props[0]] + tvars = {} + collect_tvars(cty, tvars) + for p in sr_props: + lhs_p, _ = self._split_eq(p) + hd_p, _ = unapply(lhs_p) + if hd_p[0] == "Const": + collect_tvars(hd_p[2], tvars) + unify_type_sorts(hd_p[2], cty, tvars) + collect_term_tvars(p, tvars) + b_str, tm, _ = self.build_tvar_binders(tvars) + + arms = [] + kernel_patterns = [] + max_arity = 0 + for p in sr_props: + lhs, rhs = self._split_eq(p) + _, lhs_args = unapply(lhs) + max_arity = max(max_arity, len(lhs_args)) + + # Check if all arms have the same arity; if not, eta-expand shorter arms + for p in sr_props: + lhs, rhs = self._split_eq(p) + _, lhs_args = unapply(lhs) + var_map = {} + pats = [self.emit_pattern(a, var_map) for a in lhs_args] + rhs_s = self.emit_pat_term(rhs, [], tm, var_map) + # If fewer args than max_arity, bind extra vars and apply + if len(pats) < max_arity: + extras = [f"_ea{k}" for k in range(max_arity - len(pats))] + pats.extend(extras) + rhs_s = f"({rhs_s} {' '.join(extras)})" + arms.append((pats, rhs_s)) + kernel_patterns.append(lhs_args + [None] * (max_arity - len(lhs_args))) + + # Determine if fallback wildcard is needed (safe to check for nonexhaustive primrecs & partial selectors) + if self.is_x64: + domains, _ = fun_domains_and_ret(cty) + needs_fallback = not self._patterns_total(domains[:max_arity], kernel_patterns) + else: + needs_fallback = self._needs_wildcard(nm, arms, max_arity) + + ty_s = self.emit_type(cty, tm) + hdr = f"def {short}" + (f" {b_str}" if b_str else "") + f" : {ty_s}" + lines = [hdr] + for pats, rhs_s in arms: + lines.append(f" | {', '.join(pats)} => {rhs_s}") + if needs_fallback: + wilds = ", ".join("_" for _ in range(max_arity)) + lines.append(f" | {wilds} => holUndefined") + return "\n".join(lines) + + def _pattern_constructors(self, ty): + if ty[0] != "Type": + return [] + name, args = ty[1:] + if name in self.datatypes: + return [(ctor, fields) for ctor, _, fields, _ in self.datatypes[name][3]] + if name == "Product_Type.prod": + return [("Product_Type.Pair", args)] + if name == "Product_Type.unit": + return [("Product_Type.Unity", [])] + if name == "HOL.bool": + return [("HOL.True", []), ("HOL.False", [])] + if name == "Option.option": + return [("Option.option.None", []), ("Option.option.Some", args)] + if name == "List.list": + return [("List.list.Nil", []), ("List.list.Cons", [args[0], ty])] + if name == "Sum_Type.sum": + return [("Sum_Type.Inl", args[:1]), ("Sum_Type.Inr", args[1:])] + return [] + + def _patterns_total(self, domains, rows): + """Check coverage by splitting typed constructor patterns.""" + def variable(pattern): + return pattern is None or pattern[0] in ("Free", "Var") + + if not rows: + return False + if any(all(map(variable, row)) for row in rows): + return True + # An unconstrained first column can be dropped. It may have a recursive datatype. + if all(variable(row[0]) for row in rows): + return self._patterns_total(domains[1:], [row[1:] for row in rows]) + constructors = self._pattern_constructors(domains[0]) + if not constructors: + return self._patterns_total(domains[1:], [row[1:] for row in rows if variable(row[0])]) + for ctor, fields in constructors: + cases = [] + for pattern, *rest in rows: + if variable(pattern): + cases.append([None] * len(fields) + rest) + continue + head, args = unapply(pattern) + if head[:2] == ["Const", ctor] and len(args) == len(fields): + cases.append(args + rest) + if not self._patterns_total(fields + domains[1:], cases): + return False + return True + + def _needs_wildcard(self, nm, arms, arity): + if arity == 0: + return False + # If any arm is already all-variable/wildcard on all positions, no fallback needed + for pats, _ in arms: + if all("(" not in p and "." not in p and p not in ("true", "false", "()") for p in pats): + return False + # Check if single-arg constructor match covers all constructors of its datatype + if arity == 1: + doms, _ = fun_domains_and_ret(self.const_types[nm]) + d0 = doms[0] + if d0[0] == "Type" and d0[1] in self.datatypes: + nctors = len(self.datatypes[d0[1]][3]) + # Count distinct top-level constructors in arms + top_ctors = set() + for pats, _ in arms: + p0 = pats[0].lstrip("(").split()[0] + top_ctors.add(p0) + if len(top_ctors) >= nctors: + return False + # For known exhaustive multi-arg functions (`fast_finalise`, `finalise_cap`, `same_region_as`, + # `arch_same_region_as`, `default_cap`, `make_fault_msg`, `handle_fault_reply`, `make_arch_fault_msg`, + # `invoke_tcb`, `perform_invocation`, `handle_event`, `get_extra_cptrs`, `get_receive_slots`, + # `transfer_caps_loop`, `update_ep_queue`, `List_Lib.*`, `handle_hypervisor_fault`, + # `arch_invoke_irq_control`, `arch_invoke_irq_handler`, `invoke_irq_control`, `invoke_irq_handler`, + # `is_*` discriminators): + exhaustive_prefixes = ( + "List_Lib.", "Structures_A.is_", "Arch_Structs_A.AARCH64_A.arch_cap.is_", + "Arch_Structs_A.AARCH64_A.arch_kernel_obj.is_", "Arch_Structs_A.AARCH64_A.pte.is_", + "Structures_A.ntfn.is_", "Structures_A.cap.is_", + "Structures_A.endpoint.ep_queue", "Structures_A.ntfn.ntfn_queue", + "ArchInvocation_A.AARCH64_A.page_table_invocation.pt_inv_", + "ArchInvocation_A.AARCH64_A.vcpu_invocation.vcpu_inv_vcpu", + "Arch_Structs_A.AARCH64_A.asid_pool_entry.ap_vspace", + ) + exhaustive_exact = { + "CSpace_A.fast_finalise", "CSpace_A.finalise_cap", "CSpace_A.same_region_as", + "ArchCSpace_A.AARCH64_A.arch_same_region_as", "ArchCSpace_A.X64_A.arch_same_region_as", + "Retype_A.default_cap", + "Ipc_A.make_fault_msg", "Ipc_A.handle_fault_reply", "ArchFault_A.AARCH64_A.make_arch_fault_msg", + "Tcb_A.invoke_tcb", "Syscall_A.perform_invocation", "Syscall_A.handle_event", + "Ipc_A.get_extra_cptrs", "CSpace_A.get_receive_slots", "Ipc_A.transfer_caps_loop", + "IpcCancel_A.update_ep_queue", "Hypervisor_A.AARCH64_A.handle_hypervisor_fault", + "Hypervisor_A.X64_A.handle_hypervisor_fault", + "ArchVSpace_A.X64_A.create_mapping_entries", "ArchVSpace_A.X64_A.ensure_safe_mapping", + "Arch_A.AARCH64_A.arch_invoke_irq_control", "ArchInterrupt_A.AARCH64_A.arch_invoke_irq_handler", + "Interrupt_A.invoke_irq_control", "Interrupt_A.invoke_irq_handler", + "Arch_Structs_A.AARCH64_A.aobj_ref", "Arch_Structs_A.AARCH64_A.arch_cap_is_device", + "Arch_Structs_A.AARCH64_A.arch_kobj_size", "Arch_Structs_A.AARCH64_A.arch_obj_size", + "CSpace_A.cap_delete", "CSpace_A.finalise_slot", "CSpace_A.isCTEDeleteCall", + "CSpace_A.slot_rdcall", "CSpace_A.exposed_rdcall", + "ExceptionTypes_A.msg_from_lookup_failure", "ExceptionTypes_A.msg_from_syscall_error", + "Structures_A.ipc_queued_thread_state", "Structures_A.message_info_to_data", + "Structures_A.obj_bits", "Structures_A.obj_refs", "Structures_A.runnable", + "Structures_A.reply_object", + } + if nm in exhaustive_exact or any(nm.startswith(p) for p in exhaustive_prefixes): + return False + return True + + def _split_eq(self, prop): + t = prop + if isinstance(t, list) and t[0] == "App" and t[1][:2] == ["Const", "HOL.Trueprop"]: + t = t[2] + if (isinstance(t, list) and t[0] == "App" and t[1][0] == "App" + and t[1][1][0] == "Const" and t[1][1][1] in ("HOL.eq", "Pure.eq")): + return t[1][2], t[2] + raise ValueError(f"Expected equality proposition, got: {str(prop)[:200]}") + + def emit_all(self): + spec_dir = self.out / self.lean_namespace / "Spec" + spec_dir.mkdir(parents=True, exist_ok=True) + + # Group emitted symbols by theory + by_thy = defaultdict(list) + for nm in self.emit_names: + by_thy[self.sym_theory[nm]].append(nm) + + # Topological sort of theories that have emitted symbols + active_thys = set(by_thy.keys()) + visited, order = set(), [] + + def visit_thy(t): + if t in visited: + return + visited.add(t) + for p in self.thy_parents.get(t, []): + if p in active_thys: + visit_thy(p) + order.append(t) + + for t in sorted(active_thys): + visit_thy(t) + + # Also add transitive import edges based on actual emitted references so + # no missing import can ever happen (e.g., if a theory wasn't a direct parent in inventory) + emitted_mods = [] + for thy in order: + sthy = short_thy(thy) + items = by_thy[thy] + # Partition items in this theory: + # 1. typedecl (machine_state_rest) + # 2. datatypes (topo-sorted by type deps within theory) + # 3. records (topo-sorted by parent & field type deps within theory) + # 4. Deterministic_A.state_ext_class (if Deterministic_A) + # 5. constants / defs (topo-sorted by Const deps within theory) + dts = [nm for nm in items if nm in self.datatypes] + recs = [nm for nm in items if nm in self.records] + defs = [ + nm for nm in items + if nm in self.const_types + and nm not in self.ctor_to_dt + and nm not in self.rec_derived_consts + and nm != "Deterministic_A.state_ext_class" + and not nm.startswith("Deterministic_A.state_ext_class.") + ] + + # Topo-sort datatypes + records together (records can reference datatypes and vice versa) + type_items = dts + recs + type_set = set(type_items) + type_deps = defaultdict(set) + for nm in dts: + for _, _, doms, _ in self.datatypes[nm][3]: + for d in doms: + self._collect_local_type_deps(d, type_set, type_deps[nm]) + for nm in recs: + _, _, parent_hol, _, fields = self.records[nm] + if parent_hol in type_set: + type_deps[nm].add(parent_hol) + for _, _, fty in fields: + self._collect_local_type_deps(fty, type_set, type_deps[nm]) + ordered_types = self._topo(type_items, type_deps) + + # Topo-sort defs by Const dependencies within this theory (and put HolEnum lists first) + def_set = set(defs) + enum_const_to_dt = {v: k for k, v in self.enums.items()} + local_enums = [nm for nm in defs if nm in enum_const_to_dt] + def_deps = defaultdict(set) + for nm in defs: + if nm not in enum_const_to_dt: + for en in local_enums: + def_deps[nm].add(en) + r = self.hol_decls[nm] + cs = set() + for e in r["entries"]: + if e[0] in ("definition", "spec_rule"): + rec = self.read_at(e[1]) + if not rec.get("body_omitted"): + for p in rec.get("propositions") or []: + collect_term_consts(p, cs) + elif e[0] == "constant": + abbr = self.read_at(e[1])["entry"].get("abbreviation") + if abbr is not None: + collect_term_consts(abbr, cs) + for c in cs: + if c in def_set and c != nm: + def_deps[nm].add(c) + ordered_defs = self._topo(defs, def_deps) + + # Render body blocks + blocks = [] + if self.machine_state_rest in items: + blocks.append( + "opaque machine_state_rest_type : { T : Type // Nonempty T } := ⟨Unit, ⟨()⟩⟩\n" + "def machine_state_rest : Type := machine_state_rest_type.1\n" + "instance : Nonempty machine_state_rest := machine_state_rest_type.2" + ) + for nm in ordered_types: + if nm in self.datatypes: + blocks.append(self.emit_datatype(nm)) + else: + blocks.append(self.emit_record(nm)) + if thy == "ASpec.Deterministic_A": + blocks.append(self.emit_state_ext_class()) + + # Emit defs + HolEnum instances + state_ext_class instances + enum_const_to_dt = {v: k for k, v in self.enums.items()} + for nm in ordered_defs: + code = self.emit_constant_def(nm) + if code: + blocks.append(code) + if nm in enum_const_to_dt: + dt_q = self.type_qname[enum_const_to_dt[nm]] + cq = self.const_qname[nm] + blocks.append(f"instance : HolEnum {dt_q} where enumList := {cq}") + + if thy == "ASpec.Deterministic_A": + blocks.append( + "instance : state_ext_class Unit where\n" + " ext_init := ext_init_unit\n" + " select_switch := select_switch_unit\n" + " unwrap_ext := unwrap_ext_unit\n" + " wrap_ext := wrap_ext_unit\n" + " wrap_ext_bool := wrap_ext_bool_unit\n" + " wrap_ext_op := wrap_ext_op_unit\n\n" + "instance : state_ext_class det_ext where\n" + " ext_init := ext_init_det_ext_ext\n" + " select_switch := select_switch_det_ext_ext\n" + " unwrap_ext := unwrap_ext_det_ext_ext\n" + " wrap_ext := wrap_ext_det_ext_ext\n" + " wrap_ext_bool := wrap_ext_bool_det_ext_ext\n" + " wrap_ext_op := wrap_ext_op_det_ext_ext" + ) + + body_text = "\n\n".join(blocks) + + # Determine exact imports by scanning `L4vRefA64.Spec..` in body_text + import_set = set() + for p in self.thy_parents.get(thy, []): + if p in active_thys and p != thy: + import_set.add(short_thy(p)) + for other in active_thys: + ost = short_thy(other) + if ost != sthy and f"L4vRefA64.Spec.{ost}." in body_text: + import_set.add(ost) + + hdr = [ + f"-- AUTO-GENERATED BY tools/emit_l4v_ref.py FROM aspec-full.jsonl ({thy}) — DO NOT EDIT", + "import L4vRefA64.PrimX64" if self.is_x64 else "import L4vRefA64.Prim", + ] + for imp in sorted(import_set): + hdr.append(f"import L4vRefA64.Spec.{imp}") + if self.is_x64 and thy == "ASpec.ArchVSpace_A": + # The checked 9-bit range and nested translations in flush_table + # exceed Lean's default elaboration depth. + hdr.append("set_option maxRecDepth 2048") + hdr.extend([ + "", + "set_option linter.unusedVariables false", + "set_option linter.unusedSectionVars false", + "", + f"namespace L4vRefA64.Spec.{sthy}", + "open L4vRefA64.Prim", + "open Classical", + "noncomputable section", + "", + ]) + ftr = ["", "end", f"end L4vRefA64.Spec.{sthy}", ""] + out_file = spec_dir / f"{sthy}.lean" + source = "\n".join(hdr) + body_text + "\n".join(ftr) + out_file.write_text(source.replace("L4vRefA64", self.lean_namespace)) + emitted_mods.append(sthy) + + # Write root umbrella L4vRefA64/Spec.lean + root_lines = [ + "-- AUTO-GENERATED BY tools/emit_l4v_ref.py — DO NOT EDIT", + *[f"import L4vRefA64.Spec.{m}" for m in emitted_mods], + "", + ] + (self.out / self.lean_namespace / "Spec.lean").write_text("\n".join(root_lines).replace("L4vRefA64", self.lean_namespace)) + print(f"Emitted {len(emitted_mods)} modules under {spec_dir} + {self.lean_namespace}/Spec.lean") + + def _collect_local_type_deps(self, ty, local_set, out): + if not isinstance(ty, list) or not ty: + return + if ty[0] == "Type": + nm = ty[1] + if nm in local_set: + out.add(nm) + if nm in self.rec_ext_types and self.rec_ext_types[nm] in local_set: + out.add(self.rec_ext_types[nm]) + for ch in ty[2]: + self._collect_local_type_deps(ch, local_set, out) + + def _topo(self, items, deps): + visited, res = set(), [] + item_set = set(items) + + def dfs(x): + if x in visited: + return + visited.add(x) + for d in sorted(deps.get(x, ())): + if d in item_set: + dfs(d) + res.append(x) + + for x in sorted(items): + dfs(x) + return res + + +def main(): + ev = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("a64-equivalence/evidence") + out = Path(sys.argv[2]) if len(sys.argv) > 2 else Path("a64-equivalence/l4v-ref-a64") + arch = sys.argv[3] if len(sys.argv) > 3 else "AARCH64" + if arch not in {"AARCH64", "X64"}: + raise SystemExit(f"Unknown architecture: {arch}") + em = Emitter(ev, out, arch) + em.emit_all() + + +if __name__ == "__main__": + main() diff --git a/proofs/Fl4SpecEquivX64/tools/phase1-symbols.txt b/proofs/Fl4SpecEquivX64/tools/phase1-symbols.txt new file mode 100644 index 000000000..06de3f387 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/tools/phase1-symbols.txt @@ -0,0 +1,1680 @@ +Aligned.is_aligned +ArchCSpace_A.X64_A.arch_is_cap_revocable +ArchCSpace_A.X64_A.arch_is_physical +ArchCSpace_A.X64_A.arch_same_region_as +ArchCSpace_A.X64_A.cnode_guard_size_bits +ArchCSpace_A.X64_A.cnode_padding_bits +ArchCSpace_A.X64_A.is_irq_control_descendant +ArchCSpace_A.X64_A.same_aobject_as +ArchCSpace_A.X64_A.should_be_arch_parent_of +ArchCSpace_A.X64_A.update_cnode_cap_data +ArchDecode_A.X64_A.arch_check_irq +ArchDecode_A.X64_A.arch_data_to_obj_type +ArchDecode_A.X64_A.arch_decode_invocation +ArchDecode_A.X64_A.arch_decode_irq_control_invocation +ArchDecode_A.X64_A.args_at_least +ArchDecode_A.X64_A.check_vp_alignment +ArchDecode_A.X64_A.decode_io_unmap_invocation +ArchDecode_A.X64_A.decode_ioport_control_invocation +ArchDecode_A.X64_A.decode_page_directory_invocation +ArchDecode_A.X64_A.decode_page_invocation +ArchDecode_A.X64_A.decode_page_table_invocation +ArchDecode_A.X64_A.decode_pdpt_invocation +ArchDecode_A.X64_A.decode_port_invocation +ArchDecode_A.X64_A.ensure_port_operation_allowed +ArchDecode_A.X64_A.filter_vm_attributes +ArchDecode_A.X64_A.get_iovm_rights +ArchDecode_A.X64_A.is_ioport_range_free +ArchDecode_A.X64_A.page_base +ArchDecode_A.X64_A.page_cap_set_vmmap_type +ArchFault_A.X64_A.handle_arch_fault_reply +ArchFault_A.X64_A.make_arch_fault_msg +ArchInterrupt_A.X64_A.arch_invoke_irq_handler +ArchInterrupt_A.X64_A.arch_mask_irq_signal +ArchInterrupt_A.X64_A.handle_reserved_irq +ArchInterrupt_A.X64_A.handle_spurious_irq +ArchInvocationLabels_H.X64_H.arch_invocation_label +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64ASIDControlMakePool +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64ASIDPoolAssign +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IOPortControlIssue +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IOPortIn16 +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IOPortIn32 +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IOPortIn8 +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IOPortOut16 +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IOPortOut32 +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IOPortOut8 +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IRQIssueIRQHandlerIOAPIC +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64IRQIssueIRQHandlerMSI +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PDPTMap +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PDPTUnmap +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PageDirectoryMap +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PageDirectoryUnmap +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PageGetAddress +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PageMap +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PageTableMap +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PageTableUnmap +ArchInvocationLabels_H.X64_H.arch_invocation_label.X64PageUnmap +ArchInvocationLabels_H.enum_arch_invocation_label_inst.enum_arch_invocation_label +ArchInvocation_A.X64_A.ArchDefaultExtraRegisters +ArchInvocation_A.X64_A.arch_copy_register_sets +ArchInvocation_A.X64_A.arch_copy_register_sets.X64NoExtraRegisters +ArchInvocation_A.X64_A.arch_invocation +ArchInvocation_A.X64_A.arch_invocation.InvokeASIDControl +ArchInvocation_A.X64_A.arch_invocation.InvokeASIDPool +ArchInvocation_A.X64_A.arch_invocation.InvokeIOPort +ArchInvocation_A.X64_A.arch_invocation.InvokeIOPortControl +ArchInvocation_A.X64_A.arch_invocation.InvokePDPT +ArchInvocation_A.X64_A.arch_invocation.InvokePage +ArchInvocation_A.X64_A.arch_invocation.InvokePageDirectory +ArchInvocation_A.X64_A.arch_invocation.InvokePageTable +ArchInvocation_A.X64_A.arch_irq_control_invocation +ArchInvocation_A.X64_A.arch_irq_control_invocation.IssueIRQHandlerIOAPIC +ArchInvocation_A.X64_A.arch_irq_control_invocation.IssueIRQHandlerMSI +ArchInvocation_A.X64_A.asid_control_invocation +ArchInvocation_A.X64_A.asid_control_invocation.MakePool +ArchInvocation_A.X64_A.asid_pool_invocation +ArchInvocation_A.X64_A.asid_pool_invocation.Assign +ArchInvocation_A.X64_A.io_port_control_invocation +ArchInvocation_A.X64_A.io_port_control_invocation.IOPortControlInvocation +ArchInvocation_A.X64_A.io_port_invocation +ArchInvocation_A.X64_A.io_port_invocation.IOPortInvocation +ArchInvocation_A.X64_A.io_port_invocation_data +ArchInvocation_A.X64_A.io_port_invocation_data.IOPortIn16 +ArchInvocation_A.X64_A.io_port_invocation_data.IOPortIn32 +ArchInvocation_A.X64_A.io_port_invocation_data.IOPortIn8 +ArchInvocation_A.X64_A.io_port_invocation_data.IOPortOut16 +ArchInvocation_A.X64_A.io_port_invocation_data.IOPortOut32 +ArchInvocation_A.X64_A.io_port_invocation_data.IOPortOut8 +ArchInvocation_A.X64_A.page_directory_invocation +ArchInvocation_A.X64_A.page_directory_invocation.PageDirectoryMap +ArchInvocation_A.X64_A.page_directory_invocation.PageDirectoryUnmap +ArchInvocation_A.X64_A.page_invocation +ArchInvocation_A.X64_A.page_invocation.PageGetAddr +ArchInvocation_A.X64_A.page_invocation.PageMap +ArchInvocation_A.X64_A.page_invocation.PageUnmap +ArchInvocation_A.X64_A.page_invocation.page_get_paddr +ArchInvocation_A.X64_A.page_invocation.page_map_cap +ArchInvocation_A.X64_A.page_invocation.page_map_ct_slot +ArchInvocation_A.X64_A.page_invocation.page_map_entries +ArchInvocation_A.X64_A.page_invocation.page_map_vspace +ArchInvocation_A.X64_A.page_invocation.page_unmap_cap +ArchInvocation_A.X64_A.page_invocation.page_unmap_cap_slot +ArchInvocation_A.X64_A.page_table_invocation +ArchInvocation_A.X64_A.page_table_invocation.PageTableMap +ArchInvocation_A.X64_A.page_table_invocation.PageTableUnmap +ArchInvocation_A.X64_A.pdpt_invocation +ArchInvocation_A.X64_A.pdpt_invocation.PDPTMap +ArchInvocation_A.X64_A.pdpt_invocation.PDPTUnmap +ArchIpcCancel_A.X64_A.arch_cap_cleanup_opt +ArchIpcCancel_A.X64_A.arch_gen_obj_ref +ArchIpcCancel_A.X64_A.arch_gen_obj_ref.IOPortRef +ArchIpcCancel_A.X64_A.arch_gen_obj_refs +ArchIpcCancel_A.X64_A.arch_post_cap_deletion +ArchIpcCancel_A.X64_A.free_ioport_range +ArchIpcCancel_A.X64_A.set_ioport_mask +ArchRetype_A.X64_A.arch_post_reset_untyped +ArchRetype_A.X64_A.empty_context +ArchRetype_A.X64_A.init_arch_objects +ArchRetype_A.X64_A.init_arch_tcb +ArchRetype_A.X64_A.reserve_region +ArchTcb_A.X64_A.arch_get_sanitise_register_info +ArchTcb_A.X64_A.arch_post_modify_registers +ArchTcb_A.X64_A.arch_post_set_flags +ArchTcb_A.X64_A.arch_prepare_set_domain +ArchTcb_A.X64_A.sanitise_and_flags +ArchTcb_A.X64_A.sanitise_or_flags +ArchTcb_A.X64_A.sanitise_register +ArchVMAttributes_A.X64_A.arch_raw_vmattrs +ArchVMAttributes_A.X64_A.attribs_from_word +ArchVMAttributes_A.X64_A.attribs_to_word +ArchVMAttributes_A.X64_A.table_attr +ArchVMAttributes_A.X64_A.table_attr.Accessed +ArchVMAttributes_A.X64_A.table_attr.CacheDisabled +ArchVMAttributes_A.X64_A.table_attr.ExecuteDisable +ArchVMAttributes_A.X64_A.table_attr.WriteThrough +ArchVMAttributes_A.X64_A.table_attrs +ArchVMAttributes_A.X64_A.vm_attribute +ArchVMAttributes_A.X64_A.vm_attribute.Dirty +ArchVMAttributes_A.X64_A.vm_attribute.Global +ArchVMAttributes_A.X64_A.vm_attribute.PAT +ArchVMAttributes_A.X64_A.vm_attribute.PTAttr +ArchVMAttributes_A.X64_A.vm_attributes +ArchVSpaceAcc_A.X64_A.aobjs_of +ArchVSpaceAcc_A.X64_A.asid_high_bits_of +ArchVSpaceAcc_A.X64_A.asid_low_bits_of +ArchVSpaceAcc_A.X64_A.copy_global_mappings +ArchVSpaceAcc_A.X64_A.get_asid_pool +ArchVSpaceAcc_A.X64_A.get_pd +ArchVSpaceAcc_A.X64_A.get_pd_index +ArchVSpaceAcc_A.X64_A.get_pde +ArchVSpaceAcc_A.X64_A.get_pdpt +ArchVSpaceAcc_A.X64_A.get_pdpt_index +ArchVSpaceAcc_A.X64_A.get_pdpte +ArchVSpaceAcc_A.X64_A.get_pml4 +ArchVSpaceAcc_A.X64_A.get_pml4_index +ArchVSpaceAcc_A.X64_A.get_pml4e +ArchVSpaceAcc_A.X64_A.get_pt +ArchVSpaceAcc_A.X64_A.get_pt_index +ArchVSpaceAcc_A.X64_A.get_pte +ArchVSpaceAcc_A.X64_A.lookup_pd_slot +ArchVSpaceAcc_A.X64_A.lookup_pd_slot_no_fail +ArchVSpaceAcc_A.X64_A.lookup_pdpt_slot +ArchVSpaceAcc_A.X64_A.lookup_pdpt_slot_no_fail +ArchVSpaceAcc_A.X64_A.lookup_pml4_slot +ArchVSpaceAcc_A.X64_A.lookup_pt_slot +ArchVSpaceAcc_A.X64_A.lookup_pt_slot_no_fail +ArchVSpaceAcc_A.X64_A.set_asid_pool +ArchVSpaceAcc_A.X64_A.set_pd +ArchVSpaceAcc_A.X64_A.set_pdpt +ArchVSpaceAcc_A.X64_A.set_pml4 +ArchVSpaceAcc_A.X64_A.set_pt +ArchVSpaceAcc_A.X64_A.store_pde +ArchVSpaceAcc_A.X64_A.store_pdpte +ArchVSpaceAcc_A.X64_A.store_pml4e +ArchVSpaceAcc_A.X64_A.store_pte +ArchVSpace_A.X64_A.arch_derive_cap +ArchVSpace_A.X64_A.arch_finalise_cap +ArchVSpace_A.X64_A.arch_update_cap_data +ArchVSpace_A.X64_A.attr_mask +ArchVSpace_A.X64_A.attr_mask' +ArchVSpace_A.X64_A.check_mapping_pptr +ArchVSpace_A.X64_A.check_valid_ipc_buffer +ArchVSpace_A.X64_A.cr3_addr_mask +ArchVSpace_A.X64_A.create_mapping_entries +ArchVSpace_A.X64_A.delete_asid +ArchVSpace_A.X64_A.delete_asid_pool +ArchVSpace_A.X64_A.ensure_safe_mapping +ArchVSpace_A.X64_A.find_vspace_for_asid +ArchVSpace_A.X64_A.find_vspace_for_asid_assert +ArchVSpace_A.X64_A.flush_all +ArchVSpace_A.X64_A.flush_pd +ArchVSpace_A.X64_A.flush_pdpt +ArchVSpace_A.X64_A.flush_table +ArchVSpace_A.X64_A.getCurrentVSpaceRoot +ArchVSpace_A.X64_A.get_current_cr3 +ArchVSpace_A.X64_A.handle_vm_fault +ArchVSpace_A.X64_A.hw_asid_invalidate +ArchVSpace_A.X64_A.in_user_frame +ArchVSpace_A.X64_A.invalidate_page_structure_cache_asid +ArchVSpace_A.X64_A.is_valid_vtable_root +ArchVSpace_A.X64_A.lookup_ipc_buffer +ArchVSpace_A.X64_A.make_cr3 +ArchVSpace_A.X64_A.prepare_thread_delete +ArchVSpace_A.X64_A.set_current_cr3 +ArchVSpace_A.X64_A.set_current_vspace_root +ArchVSpace_A.X64_A.set_vm_root +ArchVSpace_A.X64_A.unmap_page +ArchVSpace_A.X64_A.unmap_page_table +ArchVSpace_A.X64_A.unmap_pd +ArchVSpace_A.X64_A.unmap_pdpt +ArchVSpace_A.X64_A.update_map_data +Arch_A.X64_A.arch_activate_idle_thread +Arch_A.X64_A.arch_invoke_irq_control +Arch_A.X64_A.arch_no_return +Arch_A.X64_A.arch_perform_invocation +Arch_A.X64_A.arch_prepare_next_domain +Arch_A.X64_A.arch_switch_to_idle_thread +Arch_A.X64_A.arch_switch_to_thread +Arch_A.X64_A.page_bits +Arch_A.X64_A.pde_check_if_mapped +Arch_A.X64_A.perform_asid_control_invocation +Arch_A.X64_A.perform_asid_pool_invocation +Arch_A.X64_A.perform_io_port_invocation +Arch_A.X64_A.perform_ioport_control_invocation +Arch_A.X64_A.perform_page_directory_invocation +Arch_A.X64_A.perform_page_invocation +Arch_A.X64_A.perform_page_invocation_unmap +Arch_A.X64_A.perform_page_table_invocation +Arch_A.X64_A.perform_pdpt_invocation +Arch_A.X64_A.port_in +Arch_A.X64_A.port_out +Arch_A.X64_A.pte_check_if_mapped +Arch_A.X64_A.store_asid_pool_entry +Arch_A.X64_A.update_irq_state +Arch_Structs_A.X64_A.X64IRQState +Arch_Structs_A.X64_A.X64IRQState.IRQFree +Arch_Structs_A.X64_A.X64IRQState.IRQIOAPIC +Arch_Structs_A.X64_A.X64IRQState.IRQLevel +Arch_Structs_A.X64_A.X64IRQState.IRQMSI +Arch_Structs_A.X64_A.X64IRQState.IRQMasked +Arch_Structs_A.X64_A.X64IRQState.IRQPin +Arch_Structs_A.X64_A.X64IRQState.IRQPolarity +Arch_Structs_A.X64_A.X64IRQState.IRQReserved +Arch_Structs_A.X64_A.X64IRQState.IRQioapic +Arch_Structs_A.X64_A.X64IRQState.MSIBus +Arch_Structs_A.X64_A.X64IRQState.MSIDev +Arch_Structs_A.X64_A.X64IRQState.MSIFunc +Arch_Structs_A.X64_A.X64IRQState.MSIHandle +Arch_Structs_A.X64_A.aa_type +Arch_Structs_A.X64_A.aa_type.AASIDPool +Arch_Structs_A.X64_A.aa_type.ADeviceData +Arch_Structs_A.X64_A.aa_type.APDPointerTable +Arch_Structs_A.X64_A.aa_type.APageDirectory +Arch_Structs_A.X64_A.aa_type.APageMapL4 +Arch_Structs_A.X64_A.aa_type.APageTable +Arch_Structs_A.X64_A.aa_type.AUserData +Arch_Structs_A.X64_A.acap_rights_update +Arch_Structs_A.X64_A.aobj_ref +Arch_Structs_A.X64_A.aobject_type +Arch_Structs_A.X64_A.aobject_type.ASIDPoolObj +Arch_Structs_A.X64_A.aobject_type.HugePageObj +Arch_Structs_A.X64_A.aobject_type.LargePageObj +Arch_Structs_A.X64_A.aobject_type.PDPTObj +Arch_Structs_A.X64_A.aobject_type.PML4Obj +Arch_Structs_A.X64_A.aobject_type.PageDirectoryObj +Arch_Structs_A.X64_A.aobject_type.PageTableObj +Arch_Structs_A.X64_A.aobject_type.SmallPageObj +Arch_Structs_A.X64_A.arch_cap +Arch_Structs_A.X64_A.arch_cap.ASIDControlCap +Arch_Structs_A.X64_A.arch_cap.ASIDPoolCap +Arch_Structs_A.X64_A.arch_cap.IOPortCap +Arch_Structs_A.X64_A.arch_cap.IOPortControlCap +Arch_Structs_A.X64_A.arch_cap.PDPointerTableCap +Arch_Structs_A.X64_A.arch_cap.PML4Cap +Arch_Structs_A.X64_A.arch_cap.PageCap +Arch_Structs_A.X64_A.arch_cap.PageDirectoryCap +Arch_Structs_A.X64_A.arch_cap.PageTableCap +Arch_Structs_A.X64_A.arch_cap.acap_asid_base +Arch_Structs_A.X64_A.arch_cap.acap_asid_pool +Arch_Structs_A.X64_A.arch_cap.acap_io_port_first_port +Arch_Structs_A.X64_A.arch_cap.acap_io_port_last_port +Arch_Structs_A.X64_A.arch_cap.acap_rights +Arch_Structs_A.X64_A.arch_cap_badge +Arch_Structs_A.X64_A.arch_cap_is_device +Arch_Structs_A.X64_A.arch_default_cap +Arch_Structs_A.X64_A.arch_is_frame_type +Arch_Structs_A.X64_A.arch_kernel_obj +Arch_Structs_A.X64_A.arch_kernel_obj.ASIDPool +Arch_Structs_A.X64_A.arch_kernel_obj.DataPage +Arch_Structs_A.X64_A.arch_kernel_obj.PDPointerTable +Arch_Structs_A.X64_A.arch_kernel_obj.PageDirectory +Arch_Structs_A.X64_A.arch_kernel_obj.PageMapL4 +Arch_Structs_A.X64_A.arch_kernel_obj.PageTable +Arch_Structs_A.X64_A.arch_kobj_size +Arch_Structs_A.X64_A.arch_obj_size +Arch_Structs_A.X64_A.arch_tcb_context_get +Arch_Structs_A.X64_A.arch_tcb_context_set +Arch_Structs_A.X64_A.arch_tcb_get_registers +Arch_Structs_A.X64_A.arch_tcb_set_registers +Arch_Structs_A.X64_A.badge_bits +Arch_Structs_A.X64_A.cr3 +Arch_Structs_A.X64_A.cr3.cr3 +Arch_Structs_A.X64_A.cr3_base_address +Arch_Structs_A.X64_A.cr3_pcid +Arch_Structs_A.X64_A.cte_level_bits +Arch_Structs_A.X64_A.default_arch_object +Arch_Structs_A.X64_A.default_arch_tcb +Arch_Structs_A.X64_A.endpoint_bits +Arch_Structs_A.X64_A.io_asid +Arch_Structs_A.X64_A.io_port +Arch_Structs_A.X64_A.iocte +Arch_Structs_A.X64_A.iocte.InvalidIOCTE +Arch_Structs_A.X64_A.iocte.VTDCTE +Arch_Structs_A.X64_A.iocte.address_width +Arch_Structs_A.X64_A.iocte.domain_id +Arch_Structs_A.X64_A.iocte.iocte_present +Arch_Structs_A.X64_A.iocte.next_level_ptr +Arch_Structs_A.X64_A.iocte.res_mem_reg +Arch_Structs_A.X64_A.iocte.translation_type +Arch_Structs_A.X64_A.iopt_bits +Arch_Structs_A.X64_A.iopte +Arch_Structs_A.X64_A.iopte.InvalidIOPTE +Arch_Structs_A.X64_A.iopte.VTDPTE +Arch_Structs_A.X64_A.iopte.frame_ptr +Arch_Structs_A.X64_A.iopte.io_pte_rights +Arch_Structs_A.X64_A.iorte +Arch_Structs_A.X64_A.iorte.InvalidIORTE +Arch_Structs_A.X64_A.iorte.VTDRTE +Arch_Structs_A.X64_A.iorte.context_table +Arch_Structs_A.X64_A.iorte.iorte_present +Arch_Structs_A.X64_A.ntfn_bits +Arch_Structs_A.X64_A.parse_time_arg +Arch_Structs_A.X64_A.pd_bits +Arch_Structs_A.X64_A.pd_shift_bits +Arch_Structs_A.X64_A.pde +Arch_Structs_A.X64_A.pde.InvalidPDE +Arch_Structs_A.X64_A.pde.LargePagePDE +Arch_Structs_A.X64_A.pde.PageTablePDE +Arch_Structs_A.X64_A.pde.pde_attrs +Arch_Structs_A.X64_A.pde.pde_rights +Arch_Structs_A.X64_A.pde.pt_attrs +Arch_Structs_A.X64_A.pdpt_bits +Arch_Structs_A.X64_A.pdpt_shift_bits +Arch_Structs_A.X64_A.pdpte +Arch_Structs_A.X64_A.pdpte.HugePagePDPTE +Arch_Structs_A.X64_A.pdpte.InvalidPDPTE +Arch_Structs_A.X64_A.pdpte.PageDirectoryPDPTE +Arch_Structs_A.X64_A.pdpte.pdpt_attrs +Arch_Structs_A.X64_A.pdpte.pdpt_frame +Arch_Structs_A.X64_A.pdpte.pdpt_rights +Arch_Structs_A.X64_A.pdpte.pdpt_table +Arch_Structs_A.X64_A.pdpte.pdpt_table_attrs +Arch_Structs_A.X64_A.pml4_bits +Arch_Structs_A.X64_A.pml4_shift_bits +Arch_Structs_A.X64_A.pml4e +Arch_Structs_A.X64_A.pml4e.InvalidPML4E +Arch_Structs_A.X64_A.pml4e.PDPointerTablePML4E +Arch_Structs_A.X64_A.pml4e.pml4_table +Arch_Structs_A.X64_A.pml4e.pml4e_attrs +Arch_Structs_A.X64_A.pml4e.pml4e_rights +Arch_Structs_A.X64_A.pt_bits +Arch_Structs_A.X64_A.pt_shift_bits +Arch_Structs_A.X64_A.pte +Arch_Structs_A.X64_A.pte.InvalidPTE +Arch_Structs_A.X64_A.pte.SmallPagePTE +Arch_Structs_A.X64_A.pte.pte_attrs +Arch_Structs_A.X64_A.pte.pte_frame +Arch_Structs_A.X64_A.pte.pte_rights +Arch_Structs_A.X64_A.reply_bits +Arch_Structs_A.X64_A.table_size +Arch_Structs_A.X64_A.tcb_bits +Arch_Structs_A.X64_A.translation_type +Arch_Structs_A.X64_A.translation_type.NotTranslated +Arch_Structs_A.X64_A.translation_type.Translated +Arch_Structs_A.X64_A.untyped_max_bits +Arch_Structs_A.X64_A.untyped_min_bits +Arch_Structs_A.X64_A.vm_page_entry +Arch_Structs_A.X64_A.vm_page_entry.VMPDE +Arch_Structs_A.X64_A.vm_page_entry.VMPDPTE +Arch_Structs_A.X64_A.vm_page_entry.VMPTE +Arch_Structs_A.X64_A.vtd_cte_size_bits +Arch_Structs_A.X64_A.vtd_pt_bits +Arch_Structs_A.X64_A.words_from_time +Arch_Structs_A.X64_A.x64_num_io_pt_levels +Arch_Structs_A.X64_A.x64_vspace_region_uses +Arch_Structs_A.arch_state +Arch_Structs_A.arch_state.x64_allocated_io_ports +Arch_Structs_A.arch_state.x64_asid_table +Arch_Structs_A.arch_state.x64_current_cr3 +Arch_Structs_A.arch_state.x64_current_fpu_owner +Arch_Structs_A.arch_state.x64_global_pdpts +Arch_Structs_A.arch_state.x64_global_pds +Arch_Structs_A.arch_state.x64_global_pml4 +Arch_Structs_A.arch_state.x64_global_pts +Arch_Structs_A.arch_state.x64_ioapic_nirqs +Arch_Structs_A.arch_state.x64_irq_state +Arch_Structs_A.arch_state.x64_kernel_vspace +Arch_Structs_A.arch_state.x64_num_ioapics +Arch_Structs_A.arch_tcb +Arch_Structs_A.arch_tcb.tcb_context +Arch_Structs_A.arch_tcb.tcb_cur_fpu +Arch_Structs_B.X64_H.parseTimeArg +Arch_Structs_B.X64_H.timerPrecision +Arch_Structs_B.X64_H.x64vspace_region_use +Arch_Structs_B.X64_H.x64vspace_region_use.X64VSpaceDeviceWindow +Arch_Structs_B.X64_H.x64vspace_region_use.X64VSpaceInvalidRegion +Arch_Structs_B.X64_H.x64vspace_region_use.X64VSpaceKernelWindow +Arch_Structs_B.X64_H.x64vspace_region_use.X64VSpaceUserRegion +CSpaceAcc_A.cdt_parent_rel +CSpaceAcc_A.descendants_of +CSpaceAcc_A.ensure_empty +CSpaceAcc_A.get_cap +CSpaceAcc_A.is_cdt_parent +CSpaceAcc_A.parent_of +CSpaceAcc_A.parent_of_rtrancl +CSpaceAcc_A.parent_of_trancl +CSpaceAcc_A.set_cap +CSpaceAcc_A.set_cdt +CSpaceAcc_A.set_original +CSpaceAcc_A.update_cdt +CSpace_A.can_fast_finalise +CSpace_A.cap_cyclic_zombie +CSpace_A.cap_delete +CSpace_A.cap_delete_one +CSpace_A.cap_insert +CSpace_A.cap_move +CSpace_A.cap_removeable +CSpace_A.cap_revoke +CSpace_A.cap_swap +CSpace_A.cap_swap_for_delete +CSpace_A.capclass +CSpace_A.capclass.OtherCapClass +CSpace_A.capclass.PhysicalClass +CSpace_A.captransfer_from_words +CSpace_A.data_to_rights +CSpace_A.deleting_irq_handler +CSpace_A.derive_cap +CSpace_A.ensure_no_children +CSpace_A.exposed_rdcall +CSpace_A.fast_finalise +CSpace_A.finalise_cap +CSpace_A.finalise_slot +CSpace_A.free_index_update +CSpace_A.get_badge +CSpace_A.get_receive_slots +CSpace_A.has_cancel_send_rights +CSpace_A.invoke_cnode +CSpace_A.isCTEDeleteCall +CSpace_A.is_cap_revocable +CSpace_A.is_physical +CSpace_A.load_cap_transfer +CSpace_A.locate_slot +CSpace_A.long_running_delete +CSpace_A.lookup_cap +CSpace_A.lookup_cap_and_slot +CSpace_A.lookup_pivot_slot +CSpace_A.lookup_slot_for_cnode_op +CSpace_A.lookup_slot_for_thread +CSpace_A.lookup_source_slot +CSpace_A.lookup_target_slot +CSpace_A.max_free_index +CSpace_A.max_free_index_update +CSpace_A.rec_del +CSpace_A.rec_del_call +CSpace_A.rec_del_call.CTEDeleteCall +CSpace_A.rec_del_call.FinaliseSlotCall +CSpace_A.rec_del_call.ReduceZombieCall +CSpace_A.resolve_address_bits +CSpace_A.resolve_address_bits' +CSpace_A.same_object_as +CSpace_A.same_region_as +CSpace_A.set_untyped_cap_as_full +CSpace_A.should_be_parent_of +CSpace_A.slot_cap_long_running_delete +CSpace_A.slot_rdcall +CSpace_A.tcb_registers_caps_merge +CSpace_A.untyped_sz_bits +CSpace_A.update_cap_data +CapRights_A.AllowRecv +CapRights_A.AllowSend +CapRights_A.CanModify +CapRights_A.all_rights +CapRights_A.cap_rights +CapRights_A.rights +CapRights_A.rights.AllowGrant +CapRights_A.rights.AllowGrantReply +CapRights_A.rights.AllowRead +CapRights_A.rights.AllowWrite +Decode_A.check_handler_ep +Decode_A.check_prio +Decode_A.data_to_obj_type +Decode_A.decode_bind_notification +Decode_A.decode_cnode_invocation +Decode_A.decode_copy_registers +Decode_A.decode_cv_space +Decode_A.decode_domain_invocation +Decode_A.decode_domain_schedule_configure +Decode_A.decode_domain_schedule_set_start +Decode_A.decode_domain_set +Decode_A.decode_invocation +Decode_A.decode_irq_control_invocation +Decode_A.decode_irq_handler_invocation +Decode_A.decode_read_registers +Decode_A.decode_sched_context_bind +Decode_A.decode_sched_context_invocation +Decode_A.decode_sched_context_unbind_object +Decode_A.decode_sched_context_yield_to +Decode_A.decode_sched_control_invocation_flags +Decode_A.decode_set_flags +Decode_A.decode_set_ipc_buffer +Decode_A.decode_set_mcpriority +Decode_A.decode_set_priority +Decode_A.decode_set_sched_params +Decode_A.decode_set_space +Decode_A.decode_set_timeout_ep +Decode_A.decode_set_tls_base +Decode_A.decode_tcb_configure +Decode_A.decode_tcb_invocation +Decode_A.decode_unbind_notification +Decode_A.decode_untyped_invocation +Decode_A.decode_update_sc +Decode_A.decode_write_registers +Decode_A.has_handler_rights +Decode_A.valid_fault_handler +Deterministic_A.OR_choice +Deterministic_A.OR_choiceE +Deterministic_A.cap_insert_ext +Deterministic_A.cap_move_ext +Deterministic_A.cap_swap_ext +Deterministic_A.cdt_list +Deterministic_A.cdt_list_update +Deterministic_A.create_cap_ext +Deterministic_A.det_ext +Deterministic_A.det_ext.cdt_list_internal +Deterministic_A.det_ext.work_units_completed_internal +Deterministic_A.det_ext_monad +Deterministic_A.det_state +Deterministic_A.do_extended_op +Deterministic_A.empty_slot_ext +Deterministic_A.free_asid_pool_select +Deterministic_A.free_asid_select +Deterministic_A.next_child +Deterministic_A.next_not_child +Deterministic_A.next_revoke_cap +Deterministic_A.next_sib +Deterministic_A.next_slot +Deterministic_A.reset_work_units +Deterministic_A.select_ext +Deterministic_A.set_cdt_list +Deterministic_A.state_ext +Deterministic_A.state_ext_class.ext_init +Deterministic_A.state_ext_class.select_switch +Deterministic_A.state_ext_class.wrap_ext_bool +Deterministic_A.state_ext_class.wrap_ext_op +Deterministic_A.trans_state +Deterministic_A.truncate_state +Deterministic_A.update_cdt_list +Deterministic_A.update_work_units +Deterministic_A.valid_list +Deterministic_A.valid_list_2 +Deterministic_A.work_units_completed +Deterministic_A.work_units_completed_update +Deterministic_A.work_units_limit +Deterministic_A.work_units_limit_reached +Event_H.event +Event_H.event.HypervisorEvent +Event_H.event.Interrupt +Event_H.event.SyscallEvent +Event_H.event.UnknownSyscall +Event_H.event.UserLevelFault +Event_H.event.VMFaultEvent +Event_H.syscall +Event_H.syscall.SysCall +Event_H.syscall.SysNBRecv +Event_H.syscall.SysNBSend +Event_H.syscall.SysNBSendRecv +Event_H.syscall.SysNBSendWait +Event_H.syscall.SysNBWait +Event_H.syscall.SysRecv +Event_H.syscall.SysReplyRecv +Event_H.syscall.SysSend +Event_H.syscall.SysWait +Event_H.syscall.SysYield +ExceptionTypes_A.fault +ExceptionTypes_A.fault.ArchFault +ExceptionTypes_A.fault.CapFault +ExceptionTypes_A.fault.Timeout +ExceptionTypes_A.fault.UnknownSyscallException +ExceptionTypes_A.fault.UserException +ExceptionTypes_A.lookup_failure +ExceptionTypes_A.lookup_failure.DepthMismatch +ExceptionTypes_A.lookup_failure.GuardMismatch +ExceptionTypes_A.lookup_failure.InvalidRoot +ExceptionTypes_A.lookup_failure.MissingCapability +ExceptionTypes_A.msg_from_lookup_failure +ExceptionTypes_A.msg_from_syscall_error +ExceptionTypes_A.syscall_error +ExceptionTypes_A.syscall_error.AlignmentError +ExceptionTypes_A.syscall_error.DeleteFirst +ExceptionTypes_A.syscall_error.FailedLookup +ExceptionTypes_A.syscall_error.IllegalOperation +ExceptionTypes_A.syscall_error.InvalidArgument +ExceptionTypes_A.syscall_error.InvalidCapability +ExceptionTypes_A.syscall_error.NotEnoughMemory +ExceptionTypes_A.syscall_error.RangeError +ExceptionTypes_A.syscall_error.RevokeFirst +ExceptionTypes_A.syscall_error.TruncatedMessage +Exceptions_A.cap_fault_on_failure +Exceptions_A.const_on_failure +Exceptions_A.empty_on_failure +Exceptions_A.f_monad +Exceptions_A.lf_monad +Exceptions_A.lookup_error_on_failure +Exceptions_A.null_cap_on_failure +Exceptions_A.p_monad +Exceptions_A.range_check +Exceptions_A.s_monad +Exceptions_A.se_monad +Exceptions_A.unify_failure +Exceptions_A.without_preemption +FPU_A.X64_A.fpu_release +FPU_A.X64_A.lazy_fpu_restore +FPU_A.X64_A.load_fpu_state +FPU_A.X64_A.save_fpu_state +FPU_A.X64_A.set_x64_current_fpu_owner +FPU_A.X64_A.switch_local_fpu_owner +Hypervisor_A.X64_A.handle_hypervisor_fault +Init_A.X64_A.global_pd +Init_A.X64_A.global_pdpt +Init_A.X64_A.global_pml4 +Init_A.X64_A.init_A_st +Init_A.X64_A.init_arch_state +Init_A.X64_A.init_cdt +Init_A.X64_A.init_global_pd +Init_A.X64_A.init_global_pdpt +Init_A.X64_A.init_global_pml4 +Init_A.X64_A.init_ioc +Init_A.X64_A.init_irq_node_ptr +Init_A.X64_A.init_kheap +Interrupt_A.handle_interrupt +Interrupt_A.invoke_irq_control +Interrupt_A.invoke_irq_handler +Interrupt_A.maybe_handle_interrupt +InvocationLabels_A.gen_invocation_type +InvocationLabels_A.invocation_type +InvocationLabels_H.enum_gen_invocation_labels_inst.enum_gen_invocation_labels +InvocationLabels_H.enum_invocation_label_inst.enum_invocation_label +InvocationLabels_H.gen_invocation_labels +InvocationLabels_H.gen_invocation_labels.CNodeCancelBadgedSends +InvocationLabels_H.gen_invocation_labels.CNodeCopy +InvocationLabels_H.gen_invocation_labels.CNodeDelete +InvocationLabels_H.gen_invocation_labels.CNodeMint +InvocationLabels_H.gen_invocation_labels.CNodeMove +InvocationLabels_H.gen_invocation_labels.CNodeMutate +InvocationLabels_H.gen_invocation_labels.CNodeRevoke +InvocationLabels_H.gen_invocation_labels.CNodeRotate +InvocationLabels_H.gen_invocation_labels.DomainScheduleConfigure +InvocationLabels_H.gen_invocation_labels.DomainScheduleSetStart +InvocationLabels_H.gen_invocation_labels.DomainSetSet +InvocationLabels_H.gen_invocation_labels.IRQAckIRQ +InvocationLabels_H.gen_invocation_labels.IRQClearIRQHandler +InvocationLabels_H.gen_invocation_labels.IRQIssueIRQHandler +InvocationLabels_H.gen_invocation_labels.IRQSetIRQHandler +InvocationLabels_H.gen_invocation_labels.InvalidInvocation +InvocationLabels_H.gen_invocation_labels.SchedContextBind +InvocationLabels_H.gen_invocation_labels.SchedContextConsumed +InvocationLabels_H.gen_invocation_labels.SchedContextUnbind +InvocationLabels_H.gen_invocation_labels.SchedContextUnbindObject +InvocationLabels_H.gen_invocation_labels.SchedContextYieldTo +InvocationLabels_H.gen_invocation_labels.SchedControlConfigureFlags +InvocationLabels_H.gen_invocation_labels.TCBBindNotification +InvocationLabels_H.gen_invocation_labels.TCBConfigure +InvocationLabels_H.gen_invocation_labels.TCBCopyRegisters +InvocationLabels_H.gen_invocation_labels.TCBReadRegisters +InvocationLabels_H.gen_invocation_labels.TCBResume +InvocationLabels_H.gen_invocation_labels.TCBSetFlags +InvocationLabels_H.gen_invocation_labels.TCBSetIPCBuffer +InvocationLabels_H.gen_invocation_labels.TCBSetMCPriority +InvocationLabels_H.gen_invocation_labels.TCBSetPriority +InvocationLabels_H.gen_invocation_labels.TCBSetSchedParams +InvocationLabels_H.gen_invocation_labels.TCBSetSpace +InvocationLabels_H.gen_invocation_labels.TCBSetTLSBase +InvocationLabels_H.gen_invocation_labels.TCBSetTimeoutEndpoint +InvocationLabels_H.gen_invocation_labels.TCBSuspend +InvocationLabels_H.gen_invocation_labels.TCBUnbindNotification +InvocationLabels_H.gen_invocation_labels.TCBWriteRegisters +InvocationLabels_H.gen_invocation_labels.UntypedRetype +InvocationLabels_H.invocation_label +InvocationLabels_H.invocation_label.ArchInvocationLabel +InvocationLabels_H.invocation_label.GenInvocationLabel +Invocations_A.cnode_invocation +Invocations_A.cnode_invocation.CancelBadgedSendsCall +Invocations_A.cnode_invocation.DeleteCall +Invocations_A.cnode_invocation.InsertCall +Invocations_A.cnode_invocation.MoveCall +Invocations_A.cnode_invocation.RevokeCall +Invocations_A.cnode_invocation.RotateCall +Invocations_A.domain_invocation +Invocations_A.domain_invocation.InvokeDomainScheduleConfigure +Invocations_A.domain_invocation.InvokeDomainScheduleSetStart +Invocations_A.domain_invocation.InvokeDomainSet +Invocations_A.domain_invocation.dom_domain +Invocations_A.domain_invocation.dom_duration +Invocations_A.domain_invocation.dom_index +Invocations_A.domain_invocation.dom_thread +Invocations_A.invocation +Invocations_A.invocation.InvokeArchObject +Invocations_A.invocation.InvokeCNode +Invocations_A.invocation.InvokeDomain +Invocations_A.invocation.InvokeEndpoint +Invocations_A.invocation.InvokeIRQControl +Invocations_A.invocation.InvokeIRQHandler +Invocations_A.invocation.InvokeNotification +Invocations_A.invocation.InvokeReply +Invocations_A.invocation.InvokeSchedContext +Invocations_A.invocation.InvokeSchedControl +Invocations_A.invocation.InvokeTCB +Invocations_A.invocation.InvokeUntyped +Invocations_A.irq_control_invocation +Invocations_A.irq_control_invocation.ArchIRQControl +Invocations_A.irq_control_invocation.IRQControl +Invocations_A.irq_handler_invocation +Invocations_A.irq_handler_invocation.ACKIrq +Invocations_A.irq_handler_invocation.ClearIRQHandler +Invocations_A.irq_handler_invocation.SetIRQHandler +Invocations_A.sched_context_invocation +Invocations_A.sched_context_invocation.InvokeSchedContextBind +Invocations_A.sched_context_invocation.InvokeSchedContextConsumed +Invocations_A.sched_context_invocation.InvokeSchedContextUnbind +Invocations_A.sched_context_invocation.InvokeSchedContextUnbindObject +Invocations_A.sched_context_invocation.InvokeSchedContextYieldTo +Invocations_A.sched_control_invocation +Invocations_A.sched_control_invocation.InvokeSchedControlConfigureFlags +Invocations_A.tcb_invocation +Invocations_A.tcb_invocation.CopyRegisters +Invocations_A.tcb_invocation.NotificationControl +Invocations_A.tcb_invocation.ReadRegisters +Invocations_A.tcb_invocation.Resume +Invocations_A.tcb_invocation.SetFlags +Invocations_A.tcb_invocation.SetTLSBase +Invocations_A.tcb_invocation.Suspend +Invocations_A.tcb_invocation.ThreadControlCaps +Invocations_A.tcb_invocation.ThreadControlSched +Invocations_A.tcb_invocation.WriteRegisters +Invocations_A.tcb_invocation.tc_new_buffer +Invocations_A.tcb_invocation.tc_new_croot +Invocations_A.tcb_invocation.tc_new_fault_handler +Invocations_A.tcb_invocation.tc_new_mcpriority +Invocations_A.tcb_invocation.tc_new_priority +Invocations_A.tcb_invocation.tc_new_sc +Invocations_A.tcb_invocation.tc_new_timeout_handler +Invocations_A.tcb_invocation.tc_new_vroot +Invocations_A.tcb_invocation.tc_slot +Invocations_A.tcb_invocation.tc_target +Invocations_A.untyped_invocation +Invocations_A.untyped_invocation.Retype +IpcCancel_A.arch_cap_set_map +IpcCancel_A.arch_gen_refs +IpcCancel_A.bind_sc_reply +IpcCancel_A.blocked_cancel_ipc +IpcCancel_A.blocking_ipc_badge +IpcCancel_A.cancel_all_ipc +IpcCancel_A.cancel_all_signals +IpcCancel_A.cancel_badged_sends +IpcCancel_A.cancel_ipc +IpcCancel_A.cancel_signal +IpcCancel_A.cap_cleanup_opt +IpcCancel_A.cap_irq_opt +IpcCancel_A.cap_irqs +IpcCancel_A.deleted_irq_handler +IpcCancel_A.do_unbind_notification +IpcCancel_A.do_unbind_ntfn_sc +IpcCancel_A.empty_slot +IpcCancel_A.ep_blocked +IpcCancel_A.gen_obj_ref +IpcCancel_A.gen_obj_ref.ArchRef +IpcCancel_A.gen_obj_ref.IRQRef +IpcCancel_A.gen_obj_ref.ObjRef +IpcCancel_A.gen_obj_refs +IpcCancel_A.get_blocking_object +IpcCancel_A.is_final_cap +IpcCancel_A.is_final_cap' +IpcCancel_A.no_reply_in_ts +IpcCancel_A.ntfn_blocked +IpcCancel_A.ntfn_queue_of +IpcCancel_A.ordered_insert +IpcCancel_A.post_cap_deletion +IpcCancel_A.remove_and_restart_badged_thread +IpcCancel_A.remove_and_restart_ep_queued_thread +IpcCancel_A.remove_and_restart_ntfn_queued_thread +IpcCancel_A.reorder_ep +IpcCancel_A.reorder_ntfn +IpcCancel_A.reply_push +IpcCancel_A.reply_remove +IpcCancel_A.reply_remove_tcb +IpcCancel_A.reply_unlink_sc +IpcCancel_A.reply_unlink_tcb +IpcCancel_A.restart_thread_if_no_fault +IpcCancel_A.sc_with_reply +IpcCancel_A.sched_context_bind_ntfn +IpcCancel_A.sched_context_donate +IpcCancel_A.sched_context_maybe_unbind_ntfn +IpcCancel_A.sched_context_unbind_all_tcbs +IpcCancel_A.sched_context_unbind_ntfn +IpcCancel_A.sched_context_unbind_reply +IpcCancel_A.sched_context_unbind_tcb +IpcCancel_A.set_priority +IpcCancel_A.tcb_append +IpcCancel_A.tcb_ep_append +IpcCancel_A.tcb_ep_dequeue +IpcCancel_A.tcb_ntfn_append +IpcCancel_A.tcb_ntfn_dequeue +IpcCancel_A.test_reschedule +IpcCancel_A.unbind_maybe_notification +IpcCancel_A.unbind_notification +IpcCancel_A.update_ep_queue +IpcCancel_A.update_ntfn_queue +Ipc_A.buffer_cptr_index +Ipc_A.charge_budget +Ipc_A.check_budget +Ipc_A.check_budget_restart +Ipc_A.complete_signal +Ipc_A.do_fault_transfer +Ipc_A.do_ipc_transfer +Ipc_A.do_nbrecv_failed_transfer +Ipc_A.do_normal_transfer +Ipc_A.do_reply_transfer +Ipc_A.end_timeslice +Ipc_A.get_extra_cptr +Ipc_A.get_extra_cptrs +Ipc_A.get_message_info +Ipc_A.handle_fault +Ipc_A.handle_fault_reply +Ipc_A.handle_no_fault +Ipc_A.handle_timeout +Ipc_A.invoke_sched_control_configure_flags +Ipc_A.isActive +Ipc_A.is_timeout_fault +Ipc_A.is_valid_timeout_handler +Ipc_A.lookup_extra_caps +Ipc_A.make_fault_msg +Ipc_A.receive_blocked +Ipc_A.receive_ipc +Ipc_A.receive_ipc_blocked +Ipc_A.receive_signal +Ipc_A.receive_signal_blocked +Ipc_A.refill_reset_rr +Ipc_A.remove_rights +Ipc_A.send_fault_ipc +Ipc_A.send_ipc +Ipc_A.send_ipc_blocked +Ipc_A.send_signal +Ipc_A.set_extra_badge +Ipc_A.transfer_caps +Ipc_A.transfer_caps_data +Ipc_A.transfer_caps_loop +Ipc_A.update_waiting_ntfn +KHeap_A.active_sc +KHeap_A.arch_thread_get +KHeap_A.arch_thread_set +KHeap_A.as_user +KHeap_A.cnode_contents_of +KHeap_A.cnode_of +KHeap_A.cnode_sizes_of +KHeap_A.cnodes_of +KHeap_A.ct_schedulable +KHeap_A.get_endpoint +KHeap_A.get_irq_slot +KHeap_A.get_irq_state +KHeap_A.get_notification +KHeap_A.get_ntfn_obj_ref +KHeap_A.get_object +KHeap_A.get_refill_head +KHeap_A.get_refill_tail +KHeap_A.get_refills +KHeap_A.get_reply +KHeap_A.get_reply_obj_ref +KHeap_A.get_reply_tcb +KHeap_A.get_sc_active +KHeap_A.get_sc_obj_ref +KHeap_A.get_sc_refill_capacity +KHeap_A.get_sc_refill_ready +KHeap_A.get_sc_refill_sufficient +KHeap_A.get_sc_released +KHeap_A.get_sched_context +KHeap_A.get_simple_ko +KHeap_A.get_sk_obj_ref +KHeap_A.get_tcb +KHeap_A.get_tcb_obj_ref +KHeap_A.get_tcb_queue +KHeap_A.get_thread_state +KHeap_A.in_release_queue +KHeap_A.is_blocked +KHeap_A.is_cur_domain_expired +KHeap_A.is_irq_active +KHeap_A.is_simple_type +KHeap_A.ntfn_set_bound_tcb +KHeap_A.ntfn_set_obj +KHeap_A.possible_switch_to +KHeap_A.preemption_point +KHeap_A.r_monad +KHeap_A.read_object +KHeap_A.read_refill_head +KHeap_A.read_refill_tail +KHeap_A.read_sc_active +KHeap_A.read_sc_obj_ref +KHeap_A.read_sc_refill_capacity +KHeap_A.read_sc_refill_ready +KHeap_A.read_sc_refill_sufficient +KHeap_A.read_sc_released +KHeap_A.read_sched_context +KHeap_A.read_tcb_obj_ref +KHeap_A.read_thread_state +KHeap_A.refill_capacity +KHeap_A.refill_hd +KHeap_A.refill_ready +KHeap_A.refill_ready' +KHeap_A.refill_sufficient +KHeap_A.refill_tl +KHeap_A.reschedule_required +KHeap_A.sc_active +KHeap_A.sc_fields_of +KHeap_A.sc_of +KHeap_A.sc_released +KHeap_A.sc_sizes_of +KHeap_A.schedulable +KHeap_A.schedule_tcb +KHeap_A.scs_fields_of +KHeap_A.scs_of +KHeap_A.scs_of_kh +KHeap_A.set_endpoint +KHeap_A.set_flags +KHeap_A.set_irq_state +KHeap_A.set_mcpriority +KHeap_A.set_notification +KHeap_A.set_ntfn_obj_ref +KHeap_A.set_object +KHeap_A.set_release_queue +KHeap_A.set_reply +KHeap_A.set_reply_obj_ref +KHeap_A.set_sc_obj_ref +KHeap_A.set_sched_context +KHeap_A.set_scheduler_action +KHeap_A.set_simple_ko +KHeap_A.set_tcb_obj_ref +KHeap_A.set_tcb_queue +KHeap_A.set_thread_state +KHeap_A.set_thread_state_act +KHeap_A.tcb_of +KHeap_A.tcb_release_remove +KHeap_A.tcb_sched_action +KHeap_A.tcb_sched_append +KHeap_A.tcb_sched_dequeue +KHeap_A.tcb_sched_enqueue +KHeap_A.tcbs_of +KHeap_A.tcbs_of_kh +KHeap_A.thread_get +KHeap_A.thread_read +KHeap_A.thread_set +KHeap_A.thread_set_domain +KHeap_A.thread_set_priority +KHeap_A.throw_on_false +KHeap_A.update_sched_context +KHeap_A.update_sk_obj_ref +KHeap_A.update_time_stamp +Kernel_Config.config_HAVE_FPU +Kernel_Config.numDomains +Kernel_Config.resetChunkBits +Kernel_Config.retypeFanOutLimit +Kernel_Config_Lemmas.domainBits +Lib.partial_inv +List_Lib.after_in_list +List_Lib.list_insert_after +List_Lib.list_remove +List_Lib.list_replace +List_Lib.list_replace_list +List_Lib.list_swap +MachineMonad.ignore_failure +MachineMonad.machine_monad +MachineMonad.machine_op_lift +MachineMonad.machine_rest_lift +MachineMonad.machine_rest_monad +MachineOps.X64.FPUNullState +MachineOps.X64.IRQ +MachineOps.X64.ackDeadlineIRQ +MachineOps.X64.ackInterrupt +MachineOps.X64.clearMemory +MachineOps.X64.clearMemoryVM +MachineOps.X64.configureTimer +MachineOps.X64.configureTimer_impl +MachineOps.X64.configureTimer_val +MachineOps.X64.debugPrint +MachineOps.X64.device_regions +MachineOps.X64.disableFpu +MachineOps.X64.disableFpu_impl +MachineOps.X64.enableFpu +MachineOps.X64.enableFpu_impl +MachineOps.X64.fpu_bytes +MachineOps.X64.fpu_state +MachineOps.X64.freeMemory +MachineOps.X64.getActiveIRQ +MachineOps.X64.getCurrentTime +MachineOps.X64.getDeviceRegions +MachineOps.X64.getDeviceRegions_impl +MachineOps.X64.getDeviceRegions_val +MachineOps.X64.getFPUState +MachineOps.X64.getFaultAddress +MachineOps.X64.getFaultAddress_val +MachineOps.X64.getKernelDevices +MachineOps.X64.getKernelDevices_impl +MachineOps.X64.getKernelDevices_val +MachineOps.X64.getMemoryRegions +MachineOps.X64.getRegister +MachineOps.X64.getRestartPC +MachineOps.X64.in16 +MachineOps.X64.in16_impl +MachineOps.X64.in16_val +MachineOps.X64.in32 +MachineOps.X64.in32_impl +MachineOps.X64.in32_val +MachineOps.X64.in8 +MachineOps.X64.in8_impl +MachineOps.X64.in8_val +MachineOps.X64.initL2Cache +MachineOps.X64.initL2Cache_impl +MachineOps.X64.initMemory +MachineOps.X64.initTimer +MachineOps.X64.initTimer_impl +MachineOps.X64.invalidateASID +MachineOps.X64.invalidateASID_impl +MachineOps.X64.invalidateLocalPageStructureCacheASID +MachineOps.X64.invalidateLocalPageStructureCacheASID_impl +MachineOps.X64.invalidateTLB +MachineOps.X64.invalidateTLBEntry +MachineOps.X64.invalidateTLBEntry_impl +MachineOps.X64.invalidateTLB_impl +MachineOps.X64.invalidateTranslationSingleASID +MachineOps.X64.invalidateTranslationSingleASID_impl +MachineOps.X64.ioapicIRQLines +MachineOps.X64.ioapicMapPinToVector +MachineOps.X64.ioapicMapPinToVector_impl +MachineOps.X64.irqIntOffset +MachineOps.X64.irqIntOffset_val +MachineOps.X64.isFpuEnable +MachineOps.X64.loadWord +MachineOps.X64.maskInterrupt +MachineOps.X64.maxPCIBus +MachineOps.X64.maxPCIDev +MachineOps.X64.maxPCIFunc +MachineOps.X64.memory_regions +MachineOps.X64.mfence +MachineOps.X64.mfence_impl +MachineOps.X64.modify_registers +MachineOps.X64.non_kernel_IRQs +MachineOps.X64.out16 +MachineOps.X64.out16_impl +MachineOps.X64.out32 +MachineOps.X64.out32_impl +MachineOps.X64.out8 +MachineOps.X64.out8_impl +MachineOps.X64.readFpuState +MachineOps.X64.readFpuState_val +MachineOps.X64.resetTimer +MachineOps.X64.resetTimer_impl +MachineOps.X64.setDeadline +MachineOps.X64.setDeadline_impl +MachineOps.X64.setFPUState +MachineOps.X64.setInterruptMode +MachineOps.X64.setNextPC +MachineOps.X64.setRegister +MachineOps.X64.storeWord +MachineOps.X64.storeWordVM +MachineOps.X64.user_context +MachineOps.X64.user_context.UserContext +MachineOps.X64.user_context.user_fpu_state +MachineOps.X64.user_context.user_regs +MachineOps.X64.user_monad +MachineOps.X64.user_regs +MachineOps.X64.writeCR3 +MachineOps.X64.writeCR3_impl +MachineOps.X64.writeFpuState +MachineOps.X64.writeFpuState_impl +MachineTypes.X64.badgeRegister +MachineTypes.X64.capRegister +MachineTypes.X64.exceptionMessage +MachineTypes.X64.faultRegister +MachineTypes.X64.frameRegisters +MachineTypes.X64.gdtToSel +MachineTypes.X64.gdtToSel_masked +MachineTypes.X64.gdtslot +MachineTypes.X64.gdtslot.GDT_CS_0 +MachineTypes.X64.gdtslot.GDT_CS_3 +MachineTypes.X64.gdtslot.GDT_DS_0 +MachineTypes.X64.gdtslot.GDT_DS_3 +MachineTypes.X64.gdtslot.GDT_ENTRIES +MachineTypes.X64.gdtslot.GDT_FS +MachineTypes.X64.gdtslot.GDT_GS +MachineTypes.X64.gdtslot.GDT_NULL +MachineTypes.X64.gdtslot.GDT_TSS +MachineTypes.X64.gdtslot.GDT_TSS_Padding +MachineTypes.X64.gpRegisters +MachineTypes.X64.hyp_fault_type +MachineTypes.X64.hyp_fault_type.X64NoHypFaults +MachineTypes.X64.initContext +MachineTypes.X64.init_irq_masks +MachineTypes.X64.init_machine_state +MachineTypes.X64.init_underlying_memory +MachineTypes.X64.machine_monad +MachineTypes.X64.machine_state_rest +MachineTypes.X64.msgInfoRegister +MachineTypes.X64.msgRegisters +MachineTypes.X64.nbsendRecvDest +MachineTypes.X64.nextInstructionRegister +MachineTypes.X64.pageBits +MachineTypes.X64.pageBitsForSize +MachineTypes.X64.ptTranslationBits +MachineTypes.X64.register +MachineTypes.X64.register.CS +MachineTypes.X64.register.ErrorRegister +MachineTypes.X64.register.FLAGS +MachineTypes.X64.register.FS_BASE +MachineTypes.X64.register.FaultIP +MachineTypes.X64.register.GS_BASE +MachineTypes.X64.register.NextIP +MachineTypes.X64.register.R10 +MachineTypes.X64.register.R11 +MachineTypes.X64.register.R12 +MachineTypes.X64.register.R13 +MachineTypes.X64.register.R14 +MachineTypes.X64.register.R15 +MachineTypes.X64.register.R8 +MachineTypes.X64.register.R9 +MachineTypes.X64.register.RAX +MachineTypes.X64.register.RBP +MachineTypes.X64.register.RBX +MachineTypes.X64.register.RCX +MachineTypes.X64.register.RDI +MachineTypes.X64.register.RDX +MachineTypes.X64.register.RSI +MachineTypes.X64.register.RSP +MachineTypes.X64.register.SS +MachineTypes.X64.replyRegister +MachineTypes.X64.selCS0 +MachineTypes.X64.selCS3 +MachineTypes.X64.selDS0 +MachineTypes.X64.selDS3 +MachineTypes.X64.selFS +MachineTypes.X64.selGS +MachineTypes.X64.syscallMessage +MachineTypes.X64.timeoutMessage +MachineTypes.X64.tlsBaseRegister +MachineTypes.X64.vmfault_type +MachineTypes.X64.vmfault_type.X64DataFault +MachineTypes.X64.vmfault_type.X64InstructionFault +MachineTypes.X64.vmmap_type +MachineTypes.X64.vmmap_type.VMNoMap +MachineTypes.X64.vmmap_type.VMVSpaceMap +MachineTypes.X64.vmpage_size +MachineTypes.X64.vmpage_size.X64HugePage +MachineTypes.X64.vmpage_size.X64LargePage +MachineTypes.X64.vmpage_size.X64SmallPage +MachineTypes.irq_oracle +MachineTypes.machine_state +MachineTypes.machine_state.device_state +MachineTypes.machine_state.fpu_enabled +MachineTypes.machine_state.irq_masks +MachineTypes.machine_state.irq_state +MachineTypes.machine_state.last_machine_time +MachineTypes.machine_state.machine_state_rest +MachineTypes.machine_state.time_state +MachineTypes.machine_state.underlying_memory +MachineTypes.time_oracle +Machine_A.X64_A.arch_fault +Machine_A.X64_A.arch_fault.VMFault +Machine_A.X64_A.asid +Machine_A.X64_A.asid_high_index +Machine_A.X64_A.asid_high_len +Machine_A.X64_A.asid_len +Machine_A.X64_A.asid_low_index +Machine_A.X64_A.asid_low_len +Machine_A.X64_A.asid_rep_len +Machine_A.X64_A.badge_register +Machine_A.X64_A.cap_ref +Machine_A.X64_A.cap_register +Machine_A.X64_A.combine_ntfn_badges +Machine_A.X64_A.combine_ntfn_msgs +Machine_A.X64_A.data +Machine_A.X64_A.data_to_16 +Machine_A.X64_A.data_to_cptr +Machine_A.X64_A.data_to_nat +Machine_A.X64_A.data_to_oref +Machine_A.X64_A.data_to_vref +Machine_A.X64_A.exception_message +Machine_A.X64_A.frame_registers +Machine_A.X64_A.gp_registers +Machine_A.X64_A.idle_sc_ptr +Machine_A.X64_A.idle_thread_ptr +Machine_A.X64_A.kernel_base +Machine_A.X64_A.length_type +Machine_A.X64_A.msg_info_register +Machine_A.X64_A.msg_label_bits +Machine_A.X64_A.msg_registers +Machine_A.X64_A.nat_to_cref +Machine_A.X64_A.nat_to_len +Machine_A.X64_A.new_context +Machine_A.X64_A.obj_ref +Machine_A.X64_A.oref_to_data +Machine_A.X64_A.pptr_base +Machine_A.X64_A.slot_bits +Machine_A.X64_A.syscall_message +Machine_A.X64_A.user_vtop +Machine_A.X64_A.vref_to_data +Machine_A.X64_A.vspace_ref +Machine_Word_64_Basics.word_bits +Machine_Word_64_Basics.word_size +Machine_Word_64_Basics.word_size_bits +MiscMachine_A.asid_bits +MiscMachine_A.asid_high_bits +MiscMachine_A.asid_low_bits +More_Word_Operations.alignUp +More_Word_Operations.ptr_add +Nondet_Empty_Fail.mk_ef +Platform.X64.addrFromKPPtr +Platform.X64.addrFromPPtr +Platform.X64.cr3 +Platform.X64.cr3.CR3BaseAddress +Platform.X64.cr3.X64CR3 +Platform.X64.cr3.cr3pcid +Platform.X64.fromPAddr +Platform.X64.irq +Platform.X64.irq_len +Platform.X64.kernelELFBaseOffset +Platform.X64.maxIRQ +Platform.X64.maxUserIRQ +Platform.X64.minIRQ +Platform.X64.minUserIRQ +Platform.X64.paddr +Platform.X64.pptrBase +Platform.X64.pptrUserTop +Platform.X64.ptrFromPAddr +Platform.X64.timerIRQ +Platform.X64.toPAddr +Platform.int_literal_len +Platform.int_word +Reader_Option_Monad.asks +Reader_Option_Monad.lookup +Reader_Option_Monad.oassert +Reader_Option_Monad.oassert_opt +Reader_Option_Monad.ofail +Reader_Option_Monad.oliftM +Reader_Option_Monad.opt_map +Reader_Option_Monad.opt_map_Some +Reader_Option_Monad.opt_pred +Reader_Option_Monad.oreturn +Reader_Option_Monad.ounless +Reader_Option_Monad.owhen +Retype_A.create_cap +Retype_A.default_cap +Retype_A.default_object +Retype_A.delete_objects +Retype_A.detype +Retype_A.empty_cnode +Retype_A.get_free_index +Retype_A.get_free_ref +Retype_A.invoke_untyped +Retype_A.is_device_untyped_cap +Retype_A.obj_bits_api +Retype_A.reset_untyped_cap +Retype_A.retype_region +SchedContext_A.charge_entire_head_refill +SchedContext_A.commit_time +SchedContext_A.complete_yield_to +SchedContext_A.handle_overrun +SchedContext_A.head_insufficient_loop +SchedContext_A.head_refill_overrun +SchedContext_A.max_refills_cap +SchedContext_A.maybe_add_empty_tail +SchedContext_A.maybe_donate_sc +SchedContext_A.maybe_return_sc +SchedContext_A.merge_nonoverlapping_head_refill +SchedContext_A.postpone +SchedContext_A.read_ready_time +SchedContext_A.read_tcb_ready_time +SchedContext_A.ready_times_append +SchedContext_A.refill_add_tail +SchedContext_A.refill_budget_check +SchedContext_A.refill_budget_check_round_robin +SchedContext_A.refill_full +SchedContext_A.refill_head_insufficient +SchedContext_A.refill_new +SchedContext_A.refill_single +SchedContext_A.refill_size +SchedContext_A.refill_sum +SchedContext_A.refill_update +SchedContext_A.refills_sum +SchedContext_A.return_consumed +SchedContext_A.sched_context_bind_tcb +SchedContext_A.sched_context_cancel_yield_to +SchedContext_A.sched_context_resume +SchedContext_A.sched_context_set_inactive +SchedContext_A.sched_context_unbind_yield_from +SchedContext_A.sched_context_update_consumed +SchedContext_A.schedule_used +SchedContext_A.set_consumed +SchedContext_A.set_refill_hd +SchedContext_A.set_refill_tl +SchedContext_A.set_refills +SchedContext_A.suspend +SchedContext_A.tcb_release_enqueue +SchedContext_A.test_possible_switch_to +SchedContext_A.unbind_from_sc +SchedContext_A.update_refill_tl +SchedContext_A.update_restart_pc +Schedule_A.awaken +Schedule_A.check_domain_time +Schedule_A.choose_thread +Schedule_A.dec_domain_time +Schedule_A.domain_end_marker +Schedule_A.domain_schedule_configure +Schedule_A.domain_set_start +Schedule_A.guarded_switch_to +Schedule_A.idle +Schedule_A.invoke_sched_context +Schedule_A.is_highest_prio +Schedule_A.max_non_empty_queue +Schedule_A.next_domain +Schedule_A.read_release_q_non_empty_and_ready +Schedule_A.read_tcb_refill_ready +Schedule_A.sc_and_timer +Schedule_A.sched_context_yield_to +Schedule_A.schedule +Schedule_A.schedule_choose_new_thread +Schedule_A.schedule_switch_thread_branch +Schedule_A.schedule_switch_thread_fastfail +Schedule_A.set_next_interrupt +Schedule_A.switch_sched_context +Schedule_A.switch_to_idle_thread +Schedule_A.switch_to_thread +Schedule_A.tcb_release_dequeue +Sporadic_A.can_merge_refill +Sporadic_A.if_cond_refill_unblock_check +Sporadic_A.if_constant_bandwidth_refill_unblock_check +Sporadic_A.if_sporadic_active_cur_sc_assert_refill_unblock_check +Sporadic_A.if_sporadic_active_cur_sc_test_refill_unblock_check +Sporadic_A.if_sporadic_and_active_refill_unblock_check +Sporadic_A.if_sporadic_cur_sc_assert_refill_unblock_check +Sporadic_A.if_sporadic_cur_sc_test_refill_unblock_check +Sporadic_A.is_round_robin +Sporadic_A.merge_overlapping_refills +Sporadic_A.merge_refill +Sporadic_A.refill_head_overlapping +Sporadic_A.refill_head_overlapping_loop +Sporadic_A.refill_pop_head +Sporadic_A.refill_unblock_check +Sporadic_A.update_refill_hd +Structs_B.tcbFlagMask +Structs_B.tcbFlagToWord +Structs_B.tcb_flag +Structs_B.tcb_flag.FpuDisabled +Structs_B.ticks +Structs_B.ticks_len +Structs_B.timeArgLen +Structures_A.MIN_BUDGET +Structures_A.MIN_BUDGET_US +Structures_A.MIN_REFILLS +Structures_A.a_type +Structures_A.a_type.AArch +Structures_A.a_type.ACapTable +Structures_A.a_type.AEndpoint +Structures_A.a_type.AGarbage +Structures_A.a_type.ANTFN +Structures_A.a_type.AReply +Structures_A.a_type.ASchedContext +Structures_A.a_type.ATCB +Structures_A.abstract_state +Structures_A.abstract_state.arch_state +Structures_A.abstract_state.cdt +Structures_A.abstract_state.consumed_time +Structures_A.abstract_state.cur_domain +Structures_A.abstract_state.cur_sc +Structures_A.abstract_state.cur_thread +Structures_A.abstract_state.cur_time +Structures_A.abstract_state.domain_index +Structures_A.abstract_state.domain_list +Structures_A.abstract_state.domain_start_index +Structures_A.abstract_state.domain_time +Structures_A.abstract_state.idle_thread +Structures_A.abstract_state.interrupt_irq_node +Structures_A.abstract_state.interrupt_states +Structures_A.abstract_state.is_original_cap +Structures_A.abstract_state.kheap +Structures_A.abstract_state.machine_state +Structures_A.abstract_state.ready_queues +Structures_A.abstract_state.release_queue +Structures_A.abstract_state.reprogram_timer +Structures_A.abstract_state.scheduler_action +Structures_A.aobj_of +Structures_A.apiobject_type +Structures_A.apiobject_type.ArchObject +Structures_A.apiobject_type.CapTableObject +Structures_A.apiobject_type.EndpointObject +Structures_A.apiobject_type.NotificationObject +Structures_A.apiobject_type.ReplyObject +Structures_A.apiobject_type.SchedContextObject +Structures_A.apiobject_type.TCBObject +Structures_A.apiobject_type.Untyped +Structures_A.badge +Structures_A.badge_update +Structures_A.bits_of +Structures_A.cap +Structures_A.cap.ArchObjectCap +Structures_A.cap.CNodeCap +Structures_A.cap.DomainCap +Structures_A.cap.EndpointCap +Structures_A.cap.IRQControlCap +Structures_A.cap.IRQHandlerCap +Structures_A.cap.NotificationCap +Structures_A.cap.NullCap +Structures_A.cap.ReplyCap +Structures_A.cap.SchedContextCap +Structures_A.cap.SchedControlCap +Structures_A.cap.ThreadCap +Structures_A.cap.UntypedCap +Structures_A.cap.Zombie +Structures_A.cap.the_arch_cap +Structures_A.cap_badge +Structures_A.cap_bits_untyped +Structures_A.cap_ep_badge +Structures_A.cap_ep_ptr +Structures_A.cap_of +Structures_A.cap_rights +Structures_A.cap_rights_update +Structures_A.cap_transfer_data_size +Structures_A.caps_of +Structures_A.captransfer +Structures_A.captransfer.ct_receive_depth +Structures_A.captransfer.ct_receive_index +Structures_A.captransfer.ct_receive_root +Structures_A.cdt +Structures_A.cnode_contents +Structures_A.cnode_index +Structures_A.cslot_ptr +Structures_A.data_to_message_info +Structures_A.default_domain +Structures_A.default_ep +Structures_A.default_notification +Structures_A.default_ntfn +Structures_A.default_priority +Structures_A.default_reply +Structures_A.default_sched_context +Structures_A.default_tcb +Structures_A.do_machine_op +Structures_A.domain +Structures_A.domain_duration +Structures_A.domain_duration_len +Structures_A.domain_len +Structures_A.endpoint +Structures_A.endpoint.IdleEP +Structures_A.endpoint.RecvEP +Structures_A.endpoint.SendEP +Structures_A.endpoint.ep_queue +Structures_A.first_cslot_of +Structures_A.free_index_of +Structures_A.ipc_queued_thread_state +Structures_A.irq_state +Structures_A.irq_state.IRQInactive +Structures_A.irq_state.IRQReserved +Structures_A.irq_state.IRQSignal +Structures_A.irq_state.IRQTimer +Structures_A.is_arch_cap +Structures_A.is_blocked_on_ntfn +Structures_A.is_blocked_on_receive +Structures_A.is_blocked_on_reply +Structures_A.is_blocked_on_send +Structures_A.is_cnode_cap +Structures_A.is_domain_cap +Structures_A.is_ep_cap +Structures_A.is_frame_type +Structures_A.is_ntfn_cap +Structures_A.is_reply_cap +Structures_A.is_sched_context_cap +Structures_A.is_thread_cap +Structures_A.is_untyped_cap +Structures_A.is_zombie +Structures_A.kernel_object +Structures_A.kernel_object.ArchObj +Structures_A.kernel_object.CNode +Structures_A.kernel_object.Endpoint +Structures_A.kernel_object.Notification +Structures_A.kernel_object.Reply +Structures_A.kernel_object.SchedContext +Structures_A.kernel_object.TCB +Structures_A.kernel_object.the_arch_obj +Structures_A.kheap +Structures_A.mask_cap +Structures_A.max_domain_duration +Structures_A.max_ipc_length +Structures_A.max_num_refills +Structures_A.message +Structures_A.message_info +Structures_A.message_info.MI +Structures_A.message_info.mi_caps_unwrapped +Structures_A.message_info.mi_extra_caps +Structures_A.message_info.mi_label +Structures_A.message_info.mi_length +Structures_A.message_info_to_data +Structures_A.min_sched_context_bits +Structures_A.msg_align_bits +Structures_A.msg_label +Structures_A.msg_max_extra_caps +Structures_A.msg_max_length +Structures_A.notification +Structures_A.notification.ntfn_bound_tcb +Structures_A.notification.ntfn_bound_tcb_update +Structures_A.notification.ntfn_obj +Structures_A.notification.ntfn_obj_update +Structures_A.notification.ntfn_sc +Structures_A.notification.ntfn_sc_update +Structures_A.ntfn +Structures_A.ntfn.ActiveNtfn +Structures_A.ntfn.IdleNtfn +Structures_A.ntfn.WaitingNtfn +Structures_A.ntfn.is_WaitingNtfn +Structures_A.ntfn.ntfn_badge +Structures_A.ntfn.ntfn_queue +Structures_A.obj_bits +Structures_A.obj_ref_of +Structures_A.obj_refs +Structures_A.obj_size +Structures_A.priority +Structures_A.ready_queue +Structures_A.receiver_payload +Structures_A.receiver_payload.receiver_can_grant +Structures_A.refill +Structures_A.refill.r_amount +Structures_A.refill.r_time +Structures_A.refill_size_bytes +Structures_A.release_queue +Structures_A.reply +Structures_A.reply.reply_sc +Structures_A.reply.reply_sc_update +Structures_A.reply.reply_tcb +Structures_A.reply.reply_tcb_update +Structures_A.reply_object +Structures_A.runnable +Structures_A.sc_sporadic_flag +Structures_A.sched_context +Structures_A.sched_context.sc_badge +Structures_A.sched_context.sc_badge_update +Structures_A.sched_context.sc_budget +Structures_A.sched_context.sc_budget_update +Structures_A.sched_context.sc_consumed +Structures_A.sched_context.sc_consumed_update +Structures_A.sched_context.sc_ntfn +Structures_A.sched_context.sc_ntfn_update +Structures_A.sched_context.sc_period +Structures_A.sched_context.sc_period_update +Structures_A.sched_context.sc_refill_max +Structures_A.sched_context.sc_refill_max_update +Structures_A.sched_context.sc_refills +Structures_A.sched_context.sc_refills_update +Structures_A.sched_context.sc_replies +Structures_A.sched_context.sc_replies_update +Structures_A.sched_context.sc_sporadic +Structures_A.sched_context.sc_sporadic_update +Structures_A.sched_context.sc_tcb +Structures_A.sched_context.sc_tcb_update +Structures_A.sched_context.sc_yield_from +Structures_A.sched_context.sc_yield_from_update +Structures_A.scheduler_action +Structures_A.scheduler_action.choose_new_thread +Structures_A.scheduler_action.resume_cur_thread +Structures_A.scheduler_action.sch_act_target +Structures_A.scheduler_action.switch_thread +Structures_A.sender_payload +Structures_A.sender_payload.sender_badge +Structures_A.sender_payload.sender_can_grant +Structures_A.sender_payload.sender_can_grant_reply +Structures_A.sender_payload.sender_is_call +Structures_A.sizeof_sched_context_t +Structures_A.state +Structures_A.state.exst +Structures_A.tcb +Structures_A.tcb.tcb_arch +Structures_A.tcb.tcb_bound_notification +Structures_A.tcb.tcb_bound_notification_update +Structures_A.tcb.tcb_ctable +Structures_A.tcb.tcb_domain +Structures_A.tcb.tcb_fault +Structures_A.tcb.tcb_fault_handler +Structures_A.tcb.tcb_flags +Structures_A.tcb.tcb_ipc_buffer +Structures_A.tcb.tcb_ipcframe +Structures_A.tcb.tcb_mcpriority +Structures_A.tcb.tcb_priority +Structures_A.tcb.tcb_sched_context +Structures_A.tcb.tcb_sched_context_update +Structures_A.tcb.tcb_state +Structures_A.tcb.tcb_timeout_handler +Structures_A.tcb.tcb_vtable +Structures_A.tcb.tcb_yield_to +Structures_A.tcb.tcb_yield_to_update +Structures_A.tcb_cnode_index +Structures_A.tcb_cnode_map +Structures_A.tcb_flags +Structures_A.tcb_flags_to_word +Structures_A.the_cnode_cap +Structures_A.thread_state +Structures_A.thread_state.BlockedOnNotification +Structures_A.thread_state.BlockedOnReceive +Structures_A.thread_state.BlockedOnReply +Structures_A.thread_state.BlockedOnSend +Structures_A.thread_state.IdleThreadState +Structures_A.thread_state.Inactive +Structures_A.thread_state.Restart +Structures_A.thread_state.Running +Structures_A.valid_sched_context_size +Structures_A.well_formed_cnode_n +Structures_A.word_to_tcb_flags +Structures_A.zombie_cte_bits +Syscall_A.call_kernel +Syscall_A.get_cap_reg +Syscall_A.handle_call +Syscall_A.handle_event +Syscall_A.handle_invocation +Syscall_A.handle_recv +Syscall_A.handle_send +Syscall_A.handle_yield +Syscall_A.lookup_reply +Syscall_A.perform_invocation +Syscall_A.preemption_path +Syscall_A.syscall +TcbAcc_A.reply_from_kernel +TcbAcc_A.set_message_info +TcbAcc_A.set_mrs +TcbAcc_A.store_word_offs +Tcb_A.activate_thread +Tcb_A.bind_notification +Tcb_A.check_cap_at +Tcb_A.copy_mrs +Tcb_A.get_mrs +Tcb_A.get_tcb_ctable_ptr +Tcb_A.get_tcb_fault_handler_ptr +Tcb_A.get_tcb_timeout_handler_ptr +Tcb_A.get_tcb_vtable_ptr +Tcb_A.install_tcb_cap +Tcb_A.install_tcb_frame_cap +Tcb_A.invoke_domain +Tcb_A.invoke_set_domain +Tcb_A.invoke_tcb +Tcb_A.load_word_offs +Tcb_A.load_word_offs_word +Tcb_A.option_update_thread +Tcb_A.restart +Tcb_A.set_domain +Time.MAX_PERIOD +Time.MAX_PERIOD_US +Time.MAX_RELEASE_TIME +Time.\s_in_ms +Time.getCurrentTime_buffer +Time.kernelWCET_ticks +Time.kernelWCET_us +Time.maxTimer_us +Time.max_ticks_to_us +Time.max_time +Time.max_us_to_ticks +Time.ticks +Time.ticks_len +Time.ticks_per_timer_unit +Time.ticks_to_us +Time.time +Time.time_buffer_const +Time.timer_unit +Time.us_to_ticks +VMRights_A.mask_vm_rights +VMRights_A.valid_vm_rights +VMRights_A.validate_vm_rights +VMRights_A.vm_kernel_only +VMRights_A.vm_read_only +VMRights_A.vm_read_write +VMRights_A.vm_rights diff --git a/proofs/Fl4SpecEquivX64/tools/phase1-theories.txt b/proofs/Fl4SpecEquivX64/tools/phase1-theories.txt new file mode 100644 index 000000000..884dbe197 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/tools/phase1-theories.txt @@ -0,0 +1,71 @@ +ASpec.ArchCSpace_A +ASpec.ArchDecode_A +ASpec.ArchFault_A +ASpec.ArchInterrupt_A +ASpec.ArchInvocation_A +ASpec.ArchIpcCancel_A +ASpec.ArchRetype_A +ASpec.ArchTcb_A +ASpec.ArchVMAttributes_A +ASpec.ArchVSpaceAcc_A +ASpec.ArchVSpace_A +ASpec.Arch_A +ASpec.Arch_Structs_A +ASpec.CSpaceAcc_A +ASpec.CSpace_A +ASpec.CapRights_A +ASpec.Decode_A +ASpec.Deterministic_A +ASpec.ExceptionTypes_A +ASpec.Exceptions_A +ASpec.FPU_A +ASpec.Hypervisor_A +ASpec.Init_A +ASpec.Interrupt_A +ASpec.InvocationLabels_A +ASpec.Invocations_A +ASpec.IpcCancel_A +ASpec.Ipc_A +ASpec.KHeap_A +ASpec.Machine_A +ASpec.MiscMachine_A +ASpec.Retype_A +ASpec.SchedContext_A +ASpec.Schedule_A +ASpec.Sporadic_A +ASpec.Structures_A +ASpec.Syscall_A +ASpec.TcbAcc_A +ASpec.Tcb_A +ASpec.VMRights_A +ExecSpec.ArchInvocationLabels_H +ExecSpec.ArchLabelFuns_H +ExecSpec.Arch_Kernel_Config_Lemmas +ExecSpec.Arch_Structs_B +ExecSpec.Event_H +ExecSpec.InvocationLabels_H +ExecSpec.Kernel_Config +ExecSpec.Kernel_Config_Lemmas +ExecSpec.MachineExports +ExecSpec.MachineMonad +ExecSpec.MachineOps +ExecSpec.MachineTypes +ExecSpec.Platform +ExecSpec.Setup_Locale +ExecSpec.Structs_B +ExecSpec.Time +Lib.Lib +Lib.List_Lib +Lib.Value_Abbreviation +Monads.Nondet_Empty_Fail +Monads.Nondet_Monad +Monads.Nondet_No_Fail +Monads.Reader_Option_Monad +Word_Lib.Aligned +Word_Lib.Enumeration_Word +Word_Lib.Legacy_Aliases +Word_Lib.Machine_Word_64_Basics +Word_Lib.More_Word_Operations +Word_Lib.Reversed_Bit_Lists +Word_Lib.WordSetup +Word_Lib.Word_Lib_Sumo diff --git a/proofs/Fl4SpecEquivX64/tools/test_build.py b/proofs/Fl4SpecEquivX64/tools/test_build.py new file mode 100644 index 000000000..a35e4b540 --- /dev/null +++ b/proofs/Fl4SpecEquivX64/tools/test_build.py @@ -0,0 +1,70 @@ +"""Exercise the X64 audit gate with synthetic Lean diagnostics.""" + +from pathlib import Path +import subprocess +import tempfile +import unittest +from unittest.mock import patch + +import build + + +class ManifestGateTests(unittest.TestCase): + def setUp(self): + self.names = sorted(build.REQUIRED_MANIFEST_THEOREMS) + self.names += [ + f"L4vRefX64.Example.theorem{index}" + for index in range(build.MIN_MANIFEST_AXIOMS - len(self.names)) + ] + + def audit(self, axiom="propext", stderr=""): + source = "\n".join(f"#print axioms {name}" for name in self.names) + output = "\n".join(f"'{name}' depends on axioms: [{axiom}]" for name in self.names) + return build.audit_manifest_output(output, stderr, source) + + def test_standard_axioms(self): + self.assertTrue(self.audit()[0]) + + def test_sorry_ax(self): + passed, message = self.audit(axiom="sorryAx") + self.assertFalse(passed) + self.assertIn("disallowed axioms", message) + + def test_manifest_warning(self): + passed, message = self.audit(stderr="Manifest.lean:1:1: warning: test diagnostic") + self.assertFalse(passed) + self.assertIn("compiler warning", message) + + def test_missing_required_theorem_even_at_manifest_floor(self): + name = "L4vRefX64.Equiv.Syscall.patched_callKernel_equiv" + self.names.remove(name) + self.names.append("L4vRefX64.Example.replacement") + passed, message = self.audit() + self.assertFalse(passed) + self.assertIn("missing required Manifest theorems", message) + self.assertIn(name, message) + + +class ModuleGateTests(unittest.TestCase): + def test_module_warning_removes_output_and_fails_build(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + source = root / "L4vRefX64" / "Sample.lean" + source.parent.mkdir() + source.touch() + build_dir = root / "out" + + def lean(args, **_): + Path(args[args.index("-o") + 1]).touch() + return subprocess.CompletedProcess(args, 0, "", "Sample.lean:1:1: warning: test diagnostic") + + argv = ["build.py", str(root), str(build_dir), "L4vRefX64.Sample"] + with patch.object(build.sys, "argv", argv), patch.object(build.subprocess, "run", lean): + with patch("sys.stderr") as stderr: + self.assertEqual(build.main(), 1) + self.assertIn("warnings disallowed", "".join(call.args[0] for call in stderr.write.call_args_list)) + self.assertFalse((build_dir / "L4vRefX64" / "Sample.olean").exists()) + + +if __name__ == "__main__": + unittest.main()