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