Library mcertikos.flatmem.GuestAccessIntel1
This file defines the load and store semantics for primitives at all layers
Require Import Coqlib.
Require Import Maps.
Require Import Globalenvs.
Require Import ASTExtra.
Require Import AsmX.
Require Import Values.
Require Import Memory.
Require Import Events.
Require Import LAsm.
Require Import AuxStateDataType.
Require Import Constant.
Require Import FlatMemory.
Require Import GlobIdent.
Require Import Integers.
Require Import CommonTactic.
Require Import AuxLemma.
Require Import AsmImplLemma.
Require Import liblayers.logic.PTreeModules.
Require Import liblayers.logic.LayerLogicImpl.
Require Import liblayers.compcertx.ClightModules.
Require Import liblayers.compat.CompatLayers.
Require Import liblayers.compat.CompatClightSem.
Require Import liblayers.compcertx.MemWithData.
Require Import AbstractDataType.
Require Export FlatLoadStoreSem.
Require Import LoadStoreDef.
Require Export GuestAccessIntelDef0.
Require Export GuestAccessIntelRef0.
Section Load_Store.
Context `{Hmem: Mem.MemoryModel}.
Context `{HD: CompatData RData}.
Context `{Hmwd: UseMemWithData mem}.
Notation HDATAOps := (cdata (cdata_ops := data_ops) RData).
Section GE.
Context {F V} (ge: Genv.t F V).
Section Load_Store1.
Definition load_accessor1 (n: int64) (ofs: Z) (chunk: memory_chunk) (m: mwd HDATAOps) (rs: regset) (rd: preg) :=
let adr´ := (EPTADDR ((Int.unsigned (Int.repr (Int64.unsigned n)))/PgSize) ofs) in
if (zle (ofs mod PgSize) (PgSize - size_chunk chunk)) then
if (Zdivide_dec (align_chunk chunk) (ofs mod PgSize) (align_chunk_pos chunk)) then
exec_flatmem_load chunk m adr´ rs rd
else Stuck
else Stuck.
Definition exec_guest_intel_load1 (adr: int) (chunk: memory_chunk) (m: mwd HDATAOps) (rs: regset) (rd: preg) :=
exec_guest_intel_accessor1 ge load_accessor1 adr chunk m rs rd.
Lemma exec_guest_intel_load1_high_level_invariant:
∀ adr chunk m rs rd rs´ m´,
exec_guest_intel_load1 adr chunk m rs rd (CPU_ID (snd m)) = Next rs´ m´ →
high_level_invariant (snd m) →
high_level_invariant (snd m´).
Proof.
unfold exec_guest_intel_load1. intros.
eapply exec_guest_intel_accessor1_high_level_invariant; eauto.
unfold load_accessor1. intros.
subdestruct. inv H1. assumption.
Qed.
Lemma exec_guest_intel_load1_asm_invariant:
∀ chunk rd,
∀ TYP: subtype (type_of_chunk chunk) (typ_of_preg rd) = true,
∀ adr m rs rs´ m´,
exec_guest_intel_load1 adr chunk m rs rd (CPU_ID (snd m)) = Next rs´ m´ →
AsmX.asm_invariant ge rs m →
AsmX.asm_invariant ge rs´ m´.
Proof.
unfold exec_guest_intel_load1. intros.
eapply exec_guest_intel_accessor1_asm_invariant; eauto.
unfold load_accessor1. intros. subdestruct.
eapply exec_flatmem_load_asm_invariant; eauto.
Qed.
Lemma exec_guest_intel_load1_low_level_invariant:
∀ adr chunk m rs rd rs´ m´,
exec_guest_intel_load1 adr chunk m rs rd (CPU_ID (snd m)) = Next rs´ m´ →
CompatData.low_level_invariant (Mem.nextblock m) (snd m) →
CompatData.low_level_invariant (Mem.nextblock m´) (snd m´).
Proof.
unfold exec_guest_intel_load1. intros.
eapply exec_guest_intel_accessor1_low_level_invariant; eauto.
unfold load_accessor1. intros.
subdestruct. inv H1. assumption.
Qed.
Context `{flatmem_store: RData → memory_chunk → Z → val → option (cdata RData)}.
Definition store_accessor1 (destroyed: list preg) (n: int64) (ofs: Z)
(chunk: memory_chunk) (m: mwd HDATAOps) (rs: regset) (rd: preg) :=
let adr´ := (EPTADDR ((Int.unsigned (Int.repr (Int64.unsigned n)))/PgSize) ofs) in
if (zle (ofs mod PgSize) (PgSize - size_chunk chunk)) then
if (Zdivide_dec (align_chunk chunk) (ofs mod PgSize) (align_chunk_pos chunk)) then
exec_flatmem_store (flatmem_store:= flatmem_store) chunk m adr´ rs rd destroyed
else Stuck
else Stuck.
Definition exec_guest_intel_store1 (adr: int) (chunk: memory_chunk) (m: mwd HDATAOps)
(rs: regset) (rd: preg) (destroyed: list preg) :=
exec_guest_intel_accessor1 ge (store_accessor1 destroyed) adr chunk m rs rd.
Context {flat_inv: FlatmemStoreInvariant (data_ops := data_ops) (flatmem_store:= flatmem_store)}.
Lemma exec_guest_intel_store1_high_level_invariant:
∀ adr chunk m rs rd rs´ ds m´,
exec_guest_intel_store1 adr chunk m rs rd ds (CPU_ID (snd m)) = Next rs´ m´ →
high_level_invariant (snd m) →
high_level_invariant (snd m´).
Proof.
unfold exec_guest_intel_store1. intros.
eapply exec_guest_intel_accessor1_high_level_invariant; eauto.
unfold store_accessor1. intros. subdestruct.
eapply exec_flatmem_store_high_level_invariant; eauto 1.
eapply PTADDR_mod_lt; assumption.
Qed.
Lemma exec_guest_intel_store1_asm_invariant:
∀ chunk rd,
∀ adr m rs rs´ ds m´,
exec_guest_intel_store1 adr chunk m rs rd ds (CPU_ID (snd m)) = Next rs´ m´ →
AsmX.asm_invariant ge rs m →
AsmX.asm_invariant ge rs´ m´.
Proof.
unfold exec_guest_intel_store1. intros.
eapply exec_guest_intel_accessor1_asm_invariant; eauto.
unfold store_accessor1. intros. subdestruct.
eapply exec_flatmem_store_asm_invariant; eauto.
Qed.
Lemma exec_guest_intel_store1_low_level_invariant:
∀ adr chunk m rs rd rs´ ds m´,
exec_guest_intel_store1 adr chunk m rs rd ds (CPU_ID (snd m)) = Next rs´ m´ →
CompatData.low_level_invariant (Mem.nextblock m) (snd m) →
CompatData.low_level_invariant (Mem.nextblock m´) (snd m´).
Proof.
unfold exec_guest_intel_store1. intros.
eapply exec_guest_intel_accessor1_low_level_invariant; eauto.
unfold store_accessor1. intros. subdestruct.
eapply exec_flatmem_store_low_level_invariant in H1; eauto.
Qed.
End Load_Store1.
End GE.
End Load_Store.
Section Refinement.
Context `{Hmem: Mem.MemoryModel}.
Context `{Hmwd: UseMemWithData mem}.
Context `{HD: CompatData RData}.
Context `{HD0: CompatData RData}.
Notation HDATAOps := (cdata (cdata_ops := data_ops) RData).
Notation LDATAOps := (cdata (cdata_ops := data_ops0) RData).
Context `{rel_prf: CompatRel (mem:=mem) (memory_model_ops:= memory_model_ops) (D1 := HDATAOps) (D2:=LDATAOps)}.
Context `{Hstencil: Stencil stencil (stencil_ops:= stencil_ops)}.
Context `{trapinfo_inv: TrapinfoSetInvariant (data_ops:= data_ops)}.
Context `{hflatmem_store: RData → memory_chunk → Z → val → option RData}.
Context `{lflatmem_store: RData → memory_chunk → Z → val → option RData}.
Notation hexec_flatmem_store := (exec_flatmem_store (flatmem_store:= hflatmem_store)).
Notation lexec_flatmem_store := (exec_flatmem_store (flatmem_store:= lflatmem_store)).
Section General.
Context {loadstoreprop: LoadStoreProp (hflatmem_store:= hflatmem_store) (lflatmem_store:= lflatmem_store)}.
Context {re1: relate_impl_HP´}.
Opaque align_chunk Z.mul Z.div Z.sub.
Lemma guest_intel_load_correct1:
∀ {F V} (ge1 ge2: Genv.t F V) m1 m1´ m2 d1 d2 d1´ rs1 rs2 rs1´ f s rd t i,
exec_guest_intel_load1 ge1 i t (m1, d1) rs1 rd (CPU_ID d1) = Next rs1´ (m1´, d1´)
→ MatchPrimcallStates (one_crel HDATAOps LDATAOps) s f rs1 m1 d1 rs2 m2 d2
→ stencil_matches s ge1
→ stencil_matches s ge2
→ ∃ r´0 m2´ d2´,
exec_guest_intel_load1 ge2 i t (m2, d2) rs2 rd (CPU_ID d1) = Next r´0 (m2´, d2´)
∧ MatchPrimcallStates (one_crel HDATAOps LDATAOps) s f rs1´ m1´ d1´ r´0 m2´ d2´.
Proof.
intros. eapply guest_intel_correct1; eauto.
unfold load_accessor1; intros.
subdestruct.
eapply exec_flatmem_load_correct; eauto.
Qed.
Lemma guest_intel_store_correct1:
∀ {F V} (ge1 ge2: Genv.t F V) m1 m1´ m2 d1 d2 d1´ rs1 rs2 rs1´ f s rd t i ds,
exec_guest_intel_store1 (flatmem_store:= hflatmem_store) ge1 i t (m1, d1) rs1 rd ds (CPU_ID d1) = Next rs1´ (m1´, d1´)
→ MatchPrimcallStates (one_crel HDATAOps LDATAOps) s f rs1 m1 d1 rs2 m2 d2
→ stencil_matches s ge1
→ stencil_matches s ge2
→ ∃ r´0 m2´ d2´,
exec_guest_intel_store1 (flatmem_store:= lflatmem_store) ge2 i t (m2, d2) rs2 rd ds (CPU_ID d1) = Next r´0 (m2´, d2´)
∧ MatchPrimcallStates (one_crel HDATAOps LDATAOps) s f rs1´ m1´ d1´ r´0 m2´ d2´.
Proof.
intros. eapply guest_intel_correct1; eauto.
unfold store_accessor1; intros.
subdestruct.
eapply exec_flatmem_store_correct; eauto.
apply PTADDR_mod_lt. assumption.
Qed.
End General.
End Refinement.