Library mcertikos.ticketlog.TicketLockIntroGenAsmSource


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 log_get_sig:= mksignature (Tint::Tint::nil) (Some Tint) cc_default.
  Definition get_now_sig:= mksignature (Tint::Tint::nil) (Some Tint) cc_default.

  Definition atomic_FAI_sig:= mksignature (Tint::Tint::Tint::nil) (Some Tint) cc_default.
  Definition incr_ticket_sig:= mksignature (Tint::Tint::Tint::nil) (Some Tint) cc_default.

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

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

  Definition Im_get_now : 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 log_get log_get_sig) ::
                    asm_instruction (Pfreeframe 16 (Int.repr 12) (Int.repr 8)) ::
                    asm_instruction (Pret) ::
                    nil.

  Definition get_now_function: function := mkfunction get_now_sig Im_get_now.

  Definition Im_incr_ticket : 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.zero) 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 atomic_FAI atomic_FAI_sig) ::
                    asm_instruction (Pfreeframe 20 (Int.repr 16) (Int.repr 12)) ::
                    asm_instruction (Pret) ::
                    nil.

  Definition incr_ticket_function: function := mkfunction incr_ticket_sig Im_incr_ticket.

End ASM_CODE.