[719] | 1 | include "ASM/ASM.ma". |
---|
| 2 | include "ASM/Arithmetic.ma". |
---|
| 3 | include "ASM/Fetch.ma". |
---|
| 4 | include "ASM/Status.ma". |
---|
[1459] | 5 | include alias "basics/logic.ma". |
---|
[1528] | 6 | include alias "arithmetics/nat.ma". |
---|
[1948] | 7 | include "utilities/extralib.ma". |
---|
[719] | 8 | |
---|
[989] | 9 | (**************************************** START OF POLICY ABSTRACTION ********************) |
---|
| 10 | |
---|
[1925] | 11 | (* definition of & operations on jump length *) |
---|
[1615] | 12 | inductive jump_length: Type[0] ≝ |
---|
| 13 | | short_jump: jump_length |
---|
[2101] | 14 | | absolute_jump: jump_length |
---|
[1925] | 15 | | long_jump: jump_length. |
---|
[2048] | 16 | |
---|
| 17 | (* Functions that define the conditions under which jumps are possible *) |
---|
| 18 | definition short_jump_cond: Word → Word → (*pseudo_instruction →*) |
---|
| 19 | bool × (BitVector 8) ≝ |
---|
| 20 | λpc_plus_jmp_length.λaddr.(*λinstr.*) |
---|
| 21 | let 〈result, flags〉 ≝ sub_16_with_carry addr pc_plus_jmp_length false in |
---|
[2051] | 22 | let 〈upper, lower〉 ≝ vsplit ? 9 7 result in |
---|
[2048] | 23 | if get_index' ? 2 0 flags then |
---|
[2051] | 24 | 〈eq_bv 9 upper [[true;true;true;true;true;true;true;true;true]], true:::lower〉 |
---|
[2048] | 25 | else |
---|
[2051] | 26 | 〈eq_bv 9 upper (zero …), false:::lower〉. |
---|
[2048] | 27 | |
---|
[2101] | 28 | definition absolute_jump_cond: Word → Word → (*pseudo_instruction →*) |
---|
[2048] | 29 | bool × (BitVector 11) ≝ |
---|
| 30 | λpc_plus_jmp_length.λaddr.(*λinstr.*) |
---|
| 31 | let 〈fst_5_addr, rest_addr〉 ≝ vsplit bool 5 11 addr in |
---|
| 32 | let 〈fst_5_pc, rest_pc〉 ≝ vsplit bool 5 11 pc_plus_jmp_length in |
---|
| 33 | 〈eq_bv 5 fst_5_addr fst_5_pc, rest_addr〉. |
---|
[1615] | 34 | |
---|
| 35 | definition assembly_preinstruction ≝ |
---|
| 36 | λA: Type[0]. |
---|
| 37 | λaddr_of: A → Byte. (* relative *) |
---|
| 38 | λpre: preinstruction A. |
---|
| 39 | match pre with |
---|
| 40 | [ ADD addr1 addr2 ⇒ |
---|
| 41 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 42 | [ REGISTER r ⇒ λ_.[ ([[false;false;true;false;true]]) @@ r ] |
---|
| 43 | | DIRECT b1 ⇒ λ_.[ ([[false;false;true;false;false;true;false;true]]); b1 ] |
---|
| 44 | | INDIRECT i1 ⇒ λ_. [ ([[false;false;true;false;false;true;true;i1]]) ] |
---|
| 45 | | DATA b1 ⇒ λ_. [ ([[false;false;true;false;false;true;false;false]]) ; b1 ] |
---|
| 46 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 47 | | ADDC addr1 addr2 ⇒ |
---|
| 48 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 49 | [ REGISTER r ⇒ λ_.[ ([[false;false;true;true;true]]) @@ r ] |
---|
| 50 | | DIRECT b1 ⇒ λ_.[ ([[false;false;true;true;false;true;false;true]]); b1 ] |
---|
| 51 | | INDIRECT i1 ⇒ λ_. [ ([[false;false;true;true;false;true;true;i1]]) ] |
---|
| 52 | | DATA b1 ⇒ λ_. [ ([[false;false;true;true;false;true;false;false]]) ; b1 ] |
---|
| 53 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 54 | | ANL addrs ⇒ |
---|
| 55 | match addrs with |
---|
| 56 | [ inl addrs ⇒ match addrs with |
---|
| 57 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 58 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 59 | [ REGISTER r ⇒ λ_.[ ([[false;true;false;true;true]]) @@ r ] |
---|
| 60 | | DIRECT b1 ⇒ λ_.[ ([[false;true;false;true;false;true;false;true]]); b1 ] |
---|
| 61 | | INDIRECT i1 ⇒ λ_. [ ([[false;true;false;true;false;true;true;i1]]) ] |
---|
| 62 | | DATA b1 ⇒ λ_. [ ([[false;true;false;true;false;true;false;false]]) ; b1 ] |
---|
| 63 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 64 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 65 | let b1 ≝ |
---|
| 66 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 67 | [ DIRECT b1 ⇒ λ_.b1 |
---|
| 68 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 69 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;data]] x) → ? with |
---|
| 70 | [ ACC_A ⇒ λ_.[ ([[false;true;false;true;false;false;true;false]]) ; b1 ] |
---|
| 71 | | DATA b2 ⇒ λ_. [ ([[false;true;false;true;false;false;true;true]]) ; b1 ; b2 ] |
---|
| 72 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 73 | ] |
---|
| 74 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 75 | match addr2 return λx. bool_to_Prop (is_in ? [[bit_addr;n_bit_addr]] x) → ? with |
---|
| 76 | [ BIT_ADDR b1 ⇒ λ_.[ ([[true;false;false;false;false;false;true;false]]) ; b1 ] |
---|
| 77 | | N_BIT_ADDR b1 ⇒ λ_. [ ([[true;false;true;true;false;false;false;false]]) ; b1 ] |
---|
| 78 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 79 | | CLR addr ⇒ |
---|
| 80 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;carry;bit_addr]] x) → ? with |
---|
| 81 | [ ACC_A ⇒ λ_. |
---|
| 82 | [ ([[true; true; true; false; false; true; false; false]]) ] |
---|
| 83 | | CARRY ⇒ λ_. |
---|
| 84 | [ ([[true; true; false; false; false; false; true; true]]) ] |
---|
| 85 | | BIT_ADDR b1 ⇒ λ_. |
---|
| 86 | [ ([[true; true; false; false; false; false; true; false]]) ; b1 ] |
---|
| 87 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 88 | | CPL addr ⇒ |
---|
| 89 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;carry;bit_addr]] x) → ? with |
---|
| 90 | [ ACC_A ⇒ λ_. |
---|
| 91 | [ ([[true; true; true; true; false; true; false; false]]) ] |
---|
| 92 | | CARRY ⇒ λ_. |
---|
| 93 | [ ([[true; false; true; true; false; false; true; true]]) ] |
---|
| 94 | | BIT_ADDR b1 ⇒ λ_. |
---|
| 95 | [ ([[true; false; true; true; false; false; true; false]]) ; b1 ] |
---|
| 96 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 97 | | DA addr ⇒ |
---|
| 98 | [ ([[true; true; false; true; false; true; false; false]]) ] |
---|
| 99 | | DEC addr ⇒ |
---|
| 100 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;registr;direct;indirect]] x) → ? with |
---|
| 101 | [ ACC_A ⇒ λ_. |
---|
| 102 | [ ([[false; false; false; true; false; true; false; false]]) ] |
---|
| 103 | | REGISTER r ⇒ λ_. |
---|
| 104 | [ ([[false; false; false; true; true]]) @@ r ] |
---|
| 105 | | DIRECT b1 ⇒ λ_. |
---|
| 106 | [ ([[false; false; false; true; false; true; false; true]]); b1 ] |
---|
| 107 | | INDIRECT i1 ⇒ λ_. |
---|
| 108 | [ ([[false; false; false; true; false; true; true; i1]]) ] |
---|
| 109 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 110 | | DJNZ addr1 addr2 ⇒ |
---|
| 111 | let b2 ≝ addr_of addr2 in |
---|
| 112 | match addr1 return λx. bool_to_Prop (is_in ? [[registr;direct]] x) → ? with |
---|
| 113 | [ REGISTER r ⇒ λ_. |
---|
| 114 | [ ([[true; true; false; true; true]]) @@ r ; b2 ] |
---|
| 115 | | DIRECT b1 ⇒ λ_. |
---|
| 116 | [ ([[true; true; false; true; false; true; false; true]]); b1; b2 ] |
---|
| 117 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 118 | | JC addr ⇒ |
---|
| 119 | let b1 ≝ addr_of addr in |
---|
| 120 | [ ([[false; true; false; false; false; false; false; false]]); b1 ] |
---|
| 121 | | JNC addr ⇒ |
---|
| 122 | let b1 ≝ addr_of addr in |
---|
| 123 | [ ([[false; true; false; true; false; false; false; false]]); b1 ] |
---|
| 124 | | JZ addr ⇒ |
---|
| 125 | let b1 ≝ addr_of addr in |
---|
| 126 | [ ([[false; true; true; false; false; false; false; false]]); b1 ] |
---|
| 127 | | JNZ addr ⇒ |
---|
| 128 | let b1 ≝ addr_of addr in |
---|
| 129 | [ ([[false; true; true; true; false; false; false; false]]); b1 ] |
---|
| 130 | | JB addr1 addr2 ⇒ |
---|
| 131 | let b2 ≝ addr_of addr2 in |
---|
| 132 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 133 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 134 | [ ([[false; false; true; false; false; false; false; false]]); b1; b2 ] |
---|
| 135 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 136 | | JNB addr1 addr2 ⇒ |
---|
| 137 | let b2 ≝ addr_of addr2 in |
---|
| 138 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 139 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 140 | [ ([[false; false; true; true; false; false; false; false]]); b1; b2 ] |
---|
| 141 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 142 | | JBC addr1 addr2 ⇒ |
---|
| 143 | let b2 ≝ addr_of addr2 in |
---|
| 144 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 145 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 146 | [ ([[false; false; false; true; false; false; false; false]]); b1; b2 ] |
---|
| 147 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 148 | | CJNE addrs addr3 ⇒ |
---|
| 149 | let b3 ≝ addr_of addr3 in |
---|
| 150 | match addrs with |
---|
| 151 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 152 | match addr2 return λx. bool_to_Prop (is_in ? [[direct;data]] x) → ? with |
---|
| 153 | [ DIRECT b1 ⇒ λ_. |
---|
| 154 | [ ([[true; false; true; true; false; true; false; true]]); b1; b3 ] |
---|
| 155 | | DATA b1 ⇒ λ_. |
---|
| 156 | [ ([[true; false; true; true; false; true; false; false]]); b1; b3 ] |
---|
| 157 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 158 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 159 | let b2 ≝ |
---|
| 160 | match addr2 return λx. bool_to_Prop (is_in ? [[data]] x) → ? with |
---|
| 161 | [ DATA b2 ⇒ λ_. b2 |
---|
| 162 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) in |
---|
| 163 | match addr1 return λx. bool_to_Prop (is_in ? [[registr;indirect]] x) → list Byte with |
---|
| 164 | [ REGISTER r ⇒ λ_. |
---|
| 165 | [ ([[true; false; true; true; true]]) @@ r; b2; b3 ] |
---|
| 166 | | INDIRECT i1 ⇒ λ_. |
---|
| 167 | [ ([[true; false; true; true; false; true; true; i1]]); b2; b3 ] |
---|
| 168 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 169 | ] |
---|
| 170 | | DIV addr1 addr2 ⇒ |
---|
| 171 | [ ([[true;false;false;false;false;true;false;false]]) ] |
---|
| 172 | | INC addr ⇒ |
---|
| 173 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;registr;direct;indirect;dptr]] x) → ? with |
---|
| 174 | [ ACC_A ⇒ λ_. |
---|
| 175 | [ ([[false;false;false;false;false;true;false;false]]) ] |
---|
| 176 | | REGISTER r ⇒ λ_. |
---|
| 177 | [ ([[false;false;false;false;true]]) @@ r ] |
---|
| 178 | | DIRECT b1 ⇒ λ_. |
---|
| 179 | [ ([[false; false; false; false; false; true; false; true]]); b1 ] |
---|
| 180 | | INDIRECT i1 ⇒ λ_. |
---|
| 181 | [ ([[false; false; false; false; false; true; true; i1]]) ] |
---|
| 182 | | DPTR ⇒ λ_. |
---|
| 183 | [ ([[true;false;true;false;false;false;true;true]]) ] |
---|
| 184 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 185 | | MOV addrs ⇒ |
---|
| 186 | match addrs with |
---|
| 187 | [ inl addrs ⇒ |
---|
| 188 | match addrs with |
---|
| 189 | [ inl addrs ⇒ |
---|
| 190 | match addrs with |
---|
| 191 | [ inl addrs ⇒ |
---|
| 192 | match addrs with |
---|
| 193 | [ inl addrs ⇒ |
---|
| 194 | match addrs with |
---|
| 195 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 196 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 197 | [ REGISTER r ⇒ λ_.[ ([[true;true;true;false;true]]) @@ r ] |
---|
| 198 | | DIRECT b1 ⇒ λ_.[ ([[true;true;true;false;false;true;false;true]]); b1 ] |
---|
| 199 | | INDIRECT i1 ⇒ λ_. [ ([[true;true;true;false;false;true;true;i1]]) ] |
---|
| 200 | | DATA b1 ⇒ λ_. [ ([[false;true;true;true;false;true;false;false]]) ; b1 ] |
---|
| 201 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 202 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 203 | match addr1 return λx. bool_to_Prop (is_in ? [[registr;indirect]] x) → ? with |
---|
| 204 | [ REGISTER r ⇒ λ_. |
---|
| 205 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;direct;data]] x) → ? with |
---|
| 206 | [ ACC_A ⇒ λ_.[ ([[true;true;true;true;true]]) @@ r ] |
---|
| 207 | | DIRECT b1 ⇒ λ_.[ ([[true;false;true;false;true]]) @@ r; b1 ] |
---|
| 208 | | DATA b1 ⇒ λ_. [ ([[false;true;true;true;true]]) @@ r; b1 ] |
---|
| 209 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 210 | | INDIRECT i1 ⇒ λ_. |
---|
| 211 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;direct;data]] x) → ? with |
---|
| 212 | [ ACC_A ⇒ λ_.[ ([[true;true;true;true;false;true;true;i1]]) ] |
---|
| 213 | | DIRECT b1 ⇒ λ_.[ ([[true;false;true;false;false;true;true;i1]]); b1 ] |
---|
| 214 | | DATA b1 ⇒ λ_. [ ([[false;true;true;true;false;true;true;i1]]) ; b1 ] |
---|
| 215 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 216 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1)] |
---|
| 217 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 218 | let b1 ≝ |
---|
| 219 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 220 | [ DIRECT b1 ⇒ λ_. b1 |
---|
| 221 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 222 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;registr;direct;indirect;data]] x) → ? with |
---|
| 223 | [ ACC_A ⇒ λ_.[ ([[true;true;true;true;false;true;false;true]]); b1] |
---|
| 224 | | REGISTER r ⇒ λ_.[ ([[true;false;false;false;true]]) @@ r; b1 ] |
---|
| 225 | | DIRECT b2 ⇒ λ_.[ ([[true;false;false;false;false;true;false;true]]); b1; b2 ] |
---|
| 226 | | INDIRECT i1 ⇒ λ_. [ ([[true;false;false;false;false;true;true;i1]]); b1 ] |
---|
| 227 | | DATA b2 ⇒ λ_. [ ([[false;true;true;true;false;true;false;true]]); b1; b2 ] |
---|
| 228 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 229 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 230 | match addr2 return λx. bool_to_Prop (is_in ? [[data16]] x) → ? with |
---|
| 231 | [ DATA16 w ⇒ λ_. |
---|
[2032] | 232 | let b1_b2 ≝ vsplit ? 8 8 w in |
---|
[1615] | 233 | let b1 ≝ \fst b1_b2 in |
---|
| 234 | let b2 ≝ \snd b1_b2 in |
---|
| 235 | [ ([[true;false;false;true;false;false;false;false]]); b1; b2] |
---|
| 236 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 237 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 238 | match addr2 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 239 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 240 | [ ([[true;false;true;false;false;false;true;false]]); b1 ] |
---|
| 241 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 242 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 243 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 244 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 245 | [ ([[true;false;false;true;false;false;true;false]]); b1 ] |
---|
| 246 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1)] |
---|
| 247 | | MOVX addrs ⇒ |
---|
| 248 | match addrs with |
---|
| 249 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 250 | match addr2 return λx. bool_to_Prop (is_in ? [[ext_indirect;ext_indirect_dptr]] x) → ? with |
---|
| 251 | [ EXT_INDIRECT i1 ⇒ λ_. |
---|
| 252 | [ ([[true;true;true;false;false;false;true;i1]]) ] |
---|
| 253 | | EXT_INDIRECT_DPTR ⇒ λ_. |
---|
| 254 | [ ([[true;true;true;false;false;false;false;false]]) ] |
---|
| 255 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 256 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 257 | match addr1 return λx. bool_to_Prop (is_in ? [[ext_indirect;ext_indirect_dptr]] x) → ? with |
---|
| 258 | [ EXT_INDIRECT i1 ⇒ λ_. |
---|
| 259 | [ ([[true;true;true;true;false;false;true;i1]]) ] |
---|
| 260 | | EXT_INDIRECT_DPTR ⇒ λ_. |
---|
| 261 | [ ([[true;true;true;true;false;false;false;false]]) ] |
---|
| 262 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1)] |
---|
| 263 | | MUL addr1 addr2 ⇒ |
---|
| 264 | [ ([[true;false;true;false;false;true;false;false]]) ] |
---|
| 265 | | NOP ⇒ |
---|
| 266 | [ ([[false;false;false;false;false;false;false;false]]) ] |
---|
| 267 | | ORL addrs ⇒ |
---|
| 268 | match addrs with |
---|
| 269 | [ inl addrs ⇒ |
---|
| 270 | match addrs with |
---|
| 271 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 272 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;data;direct;indirect]] x) → ? with |
---|
| 273 | [ REGISTER r ⇒ λ_.[ ([[false;true;false;false;true]]) @@ r ] |
---|
| 274 | | DIRECT b1 ⇒ λ_.[ ([[false;true;false;false;false;true;false;true]]); b1 ] |
---|
| 275 | | INDIRECT i1 ⇒ λ_. [ ([[false;true;false;false;false;true;true;i1]]) ] |
---|
| 276 | | DATA b1 ⇒ λ_. [ ([[false;true;false;false;false;true;false;false]]) ; b1 ] |
---|
| 277 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 278 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 279 | let b1 ≝ |
---|
| 280 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 281 | [ DIRECT b1 ⇒ λ_. b1 |
---|
| 282 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 283 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;data]] x) → ? with |
---|
| 284 | [ ACC_A ⇒ λ_. |
---|
| 285 | [ ([[false;true;false;false;false;false;true;false]]); b1 ] |
---|
| 286 | | DATA b2 ⇒ λ_. |
---|
| 287 | [ ([[false;true;false;false;false;false;true;true]]); b1; b2 ] |
---|
| 288 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 289 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 290 | match addr2 return λx. bool_to_Prop (is_in ? [[bit_addr;n_bit_addr]] x) → ? with |
---|
| 291 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 292 | [ ([[false;true;true;true;false;false;true;false]]); b1 ] |
---|
| 293 | | N_BIT_ADDR b1 ⇒ λ_. |
---|
| 294 | [ ([[true;false;true;false;false;false;false;false]]); b1 ] |
---|
| 295 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 296 | | POP addr ⇒ |
---|
| 297 | match addr return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 298 | [ DIRECT b1 ⇒ λ_. |
---|
| 299 | [ ([[true;true;false;true;false;false;false;false]]) ; b1 ] |
---|
| 300 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 301 | | PUSH addr ⇒ |
---|
| 302 | match addr return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 303 | [ DIRECT b1 ⇒ λ_. |
---|
| 304 | [ ([[true;true;false;false;false;false;false;false]]) ; b1 ] |
---|
| 305 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 306 | | RET ⇒ |
---|
| 307 | [ ([[false;false;true;false;false;false;true;false]]) ] |
---|
| 308 | | RETI ⇒ |
---|
| 309 | [ ([[false;false;true;true;false;false;true;false]]) ] |
---|
| 310 | | RL addr ⇒ |
---|
| 311 | [ ([[false;false;true;false;false;false;true;true]]) ] |
---|
| 312 | | RLC addr ⇒ |
---|
| 313 | [ ([[false;false;true;true;false;false;true;true]]) ] |
---|
| 314 | | RR addr ⇒ |
---|
| 315 | [ ([[false;false;false;false;false;false;true;true]]) ] |
---|
| 316 | | RRC addr ⇒ |
---|
| 317 | [ ([[false;false;false;true;false;false;true;true]]) ] |
---|
| 318 | | SETB addr ⇒ |
---|
| 319 | match addr return λx. bool_to_Prop (is_in ? [[carry;bit_addr]] x) → ? with |
---|
| 320 | [ CARRY ⇒ λ_. |
---|
| 321 | [ ([[true;true;false;true;false;false;true;true]]) ] |
---|
| 322 | | BIT_ADDR b1 ⇒ λ_. |
---|
| 323 | [ ([[true;true;false;true;false;false;true;false]]); b1 ] |
---|
| 324 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 325 | | SUBB addr1 addr2 ⇒ |
---|
| 326 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 327 | [ REGISTER r ⇒ λ_. |
---|
| 328 | [ ([[true;false;false;true;true]]) @@ r ] |
---|
| 329 | | DIRECT b1 ⇒ λ_. |
---|
| 330 | [ ([[true;false;false;true;false;true;false;true]]); b1] |
---|
| 331 | | INDIRECT i1 ⇒ λ_. |
---|
| 332 | [ ([[true;false;false;true;false;true;true;i1]]) ] |
---|
| 333 | | DATA b1 ⇒ λ_. |
---|
| 334 | [ ([[true;false;false;true;false;true;false;false]]); b1] |
---|
| 335 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 336 | | SWAP addr ⇒ |
---|
| 337 | [ ([[true;true;false;false;false;true;false;false]]) ] |
---|
| 338 | | XCH addr1 addr2 ⇒ |
---|
| 339 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect]] x) → ? with |
---|
| 340 | [ REGISTER r ⇒ λ_. |
---|
| 341 | [ ([[true;true;false;false;true]]) @@ r ] |
---|
| 342 | | DIRECT b1 ⇒ λ_. |
---|
| 343 | [ ([[true;true;false;false;false;true;false;true]]); b1] |
---|
| 344 | | INDIRECT i1 ⇒ λ_. |
---|
| 345 | [ ([[true;true;false;false;false;true;true;i1]]) ] |
---|
| 346 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 347 | | XCHD addr1 addr2 ⇒ |
---|
| 348 | match addr2 return λx. bool_to_Prop (is_in ? [[indirect]] x) → ? with |
---|
| 349 | [ INDIRECT i1 ⇒ λ_. |
---|
| 350 | [ ([[true;true;false;true;false;true;true;i1]]) ] |
---|
| 351 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 352 | | XRL addrs ⇒ |
---|
| 353 | match addrs with |
---|
| 354 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 355 | match addr2 return λx. bool_to_Prop (is_in ? [[data;registr;direct;indirect]] x) → ? with |
---|
| 356 | [ REGISTER r ⇒ λ_. |
---|
| 357 | [ ([[false;true;true;false;true]]) @@ r ] |
---|
| 358 | | DIRECT b1 ⇒ λ_. |
---|
| 359 | [ ([[false;true;true;false;false;true;false;true]]); b1] |
---|
| 360 | | INDIRECT i1 ⇒ λ_. |
---|
| 361 | [ ([[false;true;true;false;false;true;true;i1]]) ] |
---|
| 362 | | DATA b1 ⇒ λ_. |
---|
| 363 | [ ([[false;true;true;false;false;true;false;false]]); b1] |
---|
| 364 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 365 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 366 | let b1 ≝ |
---|
| 367 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 368 | [ DIRECT b1 ⇒ λ_. b1 |
---|
| 369 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 370 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;data]] x) → ? with |
---|
| 371 | [ ACC_A ⇒ λ_. |
---|
| 372 | [ ([[false;true;true;false;false;false;true;false]]); b1 ] |
---|
| 373 | | DATA b2 ⇒ λ_. |
---|
| 374 | [ ([[false;true;true;false;false;false;true;true]]); b1; b2 ] |
---|
| 375 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 376 | ]. |
---|
| 377 | |
---|
| 378 | definition assembly1 ≝ |
---|
| 379 | λi: instruction. |
---|
| 380 | match i with |
---|
| 381 | [ ACALL addr ⇒ |
---|
| 382 | match addr return λx. bool_to_Prop (is_in ? [[addr11]] x) → ? with |
---|
| 383 | [ ADDR11 w ⇒ λ_. |
---|
[2032] | 384 | let v1_v2 ≝ vsplit ? 3 8 w in |
---|
[1615] | 385 | let v1 ≝ \fst v1_v2 in |
---|
| 386 | let v2 ≝ \snd v1_v2 in |
---|
| 387 | [ (v1 @@ [[true; false; false; false; true]]) ; v2 ] |
---|
| 388 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 389 | | AJMP addr ⇒ |
---|
| 390 | match addr return λx. bool_to_Prop (is_in ? [[addr11]] x) → ? with |
---|
| 391 | [ ADDR11 w ⇒ λ_. |
---|
[2032] | 392 | let v1_v2 ≝ vsplit ? 3 8 w in |
---|
[1615] | 393 | let v1 ≝ \fst v1_v2 in |
---|
| 394 | let v2 ≝ \snd v1_v2 in |
---|
| 395 | [ (v1 @@ [[false; false; false; false; true]]) ; v2 ] |
---|
| 396 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 397 | | JMP adptr ⇒ |
---|
| 398 | [ ([[false;true;true;true;false;false;true;true]]) ] |
---|
| 399 | | LCALL addr ⇒ |
---|
| 400 | match addr return λx. bool_to_Prop (is_in ? [[addr16]] x) → ? with |
---|
| 401 | [ ADDR16 w ⇒ λ_. |
---|
[2032] | 402 | let b1_b2 ≝ vsplit ? 8 8 w in |
---|
[1615] | 403 | let b1 ≝ \fst b1_b2 in |
---|
| 404 | let b2 ≝ \snd b1_b2 in |
---|
| 405 | [ ([[false;false;false;true;false;false;true;false]]); b1; b2 ] |
---|
| 406 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 407 | | LJMP addr ⇒ |
---|
| 408 | match addr return λx. bool_to_Prop (is_in ? [[addr16]] x) → ? with |
---|
| 409 | [ ADDR16 w ⇒ λ_. |
---|
[2032] | 410 | let b1_b2 ≝ vsplit ? 8 8 w in |
---|
[1615] | 411 | let b1 ≝ \fst b1_b2 in |
---|
| 412 | let b2 ≝ \snd b1_b2 in |
---|
| 413 | [ ([[false;false;false;false;false;false;true;false]]); b1; b2 ] |
---|
| 414 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 415 | | MOVC addr1 addr2 ⇒ |
---|
| 416 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_dptr;acc_pc]] x) → ? with |
---|
| 417 | [ ACC_DPTR ⇒ λ_. |
---|
| 418 | [ ([[true;false;false;true;false;false;true;true]]) ] |
---|
| 419 | | ACC_PC ⇒ λ_. |
---|
| 420 | [ ([[true;false;false;false;false;false;true;true]]) ] |
---|
| 421 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 422 | | SJMP addr ⇒ |
---|
| 423 | match addr return λx. bool_to_Prop (is_in ? [[relative]] x) → ? with |
---|
| 424 | [ RELATIVE b1 ⇒ λ_. |
---|
| 425 | [ ([[true;false;false;false;false;false;false;false]]); b1 ] |
---|
| 426 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 427 | | RealInstruction instr ⇒ |
---|
| 428 | assembly_preinstruction [[ relative ]] |
---|
| 429 | (λx. |
---|
| 430 | match x return λs. bool_to_Prop (is_in ? [[ relative ]] s) → ? with |
---|
| 431 | [ RELATIVE r ⇒ λ_. r |
---|
| 432 | | _ ⇒ λabsd. ⊥ |
---|
| 433 | ] (subaddressing_modein … x)) instr |
---|
| 434 | ]. |
---|
| 435 | cases absd |
---|
[1592] | 436 | qed. |
---|
| 437 | |
---|
[2015] | 438 | (* XXX: pc_plus_sjmp_length used to be just sigma of ppc. This is incorrect |
---|
| 439 | as relative lengths are computed from the *end* of the SJMP, not from |
---|
[2022] | 440 | the beginning. |
---|
[2015] | 441 | *) |
---|
[1905] | 442 | definition expand_relative_jump_internal: |
---|
[1948] | 443 | ∀lookup_labels:Identifier → Word.∀sigma:Word → Word. |
---|
[1905] | 444 | Identifier → Word → ([[relative]] → preinstruction [[relative]]) → |
---|
| 445 | list instruction |
---|
[1615] | 446 | ≝ |
---|
[1934] | 447 | λlookup_labels.λsigma.λlbl.λppc,i. |
---|
[1948] | 448 | let lookup_address ≝ sigma (lookup_labels lbl) in |
---|
[2022] | 449 | let pc_plus_jmp_length ≝ sigma (add … ppc (bitvector_of_nat … 1)) in |
---|
[2048] | 450 | let 〈sj_possible, disp〉 ≝ short_jump_cond pc_plus_jmp_length lookup_address in |
---|
| 451 | if sj_possible |
---|
| 452 | then |
---|
| 453 | let address ≝ RELATIVE disp in |
---|
[1905] | 454 | [ RealInstruction (i address) ] |
---|
| 455 | else |
---|
[1615] | 456 | [ RealInstruction (i (RELATIVE (bitvector_of_nat ? 2))); |
---|
| 457 | SJMP (RELATIVE (bitvector_of_nat ? 3)); (* LJMP size? *) |
---|
[1649] | 458 | LJMP (ADDR16 lookup_address) |
---|
[1905] | 459 | ]. |
---|
[1948] | 460 | % |
---|
[1615] | 461 | qed. |
---|
| 462 | |
---|
[1905] | 463 | definition expand_relative_jump: |
---|
| 464 | ∀lookup_labels.∀sigma. |
---|
| 465 | Word → (*jump_length →*) |
---|
| 466 | preinstruction Identifier → list instruction ≝ |
---|
| 467 | λlookup_labels: Identifier → Word. |
---|
[1948] | 468 | λsigma:Word → Word. |
---|
[1934] | 469 | λppc: Word. |
---|
[1905] | 470 | (*λjmp_len: jump_length.*) |
---|
[1615] | 471 | λi: preinstruction Identifier. |
---|
[1934] | 472 | (*let rel_jmp ≝ RELATIVE (bitvector_of_nat ? 2) in*) |
---|
[1615] | 473 | match i with |
---|
[1934] | 474 | [ JC jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JC ?) |
---|
| 475 | | JNC jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JNC ?) |
---|
| 476 | | JB baddr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JB ? baddr) |
---|
| 477 | | JZ jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JZ ?) |
---|
| 478 | | JNZ jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JNZ ?) |
---|
| 479 | | JBC baddr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JBC ? baddr) |
---|
| 480 | | JNB baddr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JNB ? baddr) |
---|
| 481 | | CJNE addr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (CJNE ? addr) |
---|
| 482 | | DJNZ addr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (DJNZ ? addr) |
---|
[1905] | 483 | | ADD arg1 arg2 ⇒ [ ADD ? arg1 arg2 ] |
---|
| 484 | | ADDC arg1 arg2 ⇒ [ ADDC ? arg1 arg2 ] |
---|
| 485 | | SUBB arg1 arg2 ⇒ [ SUBB ? arg1 arg2 ] |
---|
| 486 | | INC arg ⇒ [ INC ? arg ] |
---|
| 487 | | DEC arg ⇒ [ DEC ? arg ] |
---|
| 488 | | MUL arg1 arg2 ⇒ [ MUL ? arg1 arg2 ] |
---|
| 489 | | DIV arg1 arg2 ⇒ [ DIV ? arg1 arg2 ] |
---|
| 490 | | DA arg ⇒ [ DA ? arg ] |
---|
| 491 | | ANL arg ⇒ [ ANL ? arg ] |
---|
| 492 | | ORL arg ⇒ [ ORL ? arg ] |
---|
| 493 | | XRL arg ⇒ [ XRL ? arg ] |
---|
| 494 | | CLR arg ⇒ [ CLR ? arg ] |
---|
| 495 | | CPL arg ⇒ [ CPL ? arg ] |
---|
| 496 | | RL arg ⇒ [ RL ? arg ] |
---|
| 497 | | RR arg ⇒ [ RR ? arg ] |
---|
| 498 | | RLC arg ⇒ [ RLC ? arg ] |
---|
| 499 | | RRC arg ⇒ [ RRC ? arg ] |
---|
| 500 | | SWAP arg ⇒ [ SWAP ? arg ] |
---|
| 501 | | MOV arg ⇒ [ MOV ? arg ] |
---|
| 502 | | MOVX arg ⇒ [ MOVX ? arg ] |
---|
| 503 | | SETB arg ⇒ [ SETB ? arg ] |
---|
| 504 | | PUSH arg ⇒ [ PUSH ? arg ] |
---|
| 505 | | POP arg ⇒ [ POP ? arg ] |
---|
| 506 | | XCH arg1 arg2 ⇒ [ XCH ? arg1 arg2 ] |
---|
| 507 | | XCHD arg1 arg2 ⇒ [ XCHD ? arg1 arg2 ] |
---|
| 508 | | RET ⇒ [ RET ? ] |
---|
| 509 | | RETI ⇒ [ RETI ? ] |
---|
| 510 | | NOP ⇒ [ RealInstruction (NOP ?) ] |
---|
[1615] | 511 | ]. |
---|
| 512 | |
---|
[1905] | 513 | definition expand_pseudo_instruction: |
---|
[1948] | 514 | ∀lookup_labels. |
---|
| 515 | ∀sigma: Word → Word. |
---|
| 516 | ∀policy: Word → bool. |
---|
| 517 | Word → ? → pseudo_instruction → list instruction ≝ |
---|
| 518 | λlookup_labels: Identifier → Word. |
---|
| 519 | λsigma: Word → Word. |
---|
| 520 | λpolicy: Word → bool. |
---|
[1934] | 521 | λppc. |
---|
[1905] | 522 | λlookup_datalabels:Identifier → Word. |
---|
[1615] | 523 | λi. |
---|
| 524 | match i with |
---|
[1905] | 525 | [ Cost cost ⇒ [ ] |
---|
| 526 | | Comment comment ⇒ [ ] |
---|
[1615] | 527 | | Call call ⇒ |
---|
[2022] | 528 | let pc_plus_jmp_length ≝ sigma (add … ppc (bitvector_of_nat … 1)) in |
---|
[2048] | 529 | let lookup_address ≝ sigma (lookup_labels call) in |
---|
[2101] | 530 | let 〈mj_possible, disp〉 ≝ absolute_jump_cond pc_plus_jmp_length lookup_address in |
---|
[1948] | 531 | let do_a_long ≝ policy ppc in |
---|
[2048] | 532 | if mj_possible ∧ ¬ do_a_long then |
---|
| 533 | let address ≝ ADDR11 disp in |
---|
[1905] | 534 | [ ACALL address ] |
---|
| 535 | else |
---|
[2048] | 536 | let address ≝ ADDR16 lookup_address in |
---|
[1905] | 537 | [ LCALL address ] |
---|
[1615] | 538 | | Mov d trgt ⇒ |
---|
| 539 | let address ≝ DATA16 (lookup_datalabels trgt) in |
---|
[1905] | 540 | [ RealInstruction (MOV ? (inl ? ? (inl ? ? (inr ? ? 〈DPTR, address〉))))] |
---|
[1934] | 541 | | Instruction instr ⇒ expand_relative_jump lookup_labels sigma ppc instr |
---|
[1615] | 542 | | Jmp jmp ⇒ |
---|
[2022] | 543 | let pc_plus_jmp_length ≝ sigma (add … ppc (bitvector_of_nat … 1)) in |
---|
[1948] | 544 | let do_a_long ≝ policy ppc in |
---|
| 545 | let lookup_address ≝ sigma (lookup_labels jmp) in |
---|
[2048] | 546 | let 〈sj_possible, disp〉 ≝ short_jump_cond pc_plus_jmp_length lookup_address in |
---|
| 547 | if sj_possible ∧ ¬ do_a_long then |
---|
| 548 | let address ≝ RELATIVE disp in |
---|
[1905] | 549 | [ SJMP address ] |
---|
| 550 | else |
---|
[2101] | 551 | let 〈mj_possible, disp2〉 ≝ absolute_jump_cond pc_plus_jmp_length lookup_address in |
---|
[2048] | 552 | if mj_possible ∧ ¬ do_a_long then |
---|
| 553 | let address ≝ ADDR11 disp2 in |
---|
[1905] | 554 | [ AJMP address ] |
---|
| 555 | else |
---|
[1934] | 556 | let address ≝ ADDR16 lookup_address in |
---|
[1905] | 557 | [ LJMP address ] |
---|
[1615] | 558 | ]. |
---|
[1948] | 559 | % |
---|
[1615] | 560 | qed. |
---|
[1649] | 561 | |
---|
| 562 | definition assembly_1_pseudoinstruction ≝ |
---|
| 563 | λlookup_labels. |
---|
[1948] | 564 | λsigma: Word → Word. |
---|
| 565 | λpolicy: Word → bool. |
---|
[1934] | 566 | λppc: Word. |
---|
[832] | 567 | λlookup_datalabels. |
---|
| 568 | λi. |
---|
[1948] | 569 | let pseudos ≝ expand_pseudo_instruction lookup_labels sigma policy ppc lookup_datalabels i in |
---|
[1649] | 570 | let mapped ≝ map ? ? assembly1 pseudos in |
---|
| 571 | let flattened ≝ flatten ? mapped in |
---|
| 572 | let pc_len ≝ length ? flattened in |
---|
| 573 | 〈pc_len, flattened〉. |
---|
[1667] | 574 | |
---|
[1934] | 575 | definition instruction_size ≝ |
---|
[1948] | 576 | λlookup_labels. |
---|
| 577 | λsigma: Word → Word. |
---|
| 578 | λpolicy: Word → bool. |
---|
| 579 | λppc. |
---|
| 580 | λi. |
---|
| 581 | \fst (assembly_1_pseudoinstruction lookup_labels sigma policy ppc (λx.zero …) i). |
---|
[832] | 582 | |
---|
[2108] | 583 | |
---|
[1934] | 584 | (* label_map: identifier ↦ pseudo program counter *) |
---|
| 585 | definition label_map ≝ identifier_map ASMTag ℕ. |
---|
| 586 | |
---|
| 587 | (* Labels *) |
---|
| 588 | definition is_label ≝ |
---|
| 589 | λx:labelled_instruction.λl:Identifier. |
---|
| 590 | let 〈lbl,instr〉 ≝ x in |
---|
| 591 | match lbl with |
---|
| 592 | [ Some l' ⇒ l' = l |
---|
| 593 | | _ ⇒ False |
---|
| 594 | ]. |
---|
| 595 | |
---|
| 596 | lemma label_does_not_occur: |
---|
| 597 | ∀i:ℕ.∀p:list labelled_instruction.∀l:Identifier. |
---|
| 598 | is_label (nth i ? p 〈None ?, Comment [ ]〉) l → does_not_occur ?? l p = false. |
---|
| 599 | #i #p #l generalize in match i; elim p |
---|
| 600 | [ #i >nth_nil #H cases H |
---|
| 601 | | #h #t #IH #i cases i -i |
---|
| 602 | [ cases h #hi #hp cases hi |
---|
| 603 | [ normalize #H cases H |
---|
| 604 | | #l' #Heq whd in ⊢ (??%?); change with (eq_identifier ? l' l) in match (instruction_matches_identifier ????); |
---|
| 605 | whd in Heq; >Heq |
---|
| 606 | >eq_identifier_refl / by refl/ |
---|
| 607 | ] |
---|
| 608 | | #i #H whd in match (does_not_occur ????); |
---|
| 609 | whd in match (instruction_matches_identifier ????); |
---|
| 610 | cases h #hi #hp cases hi normalize nodelta |
---|
| 611 | [ @(IH i) @H |
---|
| 612 | | #l' @eq_identifier_elim |
---|
| 613 | [ normalize / by / |
---|
| 614 | | normalize #_ @(IH i) @H |
---|
| 615 | ] |
---|
| 616 | ] |
---|
| 617 | ] |
---|
| 618 | ] |
---|
[1556] | 619 | qed. |
---|
| 620 | |
---|
[1934] | 621 | (* The function that creates the label-to-address map *) |
---|
[1948] | 622 | definition create_label_cost_map0: ∀program:list labelled_instruction. |
---|
[1934] | 623 | (Σlabels_costs:label_map × (BitVectorTrie costlabel 16). (* Both on ppcs *) |
---|
| 624 | let 〈labels,costs〉 ≝ labels_costs in |
---|
| 625 | ∀l.occurs_exactly_once ?? l program → |
---|
[1943] | 626 | bitvector_of_nat ? (lookup_def ?? labels l 0) = |
---|
| 627 | address_of_word_labels_code_mem program l |
---|
[1934] | 628 | ) ≝ |
---|
| 629 | λprogram. |
---|
[2005] | 630 | \fst (pi1 ?? (foldl_strong (option Identifier × pseudo_instruction) |
---|
| 631 | (λprefix.Σlabels_costs_ppc:label_map × (BitVectorTrie costlabel 16) × ℕ. |
---|
[1934] | 632 | let 〈labels,costs,ppc〉 ≝ labels_costs_ppc in |
---|
| 633 | ppc = |prefix| ∧ |
---|
[1943] | 634 | ∀l.occurs_exactly_once ?? l prefix → |
---|
| 635 | bitvector_of_nat ? (lookup_def ?? labels l 0) = |
---|
[1948] | 636 | address_of_word_labels_code_mem prefix l) |
---|
[1934] | 637 | program |
---|
| 638 | (λprefix.λx.λtl.λprf.λlabels_costs_ppc. |
---|
[2005] | 639 | let 〈labels,costs,ppc〉 ≝ pi1 ?? labels_costs_ppc in |
---|
[1934] | 640 | let 〈label,instr〉 ≝ x in |
---|
| 641 | let labels ≝ |
---|
| 642 | match label with |
---|
| 643 | [ None ⇒ labels |
---|
| 644 | | Some l ⇒ add … labels l ppc |
---|
| 645 | ] in |
---|
| 646 | let costs ≝ |
---|
| 647 | match instr with |
---|
| 648 | [ Cost cost ⇒ insert … (bitvector_of_nat ? ppc) cost costs |
---|
| 649 | | _ ⇒ costs ] in |
---|
| 650 | 〈labels,costs,S ppc〉 |
---|
[2005] | 651 | ) 〈(empty_map …),(Stub ??),0〉)). |
---|
| 652 | [ normalize nodelta lapply (pi2 … labels_costs_ppc) >p >p1 normalize nodelta * #IH1 #IH2 |
---|
[1934] | 653 | -labels_costs_ppc % [>IH1 >length_append <plus_n_Sm <plus_n_O %] |
---|
| 654 | inversion label [#EQ | #l #EQ] |
---|
[1943] | 655 | [ #lbl #Hocc <address_of_word_labels_code_mem_None [2: @Hocc] normalize nodelta |
---|
| 656 | >occurs_exactly_once_None in Hocc; @(IH2 lbl) |
---|
| 657 | | #lbl normalize nodelta inversion (eq_identifier ? lbl l) |
---|
| 658 | [ #Heq #Hocc >(eq_identifier_eq … Heq) |
---|
| 659 | >address_of_word_labels_code_mem_Some_hit |
---|
| 660 | [ >IH1 >lookup_def_add_hit % |
---|
| 661 | | <(eq_identifier_eq … Heq) in Hocc; // |
---|
| 662 | ] |
---|
| 663 | | #Hneq #Hocc |
---|
| 664 | <address_of_word_labels_code_mem_Some_miss |
---|
| 665 | [ >lookup_def_add_miss |
---|
| 666 | [ @IH2 >occurs_exactly_once_Some_eq in Hocc; >eq_identifier_sym> Hneq // |
---|
| 667 | | % @neq_identifier_neq @Hneq |
---|
| 668 | ] |
---|
| 669 | | @Hocc |
---|
| 670 | | >eq_identifier_sym @Hneq |
---|
| 671 | ] |
---|
| 672 | ] |
---|
| 673 | ] |
---|
[1934] | 674 | | @pair_elim * #labels #costs #ppc #EQ destruct normalize nodelta % try % |
---|
[1943] | 675 | #l #abs cases (abs) |
---|
[1934] | 676 | | cases (foldl_strong ? (λ_.Σx.?) ???) * * #labels #costs #ppc normalize nodelta * |
---|
| 677 | #_ #H @H |
---|
| 678 | ] |
---|
| 679 | qed. |
---|
[1668] | 680 | |
---|
[1948] | 681 | (* The function that creates the label-to-address map *) |
---|
| 682 | definition create_label_cost_map: ∀program:list labelled_instruction. |
---|
| 683 | label_map × (BitVectorTrie costlabel 16) ≝ |
---|
| 684 | λprogram. |
---|
| 685 | pi1 … (create_label_cost_map0 program). |
---|
| 686 | |
---|
[1942] | 687 | theorem create_label_cost_map_ok: |
---|
| 688 | ∀pseudo_program: pseudo_assembly_program. |
---|
| 689 | let 〈labels, costs〉 ≝ create_label_cost_map (\snd pseudo_program) in |
---|
[1885] | 690 | ∀id. occurs_exactly_once ?? id (\snd pseudo_program) → |
---|
[1942] | 691 | bitvector_of_nat ? (lookup_def ?? labels id 0) = address_of_word_labels_code_mem (\snd pseudo_program) id. |
---|
[1948] | 692 | #p change with (pi1 … (create_label_cost_map0 ?)) in match (create_label_cost_map ?); @pi2 |
---|
[1942] | 693 | qed. |
---|
[2021] | 694 | |
---|
[2078] | 695 | definition sigma_policy_specification ≝ |
---|
| 696 | λprogram: pseudo_assembly_program. |
---|
| 697 | λsigma: Word → Word. |
---|
| 698 | λpolicy: Word → bool. |
---|
[2079] | 699 | sigma (zero …) = zero … ∧ |
---|
[2144] | 700 | let instr_list ≝ \snd program in |
---|
| 701 | ∀ppc: Word. ∀ppc_ok: nat_of_bitvector … ppc < |instr_list|. |
---|
[2078] | 702 | let pc ≝ sigma ppc in |
---|
| 703 | let labels ≝ \fst (create_label_cost_map instr_list) in |
---|
| 704 | let lookup_labels ≝ λx. bitvector_of_nat 16 (lookup_def … labels x 0) in |
---|
| 705 | let instruction ≝ \fst (fetch_pseudo_instruction instr_list ppc ppc_ok) in |
---|
| 706 | let next_pc ≝ sigma (add 16 ppc (bitvector_of_nat 16 1)) in |
---|
[2144] | 707 | next_pc = add 16 pc (bitvector_of_nat … (instruction_size lookup_labels sigma policy ppc instruction)) |
---|
| 708 | ∧ |
---|
[2148] | 709 | (nat_of_bitvector … pc + instruction_size lookup_labels sigma policy ppc instruction < 2^16 |
---|
[2151] | 710 | ∨ |
---|
| 711 | S (nat_of_bitvector … ppc) = |instr_list| ∧ |
---|
| 712 | nat_of_bitvector … pc + instruction_size lookup_labels sigma policy ppc instruction = 2^16). |
---|
[2078] | 713 | |
---|
[2151] | 714 | |
---|
| 715 | lemma fst_assembly_1_pseudoinstruction_insensible_to_lookup_datalabels: |
---|
| 716 | ∀lookup_labels,sigma,policy,ppc,pi. |
---|
| 717 | ∀lookup_datalabels1,lookup_datalabels2. |
---|
| 718 | \fst (assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels1 pi) = |
---|
| 719 | \fst (assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels2 pi). |
---|
| 720 | #lookup_labels #sigma #policy #ppc #pi #lookup_datalabels1 #lookup_datalabels2 |
---|
| 721 | cases pi // |
---|
| 722 | qed. |
---|
| 723 | |
---|
| 724 | lemma fst_snd_assembly_1_pseudoinstruction: |
---|
| 725 | ∀lookup_labels,sigma,policy,ppc,pi,lookup_datalabels,len,assembled. |
---|
| 726 | assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels pi |
---|
| 727 | = 〈len,assembled〉 → |
---|
| 728 | len = |assembled|. |
---|
| 729 | #lookup #sigma #policy #ppc #pi #lookup_datalabels #len #assembled |
---|
| 730 | inversion (assembly_1_pseudoinstruction ??????) #len' #assembled' |
---|
| 731 | whd in ⊢ (??%? → ?); #EQ1 #EQ2 destruct % |
---|
| 732 | qed. |
---|
| 733 | |
---|
[993] | 734 | definition assembly: |
---|
[1948] | 735 | ∀p: pseudo_assembly_program. |
---|
| 736 | ∀sigma: Word → Word. |
---|
| 737 | ∀policy: Word → bool. |
---|
[2021] | 738 | Σres:list Byte × (BitVectorTrie costlabel 16). |
---|
[2081] | 739 | sigma_policy_specification p sigma policy → |
---|
[2021] | 740 | let 〈preamble,instr_list〉 ≝ p in |
---|
[2110] | 741 | |instr_list| ≤ 2^16 → |
---|
[2021] | 742 | let 〈assembled,costs〉 ≝ res in |
---|
[2110] | 743 | |assembled| ≤ 2^16 ∧ |
---|
[2146] | 744 | (nat_of_bitvector … (sigma (bitvector_of_nat … (|instr_list|))) = |assembled| ∨ |
---|
| 745 | sigma (bitvector_of_nat … (|instr_list|)) = zero … ∧ |assembled| = 2^16) ∧ |
---|
[2021] | 746 | let 〈labels_to_ppc,ppc_to_costs〉 ≝ create_label_cost_map instr_list in |
---|
| 747 | let datalabels ≝ construct_datalabels preamble in |
---|
[2110] | 748 | let lookup_labels ≝ λx. bitvector_of_nat ? (lookup_def … labels_to_ppc x 0) in |
---|
[2021] | 749 | let lookup_datalabels ≝ λx. lookup_def … datalabels x (zero ?) in |
---|
[2055] | 750 | ∀ppc. ∀ppc_ok:nat_of_bitvector … ppc < |instr_list|. |
---|
| 751 | let 〈pi,newppc〉 ≝ fetch_pseudo_instruction instr_list ppc ppc_ok in |
---|
[2021] | 752 | let 〈len,assembledi〉 ≝ |
---|
| 753 | assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels pi in |
---|
[2147] | 754 | |assembledi| ≤ |assembled| ∧ |
---|
[2021] | 755 | ∀j:nat. ∀H: j < |assembledi|. ∀K. |
---|
| 756 | nth_safe ? j assembledi H = |
---|
| 757 | nth_safe ? (nat_of_bitvector … (add … (sigma ppc) (bitvector_of_nat ? j))) |
---|
| 758 | assembled K |
---|
[2151] | 759 | ≝ |
---|
[2081] | 760 | λp. |
---|
[1948] | 761 | λsigma. |
---|
| 762 | λpolicy. |
---|
[2021] | 763 | deplet 〈preamble, instr_list〉 as p_refl ≝ p in |
---|
[2151] | 764 | deplet 〈labels_to_ppc,ppc_to_costs〉 as eq_create_label_cost_map ≝ create_label_cost_map instr_list in |
---|
[1948] | 765 | let datalabels ≝ construct_datalabels preamble in |
---|
[2110] | 766 | let lookup_labels ≝ λx. bitvector_of_nat ? (lookup_def … labels_to_ppc x 0) in |
---|
[1948] | 767 | let lookup_datalabels ≝ λx. lookup_def … datalabels x (zero ?) in |
---|
[2138] | 768 | let 〈next_pc,revcode〉 ≝ pi1 … ( |
---|
[2021] | 769 | foldl_strong |
---|
[993] | 770 | (option Identifier × pseudo_instruction) |
---|
[2021] | 771 | (λpre. Σppc_code:(Word × (list Byte)). |
---|
[2081] | 772 | sigma_policy_specification 〈preamble,instr_list〉 sigma policy → |
---|
[2110] | 773 | |instr_list| ≤ 2^16 → |
---|
[993] | 774 | let 〈ppc,code〉 ≝ ppc_code in |
---|
[2021] | 775 | ppc = bitvector_of_nat … (|pre|) ∧ |
---|
[2151] | 776 | |code| ≤ 2^16 ∧ |
---|
[2156] | 777 | (|code| = 2^16 → |pre| = |instr_list|) ∧ |
---|
[2146] | 778 | (nat_of_bitvector … (sigma ppc) = |code| ∨ |
---|
| 779 | sigma ppc = zero … ∧ |code| = 2^16) ∧ |
---|
[2055] | 780 | ∀ppc'.∀ppc_ok'. |
---|
[2110] | 781 | (nat_of_bitvector … ppc' < nat_of_bitvector … ppc ∨ |pre| = 2^16) → |
---|
[2055] | 782 | let 〈pi,newppc〉 ≝ fetch_pseudo_instruction instr_list ppc' ppc_ok' in |
---|
[2021] | 783 | let 〈len,assembledi〉 ≝ |
---|
| 784 | assembly_1_pseudoinstruction lookup_labels sigma policy ppc' lookup_datalabels pi in |
---|
[2151] | 785 | |assembledi| ≤ |reverse … code| ∧ |
---|
[2021] | 786 | ∀j:nat. ∀H: j < |assembledi|. ∀K. |
---|
| 787 | nth_safe ? j assembledi H = |
---|
| 788 | nth_safe ? (nat_of_bitvector … (add … (sigma ppc') (bitvector_of_nat ? j))) (reverse … code) K) |
---|
[993] | 789 | instr_list |
---|
[2021] | 790 | (λprefix,hd,tl,prf,ppc_code. |
---|
| 791 | let 〈ppc, code〉 ≝ pi1 … ppc_code in |
---|
[1948] | 792 | let 〈pc_delta, program〉 ≝ assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels (\snd hd) in |
---|
[1946] | 793 | let new_ppc ≝ add ? ppc (bitvector_of_nat ? 1) in |
---|
[2021] | 794 | 〈new_ppc, (reverse … program @ code)〉) |
---|
| 795 | 〈(zero ?), [ ]〉) |
---|
[985] | 796 | in |
---|
[2021] | 797 | 〈reverse … revcode, |
---|
[1948] | 798 | fold … (λppc.λcost.λpc_to_costs. insert … (sigma ppc) cost pc_to_costs) ppc_to_costs (Stub ??)〉. |
---|
[2151] | 799 | [ cases (foldl_strong ? (λx.Σy.?) ???) in p1; #ignore_revcode #Hfold #EQignore_revcode |
---|
[2081] | 800 | >EQignore_revcode in Hfold; #Hfold #sigma_pol_ok #instr_list_ok |
---|
[2156] | 801 | cases (Hfold sigma_pol_ok instr_list_ok) -Hfold * * * #Hfold1 #Hfold4 #Hfold5 #Hfold3 #Hfold2 whd |
---|
[2151] | 802 | <eq_create_label_cost_map whd % |
---|
[2110] | 803 | [2: #ppc #LTppc @Hfold2 >Hfold1 @(eqb_elim (|instr_list|) 2^16) |
---|
| 804 | [ #limit %2 @limit |
---|
| 805 | | #nlimit %1 >nat_of_bitvector_bitvector_of_nat_inverse try assumption |
---|
| 806 | @not_eq_to_le_to_lt assumption ] |
---|
[2151] | 807 | | >length_reverse % try assumption cases Hfold3 -Hfold3 |
---|
| 808 | [ #Hfold3 <Hfold3 % >Hfold1 % |
---|
| 809 | | #Hfold5 %2 <Hfold1 assumption ]] |
---|
[2081] | 810 | | * #sigma_pol_ok1 #_ #instr_list_ok % |
---|
[2156] | 811 | [ % % [%] // [#abs change with (0=S ?) in abs; destruct(abs) | >sigma_pol_ok1 % ]] |
---|
[2110] | 812 | #ppc' #ppc_ok' #abs @⊥ cases abs |
---|
| 813 | [#abs2 cases (not_le_Sn_O ?) [#H @(H abs2) | skip] |
---|
| 814 | |#abs2 change with (0 = S ?) in abs2; destruct(abs2) ] |
---|
[2081] | 815 | | * #sigma_pol_ok1 #sigma_pol_ok2 #instr_list_ok cases ppc_code in p1; -ppc_code #ppc_code #IH #EQppc_code >EQppc_code in IH; -EQppc_code |
---|
[2151] | 816 | #IH cases (IH ? instr_list_ok) [2: % assumption ] -IH |
---|
[2156] | 817 | * * * #IH1 #IH2 #IH4 * |
---|
| 818 | [2: * #_ #H @⊥ lapply (IH4 H) >prf >length_append |
---|
| 819 | >(plus_n_O (|prefix|)) in ⊢ (??%? → ?); #X |
---|
| 820 | lapply (injective_plus_r … X) >length_append normalize #abs' destruct(abs')] |
---|
[2151] | 821 | #IH3 #IH5 |
---|
| 822 | cut (|prefix| < |instr_list|) |
---|
| 823 | [ >prf >length_append normalize <plus_n_Sm @le_S_S // ] #LT_prefix_instr_list |
---|
| 824 | cut (|prefix| < 2^16) |
---|
| 825 | [ @(lt_to_le_to_lt … (|instr_list|)) assumption ] #prefix_ok |
---|
| 826 | cut (nat_of_bitvector … ppc < |instr_list|) |
---|
| 827 | [ >IH1 >nat_of_bitvector_bitvector_of_nat_inverse assumption ] #ppc_ok |
---|
| 828 | cut (\snd hd = \fst (fetch_pseudo_instruction instr_list ppc ppc_ok)) |
---|
| 829 | [ >prf in ppc_ok; >IH1 >(add_zero … (bitvector_of_nat … (|prefix|))) |
---|
| 830 | >fetch_pseudo_instruction_append |
---|
| 831 | [ #ppc_ok whd in match fetch_pseudo_instruction; normalize nodelta |
---|
| 832 | whd in match (nth_safe ????); [ cases hd // | normalize // ] |
---|
| 833 | | <add_zero >nat_of_bitvector_bitvector_of_nat_inverse |
---|
| 834 | [ <prf assumption | assumption ] |
---|
| 835 | | skip |
---|
| 836 | | <prf assumption |
---|
| 837 | ]] #eq_fetch_pseudo_instruction |
---|
| 838 | lapply (fst_snd_assembly_1_pseudoinstruction … p2) #EQpc_delta |
---|
| 839 | cut (pc_delta < 2^16) |
---|
[2156] | 840 | [cases daemon (*CSC: DA FARE*) ] #pc_delta_ok check fst_eq |
---|
| 841 | cut (pc_delta = instruction_size lookup_labels sigma policy ppc (\snd hd)) |
---|
| 842 | [ whd in match instruction_size; normalize nodelta |
---|
| 843 | >fst_assembly_1_pseudoinstruction_insensible_to_lookup_datalabels [ >p2 | skip] % ] |
---|
| 844 | #EQpc_delta2 |
---|
| 845 | % [ % [% [% ] ] ] |
---|
[2151] | 846 | [ >length_append normalize nodelta >IH1 @sym_eq @add_bitvector_of_nat |
---|
| 847 | | >length_append >length_reverse <IH3 cases daemon (*CSC: maybe, using monotonicity*) |
---|
[2156] | 848 | | lapply (sigma_pol_ok2 … ppc_ok) * #sigma_pol_ok3 |
---|
| 849 | <eq_fetch_pseudo_instruction <eq_create_label_cost_map #sigma_pol4 |
---|
| 850 | >length_append >commutative_plus >length_reverse <IH3 <EQpc_delta >EQpc_delta2 |
---|
| 851 | #abs >abs in sigma_pol4; * |
---|
| 852 | [ #abs' cases (absurd ? abs' (not_le_Sn_n …)) |
---|
| 853 | | * #abs' #_ <abs' >length_append <plus_n_Sm <plus_n_O @eq_f >IH1 |
---|
| 854 | >nat_of_bitvector_bitvector_of_nat_inverse // ] |
---|
[2151] | 855 | | cases (sigma_pol_ok2 … ppc_ok) |
---|
| 856 | whd in match instruction_size; normalize nodelta >p2 <eq_fetch_pseudo_instruction |
---|
| 857 | <eq_create_label_cost_map |
---|
| 858 | >fst_assembly_1_pseudoinstruction_insensible_to_lookup_datalabels [ >p2 | skip] |
---|
| 859 | #sigma_ok >sigma_ok #sigma_pol_ok3 -sigma_pol_ok2 |
---|
| 860 | >length_append >length_reverse <IH3 <EQpc_delta cases sigma_pol_ok3 |
---|
| 861 | [ #LT %1 >nat_of_bitvector_add |
---|
| 862 | [2: >nat_of_bitvector_bitvector_of_nat_inverse assumption] |
---|
| 863 | >nat_of_bitvector_bitvector_of_nat_inverse try assumption // |
---|
| 864 | | * #EQ1 #EQ2 %2 % |
---|
| 865 | [ lapply (eq_f … (bitvector_of_nat 16) … EQ2) <add_bitvector_of_nat_plus |
---|
| 866 | >bitvector_of_nat_inverse_nat_of_bitvector #X >X @bitvector_of_nat_exp_zero |
---|
| 867 | | >commutative_plus assumption ]] |
---|
| 868 | | cases daemon |
---|
| 869 | ] |
---|
| 870 | |
---|
| 871 | (* |
---|
| 872 | |
---|
| 873 | % [% |
---|
[2072] | 874 | [ >length_append normalize nodelta >IH1 (*CSC: TRUE, LEMMA NEEDED *) cases daemon |
---|
| 875 | |2: (*CSC: NEES JAAP INVARIANT*) cases daemon]] |
---|
[2110] | 876 | #ppc' #LTppc' cases hd in prf p2; #label #pi #prf #p2 * |
---|
| 877 | cases daemon (* |
---|
| 878 | ?????????????? PRIMA NON C'ERA L'OR :-( |
---|
| 879 | MANTENERE LO SCHEMA DI PRIMA CON DUE CASI, MA IN UN CASO ppc=0 OVERFLOWED |
---|
| 880 | [2: #eq_S_prefix_bound -IH @(IH2 ? LTppc') |
---|
| 881 | @pair_elim #pi' #newppc' #eq_fetch_pseudo_instruction' |
---|
| 882 | @pair_elim |
---|
| 883 | | #LTppc_ppc |
---|
| 884 | cases (le_to_or_lt_eq … LTppc_ppc) |
---|
| 885 | [2: #S_S_eq normalize nodelta in S_S_eq; |
---|
| 886 | (*CSC: TRUE, NEEDS SOME WORK *) |
---|
| 887 | cut (ppc' = ppc) [ cases daemon] -S_S_eq #EQppc' >EQppc' in LTppc'; -ppc' >prf |
---|
| 888 | >IH1 (* in ⊢ match % with [_ ⇒ ?];*) #LTppc lapply LTppc |
---|
| 889 | >(add_zero … (bitvector_of_nat 16 (|prefix|))) in ⊢ (% → match % with [_ ⇒ ?]); |
---|
| 890 | >fetch_pseudo_instruction_append |
---|
| 891 | [3: @le_S_S @le_O_n |
---|
| 892 | |2: lapply LTppc; >(add_zero … (bitvector_of_nat 16 (|prefix|))) in ⊢ (% → ?); #H @H |
---|
| 893 | |4: <prf <p_refl in instr_list_ok; #H @H ] |
---|
| 894 | #LTppc' @pair_elim #pi' #newppc' #EQpair destruct(EQpair) <IH1 >p2 |
---|
| 895 | #j #LTj >nat_of_bitvector_add |
---|
| 896 | >nat_of_bitvector_bitvector_of_nat_inverse |
---|
| 897 | [2,4: (* CSC: TRUE, NEEDS LEMMA, MAYBE ALREADY PROVED *) cases daemon |
---|
| 898 | |3: (*CSC: TRUE, NEEDS LEMMA *) cases daemon ] |
---|
| 899 | >reverse_append >reverse_reverse >IH3 <(length_reverse … code) |
---|
| 900 | @nth_safe_prepend |
---|
| 901 | | #LTppc'' |
---|
| 902 | cut (nat_of_bitvector … ppc' < |instr_list|) |
---|
| 903 | [ normalize nodelta in LTppc''; |
---|
| 904 | @(transitive_le … (nat_of_bitvector … ppc)) |
---|
| 905 | [2: >IH1 >prf >length_append >nat_of_bitvector_bitvector_of_nat_inverse |
---|
| 906 | [ // |
---|
| 907 | | <p_refl in instr_list_ok; #instr_list_ok |
---|
| 908 | @(transitive_le … (S (|instr_list|))) try assumption >prf >length_append // ] |
---|
| 909 | | @le_S_S_to_le >nat_of_bitvector_add in LTppc''; |
---|
| 910 | [ >commutative_plus #H @H |
---|
| 911 | | >nat_of_bitvector_bitvector_of_nat_inverse [2: // ] >commutative_plus |
---|
| 912 | @(transitive_le … (|instr_list|)) |
---|
| 913 | [2: <p_refl in instr_list_ok; #instr_list_ok assumption |
---|
| 914 | | >IH1 >prf >length_append @le_S_S >(commutative_plus (|prefix|)) |
---|
| 915 | >length_append >nat_of_bitvector_bitvector_of_nat_inverse |
---|
| 916 | [2: <p_refl in instr_list_ok; >prf >length_append #H |
---|
| 917 | @(transitive_le … H) // |
---|
| 918 | | @le_S_S // ]]]]] |
---|
[2071] | 919 | #X lapply (IH2 ppc' X) |
---|
[2021] | 920 | @pair_elim #pi' #newppc' #eq_fetch_pseudoinstruction |
---|
| 921 | @pair_elim #len' #assembledi' #eq_assembly_1_pseudoinstruction #IH |
---|
| 922 | change with (let 〈len,assembledi〉 ≝ assembly_1_pseudoinstruction ????? pi' in ∀j:ℕ. ∀H:j<|assembledi|.?) |
---|
| 923 | >eq_assembly_1_pseudoinstruction #j #LTj >reverse_append >reverse_reverse #K |
---|
| 924 | >IH |
---|
[2073] | 925 | [2: >length_reverse <IH3 (*CSC: NEEDS JAAP INVARIANT PLUS SOME WORK *) cases daemon |
---|
[2055] | 926 | | @shift_nth_prefix |
---|
[2071] | 927 | |3: @le_S_S_to_le @(transitive_le … LTppc'') >nat_of_bitvector_add |
---|
| 928 | [ >commutative_plus % |
---|
| 929 | | >commutative_plus >IH1 whd in ⊢ (?%?); |
---|
| 930 | @(transitive_le … (S (|instr_list|))) |
---|
| 931 | [2: <p_refl in instr_list_ok; #instr_list_ok assumption |
---|
| 932 | | >prf >length_append >length_append <plus_n_Sm >nat_of_bitvector_bitvector_of_nat_inverse |
---|
| 933 | [ // | <p_refl in instr_list_ok; >prf >length_append #H @(transitive_le … H) // ]]]] |
---|
[2146] | 934 | *)*)qed. |
---|
[832] | 935 | |
---|
[1948] | 936 | definition assembly_unlabelled_program: |
---|
| 937 | assembly_program → option (list Byte × (BitVectorTrie Identifier 16)) ≝ |
---|
| 938 | λp. |
---|
[2154] | 939 | Some … (〈foldr … (λi,l. assembly1 i @ l) [ ] p, Stub …〉). |
---|