skip to main content
10.1145/2505879.2505897acmotherconferencesArticle/Chapter ViewAbstractPublication PagesppdpConference Proceedingsconference-collections
research-article

Coq: the world's best macro assembler?

Published:16 September 2013Publication History

ABSTRACT

We describe a Coq formalization of a subset of the x86 architecture. One emphasis of the model is brevity: using dependent types, type classes and notation we give the x86 semantics a makeover that counters its reputation for baroqueness. We model bits, bytes, and memory concretely using functions that can be computed inside Coq itself; concrete representations are mapped across to mathematical objects in the SSReflect library (naturals, and integers modulo 2n) to prove theorems. Finally, we use notation to support conventional assembly code syntax inside Coq, including lexically-scoped labels. Ordinary Coq definitions serve as a powerful "macro" feature for everything from simple conditionals and loops to stack-allocated local variables and procedures with parameters. Assembly code can be assembled within Coq, producing a sequence of hex bytes. The assembler enjoys a correctness theorem relating machine code in memory to a separation-logic formula suitable for program verification.

References

  1. B. Aydemir, A. Bohannon, M. Fairbairn, J. Foster, B. Pierce, P. Sewell, D. Vytiniotis, G. Washburn, S. Weirich, and S. Zdancewic. Mechanized metatheory for the masses: The POPLmark challenge. In 18th International Conference on Theorem Proving in Higher Order Logics (TPHOLs), volume 3603 of LNCS. Springer, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. N. Benton. A typed, compositional logic for a stack-based abstract machine. In 3rd Asian Symposium on Programming Languages and Systems (APLAS), volume 3780 of LNCS, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. N. Benton and C.-K. Hur. Biorthogonality, step-indexing and compiler correctness. In 14th ACM SIGPLAN International Conference on Functional Programming (ICFP). ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. N. Benton, C-K. Hur, A. J. Kennedy, and C. McBride. Strongly typed term representations in Coq. J. Automated Reasoning, 49, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. J. Boender and C. S. Coen. On the correctness of a branch displacement algorithm. Preprint arXiv:1209.5920, 2012.Google ScholarGoogle Scholar
  6. E. Brady and K. Hammond. Resource-safe systems programming with embedded domain specific languages. In 14th International Symposium on Practical Aspects of Declarative Languages (PADL), volume 7149 of LNCS. Springer, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. T. Braibant and D. Pous. An efficient Coq tactic for deciding Kleene algebras. In 1st International Conference on Interactive Theorem Proving (ITP), volume 6172 of LNCS. Springer, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. A. Chlipala. Modular development of certified program verifiers with a proof assistant. J. Functional Programming, 18(5/6), 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. A. Chlipala. Ur: statically-typed metaprogramming with type-level record computation. In 31st ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. A. Chlipala. Mostly-automated verification of low-level programs in computational separation logic. In 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Intel Corp. Intel 64 and IA-32 Architectures Software Developer's Manual. Volume 2 (2A, 2B & 2C): Instruction Set Reference, January 2013.Google ScholarGoogle Scholar
  12. P.-E. Dagand, A. Baumann, and T. Roscoe. Filet-o-Fish: practical and dependable domain-specific languages for OS development. SIGOPS Oper. Syst. Rev., 43(4):35--39, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. A. Fox and M. O. Myreen. A trustworthy monadic formalization of the ARMv7 instuction set architecture. In 1st International Conference on Interactive Theorem Proving (ITP), volume 6172 of LNCS. Springer, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. G. Gonthier. Advances in the formalization of the odd order theorem. In 2nd International Conference on Interactive Theorem Proving (ITP), volume 6898 of LNCS. Springer, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. G. Gonthier, A. Mahboubi, and E. Tassi. A small scale reflection extension for the Coq system. Technical Report 6455, INRIA, 2011.Google ScholarGoogle Scholar
  16. J. B. Jensen, N. Benton, and A. J. Kennedy. High-level separation logic for low-level code. In 40th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. X. Leroy. Formal verification of a realistic compiler. Comm. ACM, 52 (7):107--115, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. J. Strother Moore. Piton: A Verified Assembly-Level Language. Kluwer, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. G. Morrisett, G. Tan, J. Tassarotti, J. B. Tristan, and E. Gan. Rocksalt: Better, faster, stronger SFI for the x86. In 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. D. P. Mulligan and C. Sacerdoti Coen. On the correctness of an assembler for the MCS-51 microprocessor. In 2nd International Conference on Certified Programs and Proofs (CPP), volume 7679 of LNCS. Springer, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. M. O. Myreen. Verified just-in-time compiler on x86. In 37th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. R. Olinsky, C. Lindig, and N. Ramsey. Staged allocation: A compositional technique for specifying and implementing procedure calling conventions. In 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. N. Oury and W. Swierstra. The power of pi. In 13th ACM SIGPLAN International Conference on Functional Programming (ICFP). ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. L. Pike, N. Wegmann, S. Niller, and A. Goodloe. Experience report: a do-it-yourself high-assurance compiler. In 17th ACM SIGPLAN International Conference on Functional Programming (ICFP). ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. B. Spitters and van der Weegen. E. Type classes for mathematics in type theory. Math. Structures in Comp. Sci., 21:1--31, 2011.Google ScholarGoogle ScholarCross RefCross Ref
  26. G. Tan and A. W. Appel. A compositional logic for control flow. In 7th International Conference on Verification, Model Checking, and Abstract Interpretation (VMCAI), volume 3855 of LNCS, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. The Coq Development Team. The Coq Reference Manual, version 8.4, 2012. URL http://coq.inria.fr.Google ScholarGoogle Scholar
  28. H. Tuch, G. Klein, and M. Norrish. Types, bytes and separation logic. In 34th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Coq: the world's best macro assembler?

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in
          • Published in

            cover image ACM Other conferences
            PPDP '13: Proceedings of the 15th Symposium on Principles and Practice of Declarative Programming
            September 2013
            308 pages
            ISBN:9781450321549
            DOI:10.1145/2505879

            Copyright © 2013 ACM

            Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 16 September 2013

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article

            Acceptance Rates

            Overall Acceptance Rate230of486submissions,47%

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader