1 | \documentclass{llncs} |
---|
2 | |
---|
3 | \usepackage{amsfonts} |
---|
4 | \usepackage{amsmath} |
---|
5 | \usepackage{amssymb} |
---|
6 | \usepackage[english]{babel} |
---|
7 | \usepackage{color} |
---|
8 | \usepackage{fancybox} |
---|
9 | \usepackage{graphicx} |
---|
10 | \usepackage[colorlinks]{hyperref} |
---|
11 | \usepackage{hyphenat} |
---|
12 | \usepackage[utf8x]{inputenc} |
---|
13 | \usepackage{listings} |
---|
14 | \usepackage{mdwlist} |
---|
15 | \usepackage{microtype} |
---|
16 | \usepackage{stmaryrd} |
---|
17 | \usepackage{url} |
---|
18 | |
---|
19 | \renewcommand{\verb}{\lstinline} |
---|
20 | \def\lstlanguagefiles{lst-grafite.tex} |
---|
21 | \lstset{language=Grafite} |
---|
22 | |
---|
23 | \newlength{\mylength} |
---|
24 | \newenvironment{frametxt}% |
---|
25 | {\setlength{\fboxsep}{5pt} |
---|
26 | \setlength{\mylength}{\linewidth}% |
---|
27 | \addtolength{\mylength}{-2\fboxsep}% |
---|
28 | \addtolength{\mylength}{-2\fboxrule}% |
---|
29 | \Sbox |
---|
30 | \minipage{\mylength}% |
---|
31 | \setlength{\abovedisplayskip}{0pt}% |
---|
32 | \setlength{\belowdisplayskip}{0pt}% |
---|
33 | }% |
---|
34 | {\endminipage\endSbox |
---|
35 | \[\fbox{\TheSbox}\]} |
---|
36 | |
---|
37 | \title{On the correctness of an assembler for the Intel MCS-51 microprocessor\thanks{The project CerCo acknowledges the financial support of the Future and Emerging Technologies (FET) programme within the Seventh Framework Programme for Research of the European Commission, under FET-Open grant number: 243881}} |
---|
38 | \author{Dominic P. Mulligan \and Claudio Sacerdoti Coen} |
---|
39 | \institute{Dipartimento di Scienze dell'Informazione, Universit\'a di Bologna} |
---|
40 | |
---|
41 | \bibliographystyle{splncs03} |
---|
42 | |
---|
43 | \begin{document} |
---|
44 | |
---|
45 | \maketitle |
---|
46 | |
---|
47 | \begin{abstract} |
---|
48 | We present a proof of correctness, in the Matita proof assistant, for an optimising assembler for the MCS-51 8-bit microcontroller. |
---|
49 | This assembler constitutes a major component of the EU's CerCo (`Certified Complexity') project. |
---|
50 | |
---|
51 | The efficient expansion of pseudoinstructions---particularly jumps---into MCS-51 machine instructions is complex. |
---|
52 | We isolate the decision making over how jumps should be expanded from the expansion process itself as much as possible using `policies'. |
---|
53 | This makes the proof of correctness for the assembler significantly more straightforward. |
---|
54 | |
---|
55 | We observe that it is impossible for an optimising assembler to preserve the semantics of every assembly program. |
---|
56 | Assembly language programs can manipulate concrete addresses in arbitrary ways. |
---|
57 | Our proof strategy contains a notion of `good addresses' and only assembly programs that use good addresses have their semantics preserved under assembly. |
---|
58 | Our strategy offers increased flexibility over the traditional approach of keeping addresses in assembly opaque. |
---|
59 | In particular, we may experiment with allowing the benign manipulation of addresses. |
---|
60 | \end{abstract} |
---|
61 | |
---|
62 | % ---------------------------------------------------------------------------- % |
---|
63 | % SECTION % |
---|
64 | % ---------------------------------------------------------------------------- % |
---|
65 | \section{Introduction} |
---|
66 | \label{sect.introduction} |
---|
67 | |
---|
68 | We consider the formalisation of an assembler for the Intel MCS-51 8-bit microprocessor in the Matita proof assistant~\cite{asperti:user:2007}. |
---|
69 | This formalisation forms a major component of the EU-funded CerCo (`Certified Complexity') project~\cite{cerco:2011}, concerning the construction and formalisation of a concrete complexity preserving compiler for a large subset of the C programming language. |
---|
70 | |
---|
71 | The MCS-51 dates from the early 1980s and is commonly called the 8051/8052. |
---|
72 | Despite the microprocessor's age, derivatives are still widely manufactured by a number of semiconductor foundries. |
---|
73 | As a result the processor is widely used, especially in embedded systems development, where well-tested, cheap, predictable microprocessors find their niche. |
---|
74 | |
---|
75 | The MCS-51 has a relative paucity of features compared to its more modern brethren, with the lack of any caching or pipelining features means that timing of execution is predictable, making the MCS-51 very attractive for CerCo's ends. |
---|
76 | Yet, as in most things, what one hand giveth the other taketh away, and the MCS-51's paucity of features---though an advantage in many respects---also quickly become a hindrance. |
---|
77 | In particular, the MCS-51 features a relatively minuscule series of memory spaces by modern standards. |
---|
78 | As a result our C compiler, to have any sort of hope of successfully compiling realistic programs for embedded devices, ought to produce `tight' machine code. |
---|
79 | |
---|
80 | For example, the MCS-51 features three unconditional jump instructions: \texttt{LJMP} and \texttt{SJMP}---`long jump' and `short jump' respectively---and an 11-bit oddity of the MCS-51, \texttt{AJMP}. |
---|
81 | Each of these three instructions expects arguments in different sizes and behaves in markedly different ways: \texttt{SJMP} may only perform a `local jump'; \texttt{LJMP} may jump to any address in the MCS-51's memory space and \texttt{AJMP} may jump to any address in the current memory page. |
---|
82 | Consequently, the size of each opcode is different, and to squeeze as much code as possible into the MCS-51's limited code memory, the smallest possible opcode that will suffice should be selected. |
---|
83 | This is a well known problem to assembler writers, often referred to as `branch displacement'. |
---|
84 | |
---|
85 | Branch displacement is not a simple problem to solve and requires the implementation of an optimising assembler. |
---|
86 | Labels, conditional jumps to labels, a program preamble containing global data and a \texttt{MOV} instruction for moving this global data into the MCS-51's one 16-bit register all feature in our assembly language. |
---|
87 | We simplify the process by assuming that all assembly programs are pre-linked (i.e. we do not formalise a linker). |
---|
88 | The assembler expands pseudoinstructions into MCS-51 machine code, but this assembly process is not trivial, for numerous reasons. |
---|
89 | For example, our conditional jumps to labels behave differently from their machine code counterparts. |
---|
90 | At the machine code level, all conditional jumps are `short', limiting their range. |
---|
91 | However, at the assembly level, conditional jumps may jump to a label that appears anywhere in the program, significantly liberalising the use of conditional jumps. |
---|
92 | |
---|
93 | Yet, the situation is even more complex than having to expand pseudoinstructions correctly. |
---|
94 | In particular, when formalising the assembler, we must make sure that the assembly process does not change the timing characteristics of an assembly program for two reasons. |
---|
95 | |
---|
96 | First, the semantics of some functions of the MCS-51, notably I/O, depend on the microprocessor's clock. |
---|
97 | Changing how long a particular program takes to execute can affect the semantics of a program. |
---|
98 | This is undesirable. |
---|
99 | |
---|
100 | Second, CerCo imposes a cost model on C programs or, more specifically, on simple blocks of instructions. |
---|
101 | This cost model is induced by the compilation process itself, and its non-compositional nature allows us to assign different costs to identical blocks of instructions depending on how they are compiled. |
---|
102 | In short, we aim to obtain a very precise costing for a program by embracing the compilation process, not ignoring it. |
---|
103 | This, however, complicates the proof of correctness for the compiler proper. |
---|
104 | In each translation pass from intermediate language to intermediate language, we must prove that both the meaning and concrete complexity characteristics of the program are preserved. |
---|
105 | This also applies for the translation from assembly language to machine code. |
---|
106 | |
---|
107 | Naturally, this raises a question: how do we assign an \emph{accurate} cost to a pseudoinstruction? |
---|
108 | As mentioned, conditional jumps at the assembly level can jump to a label appearing anywhere in the program. |
---|
109 | However, at the machine code level, conditional jumps are limited to jumping `locally', using a measly byte offset. |
---|
110 | To translate a jump to a label, a single conditional jump pseudoinstruction may be translated into a block of three real instructions as follows (here, \texttt{JZ} is `jump if accumulator is zero'): |
---|
111 | {\small{ |
---|
112 | \begin{displaymath} |
---|
113 | \begin{array}{r@{\quad}l@{\;\;}l@{\qquad}c@{\qquad}l@{\;\;}l} |
---|
114 | & \mathtt{JZ} & \mathtt{label} & & \mathtt{JZ} & \text{size of \texttt{SJMP} instruction} \\ |
---|
115 | & \ldots & & \text{translates to} & \mathtt{SJMP} & \text{size of \texttt{LJMP} instruction} \\ |
---|
116 | \mathtt{label:} & \mathtt{MOV} & \mathtt{A}\;\;\mathtt{B} & \Longrightarrow & \mathtt{LJMP} & \text{address of \textit{label}} \\ |
---|
117 | & & & & \ldots & \\ |
---|
118 | & & & & \mathtt{MOV} & \mathtt{A}\;\;\mathtt{B} |
---|
119 | \end{array} |
---|
120 | \end{displaymath}}} |
---|
121 | Here, if \texttt{JZ} fails, we fall through to the \texttt{SJMP} which jumps over the \texttt{LJMP}. |
---|
122 | Naturally, if \texttt{label} is close enough, a conditional jump pseudoinstruction is mapped directly to a conditional jump machine instruction; the above translation only applies if \texttt{label} is not sufficiently local. |
---|
123 | We address the calculation of whether a label is indeed `close enough' for the simpler translation to be used below. |
---|
124 | |
---|
125 | Crucially, the above translation demonstrates the difficulty in predicting how many clock cycles a pseudoinstruction will take to execute. |
---|
126 | A conditional jump may be mapped to a single machine instruction or a block of three. |
---|
127 | Perhaps more insidious is the realisation that the number of cycles needed to execute the instructions in the two branches of a translated conditional jump may be different. |
---|
128 | Depending on the particular MCS-51 derivative at hand, an \texttt{SJMP} could in theory take a different number of clock cycles to execute than an \texttt{LJMP}. |
---|
129 | These issues must also be dealt with in order to prove that the translation pass preserves the concrete complexity of assembly code, and that the semantics of a program using the MCS-51's I/O facilities does not change. |
---|
130 | We address this problem by parameterising the semantics over a cost model. |
---|
131 | We prove the preservation of concrete complexity only for the program-dependent cost model induced by the optimisation. |
---|
132 | |
---|
133 | Yet one more question remains: how do we decide whether to expand a jump into an \texttt{SJMP} or an \texttt{LJMP}? |
---|
134 | To understand, again, why this problem is not trivial, consider the following snippet of assembly code: |
---|
135 | {\small{ |
---|
136 | \begin{displaymath} |
---|
137 | \begin{array}{r@{\qquad}r@{\quad}l@{\;\;}l@{\qquad}l} |
---|
138 | \text{1:} & \mathtt{(0x000)} & \texttt{LJMP} & \texttt{0x100} & \text{\texttt{;; Jump forward 256.}} \\ |
---|
139 | \text{2:} & \mathtt{...} & \mathtt{...} & & \\ |
---|
140 | \text{3:} & \mathtt{(0x0FA)} & \texttt{LJMP} & \texttt{0x100} & \text{\texttt{;; Jump forward 256.}} \\ |
---|
141 | \text{4:} & \mathtt{...} & \mathtt{...} & & \\ |
---|
142 | \text{5:} & \mathtt{(0x100)} & \texttt{LJMP} & \texttt{-0x100} & \text{\texttt{;; Jump backward 256.}} \\ |
---|
143 | \end{array} |
---|
144 | \end{displaymath}}} |
---|
145 | We observe that $100_{16} = 256_{10}$, and lies \emph{just} outside the range expressible in an 8-bit byte (0--255). |
---|
146 | |
---|
147 | As our example shows, given an occurrence $l$ of an \texttt{LJMP} instruction, it may be possible to shrink $l$ to an occurrence of an \texttt{SJMP}---consuming fewer bytes of code memory---provided we can shrink any \texttt{LJMP}s that exist between $l$ and its target location. |
---|
148 | In particular, if we wish to shrink the \texttt{LJMP} occurring at line 1, then we must shrink the \texttt{LJMP} occurring at line 3. |
---|
149 | However, to shrink the \texttt{LJMP} occurring at line 3 we must also shrink the \texttt{LJMP} occurring at line 5, and \emph{vice versa}. |
---|
150 | |
---|
151 | Further, consider what happens if, instead of appearing at memory address \texttt{0x100}, the instruction at line 5 instead appeared \emph{just} beyond the size of code memory, and all other memory addresses were shifted accordingly. |
---|
152 | Now, in order to be able to successfully fit our program into the MCS-51's limited code memory, we are \emph{obliged} to shrink the \texttt{LJMP} occurring at line 5. |
---|
153 | That is, the shrinking process is not just related to the optimisation of generated machine code but also the completeness of the assembler itself. |
---|
154 | |
---|
155 | How we went about resolving this problem affected the shape of our proof of correctness for the whole assembler in a rather profound way. |
---|
156 | We first attempted to synthesise a solution bottom up: starting with no solution, we gradually refine a solution using the same functions that implement the jump expansion process. |
---|
157 | Using this technique, solutions can fail to exist, and the proof of correctness for the assembler quickly descends into a diabolical quagmire. |
---|
158 | |
---|
159 | Abandoning this attempt, we instead split the `policy'---the decision over how any particular jump should be expanded---from the implementation that actually expands assembly programs into machine code. |
---|
160 | Assuming the existence of a correct policy, we proved the implementation of the assembler correct. |
---|
161 | Further, we proved that the assembler fails to assemble an assembly program if and only if a correct policy does not exist. |
---|
162 | This is achieved by means of dependent types: the assembly function is total over a program, a policy and the proof that the policy is correct for that program. |
---|
163 | |
---|
164 | Policies do not exist in only a limited number of circumstances: namely, if a pseudoinstruction attempts to jump to a label that does not exist, or the program is too large to fit in code memory, even after shrinking jumps according to the best policy. |
---|
165 | The first circumstance is an example of a serious compiler error, as an ill-formed assembly program was generated, and does not (and should not) count as a mark against the completeness of the assembler. |
---|
166 | |
---|
167 | The rest of this paper is a detailed description of our proof that is, in part, still a work in progress. |
---|
168 | |
---|
169 | % ---------------------------------------------------------------------------- % |
---|
170 | % SECTION % |
---|
171 | % ---------------------------------------------------------------------------- % |
---|
172 | \subsection{Overview of the paper} |
---|
173 | \label{subsect.overview.of.the.paper} |
---|
174 | In Section~\ref{sect.matita} we provide a brief overview of the Matita proof assistant for the unfamiliar reader. |
---|
175 | In Section~\ref{sect.the.proof} we discuss the design and implementation of the proof proper. |
---|
176 | In Section~\ref{sect.conclusions} we conclude. |
---|
177 | |
---|
178 | % ---------------------------------------------------------------------------- % |
---|
179 | % SECTION % |
---|
180 | % ---------------------------------------------------------------------------- % |
---|
181 | \section{Matita} |
---|
182 | \label{sect.matita} |
---|
183 | |
---|
184 | Matita is a proof assistant based on a variant of the Calculus of (Co)inductive Constructions~\cite{asperti:user:2007}. |
---|
185 | In particular, it features dependent types that we heavily exploit in the formalisation. |
---|
186 | The syntax of the statements and definitions in the paper should be self-explanatory, at least to those exposed to dependent type theory. |
---|
187 | We only remark the use of of `$\mathtt{?}$' or `$\mathtt{\ldots}$' for omitting single terms or sequences of terms to be inferred automatically by the system, respectively. |
---|
188 | Those that are not inferred are left to the user as proof obligations. |
---|
189 | Pairs are denoted with angular brackets, $\langle-, -\rangle$. |
---|
190 | |
---|
191 | Matita features a liberal system of coercions. |
---|
192 | It is possible to define a uniform coercion $\lambda x.\langle x,?\rangle$ from every type $T$ to the dependent product $\Sigma x:T.P~x$. |
---|
193 | The coercion opens a proof obligation that asks the user to prove that $P$ holds for $x$. |
---|
194 | When a coercion must be applied to a complex term (a $\lambda$-abstraction, a local definition, or a case analysis), the system automatically propagates the coercion to the sub-terms |
---|
195 | For instance, to apply a coercion to force $\lambda x.M : A \to B$ to have type $\forall x:A.\Sigma y:B.P~x~y$, the system looks for a coercion from $M: B$ to $\Sigma y:B.P~x~y$ in a context augmented with $x:A$. |
---|
196 | This is significant when the coercion opens a proof obligation, as the user will be presented with multiple, but simpler proof obligations in the correct context. |
---|
197 | In this way, Matita supports the ``Russell'' proof methodology developed by Sozeau in~\cite{sozeau:subset:2006}, with an implementation that is lighter and more tightly integrated with the system than that of Coq. |
---|
198 | |
---|
199 | % ---------------------------------------------------------------------------- % |
---|
200 | % SECTION % |
---|
201 | % ---------------------------------------------------------------------------- % |
---|
202 | \section{The proof} |
---|
203 | \label{sect.the.proof} |
---|
204 | |
---|
205 | \subsection{The assembler and semantics of machine code} |
---|
206 | \label{subsect.the.assembler.and.semantics.of.machine.code} |
---|
207 | |
---|
208 | Our emulator centres around a \texttt{Status} record, describing the microprocessor's state. |
---|
209 | This record contains fields corresponding to the microprocessor's program counter, registers, and so on. |
---|
210 | At the machine code level, code memory is implemented as a compact trie of bytes, addressed by the program counter. |
---|
211 | We parameterise \texttt{Status} records by this representation as a few technical tasks manipulating statuses are made simpler using this approach, as well as permitting a modicum of abstraction. |
---|
212 | |
---|
213 | We may execute a single step of a machine code program using the \texttt{execute\_1} function, which returns an updated \texttt{Status}: |
---|
214 | \begin{lstlisting} |
---|
215 | definition execute_1: $\forall$cm. Status cm $\rightarrow$ Status cm := $\ldots$ |
---|
216 | \end{lstlisting} |
---|
217 | The function \texttt{execute} allows one to execute an arbitrary, but fixed (due to Matita's normalisation requirement) number of steps of a program. |
---|
218 | Execution proceeds by a case analysis on the instruction fetched from code memory using the program counter of the input \texttt{Status} record. |
---|
219 | |
---|
220 | Naturally, assembly programs have analogues. |
---|
221 | The counterpart of the \texttt{Status} record is \texttt{PseudoStatus}. |
---|
222 | Instead of code memory being implemented as tries of bytes, code memory is here implemented as lists of pseudoinstructions, and program counters are merely indices into this list. |
---|
223 | Both \texttt{Status} and \texttt{PseudoStatus} are specialisations of the same \texttt{PreStatus} record, parametric in the representation of code memory. |
---|
224 | This allows us to share some code that is common to both records (for instance, `setter' and `getter' functions). |
---|
225 | |
---|
226 | Our analogue of \texttt{execute\_1} is \texttt{execute\_1\_pseudo\_instruction}: |
---|
227 | \begin{lstlisting} |
---|
228 | definition execute_1_pseudo_instruction: |
---|
229 | (Word $\rightarrow$ nat $\times$ nat) $\rightarrow$ $\forall$cm. PseudoStatus cm $\rightarrow$ PseudoStatus cm := $\ldots$ |
---|
230 | \end{lstlisting} |
---|
231 | Notice, here, that the emulation function for assembly programs takes an additional argument. |
---|
232 | This is a function that maps program counters (at the assembly level) to pairs of natural numbers representing the number of clock ticks that the pseudoinstruction needs to execute, post expansion. |
---|
233 | We call this function a \emph{costing}, and note that the costing is induced by the particular strategy we use to expand pseudoinstructions. |
---|
234 | If we change how we expand conditional jumps to labels, for instance, then the costing needs to change, hence \texttt{execute\_1\_pseudo\_instruction}'s parametricity in the costing. |
---|
235 | |
---|
236 | The costing returns \emph{pairs} of natural numbers because, in the case of expanding conditional jumps to labels, the expansion of the `true branch' and `false branch' may differ in execution time. |
---|
237 | This timing information is used inside \texttt{execute\_1\_pseudo\_instruction} to update the clock of the \texttt{PseudoStatus}. |
---|
238 | During the proof of correctness of the assembler we relate the clocks of \texttt{Status}es and \texttt{PseudoStatus}es for the policy induced by the cost model and optimisations. |
---|
239 | |
---|
240 | The assembler, mapping programs consisting of lists of pseudoinstructions to lists of bytes, operates in a mostly straightforward manner. |
---|
241 | To a degree of approximation the assembler, on an assembly program consisting of $n$ pseudoinstructions $\mathtt{P_i}$ for $1 \leq i \leq n$, works as in the following diagram (we use $-^{*}$ to denote a combined map and flatten operation): |
---|
242 | \begin{displaymath} |
---|
243 | [\mathtt{P_1}, \ldots \mathtt{P_n}] \xrightarrow{\left(\mathtt{P_i} \xrightarrow{\mbox{\fontsize{7}{9}\selectfont$\mathtt{expand\_pseudo\_instruction}$}} \mathtt{[I^1_i, \ldots I^q_i]} \xrightarrow{\mbox{\fontsize{7}{9}\selectfont$\mathtt{~~~~~~~~assembly1^{*}~~~~~~~~}$}} \mathtt{[0110]}\right)^{*}} \mathtt{[010101]} |
---|
244 | \end{displaymath} |
---|
245 | Here $\mathtt{I^j_i}$ for $1 \leq j \leq q$ are the $q$ machine code instructions obtained by expanding, with \texttt{expand\_pseudo\_instruction}, a single pseudoinstruction $P_i$. |
---|
246 | Each machine code instruction $\mathtt{I^i_j}$ is then assembled, using the \texttt{assembly1} function, into a list of bytes. |
---|
247 | This process is iterated for each pseudoinstruction, before the lists are flattened into a single bit list representation of the original assembly program. |
---|
248 | |
---|
249 | % ---------------------------------------------------------------------------- % |
---|
250 | % SECTION % |
---|
251 | % ---------------------------------------------------------------------------- % |
---|
252 | \subsection{Correctness of the assembler with respect to fetching} |
---|
253 | \label{subsect.total.correctness.of.the.assembler} |
---|
254 | |
---|
255 | Throughout the proof of correctness for assembly we assume that policies are bifurcated into two functions: \texttt{sigma} mapping \texttt{Word} to \texttt{Word} and \texttt{policy} mapping \texttt{Word} to \texttt{bool}. |
---|
256 | For our purposes, \texttt{sigma} is most interesting, as it maps pseudo program counters to program counters; \texttt{policy} is merely a technical device used in jump expansion. |
---|
257 | |
---|
258 | Using our policies, we now work toward proving the total correctness of the assembler. |
---|
259 | By `total correctness', we mean that the assembly process never fails when provided with a good policy and that the process does not change the semantics of a certain class of well behaved assembly programs. |
---|
260 | By `good policy' we mean that policies provided to us will keep a lockstep correspondence between addresses at the assembly level and addresses at the machine code level: |
---|
261 | \begin{displaymath} |
---|
262 | \texttt{sigma}(\texttt{ppc} + 1) = \texttt{pc} + \texttt{current\_instruction\_size} |
---|
263 | \end{displaymath} |
---|
264 | along with some other technical properties related to program counters falling within the bounds of our programs. |
---|
265 | We assume the correctness of the policies given to us using a function, \texttt{sigma\_policy\_specification} that we take in input, when needed. |
---|
266 | |
---|
267 | We expand pseudoinstructions using the function \texttt{expand\_pseudo\_instruction}. |
---|
268 | This takes an assembly program (consisting of a list of pseudoinstructions), a policy for the program, a map detailing the physical addresses of data labels from the pseudo program's preamble, and the pseudoinstruction to be expanded. |
---|
269 | It returns a list of instructions, corresponding to the expanded pseudoinstruction referenced by the pointer. |
---|
270 | Execution proceeds by case analysis on the pseudoinstruction given as input. |
---|
271 | The policy, \texttt{sigma}, is used to decide how to expand \texttt{Call}s, \texttt{Jmp}s and conditional jumps. |
---|
272 | \begin{lstlisting} |
---|
273 | definition expand_pseudo_instruction: |
---|
274 | $\forall$lookup_labels: Identifier $\rightarrow$ Word. |
---|
275 | $\forall$sigma: Word $\rightarrow$ Word. |
---|
276 | $\forall$policy: Word $\rightarrow$ bool. |
---|
277 | Word $\rightarrow$ (Identifier $\rightarrow$ Word) $\rightarrow$ |
---|
278 | pseudo_instruction $\rightarrow$ list instruction := ... |
---|
279 | \end{lstlisting} |
---|
280 | |
---|
281 | We can express the following lemma, expressing the correctness of the assembly function (slightly simplified): |
---|
282 | \begin{lstlisting} |
---|
283 | lemma assembly_ok: |
---|
284 | $\forall$program: pseudo_assembly_program. |
---|
285 | $\forall$sigma: Word $\rightarrow$ Word. |
---|
286 | $\forall$policy: Word $\rightarrow$ bool. |
---|
287 | $\forall$sigma_policy_witness. |
---|
288 | $\forall$assembled. |
---|
289 | $\forall$costs': BitVectorTrie costlabel 16. |
---|
290 | let $\langle$preamble, instr_list$\rangle$ := program in |
---|
291 | let $\langle$labels, costs$\rangle$ := create_label_cost_map instr_list in |
---|
292 | $\langle$assembled,costs'$\rangle$ = assembly program sigma policy $\rightarrow$ |
---|
293 | let cmem := load_code_memory assembled in |
---|
294 | $\forall$ppc. |
---|
295 | let $\langle$pi, newppc$\rangle$ := fetch_pseudo_instruction instr_list ppc in |
---|
296 | let $\langle$len,assembled$\rangle$ := assembly_1_pseudoinstruction $\ldots$ ppc $\ldots$ pi in |
---|
297 | let pc := sigma ppc in |
---|
298 | let pc_plus_len := add $\ldots$ pc (bitvector_of_nat $\ldots$ len) in |
---|
299 | encoding_check cmem pc pc_plus_len assembled $\wedge$ |
---|
300 | sigma newppc = add $\ldots$ pc (bitvector_of_nat $\ldots$ len). |
---|
301 | \end{lstlisting} |
---|
302 | Here, \texttt{encoding\_check} is a recursive function that checks that assembled machine code is correctly stored in code memory. |
---|
303 | Suppose also we assemble our program \texttt{p} in accordance with a policy \texttt{sigma} to obtain \texttt{assembled}, loading the assembled program into code memory \texttt{cmem}. |
---|
304 | Then, for every pseudoinstruction \texttt{pi}, pseudo program counter \texttt{ppc} and new pseudo program counter \texttt{newppc}, such that we obtain \texttt{pi} and \texttt{newppc} from fetching a pseudoinstruction at \texttt{ppc}, we check that assembling this pseudoinstruction produces the correct number of machine code instructions, and that the new pseudo program counter \texttt{ppc} has the value expected of it. |
---|
305 | |
---|
306 | Lemma \texttt{fetch\_assembly} establishes that the \texttt{fetch} and \texttt{assembly1} functions interact correctly. |
---|
307 | The \texttt{fetch} function, as its name implies, fetches the instruction indexed by the program counter in the code memory, while \texttt{assembly1} maps a single instruction to its byte encoding: |
---|
308 | \begin{lstlisting} |
---|
309 | lemma fetch_assembly: |
---|
310 | $\forall$pc: Word. |
---|
311 | $\forall$i: instruction. |
---|
312 | $\forall$code_memory: BitVectorTrie Byte 16. |
---|
313 | $\forall$assembled: list Byte. |
---|
314 | assembled = assembly1 i $\rightarrow$ |
---|
315 | let len := length $\ldots$ assembled in |
---|
316 | let pc_plus_len := add $\ldots$ pc (bitvector_of_nat $\ldots$ len) in |
---|
317 | encoding_check code_memory pc pc_plus_len assembled $\rightarrow$ |
---|
318 | let $\langle$instr, pc', ticks$\rangle$ := fetch code_memory pc in |
---|
319 | (eq_instruction instr i $\wedge$ |
---|
320 | eqb ticks (ticks_of_instruction instr) $\wedge$ |
---|
321 | eq_bv $\ldots$ pc' pc_plus_len) = true. |
---|
322 | \end{lstlisting} |
---|
323 | In particular, we read \texttt{fetch\_assembly} as follows. |
---|
324 | Given an instruction, \texttt{i}, we first assemble the instruction to obtain \texttt{assembled}, checking that the assembled instruction was stored in code memory correctly. |
---|
325 | Fetching from code memory, we obtain a tuple consisting of the instruction, new program counter, and the number of ticks this instruction will take to execute. |
---|
326 | We finally check that the fetched instruction is the same instruction that we began with, and the number of ticks this instruction will take to execute is the same as the result returned by a lookup function, \texttt{ticks\_of\_instruction}, devoted to tracking this information. |
---|
327 | Or, in plainer words, assembling and then immediately fetching again gets you back to where you started. |
---|
328 | |
---|
329 | Lemma \texttt{fetch\_assembly\_pseudo} (slightly simplified, here) is obtained by composition of \texttt{expand\_pseudo\_instruction} and \texttt{assembly\_1\_pseudoinstruction}: |
---|
330 | \begin{lstlisting} |
---|
331 | lemma fetch_assembly_pseudo: |
---|
332 | $\forall$program: pseudo_assembly_program. |
---|
333 | $\forall$sigma: Word $\rightarrow$ Word. |
---|
334 | $\forall$policy: Word $\rightarrow$ bool. |
---|
335 | $\forall$ppc. |
---|
336 | $\forall$code_memory. |
---|
337 | let $\langle$preamble, instr_list$\rangle$ := program in |
---|
338 | let pi := $\pi_1$ (fetch_pseudo_instruction instr_list ppc) in |
---|
339 | let pc := sigma ppc in |
---|
340 | let instrs := expand_pseudo_instruction $\ldots$ sigma policy ppc $\ldots$ pi in |
---|
341 | let $\langle$l, a$\rangle$ := assembly_1_pseudoinstruction $\ldots$ sigma policy ppc $\ldots$ pi in |
---|
342 | let pc_plus_len := add $\ldots$ pc (bitvector_of_nat $\ldots$ l) in |
---|
343 | encoding_check code_memory pc pc_plus_len a $\rightarrow$ |
---|
344 | fetch_many code_memory pc_plus_len pc instructions. |
---|
345 | \end{lstlisting} |
---|
346 | Here, \texttt{l} is the number of machine code instructions the pseudoinstruction at hand has been expanded into. |
---|
347 | We assemble a single pseudoinstruction with \texttt{assembly\_1\_pseudoinstruction}, which internally calls \texttt{jump\_expansion} and \texttt{expand\_pseudo\_instruction}. |
---|
348 | The function \texttt{fetch\_many} fetches multiple machine code instructions from code memory and performs some routine checks. |
---|
349 | |
---|
350 | Intuitively, Lemma \texttt{fetch\_assembly\_pseudo} can be read as follows. |
---|
351 | Suppose we expand the pseudoinstruction at \texttt{ppc} with the policy decision \texttt{sigma}, obtaining the list of machine code instructions \texttt{instrs}. |
---|
352 | Suppose we also assemble the pseudoinstruction at \texttt{ppc} to obtain \texttt{a}, a list of bytes. |
---|
353 | Then, we check with \texttt{fetch\_many} that the number of machine instructions that were fetched matches the number of instruction that \texttt{expand\_pseudo\_instruction} expanded. |
---|
354 | |
---|
355 | The final lemma in this series is \texttt{fetch\_assembly\_pseudo2} that combines the Lemma \texttt{fetch\_assembly\_pseudo} with the correctness of the functions that load object code into the processor's memory. |
---|
356 | Again, we slightly simplify: |
---|
357 | \begin{lstlisting} |
---|
358 | lemma fetch_assembly_pseudo2: |
---|
359 | $\forall$program. |
---|
360 | $\forall$sigma. |
---|
361 | $\forall$policy. |
---|
362 | $\forall$sigma_policy_specification_witness. |
---|
363 | $\forall$ppc. |
---|
364 | let $\langle$preamble, instr_list$\rangle$ := program in |
---|
365 | let $\langle$labels, costs$\rangle$ := create_label_cost_map instr_list in |
---|
366 | let $\langle$assembled, costs'$\rangle$ := $\pi_1$ $\ldots$ (assembly program sigma policy) in |
---|
367 | let cmem := load_code_memory assembled in |
---|
368 | let $\langle$pi, newppc$\rangle$ := fetch_pseudo_instruction instr_list ppc in |
---|
369 | let instructions := expand_pseudo_instruction $\ldots$ sigma ppc $\ldots$ pi in |
---|
370 | fetch_many cmem (sigma newppc) (sigma ppc) instructions. |
---|
371 | \end{lstlisting} |
---|
372 | |
---|
373 | Here we use $\pi_1 \ldots$ to eject out the existential witness from the Russell-typed function \texttt{assembly}. |
---|
374 | |
---|
375 | We read \texttt{fetch\_assembly\_pseudo2} as follows. |
---|
376 | Suppose we are able to successfully assemble an assembly program using \texttt{assembly} and produce a code memory, \texttt{cmem}. |
---|
377 | Then, fetching a pseudoinstruction from the pseudo code memory at address \texttt{ppc} corresponds to fetching a sequence of instructions from the real code memory using $\sigma$ to expand pseudoinstructions. |
---|
378 | The fetched sequence corresponds to the expansion, according to \texttt{sigma}, of the pseudoinstruction. |
---|
379 | |
---|
380 | At first, the lemmas appears to immediately imply the correctness of the assembler. |
---|
381 | However, this property is \emph{not} strong enough to establish that the semantics of an assembly program has been preserved by the assembly process since it does not establish the correspondence between the semantics of a pseudo-instruction and that of its expansion. |
---|
382 | In particular, the two semantics differ on instructions that \emph{could} directly manipulate program addresses. |
---|
383 | |
---|
384 | % ---------------------------------------------------------------------------- % |
---|
385 | % SECTION % |
---|
386 | % ---------------------------------------------------------------------------- % |
---|
387 | \subsection{Total correctness for `well behaved' assembly programs} |
---|
388 | \label{subsect.total.correctness.for.well.behaved.assembly.programs} |
---|
389 | |
---|
390 | The traditional approach to verifying the correctness of an assembler is to treat memory addresses as opaque structures that cannot be modified. |
---|
391 | This prevents assembly programs from performing any `dangerous', semantics breaking manipulations of memory addresses by making these programs simply unrepresentable in the source language. |
---|
392 | |
---|
393 | Here, we take a different approach to this problem: we trace memory locations (and, potentially, registers) that contain memory addresses. |
---|
394 | We then prove that only those assembly programs that use addresses in `safe' ways have their semantics preserved by the assembly process. |
---|
395 | We believe that this approach is more flexible when compared to the traditional approach, as in principle it allows us to introduce some permitted \emph{benign} manipulations of addresses that the traditional approach, using opaque addresses, cannot handle, therefore expanding the set of input programs that can be assembled correctly. |
---|
396 | |
---|
397 | However, with this approach we must detect (at run time) programs that manipulate addresses in well behaved ways, according to some approximation of well-behavedness. |
---|
398 | Second, we must compute statuses that correspond to pseudo-statuses. |
---|
399 | The contents of the program counter must be translated, as well as the contents of all traced locations, by applying the \texttt{sigma} map. |
---|
400 | Remaining memory cells are copied \emph{verbatim}. |
---|
401 | |
---|
402 | For instance, after a function call, the two bytes that form the return pseudo address are pushed on top of the stack, i.e. in internal RAM. |
---|
403 | This pseudo internal RAM corresponds to an internal RAM where the stack holds the real addresses after optimisation, and all the other values remain untouched. |
---|
404 | |
---|
405 | We use an \texttt{internal\_pseudo\_address\_map} to trace addresses of code memory addresses in internal RAM. |
---|
406 | The current code is parametric on the implementation of the map itself. |
---|
407 | \begin{lstlisting} |
---|
408 | axiom internal_pseudo_address_map: Type[0]. |
---|
409 | \end{lstlisting} |
---|
410 | |
---|
411 | The \texttt{low\_internal\_ram\_of\_pseudo\_low\_internal\_ram} function converts the lower internal RAM of a \texttt{PseudoStatus} into the lower internal RAM of a \texttt{Status}. |
---|
412 | A similar function exists for higher internal RAM. |
---|
413 | Note that both RAM segments are indexed using addresses 7-bits long. |
---|
414 | The function is currently axiomatised, and an associated set of axioms prescribe the behaviour of the function: |
---|
415 | \begin{lstlisting} |
---|
416 | axiom low_internal_ram_of_pseudo_low_internal_ram: |
---|
417 | internal_pseudo_address_map$\rightarrow$BitVectorTrie Byte 7$\rightarrow$BitVectorTrie Byte 7. |
---|
418 | \end{lstlisting} |
---|
419 | |
---|
420 | Next, we are able to translate \texttt{PseudoStatus} records into \texttt{Status} records using \texttt{status\_of\_pseudo\_status}. |
---|
421 | Translating a \texttt{PseudoStatus}'s code memory requires we expand pseudoinstructions and then assemble to obtain a trie of bytes. |
---|
422 | This never fails, providing that our policy is correct: |
---|
423 | \begin{lstlisting} |
---|
424 | definition status_of_pseudo_status: |
---|
425 | internal_pseudo_address_map $\rightarrow$ $\forall$pap. $\forall$ps: PseudoStatus pap. |
---|
426 | $\forall$sigma: Word $\rightarrow$ Word. $\forall$policy: Word $\rightarrow$ bool. |
---|
427 | Status (code_memory_of_pseudo_assembly_program pap sigma policy) |
---|
428 | \end{lstlisting} |
---|
429 | |
---|
430 | The \texttt{next\_internal\_pseudo\_address\_map} function is responsible for run time monitoring of the behaviour of assembly programs, in order to detect well behaved ones. |
---|
431 | It returns a map that traces memory addresses in internal RAM after execution of the next pseudoinstruction, failing when the instruction tampers with memory addresses in unanticipated (but potentially correct) ways. |
---|
432 | It thus decides the membership of a strict subset of the set of well behaved programs. |
---|
433 | \begin{lstlisting} |
---|
434 | definition next_internal_pseudo_address_map: internal_pseudo_address_map |
---|
435 | $\rightarrow$ PseudoStatus $\rightarrow$ option internal_pseudo_address_map |
---|
436 | \end{lstlisting} |
---|
437 | Note, if we wished to allow `benign manipulations' of addresses, it would be this function that needs to be changed. |
---|
438 | |
---|
439 | The function \texttt{ticks\_of} computes how long---in clock cycles---a pseudoinstruction will take to execute when expanded in accordance with a given policy. |
---|
440 | The function returns a pair of natural numbers, needed for recording the execution times of each branch of a conditional jump. |
---|
441 | \begin{lstlisting} |
---|
442 | axiom ticks_of: |
---|
443 | $\forall$p:pseudo_assembly_program. policy p $\rightarrow$ Word $\rightarrow$ nat $\times$ nat := $\ldots$ |
---|
444 | \end{lstlisting} |
---|
445 | |
---|
446 | Finally, we are able to state and prove our main theorem. |
---|
447 | This relates the execution of a single assembly instruction and the execution of (possibly) many machine code instructions, as long as we are able to track memory addresses properly: |
---|
448 | \begin{lstlisting} |
---|
449 | theorem main_thm: |
---|
450 | $\forall$M, M': internal_pseudo_address_map. |
---|
451 | $\forall$program: pseudo_assembly_program. |
---|
452 | let $\langle$preamble, instr_list$\rangle$ := program in |
---|
453 | $\forall$is_well_labelled: is_well_labelled_p instr_list. |
---|
454 | $\forall$sigma: Word $\rightarrow$ Word. |
---|
455 | $\forall$policy: Word $\rightarrow$ bool. |
---|
456 | $\forall$sigma_policy_specification_witness. |
---|
457 | $\forall$ps: PseudoStatus program. |
---|
458 | $\forall$program_counter_in_bounds. |
---|
459 | next_internal_pseudo_address_map M program ps = Some $\ldots$ M' $\rightarrow$ |
---|
460 | $\exists$n. execute n $\ldots$ (status_of_pseudo_status M $\ldots$ ps sigma policy) = |
---|
461 | status_of_pseudo_status M' $\ldots$ (execute_1_pseudo_instruction |
---|
462 | (ticks_of program sigma policy) program ps) sigma policy. |
---|
463 | \end{lstlisting} |
---|
464 | The statement is standard for forward simulation, but restricted to \texttt{PseudoStatuses} \texttt{ps} whose next instruction to be executed is well-behaved with respect to the \texttt{internal\_pseudo\_address\_map} \texttt{M}. |
---|
465 | Further, we explicitly requires proof that our policy is correct and the pseudo program counter lies within the bounds of the program. |
---|
466 | Theorem \texttt{main\_thm} establishes the total correctness of the assembly process and can simply be lifted to the forward simulation of an arbitrary number of well behaved steps on the assembly program. |
---|
467 | |
---|
468 | % ---------------------------------------------------------------------------- % |
---|
469 | % SECTION % |
---|
470 | % ---------------------------------------------------------------------------- % |
---|
471 | \section{Conclusions} |
---|
472 | \label{sect.conclusions} |
---|
473 | |
---|
474 | We are proving the total correctness of an assembler for MCS-51 assembly language. |
---|
475 | In particular, our assembly language featured labels, arbitrary conditional and unconditional jumps to labels, global data and instructions for moving this data into the MCS-51's single 16-bit register. |
---|
476 | Expanding these pseudoinstructions into machine code instructions is not trivial, and the proof that the assembly process is `correct', in that the semantics of a subset of assembly programs are not changed is complex. |
---|
477 | Further, we have observed the `shocking' fact that any optimising assembler cannot preserve the semantics of all assembly programs. |
---|
478 | |
---|
479 | The formalisation is a key component of the CerCo project, which aims to produce a verified concrete complexity preserving compiler for a large subset of the C programming language. |
---|
480 | The verified assembler, complete with the underlying formalisation of the semantics of MCS-51 machine code (described fully in~\cite{mulligan:executable:2011}), will form the bedrock layer upon which the rest of the CerCo project will build its verified compiler platform. |
---|
481 | However, further work is needed. |
---|
482 | In particular, as it stands, the code produced by the prototype CerCo C compiler does not fall into the `semantics preserving' subset of assembly programs for our assembler. |
---|
483 | This is because the MCS-51 features a small stack space, and a larger stack is customarily manually emulated in external RAM. |
---|
484 | As a result, the majority of programs feature slices of memory addresses and program counters being moved in-and-out of external RAM via the registers, simulating the stack mechanism. |
---|
485 | At the moment, this movement is not tracked by \texttt{internal\_pseudo\_address\_map}, which only tracks the movement of memory addresses in low internal RAM. |
---|
486 | We leave extending this tracking of memory addresses throughout the whole of the MCS-51's address spaces as future work. |
---|
487 | |
---|
488 | It is interesting to compare our work to an `industrial grade' assembler for the MCS-51: SDCC~\cite{sdcc:2011}. |
---|
489 | SDCC is the only open source C compiler that targets the MCS-51 instruction set. |
---|
490 | It appears that all pseudojumps in SDCC assembly are expanded to \texttt{LJMP} instructions, the worst possible jump expansion policy from an efficiency point of view. |
---|
491 | Note that this policy is the only possible policy \emph{in theory} that can preserve the semantics of an assembly program during the assembly process. |
---|
492 | However, this comes at the expense of assembler completeness: the generated program may be too large to fit into code memory. |
---|
493 | In this respect, there is a trade-off between the completeness of the assembler and the efficiency of the assembled program. |
---|
494 | The definition and proof of a complete, optimal (in the sense that object code size is minimised) and correct jump expansion policy is ongoing work. |
---|
495 | |
---|
496 | Aside from their application in verified compiler projects such as CerCo and CompCert, verified assemblers such as ours could also be applied to the verification of operating system kernels. |
---|
497 | Of particular note is the verified seL4 kernel~\cite{klein:sel4:2009,klein:sel4:2010}. |
---|
498 | This verification explicitly assumes the existence of, amongst other things, a trustworthy assembler and compiler. |
---|
499 | |
---|
500 | Note that both CompCert and the seL4 formalisation assume the existence of `trustworthy' assemblers. |
---|
501 | Our observation that an optimising assembler cannot preserve the semantics of every assembly program may have important consequences for these projects. |
---|
502 | If CompCert chooses to assume the existence of an optimising assembler, then care should be made to ensure that any assembly program produced by the CompCert compiler falls into the subset of programs that have a hope of having their semantics preserved by an optimising assembler. |
---|
503 | |
---|
504 | Our formalisation exploits dependent types in different ways and for multiple |
---|
505 | purposes. The first purpose is to reduce potential errors in the formalisation |
---|
506 | of the microprocessor. In particular, |
---|
507 | dependent types are used to constraint the size of bit-vectors and |
---|
508 | tries that represent memory quantities and memory areas respectively. |
---|
509 | They are also used as explained in~\cite{mulligan:executable:2011}. |
---|
510 | to simulate polymorphic variants in Matita. Polymorphic variants nicely |
---|
511 | capture the absolutely unorthogonal instruction set of the MCS-51 where every |
---|
512 | opcode must accept its own subset of the 11 addressing mode of the processor. |
---|
513 | |
---|
514 | The second purpose is to single out the sources of incompleteness. By |
---|
515 | abstracting our functions over the dependent type of correct policies, we were |
---|
516 | able to manifest the fact that the compiler never refuses to compile a program |
---|
517 | where a correct policy exists. This also allowed to simplify the |
---|
518 | initial proof by dropping lemmas establishing that one function fails if and |
---|
519 | only if some other one does so. |
---|
520 | |
---|
521 | Finally, dependent types, together with Matita's liberal system of coercions, |
---|
522 | allow to simulate almost entirely in user space the proof methodology |
---|
523 | ``Russell'' of Sozeau~\cite{sozeau:subset:2006}. However, not every |
---|
524 | proof has been done this way: we only used this style to prove that a |
---|
525 | function satisfies a specification that only involves that function in a |
---|
526 | significant way. For example, it would be unnatural to see the proof that |
---|
527 | fetch and assembly commute as the specification of one of the two functions. |
---|
528 | |
---|
529 | \subsection{Related work} |
---|
530 | \label{subsect.related.work} |
---|
531 | |
---|
532 | % piton |
---|
533 | We are not the first to consider the total correctness of an assembler for a non-trivial assembly language. |
---|
534 | Perhaps the most impressive piece of work in this domain is the Piton stack~\cite{moore:piton:1996,moore:grand:2005}. |
---|
535 | This was a stack of verified components, written and verified in ACL2, ranging from a proprietary FM9001 microprocessor verified at the gate level, to assemblers and compilers for two high-level languages---a dialect of Lisp and $\mu$Gypsy~\cite{moore:grand:2005}. |
---|
536 | |
---|
537 | % jinja |
---|
538 | Klein and Nipkow consider a Java-like programming language, Jinja~\cite{klein:machine:2006,klein:machine:2010}. |
---|
539 | They provide a compiler, virtual machine and operational semantics for the programming language and virtual machine, and prove that their compiler is semantics and type preserving. |
---|
540 | |
---|
541 | We believe some other verified assemblers exist in the literature. |
---|
542 | However, what sets our work apart from that above is our attempt to optimise the machine code generated by our assembler. |
---|
543 | This complicates any formalisation effort, as the best possible selection of machine instructions must be made, especially important on a device such as the MCS-51 with a miniscule code memory. |
---|
544 | Further, care must be taken to ensure that the time properties of an assembly program are not modified by the assembly process lest we affect the semantics of any program employing the MCS-51's I/O facilities. |
---|
545 | This is only possible by inducing a cost model on the source code from the optimisation strategy and input program. |
---|
546 | This will be a \emph{leit motif} of CerCo. |
---|
547 | |
---|
548 | Finally, mention of CerCo will invariably invite comparisons with CompCert~\cite{compcert:2011,leroy:formal:2009}, another verified compiler project related to CerCo. |
---|
549 | As previously mentioned, CompCert considers only extensional correctness of the compiler, and not intensional correctness, which CerCo focusses on. |
---|
550 | However, CerCo also extends CompCert in other ways. |
---|
551 | Namely, the CompCert verified compilation chain terminates at the assembly level, and takes for granted the existence of a trustworthy assembler. |
---|
552 | CerCo chooses to go further, by considering a verified compilation chain all the way down to the machine code level. |
---|
553 | The work presented in this publication is one part of CerCo's extension over CompCert. |
---|
554 | |
---|
555 | \subsection{Resources} |
---|
556 | \label{subsect.resources} |
---|
557 | |
---|
558 | All files relating to our formalisation effort can be found online at~\url{http://cerco.cs.unibo.it}. The code of the compiler has been completed, and the |
---|
559 | proof of correctness described here is still in progress. In particular, we |
---|
560 | have assumed several properties of ``library functions'' related in particular |
---|
561 | to modular arithmetics and datastructures manipulation. Moreover, we only |
---|
562 | completed the interesting cases of some of the main theorems that proceed by |
---|
563 | cases on all the possible opcodes. |
---|
564 | We thus believe that the proof strategy is sound and that we will be able to |
---|
565 | close soon all axioms, up to possible minor bugs that should have local fixes |
---|
566 | that do not affect the global proof strategy. |
---|
567 | |
---|
568 | The development, including the definition of the executable semantics of the MCS-51, is spread across 17 files, totalling around 11,500 lines of Matita source. |
---|
569 | The bulk of the proof described herein is contained in a single file, \texttt{AssemblyProof.ma}, consisting at the moment of approximately 2500 lines of Matita source. Another 1000 lines of proofs are spread all over the development because |
---|
570 | of dependent types and the Russell proof style, that do not allow to separate the code from the proofs. The low ratio between the number of lines of code and |
---|
571 | the number of lines of proof is unusual. It is justified by the fact that |
---|
572 | the pseudo-assembly and the assembly language share most constructs and that |
---|
573 | large parts of the semantics is also shared. Thus many lines of code are |
---|
574 | required to describe the complex semantics of the processor, but, for |
---|
575 | the shared cases, the proof of preservation of the semantics is essentially |
---|
576 | trivial. |
---|
577 | |
---|
578 | \bibliography{cpp-2012-asm.bib} |
---|
579 | |
---|
580 | \end{document}\renewcommand{\verb}{\lstinline} |
---|
581 | \def\lstlanguagefiles{lst-grafite.tex} |
---|
582 | \lstset{language=Grafite} |
---|