Library mcertikos.devdrivers.SerialIntroGenLink

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}.
  Context `{oracle_prop: MultiOracleProp}.

  Lemma init_correct:
    init_correct_type DSerialIntro_module dabsconsolebuffintro dserial_intro.
  Proof.
    init_correct.
    specialize (Globalenvs.Genv.init_mem_characterization _ _ Hbvi Hm); 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 H0.
      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.