Library mcertikos.mm.ALInitGenAsmSource


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

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

Section ASM_CODE.

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

  Definition acquire_lock_sig := mksignature (Tint::Tint::Tint::nil) None cc_default.
  Section AcqLOCK.


    Definition Im_acquire_lock_AT : list instruction :=
      asm_instruction (Pallocframe 20 (Int.repr 16) (Int.repr 12)) ::
                      asm_instruction (Pmov_ri EAX (Int.repr (Z.of_nat local_lock_bound))) ::
                      asm_instruction (Pmov_mr (AddrMake (Int.zero)) EAX) ::
                      asm_instruction (Pmov_ri EAX (Int.repr ID_AT)) ::
                      asm_instruction (Pmov_mr (AddrMake (Int.repr 4)) EAX) ::
                      asm_instruction (Pmov_ri EAX Int.zero) ::
                      asm_instruction (Pmov_mr (AddrMake (Int.repr 8)) EAX) ::
                      asm_instruction (Pcall_s acquire_lock acquire_lock_sig) ::
                      asm_instruction (Pfreeframe 20 (Int.repr 16) (Int.repr 12)) ::
                      asm_instruction (Pret) ::
                      nil.

    Definition acquire_lock_AT_function: function := mkfunction null_signature Im_acquire_lock_AT.

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


    Definition Im_release_lock_AT : list instruction :=
      asm_instruction (Pallocframe 16 (Int.repr 12) (Int.repr 8)) ::
                      asm_instruction (Pmov_ri EAX (Int.repr ID_AT)) ::
                      asm_instruction (Pmov_mr (AddrMake (Int.zero)) EAX) ::
                      asm_instruction (Pmov_ri EAX Int.zero) ::
                      asm_instruction (Pmov_mr (AddrMake (Int.repr 4)) EAX) ::
                      asm_instruction (Pcall_s release_lock release_lock_sig) ::
                      asm_instruction (Pfreeframe 16 (Int.repr 12) (Int.repr 8)) ::
                      asm_instruction (Pret) ::
                      nil.

    Definition release_lock_AT_function: function := mkfunction null_signature Im_release_lock_AT.

  End AcqLOCK.

End ASM_CODE.