Library mcertikos.devdrivers.HandlerAsmGenLink

***********************************************************************
*                                                                     *
*            The CertiKOS Certified Kit Operating System              *
*                                                                     *
*                   The FLINT Group, Yale University                  *
*                                                                     *
*  Copyright The FLINT Group, Yale University.  All rights reserved.  *
*  This file is distributed under the terms of the Yale University    *
*  Non-Commercial License Agreement.                                  *
*                                                                     *
*********************************************************************** 

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}.

  Lemma init_correct:
    init_correct_type DHandlerAsm_module dhandlersw dhandlerasm.
  Proof.
    init_correct.
    generalize H0; intro mkprog.
    inv_monad´ mkprog.
    assert (mkgenv := make_program_make_globalenv _ _ _ _ mkprog0).
    pose proof mkgenv as mkgenv´.
    eapply make_globalenv_stencil_matches in mkgenv´.
    inv_make_globalenv mkgenv. subst.
    rewrite (stencil_matches_symbols _ _ mkgenv´) in ×. inv mkgenv´.
    specialize (Globalenvs.Genv.init_mem_characterization _ _ Hb0vi H2); 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 H1.
      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.