Library mcertikos.devdrivers.SerialIntroGenLink

***********************************************************************
*                                                                     *
*            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 DSerialIntro.
Require Import SerialIntroGen.
Require Import SerialIntroGenLinkSource.
Require Import DAbsConsoleBuffIntro.
Require Import DAbsConsoleBuffIntroCSource.
Require Import DAbsConsoleBuffIntroCode.
Require Import Integers.

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

  Lemma init_correct:
    init_correct_type DSerialIntro_module dabsconsolebuffintro dserial_intro.
  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 _ _ Hbvi H2); eauto.
    unfold Globalenvs.Genv.perm_globvar. simpl. intros (Hperm & _ & init).
    specialize (init eq_refl); destruct init as (init0 & _).
    change 0 with (Int.unsigned (Int.repr 0)).
    econstructor.
    eassumption.
    assert(Mem.valid_access m2 AST.Mint32 b 0 Writable).
    {
      split.
      unfold Mem.range_perm; intros; apply Hperm.
      simpl in H1.
      omega.
       0; reflexivity.
    }
    assert (readable : Mem.valid_access m2 AST.Mint32 b 0 Readable).
    { eapply Mem.valid_access_implies; eauto; constructor. }
    exploit Mem.valid_access_load; eauto.
    assumption.
  Qed.

  Lemma link_correct_aux:
    link_correct_aux_type DSerialIntro_module dabsconsolebuffintro dserial_intro.
  Proof.
    link_correct_aux.
    - link_cfunction
        get_serial_exists_spec_ref
        DABSCONSOLEBUFFINTROCODE.get_serial_exists_code_correct.
    - link_cfunction
        set_serial_exists_spec_ref
        DABSCONSOLEBUFFINTROCODE.set_serial_exists_code_correct.
    - apply passthrough_correct.
  Qed.

  Theorem cl_backward_simulation:
    cl_backward_simulation_type DSerialIntro_module dabsconsolebuffintro dserial_intro.
  Proof.
    cl_backward_simulation init_correct link_correct_aux.
  Qed.

  Theorem make_program_exists:
    make_program_exist_type DSerialIntro_module dabsconsolebuffintro dserial_intro.
  Proof.
    make_program_exists link_correct_aux.
  Qed.
End WITHCOMPCERTIKOS.