Library mcertikos.trap.SysCallGenSpec

Require Import Coqlib.
Require Import Errors.
Require Import AST.
Require Import Integers.
Require Import Floats.
Require Import Op.
Require Import Asm.
Require Import Events.
Require Import Globalenvs.
Require Import Smallstep.
Require Import Values.
Require Import Memory.
Require Import Maps.
Require Import AuxLemma.
Require Import FlatMemory.
Require Import AuxStateDataType.
Require Import Constant.
Require Import GlobIdent.
Require Import RealParams.
Require Import AsmImplLemma.
Require Import GenSem.
Require Import PrimSemantics.

Require Import liblayers.logic.PTreeModules.
Require Import liblayers.logic.LayerLogicImpl.
Require Import liblayers.compcertx.Stencil.
Require Import liblayers.compcertx.MakeProgram.
Require Import liblayers.compat.CompatLayers.
Require Import liblayers.compat.CompatGenSem.
Require Import compcert.cfrontend.Ctypes.
Require Import TSysCall.
Require Import AbstractDataType.

Require Import Conventions.

Require Import GlobalOracleProp.
Require Import SingleOracle.

Local Open Scope string_scope.
Local Open Scope error_monad_scope.
Local Open Scope Z_scope.

Definition of the low level specification

Section SPECIFICATION.

  Context `{single_oracle_prop: SingleOracleProp}.
  Context `{real_params : RealParams}.
  Context `{multi_oracle_prop: MultiOracleProp}.

  Notation LDATAOps := (cdata (cdata_ops := pipcintro_data_ops) RData).

  Inductive sys_run_vm_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sprimcall_sem (mem := mwd LDATAOps):=
  | sys_run_vm_spec_low_intro s m (rs:regset) v7 labd labd0 labd´ rs01 rs0 rs´ rs2 v0 v1 v2 v3 v5 v6
                                v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 vargs sg b:
      v12 Int.repr 0 →
      trap_into_kernel_spec sys_run_vm s m rs labd labd0 vargs sg b
                            v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16

      rs01 = (Pregmap.init Vundef) #EDI <- (rs EDI) #EBP <- (rs EBP)
      thread_vm_run_spec rs01 labd0 = Some (labd´, rs´)

      rs0 = (undef_regs (CR ZF :: CR CF :: CR PF :: CR SF :: CR OF :: RA :: nil)
                        (undef_regs (List.map preg_of destroyed_at_call) rs))

      rs2 = (rs0#EAX<- (rs´#EAX)#EBX <- (rs´#EBX)#EDX <- (rs´#EDX)
                #ESI <- (rs´#ESI)#EDI <- (rs´#EDI)#EBP <- (rs´#EBP)
                #PC <- (rs´#RA))

      asm_invariant (mem := mwd LDATAOps) s rs (m, labd)
      high_level_invariant labd
      low_level_invariant (Mem.nextblock m) labd

      sys_run_vm_spec_low_step s rs (m, labd) rs2 (m, labd´).

  Inductive pagefault_handler_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sprimcall_sem (mem := mwd LDATAOps):=
  | pagefault_handler_spec_low_intro s m labd labd0 labd1 labd´ rs0 vadr (rs:regset) rs´ v0 v1 v2 v3 v5 v6
                                     v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b:
      v12 Int.repr 0 →
      syscall_spec pgf_handler s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
                   v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16

      
      
      vadr = fst (ti labd0) →
      ptfault_resv_spec (Int.unsigned vadr) labd0 = Some labd1

      asm_invariant (mem := mwd LDATAOps) s rs (m, labd)
      high_level_invariant labd
      low_level_invariant (Mem.nextblock m) labd

      pagefault_handler_spec_low_step s rs (m, labd) rs0 (m, labd´).


  Inductive sys_dispatch_c_spec_low_step `{StencilOps} `{Mem.MemoryModelOps} `{UseMemWithData mem}:
    sprimcall_sem (mem := mwd LDATAOps):=
  | sys_dispatch_c_spec_low_intro s m labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
                                   v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b:

      v12 Int.repr 0 →

      syscall_spec syscall_dispatch s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
                   v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16
      
      
      sys_dispatch_c_spec s m labd0 = Some labd1

      asm_invariant (mem := mwd LDATAOps) s rs (m, labd)
      high_level_invariant labd
      low_level_invariant (Mem.nextblock m) labd

      sys_dispatch_c_spec_low_step s rs (m, labd) rs0 (m, labd´).


  Section WITHMEM.

    Context `{Hstencil: Stencil}.
    Context `{Hmem: Mem.MemoryModelX}.
    Context `{Hmwd: UseMemWithData mem}.

    Definition pagefault_handler_spec_low: compatsem LDATAOps :=
      asmsem pgf_handler pagefault_handler_spec_low_step.

    Definition sys_dispatch_c_spec_low: compatsem LDATAOps :=
      asmsem syscall_dispatch sys_dispatch_c_spec_low_step.


    Definition sys_run_vm_spec_low: compatsem LDATAOps :=
      asmsem sys_run_vm sys_run_vm_spec_low_step.

  End WITHMEM.

End SPECIFICATION.