TAM: an Abstract Machine Specification in Z
Total Page:16
File Type:pdf, Size:1020Kb
TAM: An Abstract Machine Specification in Z TAM: una especificación de máquina abstracta en Z Ignacio Trejos- Iván A. Salazar- Jennifer Zelaya Solano Caballero Francisco J. Computer Computer Computer Torres-Rojas Science Costa Science Costa Science Costa Computer Rica Institute of Rica Institute Rica Institute of Science Costa Technology of Technology Technology Rica Institute Costa Rica Costa Rica Costa Rica of Technology [email protected] ivan.a.salazar.so jennifer.caballer Costa Rica [email protected] [email protected] torresrojas@gm m ail.com Fecha de recibido: 01 de marzo de 2020 Fecha de aprobado: 08 de abril de 2020 Abstract—Finding bugs in the late stages like programming languages, such as of hardware design development is Pascal, Modula, Oberon, and Triangle. expensive. In particular, for a TAM’s architecture is stack-based which microprocessor architecture, unambiguity simplifies the code generation. Z’s is an essential property. Formal methods mathematical notation and its schema’s can help designers to identify structure help to describe logical and inconsistencies in a given system’s arithmetic instructions and also provide specifications. This paper presents a mechanisms suitable for modeling formal description of a subset of the complex instructions that access instruction set of the Triangle Abstract registers, memories, and the stack. This Machine (TAM) architecture in Z. TAM is research proposes a precise—yet an abstract machine suitable for the abstract—approach that avoids the implementation of block-structured, Algol- specification of low-level concepts such as 30 bits. The work reported here is a case mecanismos adecuados para modelar study in formal specification applied to a instrucciones complejas que acceden a Computing Science subject. registros, memorias y la pila. Esta investigación propone un enfoque Index Terms—formal specification, preciso, aunque abstracto, que evita la instruction set architecture, especificación de conceptos de bajo nivel, microprocessor architecture, stack como los bits. El trabajo presentado aquí computer architecture, Z notation, TAM es un estudio de caso en especificación (Triangle Abstract Machine). formal aplicado a una asignatura de Ciencias de la Computación. Resumen- Encontrar errores en las últimas etapas del desarrollo del diseño Términos del índice: especificación de hardware es costoso. En particular, formal, arquitectura de conjunto de para una arquitectura de instrucciones, arquitectura de microprocesador, la falta de ambigüedad microprocesador, arquitectura de es una propiedad esencial. Los métodos computadora de pila, notación Z, TAM formales pueden ayudar a los (Triangle Abstract Machine). diseñadores a identificar inconsistencias en las especificaciones de un sistema I. INTRODUCTION dado. Este artículo presenta una descripción formal de un subconjunto del The precise and unambiguous conjunto de instrucciones de la modeling of system properties and arquitectura Triangle Abstract Machine behavior is one of the benefits of using (TAM) en Z. TAM es una máquina abstracta adecuada para la formal specification languages [19]. implementación de lenguajes de For a microprocessor architecture, programación tipo Algol estructurados en unambiguity is an essential property. bloques, como Pascal, Modula , Oberon y Formal methods can help designers to Triangle. La arquitectura de TAM se basa identify inconsistencies in a given en la pila, lo que simplifica la generación system’s specification, and when used de código. La notación matemática de Z y in early development stages, they can la estructura de su esquema ayudan a help to avoid costly design flaws likely describir instrucciones lógicas y to appear later in the testing stages aritméticas y también proporcionan [30]. Finding bugs the late stages of 31 hardware design development is very Section II provides an overview of part expensive; for instance, the FDIV bug of the required background. The in the Intel Pentium processor had a memory and registers of TAM are quantified cost of over $400 million specified in Section III, while most of [13]. the instruction set for TAM are specified in Section IV. Section V deals On the other hand, documentation for with the loading of programs and the microprocessor instruction sets is initial state of the TAM machine. usually distributed in tables, semi- Finally, Section VII presents the formal formulae, and informal text [2], conclusions and the sketches’ future whereas a formal language work. specification of the microprocessor architecture ensures unambiguity of II. BACKGROUND the documentation and enables verification. The stack has a long and multi-faceted tradition in Computing: as a The Z-formal specification language is mechanism for carrying procedure or based on set theory and mathematical call and return function [1], as a natural logic [26], [31]. This paper uses Z to way for describing syntax analysis specify a subset of the Triangle methods and program translation Abstract Machine (TAM) instruction [24], [16], and as the basis of most set as described in [28]. Arithmetic and techniques for the implementation of Boolean instructions are modeled recursion [5], among others. using common mathematical logic concepts while more complex E.W. Dijkstra and J.A. Zonneveld instructions—that involve memory solved the challenges of implementing accesses and stack manipulation— recursive procedures and functions— require the definition of a model to with their corresponding parameter- access the memory, the stack, and the passing mechanisms—in a block- registers. structured language setting in the first working compiler for Algol 60 [9]. That 32 work inspired the design of several real via interpretation can help to provide computer architectures that would use early feedback on the processor’s stacks in support of high-level desired behavior and assist in porting programming languages [6], more a language’s implementation to prominently, those by Burroughs [29]. diverse hardware architectures. The Over the years, register computer interpreter’s code can be instructive to architectures with complex instruction learners of the programming language sets (CISC) or reduced instruction sets implementation. (RISC) have tended to dominate the Formal specification languages offer market, yet stack computer an abstract, unbiased, and precise architectures have survived and alternative for modeling and thrived as abstract machines hat specifying computational systems, simplify compiler code generation such as computer architectures, using algorithms and ease a programming discrete mathematical structures. language’s portability [17], [18]. Their logic-mathematical foundation Both in academia and industry, opens the opportunity for proving “abstract” and “virtual” machines have properties of the models and been variously proposed. Of special specification documents, while it also attention are the Pascal ETH P- opens the opportunity for correct-by- System and the UCSD Pascal which construction and provably- correct use variants of Wirth’s P-machine implementation [3]. suitable for efficient compilation and Z is a formal specification language interpretation of Pascal- like developed by Oxford University’s programming languages [22], and the Programming Research Group in the Java Virtual Machine (JVM) [20]. early 1980s [21]. It is based on Abstract machines can be Zermelo Fränkel axiomatic set theory implemented in hardware circuits, in and first-order predicate logic [23]. software interpreters or translators, or Using Z, mathematical objects and combinations of both. The software their properties can be collected implementation of an abstract machine together in schemas [31]. A 33 characteristic feature of Z is the use of integrated processor for enhanced types. Every object in the reliability) microprocessor chip. mathematical language has a unique The Triangle Abstract Machine (TAM) type, represented as a maximal set in was designed as a vehicle to explain the current specification [31]. A tutorial high-level programming language introduction to the Z notation can be implementation techniques typically found within the Reference Manual used in compilers and interpreters written by Spivey [26]. [27]. TAM’s instruction set Other works have specified architecture, memory organization, microprocessors architectures using and addressing modes are explained formal specification languages. For informally and via interpreters written instance, in [2] the 8-bit Motorola 6800 in Pascal [27] or Java [28]. TAM’s microprocessor instruction set was architecture is simple, yet powerful specified using Z. This specification enough as a natural target of code- defines low-level concepts such as bits generation algorithms for imperative and words. The work described in this and object-oriented languages. paper uses a higher level of Although TAM’s interpreters are abstraction; all addresses, readily understandable, they are instructions, and data are specified as concrete representations in particular natural numbers instead. In [14], the programming languages after all. A design and verification of the FM8501 programming-language independent are presented, where several formulas description, precise and abstract, are used to verify the system. The Intel opens opportunities for analysis and 8085 microprocessor is specified in design. This research uses Z because [11] using algebra. A higher-order logic it makes the specification readable language (HOL) is used in [15] to and formally verifiable [12].