Library mcertikos.ticketlog.QTicketLockGenAsmSource


Require Import Coqlib.
Require Import Integers.
Require Import Constant.
Require Import GlobIdent.
Require Import AST.

Require Import liblayers.compat.CompatLayers.
Require Import LAsm.

Section ASM_CODE.

  Definition release_shared_sig := mksignature (Tint::Tint::nil) None cc_default.
  Definition pass_lock_sig := mksignature (Tint::Tint::nil) None cc_default.
  Definition release_lock_sig := mksignature (Tint::Tint::nil) None cc_default.

  Definition acquire_shared_sig := mksignature (Tint::Tint::nil) None cc_default.
  Definition wait_lock_sig := mksignature (Tint::Tint::Tint::nil) None cc_default.
  Definition acquire_lock_sig := mksignature (Tint::Tint::Tint::nil) None cc_default.

  Definition AddrMakeArg (ofs:int) := Addrmode (Some EDX) None (inl ofs).

  Definition AddrMakeArg2 (ofs:int) := Addrmode (Some ESP) None (inl ofs).

  Definition Im_acquire_lock : list instruction :=
    asm_instruction (Pallocframe 20 (Int.repr 16) (Int.repr 12)) ::
                    asm_instruction (Pmov_rm EAX (AddrMakeArg (Int.repr 0))) ::
                    asm_instruction (Pmov_mr (AddrMakeArg2 (Int.repr 0)) EAX) ::
                    asm_instruction (Pmov_rm EAX (AddrMakeArg (Int.repr 4))) ::
                    asm_instruction (Pmov_mr (AddrMakeArg2 (Int.repr 4)) EAX) ::
                    asm_instruction (Pmov_rm EAX (AddrMakeArg (Int.repr 8))) ::
                    asm_instruction (Pmov_mr (AddrMakeArg2 (Int.repr 8)) EAX) ::
                    asm_instruction (Pcall_s wait_lock wait_lock_sig) ::
                    asm_instruction (Pmov_rm EAX (AddrMakeArg2 (Int.repr 4))) ::
                    asm_instruction (Pmov_mr (AddrMakeArg2 Int.zero) EAX) ::
                    asm_instruction (Pmov_rm EAX (AddrMakeArg2 (Int.repr 8))) ::
                    asm_instruction (Pmov_mr (AddrMakeArg2 (Int.repr 4)) EAX) ::
                    asm_instruction (Pcall_s acquire_shared acquire_shared_sig) ::
                    asm_instruction (Pfreeframe 20 (Int.repr 16) (Int.repr 12)) ::
                    asm_instruction (Pret) ::
                    nil.

  Definition acquire_lock_function: function := mkfunction acquire_lock_sig Im_acquire_lock.

  Definition Im_release_lock : list instruction :=
    asm_instruction (Pallocframe 16 (Int.repr 12) (Int.repr 8)) ::
                    asm_instruction (Pmov_rm EAX (AddrMakeArg (Int.repr 0))) ::
                    asm_instruction (Pmov_mr (AddrMakeArg2 Int.zero) EAX) ::
                    asm_instruction (Pmov_rm EAX (AddrMakeArg (Int.repr 4))) ::
                    asm_instruction (Pmov_mr (AddrMakeArg2 (Int.repr 4)) EAX) ::
                    asm_instruction (Pcall_s release_shared release_shared_sig) ::
                    asm_instruction (Pcall_s pass_lock pass_lock_sig) ::
                    asm_instruction (Pfreeframe 16 (Int.repr 12) (Int.repr 8)) ::
                    asm_instruction (Pret) ::
                    nil.

  Definition release_lock_function: function := mkfunction release_lock_sig Im_release_lock.

End ASM_CODE.