Coq: the world's best macro assembler?

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.

[1]  Claudio Sacerdoti Coen,et al.  On the Correctness of an Optimising Assembler for the Intel MCS-51 Microprocessor , 2012, CPP.

[2]  Reuben Olinsky,et al.  Staged allocation: a compositional technique for specifying and implementing procedure calling conventions , 2006, POPL '06.

[3]  Nick Benton,et al.  High-level separation logic for low-level code , 2013, POPL.

[4]  Claudio Sacerdoti Coen,et al.  On the Correctness of a Branch Displacement Algorithm , 2014, TACAS.

[5]  D. B. Davis,et al.  Intel Corp. , 1993 .

[6]  Timothy Roscoe,et al.  Filet-o-Fish: practical and dependable domain-specific languages for OS development , 2009, PLOS '09.

[7]  Adam Chlipala Modular development of certified program verifiers with a proof assistant, , 2008, J. Funct. Program..

[8]  J. Strother Moore Piton: A Mechanically Verified Assembly-Level Language , 1996 .

[9]  Lee Pike,et al.  Experience report: a do-it-yourself high-assurance compiler , 2012, ICFP.

[10]  Adam Chlipala,et al.  Ur: statically-typed metaprogramming with type-level record computation , 2010, PLDI '10.

[11]  Georges Gonthier Advances in the Formalization of the Odd Order Theorem , 2011, ITP.

[12]  Wouter Swierstra,et al.  The power of Pi , 2008, ICFP.

[13]  Magnus O. Myreen Verified just-in-time compiler on x86 , 2010, POPL '10.

[14]  Nick Benton A Typed, Compositional Logic for a Stack-Based Abstract Machine , 2005, APLAS.

[15]  Vincent Siles,et al.  A Refinement-Based Approach to Computational Algebra in Coq , 2012, ITP.

[16]  Damien Pous,et al.  An Efficient Coq Tactic for Deciding Kleene Algebras , 2010, ITP.

[17]  No License,et al.  Intel ® 64 and IA-32 Architectures Software Developer ’ s Manual Volume 3 A : System Programming Guide , Part 1 , 2006 .

[18]  Chung-Kil Hur,et al.  Biorthogonality, step-indexing and compiler correctness , 2009, ICFP.

[19]  Andrew W. Appel,et al.  A Compositional Logic for Control Flow , 2006, VMCAI.

[20]  Adam Chlipala,et al.  Mostly-automated verification of low-level programs in computational separation logic , 2011, PLDI '11.

[21]  Bas Spitters,et al.  Type classes for mathematics in type theory† , 2011, Mathematical Structures in Computer Science.

[22]  Michael Norrish,et al.  Types, bytes, and separation logic , 2007, POPL '07.

[23]  Magnus O. Myreen,et al.  A Trustworthy Monadic Formalization of the ARMv7 Instruction Set Architecture , 2010, ITP.

[24]  Jeffrey S. Moore Piton: a verified assembly level language , 1988 .

[25]  Xavier Leroy,et al.  Formal verification of a realistic compiler , 2009, CACM.

[26]  Joseph Tassarotti,et al.  RockSalt: better, faster, stronger SFI for the x86 , 2012, PLDI.

[27]  Charles H. Moore,et al.  The evolution of Forth , 1996 .

[28]  Chung-Kil Hur,et al.  Strongly Typed Term Representations in Coq , 2011, Journal of Automated Reasoning.

[29]  Edwin Brady,et al.  Resource-Safe Systems Programming with Embedded Domain Specific Languages , 2012, PADL.

[30]  Enrico Tassi,et al.  A Small Scale Reflection Extension for the Coq system , 2008 .

[31]  Benjamin C. Pierce,et al.  Mechanized Metatheory for the Masses: The PoplMark Challenge , 2005, TPHOLs.