[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". |
---|
[1609] | 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 |
---|
| 14 | | medium_jump: jump_length |
---|
[1925] | 15 | | long_jump: jump_length. |
---|
[1615] | 16 | |
---|
| 17 | definition assembly_preinstruction ≝ |
---|
| 18 | λA: Type[0]. |
---|
| 19 | λaddr_of: A → Byte. (* relative *) |
---|
| 20 | λpre: preinstruction A. |
---|
| 21 | match pre with |
---|
| 22 | [ ADD addr1 addr2 ⇒ |
---|
| 23 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 24 | [ REGISTER r ⇒ λ_.[ ([[false;false;true;false;true]]) @@ r ] |
---|
| 25 | | DIRECT b1 ⇒ λ_.[ ([[false;false;true;false;false;true;false;true]]); b1 ] |
---|
| 26 | | INDIRECT i1 ⇒ λ_. [ ([[false;false;true;false;false;true;true;i1]]) ] |
---|
| 27 | | DATA b1 ⇒ λ_. [ ([[false;false;true;false;false;true;false;false]]) ; b1 ] |
---|
| 28 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 29 | | ADDC addr1 addr2 ⇒ |
---|
| 30 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 31 | [ REGISTER r ⇒ λ_.[ ([[false;false;true;true;true]]) @@ r ] |
---|
| 32 | | DIRECT b1 ⇒ λ_.[ ([[false;false;true;true;false;true;false;true]]); b1 ] |
---|
| 33 | | INDIRECT i1 ⇒ λ_. [ ([[false;false;true;true;false;true;true;i1]]) ] |
---|
| 34 | | DATA b1 ⇒ λ_. [ ([[false;false;true;true;false;true;false;false]]) ; b1 ] |
---|
| 35 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 36 | | ANL addrs ⇒ |
---|
| 37 | match addrs with |
---|
| 38 | [ inl addrs ⇒ match addrs with |
---|
| 39 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 40 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 41 | [ REGISTER r ⇒ λ_.[ ([[false;true;false;true;true]]) @@ r ] |
---|
| 42 | | DIRECT b1 ⇒ λ_.[ ([[false;true;false;true;false;true;false;true]]); b1 ] |
---|
| 43 | | INDIRECT i1 ⇒ λ_. [ ([[false;true;false;true;false;true;true;i1]]) ] |
---|
| 44 | | DATA b1 ⇒ λ_. [ ([[false;true;false;true;false;true;false;false]]) ; b1 ] |
---|
| 45 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 46 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 47 | let b1 ≝ |
---|
| 48 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 49 | [ DIRECT b1 ⇒ λ_.b1 |
---|
| 50 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 51 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;data]] x) → ? with |
---|
| 52 | [ ACC_A ⇒ λ_.[ ([[false;true;false;true;false;false;true;false]]) ; b1 ] |
---|
| 53 | | DATA b2 ⇒ λ_. [ ([[false;true;false;true;false;false;true;true]]) ; b1 ; b2 ] |
---|
| 54 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 55 | ] |
---|
| 56 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 57 | match addr2 return λx. bool_to_Prop (is_in ? [[bit_addr;n_bit_addr]] x) → ? with |
---|
| 58 | [ BIT_ADDR b1 ⇒ λ_.[ ([[true;false;false;false;false;false;true;false]]) ; b1 ] |
---|
| 59 | | N_BIT_ADDR b1 ⇒ λ_. [ ([[true;false;true;true;false;false;false;false]]) ; b1 ] |
---|
| 60 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 61 | | CLR addr ⇒ |
---|
| 62 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;carry;bit_addr]] x) → ? with |
---|
| 63 | [ ACC_A ⇒ λ_. |
---|
| 64 | [ ([[true; true; true; false; false; true; false; false]]) ] |
---|
| 65 | | CARRY ⇒ λ_. |
---|
| 66 | [ ([[true; true; false; false; false; false; true; true]]) ] |
---|
| 67 | | BIT_ADDR b1 ⇒ λ_. |
---|
| 68 | [ ([[true; true; false; false; false; false; true; false]]) ; b1 ] |
---|
| 69 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 70 | | CPL addr ⇒ |
---|
| 71 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;carry;bit_addr]] x) → ? with |
---|
| 72 | [ ACC_A ⇒ λ_. |
---|
| 73 | [ ([[true; true; true; true; false; true; false; false]]) ] |
---|
| 74 | | CARRY ⇒ λ_. |
---|
| 75 | [ ([[true; false; true; true; false; false; true; true]]) ] |
---|
| 76 | | BIT_ADDR b1 ⇒ λ_. |
---|
| 77 | [ ([[true; false; true; true; false; false; true; false]]) ; b1 ] |
---|
| 78 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 79 | | DA addr ⇒ |
---|
| 80 | [ ([[true; true; false; true; false; true; false; false]]) ] |
---|
| 81 | | DEC addr ⇒ |
---|
| 82 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;registr;direct;indirect]] x) → ? with |
---|
| 83 | [ ACC_A ⇒ λ_. |
---|
| 84 | [ ([[false; false; false; true; false; true; false; false]]) ] |
---|
| 85 | | REGISTER r ⇒ λ_. |
---|
| 86 | [ ([[false; false; false; true; true]]) @@ r ] |
---|
| 87 | | DIRECT b1 ⇒ λ_. |
---|
| 88 | [ ([[false; false; false; true; false; true; false; true]]); b1 ] |
---|
| 89 | | INDIRECT i1 ⇒ λ_. |
---|
| 90 | [ ([[false; false; false; true; false; true; true; i1]]) ] |
---|
| 91 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 92 | | DJNZ addr1 addr2 ⇒ |
---|
| 93 | let b2 ≝ addr_of addr2 in |
---|
| 94 | match addr1 return λx. bool_to_Prop (is_in ? [[registr;direct]] x) → ? with |
---|
| 95 | [ REGISTER r ⇒ λ_. |
---|
| 96 | [ ([[true; true; false; true; true]]) @@ r ; b2 ] |
---|
| 97 | | DIRECT b1 ⇒ λ_. |
---|
| 98 | [ ([[true; true; false; true; false; true; false; true]]); b1; b2 ] |
---|
| 99 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 100 | | JC addr ⇒ |
---|
| 101 | let b1 ≝ addr_of addr in |
---|
| 102 | [ ([[false; true; false; false; false; false; false; false]]); b1 ] |
---|
| 103 | | JNC addr ⇒ |
---|
| 104 | let b1 ≝ addr_of addr in |
---|
| 105 | [ ([[false; true; false; true; false; false; false; false]]); b1 ] |
---|
| 106 | | JZ addr ⇒ |
---|
| 107 | let b1 ≝ addr_of addr in |
---|
| 108 | [ ([[false; true; true; false; false; false; false; false]]); b1 ] |
---|
| 109 | | JNZ addr ⇒ |
---|
| 110 | let b1 ≝ addr_of addr in |
---|
| 111 | [ ([[false; true; true; true; false; false; false; false]]); b1 ] |
---|
| 112 | | JB addr1 addr2 ⇒ |
---|
| 113 | let b2 ≝ addr_of addr2 in |
---|
| 114 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 115 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 116 | [ ([[false; false; true; false; false; false; false; false]]); b1; b2 ] |
---|
| 117 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 118 | | JNB addr1 addr2 ⇒ |
---|
| 119 | let b2 ≝ addr_of addr2 in |
---|
| 120 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 121 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 122 | [ ([[false; false; true; true; false; false; false; false]]); b1; b2 ] |
---|
| 123 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 124 | | JBC addr1 addr2 ⇒ |
---|
| 125 | let b2 ≝ addr_of addr2 in |
---|
| 126 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 127 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 128 | [ ([[false; false; false; true; false; false; false; false]]); b1; b2 ] |
---|
| 129 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 130 | | CJNE addrs addr3 ⇒ |
---|
| 131 | let b3 ≝ addr_of addr3 in |
---|
| 132 | match addrs with |
---|
| 133 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 134 | match addr2 return λx. bool_to_Prop (is_in ? [[direct;data]] x) → ? with |
---|
| 135 | [ DIRECT b1 ⇒ λ_. |
---|
| 136 | [ ([[true; false; true; true; false; true; false; true]]); b1; b3 ] |
---|
| 137 | | DATA b1 ⇒ λ_. |
---|
| 138 | [ ([[true; false; true; true; false; true; false; false]]); b1; b3 ] |
---|
| 139 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 140 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 141 | let b2 ≝ |
---|
| 142 | match addr2 return λx. bool_to_Prop (is_in ? [[data]] x) → ? with |
---|
| 143 | [ DATA b2 ⇒ λ_. b2 |
---|
| 144 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) in |
---|
| 145 | match addr1 return λx. bool_to_Prop (is_in ? [[registr;indirect]] x) → list Byte with |
---|
| 146 | [ REGISTER r ⇒ λ_. |
---|
| 147 | [ ([[true; false; true; true; true]]) @@ r; b2; b3 ] |
---|
| 148 | | INDIRECT i1 ⇒ λ_. |
---|
| 149 | [ ([[true; false; true; true; false; true; true; i1]]); b2; b3 ] |
---|
| 150 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) |
---|
| 151 | ] |
---|
| 152 | | DIV addr1 addr2 ⇒ |
---|
| 153 | [ ([[true;false;false;false;false;true;false;false]]) ] |
---|
| 154 | | INC addr ⇒ |
---|
| 155 | match addr return λx. bool_to_Prop (is_in ? [[acc_a;registr;direct;indirect;dptr]] x) → ? with |
---|
| 156 | [ ACC_A ⇒ λ_. |
---|
| 157 | [ ([[false;false;false;false;false;true;false;false]]) ] |
---|
| 158 | | REGISTER r ⇒ λ_. |
---|
| 159 | [ ([[false;false;false;false;true]]) @@ r ] |
---|
| 160 | | DIRECT b1 ⇒ λ_. |
---|
| 161 | [ ([[false; false; false; false; false; true; false; true]]); b1 ] |
---|
| 162 | | INDIRECT i1 ⇒ λ_. |
---|
| 163 | [ ([[false; false; false; false; false; true; true; i1]]) ] |
---|
| 164 | | DPTR ⇒ λ_. |
---|
| 165 | [ ([[true;false;true;false;false;false;true;true]]) ] |
---|
| 166 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 167 | | MOV addrs ⇒ |
---|
| 168 | match addrs with |
---|
| 169 | [ inl addrs ⇒ |
---|
| 170 | match addrs with |
---|
| 171 | [ inl addrs ⇒ |
---|
| 172 | match addrs with |
---|
| 173 | [ inl addrs ⇒ |
---|
| 174 | match addrs with |
---|
| 175 | [ inl addrs ⇒ |
---|
| 176 | match addrs with |
---|
| 177 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 178 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 179 | [ REGISTER r ⇒ λ_.[ ([[true;true;true;false;true]]) @@ r ] |
---|
| 180 | | DIRECT b1 ⇒ λ_.[ ([[true;true;true;false;false;true;false;true]]); b1 ] |
---|
| 181 | | INDIRECT i1 ⇒ λ_. [ ([[true;true;true;false;false;true;true;i1]]) ] |
---|
| 182 | | DATA b1 ⇒ λ_. [ ([[false;true;true;true;false;true;false;false]]) ; b1 ] |
---|
| 183 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 184 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 185 | match addr1 return λx. bool_to_Prop (is_in ? [[registr;indirect]] x) → ? with |
---|
| 186 | [ REGISTER r ⇒ λ_. |
---|
| 187 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;direct;data]] x) → ? with |
---|
| 188 | [ ACC_A ⇒ λ_.[ ([[true;true;true;true;true]]) @@ r ] |
---|
| 189 | | DIRECT b1 ⇒ λ_.[ ([[true;false;true;false;true]]) @@ r; b1 ] |
---|
| 190 | | DATA b1 ⇒ λ_. [ ([[false;true;true;true;true]]) @@ r; b1 ] |
---|
| 191 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 192 | | INDIRECT i1 ⇒ λ_. |
---|
| 193 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;direct;data]] x) → ? with |
---|
| 194 | [ ACC_A ⇒ λ_.[ ([[true;true;true;true;false;true;true;i1]]) ] |
---|
| 195 | | DIRECT b1 ⇒ λ_.[ ([[true;false;true;false;false;true;true;i1]]); b1 ] |
---|
| 196 | | DATA b1 ⇒ λ_. [ ([[false;true;true;true;false;true;true;i1]]) ; b1 ] |
---|
| 197 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 198 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1)] |
---|
| 199 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 200 | let b1 ≝ |
---|
| 201 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 202 | [ DIRECT b1 ⇒ λ_. b1 |
---|
| 203 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 204 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;registr;direct;indirect;data]] x) → ? with |
---|
| 205 | [ ACC_A ⇒ λ_.[ ([[true;true;true;true;false;true;false;true]]); b1] |
---|
| 206 | | REGISTER r ⇒ λ_.[ ([[true;false;false;false;true]]) @@ r; b1 ] |
---|
| 207 | | DIRECT b2 ⇒ λ_.[ ([[true;false;false;false;false;true;false;true]]); b1; b2 ] |
---|
| 208 | | INDIRECT i1 ⇒ λ_. [ ([[true;false;false;false;false;true;true;i1]]); b1 ] |
---|
| 209 | | DATA b2 ⇒ λ_. [ ([[false;true;true;true;false;true;false;true]]); b1; b2 ] |
---|
| 210 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 211 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 212 | match addr2 return λx. bool_to_Prop (is_in ? [[data16]] x) → ? with |
---|
| 213 | [ DATA16 w ⇒ λ_. |
---|
| 214 | let b1_b2 ≝ split ? 8 8 w in |
---|
| 215 | let b1 ≝ \fst b1_b2 in |
---|
| 216 | let b2 ≝ \snd b1_b2 in |
---|
| 217 | [ ([[true;false;false;true;false;false;false;false]]); b1; b2] |
---|
| 218 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 219 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 220 | match addr2 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 221 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 222 | [ ([[true;false;true;false;false;false;true;false]]); b1 ] |
---|
| 223 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 224 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 225 | match addr1 return λx. bool_to_Prop (is_in ? [[bit_addr]] x) → ? with |
---|
| 226 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 227 | [ ([[true;false;false;true;false;false;true;false]]); b1 ] |
---|
| 228 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1)] |
---|
| 229 | | MOVX addrs ⇒ |
---|
| 230 | match addrs with |
---|
| 231 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 232 | match addr2 return λx. bool_to_Prop (is_in ? [[ext_indirect;ext_indirect_dptr]] x) → ? with |
---|
| 233 | [ EXT_INDIRECT i1 ⇒ λ_. |
---|
| 234 | [ ([[true;true;true;false;false;false;true;i1]]) ] |
---|
| 235 | | EXT_INDIRECT_DPTR ⇒ λ_. |
---|
| 236 | [ ([[true;true;true;false;false;false;false;false]]) ] |
---|
| 237 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 238 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 239 | match addr1 return λx. bool_to_Prop (is_in ? [[ext_indirect;ext_indirect_dptr]] x) → ? with |
---|
| 240 | [ EXT_INDIRECT i1 ⇒ λ_. |
---|
| 241 | [ ([[true;true;true;true;false;false;true;i1]]) ] |
---|
| 242 | | EXT_INDIRECT_DPTR ⇒ λ_. |
---|
| 243 | [ ([[true;true;true;true;false;false;false;false]]) ] |
---|
| 244 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1)] |
---|
| 245 | | MUL addr1 addr2 ⇒ |
---|
| 246 | [ ([[true;false;true;false;false;true;false;false]]) ] |
---|
| 247 | | NOP ⇒ |
---|
| 248 | [ ([[false;false;false;false;false;false;false;false]]) ] |
---|
| 249 | | ORL addrs ⇒ |
---|
| 250 | match addrs with |
---|
| 251 | [ inl addrs ⇒ |
---|
| 252 | match addrs with |
---|
| 253 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 254 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;data;direct;indirect]] x) → ? with |
---|
| 255 | [ REGISTER r ⇒ λ_.[ ([[false;true;false;false;true]]) @@ r ] |
---|
| 256 | | DIRECT b1 ⇒ λ_.[ ([[false;true;false;false;false;true;false;true]]); b1 ] |
---|
| 257 | | INDIRECT i1 ⇒ λ_. [ ([[false;true;false;false;false;true;true;i1]]) ] |
---|
| 258 | | DATA b1 ⇒ λ_. [ ([[false;true;false;false;false;true;false;false]]) ; b1 ] |
---|
| 259 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 260 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 261 | let b1 ≝ |
---|
| 262 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 263 | [ DIRECT b1 ⇒ λ_. b1 |
---|
| 264 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 265 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;data]] x) → ? with |
---|
| 266 | [ ACC_A ⇒ λ_. |
---|
| 267 | [ ([[false;true;false;false;false;false;true;false]]); b1 ] |
---|
| 268 | | DATA b2 ⇒ λ_. |
---|
| 269 | [ ([[false;true;false;false;false;false;true;true]]); b1; b2 ] |
---|
| 270 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 271 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 272 | match addr2 return λx. bool_to_Prop (is_in ? [[bit_addr;n_bit_addr]] x) → ? with |
---|
| 273 | [ BIT_ADDR b1 ⇒ λ_. |
---|
| 274 | [ ([[false;true;true;true;false;false;true;false]]); b1 ] |
---|
| 275 | | N_BIT_ADDR b1 ⇒ λ_. |
---|
| 276 | [ ([[true;false;true;false;false;false;false;false]]); b1 ] |
---|
| 277 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 278 | | POP addr ⇒ |
---|
| 279 | match addr return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 280 | [ DIRECT b1 ⇒ λ_. |
---|
| 281 | [ ([[true;true;false;true;false;false;false;false]]) ; b1 ] |
---|
| 282 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 283 | | PUSH addr ⇒ |
---|
| 284 | match addr return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 285 | [ DIRECT b1 ⇒ λ_. |
---|
| 286 | [ ([[true;true;false;false;false;false;false;false]]) ; b1 ] |
---|
| 287 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 288 | | RET ⇒ |
---|
| 289 | [ ([[false;false;true;false;false;false;true;false]]) ] |
---|
| 290 | | RETI ⇒ |
---|
| 291 | [ ([[false;false;true;true;false;false;true;false]]) ] |
---|
| 292 | | RL addr ⇒ |
---|
| 293 | [ ([[false;false;true;false;false;false;true;true]]) ] |
---|
| 294 | | RLC addr ⇒ |
---|
| 295 | [ ([[false;false;true;true;false;false;true;true]]) ] |
---|
| 296 | | RR addr ⇒ |
---|
| 297 | [ ([[false;false;false;false;false;false;true;true]]) ] |
---|
| 298 | | RRC addr ⇒ |
---|
| 299 | [ ([[false;false;false;true;false;false;true;true]]) ] |
---|
| 300 | | SETB addr ⇒ |
---|
| 301 | match addr return λx. bool_to_Prop (is_in ? [[carry;bit_addr]] x) → ? with |
---|
| 302 | [ CARRY ⇒ λ_. |
---|
| 303 | [ ([[true;true;false;true;false;false;true;true]]) ] |
---|
| 304 | | BIT_ADDR b1 ⇒ λ_. |
---|
| 305 | [ ([[true;true;false;true;false;false;true;false]]); b1 ] |
---|
| 306 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 307 | | SUBB addr1 addr2 ⇒ |
---|
| 308 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect;data]] x) → ? with |
---|
| 309 | [ REGISTER r ⇒ λ_. |
---|
| 310 | [ ([[true;false;false;true;true]]) @@ r ] |
---|
| 311 | | DIRECT b1 ⇒ λ_. |
---|
| 312 | [ ([[true;false;false;true;false;true;false;true]]); b1] |
---|
| 313 | | INDIRECT i1 ⇒ λ_. |
---|
| 314 | [ ([[true;false;false;true;false;true;true;i1]]) ] |
---|
| 315 | | DATA b1 ⇒ λ_. |
---|
| 316 | [ ([[true;false;false;true;false;true;false;false]]); b1] |
---|
| 317 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 318 | | SWAP addr ⇒ |
---|
| 319 | [ ([[true;true;false;false;false;true;false;false]]) ] |
---|
| 320 | | XCH addr1 addr2 ⇒ |
---|
| 321 | match addr2 return λx. bool_to_Prop (is_in ? [[registr;direct;indirect]] x) → ? with |
---|
| 322 | [ REGISTER r ⇒ λ_. |
---|
| 323 | [ ([[true;true;false;false;true]]) @@ r ] |
---|
| 324 | | DIRECT b1 ⇒ λ_. |
---|
| 325 | [ ([[true;true;false;false;false;true;false;true]]); b1] |
---|
| 326 | | INDIRECT i1 ⇒ λ_. |
---|
| 327 | [ ([[true;true;false;false;false;true;true;i1]]) ] |
---|
| 328 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 329 | | XCHD addr1 addr2 ⇒ |
---|
| 330 | match addr2 return λx. bool_to_Prop (is_in ? [[indirect]] x) → ? with |
---|
| 331 | [ INDIRECT i1 ⇒ λ_. |
---|
| 332 | [ ([[true;true;false;true;false;true;true;i1]]) ] |
---|
| 333 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 334 | | XRL addrs ⇒ |
---|
| 335 | match addrs with |
---|
| 336 | [ inl addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 337 | match addr2 return λx. bool_to_Prop (is_in ? [[data;registr;direct;indirect]] x) → ? with |
---|
| 338 | [ REGISTER r ⇒ λ_. |
---|
| 339 | [ ([[false;true;true;false;true]]) @@ r ] |
---|
| 340 | | DIRECT b1 ⇒ λ_. |
---|
| 341 | [ ([[false;true;true;false;false;true;false;true]]); b1] |
---|
| 342 | | INDIRECT i1 ⇒ λ_. |
---|
| 343 | [ ([[false;true;true;false;false;true;true;i1]]) ] |
---|
| 344 | | DATA b1 ⇒ λ_. |
---|
| 345 | [ ([[false;true;true;false;false;true;false;false]]); b1] |
---|
| 346 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 347 | | inr addrs ⇒ let 〈addr1,addr2〉 ≝ addrs in |
---|
| 348 | let b1 ≝ |
---|
| 349 | match addr1 return λx. bool_to_Prop (is_in ? [[direct]] x) → ? with |
---|
| 350 | [ DIRECT b1 ⇒ λ_. b1 |
---|
| 351 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr1) in |
---|
| 352 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_a;data]] x) → ? with |
---|
| 353 | [ ACC_A ⇒ λ_. |
---|
| 354 | [ ([[false;true;true;false;false;false;true;false]]); b1 ] |
---|
| 355 | | DATA b2 ⇒ λ_. |
---|
| 356 | [ ([[false;true;true;false;false;false;true;true]]); b1; b2 ] |
---|
| 357 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2)] |
---|
| 358 | ]. |
---|
| 359 | |
---|
| 360 | definition assembly1 ≝ |
---|
| 361 | λi: instruction. |
---|
| 362 | match i with |
---|
| 363 | [ ACALL addr ⇒ |
---|
| 364 | match addr return λx. bool_to_Prop (is_in ? [[addr11]] x) → ? with |
---|
| 365 | [ ADDR11 w ⇒ λ_. |
---|
| 366 | let v1_v2 ≝ split ? 3 8 w in |
---|
| 367 | let v1 ≝ \fst v1_v2 in |
---|
| 368 | let v2 ≝ \snd v1_v2 in |
---|
| 369 | [ (v1 @@ [[true; false; false; false; true]]) ; v2 ] |
---|
| 370 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 371 | | AJMP addr ⇒ |
---|
| 372 | match addr return λx. bool_to_Prop (is_in ? [[addr11]] x) → ? with |
---|
| 373 | [ ADDR11 w ⇒ λ_. |
---|
| 374 | let v1_v2 ≝ split ? 3 8 w in |
---|
| 375 | let v1 ≝ \fst v1_v2 in |
---|
| 376 | let v2 ≝ \snd v1_v2 in |
---|
| 377 | [ (v1 @@ [[false; false; false; false; true]]) ; v2 ] |
---|
| 378 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 379 | | JMP adptr ⇒ |
---|
| 380 | [ ([[false;true;true;true;false;false;true;true]]) ] |
---|
| 381 | | LCALL addr ⇒ |
---|
| 382 | match addr return λx. bool_to_Prop (is_in ? [[addr16]] x) → ? with |
---|
| 383 | [ ADDR16 w ⇒ λ_. |
---|
| 384 | let b1_b2 ≝ split ? 8 8 w in |
---|
| 385 | let b1 ≝ \fst b1_b2 in |
---|
| 386 | let b2 ≝ \snd b1_b2 in |
---|
| 387 | [ ([[false;false;false;true;false;false;true;false]]); b1; b2 ] |
---|
| 388 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 389 | | LJMP addr ⇒ |
---|
| 390 | match addr return λx. bool_to_Prop (is_in ? [[addr16]] x) → ? with |
---|
| 391 | [ ADDR16 w ⇒ λ_. |
---|
| 392 | let b1_b2 ≝ split ? 8 8 w in |
---|
| 393 | let b1 ≝ \fst b1_b2 in |
---|
| 394 | let b2 ≝ \snd b1_b2 in |
---|
| 395 | [ ([[false;false;false;false;false;false;true;false]]); b1; b2 ] |
---|
| 396 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 397 | | MOVC addr1 addr2 ⇒ |
---|
| 398 | match addr2 return λx. bool_to_Prop (is_in ? [[acc_dptr;acc_pc]] x) → ? with |
---|
| 399 | [ ACC_DPTR ⇒ λ_. |
---|
| 400 | [ ([[true;false;false;true;false;false;true;true]]) ] |
---|
| 401 | | ACC_PC ⇒ λ_. |
---|
| 402 | [ ([[true;false;false;false;false;false;true;true]]) ] |
---|
| 403 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr2) |
---|
| 404 | | SJMP addr ⇒ |
---|
| 405 | match addr return λx. bool_to_Prop (is_in ? [[relative]] x) → ? with |
---|
| 406 | [ RELATIVE b1 ⇒ λ_. |
---|
| 407 | [ ([[true;false;false;false;false;false;false;false]]); b1 ] |
---|
| 408 | | _ ⇒ λK.match K in False with [ ] ] (subaddressing_modein … addr) |
---|
| 409 | | RealInstruction instr ⇒ |
---|
| 410 | assembly_preinstruction [[ relative ]] |
---|
| 411 | (λx. |
---|
| 412 | match x return λs. bool_to_Prop (is_in ? [[ relative ]] s) → ? with |
---|
| 413 | [ RELATIVE r ⇒ λ_. r |
---|
| 414 | | _ ⇒ λabsd. ⊥ |
---|
| 415 | ] (subaddressing_modein … x)) instr |
---|
| 416 | ]. |
---|
| 417 | cases absd |
---|
[1592] | 418 | qed. |
---|
| 419 | |
---|
[1905] | 420 | definition expand_relative_jump_internal: |
---|
[1934] | 421 | ∀lookup_labels:Identifier → Word.∀sigma:Word → Word × bool. |
---|
[1905] | 422 | Identifier → Word → ([[relative]] → preinstruction [[relative]]) → |
---|
| 423 | list instruction |
---|
[1615] | 424 | ≝ |
---|
[1934] | 425 | λlookup_labels.λsigma.λlbl.λppc,i. |
---|
| 426 | let lookup_address ≝ \fst (sigma (lookup_labels lbl)) in |
---|
| 427 | let pc ≝ \fst (sigma ppc) in |
---|
[1905] | 428 | let 〈result, flags〉 ≝ sub_16_with_carry pc lookup_address false in |
---|
| 429 | let 〈upper, lower〉 ≝ split ? 8 8 result in |
---|
| 430 | if eq_bv ? upper (zero 8) then |
---|
| 431 | let address ≝ RELATIVE lower in |
---|
| 432 | [ RealInstruction (i address) ] |
---|
| 433 | else |
---|
[1615] | 434 | [ RealInstruction (i (RELATIVE (bitvector_of_nat ? 2))); |
---|
| 435 | SJMP (RELATIVE (bitvector_of_nat ? 3)); (* LJMP size? *) |
---|
[1649] | 436 | LJMP (ADDR16 lookup_address) |
---|
[1905] | 437 | ]. |
---|
[1615] | 438 | @ I |
---|
| 439 | qed. |
---|
| 440 | |
---|
[1905] | 441 | (*definition rel_jump_length_ok ≝ |
---|
[1649] | 442 | λlookup_address:Word. |
---|
| 443 | λpc:Word. |
---|
| 444 | Σjump_len:jump_length. |
---|
| 445 | (* CSC,JPB: Cheating here, use Jaap's better definition select_reljump_length *) |
---|
| 446 | ∀(*x,*)y. expand_relative_jump_internal_safe lookup_address jump_len (*x*) pc y ≠ None ?. |
---|
| 447 | |
---|
| 448 | lemma eject_rel_jump_length: ∀x,y. rel_jump_length_ok x y → jump_length. |
---|
| 449 | #x #y #p @(pi1 … p) |
---|
| 450 | qed. |
---|
| 451 | |
---|
| 452 | coercion eject_rel_jump_length nocomposites: |
---|
| 453 | ∀x,y.∀pol:rel_jump_length_ok x y. jump_length ≝ |
---|
[1905] | 454 | eject_rel_jump_length on _pol:(rel_jump_length_ok ??) to jump_length.*) |
---|
[1649] | 455 | |
---|
[1905] | 456 | (*definition expand_relative_jump_internal: |
---|
| 457 | ∀lookup_address:Word. ∀pc:Word. ([[relative]] → preinstruction [[relative]]) → |
---|
[1649] | 458 | list instruction |
---|
[1905] | 459 | ≝ λlookup_address,pc,i. |
---|
| 460 | match expand_relative_jump_internal_safe lookup_address pc i |
---|
[1649] | 461 | return λres. res ≠ None ? → ? |
---|
| 462 | with |
---|
| 463 | [ None ⇒ λabs.⊥ |
---|
| 464 | | Some res ⇒ λ_.res ] (pi2 … jump_len i). |
---|
| 465 | cases abs /2/ |
---|
[1905] | 466 | qed.*) |
---|
[1649] | 467 | |
---|
[1905] | 468 | definition expand_relative_jump: |
---|
| 469 | ∀lookup_labels.∀sigma. |
---|
| 470 | Word → (*jump_length →*) |
---|
| 471 | preinstruction Identifier → list instruction ≝ |
---|
| 472 | λlookup_labels: Identifier → Word. |
---|
[1934] | 473 | λsigma:Word → Word × bool. |
---|
| 474 | λppc: Word. |
---|
[1905] | 475 | (*λjmp_len: jump_length.*) |
---|
[1615] | 476 | λi: preinstruction Identifier. |
---|
[1934] | 477 | (*let rel_jmp ≝ RELATIVE (bitvector_of_nat ? 2) in*) |
---|
[1615] | 478 | match i with |
---|
[1934] | 479 | [ JC jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JC ?) |
---|
| 480 | | JNC jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JNC ?) |
---|
| 481 | | JB baddr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JB ? baddr) |
---|
| 482 | | JZ jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JZ ?) |
---|
| 483 | | JNZ jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JNZ ?) |
---|
| 484 | | JBC baddr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JBC ? baddr) |
---|
| 485 | | JNB baddr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (JNB ? baddr) |
---|
| 486 | | CJNE addr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (CJNE ? addr) |
---|
| 487 | | DJNZ addr jmp ⇒ expand_relative_jump_internal lookup_labels sigma jmp ppc (DJNZ ? addr) |
---|
[1905] | 488 | | ADD arg1 arg2 ⇒ [ ADD ? arg1 arg2 ] |
---|
| 489 | | ADDC arg1 arg2 ⇒ [ ADDC ? arg1 arg2 ] |
---|
| 490 | | SUBB arg1 arg2 ⇒ [ SUBB ? arg1 arg2 ] |
---|
| 491 | | INC arg ⇒ [ INC ? arg ] |
---|
| 492 | | DEC arg ⇒ [ DEC ? arg ] |
---|
| 493 | | MUL arg1 arg2 ⇒ [ MUL ? arg1 arg2 ] |
---|
| 494 | | DIV arg1 arg2 ⇒ [ DIV ? arg1 arg2 ] |
---|
| 495 | | DA arg ⇒ [ DA ? arg ] |
---|
| 496 | | ANL arg ⇒ [ ANL ? arg ] |
---|
| 497 | | ORL arg ⇒ [ ORL ? arg ] |
---|
| 498 | | XRL arg ⇒ [ XRL ? arg ] |
---|
| 499 | | CLR arg ⇒ [ CLR ? arg ] |
---|
| 500 | | CPL arg ⇒ [ CPL ? arg ] |
---|
| 501 | | RL arg ⇒ [ RL ? arg ] |
---|
| 502 | | RR arg ⇒ [ RR ? arg ] |
---|
| 503 | | RLC arg ⇒ [ RLC ? arg ] |
---|
| 504 | | RRC arg ⇒ [ RRC ? arg ] |
---|
| 505 | | SWAP arg ⇒ [ SWAP ? arg ] |
---|
| 506 | | MOV arg ⇒ [ MOV ? arg ] |
---|
| 507 | | MOVX arg ⇒ [ MOVX ? arg ] |
---|
| 508 | | SETB arg ⇒ [ SETB ? arg ] |
---|
| 509 | | PUSH arg ⇒ [ PUSH ? arg ] |
---|
| 510 | | POP arg ⇒ [ POP ? arg ] |
---|
| 511 | | XCH arg1 arg2 ⇒ [ XCH ? arg1 arg2 ] |
---|
| 512 | | XCHD arg1 arg2 ⇒ [ XCHD ? arg1 arg2 ] |
---|
| 513 | | RET ⇒ [ RET ? ] |
---|
| 514 | | RETI ⇒ [ RETI ? ] |
---|
| 515 | | NOP ⇒ [ RealInstruction (NOP ?) ] |
---|
[1615] | 516 | ]. |
---|
| 517 | |
---|
[1905] | 518 | definition expand_pseudo_instruction: |
---|
| 519 | ∀lookup_labels.∀sigma.Word → ? → pseudo_instruction → list instruction ≝ |
---|
| 520 | λlookup_labels:Identifier → Word. |
---|
[1934] | 521 | λsigma:Word → Word × bool. |
---|
| 522 | λppc. |
---|
[1905] | 523 | λlookup_datalabels:Identifier → Word. |
---|
[1615] | 524 | λi. |
---|
| 525 | match i with |
---|
[1905] | 526 | [ Cost cost ⇒ [ ] |
---|
| 527 | | Comment comment ⇒ [ ] |
---|
[1615] | 528 | | Call call ⇒ |
---|
[1934] | 529 | let 〈addr_5, resta〉 ≝ split ? 5 11 (\fst (sigma (lookup_labels call))) in |
---|
| 530 | let 〈pc, do_a_long〉 ≝ sigma ppc in |
---|
| 531 | let 〈pc_5, restp〉 ≝ split ? 5 11 pc in |
---|
| 532 | if eq_bv ? addr_5 pc_5 ∧ ¬ do_a_long then |
---|
| 533 | let address ≝ ADDR11 resta in |
---|
[1905] | 534 | [ ACALL address ] |
---|
| 535 | else |
---|
[1934] | 536 | let address ≝ ADDR16 (\fst (sigma (lookup_labels call))) 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 ⇒ |
---|
[1934] | 543 | let 〈pc, do_a_long〉 ≝ sigma ppc in |
---|
| 544 | let lookup_address ≝ \fst (sigma (lookup_labels jmp)) in |
---|
| 545 | let 〈result, flags〉 ≝ sub_16_with_carry pc lookup_address false in |
---|
[1905] | 546 | let 〈upper, lower〉 ≝ split ? 8 8 result in |
---|
[1934] | 547 | if eq_bv ? upper (zero 8) ∧ ¬ do_a_long then |
---|
[1905] | 548 | let address ≝ RELATIVE lower in |
---|
| 549 | [ SJMP address ] |
---|
| 550 | else |
---|
[1649] | 551 | let 〈fst_5_addr, rest_addr〉 ≝ split ? 5 11 (lookup_labels jmp) in |
---|
[1615] | 552 | let 〈fst_5_pc, rest_pc〉 ≝ split ? 5 11 pc in |
---|
[1934] | 553 | if eq_bv ? fst_5_addr fst_5_pc ∧ ¬ do_a_long then |
---|
[1615] | 554 | let address ≝ ADDR11 rest_addr in |
---|
[1905] | 555 | [ AJMP address ] |
---|
| 556 | else |
---|
[1934] | 557 | let address ≝ ADDR16 lookup_address in |
---|
[1905] | 558 | [ LJMP address ] |
---|
[1615] | 559 | ]. |
---|
| 560 | @ I |
---|
| 561 | qed. |
---|
| 562 | |
---|
[1905] | 563 | (* |
---|
| 564 | (*X? |
---|
[1649] | 565 | definition jump_length_ok ≝ |
---|
| 566 | λlookup_labels:Identifier → Word. |
---|
| 567 | λpc:Word. |
---|
| 568 | Σjump_len:jump_length. |
---|
| 569 | (* CSC,JPB: Cheating here, use Jaap's better definition select_reljump_length *) |
---|
| 570 | ∀x,y.expand_pseudo_instruction_safe lookup_labels pc jump_len x y ≠ None ?. |
---|
[1905] | 571 | *) |
---|
[1615] | 572 | |
---|
[1649] | 573 | lemma eject_jump_length: ∀x,y. jump_length_ok x y → jump_length. |
---|
| 574 | #x #y #p @(pi1 … p) |
---|
| 575 | qed. |
---|
| 576 | |
---|
| 577 | coercion eject_jump_length nocomposites: |
---|
| 578 | ∀x,y.∀pol:jump_length_ok x y. jump_length ≝ |
---|
| 579 | eject_jump_length on _pol:(jump_length_ok ??) to jump_length. |
---|
| 580 | |
---|
| 581 | definition expand_pseudo_instruction: |
---|
| 582 | ∀lookup_labels:Identifier → Word. ∀pc:Word. jump_length_ok lookup_labels pc → |
---|
| 583 | ? → pseudo_instruction → list instruction ≝ |
---|
| 584 | λlookup_labels,pc,jump_len,lookup_datalabels,i. |
---|
| 585 | match expand_pseudo_instruction_safe lookup_labels pc jump_len lookup_datalabels i |
---|
| 586 | return λres. res ≠ None ? → ? |
---|
| 587 | with |
---|
| 588 | [ None ⇒ λabs.⊥ |
---|
| 589 | | Some res ⇒ λ_.res ] (pi2 … jump_len lookup_datalabels i). |
---|
| 590 | cases abs /2/ |
---|
| 591 | qed. |
---|
[1905] | 592 | *) |
---|
| 593 | (*X? |
---|
[1649] | 594 | definition policy_type ≝ |
---|
| 595 | λlookup_labels:Identifier → Word. |
---|
| 596 | ∀pc:Word. jump_length_ok lookup_labels pc. |
---|
[1905] | 597 | *) |
---|
[1649] | 598 | |
---|
[1905] | 599 | (*definition policy_type2 ≝ |
---|
| 600 | λprogram. |
---|
| 601 | Σpol:Word → jump_length. |
---|
| 602 | let lookup_labels ≝ |
---|
| 603 | (λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x)) in |
---|
| 604 | ∀pc:Word. let jump_len ≝ pol pc in |
---|
| 605 | ∀x,y.expand_pseudo_instruction_safe lookup_labels pc jump_len x y ≠ None ?.*) |
---|
[1649] | 606 | |
---|
| 607 | definition assembly_1_pseudoinstruction ≝ |
---|
| 608 | λlookup_labels. |
---|
[1905] | 609 | λsigma. |
---|
[1934] | 610 | λppc: Word. |
---|
[832] | 611 | λlookup_datalabels. |
---|
| 612 | λi. |
---|
[1934] | 613 | let pseudos ≝ expand_pseudo_instruction lookup_labels sigma ppc lookup_datalabels i in |
---|
[1649] | 614 | let mapped ≝ map ? ? assembly1 pseudos in |
---|
| 615 | let flattened ≝ flatten ? mapped in |
---|
| 616 | let pc_len ≝ length ? flattened in |
---|
| 617 | 〈pc_len, flattened〉. |
---|
[1667] | 618 | |
---|
[1934] | 619 | definition instruction_size ≝ |
---|
| 620 | λlookup_labels.λsigma.λppc.λi. |
---|
| 621 | \fst (assembly_1_pseudoinstruction lookup_labels sigma ppc (λx.zero …) i). |
---|
[832] | 622 | |
---|
[1934] | 623 | (* Jaap: never used |
---|
[1870] | 624 | lemma fetch_pseudo_instruction_prefix: |
---|
| 625 | ∀prefix.∀x.∀ppc.ppc < (|prefix|) → |
---|
| 626 | fetch_pseudo_instruction prefix (bitvector_of_nat ? ppc) = |
---|
| 627 | fetch_pseudo_instruction (prefix@x) (bitvector_of_nat ? ppc). |
---|
| 628 | #prefix #x #ppc elim prefix |
---|
| 629 | [ #Hppc @⊥ @(absurd … Hppc) @le_to_not_lt @le_O_n |
---|
| 630 | | #h #t #Hind #Hppc whd in match (fetch_pseudo_instruction ??); |
---|
| 631 | whd in match (fetch_pseudo_instruction ((h::t)@x) ?); |
---|
| 632 | >nth_append_first |
---|
| 633 | [ // |
---|
| 634 | | >nat_of_bitvector_bitvector_of_nat |
---|
| 635 | [ @Hppc |
---|
| 636 | | cases daemon (* XXX invariant *) |
---|
| 637 | ] |
---|
| 638 | ] |
---|
| 639 | ] |
---|
| 640 | qed. |
---|
[1934] | 641 | *) |
---|
[1870] | 642 | |
---|
[1905] | 643 | (* |
---|
[985] | 644 | (* This establishes the correspondence between pseudo program counters and |
---|
| 645 | program counters. It is at the heart of the proof. *) |
---|
| 646 | (*CSC: code taken from build_maps *) |
---|
[1905] | 647 | definition sigma00: |
---|
| 648 | ∀jump_expansion:policy_type2.∀l:list labelled_instruction.? → |
---|
[1870] | 649 | (Σppc_pc_map:ℕ×(ℕ×(BitVectorTrie Word 16)). |
---|
| 650 | let 〈ppc,pc_map〉 ≝ ppc_pc_map in |
---|
| 651 | let 〈program_counter, sigma_map〉 ≝ pc_map in |
---|
| 652 | ppc = |l| ∧ |
---|
| 653 | (ppc = |l| → |
---|
| 654 | (bvt_lookup ?? (bitvector_of_nat ? ppc) sigma_map (zero ?) = (bitvector_of_nat ? program_counter)) ∧ |
---|
| 655 | (∀x.x < |l| → |
---|
| 656 | ∀pi.\fst (fetch_pseudo_instruction l (bitvector_of_nat ? x)) = pi → |
---|
| 657 | let pc_x ≝ bvt_lookup ?? (bitvector_of_nat 16 x) sigma_map (zero ?) in |
---|
| 658 | bvt_lookup ?? (bitvector_of_nat 16 (S x)) sigma_map (zero ?) = |
---|
| 659 | bitvector_of_nat 16 ((nat_of_bitvector ? pc_x) + |
---|
[1905] | 660 | (\fst (assembly_1_pseudoinstruction lookup_labels(*X?(λx.pc_x)*) (jump_expansion (*?(λx.pc_x)*)) pc_x |
---|
| 661 | (λx.zero ?) pi))))) |
---|
| 662 | ) ≝ |
---|
| 663 | (*?*)λlookup_labels. |
---|
| 664 | λjump_expansion(*X?: policy_type2*). |
---|
[987] | 665 | λl:list labelled_instruction. |
---|
[1309] | 666 | λacc. |
---|
[1870] | 667 | foldl_strong ? |
---|
| 668 | (λprefix.(Σppc_pc_map:ℕ×(ℕ×(BitVectorTrie Word 16)). |
---|
[1649] | 669 | let 〈ppc,pc_map〉 ≝ ppc_pc_map in |
---|
| 670 | let 〈program_counter, sigma_map〉 ≝ pc_map in |
---|
[1870] | 671 | (ppc = |prefix|) ∧ |
---|
| 672 | (ppc = |prefix| → |
---|
| 673 | (bvt_lookup ?? (bitvector_of_nat ? ppc) sigma_map (zero ?) = (bitvector_of_nat ? program_counter)) ∧ |
---|
| 674 | (∀x.x < |prefix| → |
---|
| 675 | ∀pi.\fst (fetch_pseudo_instruction l (bitvector_of_nat ? x)) = pi → |
---|
| 676 | let pc_x ≝ bvt_lookup ?? (bitvector_of_nat 16 x) sigma_map (zero ?) in |
---|
| 677 | bvt_lookup ?? (bitvector_of_nat 16 (S x)) sigma_map (zero ?) = |
---|
| 678 | bitvector_of_nat 16 ((nat_of_bitvector ? pc_x) + |
---|
[1905] | 679 | (\fst (assembly_1_pseudoinstruction (*X?(λx.pc_x)*)lookup_labels (jump_expansion (*X?(λx.pc_x)*)) pc_x |
---|
| 680 | (λx.zero ?) pi)))))) |
---|
[1870] | 681 | ) |
---|
| 682 | l |
---|
| 683 | (λhd.λi.λtl.λp.λppc_pc_map. |
---|
| 684 | let 〈ppc,pc_map〉 ≝ ppc_pc_map in |
---|
| 685 | let 〈program_counter, sigma_map〉 ≝ pc_map in |
---|
[1649] | 686 | let 〈label, i〉 ≝ i in |
---|
[1905] | 687 | let 〈pc,ignore〉 ≝ construct_costs lookup_labels program_counter (jump_expansion (*X?(λx.bitvector_of_nat ? program_counter)*)) ppc (Stub …) i in |
---|
[1870] | 688 | 〈S ppc, 〈pc, insert ?? (bitvector_of_nat 16 (S ppc)) (bitvector_of_nat 16 pc) sigma_map〉〉 |
---|
| 689 | ) acc. |
---|
| 690 | cases i in p; #label #ins #p @pair_elim #new_ppc #x normalize nodelta cases x -x #old_pc #old_map |
---|
| 691 | @pair_elim #new_pc #ignore #Hc #Heq normalize nodelta @conj |
---|
| 692 | [ lapply (pi2 ?? ppc_pc_map) >p1 >p2 normalize nodelta #Hind |
---|
| 693 | <(pair_eq1 ?????? Heq) >(proj1 ?? Hind) >append_length <commutative_plus normalize @refl |
---|
| 694 | | #Hnew <(pair_eq2 ?????? (pair_eq2 ?????? Heq)) <(pair_eq1 ?????? Heq) @conj |
---|
| 695 | [ >lookup_insert_hit >(pair_eq1 ?????? (pair_eq2 ?????? Heq)) @refl |
---|
| 696 | | #x <(pair_eq1 ?????? Heq) >append_length <commutative_plus #Hx normalize in Hx; |
---|
| 697 | #pi #Hpi <(pair_eq2 ?????? (pair_eq2 ?????? Heq)) <(pair_eq1 ?????? Heq) in Hnew; |
---|
| 698 | >append_length <commutative_plus #Hnew normalize in Hnew; >(injective_S … Hnew) |
---|
| 699 | elim (le_to_or_lt_eq … Hx) -Hx #Hx |
---|
| 700 | [ lapply (pi2 ?? ppc_pc_map) >p1 >p2 normalize nodelta #Hind |
---|
| 701 | lapply (proj2 ?? ((proj2 ?? Hind) (proj1 ?? Hind)) x (le_S_S_to_le … Hx) pi Hpi) |
---|
| 702 | -Hind #Hind >lookup_insert_miss |
---|
| 703 | [2: @bitvector_of_nat_abs |
---|
| 704 | [3: @lt_to_not_eq @Hx |
---|
| 705 | |1: @(transitive_le … Hx) |
---|
| 706 | ] |
---|
| 707 | cases daemon (* XXX invariant *) |
---|
| 708 | ] |
---|
| 709 | >lookup_insert_miss |
---|
| 710 | [2: @bitvector_of_nat_abs |
---|
| 711 | [3: @lt_to_not_eq @(transitive_le … (le_S_S_to_le … Hx)) @le_S @le_n |
---|
| 712 | |1: @(transitive_le … (le_S_S_to_le … Hx)) |
---|
| 713 | ] |
---|
| 714 | cases daemon (* XXX invariant *) |
---|
| 715 | ] |
---|
| 716 | @Hind |
---|
| 717 | | lapply (pi2 ?? ppc_pc_map) >p1 >p2 normalize nodelta |
---|
| 718 | #Hind lapply (proj1 ?? ((proj2 ?? Hind) (proj1 ?? Hind))) -Hind |
---|
| 719 | >(injective_S … Hnew) #Hind <(injective_S … Hx) >lookup_insert_hit >lookup_insert_miss |
---|
| 720 | [2: @bitvector_of_nat_abs |
---|
| 721 | [3: @lt_to_not_eq @le_n |
---|
| 722 | |1: @(transitive_le ??? (le_n (S x))) |
---|
| 723 | ] |
---|
| 724 | cases daemon (* XXX invariant *) |
---|
| 725 | ] |
---|
| 726 | >p in Hpi; whd in match (fetch_pseudo_instruction ??); >nth_append_second |
---|
| 727 | >nat_of_bitvector_bitvector_of_nat >(injective_S … Hx) |
---|
| 728 | [3: @le_n] |
---|
| 729 | [2,3: cases daemon (* XXX invariant *)] |
---|
| 730 | <minus_n_n cases (half_add ???) #x #y normalize nodelta -x -y #Heq <Heq |
---|
| 731 | whd in match (construct_costs ?????) in Hc; whd in match (assembly_1_pseudoinstruction ?????); |
---|
| 732 | cases ins in p Hc; normalize nodelta |
---|
| 733 | [1,2,4,5: #x #p >Hind #H <(pair_eq1 ?????? H) >commutative_plus >nat_of_bitvector_bitvector_of_nat |
---|
| 734 | [1,3,5,7: @refl |
---|
| 735 | |2,4,6,8: cases daemon (* XXX invariant *) |
---|
| 736 | ] |
---|
| 737 | |3: #c #p >Hind #H <(pair_eq1 ?????? H) >nat_of_bitvector_bitvector_of_nat |
---|
| 738 | [2: cases daemon (* XXX invariant *) ] |
---|
| 739 | whd in match (expand_pseudo_instruction ?????); normalize <plus_n_O @refl |
---|
| 740 | |6: #x #y #p >Hind #H <(pair_eq1 ?????? H) >commutative_plus >nat_of_bitvector_bitvector_of_nat |
---|
| 741 | [ @refl |
---|
| 742 | | cases daemon (* XXX invariant *) |
---|
| 743 | ] |
---|
| 744 | ] |
---|
| 745 | ] |
---|
| 746 | ] |
---|
| 747 | ] |
---|
| 748 | qed. |
---|
[985] | 749 | |
---|
[1649] | 750 | definition sigma0: pseudo_assembly_program → policy_type2 → (nat × (nat × (BitVectorTrie Word 16))) ≝ |
---|
[1556] | 751 | λprog. |
---|
| 752 | λjump_expansion. |
---|
[1870] | 753 | sigma00 jump_expansion (\snd prog) |
---|
| 754 | 〈0, 〈0, (insert … (bitvector_of_nat ? 0) (bitvector_of_nat ? 0) (Stub …))〉〉. |
---|
| 755 | normalize nodelta @conj |
---|
| 756 | [ / by refl/ |
---|
| 757 | | #H @conj |
---|
| 758 | [ >lookup_insert_hit @refl |
---|
| 759 | | #x #Hx @⊥ @(absurd … Hx) @le_to_not_lt @le_O_n |
---|
| 760 | ] |
---|
| 761 | ] |
---|
| 762 | qed. |
---|
[985] | 763 | |
---|
[1649] | 764 | definition tech_pc_sigma00: pseudo_assembly_program → policy_type2 → |
---|
| 765 | list labelled_instruction → (nat × nat) ≝ |
---|
[987] | 766 | λprogram,jump_expansion,instr_list. |
---|
[1870] | 767 | let 〈ppc,pc_sigma_map〉 ≝ sigma00 jump_expansion instr_list |
---|
| 768 | 〈0, 〈0, (insert … (bitvector_of_nat ? 0) (bitvector_of_nat ? 0) (Stub ? ?))〉〉 in |
---|
| 769 | (* acc copied from sigma0 *) |
---|
[1649] | 770 | let 〈pc,map〉 ≝ pc_sigma_map in |
---|
| 771 | 〈ppc,pc〉. |
---|
[1870] | 772 | normalize nodelta @conj |
---|
| 773 | [ / by refl/ |
---|
| 774 | | #H @conj |
---|
| 775 | [ >lookup_insert_hit @refl |
---|
| 776 | | #x #Hx @⊥ @(absurd … Hx) @le_to_not_lt @le_O_n |
---|
| 777 | ] |
---|
| 778 | ] |
---|
| 779 | qed. |
---|
[985] | 780 | |
---|
[1649] | 781 | definition sigma_safe: pseudo_assembly_program → policy_type2 → |
---|
| 782 | option (Word → Word) ≝ |
---|
[987] | 783 | λinstr_list,jump_expansion. |
---|
[1649] | 784 | let 〈ppc,pc_sigma_map〉 ≝ sigma0 instr_list jump_expansion in |
---|
| 785 | let 〈pc, sigma_map〉 ≝ pc_sigma_map in |
---|
| 786 | if gtb pc (2^16) then |
---|
| 787 | None ? |
---|
| 788 | else |
---|
[1905] | 789 | Some ? (λx. lookup … x sigma_map (zero …)). *) |
---|
[832] | 790 | |
---|
[985] | 791 | (* stuff about policy *) |
---|
| 792 | |
---|
[1905] | 793 | (*definition policy_ok ≝ λjump_expansion,p. sigma_safe p jump_expansion ≠ None ….*) |
---|
[985] | 794 | |
---|
[1905] | 795 | (*definition policy ≝ λp. Σjump_expansion:policy_type2. policy_ok jump_expansion p.*) |
---|
[987] | 796 | |
---|
[1905] | 797 | (*lemma eject_policy: ∀p. policy p → policy_type2. |
---|
[1607] | 798 | #p #pol @(pi1 … pol) |
---|
[987] | 799 | qed. |
---|
| 800 | |
---|
[1649] | 801 | coercion eject_policy nocomposites: ∀p.∀pol:policy p. policy_type2 ≝ eject_policy on _pol:(policy ?) to policy_type2. |
---|
[987] | 802 | |
---|
| 803 | definition sigma: ∀p:pseudo_assembly_program. policy p → Word → Word ≝ |
---|
| 804 | λp,policy. |
---|
[1607] | 805 | match sigma_safe p (pi1 … policy) return λr:option (Word → Word). r ≠ None … → Word → Word with |
---|
[985] | 806 | [ None ⇒ λabs. ⊥ |
---|
[1606] | 807 | | Some r ⇒ λ_.r] (pi2 … policy). |
---|
[1870] | 808 | cases abs /2 by / |
---|
[1905] | 809 | qed.*) |
---|
| 810 | |
---|
[1667] | 811 | (*CSC: Main axiom here, needs to be proved soon! *) |
---|
[1905] | 812 | (*lemma snd_assembly_1_pseudoinstruction_ok: |
---|
[1667] | 813 | ∀program:pseudo_assembly_program.∀pol: policy program. |
---|
| 814 | ∀ppc:Word.∀pi,lookup_labels,lookup_datalabels. |
---|
| 815 | lookup_labels = (λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x)) → |
---|
| 816 | lookup_datalabels = (λx. lookup_def … (construct_datalabels (\fst program)) x (zero ?)) → |
---|
[1905] | 817 | (nat_of_bitvector 16 ppc) < |\snd program| → |
---|
[1667] | 818 | \fst (fetch_pseudo_instruction (\snd program) ppc) = pi → |
---|
| 819 | let len ≝ \fst (assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) (sigma program pol ppc) lookup_datalabels pi) in |
---|
| 820 | sigma program pol (\snd (half_add ? ppc (bitvector_of_nat ? 1))) = |
---|
| 821 | bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len). |
---|
[1905] | 822 | #program #pol #ppc #pi #lookup_labels #lookup_datalabels #Hll #Hldl #Hppc |
---|
| 823 | lapply (refl … (sigma0 program pol)) whd in match (sigma0 ??) in ⊢ (??%? → ?); |
---|
| 824 | cases (sigma00 ???) #x #Hpmap #EQ |
---|
| 825 | whd in match (sigma ???); |
---|
| 826 | whd in match (sigma program pol (\snd (half_add ???))); |
---|
| 827 | whd in match sigma_safe; normalize nodelta |
---|
| 828 | (*Problem1: backtracking cases (sigma0 program pol)*) |
---|
| 829 | generalize in match (pi2 ???); whd in match policy_ok; normalize nodelta |
---|
| 830 | whd in match sigma_safe; normalize nodelta <EQ cases x in Hpmap EQ; -x #final_ppc #x |
---|
| 831 | cases x -x #final_pc #smap normalize nodelta #Hpmap #EQ #Heq #Hfetch cases (gtb final_pc (2^16)) in Heq; |
---|
| 832 | normalize nodelta |
---|
| 833 | [ #abs @⊥ @(absurd ?? abs) @refl |
---|
| 834 | | #_ lapply (proj1 ?? ((proj2 ?? Hpmap) (proj1 ?? Hpmap))) #Hpmap1 |
---|
| 835 | lapply ((proj2 ?? ((proj2 ?? Hpmap) (proj1 ?? Hpmap))) (nat_of_bitvector 16 ppc) Hppc) #Hpmap2 -Hpmap |
---|
| 836 | <(bitvector_of_nat_nat_of_bitvector 16 ppc) >half_add_SO |
---|
| 837 | |
---|
| 838 | >(Hpmap2 ? (refl …)) @eq_f @eq_f2 [%] |
---|
| 839 | >bitvector_of_nat_nat_of_bitvector |
---|
| 840 | >Hfetch lapply Hfetch lapply pi |
---|
| 841 | |
---|
| 842 | |
---|
| 843 | whd in match assembly_1_pseudoinstruction; normalize nodelta |
---|
[1870] | 844 | |
---|
[1905] | 845 | qed.*) |
---|
| 846 | |
---|
| 847 | |
---|
| 848 | (*example sigma_0: ∀p,pol. sigma p pol (bitvector_of_nat ? 0) = bitvector_of_nat ? 0. |
---|
[985] | 849 | cases daemon. |
---|
[1905] | 850 | qed.*) |
---|
[985] | 851 | |
---|
[1934] | 852 | (*CSC: FALSE!!!*) |
---|
[1482] | 853 | axiom fetch_pseudo_instruction_split: |
---|
| 854 | ∀instr_list,ppc. |
---|
| 855 | ∃pre,suff,lbl. |
---|
| 856 | (pre @ [〈lbl,\fst (fetch_pseudo_instruction instr_list ppc)〉]) @ suff = instr_list. |
---|
| 857 | |
---|
[1870] | 858 | (*lemma sigma00_append: |
---|
| 859 | ∀jump_expansion,l1,l2. |
---|
| 860 | ∀acc:ℕ×ℕ×(BitVectorTrie Word 16). |
---|
[1649] | 861 | sigma00 jump_expansion (l1@l2) acc = |
---|
[1870] | 862 | sigma00 jump_expansion |
---|
| 863 | l2 (pi1 ?? (sigma00 jump_expansion l1 acc)).*) |
---|
[1482] | 864 | |
---|
[1649] | 865 | (* lemma sigma00_strict: |
---|
| 866 | ∀jump_expansion,l,acc. acc = None ? → |
---|
| 867 | sigma00 jump_expansion l acc = None …. |
---|
| 868 | #jump_expansion #l elim l |
---|
[1482] | 869 | [ #acc #H >H % |
---|
[1649] | 870 | | #hd #tl #IH #acc #H >H change with (sigma00 ? tl ? = ?) @IH % ] |
---|
[1482] | 871 | qed. |
---|
| 872 | |
---|
| 873 | lemma policy_ok_prefix_ok: |
---|
| 874 | ∀program.∀pol:policy program.∀suffix,prefix. |
---|
| 875 | prefix@suffix = \snd program → |
---|
| 876 | sigma00 program pol prefix (Some … 〈0, 〈0, Stub …〉〉) ≠ None …. |
---|
| 877 | * #preamble #instr_list #pol #suffix #prefix #prf whd in prf:(???%); |
---|
[1606] | 878 | generalize in match (pi2 ?? pol); whd in prf:(???%); <prf in pol; #pol |
---|
[1528] | 879 | whd in match policy_ok; whd in match sigma_safe; whd in match sigma0; |
---|
[1482] | 880 | normalize nodelta >sigma00_append |
---|
| 881 | cases (sigma00 ?? prefix ?) |
---|
| 882 | [2: #x #_ % #abs destruct(abs) |
---|
| 883 | | * #abs @⊥ @abs >sigma00_strict % ] |
---|
[1649] | 884 | qed. |
---|
[1482] | 885 | |
---|
| 886 | lemma policy_ok_prefix_hd_ok: |
---|
| 887 | ∀program.∀pol:policy program.∀suffix,hd,prefix,ppc_pc_map. |
---|
| 888 | (prefix@[hd])@suffix = \snd program → |
---|
| 889 | Some ? ppc_pc_map = sigma00 program pol prefix (Some … 〈0, 〈0, Stub …〉〉) → |
---|
| 890 | let 〈ppc,pc_map〉 ≝ ppc_pc_map in |
---|
| 891 | let 〈program_counter, sigma_map〉 ≝ pc_map in |
---|
| 892 | let 〈label, i〉 ≝ hd in |
---|
| 893 | construct_costs_safe program pol ppc program_counter (Stub …) i ≠ None …. |
---|
| 894 | * #preamble #instr_list #pol #suffix #hd #prefix #ppc_pc_map #EQ1 #EQ2 |
---|
| 895 | generalize in match (policy_ok_prefix_ok 〈preamble,instr_list〉 pol suffix |
---|
[1528] | 896 | (prefix@[hd]) EQ1) in ⊢ ?; >sigma00_append <EQ2 whd in ⊢ (?(??%?) → ?); |
---|
[1609] | 897 | @pair_elim #ppc #pc_map #EQ3 normalize nodelta |
---|
| 898 | @pair_elim #pc #map #EQ4 normalize nodelta |
---|
| 899 | @pair_elim #l' #i' #EQ5 normalize nodelta |
---|
[1482] | 900 | cases (construct_costs_safe ??????) normalize |
---|
| 901 | [* #abs @⊥ @abs % | #X #_ % #abs destruct(abs)] |
---|
[1649] | 902 | qed. *) |
---|
[1482] | 903 | |
---|
[1649] | 904 | (* JPB,CSC: this definition is now replaced by the expand_pseudo_instruction higher up |
---|
[998] | 905 | definition expand_pseudo_instruction: |
---|
| 906 | ∀program:pseudo_assembly_program.∀pol: policy program. |
---|
[1014] | 907 | ∀ppc:Word.∀lookup_labels,lookup_datalabels,pc. |
---|
[998] | 908 | lookup_labels = (λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x)) → |
---|
[1556] | 909 | lookup_datalabels = (λx. lookup_def … (construct_datalabels (\fst program)) x (zero ?)) → |
---|
[1014] | 910 | let pi ≝ \fst (fetch_pseudo_instruction (\snd program) ppc) in |
---|
[998] | 911 | pc = sigma program pol ppc → |
---|
[1649] | 912 | Σres:list instruction. Some … res = expand_pseudo_instruction_safe pc (lookup_labels pi) lookup_datalabels (pol ppc) pi |
---|
[1014] | 913 | ≝ λprogram,pol,ppc,lookup_labels,lookup_datalabels,pc,prf1,prf2,prf3. |
---|
| 914 | match expand_pseudo_instruction_safe lookup_labels lookup_datalabels pc (pol ppc) (\fst (fetch_pseudo_instruction (\snd program) ppc)) with |
---|
[998] | 915 | [ None ⇒ let dummy ≝ [ ] in dummy |
---|
| 916 | | Some res ⇒ res ]. |
---|
[1482] | 917 | [ @⊥ whd in p:(??%??); |
---|
[1606] | 918 | generalize in match (pi2 ?? pol); whd in ⊢ (% → ?); |
---|
[1556] | 919 | whd in ⊢ (?(??%?) → ?); change with (sigma00 ????) in ⊢ (?(??(match % with [_ ⇒ ? | _ ⇒ ?])?) → ?); |
---|
| 920 | generalize in match (refl … (sigma00 program pol (\snd program) (Some ? 〈O,〈O,Stub (BitVector 16) 16〉〉))); |
---|
| 921 | cases (sigma00 ????) in ⊢ (??%? → %); normalize nodelta [#_ * #abs @abs %] |
---|
[1482] | 922 | #res #K |
---|
| 923 | cases (fetch_pseudo_instruction_split (\snd program) ppc) #pre * #suff * #lbl #EQ1 |
---|
[1556] | 924 | generalize in match (policy_ok_prefix_hd_ok program pol … EQ1 ?) in ⊢ ?; |
---|
[1482] | 925 | cases daemon (* CSC: XXXXXXXX Ero qui |
---|
| 926 | |
---|
| 927 | [3: @policy_ok_prefix_ok ] |
---|
| 928 | | sigma00 program pol pre |
---|
| 929 | |
---|
| 930 | |
---|
| 931 | |
---|
| 932 | QUA USARE LEMMA policy_ok_prefix_hd_ok combinato a lemma da fare che |
---|
| 933 | fetch ppc = hd sse program = pre @ [hd] @ tl e |pre| = ppc |
---|
| 934 | per concludere construct_costs_safe ≠ None *) |
---|
[998] | 935 | | >p %] |
---|
[1649] | 936 | qed. *) |
---|
[998] | 937 | |
---|
[993] | 938 | (* MAIN AXIOM HERE, HIDDEN USING cases daemon *) |
---|
[1649] | 939 | (* definition assembly_1_pseudoinstruction': |
---|
[993] | 940 | ∀program:pseudo_assembly_program.∀pol: policy program. |
---|
| 941 | ∀ppc:Word.∀lookup_labels,lookup_datalabels,pi. |
---|
| 942 | lookup_labels = (λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x)) → |
---|
[1556] | 943 | lookup_datalabels = (λx. lookup_def … (construct_datalabels (\fst program)) x (zero ?)) → |
---|
[993] | 944 | \fst (fetch_pseudo_instruction (\snd program) ppc) = pi → |
---|
| 945 | Σres:(nat × (list Byte)). |
---|
[1649] | 946 | res = assembly_1_pseudoinstruction program pol ppc (sigma program pol ppc) lookup_labels lookup_datalabels pi ∧ |
---|
[993] | 947 | let 〈len,code〉 ≝ res in |
---|
| 948 | sigma program pol (\snd (half_add ? ppc (bitvector_of_nat ? 1))) = |
---|
| 949 | bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len) |
---|
| 950 | ≝ λprogram: pseudo_assembly_program. |
---|
| 951 | λpol: policy program. |
---|
| 952 | λppc: Word. |
---|
| 953 | λlookup_labels. |
---|
| 954 | λlookup_datalabels. |
---|
| 955 | λpi. |
---|
| 956 | λprf1,prf2,prf3. |
---|
[1649] | 957 | assembly_1_pseudoinstruction program pol ppc (sigma program pol ppc) lookup_labels lookup_datalabels pi. |
---|
[1556] | 958 | [ @⊥ elim pi in p; [*] |
---|
[993] | 959 | try (#ARG1 #ARG2 #ARG3 #abs) try (#ARG1 #ARG2 #abs) try (#ARG1 #abs) try #abs |
---|
[1556] | 960 | generalize in match (jmeq_to_eq ??? abs); -abs; #abs whd in abs:(??%?); try destruct(abs) |
---|
[993] | 961 | whd in abs:(??match % with [_ ⇒ ? | _ ⇒ ?]?); |
---|
| 962 | (* WRONG HERE, NEEDS LEMMA SAYING THAT THE POLICY DOES NOT RETURN MEDIUM! *) |
---|
| 963 | cases daemon |
---|
[1309] | 964 | | % [ >p %] |
---|
| 965 | cases res in p ⊢ %; -res; #len #code #EQ normalize nodelta; |
---|
[993] | 966 | (* THIS SHOULD BE TRUE INSTEAD *) |
---|
| 967 | cases daemon] |
---|
[1649] | 968 | qed. |
---|
[993] | 969 | |
---|
[1309] | 970 | definition assembly_1_pseudoinstruction: |
---|
| 971 | ∀program:pseudo_assembly_program.∀pol: policy program. |
---|
| 972 | ∀ppc:Word.∀lookup_labels,lookup_datalabels,pi. |
---|
| 973 | lookup_labels = (λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x)) → |
---|
[1556] | 974 | lookup_datalabels = (λx. lookup_def … (construct_datalabels (\fst program)) x (zero ?)) → |
---|
[1309] | 975 | \fst (fetch_pseudo_instruction (\snd program) ppc) = pi → |
---|
| 976 | nat × (list Byte) |
---|
| 977 | ≝ λprogram,pol,ppc,lookup_labels,lookup_datalabels,pi,prf1,prf2,prf3. |
---|
| 978 | assembly_1_pseudoinstruction' program pol ppc lookup_labels lookup_datalabels pi prf1 |
---|
| 979 | prf2 prf3. |
---|
| 980 | |
---|
| 981 | lemma assembly_1_pseudoinstruction_ok1: |
---|
| 982 | ∀program:pseudo_assembly_program.∀pol: policy program. |
---|
| 983 | ∀ppc:Word.∀lookup_labels,lookup_datalabels,pi. |
---|
| 984 | ∀prf1:lookup_labels = (λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x)). |
---|
[1556] | 985 | ∀prf2:lookup_datalabels = (λx. lookup_def … (construct_datalabels (\fst program)) x (zero ?)). |
---|
[1309] | 986 | ∀prf3:\fst (fetch_pseudo_instruction (\snd program) ppc) = pi. |
---|
| 987 | Some … (assembly_1_pseudoinstruction program pol ppc lookup_labels lookup_datalabels pi prf1 prf2 prf3) |
---|
| 988 | = assembly_1_pseudoinstruction_safe program pol ppc (sigma program pol ppc) lookup_labels lookup_datalabels pi. |
---|
| 989 | #program #pol #ppc #lookup_labels #lookup_datalabels #pi #prf1 #prf2 #prf3 |
---|
[1606] | 990 | cases (pi2 … (assembly_1_pseudoinstruction' program pol ppc lookup_labels lookup_datalabels pi prf1 prf2 prf3)) |
---|
[1309] | 991 | #H1 #_ @H1 |
---|
[1649] | 992 | qed. *) |
---|
[1309] | 993 | |
---|
[993] | 994 | (* MAIN AXIOM HERE, HIDDEN USING cases daemon *) |
---|
[1649] | 995 | (* definition construct_costs': |
---|
[1309] | 996 | ∀program. ∀pol:policy program. ∀ppc,pc,costs,i. |
---|
[1556] | 997 | Σres:(nat × (BitVectorTrie costlabel 16)). Some … res = construct_costs_safe program pol ppc pc costs i |
---|
[993] | 998 | ≝ |
---|
| 999 | λprogram.λpol: policy program.λppc,pc,costs,i. |
---|
| 1000 | match construct_costs_safe program pol ppc pc costs i with |
---|
[1556] | 1001 | [ None ⇒ let dummy ≝ 〈0, Stub costlabel 16〉 in dummy |
---|
[993] | 1002 | | Some res ⇒ res ]. |
---|
| 1003 | [ cases daemon |
---|
[1309] | 1004 | | >p %] |
---|
[993] | 1005 | qed. |
---|
| 1006 | |
---|
| 1007 | definition construct_costs ≝ |
---|
[1649] | 1008 | λprogram,pol,ppc,pc,costs,i. pi1 … (construct_costs' program pol ppc pc costs i). *) |
---|
[993] | 1009 | |
---|
[1482] | 1010 | (* |
---|
| 1011 | axiom suffix_of: ∀A:Type[0]. ∀l,prefix:list A. list A. |
---|
| 1012 | axiom suffix_of_ok: ∀A,l,prefix. prefix @ suffix_of A l prefix = l. |
---|
[1309] | 1013 | |
---|
[1482] | 1014 | axiom foldl_strong_step: |
---|
| 1015 | ∀A:Type[0]. |
---|
| 1016 | ∀P: list A → Type[0]. |
---|
| 1017 | ∀l: list A. |
---|
| 1018 | ∀H: ∀prefix,hd,tl. l = prefix @ [hd] @ tl → P prefix → P (prefix @ [hd]). |
---|
| 1019 | ∀acc: P [ ]. |
---|
| 1020 | ∀Q: ∀prefix. P prefix → Prop. |
---|
| 1021 | ∀HQ: ∀prefix,hd,tl.∀prf: l = prefix @ [hd] @ tl. |
---|
| 1022 | ∀acc: P prefix. Q prefix acc → Q (prefix @ [hd]) (H prefix hd tl prf acc). |
---|
| 1023 | Q [ ] acc → |
---|
| 1024 | Q l (foldl_strong A P l H acc). |
---|
| 1025 | (* |
---|
| 1026 | #A #P #l #H #acc #Q #HQ #Hacc normalize; |
---|
| 1027 | generalize in match |
---|
| 1028 | (foldl_strong ? |
---|
| 1029 | (λpre. Q pre (foldl_strong_internal A P l (suffix_of A l pre) ? [ ] pre acc ?)) |
---|
| 1030 | l ? Hacc) |
---|
| 1031 | [3: >suffix_of_ok % | 2: #prefix #hd #tl #EQ @(H prefix hd (tl@suffix_of A l pre) EQ) ] |
---|
| 1032 | [2: #prefix #hd #tl #prf #X whd in ⊢ (??%) |
---|
| 1033 | #K |
---|
[1309] | 1034 | |
---|
[1482] | 1035 | generalize in match |
---|
| 1036 | (foldl_strong ? |
---|
| 1037 | (λpre. Q pre (foldl_strong_internal A P l H pre (suffix_of A l pre) acc (suffix_of_ok A l pre)))) |
---|
| 1038 | [2: @H |
---|
| 1039 | *) |
---|
[1309] | 1040 | |
---|
[1482] | 1041 | axiom foldl_elim: |
---|
| 1042 | ∀A:Type[0]. |
---|
| 1043 | ∀B: Type[0]. |
---|
| 1044 | ∀H: A → B → A. |
---|
| 1045 | ∀acc: A. |
---|
| 1046 | ∀l: list B. |
---|
| 1047 | ∀Q: A → Prop. |
---|
| 1048 | (∀acc:A.∀b:B. Q acc → Q (H acc b)) → |
---|
| 1049 | Q acc → |
---|
| 1050 | Q (foldl A B H acc l). |
---|
| 1051 | *) |
---|
[1309] | 1052 | |
---|
| 1053 | (* |
---|
| 1054 | lemma tech_pc_sigma00_append_Some: |
---|
| 1055 | ∀program.∀pol:policy program.∀prefix,costs,label,i,ppc,pc. |
---|
| 1056 | tech_pc_sigma00 program pol prefix = Some … 〈ppc,pc〉 → |
---|
| 1057 | tech_pc_sigma00 program pol (prefix@[〈label,i〉]) = Some … 〈S ppc,\fst (construct_costs program pol … ppc pc costs i)〉. |
---|
| 1058 | #program #pol #prefix #costs #label #i #ppc #pc #H |
---|
| 1059 | whd in match tech_pc_sigma00 in ⊢ %; normalize nodelta; |
---|
| 1060 | whd in match sigma00 in ⊢ %; normalize nodelta in ⊢ %; |
---|
[1606] | 1061 | generalize in match (pi2 … pol) whd in ⊢ (% → ?) whd in ⊢ (?(??%?) → ?) |
---|
[1309] | 1062 | whd in match sigma0; normalize nodelta; |
---|
| 1063 | >foldl_step |
---|
| 1064 | change with (? → match match sigma00 program pol prefix with [None ⇒ ? | Some res ⇒ ?] with [ None ⇒ ? | Some res ⇒ ? ] = ?) |
---|
| 1065 | whd in match tech_pc_sigma00 in H; normalize nodelta in H; |
---|
| 1066 | cases (sigma00 program pol prefix) in H ⊢ % |
---|
| 1067 | [ whd in ⊢ (??%% → ?) #abs destruct(abs) |
---|
| 1068 | | * #ppc' * #pc' #sigma_map normalize nodelta; #H generalize in match (option_destruct_Some ??? H) |
---|
| 1069 | |
---|
| 1070 | normalize nodelta; -H; |
---|
| 1071 | |
---|
| 1072 | |
---|
| 1073 | generalize in match H; -H; |
---|
| 1074 | generalize in match (foldl ?????); in H ⊢ (??match match % with [_ ⇒ ? | _ ⇒ ?] with [_ ⇒ ? | _ ⇒ ?]?) |
---|
| 1075 | [2: whd in ⊢ (??%%) |
---|
| 1076 | XXX |
---|
| 1077 | *) |
---|
| 1078 | |
---|
[1649] | 1079 | (* axiom construct_costs_sigma: |
---|
[993] | 1080 | ∀p.∀pol:policy p.∀ppc,pc,costs,i. |
---|
[987] | 1081 | bitvector_of_nat ? pc = sigma p pol (bitvector_of_nat ? ppc) → |
---|
[993] | 1082 | bitvector_of_nat ? (\fst (construct_costs p pol ppc pc costs i)) = sigma p pol (bitvector_of_nat 16 (S ppc)). |
---|
[985] | 1083 | |
---|
| 1084 | axiom tech_pc_sigma00_append_Some: |
---|
[993] | 1085 | ∀program.∀pol:policy program.∀prefix,costs,label,i,ppc,pc. |
---|
[987] | 1086 | tech_pc_sigma00 program pol prefix = Some … 〈ppc,pc〉 → |
---|
[1649] | 1087 | tech_pc_sigma00 program pol (prefix@[〈label,i〉]) = Some … 〈S ppc,\fst (construct_costs program pol … ppc pc costs i)〉. *) |
---|
[985] | 1088 | |
---|
[1934] | 1089 | (*axiom eq_identifier_eq: |
---|
[1556] | 1090 | ∀tag: String. |
---|
| 1091 | ∀l. |
---|
| 1092 | ∀r. |
---|
| 1093 | eq_identifier tag l r = true → l = r. |
---|
| 1094 | |
---|
[1562] | 1095 | axiom neq_identifier_neq: |
---|
| 1096 | ∀tag: String. |
---|
| 1097 | ∀l, r: identifier tag. |
---|
| 1098 | eq_identifier tag l r = false → (l = r → False). |
---|
[1934] | 1099 | *) |
---|
[1562] | 1100 | |
---|
[1934] | 1101 | (* label_map: identifier ↦ pseudo program counter *) |
---|
| 1102 | definition label_map ≝ identifier_map ASMTag ℕ. |
---|
| 1103 | |
---|
| 1104 | (* Labels *) |
---|
| 1105 | definition is_label ≝ |
---|
| 1106 | λx:labelled_instruction.λl:Identifier. |
---|
| 1107 | let 〈lbl,instr〉 ≝ x in |
---|
| 1108 | match lbl with |
---|
| 1109 | [ Some l' ⇒ l' = l |
---|
| 1110 | | _ ⇒ False |
---|
| 1111 | ]. |
---|
| 1112 | |
---|
| 1113 | lemma label_does_not_occur: |
---|
| 1114 | ∀i:ℕ.∀p:list labelled_instruction.∀l:Identifier. |
---|
| 1115 | is_label (nth i ? p 〈None ?, Comment [ ]〉) l → does_not_occur ?? l p = false. |
---|
| 1116 | #i #p #l generalize in match i; elim p |
---|
| 1117 | [ #i >nth_nil #H cases H |
---|
| 1118 | | #h #t #IH #i cases i -i |
---|
| 1119 | [ cases h #hi #hp cases hi |
---|
| 1120 | [ normalize #H cases H |
---|
| 1121 | | #l' #Heq whd in ⊢ (??%?); change with (eq_identifier ? l' l) in match (instruction_matches_identifier ????); |
---|
| 1122 | whd in Heq; >Heq |
---|
| 1123 | >eq_identifier_refl / by refl/ |
---|
| 1124 | ] |
---|
| 1125 | | #i #H whd in match (does_not_occur ????); |
---|
| 1126 | whd in match (instruction_matches_identifier ????); |
---|
| 1127 | cases h #hi #hp cases hi normalize nodelta |
---|
| 1128 | [ @(IH i) @H |
---|
| 1129 | | #l' @eq_identifier_elim |
---|
| 1130 | [ normalize / by / |
---|
| 1131 | | normalize #_ @(IH i) @H |
---|
| 1132 | ] |
---|
| 1133 | ] |
---|
| 1134 | ] |
---|
| 1135 | ] |
---|
[1556] | 1136 | qed. |
---|
| 1137 | |
---|
[1934] | 1138 | (* The function that creates the label-to-address map *) |
---|
| 1139 | definition create_label_cost_map: ∀program:list labelled_instruction. |
---|
| 1140 | (Σlabels_costs:label_map × (BitVectorTrie costlabel 16). (* Both on ppcs *) |
---|
| 1141 | let 〈labels,costs〉 ≝ labels_costs in |
---|
| 1142 | ∀i:ℕ.lt i (|program|) → |
---|
| 1143 | ∀l.occurs_exactly_once ?? l program → |
---|
| 1144 | is_label (nth i ? program 〈None ?, Comment [ ]〉) l → |
---|
| 1145 | lookup ?? labels l = Some ? i |
---|
| 1146 | ) ≝ |
---|
| 1147 | λprogram. |
---|
| 1148 | \fst (foldl_strong (option Identifier × pseudo_instruction) |
---|
| 1149 | (λprefix.Σlabels_costs_ppc:label_map × (BitVectorTrie costlabel 16) × nat. |
---|
| 1150 | let 〈labels,costs,ppc〉 ≝ labels_costs_ppc in |
---|
| 1151 | ppc = |prefix| ∧ |
---|
| 1152 | ∀i:ℕ.lt i (|prefix|) → |
---|
| 1153 | ∀l.occurs_exactly_once ?? l prefix → |
---|
| 1154 | is_label (nth i ? prefix 〈None ?, Comment [ ]〉) l → |
---|
| 1155 | lookup … labels l = Some ? i |
---|
| 1156 | ) |
---|
| 1157 | program |
---|
| 1158 | (λprefix.λx.λtl.λprf.λlabels_costs_ppc. |
---|
| 1159 | let 〈labels,costs,ppc〉 ≝ labels_costs_ppc in |
---|
| 1160 | let 〈label,instr〉 ≝ x in |
---|
| 1161 | let labels ≝ |
---|
| 1162 | match label with |
---|
| 1163 | [ None ⇒ labels |
---|
| 1164 | | Some l ⇒ add … labels l ppc |
---|
| 1165 | ] in |
---|
| 1166 | let costs ≝ |
---|
| 1167 | match instr with |
---|
| 1168 | [ Cost cost ⇒ insert … (bitvector_of_nat ? ppc) cost costs |
---|
| 1169 | | _ ⇒ costs ] in |
---|
| 1170 | 〈labels,costs,S ppc〉 |
---|
| 1171 | ) 〈(empty_map …),(Stub ??),0〉). |
---|
| 1172 | [2: normalize nodelta lapply (pi2 … labels_costs_ppc) >p >p1 normalize nodelta * #IH1 #IH2 |
---|
| 1173 | -labels_costs_ppc % [>IH1 >length_append <plus_n_Sm <plus_n_O %] |
---|
| 1174 | inversion label [#EQ | #l #EQ] |
---|
| 1175 | [1,2: normalize nodelta |
---|
| 1176 | #i >append_length >commutative_plus #Hi normalize in Hi; cases (le_to_or_lt_eq … Hi) -Hi; |
---|
| 1177 | [3: #Hi #lbl #Hocc #Hlbl lapply (occurs_exactly_once_Some_stronger ?????? Hocc) -Hocc |
---|
| 1178 | @eq_identifier_elim |
---|
| 1179 | [ #Heq #Hocc normalize in Hocc; >(nth_append_first ?? prefix ?? (le_S_S_to_le … Hi)) in Hlbl; #Hl |
---|
| 1180 | @⊥ @(absurd … Hocc) >(label_does_not_occur i … Hl) normalize nodelta /2 by nmk/ |
---|
| 1181 | | #Heq #Hocc normalize in Hocc; >lookup_add_miss |
---|
| 1182 | [ @(IH2 … i (le_S_S_to_le … Hi)) |
---|
| 1183 | [ @Hocc |
---|
| 1184 | | >(nth_append_first ? ? prefix ? ? (le_S_S_to_le … Hi)) in Hlbl; / by / |
---|
| 1185 | ] |
---|
| 1186 | | @sym_neq @Heq |
---|
| 1187 | ] |
---|
| 1188 | ] |
---|
| 1189 | |4: #Hi #lbl #Hocc >(injective_S … Hi) >nth_append_second |
---|
| 1190 | [ <minus_n_n #Hl normalize in Hl; >Hl >IH1 @lookup_add_hit |
---|
| 1191 | | @le_n |
---|
| 1192 | ] |
---|
| 1193 | |1: #Hi #lbl >occurs_exactly_once_None #Hocc #Hlbl |
---|
| 1194 | @(IH2 … i (le_S_S_to_le … Hi)) |
---|
| 1195 | [ @Hocc |
---|
| 1196 | | >(nth_append_first ? ? prefix ? ? (le_S_S_to_le … Hi)) in Hlbl; / by / |
---|
| 1197 | ] |
---|
| 1198 | |2: #Hi #lbl #Hocc >(injective_S … Hi) >nth_append_second |
---|
| 1199 | [ <minus_n_n #Hl cases Hl |
---|
| 1200 | | @le_n |
---|
| 1201 | ] |
---|
| 1202 | ] |
---|
| 1203 | ] |
---|
| 1204 | | @pair_elim * #labels #costs #ppc #EQ destruct normalize nodelta % try % |
---|
| 1205 | #i #Hi normalize in Hi; cases (not_le_Sn_O i) #abs cases (abs Hi) |
---|
| 1206 | | cases (foldl_strong ? (λ_.Σx.?) ???) * * #labels #costs #ppc normalize nodelta * |
---|
| 1207 | #_ #H @H |
---|
| 1208 | ] |
---|
| 1209 | qed. |
---|
[1668] | 1210 | |
---|
[1934] | 1211 | (*theorem build_maps_ok: |
---|
[1905] | 1212 | ∀pseudo_program.∀sigma:Word → Word. |
---|
| 1213 | let 〈labels, costs〉 ≝ build_maps pseudo_program sigma in |
---|
[1885] | 1214 | ∀id. occurs_exactly_once ?? id (\snd pseudo_program) → |
---|
[1905] | 1215 | lookup_def … labels id (zero ?) = sigma (address_of_word_labels_code_mem (\snd pseudo_program) id). |
---|
| 1216 | #pseudo_program #sigma @(pi2 … (build_maps0 … sigma)) |
---|
[1934] | 1217 | qed.*) |
---|
[1668] | 1218 | |
---|
[993] | 1219 | definition assembly: |
---|
[1934] | 1220 | ∀p:pseudo_assembly_program.∀sigma:Word → Word × bool.list Byte × (BitVectorTrie costlabel 16) ≝ |
---|
[993] | 1221 | λp.let 〈preamble, instr_list〉 ≝ p in |
---|
[1905] | 1222 | λsigma. |
---|
[1934] | 1223 | let 〈labels_to_ppc,ppc_to_costs〉 ≝ create_label_cost_map instr_list in |
---|
[985] | 1224 | let datalabels ≝ construct_datalabels preamble in |
---|
[1934] | 1225 | let lookup_labels ≝ λx. \fst (sigma (bitvector_of_nat ? (lookup_def … labels_to_ppc x 0))) in |
---|
[1562] | 1226 | let lookup_datalabels ≝ λx. lookup_def … datalabels x (zero ?) in |
---|
[993] | 1227 | let result ≝ |
---|
| 1228 | foldl_strong |
---|
| 1229 | (option Identifier × pseudo_instruction) |
---|
| 1230 | (λpre. Σpc_ppc_code:(Word × (Word × (list Byte))). |
---|
| 1231 | let 〈pc,ppc_code〉 ≝ pc_ppc_code in |
---|
| 1232 | let 〈ppc,code〉 ≝ ppc_code in |
---|
| 1233 | ∀ppc'. |
---|
| 1234 | let 〈pi,newppc〉 ≝ fetch_pseudo_instruction instr_list ppc' in |
---|
| 1235 | let 〈len,assembledi〉 ≝ |
---|
[1905] | 1236 | assembly_1_pseudoinstruction lookup_labels sigma ppc' lookup_datalabels pi in |
---|
[993] | 1237 | True) |
---|
| 1238 | instr_list |
---|
| 1239 | (λprefix,hd,tl,prf,pc_ppc_code. |
---|
| 1240 | let 〈pc, ppc_code〉 ≝ pc_ppc_code in |
---|
| 1241 | let 〈ppc, code〉 ≝ ppc_code in |
---|
[1905] | 1242 | let 〈pc_delta, program〉 ≝ assembly_1_pseudoinstruction lookup_labels sigma ppc lookup_datalabels (\snd hd) in |
---|
[993] | 1243 | let 〈new_pc, flags〉 ≝ add_16_with_carry pc (bitvector_of_nat ? pc_delta) false in |
---|
| 1244 | let new_ppc ≝ \snd (half_add ? ppc (bitvector_of_nat ? 1)) in |
---|
| 1245 | 〈new_pc, 〈new_ppc, (code @ program)〉〉) |
---|
| 1246 | 〈(zero ?), 〈(zero ?), [ ]〉〉 |
---|
[985] | 1247 | in |
---|
[1934] | 1248 | 〈\snd (\snd result), |
---|
| 1249 | fold … (λppc.λcost.λpc_to_costs. insert … (\fst (sigma ppc)) cost pc_to_costs) ppc_to_costs (Stub ??)〉. |
---|
| 1250 | @pair_elim normalize nodelta #x #y #z @pair_elim normalize nodelta #w1 #w2 #w3 #w4 @pair_elim // |
---|
[993] | 1251 | qed. |
---|
[832] | 1252 | |
---|
[820] | 1253 | definition assembly_unlabelled_program: assembly_program → option (list Byte × (BitVectorTrie Identifier 16)) ≝ |
---|
[1934] | 1254 | λp. Some ? (〈foldr ? ? (λi,l. assembly1 i @ l) [ ] p, Stub …〉). |
---|