Library mcertikos.mcslock.MCSLockAbsIntroGenSpec

This file provide the contextual refinement proof between MBoot layer and MALInit 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 AuxLemma.
Require Import FlatMemory.
Require Import AuxStateDataType.
Require Import Constant.
Require Import GlobIdent.
Require Import RealParams.
Require Import AsmImplLemma.
Require Import GenSem.
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.

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

Require Import AbstractDataType.
Require Import MMCSLockIntro.

Require Import ObjMultiprocessor.

Definition of the refinement relation

Section MCSLOCKABSINTRO_DEFINE.

  Context `{real_params: RealParams}.
  Context `{mcs_oracle_prop: MCSOracleProp}.

  Notation LDATAOps := (cdata RData).

  Inductive mcs_lock_init_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | ticket_lock_init_spec_low_intro s (WB: _Prop) m´0 labd labd´ mbi_adr:
      
      ticket_lock_init_spec (Int.unsigned mbi_adr) labd = Some labd´
      kernel_mode labd
      high_level_invariant labd
      mcs_lock_init_spec_low_step s WB (Vint mbi_adr :: nil) (m´0, labd) Vundef (m´0, labd´).

  Inductive mcs_get_next_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | mcs_get_next_spec_low_intro s (WB: _Prop) m´0 labd labd´ lock_index cpuid next:
      mcs_get_next_spec (Int.unsigned lock_index) (Int.unsigned cpuid) labd = Some (labd´, (Int.unsigned next))
      kernel_mode labd
      high_level_invariant labd
      mcs_get_next_spec_low_step s WB (Vint lock_index :: Vint cpuid:: nil) (m´0, labd) (Vint next) (m´0, labd´).

  Inductive mcs_set_next_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | mcs_set_next_spec_low_intro s (WB: _Prop) m´0 labd labd´ lock_index cpuid prev_id:
      mcs_set_next_spec (Int.unsigned lock_index) (Int.unsigned cpuid) (Int.unsigned prev_id) labd
      = Some labd´
      kernel_mode labd
      high_level_invariant labd
      mcs_set_next_spec_low_step s WB (Vint lock_index :: Vint cpuid:: Vint prev_id :: nil) (m´0, labd) Vundef (m´0, labd´).

  Inductive mcs_get_busy_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | mcs_get_busy_spec_low_intro s (WB: _Prop) m´0 labd labd´ lock_index cpuid busy:
      mcs_get_busy_spec (Int.unsigned lock_index) (Int.unsigned cpuid) labd = Some (labd´, (Int.unsigned busy))
      kernel_mode labd
      high_level_invariant labd
      mcs_get_busy_spec_low_step s WB (Vint lock_index :: Vint cpuid:: nil) (m´0, labd) (Vint busy) (m´0, labd´).

  Inductive mcs_set_busy_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | mcs_set_busy_spec_low_intro s (WB: _Prop) m´0 labd labd´ lock_index cpuid:
      mcs_set_busy_spec (Int.unsigned lock_index) (Int.unsigned cpuid) labd = Some labd´
      kernel_mode labd
      high_level_invariant labd
      mcs_set_busy_spec_low_step s WB (Vint lock_index :: Vint cpuid:: nil) (m´0, labd) Vundef (m´0, labd´).

  Inductive mcs_swap_tail_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | mcs_swap_tail_spec_low_intro s (WB: _Prop) m´0 labd labd´ bound lock_index cpuid old_tail:
      mcs_swap_tail_spec (Int.unsigned bound) (Int.unsigned lock_index) (Int.unsigned cpuid) labd
      = Some (labd´, (Int.unsigned old_tail))
      kernel_mode labd
      high_level_invariant labd
      mcs_swap_tail_spec_low_step s WB (Vint bound :: Vint lock_index :: Vint cpuid:: nil) (m´0, labd)
                                  (Vint old_tail) (m´0, labd´).

  Inductive mcs_cas_tail_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | mcs_cas_tail_spec_low_intro s (WB: _Prop) m´0 labd labd´ lock_index cpuid cas_success:
      mcs_cas_tail_spec (Int.unsigned lock_index) (Int.unsigned cpuid) labd = Some (labd´, (Int.unsigned cas_success))
      kernel_mode labd
      high_level_invariant labd
      mcs_cas_tail_spec_low_step s WB (Vint lock_index :: Vint cpuid:: nil) (m´0, labd) (Vint cas_success) (m´0, labd´).

  Inductive mcs_lock_get_index_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sextcall_sem (mem := mwd LDATAOps):=
  | mcs_lock_get_index_spec_low_intro s (WB: _Prop) m´0 labd labd´ lock_id offset lock_index:
      mcs_lock_get_index_spec (Int.unsigned lock_id) (Int.unsigned offset) labd = Some (labd´, Int.unsigned lock_index)
      kernel_mode labd
      high_level_invariant labd
      mcs_lock_get_index_spec_low_step s WB (Vint lock_id :: Vint offset:: nil) (m´0, labd) (Vint lock_index) (m´0, labd´).


  Section WITHMEM.

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

    Definition mcs_lock_init_spec_low: compatsem LDATAOps :=
      csem mcs_lock_init_spec_low_step (type_of_list_type (Tint32::nil)) Tvoid.

    Definition mcs_get_next_spec_low: compatsem LDATAOps :=
      csem mcs_get_next_spec_low_step (type_of_list_type (Tint32::Tint32::nil)) Tint32.

    Definition mcs_set_next_spec_low: compatsem LDATAOps :=
      csem mcs_set_next_spec_low_step (type_of_list_type (Tint32::Tint32::Tint32::nil)) Tvoid.

    Definition mcs_get_busy_spec_low: compatsem LDATAOps :=
      csem mcs_get_busy_spec_low_step (type_of_list_type (Tint32::Tint32::nil)) Tint32.

    Definition mcs_set_busy_spec_low: compatsem LDATAOps :=
      csem mcs_set_busy_spec_low_step (type_of_list_type (Tint32::Tint32::nil)) Tvoid.

    Definition mcs_swap_tail_spec_low: compatsem LDATAOps :=
      csem mcs_swap_tail_spec_low_step (type_of_list_type (Tint32::Tint32::Tint32::nil)) Tint32.

    Definition mcs_cas_tail_spec_low: compatsem LDATAOps :=
      csem mcs_cas_tail_spec_low_step (type_of_list_type (Tint32::Tint32::nil)) Tint32.

    Definition mcs_lock_get_index_spec_low: compatsem LDATAOps :=
      csem mcs_lock_get_index_spec_low_step (type_of_list_type (Tint32::Tint32::nil)) Tint32.

  End WITHMEM.

End MCSLOCKABSINTRO_DEFINE.