1 | include "ASM/ASM.ma". |
---|
2 | include "ASM/Arithmetic.ma". |
---|
3 | include "ASM/Fetch.ma". |
---|
4 | include "ASM/Status.ma". |
---|
5 | include "utilities/extralib.ma". |
---|
6 | include "ASM/Assembly.ma". |
---|
7 | |
---|
8 | (* Internal types *) |
---|
9 | |
---|
10 | (* ppc_pc_map: program length × (pseudo program counter ↦ 〈pc, jump_length〉) *) |
---|
11 | definition ppc_pc_map ≝ ℕ × (BitVectorTrie (ℕ × jump_length) 16). |
---|
12 | |
---|
13 | (* The different properties that we want/need to prove at some point *) |
---|
14 | (* During our iteration, everything not yet seen is None, and vice versa *) |
---|
15 | definition out_of_program_none ≝ |
---|
16 | λprefix:list labelled_instruction.λsigma:ppc_pc_map. |
---|
17 | ∀i.i < 2^16 → (i > |prefix| ↔ bvt_lookup_opt … (bitvector_of_nat ? i) (\snd sigma) = None ?). |
---|
18 | |
---|
19 | (* If instruction i is a jump, then there will be something in the policy at |
---|
20 | * position i *) |
---|
21 | definition is_jump' ≝ |
---|
22 | λx:preinstruction Identifier. |
---|
23 | match x with |
---|
24 | [ JC _ ⇒ True |
---|
25 | | JNC _ ⇒ True |
---|
26 | | JZ _ ⇒ True |
---|
27 | | JNZ _ ⇒ True |
---|
28 | | JB _ _ ⇒ True |
---|
29 | | JNB _ _ ⇒ True |
---|
30 | | JBC _ _ ⇒ True |
---|
31 | | CJNE _ _ ⇒ True |
---|
32 | | DJNZ _ _ ⇒ True |
---|
33 | | _ ⇒ False |
---|
34 | ]. |
---|
35 | |
---|
36 | definition is_relative_jump ≝ |
---|
37 | λinstr:pseudo_instruction. |
---|
38 | match instr with |
---|
39 | [ Instruction i ⇒ is_jump' i |
---|
40 | | _ ⇒ False |
---|
41 | ]. |
---|
42 | |
---|
43 | definition is_jump ≝ |
---|
44 | λinstr:pseudo_instruction. |
---|
45 | match instr with |
---|
46 | [ Instruction i ⇒ is_jump' i |
---|
47 | | Call _ ⇒ True |
---|
48 | | Jmp _ ⇒ True |
---|
49 | | _ ⇒ False |
---|
50 | ]. |
---|
51 | |
---|
52 | definition is_call ≝ |
---|
53 | λinstr:pseudo_instruction. |
---|
54 | match instr with |
---|
55 | [ Call _ ⇒ True |
---|
56 | | _ ⇒ False |
---|
57 | ]. |
---|
58 | |
---|
59 | definition is_jump_to ≝ |
---|
60 | λx:pseudo_instruction.λd:Identifier. |
---|
61 | match x with |
---|
62 | [ Instruction i ⇒ match i with |
---|
63 | [ JC j ⇒ d = j |
---|
64 | | JNC j ⇒ d = j |
---|
65 | | JZ j ⇒ d = j |
---|
66 | | JNZ j ⇒ d = j |
---|
67 | | JB _ j ⇒ d = j |
---|
68 | | JNB _ j ⇒ d = j |
---|
69 | | JBC _ j ⇒ d = j |
---|
70 | | CJNE _ j ⇒ d = j |
---|
71 | | DJNZ _ j ⇒ d = j |
---|
72 | | _ ⇒ False |
---|
73 | ] |
---|
74 | | Call c ⇒ d = c |
---|
75 | | Jmp j ⇒ d = j |
---|
76 | | _ ⇒ False |
---|
77 | ]. |
---|
78 | |
---|
79 | definition not_jump_default ≝ |
---|
80 | λprefix:list labelled_instruction.λsigma:ppc_pc_map. |
---|
81 | ∀i:ℕ.i < |prefix| → |
---|
82 | ¬is_jump (\snd (nth i ? prefix 〈None ?, Comment []〉)) → |
---|
83 | \snd (bvt_lookup … (bitvector_of_nat ? i) (\snd sigma) 〈0,short_jump〉) = short_jump. |
---|
84 | |
---|
85 | (* Between two policies, jumps cannot decrease *) |
---|
86 | definition jmpeqb: jump_length → jump_length → bool ≝ |
---|
87 | λj1.λj2. |
---|
88 | match j1 with |
---|
89 | [ short_jump ⇒ match j2 with [ short_jump ⇒ true | _ ⇒ false ] |
---|
90 | | absolute_jump ⇒ match j2 with [ absolute_jump ⇒ true | _ ⇒ false ] |
---|
91 | | long_jump ⇒ match j2 with [ long_jump ⇒ true | _ ⇒ false ] |
---|
92 | ]. |
---|
93 | |
---|
94 | lemma jmpeqb_to_eq: ∀j1,j2.jmpeqb j1 j2 → j1 = j2. |
---|
95 | #j1 #j2 cases j1 cases j2 |
---|
96 | [1,5,9: / by /] |
---|
97 | #H cases H |
---|
98 | qed. |
---|
99 | |
---|
100 | definition jmple: jump_length → jump_length → Prop ≝ |
---|
101 | λj1.λj2. |
---|
102 | match j1 with |
---|
103 | [ short_jump ⇒ |
---|
104 | match j2 with |
---|
105 | [ short_jump ⇒ False |
---|
106 | | _ ⇒ True |
---|
107 | ] |
---|
108 | | absolute_jump ⇒ |
---|
109 | match j2 with |
---|
110 | [ long_jump ⇒ True |
---|
111 | | _ ⇒ False |
---|
112 | ] |
---|
113 | | long_jump ⇒ False |
---|
114 | ]. |
---|
115 | |
---|
116 | definition jmpleq: jump_length → jump_length → Prop ≝ |
---|
117 | λj1.λj2.jmple j1 j2 ∨ j1 = j2. |
---|
118 | |
---|
119 | definition jump_increase ≝ |
---|
120 | λprefix:list labelled_instruction.λop:ppc_pc_map.λp:ppc_pc_map. |
---|
121 | ∀i.i ≤ |prefix| → |
---|
122 | let 〈opc,oj〉 ≝ bvt_lookup … (bitvector_of_nat ? i) (\snd op) 〈0,short_jump〉 in |
---|
123 | let 〈pc,j〉 ≝ bvt_lookup … (bitvector_of_nat ? i) (\snd p) 〈0,short_jump〉 in |
---|
124 | jmpleq oj j. |
---|
125 | |
---|
126 | (* this is the instruction size as determined by the jump length given *) |
---|
127 | definition expand_relative_jump_internal_unsafe: |
---|
128 | jump_length → ([[relative]] → preinstruction [[relative]]) → list instruction ≝ |
---|
129 | λjmp_len:jump_length.λi. |
---|
130 | match jmp_len with |
---|
131 | [ short_jump ⇒ [ RealInstruction (i (RELATIVE (zero 8))) ] |
---|
132 | | absolute_jump ⇒ [ ] (* this should not happen *) |
---|
133 | | long_jump ⇒ |
---|
134 | [ RealInstruction (i (RELATIVE (bitvector_of_nat ? 2))); |
---|
135 | SJMP (RELATIVE (bitvector_of_nat ? 3)); (* LJMP size? *) |
---|
136 | LJMP (ADDR16 (zero 16)) |
---|
137 | ] |
---|
138 | ]. |
---|
139 | @I |
---|
140 | qed. |
---|
141 | |
---|
142 | definition expand_relative_jump_unsafe: |
---|
143 | jump_length → preinstruction Identifier → list instruction ≝ |
---|
144 | λjmp_len:jump_length.λi. |
---|
145 | match i with |
---|
146 | [ JC jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (JC ?) |
---|
147 | | JNC jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (JNC ?) |
---|
148 | | JB baddr jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (JB ? baddr) |
---|
149 | | JZ jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (JZ ?) |
---|
150 | | JNZ jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (JNZ ?) |
---|
151 | | JBC baddr jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (JBC ? baddr) |
---|
152 | | JNB baddr jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (JNB ? baddr) |
---|
153 | | CJNE addr jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (CJNE ? addr) |
---|
154 | | DJNZ addr jmp ⇒ expand_relative_jump_internal_unsafe jmp_len (DJNZ ? addr) |
---|
155 | | ADD arg1 arg2 ⇒ [ ADD ? arg1 arg2 ] |
---|
156 | | ADDC arg1 arg2 ⇒ [ ADDC ? arg1 arg2 ] |
---|
157 | | SUBB arg1 arg2 ⇒ [ SUBB ? arg1 arg2 ] |
---|
158 | | INC arg ⇒ [ INC ? arg ] |
---|
159 | | DEC arg ⇒ [ DEC ? arg ] |
---|
160 | | MUL arg1 arg2 ⇒ [ MUL ? arg1 arg2 ] |
---|
161 | | DIV arg1 arg2 ⇒ [ DIV ? arg1 arg2 ] |
---|
162 | | DA arg ⇒ [ DA ? arg ] |
---|
163 | | ANL arg ⇒ [ ANL ? arg ] |
---|
164 | | ORL arg ⇒ [ ORL ? arg ] |
---|
165 | | XRL arg ⇒ [ XRL ? arg ] |
---|
166 | | CLR arg ⇒ [ CLR ? arg ] |
---|
167 | | CPL arg ⇒ [ CPL ? arg ] |
---|
168 | | RL arg ⇒ [ RL ? arg ] |
---|
169 | | RR arg ⇒ [ RR ? arg ] |
---|
170 | | RLC arg ⇒ [ RLC ? arg ] |
---|
171 | | RRC arg ⇒ [ RRC ? arg ] |
---|
172 | | SWAP arg ⇒ [ SWAP ? arg ] |
---|
173 | | MOV arg ⇒ [ MOV ? arg ] |
---|
174 | | MOVX arg ⇒ [ MOVX ? arg ] |
---|
175 | | SETB arg ⇒ [ SETB ? arg ] |
---|
176 | | PUSH arg ⇒ [ PUSH ? arg ] |
---|
177 | | POP arg ⇒ [ POP ? arg ] |
---|
178 | | XCH arg1 arg2 ⇒ [ XCH ? arg1 arg2 ] |
---|
179 | | XCHD arg1 arg2 ⇒ [ XCHD ? arg1 arg2 ] |
---|
180 | | RET ⇒ [ RET ? ] |
---|
181 | | RETI ⇒ [ RETI ? ] |
---|
182 | | NOP ⇒ [ RealInstruction (NOP ?) ] |
---|
183 | ]. |
---|
184 | |
---|
185 | definition instruction_size_jmplen: |
---|
186 | jump_length → pseudo_instruction → ℕ ≝ |
---|
187 | λjmp_len. |
---|
188 | λi. |
---|
189 | let pseudos ≝ match i with |
---|
190 | [ Cost cost ⇒ [ ] |
---|
191 | | Comment comment ⇒ [ ] |
---|
192 | | Call call ⇒ |
---|
193 | match jmp_len with |
---|
194 | [ short_jump ⇒ [ ] (* this should not happen *) |
---|
195 | | absolute_jump ⇒ [ ACALL (ADDR11 (zero 11)) ] |
---|
196 | | long_jump ⇒ [ LCALL (ADDR16 (zero 16)) ] |
---|
197 | ] |
---|
198 | | Mov d trgt ⇒ |
---|
199 | [ RealInstruction (MOV ? (inl ? ? (inl ? ? (inr ? ? 〈DPTR, DATA16 (zero 16)〉))))] |
---|
200 | | Instruction instr ⇒ expand_relative_jump_unsafe jmp_len instr |
---|
201 | | Jmp jmp ⇒ |
---|
202 | match jmp_len with |
---|
203 | [ short_jump ⇒ [ SJMP (RELATIVE (zero 8)) ] |
---|
204 | | absolute_jump ⇒ [ AJMP (ADDR11 (zero 11)) ] |
---|
205 | | long_jump ⇒ [ LJMP (ADDR16 (zero 16)) ] |
---|
206 | ] |
---|
207 | ] in |
---|
208 | let mapped ≝ map ? ? assembly1 pseudos in |
---|
209 | let flattened ≝ flatten ? mapped in |
---|
210 | let pc_len ≝ length ? flattened in |
---|
211 | pc_len. |
---|
212 | @I. |
---|
213 | qed. |
---|
214 | |
---|
215 | definition sigma_compact_unsafe ≝ |
---|
216 | λprefix:list labelled_instruction.λlabels:label_map.λsigma:ppc_pc_map. |
---|
217 | ∀n.n < |prefix| → |
---|
218 | match bvt_lookup_opt … (bitvector_of_nat ? n) (\snd sigma) with |
---|
219 | [ None ⇒ False |
---|
220 | | Some x ⇒ let 〈pc,j〉 ≝ x in |
---|
221 | match bvt_lookup_opt … (bitvector_of_nat ? (S n)) (\snd sigma) with |
---|
222 | [ None ⇒ False |
---|
223 | | Some x1 ⇒ let 〈pc1,j1〉 ≝ x1 in |
---|
224 | pc1 = pc + instruction_size_jmplen j (\snd (nth n ? prefix 〈None ?, Comment []〉)) |
---|
225 | ] |
---|
226 | ]. |
---|
227 | |
---|
228 | (* new safety condition: sigma corresponds to program and resulting program is compact *) |
---|
229 | definition sigma_compact ≝ |
---|
230 | λprogram:list labelled_instruction.λlabels:label_map.λsigma:ppc_pc_map. |
---|
231 | ∀n.n < |program| → |
---|
232 | match bvt_lookup_opt … (bitvector_of_nat ? n) (\snd sigma) with |
---|
233 | [ None ⇒ False |
---|
234 | | Some x ⇒ let 〈pc,j〉 ≝ x in |
---|
235 | match bvt_lookup_opt … (bitvector_of_nat ? (S n)) (\snd sigma) with |
---|
236 | [ None ⇒ False |
---|
237 | | Some x1 ⇒ let 〈pc1,j1〉 ≝ x1 in |
---|
238 | pc1 = pc + instruction_size (λid.bitvector_of_nat ? (lookup_def ?? labels id 0)) |
---|
239 | (λppc.bitvector_of_nat ? (\fst (bvt_lookup ?? ppc (\snd sigma) 〈0,short_jump〉))) |
---|
240 | (λppc.jmpeqb long_jump (\snd (bvt_lookup ?? ppc (\snd sigma) 〈0,short_jump〉))) |
---|
241 | (bitvector_of_nat ? n) (\snd (nth n ? program 〈None ?, Comment []〉)) |
---|
242 | ] |
---|
243 | ]. |
---|
244 | |
---|
245 | (* jumps are of the proper size *) |
---|
246 | definition sigma_safe ≝ |
---|
247 | λprefix:list labelled_instruction.λlabels:label_map.λadded:ℕ. |
---|
248 | λold_sigma:ppc_pc_map.λsigma:ppc_pc_map. |
---|
249 | ∀i.i < |prefix| → |
---|
250 | let 〈pc,j〉 ≝ bvt_lookup … (bitvector_of_nat ? i) (\snd sigma) 〈0,short_jump〉 in |
---|
251 | let pc_plus_jmp_length ≝ bitvector_of_nat ? (\fst (bvt_lookup … (bitvector_of_nat ? (S i)) (\snd sigma) 〈0,short_jump〉)) in |
---|
252 | let 〈label,instr〉 ≝ nth i ? prefix 〈None ?, Comment [ ]〉 in |
---|
253 | ∀dest.is_jump_to instr dest → |
---|
254 | let paddr ≝ lookup_def … labels dest 0 in |
---|
255 | let addr ≝ bitvector_of_nat ? (if leb paddr (|prefix|) (* jump to address already known *) |
---|
256 | then \fst (bvt_lookup … (bitvector_of_nat ? paddr) (\snd sigma) 〈0,short_jump〉) |
---|
257 | else \fst (bvt_lookup … (bitvector_of_nat ? paddr) (\snd old_sigma) 〈0,short_jump〉)+added) in |
---|
258 | match j with |
---|
259 | [ short_jump ⇒ \fst (short_jump_cond pc_plus_jmp_length addr) = true ∧ |
---|
260 | ¬is_call instr |
---|
261 | | absolute_jump ⇒ \fst (absolute_jump_cond pc_plus_jmp_length addr) = true ∧ |
---|
262 | \fst (short_jump_cond pc_plus_jmp_length addr) = false ∧ |
---|
263 | ¬is_relative_jump instr |
---|
264 | | long_jump ⇒ \fst (short_jump_cond pc_plus_jmp_length addr) = false ∧ |
---|
265 | \fst (absolute_jump_cond pc_plus_jmp_length addr) = false |
---|
266 | ]. |
---|
267 | |
---|
268 | (* Definitions and theorems for the jump_length type (itself defined in Assembly) *) |
---|
269 | definition max_length: jump_length → jump_length → jump_length ≝ |
---|
270 | λj1.λj2. |
---|
271 | match j1 with |
---|
272 | [ long_jump ⇒ long_jump |
---|
273 | | absolute_jump ⇒ |
---|
274 | match j2 with |
---|
275 | [ absolute_jump ⇒ absolute_jump |
---|
276 | | _ ⇒ long_jump |
---|
277 | ] |
---|
278 | | short_jump ⇒ |
---|
279 | match j2 with |
---|
280 | [ short_jump ⇒ short_jump |
---|
281 | | _ ⇒ long_jump |
---|
282 | ] |
---|
283 | ]. |
---|
284 | |
---|
285 | lemma dec_jmple: ∀x,y:jump_length.Sum (jmple x y) (¬(jmple x y)). |
---|
286 | #x #y cases x cases y /3 by inl, inr, nmk, I/ |
---|
287 | qed. |
---|
288 | |
---|
289 | lemma jmpleq_max_length: ∀ol,nl. |
---|
290 | jmpleq ol (max_length ol nl). |
---|
291 | #ol #nl cases ol cases nl |
---|
292 | /2 by or_introl, or_intror, I/ |
---|
293 | qed. |
---|
294 | |
---|
295 | lemma dec_eq_jump_length: ∀a,b:jump_length.Sum (a = b) (a ≠ b). |
---|
296 | #a #b cases a cases b /2/ |
---|
297 | %2 @nmk #H destruct (H) |
---|
298 | qed. |
---|
299 | |
---|
300 | (* The function that creates the label-to-address map *) |
---|
301 | definition create_label_map: ∀program:list labelled_instruction. |
---|
302 | (Σlabels:label_map. |
---|
303 | ∀l.occurs_exactly_once ?? l program → |
---|
304 | bitvector_of_nat ? (lookup_def ?? labels l 0) = |
---|
305 | address_of_word_labels_code_mem program l |
---|
306 | ) ≝ |
---|
307 | λprogram. |
---|
308 | \fst (create_label_cost_map program). |
---|
309 | #l #Hl lapply (pi2 ?? (create_label_cost_map0 program)) @pair_elim |
---|
310 | #labels #costs #EQ normalize nodelta #H whd in match create_label_cost_map; |
---|
311 | normalize nodelta >EQ @(H l Hl) |
---|
312 | qed. |
---|
313 | |
---|
314 | (* General note on jump length selection: the jump displacement is added/replaced |
---|
315 | * AFTER the fetch (and attendant PC increase), but we calculate before the |
---|
316 | * fetch, which means that in the case of a short and medium jump we are 2 |
---|
317 | * bytes off and have to compensate. |
---|
318 | * For the long jump we don't care, because the PC gets replaced integrally anyway. *) |
---|
319 | definition select_reljump_length: label_map → ppc_pc_map → ppc_pc_map → ℕ → ℕ → |
---|
320 | Identifier → jump_length ≝ |
---|
321 | λlabels.λold_sigma.λinc_sigma.λadded.λppc.λlbl. |
---|
322 | let pc ≝ \fst inc_sigma in |
---|
323 | let pc_plus_jmp_length ≝ bitvector_of_nat ? (pc+2) in |
---|
324 | let paddr ≝ lookup_def … labels lbl 0 in |
---|
325 | let addr ≝ bitvector_of_nat ? (if leb paddr ppc (* jump to address already known *) |
---|
326 | then \fst (bvt_lookup … (bitvector_of_nat 16 paddr) (\snd inc_sigma) 〈0,short_jump〉) |
---|
327 | else \fst (bvt_lookup … (bitvector_of_nat 16 paddr) (\snd old_sigma) 〈0,short_jump〉)+added) in |
---|
328 | let 〈sj_possible, disp〉 ≝ short_jump_cond pc_plus_jmp_length addr in |
---|
329 | if sj_possible |
---|
330 | then short_jump |
---|
331 | else long_jump. |
---|
332 | |
---|
333 | definition select_call_length: label_map → ppc_pc_map → ppc_pc_map → ℕ → ℕ → |
---|
334 | Identifier → jump_length ≝ |
---|
335 | λlabels.λold_sigma.λinc_sigma.λadded.λppc.λlbl. |
---|
336 | let pc ≝ \fst inc_sigma in |
---|
337 | let pc_plus_jmp_length ≝ bitvector_of_nat ? (pc+2) in |
---|
338 | let paddr ≝ lookup_def ? ? labels lbl 0 in |
---|
339 | let addr ≝ bitvector_of_nat ? |
---|
340 | (if leb paddr ppc (* jump to address already known *) |
---|
341 | then \fst (bvt_lookup … (bitvector_of_nat ? paddr) (\snd inc_sigma) 〈0,short_jump〉) |
---|
342 | else \fst (bvt_lookup … (bitvector_of_nat ? paddr) (\snd old_sigma) 〈0,short_jump〉)+added) in |
---|
343 | let 〈aj_possible, disp〉 ≝ absolute_jump_cond pc_plus_jmp_length addr in |
---|
344 | if aj_possible |
---|
345 | then absolute_jump |
---|
346 | else long_jump. |
---|
347 | |
---|
348 | definition select_jump_length: label_map → ppc_pc_map → ppc_pc_map → ℕ → ℕ → |
---|
349 | Identifier → jump_length ≝ |
---|
350 | λlabels.λold_sigma.λinc_sigma.λadded.λppc.λlbl. |
---|
351 | let pc ≝ \fst inc_sigma in |
---|
352 | let pc_plus_jmp_length ≝ bitvector_of_nat ? (pc+2) in |
---|
353 | let paddr ≝ lookup_def … labels lbl 0 in |
---|
354 | let addr ≝ bitvector_of_nat ? (if leb paddr ppc (* jump to address already known *) |
---|
355 | then \fst (bvt_lookup … (bitvector_of_nat 16 paddr) (\snd inc_sigma) 〈0,short_jump〉) |
---|
356 | else \fst (bvt_lookup … (bitvector_of_nat 16 paddr) (\snd old_sigma) 〈0,short_jump〉)+added) in |
---|
357 | let 〈sj_possible, disp〉 ≝ short_jump_cond pc_plus_jmp_length addr in |
---|
358 | if sj_possible |
---|
359 | then short_jump |
---|
360 | else select_call_length labels old_sigma inc_sigma added ppc lbl. |
---|
361 | |
---|
362 | definition jump_expansion_step_instruction: label_map → ppc_pc_map → ppc_pc_map → |
---|
363 | ℕ → ℕ → preinstruction Identifier → option jump_length ≝ |
---|
364 | λlabels.λold_sigma.λinc_sigma.λadded.λppc.λi. |
---|
365 | match i with |
---|
366 | [ JC j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
367 | | JNC j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
368 | | JZ j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
369 | | JNZ j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
370 | | JB _ j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
371 | | JBC _ j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
372 | | JNB _ j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
373 | | CJNE _ j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
374 | | DJNZ _ j ⇒ Some ? (select_reljump_length labels old_sigma inc_sigma added ppc j) |
---|
375 | | _ ⇒ None ? |
---|
376 | ]. |
---|
377 | |
---|
378 | lemma dec_is_jump: ∀x.Sum (is_jump x) (¬is_jump x). |
---|
379 | #i cases i |
---|
380 | [#id cases id |
---|
381 | [1,2,3,6,7,33,34: |
---|
382 | #x #y %2 whd in match (is_jump ?); /2 by nmk/ |
---|
383 | |4,5,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32: |
---|
384 | #x %2 whd in match (is_jump ?); /2 by nmk/ |
---|
385 | |35,36,37: %2 whd in match (is_jump ?); /2 by nmk/ |
---|
386 | |9,10,14,15: #x %1 / by I/ |
---|
387 | |11,12,13,16,17: #x #y %1 / by I/ |
---|
388 | ] |
---|
389 | |2,3: #x %2 /2 by nmk/ |
---|
390 | |4,5: #x %1 / by I/ |
---|
391 | |6: #x #y %2 /2 by nmk/ |
---|
392 | ] |
---|
393 | qed. |
---|
394 | |
---|
395 | (* The first step of the jump expansion: everything to short. *) |
---|
396 | definition jump_expansion_start: |
---|
397 | ∀program:(Σl:list labelled_instruction.S (|l|) < 2^16 ∧ is_well_labelled_p l). |
---|
398 | ∀labels:label_map. |
---|
399 | Σpolicy:option ppc_pc_map. |
---|
400 | match policy with |
---|
401 | [ None ⇒ True |
---|
402 | | Some p ⇒ And (And (And (And (And |
---|
403 | (not_jump_default (pi1 ?? program) p) |
---|
404 | (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd p) 〈0,short_jump〉) = 0)) |
---|
405 | (\fst p = \fst (bvt_lookup … (bitvector_of_nat ? (|program|)) (\snd p) 〈0,short_jump〉))) |
---|
406 | (sigma_compact_unsafe program labels p)) |
---|
407 | (∀i.i ≤ |program| → ∃pc. |
---|
408 | bvt_lookup_opt … (bitvector_of_nat ? i) (\snd p) = Some ? 〈pc,short_jump〉)) |
---|
409 | (\fst p ≤ 2^16) |
---|
410 | ] ≝ |
---|
411 | λprogram.λlabels. |
---|
412 | let final_policy ≝ foldl_strong (option Identifier × pseudo_instruction) |
---|
413 | (λprefix.Σpolicy:ppc_pc_map.And (And (And (And |
---|
414 | (not_jump_default prefix policy) |
---|
415 | (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd policy) 〈0,short_jump〉) = 0)) |
---|
416 | (\fst policy = \fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd policy) 〈0,short_jump〉))) |
---|
417 | (sigma_compact_unsafe prefix labels policy)) |
---|
418 | (∀i.i ≤ |prefix| → ∃pc. |
---|
419 | bvt_lookup_opt … (bitvector_of_nat ? i) (\snd policy) = Some ? 〈pc,short_jump〉)) |
---|
420 | program |
---|
421 | (λprefix.λx.λtl.λprf.λp. |
---|
422 | let 〈pc,sigma〉 ≝ pi1 ?? p in |
---|
423 | let 〈label,instr〉 ≝ x in |
---|
424 | let isize ≝ instruction_size_jmplen short_jump instr in |
---|
425 | 〈pc + isize, bvt_insert … (bitvector_of_nat 16 (S (|prefix|))) 〈pc+isize,short_jump〉 sigma〉 |
---|
426 | ) 〈0, bvt_insert ?? (bitvector_of_nat 16 0) 〈0,short_jump〉 (Stub ??)〉 in |
---|
427 | if gtb (\fst (pi1 ?? final_policy)) 2^16 then |
---|
428 | None ? |
---|
429 | else |
---|
430 | Some ? (pi1 ?? final_policy). |
---|
431 | [ / by I/ |
---|
432 | | lapply p -p generalize in match (foldl_strong ?????); * #p #Hp #hg |
---|
433 | @conj [ @Hp | @not_lt_to_le @ltb_false_to_not_lt @hg ] |
---|
434 | | @conj [ @conj [ @conj [ @conj |
---|
435 | [ (* not_jump_default *) cases p -p #p cases p -p #pc #sigma #Hp |
---|
436 | cases x in prf; #lbl #ins #prf #i >append_length <commutative_plus #Hi |
---|
437 | normalize in Hi; normalize nodelta cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi |
---|
438 | [ >lookup_insert_miss |
---|
439 | [ (* USE[pass]: not_jump_default *) |
---|
440 | lapply (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hp))) i Hi) |
---|
441 | >nth_append_first |
---|
442 | [ #H #H2 @H @H2 |
---|
443 | | @Hi |
---|
444 | ] |
---|
445 | | @bitvector_of_nat_abs |
---|
446 | [ @(transitive_lt ??? Hi) @le_S_to_le] |
---|
447 | [1,2: @(transitive_lt … (proj1 ?? (pi2 ?? program))) @le_S_S >prf >append_length |
---|
448 | <plus_n_Sm @le_S_S @le_plus_n_r |
---|
449 | | @lt_to_not_eq @le_S @Hi |
---|
450 | ] |
---|
451 | ] |
---|
452 | | >Hi >lookup_insert_miss |
---|
453 | [ #_ (* USE: everything is short *) |
---|
454 | elim ((proj2 ?? Hp) (|prefix|) (le_n (|prefix|))) #pc #Hl |
---|
455 | >(lookup_opt_lookup_hit … Hl 〈0,short_jump〉) @refl |
---|
456 | | @bitvector_of_nat_abs |
---|
457 | [ @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf @le_S_S >append_length @le_plus_n_r |
---|
458 | | @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf @le_S_S >append_length <plus_n_Sm @le_S_S |
---|
459 | @le_plus_n_r |
---|
460 | | @lt_to_not_eq @le_n |
---|
461 | ] |
---|
462 | ] |
---|
463 | ] |
---|
464 | | (* 0 ↦ 0 *) |
---|
465 | cases p -p #p cases p -p #pc #sigma #Hp cases x #lbl #instr normalize nodelta |
---|
466 | >lookup_insert_miss |
---|
467 | [ (* USE[pass]: 0 ↦ 0 *) |
---|
468 | @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hp)))) |
---|
469 | | @bitvector_of_nat_abs |
---|
470 | [ / by / |
---|
471 | | @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length @le_S_S <plus_n_Sm |
---|
472 | @le_S_S @le_plus_n_r |
---|
473 | | @lt_to_not_eq / by / |
---|
474 | ] |
---|
475 | ] |
---|
476 | ] |
---|
477 | | (* fst p = pc *) |
---|
478 | cases p -p #p cases p -p #pc #sigma #Hp cases x #lbl #instr normalize nodelta |
---|
479 | >append_length >(commutative_plus (|prefix|)) >lookup_insert_hit @refl |
---|
480 | ] |
---|
481 | | (* policy_compact_unsafe *) #i >append_length <commutative_plus #Hi normalize in Hi; |
---|
482 | cases p -p #p cases p -p #fpc #sigma #Hp cases x #lbl #instr normalize nodelta |
---|
483 | cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi |
---|
484 | [ >lookup_opt_insert_miss |
---|
485 | [ >lookup_opt_insert_miss |
---|
486 | [ (* USE[pass]: policy_compact_unsafe *) |
---|
487 | lapply (proj2 ?? (proj1 ?? Hp) i Hi) |
---|
488 | lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? i) sigma)) |
---|
489 | cases (bvt_lookup_opt … (bitvector_of_nat ? i) sigma) in ⊢ (???% → %); |
---|
490 | [ #_ normalize nodelta / by / |
---|
491 | | #x cases x -x #pci #ji #EQi |
---|
492 | lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S i)) sigma)) |
---|
493 | cases (bvt_lookup_opt … (bitvector_of_nat ? (S i)) sigma) in ⊢ (???% → %); |
---|
494 | [ #_ normalize nodelta / by / |
---|
495 | | #x cases x -x #pcSi #jSi #EQSi normalize nodelta >nth_append_first |
---|
496 | [ / by / |
---|
497 | | @Hi |
---|
498 | ] |
---|
499 | ] |
---|
500 | ] |
---|
501 | ] |
---|
502 | ] |
---|
503 | [2: lapply (le_S_to_le … Hi) -Hi #Hi] |
---|
504 | @bitvector_of_nat_abs |
---|
505 | [1,4: @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf @le_S_S >append_length <commutative_plus |
---|
506 | @le_plus_a @Hi |
---|
507 | |2,5: @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf @le_S_S >append_length <plus_n_Sm |
---|
508 | @le_S_S @le_plus_n_r |
---|
509 | |3,6: @lt_to_not_eq @le_S_S @Hi |
---|
510 | ] |
---|
511 | | >lookup_opt_insert_miss |
---|
512 | [ >Hi >lookup_opt_insert_hit normalize nodelta |
---|
513 | (* USE: everything is short, fst p = pc *) |
---|
514 | elim ((proj2 ?? Hp) (|prefix|) (le_n ?)) #pc #Hl |
---|
515 | lapply (proj2 ?? (proj1 ?? (proj1 ?? Hp))) >Hl |
---|
516 | >(lookup_opt_lookup_hit … Hl 〈0,short_jump〉) #EQ normalize nodelta >nth_append_second |
---|
517 | [ <minus_n_n whd in match (nth ????); >EQ @refl |
---|
518 | | @le_n |
---|
519 | ] |
---|
520 | | @bitvector_of_nat_abs |
---|
521 | [ @(transitive_lt … (proj1 ?? (pi2 ?? program))) >Hi >prf @le_S_S >append_length <commutative_plus |
---|
522 | @le_plus_a @le_n |
---|
523 | | @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf @le_S_S >append_length <plus_n_Sm |
---|
524 | @le_S_S @le_plus_n_r |
---|
525 | | @lt_to_not_eq @le_S_S >Hi @le_n |
---|
526 | ] |
---|
527 | ] |
---|
528 | ] |
---|
529 | ] |
---|
530 | | (* everything is short *) #i >append_length <commutative_plus #Hi normalize in Hi; |
---|
531 | cases p -p #p cases p -p #pc #sigma #Hp cases x #lbl #instr normalize nodelta |
---|
532 | cases (le_to_or_lt_eq … Hi) -Hi #Hi |
---|
533 | [ >lookup_opt_insert_miss |
---|
534 | [ (* USE[pass]: everything is short *) |
---|
535 | @((proj2 ?? Hp) i (le_S_S_to_le … Hi)) |
---|
536 | | @bitvector_of_nat_abs |
---|
537 | [ @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length @le_S_S |
---|
538 | >commutative_plus @le_plus_a @le_S_S_to_le @Hi |
---|
539 | | @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length <plus_n_Sm |
---|
540 | @le_S_S @le_S_S @le_plus_n_r |
---|
541 | | @lt_to_not_eq @Hi |
---|
542 | ] |
---|
543 | ] |
---|
544 | | >Hi >lookup_opt_insert_hit @(ex_intro ?? (pc+instruction_size_jmplen short_jump instr)) |
---|
545 | @refl |
---|
546 | ] |
---|
547 | ] |
---|
548 | | @conj [ @conj [ @conj [ @conj |
---|
549 | [ #i cases i |
---|
550 | [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O |
---|
551 | | -i #i #Hi #Hj @⊥ @(absurd … Hi) @not_le_Sn_O |
---|
552 | ] |
---|
553 | ] ] |
---|
554 | >lookup_insert_hit @refl |
---|
555 | | #i cases i |
---|
556 | [ #Hi @⊥ @(absurd … Hi) @le_to_not_lt @le_n |
---|
557 | | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O |
---|
558 | ] |
---|
559 | ] |
---|
560 | | #i cases i |
---|
561 | [ #Hi >lookup_opt_insert_hit @(ex_intro ?? 0) @refl |
---|
562 | | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O |
---|
563 | ] |
---|
564 | ] |
---|
565 | ] |
---|
566 | qed. |
---|
567 | |
---|
568 | (* NOTE: we only compare the first elements here because otherwise the |
---|
569 | * added = 0 → policy_equal property of jump_expansion_step doesn't hold: |
---|
570 | * if we have not added anything to the pc, we only know the PC hasn't changed, |
---|
571 | * there might still have been a short/medium jump change *) |
---|
572 | definition sigma_pc_equal ≝ |
---|
573 | λprogram:list labelled_instruction.λp1,p2:ppc_pc_map. |
---|
574 | (∀n.n ≤ |program| → |
---|
575 | \fst (bvt_lookup … (bitvector_of_nat 16 n) (\snd p1) 〈0,short_jump〉) = |
---|
576 | \fst (bvt_lookup … (bitvector_of_nat 16 n) (\snd p2) 〈0,short_jump〉)). |
---|
577 | |
---|
578 | definition sigma_jump_equal ≝ |
---|
579 | λprogram:list labelled_instruction.λp1,p2:ppc_pc_map. |
---|
580 | (∀n.n < |program| → |
---|
581 | \snd (bvt_lookup … (bitvector_of_nat 16 n) (\snd p1) 〈0,short_jump〉) = |
---|
582 | \snd (bvt_lookup … (bitvector_of_nat 16 n) (\snd p2) 〈0,short_jump〉)). |
---|
583 | |
---|
584 | definition nec_plus_ultra ≝ |
---|
585 | λprogram:list labelled_instruction.λp:ppc_pc_map. |
---|
586 | ¬(∀i.i < |program| → is_jump (\snd (nth i ? program 〈None ?, Comment []〉)) → |
---|
587 | \snd (bvt_lookup … (bitvector_of_nat 16 i) (\snd p) 〈0,short_jump〉) = long_jump). |
---|
588 | |
---|
589 | (*include alias "common/Identifiers.ma".*) |
---|
590 | include alias "ASM/BitVector.ma". |
---|
591 | include alias "basics/lists/list.ma". |
---|
592 | include alias "arithmetics/nat.ma". |
---|
593 | include alias "basics/logic.ma". |
---|
594 | |
---|
595 | lemma jump_length_equal_max: ∀a,b,i. |
---|
596 | is_jump i → instruction_size_jmplen (max_length a b) i = instruction_size_jmplen a i → |
---|
597 | (max_length a b) = a. |
---|
598 | #a #b #i cases i |
---|
599 | [1: #pi cases pi |
---|
600 | [1,2,3,4,5,6,7,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37: |
---|
601 | try (#x #y #H #_) try (#x #H #_) try (#H #_) cases H |
---|
602 | |9,10,11,12,13,14,15,16,17: #x [3,4,5,8,9: #y] #_ try (#_ %) |
---|
603 | try (#abs normalize in abs; destruct (abs) @I) |
---|
604 | cases a; cases b; try (#_ %) try (#abs normalize in abs; destruct(abs) @I) |
---|
605 | try (@(subaddressing_mode_elim … x) #w #abs normalize in abs; destruct (abs) @I) |
---|
606 | cases x * #a1 #a2 @(subaddressing_mode_elim … a2) #w |
---|
607 | try ( #abs normalize in abs; destruct (abs) @I) |
---|
608 | @(subaddressing_mode_elim … a1) #w2 #abs normalize in abs; destruct (abs) |
---|
609 | ] |
---|
610 | |2,3,6: #x [3: #y] #H cases H |
---|
611 | |4,5: #id #_ cases a cases b |
---|
612 | [2,3,4,6,11,12,13,15: normalize #H destruct (H) |
---|
613 | |1,5,7,8,9,10,14,16,17,18: #H / by refl/ |
---|
614 | ] |
---|
615 | ] |
---|
616 | qed. |
---|
617 | |
---|
618 | lemma jump_length_le_max: ∀a,b,i.is_jump i → |
---|
619 | instruction_size_jmplen a i ≤ instruction_size_jmplen (max_length a b) i. |
---|
620 | #a #b #i cases i |
---|
621 | [2,3,6: #x [3: #y] #H cases H |
---|
622 | |4,5: #id #_ cases a cases b / by le_n/ |
---|
623 | |1: #pi cases pi |
---|
624 | [1,2,3,4,5,6,7,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37: |
---|
625 | try (#x #y #H) try (#x #H) try (#H) cases H |
---|
626 | |9,10,11,12,13,14,15,16,17: #x [3,4,5,8,9: #y] |
---|
627 | #_ cases a cases b |
---|
628 | [1,4,5,6,7,8,9: / by le_n/ |
---|
629 | |10,13,14,15,16,17,18: / by le_n/ |
---|
630 | |19,22,23,24,25,26,27: / by le_n/ |
---|
631 | |28,31,32,33,34,35,36: / by le_n/ |
---|
632 | |37,40,41,42,43,44,45: / by le_n/ |
---|
633 | |46,47,48,49,50,51,52,53,54: / by le_n/ |
---|
634 | |55,56,57,58,59,60,61,62,63: / by le_n/ |
---|
635 | |64,65,66,67,68,69,70,71,72: / by le_n/ |
---|
636 | |73,74,75,76,77,78,79,80,81: / by le_n/ |
---|
637 | ] |
---|
638 | try (@(subaddressing_mode_elim … x) #w normalize @le_S @le_S @le_S @le_S @le_S @le_n) |
---|
639 | cases x * #ad |
---|
640 | try (@(subaddressing_mode_elim … ad) #w #z normalize @le_S @le_S @le_S @le_S @le_S @le_n) |
---|
641 | #z @(subaddressing_mode_elim … z) #w normalize / by / |
---|
642 | ] |
---|
643 | ] |
---|
644 | qed. |
---|
645 | |
---|
646 | lemma label_in_program: ∀program:(Σl.S (|l|) < 2^16 ∧ is_well_labelled_p l).∀labels:(Σlm. |
---|
647 | ∀l.occurs_exactly_once ?? l program → |
---|
648 | bitvector_of_nat ? (lookup_def ?? lm l 0) = |
---|
649 | address_of_word_labels_code_mem program l).∀x. |
---|
650 | occurs_exactly_once ?? x program → |
---|
651 | lookup_def ASMTag ℕ labels x O≤|program|. |
---|
652 | #program cases program -program #program #Hprogram #labels #x cases labels |
---|
653 | -labels #labels #H lapply (H x) -H |
---|
654 | generalize in match (lookup_def … labels x 0); |
---|
655 | whd in match address_of_word_labels_code_mem; |
---|
656 | whd in match index_of; normalize nodelta elim program in Hprogram; |
---|
657 | [ #Hprogram #n cases not_implemented |
---|
658 | | #h #t #Hind #Hprogram #n #Hlm #Hocc lapply (Hlm Hocc) -Hlm #Hbv |
---|
659 | whd in match (occurs_exactly_once ????) in Hocc; |
---|
660 | whd in match (index_of_internal ????) in Hbv; |
---|
661 | lapply (refl ? (instruction_matches_identifier … x h)) |
---|
662 | lapply Hocc; lapply Hbv; -Hocc -Hbv |
---|
663 | cases (instruction_matches_identifier … x h) in ⊢ (% → % → ???% → %); |
---|
664 | normalize nodelta #Hbv #Hocc #EQ |
---|
665 | [ >(bitvector_of_nat_ok 16 n 0) |
---|
666 | [ @le_O_n |
---|
667 | | >(eq_eq_bv … Hbv) @I |
---|
668 | | / by / |
---|
669 | | cases daemon |
---|
670 | ] |
---|
671 | | cases n in Hbv; |
---|
672 | [ #_ @le_O_n |
---|
673 | | -n #n #Hbv @le_S_S @(Hind … Hocc) |
---|
674 | [ @conj |
---|
675 | [ @(transitive_lt … (proj1 ?? Hprogram)) @le_n |
---|
676 | | cases daemon (* axiomatize this *) |
---|
677 | ] |
---|
678 | | #_ lapply (bitvector_of_nat_ok 16 (S n) (index_of_internal ? (instruction_matches_identifier ?? x) t 1) ???) |
---|
679 | [ >Hbv >eq_bv_refl @I |
---|
680 | | @(transitive_lt … (proj1 ?? Hprogram)) cases daemon |
---|
681 | | cases daemon |
---|
682 | | #H >(index_of_label_from_internal … Hocc) |
---|
683 | <plus_O_n >(index_of_label_from_internal … Hocc) in H; |
---|
684 | #H >(injective_S … H) <plus_O_n @refl |
---|
685 | ] |
---|
686 | ] |
---|
687 | ] |
---|
688 | ] |
---|
689 | ] |
---|
690 | qed. |
---|
691 | |
---|
692 | lemma equal_compact_unsafe_compact: ∀program:(Σl.(S (|l|)) < 2^16 ∧ is_well_labelled_p l). |
---|
693 | ∀labels.∀old_sigma.∀sigma. |
---|
694 | sigma_pc_equal program old_sigma sigma → |
---|
695 | sigma_safe program labels 0 old_sigma sigma → |
---|
696 | sigma_compact_unsafe program labels sigma → |
---|
697 | sigma_compact program labels sigma. |
---|
698 | #program #labels #old_sigma #sigma #Hequal #Hsafe #Hcp_unsafe #i #Hi |
---|
699 | lapply (Hcp_unsafe i Hi) lapply (Hsafe i Hi) |
---|
700 | lapply (refl ? (lookup_opt … (bitvector_of_nat ? i) (\snd sigma))) |
---|
701 | cases (lookup_opt … (bitvector_of_nat ? i) (\snd sigma)) in ⊢ (???% → %); |
---|
702 | [ / by / |
---|
703 | | #x cases x -x #x1 #x2 #EQ |
---|
704 | cases (lookup_opt … (bitvector_of_nat ? (S i)) (\snd sigma)) |
---|
705 | [ / by / |
---|
706 | | #y cases y -y #y1 #y2 normalize nodelta #H #H2 |
---|
707 | cut (instruction_size_jmplen x2 |
---|
708 | (\snd (nth i ? program 〈None ?, Comment []〉)) = |
---|
709 | instruction_size … (bitvector_of_nat ? i) |
---|
710 | (\snd (nth i ? program 〈None ?, Comment []〉))) |
---|
711 | [5: #H3 <H3 @H2 |
---|
712 | |4: whd in match (instruction_size_jmplen ??); |
---|
713 | whd in match (instruction_size …); |
---|
714 | whd in match (assembly_1_pseudoinstruction …); |
---|
715 | whd in match (expand_pseudo_instruction …); |
---|
716 | normalize nodelta whd in match (append …) in H; |
---|
717 | cases (nth i ? program 〈None ?,Comment []〉) in H; |
---|
718 | #lbl #instr cases instr |
---|
719 | [2,3,6: #x [3: #y] normalize nodelta #H @refl |
---|
720 | |4,5: #x >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉) #Hj |
---|
721 | lapply (Hj x (refl ? x)) -Hj normalize nodelta |
---|
722 | >add_bitvector_of_nat_plus <(plus_n_Sm i 0) <plus_n_O |
---|
723 | cases x2 normalize nodelta |
---|
724 | [1,4: whd in match short_jump_cond; normalize nodelta |
---|
725 | lapply (refl ? (leb (lookup_def ?? labels x 0) (|[]@program|))) |
---|
726 | cases (leb (lookup_def ?? labels x 0) (|[]@program|)) in ⊢ (???% → %); #Hlab |
---|
727 | normalize nodelta |
---|
728 | >(Hequal (lookup_def ?? labels x 0) ?) |
---|
729 | [2,4,6,8: @(label_in_program program labels x) |
---|
730 | cases daemon (* XXX this has to come from somewhere else *) |
---|
731 | ] |
---|
732 | <plus_n_O |
---|
733 | cases (sub_16_with_carry (bitvector_of_nat ??) (bitvector_of_nat ??) false) |
---|
734 | #result #flags normalize nodelta |
---|
735 | cases (vsplit bool 9 7 result) #upper #lower normalize nodelta |
---|
736 | cases (get_index' bool 2 0 flags) normalize nodelta |
---|
737 | [5,6,7,8: #H @⊥ @(absurd ?? (proj2 ?? H)) / by I/ |
---|
738 | |1,2,3,4: cases (eq_bv 9 upper ?) |
---|
739 | [2,4,6,8: #H lapply (proj1 ?? H) #H3 destruct (H3) |
---|
740 | |1,3,5,7: #_ normalize nodelta @refl |
---|
741 | ] |
---|
742 | ] |
---|
743 | |2,5: whd in match short_jump_cond; whd in match absolute_jump_cond; |
---|
744 | lapply (refl ? (leb (lookup_def ?? labels x 0) (|[]@program|))) |
---|
745 | cases (leb (lookup_def ?? labels x 0) (|[]@program|)) in ⊢ (???% → %); #Hlab |
---|
746 | normalize nodelta |
---|
747 | (* USE: added = 0 → policy_pc_equal (from fold) *) |
---|
748 | >(Hequal (lookup_def ?? labels x 0) ?) |
---|
749 | [2,4,6,8: @(label_in_program program labels x) |
---|
750 | cases daemon (* XXX this has to come from somewhere else *)] |
---|
751 | <plus_n_O |
---|
752 | normalize nodelta cases (vsplit bool 5 11 ?) #addr1 #addr2 |
---|
753 | cases (vsplit bool 5 11 ?) #pc1 #pc2 normalize nodelta |
---|
754 | cases (sub_16_with_carry (bitvector_of_nat ??) (bitvector_of_nat ??) false) |
---|
755 | #result #flags normalize nodelta |
---|
756 | cases (vsplit bool 9 7 result) #upper #lower normalize nodelta |
---|
757 | cases (get_index' bool 2 0 flags) normalize nodelta |
---|
758 | #H >(proj2 ?? (proj1 ?? H)) >(proj1 ?? (proj1 ?? H)) normalize nodelta @refl |
---|
759 | |3,6: whd in match short_jump_cond; whd in match absolute_jump_cond; |
---|
760 | lapply (refl ? (leb (lookup_def ?? labels x 0) (|[]@program|))) |
---|
761 | cases (leb (lookup_def ?? labels x 0) (|[]@program|)) in ⊢ (???% → %); #Hlab |
---|
762 | normalize nodelta |
---|
763 | (* USE: added = 0 → policy_pc_equal (from fold) *) |
---|
764 | >(Hequal (lookup_def ?? labels x 0) ?) |
---|
765 | [2,4,6,8: @(label_in_program program labels x) |
---|
766 | cases daemon (* XXX this has to come from somewhere else *)] |
---|
767 | <plus_n_O normalize nodelta |
---|
768 | cases (vsplit bool 5 11 ?) #addr1 #addr2 |
---|
769 | cases (vsplit bool 5 11 ?) #pc1 #pc2 normalize nodelta |
---|
770 | cases (sub_16_with_carry (bitvector_of_nat ??) (bitvector_of_nat ??) false) |
---|
771 | #result #flags normalize nodelta |
---|
772 | cases (vsplit bool 9 7 result) #upper #lower normalize nodelta |
---|
773 | cases (get_index' bool 2 0 flags) normalize nodelta |
---|
774 | #H >(proj1 ?? H) >(proj2 ?? H) normalize nodelta @refl |
---|
775 | ] |
---|
776 | |1: #pi cases pi |
---|
777 | [1,2,3,4,5,6,7,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37: |
---|
778 | [1,2,3,6,7,24,25: #x #y |
---|
779 | |4,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23: #x] |
---|
780 | normalize nodelta #H @refl |
---|
781 | |9,10,11,12,13,14,15,16,17: [1,2,6,7: #x |3,4,5,8,9: #y #x] |
---|
782 | normalize nodelta >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉) |
---|
783 | #Hj lapply (Hj x (refl ? x)) -Hj |
---|
784 | whd in match expand_relative_jump; normalize nodelta |
---|
785 | whd in match expand_relative_jump_internal; normalize nodelta |
---|
786 | whd in match expand_relative_jump_unsafe; normalize nodelta |
---|
787 | whd in match expand_relative_jump_internal_unsafe; |
---|
788 | normalize nodelta >(add_bitvector_of_nat_plus ? i 1) |
---|
789 | <(plus_n_Sm i 0) <plus_n_O |
---|
790 | cases daemon (* XXX this needs subadressing mode magic, see above *) |
---|
791 | ] |
---|
792 | ] |
---|
793 | ] |
---|
794 | ] |
---|
795 | ] |
---|
796 | qed. |
---|
797 | |
---|
798 | lemma instruction_size_irrelevant: ∀i. |
---|
799 | ¬is_jump i → ∀j1,j2.instruction_size_jmplen j1 i = instruction_size_jmplen j2 i. |
---|
800 | #i cases i |
---|
801 | [2,3,6: #x [3: #y] #Hj #j1 #j2 % |
---|
802 | |4,5: #x #Hi cases Hi #abs @⊥ @abs @I |
---|
803 | |1: #pi cases pi |
---|
804 | [1,2,3,4,5,6,7,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37: |
---|
805 | [1,2,3,6,7,24,25: #x #y |
---|
806 | |4,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23: #x] |
---|
807 | #Hj #j1 #j2 % |
---|
808 | |9,10,11,12,13,14,15,16,17: [1,2,6,7: #x |3,4,5,8,9: #y #x] |
---|
809 | #Hi cases Hi #abs @⊥ @abs @I |
---|
810 | ] |
---|
811 | ] |
---|
812 | qed. |
---|