[877] | 1 | include "ASM/Assembly.ma". |
---|
| 2 | include "ASM/Interpret.ma". |
---|
[1014] | 3 | include "ASM/StatusProofs.ma". |
---|
[877] | 4 | |
---|
[905] | 5 | definition bit_elim_prop: ∀P: bool → Prop. Prop ≝ |
---|
| 6 | λP. |
---|
| 7 | P true ∧ P false. |
---|
| 8 | |
---|
| 9 | let rec bitvector_elim_prop_internal |
---|
| 10 | (n: nat) (P: BitVector n → Prop) (m: nat) on m: m ≤ n → BitVector (n - m) → Prop ≝ |
---|
| 11 | match m return λm. m ≤ n → BitVector (n - m) → Prop with |
---|
| 12 | [ O ⇒ λprf1. λprefix. P ? |
---|
| 13 | | S n' ⇒ λprf2. λprefix. bit_elim_prop (λbit. bitvector_elim_prop_internal n P n' ? ?) |
---|
| 14 | ]. |
---|
| 15 | [ applyS prefix |
---|
| 16 | | letin res ≝ (bit ::: prefix) |
---|
| 17 | < (minus_S_S ? ?) |
---|
| 18 | > (minus_Sn_m ? ?) |
---|
| 19 | [ @ res |
---|
| 20 | | @ prf2 |
---|
| 21 | ] |
---|
| 22 | | /2/ |
---|
| 23 | ]. |
---|
| 24 | qed. |
---|
| 25 | |
---|
| 26 | definition bitvector_elim_prop ≝ |
---|
| 27 | λn: nat. |
---|
| 28 | λP: BitVector n → Prop. |
---|
| 29 | bitvector_elim_prop_internal n P n ? ?. |
---|
| 30 | [ @ (le_n ?) |
---|
| 31 | | < (minus_n_n ?) |
---|
| 32 | @ [[ ]] |
---|
| 33 | ] |
---|
| 34 | qed. |
---|
| 35 | |
---|
| 36 | lemma bool_eq_internal_eq: |
---|
| 37 | ∀b, c. |
---|
| 38 | (λb. λc. (if b then c else (if c then false else true))) b c = true → b = c. |
---|
| 39 | #b #c |
---|
| 40 | cases b |
---|
| 41 | [ normalize // |
---|
| 42 | | normalize |
---|
| 43 | cases c |
---|
| 44 | [ normalize // |
---|
| 45 | | normalize // |
---|
| 46 | ] |
---|
| 47 | ] |
---|
| 48 | qed. |
---|
| 49 | |
---|
[877] | 50 | definition bit_elim: ∀P: bool → bool. bool ≝ |
---|
| 51 | λP. |
---|
| 52 | P true ∧ P false. |
---|
| 53 | |
---|
| 54 | let rec bitvector_elim_internal |
---|
| 55 | (n: nat) (P: BitVector n → bool) (m: nat) on m: m ≤ n → BitVector (n - m) → bool ≝ |
---|
| 56 | match m return λm. m ≤ n → BitVector (n - m) → bool with |
---|
| 57 | [ O ⇒ λprf1. λprefix. P ? |
---|
| 58 | | S n' ⇒ λprf2. λprefix. bit_elim (λbit. bitvector_elim_internal n P n' ? ?) |
---|
| 59 | ]. |
---|
| 60 | [ applyS prefix |
---|
| 61 | | letin res ≝ (bit ::: prefix) |
---|
| 62 | < (minus_S_S ? ?) |
---|
| 63 | > (minus_Sn_m ? ?) |
---|
| 64 | [ @ res |
---|
| 65 | | @ prf2 |
---|
| 66 | ] |
---|
| 67 | | /2/ |
---|
| 68 | ]. |
---|
| 69 | qed. |
---|
| 70 | |
---|
| 71 | definition bitvector_elim ≝ |
---|
| 72 | λn: nat. |
---|
| 73 | λP: BitVector n → bool. |
---|
| 74 | bitvector_elim_internal n P n ? ?. |
---|
| 75 | [ @ (le_n ?) |
---|
| 76 | | < (minus_n_n ?) |
---|
| 77 | @ [[ ]] |
---|
| 78 | ] |
---|
| 79 | qed. |
---|
| 80 | |
---|
[992] | 81 | lemma super_rewrite2: |
---|
| 82 | ∀A:Type[0].∀n,m.∀v1: Vector A n.∀v2: Vector A m. |
---|
| 83 | ∀P: ∀m. Vector A m → Prop. |
---|
| 84 | n=m → v1 ≃ v2 → P n v1 → P m v2. |
---|
| 85 | #A #n #m #v1 #v2 #P #EQ <EQ in v2; #V #JMEQ >JMEQ // |
---|
| 86 | qed. |
---|
| 87 | |
---|
[877] | 88 | lemma vector_cons_append: |
---|
| 89 | ∀A: Type[0]. |
---|
| 90 | ∀n: nat. |
---|
| 91 | ∀e: A. |
---|
| 92 | ∀v: Vector A n. |
---|
| 93 | e ::: v = [[ e ]] @@ v. |
---|
| 94 | # A # N # E # V |
---|
| 95 | elim V |
---|
| 96 | [ normalize % |
---|
| 97 | | # NN # AA # VV # IH |
---|
| 98 | normalize |
---|
[994] | 99 | % |
---|
| 100 | qed. |
---|
[877] | 101 | |
---|
[992] | 102 | lemma vector_cons_append2: |
---|
| 103 | ∀A: Type[0]. |
---|
| 104 | ∀n, m: nat. |
---|
| 105 | ∀v: Vector A n. |
---|
| 106 | ∀q: Vector A m. |
---|
| 107 | ∀hd: A. |
---|
| 108 | hd:::(v@@q) = (hd:::v)@@q. |
---|
| 109 | #A #n #m #v #q |
---|
| 110 | elim v |
---|
| 111 | [ #hd % |
---|
| 112 | | #n' #hd' #tl' #ih #hd' <ih % |
---|
| 113 | ] |
---|
[877] | 114 | qed. |
---|
| 115 | |
---|
[992] | 116 | lemma jmeq_cons_vector_monotone: |
---|
| 117 | ∀A: Type[0]. |
---|
| 118 | ∀m, n: nat. |
---|
| 119 | ∀v: Vector A m. |
---|
| 120 | ∀q: Vector A n. |
---|
| 121 | ∀prf: m = n. |
---|
| 122 | ∀hd: A. |
---|
| 123 | v ≃ q → hd:::v ≃ hd:::q. |
---|
| 124 | #A #m #n #v #q #prf #hd #E |
---|
| 125 | @(super_rewrite2 A … E) |
---|
| 126 | [ assumption | @jmrefl ] |
---|
| 127 | qed. |
---|
| 128 | |
---|
| 129 | lemma vector_associative_append: |
---|
| 130 | ∀A: Type[0]. |
---|
| 131 | ∀n, m, o: nat. |
---|
| 132 | ∀v: Vector A n. |
---|
| 133 | ∀q: Vector A m. |
---|
| 134 | ∀r: Vector A o. |
---|
| 135 | ((v @@ q) @@ r) |
---|
| 136 | ≃ |
---|
| 137 | (v @@ (q @@ r)). |
---|
| 138 | #A #n #m #o #v #q #r |
---|
| 139 | elim v |
---|
| 140 | [ % |
---|
| 141 | | #n' #hd #tl #ih |
---|
| 142 | <(vector_cons_append2 A … hd) |
---|
| 143 | @jmeq_cons_vector_monotone |
---|
| 144 | // |
---|
| 145 | ] |
---|
| 146 | qed. |
---|
| 147 | |
---|
[877] | 148 | lemma mem_middle_vector: |
---|
| 149 | ∀A: Type[0]. |
---|
| 150 | ∀m, o: nat. |
---|
| 151 | ∀eq: A → A → bool. |
---|
| 152 | ∀reflex: ∀a. eq a a = true. |
---|
| 153 | ∀p: Vector A m. |
---|
| 154 | ∀a: A. |
---|
| 155 | ∀r: Vector A o. |
---|
| 156 | mem A eq ? (p@@(a:::r)) a = true. |
---|
| 157 | # A # M # O # EQ # REFLEX # P # A |
---|
| 158 | elim P |
---|
| 159 | [ normalize |
---|
| 160 | > (REFLEX A) |
---|
| 161 | normalize |
---|
| 162 | # H |
---|
| 163 | % |
---|
| 164 | | # NN # AA # PP # IH |
---|
| 165 | normalize |
---|
| 166 | cases (EQ A AA) // |
---|
| 167 | @ IH |
---|
| 168 | ] |
---|
| 169 | qed. |
---|
| 170 | |
---|
| 171 | lemma mem_monotonic_wrt_append: |
---|
| 172 | ∀A: Type[0]. |
---|
| 173 | ∀m, o: nat. |
---|
| 174 | ∀eq: A → A → bool. |
---|
| 175 | ∀reflex: ∀a. eq a a = true. |
---|
| 176 | ∀p: Vector A m. |
---|
| 177 | ∀a: A. |
---|
| 178 | ∀r: Vector A o. |
---|
| 179 | mem A eq ? r a = true → mem A eq ? (p @@ r) a = true. |
---|
| 180 | # A # M # O # EQ # REFLEX # P # A |
---|
| 181 | elim P |
---|
| 182 | [ #R #H @H |
---|
| 183 | | #NN #AA # PP # IH #R #H |
---|
| 184 | normalize |
---|
| 185 | cases (EQ A AA) |
---|
| 186 | [ normalize % |
---|
| 187 | | @ IH @ H |
---|
| 188 | ] |
---|
| 189 | ] |
---|
| 190 | qed. |
---|
| 191 | |
---|
| 192 | lemma subvector_multiple_append: |
---|
| 193 | ∀A: Type[0]. |
---|
| 194 | ∀o, n: nat. |
---|
| 195 | ∀eq: A → A → bool. |
---|
| 196 | ∀refl: ∀a. eq a a = true. |
---|
| 197 | ∀h: Vector A o. |
---|
| 198 | ∀v: Vector A n. |
---|
| 199 | ∀m: nat. |
---|
| 200 | ∀q: Vector A m. |
---|
| 201 | bool_to_Prop (subvector_with A ? ? eq v (h @@ q @@ v)). |
---|
| 202 | # A # O # N # EQ # REFLEX # H # V |
---|
| 203 | elim V |
---|
| 204 | [ normalize |
---|
| 205 | # M # V % |
---|
| 206 | | # NN # AA # VV # IH # MM # QQ |
---|
| 207 | change with (bool_to_Prop (andb ??)) |
---|
| 208 | cut ((mem A EQ (O + (MM + S NN)) (H@@QQ@@AA:::VV) AA) = true) |
---|
| 209 | [ |
---|
| 210 | | # HH > HH |
---|
| 211 | > (vector_cons_append ? ? AA VV) |
---|
| 212 | change with (bool_to_Prop (subvector_with ??????)) |
---|
| 213 | @(super_rewrite2 A ((MM + 1)+ NN) (MM+S NN) ?? |
---|
| 214 | (λSS.λVS.bool_to_Prop (subvector_with ?? (O+SS) ?? (H@@VS))) |
---|
| 215 | ? |
---|
| 216 | (vector_associative_append A ? ? ? QQ [[AA]] VV)) |
---|
| 217 | [ >associative_plus // |
---|
| 218 | | @IH ] |
---|
| 219 | ] |
---|
| 220 | @(mem_monotonic_wrt_append) |
---|
| 221 | [ @ REFLEX |
---|
| 222 | | @(mem_monotonic_wrt_append) |
---|
| 223 | [ @ REFLEX |
---|
| 224 | | normalize |
---|
| 225 | > REFLEX |
---|
| 226 | normalize |
---|
| 227 | % |
---|
| 228 | ] |
---|
| 229 | ] |
---|
| 230 | qed. |
---|
| 231 | |
---|
| 232 | lemma vector_cons_empty: |
---|
| 233 | ∀A: Type[0]. |
---|
| 234 | ∀n: nat. |
---|
| 235 | ∀v: Vector A n. |
---|
| 236 | [[ ]] @@ v = v. |
---|
| 237 | # A # N # V |
---|
| 238 | elim V |
---|
| 239 | [ normalize % |
---|
| 240 | | # NN # HH # VV #H % |
---|
| 241 | ] |
---|
| 242 | qed. |
---|
| 243 | |
---|
| 244 | corollary subvector_hd_tl: |
---|
| 245 | ∀A: Type[0]. |
---|
| 246 | ∀o: nat. |
---|
| 247 | ∀eq: A → A → bool. |
---|
| 248 | ∀refl: ∀a. eq a a = true. |
---|
| 249 | ∀h: A. |
---|
| 250 | ∀v: Vector A o. |
---|
| 251 | bool_to_Prop (subvector_with A ? ? eq v (h ::: v)). |
---|
| 252 | # A # O # EQ # REFLEX # H # V |
---|
| 253 | > (vector_cons_append A ? H V) |
---|
| 254 | < (vector_cons_empty A ? ([[H]] @@ V)) |
---|
| 255 | @ (subvector_multiple_append A ? ? EQ REFLEX [[]] V ? [[ H ]]) |
---|
| 256 | qed. |
---|
| 257 | |
---|
| 258 | lemma eq_a_reflexive: |
---|
| 259 | ∀a. eq_a a a = true. |
---|
| 260 | # A |
---|
| 261 | cases A |
---|
| 262 | % |
---|
| 263 | qed. |
---|
| 264 | |
---|
| 265 | lemma is_in_monotonic_wrt_append: |
---|
| 266 | ∀m, n: nat. |
---|
| 267 | ∀p: Vector addressing_mode_tag m. |
---|
| 268 | ∀q: Vector addressing_mode_tag n. |
---|
| 269 | ∀to_search: addressing_mode. |
---|
| 270 | bool_to_Prop (is_in ? p to_search) → bool_to_Prop (is_in ? (q @@ p) to_search). |
---|
| 271 | # M # N # P # Q # TO_SEARCH |
---|
| 272 | # H |
---|
| 273 | elim Q |
---|
| 274 | [ normalize |
---|
| 275 | @ H |
---|
| 276 | | # NN # PP # QQ # IH |
---|
| 277 | normalize |
---|
| 278 | cases (is_a PP TO_SEARCH) |
---|
| 279 | [ normalize |
---|
| 280 | % |
---|
| 281 | | normalize |
---|
| 282 | normalize in IH |
---|
| 283 | @ IH |
---|
| 284 | ] |
---|
| 285 | ] |
---|
| 286 | qed. |
---|
| 287 | |
---|
| 288 | corollary is_in_hd_tl: |
---|
| 289 | ∀to_search: addressing_mode. |
---|
| 290 | ∀hd: addressing_mode_tag. |
---|
| 291 | ∀n: nat. |
---|
| 292 | ∀v: Vector addressing_mode_tag n. |
---|
| 293 | bool_to_Prop (is_in ? v to_search) → bool_to_Prop (is_in ? (hd:::v) to_search). |
---|
| 294 | # TO_SEARCH # HD # N # V |
---|
| 295 | elim V |
---|
| 296 | [ # H |
---|
| 297 | normalize in H; |
---|
| 298 | cases H |
---|
| 299 | | # NN # HHD # VV # IH # HH |
---|
| 300 | > vector_cons_append |
---|
| 301 | > (vector_cons_append ? ? HHD VV) |
---|
| 302 | @ (is_in_monotonic_wrt_append ? 1 ([[HHD]]@@VV) [[HD]] TO_SEARCH) |
---|
| 303 | @ HH |
---|
| 304 | ] |
---|
| 305 | qed. |
---|
| 306 | |
---|
| 307 | let rec list_addressing_mode_tags_elim |
---|
| 308 | (n: nat) (l: Vector addressing_mode_tag (S n)) on l: (l → bool) → bool ≝ |
---|
| 309 | match l return λx.match x with [O ⇒ λl: Vector … O. bool | S x' ⇒ λl: Vector addressing_mode_tag (S x'). |
---|
| 310 | (l → bool) → bool ] with |
---|
| 311 | [ VEmpty ⇒ true |
---|
| 312 | | VCons len hd tl ⇒ λP. |
---|
| 313 | let process_hd ≝ |
---|
| 314 | match hd return λhd. ∀P: hd:::tl → bool. bool with |
---|
| 315 | [ direct ⇒ λP.bitvector_elim 8 (λx. P (DIRECT x)) |
---|
| 316 | | indirect ⇒ λP.bit_elim (λx. P (INDIRECT x)) |
---|
| 317 | | ext_indirect ⇒ λP.bit_elim (λx. P (EXT_INDIRECT x)) |
---|
| 318 | | registr ⇒ λP.bitvector_elim 3 (λx. P (REGISTER x)) |
---|
| 319 | | acc_a ⇒ λP.P ACC_A |
---|
| 320 | | acc_b ⇒ λP.P ACC_B |
---|
| 321 | | dptr ⇒ λP.P DPTR |
---|
| 322 | | data ⇒ λP.bitvector_elim 8 (λx. P (DATA x)) |
---|
| 323 | | data16 ⇒ λP.bitvector_elim 16 (λx. P (DATA16 x)) |
---|
| 324 | | acc_dptr ⇒ λP.P ACC_DPTR |
---|
| 325 | | acc_pc ⇒ λP.P ACC_PC |
---|
| 326 | | ext_indirect_dptr ⇒ λP.P EXT_INDIRECT_DPTR |
---|
| 327 | | indirect_dptr ⇒ λP.P INDIRECT_DPTR |
---|
| 328 | | carry ⇒ λP.P CARRY |
---|
| 329 | | bit_addr ⇒ λP.bitvector_elim 8 (λx. P (BIT_ADDR x)) |
---|
| 330 | | n_bit_addr ⇒ λP.bitvector_elim 8 (λx. P (N_BIT_ADDR x)) |
---|
| 331 | | relative ⇒ λP.bitvector_elim 8 (λx. P (RELATIVE x)) |
---|
| 332 | | addr11 ⇒ λP.bitvector_elim 11 (λx. P (ADDR11 x)) |
---|
| 333 | | addr16 ⇒ λP.bitvector_elim 16 (λx. P (ADDR16 x)) |
---|
| 334 | ] |
---|
| 335 | in |
---|
| 336 | andb (process_hd P) |
---|
| 337 | (match len return λx. x = len → bool with |
---|
| 338 | [ O ⇒ λprf. true |
---|
| 339 | | S y ⇒ λprf. list_addressing_mode_tags_elim y ? P ] (refl ? len)) |
---|
| 340 | ]. |
---|
| 341 | try % |
---|
| 342 | [ 2: cases (sym_eq ??? prf); @tl |
---|
| 343 | | generalize in match H; generalize in match tl; cases prf; |
---|
| 344 | (* cases prf in tl H; : ??? WAS WORKING BEFORE *) |
---|
| 345 | #tl |
---|
| 346 | normalize in ⊢ (∀_: %. ?) |
---|
| 347 | # H |
---|
| 348 | whd |
---|
| 349 | normalize in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]) |
---|
| 350 | cases (is_a hd (subaddressing_modeel y tl H)) whd // ] |
---|
| 351 | qed. |
---|
| 352 | |
---|
| 353 | definition product_elim ≝ |
---|
| 354 | λm, n: nat. |
---|
| 355 | λv: Vector addressing_mode_tag (S m). |
---|
| 356 | λq: Vector addressing_mode_tag (S n). |
---|
| 357 | λP: (v × q) → bool. |
---|
| 358 | list_addressing_mode_tags_elim ? v (λx. list_addressing_mode_tags_elim ? q (λy. P 〈x, y〉)). |
---|
| 359 | |
---|
| 360 | definition union_elim ≝ |
---|
| 361 | λA, B: Type[0]. |
---|
| 362 | λelimA: (A → bool) → bool. |
---|
| 363 | λelimB: (B → bool) → bool. |
---|
| 364 | λelimU: A ⊎ B → bool. |
---|
| 365 | elimA (λa. elimB (λb. elimU (inl ? ? a) ∧ elimU (inr ? ? b))). |
---|
[892] | 366 | |
---|
| 367 | (* |
---|
[877] | 368 | definition preinstruction_elim: ∀P: preinstruction [[ relative ]] → bool. bool ≝ |
---|
| 369 | λP. |
---|
| 370 | list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (ADD ? ACC_A addr)) ∧ |
---|
| 371 | list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (ADDC ? ACC_A addr)) ∧ |
---|
| 372 | list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (SUBB ? ACC_A addr)) ∧ |
---|
| 373 | list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ; dptr ]] (λaddr. P (INC ? addr)) ∧ |
---|
| 374 | list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (DEC ? addr)) ∧ |
---|
| 375 | list_addressing_mode_tags_elim ? [[acc_b]] (λaddr. P (MUL ? ACC_A addr)) ∧ |
---|
| 376 | list_addressing_mode_tags_elim ? [[acc_b]] (λaddr. P (DIV ? ACC_A addr)) ∧ |
---|
| 377 | list_addressing_mode_tags_elim ? [[ registr ; direct ]] (λaddr. bitvector_elim 8 (λr. P (DJNZ ? addr (RELATIVE r)))) ∧ |
---|
| 378 | list_addressing_mode_tags_elim ? [[ acc_a ; carry ; bit_addr ]] (λaddr. P (CLR ? addr)) ∧ |
---|
| 379 | list_addressing_mode_tags_elim ? [[ acc_a ; carry ; bit_addr ]] (λaddr. P (CPL ? addr)) ∧ |
---|
| 380 | P (DA ? ACC_A) ∧ |
---|
| 381 | bitvector_elim 8 (λr. P (JC ? (RELATIVE r))) ∧ |
---|
| 382 | bitvector_elim 8 (λr. P (JNC ? (RELATIVE r))) ∧ |
---|
| 383 | bitvector_elim 8 (λr. P (JZ ? (RELATIVE r))) ∧ |
---|
| 384 | bitvector_elim 8 (λr. P (JNZ ? (RELATIVE r))) ∧ |
---|
| 385 | bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JB ? (BIT_ADDR b) (RELATIVE r))))) ∧ |
---|
| 386 | bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JNB ? (BIT_ADDR b) (RELATIVE r))))) ∧ |
---|
| 387 | bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JBC ? (BIT_ADDR b) (RELATIVE r))))) ∧ |
---|
| 388 | list_addressing_mode_tags_elim ? [[ registr; direct ]] (λaddr. bitvector_elim 8 (λr. P (DJNZ ? addr (RELATIVE r)))) ∧ |
---|
| 389 | P (RL ? ACC_A) ∧ |
---|
| 390 | P (RLC ? ACC_A) ∧ |
---|
| 391 | P (RR ? ACC_A) ∧ |
---|
| 392 | P (RRC ? ACC_A) ∧ |
---|
| 393 | P (SWAP ? ACC_A) ∧ |
---|
| 394 | P (RET ?) ∧ |
---|
| 395 | P (RETI ?) ∧ |
---|
| 396 | P (NOP ?) ∧ |
---|
| 397 | bit_elim (λb. P (XCHD ? ACC_A (INDIRECT b))) ∧ |
---|
| 398 | list_addressing_mode_tags_elim ? [[ carry; bit_addr ]] (λaddr. P (SETB ? addr)) ∧ |
---|
| 399 | bitvector_elim 8 (λaddr. P (PUSH ? (DIRECT addr))) ∧ |
---|
| 400 | bitvector_elim 8 (λaddr. P (POP ? (DIRECT addr))) ∧ |
---|
| 401 | union_elim ? ? (product_elim ? ? [[ acc_a ]] [[ direct; data ]]) |
---|
| 402 | (product_elim ? ? [[ registr; indirect ]] [[ data ]]) |
---|
| 403 | (λd. bitvector_elim 8 (λb. P (CJNE ? d (RELATIVE b)))) ∧ |
---|
| 404 | list_addressing_mode_tags_elim ? [[ registr; direct; indirect ]] (λaddr. P (XCH ? ACC_A addr)) ∧ |
---|
| 405 | union_elim ? ? (product_elim ? ? [[acc_a]] [[ data ; registr ; direct ; indirect ]]) |
---|
| 406 | (product_elim ? ? [[direct]] [[ acc_a ; data ]]) |
---|
| 407 | (λd. P (XRL ? d)) ∧ |
---|
| 408 | union_elim ? ? (union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; direct ; indirect ; data ]]) |
---|
| 409 | (product_elim ? ? [[direct]] [[ acc_a ; data ]])) |
---|
| 410 | (product_elim ? ? [[carry]] [[ bit_addr ; n_bit_addr]]) |
---|
| 411 | (λd. P (ANL ? d)) ∧ |
---|
| 412 | union_elim ? ? (union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; data ; direct ; indirect ]]) |
---|
| 413 | (product_elim ? ? [[direct]] [[ acc_a ; data ]])) |
---|
| 414 | (product_elim ? ? [[carry]] [[ bit_addr ; n_bit_addr]]) |
---|
| 415 | (λd. P (ORL ? d)) ∧ |
---|
| 416 | union_elim ? ? (product_elim ? ? [[acc_a]] [[ ext_indirect ; ext_indirect_dptr ]]) |
---|
| 417 | (product_elim ? ? [[ ext_indirect ; ext_indirect_dptr ]] [[acc_a]]) |
---|
| 418 | (λd. P (MOVX ? d)) ∧ |
---|
| 419 | union_elim ? ? ( |
---|
| 420 | union_elim ? ? ( |
---|
| 421 | union_elim ? ? ( |
---|
| 422 | union_elim ? ? ( |
---|
| 423 | union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; direct ; indirect ; data ]]) |
---|
| 424 | (product_elim ? ? [[ registr ; indirect ]] [[ acc_a ; direct ; data ]])) |
---|
| 425 | (product_elim ? ? [[direct]] [[ acc_a ; registr ; direct ; indirect ; data ]])) |
---|
| 426 | (product_elim ? ? [[dptr]] [[data16]])) |
---|
| 427 | (product_elim ? ? [[carry]] [[bit_addr]])) |
---|
| 428 | (product_elim ? ? [[bit_addr]] [[carry]]) |
---|
| 429 | (λd. P (MOV ? d)). |
---|
| 430 | % |
---|
| 431 | qed. |
---|
| 432 | |
---|
| 433 | definition instruction_elim: ∀P: instruction → bool. bool ≝ |
---|
| 434 | λP. (* |
---|
| 435 | bitvector_elim 11 (λx. P (ACALL (ADDR11 x))) ∧ |
---|
| 436 | bitvector_elim 16 (λx. P (LCALL (ADDR16 x))) ∧ |
---|
| 437 | bitvector_elim 11 (λx. P (AJMP (ADDR11 x))) ∧ |
---|
| 438 | bitvector_elim 16 (λx. P (LJMP (ADDR16 x))) ∧ *) |
---|
| 439 | bitvector_elim 8 (λx. P (SJMP (RELATIVE x))). (* ∧ |
---|
| 440 | P (JMP INDIRECT_DPTR) ∧ |
---|
| 441 | list_addressing_mode_tags_elim ? [[ acc_dptr; acc_pc ]] (λa. P (MOVC ACC_A a)) ∧ |
---|
| 442 | preinstruction_elim (λp. P (RealInstruction p)). *) |
---|
| 443 | % |
---|
| 444 | qed. |
---|
| 445 | |
---|
| 446 | |
---|
| 447 | axiom instruction_elim_complete: |
---|
| 448 | ∀P. instruction_elim P = true → ∀i. P i = true. |
---|
[892] | 449 | *) |
---|
[883] | 450 | (*definition eq_instruction ≝ |
---|
[877] | 451 | λi, j: instruction. |
---|
[883] | 452 | true.*) |
---|
[885] | 453 | |
---|
[991] | 454 | definition eq_addressing_mode: addressing_mode → addressing_mode → bool ≝ |
---|
| 455 | λa, b: addressing_mode. |
---|
| 456 | match a with |
---|
| 457 | [ DIRECT d ⇒ |
---|
| 458 | match b with |
---|
| 459 | [ DIRECT e ⇒ eq_bv ? d e |
---|
| 460 | | _ ⇒ false |
---|
| 461 | ] |
---|
| 462 | | INDIRECT b' ⇒ |
---|
| 463 | match b with |
---|
| 464 | [ INDIRECT e ⇒ eq_b b' e |
---|
| 465 | | _ ⇒ false |
---|
| 466 | ] |
---|
| 467 | | EXT_INDIRECT b' ⇒ |
---|
| 468 | match b with |
---|
| 469 | [ EXT_INDIRECT e ⇒ eq_b b' e |
---|
| 470 | | _ ⇒ false |
---|
| 471 | ] |
---|
| 472 | | REGISTER bv ⇒ |
---|
| 473 | match b with |
---|
| 474 | [ REGISTER bv' ⇒ eq_bv ? bv bv' |
---|
| 475 | | _ ⇒ false |
---|
| 476 | ] |
---|
| 477 | | ACC_A ⇒ match b with [ ACC_A ⇒ true | _ ⇒ false ] |
---|
| 478 | | ACC_B ⇒ match b with [ ACC_B ⇒ true | _ ⇒ false ] |
---|
| 479 | | DPTR ⇒ match b with [ DPTR ⇒ true | _ ⇒ false ] |
---|
| 480 | | DATA b' ⇒ |
---|
| 481 | match b with |
---|
| 482 | [ DATA e ⇒ eq_bv ? b' e |
---|
| 483 | | _ ⇒ false |
---|
| 484 | ] |
---|
| 485 | | DATA16 w ⇒ |
---|
| 486 | match b with |
---|
| 487 | [ DATA16 e ⇒ eq_bv ? w e |
---|
| 488 | | _ ⇒ false |
---|
| 489 | ] |
---|
| 490 | | ACC_DPTR ⇒ match b with [ ACC_DPTR ⇒ true | _ ⇒ false ] |
---|
| 491 | | ACC_PC ⇒ match b with [ ACC_PC ⇒ true | _ ⇒ false ] |
---|
| 492 | | EXT_INDIRECT_DPTR ⇒ match b with [ EXT_INDIRECT_DPTR ⇒ true | _ ⇒ false ] |
---|
| 493 | | INDIRECT_DPTR ⇒ match b with [ INDIRECT_DPTR ⇒ true | _ ⇒ false ] |
---|
| 494 | | CARRY ⇒ match b with [ CARRY ⇒ true | _ ⇒ false ] |
---|
| 495 | | BIT_ADDR b' ⇒ |
---|
| 496 | match b with |
---|
| 497 | [ BIT_ADDR e ⇒ eq_bv ? b' e |
---|
| 498 | | _ ⇒ false |
---|
| 499 | ] |
---|
| 500 | | N_BIT_ADDR b' ⇒ |
---|
| 501 | match b with |
---|
| 502 | [ N_BIT_ADDR e ⇒ eq_bv ? b' e |
---|
| 503 | | _ ⇒ false |
---|
| 504 | ] |
---|
| 505 | | RELATIVE n ⇒ |
---|
| 506 | match b with |
---|
| 507 | [ RELATIVE e ⇒ eq_bv ? n e |
---|
| 508 | | _ ⇒ false |
---|
| 509 | ] |
---|
| 510 | | ADDR11 w ⇒ |
---|
| 511 | match b with |
---|
| 512 | [ ADDR11 e ⇒ eq_bv ? w e |
---|
| 513 | | _ ⇒ false |
---|
| 514 | ] |
---|
| 515 | | ADDR16 w ⇒ |
---|
| 516 | match b with |
---|
| 517 | [ ADDR16 e ⇒ eq_bv ? w e |
---|
| 518 | | _ ⇒ false |
---|
| 519 | ] |
---|
| 520 | ]. |
---|
| 521 | |
---|
| 522 | lemma eq_bv_refl: |
---|
| 523 | ∀n, b. |
---|
| 524 | eq_bv n b b = true. |
---|
| 525 | #n #b cases b // |
---|
| 526 | qed. |
---|
| 527 | |
---|
| 528 | lemma eq_b_refl: |
---|
| 529 | ∀b. |
---|
| 530 | eq_b b b = true. |
---|
| 531 | #b cases b // |
---|
| 532 | qed. |
---|
| 533 | |
---|
| 534 | lemma eq_addressing_mode_refl: |
---|
| 535 | ∀a. eq_addressing_mode a a = true. |
---|
| 536 | #a cases a try #arg1 try #arg2 try @eq_bv_refl try @eq_b_refl |
---|
| 537 | try normalize % |
---|
| 538 | qed. |
---|
| 539 | |
---|
| 540 | definition eq_sum: ∀A, B. (A → A → bool) → (B → B → bool) → (A ⊎ B) → (A ⊎ B) → bool ≝ |
---|
| 541 | λlt, rt, leq, req, left, right. |
---|
| 542 | match left with |
---|
| 543 | [ inl l ⇒ |
---|
| 544 | match right with |
---|
| 545 | [ inl l' ⇒ leq l l' |
---|
| 546 | | _ ⇒ false |
---|
| 547 | ] |
---|
| 548 | | inr r ⇒ |
---|
| 549 | match right with |
---|
| 550 | [ inr r' ⇒ req r r' |
---|
| 551 | | _ ⇒ false |
---|
| 552 | ] |
---|
| 553 | ]. |
---|
| 554 | |
---|
| 555 | definition eq_prod: ∀A, B. (A → A → bool) → (B → B → bool) → (A × B) → (A × B) → bool ≝ |
---|
| 556 | λlt, rt, leq, req, left, right. |
---|
| 557 | let 〈l, r〉 ≝ left in |
---|
| 558 | let 〈l', r'〉 ≝ right in |
---|
| 559 | leq l l' ∧ req r r'. |
---|
| 560 | |
---|
| 561 | definition eq_preinstruction: preinstruction [[relative]] → preinstruction [[relative]] → bool ≝ |
---|
| 562 | λi, j. |
---|
| 563 | match i with |
---|
| 564 | [ ADD arg1 arg2 ⇒ |
---|
| 565 | match j with |
---|
| 566 | [ ADD arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 567 | | _ ⇒ false |
---|
| 568 | ] |
---|
| 569 | | ADDC arg1 arg2 ⇒ |
---|
| 570 | match j with |
---|
| 571 | [ ADDC arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 572 | | _ ⇒ false |
---|
| 573 | ] |
---|
| 574 | | SUBB arg1 arg2 ⇒ |
---|
| 575 | match j with |
---|
| 576 | [ SUBB arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 577 | | _ ⇒ false |
---|
| 578 | ] |
---|
| 579 | | INC arg ⇒ |
---|
| 580 | match j with |
---|
| 581 | [ INC arg' ⇒ eq_addressing_mode arg arg' |
---|
| 582 | | _ ⇒ false |
---|
| 583 | ] |
---|
| 584 | | DEC arg ⇒ |
---|
| 585 | match j with |
---|
| 586 | [ DEC arg' ⇒ eq_addressing_mode arg arg' |
---|
| 587 | | _ ⇒ false |
---|
| 588 | ] |
---|
| 589 | | MUL arg1 arg2 ⇒ |
---|
| 590 | match j with |
---|
| 591 | [ MUL arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 592 | | _ ⇒ false |
---|
| 593 | ] |
---|
| 594 | | DIV arg1 arg2 ⇒ |
---|
| 595 | match j with |
---|
| 596 | [ DIV arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 597 | | _ ⇒ false |
---|
| 598 | ] |
---|
| 599 | | DA arg ⇒ |
---|
| 600 | match j with |
---|
| 601 | [ DA arg' ⇒ eq_addressing_mode arg arg' |
---|
| 602 | | _ ⇒ false |
---|
| 603 | ] |
---|
| 604 | | JC arg ⇒ |
---|
| 605 | match j with |
---|
| 606 | [ JC arg' ⇒ eq_addressing_mode arg arg' |
---|
| 607 | | _ ⇒ false |
---|
| 608 | ] |
---|
| 609 | | JNC arg ⇒ |
---|
| 610 | match j with |
---|
| 611 | [ JNC arg' ⇒ eq_addressing_mode arg arg' |
---|
| 612 | | _ ⇒ false |
---|
| 613 | ] |
---|
| 614 | | JB arg1 arg2 ⇒ |
---|
| 615 | match j with |
---|
| 616 | [ JB arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 617 | | _ ⇒ false |
---|
| 618 | ] |
---|
| 619 | | JNB arg1 arg2 ⇒ |
---|
| 620 | match j with |
---|
| 621 | [ JNB arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 622 | | _ ⇒ false |
---|
| 623 | ] |
---|
| 624 | | JBC arg1 arg2 ⇒ |
---|
| 625 | match j with |
---|
| 626 | [ JBC arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 627 | | _ ⇒ false |
---|
| 628 | ] |
---|
| 629 | | JZ arg ⇒ |
---|
| 630 | match j with |
---|
| 631 | [ JZ arg' ⇒ eq_addressing_mode arg arg' |
---|
| 632 | | _ ⇒ false |
---|
| 633 | ] |
---|
| 634 | | JNZ arg ⇒ |
---|
| 635 | match j with |
---|
| 636 | [ JNZ arg' ⇒ eq_addressing_mode arg arg' |
---|
| 637 | | _ ⇒ false |
---|
| 638 | ] |
---|
| 639 | | CJNE arg1 arg2 ⇒ |
---|
| 640 | match j with |
---|
| 641 | [ CJNE arg1' arg2' ⇒ |
---|
| 642 | let prod_eq_left ≝ eq_prod [[acc_a]] [[direct; data]] eq_addressing_mode eq_addressing_mode in |
---|
| 643 | let prod_eq_right ≝ eq_prod [[registr; indirect]] [[data]] eq_addressing_mode eq_addressing_mode in |
---|
| 644 | let arg1_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in |
---|
| 645 | arg1_eq arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 646 | | _ ⇒ false |
---|
| 647 | ] |
---|
| 648 | | DJNZ arg1 arg2 ⇒ |
---|
| 649 | match j with |
---|
| 650 | [ DJNZ arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 651 | | _ ⇒ false |
---|
| 652 | ] |
---|
| 653 | | CLR arg ⇒ |
---|
| 654 | match j with |
---|
| 655 | [ CLR arg' ⇒ eq_addressing_mode arg arg' |
---|
| 656 | | _ ⇒ false |
---|
| 657 | ] |
---|
| 658 | | CPL arg ⇒ |
---|
| 659 | match j with |
---|
| 660 | [ CPL arg' ⇒ eq_addressing_mode arg arg' |
---|
| 661 | | _ ⇒ false |
---|
| 662 | ] |
---|
| 663 | | RL arg ⇒ |
---|
| 664 | match j with |
---|
| 665 | [ RL arg' ⇒ eq_addressing_mode arg arg' |
---|
| 666 | | _ ⇒ false |
---|
| 667 | ] |
---|
| 668 | | RLC arg ⇒ |
---|
| 669 | match j with |
---|
| 670 | [ RLC arg' ⇒ eq_addressing_mode arg arg' |
---|
| 671 | | _ ⇒ false |
---|
| 672 | ] |
---|
| 673 | | RR arg ⇒ |
---|
| 674 | match j with |
---|
| 675 | [ RR arg' ⇒ eq_addressing_mode arg arg' |
---|
| 676 | | _ ⇒ false |
---|
| 677 | ] |
---|
| 678 | | RRC arg ⇒ |
---|
| 679 | match j with |
---|
| 680 | [ RRC arg' ⇒ eq_addressing_mode arg arg' |
---|
| 681 | | _ ⇒ false |
---|
| 682 | ] |
---|
| 683 | | SWAP arg ⇒ |
---|
| 684 | match j with |
---|
| 685 | [ SWAP arg' ⇒ eq_addressing_mode arg arg' |
---|
| 686 | | _ ⇒ false |
---|
| 687 | ] |
---|
| 688 | | SETB arg ⇒ |
---|
| 689 | match j with |
---|
| 690 | [ SETB arg' ⇒ eq_addressing_mode arg arg' |
---|
| 691 | | _ ⇒ false |
---|
| 692 | ] |
---|
| 693 | | PUSH arg ⇒ |
---|
| 694 | match j with |
---|
| 695 | [ PUSH arg' ⇒ eq_addressing_mode arg arg' |
---|
| 696 | | _ ⇒ false |
---|
| 697 | ] |
---|
| 698 | | POP arg ⇒ |
---|
| 699 | match j with |
---|
| 700 | [ POP arg' ⇒ eq_addressing_mode arg arg' |
---|
| 701 | | _ ⇒ false |
---|
| 702 | ] |
---|
| 703 | | XCH arg1 arg2 ⇒ |
---|
| 704 | match j with |
---|
| 705 | [ XCH arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 706 | | _ ⇒ false |
---|
| 707 | ] |
---|
| 708 | | XCHD arg1 arg2 ⇒ |
---|
| 709 | match j with |
---|
| 710 | [ XCHD arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 711 | | _ ⇒ false |
---|
| 712 | ] |
---|
| 713 | | RET ⇒ match j with [ RET ⇒ true | _ ⇒ false ] |
---|
| 714 | | RETI ⇒ match j with [ RETI ⇒ true | _ ⇒ false ] |
---|
| 715 | | NOP ⇒ match j with [ NOP ⇒ true | _ ⇒ false ] |
---|
| 716 | | MOVX arg ⇒ |
---|
| 717 | match j with |
---|
| 718 | [ MOVX arg' ⇒ |
---|
| 719 | let prod_eq_left ≝ eq_prod [[acc_a]] [[ext_indirect; ext_indirect_dptr]] eq_addressing_mode eq_addressing_mode in |
---|
| 720 | let prod_eq_right ≝ eq_prod [[ext_indirect; ext_indirect_dptr]] [[acc_a]] eq_addressing_mode eq_addressing_mode in |
---|
| 721 | let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in |
---|
| 722 | sum_eq arg arg' |
---|
| 723 | | _ ⇒ false |
---|
| 724 | ] |
---|
| 725 | | XRL arg ⇒ |
---|
| 726 | match j with |
---|
| 727 | [ XRL arg' ⇒ |
---|
| 728 | let prod_eq_left ≝ eq_prod [[acc_a]] [[ data ; registr ; direct ; indirect ]] eq_addressing_mode eq_addressing_mode in |
---|
| 729 | let prod_eq_right ≝ eq_prod [[direct]] [[ acc_a ; data ]] eq_addressing_mode eq_addressing_mode in |
---|
| 730 | let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in |
---|
| 731 | sum_eq arg arg' |
---|
| 732 | | _ ⇒ false |
---|
| 733 | ] |
---|
| 734 | | ORL arg ⇒ |
---|
| 735 | match j with |
---|
| 736 | [ ORL arg' ⇒ |
---|
| 737 | let prod_eq_left1 ≝ eq_prod [[acc_a]] [[ registr ; data ; direct ; indirect ]] eq_addressing_mode eq_addressing_mode in |
---|
| 738 | let prod_eq_left2 ≝ eq_prod [[direct]] [[ acc_a; data ]] eq_addressing_mode eq_addressing_mode in |
---|
| 739 | let prod_eq_left ≝ eq_sum ? ? prod_eq_left1 prod_eq_left2 in |
---|
| 740 | let prod_eq_right ≝ eq_prod [[carry]] [[ bit_addr ; n_bit_addr]] eq_addressing_mode eq_addressing_mode in |
---|
| 741 | let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in |
---|
| 742 | sum_eq arg arg' |
---|
| 743 | | _ ⇒ false |
---|
| 744 | ] |
---|
| 745 | | ANL arg ⇒ |
---|
| 746 | match j with |
---|
| 747 | [ ANL arg' ⇒ |
---|
| 748 | let prod_eq_left1 ≝ eq_prod [[acc_a]] [[ registr ; direct ; indirect ; data ]] eq_addressing_mode eq_addressing_mode in |
---|
| 749 | let prod_eq_left2 ≝ eq_prod [[direct]] [[ acc_a; data ]] eq_addressing_mode eq_addressing_mode in |
---|
| 750 | let prod_eq_left ≝ eq_sum ? ? prod_eq_left1 prod_eq_left2 in |
---|
| 751 | let prod_eq_right ≝ eq_prod [[carry]] [[ bit_addr ; n_bit_addr]] eq_addressing_mode eq_addressing_mode in |
---|
| 752 | let sum_eq ≝ eq_sum ? ? prod_eq_left prod_eq_right in |
---|
| 753 | sum_eq arg arg' |
---|
| 754 | | _ ⇒ false |
---|
| 755 | ] |
---|
| 756 | | MOV arg ⇒ |
---|
| 757 | match j with |
---|
| 758 | [ MOV arg' ⇒ |
---|
| 759 | let prod_eq_6 ≝ eq_prod [[acc_a]] [[registr; direct; indirect; data]] eq_addressing_mode eq_addressing_mode in |
---|
| 760 | let prod_eq_5 ≝ eq_prod [[registr; indirect]] [[acc_a; direct; data]] eq_addressing_mode eq_addressing_mode in |
---|
| 761 | let prod_eq_4 ≝ eq_prod [[direct]] [[acc_a; registr; direct; indirect; data]] eq_addressing_mode eq_addressing_mode in |
---|
| 762 | let prod_eq_3 ≝ eq_prod [[dptr]] [[data16]] eq_addressing_mode eq_addressing_mode in |
---|
| 763 | let prod_eq_2 ≝ eq_prod [[carry]] [[bit_addr]] eq_addressing_mode eq_addressing_mode in |
---|
| 764 | let prod_eq_1 ≝ eq_prod [[bit_addr]] [[carry]] eq_addressing_mode eq_addressing_mode in |
---|
| 765 | let sum_eq_1 ≝ eq_sum ? ? prod_eq_6 prod_eq_5 in |
---|
| 766 | let sum_eq_2 ≝ eq_sum ? ? sum_eq_1 prod_eq_4 in |
---|
| 767 | let sum_eq_3 ≝ eq_sum ? ? sum_eq_2 prod_eq_3 in |
---|
| 768 | let sum_eq_4 ≝ eq_sum ? ? sum_eq_3 prod_eq_2 in |
---|
| 769 | let sum_eq_5 ≝ eq_sum ? ? sum_eq_4 prod_eq_1 in |
---|
| 770 | sum_eq_5 arg arg' |
---|
| 771 | | _ ⇒ false |
---|
| 772 | ] |
---|
| 773 | ]. |
---|
| 774 | |
---|
| 775 | lemma eq_sum_refl: |
---|
| 776 | ∀A, B: Type[0]. |
---|
| 777 | ∀leq, req. |
---|
| 778 | ∀s. |
---|
| 779 | ∀leq_refl: (∀t. leq t t = true). |
---|
| 780 | ∀req_refl: (∀u. req u u = true). |
---|
| 781 | eq_sum A B leq req s s = true. |
---|
| 782 | #A #B #leq #req #s #leq_refl #req_refl |
---|
| 783 | cases s whd in ⊢ (? → ??%?) // |
---|
| 784 | qed. |
---|
| 785 | |
---|
| 786 | lemma eq_prod_refl: |
---|
| 787 | ∀A, B: Type[0]. |
---|
| 788 | ∀leq, req. |
---|
| 789 | ∀s. |
---|
| 790 | ∀leq_refl: (∀t. leq t t = true). |
---|
| 791 | ∀req_refl: (∀u. req u u = true). |
---|
| 792 | eq_prod A B leq req s s = true. |
---|
| 793 | #A #B #leq #req #s #leq_refl #req_refl |
---|
| 794 | cases s whd in ⊢ (? → ? → ??%?) #l #r >leq_refl normalize @req_refl |
---|
| 795 | qed. |
---|
| 796 | |
---|
| 797 | lemma eq_preinstruction_refl: |
---|
| 798 | ∀i. |
---|
| 799 | eq_preinstruction i i = true. |
---|
| 800 | #i cases i try #arg1 try #arg2 |
---|
| 801 | try @eq_addressing_mode_refl |
---|
| 802 | [1,2,3,4,5,6,7,8,10,16,17,18,19,20: |
---|
| 803 | whd in ⊢ (??%?) |
---|
| 804 | try % |
---|
| 805 | >eq_addressing_mode_refl |
---|
| 806 | >eq_addressing_mode_refl % |
---|
| 807 | |13,15: |
---|
| 808 | whd in ⊢ (??%?) |
---|
| 809 | cases arg1 |
---|
| 810 | [*: |
---|
| 811 | #arg1_left normalize nodelta |
---|
| 812 | >eq_prod_refl [*: try % #argr @eq_addressing_mode_refl] |
---|
| 813 | ] |
---|
| 814 | |11,12: |
---|
| 815 | whd in ⊢ (??%?) |
---|
| 816 | cases arg1 |
---|
| 817 | [1: |
---|
| 818 | #arg1_left normalize nodelta |
---|
| 819 | >(eq_sum_refl …) |
---|
| 820 | [1: % | 2,3: #arg @eq_prod_refl ] |
---|
| 821 | @eq_addressing_mode_refl |
---|
| 822 | |2: |
---|
| 823 | #arg1_left normalize nodelta |
---|
| 824 | @eq_prod_refl [*: @eq_addressing_mode_refl ] |
---|
| 825 | |3: |
---|
| 826 | #arg1_left normalize nodelta |
---|
| 827 | >(eq_sum_refl …) [1: % |
---|
| 828 | |2,3: #arg @eq_prod_refl #arg @eq_addressing_mode_refl ] |
---|
| 829 | |4: |
---|
| 830 | #arg1_left normalize nodelta |
---|
| 831 | @eq_prod_refl [*: #arg @eq_addressing_mode_refl ] |
---|
| 832 | ] |
---|
| 833 | |14: |
---|
| 834 | whd in ⊢ (??%?) |
---|
| 835 | cases arg1 |
---|
| 836 | [ #arg1_left normalize nodelta |
---|
| 837 | @eq_sum_refl |
---|
| 838 | [1: #arg @eq_sum_refl |
---|
| 839 | [1: #arg @eq_sum_refl |
---|
| 840 | [1: #arg @eq_sum_refl |
---|
| 841 | [1: #arg @eq_prod_refl |
---|
| 842 | [*: @eq_addressing_mode_refl ] |
---|
| 843 | |2: #arg @eq_prod_refl |
---|
| 844 | [*: #arg @eq_addressing_mode_refl ] |
---|
| 845 | ] |
---|
| 846 | |2: #arg @eq_prod_refl |
---|
| 847 | [*: #arg @eq_addressing_mode_refl ] |
---|
| 848 | ] |
---|
| 849 | |2: #arg @eq_prod_refl |
---|
| 850 | [*: #arg @eq_addressing_mode_refl ] |
---|
| 851 | ] |
---|
| 852 | |2: #arg @eq_prod_refl |
---|
| 853 | [*: #arg @eq_addressing_mode_refl ] |
---|
| 854 | ] |
---|
| 855 | |2: #arg1_right normalize nodelta |
---|
| 856 | @eq_prod_refl [*: #arg @eq_addressing_mode_refl ] |
---|
| 857 | ] |
---|
| 858 | |*: |
---|
| 859 | whd in ⊢ (??%?) |
---|
| 860 | cases arg1 |
---|
| 861 | [*: #arg1 >eq_sum_refl |
---|
| 862 | [1,4: normalize @eq_addressing_mode_refl |
---|
| 863 | |2,3,5,6: #arg @eq_prod_refl |
---|
| 864 | [*: #arg @eq_addressing_mode_refl ] |
---|
| 865 | ] |
---|
| 866 | ] |
---|
| 867 | ] |
---|
| 868 | qed. |
---|
| 869 | |
---|
| 870 | definition eq_instruction: instruction → instruction → bool ≝ |
---|
| 871 | λi, j. |
---|
| 872 | match i with |
---|
| 873 | [ ACALL arg ⇒ |
---|
| 874 | match j with |
---|
| 875 | [ ACALL arg' ⇒ eq_addressing_mode arg arg' |
---|
| 876 | | _ ⇒ false |
---|
| 877 | ] |
---|
| 878 | | LCALL arg ⇒ |
---|
| 879 | match j with |
---|
| 880 | [ LCALL arg' ⇒ eq_addressing_mode arg arg' |
---|
| 881 | | _ ⇒ false |
---|
| 882 | ] |
---|
| 883 | | AJMP arg ⇒ |
---|
| 884 | match j with |
---|
| 885 | [ AJMP arg' ⇒ eq_addressing_mode arg arg' |
---|
| 886 | | _ ⇒ false |
---|
| 887 | ] |
---|
| 888 | | LJMP arg ⇒ |
---|
| 889 | match j with |
---|
| 890 | [ LJMP arg' ⇒ eq_addressing_mode arg arg' |
---|
| 891 | | _ ⇒ false |
---|
| 892 | ] |
---|
| 893 | | SJMP arg ⇒ |
---|
| 894 | match j with |
---|
| 895 | [ SJMP arg' ⇒ eq_addressing_mode arg arg' |
---|
| 896 | | _ ⇒ false |
---|
| 897 | ] |
---|
| 898 | | JMP arg ⇒ |
---|
| 899 | match j with |
---|
| 900 | [ JMP arg' ⇒ eq_addressing_mode arg arg' |
---|
| 901 | | _ ⇒ false |
---|
| 902 | ] |
---|
| 903 | | MOVC arg1 arg2 ⇒ |
---|
| 904 | match j with |
---|
| 905 | [ MOVC arg1' arg2' ⇒ eq_addressing_mode arg1 arg1' ∧ eq_addressing_mode arg2 arg2' |
---|
| 906 | | _ ⇒ false |
---|
| 907 | ] |
---|
| 908 | | RealInstruction instr ⇒ |
---|
| 909 | match j with |
---|
| 910 | [ RealInstruction instr' ⇒ eq_preinstruction instr instr' |
---|
| 911 | | _ ⇒ false |
---|
| 912 | ] |
---|
| 913 | ]. |
---|
| 914 | |
---|
| 915 | lemma eq_instruction_refl: |
---|
| 916 | ∀i. eq_instruction i i = true. |
---|
| 917 | #i cases i |
---|
| 918 | [1,2,3,4,5,6: #arg1 @eq_addressing_mode_refl |
---|
| 919 | |7: #arg1 #arg2 |
---|
| 920 | whd in ⊢ (??%?) |
---|
| 921 | >eq_addressing_mode_refl |
---|
| 922 | >eq_addressing_mode_refl |
---|
| 923 | % |
---|
| 924 | |8: #arg @eq_preinstruction_refl |
---|
| 925 | ] |
---|
| 926 | qed. |
---|
| 927 | |
---|
[877] | 928 | let rec vect_member |
---|
| 929 | (A: Type[0]) (n: nat) (eq: A → A → bool) |
---|
| 930 | (v: Vector A n) (a: A) on v: bool ≝ |
---|
| 931 | match v with |
---|
| 932 | [ VEmpty ⇒ false |
---|
| 933 | | VCons len hd tl ⇒ |
---|
| 934 | eq hd a ∨ (vect_member A ? eq tl a) |
---|
| 935 | ]. |
---|
[892] | 936 | |
---|
[877] | 937 | let rec list_addressing_mode_tags_elim_prop |
---|
| 938 | (n: nat) |
---|
| 939 | (l: Vector addressing_mode_tag (S n)) |
---|
[884] | 940 | on l: |
---|
| 941 | ∀P: l → Prop. |
---|
[877] | 942 | ∀direct_a. ∀indirect_a. ∀ext_indirect_a. ∀register_a. ∀acc_a_a. |
---|
| 943 | ∀acc_b_a. ∀dptr_a. ∀data_a. ∀data16_a. ∀acc_dptr_a. ∀acc_pc_a. |
---|
| 944 | ∀ext_indirect_dptr_a. ∀indirect_dptr_a. ∀carry_a. ∀bit_addr_a. |
---|
| 945 | ∀n_bit_addr_a. ∀relative_a. ∀addr11_a. ∀addr16_a. |
---|
| 946 | ∀x: l. P x ≝ |
---|
| 947 | match l return |
---|
| 948 | λy. |
---|
| 949 | match y with |
---|
| 950 | [ O ⇒ λm: Vector addressing_mode_tag O. ∀prf: 0 = S n. True |
---|
[884] | 951 | | S y' ⇒ λl: Vector addressing_mode_tag (S y'). ∀prf: S y' = S n.∀P:l → Prop. |
---|
[877] | 952 | ∀direct_a: if vect_member … eq_a l direct then ∀x. P (DIRECT x) else True. |
---|
| 953 | ∀indirect_a: if vect_member … eq_a l indirect then ∀x. P (INDIRECT x) else True. |
---|
| 954 | ∀ext_indirect_a: if vect_member … eq_a l ext_indirect then ∀x. P (EXT_INDIRECT x) else True. |
---|
| 955 | ∀register_a: if vect_member … eq_a l registr then ∀x. P (REGISTER x) else True. |
---|
| 956 | ∀acc_a_a: if vect_member … eq_a l acc_a then P (ACC_A) else True. |
---|
| 957 | ∀acc_b_a: if vect_member … eq_a l acc_b then P (ACC_B) else True. |
---|
| 958 | ∀dptr_a: if vect_member … eq_a l dptr then P DPTR else True. |
---|
| 959 | ∀data_a: if vect_member … eq_a l data then ∀x. P (DATA x) else True. |
---|
| 960 | ∀data16_a: if vect_member … eq_a l data16 then ∀x. P (DATA16 x) else True. |
---|
| 961 | ∀acc_dptr_a: if vect_member … eq_a l acc_dptr then P ACC_DPTR else True. |
---|
| 962 | ∀acc_pc_a: if vect_member … eq_a l acc_pc then P ACC_PC else True. |
---|
| 963 | ∀ext_indirect_dptr_a: if vect_member … eq_a l ext_indirect_dptr then P EXT_INDIRECT_DPTR else True. |
---|
| 964 | ∀indirect_dptr_a: if vect_member … eq_a l indirect_dptr then P INDIRECT_DPTR else True. |
---|
| 965 | ∀carry_a: if vect_member … eq_a l carry then P CARRY else True. |
---|
| 966 | ∀bit_addr_a: if vect_member … eq_a l bit_addr then ∀x. P (BIT_ADDR x) else True. |
---|
| 967 | ∀n_bit_addr_a: if vect_member … eq_a l n_bit_addr then ∀x. P (N_BIT_ADDR x) else True. |
---|
| 968 | ∀relative_a: if vect_member … eq_a l relative then ∀x. P (RELATIVE x) else True. |
---|
| 969 | ∀addr11_a: if vect_member … eq_a l addr11 then ∀x. P (ADDR11 x) else True. |
---|
| 970 | ∀addr_16_a: if vect_member … eq_a l addr16 then ∀x. P (ADDR16 x) else True. |
---|
| 971 | ∀x:l. P x |
---|
| 972 | ] with |
---|
| 973 | [ VEmpty ⇒ λAbsurd. ⊥ |
---|
| 974 | | VCons len hd tl ⇒ λProof. ? |
---|
[884] | 975 | ] (refl ? (S n)). cases daemon. qed. (* |
---|
[877] | 976 | [ destruct(Absurd) |
---|
| 977 | | # A1 # A2 # A3 # A4 # A5 # A6 # A7 |
---|
| 978 | # A8 # A9 # A10 # A11 # A12 # A13 # A14 |
---|
| 979 | # A15 # A16 # A17 # A18 # A19 # X |
---|
| 980 | cases X |
---|
[884] | 981 | # SUB cases daemon ] qed. |
---|
[877] | 982 | cases SUB |
---|
| 983 | [ # BYTE |
---|
| 984 | normalize |
---|
| 985 | ]. |
---|
| 986 | |
---|
| 987 | |
---|
| 988 | (* let prepare_hd ≝ |
---|
| 989 | match hd with |
---|
| 990 | [ direct ⇒ λdirect_prf. ? |
---|
| 991 | | indirect ⇒ λindirect_prf. ? |
---|
| 992 | | ext_indirect ⇒ λext_indirect_prf. ? |
---|
| 993 | | registr ⇒ λregistr_prf. ? |
---|
| 994 | | acc_a ⇒ λacc_a_prf. ? |
---|
| 995 | | acc_b ⇒ λacc_b_prf. ? |
---|
| 996 | | dptr ⇒ λdptr_prf. ? |
---|
| 997 | | data ⇒ λdata_prf. ? |
---|
| 998 | | data16 ⇒ λdata16_prf. ? |
---|
| 999 | | acc_dptr ⇒ λacc_dptr_prf. ? |
---|
| 1000 | | acc_pc ⇒ λacc_pc_prf. ? |
---|
| 1001 | | ext_indirect_dptr ⇒ λext_indirect_prf. ? |
---|
| 1002 | | indirect_dptr ⇒ λindirect_prf. ? |
---|
| 1003 | | carry ⇒ λcarry_prf. ? |
---|
| 1004 | | bit_addr ⇒ λbit_addr_prf. ? |
---|
| 1005 | | n_bit_addr ⇒ λn_bit_addr_prf. ? |
---|
| 1006 | | relative ⇒ λrelative_prf. ? |
---|
| 1007 | | addr11 ⇒ λaddr11_prf. ? |
---|
| 1008 | | addr16 ⇒ λaddr16_prf. ? |
---|
| 1009 | ] |
---|
| 1010 | in ? *) |
---|
| 1011 | ]. |
---|
| 1012 | [ 1: destruct(absd) |
---|
| 1013 | | 2: # A1 # A2 # A3 # A4 # A5 # A6 |
---|
| 1014 | # A7 # A8 # A9 # A10 # A11 # A12 |
---|
| 1015 | # A13 # A14 # A15 # A16 # A17 # A18 |
---|
| 1016 | # A19 * |
---|
| 1017 | ]. |
---|
| 1018 | |
---|
| 1019 | |
---|
| 1020 | match l return λx.match x with [O ⇒ λl: Vector … O. bool | S x' ⇒ λl: Vector addressing_mode_tag (S x'). |
---|
| 1021 | (l → bool) → bool ] with |
---|
| 1022 | [ VEmpty ⇒ true |
---|
| 1023 | | VCons len hd tl ⇒ λP. |
---|
| 1024 | let process_hd ≝ |
---|
| 1025 | match hd return λhd. ∀P: hd:::tl → bool. bool with |
---|
| 1026 | [ direct ⇒ λP.bitvector_elim 8 (λx. P (DIRECT x)) |
---|
| 1027 | | indirect ⇒ λP.bit_elim (λx. P (INDIRECT x)) |
---|
| 1028 | | ext_indirect ⇒ λP.bit_elim (λx. P (EXT_INDIRECT x)) |
---|
| 1029 | | registr ⇒ λP.bitvector_elim 3 (λx. P (REGISTER x)) |
---|
| 1030 | | acc_a ⇒ λP.P ACC_A |
---|
| 1031 | | acc_b ⇒ λP.P ACC_B |
---|
| 1032 | | dptr ⇒ λP.P DPTR |
---|
| 1033 | | data ⇒ λP.bitvector_elim 8 (λx. P (DATA x)) |
---|
| 1034 | | data16 ⇒ λP.bitvector_elim 16 (λx. P (DATA16 x)) |
---|
| 1035 | | acc_dptr ⇒ λP.P ACC_DPTR |
---|
| 1036 | | acc_pc ⇒ λP.P ACC_PC |
---|
| 1037 | | ext_indirect_dptr ⇒ λP.P EXT_INDIRECT_DPTR |
---|
| 1038 | | indirect_dptr ⇒ λP.P INDIRECT_DPTR |
---|
| 1039 | | carry ⇒ λP.P CARRY |
---|
| 1040 | | bit_addr ⇒ λP.bitvector_elim 8 (λx. P (BIT_ADDR x)) |
---|
| 1041 | | n_bit_addr ⇒ λP.bitvector_elim 8 (λx. P (N_BIT_ADDR x)) |
---|
| 1042 | | relative ⇒ λP.bitvector_elim 8 (λx. P (RELATIVE x)) |
---|
| 1043 | | addr11 ⇒ λP.bitvector_elim 11 (λx. P (ADDR11 x)) |
---|
| 1044 | | addr16 ⇒ λP.bitvector_elim 16 (λx. P (ADDR16 x)) |
---|
| 1045 | ] |
---|
| 1046 | in |
---|
| 1047 | andb (process_hd P) |
---|
| 1048 | (match len return λx. x = len → bool with |
---|
| 1049 | [ O ⇒ λprf. true |
---|
| 1050 | | S y ⇒ λprf. list_addressing_mode_tags_elim y ? P ] (refl ? len)) |
---|
| 1051 | ]. |
---|
| 1052 | try % |
---|
| 1053 | [ 2: cases (sym_eq ??? prf); @tl |
---|
| 1054 | | generalize in match H; generalize in match tl; cases prf; |
---|
| 1055 | (* cases prf in tl H; : ??? WAS WORKING BEFORE *) |
---|
| 1056 | #tl |
---|
| 1057 | normalize in ⊢ (∀_: %. ?) |
---|
| 1058 | # H |
---|
| 1059 | whd |
---|
| 1060 | normalize in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]) |
---|
| 1061 | cases (is_a hd (subaddressing_modeel y tl H)) whd // ] |
---|
| 1062 | qed. |
---|
[883] | 1063 | *) |
---|
[877] | 1064 | |
---|
[883] | 1065 | definition load_code_memory_aux ≝ |
---|
| 1066 | fold_left_i_aux … ( |
---|
| 1067 | λi, mem, v. |
---|
| 1068 | insert … (bitvector_of_nat … i) v mem) (Stub Byte 16). |
---|
| 1069 | |
---|
[1045] | 1070 | lemma split_zero: |
---|
| 1071 | ∀A,m. |
---|
| 1072 | ∀v: Vector A m. |
---|
| 1073 | 〈[[]], v〉 = split A 0 m v. |
---|
| 1074 | #A #m #v |
---|
| 1075 | elim v |
---|
| 1076 | [ % |
---|
| 1077 | | #n #hd #tl #ih |
---|
| 1078 | normalize in ⊢ (???%) % |
---|
| 1079 | ] |
---|
| 1080 | qed. |
---|
| 1081 | |
---|
| 1082 | lemma Vector_O: ∀A. ∀v: Vector A 0. v ≃ VEmpty A. |
---|
| 1083 | #A #v generalize in match (refl … 0) cases v in ⊢ (??%? → ?%%??) // |
---|
| 1084 | #n #hd #tl #abs @⊥ destruct (abs) |
---|
| 1085 | qed. |
---|
| 1086 | |
---|
| 1087 | lemma Vector_Sn: ∀A. ∀n.∀v:Vector A (S n). |
---|
| 1088 | ∃hd.∃tl.v ≃ VCons A n hd tl. |
---|
| 1089 | #A #n #v generalize in match (refl … (S n)) cases v in ⊢ (??%? → ??(λ_.??(λ_.?%%??))) |
---|
| 1090 | [ #abs @⊥ destruct (abs) |
---|
| 1091 | | #m #hd #tl #EQ <(injective_S … EQ) %[@hd] %[@tl] // ] |
---|
| 1092 | qed. |
---|
| 1093 | |
---|
| 1094 | lemma vector_append_zero: |
---|
| 1095 | ∀A,m. |
---|
| 1096 | ∀v: Vector A m. |
---|
| 1097 | ∀q: Vector A 0. |
---|
| 1098 | v = q@@v. |
---|
| 1099 | #A #m #v #q |
---|
| 1100 | >(Vector_O A q) % |
---|
| 1101 | qed. |
---|
| 1102 | |
---|
| 1103 | lemma prod_eq_left: |
---|
| 1104 | ∀A: Type[0]. |
---|
| 1105 | ∀p, q, r: A. |
---|
| 1106 | p = q → 〈p, r〉 = 〈q, r〉. |
---|
| 1107 | #A #p #q #r #hyp |
---|
| 1108 | >hyp % |
---|
| 1109 | qed. |
---|
| 1110 | |
---|
| 1111 | lemma prod_eq_right: |
---|
| 1112 | ∀A: Type[0]. |
---|
| 1113 | ∀p, q, r: A. |
---|
| 1114 | p = q → 〈r, p〉 = 〈r, q〉. |
---|
| 1115 | #A #p #q #r #hyp |
---|
| 1116 | >hyp % |
---|
| 1117 | qed. |
---|
| 1118 | |
---|
| 1119 | corollary prod_vector_zero_eq_left: |
---|
| 1120 | ∀A, n. |
---|
| 1121 | ∀q: Vector A O. |
---|
| 1122 | ∀r: Vector A n. |
---|
| 1123 | 〈q, r〉 = 〈[[ ]], r〉. |
---|
| 1124 | #A #n #q #r |
---|
| 1125 | generalize in match (Vector_O A q …) |
---|
| 1126 | #hyp |
---|
| 1127 | >hyp in ⊢ (??%?) |
---|
| 1128 | % |
---|
| 1129 | qed. |
---|
| 1130 | |
---|
| 1131 | axiom split_succ: |
---|
| 1132 | ∀A, m, n. |
---|
| 1133 | ∀l: Vector A m. |
---|
| 1134 | ∀r: Vector A n. |
---|
| 1135 | ∀v: Vector A (m + n). |
---|
| 1136 | ∀hd: A. |
---|
| 1137 | v = l@@r → (〈l, r〉 = split A m n v → 〈hd:::l, r〉 = split A (S m) n (hd:::v)). |
---|
| 1138 | (* |
---|
| 1139 | #A #m |
---|
| 1140 | elim m |
---|
| 1141 | [ #n #l #r #v #hd #equal #hyp |
---|
| 1142 | normalize >(Vector_O A l) >equal |
---|
| 1143 | >(Vector_O A l) % |
---|
| 1144 | | #n' #ih #n #l #r #v #hd |
---|
| 1145 | #equal #hyp |
---|
| 1146 | cases(Vector_Sn A n' l) |
---|
| 1147 | #hd' #exists |
---|
| 1148 | cases exists #tl #jmeq |
---|
| 1149 | >jmeq *) |
---|
| 1150 | |
---|
| 1151 | lemma split_prod: |
---|
| 1152 | ∀A,m,n. |
---|
| 1153 | ∀p: Vector A (m + n). |
---|
| 1154 | ∀v: Vector A m. |
---|
| 1155 | ∀q: Vector A n. |
---|
| 1156 | p = v@@q → 〈v, q〉 = split A m n p. |
---|
| 1157 | #A #m |
---|
| 1158 | elim m |
---|
| 1159 | [ #n #p #v #q #hyp |
---|
| 1160 | >hyp <(vector_append_zero A n q v) |
---|
| 1161 | >(prod_vector_zero_eq_left A …) |
---|
| 1162 | @split_zero |
---|
| 1163 | | #r #ih #n #p #v #q #hyp |
---|
| 1164 | >hyp |
---|
| 1165 | cases (Vector_Sn A r v) |
---|
| 1166 | #hd #exists |
---|
| 1167 | cases exists |
---|
| 1168 | #tl #jmeq >jmeq |
---|
| 1169 | @split_succ [1: % |2: @ih % ] |
---|
| 1170 | ] |
---|
| 1171 | qed. |
---|
| 1172 | |
---|
| 1173 | lemma split_prod_exists: |
---|
| 1174 | ∀A, m, n. |
---|
| 1175 | ∀p: Vector A (m + n). |
---|
| 1176 | ∃v: Vector A m. |
---|
| 1177 | ∃q: Vector A n. |
---|
| 1178 | 〈v, q〉 = split A m n p. |
---|
| 1179 | #A #m #n #p |
---|
| 1180 | elim m |
---|
| 1181 | @ex_intro |
---|
| 1182 | [1: |
---|
| 1183 | |2: @ex_intro |
---|
| 1184 | [1: |
---|
| 1185 | |2: |
---|
| 1186 | ] |
---|
| 1187 | ] |
---|
| 1188 | |
---|
| 1189 | lemma split_elim: |
---|
[883] | 1190 | ∀A,l,m,v.∀P: (Vector A l) × (Vector A m) → Prop. |
---|
| 1191 | (∀vl,vm. v = vl@@vm → P 〈vl,vm〉) → P (split A l m v). |
---|
[1045] | 1192 | #A #l #m #v #P #hyp |
---|
| 1193 | normalize |
---|
| 1194 | <(split_prod A l m v ? ? ?) |
---|
[901] | 1195 | |
---|
[985] | 1196 | example half_add_SO: |
---|
[883] | 1197 | ∀pc. |
---|
| 1198 | \snd (half_add 16 (bitvector_of_nat … pc) (bitvector_of_nat … 1)) = bitvector_of_nat … (S pc). |
---|
[985] | 1199 | cases daemon. |
---|
| 1200 | qed. |
---|
[883] | 1201 | |
---|
[901] | 1202 | (* |
---|
[883] | 1203 | axiom not_eqvb_S: |
---|
| 1204 | ∀pc. |
---|
| 1205 | (¬eq_bv 16 (bitvector_of_nat 16 pc) (bitvector_of_nat 16 (S pc))). |
---|
| 1206 | |
---|
| 1207 | axiom not_eqvb_SS: |
---|
| 1208 | ∀pc. |
---|
| 1209 | (¬eq_bv 16 (bitvector_of_nat 16 pc) (bitvector_of_nat 16 (S (S pc)))). |
---|
[894] | 1210 | |
---|
[884] | 1211 | axiom bitvector_elim_complete: |
---|
| 1212 | ∀n,P. bitvector_elim n P = true → ∀bv. P bv. |
---|
| 1213 | |
---|
| 1214 | lemma bitvector_elim_complete': |
---|
| 1215 | ∀n,P. bitvector_elim n P = true → ∀bv. P bv = true. |
---|
| 1216 | #n #P #H generalize in match (bitvector_elim_complete … H) #K #bv |
---|
| 1217 | generalize in match (K bv) normalize cases (P bv) normalize // #abs @⊥ // |
---|
| 1218 | qed. |
---|
[894] | 1219 | *) |
---|
[884] | 1220 | |
---|
[893] | 1221 | (* |
---|
[884] | 1222 | lemma andb_elim': |
---|
| 1223 | ∀b1,b2. (b1 = true) → (b2 = true) → (b1 ∧ b2) = true. |
---|
| 1224 | #b1 #b2 #H1 #H2 @andb_elim cases b1 in H1; normalize // |
---|
| 1225 | qed. |
---|
[893] | 1226 | *) |
---|
[884] | 1227 | |
---|
[890] | 1228 | let rec encoding_check (code_memory: BitVectorTrie Byte 16) (pc: Word) (final_pc: Word) |
---|
| 1229 | (encoding: list Byte) on encoding: Prop ≝ |
---|
| 1230 | match encoding with |
---|
| 1231 | [ nil ⇒ final_pc = pc |
---|
| 1232 | | cons hd tl ⇒ |
---|
| 1233 | let 〈new_pc, byte〉 ≝ next code_memory pc in |
---|
[1045] | 1234 | hd = byte ∧ encoding_check code_memory new_c final_pc tl |
---|
[890] | 1235 | ]. |
---|
| 1236 | |
---|
[901] | 1237 | lemma encoding_check_append: ∀code_memory,final_pc,l1,pc,l2. |
---|
| 1238 | encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … final_pc) (l1@l2) → |
---|
| 1239 | let intermediate_pc ≝ pc + length … l1 in |
---|
| 1240 | encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … intermediate_pc) l1 ∧ |
---|
| 1241 | encoding_check code_memory (bitvector_of_nat … intermediate_pc) (bitvector_of_nat … final_pc) l2. |
---|
| 1242 | #code_memory #final_pc #l1 elim l1 |
---|
| 1243 | [ #pc #l2 whd in ⊢ (????% → ?) #H <plus_n_O whd whd in ⊢ (?%?) /2/ |
---|
| 1244 | | #hd #tl #IH #pc #l2 * #H1 #H2 >half_add_SO in H2; #H2 cases (IH … H2) <plus_n_Sm |
---|
| 1245 | #K1 #K2 % [2:@K2] whd % // >half_add_SO @K1 ] |
---|
| 1246 | qed. |
---|
[890] | 1247 | |
---|
[894] | 1248 | axiom bitvector_3_elim_prop: |
---|
| 1249 | ∀P: BitVector 3 → Prop. |
---|
| 1250 | P [[false;false;false]] → P [[false;false;true]] → P [[false;true;false]] → |
---|
| 1251 | P [[false;true;true]] → P [[true;false;false]] → P [[true;false;true]] → |
---|
| 1252 | P [[true;true;false]] → P [[true;true;true]] → ∀v. P v. |
---|
| 1253 | |
---|
[936] | 1254 | definition ticks_of_instruction ≝ |
---|
| 1255 | λi. |
---|
| 1256 | let trivial_code_memory ≝ assembly1 i in |
---|
| 1257 | let trivial_status ≝ load_code_memory trivial_code_memory in |
---|
| 1258 | \snd (fetch trivial_status (zero ?)). |
---|
| 1259 | |
---|
[1041] | 1260 | lemma fetch_assembly: |
---|
[892] | 1261 | ∀pc,i,code_memory,assembled. |
---|
| 1262 | assembled = assembly1 i → |
---|
[890] | 1263 | let len ≝ length … assembled in |
---|
| 1264 | encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … (pc + len)) assembled → |
---|
| 1265 | let fetched ≝ fetch code_memory (bitvector_of_nat … pc) in |
---|
| 1266 | let 〈instr_pc, ticks〉 ≝ fetched in |
---|
| 1267 | let 〈instr,pc'〉 ≝ instr_pc in |
---|
[936] | 1268 | (eq_instruction instr i ∧ eqb ticks (ticks_of_instruction instr) ∧ eq_bv … pc' (bitvector_of_nat … (pc + len))) = true. |
---|
[1041] | 1269 | #pc #i #code_memory #assembled cases i [8: *] |
---|
[890] | 1270 | [16,20,29: * * |18,19: * * [1,2,4,5: *] |28: * * [1,2: * [1,2: * [1,2: * [1,2: *]]]]] |
---|
[892] | 1271 | [47,48,49: |
---|
| 1272 | |*: #arg @(list_addressing_mode_tags_elim_prop … arg) whd try % -arg |
---|
[890] | 1273 | [2,3,5,7,10,12,16,17,18,21,25,26,27,30,31,32,37,38,39,40,41,42,43,44,45,48,51,58, |
---|
[892] | 1274 | 59,60,63,64,65,66,67: #ARG]] |
---|
| 1275 | [4,5,6,7,8,9,10,11,12,13,22,23,24,27,28,39,40,41,42,43,44,45,46,47,48,49,50,51,52, |
---|
| 1276 | 56,57,69,70,72,73,75: #arg2 @(list_addressing_mode_tags_elim_prop … arg2) whd try % -arg2 |
---|
| 1277 | [1,2,4,7,9,10,12,13,15,16,17,18,20,22,23,24,25,26,27,28,29,30,31,32,33,36,37,38, |
---|
| 1278 | 39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65, |
---|
| 1279 | 68,69,70,71: #ARG2]] |
---|
| 1280 | [1,2,19,20: #arg3 @(list_addressing_mode_tags_elim_prop … arg3) whd try % -arg3 #ARG3] |
---|
| 1281 | normalize in ⊢ (???% → ?) |
---|
[897] | 1282 | [92,94,42,93,95: @split_elim #vl #vm #E >E -E; [2,4: @(bitvector_3_elim_prop … vl)] |
---|
| 1283 | normalize in ⊢ (???% → ?)] |
---|
[1041] | 1284 | #H >H * #H1 try (whd in ⊢ (% → ?) * #H2) |
---|
| 1285 | try (whd in ⊢ (% → ?) * #H3) whd in ⊢ (% → ?) #H4 |
---|
[892] | 1286 | change in ⊢ (let fetched ≝ % in ?) with (fetch0 ??) |
---|
| 1287 | whd in ⊢ (let fetched ≝ ??% in ?) <H1 whd in ⊢ (let fetched ≝ % in ?) |
---|
[897] | 1288 | [17,18,19,20,21,22,23,24,25,26,31,34,35,36,37,38: <H3] |
---|
| 1289 | [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29, |
---|
| 1290 | 30,31,32,33,34,35,36,37,38,39,40,43,45,48,49,52,53,54,55,56,57,60,61,62,65,66, |
---|
| 1291 | 69,70,73,74,78,80,81,84,85,95,98,101,102,103,104,105,106,107,108,109,110: <H2] |
---|
[896] | 1292 | whd >eq_instruction_refl >H4 @eq_bv_refl |
---|
[1041] | 1293 | qed. |
---|
[901] | 1294 | |
---|
| 1295 | let rec fetch_many code_memory final_pc pc expected on expected: Prop ≝ |
---|
| 1296 | match expected with |
---|
| 1297 | [ nil ⇒ eq_bv … pc final_pc = true |
---|
| 1298 | | cons i tl ⇒ |
---|
| 1299 | let fetched ≝ fetch code_memory pc in |
---|
| 1300 | let 〈instr_pc, ticks〉 ≝ fetched in |
---|
| 1301 | let 〈instr,pc'〉 ≝ instr_pc in |
---|
[936] | 1302 | eq_instruction instr i = true ∧ |
---|
| 1303 | ticks = (ticks_of_instruction i) ∧ |
---|
| 1304 | fetch_many code_memory final_pc pc' tl]. |
---|
[901] | 1305 | |
---|
| 1306 | lemma option_destruct_Some: ∀A,a,b. Some A a = Some A b → a=b. |
---|
| 1307 | #A #a #b #EQ destruct // |
---|
[892] | 1308 | qed. |
---|
[901] | 1309 | |
---|
[994] | 1310 | axiom eq_instruction_to_eq: |
---|
| 1311 | ∀i1,i2. eq_instruction i1 i2 = true → i1 = i2. |
---|
| 1312 | |
---|
[936] | 1313 | |
---|
[998] | 1314 | notation < "❰ x ❱" with precedence 90 for @{'dp $x $y }. |
---|
| 1315 | interpretation "dp" 'dp x y = (dp x y). |
---|
| 1316 | |
---|
| 1317 | lemma fetch_assembly_pseudo': |
---|
[987] | 1318 | ∀program.∀pol:policy program.∀ppc,lookup_labels,lookup_datalabels. |
---|
[901] | 1319 | ∀pi,code_memory,len,assembled,instructions,pc. |
---|
[987] | 1320 | let expansion ≝ pol ppc in |
---|
[998] | 1321 | Some ? instructions = expand_pseudo_instruction_safe lookup_labels lookup_datalabels (bitvector_of_nat ? pc) expansion pi → |
---|
| 1322 | Some … 〈len,assembled〉 = assembly_1_pseudoinstruction_safe program pol ppc (bitvector_of_nat ? pc) lookup_labels lookup_datalabels pi → |
---|
[901] | 1323 | encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … (pc + len)) assembled → |
---|
| 1324 | fetch_many code_memory (bitvector_of_nat … (pc + len)) (bitvector_of_nat … pc) instructions. |
---|
[987] | 1325 | #program #pol #ppc #lookup_labels #lookup_datalabels #pi #code_memory #len #assembled #instructions #pc |
---|
[921] | 1326 | #EQ1 whd in ⊢ (???% → ?) <EQ1 whd in ⊢ (???% → ?) #EQ2 |
---|
| 1327 | cases (pair_destruct ?????? (option_destruct_Some … EQ2)) -EQ2; #EQ2a #EQ2b |
---|
[901] | 1328 | >EQ2a >EQ2b -EQ2a EQ2b; |
---|
| 1329 | generalize in match (pc + |flatten … (map … assembly1 instructions)|); #final_pc |
---|
| 1330 | generalize in match pc elim instructions |
---|
| 1331 | [ #pc whd in ⊢ (% → %) #H >H @eq_bv_refl |
---|
| 1332 | | #i #tl #IH #pc #H whd cases (encoding_check_append … H); -H; #H1 #H2 whd |
---|
| 1333 | generalize in match (fetch_assembly pc i code_memory … (refl …) H1) |
---|
| 1334 | cases (fetch code_memory (bitvector_of_nat … pc)) #newi_pc #ticks whd in ⊢ (% → %) |
---|
[936] | 1335 | cases newi_pc #newi #newpc whd in ⊢ (% → %) #K cases (conjunction_true … K) -K; #K1 |
---|
[985] | 1336 | cases (conjunction_true … K1) -K1; #K1 #K2 #K3 % try % |
---|
| 1337 | [ @K1 | @eqb_true_to_eq <(eq_instruction_to_eq … K1) @K2 | >(eq_bv_eq … K3) @IH @H2 ] |
---|
[901] | 1338 | qed. |
---|
| 1339 | |
---|
[998] | 1340 | axiom bitvector_of_nat_nat_of_bitvector: |
---|
| 1341 | ∀n,v. |
---|
| 1342 | bitvector_of_nat n (nat_of_bitvector n v) = v. |
---|
[877] | 1343 | |
---|
[998] | 1344 | (* CSC: soo long next one; can we merge with previous one now? *) |
---|
| 1345 | lemma fetch_assembly_pseudo: |
---|
| 1346 | ∀program.∀pol:policy program.∀ppc. |
---|
| 1347 | ∀code_memory. |
---|
| 1348 | let lookup_labels ≝ ? in |
---|
| 1349 | let lookup_datalabels ≝ ? in |
---|
| 1350 | let pc ≝ ? in |
---|
| 1351 | let pi ≝ \fst (fetch_pseudo_instruction (\snd program) ppc) in |
---|
[1014] | 1352 | let instructions ≝ expand_pseudo_instruction program pol ppc lookup_labels lookup_datalabels pc (refl …) (refl …) (refl …) in |
---|
[998] | 1353 | let 〈len,assembled〉 ≝ assembly_1_pseudoinstruction program pol ppc lookup_labels lookup_datalabels pi (refl …) (refl …) (refl …) in |
---|
| 1354 | encoding_check code_memory pc (bitvector_of_nat … (nat_of_bitvector ? pc + len)) assembled → |
---|
| 1355 | fetch_many code_memory (bitvector_of_nat … (nat_of_bitvector ? pc + len)) pc instructions. |
---|
| 1356 | #program #pol #ppc #code_memory |
---|
| 1357 | letin lookup_labels ≝ (λx:Identifier |
---|
| 1358 | .sigma program pol (address_of_word_labels_code_mem (\snd program) x)) |
---|
| 1359 | letin lookup_datalabels ≝ |
---|
| 1360 | (λx:BitVector 16 |
---|
| 1361 | .lookup Identifier 16 x (construct_datalabels (\fst program)) (zero 16)) |
---|
| 1362 | letin pc ≝ (sigma program pol ppc) |
---|
| 1363 | letin pi ≝ (\fst (fetch_pseudo_instruction (\snd program) ppc)) |
---|
[1014] | 1364 | letin instructions ≝ (expand_pseudo_instruction program pol ppc lookup_labels lookup_datalabels pc (refl …) (refl …) (refl …)) |
---|
[998] | 1365 | @pair_elim' #len #assembled #EQ1 #H |
---|
| 1366 | generalize in match |
---|
| 1367 | (fetch_assembly_pseudo' program pol ppc lookup_labels lookup_datalabels pi |
---|
| 1368 | code_memory len assembled instructions (nat_of_bitvector ? pc) ???) in ⊢ ?; |
---|
| 1369 | [ >bitvector_of_nat_nat_of_bitvector // |
---|
| 1370 | | >bitvector_of_nat_nat_of_bitvector normalize nodelta >(sig2 ?? (expand_pseudo_instruction …)) % |
---|
| 1371 | | >bitvector_of_nat_nat_of_bitvector <EQ1 @assembly_1_pseudoinstruction_ok1 |
---|
| 1372 | | //] |
---|
[877] | 1373 | qed. |
---|
| 1374 | |
---|
[1043] | 1375 | (* This is a trivial consequence of fetch_assembly + the proof that the |
---|
| 1376 | function that load the code in memory is correct. The latter is based |
---|
| 1377 | on missing properties from the standard library on the BitVectorTrie |
---|
| 1378 | data structrure. *) |
---|
[906] | 1379 | axiom assembly_ok: |
---|
[1039] | 1380 | ∀program,pol,assembled,costs'. |
---|
[987] | 1381 | let 〈labels,costs〉 ≝ build_maps program pol in |
---|
[1039] | 1382 | 〈assembled,costs'〉 = assembly program pol → |
---|
| 1383 | costs = costs' ∧ |
---|
[906] | 1384 | let code_memory ≝ load_code_memory assembled in |
---|
[915] | 1385 | let preamble ≝ \fst program in |
---|
| 1386 | let datalabels ≝ construct_datalabels preamble in |
---|
[987] | 1387 | let lookup_labels ≝ λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x) in |
---|
[906] | 1388 | let lookup_datalabels ≝ λx. lookup ?? x datalabels (zero ?) in |
---|
[1014] | 1389 | ∀ppc. |
---|
| 1390 | let pi_newppc ≝ fetch_pseudo_instruction (\snd program) ppc in |
---|
[998] | 1391 | ∀len,assembledi. |
---|
[1014] | 1392 | 〈len,assembledi〉 = assembly_1_pseudoinstruction program pol ppc lookup_labels lookup_datalabels (\fst pi_newppc) (refl …) (refl …) (refl …) → |
---|
[987] | 1393 | encoding_check code_memory (sigma program pol ppc) (bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len)) assembledi ∧ |
---|
[1014] | 1394 | sigma program pol (\snd pi_newppc) = bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len). |
---|
[906] | 1395 | |
---|
[1039] | 1396 | lemma fetch_assembly_pseudo2: |
---|
[1014] | 1397 | ∀program,pol,ppc. |
---|
[1036] | 1398 | (* let 〈labels,costs〉 ≝ build_maps program pol in *) |
---|
[1014] | 1399 | let assembled ≝ \fst (assembly program pol) in |
---|
| 1400 | let code_memory ≝ load_code_memory assembled in |
---|
| 1401 | let data_labels ≝ construct_datalabels (\fst program) in |
---|
| 1402 | let lookup_labels ≝ λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x) in |
---|
| 1403 | let lookup_datalabels ≝ λx. lookup ? ? x data_labels (zero ?) in |
---|
| 1404 | let 〈pi,newppc〉 ≝ fetch_pseudo_instruction (\snd program) ppc in |
---|
| 1405 | let instructions ≝ expand_pseudo_instruction program pol ppc lookup_labels lookup_datalabels (sigma program pol ppc) (refl …) (refl …) (refl …) in |
---|
| 1406 | fetch_many code_memory (sigma program pol newppc) (sigma program pol ppc) instructions. |
---|
[1039] | 1407 | * #preamble #instr_list #pol #ppc |
---|
| 1408 | letin assembled ≝ (\fst (assembly 〈preamble,instr_list〉 pol)) |
---|
[998] | 1409 | letin code_memory ≝ (load_code_memory assembled) |
---|
| 1410 | letin data_labels ≝ (construct_datalabels preamble) |
---|
[1039] | 1411 | letin lookup_labels ≝ (λx. sigma … pol (address_of_word_labels_code_mem instr_list x)) |
---|
[998] | 1412 | letin lookup_datalabels ≝ (λx. lookup ? ? x data_labels (zero ?)) |
---|
[1039] | 1413 | @pair_elim' #pi #newppc #EQ1 change in EQ1 with (fetch_pseudo_instruction instr_list ? = ?) |
---|
| 1414 | generalize in match (assembly_ok ? pol assembled (\snd (assembly 〈preamble,instr_list〉 pol))) |
---|
| 1415 | @pair_elim' #labels #costs #EQ2 <eq_pair_fst_snd |
---|
| 1416 | #H cases (H (refl \ldots)) -H; #EQ3 |
---|
| 1417 | generalize in match (refl … (assembly_1_pseudoinstruction … pol ppc lookup_labels lookup_datalabels ? (refl …) (refl …) (refl …))) |
---|
| 1418 | cases (assembly_1_pseudoinstruction ?????????) in ⊢ (???% → ?) #len #assembledi #EQ4 |
---|
| 1419 | #H cases (H ppc len assembledi ?) [2: <EQ4 %] -H; #H1 #H2 |
---|
| 1420 | generalize in match (fetch_assembly_pseudo … pol ppc (load_code_memory assembled)) in ⊢ ? |
---|
| 1421 | >EQ4 #H generalize in match (H H1) in ⊢ ? -H; >(pair_destruct_2 ????? (sym_eq … EQ1)) |
---|
| 1422 | >H2 #K @K |
---|
[998] | 1423 | qed. |
---|
[985] | 1424 | |
---|
[906] | 1425 | (* OLD? |
---|
[877] | 1426 | definition assembly_specification: |
---|
| 1427 | ∀assembly_program: pseudo_assembly_program. |
---|
| 1428 | ∀code_mem: BitVectorTrie Byte 16. Prop ≝ |
---|
| 1429 | λpseudo_assembly_program. |
---|
| 1430 | λcode_mem. |
---|
| 1431 | ∀pc: Word. |
---|
| 1432 | let 〈preamble, instr_list〉 ≝ pseudo_assembly_program in |
---|
| 1433 | let 〈pre_instr, pre_new_pc〉 ≝ fetch_pseudo_instruction instr_list pc in |
---|
| 1434 | let labels ≝ λx. sigma' pseudo_assembly_program (address_of_word_labels_code_mem instr_list x) in |
---|
| 1435 | let datalabels ≝ λx. sigma' pseudo_assembly_program (lookup ? ? x (construct_datalabels preamble) (zero ?)) in |
---|
| 1436 | let pre_assembled ≝ assembly_1_pseudoinstruction pseudo_assembly_program |
---|
| 1437 | (sigma' pseudo_assembly_program pc) labels datalabels pre_instr in |
---|
| 1438 | match pre_assembled with |
---|
| 1439 | [ None ⇒ True |
---|
| 1440 | | Some pc_code ⇒ |
---|
| 1441 | let 〈new_pc,code〉 ≝ pc_code in |
---|
| 1442 | encoding_check code_mem pc (sigma' pseudo_assembly_program pre_new_pc) code ]. |
---|
| 1443 | |
---|
| 1444 | axiom assembly_meets_specification: |
---|
| 1445 | ∀pseudo_assembly_program. |
---|
| 1446 | match assembly pseudo_assembly_program with |
---|
| 1447 | [ None ⇒ True |
---|
| 1448 | | Some code_mem_cost ⇒ |
---|
| 1449 | let 〈code_mem, cost〉 ≝ code_mem_cost in |
---|
| 1450 | assembly_specification pseudo_assembly_program (load_code_memory code_mem) |
---|
| 1451 | ]. |
---|
| 1452 | (* |
---|
| 1453 | # PROGRAM |
---|
| 1454 | [ cases PROGRAM |
---|
| 1455 | # PREAMBLE |
---|
| 1456 | # INSTR_LIST |
---|
| 1457 | elim INSTR_LIST |
---|
| 1458 | [ whd |
---|
| 1459 | whd in ⊢ (∀_. %) |
---|
| 1460 | # PC |
---|
| 1461 | whd |
---|
| 1462 | | # INSTR |
---|
| 1463 | # INSTR_LIST_TL |
---|
| 1464 | # H |
---|
| 1465 | whd |
---|
| 1466 | whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]) |
---|
| 1467 | ] |
---|
| 1468 | | cases not_implemented |
---|
| 1469 | ] *) |
---|
[906] | 1470 | *) |
---|
[877] | 1471 | |
---|
[942] | 1472 | definition internal_pseudo_address_map ≝ list (BitVector 8). |
---|
| 1473 | |
---|
| 1474 | axiom low_internal_ram_of_pseudo_low_internal_ram: |
---|
| 1475 | ∀M:internal_pseudo_address_map.∀ram:BitVectorTrie Byte 7.BitVectorTrie Byte 7. |
---|
| 1476 | |
---|
| 1477 | axiom high_internal_ram_of_pseudo_high_internal_ram: |
---|
| 1478 | ∀M:internal_pseudo_address_map.∀ram:BitVectorTrie Byte 7.BitVectorTrie Byte 7. |
---|
| 1479 | |
---|
| 1480 | axiom low_internal_ram_of_pseudo_internal_ram_hit: |
---|
[987] | 1481 | ∀M:internal_pseudo_address_map.∀s:PseudoStatus.∀pol:policy (code_memory … s).∀addr:BitVector 7. |
---|
[942] | 1482 | member ? (eq_bv 8) (false:::addr) M = true → |
---|
| 1483 | let ram ≝ low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … s) in |
---|
| 1484 | let pbl ≝ lookup ? 7 addr (low_internal_ram ? s) (zero 8) in |
---|
| 1485 | let pbu ≝ lookup ? 7 (\snd (half_add ? addr (bitvector_of_nat 7 1))) (low_internal_ram ? s) (zero 8) in |
---|
| 1486 | let bl ≝ lookup ? 7 addr ram (zero 8) in |
---|
| 1487 | let bu ≝ lookup ? 7 (\snd (half_add ? addr (bitvector_of_nat 7 1))) ram (zero 8) in |
---|
[987] | 1488 | bu@@bl = sigma (code_memory … s) pol (pbu@@pbl). |
---|
[942] | 1489 | |
---|
[949] | 1490 | (* changed from add to sub *) |
---|
[942] | 1491 | axiom low_internal_ram_of_pseudo_internal_ram_miss: |
---|
[950] | 1492 | ∀T.∀M:internal_pseudo_address_map.∀s:PreStatus T.∀addr:BitVector 7. |
---|
[942] | 1493 | let ram ≝ low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … s) in |
---|
[949] | 1494 | let 〈Saddr,flags〉 ≝ sub_7_with_carry addr (bitvector_of_nat 7 1) false in |
---|
| 1495 | let carr ≝ get_index_v ? ? flags 1 ? in |
---|
[942] | 1496 | carr = false → |
---|
[949] | 1497 | member ? (eq_bv 8) (false:::Saddr) M = false → |
---|
| 1498 | member ? (eq_bv 8) (false:::addr) M = false → |
---|
| 1499 | lookup ? 7 addr ram (zero ?) = lookup ? 7 addr (low_internal_ram … s) (zero ?). |
---|
| 1500 | // |
---|
| 1501 | qed. |
---|
[942] | 1502 | |
---|
| 1503 | definition addressing_mode_ok ≝ |
---|
[950] | 1504 | λT.λM:internal_pseudo_address_map.λs:PreStatus T. |
---|
[942] | 1505 | λaddr:addressing_mode. |
---|
| 1506 | match addr with |
---|
| 1507 | [ DIRECT d ⇒ |
---|
| 1508 | ¬(member ? (eq_bv 8) d M) ∧ |
---|
| 1509 | ¬(member ? (eq_bv 8) (\fst (sub_8_with_carry d (bitvector_of_nat 8 1) false)) M) |
---|
| 1510 | | INDIRECT i ⇒ |
---|
| 1511 | let d ≝ get_register ? s [[false;false;i]] in |
---|
| 1512 | ¬(member ? (eq_bv 8) d M) ∧ |
---|
| 1513 | ¬(member ? (eq_bv 8) (\fst (sub_8_with_carry d (bitvector_of_nat 8 1) false)) M) |
---|
| 1514 | | EXT_INDIRECT _ ⇒ true |
---|
| 1515 | | REGISTER _ ⇒ true |
---|
| 1516 | | ACC_A ⇒ true |
---|
| 1517 | | ACC_B ⇒ true |
---|
| 1518 | | DPTR ⇒ true |
---|
| 1519 | | DATA _ ⇒ true |
---|
| 1520 | | DATA16 _ ⇒ true |
---|
| 1521 | | ACC_DPTR ⇒ true |
---|
| 1522 | | ACC_PC ⇒ true |
---|
| 1523 | | EXT_INDIRECT_DPTR ⇒ true |
---|
| 1524 | | INDIRECT_DPTR ⇒ true |
---|
| 1525 | | CARRY ⇒ true |
---|
| 1526 | | BIT_ADDR _ ⇒ ¬true (* TO BE COMPLETED *) |
---|
| 1527 | | N_BIT_ADDR _ ⇒ ¬true (* TO BE COMPLETED *) |
---|
| 1528 | | RELATIVE _ ⇒ true |
---|
| 1529 | | ADDR11 _ ⇒ true |
---|
| 1530 | | ADDR16 _ ⇒ true ]. |
---|
[944] | 1531 | |
---|
| 1532 | definition next_internal_pseudo_address_map0 ≝ |
---|
[950] | 1533 | λT. |
---|
[944] | 1534 | λfetched. |
---|
| 1535 | λM: internal_pseudo_address_map. |
---|
[950] | 1536 | λs: PreStatus T. |
---|
[944] | 1537 | match fetched with |
---|
[942] | 1538 | [ Comment _ ⇒ Some ? M |
---|
| 1539 | | Cost _ ⇒ Some … M |
---|
| 1540 | | Jmp _ ⇒ Some … M |
---|
| 1541 | | Call _ ⇒ |
---|
| 1542 | Some … (\snd (half_add ? (get_8051_sfr … s SFR_SP) (bitvector_of_nat 8 1))::M) |
---|
| 1543 | | Mov _ _ ⇒ Some … M |
---|
| 1544 | | Instruction instr ⇒ |
---|
| 1545 | match instr with |
---|
| 1546 | [ ADD addr1 addr2 ⇒ |
---|
[950] | 1547 | if addressing_mode_ok T M s addr1 ∧ addressing_mode_ok T M s addr2 then |
---|
[942] | 1548 | Some ? M |
---|
| 1549 | else |
---|
| 1550 | None ? |
---|
| 1551 | | ADDC addr1 addr2 ⇒ |
---|
[950] | 1552 | if addressing_mode_ok T M s addr1 ∧ addressing_mode_ok T M s addr2 then |
---|
[942] | 1553 | Some ? M |
---|
| 1554 | else |
---|
| 1555 | None ? |
---|
| 1556 | | SUBB addr1 addr2 ⇒ |
---|
[950] | 1557 | if addressing_mode_ok T M s addr1 ∧ addressing_mode_ok T M s addr2 then |
---|
[942] | 1558 | Some ? M |
---|
| 1559 | else |
---|
| 1560 | None ? |
---|
| 1561 | | _ ⇒ (* TO BE COMPLETED *) Some ? M ]]. |
---|
[944] | 1562 | |
---|
| 1563 | |
---|
| 1564 | definition next_internal_pseudo_address_map ≝ |
---|
| 1565 | λM:internal_pseudo_address_map. |
---|
| 1566 | λs:PseudoStatus. |
---|
[950] | 1567 | next_internal_pseudo_address_map0 ? |
---|
| 1568 | (\fst (fetch_pseudo_instruction (\snd (code_memory ? s)) (program_counter ? s))) M s. |
---|
[942] | 1569 | |
---|
| 1570 | definition status_of_pseudo_status: |
---|
[1014] | 1571 | internal_pseudo_address_map → ∀ps:PseudoStatus. policy (code_memory … ps) → Status ≝ |
---|
[987] | 1572 | λM,ps,pol. |
---|
[877] | 1573 | let pap ≝ code_memory … ps in |
---|
[1014] | 1574 | let p ≝ assembly pap pol in |
---|
| 1575 | let cm ≝ load_code_memory (\fst p) in |
---|
| 1576 | let pc ≝ sigma pap pol (program_counter ? ps) in |
---|
| 1577 | let lir ≝ low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … ps) in |
---|
| 1578 | let hir ≝ high_internal_ram_of_pseudo_high_internal_ram M (high_internal_ram … ps) in |
---|
| 1579 | mk_PreStatus (BitVectorTrie Byte 16) |
---|
| 1580 | cm |
---|
| 1581 | lir |
---|
| 1582 | hir |
---|
| 1583 | (external_ram … ps) |
---|
| 1584 | pc |
---|
| 1585 | (special_function_registers_8051 … ps) |
---|
| 1586 | (special_function_registers_8052 … ps) |
---|
| 1587 | (p1_latch … ps) |
---|
| 1588 | (p3_latch … ps) |
---|
| 1589 | (clock … ps). |
---|
[877] | 1590 | |
---|
[909] | 1591 | (* |
---|
[877] | 1592 | definition write_at_stack_pointer': |
---|
| 1593 | ∀M. ∀ps: PreStatus M. Byte → Σps':PreStatus M.(code_memory … ps = code_memory … ps') ≝ |
---|
| 1594 | λM: Type[0]. |
---|
| 1595 | λs: PreStatus M. |
---|
| 1596 | λv: Byte. |
---|
| 1597 | let 〈 nu, nl 〉 ≝ split … 4 4 (get_8051_sfr ? s SFR_SP) in |
---|
| 1598 | let bit_zero ≝ get_index_v… nu O ? in |
---|
| 1599 | let bit_1 ≝ get_index_v… nu 1 ? in |
---|
| 1600 | let bit_2 ≝ get_index_v… nu 2 ? in |
---|
| 1601 | let bit_3 ≝ get_index_v… nu 3 ? in |
---|
| 1602 | if bit_zero then |
---|
| 1603 | let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl) |
---|
| 1604 | v (low_internal_ram ? s) in |
---|
| 1605 | set_low_internal_ram ? s memory |
---|
| 1606 | else |
---|
| 1607 | let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl) |
---|
| 1608 | v (high_internal_ram ? s) in |
---|
| 1609 | set_high_internal_ram ? s memory. |
---|
| 1610 | [ cases l0 % |
---|
| 1611 | |2,3,4,5: normalize repeat (@ le_S_S) @ le_O_n ] |
---|
| 1612 | qed. |
---|
| 1613 | |
---|
| 1614 | definition execute_1_pseudo_instruction': (Word → nat) → ∀ps:PseudoStatus. |
---|
| 1615 | Σps':PseudoStatus.(code_memory … ps = code_memory … ps') |
---|
| 1616 | ≝ |
---|
| 1617 | λticks_of. |
---|
| 1618 | λs. |
---|
| 1619 | let 〈instr, pc〉 ≝ fetch_pseudo_instruction (\snd (code_memory ? s)) (program_counter ? s) in |
---|
| 1620 | let ticks ≝ ticks_of (program_counter ? s) in |
---|
| 1621 | let s ≝ set_clock ? s (clock ? s + ticks) in |
---|
| 1622 | let s ≝ set_program_counter ? s pc in |
---|
| 1623 | match instr with |
---|
| 1624 | [ Instruction instr ⇒ |
---|
| 1625 | execute_1_preinstruction … (λx, y. address_of_word_labels y x) instr s |
---|
| 1626 | | Comment cmt ⇒ s |
---|
| 1627 | | Cost cst ⇒ s |
---|
| 1628 | | Jmp jmp ⇒ set_program_counter ? s (address_of_word_labels s jmp) |
---|
| 1629 | | Call call ⇒ |
---|
| 1630 | let a ≝ address_of_word_labels s call in |
---|
| 1631 | let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in |
---|
| 1632 | let s ≝ set_8051_sfr ? s SFR_SP new_sp in |
---|
| 1633 | let 〈pc_bu, pc_bl〉 ≝ split ? 8 8 (program_counter ? s) in |
---|
| 1634 | let s ≝ write_at_stack_pointer' ? s pc_bl in |
---|
| 1635 | let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in |
---|
| 1636 | let s ≝ set_8051_sfr ? s SFR_SP new_sp in |
---|
| 1637 | let s ≝ write_at_stack_pointer' ? s pc_bu in |
---|
| 1638 | set_program_counter ? s a |
---|
| 1639 | | Mov dptr ident ⇒ |
---|
| 1640 | set_arg_16 ? s (get_arg_16 ? s (DATA16 (address_of_word_labels s ident))) dptr |
---|
| 1641 | ]. |
---|
| 1642 | [ |
---|
| 1643 | |2,3,4: % |
---|
| 1644 | | <(sig2 … l7) whd in ⊢ (??? (??%)) <(sig2 … l5) % |
---|
| 1645 | | |
---|
| 1646 | | % |
---|
| 1647 | ] |
---|
| 1648 | cases not_implemented |
---|
| 1649 | qed. |
---|
[909] | 1650 | *) |
---|
[911] | 1651 | |
---|
| 1652 | axiom execute_1_pseudo_instruction_preserves_code_memory: |
---|
| 1653 | ∀ticks_of,ps. |
---|
| 1654 | code_memory … (execute_1_pseudo_instruction ticks_of ps) = code_memory … ps. |
---|
| 1655 | |
---|
[877] | 1656 | (* |
---|
| 1657 | lemma execute_code_memory_unchanged: |
---|
| 1658 | ∀ticks_of,ps. code_memory ? ps = code_memory ? (execute_1_pseudo_instruction ticks_of ps). |
---|
| 1659 | #ticks #ps whd in ⊢ (??? (??%)) |
---|
| 1660 | cases (fetch_pseudo_instruction (\snd (code_memory pseudo_assembly_program ps)) |
---|
| 1661 | (program_counter pseudo_assembly_program ps)) #instr #pc |
---|
| 1662 | whd in ⊢ (??? (??%)) cases instr |
---|
| 1663 | [ #pre cases pre |
---|
| 1664 | [ #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
| 1665 | cases (split ????) #z1 #z2 % |
---|
| 1666 | | #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
| 1667 | cases (split ????) #z1 #z2 % |
---|
| 1668 | | #a1 #a2 whd in ⊢ (??? (??%)) cases (sub_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
| 1669 | cases (split ????) #z1 #z2 % |
---|
| 1670 | | #a1 whd in ⊢ (??? (??%)) cases a1 #x #H whd in ⊢ (??? (??%)) cases x |
---|
| 1671 | [ #x1 whd in ⊢ (??? (??%)) |
---|
| 1672 | | *: cases not_implemented |
---|
| 1673 | ] |
---|
| 1674 | | #comment % |
---|
| 1675 | | #cost % |
---|
| 1676 | | #label % |
---|
| 1677 | | #label whd in ⊢ (??? (??%)) cases (half_add ???) #x1 #x2 whd in ⊢ (??? (??%)) |
---|
| 1678 | cases (split ????) #y1 #y2 whd in ⊢ (??? (??%)) cases (half_add ???) #z1 #z2 |
---|
| 1679 | whd in ⊢ (??? (??%)) whd in ⊢ (??? (??%)) cases (split ????) #w1 #w2 |
---|
| 1680 | whd in ⊢ (??? (??%)) cases (get_index_v bool ????) whd in ⊢ (??? (??%)) |
---|
| 1681 | (* CSC: ??? *) |
---|
| 1682 | | #dptr #label (* CSC: ??? *) |
---|
| 1683 | ] |
---|
| 1684 | cases not_implemented |
---|
| 1685 | qed. |
---|
| 1686 | *) |
---|
| 1687 | |
---|
[1014] | 1688 | (* DEAD CODE? |
---|
[877] | 1689 | lemma status_of_pseudo_status_failure_depends_only_on_code_memory: |
---|
[942] | 1690 | ∀M:internal_pseudo_address_map. |
---|
[877] | 1691 | ∀ps,ps': PseudoStatus. |
---|
[987] | 1692 | ∀pol. |
---|
| 1693 | ∀prf:code_memory … ps = code_memory … ps'. |
---|
| 1694 | let pol' ≝ ? in |
---|
| 1695 | match status_of_pseudo_status M ps pol with |
---|
| 1696 | [ None ⇒ status_of_pseudo_status M ps' pol' = None … |
---|
| 1697 | | Some _ ⇒ ∃w. status_of_pseudo_status M ps' pol' = Some … w |
---|
[877] | 1698 | ]. |
---|
[987] | 1699 | [2: <prf @pol] |
---|
| 1700 | #M #ps #ps' #pol #H normalize nodelta; whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]) |
---|
| 1701 | generalize in match (refl … (assembly (code_memory … ps) pol)) |
---|
| 1702 | cases (assembly ??) in ⊢ (???% → %) |
---|
[877] | 1703 | [ #K whd whd in ⊢ (??%?) <H >K % |
---|
| 1704 | | #x #K whd whd in ⊢ (?? (λ_.??%?)) <H >K % [2: % ] ] |
---|
[909] | 1705 | qed. |
---|
[1014] | 1706 | *) |
---|
[877] | 1707 | |
---|
[987] | 1708 | definition ticks_of0: ∀p:pseudo_assembly_program. policy p → Word → ? → nat × nat ≝ |
---|
| 1709 | λprogram: pseudo_assembly_program.λpol. |
---|
[929] | 1710 | λppc: Word. |
---|
[936] | 1711 | λfetched. |
---|
[929] | 1712 | match fetched with |
---|
| 1713 | [ Instruction instr ⇒ |
---|
| 1714 | match instr with |
---|
| 1715 | [ JC lbl ⇒ |
---|
[987] | 1716 | match pol ppc with |
---|
[929] | 1717 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1718 | | medium_jump ⇒ ? |
---|
| 1719 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1720 | ] |
---|
| 1721 | | JNC lbl ⇒ |
---|
[987] | 1722 | match pol ppc with |
---|
[929] | 1723 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1724 | | medium_jump ⇒ ? |
---|
| 1725 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1726 | ] |
---|
| 1727 | | JB bit lbl ⇒ |
---|
[987] | 1728 | match pol ppc with |
---|
[929] | 1729 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1730 | | medium_jump ⇒ ? |
---|
| 1731 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1732 | ] |
---|
| 1733 | | JNB bit lbl ⇒ |
---|
[987] | 1734 | match pol ppc with |
---|
[929] | 1735 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1736 | | medium_jump ⇒ ? |
---|
| 1737 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1738 | ] |
---|
| 1739 | | JBC bit lbl ⇒ |
---|
[987] | 1740 | match pol ppc with |
---|
[929] | 1741 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1742 | | medium_jump ⇒ ? |
---|
| 1743 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1744 | ] |
---|
| 1745 | | JZ lbl ⇒ |
---|
[987] | 1746 | match pol ppc with |
---|
[929] | 1747 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1748 | | medium_jump ⇒ ? |
---|
| 1749 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1750 | ] |
---|
| 1751 | | JNZ lbl ⇒ |
---|
[987] | 1752 | match pol ppc with |
---|
[929] | 1753 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1754 | | medium_jump ⇒ ? |
---|
| 1755 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1756 | ] |
---|
| 1757 | | CJNE arg lbl ⇒ |
---|
[987] | 1758 | match pol ppc with |
---|
[929] | 1759 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1760 | | medium_jump ⇒ ? |
---|
| 1761 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1762 | ] |
---|
| 1763 | | DJNZ arg lbl ⇒ |
---|
[987] | 1764 | match pol ppc with |
---|
[929] | 1765 | [ short_jump ⇒ 〈2, 2〉 |
---|
| 1766 | | medium_jump ⇒ ? |
---|
| 1767 | | long_jump ⇒ 〈4, 4〉 |
---|
| 1768 | ] |
---|
[936] | 1769 | | ADD arg1 arg2 ⇒ |
---|
| 1770 | let ticks ≝ ticks_of_instruction (ADD ? arg1 arg2) in |
---|
| 1771 | 〈ticks, ticks〉 |
---|
[929] | 1772 | | ADDC arg1 arg2 ⇒ |
---|
[936] | 1773 | let ticks ≝ ticks_of_instruction (ADDC ? arg1 arg2) in |
---|
| 1774 | 〈ticks, ticks〉 |
---|
[929] | 1775 | | SUBB arg1 arg2 ⇒ |
---|
[936] | 1776 | let ticks ≝ ticks_of_instruction (SUBB ? arg1 arg2) in |
---|
| 1777 | 〈ticks, ticks〉 |
---|
[929] | 1778 | | INC arg ⇒ |
---|
[936] | 1779 | let ticks ≝ ticks_of_instruction (INC ? arg) in |
---|
| 1780 | 〈ticks, ticks〉 |
---|
[929] | 1781 | | DEC arg ⇒ |
---|
[936] | 1782 | let ticks ≝ ticks_of_instruction (DEC ? arg) in |
---|
| 1783 | 〈ticks, ticks〉 |
---|
[929] | 1784 | | MUL arg1 arg2 ⇒ |
---|
[936] | 1785 | let ticks ≝ ticks_of_instruction (MUL ? arg1 arg2) in |
---|
| 1786 | 〈ticks, ticks〉 |
---|
[929] | 1787 | | DIV arg1 arg2 ⇒ |
---|
[936] | 1788 | let ticks ≝ ticks_of_instruction (DIV ? arg1 arg2) in |
---|
| 1789 | 〈ticks, ticks〉 |
---|
[929] | 1790 | | DA arg ⇒ |
---|
[936] | 1791 | let ticks ≝ ticks_of_instruction (DA ? arg) in |
---|
| 1792 | 〈ticks, ticks〉 |
---|
[929] | 1793 | | ANL arg ⇒ |
---|
[936] | 1794 | let ticks ≝ ticks_of_instruction (ANL ? arg) in |
---|
| 1795 | 〈ticks, ticks〉 |
---|
[929] | 1796 | | ORL arg ⇒ |
---|
[936] | 1797 | let ticks ≝ ticks_of_instruction (ORL ? arg) in |
---|
| 1798 | 〈ticks, ticks〉 |
---|
[929] | 1799 | | XRL arg ⇒ |
---|
[936] | 1800 | let ticks ≝ ticks_of_instruction (XRL ? arg) in |
---|
| 1801 | 〈ticks, ticks〉 |
---|
[929] | 1802 | | CLR arg ⇒ |
---|
[936] | 1803 | let ticks ≝ ticks_of_instruction (CLR ? arg) in |
---|
| 1804 | 〈ticks, ticks〉 |
---|
[929] | 1805 | | CPL arg ⇒ |
---|
[936] | 1806 | let ticks ≝ ticks_of_instruction (CPL ? arg) in |
---|
| 1807 | 〈ticks, ticks〉 |
---|
[929] | 1808 | | RL arg ⇒ |
---|
[936] | 1809 | let ticks ≝ ticks_of_instruction (RL ? arg) in |
---|
| 1810 | 〈ticks, ticks〉 |
---|
[929] | 1811 | | RLC arg ⇒ |
---|
[936] | 1812 | let ticks ≝ ticks_of_instruction (RLC ? arg) in |
---|
| 1813 | 〈ticks, ticks〉 |
---|
[929] | 1814 | | RR arg ⇒ |
---|
[936] | 1815 | let ticks ≝ ticks_of_instruction (RR ? arg) in |
---|
| 1816 | 〈ticks, ticks〉 |
---|
[929] | 1817 | | RRC arg ⇒ |
---|
[936] | 1818 | let ticks ≝ ticks_of_instruction (RRC ? arg) in |
---|
| 1819 | 〈ticks, ticks〉 |
---|
[929] | 1820 | | SWAP arg ⇒ |
---|
[936] | 1821 | let ticks ≝ ticks_of_instruction (SWAP ? arg) in |
---|
| 1822 | 〈ticks, ticks〉 |
---|
[929] | 1823 | | MOV arg ⇒ |
---|
[936] | 1824 | let ticks ≝ ticks_of_instruction (MOV ? arg) in |
---|
| 1825 | 〈ticks, ticks〉 |
---|
[929] | 1826 | | MOVX arg ⇒ |
---|
[936] | 1827 | let ticks ≝ ticks_of_instruction (MOVX ? arg) in |
---|
| 1828 | 〈ticks, ticks〉 |
---|
[929] | 1829 | | SETB arg ⇒ |
---|
[936] | 1830 | let ticks ≝ ticks_of_instruction (SETB ? arg) in |
---|
| 1831 | 〈ticks, ticks〉 |
---|
[929] | 1832 | | PUSH arg ⇒ |
---|
[936] | 1833 | let ticks ≝ ticks_of_instruction (PUSH ? arg) in |
---|
| 1834 | 〈ticks, ticks〉 |
---|
[929] | 1835 | | POP arg ⇒ |
---|
[936] | 1836 | let ticks ≝ ticks_of_instruction (POP ? arg) in |
---|
| 1837 | 〈ticks, ticks〉 |
---|
[929] | 1838 | | XCH arg1 arg2 ⇒ |
---|
[936] | 1839 | let ticks ≝ ticks_of_instruction (XCH ? arg1 arg2) in |
---|
| 1840 | 〈ticks, ticks〉 |
---|
[929] | 1841 | | XCHD arg1 arg2 ⇒ |
---|
[936] | 1842 | let ticks ≝ ticks_of_instruction (XCHD ? arg1 arg2) in |
---|
| 1843 | 〈ticks, ticks〉 |
---|
[929] | 1844 | | RET ⇒ |
---|
[936] | 1845 | let ticks ≝ ticks_of_instruction (RET ?) in |
---|
| 1846 | 〈ticks, ticks〉 |
---|
[929] | 1847 | | RETI ⇒ |
---|
[936] | 1848 | let ticks ≝ ticks_of_instruction (RETI ?) in |
---|
| 1849 | 〈ticks, ticks〉 |
---|
[929] | 1850 | | NOP ⇒ |
---|
[936] | 1851 | let ticks ≝ ticks_of_instruction (NOP ?) in |
---|
| 1852 | 〈ticks, ticks〉 |
---|
[929] | 1853 | ] |
---|
| 1854 | | Comment comment ⇒ 〈0, 0〉 |
---|
| 1855 | | Cost cost ⇒ 〈0, 0〉 |
---|
[938] | 1856 | | Jmp jmp ⇒ 〈2, 2〉 |
---|
| 1857 | | Call call ⇒ 〈2, 2〉 |
---|
| 1858 | | Mov dptr tgt ⇒ 〈2, 2〉 |
---|
[929] | 1859 | ]. |
---|
| 1860 | cases not_implemented (* policy returned medium_jump for conditional jumping = impossible *) |
---|
| 1861 | qed. |
---|
| 1862 | |
---|
[987] | 1863 | definition ticks_of: ∀p:pseudo_assembly_program. policy p → Word → nat × nat ≝ |
---|
| 1864 | λprogram: pseudo_assembly_program.λpol. |
---|
[936] | 1865 | λppc: Word. |
---|
| 1866 | let 〈preamble, pseudo〉 ≝ program in |
---|
| 1867 | let 〈fetched, new_ppc〉 ≝ fetch_pseudo_instruction pseudo ppc in |
---|
[987] | 1868 | ticks_of0 program pol ppc fetched. |
---|
[930] | 1869 | |
---|
[935] | 1870 | lemma eq_rect_Type1_r: |
---|
| 1871 | ∀A: Type[1]. |
---|
| 1872 | ∀a:A. |
---|
| 1873 | ∀P: ∀x:A. eq ? x a → Type[1]. P a (refl A a) → ∀x: A.∀p:eq ? x a. P x p. |
---|
| 1874 | #A #a #P #H #x #p |
---|
| 1875 | generalize in match H |
---|
| 1876 | generalize in match P |
---|
| 1877 | cases p |
---|
| 1878 | // |
---|
| 1879 | qed. |
---|
| 1880 | |
---|
[949] | 1881 | axiom split_append: |
---|
| 1882 | ∀A: Type[0]. |
---|
| 1883 | ∀m, n: nat. |
---|
| 1884 | ∀v, v': Vector A m. |
---|
| 1885 | ∀q, q': Vector A n. |
---|
| 1886 | let 〈v', q'〉 ≝ split A m n (v@@q) in |
---|
| 1887 | v = v' ∧ q = q'. |
---|
| 1888 | |
---|
| 1889 | axiom split_vector_singleton: |
---|
| 1890 | ∀A: Type[0]. |
---|
| 1891 | ∀n: nat. |
---|
| 1892 | ∀v: Vector A (S n). |
---|
| 1893 | ∀rest: Vector A n. |
---|
| 1894 | ∀s: Vector A 1. |
---|
| 1895 | ∀prf. |
---|
| 1896 | v = s @@ rest → |
---|
| 1897 | ((get_index_v A ? v 0 prf) ::: rest) = v. |
---|
| 1898 | |
---|
[985] | 1899 | example sub_minus_one_seven_eight: |
---|
[949] | 1900 | ∀v: BitVector 7. |
---|
| 1901 | false ::: (\fst (sub_7_with_carry v (bitvector_of_nat ? 1) false)) = |
---|
| 1902 | \fst (sub_8_with_carry (false ::: v) (bitvector_of_nat ? 1) false). |
---|
[985] | 1903 | cases daemon. |
---|
| 1904 | qed. |
---|
[949] | 1905 | |
---|
[950] | 1906 | (* |
---|
[945] | 1907 | lemma blah: |
---|
[949] | 1908 | ∀m: internal_pseudo_address_map. |
---|
[945] | 1909 | ∀s: PseudoStatus. |
---|
| 1910 | ∀arg: Byte. |
---|
[949] | 1911 | ∀b: bool. |
---|
| 1912 | addressing_mode_ok m s (DIRECT arg) = true → |
---|
| 1913 | get_arg_8 ? (set_low_internal_ram ? s (low_internal_ram_of_pseudo_low_internal_ram m (low_internal_ram ? s))) b (DIRECT arg) = |
---|
| 1914 | get_arg_8 ? s b (DIRECT arg). |
---|
| 1915 | [2, 3: normalize % ] |
---|
| 1916 | #m #s #arg #b #hyp |
---|
| 1917 | whd in ⊢ (??%%) |
---|
| 1918 | @split_elim'' |
---|
| 1919 | #nu' #nl' #arg_nu_nl_eq |
---|
| 1920 | normalize nodelta |
---|
| 1921 | generalize in match (refl ? (get_index_v bool 4 nu' ? ?)) |
---|
| 1922 | cases (get_index_v bool 4 nu' ? ?) in ⊢ (??%? → %) |
---|
| 1923 | #get_index_v_eq |
---|
| 1924 | normalize nodelta |
---|
| 1925 | [2: |
---|
| 1926 | normalize nodelta |
---|
| 1927 | @split_elim'' |
---|
| 1928 | #bit_one' #three_bits' #bit_one_three_bit_eq |
---|
| 1929 | generalize in match (low_internal_ram_of_pseudo_internal_ram_miss m s (three_bits'@@nl')) |
---|
| 1930 | normalize nodelta |
---|
| 1931 | generalize in match (refl ? (sub_7_with_carry ? ? ?)) |
---|
| 1932 | cases (sub_7_with_carry ? ? ?) in ⊢ (??%? → %) |
---|
| 1933 | #Saddr #carr' #Saddr_carr_eq |
---|
| 1934 | normalize nodelta |
---|
| 1935 | #carr_hyp' |
---|
| 1936 | @carr_hyp' |
---|
| 1937 | [1: |
---|
| 1938 | |2: whd in hyp:(??%?); generalize in match hyp; -hyp; |
---|
| 1939 | generalize in match (refl ? (¬(member (BitVector 8) ? arg m))) |
---|
| 1940 | cases (¬(member (BitVector 8) ? arg m)) in ⊢ (??%? → %) |
---|
| 1941 | #member_eq |
---|
| 1942 | normalize nodelta |
---|
| 1943 | [2: #destr destruct(destr) |
---|
| 1944 | |1: -carr_hyp'; |
---|
| 1945 | >arg_nu_nl_eq |
---|
| 1946 | <(split_vector_singleton ? ? nu' ? ? ? bit_one_three_bit_eq) |
---|
| 1947 | [1: >get_index_v_eq in ⊢ (??%? → ?) |
---|
| 1948 | |2: @le_S @le_S @le_S @le_n |
---|
| 1949 | ] |
---|
| 1950 | cases (member (BitVector 8) ? (\fst ?) ?) |
---|
| 1951 | [1: #destr normalize in destr; destruct(destr) |
---|
| 1952 | |2: |
---|
| 1953 | ] |
---|
| 1954 | ] |
---|
| 1955 | |3: >get_index_v_eq in ⊢ (??%?) |
---|
| 1956 | change in ⊢ (??(???%?)?) with ((? ::: three_bits') @@ nl') |
---|
| 1957 | >(split_vector_singleton … bit_one_three_bit_eq) |
---|
| 1958 | <arg_nu_nl_eq |
---|
| 1959 | whd in hyp:(??%?) |
---|
| 1960 | cases (member (BitVector 8) (eq_bv 8) arg m) in hyp |
---|
| 1961 | normalize nodelta [*: #ignore @sym_eq ] |
---|
| 1962 | ] |
---|
| 1963 | | |
---|
| 1964 | ]. |
---|
[950] | 1965 | *) |
---|
[949] | 1966 | (* |
---|
[945] | 1967 | map_address0 ... (DIRECT arg) = Some .. → |
---|
| 1968 | get_arg_8 (map_address0 ... (internal_ram ...) (DIRECT arg) = |
---|
| 1969 | get_arg_8 (internal_ram ...) (DIRECT arg) |
---|
| 1970 | |
---|
| 1971 | ((if addressing_mode_ok M ps ACC_A∧addressing_mode_ok M ps (DIRECT ARG2) |
---|
| 1972 | then Some internal_pseudo_address_map M |
---|
| 1973 | else None internal_pseudo_address_map ) |
---|
| 1974 | =Some internal_pseudo_address_map M') |
---|
[946] | 1975 | *) |
---|
[945] | 1976 | |
---|
[1014] | 1977 | axiom low_internal_ram_write_at_stack_pointer: |
---|
| 1978 | ∀T1,T2,M,s1,s2,s3.∀pol.∀pbu,pbl,bu,bl,sp1,sp2:BitVector 8. |
---|
| 1979 | get_8051_sfr ? s2 SFR_SP = get_8051_sfr ? s3 SFR_SP → |
---|
| 1980 | low_internal_ram ? s2 = low_internal_ram T2 s3 → |
---|
| 1981 | sp1 = \snd (half_add ? (get_8051_sfr ? s1 SFR_SP) (bitvector_of_nat 8 1)) → |
---|
| 1982 | sp2 = \snd (half_add ? sp1 (bitvector_of_nat 8 1)) → |
---|
| 1983 | bu@@bl = sigma (code_memory … s2) pol (pbu@@pbl) → |
---|
| 1984 | low_internal_ram T1 |
---|
| 1985 | (write_at_stack_pointer ? |
---|
| 1986 | (set_8051_sfr ? |
---|
| 1987 | (write_at_stack_pointer ? |
---|
| 1988 | (set_8051_sfr ? |
---|
| 1989 | (set_low_internal_ram ? s1 |
---|
| 1990 | (low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram ? s2))) |
---|
| 1991 | SFR_SP sp1) |
---|
| 1992 | bl) |
---|
| 1993 | SFR_SP sp2) |
---|
| 1994 | bu) |
---|
| 1995 | = low_internal_ram_of_pseudo_low_internal_ram (sp1::M) |
---|
| 1996 | (low_internal_ram ? |
---|
| 1997 | (write_at_stack_pointer ? |
---|
| 1998 | (set_8051_sfr ? |
---|
| 1999 | (write_at_stack_pointer ? (set_8051_sfr ? s3 SFR_SP sp1) pbl) |
---|
| 2000 | SFR_SP sp2) |
---|
| 2001 | pbu)). |
---|
| 2002 | |
---|
| 2003 | axiom high_internal_ram_write_at_stack_pointer: |
---|
| 2004 | ∀T1,T2,M,s1,s2,s3,pol.∀pbu,pbl,bu,bl,sp1,sp2:BitVector 8. |
---|
| 2005 | get_8051_sfr ? s2 SFR_SP = get_8051_sfr ? s3 SFR_SP → |
---|
| 2006 | high_internal_ram ? s2 = high_internal_ram T2 s3 → |
---|
| 2007 | sp1 = \snd (half_add ? (get_8051_sfr ? s1 SFR_SP) (bitvector_of_nat 8 1)) → |
---|
| 2008 | sp2 = \snd (half_add ? sp1 (bitvector_of_nat 8 1)) → |
---|
| 2009 | bu@@bl = sigma (code_memory … s2) pol (pbu@@pbl) → |
---|
| 2010 | high_internal_ram T1 |
---|
| 2011 | (write_at_stack_pointer ? |
---|
| 2012 | (set_8051_sfr ? |
---|
| 2013 | (write_at_stack_pointer ? |
---|
| 2014 | (set_8051_sfr ? |
---|
| 2015 | (set_high_internal_ram ? s1 |
---|
| 2016 | (high_internal_ram_of_pseudo_high_internal_ram M (high_internal_ram ? s2))) |
---|
| 2017 | SFR_SP sp1) |
---|
| 2018 | bl) |
---|
| 2019 | SFR_SP sp2) |
---|
| 2020 | bu) |
---|
| 2021 | = high_internal_ram_of_pseudo_high_internal_ram (sp1::M) |
---|
| 2022 | (high_internal_ram ? |
---|
| 2023 | (write_at_stack_pointer ? |
---|
| 2024 | (set_8051_sfr ? |
---|
| 2025 | (write_at_stack_pointer ? (set_8051_sfr ? s3 SFR_SP sp1) pbl) |
---|
| 2026 | SFR_SP sp2) |
---|
| 2027 | pbu)). |
---|
| 2028 | |
---|
[1037] | 2029 | lemma Some_Some_elim: |
---|
| 2030 | ∀T:Type[0].∀x,y:T.∀P:Type[2]. (x=y → P) → Some T x = Some T y → P. |
---|
| 2031 | #T #x #y #P #H #K @H @option_destruct_Some // |
---|
| 2032 | qed. |
---|
| 2033 | |
---|
[1035] | 2034 | theorem main_thm: |
---|
| 2035 | ∀M,M',ps,pol. |
---|
| 2036 | next_internal_pseudo_address_map M ps = Some … M' → |
---|
| 2037 | ∃n. |
---|
| 2038 | execute n (status_of_pseudo_status M ps pol) |
---|
| 2039 | = status_of_pseudo_status M' (execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol) ps) ?. |
---|
| 2040 | [2: >execute_1_pseudo_instruction_preserves_code_memory @pol] |
---|
| 2041 | #M #M' #ps #pol #SAFE |
---|
| 2042 | cut |
---|
| 2043 | (∀ps'. |
---|
| 2044 | ∀prf:ps'=execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol) ps. |
---|
| 2045 | ∃n. execute n (status_of_pseudo_status M ps pol) = status_of_pseudo_status M' ps' ?) |
---|
| 2046 | [ >prf >execute_1_pseudo_instruction_preserves_code_memory @pol |3: #K @(K ? (refl …))] |
---|
| 2047 | #ps' #EQ |
---|
| 2048 | whd in ⊢ (??(λ_.??(??%)?)) |
---|
| 2049 | change with |
---|
| 2050 | (∃n. |
---|
| 2051 | execute n |
---|
| 2052 | (set_low_internal_ram ? |
---|
| 2053 | (set_high_internal_ram ? |
---|
| 2054 | (set_program_counter ? |
---|
| 2055 | (set_code_memory ?? ps (load_code_memory ?)) |
---|
| 2056 | (sigma ? pol (program_counter ? ps))) |
---|
| 2057 | (high_internal_ram_of_pseudo_high_internal_ram M ?)) |
---|
| 2058 | (low_internal_ram_of_pseudo_low_internal_ram M ?)) |
---|
| 2059 | = set_low_internal_ram ? |
---|
| 2060 | (set_high_internal_ram ? |
---|
| 2061 | (set_program_counter ? |
---|
| 2062 | (set_code_memory ?? ? (load_code_memory ?)) |
---|
| 2063 | (sigma ???)) ?) ?) |
---|
| 2064 | >EQ whd in match eq_rect_Type0_r normalize nodelta |
---|
| 2065 | >execute_1_pseudo_instruction_preserves_code_memory normalize nodelta |
---|
| 2066 | generalize in match EQ -EQ; |
---|
| 2067 | generalize in match (refl … (code_memory pseudo_assembly_program ps)) |
---|
[1036] | 2068 | generalize in match pol -pol; generalize in ⊢ (∀_.??%? → ?) |
---|
[1035] | 2069 | * #preamble #instr_list #pol #EQ1 generalize in match pol -pol <EQ1 #pol #EQps' <EQps' |
---|
[1036] | 2070 | (* Dependent types madness ends here *) |
---|
| 2071 | letin ppc ≝ (program_counter … ps) |
---|
[1039] | 2072 | generalize in match (fetch_assembly_pseudo2 ? pol ppc) in ⊢ ? |
---|
[1036] | 2073 | letin assembled ≝ (\fst (assembly ? pol)) |
---|
| 2074 | letin lookup_labels ≝ (λx. sigma ? pol (address_of_word_labels_code_mem instr_list x)) |
---|
| 2075 | letin lookup_datalabels ≝ (λx. lookup … x (construct_datalabels preamble) (zero 16)) |
---|
| 2076 | @pair_elim' #pi #newppc #EQ2 |
---|
| 2077 | letin instructions ≝ |
---|
| 2078 | (expand_pseudo_instruction ? pol ppc lookup_labels lookup_datalabels |
---|
| 2079 | (sigma ? pol ppc) (refl …) (refl …) (refl …)) |
---|
| 2080 | change with (fetch_many ???? → ?) #H1 |
---|
| 2081 | change in EQ2 with (fetch_pseudo_instruction instr_list ppc = ?) |
---|
| 2082 | change in SAFE with (next_internal_pseudo_address_map0 ???? = ?) <EQ1 in SAFE; |
---|
| 2083 | >EQ2 whd in ⊢ (??(??%??)? → ?) #SAFE |
---|
[1037] | 2084 | whd in EQps':(???%); <EQ1 in EQps'; >EQ2 normalize nodelta |
---|
| 2085 | generalize in match H1; -H1; generalize in match instructions -instructions |
---|
| 2086 | * #instructions >EQ2 change in match (\fst 〈pi,newppc〉) with pi |
---|
| 2087 | whd in match ticks_of normalize nodelta <EQ1 >EQ2 |
---|
| 2088 | cases pi in SAFE |
---|
| 2089 | [2,3: (* Comment, Cost *) #ARG whd in ⊢ (??%? → ???% → ?) |
---|
| 2090 | @Some_Some_elim #MAP #EQ3 @(Some_Some_elim ????? EQ3) #EQ3' |
---|
| 2091 | whd in match eject normalize nodelta >EQ3' in ⊢ (% → ?) whd in ⊢ (% → ?) |
---|
| 2092 | #H2 #EQ %[1,3:@0] |
---|
| 2093 | <MAP >(eq_bv_eq … H2) >EQ % |
---|
[1039] | 2094 | |4: (* Jmp *) #label whd in ⊢ (??%? → ???% → ?) |
---|
| 2095 | @Some_Some_elim #MAP cases (pol ?) normalize nodelta |
---|
| 2096 | [3: (* long *) #EQ3 @(Some_Some_elim ????? EQ3) #EQ3' |
---|
| 2097 | whd in match eject normalize nodelta >EQ3' in ⊢ (% → ?) whd in ⊢ (% → ?) |
---|
| 2098 | @pair_elim' * #instr #newppc' #ticks #EQ4 |
---|
| 2099 | * * #H2a #H2b whd in ⊢ (% → ?) #H2 |
---|
| 2100 | >H2b >(eq_instruction_to_eq … H2a) |
---|
| 2101 | #EQ %[@1] |
---|
| 2102 | <MAP >(eq_bv_eq … H2) >EQ |
---|
| 2103 | whd in ⊢ (??%?) >EQ4 whd in ⊢ (??%?) |
---|
| 2104 | cases ps in EQ4; #A1 #A2 #A3 #A4 #A5 #A6 #A7 #A8 #A9 #A10 #XXX >XXX % |
---|
| 2105 | whd in ⊢ (??%?) |
---|
| 2106 | whd in ⊢ (??(match ?%? with [_ ⇒ ?])?) |
---|
| 2107 | cases ps in EQ0 ⊢ %; #A1 #A2 #A3 #A4 #A5 #A6 #A7 #A8 #A9 #A10 #XXXX >XXXX % |
---|
[1042] | 2108 | |6: (* Mov *) #arg1 #arg2 |
---|
[942] | 2109 | #H1 #H2 #EQ %[@1] |
---|
| 2110 | normalize in H1; generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2111 | change in ⊢ (? → ??%?) with (execute_1_0 ??) |
---|
| 2112 | cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta; |
---|
| 2113 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c |
---|
| 2114 | >H2b >(eq_instruction_to_eq … H2a) |
---|
| 2115 | generalize in match EQ; -EQ; whd in ⊢ (???% → ??%?); |
---|
| 2116 | @(list_addressing_mode_tags_elim_prop … arg1) whd try % -arg1; whd in ⊢ (???% → ??%?) |
---|
| 2117 | @(list_addressing_mode_tags_elim_prop … arg2) whd try % -arg2; #ARG2 |
---|
| 2118 | normalize nodelta; |
---|
| 2119 | [1,2,3,4,5,6,7,8: cases (add_8_with_carry ???) |*: cases (sub_8_with_carry ???)] |
---|
| 2120 | #result #flags |
---|
[1042] | 2121 | #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) % |
---|
| 2122 | |5: (* Call *) #label #MAP |
---|
[948] | 2123 | generalize in match (option_destruct_Some ??? MAP) -MAP; #MAP <MAP -MAP; |
---|
[988] | 2124 | whd in ⊢ (???% → ?) cases (pol ?) normalize nodelta; |
---|
[948] | 2125 | [ (* short *) #abs @⊥ destruct (abs) |
---|
| 2126 | |3: (* long *) #H1 #H2 #EQ %[@1] |
---|
[946] | 2127 | (* normalize in H1; !!!*) generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2128 | change in ⊢ (? → ??%?) with (execute_1_0 ??) |
---|
[988] | 2129 | cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta; |
---|
[946] | 2130 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c |
---|
| 2131 | >H2b >(eq_instruction_to_eq … H2a) |
---|
| 2132 | generalize in match EQ; -EQ; |
---|
[948] | 2133 | whd in ⊢ (???% → ??%?); |
---|
[950] | 2134 | generalize in match (refl … (half_add 8 (get_8051_sfr ? ps SFR_SP) (bitvector_of_nat ? 1))) cases (half_add ???) in ⊢ (??%? → %) #carry #new_sp #EQ1 normalize nodelta; |
---|
[985] | 2135 | >(eq_bv_eq … H2c) |
---|
[948] | 2136 | change with |
---|
| 2137 | ((?=let 〈ppc_bu,ppc_bl〉 ≝ split bool 8 8 newppc in ?) → |
---|
[988] | 2138 | (let 〈pc_bu,pc_bl〉 ≝ split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc) in ?)=?) |
---|
[948] | 2139 | generalize in match (refl … (split … 8 8 newppc)) cases (split bool 8 8 newppc) in ⊢ (??%? → %) #ppc_bu #ppc_bl #EQppc |
---|
[988] | 2140 | generalize in match (refl … (split … 8 8 (sigma 〈preamble,instr_list〉 pol newppc))) cases (split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc)) in ⊢ (??%? → %) #pc_bu #pc_bl #EQpc normalize nodelta; |
---|
[948] | 2141 | >get_8051_sfr_write_at_stack_pointer >get_8051_sfr_write_at_stack_pointer |
---|
[950] | 2142 | >get_8051_sfr_set_8051_sfr >get_8051_sfr_set_8051_sfr |
---|
| 2143 | generalize in match (refl … (half_add ? new_sp (bitvector_of_nat ? 1))) cases (half_add ???) in ⊢ (??%? → %) #carry' #new_sp' #EQ2 normalize nodelta; |
---|
[985] | 2144 | #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) |
---|
[951] | 2145 | @split_eq_status; |
---|
[948] | 2146 | [ >code_memory_write_at_stack_pointer whd in ⊢ (??%?) |
---|
| 2147 | >code_memory_write_at_stack_pointer % |
---|
[950] | 2148 | | >set_program_counter_set_low_internal_ram |
---|
| 2149 | >set_clock_set_low_internal_ram |
---|
| 2150 | @low_internal_ram_write_at_stack_pointer |
---|
[988] | 2151 | [ >EQ0 @pol | % | % |
---|
[950] | 2152 | | @(pair_destruct_2 … EQ1) |
---|
| 2153 | | @(pair_destruct_2 … EQ2) |
---|
| 2154 | | >(pair_destruct_1 ????? EQpc) |
---|
| 2155 | >(pair_destruct_2 ????? EQpc) |
---|
| 2156 | @split_elim #x #y #H <H -x y H; |
---|
| 2157 | >(pair_destruct_1 ????? EQppc) |
---|
| 2158 | >(pair_destruct_2 ????? EQppc) |
---|
| 2159 | @split_elim #x #y #H <H -x y H; |
---|
| 2160 | >EQ0 % ] |
---|
[951] | 2161 | | >set_low_internal_ram_set_high_internal_ram |
---|
| 2162 | >set_program_counter_set_high_internal_ram |
---|
| 2163 | >set_clock_set_high_internal_ram |
---|
| 2164 | @high_internal_ram_write_at_stack_pointer |
---|
[988] | 2165 | [ >EQ0 @pol | % | % |
---|
[951] | 2166 | | @(pair_destruct_2 … EQ1) |
---|
| 2167 | | @(pair_destruct_2 … EQ2) |
---|
| 2168 | | >(pair_destruct_1 ????? EQpc) |
---|
| 2169 | >(pair_destruct_2 ????? EQpc) |
---|
| 2170 | @split_elim #x #y #H <H -x y H; |
---|
| 2171 | >(pair_destruct_1 ????? EQppc) |
---|
| 2172 | >(pair_destruct_2 ????? EQppc) |
---|
| 2173 | @split_elim #x #y #H <H -x y H; |
---|
| 2174 | >EQ0 % ] |
---|
[948] | 2175 | | >external_ram_write_at_stack_pointer whd in ⊢ (??%?) |
---|
| 2176 | >external_ram_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2177 | >external_ram_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2178 | >external_ram_write_at_stack_pointer % |
---|
[988] | 2179 | | change with (? = sigma ?? (address_of_word_labels_code_mem (\snd (code_memory ? ps)) ?)) |
---|
[948] | 2180 | >EQ0 % |
---|
| 2181 | | >special_function_registers_8051_write_at_stack_pointer whd in ⊢ (??%?) |
---|
| 2182 | >special_function_registers_8051_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2183 | >special_function_registers_8051_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2184 | >special_function_registers_8051_write_at_stack_pointer % |
---|
| 2185 | | >special_function_registers_8052_write_at_stack_pointer whd in ⊢ (??%?) |
---|
| 2186 | >special_function_registers_8052_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2187 | >special_function_registers_8052_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2188 | >special_function_registers_8052_write_at_stack_pointer % |
---|
| 2189 | | >p1_latch_write_at_stack_pointer whd in ⊢ (??%?) |
---|
| 2190 | >p1_latch_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2191 | >p1_latch_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2192 | >p1_latch_write_at_stack_pointer % |
---|
| 2193 | | >p3_latch_write_at_stack_pointer whd in ⊢ (??%?) |
---|
| 2194 | >p3_latch_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2195 | >p3_latch_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2196 | >p3_latch_write_at_stack_pointer % |
---|
| 2197 | | >clock_write_at_stack_pointer whd in ⊢ (??%?) |
---|
| 2198 | >clock_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2199 | >clock_write_at_stack_pointer whd in ⊢ (???%) |
---|
| 2200 | >clock_write_at_stack_pointer %] |
---|
[985] | 2201 | (*| (* medium *) #H1 #H2 #EQ %[@1] generalize in match H1; -H1; |
---|
[959] | 2202 | @pair_elim' #fst_5_addr #rest_addr #EQ1 |
---|
| 2203 | @pair_elim' #fst_5_pc #rest_pc #EQ2 |
---|
[946] | 2204 | generalize in match (refl … (eq_bv … fst_5_addr fst_5_pc)) |
---|
| 2205 | cases (eq_bv ???) in ⊢ (??%? → %) normalize nodelta; #EQ3 #TEQ [2: destruct (TEQ)] |
---|
| 2206 | generalize in match (option_destruct_Some ??? TEQ) -TEQ; #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2207 | change in ⊢ (? →??%?) with (execute_1_0 ??) |
---|
[959] | 2208 | @pair_elim' * #instr #newppc' #ticks #EQn |
---|
| 2209 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c >H2b >(eq_instruction_to_eq … H2a) whd in ⊢ (??%?) |
---|
[985] | 2210 | generalize in match EQ; -EQ; normalize nodelta; >(eq_bv_eq … H2c) |
---|
[959] | 2211 | @pair_elim' #carry #new_sp change with (half_add ? (get_8051_sfr ? ps ?) ? = ? → ?) #EQ4 |
---|
| 2212 | @split_elim' #pc_bu #pc_bl >program_counter_set_8051_sfr XXX change with (newppc = ?) #EQ5 |
---|
| 2213 | @pair_elim' #carry' #new_sp' #EQ6 normalize nodelta; #EQx >EQx -EQx; |
---|
| 2214 | change in ⊢ (??(match ????% with [_ ⇒ ?])?) with (sigma … newppc) |
---|
| 2215 | @split_elim' #pc_bu' #pc_bl' #EQ7 change with (newppc' = ? → ?) |
---|
| 2216 | >get_8051_sfr_set_8051_sfr |
---|
| 2217 | |
---|
[985] | 2218 | whd in EQ:(???%) ⊢ ? >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) whd in ⊢ (??%?) |
---|
[946] | 2219 | change with ((let 〈pc_bu,pc_bl〉 ≝ split bool 8 8 (sigma 〈preamble,instr_list〉 newppc) in ?)=?) |
---|
| 2220 | generalize in match (refl … (split bool 8 8 (sigma 〈preamble,instr_list〉 newppc))) |
---|
| 2221 | cases (split ????) in ⊢ (??%? → %) #pc_bu #pc_bl normalize nodelta; #EQ4 |
---|
| 2222 | generalize in match (refl … (split bool 4 4 pc_bu)) |
---|
| 2223 | cases (split ????) in ⊢ (??%? → %) #nu #nl normalize nodelta; #EQ5 |
---|
| 2224 | generalize in match (refl … (split bool 3 8 rest_addr)) |
---|
| 2225 | cases (split ????) in ⊢ (??%? → %) #relevant1 #relevant2 normalize nodelta; #EQ6 |
---|
| 2226 | change with ((let 〈carry,new_pc〉 ≝ half_add ? (sigma … newppc) ? in ?) = ?) |
---|
| 2227 | generalize in match |
---|
| 2228 | (refl … |
---|
| 2229 | (half_add 16 (sigma 〈preamble,instr_list〉 newppc) |
---|
| 2230 | ((nu@@get_index' bool 0 3 nl:::relevant1)@@relevant2))) |
---|
| 2231 | cases (half_add ???) in ⊢ (??%? → %) #carry #new_pc normalize nodelta; #EQ7 |
---|
| 2232 | @split_eq_status try % |
---|
| 2233 | [ change with (? = sigma ? (address_of_word_labels ps label)) |
---|
| 2234 | (* ARITHMETICS, BUT THE GOAL SEEMS FALSE *) |
---|
| 2235 | | whd in ⊢ (??%%) whd in ⊢ (??(?%?)?) whd in ⊢ (??(?(match ?(?%)? with [_ ⇒ ?])?)?) |
---|
[985] | 2236 | @(bitvector_3_elim_prop … (\fst (split bool 3 8 rest_addr))) %]] *)] |
---|
[948] | 2237 | |4: (* Jmp *) #label #MAP |
---|
| 2238 | generalize in match (option_destruct_Some ??? MAP) -MAP; #MAP >MAP -MAP; |
---|
[988] | 2239 | whd in ⊢ (???% → ?) cases (pol ?) normalize nodelta; |
---|
[948] | 2240 | [3: (* long *) #H1 #H2 #EQ %[@1] |
---|
[938] | 2241 | (* normalize in H1; !!!*) generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2242 | change in ⊢ (? → ??%?) with (execute_1_0 ??) |
---|
[988] | 2243 | cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta; |
---|
[938] | 2244 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c |
---|
| 2245 | >H2b >(eq_instruction_to_eq … H2a) |
---|
| 2246 | generalize in match EQ; -EQ; |
---|
[985] | 2247 | #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) |
---|
[948] | 2248 | cases ps in EQ0 ⊢ %; #A1 #A2 #A3 #A4 #A5 #A6 #A7 #A8 #A9 #A10 #XXXX >XXXX % |
---|
| 2249 | |1: (* short *) #H1 #H2 #EQ %[@1] generalize in match H1; -H1; |
---|
[941] | 2250 | generalize in match |
---|
| 2251 | (refl ? |
---|
| 2252 | (sub_16_with_carry |
---|
[988] | 2253 | (sigma 〈preamble,instr_list〉 pol (program_counter … ps)) |
---|
| 2254 | (sigma 〈preamble,instr_list〉 pol (address_of_word_labels_code_mem instr_list label)) |
---|
[941] | 2255 | false)) |
---|
| 2256 | cases (sub_16_with_carry ???) in ⊢ (??%? → %); #results #flags normalize nodelta; |
---|
| 2257 | generalize in match (refl … (split … 8 8 results)) cases (split ????) in ⊢ (??%? → %) #upper #lower normalize nodelta; |
---|
| 2258 | generalize in match (refl … (eq_bv … upper (zero 8))) cases (eq_bv ???) in ⊢ (??%? → %) normalize nodelta; |
---|
| 2259 | #EQ1 #EQ2 #EQ3 #H1 [2: @⊥ destruct (H1)] |
---|
| 2260 | generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2261 | change in ⊢ (? → ??%?) with (execute_1_0 ??) |
---|
[988] | 2262 | cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta; |
---|
[941] | 2263 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c |
---|
| 2264 | >H2b >(eq_instruction_to_eq … H2a) |
---|
| 2265 | generalize in match EQ; -EQ; |
---|
| 2266 | whd in ⊢ (???% → ?); |
---|
[985] | 2267 | #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) |
---|
[988] | 2268 | change with ((let 〈carry,new_pc〉 ≝ half_add ? (sigma ???) ? in ?) = ?) |
---|
| 2269 | generalize in match (refl … (half_add 16 (sigma 〈preamble,instr_list〉 pol newppc) (sign_extension lower))) |
---|
[941] | 2270 | cases (half_add ???) in ⊢ (??%? → %) #carry #newpc normalize nodelta #EQ4 |
---|
[988] | 2271 | @split_eq_status try % change with (newpc = sigma ?? (address_of_word_labels ps label)) |
---|
[941] | 2272 | (* ARITHMETICS, BUT THE GOAL SEEMS FALSE *) |
---|
| 2273 | | (* medium *) #H1 #H2 #EQ %[@1] generalize in match H1; -H1; |
---|
| 2274 | generalize in match |
---|
| 2275 | (refl … |
---|
[988] | 2276 | (split … 5 11 (sigma 〈preamble,instr_list〉 pol (address_of_word_labels_code_mem instr_list label)))) |
---|
[941] | 2277 | cases (split ????) in ⊢ (??%? → %) #fst_5_addr #rest_addr normalize nodelta; #EQ1 |
---|
| 2278 | generalize in match |
---|
| 2279 | (refl … |
---|
[988] | 2280 | (split … 5 11 (sigma 〈preamble,instr_list〉 pol (program_counter … ps)))) |
---|
[941] | 2281 | cases (split ????) in ⊢ (??%? → %) #fst_5_pc #rest_pc normalize nodelta; #EQ2 |
---|
| 2282 | generalize in match (refl … (eq_bv … fst_5_addr fst_5_pc)) |
---|
| 2283 | cases (eq_bv ???) in ⊢ (??%? → %) normalize nodelta; #EQ3 #TEQ [2: destruct (TEQ)] |
---|
| 2284 | generalize in match (option_destruct_Some ??? TEQ) -TEQ; #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2285 | change in ⊢ (? →??%?) with (execute_1_0 ??) |
---|
[988] | 2286 | cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta; |
---|
[941] | 2287 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c |
---|
| 2288 | >H2b >(eq_instruction_to_eq … H2a) |
---|
| 2289 | generalize in match EQ; -EQ; |
---|
| 2290 | whd in ⊢ (???% → ?); |
---|
[985] | 2291 | #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) whd in ⊢ (??%?) |
---|
[988] | 2292 | change with ((let 〈pc_bu,pc_bl〉 ≝ split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc) in ?)=?) |
---|
| 2293 | generalize in match (refl … (split bool 8 8 (sigma 〈preamble,instr_list〉 pol newppc))) |
---|
[941] | 2294 | cases (split ????) in ⊢ (??%? → %) #pc_bu #pc_bl normalize nodelta; #EQ4 |
---|
| 2295 | generalize in match (refl … (split bool 4 4 pc_bu)) |
---|
| 2296 | cases (split ????) in ⊢ (??%? → %) #nu #nl normalize nodelta; #EQ5 |
---|
| 2297 | generalize in match (refl … (split bool 3 8 rest_addr)) |
---|
| 2298 | cases (split ????) in ⊢ (??%? → %) #relevant1 #relevant2 normalize nodelta; #EQ6 |
---|
| 2299 | change with ((let 〈carry,new_pc〉 ≝ half_add ? (sigma … newppc) ? in ?) = ?) |
---|
| 2300 | generalize in match |
---|
| 2301 | (refl … |
---|
[988] | 2302 | (half_add 16 (sigma 〈preamble,instr_list〉 pol newppc) |
---|
[941] | 2303 | ((nu@@get_index' bool 0 3 nl:::relevant1)@@relevant2))) |
---|
[948] | 2304 | cases (half_add ???) in ⊢ (??%? → %) #carry #new_pc normalize nodelta; #EQ7 |
---|
[941] | 2305 | @split_eq_status try % |
---|
[988] | 2306 | [ change with (? = sigma ?? (address_of_word_labels ps label)) |
---|
[941] | 2307 | (* ARITHMETICS, BUT THE GOAL SEEMS FALSE *) |
---|
| 2308 | | whd in ⊢ (??%%) whd in ⊢ (??(?%?)?) whd in ⊢ (??(?(match ?(?%)? with [_ ⇒ ?])?)?) |
---|
[948] | 2309 | @(bitvector_3_elim_prop … (\fst (split bool 3 8 rest_addr))) %]] |
---|
[1042] | 2310 | | (* Instruction *) -pi; whd in ⊢ (? → ??%? → ?) *; normalize nodelta; |
---|
[942] | 2311 | [1,2,3: (* ADD, ADDC, SUBB *) #arg1 #arg2 #MAP #H1 #H2 #EQ %[1,3,5:@1] |
---|
[930] | 2312 | normalize in H1; generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2313 | change in ⊢ (? → ??%?) with (execute_1_0 ??) |
---|
[989] | 2314 | cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 pol (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta; |
---|
[936] | 2315 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c |
---|
| 2316 | >H2b >(eq_instruction_to_eq … H2a) |
---|
[942] | 2317 | generalize in match EQ; -EQ; whd in ⊢ (???% → ??%?); generalize in match MAP; -MAP; |
---|
[933] | 2318 | @(list_addressing_mode_tags_elim_prop … arg1) whd try % -arg1; |
---|
| 2319 | @(list_addressing_mode_tags_elim_prop … arg2) whd try % -arg2; #ARG2 |
---|
[1042] | 2320 | normalize nodelta; #MAP; |
---|
[943] | 2321 | [1: change in ⊢ (? → %) with |
---|
| 2322 | ((let 〈result,flags〉 ≝ |
---|
| 2323 | add_8_with_carry |
---|
| 2324 | (get_arg_8 ? ps false ACC_A) |
---|
| 2325 | (get_arg_8 ? |
---|
| 2326 | (set_low_internal_ram ? ps (low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … ps))) |
---|
| 2327 | false (DIRECT ARG2)) |
---|
[989] | 2328 | ? in ?) = ?) |
---|
| 2329 | [2,3: %] |
---|
| 2330 | change in ⊢ (???% → ?) with |
---|
| 2331 | (let 〈result,flags〉 ≝ add_8_with_carry ?(*(get_arg_8 ? ps false ACC_A)*) ?? in ?) |
---|
[1042] | 2332 | >get_arg_8_set_clock |
---|
[989] | 2333 | [1,2: cases (addressing_mode_ok ???? ∧ addressing_mode_ok ????) in MAP ⊢ ? |
---|
| 2334 | [2,4: #abs @⊥ normalize in abs; destruct (abs) |
---|
| 2335 | |*:whd in ⊢ (??%? → ?) #H <(option_destruct_Some ??? H)] |
---|
| 2336 | [ change in ⊢ (? → %) with |
---|
| 2337 | ((let 〈result,flags〉 ≝ |
---|
| 2338 | add_8_with_carry |
---|
| 2339 | (get_arg_8 ? ps false ACC_A) |
---|
| 2340 | (get_arg_8 ? |
---|
| 2341 | (set_low_internal_ram ? ps (low_internal_ram_of_pseudo_low_internal_ram M (low_internal_ram … ps))) |
---|
| 2342 | false (DIRECT ARG2)) |
---|
| 2343 | ? in ?) = ?) |
---|
| 2344 | >get_arg_8_set_low_internal_ram |
---|
| 2345 | |
---|
| 2346 | cases (add_8_with_carry ???) |
---|
| 2347 | |
---|
| 2348 | [1,2,3,4,5,6,7,8: cases (add_8_with_carry ???) |*: cases (sub_8_with_carry ???)] |
---|
[931] | 2349 | #result #flags |
---|
[985] | 2350 | #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) % |
---|
[1042] | 2351 | | (* INC *) #arg1 #H1 #H2 #EQ %[@1] |
---|
[931] | 2352 | normalize in H1; generalize in match (option_destruct_Some ??? H1) #K1 >K1 in H2; whd in ⊢ (% → ?) |
---|
| 2353 | change in ⊢ (? → ??%?) with (execute_1_0 ??) |
---|
| 2354 | cases (fetch (load_code_memory assembled) (sigma 〈preamble,instr_list〉 (program_counter … ps))) * #instr #newppc' #ticks normalize nodelta; |
---|
[936] | 2355 | * * #H2a #H2b whd in ⊢ (% → ?) #H2c |
---|
| 2356 | >H2b >(eq_instruction_to_eq … H2a) |
---|
| 2357 | generalize in match EQ; -EQ; whd in ⊢ (???% → ??%?); |
---|
[931] | 2358 | @(list_addressing_mode_tags_elim_prop … arg1) whd try % -arg1; normalize nodelta; [1,2,3: #ARG] |
---|
[932] | 2359 | [1,2,3,4: cases (half_add ???) #carry #result |
---|
[934] | 2360 | | cases (half_add ???) #carry #bl normalize nodelta; |
---|
| 2361 | cases (full_add ????) #carry' #bu normalize nodelta ] |
---|
[985] | 2362 | #EQ >EQ -EQ; normalize nodelta; >(eq_bv_eq … H2c) -newppc'; |
---|
[934] | 2363 | [5: % |
---|
[940] | 2364 | |1: <(set_arg_8_set_code_memory 0 [[direct]] ? ? ? (set_clock pseudo_assembly_program |
---|
| 2365 | (set_program_counter pseudo_assembly_program ps newppc) |
---|
| 2366 | (\fst (ticks_of0 〈preamble,instr_list〉 |
---|
| 2367 | (program_counter pseudo_assembly_program ps) |
---|
| 2368 | (Instruction (INC Identifier (DIRECT ARG)))) |
---|
| 2369 | +clock pseudo_assembly_program |
---|
| 2370 | (set_program_counter pseudo_assembly_program ps newppc))) (load_code_memory assembled) result (DIRECT ARG)) |
---|
| 2371 | [2,3: // ] |
---|
| 2372 | <(set_arg_8_set_program_counter 0 [[direct]] ? ? ? ? ?) [2://] |
---|
| 2373 | whd in ⊢ (??%%) |
---|
| 2374 | cases (split bool 4 4 ARG) |
---|
| 2375 | #nu' #nl' |
---|
| 2376 | normalize nodelta |
---|
| 2377 | cases (split bool 1 3 nu') |
---|
| 2378 | #bit_1' #ignore' |
---|
| 2379 | normalize nodelta |
---|
| 2380 | cases (get_index_v bool 4 nu' ? ?) |
---|
| 2381 | [ normalize nodelta (* HERE *) whd in ⊢ (??%%) % |
---|
| 2382 | | |
---|
[1042] | 2383 | ] |
---|
| 2384 | cases daemon (* EASY CASES TO BE COMPLETED *) |
---|
[1043] | 2385 | qed. |
---|