Library mcertikos.devdrivers.HandlerAsmGenLink

Require Import LinkTemplate.
Require Import DHandlerAsm.
Require Import HandlerAsmGen.
Require Import HandlerAsmGenLinkSource.
Require Import DHandlerSw.
Require Import DHandlerSwAsmSource.
Require Import DHandlerSwAsmCode.
Require Import CommonTactic.

Section WITHCOMPCERTIKOS.
  Context `{compcertikos_prf: CompCertiKOS} `{real_params_prf: RealParams}.
  Context `{oracle_prop: MultiOracleProp}.

  Lemma init_correct:
    init_correct_type DHandlerAsm_module dhandlersw dhandlerasm.
  Proof.
    init_correct.
    specialize (Globalenvs.Genv.init_mem_characterization _ _ Hb0vi Hm); eauto.
    unfold Globalenvs.Genv.perm_globvar. simpl. intros (Hperm & _ & init).
    specialize (init eq_refl); destruct init as (init0 & _).
    econstructor.
    eassumption.
    assert(Mem.valid_access m2 AST.Mint32 b0 0 Writable).
    {
      split.
      unfold Mem.range_perm; intros; apply Hperm.
      simpl in H0.
      omega.
       0; reflexivity.
    }
    assumption.
    assumption.
  Qed.

  Lemma link_correct_aux:
    link_correct_aux_type DHandlerAsm_module dhandlersw dhandlerasm.
  Proof.
    unfold link_correct_aux_type. intros M HM.
    inv_link_impl HM. subst.
    eapply conseq_le_assoc_comm.
    hcomp_tac; [| link_correct_aux_passthrough].
    LinkTactic.transfer_variables.
    unfold_layer dhandlerasm_fresh.
    apply LayerLogicImpl.vdash_oplus_empty_left.
    apply LayerLogicImpl.vdash_oplus_empty.
    layer_link_split_tac.
    - link_asmfunction
        serial_intr_handler_asm_spec_ref
        serial_intr_handler_asm_code_correct.
    - apply passthrough_correct.
  Qed.

  Theorem cl_backward_simulation:
    cl_backward_simulation_type DHandlerAsm_module dhandlersw dhandlerasm.
  Proof.
    cl_backward_simulation init_correct link_correct_aux.
  Qed.

  Theorem make_program_exists:
    make_program_exist_type DHandlerAsm_module dhandlersw dhandlerasm.
  Proof.
    make_program_exists link_correct_aux.
  Qed.

End WITHCOMPCERTIKOS.