A Verifying Compiler for Embedded Networked Systems Kalyan Chakradhar Regula Clemson University, [email protected]
Total Page:16
File Type:pdf, Size:1020Kb
Clemson University TigerPrints All Theses Theses 8-2010 A Verifying Compiler for Embedded Networked Systems Kalyan chakradhar Regula Clemson University, [email protected] Follow this and additional works at: https://tigerprints.clemson.edu/all_theses Part of the Computer Sciences Commons Recommended Citation Regula, Kalyan chakradhar, "A Verifying Compiler for Embedded Networked Systems" (2010). All Theses. 899. https://tigerprints.clemson.edu/all_theses/899 This Thesis is brought to you for free and open access by the Theses at TigerPrints. It has been accepted for inclusion in All Theses by an authorized administrator of TigerPrints. For more information, please contact [email protected]. A Verifying Compiler for Embedded Networked Systems A Thesis Presented to the Graduate School of Clemson University In Partial Fulfillment of the Requirements for the Degree Master Of Science Computer Science by Kalyan Chakradhar Regula August 2010 Accepted by: Dr. Jason O. Hallstrom, Committee Chair Dr. Murali Sitaraman Dr. Brain Malloy Abstract Embedded networked devices are required to produce dependable outputs and communicate with peer devices given limited computing resources. These devices monitor and control processes within the physical world. They are used in applications related to environmental monitoring, telecommunications, social networking, and also life-critical applications in domains such as health care, aeronautics, and automotive manufacturing. For such applications, software errors can be costly - both in terms of financial and human costs. Therefore, software programs installed on these devices must meet the appropriate requirements. To guarantee this, one must verify that the implemented code meets the corresponding specifications. Manual trial-and-error validation of such applications, especially life-critical software programs, is not a feasible option. This work presents a verifying compiler developed for embedded network programs by ex- tending the RESOLVE verifying compiler with a software module that translates RESOLVE code to equivalent C code. Specifications and implementations for embedded networked applications are written in the RESOLVE language. The compiler supports automated verification, automati- cally generating mathematical assertions, which, if satisfied, ensure that the code is correct. These assertions are proved using the mathematical theorems and lemmas provided by the RESOLVE mathematical library. The verified code is then translated to C and installed on the embedded target. The contributions described in this thesis are: (i) We explore the use of RESOLVE in specifying pin-level drivers for components of an embedded device. (ii) We describe the translation strategies implemented to generate correct-by-construction C source code from verified RESOLVE code, with examples of basic and reusable operations such as sense data, broadcast data, and receive data. (iii) We provide techniques used to optimize the generated code in terms of memory usage and runtime efficiency. ii Dedication To my family. iii Acknowledgments I would like to express my deepest gratitude and respect to my advisor Dr. Jason O. Hallstrom, for his continuous support and faith in me. I would like to thank the RESOLVE research group at Clemson University for helping me in understanding the RESOLVE compiler. I also thank the faculty of the School of Computing at Clemson University who helped in creating a wealth of required knowledge. A special thanks to Hao Jiang, Sravanthi Dandamudi, Sally Wahba and Yvon Feaster for their support, suggestions and encouragement. Finally, I would like to thank my family for their love and standing by me in all my aspirations. iv Table of Contents Title Page ............................................ i Abstract ............................................. ii Dedication............................................ iii Acknowledgments ....................................... iv List of Tables ..........................................vii List of Figures..........................................viii List of Listings ......................................... ix 1 Introduction......................................... 1 1.1 Embedded Networked Systems .............................. 1 1.2 Problem Statement..................................... 2 1.3 Solution Approach..................................... 2 1.4 Contributions........................................ 3 1.5 Organization of Chapters ................................. 4 2 Related Work ........................................ 5 2.1 Testing Embedded Software................................ 6 2.2 Verification of Embedded Software............................ 7 2.3 Verification of C Programs................................. 8 2.4 RESOLVE.......................................... 11 3 RESOLVE ..........................................12 3.1 Overview .......................................... 12 3.2 Operators.......................................... 12 3.3 Keywords.......................................... 13 3.4 Concepts .......................................... 13 3.5 Realizations......................................... 16 3.6 Enhancements ....................................... 18 3.7 Facilities........................................... 21 4 Compiler Translation Strategies.............................22 4.1 Overview .......................................... 22 4.2 Datatypes.......................................... 23 4.3 Swap Operation....................................... 23 4.4 Arrays............................................ 25 4.5 Concept Instantiation ................................... 29 v 4.6 Operations as Parameters................................. 36 4.7 Translator Optimizations ................................. 39 5 Validation and Evaluation.................................42 5.1 Broadcast Data Application................................ 45 5.2 Receive Data Application ................................. 50 5.3 Optimization Results.................................... 54 6 Conclusions .........................................57 Bibliography...........................................59 vi List of Tables 3.1 RESOLVE Operators.................................... 13 3.2 RESOLVE Keywords.................................... 14 3.3 RESOLVE Parameter modes ............................... 14 5.1 Memory Usage of Applications Compiled for the ATMEGA644 Processor . 56 vii List of Figures 4.1 Overview of Compiler Translation Process........................ 23 4.2 Variable Declaration in RESOLVE and C ........................ 24 4.3 Swap Operation....................................... 26 4.4 Arrays Representation in Memory ............................ 27 4.5 Steps Involved in Concept Instantiation ......................... 30 4.6 Representation of Nested Components - Stack of Stacks of Integers.......... 34 5.1 Execution Times for Basic and Lazy Array Initialization Strategies.......... 56 viii List of Listings 3.1 Declaration of Queue Concept in RESOLVE [48].................... 14 3.2 Queue Type Family Declaration [48]........................... 15 3.3 Queue Operations [48]................................... 15 3.4 Queue Realization declaration [48]............................ 16 3.5 Implementation of Queue Operations [48]........................ 17 3.6 Stack Concept [48]..................................... 18 3.7 Copying Capability Stack Enhancement [48]...................... 19 3.8 Copying capability realization [48]............................ 20 3.9 Stack Facility....................................... 21 3.10 Stack Facility with Enhancement............................ 21 4.1 RESOLVE Generic Datatypes Declared in C...................... 24 4.2 Translated C Code for Integer Variable Declaration in RESOLVE........... 24 4.3 Swap Operation in C Source Code............................ 25 4.4 Integer Array Declaration in RESOLVE........................ 27 4.5 Translated Integer Array Declaration in C Source Code............... 27 4.6 Using Swap on an Integer Array in RESOLVE.................... 28 4.7 Translated C code for Swap Operation on Integer Array............... 28 4.8 RESOLVE Concept Declaration.............................. 29 4.9 Record Declaration in RESOLVE............................. 29 4.10 Facility Declaration in RESOLVE............................. 29 4.11 Facility Declaration in RESOLVE............................. 30 4.12 Representation Structure in Translated C Code..................... 32 4.13 Int Stack Variable Declaration in RESOLVE..................... 32 4.14 Int Stack Variable Declaration in Translated C Code................ 32 4.15 Generated Initialization Function for Int Stack in C................. 33 4.16 Generic Stack Concept Declaration [48]......................... 33 4.17 Facility Declaration in RESOLVE............................. 33 4.18 Representation Structure for Nested Stack Components in C............. 35 4.19 Generated Initialization Functions for Nested Stack Components in C........ 35 4.20 Use of an Operation as a Parameter to a Realization in RESOLVE [48]........ 36 4.21 Facility Using Copy Enhancement of Stack in RESOLVE............... 37 4.22 Generated C Source Code for Obvious CC Realiz .................. 37 4.23 Generated C Source Code for Copy Stack Fac .................... 38 4.24 Translated C Code for Integer Variable Declaration in RESOLVE......... 39 4.25 Optimized Translated C code for Swap Operation on Integer Array........ 40 4.26 Array Initialization....................................