Library mcertikos.objects.cpulocaldef.BThreadGenDef


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 Smallstep.
Require Import Values.
Require Import Memory.
Require Import Maps.
Require Import Constant.
Require Import GlobIdent.
Require Import AbstractDataType.
Require Import GlobalOracle.

Require Import liblayers.compcertx.Stencil.
Require Import liblayers.compat.CompatLayers.
Require Import AuxStateDataType.
Require Import RealParams.
Require Import LogReplay.

Notation of the refinement relation

Section Refinement.

  Local Open Scope string_scope.
  Local Open Scope error_monad_scope.
  Local Open Scope Z_scope.

  Context `{real_params: RealParams}.

  Section WITHMEM.

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

    Function BigE2E (e: BigSharedMemEvent) :=
      match e with
        | BTDSPAWN curid new_id q ofs b_uc uc_ofs´
          Some (TSHARED (OTDSPAWN new_id))
        | BTDYIELD cur_id
          Some (TSHARED (OTDYIELD cur_id))
        | BTDWAKE _ cv_id
          Some (TSHARED (OTDWAKE cv_id))
        | BTDWAKE_DIFF _ cv_id wk_id cpu´
          Some (TSHARED (OTDWAKE_DIFF wk_id cpu´))
        | _None
      end.

    Function BigE2id (e: BigOracleEvent) (id: Z) :=
      match e with
        | TBEVENT cid e0
          if zeq id lock_AT_start then
            match e0 with
              | TBSHARED (BPALLOCE _ b) ⇒
                TEVENT cid (TSHARED (OPALLOCE b)) :: nil
              | _nil
            end
          else
            if zeq id lock_range then
              match e0 with
                | TBSHARED (BTDSLEEP slp_id cv s) ⇒
                  TEVENT cid (TSHARED (OTDSLEEP slp_id cv s)) :: nil
                | TBSHARED e1
                  match BigE2E e1 with
                    | Some e2TEVENT cid e2 :: nil
                    | _nil
                  end
                | _nil
              end
            else
              match e0 with
                | TBLOCK lock_id e1
                  if zeq id lock_id then
                    match e1 with
                      | BWAIT_LOCK _ n
                        TEVENT cid (TSHARED OPULL) :: TEVENT cid (TTICKET (WAIT_LOCK (n))) :: nil
                      | BGET_LOCK _
                        TEVENT cid (TTICKET GET_LOCK) :: nil
                      | BREL_LOCK _ s
                        TEVENT cid (TTICKET REL_LOCK) :: TEVENT cid (TSHARED (OSCE s)) :: nil
                    end
                  else nil
                | TBSHARED (BTDSLEEP slp_id cv s) ⇒
                  let n := slp_q_id cv 0 in
                  let sc_id := n + lock_TCB_range in
                  if zeq id sc_id then
                    TEVENT cid (TTICKET REL_LOCK) ::
                           TEVENT cid (TSHARED (OSCE s)) :: nil
                  else nil
                | TBSHARED (BBUFFERE _ cv b) ⇒
                  let n := slp_q_id cv 0 in
                  let sc_id := n + lock_TCB_range in
                  if zeq id sc_id then
                    TEVENT cid (TSHARED (OBUFFERE b)) :: nil
                  else nil
                | _nil
              end
      end.

    Inductive BigLogMap2id: BigLogZMultiLogProp :=
    | BIGMAP_NIL:
         id,
          BigLogMap2id nil id nil
    | BIGMAP_CONS:
         id e bl l
               (Hbig: BigLogMap2id bl id l)
               (Hrel_e: BigE2id e id = ),
          BigLogMap2id (e::bl) id ( ++ l).

    Fixpoint remove_cache_event (l: MultiLog) (cid: Z) :=
      match l with
        | nilnil
        | TEVENT scid e ::
          if zeq scid cid then l
          else remove_cache_event cid
      end.

    Context `{multi_oracle_ops: MultiOracleOps}.

    Inductive relate_big_small_log: BigLogZMultiLogProp :=
    | RELATE_BIG_SMALL_LOG_DEF:
         bl ml abid bl0
               (Hlogmap: BigLogMap2id bl abid bl0)
               (Heq: ml = remove_cache_event bl0 current_CPU_ID),
          relate_big_small_log bl abid ml.

    Inductive relate_big_small_log_pool: BigLogTypeMultiLogPoolProp :=
    | RELATE_BIG_SMALL_LOG_POOL_UNDEF:
         ml,
          relate_big_small_log_pool BigUndef ml
    | RELATE_BIG_SMALL_LOG_POOL_DEF:
         bl ml
               (Hrel_log: abid
                                 (Habid: abid = ID_AT abid = lock_range
                                         ( ofs, index2Z ID_SC ofs = Some abid)),
                           l, ZMap.get abid ml = MultiDef l
                                     relate_big_small_log bl abid l),
          relate_big_small_log_pool (BigDef bl) ml.

    Inductive relate_big_small_oracle: BigOracleMultiOraclePoolProp :=
    | RELATE_BIG_SMALL_ORACLE:
         bo o
               (Hrel: abid bl l
                             (Habid: abid = ID_AT abid = lock_range
                                     ( ofs, index2Z ID_SC ofs = Some abid))
                             (Hrel_log: relate_big_small_log bl abid l),
                        BigLogMap2id (bo current_CPU_ID bl ++ bl) abid
                                     ((ZMap.get abid o) current_CPU_ID l ++ l)),
          relate_big_small_oracle bo o.

  End WITHMEM.

End Refinement.