Library mcertikos.multithread.highrefins.PHThread2TGenDef


Require Import Coqlib.
Require Import Maps.
Require Import ASTExtra.
Require Import Integers.
Require Import Floats.
Require Import Values.
Require Import Memory.
Require Import Events.
Require Import Stacklayout.
Require Import Globalenvs.
Require Import AsmX.
Require Import Smallstep.
Require Import AuxStateDataType.
Require Import Constant.
Require Import GlobIdent.
Require Import FlatMemory.
Require Import CommonTactic.
Require Import AuxLemma.
Require Import RealParams.
Require Import PrimSemantics.
Require Import LAsm.
Require Import LoadStoreSem3high.
Require Import XOmega.

Require Import liblayers.logic.PTreeModules.
Require Import liblayers.logic.LayerLogicImpl.
Require Import liblayers.compat.CompatLayers.
Require Import liblayers.compat.CompatGenSem.
Require Import I64Layer.

Require Import AlgebraicMem.

Require Import Decision.
Require Import FutureTactic.

Require Import GlobalOracleProp.
Require Import AbstractDataType.
Require Import DeviceStateDataType.
Require Import SingleConfiguration.
Require Import ObjPHBFlatMem.
Require Import PHBThread.
Require Import AsmPHThread2T.

Require Import AuxSingleAbstractDataType.
Require Import SingleOracleImpl.
Require Import PHThread2TComposeData.
Require Import LoadStoreSemPHB.
Require Import ObjPHBThreadDEV.
Require Import ObjPHBThreadINTELVIRT.
Require Import ObjPHBThreadIPC.
Require Import ObjPHBThreadReplayFunction.
Require Import ObjPHBThreadSCHED.
Require Import ObjPHBThreadVMM.
Require Import ObjInterruptManagement.
Require Import ObjConsole.
Require Import ObjInterruptController.
Require Import ObjSerialDevice.
Require Import OracleInstances.
Require Import ObjVMMFun.
Require Import ObjVMMGetSet.
Require Import ObjVMMDef.
Require Import ObjCV.
Require Import ObjCPU.
Require Import ObjVMCS.
Require Import ObjVMX.
Require Import ObjEPT.
Require Import ObjBigThread.
Require Import BigLogThreadConfigFunction.

Require Import StencilImpl.

Section PHThread2TGenDEFINITION.

  Context `{real_params : RealParams}.
  Context `{multi_oracle_prop: MultiOracleProp}.

  Context `{Hmem: Mem.MemoryModelX}.
  Context `{Hmwd: UseMemWithData mem}.

  Context `{s_oracle_ops : SingleOracleOps}.
  Context `{s_threads_ops: ThreadsConfigurationOps}.

  Local Instance s_oracle_prf : SingleOracle := s_oracle_prf.

  Context `{s_threads_prf: !ThreadsConfiguration (s_oracle := s_oracle_prf)}.
  Context `{s_oracle_basic_prop_prf: !SingleOracleBasicProp (single_oracle_prf := s_oracle_prf)
                                      (s_threads_ops := s_threads_ops)}.

  Local Instance s_oracle_prop_prf : SingleOracleProp := SingleOracleImpl.s_oracle_prop_prf.

  Context `{Hstencil : Stencil (stencil := stencil)}.

  Local Instance s_config : SingleConfiguration mem := SingleOracleImpl.s_config.

  Context `{s_oracle_basic_link_prop_prf: !SingleOracleBasicLinkProp (single_oracle_prf := s_oracle_prf)
                                           (s_threads_ops := s_threads_ops)}.

  Local Instance s_oracle_link_prop_prf : SingleOracleLinkProp := SingleOracleImpl.s_oracle_link_prop_prf.

  Local Instance s_link_config : SingleLinkConfiguration mem := s_link_config.

  Context `{acc_def: !AccessorsDefined (mem := mem) (stencil := stencil) (stencil_ops := stencil_ops)
                      (memory_model_ops := memory_model_ops)
                      (phbthread (s_config := s_config) L64)}.

  Definition CHECKUNCHAGNED (a : AbstractDataType.RData) : Prop :=
    AbstractDataType.CPU_ID a = AbstractDataType.CPU_ID
    AbstractDataType.MM a = AbstractDataType.MM
    AbstractDataType.MMSize a = AbstractDataType.MMSize
    AbstractDataType.vmxinfo a = AbstractDataType.vmxinfo
    AbstractDataType.CR3 a = AbstractDataType.CR3
    AbstractDataType.ti a = AbstractDataType.ti
    AbstractDataType.pg a = AbstractDataType.pg
    AbstractDataType.ikern a = AbstractDataType.ikern
    AbstractDataType.ihost a = AbstractDataType.ihost

    AbstractDataType.HP a = AbstractDataType.HP
    AbstractDataType.cid a = AbstractDataType.cid
    AbstractDataType.multi_log a = AbstractDataType.multi_log
    AbstractDataType.multi_oracle a = AbstractDataType.multi_oracle
    AbstractDataType.AC a = AbstractDataType.AC
    AbstractDataType.AT a = AbstractDataType.AT
    AbstractDataType.ATC a = AbstractDataType.ATC
    AbstractDataType.nps a = AbstractDataType.nps
    AbstractDataType.init a = AbstractDataType.init
    AbstractDataType.pperm a = AbstractDataType.pperm
    AbstractDataType.PT a = AbstractDataType.PT
    AbstractDataType.ptpool a = AbstractDataType.ptpool
    AbstractDataType.idpde a = AbstractDataType.idpde
    AbstractDataType.ipt a = AbstractDataType.ipt
    AbstractDataType.LAT a = AbstractDataType.LAT
    AbstractDataType.smspool a = AbstractDataType.smspool
    AbstractDataType.kctxt a = AbstractDataType.kctxt
    AbstractDataType.sleeper a = AbstractDataType.sleeper
    AbstractDataType.tcb a = AbstractDataType.tcb
    AbstractDataType.tdq a = AbstractDataType.tdq
    AbstractDataType.abtcb a = AbstractDataType.abtcb
    AbstractDataType.abq a = AbstractDataType.abq
    AbstractDataType.syncchpool a = AbstractDataType.syncchpool
    AbstractDataType.buffer a = AbstractDataType.buffer
    AbstractDataType.big_oracle a = AbstractDataType.big_oracle
    AbstractDataType.uctxt a = AbstractDataType.uctxt
    AbstractDataType.ept a = AbstractDataType.ept
    AbstractDataType.vmcs a = AbstractDataType.vmcs
    AbstractDataType.vmx a = AbstractDataType.vmx
    AbstractDataType.ts a = AbstractDataType.ts
    AbstractDataType.com1 a = AbstractDataType.com1
    AbstractDataType.drv_serial a = AbstractDataType.drv_serial
    AbstractDataType.console_concrete a = AbstractDataType.console_concrete
    AbstractDataType.console a = AbstractDataType.console
    AbstractDataType.ioapic a = AbstractDataType.ioapic
    AbstractDataType.lapic a = AbstractDataType.lapic
    AbstractDataType.tf a = AbstractDataType.tf
    AbstractDataType.tf_reg a = AbstractDataType.tf_reg
    AbstractDataType.curr_intr_num a = AbstractDataType.curr_intr_num
    AbstractDataType.intr_flag a = AbstractDataType.intr_flag
    AbstractDataType.saved_intr_flags a = AbstractDataType.saved_intr_flags
    AbstractDataType.in_intr a = AbstractDataType.in_intr
    AbstractDataType.i_dev_serial a = AbstractDataType.i_dev_serial
    AbstractDataType.kbd a = AbstractDataType.kbd
    AbstractDataType.kbd_drv a = AbstractDataType.kbd_drv .

  Lemma big2_thread_yield_satisfies_CHECKUNCHAGNED:
     a , big2_thread_yield_spec a = Some CHECKUNCHAGNED a .
  Proof.
    unfold CHECKUNCHAGNED.
    intros.
    functional inversion H; subst.
    - simpl; refine_split; try reflexivity.
    - simpl; refine_split; try reflexivity.
  Qed.

  Lemma big2_sleep_yield_satisfies_CHECKUNCHAGNED:
     i a , big2_thread_sleep_spec i a = Some CHECKUNCHAGNED a .
  Proof.
    unfold CHECKUNCHAGNED.
    intros.
    functional inversion H; subst.
    - simpl; refine_split; try reflexivity.
    - simpl; refine_split; try reflexivity.
  Qed.


  Class PHThraed2TGenProp (s_oracle_prf : SingleOracle) :=
    {
      
      
      abs_rel_t_get_env_log_exist_prop :
         (l : Log) (e : LogEvent),
          lastEvType l Some LogYieldTy
          getLogEventType e = LogYieldTy
          match last_op (e :: l) with
          | Some (LEvent curid´ _) ⇒ proc_id (uRData l) = curid´
          | NoneFalse
          end l´´ : Log,
              TAsm.get_env_log limit (proc_id (uRData l)) (e :: l) = Some l´´ lastEvType l´´ = Some LogYieldTy;
      
      
      abs_rel_t_thread_yield_match_state_prop:
         l kctxt ae ev nb a l´´,
          lastEvType l Some LogYieldTy
          relate_RData kctxt a l ae
          TAsm.get_env_log limit (proc_id (uRData l)) (LEvent (proc_id (uRData l)) (LogYield (Mem.nextblock )) :: l) = Some l´´
          last_op l´´ = Some ev
          getLogEventNB ev = Some nb
          big2_thread_yield_spec a = Some
          CHECKUNCHAGNED a
          nb = (Mem.nextblock ) relate_RData kctxt (LEvent current_curid LogYieldBack :: l´´) ae;

      
      abs_rel_t_thread_sleep_match_state_prop:
         l kctxt ae ev cv nb a l´´,
          lastEvType l Some LogYieldTy
          relate_RData kctxt a l ae
          TAsm.get_env_log limit (proc_id (uRData l))
                           (LEvent (proc_id (uRData l))
                                   (LogSleep (Int.unsigned cv) (Mem.nextblock )
                                             (sync_chpool_check thread_sleep ((Lint cv)::nil) (uRData l) ae))
                                   :: l) = Some l´´
          last_op l´´ = Some ev
          getLogEventNB ev = Some nb
          big2_thread_sleep_spec (Int.unsigned cv) a = Some
          CHECKUNCHAGNED a
          nb = (Mem.nextblock ) relate_RData kctxt (LEvent current_curid LogYieldBack :: l´´) ae

    }.

  Lemma snap_rev_func_snap_func_eq_pd:
     pd, snap_rev_func (snap_func pd) = pd.
  Proof.
    intros.
    destruct pd; simpl.
    unfold snap_rev_func; simpl.
    unfold snap_func; simpl.
    auto.
  Qed.

  Lemma ptRead_related_t :
     n vadr kctxt l pd a res,
      n = ZMap.get (AbstractDataType.CPU_ID a) (AbstractDataType.cid a) →
      relate_RData kctxt a l pd
      ptRead_spec n vadr a = Some res
       res´,
        single_ptRead_spec n vadr (uRData l, pd) = Some res res = res´.
  Proof.
    intros.
    unfold ptRead_spec in H1.
    unfold getPDE_spec, getPTE_spec in H1.
    unfold single_ptRead_spec in *; simpl in ×.
    unfold single_getPDE_spec, single_getPTE_spec in *; simpl.
    subdestruct; inv H1; inv H0; simpl; rewrite <- ikern_re, <- ihost_re, <- ipt_re, <- init_re, <- cid_re;
    rewrite Hdestruct, Hdestruct0, Hdestruct1, Hdestruct2; rewrite <- ptp_re; rewrite zeq_true, Hdestruct5.
    { rewrite zeq_true; eauto. }
    { rewrite zeq_false; auto; rewrite zlt_lt_true; eauto; rewrite Hdestruct8; auto; eauto. }
    { rewrite zeq_false; auto; rewrite zlt_lt_true; eauto; rewrite Hdestruct8; auto; eauto. }
    { rewrite zeq_true; eauto. }
    { rewrite zeq_true; eauto. }
    { rewrite zeq_true; eauto. }
  Qed.

End PHThread2TGenDEFINITION.