Library mcertikos.multithread.phbthread.INVLemmaSingleInterrupt


Require Import Coqlib.
Require Import Maps.
Require Import Constant.
Require Import GlobIdent.
Require Import FlatMemory.
Require Import CommonTactic.
Require Import FutureTactic.
Require Import AuxLemma.
Require Import DeviceStateDataType.

Require Import Values.
Require Import AsmX.
Require Import Integers.
Require Import liblayers.compat.CompatLayers.
Require Import AST.
Require Import AuxStateDataType.
Require Import ObjInterruptManagement.
Require Import Omega.
Require Import XOmega.
Require Import DeviceStateDataType.
Require Import GlobalOracleProp.
Require Import INVLemmaMemory.
Require Import RealParams.

Require Import AuxSingleAbstractDataType.
Require Import ObjPHBThreadDEV.
Require Import SingleConfiguration.

Section INTERRUPT_INV.

  Section INTR_DISABLE.
    Context `{real_params_ops: RealParamsOps}.
    Context `{multi_oracle_prop: MultiOracleProp}.
    Context `{threads_conf_ops: ThreadsConfigurationOps}.

    Lemma single_serial_intr_disable_aux_preserves_all:
       n masked d ,
        single_serial_intr_disable n masked d = ret
        CPU_ID (fst d) = CPU_ID (fst )
        cid (fst d) = cid (fst )
        ti (snd d) = ti (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        AC (snd d) = AC (snd )
        init (fst d) = init (fst )
        ikern (snd d) = ikern (snd )
        ihost (snd d) = ihost (snd )
        pg (fst d) = pg (fst )
        MM (fst d) = MM (fst )
        MMSize (fst d) = MMSize (fst )
        CR3 (fst d) = CR3 (fst )
        nps (fst d) = nps (fst )
        pperm (snd d) = pperm (snd )
        ipt (snd d) = ipt (snd )
        PT (snd d) = PT (snd )
        ptpool (snd d) = ptpool (snd )
        HP (snd d) = HP (snd )
        cid (fst d) = cid (fst )
        syncchpool (snd d) = syncchpool (snd )
        uctxt (snd d) = uctxt (snd )
        ept (snd d) = ept (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        tf (snd d) = tf (snd )
        big_oracle (fst d) = big_oracle (fst )
        big_log (fst d) = big_log (fst )
        lock (fst d) = lock (fst )
        vmxinfo (fst d) = vmxinfo (fst ).
    Proof.
      intros until n.
      induction n.
      {
        simpl.
        intros.
        inv H.
        repeat (split; [reflexivity|]); try reflexivity.
      }
      {
        simpl.
        intros.
        subdestruct.
        {
          eapply IHn in H.
          simpl in H.
          apply H.
        }
        {
          eapply IHn in H.
          functional inversion Hdestruct1; subst;
          simpl in *; eauto.
        }
        {
          inv H.
          repeat (split; [reflexivity|]); try reflexivity.
        }
      }
    Qed.

    Lemma single_serial_intr_disable_preserves_all:
       d ,
        single_serial_intr_disable_spec d = ret
        CPU_ID (fst d) = CPU_ID (fst )
        cid (fst d) = cid (fst )
        ti (snd d) = ti (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        AC (snd d) = AC (snd )
        init (fst d) = init (fst )
        ikern (snd d) = ikern (snd )
        ihost (snd d) = ihost (snd )
        pg (fst d) = pg (fst )
        MM (fst d) = MM (fst )
        MMSize (fst d) = MMSize (fst )
        CR3 (fst d) = CR3 (fst )
        nps (fst d) = nps (fst )
        pperm (snd d) = pperm (snd )
        ipt (snd d) = ipt (snd )
        PT (snd d) = PT (snd )
        ptpool (snd d) = ptpool (snd )
        HP (snd d) = HP (snd )
        cid (fst d) = cid (fst )
        syncchpool (snd d) = syncchpool (snd )
        uctxt (snd d) = uctxt (snd )
        ept (snd d) = ept (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        tf (snd d) = tf (snd )
        big_oracle (fst d) = big_oracle (fst )
        big_log (fst d) = big_log (fst )
        lock (fst d) = lock (fst )
        vmxinfo (fst d) = vmxinfo (fst ).
    Proof.
      intros.
      Opaque single_serial_intr_disable.
      functional inversion H; simpl;
      destruct d´0; destruct ;
      destruct d; simpl in *; inv H0;
      apply (single_serial_intr_disable_aux_preserves_all
               INTR_DISABLE_REC_MAX masked (d, d2 {pv_in_intr : true}) (s, d1));
      assumption.
      Transparent single_serial_intr_disable.
    Qed.

    Require Import FutureTactic.
    Lemma single_serial_intr_disable_cr2_injection:
       d m,
        single_serial_intr_disable_spec d = ret
        val_inject (Mem.flat_inj m) (snd (ti (snd d))) (snd (ti (snd d))) →
        val_inject (Mem.flat_inj m) (snd (ti (snd ))) (snd (ti (snd ))).
    Proof.
      intros. generalize (single_serial_intr_disable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H4.
      assumption.
    Qed.

    Lemma single_serial_intr_disable_cr2_type:
       d ,
        single_serial_intr_disable_spec d = ret
        Val.has_type (snd (ti (snd d))) Tint
        Val.has_type (snd (ti (snd ))) Tint.
    Proof.
      intros. generalize (single_serial_intr_disable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H4.
      assumption.
    Qed.

    Lemma single_serial_intr_disable_preserves_tf:
       d ,
        single_serial_intr_disable_spec d = Some
        tf (snd d) = tf (snd ).
    Proof.
      intros.
      generalize (single_serial_intr_disable_preserves_all d H); intro.
      destruct H0 as [? Htmp].
      repeat (destruct Htmp as [? Htmp]; try assumption).
    Qed.

    Lemma single_serial_intr_disable_uctxt_INJECT:
       d m,
        single_serial_intr_disable_spec d = ret
        priv_uctxt_inject_neutral (uctxt (snd d)) m
        priv_uctxt_inject_neutral (uctxt (snd )) m.
    Proof.
      intros. generalize (single_serial_intr_disable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H23.
      assumption.
    Qed.

    Lemma single_serial_intr_disable_VMCS_inject_neutral:
       d m,
        single_serial_intr_disable_spec d = ret
        VMCS_inject_neutral (vmcs (snd d)) m
        VMCS_inject_neutral (vmcs (snd )) m.
    Proof.
      intros. generalize (single_serial_intr_disable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H25.
      assumption.
    Qed.

    Lemma single_serial_intr_disable_VMX_inject_neutral:
       d m,
        single_serial_intr_disable_spec d = ret
        VMX_inject_neutral (vmx (snd d)) m
        VMX_inject_neutral (vmx (snd )) m.
    Proof.
      intros. generalize (single_serial_intr_disable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H26.
      assumption.
    Qed.

  End INTR_DISABLE.

  Section INTR_ENABLE.

    Context `{multi_oracle_prop: MultiOracleProp}.
    Context `{big_oracle_ops: BigOracleOps}.
    Context `{real_params_ops: RealParamsOps}.
    Context `{threads_conf_ops: ThreadsConfigurationOps}.

    Lemma single_serial_intr_enable_aux_preserves_all:
       n d ,
        single_serial_intr_enable n d = ret
        CPU_ID (fst d) = CPU_ID (fst )
        cid (fst d) = cid (fst )
        ti (snd d) = ti (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        AC (snd d) = AC (snd )
        init (fst d) = init (fst )
        ikern (snd d) = ikern (snd )
        ihost (snd d) = ihost (snd )
        pg (fst d) = pg (fst )
        MM (fst d) = MM (fst )
        MMSize (fst d) = MMSize (fst )
        CR3 (fst d) = CR3 (fst )
        nps (fst d) = nps (fst )
        pperm (snd d) = pperm (snd )
        ipt (snd d) = ipt (snd )
        PT (snd d) = PT (snd )
        ptpool (snd d) = ptpool (snd )
        HP (snd d) = HP (snd )
        cid (fst d) = cid (fst )
        syncchpool (snd d) = syncchpool (snd )
        uctxt (snd d) = uctxt (snd )
        ept (snd d) = ept (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        tf (snd d) = tf (snd )
        big_oracle (fst d) = big_oracle (fst )
        big_log (fst d) = big_log (fst )
        lock (fst d) = lock (fst )
        vmxinfo (fst d) = vmxinfo (fst ).
    Proof.
      intros until n.
      induction n.
      {
        simpl.
        intros.
        inv H.
        repeat (split; [reflexivity|]); try reflexivity.
      }
      {
        simpl.
        intros.
        subdestruct.
        {
          eapply IHn in H.
          functional inversion Hdestruct0; subst;
          simpl in *; eauto.
        }
        {
          inv H.
          repeat (split; [reflexivity|]); try reflexivity.
        }
      }
    Qed.

    Lemma single_serial_intr_enable_preserves_all:
       d ,
        single_serial_intr_enable_spec d = ret
        CPU_ID (fst d) = CPU_ID (fst )
        cid (fst d) = cid (fst )
        ti (snd d) = ti (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        AC (snd d) = AC (snd )
        init (fst d) = init (fst )
        ikern (snd d) = ikern (snd )
        ihost (snd d) = ihost (snd )
        pg (fst d) = pg (fst )
        MM (fst d) = MM (fst )
        MMSize (fst d) = MMSize (fst )
        CR3 (fst d) = CR3 (fst )
        nps (fst d) = nps (fst )
        pperm (snd d) = pperm (snd )
        ipt (snd d) = ipt (snd )
        PT (snd d) = PT (snd )
        ptpool (snd d) = ptpool (snd )
        HP (snd d) = HP (snd )
        cid (fst d) = cid (fst )
        syncchpool (snd d) = syncchpool (snd )
        uctxt (snd d) = uctxt (snd )
        ept (snd d) = ept (snd )
        vmcs (snd d) = vmcs (snd )
        vmx (snd d) = vmx (snd )
        tf (snd d) = tf (snd )
        big_oracle (fst d) = big_oracle (fst )
        big_log (fst d) = big_log (fst )
        lock (fst d) = lock (fst )
        vmxinfo (fst d) = vmxinfo (fst ).
    Proof.
      intros.
      Opaque single_serial_intr_enable.
      functional inversion H; simpl.
      destruct d; destruct abd´;
      destruct ; simpl in *; inv H0;
      apply (single_serial_intr_enable_aux_preserves_all INTR_ENABLE_REC_MAX (d, d0 { pv_in_intr : true}) (s, d2)); assumption.
      Transparent single_serial_intr_enable.
    Qed.

    Require Import FutureTactic.
    Lemma single_serial_intr_enable_cr2_injection:
       d m,
        single_serial_intr_enable_spec d = ret
        val_inject (Mem.flat_inj m) (snd (ti (snd d))) (snd (ti (snd d))) →
        val_inject (Mem.flat_inj m) (snd (ti (snd ))) (snd (ti (snd ))).
    Proof.
      intros. generalize (single_serial_intr_enable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H4.
      assumption.
    Qed.

    Lemma single_serial_intr_enable_cr2_type:
       d ,
        single_serial_intr_enable_spec d = ret
        Val.has_type (snd (ti (snd d))) Tint
        Val.has_type (snd (ti (snd ))) Tint.
    Proof.
      intros. generalize (single_serial_intr_enable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H4.
      assumption.
    Qed.

    Lemma single_serial_intr_enable_preserves_tf:
       d ,
        single_serial_intr_enable_spec d = Some
        tf (snd d) = tf (snd ).
    Proof.
      intros.
      generalize (single_serial_intr_enable_preserves_all d H); intro.
      destruct H0 as [? Htmp].
      repeat (destruct Htmp as [? Htmp]; try assumption).
    Qed.

    Lemma single_serial_intr_enable_uctxt_INJECT:
       d m,
        single_serial_intr_enable_spec d = ret
        priv_uctxt_inject_neutral (uctxt (snd d)) m
        priv_uctxt_inject_neutral (uctxt (snd )) m.
    Proof.
      intros. generalize (single_serial_intr_enable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H23.
      assumption.
    Qed.

    Lemma single_serial_intr_enable_VMCS_inject_neutral:
       d m,
        single_serial_intr_enable_spec d = ret
        VMCS_inject_neutral (vmcs (snd d)) m
        VMCS_inject_neutral (vmcs (snd )) m.
    Proof.
      intros. generalize (single_serial_intr_enable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H25.
      assumption.
    Qed.

    Lemma single_serial_intr_enable_VMX_inject_neutral:
       d m,
        single_serial_intr_enable_spec d = ret
        VMX_inject_neutral (vmx (snd d)) m
        VMX_inject_neutral (vmx (snd )) m.
    Proof.
      intros. generalize (single_serial_intr_enable_preserves_all d H).
      intros Hpre. blast Hpre.
      destruct d; destruct ; simpl in ×.
      rewrite <- H26.
      assumption.
    Qed.

  End INTR_ENABLE.

End INTERRUPT_INV.

Ltac rest :=
  match goal with
    | Hs: single_serial_intr_disable_spec _ = _ |- _
      pose proof (single_serial_intr_disable_preserves_all _ _ Hs) as Hs´;
        blast Hs´; eauto
    | Hs: single_serial_intr_enable_spec _ = _ |- _
      pose proof (single_serial_intr_enable_preserves_all _ _ Hs) as Hs´;
        blast Hs´; eauto
  end.

Create HintDb single_serial_intr_disable_invariantdb discriminated.

Hint Resolve single_serial_intr_disable_cr2_injection: serial_intr_disable_invariantdb.
Hint Resolve single_serial_intr_disable_cr2_type: serial_intr_disable_invariantdb.
Hint Resolve single_serial_intr_disable_uctxt_INJECT: serial_intr_disable_invariantdb.
Hint Resolve single_serial_intr_disable_VMCS_inject_neutral: serial_intr_disable_invariantdb.
Hint Resolve single_serial_intr_disable_VMX_inject_neutral: serial_intr_disable_invariantdb.
Hint Resolve single_serial_intr_disable_preserves_tf: serial_intr_disable_invariantdb.

Create HintDb sinble_serial_intr_enable_invariantdb discriminated.

Hint Resolve single_serial_intr_enable_cr2_injection: serial_intr_enable_invariantdb.
Hint Resolve single_serial_intr_enable_cr2_type: serial_intr_enable_invariantdb.
Hint Resolve single_serial_intr_enable_uctxt_INJECT: serial_intr_enable_invariantdb.
Hint Resolve single_serial_intr_enable_VMCS_inject_neutral: serial_intr_enable_invariantdb.
Hint Resolve single_serial_intr_enable_VMX_inject_neutral: serial_intr_enable_invariantdb.
Hint Resolve single_serial_intr_enable_preserves_tf: serial_intr_enable_invariantdb.