Library mcertikos.mcslock.MCSLockOpGen
This file provide the contextual refinement proof between MALInit layer and MALOp layer
Require Import Coqlib.
Require Import Errors.
Require Import AST.
Require Import Integers.
Require Import Floats.
Require Import Op.
Require Import Asm.
Require Import Events.
Require Import Globalenvs.
Require Import Smallstep.
Require Import Values.
Require Import Memory.
Require Import Maps.
Require Import CommonTactic.
Require Import AuxLemma.
Require Import FlatMemory.
Require Import AuxStateDataType.
Require Import Constant.
Require Import GlobIdent.
Require Import RealParams.
Require Import LoadStoreSem1.
Require Import AsmImplLemma.
Require Import LAsm.
Require Import RefinementTactic.
Require Import PrimSemantics.
Require Import liblayers.logic.PTreeModules.
Require Import liblayers.logic.LayerLogicImpl.
Require Import liblayers.compcertx.Stencil.
Require Import liblayers.compcertx.MakeProgram.
Require Import liblayers.compat.CompatLayers.
Require Import liblayers.compat.CompatGenSem.
Require Import compcert.cfrontend.Ctypes.
Require Import LayerCalculusLemma.
Require Import AbstractDataType.
Require Import MMCSLockOp.
Require Import MCSLockOpGenSpec.
Require Import DeviceStateDataType.
Require Import Errors.
Require Import AST.
Require Import Integers.
Require Import Floats.
Require Import Op.
Require Import Asm.
Require Import Events.
Require Import Globalenvs.
Require Import Smallstep.
Require Import Values.
Require Import Memory.
Require Import Maps.
Require Import CommonTactic.
Require Import AuxLemma.
Require Import FlatMemory.
Require Import AuxStateDataType.
Require Import Constant.
Require Import GlobIdent.
Require Import RealParams.
Require Import LoadStoreSem1.
Require Import AsmImplLemma.
Require Import LAsm.
Require Import RefinementTactic.
Require Import PrimSemantics.
Require Import liblayers.logic.PTreeModules.
Require Import liblayers.logic.LayerLogicImpl.
Require Import liblayers.compcertx.Stencil.
Require Import liblayers.compcertx.MakeProgram.
Require Import liblayers.compat.CompatLayers.
Require Import liblayers.compat.CompatGenSem.
Require Import compcert.cfrontend.Ctypes.
Require Import LayerCalculusLemma.
Require Import AbstractDataType.
Require Import MMCSLockOp.
Require Import MCSLockOpGenSpec.
Require Import DeviceStateDataType.
Section Refinement.
Local Open Scope string_scope.
Local Open Scope error_monad_scope.
Local Open Scope Z_scope.
Context `{real_params: RealParams}.
Context `{mcs_oracle_prop: MCSOracleProp}.
Notation HDATA := RData.
Notation LDATA := RData.
Notation HDATAOps := (cdata (cdata_ops := mmcslockabsintro_data_ops) HDATA).
Notation LDATAOps := (cdata (cdata_ops := mmcslockabsintro_data_ops) LDATA).
Section WITHMEM.
Context `{Hstencil: Stencil}.
Context `{Hmem: Mem.MemoryModelX}.
Context `{Hmwd: UseMemWithData mem}.
Local Open Scope string_scope.
Local Open Scope error_monad_scope.
Local Open Scope Z_scope.
Context `{real_params: RealParams}.
Context `{mcs_oracle_prop: MCSOracleProp}.
Notation HDATA := RData.
Notation LDATA := RData.
Notation HDATAOps := (cdata (cdata_ops := mmcslockabsintro_data_ops) HDATA).
Notation LDATAOps := (cdata (cdata_ops := mmcslockabsintro_data_ops) LDATA).
Section WITHMEM.
Context `{Hstencil: Stencil}.
Context `{Hmem: Mem.MemoryModelX}.
Context `{Hmwd: UseMemWithData mem}.
Record relate_RData (f:meminj) (hadt: HDATA) (ladt: LDATA) :=
mkrelate_RData {
flatmem_re: FlatMem.flatmem_inj (HP hadt) (HP ladt);
MM_re: MM hadt = MM ladt;
MMSize_re: MMSize hadt = MMSize ladt;
vmxinfo_re: vmxinfo hadt = vmxinfo ladt;
CR3_re: CR3 hadt = CR3 ladt;
ikern_re: ikern hadt = ikern ladt;
pg_re: pg hadt = pg ladt;
ihost_re: ihost hadt = ihost ladt;
ti_fst_re: (fst (ti hadt)) = (fst (ti ladt));
ti_snd_re: val_inject f (snd (ti hadt)) (snd (ti ladt));
init_re: init hadt = init ladt;
buffer_re: buffer hadt = buffer ladt;
CPU_ID_re: CPU_ID hadt = CPU_ID ladt;
cid_re: cid hadt = cid ladt;
multi_oracle_re: multi_oracle hadt = multi_oracle ladt;
multi_log_re: multi_log hadt = multi_log ladt;
com1_re: com1 ladt = com1 hadt;
ioapic_re: ioapic ladt = ioapic hadt;
lapic_re: lapic ladt = lapic hadt;
intr_flag_re: intr_flag ladt = intr_flag hadt;
saved_intr_flags_re: saved_intr_flags ladt = saved_intr_flags hadt;
curr_intr_num_re: curr_intr_num ladt = curr_intr_num hadt;
in_intr_re: in_intr hadt = in_intr ladt;
tf_re: tfs_inj f (tf hadt) (tf ladt)
}.
Inductive match_RData: stencil → HDATA → mem → meminj → Prop :=
| MATCH_RDATA: ∀ habd m f s, match_RData s habd m f.
Local Hint Resolve MATCH_RDATA.
Global Instance rel_ops: CompatRelOps HDATAOps LDATAOps :=
{
relate_AbData s f d1 d2 := relate_RData f d1 d2;
match_AbData s d1 m f := match_RData s d1 m f;
new_glbl := nil
}.
mkrelate_RData {
flatmem_re: FlatMem.flatmem_inj (HP hadt) (HP ladt);
MM_re: MM hadt = MM ladt;
MMSize_re: MMSize hadt = MMSize ladt;
vmxinfo_re: vmxinfo hadt = vmxinfo ladt;
CR3_re: CR3 hadt = CR3 ladt;
ikern_re: ikern hadt = ikern ladt;
pg_re: pg hadt = pg ladt;
ihost_re: ihost hadt = ihost ladt;
ti_fst_re: (fst (ti hadt)) = (fst (ti ladt));
ti_snd_re: val_inject f (snd (ti hadt)) (snd (ti ladt));
init_re: init hadt = init ladt;
buffer_re: buffer hadt = buffer ladt;
CPU_ID_re: CPU_ID hadt = CPU_ID ladt;
cid_re: cid hadt = cid ladt;
multi_oracle_re: multi_oracle hadt = multi_oracle ladt;
multi_log_re: multi_log hadt = multi_log ladt;
com1_re: com1 ladt = com1 hadt;
ioapic_re: ioapic ladt = ioapic hadt;
lapic_re: lapic ladt = lapic hadt;
intr_flag_re: intr_flag ladt = intr_flag hadt;
saved_intr_flags_re: saved_intr_flags ladt = saved_intr_flags hadt;
curr_intr_num_re: curr_intr_num ladt = curr_intr_num hadt;
in_intr_re: in_intr hadt = in_intr ladt;
tf_re: tfs_inj f (tf hadt) (tf ladt)
}.
Inductive match_RData: stencil → HDATA → mem → meminj → Prop :=
| MATCH_RDATA: ∀ habd m f s, match_RData s habd m f.
Local Hint Resolve MATCH_RDATA.
Global Instance rel_ops: CompatRelOps HDATAOps LDATAOps :=
{
relate_AbData s f d1 d2 := relate_RData f d1 d2;
match_AbData s d1 m f := match_RData s d1 m f;
new_glbl := nil
}.
Prove that after taking one step, the refinement relation still holds
Lemma relate_incr:
∀ abd abd´ f f´,
relate_RData f abd abd´
→ inject_incr f f´
→ relate_RData f´ abd abd´.
Proof.
inversion 1; subst; intros; inv H; constructor; eauto.
eapply tfs_inj_incr; eauto.
Qed.
Global Instance rel_prf: CompatRel HDATAOps LDATAOps.
Proof.
constructor; intros; simpl; trivial.
eapply relate_incr; eauto.
Qed.
End Rel_Property.
∀ abd abd´ f f´,
relate_RData f abd abd´
→ inject_incr f f´
→ relate_RData f´ abd abd´.
Proof.
inversion 1; subst; intros; inv H; constructor; eauto.
eapply tfs_inj_incr; eauto.
Qed.
Global Instance rel_prf: CompatRel HDATAOps LDATAOps.
Proof.
constructor; intros; simpl; trivial.
eapply relate_incr; eauto.
Qed.
End Rel_Property.
Section OneStep_Forward_Relation.
Section FRESH_PRIM.
Context `{fairness: WaitTime}.
Lemma mcs_pass_lock_kern_mode:
∀ i ofs d d´,
mcs_pass_lock_spec i ofs d = Some d´
→ kernel_mode d.
Proof.
unfold mcs_pass_lock_spec; simpl; intros.
subdestruct; auto.
Qed.
Lemma mcs_pass_lock_exist:
∀ habd habd´ labd lock_id ofs f,
mcs_pass_lock_spec lock_id ofs habd = Some habd´
→ relate_RData f habd labd
→ ∃ labd´, mcs_pass_lock_spec lock_id ofs labd = Some labd´ ∧ relate_RData f habd´ labd´.
Proof.
unfold mcs_pass_lock_spec; intros until f; exist_simpl.
Qed.
Lemma mcs_pass_lock_spec_ref:
compatsim (crel HDATA LDATA) (gensem mcs_pass_lock_spec) mcs_pass_lock_spec_low.
Proof.
compatsim_simpl (@match_AbData).
exploit mcs_pass_lock_exist; eauto 1.
intros [labd´ [HP HM]].
refine_split; try econstructor; eauto.
- eapply mcs_pass_lock_kern_mode; eauto.
- constructor.
Qed.
Lemma mcs_wait_lock_kern_mode:
∀ bound lock_id ofs d d´,
mcs_wait_lock_spec bound lock_id ofs d = Some d´
→ kernel_mode d.
Proof.
unfold mcs_wait_lock_spec; simpl; intros.
subdestruct; auto.
Qed.
Lemma mcs_wait_lock_exist:
∀ habd habd´ labd bound lock_id ofs f,
mcs_wait_lock_spec bound lock_id ofs habd = Some habd´
→ relate_RData f habd labd
→ ∃ labd´, mcs_wait_lock_spec bound lock_id ofs labd = Some labd´ ∧ relate_RData f habd´ labd´.
Proof.
unfold mcs_wait_lock_spec; intros until f; exist_simpl.
Qed.
Lemma mcs_wait_lock_spec_ref:
compatsim (crel HDATA LDATA) (gensem mcs_wait_lock_spec) mcs_wait_lock_spec_low.
Proof.
compatsim_simpl (@match_AbData).
exploit mcs_wait_lock_exist; eauto.
intros [labd´ [HP HM]].
refine_split; try econstructor; eauto.
- eapply mcs_wait_lock_kern_mode; eauto.
- constructor.
Qed.
Section TICKET_LOCK_INIT_PRIM.
Lemma ticket_lock_init_exist:
∀ habd habd´ labd mbi_adr f,
ticket_lock_init_spec mbi_adr habd = Some habd´
→ relate_RData f habd labd
→ ∃ labd´, ticket_lock_init_spec mbi_adr labd = Some labd´ ∧ relate_RData f habd´ labd´.
Proof.
unfold ticket_lock_init_spec; intros until f; exist_simpl.
Qed.
Lemma ticket_lock_init_match:
∀ s mbi_adr d d´ m f,
ticket_lock_init_spec mbi_adr d = Some d´
→ match_AbData s d m f
→ match_AbData s d´ m f.
Proof.
unfold ticket_lock_init_spec; intros.
subdestruct; inv H.
econstructor.
Qed.
Lemma ticket_lock_init_sim :
∀ id,
sim (crel RData RData) (id ↦ gensem ticket_lock_init_spec)
(id ↦ gensem ticket_lock_init_spec).
Proof.
intros. layer_sim_simpl.
compatsim_simpl (@match_AbData).
intros.
exploit ticket_lock_init_exist; eauto; intros.
destruct H as (labd´ & Ha & Hb).
refine_split´; eauto.
match_external_states_simpl; eauto.
constructor; eauto.
eapply ticket_lock_init_match; eauto.
Qed.
End TICKET_LOCK_INIT_PRIM.
End FRESH_PRIM.
Section PASSTHROUGH_RPIM.
Global Instance: (LoadStoreProp (hflatmem_store:= flatmem_store´) (lflatmem_store:= flatmem_store´)).
Proof.
accessor_prop_tac.
- eapply flatmem_store´_exists; eauto.
Qed.
Lemma passthrough_correct:
sim (crel HDATA LDATA) mmcslockop_passthrough mmcslockabsintro.
Proof.
sim_oplus.
- apply fload´_sim.
- apply fstore´_sim.
- apply page_copy´´´_sim.
- apply page_copy_back´_sim.
- apply vmxinfo_get_sim.
- apply setPG_sim.
- apply setCR3_sim.
- apply get_size_sim.
- apply is_mm_usable_sim.
- apply get_mm_s_sim.
- apply get_mm_l_sim.
- apply get_CPU_ID_sim.
- apply release_shared0_sim.
- apply (acquire_shared0_mcs_sim (valid_id_args:= Shared2ID_valid0)).
intros. inv H.
- apply get_curid_sim.
- apply set_curid_sim.
- apply set_curid_init_sim.
- apply ticket_lock_init_sim.
- apply trapin_sim.
- apply trapout´_sim.
- apply hostin_sim.
- apply hostout´_sim.
- apply proc_create_postinit_sim.
- apply trap_info_get_sim.
- apply trap_info_ret_sim.
- apply serial_irq_check_sim.
- apply iret_sim.
- apply cli_sim.
- apply sti_sim.
- apply serial_irq_current_sim.
- apply ic_intr_sim.
- apply save_context_sim.
- apply restore_context_sim.
- apply local_irq_save_sim.
- apply local_irq_restore_sim.
- apply serial_in_sim.
- apply serial_out_sim.
- apply serial_hw_intr_sim.
- apply ioapic_read_sim.
- apply ioapic_write_sim.
- apply lapic_read_sim.
- apply lapic_write_sim.
- layer_sim_simpl.
+ eapply load_correct1.
+ eapply store_correct1.
Qed.
End PASSTHROUGH_RPIM.
End OneStep_Forward_Relation.
End WITHMEM.
End Refinement.
Section FRESH_PRIM.
Context `{fairness: WaitTime}.
Lemma mcs_pass_lock_kern_mode:
∀ i ofs d d´,
mcs_pass_lock_spec i ofs d = Some d´
→ kernel_mode d.
Proof.
unfold mcs_pass_lock_spec; simpl; intros.
subdestruct; auto.
Qed.
Lemma mcs_pass_lock_exist:
∀ habd habd´ labd lock_id ofs f,
mcs_pass_lock_spec lock_id ofs habd = Some habd´
→ relate_RData f habd labd
→ ∃ labd´, mcs_pass_lock_spec lock_id ofs labd = Some labd´ ∧ relate_RData f habd´ labd´.
Proof.
unfold mcs_pass_lock_spec; intros until f; exist_simpl.
Qed.
Lemma mcs_pass_lock_spec_ref:
compatsim (crel HDATA LDATA) (gensem mcs_pass_lock_spec) mcs_pass_lock_spec_low.
Proof.
compatsim_simpl (@match_AbData).
exploit mcs_pass_lock_exist; eauto 1.
intros [labd´ [HP HM]].
refine_split; try econstructor; eauto.
- eapply mcs_pass_lock_kern_mode; eauto.
- constructor.
Qed.
Lemma mcs_wait_lock_kern_mode:
∀ bound lock_id ofs d d´,
mcs_wait_lock_spec bound lock_id ofs d = Some d´
→ kernel_mode d.
Proof.
unfold mcs_wait_lock_spec; simpl; intros.
subdestruct; auto.
Qed.
Lemma mcs_wait_lock_exist:
∀ habd habd´ labd bound lock_id ofs f,
mcs_wait_lock_spec bound lock_id ofs habd = Some habd´
→ relate_RData f habd labd
→ ∃ labd´, mcs_wait_lock_spec bound lock_id ofs labd = Some labd´ ∧ relate_RData f habd´ labd´.
Proof.
unfold mcs_wait_lock_spec; intros until f; exist_simpl.
Qed.
Lemma mcs_wait_lock_spec_ref:
compatsim (crel HDATA LDATA) (gensem mcs_wait_lock_spec) mcs_wait_lock_spec_low.
Proof.
compatsim_simpl (@match_AbData).
exploit mcs_wait_lock_exist; eauto.
intros [labd´ [HP HM]].
refine_split; try econstructor; eauto.
- eapply mcs_wait_lock_kern_mode; eauto.
- constructor.
Qed.
Section TICKET_LOCK_INIT_PRIM.
Lemma ticket_lock_init_exist:
∀ habd habd´ labd mbi_adr f,
ticket_lock_init_spec mbi_adr habd = Some habd´
→ relate_RData f habd labd
→ ∃ labd´, ticket_lock_init_spec mbi_adr labd = Some labd´ ∧ relate_RData f habd´ labd´.
Proof.
unfold ticket_lock_init_spec; intros until f; exist_simpl.
Qed.
Lemma ticket_lock_init_match:
∀ s mbi_adr d d´ m f,
ticket_lock_init_spec mbi_adr d = Some d´
→ match_AbData s d m f
→ match_AbData s d´ m f.
Proof.
unfold ticket_lock_init_spec; intros.
subdestruct; inv H.
econstructor.
Qed.
Lemma ticket_lock_init_sim :
∀ id,
sim (crel RData RData) (id ↦ gensem ticket_lock_init_spec)
(id ↦ gensem ticket_lock_init_spec).
Proof.
intros. layer_sim_simpl.
compatsim_simpl (@match_AbData).
intros.
exploit ticket_lock_init_exist; eauto; intros.
destruct H as (labd´ & Ha & Hb).
refine_split´; eauto.
match_external_states_simpl; eauto.
constructor; eauto.
eapply ticket_lock_init_match; eauto.
Qed.
End TICKET_LOCK_INIT_PRIM.
End FRESH_PRIM.
Section PASSTHROUGH_RPIM.
Global Instance: (LoadStoreProp (hflatmem_store:= flatmem_store´) (lflatmem_store:= flatmem_store´)).
Proof.
accessor_prop_tac.
- eapply flatmem_store´_exists; eauto.
Qed.
Lemma passthrough_correct:
sim (crel HDATA LDATA) mmcslockop_passthrough mmcslockabsintro.
Proof.
sim_oplus.
- apply fload´_sim.
- apply fstore´_sim.
- apply page_copy´´´_sim.
- apply page_copy_back´_sim.
- apply vmxinfo_get_sim.
- apply setPG_sim.
- apply setCR3_sim.
- apply get_size_sim.
- apply is_mm_usable_sim.
- apply get_mm_s_sim.
- apply get_mm_l_sim.
- apply get_CPU_ID_sim.
- apply release_shared0_sim.
- apply (acquire_shared0_mcs_sim (valid_id_args:= Shared2ID_valid0)).
intros. inv H.
- apply get_curid_sim.
- apply set_curid_sim.
- apply set_curid_init_sim.
- apply ticket_lock_init_sim.
- apply trapin_sim.
- apply trapout´_sim.
- apply hostin_sim.
- apply hostout´_sim.
- apply proc_create_postinit_sim.
- apply trap_info_get_sim.
- apply trap_info_ret_sim.
- apply serial_irq_check_sim.
- apply iret_sim.
- apply cli_sim.
- apply sti_sim.
- apply serial_irq_current_sim.
- apply ic_intr_sim.
- apply save_context_sim.
- apply restore_context_sim.
- apply local_irq_save_sim.
- apply local_irq_restore_sim.
- apply serial_in_sim.
- apply serial_out_sim.
- apply serial_hw_intr_sim.
- apply ioapic_read_sim.
- apply ioapic_write_sim.
- apply lapic_read_sim.
- apply lapic_write_sim.
- layer_sim_simpl.
+ eapply load_correct1.
+ eapply store_correct1.
Qed.
End PASSTHROUGH_RPIM.
End OneStep_Forward_Relation.
End WITHMEM.
End Refinement.