1 | include "ASM/Assembly.ma". |
---|
2 | include "ASM/Interpret.ma". |
---|
3 | |
---|
4 | (* RUSSEL **) |
---|
5 | |
---|
6 | include "basics/jmeq.ma". |
---|
7 | |
---|
8 | definition inject : ∀A.∀P:A → Prop.∀a.∀p:P a.Σx:A.P x ≝ λA,P,a,p. dp … a p. |
---|
9 | definition eject : ∀A.∀P: A → Prop.(Σx:A.P x) → A ≝ λA,P,c.match c with [ dp w p ⇒ w]. |
---|
10 | |
---|
11 | coercion inject nocomposites: ∀A.∀P:A → Prop.∀a.∀p:P a.Σx:A.P x ≝ inject on a:? to Σx:?.?. |
---|
12 | coercion eject nocomposites: ∀A.∀P:A → Prop.∀c:Σx:A.P x.A ≝ eject on _c:Σx:?.? to ?. |
---|
13 | |
---|
14 | axiom VOID: Type[0]. |
---|
15 | axiom assert_false: VOID. |
---|
16 | definition bigbang: ∀A:Type[0].False → VOID → A. |
---|
17 | #A #abs cases abs |
---|
18 | qed. |
---|
19 | |
---|
20 | coercion bigbang nocomposites: ∀A:Type[0].False → ∀v:VOID.A ≝ bigbang on _v:VOID to ?. |
---|
21 | |
---|
22 | lemma sig2: ∀A.∀P:A → Prop. ∀p:Σx:A.P x. P (eject … p). |
---|
23 | #A #P #p cases p #w #q @q |
---|
24 | qed. |
---|
25 | |
---|
26 | (* END RUSSELL **) |
---|
27 | |
---|
28 | (* This establishes the correspondence between pseudo program counters and |
---|
29 | program counters. It is at the heart of the proof. *) |
---|
30 | (*CSC: code taken from build_maps *) |
---|
31 | definition sigma0: pseudo_assembly_program → option (nat × (nat × (BitVectorTrie Word 16))) ≝ |
---|
32 | λinstr_list. |
---|
33 | foldl ?? |
---|
34 | (λt. λi. |
---|
35 | match t with |
---|
36 | [ None ⇒ None ? |
---|
37 | | Some ppc_pc_map ⇒ |
---|
38 | let 〈ppc,pc_map〉 ≝ ppc_pc_map in |
---|
39 | let 〈program_counter, sigma_map〉 ≝ pc_map in |
---|
40 | let 〈label, i〉 ≝ i in |
---|
41 | match construct_costs instr_list program_counter (λx. zero ?) (λx. zero ?) (Stub …) i with |
---|
42 | [ None ⇒ None ? |
---|
43 | | Some pc_ignore ⇒ |
---|
44 | let 〈pc,ignore〉 ≝ pc_ignore in |
---|
45 | Some … 〈S ppc,〈pc, insert ? ? (bitvector_of_nat ? ppc) (bitvector_of_nat ? pc) sigma_map〉〉 ] |
---|
46 | ]) (Some ? 〈0, 〈0, (Stub ? ?)〉〉) (\snd instr_list). |
---|
47 | |
---|
48 | definition tech_pc_sigma0: pseudo_assembly_program → option nat ≝ |
---|
49 | λinstr_list. |
---|
50 | match sigma0 instr_list with |
---|
51 | [ None ⇒ None … |
---|
52 | | Some result ⇒ |
---|
53 | let 〈ppc,pc_sigma_map〉 ≝ result in |
---|
54 | let 〈pc, sigma_map〉 ≝ pc_sigma_map in |
---|
55 | Some … pc ]. |
---|
56 | |
---|
57 | definition sigma_safe: pseudo_assembly_program → option (Word → Word) ≝ |
---|
58 | λinstr_list. |
---|
59 | match sigma0 instr_list with |
---|
60 | [ None ⇒ None ? |
---|
61 | | Some result ⇒ |
---|
62 | let 〈ppc,pc_sigma_map〉 ≝ result in |
---|
63 | let 〈pc, sigma_map〉 ≝ pc_sigma_map in |
---|
64 | if gtb pc (2^16) then |
---|
65 | None ? |
---|
66 | else |
---|
67 | Some ? (λx.lookup ?? x sigma_map (zero …)) ]. |
---|
68 | |
---|
69 | axiom policy_ok: ∀p. sigma_safe p ≠ None …. |
---|
70 | |
---|
71 | definition sigma: pseudo_assembly_program → Word → Word ≝ |
---|
72 | λp. |
---|
73 | match sigma_safe p return λr:option (Word → Word). r ≠ None … → Word → Word with |
---|
74 | [ None ⇒ λabs. ⊥ |
---|
75 | | Some r ⇒ λ_.r] (policy_ok p). |
---|
76 | cases abs // |
---|
77 | qed. |
---|
78 | |
---|
79 | (* |
---|
80 | definition build_maps' ≝ |
---|
81 | λpseudo_program. |
---|
82 | let 〈preamble,instr_list〉 ≝ pseudo_program in |
---|
83 | let result ≝ |
---|
84 | foldl |
---|
85 | ((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))) |
---|
86 | (option Identifier × pseudo_instruction) |
---|
87 | (λt,i. |
---|
88 | let 〈labels, pc_costs〉 ≝ t in |
---|
89 | let 〈program_counter, costs〉 ≝ pc_costs in |
---|
90 | let 〈label, i'〉 ≝ i in |
---|
91 | let labels ≝ |
---|
92 | match label with |
---|
93 | [ None ⇒ labels |
---|
94 | | Some label ⇒ |
---|
95 | let program_counter_bv ≝ bitvector_of_nat ? program_counter in |
---|
96 | insert ? ? label program_counter_bv labels |
---|
97 | ] |
---|
98 | in |
---|
99 | match construct_costs pseudo_program program_counter (λx. zero ?) (λx. zero ?) costs i' with |
---|
100 | [ None ⇒ |
---|
101 | let dummy ≝ 〈labels,pc_costs〉 in |
---|
102 | dummy |
---|
103 | | Some construct ⇒ 〈labels, construct〉 |
---|
104 | ] |
---|
105 | ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉 instr_list |
---|
106 | in |
---|
107 | let 〈labels, pc_costs〉 ≝ result in |
---|
108 | let 〈pc, costs〉 ≝ pc_costs in |
---|
109 | 〈labels, costs〉. |
---|
110 | |
---|
111 | (* |
---|
112 | notation < "hvbox('let' 〈ident x,ident y〉 ≝ t 'in' s)" |
---|
113 | with precedence 10 |
---|
114 | for @{ match $t with [ pair ${ident x} ${ident y} ⇒ $s ] }. |
---|
115 | *) |
---|
116 | |
---|
117 | lemma build_maps_ok: |
---|
118 | ∀p:pseudo_assembly_program. |
---|
119 | let 〈labels,costs〉 ≝ build_maps' p in |
---|
120 | ∀pc. |
---|
121 | (nat_of_bitvector … pc) < length … (\snd p) → |
---|
122 | lookup ?? pc labels (zero …) = sigma p (\snd (fetch_pseudo_instruction (\snd p) pc)). |
---|
123 | #p cases p #preamble #instr_list |
---|
124 | elim instr_list |
---|
125 | [ whd #pc #abs normalize in abs; cases (not_le_Sn_O ?) [#H cases (H abs) ] |
---|
126 | | #hd #tl #IH |
---|
127 | whd in ⊢ (match % with [ _ ⇒ ?]) |
---|
128 | ] |
---|
129 | qed. |
---|
130 | *) |
---|
131 | |
---|
132 | (* |
---|
133 | lemma list_elim_rev: |
---|
134 | ∀A:Type[0].∀P:list A → Prop. |
---|
135 | P [ ] → (∀n,l. length l = n → P l → |
---|
136 | P [ ] → (∀l,a. P l → P (l@[a])) → |
---|
137 | ∀l. P l. |
---|
138 | #A #P |
---|
139 | qed.*) |
---|
140 | |
---|
141 | lemma length_append: |
---|
142 | ∀A.∀l1,l2:list A. |
---|
143 | |l1 @ l2| = |l1| + |l2|. |
---|
144 | #A #l1 elim l1 |
---|
145 | [ // |
---|
146 | | #hd #tl #IH #l2 normalize <IH //] |
---|
147 | qed. |
---|
148 | |
---|
149 | lemma rev_preserves_length: |
---|
150 | ∀A.∀l. length … (rev A l) = length … l. |
---|
151 | #A #l elim l |
---|
152 | [ % |
---|
153 | | #hd #tl #IH normalize >length_append normalize /2/ ] |
---|
154 | qed. |
---|
155 | |
---|
156 | lemma rev_append: |
---|
157 | ∀A.∀l1,l2. |
---|
158 | rev A (l1@l2) = rev A l2 @ rev A l1. |
---|
159 | #A #l1 elim l1 normalize // |
---|
160 | qed. |
---|
161 | |
---|
162 | lemma rev_rev: ∀A.∀l. rev … (rev A l) = l. |
---|
163 | #A #l elim l |
---|
164 | [ // |
---|
165 | | #hd #tl #IH normalize >rev_append normalize // ] |
---|
166 | qed. |
---|
167 | |
---|
168 | lemma split_len_Sn: |
---|
169 | ∀A:Type[0].∀l:list A.∀len. |
---|
170 | length … l = S len → |
---|
171 | Σl'.Σa. l = l'@[a] ∧ length … l' = len. |
---|
172 | #A #l elim l |
---|
173 | [ normalize #len #abs destruct |
---|
174 | | #hd #tl #IH #len |
---|
175 | generalize in match (rev_rev … tl) |
---|
176 | cases (rev A tl) in ⊢ (??%? → ?) |
---|
177 | [ #H <H normalize #EQ % [@[ ]] % [@hd] normalize /2/ |
---|
178 | | #a #l' #H <H normalize #EQ |
---|
179 | %[@(hd::rev … l')] %[@a] % // |
---|
180 | >length_append in EQ #EQ normalize in EQ; normalize; |
---|
181 | generalize in match (injective_S … EQ) #EQ2 /2/ ]] |
---|
182 | qed. |
---|
183 | |
---|
184 | lemma list_elim_rev: |
---|
185 | ∀A:Type[0].∀P:list A → Type[0]. |
---|
186 | P [ ] → (∀l,a. P l → P (l@[a])) → |
---|
187 | ∀l. P l. |
---|
188 | #A #P #H1 #H2 #l |
---|
189 | generalize in match (refl … (length … l)) |
---|
190 | generalize in ⊢ (???% → ?) #n generalize in match l |
---|
191 | elim n |
---|
192 | [ #L cases L [ // | #x #w #abs (normalize in abs) @⊥ // ] |
---|
193 | | #m #IH #L #EQ |
---|
194 | cases (split_len_Sn … EQ) #l' * #a * /3/ ] |
---|
195 | qed. |
---|
196 | |
---|
197 | axiom is_prefix: ∀A:Type[0]. list A → list A → Prop. |
---|
198 | axiom prefix_of_append: |
---|
199 | ∀A:Type[0].∀l,l1,l2:list A. |
---|
200 | is_prefix … l l1 → is_prefix … l (l1@l2). |
---|
201 | |
---|
202 | record Propify (A:Type[0]) : Prop ≝ { in_propify: A }. |
---|
203 | |
---|
204 | definition Propify_elim: ∀A. ∀P:Prop. (A → P) → (Propify A → P) ≝ |
---|
205 | λA,P,H,x. match x with [ mk_Propify p ⇒ H p ]. |
---|
206 | |
---|
207 | let rec foldli (A: Type[0]) (B: Type[0]) (f: Propify nat → A → B → A) (i: Propify nat) (a: A) (l: list B) on l ≝ |
---|
208 | match l with |
---|
209 | [ nil ⇒ a |
---|
210 | | cons hd tl ⇒ foldli A B f (match i with [ mk_Propify i ⇒ mk_Propify … (S i)]) (f i a hd) tl |
---|
211 | ]. |
---|
212 | |
---|
213 | definition build_maps' ≝ |
---|
214 | λpseudo_program. |
---|
215 | let 〈preamble,instr_list〉 ≝ pseudo_program in |
---|
216 | let result ≝ |
---|
217 | foldl |
---|
218 | (Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))). |
---|
219 | ∃instr_list_prefix. is_prefix ? instr_list_prefix instr_list ∧ |
---|
220 | tech_pc_sigma0 〈preamble,instr_list_prefix〉 = Some ? (\fst (\snd t))) |
---|
221 | (Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix. |
---|
222 | let instr_list_prefix' ≝ instr_list_prefix @ [i] in |
---|
223 | is_prefix ? instr_list_prefix' instr_list → |
---|
224 | tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ?) |
---|
225 | (λt: Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))). |
---|
226 | ∃instr_list_prefix. is_prefix ? instr_list_prefix instr_list ∧ |
---|
227 | tech_pc_sigma0 〈preamble,instr_list_prefix〉 = Some ? (\fst (\snd t)). |
---|
228 | λi: Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix. |
---|
229 | let instr_list_prefix' ≝ instr_list_prefix @ [i] in |
---|
230 | is_prefix ? instr_list_prefix' instr_list → |
---|
231 | tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ? . |
---|
232 | let 〈labels, pc_costs〉 ≝ t in |
---|
233 | let 〈program_counter, costs〉 ≝ pc_costs in |
---|
234 | let 〈label, i'〉 ≝ i in |
---|
235 | let labels ≝ |
---|
236 | match label with |
---|
237 | [ None ⇒ labels |
---|
238 | | Some label ⇒ |
---|
239 | let program_counter_bv ≝ bitvector_of_nat ? program_counter in |
---|
240 | insert ? ? label program_counter_bv labels |
---|
241 | ] |
---|
242 | in |
---|
243 | match construct_costs pseudo_program program_counter (λx. zero ?) (λx. zero ?) costs i' with |
---|
244 | [ None ⇒ |
---|
245 | let dummy ≝ 〈labels,pc_costs〉 in |
---|
246 | dummy |
---|
247 | | Some construct ⇒ 〈labels, construct〉 |
---|
248 | ] |
---|
249 | ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉 ?(*instr_list*) |
---|
250 | in |
---|
251 | let 〈labels, pc_costs〉 ≝ result in |
---|
252 | let 〈pc, costs〉 ≝ pc_costs in |
---|
253 | 〈labels, costs〉. |
---|
254 | [4: @(list_elim_rev ? |
---|
255 | (λinstr_list. list ( |
---|
256 | (Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix. |
---|
257 | let instr_list_prefix' ≝ instr_list_prefix @ [i] in |
---|
258 | is_prefix ? instr_list_prefix' instr_list → |
---|
259 | tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ?))) |
---|
260 | ?? instr_list) (* CSC: BAD ORDER FOR CODE EXTRACTION *) |
---|
261 | [ @[ ] |
---|
262 | | #l' #a #limage %2 |
---|
263 | [ %[@a] #PREFIX #PREFIX_OK |
---|
264 | | (* CSC: EVEN WORST CODE FOR EXTRACTION: WE SHOULD STRENGTHEN |
---|
265 | THE INDUCTION HYPOTHESIS INSTEAD *) |
---|
266 | elim limage |
---|
267 | [ %1 |
---|
268 | | #HD #TL #IH @(?::IH) cases HD #ELEM #K1 %[@ELEM] #K2 #K3 |
---|
269 | @K1 @(prefix_of_append ???? K3) |
---|
270 | ] |
---|
271 | ] |
---|
272 | |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | cases t in c2 ⊢ % #t' * #LIST_PREFIX * #H1t' #H2t' #HJMt' |
---|
277 | % [@ (LIST_PREFIX @ [i])] % |
---|
278 | [ cases (sig2 … i LIST_PREFIX) #K1 #K2 @K1 |
---|
279 | | (* DOABLE IN PRINCIPLE *) |
---|
280 | ] |
---|
281 | | (* assert false case *) |
---|
282 | |3: % [@ ([ ])] % [2: % | (* DOABLE *)] |
---|
283 | | |
---|
284 | |
---|
285 | let rec encoding_check (code_memory: BitVectorTrie Byte 16) (pc: Word) (final_pc: Word) |
---|
286 | (encoding: list Byte) on encoding: Prop ≝ |
---|
287 | match encoding with |
---|
288 | [ nil ⇒ final_pc = pc |
---|
289 | | cons hd tl ⇒ |
---|
290 | let 〈new_pc, byte〉 ≝ next code_memory pc in |
---|
291 | hd = byte ∧ encoding_check code_memory new_pc final_pc tl |
---|
292 | ]. |
---|
293 | |
---|
294 | definition assembly_specification: |
---|
295 | ∀assembly_program: pseudo_assembly_program. |
---|
296 | ∀code_mem: BitVectorTrie Byte 16. Prop ≝ |
---|
297 | λpseudo_assembly_program. |
---|
298 | λcode_mem. |
---|
299 | ∀pc: Word. |
---|
300 | let 〈preamble, instr_list〉 ≝ pseudo_assembly_program in |
---|
301 | let 〈pre_instr, pre_new_pc〉 ≝ fetch_pseudo_instruction instr_list pc in |
---|
302 | let labels ≝ λx. sigma' pseudo_assembly_program (address_of_word_labels_code_mem instr_list x) in |
---|
303 | let datalabels ≝ λx. sigma' pseudo_assembly_program (lookup ? ? x (construct_datalabels preamble) (zero ?)) in |
---|
304 | let pre_assembled ≝ assembly_1_pseudoinstruction pseudo_assembly_program |
---|
305 | (sigma' pseudo_assembly_program pc) labels datalabels pre_instr in |
---|
306 | match pre_assembled with |
---|
307 | [ None ⇒ True |
---|
308 | | Some pc_code ⇒ |
---|
309 | let 〈new_pc,code〉 ≝ pc_code in |
---|
310 | encoding_check code_mem pc (sigma' pseudo_assembly_program pre_new_pc) code ]. |
---|
311 | |
---|
312 | axiom assembly_meets_specification: |
---|
313 | ∀pseudo_assembly_program. |
---|
314 | match assembly pseudo_assembly_program with |
---|
315 | [ None ⇒ True |
---|
316 | | Some code_mem_cost ⇒ |
---|
317 | let 〈code_mem, cost〉 ≝ code_mem_cost in |
---|
318 | assembly_specification pseudo_assembly_program (load_code_memory code_mem) |
---|
319 | ]. |
---|
320 | (* |
---|
321 | # PROGRAM |
---|
322 | [ cases PROGRAM |
---|
323 | # PREAMBLE |
---|
324 | # INSTR_LIST |
---|
325 | elim INSTR_LIST |
---|
326 | [ whd |
---|
327 | whd in ⊢ (∀_. %) |
---|
328 | # PC |
---|
329 | whd |
---|
330 | | # INSTR |
---|
331 | # INSTR_LIST_TL |
---|
332 | # H |
---|
333 | whd |
---|
334 | whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]) |
---|
335 | ] |
---|
336 | | cases not_implemented |
---|
337 | ] *) |
---|
338 | |
---|
339 | definition status_of_pseudo_status: PseudoStatus → option Status ≝ |
---|
340 | λps. |
---|
341 | let pap ≝ code_memory … ps in |
---|
342 | match assembly pap with |
---|
343 | [ None ⇒ None … |
---|
344 | | Some p ⇒ |
---|
345 | let cm ≝ load_code_memory (\fst p) in |
---|
346 | let pc ≝ sigma' pap (program_counter ? ps) in |
---|
347 | Some … |
---|
348 | (mk_PreStatus (BitVectorTrie Byte 16) |
---|
349 | cm |
---|
350 | (low_internal_ram … ps) |
---|
351 | (high_internal_ram … ps) |
---|
352 | (external_ram … ps) |
---|
353 | pc |
---|
354 | (special_function_registers_8051 … ps) |
---|
355 | (special_function_registers_8052 … ps) |
---|
356 | (p1_latch … ps) |
---|
357 | (p3_latch … ps) |
---|
358 | (clock … ps)) ]. |
---|
359 | |
---|
360 | definition write_at_stack_pointer': |
---|
361 | ∀M. ∀ps: PreStatus M. Byte → Σps':PreStatus M.(code_memory … ps = code_memory … ps') ≝ |
---|
362 | λM: Type[0]. |
---|
363 | λs: PreStatus M. |
---|
364 | λv: Byte. |
---|
365 | let 〈 nu, nl 〉 ≝ split … 4 4 (get_8051_sfr ? s SFR_SP) in |
---|
366 | let bit_zero ≝ get_index_v… nu O ? in |
---|
367 | let bit_1 ≝ get_index_v… nu 1 ? in |
---|
368 | let bit_2 ≝ get_index_v… nu 2 ? in |
---|
369 | let bit_3 ≝ get_index_v… nu 3 ? in |
---|
370 | if bit_zero then |
---|
371 | let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl) |
---|
372 | v (low_internal_ram ? s) in |
---|
373 | set_low_internal_ram ? s memory |
---|
374 | else |
---|
375 | let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl) |
---|
376 | v (high_internal_ram ? s) in |
---|
377 | set_high_internal_ram ? s memory. |
---|
378 | [ cases l0 % |
---|
379 | |2,3,4,5: normalize repeat (@ le_S_S) @ le_O_n ] |
---|
380 | qed. |
---|
381 | |
---|
382 | definition execute_1_pseudo_instruction': (Word → nat) → ∀ps:PseudoStatus. |
---|
383 | Σps':PseudoStatus.(code_memory … ps = code_memory … ps') |
---|
384 | ≝ |
---|
385 | λticks_of. |
---|
386 | λs. |
---|
387 | let 〈instr, pc〉 ≝ fetch_pseudo_instruction (\snd (code_memory ? s)) (program_counter ? s) in |
---|
388 | let ticks ≝ ticks_of (program_counter ? s) in |
---|
389 | let s ≝ set_clock ? s (clock ? s + ticks) in |
---|
390 | let s ≝ set_program_counter ? s pc in |
---|
391 | match instr with |
---|
392 | [ Instruction instr ⇒ |
---|
393 | execute_1_preinstruction … (λx, y. address_of_word_labels y x) instr s |
---|
394 | | Comment cmt ⇒ s |
---|
395 | | Cost cst ⇒ s |
---|
396 | | Jmp jmp ⇒ set_program_counter ? s (address_of_word_labels s jmp) |
---|
397 | | Call call ⇒ |
---|
398 | let a ≝ address_of_word_labels s call in |
---|
399 | let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in |
---|
400 | let s ≝ set_8051_sfr ? s SFR_SP new_sp in |
---|
401 | let 〈pc_bu, pc_bl〉 ≝ split ? 8 8 (program_counter ? s) in |
---|
402 | let s ≝ write_at_stack_pointer' ? s pc_bl in |
---|
403 | let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in |
---|
404 | let s ≝ set_8051_sfr ? s SFR_SP new_sp in |
---|
405 | let s ≝ write_at_stack_pointer' ? s pc_bu in |
---|
406 | set_program_counter ? s a |
---|
407 | | Mov dptr ident ⇒ |
---|
408 | set_arg_16 ? s (get_arg_16 ? s (DATA16 (address_of_word_labels s ident))) dptr |
---|
409 | ]. |
---|
410 | [ |
---|
411 | |2,3,4: % |
---|
412 | | <(sig2 … l7) whd in ⊢ (??? (??%)) <(sig2 … l5) % |
---|
413 | | |
---|
414 | | % |
---|
415 | ] |
---|
416 | cases not_implemented |
---|
417 | qed. |
---|
418 | |
---|
419 | (* |
---|
420 | lemma execute_code_memory_unchanged: |
---|
421 | ∀ticks_of,ps. code_memory ? ps = code_memory ? (execute_1_pseudo_instruction ticks_of ps). |
---|
422 | #ticks #ps whd in ⊢ (??? (??%)) |
---|
423 | cases (fetch_pseudo_instruction (\snd (code_memory pseudo_assembly_program ps)) |
---|
424 | (program_counter pseudo_assembly_program ps)) #instr #pc |
---|
425 | whd in ⊢ (??? (??%)) cases instr |
---|
426 | [ #pre cases pre |
---|
427 | [ #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
428 | cases (split ????) #z1 #z2 % |
---|
429 | | #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
430 | cases (split ????) #z1 #z2 % |
---|
431 | | #a1 #a2 whd in ⊢ (??? (??%)) cases (sub_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
432 | cases (split ????) #z1 #z2 % |
---|
433 | | #a1 whd in ⊢ (??? (??%)) cases a1 #x #H whd in ⊢ (??? (??%)) cases x |
---|
434 | [ #x1 whd in ⊢ (??? (??%)) |
---|
435 | | *: cases not_implemented |
---|
436 | ] |
---|
437 | | #comment % |
---|
438 | | #cost % |
---|
439 | | #label % |
---|
440 | | #label whd in ⊢ (??? (??%)) cases (half_add ???) #x1 #x2 whd in ⊢ (??? (??%)) |
---|
441 | cases (split ????) #y1 #y2 whd in ⊢ (??? (??%)) cases (half_add ???) #z1 #z2 |
---|
442 | whd in ⊢ (??? (??%)) whd in ⊢ (??? (??%)) cases (split ????) #w1 #w2 |
---|
443 | whd in ⊢ (??? (??%)) cases (get_index_v bool ????) whd in ⊢ (??? (??%)) |
---|
444 | (* CSC: ??? *) |
---|
445 | | #dptr #label (* CSC: ??? *) |
---|
446 | ] |
---|
447 | cases not_implemented |
---|
448 | qed. |
---|
449 | *) |
---|
450 | |
---|
451 | lemma status_of_pseudo_status_failure_depends_only_on_code_memory: |
---|
452 | ∀ps,ps': PseudoStatus. |
---|
453 | code_memory … ps = code_memory … ps' → |
---|
454 | match status_of_pseudo_status ps with |
---|
455 | [ None ⇒ status_of_pseudo_status ps' = None … |
---|
456 | | Some _ ⇒ ∃w. status_of_pseudo_status ps' = Some … w |
---|
457 | ]. |
---|
458 | #ps #ps' #H whd in ⊢ (mat |
---|
459 | ch % with [ _ ⇒ ? | _ ⇒ ? ]) |
---|
460 | generalize in match (refl … (assembly (code_memory … ps))) |
---|
461 | cases (assembly ?) in ⊢ (???% → %) |
---|
462 | [ #K whd whd in ⊢ (??%?) <H >K % |
---|
463 | | #x #K whd whd in ⊢ (?? (λ_.??%?)) <H >K % [2: % ] ] |
---|
464 | qed.*) |
---|
465 | |
---|
466 | let rec encoding_check' (code_memory: BitVectorTrie Byte 16) (pc: Word) (encoding: list Byte) on encoding: Prop ≝ |
---|
467 | match encoding with |
---|
468 | [ nil ⇒ True |
---|
469 | | cons hd tl ⇒ |
---|
470 | let 〈new_pc, byte〉 ≝ next code_memory pc in |
---|
471 | hd = byte ∧ encoding_check' code_memory new_pc tl |
---|
472 | ]. |
---|
473 | |
---|
474 | lemma test: |
---|
475 | ∀i: instruction. |
---|
476 | ∃pc. |
---|
477 | let assembled ≝ assembly1 i in |
---|
478 | let code_memory ≝ load_code_memory assembled in |
---|
479 | let fetched ≝ fetch code_memory pc in |
---|
480 | let 〈instr_pc, ticks〉 ≝ fetched in |
---|
481 | \fst instr_pc = i. |
---|
482 | # INSTR |
---|
483 | % |
---|
484 | [ @ (zero 16) |
---|
485 | | cases INSTR |
---|
486 | ]. |
---|
487 | |
---|
488 | lemma test: |
---|
489 | ∀pc: Word. |
---|
490 | ∀code_memory: BitVectorTrie Byte 16. |
---|
491 | ∀i: instruction. |
---|
492 | let assembled ≝ assembly1 i in |
---|
493 | encoding_check' code_memory pc assembled → |
---|
494 | let 〈instr_pc, ignore〉 ≝ fetch code_memory pc in |
---|
495 | let 〈instr, pc〉 ≝ instr_pc in |
---|
496 | instr = i. |
---|
497 | # PC # CODE_MEMORY # INSTRUCTION |
---|
498 | whd |
---|
499 | whd in ⊢ (? → match % with [ _ ⇒ ? ]) |
---|
500 | cases (next CODE_MEMORY PC) |
---|
501 | whd |
---|
502 | # PC1 # V1 |
---|
503 | |
---|
504 | |
---|
505 | cases (fetch CODE_MEMORY PC) |
---|
506 | # INSTR_PC |
---|
507 | # TICKS |
---|
508 | cases (INSTRUCTION) |
---|
509 | [ # ADDR11 |
---|
510 | # ENCODING_CHECK |
---|
511 | whd in ENCODING_CHECK; |
---|
512 | normalize |
---|
513 | cases (INSTR_PC) |
---|
514 | # INSTR |
---|
515 | # PC |
---|
516 | normalize |
---|
517 | |
---|
518 | |
---|
519 | # ENCODING |
---|
520 | normalize |
---|
521 | [ cases INSTR_PC |
---|
522 | # NEW_INSTRUCTION |
---|
523 | # PC |
---|
524 | normalize |
---|
525 | normalize in ENCODING; |
---|
526 | | # ASSEMBLED |
---|
527 | whd |
---|
528 | |
---|
529 | lemma main_thm: |
---|
530 | ∀ticks_of. |
---|
531 | ∀ps: PseudoStatus. |
---|
532 | match status_of_pseudo_status ps with [ None ⇒ True | Some s ⇒ |
---|
533 | let ps' ≝ execute_1_pseudo_instruction ticks_of ps in |
---|
534 | match status_of_pseudo_status ps' with [ None ⇒ True | Some s'' ⇒ |
---|
535 | let s' ≝ execute_1 s in |
---|
536 | s = s'']]. |
---|
537 | #ticks_of #ps |
---|
538 | whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]) |
---|
539 | cases (assembly (code_memory pseudo_assembly_program ps)) [%] * #cm #costs whd |
---|
540 | whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]) |
---|
541 | generalize in match (sig2 … (execute_1_pseudo_instruction' ticks_of ps)) |
---|
542 | |
---|
543 | cases (status_of_pseudo_status (execute_1_pseudo_instruction ticks_of ps)) [%] #s'' whd |
---|